OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/win/windows_version.h" | 14 #include "base/win/windows_version.h" |
14 #include "content/common/gpu/gpu_messages.h" | 15 #include "content/common/gpu/gpu_messages.h" |
| 16 #include "content/public/common/content_switches.h" |
15 #include "ui/gfx/gl/gl_bindings.h" | 17 #include "ui/gfx/gl/gl_bindings.h" |
16 #include "ui/gfx/gl/gl_context.h" | 18 #include "ui/gfx/gl/gl_context.h" |
17 #include "ui/gfx/gl/gl_implementation.h" | 19 #include "ui/gfx/gl/gl_implementation.h" |
18 #include "ui/gfx/gl/gl_surface_egl.h" | 20 #include "ui/gfx/gl/gl_surface_egl.h" |
19 #include "ui/gfx/native_widget_types.h" | 21 #include "ui/gfx/native_widget_types.h" |
20 | 22 |
21 namespace { | 23 namespace { |
22 | 24 |
23 // We are backed by an Pbuffer offscreen surface through which ANGLE provides | 25 // We are backed by an Pbuffer offscreen surface through which ANGLE provides |
24 // a handle to the corresponding render target texture through an extension. | 26 // a handle to the corresponding render target texture through an extension. |
25 class PbufferImageTransportSurface | 27 class PbufferImageTransportSurface |
26 : public gfx::GLSurfaceAdapter, | 28 : public gfx::GLSurfaceAdapter, |
27 public ImageTransportSurface, | 29 public ImageTransportSurface, |
28 public base::SupportsWeakPtr<PbufferImageTransportSurface> { | 30 public base::SupportsWeakPtr<PbufferImageTransportSurface> { |
29 public: | 31 public: |
30 PbufferImageTransportSurface(GpuChannelManager* manager, | 32 PbufferImageTransportSurface(GpuChannelManager* manager, |
31 int32 render_view_id, | 33 int32 render_view_id, |
32 int32 renderer_id, | 34 int32 renderer_id, |
33 int32 command_buffer_id); | 35 int32 command_buffer_id); |
34 | 36 |
35 // gfx::GLSurface implementation | 37 // gfx::GLSurface implementation |
36 virtual bool Initialize() OVERRIDE; | 38 virtual bool Initialize() OVERRIDE; |
37 virtual void Destroy() OVERRIDE; | 39 virtual void Destroy() OVERRIDE; |
38 virtual bool IsOffscreen() OVERRIDE; | 40 virtual bool IsOffscreen() OVERRIDE; |
39 virtual bool SwapBuffers() OVERRIDE; | 41 virtual bool SwapBuffers() OVERRIDE; |
40 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; | 42 virtual bool PostSubBuffer(int x, int y, int width, int height) OVERRIDE; |
41 virtual std::string GetExtensions() OVERRIDE; | 43 virtual std::string GetExtensions() OVERRIDE; |
| 44 virtual void SetVisible(bool visible) OVERRIDE; |
42 | 45 |
43 protected: | 46 protected: |
44 // ImageTransportSurface implementation | 47 // ImageTransportSurface implementation |
45 virtual void OnNewSurfaceACK(uint64 surface_id, | 48 virtual void OnNewSurfaceACK(uint64 surface_id, |
46 TransportDIB::Handle shm_handle) OVERRIDE; | 49 TransportDIB::Handle shm_handle) OVERRIDE; |
47 virtual void OnBuffersSwappedACK() OVERRIDE; | 50 virtual void OnBuffersSwappedACK() OVERRIDE; |
48 virtual void OnPostSubBufferACK() OVERRIDE; | 51 virtual void OnPostSubBufferACK() OVERRIDE; |
49 virtual void OnResizeViewACK() OVERRIDE; | 52 virtual void OnResizeViewACK() OVERRIDE; |
50 virtual void OnResize(gfx::Size size) OVERRIDE; | 53 virtual void OnResize(gfx::Size size) OVERRIDE; |
51 | 54 |
52 private: | 55 private: |
53 virtual ~PbufferImageTransportSurface(); | 56 virtual ~PbufferImageTransportSurface(); |
54 void SendBuffersSwapped(); | 57 void SendBuffersSwapped(); |
55 | 58 |
| 59 // Whether the surface is currently visible. |
| 60 bool is_visible_; |
| 61 |
| 62 // Size to resize to when the surface becomes visible. |
| 63 gfx::Size visible_size_; |
| 64 |
56 scoped_ptr<ImageTransportHelper> helper_; | 65 scoped_ptr<ImageTransportHelper> helper_; |
57 | 66 |
58 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); | 67 DISALLOW_COPY_AND_ASSIGN(PbufferImageTransportSurface); |
59 }; | 68 }; |
60 | 69 |
61 PbufferImageTransportSurface::PbufferImageTransportSurface( | 70 PbufferImageTransportSurface::PbufferImageTransportSurface( |
62 GpuChannelManager* manager, | 71 GpuChannelManager* manager, |
63 int32 render_view_id, | 72 int32 render_view_id, |
64 int32 renderer_id, | 73 int32 renderer_id, |
65 int32 command_buffer_id) | 74 int32 command_buffer_id) |
66 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, | 75 : GLSurfaceAdapter(new gfx::PbufferGLSurfaceEGL(false, |
67 gfx::Size(1, 1))) { | 76 gfx::Size(1, 1))), |
| 77 is_visible_(true) { |
68 helper_.reset(new ImageTransportHelper(this, | 78 helper_.reset(new ImageTransportHelper(this, |
69 manager, | 79 manager, |
70 render_view_id, | 80 render_view_id, |
71 renderer_id, | 81 renderer_id, |
72 command_buffer_id, | 82 command_buffer_id, |
73 gfx::kNullPluginWindow)); | 83 gfx::kNullPluginWindow)); |
74 } | 84 } |
75 | 85 |
76 PbufferImageTransportSurface::~PbufferImageTransportSurface() { | 86 PbufferImageTransportSurface::~PbufferImageTransportSurface() { |
77 Destroy(); | 87 Destroy(); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 | 120 |
111 return true; | 121 return true; |
112 } | 122 } |
113 | 123 |
114 bool PbufferImageTransportSurface::PostSubBuffer( | 124 bool PbufferImageTransportSurface::PostSubBuffer( |
115 int x, int y, int width, int height) { | 125 int x, int y, int width, int height) { |
116 NOTREACHED(); | 126 NOTREACHED(); |
117 return false; | 127 return false; |
118 } | 128 } |
119 | 129 |
| 130 void PbufferImageTransportSurface::SetVisible(bool visible) { |
| 131 if (visible == is_visible_) |
| 132 return; |
| 133 |
| 134 is_visible_ = visible; |
| 135 |
| 136 if (visible) |
| 137 Resize(visible_size_); |
| 138 else |
| 139 Resize(gfx::Size(1, 1)); |
| 140 } |
| 141 |
120 std::string PbufferImageTransportSurface::GetExtensions() { | 142 std::string PbufferImageTransportSurface::GetExtensions() { |
121 std::string extensions = gfx::GLSurface::GetExtensions(); | 143 std::string extensions = gfx::GLSurface::GetExtensions(); |
122 extensions += extensions.empty() ? "" : " "; | 144 extensions += extensions.empty() ? "" : " "; |
123 extensions += "GL_CHROMIUM_front_buffer_cached"; | 145 extensions += "GL_CHROMIUM_front_buffer_cached"; |
124 return extensions; | 146 return extensions; |
125 } | 147 } |
126 | 148 |
127 void PbufferImageTransportSurface::SendBuffersSwapped() { | 149 void PbufferImageTransportSurface::SendBuffersSwapped() { |
128 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; | 150 GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params params; |
129 params.surface_id = reinterpret_cast<int64>(GetShareHandle()); | 151 params.surface_id = reinterpret_cast<int64>(GetShareHandle()); |
(...skipping 15 matching lines...) Expand all Loading... |
145 uint64 surface_id, | 167 uint64 surface_id, |
146 TransportDIB::Handle shm_handle) { | 168 TransportDIB::Handle shm_handle) { |
147 NOTREACHED(); | 169 NOTREACHED(); |
148 } | 170 } |
149 | 171 |
150 void PbufferImageTransportSurface::OnResizeViewACK() { | 172 void PbufferImageTransportSurface::OnResizeViewACK() { |
151 NOTREACHED(); | 173 NOTREACHED(); |
152 } | 174 } |
153 | 175 |
154 void PbufferImageTransportSurface::OnResize(gfx::Size size) { | 176 void PbufferImageTransportSurface::OnResize(gfx::Size size) { |
155 Resize(size); | 177 if (is_visible_) |
| 178 Resize(size); |
| 179 |
| 180 visible_size_ = size; |
156 } | 181 } |
157 | 182 |
158 } // namespace anonymous | 183 } // namespace anonymous |
159 | 184 |
160 // static | 185 // static |
161 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( | 186 scoped_refptr<gfx::GLSurface> ImageTransportSurface::CreateSurface( |
162 GpuChannelManager* manager, | 187 GpuChannelManager* manager, |
163 int32 render_view_id, | 188 int32 render_view_id, |
164 int32 renderer_id, | 189 int32 renderer_id, |
165 int32 command_buffer_id, | 190 int32 command_buffer_id, |
166 gfx::PluginWindowHandle handle) { | 191 gfx::PluginWindowHandle handle) { |
167 scoped_refptr<gfx::GLSurface> surface; | 192 scoped_refptr<gfx::GLSurface> surface; |
168 | 193 |
169 base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); | 194 base::win::OSInfo* os_info = base::win::OSInfo::GetInstance(); |
170 | 195 |
171 // TODO(apatrick): Enable this once it has settled in the tree. | 196 if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
172 if (false && gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && | 197 os_info->version() >= base::win::VERSION_VISTA && |
173 os_info->version() >= base::win::VERSION_VISTA) { | 198 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 199 switches::kDisableImageTransportSurface)) { |
174 surface = new PbufferImageTransportSurface(manager, | 200 surface = new PbufferImageTransportSurface(manager, |
175 render_view_id, | 201 render_view_id, |
176 renderer_id, | 202 renderer_id, |
177 command_buffer_id); | 203 command_buffer_id); |
178 } else { | 204 } else { |
179 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); | 205 surface = gfx::GLSurface::CreateViewGLSurface(false, handle); |
180 if (!surface.get()) | 206 if (!surface.get()) |
181 return NULL; | 207 return NULL; |
182 | 208 |
183 surface = new PassThroughImageTransportSurface(manager, | 209 surface = new PassThroughImageTransportSurface(manager, |
184 render_view_id, | 210 render_view_id, |
185 renderer_id, | 211 renderer_id, |
186 command_buffer_id, | 212 command_buffer_id, |
187 surface.get()); | 213 surface.get()); |
188 } | 214 } |
189 | 215 |
190 if (surface->Initialize()) | 216 if (surface->Initialize()) |
191 return surface; | 217 return surface; |
192 else | 218 else |
193 return NULL; | 219 return NULL; |
194 } | 220 } |
195 | 221 |
196 #endif // ENABLE_GPU | 222 #endif // ENABLE_GPU |
OLD | NEW |