OLD | NEW |
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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 : surface_(surface) { | 38 : surface_(surface) { |
39 } | 39 } |
40 void Resize(const gfx::Size& pixel_size, float scale_factor) override { | 40 void Resize(const gfx::Size& pixel_size, float scale_factor) override { |
41 // Intentional no-op: canvas size is controlled by the embedder. | 41 // Intentional no-op: canvas size is controlled by the embedder. |
42 } | 42 } |
43 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { | 43 SkCanvas* BeginPaint(const gfx::Rect& damage_rect) override { |
44 if (!surface_->current_sw_canvas_) { | 44 if (!surface_->current_sw_canvas_) { |
45 NOTREACHED() << "BeginPaint with no canvas set"; | 45 NOTREACHED() << "BeginPaint with no canvas set"; |
46 return &null_canvas_; | 46 return &null_canvas_; |
47 } | 47 } |
48 LOG_IF(WARNING, surface_->frame_holder_.get()) | 48 LOG_IF(WARNING, surface_->did_swap_) |
49 << "Mutliple calls to BeginPaint per frame"; | 49 << "Mutliple calls to BeginPaint per frame"; |
50 return surface_->current_sw_canvas_; | 50 return surface_->current_sw_canvas_; |
51 } | 51 } |
52 void EndPaint() override {} | 52 void EndPaint() override {} |
53 | 53 |
54 private: | 54 private: |
55 SynchronousCompositorOutputSurface* surface_; | 55 SynchronousCompositorOutputSurface* surface_; |
56 SkCanvas null_canvas_; | 56 SkCanvas null_canvas_; |
57 | 57 |
58 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); | 58 DISALLOW_COPY_AND_ASSIGN(SoftwareDevice); |
59 }; | 59 }; |
60 | 60 |
61 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( | 61 SynchronousCompositorOutputSurface::SynchronousCompositorOutputSurface( |
62 const scoped_refptr<cc::ContextProvider>& context_provider, | 62 const scoped_refptr<cc::ContextProvider>& context_provider, |
63 const scoped_refptr<cc::ContextProvider>& worker_context_provider, | 63 const scoped_refptr<cc::ContextProvider>& worker_context_provider, |
64 int routing_id, | 64 int routing_id, |
65 SynchronousCompositorRegistry* registry, | 65 SynchronousCompositorRegistry* registry, |
66 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) | 66 scoped_refptr<FrameSwapMessageQueue> frame_swap_message_queue) |
67 : cc::OutputSurface( | 67 : cc::OutputSurface( |
68 context_provider, | 68 context_provider, |
69 worker_context_provider, | 69 worker_context_provider, |
70 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), | 70 scoped_ptr<cc::SoftwareOutputDevice>(new SoftwareDevice(this))), |
71 routing_id_(routing_id), | 71 routing_id_(routing_id), |
72 registry_(registry), | 72 registry_(registry), |
73 registered_(false), | 73 registered_(false), |
74 sync_client_(nullptr), | 74 sync_client_(nullptr), |
75 current_sw_canvas_(nullptr), | 75 current_sw_canvas_(nullptr), |
76 memory_policy_(0u), | 76 memory_policy_(0u), |
| 77 did_swap_(false), |
77 frame_swap_message_queue_(frame_swap_message_queue) { | 78 frame_swap_message_queue_(frame_swap_message_queue) { |
78 thread_checker_.DetachFromThread(); | 79 thread_checker_.DetachFromThread(); |
79 DCHECK(registry_); | 80 DCHECK(registry_); |
80 capabilities_.adjust_deadline_for_parent = false; | 81 capabilities_.adjust_deadline_for_parent = false; |
81 capabilities_.delegated_rendering = true; | 82 capabilities_.delegated_rendering = true; |
82 memory_policy_.priority_cutoff_when_visible = | 83 memory_policy_.priority_cutoff_when_visible = |
83 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; | 84 gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE; |
84 } | 85 } |
85 | 86 |
86 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {} | 87 SynchronousCompositorOutputSurface::~SynchronousCompositorOutputSurface() {} |
(...skipping 26 matching lines...) Expand all Loading... |
113 | 114 |
114 void SynchronousCompositorOutputSurface::Reshape(const gfx::Size& size, | 115 void SynchronousCompositorOutputSurface::Reshape(const gfx::Size& size, |
115 float scale_factor, | 116 float scale_factor, |
116 bool has_alpha) { | 117 bool has_alpha) { |
117 // Intentional no-op: surface size is controlled by the embedder. | 118 // Intentional no-op: surface size is controlled by the embedder. |
118 } | 119 } |
119 | 120 |
120 void SynchronousCompositorOutputSurface::SwapBuffers( | 121 void SynchronousCompositorOutputSurface::SwapBuffers( |
121 cc::CompositorFrame* frame) { | 122 cc::CompositorFrame* frame) { |
122 DCHECK(CalledOnValidThread()); | 123 DCHECK(CalledOnValidThread()); |
123 frame_holder_.reset(new cc::CompositorFrame); | 124 DCHECK(sync_client_); |
124 frame->AssignTo(frame_holder_.get()); | 125 sync_client_->SwapBuffers(frame); |
125 client_->DidSwapBuffers(); | 126 client_->DidSwapBuffers(); |
| 127 did_swap_ = true; |
126 } | 128 } |
127 | 129 |
128 void SynchronousCompositorOutputSurface::Invalidate() { | 130 void SynchronousCompositorOutputSurface::Invalidate() { |
129 DCHECK(CalledOnValidThread()); | 131 DCHECK(CalledOnValidThread()); |
130 if (sync_client_) | 132 if (sync_client_) |
131 sync_client_->Invalidate(); | 133 sync_client_->Invalidate(); |
132 } | 134 } |
133 | 135 |
134 scoped_ptr<cc::CompositorFrame> | 136 void SynchronousCompositorOutputSurface::DemandDrawHw( |
135 SynchronousCompositorOutputSurface::DemandDrawHw( | |
136 const gfx::Size& surface_size, | 137 const gfx::Size& surface_size, |
137 const gfx::Transform& transform, | 138 const gfx::Transform& transform, |
138 const gfx::Rect& viewport, | 139 const gfx::Rect& viewport, |
139 const gfx::Rect& clip, | 140 const gfx::Rect& clip, |
140 const gfx::Rect& viewport_rect_for_tile_priority, | 141 const gfx::Rect& viewport_rect_for_tile_priority, |
141 const gfx::Transform& transform_for_tile_priority) { | 142 const gfx::Transform& transform_for_tile_priority) { |
142 DCHECK(CalledOnValidThread()); | 143 DCHECK(CalledOnValidThread()); |
143 DCHECK(HasClient()); | 144 DCHECK(HasClient()); |
144 DCHECK(context_provider_.get()); | 145 DCHECK(context_provider_.get()); |
145 | 146 |
146 surface_size_ = surface_size; | 147 surface_size_ = surface_size; |
147 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, | 148 client_->SetExternalTilePriorityConstraints(viewport_rect_for_tile_priority, |
148 transform_for_tile_priority); | 149 transform_for_tile_priority); |
149 const bool software_draw = false; | 150 const bool software_draw = false; |
150 InvokeComposite(transform, viewport, clip, software_draw); | 151 InvokeComposite(transform, viewport, clip, software_draw); |
151 | |
152 return frame_holder_.Pass(); | |
153 } | 152 } |
154 | 153 |
155 scoped_ptr<cc::CompositorFrame> | 154 void SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
156 SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | |
157 DCHECK(CalledOnValidThread()); | 155 DCHECK(CalledOnValidThread()); |
158 DCHECK(canvas); | 156 DCHECK(canvas); |
159 DCHECK(!current_sw_canvas_); | 157 DCHECK(!current_sw_canvas_); |
160 | 158 |
161 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); | 159 base::AutoReset<SkCanvas*> canvas_resetter(¤t_sw_canvas_, canvas); |
162 | 160 |
163 SkIRect canvas_clip; | 161 SkIRect canvas_clip; |
164 canvas->getClipDeviceBounds(&canvas_clip); | 162 canvas->getClipDeviceBounds(&canvas_clip); |
165 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); | 163 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
166 | 164 |
167 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 165 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
168 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 166 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
169 | 167 |
170 surface_size_ = gfx::Size(canvas->getBaseLayerSize().width(), | 168 surface_size_ = gfx::Size(canvas->getBaseLayerSize().width(), |
171 canvas->getBaseLayerSize().height()); | 169 canvas->getBaseLayerSize().height()); |
172 const bool software_draw = true; | 170 const bool software_draw = true; |
173 InvokeComposite(transform, clip, clip, software_draw); | 171 InvokeComposite(transform, clip, clip, software_draw); |
174 | |
175 return frame_holder_.Pass(); | |
176 } | 172 } |
177 | 173 |
178 void SynchronousCompositorOutputSurface::InvokeComposite( | 174 void SynchronousCompositorOutputSurface::InvokeComposite( |
179 const gfx::Transform& transform, | 175 const gfx::Transform& transform, |
180 const gfx::Rect& viewport, | 176 const gfx::Rect& viewport, |
181 const gfx::Rect& clip, | 177 const gfx::Rect& clip, |
182 bool software_draw) { | 178 bool software_draw) { |
183 DCHECK(!frame_holder_.get()); | |
184 | |
185 gfx::Transform adjusted_transform = transform; | 179 gfx::Transform adjusted_transform = transform; |
186 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); | 180 adjusted_transform.matrix().postTranslate(-viewport.x(), -viewport.y(), 0); |
| 181 did_swap_ = false; |
187 client_->OnDraw(adjusted_transform, viewport, clip, software_draw); | 182 client_->OnDraw(adjusted_transform, viewport, clip, software_draw); |
188 | 183 |
189 if (frame_holder_.get()) | 184 if (did_swap_) |
190 client_->DidSwapBuffersComplete(); | 185 client_->DidSwapBuffersComplete(); |
191 } | 186 } |
192 | 187 |
193 void SynchronousCompositorOutputSurface::ReturnResources( | 188 void SynchronousCompositorOutputSurface::ReturnResources( |
194 const cc::CompositorFrameAck& frame_ack) { | 189 const cc::CompositorFrameAck& frame_ack) { |
195 ReclaimResources(&frame_ack); | 190 ReclaimResources(&frame_ack); |
196 } | 191 } |
197 | 192 |
198 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { | 193 void SynchronousCompositorOutputSurface::SetMemoryPolicy(size_t bytes_limit) { |
199 DCHECK(CalledOnValidThread()); | 194 DCHECK(CalledOnValidThread()); |
(...skipping 29 matching lines...) Expand all Loading... |
229 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = | 224 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
230 frame_swap_message_queue_->AcquireSendMessageScope(); | 225 frame_swap_message_queue_->AcquireSendMessageScope(); |
231 frame_swap_message_queue_->DrainMessages(messages); | 226 frame_swap_message_queue_->DrainMessages(messages); |
232 } | 227 } |
233 | 228 |
234 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 229 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
235 return thread_checker_.CalledOnValidThread(); | 230 return thread_checker_.CalledOnValidThread(); |
236 } | 231 } |
237 | 232 |
238 } // namespace content | 233 } // namespace content |
OLD | NEW |