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 GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_ 6#define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_ 7 8#include <vector> 9 10#include "base/containers/hash_tables.h" 11#include "gpu/command_buffer/service/gl_utils.h" 12#include "gpu/gpu_export.h" 13 14namespace gpu { 15namespace gles2 { 16 17class GLES2Decoder; 18 19} // namespace gles2. 20 21// This class encapsulates the resources required to implement the 22// GL_CHROMIUM_copy_texture extension. The copy operation is performed 23// via glCopyTexImage2D() or a blit to a framebuffer object. 24// The target of |dest_id| texture must be GL_TEXTURE_2D. 25class GPU_EXPORT CopyTextureCHROMIUMResourceManager { 26 public: 27 CopyTextureCHROMIUMResourceManager(); 28 ~CopyTextureCHROMIUMResourceManager(); 29 30 void Initialize(const gles2::GLES2Decoder* decoder); 31 void Destroy(); 32 33 void DoCopyTexture(const gles2::GLES2Decoder* decoder, 34 GLenum source_target, 35 GLuint source_id, 36 GLenum source_internal_format, 37 GLuint dest_id, 38 GLint dest_level, 39 GLenum dest_internal_format, 40 GLsizei width, 41 GLsizei height, 42 bool flip_y, 43 bool premultiply_alpha, 44 bool unpremultiply_alpha); 45 46 // This will apply a transform on the source texture before copying to 47 // destination texture. 48 void DoCopyTextureWithTransform(const gles2::GLES2Decoder* decoder, 49 GLenum source_target, 50 GLuint source_id, 51 GLuint dest_id, 52 GLint dest_level, 53 GLsizei width, 54 GLsizei height, 55 bool flip_y, 56 bool premultiply_alpha, 57 bool unpremultiply_alpha, 58 const GLfloat transform_matrix[16]); 59 60 // The attributes used during invocation of the extension. 61 static const GLuint kVertexPositionAttrib = 0; 62 63 private: 64 struct ProgramInfo { 65 ProgramInfo() 66 : program(0u), 67 matrix_handle(0u), 68 half_size_handle(0u), 69 sampler_handle(0u) {} 70 71 GLuint program; 72 GLuint matrix_handle; 73 GLuint half_size_handle; 74 GLuint sampler_handle; 75 }; 76 77 bool initialized_; 78 typedef std::vector<GLuint> ShaderVector; 79 ShaderVector vertex_shaders_; 80 ShaderVector fragment_shaders_; 81 typedef std::pair<int, int> ProgramMapKey; 82 typedef base::hash_map<ProgramMapKey, ProgramInfo> ProgramMap; 83 ProgramMap programs_; 84 GLuint buffer_id_; 85 GLuint framebuffer_; 86 87 DISALLOW_COPY_AND_ASSIGN(CopyTextureCHROMIUMResourceManager); 88}; 89 90} // namespace gpu. 91 92#endif // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_ 93