Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: content/renderer/android/synchronous_compositor_output_surface.cc

Issue 16119003: Move SynchronousCompositor into content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment, check Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013 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.
4
5 #include "content/renderer/android/synchronous_compositor_output_surface.h"
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/time.h"
10 #include "cc/output/compositor_frame.h"
11 #include "cc/output/compositor_frame_ack.h"
12 #include "cc/output/output_surface_client.h"
13 #include "cc/output/software_output_device.h"
14 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
15 #include "content/public/common/content_switches.h"
16 #include "content/public/renderer/android/synchronous_compositor_client.h"
17 #include "content/public/renderer/content_renderer_client.h"
18 #include "skia/ext/refptr.h"
19 #include "third_party/skia/include/core/SkCanvas.h"
20 #include "third_party/skia/include/core/SkDevice.h"
21 #include "third_party/skia/include/core/SkPicture.h"
22 #include "ui/gfx/rect_conversions.h"
23 #include "ui/gfx/skia_util.h"
24 #include "ui/gfx/transform.h"
25 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
26
27 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
28
29 namespace content {
30
31 namespace {
32
33 // TODO(boliu): RenderThreadImpl should create in process contexts as well.
34 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() {
35 if (!CommandLine::ForCurrentProcess()->HasSwitch("testing-webview-gl-mode"))
36 return scoped_ptr<WebKit::WebGraphicsContext3D>();
37
38 WebKit::WebGraphicsContext3D::Attributes attributes;
39 attributes.antialias = false;
40 attributes.shareResources = true;
41 attributes.noAutomaticFlushes = true;
42
43 return scoped_ptr<WebKit::WebGraphicsContext3D>(
44 WebGraphicsContext3DInProcessCommandBufferImpl
45 ::CreateViewContext(attributes, NULL));
46 }
47
48 } // namespace
49
50 class SynchronousCompositorOutputSurface::SoftwareDevice
51 : public cc::SoftwareOutputDevice {
52 public:
53 SoftwareDevice(SynchronousCompositorOutputSurface* surface)
54 : surface_(surface),
55 null_device_(SkBitmap::kARGB_8888_Config, 1, 1),
56 null_canvas_(&null_device_) {
57 }
58 virtual void Resize(gfx::Size size) OVERRIDE {
59 // Intentional no-op: canvas size is controlled by the embedder.
60 }
61 virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE {
62 DCHECK(surface_->current_sw_canvas_);
63 if (surface_->current_sw_canvas_)
64 return surface_->current_sw_canvas_;
65 return &null_canvas_;
66 }
67 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE {
68 surface_->current_sw_canvas_ = NULL;
69 }
70 virtual void CopyToBitmap(gfx::Rect rect, SkBitmap* output) OVERRIDE {
71 NOTIMPLEMENTED();
72 }
73 virtual void Scroll(gfx::Vector2d delta,
74 gfx::Rect clip_rect) OVERRIDE {
75 NOTIMPLEMENTED();
76 }
77 virtual void ReclaimDIB(const TransportDIB::Id& id) OVERRIDE {
78 NOTIMPLEMENTED();
79 }
80
81 private:
82 SynchronousCompositorOutputSurface* surface_;
83 SkDevice null_device_;
84 SkCanvas null_canvas_;
85
86 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice);
87 };
88
89 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface(
90 int32 routing_id)
91 : cc::OutputSurface(CreateWebGraphicsContext3D(),
92 scoped_ptr<cc::SoftwareOutputDevice>(
93 new SoftwareDevice(this))),
94 compositor_client_(NULL),
95 routing_id_(routing_id),
96 needs_begin_frame_(false),
97 did_swap_buffer_(false),
98 current_sw_canvas_(NULL) {
99 capabilities_.deferred_gl_initialization = true;
100 }
101
102 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {
103 DCHECK(CalledOnValidThread());
104 if (compositor_client_)
105 compositor_client_->DidDestroyCompositor(this);
106 }
107
108 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const {
109 return current_sw_canvas_ != NULL;
110 }
111
112 bool SynchronousCompositorOutputSurface::BindToClient(
113 cc::OutputSurfaceClient* surface_client) {
114 DCHECK(CalledOnValidThread());
115 if (!cc::OutputSurface::BindToClient(surface_client))
116 return false;
117 GetContentClient()->renderer()->DidCreateSynchronousCompositor(routing_id_,
118 this);
119 return true;
120 }
121
122 void SynchronousCompositorOutputSurface::Reshape(
123 gfx::Size size, float scale_factor) {
124 // Intentional no-op: surface size is controlled by the embedder.
125 }
126
127 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor(
128 cc::CompositorFrame* frame) {
129 NOTREACHED();
130 // TODO(joth): Route page scale to the client, see http://crbug.com/237006
131 }
132
133 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame(
134 bool enable) {
135 DCHECK(CalledOnValidThread());
136 needs_begin_frame_ = enable;
137 UpdateCompositorClientSettings();
138 }
139
140 void SynchronousCompositorOutputSurface::SwapBuffers(
141 const ui::LatencyInfo& info) {
142 context3d()->shallowFlushCHROMIUM();
143 did_swap_buffer_ = true;
144 }
145
146 void SynchronousCompositorOutputSurface::SetClient(
147 SynchronousCompositorClient* compositor_client) {
148 DCHECK(CalledOnValidThread());
149 compositor_client_ = compositor_client;
150 UpdateCompositorClientSettings();
151 }
152
153 bool SynchronousCompositorOutputSurface::IsHwReady() {
154 return context3d() != NULL;
155 }
156
157 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
158 DCHECK(CalledOnValidThread());
159 DCHECK(canvas);
160 DCHECK(!current_sw_canvas_);
161 current_sw_canvas_ = canvas;
162
163 SkRect canvas_clip;
164 gfx::Rect damage_area;
165 if (canvas->getClipBounds(&canvas_clip)) {
166 damage_area = gfx::ToEnclosedRect(gfx::SkRectToRectF(canvas_clip));
167 } else {
168 damage_area = gfx::Rect(kint16max, kint16max);
169 }
170
171 gfx::Transform transform;
172 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
173
174 InvokeComposite(transform, damage_area);
175
176 bool finished_draw = current_sw_canvas_ == NULL;
177 current_sw_canvas_ = NULL;
178 return finished_draw;
179 }
180
181 bool SynchronousCompositorOutputSurface::DemandDrawHw(
182 gfx::Size view_size,
183 const gfx::Transform& transform,
184 gfx::Rect damage_area) {
185 DCHECK(CalledOnValidThread());
186 DCHECK(client_);
187
188 did_swap_buffer_ = false;
189
190 InvokeComposite(transform, damage_area);
191
192 return did_swap_buffer_;
193 }
194
195 void SynchronousCompositorOutputSurface::InvokeComposite(
196 const gfx::Transform& transform,
197 gfx::Rect damage_area) {
198 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the
199 // whole view. Tracking bug to implement this: crbug.com/230463.
200 client_->SetNeedsRedrawRect(damage_area);
201 if (needs_begin_frame_)
202 client_->BeginFrame(base::TimeTicks::Now());
203 }
204
205 void SynchronousCompositorOutputSurface::UpdateCompositorClientSettings() {
206 if (compositor_client_) {
207 compositor_client_->SetContinuousInvalidate(needs_begin_frame_);
208 }
209 }
210
211 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
212 // requirement: SynchronousCompositorOutputSurface() must only be used by
213 // embedders that supply their own compositor loop via
214 // OverrideCompositorMessageLoop().
215 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
216 return base::MessageLoop::current() && (base::MessageLoop::current() ==
217 GetContentClient()->renderer()->OverrideCompositorMessageLoop());
218 }
219
220 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/android/synchronous_compositor_output_surface.h ('k') | content/renderer/render_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698