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