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

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

Issue 2187563006: sync compositor: Set display viewport for software draw (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 <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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 namespace content { 42 namespace content {
43 43
44 namespace { 44 namespace {
45 45
46 const int64_t kFallbackTickTimeoutInMilliseconds = 100; 46 const int64_t kFallbackTickTimeoutInMilliseconds = 100;
47 const uint32_t kCompositorClientId = 1; 47 const uint32_t kCompositorClientId = 1;
48 48
49 // Do not limit number of resources, so use an unrealistically high value. 49 // Do not limit number of resources, so use an unrealistically high value.
50 const size_t kNumResourcesLimit = 10 * 1000 * 1000; 50 const size_t kNumResourcesLimit = 10 * 1000 * 1000;
51 51
52 } // namespace
53
54 class SoftwareDevice : public cc::SoftwareOutputDevice { 52 class SoftwareDevice : public cc::SoftwareOutputDevice {
55 public: 53 public:
56 SoftwareDevice(SkCanvas** canvas) : canvas_(canvas) {} 54 SoftwareDevice(SkCanvas** canvas) : canvas_(canvas) {}
57 55
58 void Resize(const gfx::Size& pixel_size, float scale_factor) override { 56 void Resize(const gfx::Size& pixel_size, float scale_factor) override {
59 // Intentional no-op: canvas size is controlled by the embedder. 57 // Intentional no-op: canvas size is controlled by the embedder.
60 } 58 }
61 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { 59 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override {
62 DCHECK(*canvas_) << "BeginPaint with no canvas set"; 60 DCHECK(*canvas_) << "BeginPaint with no canvas set";
63 return *canvas_; 61 return *canvas_;
64 } 62 }
65 void EndPaint() override {} 63 void EndPaint() override {}
66 64
67 private: 65 private:
68 SkCanvas** canvas_; 66 SkCanvas** canvas_;
69 67
70 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); 68 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice);
71 }; 69 };
72 70
73 class SoftwareOutputSurface : public cc::OutputSurface { 71 } // namespace
72
73 class SynchronousCompositorOutputSurface::SoftwareOutputSurface
74 : public cc::OutputSurface {
74 public: 75 public:
75 SoftwareOutputSurface(std::unique_ptr<SoftwareDevice> software_device) 76 SoftwareOutputSurface(std::unique_ptr<SoftwareDevice> software_device)
76 : cc::OutputSurface(nullptr, nullptr, std::move(software_device)) {} 77 : cc::OutputSurface(nullptr, nullptr, std::move(software_device)) {}
77 78
78 // cc::OutputSurface implementation. 79 // cc::OutputSurface implementation.
79 uint32_t GetFramebufferCopyTextureFormat() override { return 0; } 80 uint32_t GetFramebufferCopyTextureFormat() override { return 0; }
80 void SwapBuffers(cc::CompositorFrame frame) override {} 81 void SwapBuffers(cc::CompositorFrame frame) override {}
82 void Reshape(const gfx::Size& size,
83 float scale_factor,
84 const gfx::ColorSpace& color_space,
85 bool has_alpha) override {
86 // Intentional no-op. Surface size controlled by embedder.
87 }
88
89 void SetSurfaceSize(const gfx::Size surface_size) {
90 surface_size_ = surface_size;
91 }
81 }; 92 };
82 93
83 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( 94 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface(
84 scoped_refptr<cc::ContextProvider> context_provider, 95 scoped_refptr<cc::ContextProvider> context_provider,
85 scoped_refptr<cc::ContextProvider> worker_context_provider, 96 scoped_refptr<cc::ContextProvider> worker_context_provider,
86 int routing_id, 97 int routing_id,
87 uint32_t output_surface_id, 98 uint32_t output_surface_id,
88 SynchronousCompositorRegistry* registry, 99 SynchronousCompositorRegistry* registry,
89 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) 100 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue)
90 : cc::OutputSurface(std::move(context_provider), 101 : cc::OutputSurface(std::move(context_provider),
91 std::move(worker_context_provider), 102 std::move(worker_context_provider),
92 nullptr), 103 nullptr),
93 routing_id_(routing_id), 104 routing_id_(routing_id),
94 output_surface_id_(output_surface_id), 105 output_surface_id_(output_surface_id),
95 registry_(registry), 106 registry_(registry),
96 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()), 107 sender_(RenderThreadImpl::current()->sync_compositor_message_filter()),
97 memory_policy_(0u), 108 memory_policy_(0u),
98 frame_swap_message_queue_(frame_swap_message_queue), 109 frame_swap_message_queue_(frame_swap_message_queue),
99 surface_manager_(new cc::SurfaceManager), 110 surface_manager_(new cc::SurfaceManager),
100 surface_id_allocator_(new cc::SurfaceIdAllocator(kCompositorClientId)), 111 surface_id_allocator_(new cc::SurfaceIdAllocator(kCompositorClientId)),
101 surface_factory_(new cc::SurfaceFactory(surface_manager_.get(), this)) { 112 surface_factory_(new cc::SurfaceFactory(surface_manager_.get(), this)),
113 software_output_surface_(nullptr) {
102 DCHECK(registry_); 114 DCHECK(registry_);
103 DCHECK(sender_); 115 DCHECK(sender_);
104 thread_checker_.DetachFromThread(); 116 thread_checker_.DetachFromThread();
105 capabilities_.adjust_deadline_for_parent = false; 117 capabilities_.adjust_deadline_for_parent = false;
106 capabilities_.delegated_rendering = true; 118 capabilities_.delegated_rendering = true;
107 memory_policy_.priority_cutoff_when_visible = 119 memory_policy_.priority_cutoff_when_visible =
108 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; 120 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
109 } 121 }
110 122
111 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() = 123 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() =
(...skipping 30 matching lines...) Expand all
142 base::Unretained(this))); 154 base::Unretained(this)));
143 registry_->RegisterOutputSurface(routing_id_, this); 155 registry_->RegisterOutputSurface(routing_id_, this);
144 registered_ = true; 156 registered_ = true;
145 157
146 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id()); 158 surface_manager_->RegisterSurfaceClientId(surface_id_allocator_->client_id());
147 surface_manager_->RegisterSurfaceFactoryClient( 159 surface_manager_->RegisterSurfaceFactoryClient(
148 surface_id_allocator_->client_id(), this); 160 surface_id_allocator_->client_id(), this);
149 161
150 cc::RendererSettings software_renderer_settings; 162 cc::RendererSettings software_renderer_settings;
151 163
164 std::unique_ptr<SoftwareOutputSurface> output_surface(
165 new SoftwareOutputSurface(
166 base::MakeUnique<SoftwareDevice>(&current_sw_canvas_)));
167 software_output_surface_ = output_surface.get();
168
152 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as 169 // The shared_bitmap_manager and gpu_memory_buffer_manager here are null as
153 // this Display is only used for resourcesless software draws, where no 170 // this Display is only used for resourcesless software draws, where no
154 // resources are included in the frame swapped from the compositor. So there 171 // resources are included in the frame swapped from the compositor. So there
155 // is no need for these. 172 // is no need for these.
156 display_.reset(new cc::Display( 173 display_.reset(new cc::Display(
157 nullptr /* shared_bitmap_manager */, 174 nullptr /* shared_bitmap_manager */,
158 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings, 175 nullptr /* gpu_memory_buffer_manager */, software_renderer_settings,
159 nullptr /* begin_frame_source */, 176 nullptr /* begin_frame_source */, std::move(output_surface),
160 base::MakeUnique<SoftwareOutputSurface>(
161 base::MakeUnique<SoftwareDevice>(&current_sw_canvas_)),
162 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */)); 177 nullptr /* scheduler */, nullptr /* texture_mailbox_deleter */));
163 display_->Initialize(&display_client_, surface_manager_.get(), 178 display_->Initialize(&display_client_, surface_manager_.get(),
164 surface_id_allocator_->client_id()); 179 surface_id_allocator_->client_id());
165 return true; 180 return true;
166 } 181 }
167 182
168 void SynchronousCompositorOutputSurface::DetachFromClient() { 183 void SynchronousCompositorOutputSurface::DetachFromClient() {
169 DCHECK(CalledOnValidThread()); 184 DCHECK(CalledOnValidThread());
170 if (registered_) { 185 if (registered_) {
171 registry_->UnregisterOutputSurface(routing_id_, this); 186 registry_->UnregisterOutputSurface(routing_id_, this);
172 } 187 }
173 client_->SetTreeActivationCallback(base::Closure()); 188 client_->SetTreeActivationCallback(base::Closure());
174 if (!delegated_surface_id_.is_null()) 189 if (!delegated_surface_id_.is_null())
175 surface_factory_->Destroy(delegated_surface_id_); 190 surface_factory_->Destroy(delegated_surface_id_);
176 surface_manager_->UnregisterSurfaceFactoryClient( 191 surface_manager_->UnregisterSurfaceFactoryClient(
177 surface_id_allocator_->client_id()); 192 surface_id_allocator_->client_id());
178 surface_manager_->InvalidateSurfaceClientId( 193 surface_manager_->InvalidateSurfaceClientId(
179 surface_id_allocator_->client_id()); 194 surface_id_allocator_->client_id());
195 software_output_surface_ = nullptr;
180 display_ = nullptr; 196 display_ = nullptr;
181 surface_factory_ = nullptr; 197 surface_factory_ = nullptr;
182 surface_id_allocator_ = nullptr; 198 surface_id_allocator_ = nullptr;
183 surface_manager_ = nullptr; 199 surface_manager_ = nullptr;
184 cc::OutputSurface::DetachFromClient(); 200 cc::OutputSurface::DetachFromClient();
185 CancelFallbackTick(); 201 CancelFallbackTick();
186 } 202 }
187 203
188 void SynchronousCompositorOutputSurface::Reshape( 204 void SynchronousCompositorOutputSurface::Reshape(
189 const gfx::Size& size, 205 const gfx::Size& size,
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 328
313 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas); 329 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
314 330
315 SkIRect canvas_clip; 331 SkIRect canvas_clip;
316 canvas->getClipDeviceBounds(&canvas_clip); 332 canvas->getClipDeviceBounds(&canvas_clip);
317 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); 333 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip);
318 334
319 gfx::Transform transform(gfx::Transform::kSkipInitialization); 335 gfx::Transform transform(gfx::Transform::kSkipInitialization);
320 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 336 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
321 337
322 surface_size_ = gfx::Size(canvas->getBaseLayerSize().width(), 338 surface_size_ = gfx::Size(canvas->getBaseLayerSize().width(),
danakj 2016/07/27 21:28:36 Ahh. Does it need to be a member on SCOS still too
boliu 2016/07/27 21:43:04 Hmm... in practice, no, because DelegatingRenderer
danakj 2016/07/27 21:49:53 I'm working toward that right now.
boliu 2016/07/27 22:00:51 Ok, not setting SCOS::surface_size_ anywhere, and
323 canvas->getBaseLayerSize().height()); 339 canvas->getBaseLayerSize().height());
324 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true); 340 base::AutoReset<bool> set_in_software_draw(&in_software_draw_, true);
341 display_->SetExternalViewport(clip);
342 display_->SetExternalClip(clip);
343 software_output_surface_->SetSurfaceSize(surface_size_);
325 InvokeComposite(transform, clip, clip); 344 InvokeComposite(transform, clip, clip);
326 } 345 }
327 346
328 void SynchronousCompositorOutputSurface::InvokeComposite( 347 void SynchronousCompositorOutputSurface::InvokeComposite(
329 const gfx::Transform& transform, 348 const gfx::Transform& transform,
330 const gfx::Rect& viewport, 349 const gfx::Rect& viewport,
331 const gfx::Rect& clip) { 350 const gfx::Rect& clip) {
332 gfx::Transform adjusted_transform = transform; 351 gfx::Transform adjusted_transform = transform;
333 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); 352 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0);
334 did_swap_ = false; 353 did_swap_ = false;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 client_->ReclaimResources(resources); 425 client_->ReclaimResources(resources);
407 } 426 }
408 427
409 void SynchronousCompositorOutputSurface::SetBeginFrameSource( 428 void SynchronousCompositorOutputSurface::SetBeginFrameSource(
410 cc::BeginFrameSource* begin_frame_source) { 429 cc::BeginFrameSource* begin_frame_source) {
411 // Software output is synchronous and doesn't use a BeginFrameSource. 430 // Software output is synchronous and doesn't use a BeginFrameSource.
412 NOTREACHED(); 431 NOTREACHED();
413 } 432 }
414 433
415 } // namespace content 434 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698