OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #if defined(ENABLE_GPU) | 5 #if defined(ENABLE_GPU) |
6 | 6 |
7 #include "content/common/gpu/image_transport_surface.h" | 7 #include "content/common/gpu/image_transport_surface.h" |
8 | 8 |
9 #include "base/mac/scoped_cftyperef.h" | 9 #include "base/mac/scoped_cftyperef.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "content/common/gpu/gpu_messages.h" | 11 #include "content/common/gpu/gpu_messages.h" |
12 #include "ui/gfx/gl/gl_context.h" | 12 #include "ui/gfx/gl/gl_context.h" |
13 #include "ui/gfx/gl/gl_bindings.h" | 13 #include "ui/gfx/gl/gl_bindings.h" |
14 #include "ui/gfx/gl/gl_implementation.h" | 14 #include "ui/gfx/gl/gl_implementation.h" |
15 #include "ui/gfx/gl/gl_surface_cgl.h" | 15 #include "ui/gfx/gl/gl_surface_cgl.h" |
16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
17 #include "ui/gfx/surface/io_surface_support_mac.h" | 17 #include "ui/gfx/surface/io_surface_support_mac.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // We are backed by an offscreen surface for the purposes of creating | 21 // We are backed by an offscreen surface for the purposes of creating |
22 // a context, but use FBOs to render to texture backed IOSurface | 22 // a context, but use FBOs to render to texture backed IOSurface |
23 class IOSurfaceImageTransportSurface : public gfx::NoOpGLSurfaceCGL, | 23 class IOSurfaceImageTransportSurface : public gfx::NoOpGLSurfaceCGL, |
24 public ImageTransportSurface { | 24 public ImageTransportSurface { |
25 public: | 25 public: |
26 IOSurfaceImageTransportSurface(GpuChannelManager* manager, | 26 IOSurfaceImageTransportSurface(GpuChannelManager* manager, |
27 int32 render_view_id, | 27 GpuCommandBufferStub* stub, |
28 int32 client_id, | |
29 int32 command_buffer_id, | |
30 gfx::PluginWindowHandle handle); | 28 gfx::PluginWindowHandle handle); |
31 | 29 |
32 // GLSurface implementation | 30 // GLSurface implementation |
33 virtual bool Initialize() OVERRIDE; | 31 virtual bool Initialize() OVERRIDE; |
34 virtual void Destroy() OVERRIDE; | 32 virtual void Destroy() OVERRIDE; |
35 virtual bool IsOffscreen() OVERRIDE; | 33 virtual bool IsOffscreen() OVERRIDE; |
36 virtual bool SwapBuffers() OVERRIDE; | 34 virtual bool SwapBuffers() OVERRIDE; |
37 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 35 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
38 virtual std::string GetExtensions() OVERRIDE; | 36 virtual std::string GetExtensions() OVERRIDE; |
39 virtual gfx::Size GetSize() OVERRIDE; | 37 virtual gfx::Size GetSize() OVERRIDE; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 70 |
73 DISALLOW_COPY_AND_ASSIGN(IOSurfaceImageTransportSurface); | 71 DISALLOW_COPY_AND_ASSIGN(IOSurfaceImageTransportSurface); |
74 }; | 72 }; |
75 | 73 |
76 // We are backed by an offscreen surface for the purposes of creating | 74 // We are backed by an offscreen surface for the purposes of creating |
77 // a context, but use FBOs to render to texture backed IOSurface | 75 // a context, but use FBOs to render to texture backed IOSurface |
78 class TransportDIBImageTransportSurface : public gfx::NoOpGLSurfaceCGL, | 76 class TransportDIBImageTransportSurface : public gfx::NoOpGLSurfaceCGL, |
79 public ImageTransportSurface { | 77 public ImageTransportSurface { |
80 public: | 78 public: |
81 TransportDIBImageTransportSurface(GpuChannelManager* manager, | 79 TransportDIBImageTransportSurface(GpuChannelManager* manager, |
82 int32 render_view_id, | 80 GpuCommandBufferStub* stub, |
83 int32 client_id, | |
84 int32 command_buffer_id, | |
85 gfx::PluginWindowHandle handle); | 81 gfx::PluginWindowHandle handle); |
86 | 82 |
87 // GLSurface implementation | 83 // GLSurface implementation |
88 virtual bool Initialize() OVERRIDE; | 84 virtual bool Initialize() OVERRIDE; |
89 virtual void Destroy() OVERRIDE; | 85 virtual void Destroy() OVERRIDE; |
90 virtual bool IsOffscreen() OVERRIDE; | 86 virtual bool IsOffscreen() OVERRIDE; |
91 virtual bool SwapBuffers() OVERRIDE; | 87 virtual bool SwapBuffers() OVERRIDE; |
92 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 88 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
93 virtual std::string GetExtensions() OVERRIDE; | 89 virtual std::string GetExtensions() OVERRIDE; |
94 virtual gfx::Size GetSize() OVERRIDE; | 90 virtual gfx::Size GetSize() OVERRIDE; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 void AddIntegerValue(CFMutableDictionaryRef dictionary, | 132 void AddIntegerValue(CFMutableDictionaryRef dictionary, |
137 const CFStringRef key, | 133 const CFStringRef key, |
138 int32 value) { | 134 int32 value) { |
139 base::mac::ScopedCFTypeRef<CFNumberRef> number( | 135 base::mac::ScopedCFTypeRef<CFNumberRef> number( |
140 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); | 136 CFNumberCreate(NULL, kCFNumberSInt32Type, &value)); |
141 CFDictionaryAddValue(dictionary, key, number.get()); | 137 CFDictionaryAddValue(dictionary, key, number.get()); |
142 } | 138 } |
143 | 139 |
144 IOSurfaceImageTransportSurface::IOSurfaceImageTransportSurface( | 140 IOSurfaceImageTransportSurface::IOSurfaceImageTransportSurface( |
145 GpuChannelManager* manager, | 141 GpuChannelManager* manager, |
146 int32 render_view_id, | 142 GpuCommandBufferStub* stub, |
147 int32 client_id, | |
148 int32 command_buffer_id, | |
149 gfx::PluginWindowHandle handle) | 143 gfx::PluginWindowHandle handle) |
150 : gfx::NoOpGLSurfaceCGL(gfx::Size(1, 1)), | 144 : gfx::NoOpGLSurfaceCGL(gfx::Size(1, 1)), |
151 fbo_id_(0), | 145 fbo_id_(0), |
152 texture_id_(0), | 146 texture_id_(0), |
153 io_surface_id_(0), | 147 io_surface_id_(0), |
154 context_(NULL), | 148 context_(NULL), |
155 made_current_(false) { | 149 made_current_(false) { |
156 helper_.reset(new ImageTransportHelper(this, | 150 helper_.reset(new ImageTransportHelper(this, manager, stub, handle)); |
157 manager, | |
158 render_view_id, | |
159 client_id, | |
160 command_buffer_id, | |
161 handle)); | |
162 | |
163 } | 151 } |
164 | 152 |
165 IOSurfaceImageTransportSurface::~IOSurfaceImageTransportSurface() { | 153 IOSurfaceImageTransportSurface::~IOSurfaceImageTransportSurface() { |
166 Destroy(); | 154 Destroy(); |
167 } | 155 } |
168 | 156 |
169 bool IOSurfaceImageTransportSurface::Initialize() { | 157 bool IOSurfaceImageTransportSurface::Initialize() { |
170 // Only support IOSurfaces if the GL implementation is the native desktop GL. | 158 // Only support IOSurfaces if the GL implementation is the native desktop GL. |
171 // IO surfaces will not work with, for example, OSMesa software renderer | 159 // IO surfaces will not work with, for example, OSMesa software renderer |
172 // GL contexts. | 160 // GL contexts. |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 params.height = size_.height(); | 352 params.height = size_.height(); |
365 params.surface_id = io_surface_id_; | 353 params.surface_id = io_surface_id_; |
366 params.create_transport_dib = false; | 354 params.create_transport_dib = false; |
367 helper_->SendAcceleratedSurfaceNew(params); | 355 helper_->SendAcceleratedSurfaceNew(params); |
368 | 356 |
369 helper_->SetScheduled(false); | 357 helper_->SetScheduled(false); |
370 } | 358 } |
371 | 359 |
372 TransportDIBImageTransportSurface::TransportDIBImageTransportSurface( | 360 TransportDIBImageTransportSurface::TransportDIBImageTransportSurface( |
373 GpuChannelManager* manager, | 361 GpuChannelManager* manager, |
374 int32 render_view_id, | 362 GpuCommandBufferStub* stub, |
375 int32 client_id, | |
376 int32 command_buffer_id, | |
377 gfx::PluginWindowHandle handle) | 363 gfx::PluginWindowHandle handle) |
378 : gfx::NoOpGLSurfaceCGL(gfx::Size(1, 1)), | 364 : gfx::NoOpGLSurfaceCGL(gfx::Size(1, 1)), |
379 fbo_id_(0), | 365 fbo_id_(0), |
380 render_buffer_id_(0), | 366 render_buffer_id_(0), |
381 made_current_(false) { | 367 made_current_(false) { |
382 helper_.reset(new ImageTransportHelper(this, | 368 helper_.reset(new ImageTransportHelper(this, stub, handle)); |
383 manager, | |
384 render_view_id, | |
385 client_id, | |
386 command_buffer_id, | |
387 handle)); | |
388 | 369 |
389 } | 370 } |
390 | 371 |
391 TransportDIBImageTransportSurface::~TransportDIBImageTransportSurface() { | 372 TransportDIBImageTransportSurface::~TransportDIBImageTransportSurface() { |
392 Destroy(); | 373 Destroy(); |
393 } | 374 } |
394 | 375 |
395 bool TransportDIBImageTransportSurface::Initialize() { | 376 bool TransportDIBImageTransportSurface::Initialize() { |
396 if (!helper_->Initialize()) | 377 if (!helper_->Initialize()) |
397 return false; | 378 return false; |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 helper_->SendAcceleratedSurfaceNew(params); | 556 helper_->SendAcceleratedSurfaceNew(params); |
576 | 557 |
577 helper_->SetScheduled(false); | 558 helper_->SetScheduled(false); |
578 } | 559 } |
579 | 560 |
580 } // namespace | 561 } // namespace |
581 | 562 |
582 // static | 563 // static |
583 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 564 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
584 GpuChannelManager* manager, | 565 GpuChannelManager* manager, |
585 int32 render_view_id, | 566 GpuCommandBufferStub* stub, |
586 int32 client_id, | |
587 int32 command_buffer_id, | |
588 gfx::PluginWindowHandle handle) { | 567 gfx::PluginWindowHandle handle) { |
589 scoped_refptr<gfx::GLSurface> surface; | 568 scoped_refptr<gfx::GLSurface> surface; |
590 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); | 569 IOSurfaceSupport* io_surface_support = IOSurfaceSupport::Initialize(); |
591 | 570 |
592 switch (gfx::GetGLImplementation()) { | 571 switch (gfx::GetGLImplementation()) { |
593 case gfx::kGLImplementationDesktopGL: | 572 case gfx::kGLImplementationDesktopGL: |
594 case gfx::kGLImplementationAppleGL: | 573 case gfx::kGLImplementationAppleGL: |
595 if (!io_surface_support) { | 574 if (!io_surface_support) { |
596 surface = new TransportDIBImageTransportSurface(manager, | 575 surface = new TransportDIBImageTransportSurface(manager, stub, handle); |
597 render_view_id, | |
598 client_id, | |
599 command_buffer_id, | |
600 handle); | |
601 } else { | 576 } else { |
602 surface = new IOSurfaceImageTransportSurface(manager, | 577 surface = new IOSurfaceImageTransportSurface(manager, stub, handle); |
603 render_view_id, | |
604 client_id, | |
605 command_buffer_id, | |
606 handle); | |
607 } | 578 } |
608 break; | 579 break; |
609 default: | 580 default: |
610 NOTREACHED(); | 581 NOTREACHED(); |
611 return NULL; | 582 return NULL; |
612 } | 583 } |
613 if (surface->Initialize()) | 584 if (surface->Initialize()) |
614 return surface; | 585 return surface; |
615 else | 586 else |
616 return NULL; | 587 return NULL; |
617 } | 588 } |
618 | 589 |
619 #endif // defined(USE_GPU) | 590 #endif // defined(USE_GPU) |
OLD | NEW |