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

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_output_surface.cc

Issue 17553012: Force spontaneous draws into the SW path (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: boliu comments 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
« no previous file with comments | « content/browser/android/in_process/synchronous_compositor_output_surface.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/android/in_process/synchronous_compositor_output_surfa ce.h" 5 #include "content/browser/android/in_process/synchronous_compositor_output_surfa ce.h"
6 6
7 #include "base/command_line.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/time.h"
10 #include "cc/output/begin_frame_args.h" 9 #include "cc/output/begin_frame_args.h"
11 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
12 #include "cc/output/compositor_frame_ack.h"
13 #include "cc/output/context_provider.h" 11 #include "cc/output/context_provider.h"
14 #include "cc/output/output_surface_client.h" 12 #include "cc/output/output_surface_client.h"
15 #include "cc/output/software_output_device.h" 13 #include "cc/output/software_output_device.h"
16 #include "content/browser/android/in_process/synchronous_compositor_impl.h" 14 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
17 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 15 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
18 #include "content/public/browser/android/synchronous_compositor_client.h"
19 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
20 #include "content/public/common/content_switches.h"
21 #include "skia/ext/refptr.h"
22 #include "third_party/skia/include/core/SkCanvas.h" 17 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkDevice.h" 18 #include "third_party/skia/include/core/SkDevice.h"
24 #include "third_party/skia/include/core/SkPicture.h"
25 #include "ui/gfx/rect_conversions.h" 19 #include "ui/gfx/rect_conversions.h"
26 #include "ui/gfx/skia_util.h" 20 #include "ui/gfx/skia_util.h"
27 #include "ui/gfx/transform.h" 21 #include "ui/gfx/transform.h"
28 #include "ui/gl/gl_context.h" 22 #include "ui/gl/gl_context.h"
29 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" 23 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
30 24
31 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl; 25 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
32 26
33 namespace content { 27 namespace content {
34 28
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 75
82 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); 76 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice);
83 }; 77 };
84 78
85 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( 79 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface(
86 int routing_id) 80 int routing_id)
87 : cc::OutputSurface( 81 : cc::OutputSurface(
88 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), 82 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))),
89 routing_id_(routing_id), 83 routing_id_(routing_id),
90 needs_begin_frame_(false), 84 needs_begin_frame_(false),
85 invoking_composite_(false),
91 did_swap_buffer_(false), 86 did_swap_buffer_(false),
92 current_sw_canvas_(NULL) { 87 current_sw_canvas_(NULL) {
93 capabilities_.deferred_gl_initialization = true; 88 capabilities_.deferred_gl_initialization = true;
94 capabilities_.adjust_deadline_for_parent = false; 89 capabilities_.adjust_deadline_for_parent = false;
95 // Cannot call out to GetDelegate() here as the output surface is not 90 // Cannot call out to GetDelegate() here as the output surface is not
96 // constructed on the correct thread. 91 // constructed on the correct thread.
97 } 92 }
98 93
99 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { 94 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {
100 DCHECK(CalledOnValidThread()); 95 DCHECK(CalledOnValidThread());
101 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); 96 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate();
102 if (delegate) 97 if (delegate)
103 delegate->DidDestroySynchronousOutputSurface(this); 98 delegate->DidDestroySynchronousOutputSurface(this);
104 } 99 }
105 100
106 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const { 101 bool SynchronousCompositorOutputSurface::ForcedDrawToSoftwareDevice() const {
107 return current_sw_canvas_ != NULL; 102 // |current_sw_canvas_| indicates we're in a DemandDrawSw call. In addition
103 // |invoking_composite_| == false indicates an attempt to draw outside of
104 // the synchronous compositor's control: force it into SW path and hence to
105 // the null canvas (and will log a warning there).
106 return current_sw_canvas_ != NULL || !invoking_composite_;
108 } 107 }
109 108
110 bool SynchronousCompositorOutputSurface::BindToClient( 109 bool SynchronousCompositorOutputSurface::BindToClient(
111 cc::OutputSurfaceClient* surface_client) { 110 cc::OutputSurfaceClient* surface_client) {
112 DCHECK(CalledOnValidThread()); 111 DCHECK(CalledOnValidThread());
113 if (!cc::OutputSurface::BindToClient(surface_client)) 112 if (!cc::OutputSurface::BindToClient(surface_client))
114 return false; 113 return false;
115 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); 114 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate();
116 if (delegate) 115 if (delegate)
117 delegate->DidBindOutputSurface(this); 116 delegate->DidBindOutputSurface(this);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 188
190 // TODO(boliu): Check if context is lost here. 189 // TODO(boliu): Check if context is lost here.
191 190
192 return did_swap_buffer_; 191 return did_swap_buffer_;
193 } 192 }
194 193
195 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 194 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
196 DCHECK(CalledOnValidThread()); 195 DCHECK(CalledOnValidThread());
197 DCHECK(canvas); 196 DCHECK(canvas);
198 DCHECK(!current_sw_canvas_); 197 DCHECK(!current_sw_canvas_);
199 current_sw_canvas_ = canvas; 198 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
200 199
201 SkIRect canvas_clip; 200 SkIRect canvas_clip;
202 canvas->getClipDeviceBounds(&canvas_clip); 201 canvas->getClipDeviceBounds(&canvas_clip);
203 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); 202 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip);
204 203
205 gfx::Transform transform(gfx::Transform::kSkipInitialization); 204 gfx::Transform transform(gfx::Transform::kSkipInitialization);
206 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 205 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
207 AdjustTransformForClip(&transform, clip); 206 AdjustTransformForClip(&transform, clip);
208 207
209 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), 208 surface_size_ = gfx::Size(canvas->getDeviceSize().width(),
210 canvas->getDeviceSize().height()); 209 canvas->getDeviceSize().height());
211 SetExternalDrawConstraints(transform, clip); 210 SetExternalDrawConstraints(transform, clip);
212 211
213 InvokeComposite(clip.size()); 212 InvokeComposite(clip.size());
214 213
215 current_sw_canvas_ = NULL;
216 return did_swap_buffer_; 214 return did_swap_buffer_;
217 } 215 }
218 216
219 void SynchronousCompositorOutputSurface::InvokeComposite( 217 void SynchronousCompositorOutputSurface::InvokeComposite(
220 gfx::Size damage_size) { 218 gfx::Size damage_size) {
219 DCHECK(!invoking_composite_);
220 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true);
221 did_swap_buffer_ = false; 221 did_swap_buffer_ = false;
222 SetNeedsRedrawRect(gfx::Rect(damage_size)); 222 SetNeedsRedrawRect(gfx::Rect(damage_size));
223 if (needs_begin_frame_) 223 if (needs_begin_frame_)
224 BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); 224 BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor());
225 225
226 if (did_swap_buffer_) 226 if (did_swap_buffer_)
227 OnSwapBuffersComplete(NULL); 227 OnSwapBuffersComplete(NULL);
228 } 228 }
229 229
230 void SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginFrame() { 230 void SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginFrame() {
231 // Synchronous compositor cannot perform retroactive begin frames, so 231 // Synchronous compositor cannot perform retroactive begin frames, so
232 // intentionally no-op here. 232 // intentionally no-op here.
233 } 233 }
234 234
235 // Not using base::NonThreadSafe as we want to enforce a more exacting threading 235 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
236 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI 236 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI
237 // thread. 237 // thread.
238 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 238 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
239 return BrowserThread::CurrentlyOn(BrowserThread::UI); 239 return BrowserThread::CurrentlyOn(BrowserThread::UI);
240 } 240 }
241 241
242 SynchronousCompositorOutputSurfaceDelegate* 242 SynchronousCompositorOutputSurfaceDelegate*
243 SynchronousCompositorOutputSurface::GetDelegate() { 243 SynchronousCompositorOutputSurface::GetDelegate() {
244 return SynchronousCompositorImpl::FromRoutingID(routing_id_); 244 return SynchronousCompositorImpl::FromRoutingID(routing_id_);
245 } 245 }
246 246
247 } // namespace content 247 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/android/in_process/synchronous_compositor_output_surface.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698