| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 public: | 54 public: |
| 55 SoftwareDevice(SynchronousCompositorOutputSurface* surface) | 55 SoftwareDevice(SynchronousCompositorOutputSurface* surface) |
| 56 : surface_(surface), | 56 : surface_(surface), |
| 57 null_device_(SkBitmap::kARGB_8888_Config, 1, 1), | 57 null_device_(SkBitmap::kARGB_8888_Config, 1, 1), |
| 58 null_canvas_(&null_device_) { | 58 null_canvas_(&null_device_) { |
| 59 } | 59 } |
| 60 virtual void Resize(gfx::Size size) OVERRIDE { | 60 virtual void Resize(gfx::Size size) OVERRIDE { |
| 61 // Intentional no-op: canvas size is controlled by the embedder. | 61 // Intentional no-op: canvas size is controlled by the embedder. |
| 62 } | 62 } |
| 63 virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE { | 63 virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE { |
| 64 DCHECK(surface_->current_sw_canvas_); | 64 if (!surface_->current_sw_canvas_) { |
| 65 if (surface_->current_sw_canvas_) | 65 NOTREACHED() << "BeginPaint with no canvas set"; |
| 66 return surface_->current_sw_canvas_; | 66 return &null_canvas_; |
| 67 return &null_canvas_; | 67 } |
| 68 LOG_IF(WARNING, surface_->did_swap_buffer_) |
| 69 << "Mutliple calls to BeginPaint per frame"; |
| 70 return surface_->current_sw_canvas_; |
| 68 } | 71 } |
| 69 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE { | 72 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE { |
| 70 surface_->current_sw_canvas_ = NULL; | |
| 71 } | 73 } |
| 72 virtual void CopyToBitmap(gfx::Rect rect, SkBitmap* output) OVERRIDE { | 74 virtual void CopyToBitmap(gfx::Rect rect, SkBitmap* output) OVERRIDE { |
| 73 NOTIMPLEMENTED(); | 75 NOTIMPLEMENTED(); |
| 74 } | 76 } |
| 75 virtual void Scroll(gfx::Vector2d delta, | 77 virtual void Scroll(gfx::Vector2d delta, |
| 76 gfx::Rect clip_rect) OVERRIDE { | 78 gfx::Rect clip_rect) OVERRIDE { |
| 77 NOTIMPLEMENTED(); | 79 NOTIMPLEMENTED(); |
| 78 } | 80 } |
| 79 virtual void ReclaimDIB(const TransportDIB::Id& id) OVERRIDE { | 81 virtual void ReclaimDIB(const TransportDIB::Id& id) OVERRIDE { |
| 80 NOTIMPLEMENTED(); | 82 NOTIMPLEMENTED(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 bool enable) { | 141 bool enable) { |
| 140 DCHECK(CalledOnValidThread()); | 142 DCHECK(CalledOnValidThread()); |
| 141 needs_begin_frame_ = enable; | 143 needs_begin_frame_ = enable; |
| 142 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 144 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
| 143 if (delegate) | 145 if (delegate) |
| 144 delegate->SetContinuousInvalidate(needs_begin_frame_); | 146 delegate->SetContinuousInvalidate(needs_begin_frame_); |
| 145 } | 147 } |
| 146 | 148 |
| 147 void SynchronousCompositorOutputSurface::SwapBuffers( | 149 void SynchronousCompositorOutputSurface::SwapBuffers( |
| 148 const ui::LatencyInfo& info) { | 150 const ui::LatencyInfo& info) { |
| 149 context3d()->shallowFlushCHROMIUM(); | 151 if (!ForcedDrawToSoftwareDevice()) { |
| 152 DCHECK(context3d()); |
| 153 context3d()->shallowFlushCHROMIUM(); |
| 154 } |
| 150 did_swap_buffer_ = true; | 155 did_swap_buffer_ = true; |
| 151 } | 156 } |
| 152 | 157 |
| 153 bool SynchronousCompositorOutputSurface::IsHwReady() { | 158 bool SynchronousCompositorOutputSurface::IsHwReady() { |
| 154 return context3d() != NULL; | 159 return context3d() != NULL; |
| 155 } | 160 } |
| 156 | 161 |
| 157 namespace { | 162 namespace { |
| 158 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { | 163 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { |
| 159 // The system-provided transform translates us from the screen origin to the | 164 // The system-provided transform translates us from the screen origin to the |
| (...skipping 15 matching lines...) Expand all Loading... |
| 175 gfx::Transform transform(gfx::Transform::kSkipInitialization); | 180 gfx::Transform transform(gfx::Transform::kSkipInitialization); |
| 176 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. | 181 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. |
| 177 AdjustTransformForClip(&transform, clip); | 182 AdjustTransformForClip(&transform, clip); |
| 178 | 183 |
| 179 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), | 184 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), |
| 180 canvas->getDeviceSize().height()); | 185 canvas->getDeviceSize().height()); |
| 181 client_->SetExternalDrawConstraints(transform, clip); | 186 client_->SetExternalDrawConstraints(transform, clip); |
| 182 | 187 |
| 183 InvokeComposite(clip.size()); | 188 InvokeComposite(clip.size()); |
| 184 | 189 |
| 185 bool finished_draw = current_sw_canvas_ == NULL; | |
| 186 current_sw_canvas_ = NULL; | 190 current_sw_canvas_ = NULL; |
| 187 return finished_draw; | 191 return did_swap_buffer_; |
| 188 } | 192 } |
| 189 | 193 |
| 190 bool SynchronousCompositorOutputSurface::DemandDrawHw( | 194 bool SynchronousCompositorOutputSurface::DemandDrawHw( |
| 191 gfx::Size surface_size, | 195 gfx::Size surface_size, |
| 192 const gfx::Transform& transform, | 196 const gfx::Transform& transform, |
| 193 gfx::Rect clip) { | 197 gfx::Rect clip) { |
| 194 DCHECK(CalledOnValidThread()); | 198 DCHECK(CalledOnValidThread()); |
| 195 DCHECK(client_); | 199 DCHECK(client_); |
| 196 DCHECK(context3d()); | 200 DCHECK(context3d()); |
| 197 | 201 |
| 198 // Force a GL state restore next time a GLContextVirtual is made current. | 202 // Force a GL state restore next time a GLContextVirtual is made current. |
| 199 // TODO(boliu): Move this to the end of this function after we have fixed | 203 // TODO(boliu): Move this to the end of this function after we have fixed |
| 200 // all cases of MakeCurrent calls outside of draws. Tracked in | 204 // all cases of MakeCurrent calls outside of draws. Tracked in |
| 201 // crbug.com/239856. | 205 // crbug.com/239856. |
| 202 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); | 206 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); |
| 203 if (current_context) | 207 if (current_context) |
| 204 current_context->ReleaseCurrent(NULL); | 208 current_context->ReleaseCurrent(NULL); |
| 205 | 209 |
| 206 did_swap_buffer_ = false; | |
| 207 | |
| 208 gfx::Transform adjusted_transform = transform; | 210 gfx::Transform adjusted_transform = transform; |
| 209 AdjustTransformForClip(&adjusted_transform, clip); | 211 AdjustTransformForClip(&adjusted_transform, clip); |
| 210 surface_size_ = surface_size; | 212 surface_size_ = surface_size; |
| 211 client_->SetExternalDrawConstraints(adjusted_transform, clip); | 213 client_->SetExternalDrawConstraints(adjusted_transform, clip); |
| 212 InvokeComposite(clip.size()); | 214 InvokeComposite(clip.size()); |
| 213 | 215 |
| 214 return did_swap_buffer_; | 216 return did_swap_buffer_; |
| 215 } | 217 } |
| 216 | 218 |
| 217 void SynchronousCompositorOutputSurface::InvokeComposite( | 219 void SynchronousCompositorOutputSurface::InvokeComposite( |
| 218 gfx::Size damage_size) { | 220 gfx::Size damage_size) { |
| 221 did_swap_buffer_ = false; |
| 219 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); | 222 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); |
| 220 if (needs_begin_frame_) | 223 if (needs_begin_frame_) |
| 221 client_->BeginFrame(base::TimeTicks::Now()); | 224 client_->BeginFrame(base::TimeTicks::Now()); |
| 225 |
| 226 if (did_swap_buffer_) |
| 227 client_->OnSwapBuffersComplete(); |
| 222 } | 228 } |
| 223 | 229 |
| 224 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 230 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
| 225 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 231 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
| 226 // thread. | 232 // thread. |
| 227 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 233 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
| 228 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 234 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
| 229 } | 235 } |
| 230 | 236 |
| 231 SynchronousCompositorOutputSurfaceDelegate* | 237 SynchronousCompositorOutputSurfaceDelegate* |
| 232 SynchronousCompositorOutputSurface::GetDelegate() { | 238 SynchronousCompositorOutputSurface::GetDelegate() { |
| 233 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 239 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
| 234 } | 240 } |
| 235 | 241 |
| 236 } // namespace content | 242 } // namespace content |
| OLD | NEW |