| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #if defined(ENABLE_GPU) | |
| 6 | |
| 7 #include "content/common/gpu/image_transport_surface.h" | |
| 8 | |
| 9 #include "base/bind.h" | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/win/windows_version.h" | |
| 14 #include "content/common/gpu/gpu_messages.h" | |
| 15 #include "ui/gfx/gl/gl_bindings.h" | |
| 16 #include "ui/gfx/gl/gl_context.h" | |
| 17 #include "ui/gfx/gl/gl_implementation.h" | |
| 18 #include "ui/gfx/gl/gl_surface_egl.h" | |
| 19 #include "ui/gfx/native_widget_types.h" | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // We are backed by an Pbuffer offscreen surface through which ANGLE provides | |
| 24 // a handle to the corresponding render target texture through an extension. | |
| 25 class PbufferImageTransportSurface | |
| 26 : public gfx::GLSurfaceAdapter, | |
| 27 public ImageTransportSurface, | |
| 28 public base::SupportsWeakPtr<PbufferImageTransportSurface> { | |
| 29 public: | |
| 30 PbufferImageTransportSurface(GpuChannelManager* manager, | |
| 31 int32 render_view_id, | |
| 32 int32 renderer_id, | |
| 33 int32 command_buffer_id); | |
| 34 | |
| 35 // GLSurface implementation | |
| 36 virtual bool Initialize(); | |
| 37 virtual void Destroy(); | |
| 38 virtual bool IsOffscreen(); | |
| 39 virtual bool SwapBuffers(); | |
| 40 | |
| 41 protected: | |
| 42 // ImageTransportSurface implementation | |
| 43 virtual void OnNewSurfaceACK(uint64 surface_id, | |
| 44 TransportDIB::Handle shm_handle) OVERRIDE; | |
| 45 virtual void OnBuffersSwappedACK() OVERRIDE; | |
| 46 virtual void OnResizeViewACK() OVERRIDE; | |
| 47 virtual void OnResize(gfx::Size size) OVERRIDE; | |
| 48 | |
| 49 private: | |
| 50 virtual ~PbufferImageTransportSurface(); | |
| 51 void SendBuffersSwapped(); | |
| 52 | |
| 53 scoped_ptr<ImageTransportHelper> helper_; | |
| 54 | |
| 55 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); | |
| 56 }; | |
| 57 | |
| 58 PbufferImageTransportSurface::PbufferImageTransportSurface( | |
| 59 GpuChannelManager* manager, | |
| 60 int32 render_view_id, | |
| 61 int32 renderer_id, | |
| 62 int32 command_buffer_id) | |
| 63 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, | |
| 64 gfx::Size(1, 1))) { | |
| 65 helper_.reset(new ImageTransportHelper(this, | |
| 66 manager, | |
| 67 render_view_id, | |
| 68 renderer_id, | |
| 69 command_buffer_id, | |
| 70 gfx::kNullPluginWindow)); | |
| 71 } | |
| 72 | |
| 73 PbufferImageTransportSurface::~PbufferImageTransportSurface() { | |
| 74 Destroy(); | |
| 75 } | |
| 76 | |
| 77 bool PbufferImageTransportSurface::Initialize() { | |
| 78 // Only support this path if the GL implementation is ANGLE. | |
| 79 // IO surfaces will not work with, for example, OSMesa software renderer | |
| 80 // GL contexts. | |
| 81 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) | |
| 82 return false; | |
| 83 | |
| 84 if (!helper_->Initialize()) | |
| 85 return false; | |
| 86 | |
| 87 return GLSurfaceAdapter::Initialize(); | |
| 88 } | |
| 89 | |
| 90 void PbufferImageTransportSurface::Destroy() { | |
| 91 helper_->Destroy(); | |
| 92 GLSurfaceAdapter::Destroy(); | |
| 93 } | |
| 94 | |
| 95 bool PbufferImageTransportSurface::IsOffscreen() { | |
| 96 return false; | |
| 97 } | |
| 98 | |
| 99 bool PbufferImageTransportSurface::SwapBuffers() { | |
| 100 HANDLE surface_handle = GetShareHandle(); | |
| 101 if (!surface_handle) | |
| 102 return false; | |
| 103 | |
| 104 helper_->DeferToFence(base::Bind( | |
| 105 &PbufferImageTransportSurface::SendBuffersSwapped, | |
| 106 AsWeakPtr())); | |
| 107 | |
| 108 return true; | |
| 109 } | |
| 110 | |
| 111 void PbufferImageTransportSurface::SendBuffersSwapped() { | |
| 112 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | |
| 113 params.surface_id = reinterpret_cast<int64>(GetShareHandle()); | |
| 114 params.size = GetSize(); | |
| 115 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | |
| 116 | |
| 117 helper_->SetScheduled(false); | |
| 118 } | |
| 119 | |
| 120 void PbufferImageTransportSurface::OnBuffersSwappedACK() { | |
| 121 helper_->SetScheduled(true); | |
| 122 } | |
| 123 | |
| 124 void PbufferImageTransportSurface::OnNewSurfaceACK( | |
| 125 uint64 surface_id, | |
| 126 TransportDIB::Handle shm_handle) { | |
| 127 NOTIMPLEMENTED(); | |
| 128 } | |
| 129 | |
| 130 void PbufferImageTransportSurface::OnResizeViewACK() { | |
| 131 NOTIMPLEMENTED(); | |
| 132 } | |
| 133 | |
| 134 void PbufferImageTransportSurface::OnResize(gfx::Size size) { | |
| 135 Resize(size); | |
| 136 } | |
| 137 | |
| 138 } // namespace anonymous | |
| 139 | |
| 140 // static | |
| 141 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | |
| 142 GpuChannelManager* manager, | |
| 143 int32 render_view_id, | |
| 144 int32 renderer_id, | |
| 145 int32 command_buffer_id, | |
| 146 gfx::PluginWindowHandle handle) { | |
| 147 scoped_refptr<gfx::GLSurface> surface; | |
| 148 | |
| 149 base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); | |
| 150 | |
| 151 // TODO(apatrick): Enable this once it has settled in the tree. | |
| 152 if (false && gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && | |
| 153 os_info->version() >= base::win::VERSION_VISTA) { | |
| 154 surface = new PbufferImageTransportSurface(manager, | |
| 155 render_view_id, | |
| 156 renderer_id, | |
| 157 command_buffer_id); | |
| 158 } else { | |
| 159 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); | |
| 160 if (!surface.get()) | |
| 161 return NULL; | |
| 162 | |
| 163 surface = new PassThroughImageTransportSurface(manager, | |
| 164 render_view_id, | |
| 165 renderer_id, | |
| 166 command_buffer_id, | |
| 167 surface.get()); | |
| 168 } | |
| 169 | |
| 170 if (surface->Initialize()) | |
| 171 return surface; | |
| 172 else | |
| 173 return NULL; | |
| 174 } | |
| 175 | |
| 176 #endif // ENABLE_GPU | |
| OLD | NEW |