Fix a UAF defect on SocketStream.
[chromium-blink-merge.git] / cc / output / direct_renderer.h
blobe5ee83c87bd636c397b8e44b49df5b9787adb6c3
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_OUTPUT_DIRECT_RENDERER_H_
6 #define CC_OUTPUT_DIRECT_RENDERER_H_
8 #include "base/basictypes.h"
9 #include "base/callback.h"
10 #include "base/containers/scoped_ptr_hash_map.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/output/renderer.h"
13 #include "cc/resources/resource_provider.h"
14 #include "cc/resources/scoped_resource.h"
16 namespace cc {
18 class ResourceProvider;
20 // This is the base class for code shared between the GL and software
21 // renderer implementations. "Direct" refers to the fact that it does not
22 // delegate rendering to another compositor.
23 class CC_EXPORT DirectRenderer : public Renderer {
24 public:
25 virtual ~DirectRenderer();
27 ResourceProvider* resource_provider() const { return resource_provider_; }
29 virtual bool CanReadPixels() const OVERRIDE;
30 virtual void DecideRenderPassAllocationsForFrame(
31 const RenderPassList& render_passes_in_draw_order) OVERRIDE;
32 virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id) const
33 OVERRIDE;
34 virtual void DrawFrame(RenderPassList* render_passes_in_draw_order,
35 ContextProvider* offscreen_context_provider,
36 float device_scale_factor,
37 bool allow_partial_swap) OVERRIDE;
39 struct CC_EXPORT DrawingFrame {
40 DrawingFrame();
41 ~DrawingFrame();
43 const RenderPass* root_render_pass;
44 const RenderPass* current_render_pass;
45 const ScopedResource* current_texture;
47 gfx::RectF root_damage_rect;
49 gfx::Transform projection_matrix;
50 gfx::Transform window_matrix;
52 ContextProvider* offscreen_context_provider;
55 void SetEnlargePassTextureAmountForTesting(gfx::Vector2d amount);
57 protected:
58 DirectRenderer(RendererClient* client,
59 const LayerTreeSettings* settings,
60 OutputSurface* output_surface,
61 ResourceProvider* resource_provider);
63 class CachedResource : public ScopedResource {
64 public:
65 static scoped_ptr<CachedResource> Create(
66 ResourceProvider* resource_provider) {
67 return make_scoped_ptr(new CachedResource(resource_provider));
69 virtual ~CachedResource() {}
71 bool is_complete() const { return is_complete_; }
72 void set_is_complete(bool is_complete) { is_complete_ = is_complete; }
74 protected:
75 explicit CachedResource(ResourceProvider* resource_provider)
76 : ScopedResource(resource_provider),
77 is_complete_(false) {}
79 private:
80 bool is_complete_;
82 DISALLOW_COPY_AND_ASSIGN(CachedResource);
85 static gfx::RectF QuadVertexRect();
86 static void QuadRectTransform(gfx::Transform* quad_rect_transform,
87 const gfx::Transform& quad_transform,
88 const gfx::RectF& quad_rect);
89 void InitializeViewport(DrawingFrame* frame,
90 gfx::Rect draw_rect,
91 gfx::Rect viewport_rect,
92 gfx::Size surface_size);
93 gfx::Rect MoveFromDrawToWindowSpace(const gfx::RectF& draw_rect) const;
95 bool NeedDeviceClip(const DrawingFrame* frame) const;
96 gfx::Rect DeviceClipRect(const DrawingFrame* frame) const;
97 static gfx::RectF ComputeScissorRectForRenderPass(const DrawingFrame* frame);
98 void SetScissorStateForQuad(const DrawingFrame* frame, const DrawQuad& quad);
99 void SetScissorStateForQuadWithRenderPassScissor(
100 const DrawingFrame* frame,
101 const DrawQuad& quad,
102 const gfx::RectF& render_pass_scissor,
103 bool* should_skip_quad);
104 void SetScissorTestRectInDrawSpace(const DrawingFrame* frame,
105 gfx::RectF draw_space_rect);
107 static gfx::Size RenderPassTextureSize(const RenderPass* render_pass);
108 static ResourceFormat RenderPassTextureFormat(const RenderPass* render_pass);
110 void DrawRenderPass(DrawingFrame* frame,
111 const RenderPass* render_pass,
112 bool allow_partial_swap);
113 bool UseRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
115 virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) = 0;
116 virtual bool BindFramebufferToTexture(DrawingFrame* frame,
117 const ScopedResource* resource,
118 gfx::Rect target_rect) = 0;
119 virtual void SetDrawViewport(gfx::Rect window_space_viewport) = 0;
120 virtual void SetScissorTestRect(gfx::Rect scissor_rect) = 0;
121 virtual void DiscardPixels(bool has_external_stencil_test,
122 bool draw_rect_covers_full_surface) = 0;
123 virtual void ClearFramebuffer(DrawingFrame* frame,
124 bool has_external_stencil_test) = 0;
125 virtual void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) = 0;
126 virtual void BeginDrawingFrame(DrawingFrame* frame) = 0;
127 virtual void FinishDrawingFrame(DrawingFrame* frame) = 0;
128 virtual void FinishDrawingQuadList();
129 virtual bool FlippedFramebuffer() const = 0;
130 virtual void EnsureScissorTestEnabled() = 0;
131 virtual void EnsureScissorTestDisabled() = 0;
132 virtual void DiscardBackbuffer() {}
133 virtual void EnsureBackbuffer() {}
135 virtual void CopyCurrentRenderPassToBitmap(
136 DrawingFrame* frame,
137 scoped_ptr<CopyOutputRequest> request) = 0;
139 base::ScopedPtrHashMap<RenderPass::Id, CachedResource> render_pass_textures_;
140 OutputSurface* output_surface_;
141 ResourceProvider* resource_provider_;
143 // For use in coordinate conversion, this stores the output rect, viewport
144 // rect (= unflipped version of glViewport rect), and the size of target
145 // framebuffer. During a draw, this stores the values for the current render
146 // pass; in between draws, they retain the values for the root render pass of
147 // the last draw.
148 gfx::Rect current_draw_rect_;
149 gfx::Rect current_viewport_rect_;
150 gfx::Size current_surface_size_;
152 private:
153 gfx::Vector2d enlarge_pass_texture_amount_;
155 DISALLOW_COPY_AND_ASSIGN(DirectRenderer);
158 } // namespace cc
160 #endif // CC_OUTPUT_DIRECT_RENDERER_H_