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

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

Issue 22277004: Add gfx::SurfaceFactoryWebview (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: InProcessContext takes attrib struct Created 7 years, 4 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/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "cc/output/begin_frame_args.h" 9 #include "cc/output/begin_frame_args.h"
10 #include "cc/output/compositor_frame.h" 10 #include "cc/output/compositor_frame.h"
11 #include "cc/output/context_provider.h" 11 #include "cc/output/context_provider.h"
12 #include "cc/output/managed_memory_policy.h" 12 #include "cc/output/managed_memory_policy.h"
13 #include "cc/output/output_surface_client.h" 13 #include "cc/output/output_surface_client.h"
14 #include "cc/output/software_output_device.h" 14 #include "cc/output/software_output_device.h"
15 #include "content/browser/android/in_process/synchronous_compositor_impl.h" 15 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 16 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "gpu/command_buffer/client/gl_in_process_context.h"
18 #include "third_party/skia/include/core/SkCanvas.h" 19 #include "third_party/skia/include/core/SkCanvas.h"
19 #include "third_party/skia/include/core/SkDevice.h" 20 #include "third_party/skia/include/core/SkDevice.h"
20 #include "ui/gfx/rect_conversions.h" 21 #include "ui/gfx/rect_conversions.h"
21 #include "ui/gfx/skia_util.h" 22 #include "ui/gfx/skia_util.h"
22 #include "ui/gfx/transform.h" 23 #include "ui/gfx/transform.h"
23 #include "ui/gl/gl_context.h" 24 #include "ui/gl/gl_surface.h"
24 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h" 25 #include "webkit/common/gpu/webgraphicscontext3d_in_process_command_buffer_impl. h"
25 26
26 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
27 27
28 namespace content { 28 namespace content {
29 29
30 namespace { 30 namespace {
31 31
32 // TODO(boliu): RenderThreadImpl should create in process contexts as well. 32 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D(
33 scoped_ptr<WebKit::WebGraphicsContext3D> CreateWebGraphicsContext3D() { 33 scoped_refptr<gfx::GLSurface> surface) {
34 using webkit::gpu::WebGraphicsContext3DInProcessCommandBufferImpl;
35 if (!gfx::GLSurface::InitializeOneOff())
36 scoped_ptr<WebKit::WebGraphicsContext3D>();
no sievers 2013/08/07 01:52:38 return
boliu 2013/08/07 02:58:48 Done.
37
38 const bool offscreen = false;
39 const gfx::Size size(1, 1);
40 const char* allowed_extensions = "*";
41 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
42
34 WebKit::WebGraphicsContext3D::Attributes attributes; 43 WebKit::WebGraphicsContext3D::Attributes attributes;
35 attributes.antialias = false; 44 attributes.antialias = false;
36 attributes.shareResources = true; 45 attributes.shareResources = true;
37 attributes.noAutomaticFlushes = true; 46 attributes.noAutomaticFlushes = true;
38 47
48 gpu::GLInProcessContextAttribs in_process_attribs;
49 WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
50 attributes, &in_process_attribs);
51 scoped_ptr<gpu::GLInProcessContext> context(
52 gpu::GLInProcessContext::CreateWithSurface(surface,
53 offscreen,
54 size,
55 attributes.shareResources,
56 allowed_extensions,
57 in_process_attribs,
58 gpu_preference));
59
60 if (!context.get())
61 scoped_ptr<WebKit::WebGraphicsContext3D>();
no sievers 2013/08/07 01:52:38 return
boliu 2013/08/07 02:58:48 Done.
62
39 return scoped_ptr<WebKit::WebGraphicsContext3D>( 63 return scoped_ptr<WebKit::WebGraphicsContext3D>(
40 WebGraphicsContext3DInProcessCommandBufferImpl 64 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
41 ::CreateViewContext(attributes, NULL)); 65 context.Pass(), attributes));
42 } 66 }
43 67
44 void DidActivatePendingTree(int routing_id) { 68 void DidActivatePendingTree(int routing_id) {
45 SynchronousCompositorOutputSurfaceDelegate* delegate = 69 SynchronousCompositorOutputSurfaceDelegate* delegate =
46 SynchronousCompositorImpl::FromRoutingID(routing_id); 70 SynchronousCompositorImpl::FromRoutingID(routing_id);
47 if (delegate) 71 if (delegate)
48 delegate->DidActivatePendingTree(); 72 delegate->DidActivatePendingTree();
49 } 73 }
50 74
51 } // namespace 75 } // namespace
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 193
170 namespace { 194 namespace {
171 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { 195 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) {
172 // The system-provided transform translates us from the screen origin to the 196 // The system-provided transform translates us from the screen origin to the
173 // origin of the clip rect, but CC's draw origin starts at the clip. 197 // origin of the clip rect, but CC's draw origin starts at the clip.
174 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); 198 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0);
175 } 199 }
176 } // namespace 200 } // namespace
177 201
178 bool SynchronousCompositorOutputSurface::InitializeHwDraw( 202 bool SynchronousCompositorOutputSurface::InitializeHwDraw(
203 scoped_refptr<gfx::GLSurface> surface,
179 scoped_refptr<cc::ContextProvider> offscreen_context) { 204 scoped_refptr<cc::ContextProvider> offscreen_context) {
180 DCHECK(CalledOnValidThread()); 205 DCHECK(CalledOnValidThread());
181 DCHECK(HasClient()); 206 DCHECK(HasClient());
182 DCHECK(!context3d_); 207 DCHECK(!context3d_);
208 DCHECK(surface);
183 209
184 return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(), 210 return InitializeAndSetContext3D(
185 offscreen_context); 211 CreateWebGraphicsContext3D(surface).Pass(), offscreen_context);
186 } 212 }
187 213
188 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { 214 void SynchronousCompositorOutputSurface::ReleaseHwDraw() {
189 cc::OutputSurface::ReleaseGL(); 215 cc::OutputSurface::ReleaseGL();
190 } 216 }
191 217
192 bool SynchronousCompositorOutputSurface::DemandDrawHw( 218 bool SynchronousCompositorOutputSurface::DemandDrawHw(
193 gfx::Size surface_size, 219 gfx::Size surface_size,
194 const gfx::Transform& transform, 220 const gfx::Transform& transform,
195 gfx::Rect clip, 221 gfx::Rect clip,
196 bool stencil_enabled) { 222 bool stencil_enabled) {
197 DCHECK(CalledOnValidThread()); 223 DCHECK(CalledOnValidThread());
198 DCHECK(HasClient()); 224 DCHECK(HasClient());
199 DCHECK(context3d()); 225 DCHECK(context3d());
200 226
201 gfx::Transform adjusted_transform = transform; 227 gfx::Transform adjusted_transform = transform;
202 AdjustTransformForClip(&adjusted_transform, clip); 228 AdjustTransformForClip(&adjusted_transform, clip);
203 surface_size_ = surface_size; 229 surface_size_ = surface_size;
204 SetExternalDrawConstraints(adjusted_transform, clip); 230 SetExternalDrawConstraints(adjusted_transform, clip);
205 SetExternalStencilTest(stencil_enabled); 231 SetExternalStencilTest(stencil_enabled);
206 InvokeComposite(clip.size()); 232 InvokeComposite(clip.size());
207 233
208 // TODO(boliu): Check if context is lost here.
209
210 return did_swap_buffer_; 234 return did_swap_buffer_;
211 } 235 }
212 236
213 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 237 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
214 DCHECK(CalledOnValidThread()); 238 DCHECK(CalledOnValidThread());
215 DCHECK(canvas); 239 DCHECK(canvas);
216 DCHECK(!current_sw_canvas_); 240 DCHECK(!current_sw_canvas_);
217 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas); 241 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
218 242
219 SkIRect canvas_clip; 243 SkIRect canvas_clip;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 282 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
259 return BrowserThread::CurrentlyOn(BrowserThread::UI); 283 return BrowserThread::CurrentlyOn(BrowserThread::UI);
260 } 284 }
261 285
262 SynchronousCompositorOutputSurfaceDelegate* 286 SynchronousCompositorOutputSurfaceDelegate*
263 SynchronousCompositorOutputSurface::GetDelegate() { 287 SynchronousCompositorOutputSurface::GetDelegate() {
264 return SynchronousCompositorImpl::FromRoutingID(routing_id_); 288 return SynchronousCompositorImpl::FromRoutingID(routing_id_);
265 } 289 }
266 290
267 } // namespace content 291 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698