gl_helper.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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 3// found in the LICENSE file. 4 5#ifndef CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ 6#define CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ 7 8#include "base/atomicops.h" 9#include "base/basictypes.h" 10#include "base/callback.h" 11#include "base/memory/scoped_ptr.h" 12#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" 13 14namespace gfx { 15class Rect; 16class Size; 17} 18 19class SkRegion; 20 21namespace content { 22 23// Provides higher level operations on top of the WebKit::WebGraphicsContext3D 24// interfaces. 25class GLHelper { 26 public: 27 explicit GLHelper(WebGraphicsContext3DCommandBufferImpl* context); 28 virtual ~GLHelper(); 29 30 WebGraphicsContext3DCommandBufferImpl* context() const; 31 32 // Copies the block of pixels specified with |src_subrect| from |src_texture|, 33 // scales it to |dst_size|, and writes it into |out|. 34 // |src_size| is the size of |src_texture|. The result is of format GL_BGRA 35 // and is potentially flipped vertically to make it a correct image 36 // representation. |callback| is invoked with the copy result when the copy 37 // operation has completed. 38 void CropScaleReadbackAndCleanTexture( 39 WebKit::WebGLId src_texture, 40 const gfx::Size& src_size, 41 const gfx::Rect& src_subrect, 42 const gfx::Size& dst_size, 43 unsigned char* out, 44 const base::Callback<void(bool)>& callback); 45 46 // Copies the texture data out of |texture| into |out|. |size| is the 47 // size of the texture. No post processing is applied to the pixels. The 48 // texture is assumed to have a format of GL_RGBA with a pixel type of 49 // GL_UNSIGNED_BYTE. This is a blocking call that calls glReadPixels on this 50 // current context. 51 void ReadbackTextureSync(WebKit::WebGLId texture, 52 const gfx::Rect& src_rect, 53 unsigned char* out); 54 55 // Creates a copy of the specified texture. |size| is the size of the texture. 56 WebKit::WebGLId CopyTexture(WebKit::WebGLId texture, 57 const gfx::Size& size); 58 59 // Creates a scaled copy of the specified texture. |src_size| is the size of 60 // the texture and |dst_size| is the size of the resulting copy. 61 WebKit::WebGLId CopyAndScaleTexture(WebKit::WebGLId texture, 62 const gfx::Size& src_size, 63 const gfx::Size& dst_size, 64 bool vertically_flip_texture); 65 66 // Returns the shader compiled from the source. 67 WebKit::WebGLId CompileShaderFromSource(const WebKit::WGC3Dchar* source, 68 WebKit::WGC3Denum type); 69 70 // Copies all pixels from |previous_texture| into |texture| that are 71 // inside the region covered by |old_damage| but not part of |new_damage|. 72 void CopySubBufferDamage(WebKit::WebGLId texture, 73 WebKit::WebGLId previous_texture, 74 const SkRegion& new_damage, 75 const SkRegion& old_damage); 76 77 private: 78 class CopyTextureToImpl; 79 80 // Creates |copy_texture_to_impl_| if NULL. 81 void InitCopyTextToImpl(); 82 83 WebGraphicsContext3DCommandBufferImpl* context_; 84 scoped_ptr<CopyTextureToImpl> copy_texture_to_impl_; 85 86 DISALLOW_COPY_AND_ASSIGN(GLHelper); 87}; 88 89} // namespace content 90 91#endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ 92