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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 public: | 52 public: |
53 SoftwareDevice(SynchronousCompositorOutputSurface* surface) | 53 SoftwareDevice(SynchronousCompositorOutputSurface* surface) |
54 : surface_(surface), | 54 : surface_(surface), |
55 null_device_(SkBitmap::kARGB_8888_Config, 1, 1), | 55 null_device_(SkBitmap::kARGB_8888_Config, 1, 1), |
56 null_canvas_(&null_device_) { | 56 null_canvas_(&null_device_) { |
57 } | 57 } |
58 virtual void Resize(gfx::Size size) OVERRIDE { | 58 virtual void Resize(gfx::Size size) OVERRIDE { |
59 // Intentional no-op: canvas size is controlled by the embedder. | 59 // Intentional no-op: canvas size is controlled by the embedder. |
60 } | 60 } |
61 virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE { | 61 virtual SkCanvas* BeginPaint(gfx::Rect damage_rect) OVERRIDE { |
62 DCHECK(surface_->current_sw_canvas_); | 62 if (!surface_->current_sw_canvas_) { |
63 if (surface_->current_sw_canvas_) | 63 NOTREACHED() << "BeginPaint with no canvas set"; |
64 return surface_->current_sw_canvas_; | 64 return &null_canvas_; |
65 return &null_canvas_; | 65 } |
66 LOG_IF(WARNING, surface_->did_swap_buffer_) | |
67 << "Mutliple calls to BeginPaint per frame"; | |
68 return surface_->current_sw_canvas_; | |
66 } | 69 } |
67 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE { | 70 virtual void EndPaint(cc::SoftwareFrameData* frame_data) OVERRIDE { |
68 surface_->current_sw_canvas_ = NULL; | |
69 } | 71 } |
70 virtual void CopyToBitmap(gfx::Rect rect, SkBitmap* output) OVERRIDE { | 72 virtual void CopyToBitmap(gfx::Rect rect, SkBitmap* output) OVERRIDE { |
71 NOTIMPLEMENTED(); | 73 NOTIMPLEMENTED(); |
72 } | 74 } |
73 | 75 |
74 private: | 76 private: |
75 SynchronousCompositorOutputSurface* surface_; | 77 SynchronousCompositorOutputSurface* surface_; |
76 SkDevice null_device_; | 78 SkDevice null_device_; |
77 SkCanvas null_canvas_; | 79 SkCanvas null_canvas_; |
78 | 80 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 if (delegate) | 114 if (delegate) |
113 delegate->DidBindOutputSurface(this); | 115 delegate->DidBindOutputSurface(this); |
114 return true; | 116 return true; |
115 } | 117 } |
116 | 118 |
117 void SynchronousCompositorOutputSurface::Reshape( | 119 void SynchronousCompositorOutputSurface::Reshape( |
118 gfx::Size size, float scale_factor) { | 120 gfx::Size size, float scale_factor) { |
119 // Intentional no-op: surface size is controlled by the embedder. | 121 // Intentional no-op: surface size is controlled by the embedder. |
120 } | 122 } |
121 | 123 |
122 void SynchronousCompositorOutputSurface::SendFrameToParentCompositor( | |
123 cc::CompositorFrame* frame) { | |
124 NOTREACHED(); | |
125 // TODO(joth): Route page scale to the client, see http://crbug.com/237006 | |
126 } | |
127 | |
128 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( | 124 void SynchronousCompositorOutputSurface::SetNeedsBeginFrame( |
129 bool enable) { | 125 bool enable) { |
130 DCHECK(CalledOnValidThread()); | 126 DCHECK(CalledOnValidThread()); |
131 needs_begin_frame_ = enable; | 127 needs_begin_frame_ = enable; |
132 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); | 128 SynchronousCompositorOutputSurfaceDelegate* delegate = GetDelegate(); |
133 if (delegate) | 129 if (delegate) |
134 delegate->SetContinuousInvalidate(needs_begin_frame_); | 130 delegate->SetContinuousInvalidate(needs_begin_frame_); |
135 } | 131 } |
136 | 132 |
137 void SynchronousCompositorOutputSurface::SwapBuffers( | 133 void SynchronousCompositorOutputSurface::SwapBuffers( |
138 const ui::LatencyInfo& info) { | 134 cc::CompositorFrame* frame) { |
139 context3d()->shallowFlushCHROMIUM(); | 135 if (!ForcedDrawToSoftwareDevice()) { |
136 DCHECK(context3d()); | |
137 context3d()->shallowFlushCHROMIUM(); | |
138 } | |
140 did_swap_buffer_ = true; | 139 did_swap_buffer_ = true; |
joth
2013/06/10 18:43:32
// TODO(joth): Route page scale to the client, see
aelias_OOO_until_Jul13
2013/06/10 18:57:57
Done.
| |
141 } | 140 } |
142 | 141 |
143 namespace { | 142 namespace { |
144 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { | 143 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { |
145 // The system-provided transform translates us from the screen origin to the | 144 // 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. | 145 // origin of the clip rect, but CC's draw origin starts at the clip. |
147 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); | 146 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); |
148 } | 147 } |
149 } // namespace | 148 } // namespace |
150 | 149 |
(...skipping 16 matching lines...) Expand all Loading... | |
167 DCHECK(context3d()); | 166 DCHECK(context3d()); |
168 | 167 |
169 // Force a GL state restore next time a GLContextVirtual is made current. | 168 // 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 | 169 // 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 | 170 // all cases of MakeCurrent calls outside of draws. Tracked in |
172 // crbug.com/239856. | 171 // crbug.com/239856. |
173 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); | 172 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); |
174 if (current_context) | 173 if (current_context) |
175 current_context->ReleaseCurrent(NULL); | 174 current_context->ReleaseCurrent(NULL); |
176 | 175 |
177 did_swap_buffer_ = false; | |
178 | |
179 gfx::Transform adjusted_transform = transform; | 176 gfx::Transform adjusted_transform = transform; |
180 AdjustTransformForClip(&adjusted_transform, clip); | 177 AdjustTransformForClip(&adjusted_transform, clip); |
181 surface_size_ = surface_size; | 178 surface_size_ = surface_size; |
182 client_->SetExternalDrawConstraints(adjusted_transform, clip); | 179 client_->SetExternalDrawConstraints(adjusted_transform, clip); |
183 InvokeComposite(clip.size()); | 180 InvokeComposite(clip.size()); |
184 | 181 |
185 // TODO(boliu): Check if context is lost here. | 182 // TODO(boliu): Check if context is lost here. |
186 | 183 |
187 return did_swap_buffer_; | 184 return did_swap_buffer_; |
188 } | 185 } |
(...skipping 18 matching lines...) Expand all Loading... | |
207 | 204 |
208 InvokeComposite(clip.size()); | 205 InvokeComposite(clip.size()); |
209 | 206 |
210 bool finished_draw = current_sw_canvas_ == NULL; | 207 bool finished_draw = current_sw_canvas_ == NULL; |
211 current_sw_canvas_ = NULL; | 208 current_sw_canvas_ = NULL; |
212 return finished_draw; | 209 return finished_draw; |
213 } | 210 } |
214 | 211 |
215 void SynchronousCompositorOutputSurface::InvokeComposite( | 212 void SynchronousCompositorOutputSurface::InvokeComposite( |
216 gfx::Size damage_size) { | 213 gfx::Size damage_size) { |
214 did_swap_buffer_ = false; | |
217 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); | 215 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); |
218 if (needs_begin_frame_) | 216 if (needs_begin_frame_) |
219 client_->BeginFrame(base::TimeTicks::Now()); | 217 client_->BeginFrame(base::TimeTicks::Now()); |
218 | |
219 if (did_swap_buffer_) | |
220 client_->OnSwapBuffersComplete(NULL); | |
220 } | 221 } |
221 | 222 |
222 // Not using base::NonThreadSafe as we want to enforce a more exacting threading | 223 // Not using base::NonThreadSafe as we want to enforce a more exacting threading |
223 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI | 224 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI |
224 // thread. | 225 // thread. |
225 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { | 226 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { |
226 return BrowserThread::CurrentlyOn(BrowserThread::UI); | 227 return BrowserThread::CurrentlyOn(BrowserThread::UI); |
227 } | 228 } |
228 | 229 |
229 SynchronousCompositorOutputSurfaceDelegate* | 230 SynchronousCompositorOutputSurfaceDelegate* |
230 SynchronousCompositorOutputSurface::GetDelegate() { | 231 SynchronousCompositorOutputSurface::GetDelegate() { |
231 return SynchronousCompositorImpl::FromRoutingID(routing_id_); | 232 return SynchronousCompositorImpl::FromRoutingID(routing_id_); |
232 } | 233 } |
233 | 234 |
234 } // namespace content | 235 } // namespace content |
OLD | NEW |