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" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 // Image quality is nearly as good as the BEST option. | 162 // Image quality is nearly as good as the BEST option. |
163 SCALER_QUALITY_GOOD = 2, | 163 SCALER_QUALITY_GOOD = 2, |
164 | 164 |
165 // Bicubic upscale + N * 50% bicubic downscales. | 165 // Bicubic upscale + N * 50% bicubic downscales. |
166 // Produces very good quality scaled images, but it's | 166 // Produces very good quality scaled images, but it's |
167 // 2-8x slower than the "GOOD" quality, so it's not always | 167 // 2-8x slower than the "GOOD" quality, so it's not always |
168 // worth it. | 168 // worth it. |
169 SCALER_QUALITY_BEST = 3, | 169 SCALER_QUALITY_BEST = 3, |
170 }; | 170 }; |
171 | 171 |
| 172 enum FormatSupport { |
| 173 FORMAT_NOT_SUPPORTED = 0, |
| 174 FORMAT_SUPPORTED, |
| 175 FORMAT_SUPPORT_UNKNOWN, |
| 176 }; |
| 177 |
172 // Copies the block of pixels specified with |src_subrect| from |src_texture|, | 178 // Copies the block of pixels specified with |src_subrect| from |src_texture|, |
173 // scales it to |dst_size|, and writes it into |out|. | 179 // scales it to |dst_size|, and writes it into |out|. |
174 // |src_size| is the size of |src_texture|. The result is of format GL_BGRA | 180 // |src_size| is the size of |src_texture|. The result is of format GL_BGRA |
175 // and is potentially flipped vertically to make it a correct image | 181 // and is potentially flipped vertically to make it a correct image |
176 // representation. |callback| is invoked with the copy result when the copy | 182 // representation. |callback| is invoked with the copy result when the copy |
177 // operation has completed. | 183 // operation has completed. |
178 // Note that the src_texture will have the min/mag filter set to GL_LINEAR | 184 // Note that the src_texture will have the min/mag filter set to GL_LINEAR |
179 // and wrap_s/t set to CLAMP_TO_EDGE in this call. | 185 // and wrap_s/t set to CLAMP_TO_EDGE in this call. |
180 void CropScaleReadbackAndCleanTexture( | 186 void CropScaleReadbackAndCleanTexture( |
181 GLuint src_texture, | 187 GLuint src_texture, |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // Resizes the texture's size to |size|. | 276 // Resizes the texture's size to |size|. |
271 void ResizeTexture(GLuint texture, const gfx::Size& size); | 277 void ResizeTexture(GLuint texture, const gfx::Size& size); |
272 | 278 |
273 // Copies the framebuffer data given in |rect| to |texture|. | 279 // Copies the framebuffer data given in |rect| to |texture|. |
274 void CopyTextureSubImage(GLuint texture, const gfx::Rect& rect); | 280 void CopyTextureSubImage(GLuint texture, const gfx::Rect& rect); |
275 | 281 |
276 // Copies the all framebuffer data to |texture|. |size| specifies the | 282 // Copies the all framebuffer data to |texture|. |size| specifies the |
277 // size of the framebuffer. | 283 // size of the framebuffer. |
278 void CopyTextureFullImage(GLuint texture, const gfx::Size& size); | 284 void CopyTextureFullImage(GLuint texture, const gfx::Size& size); |
279 | 285 |
280 // Check whether rgb565 readback is supported or not. | 286 // Checks whether the readback (Color read format and type) is supported |
281 bool CanUseRgb565Readback(); | 287 // for the requested texture format by the hardware or not. |
| 288 // For ex: some hardwares have rgb565 readback |
| 289 // support when binded with the frame buffer for others it may fail. |
| 290 |
| 291 bool IsReadbackConfigSupported(SkBitmap::Config bitmap_format); |
282 | 292 |
283 // A scaler will cache all intermediate textures and programs | 293 // A scaler will cache all intermediate textures and programs |
284 // needed to scale from a specified size to a destination size. | 294 // needed to scale from a specified size to a destination size. |
285 // If the source or destination sizes changes, you must create | 295 // If the source or destination sizes changes, you must create |
286 // a new scaler. | 296 // a new scaler. |
287 class CONTENT_EXPORT ScalerInterface { | 297 class CONTENT_EXPORT ScalerInterface { |
288 public: | 298 public: |
289 ScalerInterface() {} | 299 ScalerInterface() {} |
290 virtual ~ScalerInterface() {} | 300 virtual ~ScalerInterface() {} |
291 | 301 |
(...skipping 29 matching lines...) Expand all Loading... |
321 const gfx::Rect& src_subrect, | 331 const gfx::Rect& src_subrect, |
322 const gfx::Size& dst_size, | 332 const gfx::Size& dst_size, |
323 const gfx::Rect& dst_subrect, | 333 const gfx::Rect& dst_subrect, |
324 bool flip_vertically, | 334 bool flip_vertically, |
325 bool use_mrt); | 335 bool use_mrt); |
326 | 336 |
327 // Returns the maximum number of draw buffers available, | 337 // Returns the maximum number of draw buffers available, |
328 // 0 if GL_EXT_draw_buffers is not available. | 338 // 0 if GL_EXT_draw_buffers is not available. |
329 GLint MaxDrawBuffers(); | 339 GLint MaxDrawBuffers(); |
330 | 340 |
| 341 private: |
| 342 // IsReadbackConfigSupported does texture bind and attach operations, |
| 343 // better do it in the constructor, and never do it again. |
| 344 // This populates the readback support list at a time once. |
| 345 void InitializeReadbackSupport(); |
| 346 |
| 347 // Helper functions for checking the supported texture formats. |
| 348 // Avoid using this API in between texture operations, as this does some |
| 349 // teture opertions (bind, attach) internally. |
| 350 bool SupportsFormat(GLint format, GLint type); |
| 351 |
331 protected: | 352 protected: |
332 class CopyTextureToImpl; | 353 class CopyTextureToImpl; |
333 | 354 |
334 // Creates |copy_texture_to_impl_| if NULL. | 355 // Creates |copy_texture_to_impl_| if NULL. |
335 void InitCopyTextToImpl(); | 356 void InitCopyTextToImpl(); |
336 // Creates |scaler_impl_| if NULL. | 357 // Creates |scaler_impl_| if NULL. |
337 void InitScalerImpl(); | 358 void InitScalerImpl(); |
338 | 359 |
339 gpu::gles2::GLES2Interface* gl_; | 360 gpu::gles2::GLES2Interface* gl_; |
340 gpu::ContextSupport* context_support_; | 361 gpu::ContextSupport* context_support_; |
341 scoped_ptr<CopyTextureToImpl> copy_texture_to_impl_; | 362 scoped_ptr<CopyTextureToImpl> copy_texture_to_impl_; |
342 scoped_ptr<GLHelperScaling> scaler_impl_; | 363 scoped_ptr<GLHelperScaling> scaler_impl_; |
343 bool initialized_565_format_check_; | 364 FormatSupport format_support_table_[SkBitmap::kConfigCount]; |
344 bool support_565_format_; | |
345 | 365 |
346 DISALLOW_COPY_AND_ASSIGN(GLHelper); | 366 DISALLOW_COPY_AND_ASSIGN(GLHelper); |
347 }; | 367 }; |
348 | 368 |
349 // Similar to a ScalerInterface, a yuv readback pipeline will | 369 // Similar to a ScalerInterface, a yuv readback pipeline will |
350 // cache a scaler and all intermediate textures and frame buffers | 370 // cache a scaler and all intermediate textures and frame buffers |
351 // needed to scale, crop, letterbox and read back a texture from | 371 // needed to scale, crop, letterbox and read back a texture from |
352 // the GPU into CPU-accessible RAM. A single readback pipeline | 372 // the GPU into CPU-accessible RAM. A single readback pipeline |
353 // can handle multiple outstanding readbacks at the same time, but | 373 // can handle multiple outstanding readbacks at the same time, but |
354 // if the source or destination sizes change, you'll need to create | 374 // if the source or destination sizes change, you'll need to create |
355 // a new readback pipeline. | 375 // a new readback pipeline. |
356 class CONTENT_EXPORT ReadbackYUVInterface { | 376 class CONTENT_EXPORT ReadbackYUVInterface { |
357 public: | 377 public: |
358 ReadbackYUVInterface() {} | 378 ReadbackYUVInterface() {} |
359 virtual ~ReadbackYUVInterface() {} | 379 virtual ~ReadbackYUVInterface() {} |
360 | 380 |
361 // Note that |target| must use YV12 format. | 381 // Note that |target| must use YV12 format. |
362 virtual void ReadbackYUV(const gpu::Mailbox& mailbox, | 382 virtual void ReadbackYUV(const gpu::Mailbox& mailbox, |
363 uint32 sync_point, | 383 uint32 sync_point, |
364 const scoped_refptr<media::VideoFrame>& target, | 384 const scoped_refptr<media::VideoFrame>& target, |
365 const base::Callback<void(bool)>& callback) = 0; | 385 const base::Callback<void(bool)>& callback) = 0; |
366 virtual GLHelper::ScalerInterface* scaler() = 0; | 386 virtual GLHelper::ScalerInterface* scaler() = 0; |
367 }; | 387 }; |
368 | 388 |
369 } // namespace content | 389 } // namespace content |
370 | 390 |
371 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ | 391 #endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ |
OLD | NEW |