| 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 void SynchronousCompositorOutputSurface::Reshape( | 119 void SynchronousCompositorOutputSurface::Reshape( |
| 120 gfx::Size size, float scale_factor) { | 120 gfx::Size size, float scale_factor) { |
| 121 // Intentional no-op: surface size is controlled by the embedder. | 121 // Intentional no-op: surface size is controlled by the embedder. |
| 122 } | 122 } |
| 123 | 123 |
| 124 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( | 124 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( |
| 125 bool enable) { | 125 bool enable) { |
| 126 DCHECK(CalledOnValidThread()); | 126 DCHECK(CalledOnValidThread()); |
| 127 cc::OutputSurface::SetNeedsBeginFrame(enable); |
| 127 needs_begin_frame_ = enable; | 128 needs_begin_frame_ = enable; |
| 128 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 129 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 129 if (delegate) | 130 if (delegate) |
| 130 delegate->SetContinuousInvalidate(needs_begin_frame_); | 131 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void SynchronousCompositorOutputSurface::SwapBuffers( | 134 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 134 cc::CompositorFrame* frame) { | 135 cc::CompositorFrame* frame) { |
| 135 if (!ForcedDrawToSoftwareDevice()) { | 136 if (!ForcedDrawToSoftwareDevice()) { |
| 136 DCHECK(context3d()); | 137 DCHECK(context3d()); |
| 137 context3d()->shallowFlushCHROMIUM(); | 138 context3d()->shallowFlushCHROMIUM(); |
| 138 } | 139 } |
| 139 // TODO(joth): Route page scale to the client, see http://crbug.com/237006 | 140 // TODO(joth): Route page scale to the client, see http://crbug.com/237006 |
| 140 did_swap_buffer_ = true; | 141 did_swap_buffer_ = true; |
| 142 DidSwapBuffers(); |
| 141 } | 143 } |
| 142 | 144 |
| 143 namespace { | 145 namespace { |
| 144 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { | 146 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { |
| 145 // The system-provided transform translates us from the screen origin to the | 147 // The system-provided transform translates us from the screen origin to the |
| 146 // origin of the clip rect, but CC's draw origin starts at the clip. | 148 // origin of the clip rect, but CC's draw origin starts at the clip. |
| 147 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); | 149 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); |
| 148 } | 150 } |
| 149 } // namespace | 151 } // namespace |
| 150 | 152 |
| 151 bool SynchronousCompositorOutputSurface::InitializeHwDraw() { | 153 bool SynchronousCompositorOutputSurface::InitializeHwDraw() { |
| 152 DCHECK(CalledOnValidThread()); | 154 DCHECK(CalledOnValidThread()); |
| 153 DCHECK(client_); | 155 DCHECK(HasClient()); |
| 154 DCHECK(!context3d_); | 156 DCHECK(!context3d_); |
| 155 | 157 |
| 156 // TODO(boliu): Get a context provider in constructor and pass here. | 158 // TODO(boliu): Get a context provider in constructor and pass here. |
| 157 return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(), | 159 return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(), |
| 158 scoped_refptr<cc::ContextProvider>()); | 160 scoped_refptr<cc::ContextProvider>()); |
| 159 } | 161 } |
| 160 | 162 |
| 161 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 163 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
| 162 gfx::Size surface_size, | 164 gfx::Size surface_size, |
| 163 const gfx::Transform& transform, | 165 const gfx::Transform& transform, |
| 164 gfx::Rect clip) { | 166 gfx::Rect clip) { |
| 165 DCHECK(CalledOnValidThread()); | 167 DCHECK(CalledOnValidThread()); |
| 166 DCHECK(client_); | 168 DCHECK(HasClient()); |
| 167 DCHECK(context3d()); | 169 DCHECK(context3d()); |
| 168 | 170 |
| 169 // Force a GL state restore next time a GLContextVirtual is made current. | 171 // Force a GL state restore next time a GLContextVirtual is made current. |
| 170 // TODO(boliu): Move this to the end of this function after we have fixed | 172 // TODO(boliu): Move this to the end of this function after we have fixed |
| 171 // all cases of MakeCurrent calls outside of draws. Tracked in | 173 // all cases of MakeCurrent calls outside of draws. Tracked in |
| 172 // crbug.com/239856. | 174 // crbug.com/239856. |
| 173 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); | 175 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); |
| 174 if (current_context) | 176 if (current_context) |
| 175 current_context->ReleaseCurrent(NULL); | 177 current_context->ReleaseCurrent(NULL); |
| 176 | 178 |
| 177 gfx::Transform adjusted_transform = transform; | 179 gfx::Transform adjusted_transform = transform; |
| 178 AdjustTransformForClip(&adjusted_transform, clip); | 180 AdjustTransformForClip(&adjusted_transform, clip); |
| 179 surface_size_ = surface_size; | 181 surface_size_ = surface_size; |
| 180 client_->SetExternalDrawConstraints(adjusted_transform, clip); | 182 SetExternalDrawConstraints(adjusted_transform, clip); |
| 181 InvokeComposite(clip.size()); | 183 InvokeComposite(clip.size()); |
| 182 | 184 |
| 183 // TODO(boliu): Check if context is lost here. | 185 // TODO(boliu): Check if context is lost here. |
| 184 | 186 |
| 185 return did_swap_buffer_; | 187 return did_swap_buffer_; |
| 186 } | 188 } |
| 187 | 189 |
| 188 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { | 190 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { |
| 189 DCHECK(CalledOnValidThread()); | 191 DCHECK(CalledOnValidThread()); |
| 190 DCHECK(canvas); | 192 DCHECK(canvas); |
| 191 DCHECK(!current_sw_canvas_); | 193 DCHECK(!current_sw_canvas_); |
| 192 current_sw_canvas_ = canvas; | 194 current_sw_canvas_ = canvas; |
| 193 | 195 |
| 194 SkIRect canvas_clip; | 196 SkIRect canvas_clip; |
| 195 canvas->getClipDeviceBounds(&canvas_clip); | 197 canvas->getClipDeviceBounds(&canvas_clip); |
| 196 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); | 198 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); |
| 197 | 199 |
| 198 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 200 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 199 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 201 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 200 AdjustTransformForClip(&transform, clip); | 202 AdjustTransformForClip(&transform, clip); |
| 201 | 203 |
| 202 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), | 204 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), |
| 203 canvas->getDeviceSize().height()); | 205 canvas->getDeviceSize().height()); |
| 204 client_->SetExternalDrawConstraints(transform, clip); | 206 SetExternalDrawConstraints(transform, clip); |
| 205 | 207 |
| 206 InvokeComposite(clip.size()); | 208 InvokeComposite(clip.size()); |
| 207 | 209 |
| 208 current_sw_canvas_ = NULL; | 210 current_sw_canvas_ = NULL; |
| 209 return did_swap_buffer_; | 211 return did_swap_buffer_; |
| 210 } | 212 } |
| 211 | 213 |
| 212 void SynchronousCompositorOutputSurface::InvokeComposite( | 214 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 213 gfx::Size damage_size) { | 215 gfx::Size damage_size) { |
| 214 did_swap_buffer_ = false; | 216 did_swap_buffer_ = false; |
| 215 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); | 217 SetNeedsRedrawRect(gfx::Rect(damage_size)); |
| 216 if (needs_begin_frame_) | 218 if (needs_begin_frame_) |
| 217 client_->BeginFrame(base::TimeTicks::Now()); | 219 BeginFrame(base::TimeTicks::Now()); |
| 218 | 220 |
| 219 if (did_swap_buffer_) | 221 if (did_swap_buffer_) |
| 220 client_->OnSwapBuffersComplete(NULL); | 222 OnSwapBuffersComplete(NULL); |
| 221 } | 223 } |
| 222 | 224 |
| 223 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 225 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 224 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 226 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 225 // thread. | 227 // thread. |
| 226 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 228 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 227 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 229 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 228 } | 230 } |
| 229 | 231 |
| 230 SynchronousCompositorOutputSurfaceDelegate* | 232 SynchronousCompositorOutputSurfaceDelegate* |
| 231 SynchronousCompositorOutputSurface::GetDelegate() { | 233 SynchronousCompositorOutputSurface::GetDelegate() { |
| 232 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 234 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 233 } | 235 } |
| 234 | 236 |
| 235 } // namespace content | 237 } // namespace content |
| OLD | NEW |