gl_helper.h revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.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 GLHelper(WebKit::WebGraphicsContext3D* context, 28 WebKit::WebGraphicsContext3D* context_for_thread); 29 virtual ~GLHelper(); 30 31 WebKit::WebGraphicsContext3D* context() const; 32 33 // Copies the block of pixels specified with |src_subrect| from |src_texture|, 34 // scales it to |dst_size|, and writes it into |out|. 35 // |src_size| is the size of |src_texture|. The result is of format GL_BGRA 36 // and is potentially flipped vertically to make it a correct image 37 // representation. |callback| is invoked with the copy result when the copy 38 // operation has completed. 39 void CropScaleReadbackAndCleanTexture( 40 WebKit::WebGLId src_texture, 41 const gfx::Size& src_size, 42 const gfx::Rect& src_subrect, 43 const gfx::Size& dst_size, 44 unsigned char* out, 45 const base::Callback<void(bool)>& callback); 46 47 // Copies the texture data out of |texture| into |out|. |size| is the 48 // size of the texture. No post processing is applied to the pixels. The 49 // texture is assumed to have a format of GL_RGBA with a pixel type of 50 // GL_UNSIGNED_BYTE. This is a blocking call that calls glReadPixels on this 51 // current context. 52 void ReadbackTextureSync(WebKit::WebGLId texture, 53 const gfx::Rect& src_rect, 54 unsigned char* out); 55 56 // Creates a copy of the specified texture. |size| is the size of the texture. 57 WebKit::WebGLId CopyTexture(WebKit::WebGLId texture, 58 const gfx::Size& size); 59 60 // Creates a scaled copy of the specified texture. |src_size| is the size of 61 // the texture and |dst_size| is the size of the resulting copy. 62 WebKit::WebGLId CopyAndScaleTexture(WebKit::WebGLId texture, 63 const gfx::Size& src_size, 64 const gfx::Size& dst_size, 65 bool vertically_flip_texture); 66 67 // Returns the shader compiled from the source. 68 WebKit::WebGLId CompileShaderFromSource(const WebKit::WGC3Dchar* source, 69 WebKit::WGC3Denum type); 70 71 // Copies all pixels from |previous_texture| into |texture| that are 72 // inside the region covered by |old_damage| but not part of |new_damage|. 73 void CopySubBufferDamage(WebKit::WebGLId texture, 74 WebKit::WebGLId previous_texture, 75 const SkRegion& new_damage, 76 const SkRegion& old_damage); 77 78 private: 79 class CopyTextureToImpl; 80 81 // Creates |copy_texture_to_impl_| if NULL. 82 void InitCopyTextToImpl(); 83 84 WebKit::WebGraphicsContext3D* context_; 85 WebKit::WebGraphicsContext3D* context_for_thread_; 86 scoped_ptr<CopyTextureToImpl> copy_texture_to_impl_; 87 88 // The number of all GLHelper instances. 89 static base::subtle::Atomic32 count_; 90 91 DISALLOW_COPY_AND_ASSIGN(GLHelper); 92}; 93 94} // namespace content 95 96#endif // CONTENT_COMMON_GPU_CLIENT_GL_HELPER_H_ 97