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

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

Issue 15836005: cc: Emulate BeginFrame in OutputSurfaces that don't support it natively (Closed) Base URL: http://git.chromium.org/chromium/src.git@nofrc
Patch Set: Fix PRId64 for Windows 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
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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
150 150
151 bool SynchronousCompositorOutputSurface::InitializeHwDraw() { 151 bool SynchronousCompositorOutputSurface::InitializeHwDraw() {
152 DCHECK(CalledOnValidThread()); 152 DCHECK(CalledOnValidThread());
153 DCHECK(client_); 153 DCHECK(HasClient());
154 DCHECK(!context3d_); 154 DCHECK(!context3d_);
155 155
156 // TODO(boliu): Get a context provider in constructor and pass here. 156 // TODO(boliu): Get a context provider in constructor and pass here.
157 return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(), 157 return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(),
158 scoped_refptr<cc::ContextProvider>()); 158 scoped_refptr<cc::ContextProvider>());
159 } 159 }
160 160
161 bool SynchronousCompositorOutputSurface::DemandDrawHw( 161 bool SynchronousCompositorOutputSurface::DemandDrawHw(
162 gfx::Size surface_size, 162 gfx::Size surface_size,
163 const gfx::Transform& transform, 163 const gfx::Transform& transform,
164 gfx::Rect clip) { 164 gfx::Rect clip) {
165 DCHECK(CalledOnValidThread()); 165 DCHECK(CalledOnValidThread());
166 DCHECK(client_); 166 DCHECK(HasClient());
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 gfx::Transform adjusted_transform = transform; 177 gfx::Transform adjusted_transform = transform;
178 AdjustTransformForClip(&adjusted_transform, clip); 178 AdjustTransformForClip(&adjusted_transform, clip);
179 surface_size_ = surface_size; 179 surface_size_ = surface_size;
180 client_->SetExternalDrawConstraints(adjusted_transform, clip); 180 SetExternalDrawConstraints(adjusted_transform, clip);
181 InvokeComposite(clip.size()); 181 InvokeComposite(clip.size());
182 182
183 // TODO(boliu): Check if context is lost here. 183 // TODO(boliu): Check if context is lost here.
184 184
185 return did_swap_buffer_; 185 return did_swap_buffer_;
186 } 186 }
187 187
188 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 188 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
189 DCHECK(CalledOnValidThread()); 189 DCHECK(CalledOnValidThread());
190 DCHECK(canvas); 190 DCHECK(canvas);
191 DCHECK(!current_sw_canvas_); 191 DCHECK(!current_sw_canvas_);
192 current_sw_canvas_ = canvas; 192 current_sw_canvas_ = canvas;
193 193
194 SkIRect canvas_clip; 194 SkIRect canvas_clip;
195 canvas->getClipDeviceBounds(&canvas_clip); 195 canvas->getClipDeviceBounds(&canvas_clip);
196 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip); 196 gfx::Rect clip = gfx::SkIRectToRect(canvas_clip);
197 197
198 gfx::Transform transform(gfx::Transform::kSkipInitialization); 198 gfx::Transform transform(gfx::Transform::kSkipInitialization);
199 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4. 199 transform.matrix() = canvas->getTotalMatrix(); // Converts 3x3 matrix to 4x4.
200 AdjustTransformForClip(&transform, clip); 200 AdjustTransformForClip(&transform, clip);
201 201
202 surface_size_ = gfx::Size(canvas->getDeviceSize().width(), 202 surface_size_ = gfx::Size(canvas->getDeviceSize().width(),
203 canvas->getDeviceSize().height()); 203 canvas->getDeviceSize().height());
204 client_->SetExternalDrawConstraints(transform, clip); 204 SetExternalDrawConstraints(transform, clip);
205 205
206 InvokeComposite(clip.size()); 206 InvokeComposite(clip.size());
207 207
208 current_sw_canvas_ = NULL; 208 current_sw_canvas_ = NULL;
209 return did_swap_buffer_; 209 return did_swap_buffer_;
210 } 210 }
211 211
212 void SynchronousCompositorOutputSurface::InvokeComposite( 212 void SynchronousCompositorOutputSurface::InvokeComposite(
213 gfx::Size damage_size) { 213 gfx::Size damage_size) {
214 did_swap_buffer_ = false; 214 did_swap_buffer_ = false;
215 client_->SetNeedsRedrawRect(gfx::Rect(damage_size)); 215 SetNeedsRedrawRect(gfx::Rect(damage_size));
216 if (needs_begin_frame_) 216 if (needs_begin_frame_)
217 client_->BeginFrame(base::TimeTicks::Now()); 217 BeginFrame(base::TimeTicks::Now());
218 218
219 if (did_swap_buffer_) 219 if (did_swap_buffer_)
220 client_->OnSwapBuffersComplete(NULL); 220 OnSwapBuffersComplete(NULL);
221 } 221 }
222 222
223 // 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
224 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI 224 // requirement: SynchronousCompositorOutputSurface() must only be used on the UI
225 // thread. 225 // thread.
226 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 226 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
227 return BrowserThread::CurrentlyOn(BrowserThread::UI); 227 return BrowserThread::CurrentlyOn(BrowserThread::UI);
228 } 228 }
229 229
230 SynchronousCompositorOutputSurfaceDelegate* 230 SynchronousCompositorOutputSurfaceDelegate*
231 SynchronousCompositorOutputSurface::GetDelegate() { 231 SynchronousCompositorOutputSurface::GetDelegate() {
232 return SynchronousCompositorImpl::FromRoutingID(routing_id_); 232 return SynchronousCompositorImpl::FromRoutingID(routing_id_);
233 } 233 }
234 234
235 } // namespace content 235 } // namespace content
OLDNEW
« no previous file with comments | « chrome/test/perf/rendering/latency_tests.cc ('k') | content/browser/renderer_host/image_transport_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698