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

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: fix clang build 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 return scoped_ptr<WebKit::WebGraphicsContext3D>();
37
38 const char* allowed_extensions = "*";
39 const gfx::GpuPreference gpu_preference = gfx::PreferDiscreteGpu;
40
34 WebKit::WebGraphicsContext3D::Attributes attributes; 41 WebKit::WebGraphicsContext3D::Attributes attributes;
35 attributes.antialias = false; 42 attributes.antialias = false;
36 attributes.shareResources = true; 43 attributes.shareResources = true;
37 attributes.noAutomaticFlushes = true; 44 attributes.noAutomaticFlushes = true;
38 45
46 gpu::GLInProcessContextAttribs in_process_attribs;
47 WebGraphicsContext3DInProcessCommandBufferImpl::ConvertAttributes(
48 attributes, &in_process_attribs);
49 scoped_ptr<gpu::GLInProcessContext> context(
50 gpu::GLInProcessContext::CreateWithSurface(surface,
51 attributes.shareResources,
52 allowed_extensions,
53 in_process_attribs,
54 gpu_preference));
55
56 if (!context.get())
57 return scoped_ptr<WebKit::WebGraphicsContext3D>();
58
39 return scoped_ptr<WebKit::WebGraphicsContext3D>( 59 return scoped_ptr<WebKit::WebGraphicsContext3D>(
40 WebGraphicsContext3DInProcessCommandBufferImpl 60 WebGraphicsContext3DInProcessCommandBufferImpl::WrapContext(
41 ::CreateViewContext(attributes, NULL)); 61 context.Pass(), attributes));
42 } 62 }
43 63
44 void DidActivatePendingTree(int routing_id) { 64 void DidActivatePendingTree(int routing_id) {
45 SynchronousCompositorOutputSurfaceDelegate* delegate = 65 SynchronousCompositorOutputSurfaceDelegate* delegate =
46 SynchronousCompositorImpl::FromRoutingID(routing_id); 66 SynchronousCompositorImpl::FromRoutingID(routing_id);
47 if (delegate) 67 if (delegate)
48 delegate->DidActivatePendingTree(); 68 delegate->DidActivatePendingTree();
49 } 69 }
50 70
51 } // namespace 71 } // namespace
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 189
170 namespace { 190 namespace {
171 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) { 191 void AdjustTransformForClip(gfx::Transform* transform, gfx::Rect clip) {
172 // The system-provided transform translates us from the screen origin to the 192 // 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. 193 // origin of the clip rect, but CC's draw origin starts at the clip.
174 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0); 194 transform->matrix().postTranslate(-clip.x(), -clip.y(), 0);
175 } 195 }
176 } // namespace 196 } // namespace
177 197
178 bool SynchronousCompositorOutputSurface::InitializeHwDraw( 198 bool SynchronousCompositorOutputSurface::InitializeHwDraw(
199 scoped_refptr<gfx::GLSurface> surface,
179 scoped_refptr<cc::ContextProvider> offscreen_context) { 200 scoped_refptr<cc::ContextProvider> offscreen_context) {
180 DCHECK(CalledOnValidThread()); 201 DCHECK(CalledOnValidThread());
181 DCHECK(HasClient()); 202 DCHECK(HasClient());
182 DCHECK(!context3d_); 203 DCHECK(!context3d_);
204 DCHECK(surface);
183 205
184 return InitializeAndSetContext3D(CreateWebGraphicsContext3D().Pass(), 206 return InitializeAndSetContext3D(
185 offscreen_context); 207 CreateWebGraphicsContext3D(surface).Pass(), offscreen_context);
186 } 208 }
187 209
188 void SynchronousCompositorOutputSurface::ReleaseHwDraw() { 210 void SynchronousCompositorOutputSurface::ReleaseHwDraw() {
189 cc::OutputSurface::ReleaseGL(); 211 cc::OutputSurface::ReleaseGL();
190 } 212 }
191 213
192 bool SynchronousCompositorOutputSurface::DemandDrawHw( 214 bool SynchronousCompositorOutputSurface::DemandDrawHw(
193 gfx::Size surface_size, 215 gfx::Size surface_size,
194 const gfx::Transform& transform, 216 const gfx::Transform& transform,
195 gfx::Rect clip, 217 gfx::Rect clip,
196 bool stencil_enabled) { 218 bool stencil_enabled) {
197 DCHECK(CalledOnValidThread()); 219 DCHECK(CalledOnValidThread());
198 DCHECK(HasClient()); 220 DCHECK(HasClient());
199 DCHECK(context3d()); 221 DCHECK(context3d());
200 222
201 gfx::Transform adjusted_transform = transform; 223 gfx::Transform adjusted_transform = transform;
202 AdjustTransformForClip(&adjusted_transform, clip); 224 AdjustTransformForClip(&adjusted_transform, clip);
203 surface_size_ = surface_size; 225 surface_size_ = surface_size;
204 SetExternalDrawConstraints(adjusted_transform, clip); 226 SetExternalDrawConstraints(adjusted_transform, clip);
205 SetExternalStencilTest(stencil_enabled); 227 SetExternalStencilTest(stencil_enabled);
206 InvokeComposite(clip.size()); 228 InvokeComposite(clip.size());
207 229
208 // TODO(boliu): Check if context is lost here.
209
210 return did_swap_buffer_; 230 return did_swap_buffer_;
211 } 231 }
212 232
213 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) { 233 bool SynchronousCompositorOutputSurface::DemandDrawSw(SkCanvas* canvas) {
214 DCHECK(CalledOnValidThread()); 234 DCHECK(CalledOnValidThread());
215 DCHECK(canvas); 235 DCHECK(canvas);
216 DCHECK(!current_sw_canvas_); 236 DCHECK(!current_sw_canvas_);
217 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas); 237 base::AutoReset<SkCanvas*> canvas_resetter(&current_sw_canvas_, canvas);
218 238
219 SkIRect canvas_clip; 239 SkIRect canvas_clip;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const { 278 bool SynchronousCompositorOutputSurface::CalledOnValidThread() const {
259 return BrowserThread::CurrentlyOn(BrowserThread::UI); 279 return BrowserThread::CurrentlyOn(BrowserThread::UI);
260 } 280 }
261 281
262 SynchronousCompositorOutputSurfaceDelegate* 282 SynchronousCompositorOutputSurfaceDelegate*
263 SynchronousCompositorOutputSurface::GetDelegate() { 283 SynchronousCompositorOutputSurface::GetDelegate() {
264 return SynchronousCompositorImpl::FromRoutingID(routing_id_); 284 return SynchronousCompositorImpl::FromRoutingID(routing_id_);
265 } 285 }
266 286
267 } // namespace content 287 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698