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

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

Issue 23171014: Fix UpdateTilePriorities viewport in Android WebView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to 221292 Created 7 years, 3 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
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"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 179 }
180 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); 180 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate();
181 if (delegate) 181 if (delegate)
182 delegate->UpdateFrameMetaData(frame->metadata); 182 delegate->UpdateFrameMetaData(frame->metadata);
183 183
184 did_swap_buffer_ = true; 184 did_swap_buffer_ = true;
185 DidSwapBuffers(); 185 DidSwapBuffers();
186 } 186 }
187 187
188 namespace { 188 namespace {
189 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { 189 void AdjustTransform(gfx::Transform* transform, gfx::Rect viewport) {
190 // The system-provided transform translates us from the screen origin to the 190 // CC's draw origin starts at the viewport.
191 // origin of the clip rect, but CC's draw origin starts at the clip. 191 transform->matrix().postTranslate(-viewport.x(), -viewport.y(), 0);
192 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0);
193 } 192 }
194 } // namespace 193 } // namespace
195 194
196 bool SynchronousCompositorOutputSurface::InitializeHwDraw( 195 bool SynchronousCompositorOutputSurface::InitializeHwDraw(
197 scoped_refptr<gfx::GLSurface> surface, 196 scoped_refptr<gfx::GLSurface> surface,
198 scoped_refptr<cc::ContextProvider> offscreen_context_provider) { 197 scoped_refptr<cc::ContextProvider> offscreen_context_provider) {
199 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
200 DCHECK(HasClient()); 199 DCHECK(HasClient());
201 DCHECK(!context_provider_); 200 DCHECK(!context_provider_);
202 DCHECK(surface); 201 DCHECK(surface);
203 202
204 scoped_refptr<cc::ContextProvider> onscreen_context_provider = 203 scoped_refptr<cc::ContextProvider> onscreen_context_provider =
205 webkit::gpu::ContextProviderInProcess::Create( 204 webkit::gpu::ContextProviderInProcess::Create(
206 CreateWebGraphicsContext3D(surface)); 205 CreateWebGraphicsContext3D(surface));
207 return InitializeAndSetContext3d(onscreen_context_provider, 206 return InitializeAndSetContext3d(onscreen_context_provider,
208 offscreen_context_provider); 207 offscreen_context_provider);
209 } 208 }
210 209
211 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { 210 void SynchronousCompositorOutputSurface::ReleaseHwDraw() {
212 cc::OutputSurface::ReleaseGL(); 211 cc::OutputSurface::ReleaseGL();
213 } 212 }
214 213
215 bool SynchronousCompositorOutputSurface::DemandDrawHw( 214 bool SynchronousCompositorOutputSurface::DemandDrawHw(
216 gfx::Size surface_size, 215 gfx::Size surface_size,
217 const gfx::Transform& transform, 216 const gfx::Transform& transform,
217 gfx::Rect viewport,
218 gfx::Rect clip, 218 gfx::Rect clip,
219 bool stencil_enabled) { 219 bool stencil_enabled) {
220 DCHECK(CalledOnValidThread()); 220 DCHECK(CalledOnValidThread());
221 DCHECK(HasClient()); 221 DCHECK(HasClient());
222 DCHECK(context_provider_); 222 DCHECK(context_provider_);
223 223
224 gfx::Transform adjusted_transform = transform;
225 AdjustTransformForClip(&adjusted_transform, clip);
226 surface_size_ = surface_size; 224 surface_size_ = surface_size;
227 SetExternalDrawConstraints(adjusted_transform, clip);
228 SetExternalStencilTest(stencil_enabled); 225 SetExternalStencilTest(stencil_enabled);
229 InvokeComposite(clip.size()); 226 InvokeComposite(transform, viewport, clip, true);
230 227
231 return did_swap_buffer_; 228 return did_swap_buffer_;
232 } 229 }
233 230
234 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 231 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
235 DCHECK(CalledOnValidThread()); 232 DCHECK(CalledOnValidThread());
236 DCHECK(canvas); 233 DCHECK(canvas);
237 DCHECK(!current_sw_canvas_); 234 DCHECK(!current_sw_canvas_);
238 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas); 235 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
239 236
240 SkIRect canvas_clip; 237 SkIRect canvas_clip;
241 canvas->getClipDeviceBounds(&canvas_clip); 238 canvas->getClipDeviceBounds(&canvas_clip);
242 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); 239 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip);
243 240
244 gfx::Transform transform(gfx::Transform::kSkipInitialization); 241 gfx::Transform transform(gfx::Transform::kSkipInitialization);
245 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 242 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
246 AdjustTransformForClip(&transform, clip);
247 243
248 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), 244 surface_size_ = gfx::Size(canvas->getDeviceSize().width(),
249 canvas->getDeviceSize().height()); 245 canvas->getDeviceSize().height());
250 SetExternalDrawConstraints(transform, clip);
251 SetExternalStencilTest(false); 246 SetExternalStencilTest(false);
252 247
253 InvokeComposite(clip.size()); 248 InvokeComposite(transform, clip, clip, false);
254 249
255 return did_swap_buffer_; 250 return did_swap_buffer_;
256 } 251 }
257 252
258 void SynchronousCompositorOutputSurface::InvokeComposite( 253 void SynchronousCompositorOutputSurface::InvokeComposite(
259 gfx::Size damage_size) { 254 const gfx::Transform& transform,
255 gfx::Rect viewport,
256 gfx::Rect clip,
257 bool valid_for_tile_management) {
260 DCHECK(!invoking_composite_); 258 DCHECK(!invoking_composite_);
261 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true); 259 base::AutoReset<bool> invoking_composite_resetter(&invoking_composite_, true);
262 did_swap_buffer_ = false; 260 did_swap_buffer_ = false;
263 SetNeedsRedrawRect(gfx::Rect(damage_size)); 261
262 gfx::Transform adjusted_transform = transform;
263 AdjustTransform(&adjusted_transform, viewport);
264 SetExternalDrawConstraints(
265 adjusted_transform, viewport, clip, valid_for_tile_management);
266 SetNeedsRedrawRect(gfx::Rect(viewport.size()));
267
264 if (needs_begin_frame_) 268 if (needs_begin_frame_)
265 BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor()); 269 BeginFrame(cc::BeginFrameArgs::CreateForSynchronousCompositor());
266 270
271 // After software draws (which might move the viewport arbitrarily), restore
272 // the previous hardware viewport to allow CC's tile manager to prioritize
273 // properly.
274 if (valid_for_tile_management) {
275 cached_hw_transform_ = adjusted_transform;
276 cached_hw_viewport_ = viewport;
277 cached_hw_clip_ = clip;
278 } else {
279 SetExternalDrawConstraints(
280 cached_hw_transform_, cached_hw_viewport_, cached_hw_clip_, true);
281 }
282
267 if (did_swap_buffer_) 283 if (did_swap_buffer_)
268 OnSwapBuffersComplete(NULL); 284 OnSwapBuffersComplete(NULL);
269 } 285 }
270 286
271 void SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginFrame() { 287 void SynchronousCompositorOutputSurface::PostCheckForRetroactiveBeginFrame() {
272 // Synchronous compositor cannot perform retroactive begin frames, so 288 // Synchronous compositor cannot perform retroactive begin frames, so
273 // intentionally no-op here. 289 // intentionally no-op here.
274 } 290 }
275 291
276 // Not using base::NonThreadSafe as we want to enforce a more exacting threading 292 // Not using base::NonThreadSafe as we want to enforce a more exacting threading
277 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI 293 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI
278 // thread. 294 // thread.
279 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 295 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
280 return BrowserThread::CurrentlyOn(BrowserThread::UI); 296 return BrowserThread::CurrentlyOn(BrowserThread::UI);
281 } 297 }
282 298
283 SynchronousCompositorOutputSurfaceDelegate* 299 SynchronousCompositorOutputSurfaceDelegate*
284 SynchronousCompositorOutputSurface::GetDelegate() { 300 SynchronousCompositorOutputSurface::GetDelegate() {
285 return SynchronousCompositorImpl::FromRoutingID(routing_id_); 301 return SynchronousCompositorImpl::FromRoutingID(routing_id_);
286 } 302 }
287 303
288 } // namespace content 304 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698