| 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 "gpu/command_buffer/client/gles2_interface.h" | 13 #include "gpu/command_buffer/client/gles2_interface.h" |
| 14 #include "gpu/command_buffer/common/mailbox_holder.h" | 14 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 15 | 16 |
| 16 namespace gfx { | 17 namespace gfx { |
| 17 class Rect; | 18 class Rect; |
| 18 class Size; | 19 class Size; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace gpu { | 22 namespace gpu { |
| 22 class ContextSupport; | 23 class ContextSupport; |
| 23 struct Mailbox; | 24 struct Mailbox; |
| 24 } | 25 } |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 // representation. |callback| is invoked with the copy result when the copy | 176 // representation. |callback| is invoked with the copy result when the copy |
| 176 // operation has completed. | 177 // operation has completed. |
| 177 // Note that the src_texture will have the min/mag filter set to GL_LINEAR | 178 // Note that the src_texture will have the min/mag filter set to GL_LINEAR |
| 178 // and wrap_s/t set to CLAMP_TO_EDGE in this call. | 179 // and wrap_s/t set to CLAMP_TO_EDGE in this call. |
| 179 void CropScaleReadbackAndCleanTexture( | 180 void CropScaleReadbackAndCleanTexture( |
| 180 GLuint src_texture, | 181 GLuint src_texture, |
| 181 const gfx::Size& src_size, | 182 const gfx::Size& src_size, |
| 182 const gfx::Rect& src_subrect, | 183 const gfx::Rect& src_subrect, |
| 183 const gfx::Size& dst_size, | 184 const gfx::Size& dst_size, |
| 184 unsigned char* out, | 185 unsigned char* out, |
| 186 bool readback_config_rgb565, |
| 185 const base::Callback<void(bool)>& callback); | 187 const base::Callback<void(bool)>& callback); |
| 186 | 188 |
| 187 // Copies the block of pixels specified with |src_subrect| from |src_mailbox|, | 189 // Copies the block of pixels specified with |src_subrect| from |src_mailbox|, |
| 188 // scales it to |dst_size|, and writes it into |out|. | 190 // scales it to |dst_size|, and writes it into |out|. |
| 189 // |src_size| is the size of |src_mailbox|. The result is of format GL_BGRA | 191 // |src_size| is the size of |src_mailbox|. The result is of format GL_BGRA |
| 190 // and is potentially flipped vertically to make it a correct image | 192 // and is potentially flipped vertically to make it a correct image |
| 191 // representation. |callback| is invoked with the copy result when the copy | 193 // representation. |callback| is invoked with the copy result when the copy |
| 192 // operation has completed. | 194 // operation has completed. |
| 193 // Note that the texture bound to src_mailbox will have the min/mag filter set | 195 // Note that the texture bound to src_mailbox will have the min/mag filter set |
| 194 // to GL_LINEAR and wrap_s/t set to CLAMP_TO_EDGE in this call. src_mailbox is | 196 // to GL_LINEAR and wrap_s/t set to CLAMP_TO_EDGE in this call. src_mailbox is |
| 195 // assumed to be GL_TEXTURE_2D. | 197 // assumed to be GL_TEXTURE_2D. |
| 196 void CropScaleReadbackAndCleanMailbox( | 198 void CropScaleReadbackAndCleanMailbox( |
| 197 const gpu::Mailbox& src_mailbox, | 199 const gpu::Mailbox& src_mailbox, |
| 198 uint32 sync_point, | 200 uint32 sync_point, |
| 199 const gfx::Size& src_size, | 201 const gfx::Size& src_size, |
| 200 const gfx::Rect& src_subrect, | 202 const gfx::Rect& src_subrect, |
| 201 const gfx::Size& dst_size, | 203 const gfx::Size& dst_size, |
| 202 unsigned char* out, | 204 unsigned char* out, |
| 205 bool readback_config_rgb565, |
| 203 const base::Callback<void(bool)>& callback); | 206 const base::Callback<void(bool)>& callback); |
| 204 | 207 |
| 205 // Copies the texture data out of |texture| into |out|. |size| is the | 208 // Copies the texture data out of |texture| into |out|. |size| is the |
| 206 // size of the texture. No post processing is applied to the pixels. The | 209 // size of the texture. No post processing is applied to the pixels. The |
| 207 // texture is assumed to have a format of GL_RGBA with a pixel type of | 210 // texture is assumed to have a format of GL_RGBA with a pixel type of |
| 208 // GL_UNSIGNED_BYTE. This is a blocking call that calls glReadPixels on the | 211 // GL_UNSIGNED_BYTE. This is a blocking call that calls glReadPixels on the |
| 209 // current OpenGL context. | 212 // current OpenGL context. |
| 210 void ReadbackTextureSync(GLuint texture, | 213 void ReadbackTextureSync(GLuint texture, |
| 211 const gfx::Rect& src_rect, | 214 const gfx::Rect& src_rect, |
| 212 unsigned char* out); | 215 unsigned char* out, |
| 216 SkBitmap::Config format); |
| 213 | 217 |
| 214 // Creates a copy of the specified texture. |size| is the size of the texture. | 218 // Creates a copy of the specified texture. |size| is the size of the texture. |
| 215 // 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 |
| 216 // 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. |
| 217 GLuint CopyTexture(GLuint texture, const gfx::Size& size); | 221 GLuint CopyTexture(GLuint texture, const gfx::Size& size); |
| 218 | 222 |
| 219 // Creates a scaled copy of the specified texture. |src_size| is the size of | 223 // Creates a scaled copy of the specified texture. |src_size| is the size of |
| 220 // the texture and |dst_size| is the size of the resulting copy. | 224 // the texture and |dst_size| is the size of the resulting copy. |
| 221 // Note that the src_texture will have the min/mag filter set to GL_LINEAR | 225 // Note that the src_texture will have the min/mag filter set to GL_LINEAR |
| 222 // and wrap_s/t set to CLAMP_TO_EDGE in this call. | 226 // and wrap_s/t set to CLAMP_TO_EDGE in this call. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 // Resizes the texture's size to |size|. | 264 // Resizes the texture's size to |size|. |
| 261 void ResizeTexture(GLuint texture, const gfx::Size& size); | 265 void ResizeTexture(GLuint texture, const gfx::Size& size); |
| 262 | 266 |
| 263 // Copies the framebuffer data given in |rect| to |texture|. | 267 // Copies the framebuffer data given in |rect| to |texture|. |
| 264 void CopyTextureSubImage(GLuint texture, const gfx::Rect& rect); | 268 void CopyTextureSubImage(GLuint texture, const gfx::Rect& rect); |
| 265 | 269 |
| 266 // Copies the all framebuffer data to |texture|. |size| specifies the | 270 // Copies the all framebuffer data to |texture|. |size| specifies the |
| 267 // size of the framebuffer. | 271 // size of the framebuffer. |
| 268 void CopyTextureFullImage(GLuint texture, const gfx::Size& size); | 272 void CopyTextureFullImage(GLuint texture, const gfx::Size& size); |
| 269 | 273 |
| 274 // Check whether rgb565 readback is supported or not. |
| 275 bool CanUseRgb565Readback(); |
| 276 |
| 270 // A scaler will cache all intermediate textures and programs | 277 // A scaler will cache all intermediate textures and programs |
| 271 // needed to scale from a specified size to a destination size. | 278 // needed to scale from a specified size to a destination size. |
| 272 // If the source or destination sizes changes, you must create | 279 // If the source or destination sizes changes, you must create |
| 273 // a new scaler. | 280 // a new scaler. |
| 274 class CONTENT_EXPORT ScalerInterface { | 281 class CONTENT_EXPORT ScalerInterface { |
| 275 public: | 282 public: |
| 276 ScalerInterface() {} | 283 ScalerInterface() {} |
| 277 virtual ~ScalerInterface() {} | 284 virtual ~ScalerInterface() {} |
| 278 | 285 |
| 279 // Note that the src_texture will have the min/mag filter set to GL_LINEAR | 286 // Note that the src_texture will have the min/mag filter set to GL_LINEAR |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 327 |
| 321 // Creates |copy_texture_to_impl_| if NULL. | 328 // Creates |copy_texture_to_impl_| if NULL. |
| 322 void InitCopyTextToImpl(); | 329 void InitCopyTextToImpl(); |
| 323 // Creates |scaler_impl_| if NULL. | 330 // Creates |scaler_impl_| if NULL. |
| 324 void InitScalerImpl(); | 331 void InitScalerImpl(); |
| 325 | 332 |
| 326 gpu::gles2::GLES2Interface* gl_; | 333 gpu::gles2::GLES2Interface* gl_; |
| 327 gpu::ContextSupport* context_support_; | 334 gpu::ContextSupport* context_support_; |
| 328 scoped_ptr<CopyTextureToImpl> copy_texture_to_impl_; | 335 scoped_ptr<CopyTextureToImpl> copy_texture_to_impl_; |
| 329 scoped_ptr<GLHelperScaling> scaler_impl_; | 336 scoped_ptr<GLHelperScaling> scaler_impl_; |
| 337 bool initialized_565_format_check_; |
| 338 bool support_565_format_; |
| 330 | 339 |
| 331 DISALLOW_COPY_AND_ASSIGN(GLHelper); | 340 DISALLOW_COPY_AND_ASSIGN(GLHelper); |
| 332 }; | 341 }; |
| 333 | 342 |
| 334 // Similar to a ScalerInterface, a yuv readback pipeline will | 343 // Similar to a ScalerInterface, a yuv readback pipeline will |
| 335 // cache a scaler and all intermediate textures and frame buffers | 344 // cache a scaler and all intermediate textures and frame buffers |
| 336 // needed to scale, crop, letterbox and read back a texture from | 345 // needed to scale, crop, letterbox and read back a texture from |
| 337 // the GPU into CPU-accessible RAM. A single readback pipeline | 346 // the GPU into CPU-accessible RAM. A single readback pipeline |
| 338 // can handle multiple outstanding readbacks at the same time, but | 347 // can handle multiple outstanding readbacks at the same time, but |
| 339 // if the source or destination sizes change, you'll need to create | 348 // if the source or destination sizes change, you'll need to create |
| 340 // a new readback pipeline. | 349 // a new readback pipeline. |
| 341 class CONTENT_EXPORT ReadbackYUVInterface { | 350 class CONTENT_EXPORT ReadbackYUVInterface { |
| 342 public: | 351 public: |
| 343 ReadbackYUVInterface() {} | 352 ReadbackYUVInterface() {} |
| 344 virtual ~ReadbackYUVInterface() {} | 353 virtual ~ReadbackYUVInterface() {} |
| 345 | 354 |
| 346 // Note that |target| must use YV12 format. | 355 // Note that |target| must use YV12 format. |
| 347 virtual void ReadbackYUV(const gpu::Mailbox& mailbox, | 356 virtual void ReadbackYUV(const gpu::Mailbox& mailbox, |
| 348 uint32 sync_point, | 357 uint32 sync_point, |
| 349 const scoped_refptr<media::VideoFrame>& target, | 358 const scoped_refptr<media::VideoFrame>& target, |
| 350 const base::Callback<void(bool)>& callback) = 0; | 359 const base::Callback<void(bool)>& callback) = 0; |
| 351 virtual GLHelper::ScalerInterface* scaler() = 0; | 360 virtual GLHelper::ScalerInterface* scaler() = 0; |
| 352 }; | 361 }; |
| 353 | 362 |
| 354 } // namespace content | 363 } // namespace content |
| 355 | 364 |
| 356 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ | 365 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ |
| OLD | NEW |