| 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // We are backed by an Pbuffer offscreen surface through which ANGLE provides | 26 // We are backed by an Pbuffer offscreen surface through which ANGLE provides |
| 27 // a handle to the corresponding render target texture through an extension. | 27 // a handle to the corresponding render target texture through an extension. |
| 28 class PbufferImageTransportSurface | 28 class PbufferImageTransportSurface |
| 29 : public gfx::GLSurfaceAdapter, | 29 : public gfx::GLSurfaceAdapter, |
| 30 public ImageTransportSurface, | 30 public ImageTransportSurface, |
| 31 public base::SupportsWeakPtr<PbufferImageTransportSurface> { | 31 public base::SupportsWeakPtr<PbufferImageTransportSurface> { |
| 32 public: | 32 public: |
| 33 PbufferImageTransportSurface(GpuChannelManager* manager, | 33 PbufferImageTransportSurface(GpuChannelManager* manager, |
| 34 int32 render_view_id, | 34 GpuCommandBufferStub* stub); |
| 35 int32 client_id, | |
| 36 int32 command_buffer_id); | |
| 37 | 35 |
| 38 // gfx::GLSurface implementation | 36 // gfx::GLSurface implementation |
| 39 virtual bool Initialize() OVERRIDE; | 37 virtual bool Initialize() OVERRIDE; |
| 40 virtual void Destroy() OVERRIDE; | 38 virtual void Destroy() OVERRIDE; |
| 41 virtual bool IsOffscreen() OVERRIDE; | 39 virtual bool IsOffscreen() OVERRIDE; |
| 42 virtual bool SwapBuffers() OVERRIDE; | 40 virtual bool SwapBuffers() OVERRIDE; |
| 43 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 41 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
| 44 virtual std::string GetExtensions() OVERRIDE; | 42 virtual std::string GetExtensions() OVERRIDE; |
| 45 virtual void SetVisible(bool visible) OVERRIDE; | 43 virtual void SetVisible(bool visible) OVERRIDE; |
| 46 | 44 |
| 47 protected: | 45 protected: |
| 48 // ImageTransportSurface implementation | 46 // ImageTransportSurface implementation |
| 49 virtual void OnNewSurfaceACK(uint64 surface_id, | 47 virtual void OnNewSurfaceACK(uint64 surface_handle, |
| 50 TransportDIB::Handle shm_handle) OVERRIDE; | 48 TransportDIB::Handle shm_handle) OVERRIDE; |
| 51 virtual void OnBuffersSwappedACK() OVERRIDE; | 49 virtual void OnBuffersSwappedACK() OVERRIDE; |
| 52 virtual void OnPostSubBufferACK() OVERRIDE; | 50 virtual void OnPostSubBufferACK() OVERRIDE; |
| 53 virtual void OnResizeViewACK() OVERRIDE; | 51 virtual void OnResizeViewACK() OVERRIDE; |
| 54 virtual void OnResize(gfx::Size size) OVERRIDE; | 52 virtual void OnResize(gfx::Size size) OVERRIDE; |
| 55 | 53 |
| 56 private: | 54 private: |
| 57 virtual ~PbufferImageTransportSurface(); | 55 virtual ~PbufferImageTransportSurface(); |
| 58 void SendBuffersSwapped(); | 56 void SendBuffersSwapped(); |
| 59 | 57 |
| 60 // Whether the surface is currently visible. | 58 // Whether the surface is currently visible. |
| 61 bool is_visible_; | 59 bool is_visible_; |
| 62 | 60 |
| 63 // Size to resize to when the surface becomes visible. | 61 // Size to resize to when the surface becomes visible. |
| 64 gfx::Size visible_size_; | 62 gfx::Size visible_size_; |
| 65 | 63 |
| 66 scoped_ptr<ImageTransportHelper> helper_; | 64 scoped_ptr<ImageTransportHelper> helper_; |
| 67 | 65 |
| 68 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); | 66 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); |
| 69 }; | 67 }; |
| 70 | 68 |
| 71 PbufferImageTransportSurface::PbufferImageTransportSurface( | 69 PbufferImageTransportSurface::PbufferImageTransportSurface( |
| 72 GpuChannelManager* manager, | 70 GpuChannelManager* manager, |
| 73 int32 render_view_id, | 71 GpuCommandBufferStub* stub) |
| 74 int32 client_id, | 72 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, gfx::Size(1, 1))), |
| 75 int32 command_buffer_id) | 73 is_visible_(true) { |
| 76 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, | |
| 77 gfx::Size(1, 1))), | |
| 78 is_visible_(true) { | |
| 79 helper_.reset(new ImageTransportHelper(this, | 74 helper_.reset(new ImageTransportHelper(this, |
| 80 manager, | 75 manager, |
| 81 render_view_id, | 76 stub, |
| 82 client_id, | |
| 83 command_buffer_id, | |
| 84 gfx::kNullPluginWindow)); | 77 gfx::kNullPluginWindow)); |
| 85 } | 78 } |
| 86 | 79 |
| 87 PbufferImageTransportSurface::~PbufferImageTransportSurface() { | 80 PbufferImageTransportSurface::~PbufferImageTransportSurface() { |
| 88 Destroy(); | 81 Destroy(); |
| 89 } | 82 } |
| 90 | 83 |
| 91 bool PbufferImageTransportSurface::Initialize() { | 84 bool PbufferImageTransportSurface::Initialize() { |
| 92 // Only support this path if the GL implementation is ANGLE. | 85 // Only support this path if the GL implementation is ANGLE. |
| 93 // IO surfaces will not work with, for example, OSMesa software renderer | 86 // IO surfaces will not work with, for example, OSMesa software renderer |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 135 |
| 143 std::string PbufferImageTransportSurface::GetExtensions() { | 136 std::string PbufferImageTransportSurface::GetExtensions() { |
| 144 std::string extensions = gfx::GLSurface::GetExtensions(); | 137 std::string extensions = gfx::GLSurface::GetExtensions(); |
| 145 extensions += extensions.empty() ? "" : " "; | 138 extensions += extensions.empty() ? "" : " "; |
| 146 extensions += "GL_CHROMIUM_front_buffer_cached"; | 139 extensions += "GL_CHROMIUM_front_buffer_cached"; |
| 147 return extensions; | 140 return extensions; |
| 148 } | 141 } |
| 149 | 142 |
| 150 void PbufferImageTransportSurface::SendBuffersSwapped() { | 143 void PbufferImageTransportSurface::SendBuffersSwapped() { |
| 151 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 144 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
| 152 params.surface_id = reinterpret_cast<int64>(GetShareHandle()); | 145 params.surface_handle = reinterpret_cast<int64>(GetShareHandle()); |
| 153 params.size = GetSize(); | 146 params.size = GetSize(); |
| 154 helper_->SendAcceleratedSurfaceBuffersSwapped(params); | 147 helper_->SendAcceleratedSurfaceBuffersSwapped(params); |
| 155 | 148 |
| 156 helper_->SetScheduled(false); | 149 helper_->SetScheduled(false); |
| 157 } | 150 } |
| 158 | 151 |
| 159 void PbufferImageTransportSurface::OnBuffersSwappedACK() { | 152 void PbufferImageTransportSurface::OnBuffersSwappedACK() { |
| 160 helper_->SetScheduled(true); | 153 helper_->SetScheduled(true); |
| 161 } | 154 } |
| 162 | 155 |
| 163 void PbufferImageTransportSurface::OnPostSubBufferACK() { | 156 void PbufferImageTransportSurface::OnPostSubBufferACK() { |
| 164 NOTREACHED(); | 157 NOTREACHED(); |
| 165 } | 158 } |
| 166 | 159 |
| 167 void PbufferImageTransportSurface::OnNewSurfaceACK( | 160 void PbufferImageTransportSurface::OnNewSurfaceACK( |
| 168 uint64 surface_id, | 161 uint64 surface_handle, |
| 169 TransportDIB::Handle shm_handle) { | 162 TransportDIB::Handle shm_handle) { |
| 170 NOTREACHED(); | 163 NOTREACHED(); |
| 171 } | 164 } |
| 172 | 165 |
| 173 void PbufferImageTransportSurface::OnResizeViewACK() { | 166 void PbufferImageTransportSurface::OnResizeViewACK() { |
| 174 NOTREACHED(); | 167 NOTREACHED(); |
| 175 } | 168 } |
| 176 | 169 |
| 177 void PbufferImageTransportSurface::OnResize(gfx::Size size) { | 170 void PbufferImageTransportSurface::OnResize(gfx::Size size) { |
| 178 if (is_visible_) | 171 if (is_visible_) |
| 179 Resize(size); | 172 Resize(size); |
| 180 | 173 |
| 181 visible_size_ = size; | 174 visible_size_ = size; |
| 182 } | 175 } |
| 183 | 176 |
| 184 } // namespace anonymous | 177 } // namespace anonymous |
| 185 | 178 |
| 186 // static | 179 // static |
| 187 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 180 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
| 188 GpuChannelManager* manager, | 181 GpuChannelManager* manager, |
| 189 int32 render_view_id, | 182 GpuCommandBufferStub* stub, |
| 190 int32 client_id, | |
| 191 int32 command_buffer_id, | |
| 192 gfx::PluginWindowHandle handle) { | 183 gfx::PluginWindowHandle handle) { |
| 193 scoped_refptr<gfx::GLSurface> surface; | 184 scoped_refptr<gfx::GLSurface> surface; |
| 194 | 185 |
| 195 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && | 186 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
| 196 !CommandLine::ForCurrentProcess()->HasSwitch( | 187 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 197 switches::kDisableImageTransportSurface)) { | 188 switches::kDisableImageTransportSurface)) { |
| 198 const char* extensions = eglQueryString(eglGetDisplay(EGL_DEFAULT_DISPLAY), | 189 const char* extensions = eglQueryString(eglGetDisplay(EGL_DEFAULT_DISPLAY), |
| 199 EGL_EXTENSIONS); | 190 EGL_EXTENSIONS); |
| 200 if (strstr(extensions, "EGL_ANGLE_query_surface_pointer") && | 191 if (strstr(extensions, "EGL_ANGLE_query_surface_pointer") && |
| 201 strstr(extensions, "EGL_ANGLE_surface_d3d_texture_2d_share_handle")) { | 192 strstr(extensions, "EGL_ANGLE_surface_d3d_texture_2d_share_handle")) { |
| 202 surface = new PbufferImageTransportSurface(manager, | 193 surface = new PbufferImageTransportSurface(manager, stub); |
| 203 render_view_id, | |
| 204 client_id, | |
| 205 command_buffer_id); | |
| 206 } | 194 } |
| 207 } | 195 } |
| 208 | 196 |
| 209 if (!surface.get()) { | 197 if (!surface.get()) { |
| 210 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); | 198 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); |
| 211 if (!surface.get()) | 199 if (!surface.get()) |
| 212 return NULL; | 200 return NULL; |
| 213 | 201 |
| 214 surface = new PassThroughImageTransportSurface(manager, | 202 surface = new PassThroughImageTransportSurface(manager, |
| 215 render_view_id, | 203 stub, |
| 216 client_id, | |
| 217 command_buffer_id, | |
| 218 surface.get()); | 204 surface.get()); |
| 219 } | 205 } |
| 220 | 206 |
| 221 if (surface->Initialize()) | 207 if (surface->Initialize()) |
| 222 return surface; | 208 return surface; |
| 223 else | 209 else |
| 224 return NULL; | 210 return NULL; |
| 225 } | 211 } |
| 226 | 212 |
| 227 #endif // ENABLE_GPU | 213 #endif // ENABLE_GPU |
| OLD | NEW |