OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GL_SCOPED_BINDERS_H_ | 5 #ifndef UI_GL_SCOPED_BINDERS_H_ |
6 #define UI_GL_SCOPED_BINDERS_H_ | 6 #define UI_GL_SCOPED_BINDERS_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "ui/gl/gl_export.h" | 9 #include "ui/gl/gl_export.h" |
10 | 10 |
11 namespace gfx { | 11 namespace gfx { |
12 class GLStateRestorer; | 12 class GLStateRestorer; |
13 | 13 |
14 class GL_EXPORT ScopedFrameBufferBinder { | 14 class GL_EXPORT ScopedFrameBufferBinder { |
15 public: | 15 public: |
16 explicit ScopedFrameBufferBinder(unsigned int fbo); | 16 explicit ScopedFrameBufferBinder(unsigned int fbo); |
17 ~ScopedFrameBufferBinder(); | 17 ~ScopedFrameBufferBinder(); |
18 | 18 |
19 private: | 19 private: |
20 // Whenever possible we prefer to use the current GLContext's | 20 // Whenever possible we prefer to use the current GLContext's |
21 // GLStateRestorer to maximize driver compabitility. | 21 // GLStateRestorer to maximize driver compabitility. |
22 GLStateRestorer* state_restorer_; | 22 GLStateRestorer* state_restorer_; |
23 | 23 |
24 // Failing that we use GL calls to save and restore state. | 24 // Failing that we use GL calls to save and restore state. |
25 int old_fbo_; | 25 int old_fbo_; |
26 | 26 |
27 DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); | 27 DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); |
28 }; | 28 }; |
29 | 29 |
| 30 class GL_EXPORT ScopedActiveTexture { |
| 31 public: |
| 32 ScopedActiveTexture(unsigned int texture); |
| 33 ~ScopedActiveTexture(); |
| 34 |
| 35 private: |
| 36 // TODO(dcastagna): Use GLStateRestorer. |
| 37 int old_texture_; |
| 38 |
| 39 DISALLOW_COPY_AND_ASSIGN(ScopedActiveTexture); |
| 40 }; |
30 | 41 |
31 class GL_EXPORT ScopedTextureBinder { | 42 class GL_EXPORT ScopedTextureBinder { |
32 public: | 43 public: |
33 ScopedTextureBinder(unsigned int target, unsigned int id); | 44 ScopedTextureBinder(unsigned int target, unsigned int id); |
34 ~ScopedTextureBinder(); | 45 ~ScopedTextureBinder(); |
35 | 46 |
36 private: | 47 private: |
37 // Whenever possible we prefer to use the current GLContext's | 48 // Whenever possible we prefer to use the current GLContext's |
38 // GLStateRestorer to maximize driver compabitility. | 49 // GLStateRestorer to maximize driver compabitility. |
39 GLStateRestorer* state_restorer_; | 50 GLStateRestorer* state_restorer_; |
40 | 51 |
41 // Failing that we use GL calls to save and restore state. | 52 // Failing that we use GL calls to save and restore state. |
42 int target_; | 53 int target_; |
43 int old_id_; | 54 int old_id_; |
44 | 55 |
45 DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder); | 56 DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder); |
46 }; | 57 }; |
47 | 58 |
| 59 class GL_EXPORT ScopedUseProgram { |
| 60 public: |
| 61 ScopedUseProgram(unsigned int program); |
| 62 ~ScopedUseProgram(); |
| 63 |
| 64 private: |
| 65 // TODO(dcastagna): Use GLStateRestorer. |
| 66 int old_program_; |
| 67 |
| 68 DISALLOW_COPY_AND_ASSIGN(ScopedUseProgram); |
| 69 }; |
| 70 |
| 71 class GL_EXPORT ScopedVertexAttribArray { |
| 72 public: |
| 73 ScopedVertexAttribArray(unsigned int index, |
| 74 int size, |
| 75 unsigned int type, |
| 76 char normalized, |
| 77 int stride, |
| 78 const void* pointer); |
| 79 ~ScopedVertexAttribArray(); |
| 80 |
| 81 private: |
| 82 // TODO(dcastagna): Use GLStateRestorer. |
| 83 int enabled_; |
| 84 int index_; |
| 85 int size_; |
| 86 int type_; |
| 87 int normalized_; |
| 88 int stride_; |
| 89 void* pointer_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(ScopedVertexAttribArray); |
| 92 }; |
| 93 |
| 94 class GL_EXPORT ScopedBufferBinder { |
| 95 public: |
| 96 ScopedBufferBinder(unsigned int target, unsigned int index); |
| 97 ~ScopedBufferBinder(); |
| 98 |
| 99 private: |
| 100 // TODO(dcastagna): Use GLStateRestorer. |
| 101 int target_; |
| 102 int old_id_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(ScopedBufferBinder); |
| 105 }; |
| 106 |
| 107 class GL_EXPORT ScopedViewport { |
| 108 public: |
| 109 ScopedViewport(int x, int y, int width, int height); |
| 110 ~ScopedViewport(); |
| 111 |
| 112 private: |
| 113 int data_[4] = {}; |
| 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(ScopedViewport); |
| 116 }; |
| 117 |
| 118 class GL_EXPORT ScopedVertexAttribPointer { |
| 119 public: |
| 120 ScopedVertexAttribPointer(unsigned index, |
| 121 int size, |
| 122 unsigned type, |
| 123 char normalized, |
| 124 int stride, |
| 125 const void* pointer); |
| 126 ~ScopedVertexAttribPointer(); |
| 127 |
| 128 private: |
| 129 DISALLOW_COPY_AND_ASSIGN(ScopedVertexAttribPointer); |
| 130 }; |
| 131 |
| 132 class GL_EXPORT ScopedColorMask { |
| 133 public: |
| 134 ScopedColorMask(char red, char green, char blue, char alpha); |
| 135 ~ScopedColorMask(); |
| 136 |
| 137 private: |
| 138 unsigned char colors_[4] = {}; |
| 139 |
| 140 DISALLOW_COPY_AND_ASSIGN(ScopedColorMask); |
| 141 }; |
| 142 |
| 143 class GL_EXPORT ScopedCapabilitiesRestorer { |
| 144 public: |
| 145 ScopedCapabilitiesRestorer(); |
| 146 ~ScopedCapabilitiesRestorer(); |
| 147 |
| 148 private: |
| 149 static unsigned kCapabilities[]; |
| 150 unsigned char enabled_[8] = {}; |
| 151 |
| 152 DISALLOW_COPY_AND_ASSIGN(ScopedCapabilitiesRestorer); |
| 153 }; |
| 154 |
48 } // namespace gfx | 155 } // namespace gfx |
49 | 156 |
50 #endif // UI_GL_SCOPED_BINDERS_H_ | 157 #endif // UI_GL_SCOPED_BINDERS_H_ |
OLD | NEW |