summaryrefslogtreecommitdiffstats
path: root/gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h
blob: 5c62141149d44f1bf250fd70c68e7bce883d9be1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_
#define GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_

#include <vector>

#include "base/containers/hash_tables.h"
#include "gpu/command_buffer/service/gl_utils.h"
#include "gpu/gpu_export.h"

namespace gpu {
namespace gles2 {

class GLES2Decoder;

}  // namespace gles2.

// This class encapsulates the resources required to implement the
// GL_CHROMIUM_copy_texture extension.  The copy operation is performed
// via glCopyTexImage2D() or a blit to a framebuffer object.
// The target of |dest_id| texture must be GL_TEXTURE_2D.
class GPU_EXPORT CopyTextureCHROMIUMResourceManager {
 public:
  CopyTextureCHROMIUMResourceManager();
  ~CopyTextureCHROMIUMResourceManager();

  void Initialize(const gles2::GLES2Decoder* decoder);
  void Destroy();

  void DoCopyTexture(const gles2::GLES2Decoder* decoder,
                     GLenum source_target,
                     GLuint source_id,
                     GLenum source_internal_format,
                     GLuint dest_id,
                     GLenum dest_internal_format,
                     GLsizei width,
                     GLsizei height,
                     bool flip_y,
                     bool premultiply_alpha,
                     bool unpremultiply_alpha);

  void DoCopySubTexture(const gles2::GLES2Decoder* decoder,
                        GLenum source_target,
                        GLuint source_id,
                        GLenum source_internal_format,
                        GLuint dest_id,
                        GLenum dest_internal_format,
                        GLint xoffset,
                        GLint yoffset,
                        GLsizei dest_width,
                        GLsizei dest_height,
                        GLsizei source_width,
                        GLsizei source_height,
                        bool flip_y,
                        bool premultiply_alpha,
                        bool unpremultiply_alpha);

  // This will apply a transform on the source texture before copying to
  // destination texture.
  void DoCopyTextureWithTransform(const gles2::GLES2Decoder* decoder,
                                  GLenum source_target,
                                  GLuint source_id,
                                  GLuint dest_id,
                                  GLsizei width,
                                  GLsizei height,
                                  bool flip_y,
                                  bool premultiply_alpha,
                                  bool unpremultiply_alpha,
                                  const GLfloat transform_matrix[16]);

  void DoCopySubTextureWithTransform(const gles2::GLES2Decoder* decoder,
                                     GLenum source_target,
                                     GLuint source_id,
                                     GLuint dest_id,
                                     GLint xoffset,
                                     GLint yoffset,
                                     GLsizei dest_width,
                                     GLsizei dest_height,
                                     GLsizei source_width,
                                     GLsizei source_height,
                                     bool flip_y,
                                     bool premultiply_alpha,
                                     bool unpremultiply_alpha,
                                     const GLfloat transform_matrix[16]);

  // The attributes used during invocation of the extension.
  static const GLuint kVertexPositionAttrib = 0;

 private:
  struct ProgramInfo {
    ProgramInfo()
        : program(0u),
          matrix_handle(0u),
          half_size_handle(0u),
          sampler_handle(0u) {}

    GLuint program;
    GLuint matrix_handle;
    GLuint half_size_handle;
    GLuint sampler_handle;
  };

  void DoCopyTextureInternal(const gles2::GLES2Decoder* decoder,
                             GLenum source_target,
                             GLuint source_id,
                             GLuint dest_id,
                             GLint xoffset,
                             GLint yoffset,
                             GLsizei dest_width,
                             GLsizei dest_height,
                             GLsizei source_width,
                             GLsizei source_height,
                             bool flip_y,
                             bool premultiply_alpha,
                             bool unpremultiply_alpha,
                             const GLfloat transform_matrix[16]);

  bool initialized_;
  typedef std::vector<GLuint> ShaderVector;
  ShaderVector vertex_shaders_;
  ShaderVector fragment_shaders_;
  typedef std::pair<int, int> ProgramMapKey;
  typedef base::hash_map<ProgramMapKey, ProgramInfo> ProgramMap;
  ProgramMap programs_;
  GLuint buffer_id_;
  GLuint framebuffer_;

  DISALLOW_COPY_AND_ASSIGN(CopyTextureCHROMIUMResourceManager);
};

}  // namespace gpu.

#endif  // GPU_COMMAND_BUFFER_SERVICE_GLES2_CMD_COPY_TEXTURE_CHROMIUM_H_