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

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

Issue 2377533002: cc: Remove Display::SetExternalViewport. (Closed)
Patch Set: webview-expand-sw: rebase Created 4 years, 2 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
« no previous file with comments | « content/renderer/android/synchronous_compositor_frame_sink.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/renderer/android/synchronous_compositor_frame_sink.h" 5 #include "content/renderer/android/synchronous_compositor_frame_sink.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "cc/output/compositor_frame.h" 16 #include "cc/output/compositor_frame.h"
17 #include "cc/output/compositor_frame_sink_client.h" 17 #include "cc/output/compositor_frame_sink_client.h"
18 #include "cc/output/context_provider.h" 18 #include "cc/output/context_provider.h"
19 #include "cc/output/output_surface.h" 19 #include "cc/output/output_surface.h"
20 #include "cc/output/renderer_settings.h" 20 #include "cc/output/renderer_settings.h"
21 #include "cc/output/software_output_device.h" 21 #include "cc/output/software_output_device.h"
22 #include "cc/output/texture_mailbox_deleter.h" 22 #include "cc/output/texture_mailbox_deleter.h"
23 #include "cc/quads/render_pass.h"
24 #include "cc/quads/surface_draw_quad.h"
23 #include "cc/surfaces/display.h" 25 #include "cc/surfaces/display.h"
24 #include "cc/surfaces/surface_factory.h" 26 #include "cc/surfaces/surface_factory.h"
25 #include "cc/surfaces/surface_id_allocator.h" 27 #include "cc/surfaces/surface_id_allocator.h"
26 #include "cc/surfaces/surface_manager.h" 28 #include "cc/surfaces/surface_manager.h"
27 #include "content/common/android/sync_compositor_messages.h" 29 #include "content/common/android/sync_compositor_messages.h"
28 #include "content/renderer/android/synchronous_compositor_filter.h" 30 #include "content/renderer/android/synchronous_compositor_filter.h"
29 #include "content/renderer/android/synchronous_compositor_registry.h" 31 #include "content/renderer/android/synchronous_compositor_registry.h"
30 #include "content/renderer/gpu/frame_swap_message_queue.h" 32 #include "content/renderer/gpu/frame_swap_message_queue.h"
31 #include "content/renderer/render_thread_impl.h" 33 #include "content/renderer/render_thread_impl.h"
32 #include "gpu/command_buffer/client/context_support.h" 34 #include "gpu/command_buffer/client/context_support.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 81
80 // cc::OutputSurface implementation. 82 // cc::OutputSurface implementation.
81 void EnsureBackbuffer() override {} 83 void EnsureBackbuffer() override {}
82 void DiscardBackbuffer() override {} 84 void DiscardBackbuffer() override {}
83 void BindFramebuffer() override {} 85 void BindFramebuffer() override {}
84 void SwapBuffers(cc::CompositorFrame frame) override {} 86 void SwapBuffers(cc::CompositorFrame frame) override {}
85 void Reshape(const gfx::Size& size, 87 void Reshape(const gfx::Size& size,
86 float scale_factor, 88 float scale_factor,
87 const gfx::ColorSpace& color_space, 89 const gfx::ColorSpace& color_space,
88 bool has_alpha) override { 90 bool has_alpha) override {
89 // Intentional no-op. Surface size controlled by embedder. 91 surface_size_ = size;
90 } 92 }
91 uint32_t GetFramebufferCopyTextureFormat() override { return 0; } 93 uint32_t GetFramebufferCopyTextureFormat() override { return 0; }
92 cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override { 94 cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override {
93 return nullptr; 95 return nullptr;
94 } 96 }
95 bool IsDisplayedAsOverlayPlane() const override { return false; } 97 bool IsDisplayedAsOverlayPlane() const override { return false; }
96 unsigned GetOverlayTextureId() const override { return 0; } 98 unsigned GetOverlayTextureId() const override { return 0; }
97 bool SurfaceIsSuspendForRecycle() const override { return false; } 99 bool SurfaceIsSuspendForRecycle() const override { return false; }
98 bool HasExternalStencilTest() const override { return false; } 100 bool HasExternalStencilTest() const override { return false; }
99 void ApplyExternalStencil() override {} 101 void ApplyExternalStencil() override {}
100
101 void SetSurfaceSize(const gfx::Size surface_size) {
102 surface_size_ = surface_size;
103 }
104 }; 102 };
105 103
106 SynchronousCompositorFrameSink::SynchronousCompositorFrameSink( 104 SynchronousCompositorFrameSink::SynchronousCompositorFrameSink(
107 scoped_refptr<cc::ContextProvider> context_provider, 105 scoped_refptr<cc::ContextProvider> context_provider,
108 scoped_refptr<cc::ContextProvider> worker_context_provider, 106 scoped_refptr<cc::ContextProvider> worker_context_provider,
109 int routing_id, 107 int routing_id,
110 uint32_t compositor_frame_sink_id, 108 uint32_t compositor_frame_sink_id,
111 std::unique_ptr<cc::BeginFrameSource> begin_frame_source, 109 std::unique_ptr<cc::BeginFrameSource> begin_frame_source,
112 SynchronousCompositorRegistry* registry, 110 SynchronousCompositorRegistry* registry,
113 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) 111 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree, 164 base::Bind(&SynchronousCompositorFrameSink::DidActivatePendingTree,
167 base::Unretained(this))); 165 base::Unretained(this)));
168 registry_->RegisterCompositorFrameSink(routing_id_, this); 166 registry_->RegisterCompositorFrameSink(routing_id_, this);
169 registered_ = true; 167 registered_ = true;
170 168
171 surface_manager_->RegisterFrameSinkId(kFrameSinkId); 169 surface_manager_->RegisterFrameSinkId(kFrameSinkId);
172 surface_manager_->RegisterSurfaceFactoryClient(kFrameSinkId, this); 170 surface_manager_->RegisterSurfaceFactoryClient(kFrameSinkId, this);
173 171
174 cc::RendererSettings software_renderer_settings; 172 cc::RendererSettings software_renderer_settings;
175 173
176 std::unique_ptr<SoftwareOutputSurface> compositor_frame_sink( 174 auto output_surface = base::MakeUnique<SoftwareOutputSurface>(
177 new SoftwareOutputSurface( 175 base::MakeUnique<SoftwareDevice>(&current_sw_canvas_));
178 base::MakeUnique<SoftwareDevice>(&current_sw_canvas_))); 176 software_output_surface_ = output_surface.get();
179 software_compositor_frame_sink_ = compositor_frame_sink.get();
180 177
181 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as 178 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as
182 // this Display is only used for resourcesless software draws, where no 179 // this Display is only used for resourcesless software draws, where no
183 // resources are included in the frame swapped from the compositor. So there 180 // resources are included in the frame swapped from the compositor. So there
184 // is no need for these. 181 // is no need for these.
185 display_.reset(new cc::Display( 182 display_.reset(new cc::Display(
186 nullptr /* shared_bitmap_manager */, 183 nullptr /* shared_bitmap_manager */,
187 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, 184 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings,
188 nullptr /* begin_frame_source */, std::move(compositor_frame_sink), 185 nullptr /* begin_frame_source */, std::move(output_surface),
189 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); 186 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */));
190 display_->Initialize(&display_client_, surface_manager_.get(), kFrameSinkId); 187 display_->Initialize(&display_client_, surface_manager_.get(), kFrameSinkId);
191 display_->SetVisible(true); 188 display_->SetVisible(true);
192 return true; 189 return true;
193 } 190 }
194 191
195 void SynchronousCompositorFrameSink::DetachFromClient() { 192 void SynchronousCompositorFrameSink::DetachFromClient() {
196 DCHECK(CalledOnValidThread()); 193 DCHECK(CalledOnValidThread());
197 client_->SetBeginFrameSource(nullptr); 194 client_->SetBeginFrameSource(nullptr);
198 // Destroy the begin frame source on the same thread it was bound on. 195 // Destroy the begin frame source on the same thread it was bound on.
199 begin_frame_source_ = nullptr; 196 begin_frame_source_ = nullptr;
200 if (registered_) 197 if (registered_)
201 registry_->UnregisterCompositorFrameSink(routing_id_, this); 198 registry_->UnregisterCompositorFrameSink(routing_id_, this);
202 client_->SetTreeActivationCallback(base::Closure()); 199 client_->SetTreeActivationCallback(base::Closure());
203 if (!delegated_surface_id_.is_null()) 200 if (!root_surface_id_.is_null()) {
204 surface_factory_->Destroy(delegated_surface_id_); 201 surface_factory_->Destroy(root_surface_id_);
202 surface_factory_->Destroy(child_surface_id_);
203 }
205 surface_manager_->UnregisterSurfaceFactoryClient(kFrameSinkId); 204 surface_manager_->UnregisterSurfaceFactoryClient(kFrameSinkId);
206 surface_manager_->InvalidateFrameSinkId(kFrameSinkId); 205 surface_manager_->InvalidateFrameSinkId(kFrameSinkId);
207 software_compositor_frame_sink_ = nullptr; 206 software_output_surface_ = nullptr;
208 display_ = nullptr; 207 display_ = nullptr;
209 surface_factory_ = nullptr; 208 surface_factory_ = nullptr;
210 surface_id_allocator_ = nullptr; 209 surface_id_allocator_ = nullptr;
211 surface_manager_ = nullptr; 210 surface_manager_ = nullptr;
212 cc::CompositorFrameSink::DetachFromClient(); 211 cc::CompositorFrameSink::DetachFromClient();
213 CancelFallbackTick(); 212 CancelFallbackTick();
214 } 213 }
215 214
216 static void NoOpDrawCallback() {} 215 static void NoOpDrawCallback() {}
217 216
218 void SynchronousCompositorFrameSink::SwapBuffers(cc::CompositorFrame frame) { 217 void SynchronousCompositorFrameSink::SwapBuffers(cc::CompositorFrame frame) {
219 DCHECK(CalledOnValidThread()); 218 DCHECK(CalledOnValidThread());
220 DCHECK(sync_client_); 219 DCHECK(sync_client_);
221 220
222 if (fallback_tick_running_) { 221 if (fallback_tick_running_) {
223 DCHECK(frame.delegated_frame_data->resource_list.empty()); 222 DCHECK(frame.delegated_frame_data->resource_list.empty());
224 cc::ReturnedResourceArray return_resources; 223 cc::ReturnedResourceArray return_resources;
225 ReturnResources(return_resources); 224 ReturnResources(return_resources);
226 did_swap_ = true; 225 did_swap_ = true;
227 return; 226 return;
228 } 227 }
229 228
230 cc::CompositorFrame swap_frame; 229 cc::CompositorFrame swap_frame;
231 230
232 if (in_software_draw_) { 231 if (in_software_draw_) {
233 // The frame we send to the client is actually just the metadata. Preserve 232 // The frame we send to the client is actually just the metadata. Preserve
234 // the |frame| for the software path below. 233 // the |frame| for the software path below.
235 swap_frame.metadata = frame.metadata.Clone(); 234 swap_frame.metadata = frame.metadata.Clone();
236 235
237 if (delegated_surface_id_.is_null()) { 236 if (root_surface_id_.is_null()) {
238 delegated_surface_id_ = surface_id_allocator_->GenerateId(); 237 root_surface_id_ = surface_id_allocator_->GenerateId();
239 surface_factory_->Create(delegated_surface_id_); 238 surface_factory_->Create(root_surface_id_);
239 child_surface_id_ = surface_id_allocator_->GenerateId();
240 surface_factory_->Create(child_surface_id_);
240 } 241 }
241 242
242 display_->SetSurfaceId(delegated_surface_id_, 243 display_->SetSurfaceId(root_surface_id_,
243 frame.metadata.device_scale_factor); 244 frame.metadata.device_scale_factor);
244 245
245 gfx::Size frame_size = 246 // The layer compositor should be giving a frame that covers the
246 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); 247 // |sw_viewport_for_current_draw_| but at 0,0.
247 display_->Resize(frame_size); 248 gfx::Size child_size = sw_viewport_for_current_draw_.size();
249 DCHECK(gfx::Rect(child_size) ==
250 frame.delegated_frame_data->render_pass_list.back()->output_rect);
248 251
249 surface_factory_->SubmitCompositorFrame( 252 // Make a size that covers from 0,0 and includes the area coming from the
250 delegated_surface_id_, std::move(frame), base::Bind(&NoOpDrawCallback)); 253 // layer compositor.
254 gfx::Size display_size(sw_viewport_for_current_draw_.right(),
255 sw_viewport_for_current_draw_.bottom());
256 display_->Resize(display_size);
257
258 // The offset for the child frame relative to the origin of the canvas being
259 // drawn into.
260 gfx::Transform child_transform;
261 child_transform.Translate(
262 gfx::Vector2dF(sw_viewport_for_current_draw_.OffsetFromOrigin()));
263
264 // Make a root frame that embeds the frame coming from the layer compositor
265 // and positions it based on the provided viewport.
266 // TODO(danakj): We could apply the transform here instead of passing it to
267 // the CompositorFrameSink client too? (We'd have to do the same for
268 // hardware frames in SurfacesInstance?)
269 cc::CompositorFrame embed_frame;
270 embed_frame.delegated_frame_data =
271 base::MakeUnique<cc::DelegatedFrameData>();
272 embed_frame.delegated_frame_data->render_pass_list.push_back(
273 cc::RenderPass::Create());
274
275 // The embedding RenderPass covers the entire Display's area.
276 const auto& embed_render_pass =
277 embed_frame.delegated_frame_data->render_pass_list.back();
278 embed_render_pass->SetAll(cc::RenderPassId(1, 1), gfx::Rect(display_size),
279 gfx::Rect(display_size), gfx::Transform(), false);
280
281 // The RenderPass has a single SurfaceDrawQuad (and SharedQuadState for it).
282 auto* shared_quad_state =
283 embed_render_pass->CreateAndAppendSharedQuadState();
284 auto* surface_quad =
285 embed_render_pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
286 shared_quad_state->SetAll(
287 child_transform, child_size, gfx::Rect(child_size),
288 gfx::Rect() /* clip_rect */, false /* is_clipped */, 1.f /* opacity */,
289 SkXfermode::kSrcOver_Mode, 0 /* sorting_context_id */);
290 surface_quad->SetNew(shared_quad_state, gfx::Rect(child_size),
291 gfx::Rect(child_size), child_surface_id_);
292
293 surface_factory_->SubmitCompositorFrame(child_surface_id_, std::move(frame),
294 base::Bind(&NoOpDrawCallback));
295 surface_factory_->SubmitCompositorFrame(root_surface_id_,
296 std::move(embed_frame),
297 base::Bind(&NoOpDrawCallback));
251 display_->DrawAndSwap(); 298 display_->DrawAndSwap();
252 } else { 299 } else {
253 // For hardware draws we send the whole frame to the client so it can draw 300 // For hardware draws we send the whole frame to the client so it can draw
254 // the content in it. 301 // the content in it.
255 swap_frame = std::move(frame); 302 swap_frame = std::move(frame);
256 } 303 }
257 304
258 sync_client_->SwapBuffers(compositor_frame_sink_id_, std::move(swap_frame)); 305 sync_client_->SwapBuffers(compositor_frame_sink_id_, std::move(swap_frame));
259 DeliverMessages(); 306 DeliverMessages();
260 did_swap_ = true; 307 did_swap_ = true;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 362
316 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas); 363 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
317 364
318 SkIRect canvas_clip; 365 SkIRect canvas_clip;
319 canvas->getClipDeviceBounds(&canvas_clip); 366 canvas->getClipDeviceBounds(&canvas_clip);
320 gfx::Rect viewport = gfx::SkIRectToRect(canvas_clip); 367 gfx::Rect viewport = gfx::SkIRectToRect(canvas_clip);
321 368
322 gfx::Transform transform(gfx::Transform::kSkipInitialization); 369 gfx::Transform transform(gfx::Transform::kSkipInitialization);
323 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 370 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
324 371
372 // We will resize the Display to ensure it covers the entire |viewport|, so
373 // save it for later.
374 sw_viewport_for_current_draw_ = viewport;
375
325 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true); 376 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true);
326 display_->SetExternalViewport(viewport);
327 display_->SetExternalClip(viewport);
328 software_compositor_frame_sink_->SetSurfaceSize(
329 gfx::SkISizeToSize(canvas->getBaseLayerSize()));
330 InvokeComposite(transform, viewport); 377 InvokeComposite(transform, viewport);
331 } 378 }
332 379
333 void SynchronousCompositorFrameSink::InvokeComposite( 380 void SynchronousCompositorFrameSink::InvokeComposite(
334 const gfx::Transform& transform, 381 const gfx::Transform& transform,
335 const gfx::Rect& viewport) { 382 const gfx::Rect& viewport) {
383 did_swap_ = false;
384 // Adjust transform so that the layer compositor draws the |viewport| rect
385 // at its origin. The offset of the |viewport| we pass to the layer compositor
386 // is ignored for drawing, so its okay to not match the transform.
387 // TODO(danakj): Why do we pass a viewport origin and then not really use it
388 // (only for comparing to the viewport passed in
389 // SetExternalTilePriorityConstraints), surely this could be more clear?
336 gfx::Transform adjusted_transform = transform; 390 gfx::Transform adjusted_transform = transform;
337 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); 391 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0);
338 did_swap_ = false;
339 client_->OnDraw(adjusted_transform, viewport, in_software_draw_); 392 client_->OnDraw(adjusted_transform, viewport, in_software_draw_);
340 393
341 if (did_swap_) { 394 if (did_swap_) {
342 // This must happen after unwinding the stack and leaving the compositor. 395 // This must happen after unwinding the stack and leaving the compositor.
343 // Usually it is a separate task but we just defer it until OnDraw completes 396 // Usually it is a separate task but we just defer it until OnDraw completes
344 // instead. 397 // instead.
345 client_->DidSwapBuffersComplete(); 398 client_->DidSwapBuffersComplete();
346 } 399 }
347 } 400 }
348 401
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 client_->ReclaimResources(resources); 463 client_->ReclaimResources(resources);
411 } 464 }
412 465
413 void SynchronousCompositorFrameSink::SetBeginFrameSource( 466 void SynchronousCompositorFrameSink::SetBeginFrameSource(
414 cc::BeginFrameSource* begin_frame_source) { 467 cc::BeginFrameSource* begin_frame_source) {
415 // Software output is synchronous and doesn't use a BeginFrameSource. 468 // Software output is synchronous and doesn't use a BeginFrameSource.
416 NOTREACHED(); 469 NOTREACHED();
417 } 470 }
418 471
419 } // namespace content 472 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/android/synchronous_compositor_frame_sink.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698