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

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

Issue 2377533002: cc: Remove Display::SetExternalViewport. (Closed)
Patch Set: webview-expand-sw: . 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"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 79
80 // cc::OutputSurface implementation. 80 // cc::OutputSurface implementation.
81 void EnsureBackbuffer() override {} 81 void EnsureBackbuffer() override {}
82 void DiscardBackbuffer() override {} 82 void DiscardBackbuffer() override {}
83 void BindFramebuffer() override {} 83 void BindFramebuffer() override {}
84 void SwapBuffers(cc::CompositorFrame frame) override {} 84 void SwapBuffers(cc::CompositorFrame frame) override {}
85 void Reshape(const gfx::Size& size, 85 void Reshape(const gfx::Size& size,
86 float scale_factor, 86 float scale_factor,
87 const gfx::ColorSpace& color_space, 87 const gfx::ColorSpace& color_space,
88 bool has_alpha) override { 88 bool has_alpha) override {
89 // Intentional no-op. Surface size controlled by embedder. 89 surface_size_ = size;
90 } 90 }
91 uint32_t GetFramebufferCopyTextureFormat() override { return 0; } 91 uint32_t GetFramebufferCopyTextureFormat() override { return 0; }
92 cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override { 92 cc::OverlayCandidateValidator* GetOverlayCandidateValidator() const override {
93 return nullptr; 93 return nullptr;
94 } 94 }
95 bool IsDisplayedAsOverlayPlane() const override { return false; } 95 bool IsDisplayedAsOverlayPlane() const override { return false; }
96 unsigned GetOverlayTextureId() const override { return 0; } 96 unsigned GetOverlayTextureId() const override { return 0; }
97 bool SurfaceIsSuspendForRecycle() const override { return false; } 97 bool SurfaceIsSuspendForRecycle() const override { return false; }
98 bool HasExternalStencilTest() const override { return false; } 98 bool HasExternalStencilTest() const override { return false; }
99 void ApplyExternalStencil() override {} 99 void ApplyExternalStencil() override {}
100
101 void SetSurfaceSize(const gfx::Size surface_size) {
102 surface_size_ = surface_size;
103 }
104 }; 100 };
105 101
106 SynchronousCompositorFrameSink::SynchronousCompositorFrameSink( 102 SynchronousCompositorFrameSink::SynchronousCompositorFrameSink(
107 scoped_refptr<cc::ContextProvider> context_provider, 103 scoped_refptr<cc::ContextProvider> context_provider,
108 scoped_refptr<cc::ContextProvider> worker_context_provider, 104 scoped_refptr<cc::ContextProvider> worker_context_provider,
109 int routing_id, 105 int routing_id,
110 uint32_t compositor_frame_sink_id, 106 uint32_t compositor_frame_sink_id,
111 std::unique_ptr<cc::BeginFrameSource> begin_frame_source, 107 std::unique_ptr<cc::BeginFrameSource> begin_frame_source,
112 SynchronousCompositorRegistry* registry, 108 SynchronousCompositorRegistry* registry,
113 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) 109 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 base::Unretained(this))); 162 base::Unretained(this)));
167 registry_->RegisterCompositorFrameSink(routing_id_, this); 163 registry_->RegisterCompositorFrameSink(routing_id_, this);
168 registered_ = true; 164 registered_ = true;
169 165
170 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id()); 166 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id());
171 surface_manager_->RegisterSurfaceFactoryClient( 167 surface_manager_->RegisterSurfaceFactoryClient(
172 surface_id_allocator_->client_id(), this); 168 surface_id_allocator_->client_id(), this);
173 169
174 cc::RendererSettings software_renderer_settings; 170 cc::RendererSettings software_renderer_settings;
175 171
176 std::unique_ptr<SoftwareOutputSurface> compositor_frame_sink( 172 auto output_surface = base::MakeUnique<SoftwareOutputSurface>(
177 new SoftwareOutputSurface( 173 base::MakeUnique<SoftwareDevice>(&current_sw_canvas_));
178 base::MakeUnique<SoftwareDevice>(&current_sw_canvas_))); 174 software_output_surface_ = output_surface.get();
179 software_compositor_frame_sink_ = compositor_frame_sink.get();
180 175
181 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as 176 // 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 177 // this Display is only used for resourcesless software draws, where no
183 // resources are included in the frame swapped from the compositor. So there 178 // resources are included in the frame swapped from the compositor. So there
184 // is no need for these. 179 // is no need for these.
185 display_.reset(new cc::Display( 180 display_.reset(new cc::Display(
186 nullptr /* shared_bitmap_manager */, 181 nullptr /* shared_bitmap_manager */,
187 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, 182 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings,
188 nullptr /* begin_frame_source */, std::move(compositor_frame_sink), 183 nullptr /* begin_frame_source */, std::move(output_surface),
189 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); 184 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */));
190 display_->Initialize(&display_client_, surface_manager_.get(), 185 display_->Initialize(&display_client_, surface_manager_.get(),
191 surface_id_allocator_->client_id()); 186 surface_id_allocator_->client_id());
192 display_->SetVisible(true); 187 display_->SetVisible(true);
193 return true; 188 return true;
194 } 189 }
195 190
196 void SynchronousCompositorFrameSink::DetachFromClient() { 191 void SynchronousCompositorFrameSink::DetachFromClient() {
197 DCHECK(CalledOnValidThread()); 192 DCHECK(CalledOnValidThread());
198 client_->SetBeginFrameSource(nullptr); 193 client_->SetBeginFrameSource(nullptr);
199 // Destroy the begin frame source on the same thread it was bound on. 194 // Destroy the begin frame source on the same thread it was bound on.
200 begin_frame_source_ = nullptr; 195 begin_frame_source_ = nullptr;
201 if (registered_) 196 if (registered_)
202 registry_->UnregisterCompositorFrameSink(routing_id_, this); 197 registry_->UnregisterCompositorFrameSink(routing_id_, this);
203 client_->SetTreeActivationCallback(base::Closure()); 198 client_->SetTreeActivationCallback(base::Closure());
204 if (!delegated_surface_id_.is_null()) 199 if (!delegated_surface_id_.is_null())
205 surface_factory_->Destroy(delegated_surface_id_); 200 surface_factory_->Destroy(delegated_surface_id_);
206 surface_manager_->UnregisterSurfaceFactoryClient( 201 surface_manager_->UnregisterSurfaceFactoryClient(
207 surface_id_allocator_->client_id()); 202 surface_id_allocator_->client_id());
208 surface_manager_->InvalidateSurfaceClientId( 203 surface_manager_->InvalidateSurfaceClientId(
209 surface_id_allocator_->client_id()); 204 surface_id_allocator_->client_id());
210 software_compositor_frame_sink_ = nullptr; 205 software_output_surface_ = nullptr;
211 display_ = nullptr; 206 display_ = nullptr;
212 surface_factory_ = nullptr; 207 surface_factory_ = nullptr;
213 surface_id_allocator_ = nullptr; 208 surface_id_allocator_ = nullptr;
214 surface_manager_ = nullptr; 209 surface_manager_ = nullptr;
215 cc::CompositorFrameSink::DetachFromClient(); 210 cc::CompositorFrameSink::DetachFromClient();
216 CancelFallbackTick(); 211 CancelFallbackTick();
217 } 212 }
218 213
219 static void NoOpDrawCallback() {} 214 static void NoOpDrawCallback() {}
220 215
(...skipping 17 matching lines...) Expand all
238 swap_frame.metadata = frame.metadata.Clone(); 233 swap_frame.metadata = frame.metadata.Clone();
239 234
240 if (delegated_surface_id_.is_null()) { 235 if (delegated_surface_id_.is_null()) {
241 delegated_surface_id_ = surface_id_allocator_->GenerateId(); 236 delegated_surface_id_ = surface_id_allocator_->GenerateId();
242 surface_factory_->Create(delegated_surface_id_); 237 surface_factory_->Create(delegated_surface_id_);
243 } 238 }
244 239
245 display_->SetSurfaceId(delegated_surface_id_, 240 display_->SetSurfaceId(delegated_surface_id_,
246 frame.metadata.device_scale_factor); 241 frame.metadata.device_scale_factor);
247 242
248 gfx::Size frame_size = 243 // This size covers the entire external clip given to DemandDrawSw(). The
249 frame.delegated_frame_data->render_pass_list.back()->output_rect.size(); 244 // CompositorFrame here could be either smaller than this size (we're
250 display_->Resize(frame_size); 245 // drawing an enlarged viewport that extends beyond the layer compositor's
246 // concept of the output size) or larger than this size (we're only drawing
247 // a portion of the layer compositor's usual output size).
248 display_->Resize(sw_display_size_for_current_draw_);
251 249
252 surface_factory_->SubmitCompositorFrame( 250 surface_factory_->SubmitCompositorFrame(
253 delegated_surface_id_, std::move(frame), base::Bind(&NoOpDrawCallback)); 251 delegated_surface_id_, std::move(frame), base::Bind(&NoOpDrawCallback));
254 display_->DrawAndSwap(); 252 display_->DrawAndSwap();
255 } else { 253 } else {
256 // For hardware draws we send the whole frame to the client so it can draw 254 // For hardware draws we send the whole frame to the client so it can draw
257 // the content in it. 255 // the content in it.
258 swap_frame = std::move(frame); 256 swap_frame = std::move(frame);
259 } 257 }
260 258
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas); 317 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
320 318
321 SkIRect canvas_clip; 319 SkIRect canvas_clip;
322 canvas->getClipDeviceBounds(&canvas_clip); 320 canvas->getClipDeviceBounds(&canvas_clip);
323 gfx::Rect viewport = gfx::SkIRectToRect(canvas_clip); 321 gfx::Rect viewport = gfx::SkIRectToRect(canvas_clip);
324 322
325 gfx::Transform transform(gfx::Transform::kSkipInitialization); 323 gfx::Transform transform(gfx::Transform::kSkipInitialization);
326 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 324 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
327 325
328 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true); 326 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true);
329 display_->SetExternalViewport(viewport); 327
328 // We will resize the Display to ensure it draws the entire |viewport| given
329 // here instead of only the layer compositor's idea of what the viewport is.
330 sw_display_size_for_current_draw_ =
331 gfx::Size(viewport.right(), viewport.bottom());
332 // Though the canvas already has a clip on it the Display can destroy it so we
333 // need to tell it about the clip.
330 display_->SetExternalClip(viewport); 334 display_->SetExternalClip(viewport);
331 software_compositor_frame_sink_->SetSurfaceSize(
332 gfx::SkISizeToSize(canvas->getBaseLayerSize()));
333 InvokeComposite(transform, viewport); 335 InvokeComposite(transform, viewport);
334 } 336 }
335 337
336 void SynchronousCompositorFrameSink::InvokeComposite( 338 void SynchronousCompositorFrameSink::InvokeComposite(
337 const gfx::Transform& transform, 339 const gfx::Transform& transform,
338 const gfx::Rect& viewport) { 340 const gfx::Rect& viewport) {
339 gfx::Transform adjusted_transform = transform;
340 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0);
341 did_swap_ = false; 341 did_swap_ = false;
342 client_->OnDraw(adjusted_transform, viewport, in_software_draw_); 342 client_->OnDraw(transform, viewport, in_software_draw_);
danakj 2016/09/30 18:58:24 Or it's probably related to this change..
danakj 2016/09/30 19:10:23 So LTHI::UpdateDrawProperties would use this trans
343 343
344 if (did_swap_) { 344 if (did_swap_) {
345 // This must happen after unwinding the stack and leaving the compositor. 345 // This must happen after unwinding the stack and leaving the compositor.
346 // Usually it is a separate task but we just defer it until OnDraw completes 346 // Usually it is a separate task but we just defer it until OnDraw completes
347 // instead. 347 // instead.
348 client_->DidSwapBuffersComplete(); 348 client_->DidSwapBuffersComplete();
349 } 349 }
350 } 350 }
351 351
352 void SynchronousCompositorFrameSink::OnReclaimResources( 352 void SynchronousCompositorFrameSink::OnReclaimResources(
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 client_->ReclaimResources(resources); 413 client_->ReclaimResources(resources);
414 } 414 }
415 415
416 void SynchronousCompositorFrameSink::SetBeginFrameSource( 416 void SynchronousCompositorFrameSink::SetBeginFrameSource(
417 cc::BeginFrameSource* begin_frame_source) { 417 cc::BeginFrameSource* begin_frame_source) {
418 // Software output is synchronous and doesn't use a BeginFrameSource. 418 // Software output is synchronous and doesn't use a BeginFrameSource.
419 NOTREACHED(); 419 NOTREACHED();
420 } 420 }
421 421
422 } // namespace content 422 } // 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