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