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

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

Issue 1782093002: Move fallback tick handling to compositor thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/renderer/android/synchronous_compositor_output_surface.h" 5 #include "content/renderer/android/synchronous_compositor_output_surface.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 "base/macros.h" 9 #include "base/macros.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/renderer/android/synchronous_compositor_external_begin_frame_s ource.h" 14 #include "content/renderer/android/synchronous_compositor_external_begin_frame_s ource.h"
15 #include "content/renderer/android/synchronous_compositor_registry.h" 15 #include "content/renderer/android/synchronous_compositor_registry.h"
16 #include "content/renderer/gpu/frame_swap_message_queue.h" 16 #include "content/renderer/gpu/frame_swap_message_queue.h"
17 #include "gpu/command_buffer/client/context_support.h" 17 #include "gpu/command_buffer/client/context_support.h"
18 #include "gpu/command_buffer/client/gles2_interface.h" 18 #include "gpu/command_buffer/client/gles2_interface.h"
19 #include "gpu/command_buffer/common/gpu_memory_allocation.h" 19 #include "gpu/command_buffer/common/gpu_memory_allocation.h"
20 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkCanvas.h"
21 #include "ui/gfx/geometry/rect_conversions.h" 21 #include "ui/gfx/geometry/rect_conversions.h"
22 #include "ui/gfx/skia_util.h" 22 #include "ui/gfx/skia_util.h"
23 #include "ui/gfx/transform.h" 23 #include "ui/gfx/transform.h"
24 24
25 namespace content { 25 namespace content {
26 26
27 namespace { 27 namespace {
28 28
29 const int64_t kFallbackTickTimeoutInMilliseconds = 100;
30
29 // Do not limit number of resources, so use an unrealistically high value. 31 // Do not limit number of resources, so use an unrealistically high value.
30 const size_t kNumResourcesLimit = 10 * 1000 * 1000; 32 const size_t kNumResourcesLimit = 10 * 1000 * 1000;
31 33
32 } // namespace 34 } // namespace
33 35
34 class SynchronousCompositorOutputSurface::SoftwareDevice 36 class SynchronousCompositorOutputSurface::SoftwareDevice
35 : public cc::SoftwareOutputDevice { 37 : public cc::SoftwareOutputDevice {
36 public: 38 public:
37 SoftwareDevice(SynchronousCompositorOutputSurface* surface) 39 SoftwareDevice(SynchronousCompositorOutputSurface* surface)
38 : surface_(surface) { 40 : surface_(surface) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 127
126 void SynchronousCompositorOutputSurface::SwapBuffers( 128 void SynchronousCompositorOutputSurface::SwapBuffers(
127 cc::CompositorFrame* frame) { 129 cc::CompositorFrame* frame) {
128 DCHECK(CalledOnValidThread()); 130 DCHECK(CalledOnValidThread());
129 DCHECK(sync_client_); 131 DCHECK(sync_client_);
130 sync_client_->SwapBuffers(frame); 132 sync_client_->SwapBuffers(frame);
131 client_->DidSwapBuffers(); 133 client_->DidSwapBuffers();
132 did_swap_ = true; 134 did_swap_ = true;
133 } 135 }
134 136
137 void SynchronousCompositorOutputSurface::FallbackTickFired() {
boliu 2016/03/11 17:43:09 DCHECK(CalledOnValidThread());
Tobias Sargeant 2016/03/14 13:11:03 Done.
138 TRACE_EVENT0("android_webview",
boliu 2016/03/11 17:43:09 change category to "renderer"
Tobias Sargeant 2016/03/14 13:11:03 Done.
139 "SynchronousCompositorOutputSurface::FallbackTickFired");
140 SkBitmap bitmap;
141 bitmap.allocN32Pixels(1, 1);
142 bitmap.eraseColor(0);
143 SkCanvas canvas(bitmap);
144 DemandDrawSw(&canvas);
145 }
146
135 void SynchronousCompositorOutputSurface::Invalidate() { 147 void SynchronousCompositorOutputSurface::Invalidate() {
136 DCHECK(CalledOnValidThread()); 148 DCHECK(CalledOnValidThread());
137 if (sync_client_) 149 if (sync_client_)
138 sync_client_->Invalidate(); 150 sync_client_->Invalidate();
151
152 fallback_tick_.Reset(
boliu 2016/03/11 17:43:09 Need to check if fallback tick is already pending,
Tobias Sargeant 2016/03/14 13:11:03 Done.
153 base::Bind(&SynchronousCompositorOutputSurface::FallbackTickFired,
154 base::Unretained(this)));
155 base::MessageLoop::current()->PostDelayedTask(
156 FROM_HERE, fallback_tick_.callback(),
157 base::TimeDelta::FromMilliseconds(kFallbackTickTimeoutInMilliseconds));
139 } 158 }
140 159
141 void SynchronousCompositorOutputSurface::DemandDrawHw( 160 void SynchronousCompositorOutputSurface::DemandDrawHw(
142 const gfx::Size& surface_size, 161 const gfx::Size& surface_size,
143 const gfx::Transform& transform, 162 const gfx::Transform& transform,
144 const gfx::Rect& viewport, 163 const gfx::Rect& viewport,
145 const gfx::Rect& clip, 164 const gfx::Rect& clip,
146 const gfx::Rect& viewport_rect_for_tile_priority, 165 const gfx::Rect& viewport_rect_for_tile_priority,
147 const gfx::Transform& transform_for_tile_priority) { 166 const gfx::Transform& transform_for_tile_priority) {
148 DCHECK(CalledOnValidThread()); 167 DCHECK(CalledOnValidThread());
149 DCHECK(HasClient()); 168 DCHECK(HasClient());
150 DCHECK(context_provider_.get()); 169 DCHECK(context_provider_.get());
170 fallback_tick_.Cancel();
151 171
152 surface_size_ = surface_size; 172 surface_size_ = surface_size;
153 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, 173 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority,
154 transform_for_tile_priority); 174 transform_for_tile_priority);
155 const bool software_draw = false; 175 const bool software_draw = false;
156 InvokeComposite(transform, viewport, clip, software_draw); 176 InvokeComposite(transform, viewport, clip, software_draw);
157 } 177 }
158 178
159 void SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 179 void SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
160 DCHECK(CalledOnValidThread()); 180 DCHECK(CalledOnValidThread());
161 DCHECK(canvas); 181 DCHECK(canvas);
162 DCHECK(!current_sw_canvas_); 182 DCHECK(!current_sw_canvas_);
183 fallback_tick_.Cancel();
163 184
164 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas); 185 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
165 186
166 SkIRect canvas_clip; 187 SkIRect canvas_clip;
167 canvas->getClipDeviceBounds(&canvas_clip); 188 canvas->getClipDeviceBounds(&canvas_clip);
168 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); 189 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip);
169 190
170 gfx::Transform transform(gfx::Transform::kSkipInitialization); 191 gfx::Transform transform(gfx::Transform::kSkipInitialization);
171 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 192 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
172 193
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = 250 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope =
230 frame_swap_message_queue_->AcquireSendMessageScope(); 251 frame_swap_message_queue_->AcquireSendMessageScope();
231 frame_swap_message_queue_->DrainMessages(messages); 252 frame_swap_message_queue_->DrainMessages(messages);
232 } 253 }
233 254
234 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 255 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
235 return thread_checker_.CalledOnValidThread(); 256 return thread_checker_.CalledOnValidThread();
236 } 257 }
237 258
238 } // namespace content 259 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698