Home | History | Annotate | Download | only in service
      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 
     14 namespace gpu {
     15 namespace gles2 {
     16 
     17 class 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 a blit to a framebuffer object.
     24 class GPU_EXPORT CopyTextureCHROMIUMResourceManager {
     25  public:
     26   CopyTextureCHROMIUMResourceManager();
     27   ~CopyTextureCHROMIUMResourceManager();
     28 
     29   void Initialize(const gles2::GLES2Decoder* decoder);
     30   void Destroy();
     31 
     32   void DoCopyTexture(const gles2::GLES2Decoder* decoder, GLenum source_target,
     33                      GLenum dest_target, GLuint source_id, GLuint dest_id,
     34                      GLint level, GLsizei width, GLsizei height,
     35                      bool flip_y, bool premultiply_alpha,
     36                      bool unpremultiply_alpha);
     37 
     38   // This will apply a transform on the source texture before copying to
     39   // destination texture.
     40   void DoCopyTextureWithTransform(const gles2::GLES2Decoder* decoder,
     41                                   GLenum source_target, GLenum dest_target,
     42                                   GLuint source_id, GLuint dest_id, GLint level,
     43                                   GLsizei width, GLsizei height, bool flip_y,
     44                                   bool premultiply_alpha,
     45                                   bool unpremultiply_alpha,
     46                                   const GLfloat transform_matrix[16]);
     47 
     48   // The attributes used during invocation of the extension.
     49   static const GLuint kVertexPositionAttrib = 0;
     50 
     51  private:
     52   struct ProgramInfo {
     53     ProgramInfo()
     54         : program(0u),
     55           matrix_handle(0u),
     56           half_size_handle(0u),
     57           sampler_handle(0u) {}
     58 
     59     GLuint program;
     60     GLuint matrix_handle;
     61     GLuint half_size_handle;
     62     GLuint sampler_handle;
     63   };
     64 
     65   bool initialized_;
     66   typedef std::vector<GLuint> ShaderVector;
     67   ShaderVector vertex_shaders_;
     68   ShaderVector fragment_shaders_;
     69   typedef std::pair<int, int> ProgramMapKey;
     70   typedef base::hash_map<ProgramMapKey, ProgramInfo> ProgramMap;
     71   ProgramMap programs_;
     72   GLuint buffer_id_;
     73   GLuint framebuffer_;
     74 
     75   DISALLOW_COPY_AND_ASSIGN(CopyTextureCHROMIUMResourceManager);
     76 };
     77 
     78 }  // namespace gpu.
     79 
     80 #endif  // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_
     81