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

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

Issue 287993004: [Android WebView] Implement Ubercomp for Render Thread support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 6 years, 7 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
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/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "cc/output/begin_frame_args.h" 9 #include "cc/output/begin_frame_args.h"
10 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
11 #include "cc/output/context_provider.h" 11 #include "cc/output/context_provider.h"
12 #include "cc/output/output_surface_client.h" 12 #include "cc/output/output_surface_client.h"
13 #include "cc/output/software_output_device.h" 13 #include "cc/output/software_output_device.h"
14 #include "content/browser/android/in_process/synchronous_compositor_impl.h" 14 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
15 #include "content/browser/gpu/compositor_util.h"
15 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
16 #include "gpu/command_buffer/client/gles2_interface.h" 17 #include "gpu/command_buffer/client/gles2_interface.h"
17 #include "gpu/command_buffer/common/gpu_memory_allocation.h" 18 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
18 #include "third_party/skia/include/core/SkCanvas.h" 19 #include "third_party/skia/include/core/SkCanvas.h"
19 #include "ui/gfx/rect_conversions.h" 20 #include "ui/gfx/rect_conversions.h"
20 #include "ui/gfx/skia_util.h" 21 #include "ui/gfx/skia_util.h"
21 #include "ui/gfx/transform.h" 22 #include "ui/gfx/transform.h"
22 23
23 namespace content { 24 namespace content {
24 25
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( 68 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface(
68 int routing_id) 69 int routing_id)
69 : cc::OutputSurface( 70 : cc::OutputSurface(
70 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), 71 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))),
71 routing_id_(routing_id), 72 routing_id_(routing_id),
72 needs_begin_frame_(false), 73 needs_begin_frame_(false),
73 invoking_composite_(false), 74 invoking_composite_(false),
74 did_swap_buffer_(false), 75 did_swap_buffer_(false),
75 current_sw_canvas_(NULL), 76 current_sw_canvas_(NULL),
76 memory_policy_(0), 77 memory_policy_(0),
77 output_surface_client_(NULL), 78 output_surface_client_(NULL) {
78 weak_ptr_factory_(this) {
79 capabilities_.deferred_gl_initialization = true; 79 capabilities_.deferred_gl_initialization = true;
80 capabilities_.draw_and_swap_full_viewport_every_frame = true; 80 capabilities_.draw_and_swap_full_viewport_every_frame = true;
danakj 2014/05/20 21:50:02 Is this still needed here then? The browser side i
boliu 2014/05/21 01:33:26 Still needed for software path, which child compos
81 capabilities_.adjust_deadline_for_parent = false; 81 capabilities_.adjust_deadline_for_parent = false;
danakj 2014/05/20 21:50:02 Still needed?
boliu 2014/05/21 19:58:22 Yes. This is to avoid enabling part of the deadlin
danakj 2014/05/21 20:01:01 This is true for the browser compositor, but is th
boliu 2014/05/21 20:12:20 This renderer compositor still needs to be synchro
danakj 2014/05/21 20:13:39 Oh ok. Ya, I bumped into onDraw in the removal of
82 if (IsDelegatedRendererEnabled()) {
83 capabilities_.delegated_rendering = true;
84 capabilities_.max_frames_pending = 1;
85 }
82 // Cannot call out to GetDelegate() here as the output surface is not 86 // Cannot call out to GetDelegate() here as the output surface is not
83 // constructed on the correct thread. 87 // constructed on the correct thread.
84 88
85 memory_policy_.priority_cutoff_when_visible = 89 memory_policy_.priority_cutoff_when_visible =
86 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; 90 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
87 } 91 }
88 92
89 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() { 93 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {
90 DCHECK(CalledOnValidThread()); 94 DCHECK(CalledOnValidThread());
91 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); 95 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 delegate->SetContinuousInvalidate(needs_begin_frame_); 136 delegate->SetContinuousInvalidate(needs_begin_frame_);
133 } 137 }
134 138
135 void SynchronousCompositorOutputSurface::SwapBuffers( 139 void SynchronousCompositorOutputSurface::SwapBuffers(
136 cc::CompositorFrame* frame) { 140 cc::CompositorFrame* frame) {
137 DCHECK(CalledOnValidThread()); 141 DCHECK(CalledOnValidThread());
138 if (!ForcedDrawToSoftwareDevice()) { 142 if (!ForcedDrawToSoftwareDevice()) {
139 DCHECK(context_provider_); 143 DCHECK(context_provider_);
140 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); 144 context_provider_->ContextGL()->ShallowFlushCHROMIUM();
141 } 145 }
142 UpdateFrameMetaData(frame->metadata); 146
147 DCHECK(frame_);
148 frame->AssignTo(frame_);
143 149
144 did_swap_buffer_ = true; 150 did_swap_buffer_ = true;
145 client_->DidSwapBuffers(); 151 client_->DidSwapBuffers();
146 } 152 }
147 153
148 void SynchronousCompositorOutputSurface::UpdateFrameMetaData(
149 const cc::CompositorFrameMetadata& frame_info) {
150 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
151 BrowserThread::PostTask(
152 BrowserThread::UI,
153 FROM_HERE,
154 base::Bind(&SynchronousCompositorOutputSurface::UpdateFrameMetaData,
155 weak_ptr_factory_.GetWeakPtr(),
156 frame_info));
157 return;
158 }
159
160 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate();
161 if (delegate)
162 delegate->UpdateFrameMetaData(frame_info);
163 }
164
165 namespace { 154 namespace {
166 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) { 155 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) {
167 // CC's draw origin starts at the viewport. 156 // CC's draw origin starts at the viewport.
168 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0); 157 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0);
169 } 158 }
170 } // namespace 159 } // namespace
171 160
172 bool SynchronousCompositorOutputSurface::InitializeHwDraw( 161 bool SynchronousCompositorOutputSurface::InitializeHwDraw(
173 scoped_refptr<cc::ContextProvider> onscreen_context_provider) { 162 scoped_refptr<cc::ContextProvider> onscreen_context_provider) {
174 DCHECK(CalledOnValidThread()); 163 DCHECK(CalledOnValidThread());
175 DCHECK(HasClient()); 164 DCHECK(HasClient());
176 DCHECK(!context_provider_); 165 DCHECK(!context_provider_);
177 166
178 return InitializeAndSetContext3d(onscreen_context_provider); 167 return InitializeAndSetContext3d(onscreen_context_provider);
179 } 168 }
180 169
181 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { 170 void SynchronousCompositorOutputSurface::ReleaseHwDraw() {
182 DCHECK(CalledOnValidThread()); 171 DCHECK(CalledOnValidThread());
183 cc::OutputSurface::ReleaseGL(); 172 cc::OutputSurface::ReleaseGL();
184 } 173 }
185 174
186 bool SynchronousCompositorOutputSurface::DemandDrawHw( 175 bool SynchronousCompositorOutputSurface::DemandDrawHw(
187 gfx::Size surface_size, 176 gfx::Size surface_size,
188 const gfx::Transform& transform, 177 const gfx::Transform& transform,
189 gfx::Rect viewport, 178 gfx::Rect viewport,
190 gfx::Rect clip, 179 gfx::Rect clip,
191 bool stencil_enabled) { 180 bool stencil_enabled,
181 cc::CompositorFrame* frame) {
danakj 2014/05/20 21:50:02 It feels a bit awkward to be passing in a Composit
192 DCHECK(CalledOnValidThread()); 182 DCHECK(CalledOnValidThread());
193 DCHECK(HasClient()); 183 DCHECK(HasClient());
194 DCHECK(context_provider_); 184 DCHECK(context_provider_);
195 185
186 base::AutoReset<cc::CompositorFrame*> frame_resetter(&frame_, frame);
196 surface_size_ = surface_size; 187 surface_size_ = surface_size;
197 SetExternalStencilTest(stencil_enabled); 188 SetExternalStencilTest(stencil_enabled);
198 InvokeComposite(transform, viewport, clip, true); 189 InvokeComposite(transform, viewport, clip, true);
199 190
200 return did_swap_buffer_; 191 return did_swap_buffer_;
201 } 192 }
202 193
203 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 194 bool SynchronousCompositorOutputSurface::DemandDrawSw(
195 SkCanvas* canvas,
196 cc::CompositorFrame* frame) {
204 DCHECK(CalledOnValidThread()); 197 DCHECK(CalledOnValidThread());
205 DCHECK(canvas); 198 DCHECK(canvas);
206 DCHECK(!current_sw_canvas_); 199 DCHECK(!current_sw_canvas_);
200 base::AutoReset<cc::CompositorFrame*> frame_resetter(&frame_, frame);
207 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas); 201 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
208 202
209 SkIRect canvas_clip; 203 SkIRect canvas_clip;
210 canvas->getClipDeviceBounds(&canvas_clip); 204 canvas->getClipDeviceBounds(&canvas_clip);
211 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); 205 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip);
212 206
213 gfx::Transform transform(gfx::Transform::kSkipInitialization); 207 gfx::Transform transform(gfx::Transform::kSkipInitialization);
214 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 208 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
215 209
216 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), 210 surface_size_ = gfx::Size(canvas->getDeviceSize().width(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 } 245 }
252 246
253 if (did_swap_buffer_) 247 if (did_swap_buffer_)
254 client_->DidSwapBuffersComplete(); 248 client_->DidSwapBuffersComplete();
255 249
256 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); 250 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate();
257 if (delegate) 251 if (delegate)
258 delegate->SetContinuousInvalidate(needs_begin_frame_); 252 delegate->SetContinuousInvalidate(needs_begin_frame_);
259 } 253 }
260 254
255 void SynchronousCompositorOutputSurface::ReturnResources(
256 const cc::CompositorFrameAck& frame_ack) {
257 ReclaimResources(&frame_ack);
258 }
259
261 void SynchronousCompositorOutputSurface::SetMemoryPolicy( 260 void SynchronousCompositorOutputSurface::SetMemoryPolicy(
262 const SynchronousCompositorMemoryPolicy& policy) { 261 const SynchronousCompositorMemoryPolicy& policy) {
263 DCHECK(CalledOnValidThread()); 262 DCHECK(CalledOnValidThread());
264 memory_policy_.bytes_limit_when_visible = policy.bytes_limit; 263 memory_policy_.bytes_limit_when_visible = policy.bytes_limit;
265 memory_policy_.num_resources_limit = policy.num_resources_limit; 264 memory_policy_.num_resources_limit = policy.num_resources_limit;
266 265
267 if (output_surface_client_) 266 if (output_surface_client_)
268 output_surface_client_->SetMemoryPolicy(memory_policy_); 267 output_surface_client_->SetMemoryPolicy(memory_policy_);
269 } 268 }
270 269
271 // Not using base::NonThreadSafe as we want to enforce a more exacting threading 270 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
272 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI 271 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI
273 // thread. 272 // thread.
274 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 273 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
275 return BrowserThread::CurrentlyOn(BrowserThread::UI); 274 return BrowserThread::CurrentlyOn(BrowserThread::UI);
276 } 275 }
277 276
278 SynchronousCompositorOutputSurfaceDelegate* 277 SynchronousCompositorOutputSurfaceDelegate*
279 SynchronousCompositorOutputSurface::GetDelegate() { 278 SynchronousCompositorOutputSurface::GetDelegate() {
280 return SynchronousCompositorImpl::FromRoutingID(routing_id_); 279 return SynchronousCompositorImpl::FromRoutingID(routing_id_);
281 } 280 }
282 281
283 } // namespace content 282 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698