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/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" | 5 #include "content/browser/android/in_process/synchronous_compositor_output_surfa
ce.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "cc/output/compositor_frame.h" | 10 #include "cc/output/compositor_frame.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 void SynchronousCompositorOutputSurface::SwapBuffers( | 147 void SynchronousCompositorOutputSurface::SwapBuffers( |
148 const ui::LatencyInfo& info) { | 148 const ui::LatencyInfo& info) { |
149 context3d()->shallowFlushCHROMIUM(); | 149 context3d()->shallowFlushCHROMIUM(); |
150 did_swap_buffer_ = true; | 150 did_swap_buffer_ = true; |
151 } | 151 } |
152 | 152 |
153 bool SynchronousCompositorOutputSurface::IsHwReady() { | 153 bool SynchronousCompositorOutputSurface::IsHwReady() { |
154 return context3d() != NULL; | 154 return context3d() != NULL; |
155 } | 155 } |
156 | 156 |
| 157 namespace { |
| 158 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { |
| 159 // The system-provided transform translates us from the screen origin to the |
| 160 // origin of the clip rect, but CC's draw origin starts at the clip. |
| 161 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); |
| 162 } |
| 163 } // namespace |
| 164 |
157 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 165 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
158 DCHECK(CalledOnValidThread()); | 166 DCHECK(CalledOnValidThread()); |
159 DCHECK(canvas); | 167 DCHECK(canvas); |
160 DCHECK(!current_sw_canvas_); | 168 DCHECK(!current_sw_canvas_); |
161 current_sw_canvas_ = canvas; | 169 current_sw_canvas_ = canvas; |
162 | 170 |
163 SkRect canvas_clip; | 171 SkIRect canvas_clip; |
164 gfx::Rect damage_area; | 172 canvas->getClipDeviceBounds(&canvas_clip); |
165 if (canvas->getClipBounds(&canvas_clip)) { | 173 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
166 damage_area = gfx::ToEnclosedRect(gfx::SkRectToRectF(canvas_clip)); | |
167 } else { | |
168 damage_area = gfx::Rect(kint16max, kint16max); | |
169 } | |
170 | 174 |
171 gfx::Transform transform; | 175 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
172 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 176 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 177 AdjustTransformForClip(&transform, clip); |
173 | 178 |
174 InvokeComposite(transform, damage_area); | 179 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), |
| 180 canvas->getDeviceSize().height()); |
| 181 client_->SetExternalDrawConstraints(transform, clip); |
| 182 |
| 183 InvokeComposite(clip.size()); |
175 | 184 |
176 bool finished_draw = current_sw_canvas_ == NULL; | 185 bool finished_draw = current_sw_canvas_ == NULL; |
177 current_sw_canvas_ = NULL; | 186 current_sw_canvas_ = NULL; |
178 return finished_draw; | 187 return finished_draw; |
179 } | 188 } |
180 | 189 |
181 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 190 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
182 gfx::Size view_size, | 191 gfx::Size surface_size, |
183 const gfx::Transform& transform, | 192 const gfx::Transform& transform, |
184 gfx::Rect damage_area) { | 193 gfx::Rect clip) { |
185 DCHECK(CalledOnValidThread()); | 194 DCHECK(CalledOnValidThread()); |
186 DCHECK(client_); | 195 DCHECK(client_); |
187 DCHECK(context3d()); | 196 DCHECK(context3d()); |
188 | 197 |
189 // Force a GL state restore next time a GLContextVirtual is made current. | 198 // Force a GL state restore next time a GLContextVirtual is made current. |
190 // TODO(boliu): Move this to the end of this function after we have fixed | 199 // TODO(boliu): Move this to the end of this function after we have fixed |
191 // all cases of MakeCurrent calls outside of draws. Tracked in | 200 // all cases of MakeCurrent calls outside of draws. Tracked in |
192 // crbug.com/239856. | 201 // crbug.com/239856. |
193 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); | 202 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); |
194 if (current_context) | 203 if (current_context) |
195 current_context->ReleaseCurrent(NULL); | 204 current_context->ReleaseCurrent(NULL); |
196 | 205 |
197 did_swap_buffer_ = false; | 206 did_swap_buffer_ = false; |
198 | 207 |
199 InvokeComposite(transform, damage_area); | 208 gfx::Transform adjusted_transform = transform; |
| 209 AdjustTransformForClip(&adjusted_transform, clip); |
| 210 surface_size_ = surface_size; |
| 211 client_->SetExternalDrawConstraints(adjusted_transform, clip); |
| 212 InvokeComposite(clip.size()); |
200 | 213 |
201 return did_swap_buffer_; | 214 return did_swap_buffer_; |
202 } | 215 } |
203 | 216 |
204 void SynchronousCompositorOutputSurface::InvokeComposite( | 217 void SynchronousCompositorOutputSurface::InvokeComposite( |
205 const gfx::Transform& transform, | 218 gfx::Size damage_size) { |
206 gfx::Rect damage_area) { | 219 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); |
207 // TODO(boliu): This assumes |transform| is identity and |damage_area| is the | |
208 // whole view. Tracking bug to implement this: crbug.com/230463. | |
209 client_->SetNeedsRedrawRect(damage_area); | |
210 if (needs_begin_frame_) | 220 if (needs_begin_frame_) |
211 client_->BeginFrame(base::TimeTicks::Now()); | 221 client_->BeginFrame(base::TimeTicks::Now()); |
212 } | 222 } |
213 | 223 |
214 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 224 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
215 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 225 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
216 // thread. | 226 // thread. |
217 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 227 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
218 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 228 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
219 } | 229 } |
220 | 230 |
221 SynchronousCompositorOutputSurfaceDelegate* | 231 SynchronousCompositorOutputSurfaceDelegate* |
222 SynchronousCompositorOutputSurface::GetDelegate() { | 232 SynchronousCompositorOutputSurface::GetDelegate() { |
223 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 233 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
224 } | 234 } |
225 | 235 |
226 } // namespace content | 236 } // namespace content |
OLD | NEW |