| 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 #ifndef CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ | 5 #ifndef CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ |
| 6 #define CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ | 6 #define CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ |
| 7 | 7 |
| 8 #include "base/atomicops.h" | 8 #include "base/atomicops.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 13 #include "gpu/command_buffer/client/gles2_interface.h" |
| 14 | 14 |
| 15 namespace gfx { | 15 namespace gfx { |
| 16 class Rect; | 16 class Rect; |
| 17 class Size; | 17 class Size; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace gpu { | 20 namespace gpu { |
| 21 class ContextSupport; | 21 class ContextSupport; |
| 22 struct Mailbox; | 22 struct Mailbox; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace media { | 25 namespace media { |
| 26 class VideoFrame; | 26 class VideoFrame; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 class SkRegion; | 29 class SkRegion; |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 class GLHelperScaling; | 33 class GLHelperScaling; |
| 34 | 34 |
| 35 class ScopedWebGLId { | 35 class ScopedGLuint { |
| 36 public: | 36 public: |
| 37 typedef void (blink::WebGraphicsContext3D::*DeleteFunc)(WebGLId); | 37 typedef void (gpu::gles2::GLES2Interface::*GenFunc)(GLsizei n, GLuint* ids); |
| 38 ScopedWebGLId(blink::WebGraphicsContext3D* context, | 38 typedef void (gpu::gles2::GLES2Interface::*DeleteFunc)(GLsizei n, |
| 39 WebGLId id, | 39 const GLuint* ids); |
| 40 DeleteFunc delete_func) | 40 ScopedGLuint(gpu::gles2::GLES2Interface* gl, |
| 41 : context_(context), | 41 GenFunc gen_func, |
| 42 id_(id), | 42 DeleteFunc delete_func) |
| 43 delete_func_(delete_func) { | 43 : gl_(gl), id_(0u), delete_func_(delete_func) { |
| 44 (gl_->*gen_func)(1, &id_); |
| 44 } | 45 } |
| 45 | 46 |
| 46 operator WebGLId() const { | 47 operator GLuint() const { return id_; } |
| 47 return id_; | |
| 48 } | |
| 49 | 48 |
| 50 WebGLId id() const { return id_; } | 49 GLuint id() const { return id_; } |
| 51 | 50 |
| 52 WebGLId Detach() { | 51 ~ScopedGLuint() { |
| 53 WebGLId id = id_; | |
| 54 id_ = 0; | |
| 55 return id; | |
| 56 } | |
| 57 | |
| 58 ~ScopedWebGLId() { | |
| 59 if (id_ != 0) { | 52 if (id_ != 0) { |
| 60 (context_->*delete_func_)(id_); | 53 (gl_->*delete_func_)(1, &id_); |
| 61 } | 54 } |
| 62 } | 55 } |
| 63 | 56 |
| 64 private: | 57 private: |
| 65 blink::WebGraphicsContext3D* context_; | 58 gpu::gles2::GLES2Interface* gl_; |
| 66 WebGLId id_; | 59 GLuint id_; |
| 67 DeleteFunc delete_func_; | 60 DeleteFunc delete_func_; |
| 68 | 61 |
| 69 DISALLOW_COPY_AND_ASSIGN(ScopedWebGLId); | 62 DISALLOW_COPY_AND_ASSIGN(ScopedGLuint); |
| 70 }; | 63 }; |
| 71 | 64 |
| 72 class ScopedBuffer : public ScopedWebGLId { | 65 class ScopedBuffer : public ScopedGLuint { |
| 73 public: | 66 public: |
| 74 ScopedBuffer(blink::WebGraphicsContext3D* context, | 67 explicit ScopedBuffer(gpu::gles2::GLES2Interface* gl) |
| 75 WebGLId id) | 68 : ScopedGLuint(gl, |
| 76 : ScopedWebGLId(context, | 69 &gpu::gles2::GLES2Interface::GenBuffers, |
| 77 id, | 70 &gpu::gles2::GLES2Interface::DeleteBuffers) {} |
| 78 &blink::WebGraphicsContext3D::deleteBuffer) {} | |
| 79 }; | 71 }; |
| 80 | 72 |
| 81 class ScopedFramebuffer : public ScopedWebGLId { | 73 class ScopedFramebuffer : public ScopedGLuint { |
| 82 public: | 74 public: |
| 83 ScopedFramebuffer(blink::WebGraphicsContext3D* context, | 75 explicit ScopedFramebuffer(gpu::gles2::GLES2Interface* gl) |
| 84 WebGLId id) | 76 : ScopedGLuint(gl, |
| 85 : ScopedWebGLId(context, | 77 &gpu::gles2::GLES2Interface::GenFramebuffers, |
| 86 id, | 78 &gpu::gles2::GLES2Interface::DeleteFramebuffers) {} |
| 87 &blink::WebGraphicsContext3D::deleteFramebuffer) {} | |
| 88 }; | 79 }; |
| 89 | 80 |
| 90 class ScopedProgram : public ScopedWebGLId { | 81 class ScopedTexture : public ScopedGLuint { |
| 91 public: | 82 public: |
| 92 ScopedProgram(blink::WebGraphicsContext3D* context, | 83 explicit ScopedTexture(gpu::gles2::GLES2Interface* gl) |
| 93 WebGLId id) | 84 : ScopedGLuint(gl, |
| 94 : ScopedWebGLId(context, | 85 &gpu::gles2::GLES2Interface::GenTextures, |
| 95 id, | 86 &gpu::gles2::GLES2Interface::DeleteTextures) {} |
| 96 &blink::WebGraphicsContext3D::deleteProgram) {} | |
| 97 }; | 87 }; |
| 98 | 88 |
| 99 class ScopedShader : public ScopedWebGLId { | 89 template <GLenum Target> |
| 100 public: | |
| 101 ScopedShader(blink::WebGraphicsContext3D* context, | |
| 102 WebGLId id) | |
| 103 : ScopedWebGLId(context, | |
| 104 id, | |
| 105 &blink::WebGraphicsContext3D::deleteShader) {} | |
| 106 }; | |
| 107 | |
| 108 class ScopedTexture : public ScopedWebGLId { | |
| 109 public: | |
| 110 ScopedTexture(blink::WebGraphicsContext3D* context, | |
| 111 WebGLId id) | |
| 112 : ScopedWebGLId(context, | |
| 113 id, | |
| 114 &blink::WebGraphicsContext3D::deleteTexture) {} | |
| 115 }; | |
| 116 | |
| 117 template <blink::WGC3Denum target> | |
| 118 class ScopedBinder { | 90 class ScopedBinder { |
| 119 public: | 91 public: |
| 120 typedef void (blink::WebGraphicsContext3D::*BindFunc)(blink::WGC3Denum, | 92 typedef void (gpu::gles2::GLES2Interface::*BindFunc)(GLenum target, |
| 121 WebGLId); | 93 GLuint id); |
| 122 ScopedBinder(blink::WebGraphicsContext3D* context, | 94 ScopedBinder(gpu::gles2::GLES2Interface* gl, GLuint id, BindFunc bind_func) |
| 123 WebGLId id, | 95 : gl_(gl), bind_func_(bind_func) { |
| 124 BindFunc bind_func) | 96 (gl_->*bind_func_)(Target, id); |
| 125 : context_(context), | |
| 126 bind_func_(bind_func) { | |
| 127 (context_->*bind_func_)(target, id); | |
| 128 } | 97 } |
| 129 | 98 |
| 130 virtual ~ScopedBinder() { | 99 virtual ~ScopedBinder() { (gl_->*bind_func_)(Target, 0); } |
| 131 (context_->*bind_func_)(target, 0); | |
| 132 } | |
| 133 | 100 |
| 134 private: | 101 private: |
| 135 blink::WebGraphicsContext3D* context_; | 102 gpu::gles2::GLES2Interface* gl_; |
| 136 BindFunc bind_func_; | 103 BindFunc bind_func_; |
| 137 | 104 |
| 138 DISALLOW_COPY_AND_ASSIGN(ScopedBinder); | 105 DISALLOW_COPY_AND_ASSIGN(ScopedBinder); |
| 139 }; | 106 }; |
| 140 | 107 |
| 141 template <blink::WGC3Denum target> | 108 template <GLenum Target> |
| 142 class ScopedBufferBinder : ScopedBinder<target> { | 109 class ScopedBufferBinder : ScopedBinder<Target> { |
| 143 public: | 110 public: |
| 144 ScopedBufferBinder(blink::WebGraphicsContext3D* context, | 111 ScopedBufferBinder(gpu::gles2::GLES2Interface* gl, GLuint id) |
| 145 WebGLId id) | 112 : ScopedBinder<Target>(gl, id, &gpu::gles2::GLES2Interface::BindBuffer) {} |
| 146 : ScopedBinder<target>( | |
| 147 context, | |
| 148 id, | |
| 149 &blink::WebGraphicsContext3D::bindBuffer) {} | |
| 150 }; | 113 }; |
| 151 | 114 |
| 152 template <blink::WGC3Denum target> | 115 template <GLenum Target> |
| 153 class ScopedFramebufferBinder : ScopedBinder<target> { | 116 class ScopedFramebufferBinder : ScopedBinder<Target> { |
| 154 public: | 117 public: |
| 155 ScopedFramebufferBinder(blink::WebGraphicsContext3D* context, | 118 ScopedFramebufferBinder(gpu::gles2::GLES2Interface* gl, GLuint id) |
| 156 WebGLId id) | 119 : ScopedBinder<Target>(gl, |
| 157 : ScopedBinder<target>( | 120 id, |
| 158 context, | 121 &gpu::gles2::GLES2Interface::BindFramebuffer) {} |
| 159 id, | |
| 160 &blink::WebGraphicsContext3D::bindFramebuffer) {} | |
| 161 }; | 122 }; |
| 162 | 123 |
| 163 template <blink::WGC3Denum target> | 124 template <GLenum Target> |
| 164 class ScopedTextureBinder : ScopedBinder<target> { | 125 class ScopedTextureBinder : ScopedBinder<Target> { |
| 165 public: | 126 public: |
| 166 ScopedTextureBinder(blink::WebGraphicsContext3D* context, | 127 ScopedTextureBinder(gpu::gles2::GLES2Interface* gl, GLuint id) |
| 167 WebGLId id) | 128 : ScopedBinder<Target>(gl, id, &gpu::gles2::GLES2Interface::BindTexture) { |
| 168 : ScopedBinder<target>( | 129 } |
| 169 context, | |
| 170 id, | |
| 171 &blink::WebGraphicsContext3D::bindTexture) {} | |
| 172 }; | 130 }; |
| 173 | 131 |
| 174 class ScopedFlush { | 132 class ScopedFlush { |
| 175 public: | 133 public: |
| 176 explicit ScopedFlush(blink::WebGraphicsContext3D* context) | 134 explicit ScopedFlush(gpu::gles2::GLES2Interface* gl) : gl_(gl) {} |
| 177 : context_(context) { | |
| 178 } | |
| 179 | 135 |
| 180 ~ScopedFlush() { | 136 ~ScopedFlush() { gl_->Flush(); } |
| 181 context_->flush(); | |
| 182 } | |
| 183 | 137 |
| 184 private: | 138 private: |
| 185 blink::WebGraphicsContext3D* context_; | 139 gpu::gles2::GLES2Interface* gl_; |
| 186 | 140 |
| 187 DISALLOW_COPY_AND_ASSIGN(ScopedFlush); | 141 DISALLOW_COPY_AND_ASSIGN(ScopedFlush); |
| 188 }; | 142 }; |
| 189 | 143 |
| 190 | |
| 191 class ReadbackYUVInterface; | 144 class ReadbackYUVInterface; |
| 192 | 145 |
| 193 // Provides higher level operations on top of the blink::WebGraphicsContext3D | 146 // Provides higher level operations on top of the gpu::gles2::GLES2Interface |
| 194 // interfaces. | 147 // interfaces. |
| 195 class CONTENT_EXPORT GLHelper { | 148 class CONTENT_EXPORT GLHelper { |
| 196 public: | 149 public: |
| 197 GLHelper(blink::WebGraphicsContext3D* context, | 150 GLHelper(gpu::gles2::GLES2Interface* gl, |
| 198 gpu::ContextSupport* context_support); | 151 gpu::ContextSupport* context_support); |
| 199 ~GLHelper(); | 152 ~GLHelper(); |
| 200 | 153 |
| 201 enum ScalerQuality { | 154 enum ScalerQuality { |
| 202 // Bilinear single pass, fastest possible. | 155 // Bilinear single pass, fastest possible. |
| 203 SCALER_QUALITY_FAST = 1, | 156 SCALER_QUALITY_FAST = 1, |
| 204 | 157 |
| 205 // Bilinear upscale + N * 50% bilinear downscales. | 158 // Bilinear upscale + N * 50% bilinear downscales. |
| 206 // This is still fast enough for most purposes and | 159 // This is still fast enough for most purposes and |
| 207 // Image quality is nearly as good as the BEST option. | 160 // Image quality is nearly as good as the BEST option. |
| 208 SCALER_QUALITY_GOOD = 2, | 161 SCALER_QUALITY_GOOD = 2, |
| 209 | 162 |
| 210 // Bicubic upscale + N * 50% bicubic downscales. | 163 // Bicubic upscale + N * 50% bicubic downscales. |
| 211 // Produces very good quality scaled images, but it's | 164 // Produces very good quality scaled images, but it's |
| 212 // 2-8x slower than the "GOOD" quality, so it's not always | 165 // 2-8x slower than the "GOOD" quality, so it's not always |
| 213 // worth it. | 166 // worth it. |
| 214 SCALER_QUALITY_BEST = 3, | 167 SCALER_QUALITY_BEST = 3, |
| 215 }; | 168 }; |
| 216 | 169 |
| 217 | |
| 218 // Copies the block of pixels specified with |src_subrect| from |src_texture|, | 170 // Copies the block of pixels specified with |src_subrect| from |src_texture|, |
| 219 // scales it to |dst_size|, and writes it into |out|. | 171 // scales it to |dst_size|, and writes it into |out|. |
| 220 // |src_size| is the size of |src_texture|. The result is of format GL_BGRA | 172 // |src_size| is the size of |src_texture|. The result is of format GL_BGRA |
| 221 // and is potentially flipped vertically to make it a correct image | 173 // and is potentially flipped vertically to make it a correct image |
| 222 // representation. |callback| is invoked with the copy result when the copy | 174 // representation. |callback| is invoked with the copy result when the copy |
| 223 // operation has completed. | 175 // operation has completed. |
| 224 // Note that the src_texture will have the min/mag filter set to GL_LINEAR | 176 // Note that the src_texture will have the min/mag filter set to GL_LINEAR |
| 225 // and wrap_s/t set to CLAMP_TO_EDGE in this call. | 177 // and wrap_s/t set to CLAMP_TO_EDGE in this call. |
| 226 void CropScaleReadbackAndCleanTexture( | 178 void CropScaleReadbackAndCleanTexture( |
| 227 blink::WebGLId src_texture, | 179 GLuint src_texture, |
| 228 const gfx::Size& src_size, | 180 const gfx::Size& src_size, |
| 229 const gfx::Rect& src_subrect, | 181 const gfx::Rect& src_subrect, |
| 230 const gfx::Size& dst_size, | 182 const gfx::Size& dst_size, |
| 231 unsigned char* out, | 183 unsigned char* out, |
| 232 const base::Callback<void(bool)>& callback); | 184 const base::Callback<void(bool)>& callback); |
| 233 | 185 |
| 234 // Copies the block of pixels specified with |src_subrect| from |src_mailbox|, | 186 // Copies the block of pixels specified with |src_subrect| from |src_mailbox|, |
| 235 // scales it to |dst_size|, and writes it into |out|. | 187 // scales it to |dst_size|, and writes it into |out|. |
| 236 // |src_size| is the size of |src_mailbox|. The result is of format GL_BGRA | 188 // |src_size| is the size of |src_mailbox|. The result is of format GL_BGRA |
| 237 // and is potentially flipped vertically to make it a correct image | 189 // and is potentially flipped vertically to make it a correct image |
| 238 // representation. |callback| is invoked with the copy result when the copy | 190 // representation. |callback| is invoked with the copy result when the copy |
| 239 // operation has completed. | 191 // operation has completed. |
| 240 // Note that the texture bound to src_mailbox will have the min/mag filter set | 192 // Note that the texture bound to src_mailbox will have the min/mag filter set |
| 241 // to GL_LINEAR and wrap_s/t set to CLAMP_TO_EDGE in this call. src_mailbox is | 193 // to GL_LINEAR and wrap_s/t set to CLAMP_TO_EDGE in this call. src_mailbox is |
| 242 // assumed to be GL_TEXTURE_2D. | 194 // assumed to be GL_TEXTURE_2D. |
| 243 void CropScaleReadbackAndCleanMailbox( | 195 void CropScaleReadbackAndCleanMailbox( |
| 244 const gpu::Mailbox& src_mailbox, | 196 const gpu::Mailbox& src_mailbox, |
| 245 uint32 sync_point, | 197 uint32 sync_point, |
| 246 const gfx::Size& src_size, | 198 const gfx::Size& src_size, |
| 247 const gfx::Rect& src_subrect, | 199 const gfx::Rect& src_subrect, |
| 248 const gfx::Size& dst_size, | 200 const gfx::Size& dst_size, |
| 249 unsigned char* out, | 201 unsigned char* out, |
| 250 const base::Callback<void(bool)>& callback); | 202 const base::Callback<void(bool)>& callback); |
| 251 | 203 |
| 252 // Copies the texture data out of |texture| into |out|. |size| is the | 204 // Copies the texture data out of |texture| into |out|. |size| is the |
| 253 // size of the texture. No post processing is applied to the pixels. The | 205 // size of the texture. No post processing is applied to the pixels. The |
| 254 // texture is assumed to have a format of GL_RGBA with a pixel type of | 206 // texture is assumed to have a format of GL_RGBA with a pixel type of |
| 255 // GL_UNSIGNED_BYTE. This is a blocking call that calls glReadPixels on this | 207 // GL_UNSIGNED_BYTE. This is a blocking call that calls glReadPixels on the |
| 256 // current context. | 208 // current OpenGL context. |
| 257 void ReadbackTextureSync(blink::WebGLId texture, | 209 void ReadbackTextureSync(GLuint texture, |
| 258 const gfx::Rect& src_rect, | 210 const gfx::Rect& src_rect, |
| 259 unsigned char* out); | 211 unsigned char* out); |
| 260 | 212 |
| 261 // Creates a copy of the specified texture. |size| is the size of the texture. | 213 // Creates a copy of the specified texture. |size| is the size of the texture. |
| 262 // Note that the src_texture will have the min/mag filter set to GL_LINEAR | 214 // Note that the src_texture will have the min/mag filter set to GL_LINEAR |
| 263 // and wrap_s/t set to CLAMP_TO_EDGE in this call. | 215 // and wrap_s/t set to CLAMP_TO_EDGE in this call. |
| 264 blink::WebGLId CopyTexture(blink::WebGLId texture, | 216 GLuint CopyTexture(GLuint texture, const gfx::Size& size); |
| 265 const gfx::Size& size); | |
| 266 | 217 |
| 267 // Creates a scaled copy of the specified texture. |src_size| is the size of | 218 // Creates a scaled copy of the specified texture. |src_size| is the size of |
| 268 // the texture and |dst_size| is the size of the resulting copy. | 219 // the texture and |dst_size| is the size of the resulting copy. |
| 269 // Note that the src_texture will have the min/mag filter set to GL_LINEAR | 220 // Note that the src_texture will have the min/mag filter set to GL_LINEAR |
| 270 // and wrap_s/t set to CLAMP_TO_EDGE in this call. | 221 // and wrap_s/t set to CLAMP_TO_EDGE in this call. |
| 271 blink::WebGLId CopyAndScaleTexture( | 222 GLuint CopyAndScaleTexture(GLuint texture, |
| 272 blink::WebGLId texture, | 223 const gfx::Size& src_size, |
| 273 const gfx::Size& src_size, | 224 const gfx::Size& dst_size, |
| 274 const gfx::Size& dst_size, | 225 bool vertically_flip_texture, |
| 275 bool vertically_flip_texture, | 226 ScalerQuality quality); |
| 276 ScalerQuality quality); | |
| 277 | 227 |
| 278 // Returns the shader compiled from the source. | 228 // Returns the shader compiled from the source. |
| 279 blink::WebGLId CompileShaderFromSource(const blink::WGC3Dchar* source, | 229 GLuint CompileShaderFromSource(const GLchar* source, GLenum type); |
| 280 blink::WGC3Denum type); | |
| 281 | 230 |
| 282 // Copies all pixels from |previous_texture| into |texture| that are | 231 // Copies all pixels from |previous_texture| into |texture| that are |
| 283 // inside the region covered by |old_damage| but not part of |new_damage|. | 232 // inside the region covered by |old_damage| but not part of |new_damage|. |
| 284 void CopySubBufferDamage(blink::WebGLId texture, | 233 void CopySubBufferDamage(GLuint texture, |
| 285 blink::WebGLId previous_texture, | 234 GLuint previous_texture, |
| 286 const SkRegion& new_damage, | 235 const SkRegion& new_damage, |
| 287 const SkRegion& old_damage); | 236 const SkRegion& old_damage); |
| 288 | 237 |
| 289 // Simply creates a texture. | 238 // Simply creates a texture. |
| 290 blink::WebGLId CreateTexture(); | 239 GLuint CreateTexture(); |
| 291 // Deletes a texture. | 240 // Deletes a texture. |
| 292 void DeleteTexture(blink::WebGLId texture_id); | 241 void DeleteTexture(GLuint texture_id); |
| 293 | 242 |
| 294 // Insert a sync point into the GL command buffer. | 243 // Insert a sync point into the GL command buffer. |
| 295 uint32 InsertSyncPoint(); | 244 uint32 InsertSyncPoint(); |
| 296 // Wait for the sync point before executing further GL commands. | 245 // Wait for the sync point before executing further GL commands. |
| 297 void WaitSyncPoint(uint32 sync_point); | 246 void WaitSyncPoint(uint32 sync_point); |
| 298 | 247 |
| 299 // Creates a mailbox that is attached to the given texture id, and a sync | 248 // Creates a mailbox that is attached to the given texture id, and a sync |
| 300 // point to wait on before using the mailbox. Returns an empty mailbox on | 249 // point to wait on before using the mailbox. Returns an empty mailbox on |
| 301 // failure. | 250 // failure. |
| 302 // Note the texture is assumed to be GL_TEXTURE_2D. | 251 // Note the texture is assumed to be GL_TEXTURE_2D. |
| 303 gpu::Mailbox ProduceMailboxFromTexture(blink::WebGLId texture_id, | 252 gpu::Mailbox ProduceMailboxFromTexture(GLuint texture_id, uint32* sync_point); |
| 304 uint32* sync_point); | |
| 305 | 253 |
| 306 // Creates a texture and consumes a mailbox into it. Returns 0 on failure. | 254 // Creates a texture and consumes a mailbox into it. Returns 0 on failure. |
| 307 // Note the mailbox is assumed to be GL_TEXTURE_2D. | 255 // Note the mailbox is assumed to be GL_TEXTURE_2D. |
| 308 blink::WebGLId ConsumeMailboxToTexture(const gpu::Mailbox& mailbox, | 256 GLuint ConsumeMailboxToTexture(const gpu::Mailbox& mailbox, |
| 309 uint32 sync_point); | 257 uint32 sync_point); |
| 310 | 258 |
| 311 // Resizes the texture's size to |size|. | 259 // Resizes the texture's size to |size|. |
| 312 void ResizeTexture(blink::WebGLId texture, const gfx::Size& size); | 260 void ResizeTexture(GLuint texture, const gfx::Size& size); |
| 313 | 261 |
| 314 // Copies the framebuffer data given in |rect| to |texture|. | 262 // Copies the framebuffer data given in |rect| to |texture|. |
| 315 void CopyTextureSubImage(blink::WebGLId texture, const gfx::Rect& rect); | 263 void CopyTextureSubImage(GLuint texture, const gfx::Rect& rect); |
| 316 | 264 |
| 317 // Copies the all framebuffer data to |texture|. |size| specifies the | 265 // Copies the all framebuffer data to |texture|. |size| specifies the |
| 318 // size of the framebuffer. | 266 // size of the framebuffer. |
| 319 void CopyTextureFullImage(blink::WebGLId texture, const gfx::Size& size); | 267 void CopyTextureFullImage(GLuint texture, const gfx::Size& size); |
| 320 | 268 |
| 321 // A scaler will cache all intermediate textures and programs | 269 // A scaler will cache all intermediate textures and programs |
| 322 // needed to scale from a specified size to a destination size. | 270 // needed to scale from a specified size to a destination size. |
| 323 // If the source or destination sizes changes, you must create | 271 // If the source or destination sizes changes, you must create |
| 324 // a new scaler. | 272 // a new scaler. |
| 325 class CONTENT_EXPORT ScalerInterface { | 273 class CONTENT_EXPORT ScalerInterface { |
| 326 public: | 274 public: |
| 327 ScalerInterface() {} | 275 ScalerInterface() {} |
| 328 virtual ~ScalerInterface() {} | 276 virtual ~ScalerInterface() {} |
| 329 | 277 |
| 330 // Note that the src_texture will have the min/mag filter set to GL_LINEAR | 278 // Note that the src_texture will have the min/mag filter set to GL_LINEAR |
| 331 // and wrap_s/t set to CLAMP_TO_EDGE in this call. | 279 // and wrap_s/t set to CLAMP_TO_EDGE in this call. |
| 332 virtual void Scale(blink::WebGLId source_texture, | 280 virtual void Scale(GLuint source_texture, GLuint dest_texture) = 0; |
| 333 blink::WebGLId dest_texture) = 0; | |
| 334 virtual const gfx::Size& SrcSize() = 0; | 281 virtual const gfx::Size& SrcSize() = 0; |
| 335 virtual const gfx::Rect& SrcSubrect() = 0; | 282 virtual const gfx::Rect& SrcSubrect() = 0; |
| 336 virtual const gfx::Size& DstSize() = 0; | 283 virtual const gfx::Size& DstSize() = 0; |
| 337 }; | 284 }; |
| 338 | 285 |
| 339 // Note that the quality may be adjusted down if texture | 286 // Note that the quality may be adjusted down if texture |
| 340 // allocations fail or hardware doesn't support the requtested | 287 // allocations fail or hardware doesn't support the requtested |
| 341 // quality. Note that ScalerQuality enum is arranged in | 288 // quality. Note that ScalerQuality enum is arranged in |
| 342 // numerical order for simplicity. | 289 // numerical order for simplicity. |
| 343 ScalerInterface* CreateScaler(ScalerQuality quality, | 290 ScalerInterface* CreateScaler(ScalerQuality quality, |
| 344 const gfx::Size& src_size, | 291 const gfx::Size& src_size, |
| 345 const gfx::Rect& src_subrect, | 292 const gfx::Rect& src_subrect, |
| 346 const gfx::Size& dst_size, | 293 const gfx::Size& dst_size, |
| 347 bool vertically_flip_texture, | 294 bool vertically_flip_texture, |
| 348 bool swizzle); | 295 bool swizzle); |
| 349 | 296 |
| 350 // Create a readback pipeline that will scale a subsection of the source | 297 // Create a readback pipeline that will scale a subsection of the source |
| 351 // texture, then convert it to YUV422 planar form and then read back that. | 298 // texture, then convert it to YUV422 planar form and then read back that. |
| 352 // This reduces the amount of memory read from GPU to CPU memory by a factor | 299 // This reduces the amount of memory read from GPU to CPU memory by a factor |
| 353 // 2.6, which can be quite handy since readbacks have very limited speed | 300 // 2.6, which can be quite handy since readbacks have very limited speed |
| 354 // on some platforms. All values in |dst_size| and |dst_subrect| must be | 301 // on some platforms. All values in |dst_size| and |dst_subrect| must be |
| 355 // a multiple of two. If |use_mrt| is true, the pipeline will try to optimize | 302 // a multiple of two. If |use_mrt| is true, the pipeline will try to optimize |
| 356 // the YUV conversion using the multi-render-target extension. |use_mrt| | 303 // the YUV conversion using the multi-render-target extension. |use_mrt| |
| 357 // should only be set to false for testing. | 304 // should only be set to false for testing. |
| 358 ReadbackYUVInterface* CreateReadbackPipelineYUV( | 305 ReadbackYUVInterface* CreateReadbackPipelineYUV(ScalerQuality quality, |
| 359 ScalerQuality quality, | 306 const gfx::Size& src_size, |
| 360 const gfx::Size& src_size, | 307 const gfx::Rect& src_subrect, |
| 361 const gfx::Rect& src_subrect, | 308 const gfx::Size& dst_size, |
| 362 const gfx::Size& dst_size, | 309 const gfx::Rect& dst_subrect, |
| 363 const gfx::Rect& dst_subrect, | 310 bool flip_vertically, |
| 364 bool flip_vertically, | 311 bool use_mrt); |
| 365 bool use_mrt); | |
| 366 | 312 |
| 367 // Returns the maximum number of draw buffers available, | 313 // Returns the maximum number of draw buffers available, |
| 368 // 0 if GL_EXT_draw_buffers is not available. | 314 // 0 if GL_EXT_draw_buffers is not available. |
| 369 blink::WGC3Dint MaxDrawBuffers(); | 315 GLint MaxDrawBuffers(); |
| 370 | 316 |
| 371 protected: | 317 protected: |
| 372 class CopyTextureToImpl; | 318 class CopyTextureToImpl; |
| 373 | 319 |
| 374 // Creates |copy_texture_to_impl_| if NULL. | 320 // Creates |copy_texture_to_impl_| if NULL. |
| 375 void InitCopyTextToImpl(); | 321 void InitCopyTextToImpl(); |
| 376 // Creates |scaler_impl_| if NULL. | 322 // Creates |scaler_impl_| if NULL. |
| 377 void InitScalerImpl(); | 323 void InitScalerImpl(); |
| 378 | 324 |
| 379 blink::WebGraphicsContext3D* context_; | 325 gpu::gles2::GLES2Interface* gl_; |
| 380 gpu::ContextSupport* context_support_; | 326 gpu::ContextSupport* context_support_; |
| 381 scoped_ptr<CopyTextureToImpl> copy_texture_to_impl_; | 327 scoped_ptr<CopyTextureToImpl> copy_texture_to_impl_; |
| 382 scoped_ptr<GLHelperScaling> scaler_impl_; | 328 scoped_ptr<GLHelperScaling> scaler_impl_; |
| 383 | 329 |
| 384 DISALLOW_COPY_AND_ASSIGN(GLHelper); | 330 DISALLOW_COPY_AND_ASSIGN(GLHelper); |
| 385 }; | 331 }; |
| 386 | 332 |
| 387 // Similar to a ScalerInterface, a yuv readback pipeline will | 333 // Similar to a ScalerInterface, a yuv readback pipeline will |
| 388 // cache a scaler and all intermediate textures and frame buffers | 334 // cache a scaler and all intermediate textures and frame buffers |
| 389 // needed to scale, crop, letterbox and read back a texture from | 335 // needed to scale, crop, letterbox and read back a texture from |
| 390 // the GPU into CPU-accessible RAM. A single readback pipeline | 336 // the GPU into CPU-accessible RAM. A single readback pipeline |
| 391 // can handle multiple outstanding readbacks at the same time, but | 337 // can handle multiple outstanding readbacks at the same time, but |
| 392 // if the source or destination sizes change, you'll need to create | 338 // if the source or destination sizes change, you'll need to create |
| 393 // a new readback pipeline. | 339 // a new readback pipeline. |
| 394 class CONTENT_EXPORT ReadbackYUVInterface { | 340 class CONTENT_EXPORT ReadbackYUVInterface { |
| 395 public: | 341 public: |
| 396 ReadbackYUVInterface() {} | 342 ReadbackYUVInterface() {} |
| 397 virtual ~ReadbackYUVInterface() {} | 343 virtual ~ReadbackYUVInterface() {} |
| 398 | 344 |
| 399 // Note that |target| must use YV12 format. | 345 // Note that |target| must use YV12 format. |
| 400 virtual void ReadbackYUV( | 346 virtual void ReadbackYUV(const gpu::Mailbox& mailbox, |
| 401 const gpu::Mailbox& mailbox, | 347 uint32 sync_point, |
| 402 uint32 sync_point, | 348 const scoped_refptr<media::VideoFrame>& target, |
| 403 const scoped_refptr<media::VideoFrame>& target, | 349 const base::Callback<void(bool)>& callback) = 0; |
| 404 const base::Callback<void(bool)>& callback) = 0; | |
| 405 virtual GLHelper::ScalerInterface* scaler() = 0; | 350 virtual GLHelper::ScalerInterface* scaler() = 0; |
| 406 }; | 351 }; |
| 407 | 352 |
| 408 } // namespace content | 353 } // namespace content |
| 409 | 354 |
| 410 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ | 355 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ |
| OLD | NEW |