Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: content/browser/android/in_process/synchronous_compositor_output_surface.cc

Issue 16304003: Unified OutputSurface::SwapBuffers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address joth's code review comments Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 }
139 // TODO(joth): Route page scale to the client, see http://crbug.com/237006
140 did_swap_buffer_ = true; 140 did_swap_buffer_ = true;
141 } 141 }
142 142
143 namespace { 143 namespace {
144 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { 144 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) {
145 // The system-provided transform translates us from the screen origin to the 145 // 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. 146 // origin of the clip rect, but CC's draw origin starts at the clip.
147 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); 147 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0);
148 } 148 }
149 } // namespace 149 } // namespace
(...skipping 17 matching lines...) Expand all
167 DCHECK(context3d()); 167 DCHECK(context3d());
168 168
169 // Force a GL state restore next time a GLContextVirtual is made current. 169 // 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 170 // 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 171 // all cases of MakeCurrent calls outside of draws. Tracked in
172 // crbug.com/239856. 172 // crbug.com/239856.
173 gfx::GLContext* current_context = gfx::GLContext::GetCurrent(); 173 gfx::GLContext* current_context = gfx::GLContext::GetCurrent();
174 if (current_context) 174 if (current_context)
175 current_context->ReleaseCurrent(NULL); 175 current_context->ReleaseCurrent(NULL);
176 176
177 did_swap_buffer_ = false;
178
179 gfx::Transform adjusted_transform = transform; 177 gfx::Transform adjusted_transform = transform;
180 AdjustTransformForClip(&adjusted_transform, clip); 178 AdjustTransformForClip(&adjusted_transform, clip);
181 surface_size_ = surface_size; 179 surface_size_ = surface_size;
182 client_->SetExternalDrawConstraints(adjusted_transform, clip); 180 client_->SetExternalDrawConstraints(adjusted_transform, clip);
183 InvokeComposite(clip.size()); 181 InvokeComposite(clip.size());
184 182
185 // TODO(boliu): Check if context is lost here. 183 // TODO(boliu): Check if context is lost here.
186 184
187 return did_swap_buffer_; 185 return did_swap_buffer_;
188 } 186 }
(...skipping 13 matching lines...) Expand all
202 AdjustTransformForClip(&transform, clip); 200 AdjustTransformForClip(&transform, clip);
203 201
204 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), 202 surface_size_ = gfx::Size(canvas->getDeviceSize().width(),
205 canvas->getDeviceSize().height()); 203 canvas->getDeviceSize().height());
206 client_->SetExternalDrawConstraints(transform, clip); 204 client_->SetExternalDrawConstraints(transform, clip);
207 205
208 InvokeComposite(clip.size()); 206 InvokeComposite(clip.size());
209 207
210 bool finished_draw = current_sw_canvas_ == NULL; 208 bool finished_draw = current_sw_canvas_ == NULL;
211 current_sw_canvas_ = NULL; 209 current_sw_canvas_ = NULL;
212 return finished_draw; 210 return finished_draw;
joth 2013/06/10 19:06:42 ah, need to return did_swap_buffer_ here now (so
aelias_OOO_until_Jul13 2013/06/10 19:19:04 Done.
213 } 211 }
214 212
215 void SynchronousCompositorOutputSurface::InvokeComposite( 213 void SynchronousCompositorOutputSurface::InvokeComposite(
216 gfx::Size damage_size) { 214 gfx::Size damage_size) {
215 did_swap_buffer_ = false;
217 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); 216 client_->SetNeedsRedrawRect(gfx::Rect(damage_size));
218 if (needs_begin_frame_) 217 if (needs_begin_frame_)
219 client_->BeginFrame(base::TimeTicks::Now()); 218 client_->BeginFrame(base::TimeTicks::Now());
219
220 if (did_swap_buffer_)
221 client_->OnSwapBuffersComplete(NULL);
220 } 222 }
221 223
222 // 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
223 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI 225 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI
224 // thread. 226 // thread.
225 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 227 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
226 return BrowserThread::CurrentlyOn(BrowserThread::UI); 228 return BrowserThread::CurrentlyOn(BrowserThread::UI);
227 } 229 }
228 230
229 SynchronousCompositorOutputSurfaceDelegate* 231 SynchronousCompositorOutputSurfaceDelegate*
230 SynchronousCompositorOutputSurface::GetDelegate() { 232 SynchronousCompositorOutputSurface::GetDelegate() {
231 return SynchronousCompositorImpl::FromRoutingID(routing_id_); 233 return SynchronousCompositorImpl::FromRoutingID(routing_id_);
232 } 234 }
233 235
234 } // namespace content 236 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698