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