Dismiss autofill popup on screen orientation change.
[chromium-blink-merge.git] / cc / output / direct_renderer.h
blobffc2b67b8a707f2c802253b3098f6c4a84f63556
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 "cc/base/cc_export.h"
11 #include "cc/output/renderer.h"
12 #include "cc/resources/resource_provider.h"
13 #include "cc/resources/scoped_resource.h"
15 namespace cc {
17 class ResourceProvider;
19 // This is the base class for code shared between the GL and software
20 // renderer implementations. "Direct" refers to the fact that it does not
21 // delegate rendering to another compositor.
22 class CC_EXPORT DirectRenderer : public Renderer {
23 public:
24 virtual ~DirectRenderer();
26 ResourceProvider* resource_provider() const { return resource_provider_; }
28 virtual bool CanReadPixels() const OVERRIDE;
29 virtual void DecideRenderPassAllocationsForFrame(
30 const RenderPassList& render_passes_in_draw_order) OVERRIDE;
31 virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id) const
32 OVERRIDE;
33 virtual void DrawFrame(RenderPassList* render_passes_in_draw_order) OVERRIDE;
35 struct CC_EXPORT DrawingFrame {
36 DrawingFrame();
37 ~DrawingFrame();
39 const RenderPass* root_render_pass;
40 const RenderPass* current_render_pass;
41 const ScopedResource* current_texture;
43 gfx::RectF root_damage_rect;
45 gfx::Transform projection_matrix;
46 gfx::Transform window_matrix;
49 void SetEnlargePassTextureAmountForTesting(gfx::Vector2d amount);
51 protected:
52 DirectRenderer(RendererClient* client,
53 OutputSurface* output_surface,
54 ResourceProvider* resource_provider);
56 class CachedResource : public ScopedResource {
57 public:
58 static scoped_ptr<CachedResource> Create(
59 ResourceProvider* resource_provider) {
60 return make_scoped_ptr(new CachedResource(resource_provider));
62 virtual ~CachedResource() {}
64 bool is_complete() const { return is_complete_; }
65 void set_is_complete(bool is_complete) { is_complete_ = is_complete; }
67 protected:
68 explicit CachedResource(ResourceProvider* resource_provider)
69 : ScopedResource(resource_provider),
70 is_complete_(false) {}
72 private:
73 bool is_complete_;
75 DISALLOW_COPY_AND_ASSIGN(CachedResource);
78 static gfx::RectF QuadVertexRect();
79 static void QuadRectTransform(gfx::Transform* quad_rect_transform,
80 const gfx::Transform& quad_transform,
81 const gfx::RectF& quad_rect);
82 void InitializeViewport(DrawingFrame* frame,
83 gfx::Rect draw_rect,
84 gfx::Rect viewport_rect,
85 gfx::Size surface_size);
86 gfx::Rect MoveFromDrawToWindowSpace(const gfx::RectF& draw_rect) const;
88 static gfx::RectF ComputeScissorRectForRenderPass(const DrawingFrame* frame);
89 void SetScissorStateForQuad(const DrawingFrame* frame, const DrawQuad& quad);
90 void SetScissorStateForQuadWithRenderPassScissor(
91 const DrawingFrame* frame,
92 const DrawQuad& quad,
93 const gfx::RectF& render_pass_scissor,
94 bool* should_skip_quad);
96 static gfx::Size RenderPassTextureSize(const RenderPass* render_pass);
97 static GLenum RenderPassTextureFormat(const RenderPass* render_pass);
99 void DrawRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
100 bool UseRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
102 virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) = 0;
103 virtual bool BindFramebufferToTexture(DrawingFrame* frame,
104 const ScopedResource* resource,
105 gfx::Rect target_rect) = 0;
106 virtual void SetDrawViewport(gfx::Rect window_space_viewport) = 0;
107 virtual void SetScissorTestRect(gfx::Rect scissor_rect) = 0;
108 virtual void ClearFramebuffer(DrawingFrame* frame) = 0;
109 virtual void DoDrawQuad(DrawingFrame* frame, const DrawQuad* quad) = 0;
110 virtual void BeginDrawingFrame(DrawingFrame* frame) = 0;
111 virtual void FinishDrawingFrame(DrawingFrame* frame) = 0;
112 virtual void FinishDrawingQuadList();
113 virtual bool FlippedFramebuffer() const = 0;
114 virtual void EnsureScissorTestEnabled() = 0;
115 virtual void EnsureScissorTestDisabled() = 0;
116 virtual void DiscardBackbuffer() {}
117 virtual void EnsureBackbuffer() {}
119 virtual void CopyCurrentRenderPassToBitmap(
120 DrawingFrame* frame,
121 scoped_ptr<CopyOutputRequest> request) = 0;
123 ScopedPtrHashMap<RenderPass::Id, CachedResource> render_pass_textures_;
124 OutputSurface* output_surface_;
125 ResourceProvider* resource_provider_;
127 // For use in coordinate conversion, this stores the output rect, viewport
128 // rect (= unflipped version of glViewport rect), and the size of target
129 // framebuffer. During a draw, this stores the values for the current render
130 // pass; in between draws, they retain the values for the root render pass of
131 // the last draw.
132 gfx::Rect current_draw_rect_;
133 gfx::Rect current_viewport_rect_;
134 gfx::Size current_surface_size_;
136 private:
137 gfx::Vector2d enlarge_pass_texture_amount_;
139 DISALLOW_COPY_AND_ASSIGN(DirectRenderer);
142 } // namespace cc
144 #endif // CC_OUTPUT_DIRECT_RENDERER_H_