[email protected] | 529c667 | 2012-01-04 02:18:26 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 8a837bb | 2010-01-05 00:21:24 | [diff] [blame] | 5 | #include "gpu/command_buffer/service/gles2_cmd_decoder.h" |
[email protected] | 7447070 | 2010-01-06 18:51:16 | [diff] [blame] | 6 | |
| 7 | #include <stdio.h> |
| 8 | |
[email protected] | 1aef9813 | 2010-02-23 18:00:07 | [diff] [blame] | 9 | #include <algorithm> |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 10 | #include <list> |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 11 | #include <map> |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 12 | #include <stack> |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 13 | #include <string> |
| 14 | #include <vector> |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 15 | |
[email protected] | 00eb49a | 2010-08-12 20:46:57 | [diff] [blame] | 16 | #include "base/at_exit.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 17 | #include "base/atomicops.h" |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 18 | #include "base/bind.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 19 | #include "base/command_line.h" |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 20 | #include "base/debug/trace_event.h" |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 21 | #if defined(OS_MACOSX) |
| 22 | #include "base/mac/scoped_cftyperef.h" |
| 23 | #endif |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 24 | #include "base/memory/scoped_ptr.h" |
| 25 | #include "base/memory/weak_ptr.h" |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 26 | #include "base/string_number_conversions.h" |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 27 | #include "build/build_config.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 28 | #define GLES2_GPU_SERVICE 1 |
| 29 | #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 30 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 31 | #include "gpu/command_buffer/common/debug_marker_manager.h" |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 32 | #include "gpu/command_buffer/common/id_allocator.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 33 | #include "gpu/command_buffer/service/buffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 34 | #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 35 | #include "gpu/command_buffer/service/context_group.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 36 | #include "gpu/command_buffer/service/context_state.h" |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 37 | #include "gpu/command_buffer/service/feature_info.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 38 | #include "gpu/command_buffer/service/framebuffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 39 | #include "gpu/command_buffer/service/gl_utils.h" |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 40 | #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 41 | #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 42 | #include "gpu/command_buffer/service/gpu_switches.h" |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 43 | #include "gpu/command_buffer/service/gpu_trace.h" |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 44 | #include "gpu/command_buffer/service/image_manager.h" |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 45 | #include "gpu/command_buffer/service/mailbox_manager.h" |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 46 | #include "gpu/command_buffer/service/memory_tracking.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 47 | #include "gpu/command_buffer/service/program_manager.h" |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 48 | #include "gpu/command_buffer/service/query_manager.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 49 | #include "gpu/command_buffer/service/renderbuffer_manager.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 50 | #include "gpu/command_buffer/service/shader_manager.h" |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 51 | #include "gpu/command_buffer/service/shader_translator.h" |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 52 | #include "gpu/command_buffer/service/shader_translator_cache.h" |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 53 | #include "gpu/command_buffer/service/stream_texture.h" |
| 54 | #include "gpu/command_buffer/service/stream_texture_manager.h" |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 55 | #include "gpu/command_buffer/service/texture_definition.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 56 | #include "gpu/command_buffer/service/texture_manager.h" |
[email protected] | d8ea977 | 2011-07-11 18:11:43 | [diff] [blame] | 57 | #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 58 | #include "gpu/command_buffer/service/vertex_array_manager.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 59 | #include "ui/gl/gl_context.h" |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 60 | #include "ui/gl/gl_image.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 61 | #include "ui/gl/gl_implementation.h" |
| 62 | #include "ui/gl/gl_surface.h" |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 63 | #if defined(OS_MACOSX) |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 64 | #include "ui/surface/io_surface_support_mac.h" |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 65 | #endif |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 66 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 67 | #if !defined(GL_DEPTH24_STENCIL8) |
| 68 | #define GL_DEPTH24_STENCIL8 0x88F0 |
| 69 | #endif |
| 70 | |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 71 | // TODO(zmo): we can't include "City.h" due to type def conflicts. |
| 72 | extern uint64 CityHash64(const char*, size_t); |
| 73 | |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 74 | namespace gpu { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 75 | namespace gles2 { |
| 76 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 77 | namespace { |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 78 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 79 | static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 80 | |
| 81 | khronos_uint64_t CityHashForAngle(const char* name, unsigned int len) { |
| 82 | return static_cast<khronos_uint64_t>( |
| 83 | CityHash64(name, static_cast<size_t>(len))); |
| 84 | } |
| 85 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 86 | } |
| 87 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 88 | class GLES2DecoderImpl; |
| 89 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 90 | // Check that certain assumptions the code makes are true. There are places in |
| 91 | // the code where shared memory is passed direclty to GL. Example, glUniformiv, |
| 92 | // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe |
| 93 | // a few others) are 32bits. If they are not 32bits the code will have to change |
| 94 | // to call those GL functions with service side memory and then copy the results |
| 95 | // to shared memory, converting the sizes. |
| 96 | COMPILE_ASSERT(sizeof(GLint) == sizeof(uint32), // NOLINT |
| 97 | GLint_not_same_size_as_uint32); |
| 98 | COMPILE_ASSERT(sizeof(GLsizei) == sizeof(uint32), // NOLINT |
| 99 | GLint_not_same_size_as_uint32); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 100 | COMPILE_ASSERT(sizeof(GLfloat) == sizeof(float), // NOLINT |
| 101 | GLfloat_not_same_size_as_float); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 102 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 103 | // TODO(kbr): the use of this anonymous namespace core dumps the |
| 104 | // linker on Mac OS X 10.6 when the symbol ordering file is used |
| 105 | // namespace { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 106 | |
| 107 | // Returns the address of the first byte after a struct. |
| 108 | template <typename T> |
| 109 | const void* AddressAfterStruct(const T& pod) { |
| 110 | return reinterpret_cast<const uint8*>(&pod) + sizeof(pod); |
| 111 | } |
| 112 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 113 | // Returns the address of the frst byte after the struct or NULL if size > |
| 114 | // immediate_data_size. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 115 | template <typename RETURN_TYPE, typename COMMAND_TYPE> |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 116 | RETURN_TYPE GetImmediateDataAs(const COMMAND_TYPE& pod, |
| 117 | uint32 size, |
| 118 | uint32 immediate_data_size) { |
| 119 | return (size <= immediate_data_size) ? |
| 120 | static_cast<RETURN_TYPE>(const_cast<void*>(AddressAfterStruct(pod))) : |
| 121 | NULL; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 122 | } |
| 123 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 124 | // Computes the data size for certain gl commands like glUniform. |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 125 | bool ComputeDataSize( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 126 | GLuint count, |
| 127 | size_t size, |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 128 | unsigned int elements_per_unit, |
| 129 | uint32* dst) { |
| 130 | uint32 value; |
| 131 | if (!SafeMultiplyUint32(count, size, &value)) { |
| 132 | return false; |
| 133 | } |
| 134 | if (!SafeMultiplyUint32(value, elements_per_unit, &value)) { |
| 135 | return false; |
| 136 | } |
| 137 | *dst = value; |
| 138 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | // A struct to hold info about each command. |
| 142 | struct CommandInfo { |
| 143 | int arg_flags; // How to handle the arguments for this command |
| 144 | int arg_count; // How many arguments are expected for this command. |
| 145 | }; |
| 146 | |
| 147 | // A table of CommandInfo for all the commands. |
| 148 | const CommandInfo g_command_info[] = { |
| 149 | #define GLES2_CMD_OP(name) { \ |
| 150 | name::kArgFlags, \ |
| 151 | sizeof(name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \ |
| 152 | |
| 153 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 154 | |
| 155 | #undef GLES2_CMD_OP |
| 156 | }; |
| 157 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 158 | // Return true if a character belongs to the ASCII subset as defined in |
| 159 | // GLSL ES 1.0 spec section 3.1. |
| 160 | static bool CharacterIsValidForGLES(unsigned char c) { |
| 161 | // Printing characters are valid except " $ ` @ \ ' DEL. |
| 162 | if (c >= 32 && c <= 126 && |
| 163 | c != '"' && |
| 164 | c != '$' && |
| 165 | c != '`' && |
| 166 | c != '@' && |
| 167 | c != '\\' && |
| 168 | c != '\'') { |
| 169 | return true; |
| 170 | } |
| 171 | // Horizontal tab, line feed, vertical tab, form feed, carriage return |
| 172 | // are also valid. |
| 173 | if (c >= 9 && c <= 13) { |
| 174 | return true; |
| 175 | } |
| 176 | |
| 177 | return false; |
| 178 | } |
| 179 | |
| 180 | static bool StringIsValidForGLES(const char* str) { |
| 181 | for (; *str; ++str) { |
| 182 | if (!CharacterIsValidForGLES(*str)) { |
| 183 | return false; |
| 184 | } |
| 185 | } |
| 186 | return true; |
| 187 | } |
| 188 | |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 189 | static inline GLenum GetTexInternalFormat(GLenum internal_format) { |
| 190 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 191 | if (internal_format == GL_BGRA_EXT || internal_format == GL_BGRA8_EXT) |
| 192 | return GL_RGBA8; |
| 193 | } |
| 194 | return internal_format; |
| 195 | } |
| 196 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 197 | static void WrappedTexImage2D( |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 198 | GLenum target, |
| 199 | GLint level, |
| 200 | GLenum internal_format, |
| 201 | GLsizei width, |
| 202 | GLsizei height, |
| 203 | GLint border, |
| 204 | GLenum format, |
| 205 | GLenum type, |
| 206 | const void* pixels) { |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 207 | GLenum gl_internal_format = GetTexInternalFormat(internal_format); |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 208 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 209 | if (type == GL_FLOAT) { |
[email protected] | 58b75f9 | 2012-03-20 21:15:43 | [diff] [blame] | 210 | switch (format) { |
| 211 | case GL_RGBA: |
| 212 | gl_internal_format = GL_RGBA32F_ARB; |
| 213 | break; |
| 214 | case GL_RGB: |
| 215 | gl_internal_format = GL_RGB32F_ARB; |
| 216 | break; |
| 217 | case GL_LUMINANCE_ALPHA: |
| 218 | gl_internal_format = GL_LUMINANCE_ALPHA32F_ARB; |
| 219 | break; |
| 220 | case GL_LUMINANCE: |
| 221 | gl_internal_format = GL_LUMINANCE32F_ARB; |
| 222 | break; |
| 223 | case GL_ALPHA: |
| 224 | gl_internal_format = GL_ALPHA32F_ARB; |
| 225 | break; |
| 226 | default: |
| 227 | NOTREACHED(); |
| 228 | break; |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 229 | } |
| 230 | } else if (type == GL_HALF_FLOAT_OES) { |
[email protected] | 58b75f9 | 2012-03-20 21:15:43 | [diff] [blame] | 231 | switch (format) { |
| 232 | case GL_RGBA: |
| 233 | gl_internal_format = GL_RGBA16F_ARB; |
| 234 | break; |
| 235 | case GL_RGB: |
| 236 | gl_internal_format = GL_RGB16F_ARB; |
| 237 | break; |
| 238 | case GL_LUMINANCE_ALPHA: |
| 239 | gl_internal_format = GL_LUMINANCE_ALPHA16F_ARB; |
| 240 | break; |
| 241 | case GL_LUMINANCE: |
| 242 | gl_internal_format = GL_LUMINANCE16F_ARB; |
| 243 | break; |
| 244 | case GL_ALPHA: |
| 245 | gl_internal_format = GL_ALPHA16F_ARB; |
| 246 | break; |
| 247 | default: |
| 248 | NOTREACHED(); |
| 249 | break; |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | } |
| 253 | glTexImage2D( |
| 254 | target, level, gl_internal_format, width, height, border, format, type, |
| 255 | pixels); |
| 256 | } |
| 257 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 258 | // Wrapper for glEnable/glDisable that doesn't suck. |
| 259 | static void EnableDisable(GLenum pname, bool enable) { |
| 260 | if (enable) { |
| 261 | glEnable(pname); |
| 262 | } else { |
| 263 | glDisable(pname); |
| 264 | } |
| 265 | } |
| 266 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 267 | // This class prevents any GL errors that occur when it is in scope from |
| 268 | // being reported to the client. |
| 269 | class ScopedGLErrorSuppressor { |
| 270 | public: |
| 271 | explicit ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder); |
| 272 | ~ScopedGLErrorSuppressor(); |
| 273 | private: |
| 274 | GLES2DecoderImpl* decoder_; |
| 275 | DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); |
| 276 | }; |
| 277 | |
| 278 | // Temporarily changes a decoder's bound 2D texture and restore it when this |
| 279 | // object goes out of scope. Also temporarily switches to using active texture |
| 280 | // unit zero in case the client has changed that to something invalid. |
| 281 | class ScopedTexture2DBinder { |
| 282 | public: |
| 283 | ScopedTexture2DBinder(GLES2DecoderImpl* decoder, GLuint id); |
| 284 | ~ScopedTexture2DBinder(); |
| 285 | |
| 286 | private: |
| 287 | GLES2DecoderImpl* decoder_; |
| 288 | DISALLOW_COPY_AND_ASSIGN(ScopedTexture2DBinder); |
| 289 | }; |
| 290 | |
| 291 | // Temporarily changes a decoder's bound render buffer and restore it when this |
| 292 | // object goes out of scope. |
| 293 | class ScopedRenderBufferBinder { |
| 294 | public: |
| 295 | ScopedRenderBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
| 296 | ~ScopedRenderBufferBinder(); |
| 297 | |
| 298 | private: |
| 299 | GLES2DecoderImpl* decoder_; |
| 300 | DISALLOW_COPY_AND_ASSIGN(ScopedRenderBufferBinder); |
| 301 | }; |
| 302 | |
| 303 | // Temporarily changes a decoder's bound frame buffer and restore it when this |
| 304 | // object goes out of scope. |
| 305 | class ScopedFrameBufferBinder { |
| 306 | public: |
| 307 | ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
| 308 | ~ScopedFrameBufferBinder(); |
| 309 | |
| 310 | private: |
| 311 | GLES2DecoderImpl* decoder_; |
| 312 | DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); |
| 313 | }; |
| 314 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 315 | // Temporarily changes a decoder's bound frame buffer to a resolved version of |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 316 | // the multisampled offscreen render buffer if that buffer is multisampled, and, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 317 | // if it is bound or enforce_internal_framebuffer is true. If internal is |
| 318 | // true, the resolved framebuffer is not visible to the parent. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 319 | class ScopedResolvedFrameBufferBinder { |
| 320 | public: |
[email protected] | e7e3803 | 2011-07-26 17:25:25 | [diff] [blame] | 321 | ScopedResolvedFrameBufferBinder(GLES2DecoderImpl* decoder, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 322 | bool enforce_internal_framebuffer, |
| 323 | bool internal); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 324 | ~ScopedResolvedFrameBufferBinder(); |
| 325 | |
| 326 | private: |
| 327 | GLES2DecoderImpl* decoder_; |
| 328 | bool resolve_and_bind_; |
| 329 | DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); |
| 330 | }; |
| 331 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 332 | // This class records texture upload time when in scope. |
| 333 | class ScopedTextureUploadTimer { |
| 334 | public: |
| 335 | explicit ScopedTextureUploadTimer(GLES2DecoderImpl* decoder); |
| 336 | ~ScopedTextureUploadTimer(); |
| 337 | |
| 338 | private: |
| 339 | GLES2DecoderImpl* decoder_; |
| 340 | base::TimeTicks begin_time_; |
| 341 | DISALLOW_COPY_AND_ASSIGN(ScopedTextureUploadTimer); |
| 342 | }; |
| 343 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 344 | // Encapsulates an OpenGL texture. |
| 345 | class Texture { |
| 346 | public: |
| 347 | explicit Texture(GLES2DecoderImpl* decoder); |
| 348 | ~Texture(); |
| 349 | |
| 350 | // Create a new render texture. |
| 351 | void Create(); |
| 352 | |
| 353 | // Set the initial size and format of a render texture or resize it. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 354 | bool AllocateStorage(const gfx::Size& size, GLenum format); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 355 | |
| 356 | // Copy the contents of the currently bound frame buffer. |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 357 | void Copy(const gfx::Size& size, GLenum format); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 358 | |
| 359 | // Destroy the render texture. This must be explicitly called before |
| 360 | // destroying this object. |
| 361 | void Destroy(); |
| 362 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 363 | // Invalidate the texture. This can be used when a context is lost and it is |
| 364 | // not possible to make it current in order to free the resource. |
| 365 | void Invalidate(); |
| 366 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 367 | GLuint id() const { |
| 368 | return id_; |
| 369 | } |
| 370 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 371 | gfx::Size size() const { |
| 372 | return size_; |
| 373 | } |
| 374 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 375 | size_t estimated_size() const { |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 376 | return memory_tracker_.GetMemRepresented(); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 377 | } |
| 378 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 379 | private: |
| 380 | GLES2DecoderImpl* decoder_; |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 381 | MemoryTypeTracker memory_tracker_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 382 | GLuint id_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 383 | gfx::Size size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 384 | DISALLOW_COPY_AND_ASSIGN(Texture); |
| 385 | }; |
| 386 | |
| 387 | // Encapsulates an OpenGL render buffer of any format. |
| 388 | class RenderBuffer { |
| 389 | public: |
| 390 | explicit RenderBuffer(GLES2DecoderImpl* decoder); |
| 391 | ~RenderBuffer(); |
| 392 | |
| 393 | // Create a new render buffer. |
| 394 | void Create(); |
| 395 | |
| 396 | // Set the initial size and format of a render buffer or resize it. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 397 | bool AllocateStorage(const gfx::Size& size, GLenum format, GLsizei samples); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 398 | |
| 399 | // Destroy the render buffer. This must be explicitly called before destroying |
| 400 | // this object. |
| 401 | void Destroy(); |
| 402 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 403 | // Invalidate the render buffer. This can be used when a context is lost and |
| 404 | // it is not possible to make it current in order to free the resource. |
| 405 | void Invalidate(); |
| 406 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 407 | GLuint id() const { |
| 408 | return id_; |
| 409 | } |
| 410 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 411 | size_t estimated_size() const { |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 412 | return memory_tracker_.GetMemRepresented(); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 413 | } |
| 414 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 415 | private: |
| 416 | GLES2DecoderImpl* decoder_; |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 417 | MemoryTypeTracker memory_tracker_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 418 | GLuint id_; |
| 419 | DISALLOW_COPY_AND_ASSIGN(RenderBuffer); |
| 420 | }; |
| 421 | |
| 422 | // Encapsulates an OpenGL frame buffer. |
| 423 | class FrameBuffer { |
| 424 | public: |
| 425 | explicit FrameBuffer(GLES2DecoderImpl* decoder); |
| 426 | ~FrameBuffer(); |
| 427 | |
| 428 | // Create a new frame buffer. |
| 429 | void Create(); |
| 430 | |
| 431 | // Attach a color render buffer to a frame buffer. |
| 432 | void AttachRenderTexture(Texture* texture); |
| 433 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 434 | // Attach a render buffer to a frame buffer. Note that this unbinds any |
| 435 | // currently bound frame buffer. |
| 436 | void AttachRenderBuffer(GLenum target, RenderBuffer* render_buffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 437 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 438 | // Destroy the frame buffer. This must be explicitly called before destroying |
| 439 | // this object. |
| 440 | void Destroy(); |
| 441 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 442 | // Invalidate the frame buffer. This can be used when a context is lost and it |
| 443 | // is not possible to make it current in order to free the resource. |
| 444 | void Invalidate(); |
| 445 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 446 | // See glCheckFramebufferStatusEXT. |
| 447 | GLenum CheckStatus(); |
| 448 | |
| 449 | GLuint id() const { |
| 450 | return id_; |
| 451 | } |
| 452 | |
| 453 | private: |
| 454 | GLES2DecoderImpl* decoder_; |
| 455 | GLuint id_; |
| 456 | DISALLOW_COPY_AND_ASSIGN(FrameBuffer); |
| 457 | }; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 458 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 459 | // } // anonymous namespace. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 460 | |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 461 | bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, |
| 462 | uint32* service_texture_id) { |
| 463 | return false; |
| 464 | } |
| 465 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 466 | GLES2Decoder::GLES2Decoder() |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 467 | : debug_(false), |
[email protected] | b5d647c | 2012-02-10 01:41:32 | [diff] [blame] | 468 | log_commands_(false), |
| 469 | log_synthesized_gl_errors_(true) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 470 | } |
| 471 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 472 | GLES2Decoder::~GLES2Decoder() { |
| 473 | } |
| 474 | |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 475 | bool GLES2Decoder::testing_force_is_angle_; |
| 476 | |
| 477 | void GLES2Decoder::set_testing_force_is_angle(bool force) { |
| 478 | testing_force_is_angle_ = force; |
| 479 | } |
| 480 | |
| 481 | bool GLES2Decoder::IsAngle() { |
| 482 | #if defined(OS_WIN) |
| 483 | return testing_force_is_angle_ || |
| 484 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; |
| 485 | #else |
| 486 | return testing_force_is_angle_; |
| 487 | #endif |
| 488 | } |
| 489 | |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 490 | // This class implements GLES2Decoder so we don't have to expose all the GLES2 |
| 491 | // cmd stuff to outside this class. |
| 492 | class GLES2DecoderImpl : public base::SupportsWeakPtr<GLES2DecoderImpl>, |
| 493 | public GLES2Decoder { |
| 494 | public: |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 495 | static const int kMaxLogMessages = 256; |
[email protected] | fa20ec8 | 2012-05-04 04:02:48 | [diff] [blame] | 496 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 497 | explicit GLES2DecoderImpl(ContextGroup* group); |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 498 | virtual ~GLES2DecoderImpl(); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 499 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 500 | // Overridden from AsyncAPIInterface. |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 501 | virtual Error DoCommand(unsigned int command, |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 502 | unsigned int arg_count, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 503 | const void* args) OVERRIDE; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 504 | |
| 505 | // Overridden from AsyncAPIInterface. |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 506 | virtual const char* GetCommandName(unsigned int command_id) const OVERRIDE; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 507 | |
| 508 | // Overridden from GLES2Decoder. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 509 | virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
| 510 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 511 | bool offscreen, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 512 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 513 | const DisallowedFeatures& disallowed_features, |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 514 | const char* allowed_extensions, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 515 | const std::vector<int32>& attribs) OVERRIDE; |
| 516 | virtual void Destroy(bool have_context) OVERRIDE; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 517 | virtual void SetSurface( |
| 518 | const scoped_refptr<gfx::GLSurface>& surface) OVERRIDE; |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 519 | virtual bool SetParent(GLES2Decoder* parent_decoder, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 520 | uint32 parent_texture_id) OVERRIDE; |
| 521 | virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) OVERRIDE; |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 522 | void UpdateParentTextureInfo(); |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 523 | virtual bool MakeCurrent() OVERRIDE; |
| 524 | virtual void ReleaseCurrent() OVERRIDE; |
| 525 | virtual GLES2Util* GetGLES2Util() OVERRIDE { return &util_; } |
| 526 | virtual gfx::GLContext* GetGLContext() OVERRIDE { return context_.get(); } |
| 527 | virtual ContextGroup* GetContextGroup() OVERRIDE { return group_.get(); } |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 528 | virtual void RestoreState() const OVERRIDE; |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 529 | virtual QueryManager* GetQueryManager() OVERRIDE { |
| 530 | return query_manager_.get(); |
| 531 | } |
| 532 | virtual VertexArrayManager* GetVertexArrayManager() OVERRIDE { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 533 | return vertex_array_manager_.get(); |
| 534 | } |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 535 | virtual bool ProcessPendingQueries() OVERRIDE; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 536 | |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 537 | virtual void SetGLError(GLenum error, |
| 538 | const char* function_name, |
| 539 | const char* msg); |
| 540 | virtual void SetGLErrorInvalidEnum(const char* function_name, |
| 541 | GLenum value, |
| 542 | const char* label); |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 543 | virtual void SetResizeCallback( |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 544 | const base::Callback<void(gfx::Size)>& callback) OVERRIDE; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 545 | |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 546 | virtual void SetMsgCallback(const MsgCallback& callback) OVERRIDE; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 547 | |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 548 | virtual void SetStreamTextureManager(StreamTextureManager* manager) OVERRIDE; |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 549 | virtual bool GetServiceTextureId(uint32 client_texture_id, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 550 | uint32* service_texture_id) OVERRIDE; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 551 | |
[email protected] | efcdd236 | 2012-07-09 21:07:00 | [diff] [blame] | 552 | virtual uint32 GetGLError() OVERRIDE; |
| 553 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 554 | virtual uint32 GetTextureUploadCount() OVERRIDE; |
| 555 | virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; |
| 556 | virtual base::TimeDelta GetTotalProcessingCommandsTime() OVERRIDE; |
[email protected] | dc25dda | 2012-09-27 21:36:30 | [diff] [blame] | 557 | virtual void AddProcessingCommandsTime(base::TimeDelta) OVERRIDE; |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 558 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 559 | // Restores the current state to the user's settings. |
| 560 | void RestoreCurrentFramebufferBindings(); |
| 561 | void RestoreCurrentRenderbufferBindings(); |
| 562 | void RestoreCurrentTexture2DBindings(); |
| 563 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 564 | // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
| 565 | void ApplyDirtyState(); |
| 566 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 567 | // Reapply the texture parameters to the given texture. |
| 568 | void BindAndApplyTextureParameters(TextureManager::TextureInfo* info); |
| 569 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 570 | // These check the state of the currently bound framebuffer or the |
| 571 | // backbuffer if no framebuffer is bound. |
| 572 | bool BoundFramebufferHasColorAttachmentWithAlpha(); |
| 573 | bool BoundFramebufferHasDepthAttachment(); |
| 574 | bool BoundFramebufferHasStencilAttachment(); |
| 575 | |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 576 | virtual error::ContextLostReason GetContextLostReason() OVERRIDE; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 577 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 578 | private: |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 579 | friend class ScopedGLErrorSuppressor; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 580 | friend class ScopedResolvedFrameBufferBinder; |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 581 | friend class ScopedTextureUploadTimer; |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 582 | friend class Texture; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 583 | friend class RenderBuffer; |
| 584 | friend class FrameBuffer; |
| 585 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 586 | // Initialize or re-initialize the shader translator. |
| 587 | bool InitializeShaderTranslator(); |
| 588 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 589 | void UpdateCapabilities(); |
| 590 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 591 | // Helpers for the glGen and glDelete functions. |
| 592 | bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 593 | void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 594 | bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 595 | void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 596 | bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 597 | void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 598 | bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
| 599 | void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 600 | bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
| 601 | void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 602 | bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
| 603 | void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 604 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 605 | // TODO(gman): Cache these pointers? |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 606 | BufferManager* buffer_manager() { |
| 607 | return group_->buffer_manager(); |
| 608 | } |
| 609 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 610 | RenderbufferManager* renderbuffer_manager() { |
| 611 | return group_->renderbuffer_manager(); |
| 612 | } |
| 613 | |
| 614 | FramebufferManager* framebuffer_manager() { |
| 615 | return group_->framebuffer_manager(); |
| 616 | } |
| 617 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 618 | ProgramManager* program_manager() { |
| 619 | return group_->program_manager(); |
| 620 | } |
| 621 | |
| 622 | ShaderManager* shader_manager() { |
| 623 | return group_->shader_manager(); |
| 624 | } |
| 625 | |
| 626 | TextureManager* texture_manager() { |
| 627 | return group_->texture_manager(); |
| 628 | } |
| 629 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 630 | MailboxManager* mailbox_manager() { |
| 631 | return group_->mailbox_manager(); |
| 632 | } |
| 633 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 634 | ImageManager* image_manager() { |
| 635 | return group_->image_manager(); |
| 636 | } |
| 637 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 638 | VertexArrayManager* vertex_array_manager() { |
| 639 | return vertex_array_manager_.get(); |
| 640 | } |
| 641 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 642 | bool IsOffscreenBufferMultisampled() const { |
| 643 | return offscreen_target_samples_ > 1; |
| 644 | } |
| 645 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 646 | // Creates a TextureInfo for the given texture. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 647 | TextureManager::TextureInfo* CreateTextureInfo( |
| 648 | GLuint client_id, GLuint service_id) { |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 649 | return texture_manager()->CreateTextureInfo(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | // Gets the texture info for the given texture. Returns NULL if none exists. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 653 | TextureManager::TextureInfo* GetTextureInfo(GLuint client_id) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 654 | TextureManager::TextureInfo* info = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 655 | texture_manager()->GetTextureInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 656 | return info; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | // Deletes the texture info for the given texture. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 660 | void RemoveTextureInfo(GLuint client_id) { |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 661 | texture_manager()->RemoveTextureInfo(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 662 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 663 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 664 | // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| 665 | // or regular back buffer). |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 666 | gfx::Size GetBoundReadFrameBufferSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 667 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 668 | // Get the format of the currently bound frame buffer (either FBO or regular |
| 669 | // back buffer) |
| 670 | GLenum GetBoundReadFrameBufferInternalFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 671 | GLenum GetBoundDrawFrameBufferInternalFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 672 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 673 | // Wrapper for CompressedTexImage2D commands. |
| 674 | error::Error DoCompressedTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 675 | GLenum target, |
| 676 | GLint level, |
| 677 | GLenum internal_format, |
| 678 | GLsizei width, |
| 679 | GLsizei height, |
| 680 | GLint border, |
| 681 | GLsizei image_size, |
| 682 | const void* data); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 683 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 684 | // Wrapper for CompressedTexSubImage2D. |
| 685 | void DoCompressedTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 686 | GLenum target, |
| 687 | GLint level, |
| 688 | GLint xoffset, |
| 689 | GLint yoffset, |
| 690 | GLsizei width, |
| 691 | GLsizei height, |
| 692 | GLenum format, |
| 693 | GLsizei imageSize, |
| 694 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 695 | |
| 696 | // Wrapper for CopyTexImage2D. |
| 697 | void DoCopyTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 698 | GLenum target, |
| 699 | GLint level, |
| 700 | GLenum internal_format, |
| 701 | GLint x, |
| 702 | GLint y, |
| 703 | GLsizei width, |
| 704 | GLsizei height, |
| 705 | GLint border); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 706 | |
| 707 | // Wrapper for CopyTexSubImage2D. |
| 708 | void DoCopyTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 709 | GLenum target, |
| 710 | GLint level, |
| 711 | GLint xoffset, |
| 712 | GLint yoffset, |
| 713 | GLint x, |
| 714 | GLint y, |
| 715 | GLsizei width, |
| 716 | GLsizei height); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 717 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 718 | // Wrapper for TexImage2D commands. |
| 719 | error::Error DoTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 720 | GLenum target, |
| 721 | GLint level, |
| 722 | GLenum internal_format, |
| 723 | GLsizei width, |
| 724 | GLsizei height, |
| 725 | GLint border, |
| 726 | GLenum format, |
| 727 | GLenum type, |
| 728 | const void* pixels, |
| 729 | uint32 pixels_size); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 730 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 731 | // Wrapper for TexSubImage2D. |
| 732 | void DoTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 733 | GLenum target, |
| 734 | GLint level, |
| 735 | GLint xoffset, |
| 736 | GLint yoffset, |
| 737 | GLsizei width, |
| 738 | GLsizei height, |
| 739 | GLenum format, |
| 740 | GLenum type, |
| 741 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 742 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 743 | // Wrapper for TexImageIOSurface2DCHROMIUM. |
| 744 | void DoTexImageIOSurface2DCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 745 | GLenum target, |
| 746 | GLsizei width, |
| 747 | GLsizei height, |
| 748 | GLuint io_surface_id, |
| 749 | GLuint plane); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 750 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 751 | void DoCopyTextureCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 752 | GLenum target, |
| 753 | GLuint source_id, |
| 754 | GLuint target_id, |
| 755 | GLint level, |
| 756 | GLenum internal_format); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 757 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 758 | // Wrapper for TexStorage2DEXT. |
| 759 | void DoTexStorage2DEXT( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 760 | GLenum target, |
| 761 | GLint levels, |
| 762 | GLenum internal_format, |
| 763 | GLsizei width, |
| 764 | GLsizei height); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 765 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 766 | void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 767 | void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 768 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 769 | void DoBindTexImage2DCHROMIUM( |
| 770 | GLenum target, |
| 771 | GLint image_id); |
| 772 | void DoReleaseTexImage2DCHROMIUM( |
| 773 | GLenum target, |
| 774 | GLint image_id); |
| 775 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 776 | void DoTraceEndCHROMIUM(void); |
| 777 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 778 | // Creates a ProgramInfo for the given program. |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 779 | ProgramManager::ProgramInfo* CreateProgramInfo( |
| 780 | GLuint client_id, GLuint service_id) { |
| 781 | return program_manager()->CreateProgramInfo(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 782 | } |
| 783 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 784 | // Gets the program info for the given program. Returns NULL if none exists. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 785 | ProgramManager::ProgramInfo* GetProgramInfo(GLuint client_id) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 786 | return program_manager()->GetProgramInfo(client_id); |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 787 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 788 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 789 | // Gets the program info for the given program. If it's not a program |
| 790 | // generates a GL error. Returns NULL if not program. |
| 791 | ProgramManager::ProgramInfo* GetProgramInfoNotShader( |
| 792 | GLuint client_id, const char* function_name) { |
| 793 | ProgramManager::ProgramInfo* info = GetProgramInfo(client_id); |
| 794 | if (!info) { |
| 795 | if (GetShaderInfo(client_id)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 796 | SetGLError( |
| 797 | GL_INVALID_OPERATION, function_name, "shader passed for program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 798 | } else { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 799 | SetGLError(GL_INVALID_VALUE, function_name, "unknown program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | return info; |
| 803 | } |
| 804 | |
| 805 | |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 806 | // Creates a ShaderInfo for the given shader. |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 807 | ShaderManager::ShaderInfo* CreateShaderInfo( |
| 808 | GLuint client_id, |
| 809 | GLuint service_id, |
| 810 | GLenum shader_type) { |
| 811 | return shader_manager()->CreateShaderInfo( |
| 812 | client_id, service_id, shader_type); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // Gets the shader info for the given shader. Returns NULL if none exists. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 816 | ShaderManager::ShaderInfo* GetShaderInfo(GLuint client_id) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 817 | return shader_manager()->GetShaderInfo(client_id); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 818 | } |
| 819 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 820 | // Gets the shader info for the given shader. If it's not a shader generates a |
| 821 | // GL error. Returns NULL if not shader. |
| 822 | ShaderManager::ShaderInfo* GetShaderInfoNotProgram( |
| 823 | GLuint client_id, const char* function_name) { |
| 824 | ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); |
| 825 | if (!info) { |
| 826 | if (GetProgramInfo(client_id)) { |
| 827 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 828 | GL_INVALID_OPERATION, function_name, "program passed for shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 829 | } else { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 830 | SetGLError( |
| 831 | GL_INVALID_VALUE, function_name, "unknown shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 832 | } |
| 833 | } |
| 834 | return info; |
| 835 | } |
| 836 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 837 | // Creates a buffer info for the given buffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 838 | void CreateBufferInfo(GLuint client_id, GLuint service_id) { |
| 839 | return buffer_manager()->CreateBufferInfo(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 840 | } |
| 841 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 842 | // Gets the buffer info for the given buffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 843 | BufferManager::BufferInfo* GetBufferInfo(GLuint client_id) { |
| 844 | BufferManager::BufferInfo* info = |
| 845 | buffer_manager()->GetBufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 846 | return info; |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 847 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 848 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 849 | // Removes any buffers in the VertexAtrribInfos and BufferInfos. This is used |
| 850 | // on glDeleteBuffers so we can make sure the user does not try to render |
| 851 | // with deleted buffers. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 852 | void RemoveBufferInfo(GLuint client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 853 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 854 | // Creates a framebuffer info for the given framebuffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 855 | void CreateFramebufferInfo(GLuint client_id, GLuint service_id) { |
| 856 | return framebuffer_manager()->CreateFramebufferInfo(client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | // Gets the framebuffer info for the given framebuffer. |
| 860 | FramebufferManager::FramebufferInfo* GetFramebufferInfo( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 861 | GLuint client_id) { |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 862 | FramebufferManager::FramebufferInfo* info = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 863 | framebuffer_manager()->GetFramebufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 864 | return info; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | // Removes the framebuffer info for the given framebuffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 868 | void RemoveFramebufferInfo(GLuint client_id) { |
| 869 | framebuffer_manager()->RemoveFramebufferInfo(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | // Creates a renderbuffer info for the given renderbuffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 873 | void CreateRenderbufferInfo(GLuint client_id, GLuint service_id) { |
| 874 | return renderbuffer_manager()->CreateRenderbufferInfo( |
| 875 | client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | // Gets the renderbuffer info for the given renderbuffer. |
| 879 | RenderbufferManager::RenderbufferInfo* GetRenderbufferInfo( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 880 | GLuint client_id) { |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 881 | RenderbufferManager::RenderbufferInfo* info = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 882 | renderbuffer_manager()->GetRenderbufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 883 | return info; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | // Removes the renderbuffer info for the given renderbuffer. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 887 | void RemoveRenderbufferInfo(GLuint client_id) { |
| 888 | renderbuffer_manager()->RemoveRenderbufferInfo(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 889 | } |
| 890 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 891 | // Gets the vertex attrib manager for the given vertex array. |
| 892 | VertexAttribManager* GetVertexAttribManager(GLuint client_id) { |
| 893 | VertexAttribManager* info = |
| 894 | vertex_array_manager()->GetVertexAttribManager(client_id); |
| 895 | return info; |
| 896 | } |
| 897 | |
| 898 | // Removes the vertex attrib manager for the given vertex array. |
| 899 | void RemoveVertexAttribManager(GLuint client_id) { |
| 900 | vertex_array_manager()->RemoveVertexAttribManager(client_id); |
| 901 | } |
| 902 | |
| 903 | // Creates a vertex attrib manager for the given vertex array. |
| 904 | void CreateVertexAttribManager(GLuint client_id, GLuint service_id) { |
| 905 | return vertex_array_manager()->CreateVertexAttribManager( |
| 906 | client_id, service_id, group_->max_vertex_attribs()); |
| 907 | } |
| 908 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 909 | void DoBindAttribLocation(GLuint client_id, GLuint index, const char* name); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 910 | void DoBindUniformLocationCHROMIUM( |
| 911 | GLuint client_id, GLint location, const char* name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 912 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 913 | error::Error GetAttribLocationHelper( |
| 914 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 915 | const std::string& name_str); |
| 916 | |
| 917 | error::Error GetUniformLocationHelper( |
| 918 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 919 | const std::string& name_str); |
| 920 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 921 | // Helper for glShaderSource. |
| 922 | error::Error ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 923 | GLuint client_id, const char* data, uint32 data_size); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 924 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 925 | // Clear any textures used by the current program. |
| 926 | bool ClearUnclearedTextures(); |
| 927 | |
| 928 | // Clear any uncleared level in texture. |
| 929 | // Returns false if there was a generated GL error. |
| 930 | bool ClearTexture(TextureManager::TextureInfo* info); |
| 931 | |
| 932 | // Clears any uncleared attachments attached to the given frame buffer. |
| 933 | // Returns false if there was a generated GL error. |
| 934 | void ClearUnclearedAttachments( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 935 | GLenum target, FramebufferManager::FramebufferInfo* info); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 936 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 937 | // overridden from GLES2Decoder |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 938 | virtual bool ClearLevel(unsigned service_id, |
| 939 | unsigned bind_target, |
| 940 | unsigned target, |
| 941 | int level, |
| 942 | unsigned format, |
| 943 | unsigned type, |
| 944 | int width, |
| 945 | int height, |
| 946 | bool is_texture_immutable) OVERRIDE; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 947 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 948 | // Restore all GL state that affects clearing. |
| 949 | void RestoreClearState(); |
| 950 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 951 | // Remembers the state of some capabilities. |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 952 | // Returns: true if glEnable/glDisable should actually be called. |
| 953 | bool SetCapabilityState(GLenum cap, bool enabled); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 954 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 955 | // Check that the currently bound framebuffers are valid. |
| 956 | // Generates GL error if not. |
| 957 | bool CheckBoundFramebuffersValid(const char* func_name); |
| 958 | |
| 959 | // Check if a framebuffer meets our requirements. |
| 960 | bool CheckFramebufferValid( |
| 961 | FramebufferManager::FramebufferInfo* framebuffer, |
| 962 | GLenum target, |
| 963 | const char* func_name); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 964 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 965 | // Checks if the current program exists and is valid. If not generates the |
| 966 | // appropriate GL error. Returns true if the current program is in a usable |
| 967 | // state. |
| 968 | bool CheckCurrentProgram(const char* function_name); |
| 969 | |
| 970 | // Checks if the current program exists and is valid and that location is not |
| 971 | // -1. If the current program is not valid generates the appropriate GL |
| 972 | // error. Returns true if the current program is in a usable state and |
| 973 | // location is not -1. |
| 974 | bool CheckCurrentProgramForUniform(GLint location, const char* function_name); |
| 975 | |
| 976 | // Gets the type of a uniform for a location in the current program. Sets GL |
| 977 | // errors if the current program is not valid. Returns true if the current |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 978 | // program is valid and the location exists. Adjusts count so it |
| 979 | // does not overflow the uniform. |
| 980 | bool PrepForSetUniformByLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 981 | GLint fake_location, const char* function_name, |
| 982 | GLint* real_location, GLenum* type, GLsizei* count); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 983 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 984 | // Gets the service id for any simulated backbuffer fbo. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 985 | GLuint GetBackbufferServiceId() const; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 986 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 987 | // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv |
| 988 | bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 989 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 990 | // Wrapper for glCreateProgram |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 991 | bool CreateProgramHelper(GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 992 | |
| 993 | // Wrapper for glCreateShader |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 994 | bool CreateShaderHelper(GLenum type, GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 995 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 996 | // Wrapper for glActiveTexture |
| 997 | void DoActiveTexture(GLenum texture_unit); |
| 998 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 999 | // Wrapper for glAttachShader |
| 1000 | void DoAttachShader(GLuint client_program_id, GLint client_shader_id); |
| 1001 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1002 | // Wrapper for glBindBuffer since we need to track the current targets. |
| 1003 | void DoBindBuffer(GLenum target, GLuint buffer); |
| 1004 | |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 1005 | // Wrapper for glBindFramebuffer since we need to track the current targets. |
| 1006 | void DoBindFramebuffer(GLenum target, GLuint framebuffer); |
| 1007 | |
| 1008 | // Wrapper for glBindRenderbuffer since we need to track the current targets. |
| 1009 | void DoBindRenderbuffer(GLenum target, GLuint renderbuffer); |
| 1010 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1011 | // Wrapper for glBindTexture since we need to track the current targets. |
| 1012 | void DoBindTexture(GLenum target, GLuint texture); |
| 1013 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1014 | // Wrapper for glBindVertexArrayOES |
| 1015 | void DoBindVertexArrayOES(GLuint array); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 1016 | void EmulateVertexArrayState(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1017 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1018 | // Wrapper for glBlitFramebufferEXT. |
| 1019 | void DoBlitFramebufferEXT( |
| 1020 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 1021 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 1022 | GLbitfield mask, GLenum filter); |
| 1023 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1024 | // Wrapper for glBufferData. |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 1025 | void DoBufferData( |
| 1026 | GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); |
| 1027 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1028 | // Wrapper for glBufferSubData. |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 1029 | void DoBufferSubData( |
| 1030 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); |
| 1031 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1032 | // Wrapper for glCheckFramebufferStatus |
| 1033 | GLenum DoCheckFramebufferStatus(GLenum target); |
| 1034 | |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1035 | // Wrapper for glClear |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1036 | error::Error DoClear(GLbitfield mask); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1037 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1038 | // Wrappers for various state. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1039 | void DoDepthRangef(GLclampf znear, GLclampf zfar); |
| 1040 | void DoHint(GLenum target, GLenum mode); |
| 1041 | void DoSampleCoverage (GLclampf value, GLboolean invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1042 | |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1043 | // Wrapper for glCompileShader. |
| 1044 | void DoCompileShader(GLuint shader); |
| 1045 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1046 | // Helper for DeleteSharedIdsCHROMIUM commands. |
| 1047 | void DoDeleteSharedIdsCHROMIUM( |
| 1048 | GLuint namespace_id, GLsizei n, const GLuint* ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1049 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1050 | // Wrapper for glDetachShader |
| 1051 | void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
| 1052 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1053 | // Wrapper for glDisable |
| 1054 | void DoDisable(GLenum cap); |
| 1055 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1056 | // Wrapper for glDisableVertexAttribArray. |
| 1057 | void DoDisableVertexAttribArray(GLuint index); |
| 1058 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1059 | // Wrapper for glEnable |
| 1060 | void DoEnable(GLenum cap); |
| 1061 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1062 | // Wrapper for glEnableVertexAttribArray. |
| 1063 | void DoEnableVertexAttribArray(GLuint index); |
| 1064 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1065 | // Wrapper for glFinish. |
| 1066 | void DoFinish(); |
| 1067 | |
| 1068 | // Wrapper for glFlush. |
| 1069 | void DoFlush(); |
| 1070 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1071 | // Wrapper for glFramebufferRenderbufffer. |
| 1072 | void DoFramebufferRenderbuffer( |
| 1073 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
| 1074 | GLuint renderbuffer); |
| 1075 | |
| 1076 | // Wrapper for glFramebufferTexture2D. |
| 1077 | void DoFramebufferTexture2D( |
| 1078 | GLenum target, GLenum attachment, GLenum textarget, GLuint texture, |
| 1079 | GLint level); |
| 1080 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1081 | // Wrapper for glGenerateMipmap |
| 1082 | void DoGenerateMipmap(GLenum target); |
| 1083 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1084 | // Helper for GenSharedIdsCHROMIUM commands. |
| 1085 | void DoGenSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1086 | GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids); |
| 1087 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1088 | // Wrapper for DoGetBooleanv. |
| 1089 | void DoGetBooleanv(GLenum pname, GLboolean* params); |
| 1090 | |
| 1091 | // Wrapper for DoGetFloatv. |
| 1092 | void DoGetFloatv(GLenum pname, GLfloat* params); |
| 1093 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1094 | // Wrapper for glGetFramebufferAttachmentParameteriv. |
| 1095 | void DoGetFramebufferAttachmentParameteriv( |
| 1096 | GLenum target, GLenum attachment, GLenum pname, GLint* params); |
| 1097 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1098 | // Wrapper for glGetIntegerv. |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1099 | void DoGetIntegerv(GLenum pname, GLint* params); |
| 1100 | |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1101 | // Gets the max value in a range in a buffer. |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1102 | GLuint DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1103 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); |
| 1104 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1105 | // Wrapper for glGetProgramiv. |
| 1106 | void DoGetProgramiv( |
| 1107 | GLuint program_id, GLenum pname, GLint* params); |
| 1108 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1109 | // Wrapper for glRenderbufferParameteriv. |
| 1110 | void DoGetRenderbufferParameteriv( |
| 1111 | GLenum target, GLenum pname, GLint* params); |
| 1112 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 1113 | // Wrapper for glGetShaderiv |
| 1114 | void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); |
| 1115 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1116 | // Wrappers for glGetVertexAttrib. |
| 1117 | void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); |
| 1118 | void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); |
| 1119 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1120 | // Wrappers for glIsXXX functions. |
[email protected] | 3dc69c4 | 2012-05-12 02:29:24 | [diff] [blame] | 1121 | bool DoIsEnabled(GLenum cap); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1122 | bool DoIsBuffer(GLuint client_id); |
| 1123 | bool DoIsFramebuffer(GLuint client_id); |
| 1124 | bool DoIsProgram(GLuint client_id); |
| 1125 | bool DoIsRenderbuffer(GLuint client_id); |
| 1126 | bool DoIsShader(GLuint client_id); |
| 1127 | bool DoIsTexture(GLuint client_id); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1128 | bool DoIsVertexArrayOES(GLuint client_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1129 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1130 | // Wrapper for glLinkProgram |
| 1131 | void DoLinkProgram(GLuint program); |
| 1132 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1133 | // Helper for RegisterSharedIdsCHROMIUM. |
| 1134 | void DoRegisterSharedIdsCHROMIUM( |
| 1135 | GLuint namespace_id, GLsizei n, const GLuint* ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1136 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1137 | // Wrapper for glRenderbufferStorage. |
| 1138 | void DoRenderbufferStorage( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1139 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1140 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1141 | // Wrapper for glRenderbufferStorageMultisampleEXT. |
| 1142 | void DoRenderbufferStorageMultisample( |
| 1143 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1144 | GLsizei width, GLsizei height); |
| 1145 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1146 | // Wrapper for glReleaseShaderCompiler. |
| 1147 | void DoReleaseShaderCompiler() { } |
| 1148 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1149 | // Wrappers for glTexParameter functions. |
| 1150 | void DoTexParameterf(GLenum target, GLenum pname, GLfloat param); |
| 1151 | void DoTexParameteri(GLenum target, GLenum pname, GLint param); |
| 1152 | void DoTexParameterfv(GLenum target, GLenum pname, const GLfloat* params); |
| 1153 | void DoTexParameteriv(GLenum target, GLenum pname, const GLint* params); |
| 1154 | |
| 1155 | // Wrappers for glUniform1i and glUniform1iv as according to the GLES2 |
| 1156 | // spec only these 2 functions can be used to set sampler uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1157 | void DoUniform1i(GLint fake_location, GLint v0); |
| 1158 | void DoUniform1iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1159 | void DoUniform2iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1160 | void DoUniform3iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1161 | void DoUniform4iv(GLint fake_location, GLsizei count, const GLint* value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1162 | |
| 1163 | // Wrappers for glUniformfv because some drivers don't correctly accept |
| 1164 | // bool uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1165 | void DoUniform1fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1166 | void DoUniform2fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1167 | void DoUniform3fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1168 | void DoUniform4fv(GLint fake_location, GLsizei count, const GLfloat* value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1169 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1170 | void DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1171 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1172 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1173 | void DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1174 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1175 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1176 | void DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1177 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1178 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1179 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1180 | // Wrappers for glVertexAttrib?? |
| 1181 | void DoVertexAttrib1f(GLuint index, GLfloat v0); |
| 1182 | void DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1); |
| 1183 | void DoVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2); |
| 1184 | void DoVertexAttrib4f( |
| 1185 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); |
| 1186 | void DoVertexAttrib1fv(GLuint index, const GLfloat *v); |
| 1187 | void DoVertexAttrib2fv(GLuint index, const GLfloat *v); |
| 1188 | void DoVertexAttrib3fv(GLuint index, const GLfloat *v); |
| 1189 | void DoVertexAttrib4fv(GLuint index, const GLfloat *v); |
| 1190 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1191 | // Wrapper for glViewport |
| 1192 | void DoViewport(GLint x, GLint y, GLsizei width, GLsizei height); |
| 1193 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1194 | // Wrapper for glUseProgram |
| 1195 | void DoUseProgram(GLuint program); |
| 1196 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1197 | // Wrapper for glValidateProgram. |
| 1198 | void DoValidateProgram(GLuint program_client_id); |
| 1199 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 1200 | void DoInsertEventMarkerEXT(GLsizei length, const GLchar* marker); |
| 1201 | void DoPushGroupMarkerEXT(GLsizei length, const GLchar* group); |
| 1202 | void DoPopGroupMarkerEXT(void); |
| 1203 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 1204 | // Gets the number of values that will be returned by glGetXXX. Returns |
| 1205 | // false if pname is unknown. |
| 1206 | bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values); |
| 1207 | |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 1208 | // Gets the GLError and stores it in our wrapper. Effectively |
| 1209 | // this lets us peek at the error without losing it. |
| 1210 | GLenum PeekGLError(); |
| 1211 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1212 | // Copies the real GL errors to the wrapper. This is so we can |
| 1213 | // make sure there are no native GL errors before calling some GL function |
| 1214 | // so that on return we know any error generated was for that specific |
| 1215 | // command. |
| 1216 | void CopyRealGLErrorsToWrapper(); |
| 1217 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1218 | // Clear all real GL errors. This is to prevent the client from seeing any |
| 1219 | // errors caused by GL calls that it was not responsible for issuing. |
| 1220 | void ClearRealGLErrors(); |
| 1221 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1222 | // Checks if the current program and vertex attributes are valid for drawing. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1223 | bool IsDrawValid( |
| 1224 | const char* function_name, GLuint max_vertex_accessed, GLsizei primcount); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1225 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 1226 | // Returns true if successful, simulated will be true if attrib0 was |
| 1227 | // simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1228 | bool SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1229 | const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1230 | void RestoreStateForAttrib(GLuint attrib); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1231 | |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 1232 | // Returns true if textures were set. |
| 1233 | bool SetBlackTextureForNonRenderableTextures(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1234 | void RestoreStateForNonRenderableTextures(); |
| 1235 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1236 | // Returns true if GL_FIXED attribs were simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1237 | bool SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1238 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1239 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1240 | void RestoreStateForSimulatedFixedAttribs(); |
| 1241 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1242 | // Handle DrawArrays and DrawElements for both instanced and non-instanced |
| 1243 | // cases (primcount is 0 for non-instanced). |
| 1244 | error::Error DoDrawArrays( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1245 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1246 | bool instanced, GLenum mode, GLint first, GLsizei count, |
| 1247 | GLsizei primcount); |
| 1248 | error::Error DoDrawElements( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1249 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1250 | bool instanced, GLenum mode, GLsizei count, GLenum type, |
| 1251 | int32 offset, GLsizei primcount); |
| 1252 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1253 | // Gets the buffer id for a given target. |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1254 | BufferManager::BufferInfo* GetBufferInfoForTarget(GLenum target) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1255 | DCHECK(target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1256 | if (target == GL_ARRAY_BUFFER) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1257 | return state_.bound_array_buffer; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1258 | } else { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1259 | return state_.vertex_attrib_manager->element_array_buffer(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1260 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1261 | } |
| 1262 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1263 | // Gets the texture id for a given target. |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1264 | TextureManager::TextureInfo* GetTextureInfoForTarget(GLenum target) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1265 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1266 | TextureManager::TextureInfo* info = NULL; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1267 | switch (target) { |
| 1268 | case GL_TEXTURE_2D: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1269 | info = unit.bound_texture_2d; |
| 1270 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1271 | case GL_TEXTURE_CUBE_MAP: |
| 1272 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1273 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1274 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1275 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1276 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1277 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1278 | info = unit.bound_texture_cube_map; |
| 1279 | break; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1280 | case GL_TEXTURE_EXTERNAL_OES: |
| 1281 | info = unit.bound_texture_external_oes; |
| 1282 | break; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1283 | case GL_TEXTURE_RECTANGLE_ARB: |
| 1284 | info = unit.bound_texture_rectangle_arb; |
| 1285 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1286 | default: |
| 1287 | NOTREACHED(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1288 | return NULL; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1289 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 1290 | return info; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1291 | } |
| 1292 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 1293 | TextureManager::TextureInfo* GetTextureInfoForTargetUnlessDefault( |
| 1294 | GLenum target) { |
| 1295 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 1296 | if (!info) |
| 1297 | return NULL; |
| 1298 | if (info == texture_manager()->GetDefaultTextureInfo(target)) |
| 1299 | return NULL; |
| 1300 | return info; |
| 1301 | } |
| 1302 | |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1303 | GLenum GetBindTargetForSamplerType(GLenum type) { |
| 1304 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1305 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 1306 | switch (type) { |
| 1307 | case GL_SAMPLER_2D: |
| 1308 | return GL_TEXTURE_2D; |
| 1309 | case GL_SAMPLER_CUBE: |
| 1310 | return GL_TEXTURE_CUBE_MAP; |
| 1311 | case GL_SAMPLER_EXTERNAL_OES: |
| 1312 | return GL_TEXTURE_EXTERNAL_OES; |
| 1313 | case GL_SAMPLER_2D_RECT_ARB: |
| 1314 | return GL_TEXTURE_RECTANGLE_ARB; |
| 1315 | } |
| 1316 | |
| 1317 | NOTREACHED(); |
| 1318 | return 0; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1319 | } |
| 1320 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1321 | // Gets the framebuffer info for a particular target. |
| 1322 | FramebufferManager::FramebufferInfo* GetFramebufferInfoForTarget( |
| 1323 | GLenum target) { |
| 1324 | FramebufferManager::FramebufferInfo* info = NULL; |
| 1325 | switch (target) { |
| 1326 | case GL_FRAMEBUFFER: |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1327 | case GL_DRAW_FRAMEBUFFER_EXT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1328 | info = state_.bound_draw_framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1329 | break; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1330 | case GL_READ_FRAMEBUFFER_EXT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1331 | info = state_.bound_read_framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1332 | break; |
| 1333 | default: |
| 1334 | NOTREACHED(); |
| 1335 | break; |
| 1336 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 1337 | return info; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1338 | } |
| 1339 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1340 | RenderbufferManager::RenderbufferInfo* GetRenderbufferInfoForTarget( |
| 1341 | GLenum target) { |
| 1342 | RenderbufferManager::RenderbufferInfo* info = NULL; |
| 1343 | switch (target) { |
| 1344 | case GL_RENDERBUFFER: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1345 | info = state_.bound_renderbuffer; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1346 | break; |
| 1347 | default: |
| 1348 | NOTREACHED(); |
| 1349 | break; |
| 1350 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 1351 | return info; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1352 | } |
| 1353 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1354 | // Validates the program and location for a glGetUniform call and returns |
| 1355 | // a SizeResult setup to receive the result. Returns true if glGetUniform |
| 1356 | // should be called. |
| 1357 | bool GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1358 | GLuint program, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1359 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1360 | error::Error* error, GLint* real_location, GLuint* service_id, |
| 1361 | void** result, GLenum* result_type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1362 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1363 | // Computes the estimated memory used for the backbuffer and passes it to |
| 1364 | // the tracing system. |
[email protected] | 260ddc4e | 2012-06-28 00:01:53 | [diff] [blame] | 1365 | size_t GetBackbufferMemoryTotal(); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1366 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1367 | // Returns true if the context was just lost due to e.g. GL_ARB_robustness. |
| 1368 | bool WasContextLost(); |
| 1369 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1370 | #if defined(OS_MACOSX) |
| 1371 | void ReleaseIOSurfaceForTexture(GLuint texture_id); |
| 1372 | #endif |
| 1373 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 1374 | // Validates the combination of texture parameters. For example validates that |
| 1375 | // for a given format the specific type, level and targets are valid. |
| 1376 | // Synthesizes the correct GL error if invalid. Returns true if valid. |
| 1377 | bool ValidateTextureParameters( |
| 1378 | const char* function_name, |
| 1379 | GLenum target, GLenum format, GLenum type, GLint level); |
| 1380 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1381 | bool ValidateCompressedTexDimensions( |
| 1382 | const char* function_name, |
| 1383 | GLint level, GLsizei width, GLsizei height, GLenum format); |
| 1384 | bool ValidateCompressedTexFuncData( |
| 1385 | const char* function_name, |
| 1386 | GLsizei width, GLsizei height, GLenum format, size_t size); |
| 1387 | bool ValidateCompressedTexSubDimensions( |
| 1388 | const char* function_name, |
| 1389 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 1390 | GLsizei width, GLsizei height, GLenum format, |
| 1391 | TextureManager::TextureInfo* texture); |
| 1392 | |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 1393 | void LogMessage(const std::string& msg); |
| 1394 | void RenderWarning(const std::string& msg); |
| 1395 | void PerformanceWarning(const std::string& msg); |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 1396 | const std::string& GetLogPrefix() const; |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 1397 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 1398 | const FeatureInfo::FeatureFlags& features() const { |
| 1399 | return feature_info_->feature_flags(); |
| 1400 | } |
| 1401 | |
| 1402 | const FeatureInfo::Workarounds& workarounds() const { |
| 1403 | return feature_info_->workarounds(); |
| 1404 | } |
| 1405 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1406 | bool ShouldDeferDraws() { |
| 1407 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1408 | state_.bound_draw_framebuffer == NULL && |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1409 | surface_->DeferDraws(); |
| 1410 | } |
| 1411 | |
[email protected] | c447acd | 2012-07-23 23:48:41 | [diff] [blame] | 1412 | void ForceCompileShaderIfPending(ShaderManager::ShaderInfo* info); |
| 1413 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1414 | // Generate a member function prototype for each command in an automated and |
| 1415 | // typesafe way. |
| 1416 | #define GLES2_CMD_OP(name) \ |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 1417 | Error Handle ## name( \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 1418 | uint32 immediate_data_size, \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1419 | const gles2::name& args); \ |
| 1420 | |
| 1421 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 1422 | |
| 1423 | #undef GLES2_CMD_OP |
| 1424 | |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 1425 | // The GL context this decoder renders to on behalf of the client. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1426 | scoped_refptr<gfx::GLSurface> surface_; |
| 1427 | scoped_refptr<gfx::GLContext> context_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1428 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1429 | // The ContextGroup for this decoder uses to track resources. |
| 1430 | ContextGroup::Ref group_; |
| 1431 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1432 | // All the state for this context. |
| 1433 | ContextState state_; |
| 1434 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1435 | // A parent decoder can access this decoders saved offscreen frame buffer. |
| 1436 | // The parent pointer is reset if the parent is destroyed. |
| 1437 | base::WeakPtr<GLES2DecoderImpl> parent_; |
| 1438 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1439 | // Current width and height of the offscreen frame buffer. |
| 1440 | gfx::Size offscreen_size_; |
| 1441 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1442 | // Current GL error bits. |
| 1443 | uint32 error_bits_; |
| 1444 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1445 | // Util to help with GL. |
| 1446 | GLES2Util util_; |
| 1447 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1448 | // unpack flip y as last set by glPixelStorei |
| 1449 | bool unpack_flip_y_; |
| 1450 | |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1451 | // unpack (un)premultiply alpha as last set by glPixelStorei |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1452 | bool unpack_premultiply_alpha_; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1453 | bool unpack_unpremultiply_alpha_; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1454 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1455 | // Default vertex attribs manager, used when no VAOs are bound. |
| 1456 | VertexAttribManager::Ref default_vertex_attrib_manager_; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1457 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1458 | // The buffer we bind to attrib 0 since OpenGL requires it (ES does not). |
| 1459 | GLuint attrib_0_buffer_id_; |
| 1460 | |
| 1461 | // The value currently in attrib_0. |
| 1462 | VertexAttribManager::VertexAttribInfo::Vec4 attrib_0_value_; |
| 1463 | |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 1464 | // Whether or not the attrib_0 buffer holds the attrib_0_value. |
| 1465 | bool attrib_0_buffer_matches_value_; |
| 1466 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1467 | // The size of attrib 0. |
| 1468 | GLsizei attrib_0_size_; |
| 1469 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1470 | // The buffer used to simulate GL_FIXED attribs. |
| 1471 | GLuint fixed_attrib_buffer_id_; |
| 1472 | |
| 1473 | // The size of fiixed attrib buffer. |
| 1474 | GLsizei fixed_attrib_buffer_size_; |
| 1475 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1476 | // state saved for clearing so we can clear render buffers and then |
| 1477 | // restore to these values. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1478 | bool clear_state_dirty_; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1479 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1480 | // The offscreen frame buffer that the client renders to. With EGL, the |
| 1481 | // depth and stencil buffers are separate. With regular GL there is a single |
| 1482 | // packed depth stencil buffer in offscreen_target_depth_render_buffer_. |
| 1483 | // offscreen_target_stencil_render_buffer_ is unused. |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1484 | scoped_ptr<FrameBuffer> offscreen_target_frame_buffer_; |
| 1485 | scoped_ptr<Texture> offscreen_target_color_texture_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1486 | scoped_ptr<RenderBuffer> offscreen_target_color_render_buffer_; |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1487 | scoped_ptr<RenderBuffer> offscreen_target_depth_render_buffer_; |
| 1488 | scoped_ptr<RenderBuffer> offscreen_target_stencil_render_buffer_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1489 | GLenum offscreen_target_color_format_; |
| 1490 | GLenum offscreen_target_depth_format_; |
| 1491 | GLenum offscreen_target_stencil_format_; |
| 1492 | GLsizei offscreen_target_samples_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1493 | GLboolean offscreen_target_buffer_preserved_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1494 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1495 | // The copy that is saved when SwapBuffers is called. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1496 | scoped_ptr<FrameBuffer> offscreen_saved_frame_buffer_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1497 | scoped_ptr<Texture> offscreen_saved_color_texture_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1498 | TextureManager::TextureInfo::Ref offscreen_saved_color_texture_info_; |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1499 | |
| 1500 | // The copy that is used as the destination for multi-sample resolves. |
| 1501 | scoped_ptr<FrameBuffer> offscreen_resolved_frame_buffer_; |
| 1502 | scoped_ptr<Texture> offscreen_resolved_color_texture_; |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1503 | GLenum offscreen_saved_color_format_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1504 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1505 | scoped_ptr<QueryManager> query_manager_; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1506 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1507 | scoped_ptr<VertexArrayManager> vertex_array_manager_; |
| 1508 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 1509 | base::Callback<void(gfx::Size)> resize_callback_; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 1510 | |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 1511 | MsgCallback msg_callback_; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 1512 | |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 1513 | StreamTextureManager* stream_texture_manager_; |
| 1514 | |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1515 | // The format of the back buffer_ |
| 1516 | GLenum back_buffer_color_format_; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1517 | bool back_buffer_has_depth_; |
| 1518 | bool back_buffer_has_stencil_; |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1519 | |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 1520 | bool teximage2d_faster_than_texsubimage2d_; |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 1521 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 1522 | // The last error message set. |
| 1523 | std::string last_error_; |
| 1524 | |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 1525 | int log_message_count_; |
[email protected] | fa20ec8 | 2012-05-04 04:02:48 | [diff] [blame] | 1526 | |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 1527 | // The current decoder error. |
| 1528 | error::Error current_decoder_error_; |
| 1529 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 1530 | DebugMarkerManager debug_marker_manager_; |
| 1531 | std::string this_in_hex_; |
| 1532 | |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1533 | bool use_shader_translator_; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 1534 | scoped_refptr<ShaderTranslator> vertex_translator_; |
| 1535 | scoped_refptr<ShaderTranslator> fragment_translator_; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1536 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1537 | DisallowedFeatures disallowed_features_; |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1538 | |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 1539 | // Cached from ContextGroup |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1540 | const Validators* validators_; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 1541 | FeatureInfo::Ref feature_info_; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1542 | |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 1543 | // This indicates all the following texSubImage2D calls that are part of the |
| 1544 | // failed texImage2D call should be ignored. |
| 1545 | bool tex_image_2d_failed_; |
| 1546 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1547 | int frame_number_; |
| 1548 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 1549 | bool has_robustness_extension_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1550 | GLenum reset_status_; |
| 1551 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1552 | // These flags are used to override the state of the shared feature_info_ |
| 1553 | // member. Because the same FeatureInfo instance may be shared among many |
| 1554 | // contexts, the assumptions on the availablity of extensions in WebGL |
| 1555 | // contexts may be broken. These flags override the shared state to preserve |
| 1556 | // WebGL semantics. |
| 1557 | bool force_webgl_glsl_validation_; |
| 1558 | bool derivatives_explicitly_enabled_; |
| 1559 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 1560 | bool compile_shader_always_succeeds_; |
| 1561 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1562 | #if defined(OS_MACOSX) |
| 1563 | typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; |
| 1564 | TextureToIOSurfaceMap texture_to_io_surface_map_; |
| 1565 | #endif |
| 1566 | |
[email protected] | c826d73 | 2012-02-09 04:40:26 | [diff] [blame] | 1567 | typedef std::vector<GLES2DecoderImpl*> ChildList; |
| 1568 | ChildList children_; |
| 1569 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1570 | scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
| 1571 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1572 | // Cached values of the currently assigned viewport dimensions. |
| 1573 | GLsizei viewport_max_width_; |
| 1574 | GLsizei viewport_max_height_; |
| 1575 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1576 | // Command buffer stats. |
| 1577 | int texture_upload_count_; |
| 1578 | base::TimeDelta total_texture_upload_time_; |
| 1579 | base::TimeDelta total_processing_commands_time_; |
| 1580 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 1581 | std::stack<linked_ptr<GPUTrace> > gpu_trace_stack_; |
| 1582 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1583 | DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
| 1584 | }; |
| 1585 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1586 | ScopedGLErrorSuppressor::ScopedGLErrorSuppressor(GLES2DecoderImpl* decoder) |
| 1587 | : decoder_(decoder) { |
| 1588 | decoder_->CopyRealGLErrorsToWrapper(); |
| 1589 | } |
| 1590 | |
| 1591 | ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { |
| 1592 | decoder_->ClearRealGLErrors(); |
| 1593 | } |
| 1594 | |
| 1595 | ScopedTexture2DBinder::ScopedTexture2DBinder(GLES2DecoderImpl* decoder, |
| 1596 | GLuint id) |
| 1597 | : decoder_(decoder) { |
| 1598 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1599 | |
| 1600 | // TODO(apatrick): Check if there are any other states that need to be reset |
| 1601 | // before binding a new texture. |
| 1602 | glActiveTexture(GL_TEXTURE0); |
| 1603 | glBindTexture(GL_TEXTURE_2D, id); |
| 1604 | } |
| 1605 | |
| 1606 | ScopedTexture2DBinder::~ScopedTexture2DBinder() { |
| 1607 | ScopedGLErrorSuppressor suppressor(decoder_); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1608 | decoder_->RestoreCurrentTexture2DBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | ScopedRenderBufferBinder::ScopedRenderBufferBinder(GLES2DecoderImpl* decoder, |
| 1612 | GLuint id) |
| 1613 | : decoder_(decoder) { |
| 1614 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1615 | glBindRenderbufferEXT(GL_RENDERBUFFER, id); |
| 1616 | } |
| 1617 | |
| 1618 | ScopedRenderBufferBinder::~ScopedRenderBufferBinder() { |
| 1619 | ScopedGLErrorSuppressor suppressor(decoder_); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1620 | decoder_->RestoreCurrentRenderbufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | ScopedFrameBufferBinder::ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 1624 | GLuint id) |
| 1625 | : decoder_(decoder) { |
| 1626 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1627 | glBindFramebufferEXT(GL_FRAMEBUFFER, id); |
| 1628 | } |
| 1629 | |
| 1630 | ScopedFrameBufferBinder::~ScopedFrameBufferBinder() { |
| 1631 | ScopedGLErrorSuppressor suppressor(decoder_); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1632 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1633 | } |
| 1634 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1635 | ScopedResolvedFrameBufferBinder::ScopedResolvedFrameBufferBinder( |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1636 | GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 1637 | : decoder_(decoder) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1638 | resolve_and_bind_ = (decoder_->offscreen_target_frame_buffer_.get() && |
| 1639 | decoder_->IsOffscreenBufferMultisampled() && |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1640 | (!decoder_->state_.bound_read_framebuffer.get() || |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 1641 | enforce_internal_framebuffer)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1642 | if (!resolve_and_bind_) |
| 1643 | return; |
| 1644 | |
| 1645 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1646 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, |
| 1647 | decoder_->offscreen_target_frame_buffer_->id()); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1648 | GLuint targetid; |
| 1649 | if (internal) { |
| 1650 | if (!decoder_->offscreen_resolved_frame_buffer_.get()) { |
| 1651 | decoder_->offscreen_resolved_frame_buffer_.reset( |
| 1652 | new FrameBuffer(decoder_)); |
| 1653 | decoder_->offscreen_resolved_frame_buffer_->Create(); |
| 1654 | decoder_->offscreen_resolved_color_texture_.reset(new Texture(decoder_)); |
| 1655 | decoder_->offscreen_resolved_color_texture_->Create(); |
| 1656 | |
| 1657 | DCHECK(decoder_->offscreen_saved_color_format_); |
| 1658 | decoder_->offscreen_resolved_color_texture_->AllocateStorage( |
| 1659 | decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1660 | decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( |
| 1661 | decoder_->offscreen_resolved_color_texture_.get()); |
| 1662 | if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != |
| 1663 | GL_FRAMEBUFFER_COMPLETE) { |
| 1664 | LOG(ERROR) << "ScopedResolvedFrameBufferBinder failed " |
| 1665 | << "because offscreen resolved FBO was incomplete."; |
| 1666 | return; |
| 1667 | } |
| 1668 | } |
| 1669 | targetid = decoder_->offscreen_resolved_frame_buffer_->id(); |
| 1670 | } else { |
| 1671 | targetid = decoder_->offscreen_saved_frame_buffer_->id(); |
| 1672 | } |
| 1673 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1674 | const int width = decoder_->offscreen_size_.width(); |
| 1675 | const int height = decoder_->offscreen_size_.height(); |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 1676 | glDisable(GL_SCISSOR_TEST); |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 1677 | if (GLES2Decoder::IsAngle()) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1678 | glBlitFramebufferANGLE(0, 0, width, height, 0, 0, width, height, |
| 1679 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 1680 | } else { |
| 1681 | glBlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, |
| 1682 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 1683 | } |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1684 | glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { |
| 1688 | if (!resolve_and_bind_) |
| 1689 | return; |
| 1690 | |
| 1691 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1692 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 1693 | if (decoder_->state_.enable_flags.scissor_test) { |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 1694 | glEnable(GL_SCISSOR_TEST); |
| 1695 | } |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1696 | } |
| 1697 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1698 | ScopedTextureUploadTimer::ScopedTextureUploadTimer(GLES2DecoderImpl* decoder) |
| 1699 | : decoder_(decoder), |
| 1700 | begin_time_(base::TimeTicks::HighResNow()) { |
| 1701 | } |
| 1702 | |
| 1703 | ScopedTextureUploadTimer::~ScopedTextureUploadTimer() { |
| 1704 | decoder_->texture_upload_count_++; |
| 1705 | decoder_->total_texture_upload_time_ += |
| 1706 | base::TimeTicks::HighResNow() - begin_time_; |
| 1707 | } |
| 1708 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1709 | Texture::Texture(GLES2DecoderImpl* decoder) |
| 1710 | : decoder_(decoder), |
[email protected] | 3e7951c | 2012-09-17 03:16:28 | [diff] [blame] | 1711 | memory_tracker_(decoder->GetContextGroup()->memory_tracker()), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1712 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | Texture::~Texture() { |
| 1716 | // This does not destroy the render texture because that would require that |
| 1717 | // the associated GL context was current. Just check that it was explicitly |
| 1718 | // destroyed. |
| 1719 | DCHECK_EQ(id_, 0u); |
| 1720 | } |
| 1721 | |
| 1722 | void Texture::Create() { |
| 1723 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1724 | Destroy(); |
| 1725 | glGenTextures(1, &id_); |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1726 | ScopedTexture2DBinder binder(decoder_, id_); |
| 1727 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1728 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1729 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1730 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
[email protected] | 6278880 | 2011-10-03 17:57:16 | [diff] [blame] | 1731 | |
| 1732 | // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 1733 | // never called on an offscreen context, no data will ever be uploaded to the |
| 1734 | // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 1735 | // is called). My idea is that some nvidia drivers might have a bug where |
| 1736 | // deleting a texture that has never been populated might cause a |
| 1737 | // crash. |
| 1738 | glTexImage2D( |
| 1739 | GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1740 | memory_tracker_.UpdateMemRepresented(16u * 16u * 4u); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1741 | } |
| 1742 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1743 | bool Texture::AllocateStorage(const gfx::Size& size, GLenum format) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1744 | DCHECK_NE(id_, 0u); |
| 1745 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1746 | ScopedTexture2DBinder binder(decoder_, id_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1747 | |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 1748 | WrappedTexImage2D(GL_TEXTURE_2D, |
| 1749 | 0, // mip level |
| 1750 | format, |
| 1751 | size.width(), |
| 1752 | size.height(), |
| 1753 | 0, // border |
| 1754 | format, |
| 1755 | GL_UNSIGNED_BYTE, |
| 1756 | NULL); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1757 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1758 | size_ = size; |
| 1759 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1760 | bool success = glGetError() == GL_NO_ERROR; |
| 1761 | if (success) { |
| 1762 | uint32 image_size = 0; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 1763 | GLES2Util::ComputeImageDataSizes( |
| 1764 | size.width(), size.height(), format, GL_UNSIGNED_BYTE, 4, &image_size, |
| 1765 | NULL, NULL); |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1766 | memory_tracker_.UpdateMemRepresented(image_size); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1767 | } |
| 1768 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1769 | } |
| 1770 | |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1771 | void Texture::Copy(const gfx::Size& size, GLenum format) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1772 | DCHECK_NE(id_, 0u); |
| 1773 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1774 | ScopedTexture2DBinder binder(decoder_, id_); |
| 1775 | glCopyTexImage2D(GL_TEXTURE_2D, |
| 1776 | 0, // level |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1777 | format, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1778 | 0, 0, |
| 1779 | size.width(), |
| 1780 | size.height(), |
| 1781 | 0); // border |
| 1782 | } |
| 1783 | |
| 1784 | void Texture::Destroy() { |
| 1785 | if (id_ != 0) { |
| 1786 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1787 | glDeleteTextures(1, &id_); |
| 1788 | id_ = 0; |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1789 | memory_tracker_.UpdateMemRepresented(0); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1790 | } |
| 1791 | } |
| 1792 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1793 | void Texture::Invalidate() { |
| 1794 | id_ = 0; |
| 1795 | } |
| 1796 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1797 | RenderBuffer::RenderBuffer(GLES2DecoderImpl* decoder) |
| 1798 | : decoder_(decoder), |
[email protected] | 3e7951c | 2012-09-17 03:16:28 | [diff] [blame] | 1799 | memory_tracker_(decoder->GetContextGroup()->memory_tracker()), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1800 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | RenderBuffer::~RenderBuffer() { |
| 1804 | // This does not destroy the render buffer because that would require that |
| 1805 | // the associated GL context was current. Just check that it was explicitly |
| 1806 | // destroyed. |
| 1807 | DCHECK_EQ(id_, 0u); |
| 1808 | } |
| 1809 | |
| 1810 | void RenderBuffer::Create() { |
| 1811 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1812 | Destroy(); |
| 1813 | glGenRenderbuffersEXT(1, &id_); |
| 1814 | } |
| 1815 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1816 | bool RenderBuffer::AllocateStorage(const gfx::Size& size, GLenum format, |
| 1817 | GLsizei samples) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1818 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1819 | ScopedRenderBufferBinder binder(decoder_, id_); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1820 | if (samples <= 1) { |
| 1821 | glRenderbufferStorageEXT(GL_RENDERBUFFER, |
| 1822 | format, |
| 1823 | size.width(), |
| 1824 | size.height()); |
| 1825 | } else { |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 1826 | if (GLES2Decoder::IsAngle()) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1827 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, |
| 1828 | samples, |
| 1829 | format, |
| 1830 | size.width(), |
| 1831 | size.height()); |
| 1832 | } else { |
| 1833 | glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, |
| 1834 | samples, |
| 1835 | format, |
| 1836 | size.width(), |
| 1837 | size.height()); |
| 1838 | } |
| 1839 | } |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1840 | bool success = glGetError() == GL_NO_ERROR; |
| 1841 | if (success) { |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1842 | memory_tracker_.UpdateMemRepresented( |
| 1843 | size.width() * size.height() * samples * |
| 1844 | GLES2Util::RenderbufferBytesPerPixel(format)); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1845 | } |
| 1846 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1847 | } |
| 1848 | |
| 1849 | void RenderBuffer::Destroy() { |
| 1850 | if (id_ != 0) { |
| 1851 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1852 | glDeleteRenderbuffersEXT(1, &id_); |
| 1853 | id_ = 0; |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1854 | memory_tracker_.UpdateMemRepresented(0); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1855 | } |
| 1856 | } |
| 1857 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1858 | void RenderBuffer::Invalidate() { |
| 1859 | id_ = 0; |
| 1860 | } |
| 1861 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1862 | FrameBuffer::FrameBuffer(GLES2DecoderImpl* decoder) |
| 1863 | : decoder_(decoder), |
| 1864 | id_(0) { |
| 1865 | } |
| 1866 | |
| 1867 | FrameBuffer::~FrameBuffer() { |
| 1868 | // This does not destroy the frame buffer because that would require that |
| 1869 | // the associated GL context was current. Just check that it was explicitly |
| 1870 | // destroyed. |
| 1871 | DCHECK_EQ(id_, 0u); |
| 1872 | } |
| 1873 | |
| 1874 | void FrameBuffer::Create() { |
| 1875 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1876 | Destroy(); |
| 1877 | glGenFramebuffersEXT(1, &id_); |
| 1878 | } |
| 1879 | |
| 1880 | void FrameBuffer::AttachRenderTexture(Texture* texture) { |
| 1881 | DCHECK_NE(id_, 0u); |
| 1882 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1883 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 1884 | GLuint attach_id = texture ? texture->id() : 0; |
| 1885 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 1886 | GL_COLOR_ATTACHMENT0, |
| 1887 | GL_TEXTURE_2D, |
| 1888 | attach_id, |
| 1889 | 0); |
| 1890 | } |
| 1891 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1892 | void FrameBuffer::AttachRenderBuffer(GLenum target, |
| 1893 | RenderBuffer* render_buffer) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1894 | DCHECK_NE(id_, 0u); |
| 1895 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1896 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 1897 | GLuint attach_id = render_buffer ? render_buffer->id() : 0; |
| 1898 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1899 | target, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1900 | GL_RENDERBUFFER, |
| 1901 | attach_id); |
| 1902 | } |
| 1903 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1904 | void FrameBuffer::Destroy() { |
| 1905 | if (id_ != 0) { |
| 1906 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1907 | glDeleteFramebuffersEXT(1, &id_); |
| 1908 | id_ = 0; |
| 1909 | } |
| 1910 | } |
| 1911 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1912 | void FrameBuffer::Invalidate() { |
| 1913 | id_ = 0; |
| 1914 | } |
| 1915 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1916 | GLenum FrameBuffer::CheckStatus() { |
| 1917 | DCHECK_NE(id_, 0u); |
| 1918 | ScopedGLErrorSuppressor suppressor(decoder_); |
| 1919 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 1920 | return glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 1921 | } |
| 1922 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 1923 | GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) { |
| 1924 | return new GLES2DecoderImpl(group); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1925 | } |
| 1926 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 1927 | GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1928 | : GLES2Decoder(), |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 1929 | group_(group), |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1930 | error_bits_(0), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1931 | unpack_flip_y_(false), |
| 1932 | unpack_premultiply_alpha_(false), |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1933 | unpack_unpremultiply_alpha_(false), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1934 | attrib_0_buffer_id_(0), |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 1935 | attrib_0_buffer_matches_value_(true), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1936 | attrib_0_size_(0), |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1937 | fixed_attrib_buffer_id_(0), |
| 1938 | fixed_attrib_buffer_size_(0), |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1939 | clear_state_dirty_(true), |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1940 | offscreen_target_color_format_(0), |
| 1941 | offscreen_target_depth_format_(0), |
| 1942 | offscreen_target_stencil_format_(0), |
| 1943 | offscreen_target_samples_(0), |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1944 | offscreen_target_buffer_preserved_(true), |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1945 | offscreen_saved_color_format_(0), |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 1946 | stream_texture_manager_(NULL), |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1947 | back_buffer_color_format_(0), |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1948 | back_buffer_has_depth_(false), |
| 1949 | back_buffer_has_stencil_(false), |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 1950 | teximage2d_faster_than_texsubimage2d_(true), |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 1951 | log_message_count_(0), |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 1952 | current_decoder_error_(error::kNoError), |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1953 | use_shader_translator_(true), |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 1954 | validators_(group_->feature_info()->validators()), |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 1955 | feature_info_(group_->feature_info()), |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1956 | tex_image_2d_failed_(false), |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1957 | frame_number_(0), |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 1958 | has_robustness_extension_(false), |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 1959 | reset_status_(GL_NO_ERROR), |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1960 | force_webgl_glsl_validation_(false), |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 1961 | derivatives_explicitly_enabled_(false), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1962 | compile_shader_always_succeeds_(false), |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1963 | viewport_max_width_(0), |
| 1964 | viewport_max_height_(0), |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1965 | texture_upload_count_(0) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 1966 | DCHECK(group); |
| 1967 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 1968 | GLES2DecoderImpl* this_temp = this; |
| 1969 | this_in_hex_ = HexEncode(&this_temp, sizeof(this_temp)); |
| 1970 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1971 | attrib_0_value_.v[0] = 0.0f; |
| 1972 | attrib_0_value_.v[1] = 0.0f; |
| 1973 | attrib_0_value_.v[2] = 0.0f; |
| 1974 | attrib_0_value_.v[3] = 1.0f; |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1975 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 1976 | // The shader translator is used for WebGL even when running on EGL |
| 1977 | // because additional restrictions are needed (like only enabling |
| 1978 | // GL_OES_standard_derivatives on demand). It is used for the unit |
| 1979 | // tests because |
| 1980 | // GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes the |
| 1981 | // empty string to CompileShader and this is not a valid shader. |
| 1982 | // TODO(apatrick): fix this test. |
| 1983 | if ((gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 1984 | !features().chromium_webglsl && !force_webgl_glsl_validation_) || |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 1985 | gfx::GetGLImplementation() == gfx::kGLImplementationMockGL || |
| 1986 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 1987 | switches::kDisableGLSLTranslator)) { |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1988 | use_shader_translator_ = false; |
| 1989 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 1990 | |
[email protected] | a3937065 | 2012-09-25 21:52:13 | [diff] [blame] | 1991 | // TODO(gman): Consider setting this based on GPU and/or driver. |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 1992 | if (IsAngle()) { |
| 1993 | teximage2d_faster_than_texsubimage2d_ = false; |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 1994 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1995 | } |
| 1996 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 1997 | GLES2DecoderImpl::~GLES2DecoderImpl() { |
| 1998 | } |
| 1999 | |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2000 | bool GLES2DecoderImpl::Initialize( |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2001 | const scoped_refptr<gfx::GLSurface>& surface, |
| 2002 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2003 | bool offscreen, |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2004 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2005 | const DisallowedFeatures& disallowed_features, |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2006 | const char* allowed_extensions, |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2007 | const std::vector<int32>& attribs) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 2008 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2009 | DCHECK(context->IsCurrent(surface.get())); |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 2010 | DCHECK(!context_.get()); |
| 2011 | |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 2012 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2013 | switches::kEnableGPUDebugging)) { |
| 2014 | set_debug(true); |
| 2015 | } |
| 2016 | |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2017 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2018 | switches::kEnableGPUCommandLogging)) { |
| 2019 | set_log_commands(true); |
| 2020 | } |
| 2021 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2022 | compile_shader_always_succeeds_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 2023 | switches::kCompileShaderAlwaysSucceeds); |
| 2024 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 2025 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2026 | // Take ownership of the context and surface. The surface can be replaced with |
| 2027 | // SetSurface. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2028 | context_ = context; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2029 | surface_ = surface; |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2030 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2031 | if (!group_->Initialize(disallowed_features, allowed_extensions)) { |
[email protected] | 09ddb91f | 2011-04-14 23:16:22 | [diff] [blame] | 2032 | LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2033 | << "failed to initialize."; |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 2034 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2035 | Destroy(true); |
[email protected] | ae174109 | 2010-11-17 19:16:03 | [diff] [blame] | 2036 | return false; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2037 | } |
[email protected] | b64c2495 | 2012-04-19 03:20:27 | [diff] [blame] | 2038 | CHECK_GL_ERROR(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2039 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2040 | disallowed_features_ = disallowed_features; |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2041 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2042 | default_vertex_attrib_manager_ = new VertexAttribManager(); |
| 2043 | default_vertex_attrib_manager_->Initialize(group_->max_vertex_attribs()); |
| 2044 | |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 2045 | // vertex_attrib_manager is set to default_vertex_attrib_manager_ by this call |
| 2046 | DoBindVertexArrayOES(0); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 2047 | |
[email protected] | d6ca479 | 2012-05-14 19:24:13 | [diff] [blame] | 2048 | query_manager_.reset(new QueryManager(this, feature_info_)); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2049 | vertex_array_manager_.reset(new VertexArrayManager()); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 2050 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2051 | util_.set_num_compressed_texture_formats( |
| 2052 | validators_->compressed_texture_format.GetValues().size()); |
| 2053 | |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 2054 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2055 | // We have to enable vertex array 0 on OpenGL or it won't render. Note that |
| 2056 | // OpenGL ES 2.0 does not have this issue. |
| 2057 | glEnableVertexAttribArray(0); |
| 2058 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2059 | glGenBuffersARB(1, &attrib_0_buffer_id_); |
| 2060 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 2061 | glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); |
| 2062 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2063 | glGenBuffersARB(1, &fixed_attrib_buffer_id_); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 2064 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2065 | state_.texture_units.resize(group_->max_texture_units()); |
| 2066 | for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) { |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2067 | glActiveTexture(GL_TEXTURE0 + tt); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2068 | // We want the last bind to be 2D. |
| 2069 | TextureManager::TextureInfo* info; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2070 | if (features().oes_egl_image_external) { |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2071 | info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_EXTERNAL_OES); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2072 | state_.texture_units[tt].bound_texture_external_oes = info; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2073 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, info->service_id()); |
| 2074 | } |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2075 | if (features().arb_texture_rectangle) { |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2076 | info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_RECTANGLE_ARB); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2077 | state_.texture_units[tt].bound_texture_rectangle_arb = info; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2078 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, info->service_id()); |
| 2079 | } |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2080 | info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2081 | state_.texture_units[tt].bound_texture_cube_map = info; |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2082 | glBindTexture(GL_TEXTURE_CUBE_MAP, info->service_id()); |
| 2083 | info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2084 | state_.texture_units[tt].bound_texture_2d = info; |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2085 | glBindTexture(GL_TEXTURE_2D, info->service_id()); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 2086 | } |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2087 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2088 | CHECK_GL_ERROR(); |
| 2089 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2090 | ContextCreationAttribParser attrib_parser; |
| 2091 | if (!attrib_parser.Parse(attribs)) |
| 2092 | return false; |
[email protected] | 41c5636 | 2011-06-14 16:47:43 | [diff] [blame] | 2093 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2094 | // These are NOT if the back buffer has these proprorties. They are |
| 2095 | // if we want the command buffer to enforce them regardless of what |
| 2096 | // the real backbuffer is assuming the real back buffer gives us more than |
| 2097 | // we ask for. In other words, if we ask for RGB and we get RGBA then we'll |
| 2098 | // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we |
| 2099 | // can't do anything about that. |
| 2100 | |
| 2101 | GLint v = 0; |
| 2102 | glGetIntegerv(GL_ALPHA_BITS, &v); |
| 2103 | // This checks if the user requested RGBA and we have RGBA then RGBA. If the |
| 2104 | // user requested RGB then RGB. If the user did not specify a preference than |
| 2105 | // use whatever we were given. Same for DEPTH and STENCIL. |
| 2106 | back_buffer_color_format_ = |
| 2107 | (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB; |
| 2108 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 2109 | back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0; |
| 2110 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 2111 | back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0; |
| 2112 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2113 | if (offscreen) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2114 | if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && |
[email protected] | 53862ed | 2010-10-25 19:22:54 | [diff] [blame] | 2115 | (context_->HasExtension("GL_EXT_framebuffer_multisample") || |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2116 | context_->HasExtension("GL_ANGLE_framebuffer_multisample"))) { |
| 2117 | // Per ext_framebuffer_multisample spec, need max bound on sample count. |
[email protected] | 0b1e9d7 | 2010-11-11 16:29:43 | [diff] [blame] | 2118 | // max_sample_count must be initialized to a sane value. If |
| 2119 | // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
| 2120 | GLint max_sample_count = 1; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2121 | glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
| 2122 | offscreen_target_samples_ = std::min(attrib_parser.samples_, |
| 2123 | max_sample_count); |
| 2124 | } else { |
| 2125 | offscreen_target_samples_ = 1; |
| 2126 | } |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2127 | offscreen_target_buffer_preserved_ = attrib_parser.buffer_preserved_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2128 | |
| 2129 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 2130 | const bool rgb8_supported = |
| 2131 | context_->HasExtension("GL_OES_rgb8_rgba8"); |
| 2132 | // The only available default render buffer formats in GLES2 have very |
| 2133 | // little precision. Don't enable multisampling unless 8-bit render |
| 2134 | // buffer formats are available--instead fall back to 8-bit textures. |
| 2135 | if (rgb8_supported && offscreen_target_samples_ > 1) { |
| 2136 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2137 | GL_RGBA8 : GL_RGB8; |
| 2138 | } else { |
| 2139 | offscreen_target_samples_ = 1; |
| 2140 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2141 | GL_RGBA : GL_RGB; |
| 2142 | } |
| 2143 | |
| 2144 | // ANGLE only supports packed depth/stencil formats, so use it if it is |
| 2145 | // available. |
| 2146 | const bool depth24_stencil8_supported = |
| 2147 | context_->HasExtension("GL_OES_packed_depth_stencil"); |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2148 | VLOG(1) << "GL_OES_packed_depth_stencil " |
| 2149 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2150 | if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && |
| 2151 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2152 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2153 | offscreen_target_stencil_format_ = 0; |
| 2154 | } else { |
| 2155 | // It may be the case that this depth/stencil combination is not |
| 2156 | // supported, but this will be checked later by CheckFramebufferStatus. |
| 2157 | offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? |
| 2158 | GL_DEPTH_COMPONENT16 : 0; |
| 2159 | offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? |
| 2160 | GL_STENCIL_INDEX8 : 0; |
| 2161 | } |
| 2162 | } else { |
| 2163 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2164 | GL_RGBA : GL_RGB; |
| 2165 | |
| 2166 | // If depth is requested at all, use the packed depth stencil format if |
| 2167 | // it's available, as some desktop GL drivers don't support any non-packed |
| 2168 | // formats for depth attachments. |
| 2169 | const bool depth24_stencil8_supported = |
| 2170 | context_->HasExtension("GL_EXT_packed_depth_stencil"); |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2171 | VLOG(1) << "GL_EXT_packed_depth_stencil " |
| 2172 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2173 | |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2174 | if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && |
| 2175 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2176 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2177 | offscreen_target_stencil_format_ = 0; |
| 2178 | } else { |
| 2179 | offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? |
| 2180 | GL_DEPTH_COMPONENT : 0; |
| 2181 | offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? |
| 2182 | GL_STENCIL_INDEX : 0; |
| 2183 | } |
| 2184 | } |
| 2185 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2186 | offscreen_saved_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2187 | GL_RGBA : GL_RGB; |
| 2188 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2189 | // Create the target frame buffer. This is the one that the client renders |
| 2190 | // directly to. |
| 2191 | offscreen_target_frame_buffer_.reset(new FrameBuffer(this)); |
| 2192 | offscreen_target_frame_buffer_->Create(); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2193 | // Due to GLES2 format limitations, either the color texture (for |
| 2194 | // non-multisampling) or the color render buffer (for multisampling) will be |
| 2195 | // attached to the offscreen frame buffer. The render buffer has more |
| 2196 | // limited formats available to it, but the texture can't do multisampling. |
| 2197 | if (IsOffscreenBufferMultisampled()) { |
| 2198 | offscreen_target_color_render_buffer_.reset(new RenderBuffer(this)); |
| 2199 | offscreen_target_color_render_buffer_->Create(); |
| 2200 | } else { |
| 2201 | offscreen_target_color_texture_.reset(new Texture(this)); |
| 2202 | offscreen_target_color_texture_->Create(); |
| 2203 | } |
| 2204 | offscreen_target_depth_render_buffer_.reset(new RenderBuffer(this)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2205 | offscreen_target_depth_render_buffer_->Create(); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2206 | offscreen_target_stencil_render_buffer_.reset(new RenderBuffer(this)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2207 | offscreen_target_stencil_render_buffer_->Create(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2208 | |
| 2209 | // Create the saved offscreen texture. The target frame buffer is copied |
| 2210 | // here when SwapBuffers is called. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2211 | offscreen_saved_frame_buffer_.reset(new FrameBuffer(this)); |
| 2212 | offscreen_saved_frame_buffer_->Create(); |
| 2213 | // |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2214 | offscreen_saved_color_texture_.reset(new Texture(this)); |
| 2215 | offscreen_saved_color_texture_->Create(); |
| 2216 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2217 | // Allocate the render buffers at their initial size and check the status |
| 2218 | // of the frame buffers is okay. |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2219 | if (!ResizeOffscreenFrameBuffer(size)) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 2220 | LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2221 | Destroy(true); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2222 | return false; |
| 2223 | } |
| 2224 | |
| 2225 | // Bind to the new default frame buffer (the offscreen target frame buffer). |
| 2226 | // This should now be associated with ID zero. |
| 2227 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2228 | } |
| 2229 | |
[email protected] | 295faf4b | 2012-01-25 23:31:41 | [diff] [blame] | 2230 | // Clear the backbuffer. |
| 2231 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 2232 | |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2233 | // OpenGL ES 2.0 implicitly enables the desktop GL capability |
| 2234 | // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact |
| 2235 | // isn't well documented; it was discovered in the Khronos OpenGL ES |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2236 | // mailing list archives. It also implicitly enables the desktop GL |
| 2237 | // capability GL_POINT_SPRITE to provide access to the gl_PointCoord |
| 2238 | // variable in fragment shaders. |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2239 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2240 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2241 | glEnable(GL_POINT_SPRITE); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2242 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2243 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2244 | has_robustness_extension_ = |
| 2245 | context->HasExtension("GL_ARB_robustness") || |
| 2246 | context->HasExtension("GL_EXT_robustness"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2247 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2248 | if (!InitializeShaderTranslator()) { |
| 2249 | return false; |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2250 | } |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2251 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2252 | state_.viewport_width = size.width(); |
| 2253 | state_.viewport_height = size.height(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2254 | |
[email protected] | 5904806b | 2012-05-08 18:10:22 | [diff] [blame] | 2255 | GLint viewport_params[4] = { 0 }; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2256 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2257 | viewport_max_width_ = viewport_params[0]; |
| 2258 | viewport_max_height_ = viewport_params[1]; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2259 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2260 | state_.scissor_width = state_.viewport_width; |
| 2261 | state_.scissor_height = state_.viewport_height; |
| 2262 | |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2263 | // Set all the default state because some GL drivers get it wrong. |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 2264 | state_.InitCapabilities(); |
| 2265 | state_.InitState(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2266 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2267 | glHint(GL_GENERATE_MIPMAP_HINT, state_.hint_generate_mipmap); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2268 | glPixelStorei(GL_PACK_ALIGNMENT, state_.pack_alignment); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2269 | glPixelStorei(GL_UNPACK_ALIGNMENT, state_.unpack_alignment); |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2270 | |
| 2271 | DoBindBuffer(GL_ARRAY_BUFFER, 0); |
| 2272 | DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 2273 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2274 | DoBindRenderbuffer(GL_RENDERBUFFER, 0); |
| 2275 | |
[email protected] | 6d9374e | 2012-07-17 03:31:24 | [diff] [blame] | 2276 | // AMD and Intel drivers on Mac OS apparently get gl_PointCoord |
| 2277 | // backward from the spec and this setting makes them work |
| 2278 | // correctly. rdar://problem/11883495 |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2279 | if (feature_info_->workarounds().reverse_point_sprite_coord_origin) { |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2280 | glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); |
| 2281 | } |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2282 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2283 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2284 | } |
| 2285 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2286 | void GLES2DecoderImpl::UpdateCapabilities() { |
| 2287 | util_.set_num_compressed_texture_formats( |
| 2288 | validators_->compressed_texture_format.GetValues().size()); |
| 2289 | util_.set_num_shader_binary_formats( |
| 2290 | validators_->shader_binary_format.GetValues().size()); |
| 2291 | } |
| 2292 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2293 | bool GLES2DecoderImpl::InitializeShaderTranslator() { |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 2294 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::InitializeShaderTranslator"); |
| 2295 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2296 | // Re-check the state of use_shader_translator_ each time this is called. |
| 2297 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2298 | (features().chromium_webglsl || force_webgl_glsl_validation_) && |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2299 | !use_shader_translator_) { |
| 2300 | use_shader_translator_ = true; |
| 2301 | } |
| 2302 | if (!use_shader_translator_) { |
| 2303 | return true; |
| 2304 | } |
| 2305 | ShBuiltInResources resources; |
| 2306 | ShInitBuiltInResources(&resources); |
| 2307 | resources.MaxVertexAttribs = group_->max_vertex_attribs(); |
| 2308 | resources.MaxVertexUniformVectors = |
| 2309 | group_->max_vertex_uniform_vectors(); |
| 2310 | resources.MaxVaryingVectors = group_->max_varying_vectors(); |
| 2311 | resources.MaxVertexTextureImageUnits = |
| 2312 | group_->max_vertex_texture_image_units(); |
| 2313 | resources.MaxCombinedTextureImageUnits = group_->max_texture_units(); |
| 2314 | resources.MaxTextureImageUnits = group_->max_texture_image_units(); |
| 2315 | resources.MaxFragmentUniformVectors = |
| 2316 | group_->max_fragment_uniform_vectors(); |
| 2317 | resources.MaxDrawBuffers = 1; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2318 | |
| 2319 | if (force_webgl_glsl_validation_) { |
| 2320 | resources.OES_standard_derivatives = derivatives_explicitly_enabled_; |
| 2321 | } else { |
| 2322 | resources.OES_standard_derivatives = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2323 | features().oes_standard_derivatives ? 1 : 0; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2324 | resources.ARB_texture_rectangle = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2325 | features().arb_texture_rectangle ? 1 : 0; |
[email protected] | 70e7bb1 | 2012-09-29 14:01:06 | [diff] [blame] | 2326 | resources.OES_EGL_image_external = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2327 | features().oes_egl_image_external ? 1 : 0; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2328 | } |
| 2329 | |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 2330 | if (features().enable_shader_name_hashing) |
| 2331 | resources.HashFunction = &CityHashForAngle; |
| 2332 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2333 | ShShaderSpec shader_spec = force_webgl_glsl_validation_ || |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2334 | features().chromium_webglsl ? SH_WEBGL_SPEC : SH_GLES2_SPEC; |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2335 | ShaderTranslatorInterface::GlslImplementationType implementation_type = |
| 2336 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? |
| 2337 | ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; |
| 2338 | ShaderTranslatorInterface::GlslBuiltInFunctionBehavior function_behavior = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2339 | workarounds().needs_glsl_built_in_function_emulation ? |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2340 | ShaderTranslatorInterface::kGlslBuiltInFunctionEmulated : |
| 2341 | ShaderTranslatorInterface::kGlslBuiltInFunctionOriginal; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2342 | |
| 2343 | ShaderTranslatorCache* cache = ShaderTranslatorCache::GetInstance(); |
| 2344 | vertex_translator_ = cache->GetTranslator( |
| 2345 | SH_VERTEX_SHADER, shader_spec, &resources, |
| 2346 | implementation_type, function_behavior); |
| 2347 | if (!vertex_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2348 | LOG(ERROR) << "Could not initialize vertex shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2349 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2350 | return false; |
| 2351 | } |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2352 | |
| 2353 | fragment_translator_ = cache->GetTranslator( |
| 2354 | SH_FRAGMENT_SHADER, shader_spec, &resources, |
| 2355 | implementation_type, function_behavior); |
| 2356 | if (!fragment_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2357 | LOG(ERROR) << "Could not initialize fragment shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2358 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2359 | return false; |
| 2360 | } |
| 2361 | return true; |
| 2362 | } |
| 2363 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2364 | bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2365 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2366 | if (GetBufferInfo(client_ids[ii])) { |
| 2367 | return false; |
| 2368 | } |
| 2369 | } |
| 2370 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 2371 | glGenBuffersARB(n, service_ids.get()); |
| 2372 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2373 | CreateBufferInfo(client_ids[ii], service_ids[ii]); |
| 2374 | } |
| 2375 | return true; |
| 2376 | } |
| 2377 | |
| 2378 | bool GLES2DecoderImpl::GenFramebuffersHelper( |
| 2379 | GLsizei n, const GLuint* client_ids) { |
| 2380 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2381 | if (GetFramebufferInfo(client_ids[ii])) { |
| 2382 | return false; |
| 2383 | } |
| 2384 | } |
| 2385 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 2386 | glGenFramebuffersEXT(n, service_ids.get()); |
| 2387 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2388 | CreateFramebufferInfo(client_ids[ii], service_ids[ii]); |
| 2389 | } |
| 2390 | return true; |
| 2391 | } |
| 2392 | |
| 2393 | bool GLES2DecoderImpl::GenRenderbuffersHelper( |
| 2394 | GLsizei n, const GLuint* client_ids) { |
| 2395 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2396 | if (GetRenderbufferInfo(client_ids[ii])) { |
| 2397 | return false; |
| 2398 | } |
| 2399 | } |
| 2400 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 2401 | glGenRenderbuffersEXT(n, service_ids.get()); |
| 2402 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2403 | CreateRenderbufferInfo(client_ids[ii], service_ids[ii]); |
| 2404 | } |
| 2405 | return true; |
| 2406 | } |
| 2407 | |
| 2408 | bool GLES2DecoderImpl::GenTexturesHelper(GLsizei n, const GLuint* client_ids) { |
| 2409 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2410 | if (GetTextureInfo(client_ids[ii])) { |
| 2411 | return false; |
| 2412 | } |
| 2413 | } |
| 2414 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 2415 | glGenTextures(n, service_ids.get()); |
| 2416 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 2417 | CreateTextureInfo(client_ids[ii], service_ids[ii]); |
| 2418 | } |
| 2419 | return true; |
| 2420 | } |
| 2421 | |
| 2422 | void GLES2DecoderImpl::DeleteBuffersHelper( |
| 2423 | GLsizei n, const GLuint* client_ids) { |
| 2424 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2425 | BufferManager::BufferInfo* buffer = GetBufferInfo(client_ids[ii]); |
| 2426 | if (buffer && !buffer->IsDeleted()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2427 | state_.vertex_attrib_manager->Unbind(buffer); |
| 2428 | if (state_.bound_array_buffer == buffer) { |
| 2429 | state_.bound_array_buffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2430 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2431 | RemoveBufferInfo(client_ids[ii]); |
| 2432 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2433 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2434 | } |
| 2435 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2436 | void GLES2DecoderImpl::DeleteFramebuffersHelper( |
| 2437 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2438 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2439 | features().chromium_framebuffer_multisample; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2440 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2441 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2442 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2443 | GetFramebufferInfo(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2444 | if (framebuffer && !framebuffer->IsDeleted()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2445 | if (framebuffer == state_.bound_draw_framebuffer) { |
| 2446 | state_.bound_draw_framebuffer = NULL; |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2447 | clear_state_dirty_ = true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2448 | GLenum target = supports_separate_framebuffer_binds ? |
| 2449 | GL_DRAW_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2450 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
| 2451 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2452 | if (framebuffer == state_.bound_read_framebuffer) { |
| 2453 | state_.bound_read_framebuffer = NULL; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2454 | GLenum target = supports_separate_framebuffer_binds ? |
| 2455 | GL_READ_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2456 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2457 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2458 | RemoveFramebufferInfo(client_ids[ii]); |
| 2459 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2460 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2461 | } |
| 2462 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2463 | void GLES2DecoderImpl::DeleteRenderbuffersHelper( |
| 2464 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2465 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2466 | features().chromium_framebuffer_multisample; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2467 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2468 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2469 | GetRenderbufferInfo(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2470 | if (renderbuffer && !renderbuffer->IsDeleted()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2471 | if (state_.bound_renderbuffer == renderbuffer) { |
| 2472 | state_.bound_renderbuffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2473 | } |
| 2474 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2475 | if (supports_separate_framebuffer_binds) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2476 | if (state_.bound_read_framebuffer) { |
| 2477 | state_.bound_read_framebuffer->UnbindRenderbuffer( |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2478 | GL_READ_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2479 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2480 | if (state_.bound_draw_framebuffer) { |
| 2481 | state_.bound_draw_framebuffer->UnbindRenderbuffer( |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2482 | GL_DRAW_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2483 | } |
| 2484 | } else { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2485 | if (state_.bound_draw_framebuffer) { |
| 2486 | state_.bound_draw_framebuffer->UnbindRenderbuffer( |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2487 | GL_FRAMEBUFFER, renderbuffer); |
| 2488 | } |
| 2489 | } |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2490 | clear_state_dirty_ = true; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2491 | RemoveRenderbufferInfo(client_ids[ii]); |
| 2492 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2493 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2494 | } |
| 2495 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2496 | void GLES2DecoderImpl::DeleteTexturesHelper( |
| 2497 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2498 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2499 | features().chromium_framebuffer_multisample; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2500 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2501 | TextureManager::TextureInfo* texture = GetTextureInfo(client_ids[ii]); |
| 2502 | if (texture && !texture->IsDeleted()) { |
| 2503 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2504 | clear_state_dirty_ = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2505 | } |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2506 | // Unbind texture from texture units. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2507 | for (size_t jj = 0; jj < state_.texture_units.size(); ++jj) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2508 | state_.texture_units[jj].Unbind(texture); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2509 | } |
| 2510 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2511 | if (supports_separate_framebuffer_binds) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2512 | if (state_.bound_read_framebuffer) { |
| 2513 | state_.bound_read_framebuffer->UnbindTexture( |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2514 | GL_READ_FRAMEBUFFER_EXT, texture); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2515 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2516 | if (state_.bound_draw_framebuffer) { |
| 2517 | state_.bound_draw_framebuffer->UnbindTexture( |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2518 | GL_DRAW_FRAMEBUFFER_EXT, texture); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2519 | } |
| 2520 | } else { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2521 | if (state_.bound_draw_framebuffer) { |
| 2522 | state_.bound_draw_framebuffer->UnbindTexture(GL_FRAMEBUFFER, texture); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2523 | } |
| 2524 | } |
| 2525 | GLuint service_id = texture->service_id(); |
| 2526 | if (texture->IsStreamTexture() && stream_texture_manager_) { |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 2527 | stream_texture_manager_->DestroyStreamTexture(service_id); |
| 2528 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2529 | #if defined(OS_MACOSX) |
| 2530 | if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { |
| 2531 | ReleaseIOSurfaceForTexture(service_id); |
| 2532 | } |
| 2533 | #endif |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2534 | RemoveTextureInfo(client_ids[ii]); |
| 2535 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2536 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2537 | } |
| 2538 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 2539 | // } // anonymous namespace |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2540 | |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2541 | bool GLES2DecoderImpl::MakeCurrent() { |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2542 | if (!context_.get() || !context_->MakeCurrent(surface_.get())) |
| 2543 | return false; |
| 2544 | |
| 2545 | if (WasContextLost()) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2546 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during MakeCurrent."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2547 | return false; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2548 | } |
| 2549 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2550 | return true; |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2551 | } |
| 2552 | |
[email protected] | a96a602 | 2011-11-04 00:58:12 | [diff] [blame] | 2553 | void GLES2DecoderImpl::ReleaseCurrent() { |
| 2554 | if (context_.get()) |
| 2555 | context_->ReleaseCurrent(surface_.get()); |
| 2556 | } |
| 2557 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2558 | void GLES2DecoderImpl::RestoreCurrentRenderbufferBindings() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2559 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 2560 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2561 | glBindRenderbufferEXT( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2562 | GL_RENDERBUFFER, renderbuffer ? renderbuffer->service_id() : 0); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | static void RebindCurrentFramebuffer( |
| 2566 | GLenum target, |
| 2567 | FramebufferManager::FramebufferInfo* info, |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2568 | GLuint back_buffer_service_id) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2569 | GLuint framebuffer_id = info ? info->service_id() : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2570 | |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2571 | if (framebuffer_id == 0) { |
| 2572 | framebuffer_id = back_buffer_service_id; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2573 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2574 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2575 | glBindFramebufferEXT(target, framebuffer_id); |
| 2576 | } |
| 2577 | |
| 2578 | void GLES2DecoderImpl::RestoreCurrentFramebufferBindings() { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2579 | clear_state_dirty_ = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2580 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2581 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2582 | RebindCurrentFramebuffer( |
| 2583 | GL_FRAMEBUFFER, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2584 | state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2585 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2586 | } else { |
| 2587 | RebindCurrentFramebuffer( |
| 2588 | GL_READ_FRAMEBUFFER_EXT, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2589 | state_.bound_read_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2590 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2591 | RebindCurrentFramebuffer( |
| 2592 | GL_DRAW_FRAMEBUFFER_EXT, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2593 | state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2594 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2595 | } |
| 2596 | } |
| 2597 | |
| 2598 | void GLES2DecoderImpl::RestoreCurrentTexture2DBindings() { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2599 | TextureUnit& info = state_.texture_units[0]; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2600 | GLuint last_id; |
| 2601 | if (info.bound_texture_2d) { |
| 2602 | last_id = info.bound_texture_2d->service_id(); |
| 2603 | } else { |
| 2604 | last_id = 0; |
| 2605 | } |
| 2606 | |
| 2607 | glBindTexture(GL_TEXTURE_2D, last_id); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2608 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2609 | } |
| 2610 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2611 | bool GLES2DecoderImpl::CheckFramebufferValid( |
| 2612 | FramebufferManager::FramebufferInfo* framebuffer, |
| 2613 | GLenum target, const char* func_name) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2614 | if (!framebuffer) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2615 | return true; |
| 2616 | } |
| 2617 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2618 | if (framebuffer_manager()->IsComplete(framebuffer)) { |
| 2619 | return true; |
| 2620 | } |
| 2621 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2622 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 2623 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
| 2624 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 2625 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, "framebuffer incomplete"); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 2626 | return false; |
| 2627 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2628 | |
| 2629 | // Are all the attachments cleared? |
| 2630 | if (renderbuffer_manager()->HaveUnclearedRenderbuffers() || |
| 2631 | texture_manager()->HaveUnclearedMips()) { |
| 2632 | if (!framebuffer->IsCleared()) { |
| 2633 | // Can we clear them? |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 2634 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 2635 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2636 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 2637 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 2638 | "framebuffer incomplete (clear)"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2639 | return false; |
| 2640 | } |
| 2641 | ClearUnclearedAttachments(target, framebuffer); |
| 2642 | } |
| 2643 | } |
| 2644 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2645 | if (!framebuffer_manager()->IsComplete(framebuffer)) { |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 2646 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 2647 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2648 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 2649 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 2650 | "framebuffer incomplete (check)"); |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2651 | return false; |
| 2652 | } |
| 2653 | framebuffer_manager()->MarkAsComplete(framebuffer); |
| 2654 | } |
| 2655 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2656 | // NOTE: At this point we don't know if the framebuffer is complete but |
| 2657 | // we DO know that everything that needs to be cleared has been cleared. |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 2658 | return true; |
| 2659 | } |
| 2660 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2661 | bool GLES2DecoderImpl::CheckBoundFramebuffersValid(const char* func_name) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2662 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2663 | return CheckFramebufferValid( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2664 | state_.bound_draw_framebuffer, GL_FRAMEBUFFER_EXT, func_name); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2665 | } |
| 2666 | return CheckFramebufferValid( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2667 | state_.bound_draw_framebuffer, |
| 2668 | GL_DRAW_FRAMEBUFFER_EXT, func_name) && |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2669 | CheckFramebufferValid( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2670 | state_.bound_read_framebuffer, |
| 2671 | GL_READ_FRAMEBUFFER_EXT, func_name); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2672 | } |
| 2673 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2674 | gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2675 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2676 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2677 | if (framebuffer != NULL) { |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2678 | const FramebufferManager::FramebufferInfo::Attachment* attachment = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2679 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2680 | if (attachment) { |
| 2681 | return gfx::Size(attachment->width(), attachment->height()); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2682 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2683 | return gfx::Size(0, 0); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2684 | } else if (offscreen_target_frame_buffer_.get()) { |
| 2685 | return offscreen_size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2686 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 2687 | return surface_->GetSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2688 | } |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2689 | } |
| 2690 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2691 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2692 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2693 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2694 | if (framebuffer != NULL) { |
| 2695 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2696 | } else if (offscreen_target_frame_buffer_.get()) { |
| 2697 | return offscreen_target_color_format_; |
| 2698 | } else { |
| 2699 | return back_buffer_color_format_; |
| 2700 | } |
| 2701 | } |
| 2702 | |
| 2703 | GLenum GLES2DecoderImpl::GetBoundDrawFrameBufferInternalFormat() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2704 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2705 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2706 | if (framebuffer != NULL) { |
| 2707 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2708 | } else if (offscreen_target_frame_buffer_.get()) { |
| 2709 | return offscreen_target_color_format_; |
| 2710 | } else { |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 2711 | return back_buffer_color_format_; |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2712 | } |
| 2713 | } |
| 2714 | |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 2715 | void GLES2DecoderImpl::UpdateParentTextureInfo() { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2716 | if (parent_) { |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 2717 | // Update the info about the offscreen saved color texture in the parent. |
| 2718 | // The reference to the parent is a weak pointer and will become null if the |
| 2719 | // parent is later destroyed. |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2720 | TextureManager* parent_texture_manager = parent_->texture_manager(); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2721 | parent_texture_manager->SetLevelInfo( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2722 | offscreen_saved_color_texture_info_, |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 2723 | GL_TEXTURE_2D, |
| 2724 | 0, // level |
| 2725 | GL_RGBA, |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2726 | offscreen_size_.width(), |
| 2727 | offscreen_size_.height(), |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 2728 | 1, // depth |
| 2729 | 0, // border |
| 2730 | GL_RGBA, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2731 | GL_UNSIGNED_BYTE, |
| 2732 | true); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2733 | parent_texture_manager->SetParameter( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2734 | offscreen_saved_color_texture_info_, |
[email protected] | 8c515f8 | 2010-11-09 03:40:04 | [diff] [blame] | 2735 | GL_TEXTURE_MAG_FILTER, |
| 2736 | GL_NEAREST); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2737 | parent_texture_manager->SetParameter( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2738 | offscreen_saved_color_texture_info_, |
[email protected] | 8c515f8 | 2010-11-09 03:40:04 | [diff] [blame] | 2739 | GL_TEXTURE_MIN_FILTER, |
| 2740 | GL_NEAREST); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2741 | parent_texture_manager->SetParameter( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2742 | offscreen_saved_color_texture_info_, |
[email protected] | 8c515f8 | 2010-11-09 03:40:04 | [diff] [blame] | 2743 | GL_TEXTURE_WRAP_S, |
| 2744 | GL_CLAMP_TO_EDGE); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 2745 | parent_texture_manager->SetParameter( |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2746 | offscreen_saved_color_texture_info_, |
[email protected] | 8c515f8 | 2010-11-09 03:40:04 | [diff] [blame] | 2747 | GL_TEXTURE_WRAP_T, |
| 2748 | GL_CLAMP_TO_EDGE); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2749 | } else { |
| 2750 | offscreen_saved_color_texture_info_ = NULL; |
[email protected] | 0c8c9d2 | 2010-06-25 17:36:39 | [diff] [blame] | 2751 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2752 | } |
| 2753 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2754 | void GLES2DecoderImpl::SetResizeCallback( |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 2755 | const base::Callback<void(gfx::Size)>& callback) { |
| 2756 | resize_callback_ = callback; |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 2757 | } |
| 2758 | |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 2759 | void GLES2DecoderImpl::SetMsgCallback(const MsgCallback& callback) { |
| 2760 | msg_callback_ = callback; |
| 2761 | } |
| 2762 | |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 2763 | void GLES2DecoderImpl::SetStreamTextureManager(StreamTextureManager* manager) { |
| 2764 | stream_texture_manager_ = manager; |
| 2765 | } |
| 2766 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 2767 | bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, |
| 2768 | uint32* service_texture_id) { |
| 2769 | TextureManager::TextureInfo* texture = |
| 2770 | texture_manager()->GetTextureInfo(client_texture_id); |
| 2771 | if (texture) { |
| 2772 | *service_texture_id = texture->service_id(); |
| 2773 | return true; |
| 2774 | } |
| 2775 | return false; |
| 2776 | } |
| 2777 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 2778 | uint32 GLES2DecoderImpl::GetTextureUploadCount() { |
| 2779 | return texture_upload_count_; |
| 2780 | } |
| 2781 | |
| 2782 | base::TimeDelta GLES2DecoderImpl::GetTotalTextureUploadTime() { |
| 2783 | return total_texture_upload_time_; |
| 2784 | } |
| 2785 | |
| 2786 | base::TimeDelta GLES2DecoderImpl::GetTotalProcessingCommandsTime() { |
| 2787 | return total_processing_commands_time_; |
| 2788 | } |
| 2789 | |
[email protected] | dc25dda | 2012-09-27 21:36:30 | [diff] [blame] | 2790 | void GLES2DecoderImpl::AddProcessingCommandsTime(base::TimeDelta time) { |
| 2791 | total_processing_commands_time_ += time; |
| 2792 | } |
| 2793 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2794 | void GLES2DecoderImpl::Destroy(bool have_context) { |
| 2795 | DCHECK(!have_context || context_->IsCurrent(NULL)); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2796 | |
[email protected] | c826d73 | 2012-02-09 04:40:26 | [diff] [blame] | 2797 | ChildList children = children_; |
| 2798 | for (ChildList::iterator it = children.begin(); it != children.end(); ++it) |
| 2799 | (*it)->SetParent(NULL, 0); |
| 2800 | DCHECK(children_.empty()); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2801 | SetParent(NULL, 0); |
| 2802 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2803 | // Unbind everything. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2804 | state_.vertex_attrib_manager = NULL; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2805 | default_vertex_attrib_manager_ = NULL; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2806 | state_.texture_units.clear(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2807 | state_.bound_array_buffer = NULL; |
| 2808 | state_.current_query = NULL; |
| 2809 | state_.current_program = NULL; |
| 2810 | state_.bound_read_framebuffer = NULL; |
| 2811 | state_.bound_draw_framebuffer = NULL; |
| 2812 | state_.bound_renderbuffer = NULL; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2813 | |
[email protected] | eadc9679 | 2010-10-27 19:39:39 | [diff] [blame] | 2814 | if (have_context) { |
[email protected] | c322e88 | 2012-05-23 18:06:18 | [diff] [blame] | 2815 | if (copy_texture_CHROMIUM_.get()) { |
| 2816 | copy_texture_CHROMIUM_->Destroy(); |
| 2817 | copy_texture_CHROMIUM_.reset(); |
| 2818 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2819 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2820 | if (state_.current_program) { |
| 2821 | program_manager()->UnuseProgram(shader_manager(), state_.current_program); |
| 2822 | state_.current_program = NULL; |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 2823 | } |
| 2824 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2825 | if (attrib_0_buffer_id_) { |
| 2826 | glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
| 2827 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2828 | if (fixed_attrib_buffer_id_) { |
| 2829 | glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); |
| 2830 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2831 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2832 | if (offscreen_target_frame_buffer_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 2833 | offscreen_target_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2834 | if (offscreen_target_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 2835 | offscreen_target_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2836 | if (offscreen_target_color_render_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2837 | offscreen_target_color_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2838 | if (offscreen_target_depth_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2839 | offscreen_target_depth_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2840 | if (offscreen_target_stencil_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2841 | offscreen_target_stencil_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2842 | if (offscreen_saved_frame_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2843 | offscreen_saved_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2844 | if (offscreen_saved_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 2845 | offscreen_saved_color_texture_->Destroy(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2846 | if (offscreen_resolved_frame_buffer_.get()) |
| 2847 | offscreen_resolved_frame_buffer_->Destroy(); |
| 2848 | if (offscreen_resolved_color_texture_.get()) |
| 2849 | offscreen_resolved_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2850 | } else { |
| 2851 | if (offscreen_target_frame_buffer_.get()) |
| 2852 | offscreen_target_frame_buffer_->Invalidate(); |
| 2853 | if (offscreen_target_color_texture_.get()) |
| 2854 | offscreen_target_color_texture_->Invalidate(); |
| 2855 | if (offscreen_target_color_render_buffer_.get()) |
| 2856 | offscreen_target_color_render_buffer_->Invalidate(); |
| 2857 | if (offscreen_target_depth_render_buffer_.get()) |
| 2858 | offscreen_target_depth_render_buffer_->Invalidate(); |
| 2859 | if (offscreen_target_stencil_render_buffer_.get()) |
| 2860 | offscreen_target_stencil_render_buffer_->Invalidate(); |
| 2861 | if (offscreen_saved_frame_buffer_.get()) |
| 2862 | offscreen_saved_frame_buffer_->Invalidate(); |
| 2863 | if (offscreen_saved_color_texture_.get()) |
| 2864 | offscreen_saved_color_texture_->Invalidate(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2865 | if (offscreen_resolved_frame_buffer_.get()) |
| 2866 | offscreen_resolved_frame_buffer_->Invalidate(); |
| 2867 | if (offscreen_resolved_color_texture_.get()) |
| 2868 | offscreen_resolved_color_texture_->Invalidate(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2869 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2870 | copy_texture_CHROMIUM_.reset(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2871 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 2872 | if (query_manager_.get()) { |
| 2873 | query_manager_->Destroy(have_context); |
| 2874 | query_manager_.reset(); |
| 2875 | } |
| 2876 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2877 | if (vertex_array_manager_ .get()) { |
| 2878 | vertex_array_manager_->Destroy(have_context); |
| 2879 | vertex_array_manager_.reset(); |
| 2880 | } |
| 2881 | |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 2882 | if (group_) { |
| 2883 | group_->Destroy(have_context); |
| 2884 | group_ = NULL; |
| 2885 | } |
[email protected] | 3ae01938 | 2011-10-05 19:42:41 | [diff] [blame] | 2886 | |
[email protected] | fe87166 | 2011-06-16 20:43:05 | [diff] [blame] | 2887 | if (context_.get()) { |
| 2888 | context_->ReleaseCurrent(NULL); |
[email protected] | 79311e8 | 2011-09-20 00:40:50 | [diff] [blame] | 2889 | context_ = NULL; |
[email protected] | fe87166 | 2011-06-16 20:43:05 | [diff] [blame] | 2890 | } |
[email protected] | 0fc3574 | 2011-04-13 17:57:54 | [diff] [blame] | 2891 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2892 | offscreen_target_frame_buffer_.reset(); |
| 2893 | offscreen_target_color_texture_.reset(); |
| 2894 | offscreen_target_color_render_buffer_.reset(); |
| 2895 | offscreen_target_depth_render_buffer_.reset(); |
| 2896 | offscreen_target_stencil_render_buffer_.reset(); |
| 2897 | offscreen_saved_frame_buffer_.reset(); |
| 2898 | offscreen_saved_color_texture_.reset(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2899 | offscreen_resolved_frame_buffer_.reset(); |
| 2900 | offscreen_resolved_color_texture_.reset(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2901 | |
| 2902 | #if defined(OS_MACOSX) |
| 2903 | for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); |
| 2904 | it != texture_to_io_surface_map_.end(); ++it) { |
| 2905 | CFRelease(it->second); |
| 2906 | } |
| 2907 | texture_to_io_surface_map_.clear(); |
| 2908 | #endif |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2909 | } |
| 2910 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2911 | void GLES2DecoderImpl::SetSurface( |
| 2912 | const scoped_refptr<gfx::GLSurface>& surface) { |
| 2913 | DCHECK(context_->IsCurrent(NULL)); |
| 2914 | DCHECK(surface_.get()); |
| 2915 | surface_ = surface; |
| 2916 | RestoreCurrentFramebufferBindings(); |
| 2917 | } |
| 2918 | |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2919 | bool GLES2DecoderImpl::SetParent(GLES2Decoder* new_parent, |
| 2920 | uint32 new_parent_texture_id) { |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 2921 | if (!offscreen_saved_color_texture_.get()) |
| 2922 | return false; |
| 2923 | |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2924 | // Remove the saved frame buffer mapping from the parent decoder. The |
| 2925 | // parent pointer is a weak pointer so it will be null if the parent has |
| 2926 | // already been destroyed. |
| 2927 | if (parent_) { |
[email protected] | c826d73 | 2012-02-09 04:40:26 | [diff] [blame] | 2928 | ChildList::iterator it = std::find( |
| 2929 | parent_->children_.begin(), |
| 2930 | parent_->children_.end(), |
| 2931 | this); |
| 2932 | DCHECK(it != parent_->children_.end()); |
| 2933 | parent_->children_.erase(it); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2934 | // First check the texture has been mapped into the parent. This might not |
| 2935 | // be the case if initialization failed midway through. |
| 2936 | GLuint service_id = offscreen_saved_color_texture_->id(); |
| 2937 | GLuint client_id = 0; |
| 2938 | if (parent_->texture_manager()->GetClientId(service_id, &client_id)) { |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2939 | parent_->texture_manager()->RemoveTextureInfo(client_id); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2940 | } |
| 2941 | } |
| 2942 | |
| 2943 | GLES2DecoderImpl* new_parent_impl = static_cast<GLES2DecoderImpl*>( |
| 2944 | new_parent); |
| 2945 | if (new_parent_impl) { |
[email protected] | c826d73 | 2012-02-09 04:40:26 | [diff] [blame] | 2946 | #ifndef NDEBUG |
| 2947 | ChildList::iterator it = std::find( |
| 2948 | new_parent_impl->children_.begin(), |
| 2949 | new_parent_impl->children_.end(), |
| 2950 | this); |
| 2951 | DCHECK(it == new_parent_impl->children_.end()); |
| 2952 | #endif |
| 2953 | new_parent_impl->children_.push_back(this); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2954 | // Map the ID of the saved offscreen texture into the parent so that |
| 2955 | // it can reference it. |
| 2956 | GLuint service_id = offscreen_saved_color_texture_->id(); |
[email protected] | 9868786 | 2011-07-11 23:31:30 | [diff] [blame] | 2957 | |
| 2958 | // Replace texture info when ID is already in use by parent. |
| 2959 | if (new_parent_impl->texture_manager()->GetTextureInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2960 | new_parent_texture_id)) |
[email protected] | 9868786 | 2011-07-11 23:31:30 | [diff] [blame] | 2961 | new_parent_impl->texture_manager()->RemoveTextureInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2962 | new_parent_texture_id); |
[email protected] | 9868786 | 2011-07-11 23:31:30 | [diff] [blame] | 2963 | |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2964 | offscreen_saved_color_texture_info_ = |
[email protected] | 5f4f2a73 | 2011-07-30 00:47:55 | [diff] [blame] | 2965 | new_parent_impl->CreateTextureInfo(new_parent_texture_id, service_id); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2966 | offscreen_saved_color_texture_info_->SetNotOwned(); |
| 2967 | new_parent_impl->texture_manager()-> |
| 2968 | SetInfoTarget(offscreen_saved_color_texture_info_, GL_TEXTURE_2D); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2969 | |
| 2970 | parent_ = new_parent_impl->AsWeakPtr(); |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 2971 | |
| 2972 | UpdateParentTextureInfo(); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2973 | } else { |
| 2974 | parent_.reset(); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2975 | offscreen_saved_color_texture_info_ = NULL; |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | return true; |
| 2979 | } |
| 2980 | |
[email protected] | 260ddc4e | 2012-06-28 00:01:53 | [diff] [blame] | 2981 | size_t GLES2DecoderImpl::GetBackbufferMemoryTotal() { |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2982 | size_t total = 0; |
| 2983 | if (offscreen_target_frame_buffer_.get()) { |
| 2984 | if (offscreen_target_color_texture_.get()) { |
| 2985 | total += offscreen_target_color_texture_->estimated_size(); |
| 2986 | } |
| 2987 | if (offscreen_target_color_render_buffer_.get()) { |
| 2988 | total += offscreen_target_color_render_buffer_->estimated_size(); |
| 2989 | } |
| 2990 | if (offscreen_target_depth_render_buffer_.get()) { |
| 2991 | total += offscreen_target_depth_render_buffer_->estimated_size(); |
| 2992 | } |
| 2993 | if (offscreen_target_stencil_render_buffer_.get()) { |
| 2994 | total += offscreen_target_stencil_render_buffer_->estimated_size(); |
| 2995 | } |
| 2996 | if (offscreen_saved_color_texture_.get()) { |
| 2997 | total += offscreen_saved_color_texture_->estimated_size(); |
| 2998 | } |
| 2999 | if (offscreen_resolved_color_texture_.get()) { |
| 3000 | total += offscreen_resolved_color_texture_->estimated_size(); |
| 3001 | } |
| 3002 | } else { |
| 3003 | gfx::Size size = surface_->GetSize(); |
| 3004 | total += size.width() * size.height() * |
| 3005 | GLES2Util::RenderbufferBytesPerPixel(back_buffer_color_format_); |
| 3006 | } |
[email protected] | 260ddc4e | 2012-06-28 00:01:53 | [diff] [blame] | 3007 | return total; |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 3008 | } |
| 3009 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3010 | bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 3011 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3012 | if (!is_offscreen) { |
| 3013 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " |
| 3014 | << " with an onscreen framebuffer."; |
| 3015 | return false; |
| 3016 | } |
| 3017 | |
| 3018 | if (offscreen_size_ == size) |
| 3019 | return true; |
| 3020 | |
| 3021 | offscreen_size_ = size; |
| 3022 | int w = offscreen_size_.width(); |
| 3023 | int h = offscreen_size_.height(); |
| 3024 | if (w < 0 || h < 0 || h >= (INT_MAX / 4) / (w ? w : 1)) { |
| 3025 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3026 | << "to allocate storage due to excessive dimensions."; |
| 3027 | return false; |
| 3028 | } |
| 3029 | |
| 3030 | // Reallocate the offscreen target buffers. |
| 3031 | DCHECK(offscreen_target_color_format_); |
| 3032 | if (IsOffscreenBufferMultisampled()) { |
| 3033 | if (!offscreen_target_color_render_buffer_->AllocateStorage( |
| 3034 | offscreen_size_, offscreen_target_color_format_, |
| 3035 | offscreen_target_samples_)) { |
| 3036 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3037 | << "to allocate storage for offscreen target color buffer."; |
| 3038 | return false; |
| 3039 | } |
| 3040 | } else { |
| 3041 | if (!offscreen_target_color_texture_->AllocateStorage( |
| 3042 | offscreen_size_, offscreen_target_color_format_)) { |
| 3043 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3044 | << "to allocate storage for offscreen target color texture."; |
| 3045 | return false; |
| 3046 | } |
| 3047 | } |
| 3048 | if (offscreen_target_depth_format_ && |
| 3049 | !offscreen_target_depth_render_buffer_->AllocateStorage( |
| 3050 | offscreen_size_, offscreen_target_depth_format_, |
| 3051 | offscreen_target_samples_)) { |
| 3052 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3053 | << "to allocate storage for offscreen target depth buffer."; |
| 3054 | return false; |
| 3055 | } |
| 3056 | if (offscreen_target_stencil_format_ && |
| 3057 | !offscreen_target_stencil_render_buffer_->AllocateStorage( |
| 3058 | offscreen_size_, offscreen_target_stencil_format_, |
| 3059 | offscreen_target_samples_)) { |
| 3060 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3061 | << "to allocate storage for offscreen target stencil buffer."; |
| 3062 | return false; |
| 3063 | } |
| 3064 | |
| 3065 | // Attach the offscreen target buffers to the target frame buffer. |
| 3066 | if (IsOffscreenBufferMultisampled()) { |
| 3067 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3068 | GL_COLOR_ATTACHMENT0, |
| 3069 | offscreen_target_color_render_buffer_.get()); |
| 3070 | } else { |
| 3071 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 3072 | offscreen_target_color_texture_.get()); |
| 3073 | } |
| 3074 | if (offscreen_target_depth_format_) { |
| 3075 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3076 | GL_DEPTH_ATTACHMENT, |
| 3077 | offscreen_target_depth_render_buffer_.get()); |
| 3078 | } |
| 3079 | const bool packed_depth_stencil = |
| 3080 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 3081 | if (packed_depth_stencil) { |
| 3082 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3083 | GL_STENCIL_ATTACHMENT, |
| 3084 | offscreen_target_depth_render_buffer_.get()); |
| 3085 | } else if (offscreen_target_stencil_format_) { |
| 3086 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3087 | GL_STENCIL_ATTACHMENT, |
| 3088 | offscreen_target_stencil_render_buffer_.get()); |
| 3089 | } |
| 3090 | |
| 3091 | if (offscreen_target_frame_buffer_->CheckStatus() != |
| 3092 | GL_FRAMEBUFFER_COMPLETE) { |
| 3093 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3094 | << "because offscreen FBO was incomplete."; |
| 3095 | return false; |
| 3096 | } |
| 3097 | |
| 3098 | // Clear the target frame buffer. |
| 3099 | { |
| 3100 | ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); |
| 3101 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
| 3102 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
| 3103 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 3104 | glClearStencil(0); |
| 3105 | glStencilMaskSeparate(GL_FRONT, -1); |
| 3106 | glStencilMaskSeparate(GL_BACK, -1); |
| 3107 | glClearDepth(0); |
| 3108 | glDepthMask(GL_TRUE); |
| 3109 | glDisable(GL_SCISSOR_TEST); |
| 3110 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 3111 | RestoreClearState(); |
| 3112 | } |
[email protected] | d85ef76d | 2011-09-08 22:21:43 | [diff] [blame] | 3113 | |
| 3114 | // Destroy the offscreen resolved framebuffers. |
| 3115 | if (offscreen_resolved_frame_buffer_.get()) |
| 3116 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3117 | if (offscreen_resolved_color_texture_.get()) |
| 3118 | offscreen_resolved_color_texture_->Destroy(); |
| 3119 | offscreen_resolved_color_texture_.reset(); |
| 3120 | offscreen_resolved_frame_buffer_.reset(); |
| 3121 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3122 | return true; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3123 | } |
| 3124 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3125 | error::Error GLES2DecoderImpl::HandleResizeCHROMIUM( |
| 3126 | uint32 immediate_data_size, const gles2::ResizeCHROMIUM& c) { |
[email protected] | 45212087 | 2012-09-27 15:21:02 | [diff] [blame] | 3127 | if (ShouldDeferDraws()) |
| 3128 | return error::kDeferCommandUntilLater; |
| 3129 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3130 | GLuint width = static_cast<GLuint>(c.width); |
| 3131 | GLuint height = static_cast<GLuint>(c.height); |
| 3132 | TRACE_EVENT2("gpu", "glResizeChromium", "width", width, "height", height); |
[email protected] | a0d98916 | 2011-11-22 13:15:07 | [diff] [blame] | 3133 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && \ |
| 3134 | !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3135 | // Make sure that we are done drawing to the back buffer before resizing. |
| 3136 | glFinish(); |
| 3137 | #endif |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3138 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3139 | if (is_offscreen) { |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3140 | if (!ResizeOffscreenFrameBuffer(gfx::Size(width, height))) { |
| 3141 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because " |
| 3142 | << "ResizeOffscreenFrameBuffer failed."; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3143 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3144 | } |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3145 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3146 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3147 | if (!resize_callback_.is_null()) { |
| 3148 | resize_callback_.Run(gfx::Size(width, height)); |
[email protected] | c777de5 | 2011-09-09 23:08:56 | [diff] [blame] | 3149 | DCHECK(context_->IsCurrent(surface_.get())); |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3150 | if (!context_->IsCurrent(surface_.get())) { |
| 3151 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because context no longer " |
| 3152 | << "current after resize callback."; |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3153 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3154 | } |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3155 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3156 | |
| 3157 | return error::kNoError; |
[email protected] | 43ecf37 | 2010-11-16 19:19:39 | [diff] [blame] | 3158 | } |
| 3159 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3160 | const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { |
| 3161 | if (command_id > kStartPoint && command_id < kNumCommands) { |
| 3162 | return gles2::GetCommandName(static_cast<CommandId>(command_id)); |
| 3163 | } |
| 3164 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 3165 | } |
| 3166 | |
| 3167 | // Decode command with its arguments, and call the corresponding GL function. |
| 3168 | // Note: args is a pointer to the command buffer. As such, it could be changed |
| 3169 | // by a (malicious) client at any time, so if validation has to happen, it |
| 3170 | // should operate on a copy of them. |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3171 | error::Error GLES2DecoderImpl::DoCommand( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3172 | unsigned int command, |
| 3173 | unsigned int arg_count, |
| 3174 | const void* cmd_data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3175 | error::Error result = error::kNoError; |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 3176 | if (log_commands()) { |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 3177 | // TODO(notme): Change this to a LOG/VLOG that works in release. Tried |
| 3178 | // LOG(INFO), tried VLOG(1), no luck. |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 3179 | LOG(ERROR) << "[" << GetLogPrefix() << "]" << "cmd: " |
| 3180 | << GetCommandName(command); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3181 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3182 | unsigned int command_index = command - kStartPoint - 1; |
| 3183 | if (command_index < arraysize(g_command_info)) { |
| 3184 | const CommandInfo& info = g_command_info[command_index]; |
| 3185 | unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
| 3186 | if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
| 3187 | (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3188 | uint32 immediate_data_size = |
| 3189 | (arg_count - info_arg_count) * sizeof(CommandBufferEntry); // NOLINT |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3190 | switch (command) { |
| 3191 | #define GLES2_CMD_OP(name) \ |
| 3192 | case name::kCmdId: \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3193 | result = Handle ## name( \ |
| 3194 | immediate_data_size, \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3195 | *static_cast<const name*>(cmd_data)); \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3196 | break; \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3197 | |
| 3198 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3199 | #undef GLES2_CMD_OP |
[email protected] | bf0985e | 2009-12-17 03:04:38 | [diff] [blame] | 3200 | } |
| 3201 | if (debug()) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3202 | GLenum error; |
| 3203 | while ((error = glGetError()) != GL_NO_ERROR) { |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 3204 | LOG(ERROR) << "[" << GetLogPrefix() << "] " |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 3205 | << "GL ERROR: " << GLES2Util::GetStringEnum(error) << " : " |
| 3206 | << GetCommandName(command); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3207 | SetGLError(error, "DoCommand", "GL error from driver"); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3208 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3209 | } |
| 3210 | } else { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3211 | result = error::kInvalidArguments; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3212 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3213 | } else { |
| 3214 | result = DoCommonCommand(command, arg_count, cmd_data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3215 | } |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 3216 | if (result == error::kNoError && current_decoder_error_ != error::kNoError) { |
| 3217 | result = current_decoder_error_; |
| 3218 | current_decoder_error_ = error::kNoError; |
| 3219 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3220 | return result; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3221 | } |
| 3222 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3223 | void GLES2DecoderImpl::RemoveBufferInfo(GLuint client_id) { |
| 3224 | buffer_manager()->RemoveBufferInfo(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3225 | } |
| 3226 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3227 | bool GLES2DecoderImpl::CreateProgramHelper(GLuint client_id) { |
| 3228 | if (GetProgramInfo(client_id)) { |
| 3229 | return false; |
| 3230 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3231 | GLuint service_id = glCreateProgram(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3232 | if (service_id != 0) { |
| 3233 | CreateProgramInfo(client_id, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3234 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3235 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3236 | } |
| 3237 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3238 | bool GLES2DecoderImpl::CreateShaderHelper(GLenum type, GLuint client_id) { |
| 3239 | if (GetShaderInfo(client_id)) { |
| 3240 | return false; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3241 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3242 | GLuint service_id = glCreateShader(type); |
| 3243 | if (service_id != 0) { |
[email protected] | 7cea56d9 | 2010-04-28 17:21:38 | [diff] [blame] | 3244 | CreateShaderInfo(client_id, service_id, type); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3245 | } |
| 3246 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3247 | } |
| 3248 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3249 | void GLES2DecoderImpl::DoFinish() { |
| 3250 | glFinish(); |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 3251 | ProcessPendingQueries(); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | void GLES2DecoderImpl::DoFlush() { |
| 3255 | glFlush(); |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 3256 | ProcessPendingQueries(); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3257 | } |
| 3258 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3259 | void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3260 | GLuint texture_index = texture_unit - GL_TEXTURE0; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3261 | if (texture_index >= state_.texture_units.size()) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 3262 | SetGLErrorInvalidEnum( |
| 3263 | "glActiveTexture", texture_unit, "texture_unit"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3264 | return; |
| 3265 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3266 | state_.active_texture_unit = texture_index; |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3267 | glActiveTexture(texture_unit); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3268 | } |
| 3269 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3270 | void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3271 | BufferManager::BufferInfo* info = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3272 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3273 | if (client_id != 0) { |
| 3274 | info = GetBufferInfo(client_id); |
| 3275 | if (!info) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3276 | if (!group_->bind_generates_resource()) { |
[email protected] | f4eac070 | 2012-03-30 17:55:15 | [diff] [blame] | 3277 | LOG(ERROR) << "glBindBuffer: id not generated by glGenBuffers"; |
| 3278 | current_decoder_error_ = error::kGenericError; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3279 | return; |
| 3280 | } |
| 3281 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3282 | // It's a new id so make a buffer info for it. |
| 3283 | glGenBuffersARB(1, &service_id); |
| 3284 | CreateBufferInfo(client_id, service_id); |
| 3285 | info = GetBufferInfo(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3286 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3287 | group_->GetIdAllocator(id_namespaces::kBuffers); |
| 3288 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3289 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3290 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3291 | if (info) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3292 | if (!buffer_manager()->SetTarget(info, target)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3293 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3294 | "glBindBuffer", "buffer bound to more than 1 target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3295 | return; |
| 3296 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3297 | service_id = info->service_id(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3298 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3299 | switch (target) { |
| 3300 | case GL_ARRAY_BUFFER: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3301 | state_.bound_array_buffer = info; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3302 | break; |
| 3303 | case GL_ELEMENT_ARRAY_BUFFER: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3304 | state_.vertex_attrib_manager->SetElementArrayBuffer(info); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3305 | break; |
| 3306 | default: |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3307 | NOTREACHED(); // Validation should prevent us getting here. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3308 | break; |
| 3309 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3310 | glBindBuffer(target, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3311 | } |
| 3312 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3313 | bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha() { |
| 3314 | return (GLES2Util::GetChannelsForFormat( |
| 3315 | GetBoundDrawFrameBufferInternalFormat()) & 0x0008) != 0; |
| 3316 | } |
| 3317 | |
| 3318 | bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3319 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3320 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3321 | if (framebuffer) { |
| 3322 | return framebuffer->HasDepthAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3323 | } |
| 3324 | if (offscreen_target_frame_buffer_.get()) { |
| 3325 | return offscreen_target_depth_format_ != 0; |
| 3326 | } |
| 3327 | return back_buffer_has_depth_; |
| 3328 | } |
| 3329 | |
| 3330 | bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3331 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3332 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3333 | if (framebuffer) { |
| 3334 | return framebuffer->HasStencilAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3335 | } |
| 3336 | if (offscreen_target_frame_buffer_.get()) { |
| 3337 | return offscreen_target_stencil_format_ != 0 || |
| 3338 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 3339 | } |
| 3340 | return back_buffer_has_stencil_; |
| 3341 | } |
| 3342 | |
| 3343 | void GLES2DecoderImpl::ApplyDirtyState() { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 3344 | if (clear_state_dirty_) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3345 | glColorMask( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3346 | state_.color_mask_red, state_.color_mask_green, state_.color_mask_blue, |
| 3347 | state_.color_mask_alpha && |
| 3348 | BoundFramebufferHasColorAttachmentWithAlpha()); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3349 | bool have_depth = BoundFramebufferHasDepthAttachment(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3350 | glDepthMask(state_.depth_mask && have_depth); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 3351 | EnableDisable(GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3352 | bool have_stencil = BoundFramebufferHasStencilAttachment(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3353 | glStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 3354 | GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3355 | glStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 3356 | GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 3357 | EnableDisable( |
| 3358 | GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil); |
| 3359 | EnableDisable(GL_CULL_FACE, state_.enable_flags.cull_face); |
| 3360 | EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test); |
| 3361 | EnableDisable(GL_BLEND, state_.enable_flags.blend); |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 3362 | clear_state_dirty_ = false; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3363 | } |
| 3364 | } |
| 3365 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 3366 | void GLES2DecoderImpl::BindAndApplyTextureParameters( |
| 3367 | TextureManager::TextureInfo* info) { |
| 3368 | glBindTexture(info->target(), info->service_id()); |
| 3369 | glTexParameteri(info->target(), GL_TEXTURE_MIN_FILTER, info->min_filter()); |
| 3370 | glTexParameteri(info->target(), GL_TEXTURE_MAG_FILTER, info->mag_filter()); |
| 3371 | glTexParameteri(info->target(), GL_TEXTURE_WRAP_S, info->wrap_s()); |
| 3372 | glTexParameteri(info->target(), GL_TEXTURE_WRAP_T, info->wrap_t()); |
| 3373 | } |
| 3374 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3375 | GLuint GLES2DecoderImpl::GetBackbufferServiceId() const { |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3376 | return (offscreen_target_frame_buffer_.get()) ? |
| 3377 | offscreen_target_frame_buffer_->id() : |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3378 | (surface_ ? surface_->GetBackingFrameBufferObject() : 0); |
| 3379 | } |
| 3380 | |
| 3381 | void GLES2DecoderImpl::RestoreState() const { |
| 3382 | state_.RestoreState(); |
| 3383 | |
| 3384 | // TODO: Restore multisample bindings |
| 3385 | GLuint service_id = state_.bound_draw_framebuffer ? |
| 3386 | state_.bound_draw_framebuffer->service_id() : |
| 3387 | GetBackbufferServiceId(); |
| 3388 | glBindFramebufferEXT(GL_FRAMEBUFFER, service_id); |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3389 | } |
| 3390 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3391 | void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { |
| 3392 | FramebufferManager::FramebufferInfo* info = NULL; |
| 3393 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3394 | if (client_id != 0) { |
| 3395 | info = GetFramebufferInfo(client_id); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3396 | if (!info) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3397 | if (!group_->bind_generates_resource()) { |
[email protected] | f4eac070 | 2012-03-30 17:55:15 | [diff] [blame] | 3398 | LOG(ERROR) |
| 3399 | << "glBindFramebuffer: id not generated by glGenFramebuffers"; |
| 3400 | current_decoder_error_ = error::kGenericError; |
| 3401 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3402 | } |
| 3403 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3404 | // It's a new id so make a framebuffer info for it. |
| 3405 | glGenFramebuffersEXT(1, &service_id); |
| 3406 | CreateFramebufferInfo(client_id, service_id); |
| 3407 | info = GetFramebufferInfo(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3408 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3409 | group_->GetIdAllocator(id_namespaces::kFramebuffers); |
| 3410 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3411 | } else { |
| 3412 | service_id = info->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3413 | } |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 3414 | info->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3415 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3416 | |
| 3417 | if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3418 | state_.bound_draw_framebuffer = info; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3419 | } |
| 3420 | if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3421 | state_.bound_read_framebuffer = info; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3422 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3423 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 3424 | clear_state_dirty_ = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3425 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3426 | // If we are rendering to the backbuffer get the FBO id for any simulated |
| 3427 | // backbuffer. |
| 3428 | if (info == NULL) { |
| 3429 | service_id = GetBackbufferServiceId(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3430 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3431 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3432 | glBindFramebufferEXT(target, service_id); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 3433 | } |
| 3434 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3435 | void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { |
| 3436 | RenderbufferManager::RenderbufferInfo* info = NULL; |
| 3437 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3438 | if (client_id != 0) { |
| 3439 | info = GetRenderbufferInfo(client_id); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3440 | if (!info) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3441 | if (!group_->bind_generates_resource()) { |
[email protected] | f4eac070 | 2012-03-30 17:55:15 | [diff] [blame] | 3442 | LOG(ERROR) |
| 3443 | << "glBindRenderbuffer: id not generated by glGenRenderbuffers"; |
| 3444 | current_decoder_error_ = error::kGenericError; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3445 | return; |
| 3446 | } |
| 3447 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3448 | // It's a new id so make a renderbuffer info for it. |
| 3449 | glGenRenderbuffersEXT(1, &service_id); |
| 3450 | CreateRenderbufferInfo(client_id, service_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3451 | info = GetRenderbufferInfo(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3452 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3453 | group_->GetIdAllocator(id_namespaces::kRenderbuffers); |
| 3454 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3455 | } else { |
| 3456 | service_id = info->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3457 | } |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 3458 | info->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3459 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3460 | state_.bound_renderbuffer = info; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3461 | glBindRenderbufferEXT(target, service_id); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 3462 | } |
| 3463 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3464 | void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3465 | TextureManager::TextureInfo* info = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3466 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3467 | if (client_id != 0) { |
| 3468 | info = GetTextureInfo(client_id); |
| 3469 | if (!info) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3470 | if (!group_->bind_generates_resource()) { |
[email protected] | f4eac070 | 2012-03-30 17:55:15 | [diff] [blame] | 3471 | LOG(ERROR) << "glBindTexture: id not generated by glGenTextures"; |
| 3472 | current_decoder_error_ = error::kGenericError; |
| 3473 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3474 | } |
| 3475 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3476 | // It's a new id so make a texture info for it. |
| 3477 | glGenTextures(1, &service_id); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3478 | DCHECK_NE(0u, service_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3479 | CreateTextureInfo(client_id, service_id); |
| 3480 | info = GetTextureInfo(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3481 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3482 | group_->GetIdAllocator(id_namespaces::kTextures); |
| 3483 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3484 | } |
| 3485 | } else { |
| 3486 | info = texture_manager()->GetDefaultTextureInfo(target); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3487 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3488 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3489 | // Check the texture exists |
| 3490 | // Check that we are not trying to bind it to a different target. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3491 | if (info->target() != 0 && info->target() != target) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3492 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3493 | "glBindTexture", "texture bound to more than 1 target."); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3494 | return; |
| 3495 | } |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 3496 | if (info->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) { |
| 3497 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3498 | "glBindTexture", "illegal target for stream texture."); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 3499 | return; |
| 3500 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3501 | if (info->target() == 0) { |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3502 | texture_manager()->SetInfoTarget(info, target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3503 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3504 | glBindTexture(target, info->service_id()); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3505 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3506 | unit.bind_target = target; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3507 | switch (target) { |
| 3508 | case GL_TEXTURE_2D: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3509 | unit.bound_texture_2d = info; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3510 | break; |
| 3511 | case GL_TEXTURE_CUBE_MAP: |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3512 | unit.bound_texture_cube_map = info; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3513 | break; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3514 | case GL_TEXTURE_EXTERNAL_OES: |
| 3515 | unit.bound_texture_external_oes = info; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 3516 | if (info->IsStreamTexture()) { |
| 3517 | DCHECK(stream_texture_manager_); |
| 3518 | StreamTexture* stream_tex = |
| 3519 | stream_texture_manager_->LookupStreamTexture(info->service_id()); |
| 3520 | if (stream_tex) |
| 3521 | stream_tex->Update(); |
| 3522 | } |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3523 | break; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3524 | case GL_TEXTURE_RECTANGLE_ARB: |
| 3525 | unit.bound_texture_rectangle_arb = info; |
| 3526 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3527 | default: |
| 3528 | NOTREACHED(); // Validation should prevent us getting here. |
| 3529 | break; |
| 3530 | } |
| 3531 | } |
| 3532 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3533 | void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3534 | if (state_.vertex_attrib_manager->Enable(index, false)) { |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 3535 | if (index != 0 || |
| 3536 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3537 | glDisableVertexAttribArray(index); |
| 3538 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3539 | } else { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3540 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3541 | "glDisableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3542 | } |
| 3543 | } |
| 3544 | |
| 3545 | void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3546 | if (state_.vertex_attrib_manager->Enable(index, true)) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3547 | glEnableVertexAttribArray(index); |
| 3548 | } else { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3549 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3550 | "glEnableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3551 | } |
| 3552 | } |
| 3553 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3554 | void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3555 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 3556 | if (!info || |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 3557 | !texture_manager()->CanGenerateMipmaps(info)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 3558 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3559 | "glGenerateMipmaps", "Can not generate mips"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3560 | return; |
| 3561 | } |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 3562 | |
[email protected] | 7687479c | 2012-05-14 23:54:04 | [diff] [blame] | 3563 | if (!texture_manager()->ClearTextureLevel(this, info, target, 0)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3564 | SetGLError(GL_OUT_OF_MEMORY, "glGenerateMipmaps", "dimensions too big"); |
[email protected] | 7687479c | 2012-05-14 23:54:04 | [diff] [blame] | 3565 | return; |
| 3566 | } |
| 3567 | |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 3568 | CopyRealGLErrorsToWrapper(); |
[email protected] | 59f3ca0 | 2011-03-26 22:24:19 | [diff] [blame] | 3569 | // Workaround for Mac driver bug. In the large scheme of things setting |
| 3570 | // glTexParamter twice for glGenerateMipmap is probably not a lage performance |
[email protected] | a8bad26 | 2011-10-21 18:28:56 | [diff] [blame] | 3571 | // hit so there's probably no need to make this conditional. The bug appears |
| 3572 | // to be that if the filtering mode is set to something that doesn't require |
| 3573 | // mipmaps for rendering, or is never set to something other than the default, |
| 3574 | // then glGenerateMipmap misbehaves. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3575 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 3576 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 3577 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3578 | glGenerateMipmapEXT(target); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3579 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 3580 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, info->min_filter()); |
| 3581 | } |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 3582 | GLenum error = PeekGLError(); |
| 3583 | if (error == GL_NO_ERROR) { |
| 3584 | texture_manager()->MarkMipmapsGenerated(info); |
| 3585 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3586 | } |
| 3587 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3588 | bool GLES2DecoderImpl::GetHelper( |
| 3589 | GLenum pname, GLint* params, GLsizei* num_written) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3590 | DCHECK(num_written); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3591 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 3592 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3593 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 3594 | *num_written = 1; |
| 3595 | if (params) { |
| 3596 | *params = GL_RGBA; // We don't support other formats. |
| 3597 | } |
| 3598 | return true; |
| 3599 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 3600 | *num_written = 1; |
| 3601 | if (params) { |
| 3602 | *params = GL_UNSIGNED_BYTE; // We don't support other types. |
| 3603 | } |
| 3604 | return true; |
| 3605 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 3606 | *num_written = 1; |
| 3607 | if (params) { |
| 3608 | *params = group_->max_fragment_uniform_vectors(); |
| 3609 | } |
| 3610 | return true; |
| 3611 | case GL_MAX_VARYING_VECTORS: |
| 3612 | *num_written = 1; |
| 3613 | if (params) { |
| 3614 | *params = group_->max_varying_vectors(); |
| 3615 | } |
| 3616 | return true; |
| 3617 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 3618 | *num_written = 1; |
| 3619 | if (params) { |
| 3620 | *params = group_->max_vertex_uniform_vectors(); |
| 3621 | } |
| 3622 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3623 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 3624 | } |
| 3625 | switch (pname) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 3626 | case GL_MAX_VIEWPORT_DIMS: |
| 3627 | if (offscreen_target_frame_buffer_.get()) { |
| 3628 | *num_written = 2; |
| 3629 | if (params) { |
| 3630 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 3631 | params[1] = renderbuffer_manager()->max_renderbuffer_size(); |
| 3632 | } |
| 3633 | return true; |
| 3634 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 3635 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 3636 | case GL_MAX_SAMPLES: |
| 3637 | *num_written = 1; |
| 3638 | if (params) { |
| 3639 | params[0] = renderbuffer_manager()->max_samples(); |
| 3640 | } |
| 3641 | return true; |
| 3642 | case GL_MAX_RENDERBUFFER_SIZE: |
| 3643 | *num_written = 1; |
| 3644 | if (params) { |
| 3645 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 3646 | } |
| 3647 | return true; |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 3648 | case GL_MAX_TEXTURE_SIZE: |
| 3649 | *num_written = 1; |
| 3650 | if (params) { |
| 3651 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_2D); |
| 3652 | } |
| 3653 | return true; |
| 3654 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 3655 | *num_written = 1; |
| 3656 | if (params) { |
| 3657 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP); |
| 3658 | } |
| 3659 | return true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3660 | case GL_ALPHA_BITS: |
| 3661 | *num_written = 1; |
| 3662 | if (params) { |
| 3663 | GLint v = 0; |
| 3664 | glGetIntegerv(GL_ALPHA_BITS, &v); |
| 3665 | params[0] = BoundFramebufferHasColorAttachmentWithAlpha() ? v : 0; |
| 3666 | } |
| 3667 | return true; |
| 3668 | case GL_DEPTH_BITS: |
| 3669 | *num_written = 1; |
| 3670 | if (params) { |
| 3671 | GLint v = 0; |
| 3672 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 3673 | params[0] = BoundFramebufferHasDepthAttachment() ? v : 0; |
| 3674 | } |
| 3675 | return true; |
| 3676 | case GL_STENCIL_BITS: |
| 3677 | *num_written = 1; |
| 3678 | if (params) { |
| 3679 | GLint v = 0; |
| 3680 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 3681 | params[0] = BoundFramebufferHasStencilAttachment() ? v : 0; |
| 3682 | } |
| 3683 | return true; |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 3684 | case GL_COMPRESSED_TEXTURE_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 3685 | *num_written = validators_->compressed_texture_format.GetValues().size(); |
| 3686 | if (params) { |
| 3687 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 3688 | params[ii] = validators_->compressed_texture_format.GetValues()[ii]; |
| 3689 | } |
| 3690 | } |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 3691 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3692 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 3693 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3694 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 3695 | *params = validators_->compressed_texture_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3696 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3697 | return true; |
| 3698 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 3699 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3700 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 3701 | *params = validators_->shader_binary_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3702 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3703 | return true; |
| 3704 | case GL_SHADER_BINARY_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 3705 | *num_written = validators_->shader_binary_format.GetValues().size(); |
| 3706 | if (params) { |
| 3707 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 3708 | params[ii] = validators_->shader_binary_format.GetValues()[ii]; |
| 3709 | } |
| 3710 | } |
| 3711 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3712 | case GL_SHADER_COMPILER: |
| 3713 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3714 | if (params) { |
| 3715 | *params = GL_TRUE; |
| 3716 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3717 | return true; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3718 | case GL_ARRAY_BUFFER_BINDING: |
| 3719 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3720 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3721 | if (state_.bound_array_buffer) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3722 | GLuint client_id = 0; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3723 | buffer_manager()->GetClientId(state_.bound_array_buffer->service_id(), |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3724 | &client_id); |
| 3725 | *params = client_id; |
| 3726 | } else { |
| 3727 | *params = 0; |
| 3728 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3729 | } |
| 3730 | return true; |
| 3731 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 3732 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3733 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3734 | if (state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3735 | GLuint client_id = 0; |
| 3736 | buffer_manager()->GetClientId( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3737 | state_.vertex_attrib_manager->element_array_buffer( |
| 3738 | )->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3739 | *params = client_id; |
| 3740 | } else { |
| 3741 | *params = 0; |
| 3742 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3743 | } |
| 3744 | return true; |
| 3745 | case GL_FRAMEBUFFER_BINDING: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3746 | // case GL_DRAW_FRAMEBUFFER_BINDING_EXT: (same as GL_FRAMEBUFFER_BINDING) |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3747 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3748 | if (params) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3749 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3750 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3751 | if (framebuffer) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3752 | GLuint client_id = 0; |
| 3753 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3754 | framebuffer->service_id(), &client_id); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3755 | *params = client_id; |
| 3756 | } else { |
| 3757 | *params = 0; |
| 3758 | } |
| 3759 | } |
| 3760 | return true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3761 | case GL_READ_FRAMEBUFFER_BINDING_EXT: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3762 | *num_written = 1; |
| 3763 | if (params) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3764 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3765 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3766 | if (framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3767 | GLuint client_id = 0; |
| 3768 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3769 | framebuffer->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3770 | *params = client_id; |
| 3771 | } else { |
| 3772 | *params = 0; |
| 3773 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3774 | } |
| 3775 | return true; |
| 3776 | case GL_RENDERBUFFER_BINDING: |
| 3777 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3778 | if (params) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3779 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 3780 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 3781 | if (renderbuffer) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3782 | GLuint client_id = 0; |
| 3783 | renderbuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3784 | renderbuffer->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3785 | *params = client_id; |
| 3786 | } else { |
| 3787 | *params = 0; |
| 3788 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3789 | } |
| 3790 | return true; |
| 3791 | case GL_CURRENT_PROGRAM: |
| 3792 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3793 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3794 | if (state_.current_program) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3795 | GLuint client_id = 0; |
| 3796 | program_manager()->GetClientId( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3797 | state_.current_program->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3798 | *params = client_id; |
| 3799 | } else { |
| 3800 | *params = 0; |
| 3801 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3802 | } |
| 3803 | return true; |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 3804 | case GL_VERTEX_ARRAY_BINDING_OES: |
| 3805 | *num_written = 1; |
| 3806 | if (params) { |
| 3807 | if (state_.vertex_attrib_manager != default_vertex_attrib_manager_) { |
| 3808 | GLuint client_id = 0; |
| 3809 | vertex_array_manager_->GetClientId( |
| 3810 | state_.vertex_attrib_manager->service_id(), &client_id); |
| 3811 | *params = client_id; |
| 3812 | } else { |
| 3813 | *params = 0; |
| 3814 | } |
| 3815 | } |
| 3816 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3817 | case GL_TEXTURE_BINDING_2D: |
| 3818 | *num_written = 1; |
| 3819 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3820 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3821 | if (unit.bound_texture_2d) { |
| 3822 | GLuint client_id = 0; |
| 3823 | texture_manager()->GetClientId( |
| 3824 | unit.bound_texture_2d->service_id(), &client_id); |
| 3825 | *params = client_id; |
| 3826 | } else { |
| 3827 | *params = 0; |
| 3828 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3829 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3830 | return true; |
| 3831 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 3832 | *num_written = 1; |
| 3833 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3834 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3835 | if (unit.bound_texture_cube_map) { |
| 3836 | GLuint client_id = 0; |
| 3837 | texture_manager()->GetClientId( |
| 3838 | unit.bound_texture_cube_map->service_id(), &client_id); |
| 3839 | *params = client_id; |
| 3840 | } else { |
| 3841 | *params = 0; |
| 3842 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3843 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3844 | return true; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3845 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 3846 | *num_written = 1; |
| 3847 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3848 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3849 | if (unit.bound_texture_external_oes) { |
| 3850 | GLuint client_id = 0; |
| 3851 | texture_manager()->GetClientId( |
| 3852 | unit.bound_texture_external_oes->service_id(), &client_id); |
| 3853 | *params = client_id; |
| 3854 | } else { |
| 3855 | *params = 0; |
| 3856 | } |
| 3857 | } |
| 3858 | return true; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3859 | case GL_TEXTURE_BINDING_RECTANGLE_ARB: |
| 3860 | *num_written = 1; |
| 3861 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3862 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3863 | if (unit.bound_texture_rectangle_arb) { |
| 3864 | GLuint client_id = 0; |
| 3865 | texture_manager()->GetClientId( |
| 3866 | unit.bound_texture_rectangle_arb->service_id(), &client_id); |
| 3867 | *params = client_id; |
| 3868 | } else { |
| 3869 | *params = 0; |
| 3870 | } |
| 3871 | } |
| 3872 | return true; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 3873 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 3874 | *num_written = 1; |
| 3875 | if (params) { |
| 3876 | params[0] = unpack_flip_y_; |
| 3877 | } |
| 3878 | return true; |
| 3879 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 3880 | *num_written = 1; |
| 3881 | if (params) { |
| 3882 | params[0] = unpack_premultiply_alpha_; |
| 3883 | } |
| 3884 | return true; |
| 3885 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 3886 | *num_written = 1; |
| 3887 | if (params) { |
| 3888 | params[0] = unpack_unpremultiply_alpha_; |
| 3889 | } |
| 3890 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3891 | default: |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3892 | *num_written = util_.GLGetNumValuesReturned(pname); |
[email protected] | c5d79834 | 2010-09-24 20:42:53 | [diff] [blame] | 3893 | return false; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3894 | } |
| 3895 | } |
| 3896 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3897 | bool GLES2DecoderImpl::GetNumValuesReturnedForGLGet( |
| 3898 | GLenum pname, GLsizei* num_values) { |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 3899 | if (state_.GetStateAsGLint(pname, NULL, num_values)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 3900 | return true; |
| 3901 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3902 | return GetHelper(pname, NULL, num_values); |
| 3903 | } |
| 3904 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3905 | void GLES2DecoderImpl::DoGetBooleanv(GLenum pname, GLboolean* params) { |
| 3906 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3907 | GLsizei num_written = 0; |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 3908 | if (GetNumValuesReturnedForGLGet(pname, &num_written)) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3909 | scoped_array<GLint> values(new GLint[num_written]); |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 3910 | if (!state_.GetStateAsGLint(pname, values.get(), &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 3911 | GetHelper(pname, values.get(), &num_written); |
| 3912 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3913 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 3914 | params[ii] = static_cast<GLboolean>(values[ii]); |
| 3915 | } |
| 3916 | } else { |
| 3917 | glGetBooleanv(pname, params); |
| 3918 | } |
| 3919 | } |
| 3920 | |
| 3921 | void GLES2DecoderImpl::DoGetFloatv(GLenum pname, GLfloat* params) { |
| 3922 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 3923 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 3924 | if (!state_.GetStateAsGLfloat(pname, params, &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 3925 | if (GetHelper(pname, NULL, &num_written)) { |
| 3926 | scoped_array<GLint> values(new GLint[num_written]); |
| 3927 | GetHelper(pname, values.get(), &num_written); |
| 3928 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 3929 | params[ii] = static_cast<GLfloat>(values[ii]); |
| 3930 | } |
| 3931 | } else { |
| 3932 | glGetFloatv(pname, params); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3933 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3934 | } |
| 3935 | } |
| 3936 | |
| 3937 | void GLES2DecoderImpl::DoGetIntegerv(GLenum pname, GLint* params) { |
| 3938 | DCHECK(params); |
| 3939 | GLsizei num_written; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 3940 | if (!state_.GetStateAsGLint(pname, params, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 3941 | !GetHelper(pname, params, &num_written)) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 3942 | glGetIntegerv(pname, params); |
| 3943 | } |
| 3944 | } |
| 3945 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 3946 | void GLES2DecoderImpl::DoGetProgramiv( |
| 3947 | GLuint program_id, GLenum pname, GLint* params) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3948 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 3949 | program_id, "glGetProgramiv"); |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 3950 | if (!info) { |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 3951 | return; |
| 3952 | } |
| 3953 | info->GetProgramiv(pname, params); |
| 3954 | } |
| 3955 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3956 | void GLES2DecoderImpl::DoBindAttribLocation( |
| 3957 | GLuint program, GLuint index, const char* name) { |
| 3958 | if (!StringIsValidForGLES(name)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3959 | SetGLError(GL_INVALID_VALUE, "glBindAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3960 | return; |
| 3961 | } |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 3962 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3963 | SetGLError(GL_INVALID_OPERATION, "glBindAttribLocation", "reserved prefix"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 3964 | return; |
| 3965 | } |
| 3966 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3967 | SetGLError(GL_INVALID_VALUE, "glBindAttribLocation", "index out of range"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 3968 | return; |
| 3969 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3970 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 3971 | program, "glBindAttribLocation"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3972 | if (!info) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3973 | return; |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3974 | } |
[email protected] | c3e4c4e | 2012-03-02 19:23:24 | [diff] [blame] | 3975 | info->SetAttribLocationBinding(name, static_cast<GLint>(index)); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3976 | glBindAttribLocation(info->service_id(), index, name); |
| 3977 | } |
| 3978 | |
| 3979 | error::Error GLES2DecoderImpl::HandleBindAttribLocation( |
| 3980 | uint32 immediate_data_size, const gles2::BindAttribLocation& c) { |
| 3981 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3982 | GLuint index = static_cast<GLuint>(c.index); |
| 3983 | uint32 name_size = c.data_size; |
| 3984 | const char* name = GetSharedMemoryAs<const char*>( |
| 3985 | c.name_shm_id, c.name_shm_offset, name_size); |
| 3986 | if (name == NULL) { |
| 3987 | return error::kOutOfBounds; |
| 3988 | } |
| 3989 | String name_str(name, name_size); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 3990 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3991 | return error::kNoError; |
| 3992 | } |
| 3993 | |
| 3994 | error::Error GLES2DecoderImpl::HandleBindAttribLocationImmediate( |
| 3995 | uint32 immediate_data_size, const gles2::BindAttribLocationImmediate& c) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 3996 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 3997 | GLuint index = static_cast<GLuint>(c.index); |
| 3998 | uint32 name_size = c.data_size; |
| 3999 | const char* name = GetImmediateDataAs<const char*>( |
| 4000 | c, name_size, immediate_data_size); |
| 4001 | if (name == NULL) { |
| 4002 | return error::kOutOfBounds; |
| 4003 | } |
| 4004 | String name_str(name, name_size); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4005 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4006 | return error::kNoError; |
| 4007 | } |
| 4008 | |
| 4009 | error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( |
| 4010 | uint32 immediate_data_size, const gles2::BindAttribLocationBucket& c) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4011 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4012 | GLuint index = static_cast<GLuint>(c.index); |
| 4013 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 4014 | if (!bucket || bucket->size() == 0) { |
| 4015 | return error::kInvalidArguments; |
| 4016 | } |
| 4017 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 4018 | if (!bucket->GetAsString(&name_str)) { |
| 4019 | return error::kInvalidArguments; |
| 4020 | } |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4021 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4022 | return error::kNoError; |
| 4023 | } |
| 4024 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4025 | void GLES2DecoderImpl::DoBindUniformLocationCHROMIUM( |
| 4026 | GLuint program, GLint location, const char* name) { |
| 4027 | if (!StringIsValidForGLES(name)) { |
| 4028 | SetGLError(GL_INVALID_VALUE, |
| 4029 | "glBindUniformLocationCHROMIUM", "Invalid character"); |
| 4030 | return; |
| 4031 | } |
| 4032 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
| 4033 | SetGLError(GL_INVALID_OPERATION, |
| 4034 | "glBindUniformLocationCHROMIUM", "reserved prefix"); |
| 4035 | return; |
| 4036 | } |
| 4037 | if (location < 0 || static_cast<uint32>(location) >= |
| 4038 | (group_->max_fragment_uniform_vectors() + |
| 4039 | group_->max_vertex_uniform_vectors()) * 4) { |
| 4040 | SetGLError(GL_INVALID_VALUE, |
| 4041 | "glBindUniformLocationCHROMIUM", "location out of range"); |
| 4042 | return; |
| 4043 | } |
| 4044 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 4045 | program, "glBindUniformLocationCHROMIUM"); |
| 4046 | if (!info) { |
| 4047 | return; |
| 4048 | } |
| 4049 | if (!info->SetUniformLocationBinding(name, location)) { |
| 4050 | SetGLError(GL_INVALID_VALUE, |
| 4051 | "glBindUniformLocationCHROMIUM", "location out of range"); |
| 4052 | } |
| 4053 | } |
| 4054 | |
| 4055 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUM( |
| 4056 | uint32 immediate_data_size, const gles2::BindUniformLocationCHROMIUM& c) { |
| 4057 | GLuint program = static_cast<GLuint>(c.program); |
| 4058 | GLint location = static_cast<GLint>(c.location); |
| 4059 | uint32 name_size = c.data_size; |
| 4060 | const char* name = GetSharedMemoryAs<const char*>( |
| 4061 | c.name_shm_id, c.name_shm_offset, name_size); |
| 4062 | if (name == NULL) { |
| 4063 | return error::kOutOfBounds; |
| 4064 | } |
| 4065 | String name_str(name, name_size); |
| 4066 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 4067 | return error::kNoError; |
| 4068 | } |
| 4069 | |
| 4070 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUMImmediate( |
| 4071 | uint32 immediate_data_size, |
| 4072 | const gles2::BindUniformLocationCHROMIUMImmediate& c) { |
| 4073 | GLuint program = static_cast<GLuint>(c.program); |
| 4074 | GLint location = static_cast<GLint>(c.location); |
| 4075 | uint32 name_size = c.data_size; |
| 4076 | const char* name = GetImmediateDataAs<const char*>( |
| 4077 | c, name_size, immediate_data_size); |
| 4078 | if (name == NULL) { |
| 4079 | return error::kOutOfBounds; |
| 4080 | } |
| 4081 | String name_str(name, name_size); |
| 4082 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 4083 | return error::kNoError; |
| 4084 | } |
| 4085 | |
| 4086 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUMBucket( |
| 4087 | uint32 immediate_data_size, |
| 4088 | const gles2::BindUniformLocationCHROMIUMBucket& c) { |
| 4089 | GLuint program = static_cast<GLuint>(c.program); |
| 4090 | GLint location = static_cast<GLint>(c.location); |
| 4091 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 4092 | if (!bucket || bucket->size() == 0) { |
| 4093 | return error::kInvalidArguments; |
| 4094 | } |
| 4095 | std::string name_str; |
| 4096 | if (!bucket->GetAsString(&name_str)) { |
| 4097 | return error::kInvalidArguments; |
| 4098 | } |
| 4099 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 4100 | return error::kNoError; |
| 4101 | } |
| 4102 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4103 | error::Error GLES2DecoderImpl::HandleDeleteShader( |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 4104 | uint32 immediate_data_size, const gles2::DeleteShader& c) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4105 | GLuint client_id = c.shader; |
| 4106 | if (client_id) { |
| 4107 | ShaderManager::ShaderInfo* info = GetShaderInfo(client_id); |
| 4108 | if (info) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4109 | if (!info->IsDeleted()) { |
| 4110 | glDeleteShader(info->service_id()); |
| 4111 | shader_manager()->MarkAsDeleted(info); |
| 4112 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4113 | } else { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4114 | SetGLError(GL_INVALID_VALUE, "glDeleteShader", "unknown shader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4115 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4116 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4117 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4118 | } |
| 4119 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4120 | error::Error GLES2DecoderImpl::HandleDeleteProgram( |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 4121 | uint32 immediate_data_size, const gles2::DeleteProgram& c) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4122 | GLuint client_id = c.program; |
| 4123 | if (client_id) { |
| 4124 | ProgramManager::ProgramInfo* info = GetProgramInfo(client_id); |
| 4125 | if (info) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4126 | if (!info->IsDeleted()) { |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4127 | program_manager()->MarkAsDeleted(shader_manager(), info); |
| 4128 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4129 | } else { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4130 | SetGLError(GL_INVALID_VALUE, "glDeleteProgram", "unknown program"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4131 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4132 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4133 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4134 | } |
| 4135 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4136 | void GLES2DecoderImpl::DoDeleteSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4137 | GLuint namespace_id, GLsizei n, const GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 4138 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4139 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4140 | id_allocator->FreeID(ids[ii]); |
| 4141 | } |
| 4142 | } |
| 4143 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4144 | error::Error GLES2DecoderImpl::HandleDeleteSharedIdsCHROMIUM( |
| 4145 | uint32 immediate_data_size, const gles2::DeleteSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4146 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 4147 | GLsizei n = static_cast<GLsizei>(c.n); |
| 4148 | uint32 data_size; |
| 4149 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 4150 | return error::kOutOfBounds; |
| 4151 | } |
| 4152 | const GLuint* ids = GetSharedMemoryAs<const GLuint*>( |
| 4153 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 4154 | if (n < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4155 | SetGLError(GL_INVALID_VALUE, "DeleteSharedIdsCHROMIUM", "n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4156 | return error::kNoError; |
| 4157 | } |
| 4158 | if (ids == NULL) { |
| 4159 | return error::kOutOfBounds; |
| 4160 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4161 | DoDeleteSharedIdsCHROMIUM(namespace_id, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4162 | return error::kNoError; |
| 4163 | } |
| 4164 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4165 | void GLES2DecoderImpl::DoGenSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4166 | GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 4167 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4168 | if (id_offset == 0) { |
| 4169 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4170 | ids[ii] = id_allocator->AllocateID(); |
| 4171 | } |
| 4172 | } else { |
| 4173 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4174 | ids[ii] = id_allocator->AllocateIDAtOrAbove(id_offset); |
| 4175 | id_offset = ids[ii] + 1; |
| 4176 | } |
| 4177 | } |
| 4178 | } |
| 4179 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4180 | error::Error GLES2DecoderImpl::HandleGenSharedIdsCHROMIUM( |
| 4181 | uint32 immediate_data_size, const gles2::GenSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4182 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 4183 | GLuint id_offset = static_cast<GLuint>(c.id_offset); |
| 4184 | GLsizei n = static_cast<GLsizei>(c.n); |
| 4185 | uint32 data_size; |
| 4186 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 4187 | return error::kOutOfBounds; |
| 4188 | } |
| 4189 | GLuint* ids = GetSharedMemoryAs<GLuint*>( |
| 4190 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 4191 | if (n < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4192 | SetGLError(GL_INVALID_VALUE, "GenSharedIdsCHROMIUM", "n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4193 | return error::kNoError; |
| 4194 | } |
| 4195 | if (ids == NULL) { |
| 4196 | return error::kOutOfBounds; |
| 4197 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4198 | DoGenSharedIdsCHROMIUM(namespace_id, id_offset, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4199 | return error::kNoError; |
| 4200 | } |
| 4201 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4202 | void GLES2DecoderImpl::DoRegisterSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4203 | GLuint namespace_id, GLsizei n, const GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 4204 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4205 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4206 | if (!id_allocator->MarkAsUsed(ids[ii])) { |
| 4207 | for (GLsizei jj = 0; jj < ii; ++jj) { |
| 4208 | id_allocator->FreeID(ids[jj]); |
| 4209 | } |
| 4210 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4211 | GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM", |
| 4212 | "attempt to register id that already exists"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4213 | return; |
| 4214 | } |
| 4215 | } |
| 4216 | } |
| 4217 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4218 | error::Error GLES2DecoderImpl::HandleRegisterSharedIdsCHROMIUM( |
| 4219 | uint32 immediate_data_size, const gles2::RegisterSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4220 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 4221 | GLsizei n = static_cast<GLsizei>(c.n); |
| 4222 | uint32 data_size; |
| 4223 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 4224 | return error::kOutOfBounds; |
| 4225 | } |
| 4226 | GLuint* ids = GetSharedMemoryAs<GLuint*>( |
| 4227 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 4228 | if (n < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4229 | SetGLError(GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM", "n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4230 | return error::kNoError; |
| 4231 | } |
| 4232 | if (ids == NULL) { |
| 4233 | return error::kOutOfBounds; |
| 4234 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4235 | DoRegisterSharedIdsCHROMIUM(namespace_id, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4236 | return error::kNoError; |
| 4237 | } |
| 4238 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 4239 | error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { |
| 4240 | if (ShouldDeferDraws()) |
| 4241 | return error::kDeferCommandUntilLater; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4242 | if (CheckBoundFramebuffersValid("glClear")) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4243 | UNSHIPPED_TRACE_EVENT_INSTANT2( |
| 4244 | "test_gpu", "DoClear", |
| 4245 | "red", state_.color_clear_red, |
| 4246 | "green", state_.color_clear_green); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4247 | ApplyDirtyState(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4248 | glClear(mask); |
| 4249 | } |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 4250 | return error::kNoError; |
| 4251 | } |
| 4252 | |
| 4253 | error::Error GLES2DecoderImpl::HandleClear( |
| 4254 | uint32 immediate_data_size, const gles2::Clear& c) { |
| 4255 | GLbitfield mask = static_cast<GLbitfield>(c.mask); |
| 4256 | return DoClear(mask); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4257 | } |
| 4258 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4259 | void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
| 4260 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4261 | GLuint client_renderbuffer_id) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4262 | FramebufferManager::FramebufferInfo* framebuffer_info = |
| 4263 | GetFramebufferInfoForTarget(target); |
| 4264 | if (!framebuffer_info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4265 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4266 | "glFramebufferRenderbuffer", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4267 | return; |
| 4268 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4269 | GLuint service_id = 0; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4270 | RenderbufferManager::RenderbufferInfo* info = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4271 | if (client_renderbuffer_id) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4272 | info = GetRenderbufferInfo(client_renderbuffer_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4273 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4274 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4275 | "glFramebufferRenderbuffer", "unknown renderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4276 | return; |
| 4277 | } |
| 4278 | service_id = info->service_id(); |
| 4279 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4280 | CopyRealGLErrorsToWrapper(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4281 | glFramebufferRenderbufferEXT( |
| 4282 | target, attachment, renderbuffertarget, service_id); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4283 | GLenum error = PeekGLError(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4284 | if (error == GL_NO_ERROR) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4285 | framebuffer_info->AttachRenderbuffer(attachment, info); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4286 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4287 | if (framebuffer_info == state_.bound_draw_framebuffer) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4288 | clear_state_dirty_ = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4289 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4290 | } |
| 4291 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4292 | void GLES2DecoderImpl::DoDisable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4293 | if (SetCapabilityState(cap, false)) { |
| 4294 | glDisable(cap); |
| 4295 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4296 | } |
| 4297 | |
| 4298 | void GLES2DecoderImpl::DoEnable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4299 | if (SetCapabilityState(cap, true)) { |
| 4300 | glEnable(cap); |
| 4301 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4302 | } |
| 4303 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4304 | void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { |
| 4305 | state_.z_near = std::min(1.0f, std::max(0.0f, znear)); |
| 4306 | state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); |
| 4307 | glDepthRange(znear, zfar); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4308 | } |
| 4309 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4310 | void GLES2DecoderImpl::DoHint(GLenum target, GLenum mode) { |
| 4311 | switch (target) { |
| 4312 | case GL_GENERATE_MIPMAP_HINT: |
| 4313 | state_.hint_generate_mipmap = mode; |
| 4314 | break; |
| 4315 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: |
| 4316 | state_.hint_fragment_shader_derivative = mode; |
| 4317 | break; |
| 4318 | default: |
| 4319 | NOTREACHED(); |
| 4320 | } |
| 4321 | glHint(target, mode); |
| 4322 | } |
| 4323 | |
| 4324 | void GLES2DecoderImpl::DoSampleCoverage (GLclampf value, GLboolean invert) { |
| 4325 | state_.sample_coverage_value = std::min(1.0f, std::max(0.0f, value)); |
| 4326 | state_.sample_coverage_invert = (invert != 0); |
| 4327 | glSampleCoverage(state_.sample_coverage_value, invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4328 | } |
| 4329 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4330 | // Assumes framebuffer is complete. |
| 4331 | void GLES2DecoderImpl::ClearUnclearedAttachments( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4332 | GLenum target, FramebufferManager::FramebufferInfo* info) { |
| 4333 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4334 | // bind this to the DRAW point, clear then bind back to READ |
| 4335 | // TODO(gman): I don't think there is any guarantee that an FBO that |
| 4336 | // is complete on the READ attachment will be complete as a DRAW |
| 4337 | // attachment. |
| 4338 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); |
| 4339 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, info->service_id()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4340 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4341 | GLbitfield clear_bits = 0; |
| 4342 | if (info->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4343 | glClearColor( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4344 | 0.0f, 0.0f, 0.0f, |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4345 | (GLES2Util::GetChannelsForFormat( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4346 | info->GetColorAttachmentFormat()) & 0x0008) != 0 ? 0.0f : 1.0f); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4347 | glColorMask(true, true, true, true); |
| 4348 | clear_bits |= GL_COLOR_BUFFER_BIT; |
| 4349 | } |
| 4350 | |
| 4351 | if (info->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
| 4352 | info->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
| 4353 | glClearStencil(0); |
| 4354 | glStencilMask(-1); |
| 4355 | clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 4356 | } |
| 4357 | |
| 4358 | if (info->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
| 4359 | info->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
| 4360 | glClearDepth(1.0f); |
| 4361 | glDepthMask(true); |
| 4362 | clear_bits |= GL_DEPTH_BUFFER_BIT; |
| 4363 | } |
| 4364 | |
| 4365 | glDisable(GL_SCISSOR_TEST); |
| 4366 | glClear(clear_bits); |
| 4367 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 4368 | framebuffer_manager()->MarkAttachmentsAsCleared( |
| 4369 | info, renderbuffer_manager(), texture_manager()); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4370 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 4371 | RestoreClearState(); |
| 4372 | |
| 4373 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4374 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, info->service_id()); |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 4375 | FramebufferManager::FramebufferInfo* framebuffer = |
| 4376 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 4377 | GLuint service_id = |
| 4378 | framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); |
| 4379 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, service_id); |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 4380 | } |
| 4381 | } |
| 4382 | |
| 4383 | void GLES2DecoderImpl::RestoreClearState() { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4384 | clear_state_dirty_ = true; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4385 | glClearColor( |
| 4386 | state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, |
| 4387 | state_.color_clear_alpha); |
| 4388 | glClearStencil(state_.stencil_clear); |
| 4389 | glClearDepth(state_.depth_clear); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 4390 | if (state_.enable_flags.scissor_test) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4391 | glEnable(GL_SCISSOR_TEST); |
| 4392 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4396 | FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4397 | GetFramebufferInfoForTarget(target); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4398 | if (!framebuffer) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4399 | return GL_FRAMEBUFFER_COMPLETE; |
| 4400 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4401 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 4402 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
| 4403 | return completeness; |
| 4404 | } |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 4405 | return framebuffer->GetStatus(texture_manager(), target); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4406 | } |
| 4407 | |
| 4408 | void GLES2DecoderImpl::DoFramebufferTexture2D( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4409 | GLenum target, GLenum attachment, GLenum textarget, |
| 4410 | GLuint client_texture_id, GLint level) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4411 | FramebufferManager::FramebufferInfo* framebuffer_info = |
| 4412 | GetFramebufferInfoForTarget(target); |
| 4413 | if (!framebuffer_info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4414 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4415 | "glFramebufferTexture2D", "no framebuffer bound."); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4416 | return; |
| 4417 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4418 | GLuint service_id = 0; |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4419 | TextureManager::TextureInfo* info = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4420 | if (client_texture_id) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4421 | info = GetTextureInfo(client_texture_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4422 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4423 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4424 | "glFramebufferTexture2D", "unknown texture"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4425 | return; |
| 4426 | } |
| 4427 | service_id = info->service_id(); |
| 4428 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4429 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4430 | if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4431 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4432 | "glFramebufferTexture2D", "level out of range"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4433 | return; |
| 4434 | } |
| 4435 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4436 | CopyRealGLErrorsToWrapper(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4437 | glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4438 | GLenum error = PeekGLError(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4439 | if (error == GL_NO_ERROR) { |
| 4440 | framebuffer_info->AttachTexture(attachment, info, textarget, level); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4441 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4442 | if (framebuffer_info == state_.bound_draw_framebuffer) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4443 | clear_state_dirty_ = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4444 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( |
| 4448 | GLenum target, GLenum attachment, GLenum pname, GLint* params) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4449 | FramebufferManager::FramebufferInfo* framebuffer_info = |
| 4450 | GetFramebufferInfoForTarget(target); |
| 4451 | if (!framebuffer_info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4452 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4453 | "glFramebufferAttachmentParameteriv", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4454 | return; |
| 4455 | } |
| 4456 | glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 4457 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { |
| 4458 | GLint type = 0; |
| 4459 | GLuint client_id = 0; |
| 4460 | glGetFramebufferAttachmentParameterivEXT( |
| 4461 | target, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &type); |
| 4462 | switch (type) { |
| 4463 | case GL_RENDERBUFFER: { |
| 4464 | renderbuffer_manager()->GetClientId(*params, &client_id); |
| 4465 | break; |
| 4466 | } |
| 4467 | case GL_TEXTURE: { |
| 4468 | texture_manager()->GetClientId(*params, &client_id); |
| 4469 | break; |
| 4470 | } |
| 4471 | default: |
| 4472 | break; |
| 4473 | } |
| 4474 | *params = client_id; |
| 4475 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4476 | } |
| 4477 | |
| 4478 | void GLES2DecoderImpl::DoGetRenderbufferParameteriv( |
| 4479 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4480 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 4481 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4482 | if (!renderbuffer) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4483 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4484 | "glGetRenderbufferParameteriv", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4485 | return; |
| 4486 | } |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4487 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4488 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 4489 | *params = renderbuffer->internal_format(); |
| 4490 | break; |
| 4491 | case GL_RENDERBUFFER_WIDTH: |
| 4492 | *params = renderbuffer->width(); |
| 4493 | break; |
| 4494 | case GL_RENDERBUFFER_HEIGHT: |
| 4495 | *params = renderbuffer->height(); |
| 4496 | break; |
| 4497 | default: |
| 4498 | glGetRenderbufferParameterivEXT(target, pname, params); |
| 4499 | break; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 4500 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4501 | } |
| 4502 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4503 | void GLES2DecoderImpl::DoBlitFramebufferEXT( |
| 4504 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 4505 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 4506 | GLbitfield mask, GLenum filter) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4507 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4508 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4509 | "glBlitFramebufferEXT", "function not available"); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4510 | } |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4511 | glDisable(GL_SCISSOR_TEST); |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 4512 | if (IsAngle()) { |
| 4513 | glBlitFramebufferANGLE( |
| 4514 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 4515 | } else { |
| 4516 | glBlitFramebufferEXT( |
| 4517 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 4518 | } |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4519 | EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test); |
[email protected] | 529c667 | 2012-01-04 02:18:26 | [diff] [blame] | 4520 | UNSHIPPED_TRACE_EVENT_INSTANT1("test_gpu", "DoBlit", "width", srcX1 - srcX0); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | void GLES2DecoderImpl::DoRenderbufferStorageMultisample( |
| 4524 | GLenum target, GLsizei samples, GLenum internalformat, |
| 4525 | GLsizei width, GLsizei height) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4526 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4527 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4528 | "glRenderbufferStorageMultisampleEXT", "function not available"); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4529 | return; |
| 4530 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4531 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4532 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 4533 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4534 | if (!renderbuffer) { |
| 4535 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4536 | "glGetRenderbufferStorageMultisample", "no renderbuffer bound"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4537 | return; |
| 4538 | } |
| 4539 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4540 | if (samples > renderbuffer_manager()->max_samples()) { |
| 4541 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4542 | "glGetRenderbufferStorageMultisample", "samples too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4543 | return; |
| 4544 | } |
| 4545 | |
| 4546 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 4547 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
| 4548 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4549 | "glGetRenderbufferStorageMultisample", "size too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4550 | return; |
| 4551 | } |
| 4552 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4553 | GLenum impl_format = internalformat; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4554 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4555 | switch (impl_format) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4556 | case GL_DEPTH_COMPONENT16: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4557 | impl_format = GL_DEPTH_COMPONENT; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4558 | break; |
| 4559 | case GL_RGBA4: |
| 4560 | case GL_RGB5_A1: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4561 | impl_format = GL_RGBA; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4562 | break; |
| 4563 | case GL_RGB565: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4564 | impl_format = GL_RGB; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4565 | break; |
| 4566 | } |
| 4567 | } |
| 4568 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4569 | CopyRealGLErrorsToWrapper(); |
[email protected] | 866b91c5 | 2011-03-23 14:38:08 | [diff] [blame] | 4570 | if (IsAngle()) { |
| 4571 | glRenderbufferStorageMultisampleANGLE( |
| 4572 | target, samples, impl_format, width, height); |
| 4573 | } else { |
| 4574 | glRenderbufferStorageMultisampleEXT( |
| 4575 | target, samples, impl_format, width, height); |
| 4576 | } |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4577 | GLenum error = PeekGLError(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4578 | if (error == GL_NO_ERROR) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 4579 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 4580 | // attached to we could just mark those framebuffers as not complete. |
| 4581 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4582 | renderbuffer_manager()->SetInfo( |
| 4583 | renderbuffer, samples, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4584 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4585 | } |
| 4586 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4587 | void GLES2DecoderImpl::DoRenderbufferStorage( |
| 4588 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4589 | RenderbufferManager::RenderbufferInfo* renderbuffer = |
| 4590 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4591 | if (!renderbuffer) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 4592 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4593 | "glGetRenderbufferStorage", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4594 | return; |
| 4595 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4596 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4597 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 4598 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
| 4599 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4600 | "glGetRenderbufferStorage", "size too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4601 | return; |
| 4602 | } |
| 4603 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4604 | GLenum impl_format = internalformat; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4605 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4606 | switch (impl_format) { |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4607 | case GL_DEPTH_COMPONENT16: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4608 | impl_format = GL_DEPTH_COMPONENT; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4609 | break; |
| 4610 | case GL_RGBA4: |
| 4611 | case GL_RGB5_A1: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4612 | impl_format = GL_RGBA; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4613 | break; |
| 4614 | case GL_RGB565: |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4615 | impl_format = GL_RGB; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4616 | break; |
| 4617 | } |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 4618 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 4619 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4620 | CopyRealGLErrorsToWrapper(); |
| 4621 | glRenderbufferStorageEXT(target, impl_format, width, height); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4622 | GLenum error = PeekGLError(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4623 | if (error == GL_NO_ERROR) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 4624 | // TODO(gman): If tetxures tracked which framebuffers they were attached to |
| 4625 | // we could just mark those framebuffers as not complete. |
| 4626 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4627 | renderbuffer_manager()->SetInfo( |
| 4628 | renderbuffer, 0, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4629 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4630 | } |
| 4631 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4632 | void GLES2DecoderImpl::DoLinkProgram(GLuint program) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 4633 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoLinkProgram"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4634 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 4635 | program, "glLinkProgram"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4636 | if (!info) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4637 | return; |
| 4638 | } |
[email protected] | 05afda1 | 2011-01-20 00:17:34 | [diff] [blame] | 4639 | |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 4640 | ShaderTranslator* vertex_translator = NULL; |
| 4641 | ShaderTranslator* fragment_translator = NULL; |
| 4642 | if (use_shader_translator_) { |
| 4643 | vertex_translator = vertex_translator_; |
| 4644 | fragment_translator = fragment_translator_; |
| 4645 | } |
| 4646 | if (info->Link(shader_manager(), |
| 4647 | vertex_translator, |
| 4648 | fragment_translator, |
| 4649 | feature_info_)) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4650 | if (info == state_.current_program.get()) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4651 | if (workarounds().use_current_program_after_successful_link) { |
| 4652 | glUseProgram(info->service_id()); |
[email protected] | c2a3caf1 | 2012-10-23 19:32:00 | [diff] [blame] | 4653 | } |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4654 | program_manager()->ClearUniforms(info); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 4655 | } |
| 4656 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4657 | }; |
| 4658 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4659 | void GLES2DecoderImpl::DoTexParameterf( |
| 4660 | GLenum target, GLenum pname, GLfloat param) { |
| 4661 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4662 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4663 | SetGLError(GL_INVALID_VALUE, "glTexParameterf", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4664 | return; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4665 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4666 | |
| 4667 | if (!texture_manager()->SetParameter( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4668 | info, pname, static_cast<GLint>(param))) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 4669 | SetGLErrorInvalidEnum("glTexParameterf", pname, "pname"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4670 | return; |
| 4671 | } |
| 4672 | glTexParameterf(target, pname, param); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4673 | } |
| 4674 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4675 | void GLES2DecoderImpl::DoTexParameteri( |
| 4676 | GLenum target, GLenum pname, GLint param) { |
| 4677 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 4678 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4679 | SetGLError(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4680 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4681 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4682 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4683 | if (!texture_manager()->SetParameter(info, pname, param)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 4684 | SetGLErrorInvalidEnum("glTexParameteri", pname, "pname"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4685 | return; |
| 4686 | } |
| 4687 | glTexParameteri(target, pname, param); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4688 | } |
| 4689 | |
| 4690 | void GLES2DecoderImpl::DoTexParameterfv( |
| 4691 | GLenum target, GLenum pname, const GLfloat* params) { |
| 4692 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 4693 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4694 | SetGLError(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4695 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4696 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4697 | |
| 4698 | if (!texture_manager()->SetParameter( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4699 | info, pname, static_cast<GLint>(params[0]))) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 4700 | SetGLErrorInvalidEnum("glTexParameterfv", pname, "pname"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4701 | return; |
| 4702 | } |
| 4703 | glTexParameterfv(target, pname, params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4704 | } |
| 4705 | |
| 4706 | void GLES2DecoderImpl::DoTexParameteriv( |
| 4707 | GLenum target, GLenum pname, const GLint* params) { |
| 4708 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 4709 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4710 | SetGLError(GL_INVALID_VALUE, "glTexParameteriv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4711 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4712 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4713 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4714 | if (!texture_manager()->SetParameter(info, pname, *params)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 4715 | SetGLErrorInvalidEnum("glTexParameteriv", pname, "pname"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 4716 | return; |
| 4717 | } |
| 4718 | glTexParameteriv(target, pname, params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4719 | } |
| 4720 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4721 | bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4722 | if (!state_.current_program) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4723 | // The program does not exist. |
| 4724 | SetGLError(GL_INVALID_OPERATION, function_name, "no program in use"); |
| 4725 | return false; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4726 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4727 | if (!state_.current_program->InUse()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4728 | SetGLError(GL_INVALID_OPERATION, function_name, "program not linked"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4729 | return false; |
| 4730 | } |
| 4731 | return true; |
| 4732 | } |
| 4733 | |
| 4734 | bool GLES2DecoderImpl::CheckCurrentProgramForUniform( |
| 4735 | GLint location, const char* function_name) { |
| 4736 | if (!CheckCurrentProgram(function_name)) { |
| 4737 | return false; |
| 4738 | } |
| 4739 | return location != -1; |
| 4740 | } |
| 4741 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4742 | bool GLES2DecoderImpl::PrepForSetUniformByLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4743 | GLint fake_location, const char* function_name, |
| 4744 | GLint* real_location, GLenum* type, GLsizei* count) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4745 | DCHECK(type); |
| 4746 | DCHECK(count); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4747 | DCHECK(real_location); |
| 4748 | if (!CheckCurrentProgramForUniform(fake_location, function_name)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4749 | return false; |
| 4750 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4751 | GLint array_index = -1; |
| 4752 | const ProgramManager::ProgramInfo::UniformInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4753 | state_.current_program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4754 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4755 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4756 | SetGLError(GL_INVALID_OPERATION, function_name, "unknown location"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4757 | return false; |
| 4758 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4759 | if (*count > 1 && !info->is_array) { |
| 4760 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4761 | GL_INVALID_OPERATION, function_name, "count > 1 for non-array"); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4762 | return false; |
| 4763 | } |
| 4764 | *count = std::min(info->size - array_index, *count); |
| 4765 | if (*count <= 0) { |
| 4766 | return false; |
| 4767 | } |
| 4768 | *type = info->type; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4769 | return true; |
| 4770 | } |
| 4771 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4772 | void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) { |
| 4773 | GLenum type = 0; |
| 4774 | GLsizei count = 1; |
| 4775 | GLint real_location = -1; |
| 4776 | if (!PrepForSetUniformByLocation( |
| 4777 | fake_location, "glUniform1iv", &real_location, &type, &count)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4778 | return; |
| 4779 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4780 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4781 | state_.texture_units.size(), fake_location, 1, &v0)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4782 | SetGLError(GL_INVALID_VALUE, "glUniform1i", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 4783 | return; |
| 4784 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4785 | glUniform1i(real_location, v0); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4786 | } |
| 4787 | |
| 4788 | void GLES2DecoderImpl::DoUniform1iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4789 | GLint fake_location, GLsizei count, const GLint *value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4790 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4791 | GLint real_location = -1; |
| 4792 | if (!PrepForSetUniformByLocation( |
| 4793 | fake_location, "glUniform1iv", &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4794 | return; |
| 4795 | } |
[email protected] | 7472711 | 2012-06-13 21:18:08 | [diff] [blame] | 4796 | if (type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || |
| 4797 | type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4798 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4799 | state_.texture_units.size(), fake_location, count, value)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4800 | SetGLError(GL_INVALID_VALUE, "glUniform1iv", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 4801 | return; |
| 4802 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4803 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4804 | glUniform1iv(real_location, count, value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4805 | } |
| 4806 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4807 | void GLES2DecoderImpl::DoUniform1fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4808 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4809 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4810 | GLint real_location = -1; |
| 4811 | if (!PrepForSetUniformByLocation( |
| 4812 | fake_location, "glUniform1fv", &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4813 | return; |
| 4814 | } |
| 4815 | if (type == GL_BOOL) { |
| 4816 | scoped_array<GLint> temp(new GLint[count]); |
| 4817 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 4818 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4819 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4820 | DoUniform1iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4821 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4822 | glUniform1fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | void GLES2DecoderImpl::DoUniform2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4827 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4828 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4829 | GLint real_location = -1; |
| 4830 | if (!PrepForSetUniformByLocation( |
| 4831 | fake_location, "glUniform2fv", &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4832 | return; |
| 4833 | } |
| 4834 | if (type == GL_BOOL_VEC2) { |
| 4835 | GLsizei num_values = count * 2; |
| 4836 | scoped_array<GLint> temp(new GLint[num_values]); |
| 4837 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 4838 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4839 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4840 | glUniform2iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4841 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4842 | glUniform2fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | void GLES2DecoderImpl::DoUniform3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4847 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4848 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4849 | GLint real_location = -1; |
| 4850 | if (!PrepForSetUniformByLocation( |
| 4851 | fake_location, "glUniform3fv", &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4852 | return; |
| 4853 | } |
| 4854 | if (type == GL_BOOL_VEC3) { |
| 4855 | GLsizei num_values = count * 3; |
| 4856 | scoped_array<GLint> temp(new GLint[num_values]); |
| 4857 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 4858 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4859 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4860 | glUniform3iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4861 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4862 | glUniform3fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4863 | } |
| 4864 | } |
| 4865 | |
| 4866 | void GLES2DecoderImpl::DoUniform4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4867 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4868 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4869 | GLint real_location = -1; |
| 4870 | if (!PrepForSetUniformByLocation( |
| 4871 | fake_location, "glUniform4fv", &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4872 | return; |
| 4873 | } |
| 4874 | if (type == GL_BOOL_VEC4) { |
| 4875 | GLsizei num_values = count * 4; |
| 4876 | scoped_array<GLint> temp(new GLint[num_values]); |
| 4877 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 4878 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4879 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4880 | glUniform4iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4881 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4882 | glUniform4fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 4883 | } |
| 4884 | } |
| 4885 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4886 | void GLES2DecoderImpl::DoUniform2iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4887 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4888 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4889 | GLint real_location = -1; |
| 4890 | if (!PrepForSetUniformByLocation( |
| 4891 | fake_location, "glUniform2iv", &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4892 | return; |
| 4893 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4894 | glUniform2iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | void GLES2DecoderImpl::DoUniform3iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4898 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4899 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4900 | GLint real_location = -1; |
| 4901 | if (!PrepForSetUniformByLocation( |
| 4902 | fake_location, "glUniform3iv", &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4903 | return; |
| 4904 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4905 | glUniform3iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | void GLES2DecoderImpl::DoUniform4iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4909 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4910 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4911 | GLint real_location = -1; |
| 4912 | if (!PrepForSetUniformByLocation( |
| 4913 | fake_location, "glUniform4iv", &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4914 | return; |
| 4915 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4916 | glUniform4iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4917 | } |
| 4918 | |
| 4919 | void GLES2DecoderImpl::DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4920 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 4921 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4922 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4923 | GLint real_location = -1; |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4924 | if (!PrepForSetUniformByLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4925 | fake_location, "glUniformMatrix2fv", &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4926 | return; |
| 4927 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4928 | glUniformMatrix2fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4929 | } |
| 4930 | |
| 4931 | void GLES2DecoderImpl::DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4932 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 4933 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4934 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4935 | GLint real_location = -1; |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4936 | if (!PrepForSetUniformByLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4937 | fake_location, "glUniformMatrix3fv", &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4938 | return; |
| 4939 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4940 | glUniformMatrix3fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4941 | } |
| 4942 | |
| 4943 | void GLES2DecoderImpl::DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4944 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 4945 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4946 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4947 | GLint real_location = -1; |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4948 | if (!PrepForSetUniformByLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4949 | fake_location, "glUniformMatrix4fv", &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4950 | return; |
| 4951 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 4952 | glUniformMatrix4fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 4953 | } |
| 4954 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4955 | void GLES2DecoderImpl::DoUseProgram(GLuint program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4956 | GLuint service_id = 0; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4957 | ProgramManager::ProgramInfo* info = NULL; |
| 4958 | if (program) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4959 | info = GetProgramInfoNotShader(program, "glUseProgram"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4960 | if (!info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4961 | return; |
| 4962 | } |
| 4963 | if (!info->IsValid()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4964 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4965 | SetGLError(GL_INVALID_OPERATION, "glUseProgram", "program not linked"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4966 | return; |
| 4967 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4968 | service_id = info->service_id(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4969 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4970 | if (state_.current_program) { |
| 4971 | program_manager()->UnuseProgram(shader_manager(), state_.current_program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4972 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4973 | state_.current_program = info; |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 4974 | glUseProgram(service_id); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4975 | if (state_.current_program) { |
| 4976 | program_manager()->UseProgram(state_.current_program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4977 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4978 | } |
| 4979 | |
[email protected] | efcdd236 | 2012-07-09 21:07:00 | [diff] [blame] | 4980 | uint32 GLES2DecoderImpl::GetGLError() { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4981 | // Check the GL error first, then our wrapped error. |
| 4982 | GLenum error = glGetError(); |
| 4983 | if (error == GL_NO_ERROR && error_bits_ != 0) { |
[email protected] | 03f882a | 2010-01-08 20:46:37 | [diff] [blame] | 4984 | for (uint32 mask = 1; mask != 0; mask = mask << 1) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4985 | if ((error_bits_ & mask) != 0) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 4986 | error = GLES2Util::GLErrorBitToGLError(mask); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4987 | break; |
| 4988 | } |
| 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | if (error != GL_NO_ERROR) { |
| 4993 | // There was an error, clear the corresponding wrapped error. |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 4994 | error_bits_ &= ~GLES2Util::GLErrorToErrorBit(error); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4995 | } |
| 4996 | return error; |
| 4997 | } |
| 4998 | |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 4999 | GLenum GLES2DecoderImpl::PeekGLError() { |
| 5000 | GLenum error = glGetError(); |
| 5001 | if (error != GL_NO_ERROR) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5002 | SetGLError(error, "", ""); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 5003 | } |
| 5004 | return error; |
| 5005 | } |
| 5006 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5007 | void GLES2DecoderImpl::SetGLError( |
| 5008 | GLenum error, const char* function_name, const char* msg) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5009 | if (msg) { |
| 5010 | last_error_ = msg; |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 5011 | LogMessage(GetLogPrefix() + ": " + std::string("GL ERROR :") + |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5012 | GLES2Util::GetStringEnum(error) + " : " + |
| 5013 | function_name + ": " + msg); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5014 | } |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5015 | error_bits_ |= GLES2Util::GLErrorToErrorBit(error); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5016 | } |
| 5017 | |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 5018 | void GLES2DecoderImpl::SetGLErrorInvalidEnum( |
| 5019 | const char* function_name, GLenum value, const char* label) { |
| 5020 | SetGLError(GL_INVALID_ENUM, function_name, |
| 5021 | (std::string(label) + " was " + |
| 5022 | GLES2Util::GetStringEnum(value)).c_str()); |
| 5023 | } |
| 5024 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 5025 | const std::string& GLES2DecoderImpl::GetLogPrefix() const { |
| 5026 | const std::string& prefix(debug_marker_manager_.GetMarker()); |
| 5027 | return prefix.empty() ? this_in_hex_ : prefix; |
| 5028 | } |
| 5029 | |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5030 | void GLES2DecoderImpl::LogMessage(const std::string& msg) { |
| 5031 | if (log_message_count_ < kMaxLogMessages || |
| 5032 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 5033 | switches::kDisableGLErrorLimit)) { |
| 5034 | ++log_message_count_; |
| 5035 | // LOG this unless logging is turned off as any chromium code that |
| 5036 | // generates these errors probably has a bug. |
| 5037 | if (log_synthesized_gl_errors()) { |
[email protected] | 3f00df9 | 2012-06-19 00:44:58 | [diff] [blame] | 5038 | LOG(ERROR) << msg; |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5039 | } |
| 5040 | if (!msg_callback_.is_null()) { |
| 5041 | msg_callback_.Run(0, msg); |
| 5042 | } |
| 5043 | } else { |
| 5044 | if (log_message_count_ == kMaxLogMessages) { |
| 5045 | ++log_message_count_; |
| 5046 | LOG(ERROR) |
| 5047 | << "Too many GL errors, not reporting any more for this context." |
| 5048 | << " use --disable-gl-error-limit to see all errors."; |
| 5049 | } |
| 5050 | } |
| 5051 | } |
| 5052 | |
| 5053 | void GLES2DecoderImpl::RenderWarning(const std::string& msg) { |
| 5054 | LogMessage(std::string("RENDER WARNING: ") + msg); |
| 5055 | } |
| 5056 | |
| 5057 | void GLES2DecoderImpl::PerformanceWarning(const std::string& msg) { |
| 5058 | LogMessage(std::string("PERFORMANCE WARNING: ") + msg); |
| 5059 | } |
| 5060 | |
[email protected] | c447acd | 2012-07-23 23:48:41 | [diff] [blame] | 5061 | void GLES2DecoderImpl::ForceCompileShaderIfPending( |
| 5062 | ShaderManager::ShaderInfo* info) { |
| 5063 | if (info->compilation_status() == |
| 5064 | ShaderManager::ShaderInfo::PENDING_DEFERRED_COMPILE) { |
[email protected] | c447acd | 2012-07-23 23:48:41 | [diff] [blame] | 5065 | ShaderTranslator* translator = NULL; |
| 5066 | if (use_shader_translator_) { |
| 5067 | translator = info->shader_type() == GL_VERTEX_SHADER ? |
| 5068 | vertex_translator_.get() : fragment_translator_.get(); |
| 5069 | } |
| 5070 | // We know there will be no errors, because we only defer compilation on |
| 5071 | // shaders that were previously compiled successfully. |
| 5072 | program_manager()->ForceCompileShader(info->deferred_compilation_source(), |
| 5073 | info, |
| 5074 | translator, |
| 5075 | feature_info_); |
| 5076 | } |
| 5077 | } |
| 5078 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5079 | void GLES2DecoderImpl::CopyRealGLErrorsToWrapper() { |
| 5080 | GLenum error; |
| 5081 | while ((error = glGetError()) != GL_NO_ERROR) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5082 | SetGLError(error, "", NULL); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5083 | } |
| 5084 | } |
| 5085 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 5086 | void GLES2DecoderImpl::ClearRealGLErrors() { |
| 5087 | GLenum error; |
| 5088 | while ((error = glGetError()) != GL_NO_ERROR) { |
[email protected] | 3ed14d11 | 2011-12-13 22:05:51 | [diff] [blame] | 5089 | if (error != GL_OUT_OF_MEMORY) { |
| 5090 | // GL_OUT_OF_MEMORY can legally happen on lost device. |
| 5091 | NOTREACHED() << "GL error " << error << " was unhandled."; |
| 5092 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 5093 | } |
| 5094 | } |
| 5095 | |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5096 | bool GLES2DecoderImpl::SetBlackTextureForNonRenderableTextures() { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5097 | DCHECK(state_.current_program); |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5098 | // Only check if there are some unrenderable textures. |
| 5099 | if (!texture_manager()->HaveUnrenderableTextures()) { |
| 5100 | return false; |
| 5101 | } |
| 5102 | bool textures_set = false; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5103 | const ProgramManager::ProgramInfo::SamplerIndices& sampler_indices = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5104 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5105 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 5106 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5107 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5108 | DCHECK(uniform_info); |
| 5109 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 5110 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5111 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5112 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5113 | TextureManager::TextureInfo* texture_info = |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 5114 | texture_unit.GetInfoForSamplerType(uniform_info->type); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 5115 | if (!texture_info || !texture_manager()->CanRender(texture_info)) { |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5116 | textures_set = true; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5117 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 5118 | glBindTexture( |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 5119 | GetBindTargetForSamplerType(uniform_info->type), |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 5120 | texture_manager()->black_texture_id(uniform_info->type)); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5121 | RenderWarning( |
| 5122 | std::string("texture bound to texture unit ") + |
| 5123 | base::IntToString(texture_unit_index) + |
| 5124 | " is not renderable. It maybe non-power-of-2 and have " |
| 5125 | " incompatible texture filtering or is not " |
| 5126 | "'texture complete'"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5127 | } |
| 5128 | } |
| 5129 | // else: should this be an error? |
| 5130 | } |
| 5131 | } |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5132 | return textures_set; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5133 | } |
| 5134 | |
| 5135 | void GLES2DecoderImpl::RestoreStateForNonRenderableTextures() { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5136 | DCHECK(state_.current_program); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5137 | const ProgramManager::ProgramInfo::SamplerIndices& sampler_indices = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5138 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5139 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 5140 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5141 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5142 | DCHECK(uniform_info); |
| 5143 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 5144 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5145 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5146 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5147 | TextureManager::TextureInfo* texture_info = |
| 5148 | uniform_info->type == GL_SAMPLER_2D ? |
| 5149 | texture_unit.bound_texture_2d : |
| 5150 | texture_unit.bound_texture_cube_map; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 5151 | if (!texture_info || !texture_manager()->CanRender(texture_info)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5152 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 5153 | // Get the texture info that was previously bound here. |
| 5154 | texture_info = texture_unit.bind_target == GL_TEXTURE_2D ? |
| 5155 | texture_unit.bound_texture_2d : |
| 5156 | texture_unit.bound_texture_cube_map; |
| 5157 | glBindTexture(texture_unit.bind_target, |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5158 | texture_info ? texture_info->service_id() : 0); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5159 | } |
| 5160 | } |
| 5161 | } |
| 5162 | } |
| 5163 | // Set the active texture back to whatever the user had it as. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5164 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5165 | } |
| 5166 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5167 | bool GLES2DecoderImpl::ClearUnclearedTextures() { |
| 5168 | // Only check if there are some uncleared textures. |
| 5169 | if (!texture_manager()->HaveUnsafeTextures()) { |
| 5170 | return true; |
| 5171 | } |
| 5172 | |
| 5173 | // 1: Check all textures we are about to render with. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5174 | if (state_.current_program) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5175 | const ProgramManager::ProgramInfo::SamplerIndices& sampler_indices = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5176 | state_.current_program->sampler_indices(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5177 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 5178 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5179 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5180 | DCHECK(uniform_info); |
| 5181 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 5182 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5183 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5184 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5185 | TextureManager::TextureInfo* texture_info = |
| 5186 | texture_unit.GetInfoForSamplerType(uniform_info->type); |
| 5187 | if (texture_info && !texture_info->SafeToRenderFrom()) { |
| 5188 | if (!texture_manager()->ClearRenderableLevels(this, texture_info)) { |
| 5189 | return false; |
| 5190 | } |
| 5191 | } |
| 5192 | } |
| 5193 | } |
| 5194 | } |
| 5195 | } |
| 5196 | return true; |
| 5197 | } |
| 5198 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5199 | bool GLES2DecoderImpl::IsDrawValid( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5200 | const char* function_name, GLuint max_vertex_accessed, GLsizei primcount) { |
[email protected] | 689fa1c5 | 2010-06-09 18:35:03 | [diff] [blame] | 5201 | // NOTE: We specifically do not check current_program->IsValid() because |
| 5202 | // it could never be invalid since glUseProgram would have failed. While |
| 5203 | // glLinkProgram could later mark the program as invalid the previous |
| 5204 | // valid program will still function if it is still the current program. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5205 | if (!state_.current_program) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5206 | // The program does not exist. |
| 5207 | // But GL says no ERROR. |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5208 | RenderWarning("Drawing with no current shader program."); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5209 | return false; |
| 5210 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5211 | |
| 5212 | // true if any enabled, used divisor is zero |
| 5213 | bool divisor0 = false; |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 5214 | // Validate all attribs currently enabled. If they are used by the current |
| 5215 | // program then check that they have enough elements to handle the draw call. |
| 5216 | // If they are not used by the current program check that they have a buffer |
| 5217 | // assigned. |
| 5218 | const VertexAttribManager::VertexAttribInfoList& infos = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5219 | state_.vertex_attrib_manager->GetEnabledVertexAttribInfos(); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 5220 | for (VertexAttribManager::VertexAttribInfoList::const_iterator it = |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5221 | infos.begin(); it != infos.end(); ++it) { |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 5222 | const VertexAttribManager::VertexAttribInfo* info = *it; |
| 5223 | const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5224 | state_.current_program->GetAttribInfoByLocation(info->index()); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 5225 | if (attrib_info) { |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5226 | divisor0 |= (info->divisor() == 0); |
| 5227 | GLuint count = info->MaxVertexAccessed(primcount, max_vertex_accessed); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 5228 | // This attrib is used in the current program. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5229 | if (!info->CanAccess(count)) { |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5230 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5231 | GL_INVALID_OPERATION, function_name, |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5232 | (std::string( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5233 | "attempt to access out of range vertices in attribute ") + |
| 5234 | base::IntToString(info->index())).c_str()); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 5235 | return false; |
| 5236 | } |
| 5237 | } else { |
| 5238 | // This attrib is not used in the current program. |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5239 | if (!info->buffer()) { |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 5240 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5241 | GL_INVALID_OPERATION, function_name, |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5242 | (std::string( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5243 | "attempt to render with no buffer attached to " |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5244 | "enabled attribute ") + |
| 5245 | base::IntToString(info->index())).c_str()); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 5246 | return false; |
| 5247 | } |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 5248 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5249 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5250 | |
| 5251 | if (primcount && !divisor0) { |
| 5252 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5253 | GL_INVALID_OPERATION, function_name, |
| 5254 | "attempt instanced render with all attributes having " |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5255 | "non-zero divisors"); |
| 5256 | return false; |
| 5257 | } |
| 5258 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5259 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5260 | } |
| 5261 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5262 | bool GLES2DecoderImpl::SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5263 | const char* function_name, GLuint max_vertex_accessed, bool* simulated) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5264 | DCHECK(simulated); |
| 5265 | *simulated = false; |
| 5266 | |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5267 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5268 | return true; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5269 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5270 | const VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5271 | state_.vertex_attrib_manager->GetVertexAttribInfo(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5272 | // If it's enabled or it's not used then we don't need to do anything. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5273 | bool attrib_0_used = |
| 5274 | state_.current_program->GetAttribInfoByLocation(0) != NULL; |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 5275 | if (info->enabled() && attrib_0_used) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5276 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5277 | } |
| 5278 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5279 | // Make a buffer with a single repeated vec4 value enough to |
| 5280 | // simulate the constant value that is supposed to be here. |
| 5281 | // This is required to emulate GLES2 on GL. |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5282 | typedef VertexAttribManager::VertexAttribInfo::Vec4 Vec4; |
| 5283 | |
| 5284 | GLuint num_vertices = max_vertex_accessed + 1; |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 5285 | uint32 size_needed = 0; |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5286 | |
| 5287 | if (num_vertices == 0 || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 5288 | !SafeMultiplyUint32(num_vertices, sizeof(Vec4), &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5289 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5290 | SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5291 | return false; |
| 5292 | } |
| 5293 | |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5294 | PerformanceWarning( |
| 5295 | "Attribute 0 is disabled. This has signficant performance penalty"); |
| 5296 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5297 | CopyRealGLErrorsToWrapper(); |
| 5298 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 5299 | |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 5300 | bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; |
| 5301 | if (new_buffer) { |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 5302 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5303 | GLenum error = glGetError(); |
| 5304 | if (error != GL_NO_ERROR) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5305 | SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5306 | return false; |
| 5307 | } |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 5308 | } |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 5309 | if (new_buffer || |
| 5310 | (attrib_0_used && |
| 5311 | (!attrib_0_buffer_matches_value_ || |
| 5312 | (info->value().v[0] != attrib_0_value_.v[0] || |
| 5313 | info->value().v[1] != attrib_0_value_.v[1] || |
| 5314 | info->value().v[2] != attrib_0_value_.v[2] || |
| 5315 | info->value().v[3] != attrib_0_value_.v[3])))) { |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 5316 | std::vector<Vec4> temp(num_vertices, info->value()); |
| 5317 | glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); |
| 5318 | attrib_0_buffer_matches_value_ = true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5319 | attrib_0_value_ = info->value(); |
| 5320 | attrib_0_size_ = size_needed; |
| 5321 | } |
| 5322 | |
| 5323 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 5324 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5325 | if (info->divisor()) |
| 5326 | glVertexAttribDivisorANGLE(0, 0); |
| 5327 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5328 | *simulated = true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5329 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5330 | } |
| 5331 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 5332 | void GLES2DecoderImpl::RestoreStateForAttrib(GLuint attrib) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5333 | const VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5334 | state_.vertex_attrib_manager->GetVertexAttribInfo(attrib); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5335 | const void* ptr = reinterpret_cast<const void*>(info->offset()); |
| 5336 | BufferManager::BufferInfo* buffer_info = info->buffer(); |
| 5337 | glBindBuffer(GL_ARRAY_BUFFER, buffer_info ? buffer_info->service_id() : 0); |
| 5338 | glVertexAttribPointer( |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 5339 | attrib, info->size(), info->type(), info->normalized(), info->gl_stride(), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5340 | ptr); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5341 | if (info->divisor()) |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 5342 | glVertexAttribDivisorANGLE(attrib, info->divisor()); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5343 | glBindBuffer( |
| 5344 | GL_ARRAY_BUFFER, |
| 5345 | state_.bound_array_buffer ? state_.bound_array_buffer->service_id() : 0); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 5346 | |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 5347 | // Never touch vertex attribute 0's state (in particular, never |
| 5348 | // disable it) when running on desktop GL because it will never be |
| 5349 | // re-enabled. |
| 5350 | if (attrib != 0 || |
| 5351 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 5352 | if (info->enabled()) { |
| 5353 | glEnableVertexAttribArray(attrib); |
| 5354 | } else { |
| 5355 | glDisableVertexAttribArray(attrib); |
| 5356 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 5357 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5358 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5359 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5360 | bool GLES2DecoderImpl::SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5361 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5362 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5363 | DCHECK(simulated); |
| 5364 | *simulated = false; |
| 5365 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
| 5366 | return true; |
| 5367 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5368 | if (!state_.vertex_attrib_manager->HaveFixedAttribs()) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5369 | return true; |
| 5370 | } |
| 5371 | |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5372 | PerformanceWarning( |
| 5373 | "GL_FIXED attributes have a signficant performance penalty"); |
| 5374 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5375 | // NOTE: we could be smart and try to check if a buffer is used |
| 5376 | // twice in 2 different attribs, find the overlapping parts and therefore |
| 5377 | // duplicate the minimum amount of data but this whole code path is not meant |
| 5378 | // to be used normally. It's just here to pass that OpenGL ES 2.0 conformance |
| 5379 | // tests so we just add to the buffer attrib used. |
| 5380 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5381 | GLuint elements_needed = 0; |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5382 | const VertexAttribManager::VertexAttribInfoList& infos = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5383 | state_.vertex_attrib_manager->GetEnabledVertexAttribInfos(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5384 | for (VertexAttribManager::VertexAttribInfoList::const_iterator it = |
| 5385 | infos.begin(); it != infos.end(); ++it) { |
| 5386 | const VertexAttribManager::VertexAttribInfo* info = *it; |
| 5387 | const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5388 | state_.current_program->GetAttribInfoByLocation(info->index()); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5389 | GLuint max_accessed = info->MaxVertexAccessed(primcount, |
| 5390 | max_vertex_accessed); |
| 5391 | GLuint num_vertices = max_accessed + 1; |
| 5392 | if (num_vertices == 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5393 | SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5394 | return false; |
| 5395 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5396 | if (attrib_info && |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5397 | info->CanAccess(max_accessed) && |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5398 | info->type() == GL_FIXED) { |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 5399 | uint32 elements_used = 0; |
| 5400 | if (!SafeMultiplyUint32(num_vertices, info->size(), &elements_used) || |
| 5401 | !SafeAddUint32(elements_needed, elements_used, &elements_needed)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5402 | SetGLError( |
| 5403 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5404 | return false; |
| 5405 | } |
| 5406 | } |
| 5407 | } |
| 5408 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 5409 | const uint32 kSizeOfFloat = sizeof(float); // NOLINT |
| 5410 | uint32 size_needed = 0; |
| 5411 | if (!SafeMultiplyUint32(elements_needed, kSizeOfFloat, &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5412 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5413 | SetGLError(GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5414 | return false; |
| 5415 | } |
| 5416 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5417 | CopyRealGLErrorsToWrapper(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5418 | |
| 5419 | glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5420 | if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5421 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5422 | GLenum error = glGetError(); |
| 5423 | if (error != GL_NO_ERROR) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5424 | SetGLError( |
| 5425 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5426 | return false; |
| 5427 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5428 | } |
| 5429 | |
| 5430 | // Copy the elements and convert to float |
| 5431 | GLintptr offset = 0; |
| 5432 | for (VertexAttribManager::VertexAttribInfoList::const_iterator it = |
| 5433 | infos.begin(); it != infos.end(); ++it) { |
| 5434 | const VertexAttribManager::VertexAttribInfo* info = *it; |
| 5435 | const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5436 | state_.current_program->GetAttribInfoByLocation(info->index()); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5437 | GLuint max_accessed = info->MaxVertexAccessed(primcount, |
| 5438 | max_vertex_accessed); |
| 5439 | GLuint num_vertices = max_accessed + 1; |
| 5440 | if (num_vertices == 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5441 | SetGLError(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5442 | return false; |
| 5443 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5444 | if (attrib_info && |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5445 | info->CanAccess(max_accessed) && |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5446 | info->type() == GL_FIXED) { |
| 5447 | int num_elements = info->size() * kSizeOfFloat; |
| 5448 | int size = num_elements * num_vertices; |
| 5449 | scoped_array<float> data(new float[size]); |
| 5450 | const int32* src = reinterpret_cast<const int32 *>( |
| 5451 | info->buffer()->GetRange(info->offset(), size)); |
| 5452 | const int32* end = src + num_elements; |
| 5453 | float* dst = data.get(); |
| 5454 | while (src != end) { |
| 5455 | *dst++ = static_cast<float>(*src++) / 65536.0f; |
| 5456 | } |
| 5457 | glBufferSubData(GL_ARRAY_BUFFER, offset, size, data.get()); |
| 5458 | glVertexAttribPointer( |
| 5459 | info->index(), info->size(), GL_FLOAT, false, 0, |
| 5460 | reinterpret_cast<GLvoid*>(offset)); |
| 5461 | offset += size; |
| 5462 | } |
| 5463 | } |
| 5464 | *simulated = true; |
| 5465 | return true; |
| 5466 | } |
| 5467 | |
| 5468 | void GLES2DecoderImpl::RestoreStateForSimulatedFixedAttribs() { |
| 5469 | // There's no need to call glVertexAttribPointer because we shadow all the |
| 5470 | // settings and passing GL_FIXED to it will not work. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5471 | glBindBuffer( |
| 5472 | GL_ARRAY_BUFFER, |
| 5473 | state_.bound_array_buffer ? state_.bound_array_buffer->service_id() : 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5474 | } |
| 5475 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5476 | error::Error GLES2DecoderImpl::DoDrawArrays( |
| 5477 | const char* function_name, |
| 5478 | bool instanced, |
| 5479 | GLenum mode, |
| 5480 | GLint first, |
| 5481 | GLsizei count, |
| 5482 | GLsizei primcount) { |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 5483 | if (ShouldDeferDraws()) |
| 5484 | return error::kDeferCommandUntilLater; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5485 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 5486 | SetGLErrorInvalidEnum(function_name, mode, "mode"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5487 | return error::kNoError; |
| 5488 | } |
| 5489 | if (count < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5490 | SetGLError(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5491 | return error::kNoError; |
| 5492 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5493 | if (primcount < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5494 | SetGLError(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5495 | return error::kNoError; |
| 5496 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5497 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5498 | return error::kNoError; |
| 5499 | } |
| 5500 | // We have to check this here because the prototype for glDrawArrays |
| 5501 | // is GLint not GLsizei. |
| 5502 | if (first < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5503 | SetGLError(GL_INVALID_VALUE, function_name, "first < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5504 | return error::kNoError; |
| 5505 | } |
| 5506 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5507 | if (count == 0 || (instanced && primcount == 0)) { |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5508 | RenderWarning("Render count or primcount is 0."); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5509 | return error::kNoError; |
| 5510 | } |
| 5511 | |
| 5512 | GLuint max_vertex_accessed = first + count - 1; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5513 | if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5514 | if (!ClearUnclearedTextures()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5515 | SetGLError(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5516 | return error::kNoError; |
| 5517 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5518 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5519 | if (!SimulateAttrib0( |
| 5520 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5521 | return error::kNoError; |
| 5522 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5523 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5524 | if (SimulateFixedAttribs( |
| 5525 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 5526 | primcount)) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5527 | bool textures_set = SetBlackTextureForNonRenderableTextures(); |
| 5528 | ApplyDirtyState(); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5529 | if (!instanced) { |
| 5530 | glDrawArrays(mode, first, count); |
| 5531 | } else { |
| 5532 | glDrawArraysInstancedANGLE(mode, first, count, primcount); |
| 5533 | } |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 5534 | ProcessPendingQueries(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5535 | if (textures_set) { |
| 5536 | RestoreStateForNonRenderableTextures(); |
| 5537 | } |
| 5538 | if (simulated_fixed_attribs) { |
| 5539 | RestoreStateForSimulatedFixedAttribs(); |
| 5540 | } |
| 5541 | } |
| 5542 | if (simulated_attrib_0) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 5543 | RestoreStateForAttrib(0); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5544 | } |
| 5545 | if (WasContextLost()) { |
| 5546 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during DrawArrays."; |
| 5547 | return error::kLostContext; |
| 5548 | } |
| 5549 | } |
| 5550 | return error::kNoError; |
| 5551 | } |
| 5552 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5553 | error::Error GLES2DecoderImpl::HandleDrawArrays( |
| 5554 | uint32 immediate_data_size, const gles2::DrawArrays& c) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5555 | return DoDrawArrays("glDrawArrays", |
| 5556 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5557 | static_cast<GLenum>(c.mode), |
| 5558 | static_cast<GLint>(c.first), |
| 5559 | static_cast<GLsizei>(c.count), |
| 5560 | 0); |
| 5561 | } |
| 5562 | |
| 5563 | error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE( |
| 5564 | uint32 immediate_data_size, const gles2::DrawArraysInstancedANGLE& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 5565 | if (!features().angle_instanced_arrays) { |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5566 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5567 | "glDrawArraysInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5568 | return error::kNoError; |
| 5569 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5570 | return DoDrawArrays("glDrawArraysIntancedANGLE", |
| 5571 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5572 | static_cast<GLenum>(c.mode), |
| 5573 | static_cast<GLint>(c.first), |
| 5574 | static_cast<GLsizei>(c.count), |
| 5575 | static_cast<GLsizei>(c.primcount)); |
| 5576 | } |
| 5577 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5578 | error::Error GLES2DecoderImpl::DoDrawElements( |
| 5579 | const char* function_name, |
| 5580 | bool instanced, |
| 5581 | GLenum mode, |
| 5582 | GLsizei count, |
| 5583 | GLenum type, |
| 5584 | int32 offset, |
| 5585 | GLsizei primcount) { |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 5586 | if (ShouldDeferDraws()) |
| 5587 | return error::kDeferCommandUntilLater; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5588 | if (!state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5589 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5590 | function_name, "No element array buffer bound"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5591 | return error::kNoError; |
| 5592 | } |
| 5593 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5594 | if (count < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5595 | SetGLError(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5596 | return error::kNoError; |
| 5597 | } |
| 5598 | if (offset < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5599 | SetGLError(GL_INVALID_VALUE, function_name, "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5600 | return error::kNoError; |
| 5601 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 5602 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 5603 | SetGLErrorInvalidEnum(function_name, mode, "mode"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5604 | return error::kNoError; |
| 5605 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 5606 | if (!validators_->index_type.IsValid(type)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 5607 | SetGLErrorInvalidEnum(function_name, type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5608 | return error::kNoError; |
| 5609 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5610 | if (primcount < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5611 | SetGLError(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5612 | return error::kNoError; |
| 5613 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5614 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5615 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 5616 | return error::kNoError; |
| 5617 | } |
| 5618 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5619 | if (count == 0 || (instanced && primcount == 0)) { |
[email protected] | 6c788fb7 | 2010-08-26 02:16:31 | [diff] [blame] | 5620 | return error::kNoError; |
| 5621 | } |
| 5622 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5623 | GLuint max_vertex_accessed; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5624 | if (!state_.vertex_attrib_manager->element_array_buffer( |
| 5625 | )->GetMaxValueForRange(offset, count, type, &max_vertex_accessed)) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5626 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5627 | function_name, "range out of bounds for buffer"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5628 | return error::kNoError; |
| 5629 | } |
| 5630 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5631 | if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5632 | if (!ClearUnclearedTextures()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5633 | SetGLError(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5634 | return error::kNoError; |
| 5635 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5636 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5637 | if (!SimulateAttrib0( |
| 5638 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5639 | return error::kNoError; |
| 5640 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5641 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5642 | if (SimulateFixedAttribs( |
| 5643 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 5644 | primcount)) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5645 | bool textures_set = SetBlackTextureForNonRenderableTextures(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5646 | ApplyDirtyState(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5647 | const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5648 | if (!instanced) { |
| 5649 | glDrawElements(mode, count, type, indices); |
| 5650 | } else { |
| 5651 | glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); |
| 5652 | } |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 5653 | ProcessPendingQueries(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 5654 | if (textures_set) { |
| 5655 | RestoreStateForNonRenderableTextures(); |
| 5656 | } |
| 5657 | if (simulated_fixed_attribs) { |
| 5658 | RestoreStateForSimulatedFixedAttribs(); |
| 5659 | } |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 5660 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5661 | if (simulated_attrib_0) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 5662 | RestoreStateForAttrib(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5663 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 5664 | if (WasContextLost()) { |
| 5665 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during DrawElements."; |
| 5666 | return error::kLostContext; |
| 5667 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5668 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5669 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5670 | } |
| 5671 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5672 | error::Error GLES2DecoderImpl::HandleDrawElements( |
| 5673 | uint32 immediate_data_size, const gles2::DrawElements& c) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5674 | return DoDrawElements("glDrawElements", |
| 5675 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5676 | static_cast<GLenum>(c.mode), |
| 5677 | static_cast<GLsizei>(c.count), |
| 5678 | static_cast<GLenum>(c.type), |
| 5679 | static_cast<int32>(c.index_offset), |
| 5680 | 0); |
| 5681 | } |
| 5682 | |
| 5683 | error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE( |
| 5684 | uint32 immediate_data_size, const gles2::DrawElementsInstancedANGLE& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 5685 | if (!features().angle_instanced_arrays) { |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5686 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5687 | "glDrawElementsInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5688 | return error::kNoError; |
| 5689 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5690 | return DoDrawElements("glDrawElementsInstancedANGLE", |
| 5691 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5692 | static_cast<GLenum>(c.mode), |
| 5693 | static_cast<GLsizei>(c.count), |
| 5694 | static_cast<GLenum>(c.type), |
| 5695 | static_cast<int32>(c.index_offset), |
| 5696 | static_cast<GLsizei>(c.primcount)); |
| 5697 | } |
| 5698 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 5699 | GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 5700 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { |
| 5701 | GLuint max_vertex_accessed = 0; |
| 5702 | BufferManager::BufferInfo* info = GetBufferInfo(buffer_id); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5703 | if (!info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5704 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5705 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5706 | "GetMaxValueInBufferCHROMIUM", "unknown buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 5707 | } else { |
| 5708 | if (!info->GetMaxValueForRange(offset, count, type, &max_vertex_accessed)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5709 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 5710 | SetGLError( |
| 5711 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5712 | "GetMaxValueInBufferCHROMIUM", "range out of bounds for buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 5713 | } |
| 5714 | } |
| 5715 | return max_vertex_accessed; |
| 5716 | } |
| 5717 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5718 | // Calls glShaderSource for the various versions of the ShaderSource command. |
| 5719 | // Assumes that data / data_size points to a piece of memory that is in range |
| 5720 | // of whatever context it came from (shared memory, immediate memory, bucket |
| 5721 | // memory.) |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5722 | error::Error GLES2DecoderImpl::ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5723 | GLuint client_id, const char* data, uint32 data_size) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5724 | std::string str(data, data + data_size); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5725 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5726 | client_id, "glShaderSource"); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5727 | if (!info) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5728 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5729 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5730 | // Note: We don't actually call glShaderSource here. We wait until |
| 5731 | // the call to glCompileShader. |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5732 | info->UpdateSource(str.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5733 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5734 | } |
| 5735 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5736 | error::Error GLES2DecoderImpl::HandleShaderSource( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 5737 | uint32 immediate_data_size, const gles2::ShaderSource& c) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5738 | uint32 data_size = c.data_size; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5739 | const char* data = GetSharedMemoryAs<const char*>( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5740 | c.data_shm_id, c.data_shm_offset, data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 5741 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5742 | return error::kOutOfBounds; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5743 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5744 | return ShaderSourceHelper(c.shader, data, data_size); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5745 | } |
| 5746 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5747 | error::Error GLES2DecoderImpl::HandleShaderSourceImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 5748 | uint32 immediate_data_size, const gles2::ShaderSourceImmediate& c) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5749 | uint32 data_size = c.data_size; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5750 | const char* data = GetImmediateDataAs<const char*>( |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5751 | c, data_size, immediate_data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 5752 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5753 | return error::kOutOfBounds; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5754 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5755 | return ShaderSourceHelper(c.shader, data, data_size); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5756 | } |
| 5757 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5758 | error::Error GLES2DecoderImpl::HandleShaderSourceBucket( |
| 5759 | uint32 immediate_data_size, const gles2::ShaderSourceBucket& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5760 | Bucket* bucket = GetBucket(c.data_bucket_id); |
| 5761 | if (!bucket || bucket->size() == 0) { |
| 5762 | return error::kInvalidArguments; |
| 5763 | } |
| 5764 | return ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5765 | c.shader, bucket->GetDataAs<const char*>(0, bucket->size() - 1), |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5766 | bucket->size() - 1); |
| 5767 | } |
| 5768 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5769 | void GLES2DecoderImpl::DoCompileShader(GLuint client_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 5770 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompileShader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5771 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5772 | client_id, "glCompileShader"); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5773 | if (!info) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5774 | return; |
| 5775 | } |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 5776 | ShaderTranslator* translator = NULL; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 5777 | if (use_shader_translator_) { |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 5778 | translator = info->shader_type() == GL_VERTEX_SHADER ? |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 5779 | vertex_translator_.get() : fragment_translator_.get(); |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 5780 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 5781 | |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 5782 | program_manager()->DoCompileShader(info, translator, feature_info_); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5783 | }; |
| 5784 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5785 | void GLES2DecoderImpl::DoGetShaderiv( |
| 5786 | GLuint shader, GLenum pname, GLint* params) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5787 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5788 | shader, "glGetShaderiv"); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5789 | if (!info) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5790 | return; |
| 5791 | } |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5792 | switch (pname) { |
| 5793 | case GL_SHADER_SOURCE_LENGTH: |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5794 | *params = info->source() ? info->source()->size() + 1 : 0; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5795 | return; |
| 5796 | case GL_COMPILE_STATUS: |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 5797 | *params = compile_shader_always_succeeds_ ? true : info->IsValid(); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 5798 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5799 | case GL_INFO_LOG_LENGTH: |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5800 | *params = info->log_info() ? info->log_info()->size() + 1 : 0; |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 5801 | return; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 5802 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
[email protected] | c447acd | 2012-07-23 23:48:41 | [diff] [blame] | 5803 | ForceCompileShaderIfPending(info); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 5804 | *params = info->translated_source() ? |
| 5805 | info->translated_source()->size() + 1 : 0; |
| 5806 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5807 | default: |
| 5808 | break; |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5809 | } |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 5810 | glGetShaderiv(info->service_id(), pname, params); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 5811 | } |
| 5812 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5813 | error::Error GLES2DecoderImpl::HandleGetShaderSource( |
| 5814 | uint32 immediate_data_size, const gles2::GetShaderSource& c) { |
| 5815 | GLuint shader = c.shader; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5816 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 5817 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5818 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5819 | shader, "glGetShaderSource"); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5820 | if (!info || !info->source()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5821 | bucket->SetSize(0); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 5822 | return error::kNoError; |
| 5823 | } |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5824 | bucket->SetFromString(info->source()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5825 | return error::kNoError; |
| 5826 | } |
| 5827 | |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 5828 | error::Error GLES2DecoderImpl::HandleGetTranslatedShaderSourceANGLE( |
| 5829 | uint32 immediate_data_size, |
| 5830 | const gles2::GetTranslatedShaderSourceANGLE& c) { |
| 5831 | GLuint shader = c.shader; |
| 5832 | |
| 5833 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 5834 | Bucket* bucket = CreateBucket(bucket_id); |
| 5835 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5836 | shader, "glTranslatedGetShaderSourceANGLE"); |
| 5837 | if (!info) { |
| 5838 | bucket->SetSize(0); |
| 5839 | return error::kNoError; |
| 5840 | } |
[email protected] | c447acd | 2012-07-23 23:48:41 | [diff] [blame] | 5841 | ForceCompileShaderIfPending(info); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 5842 | |
| 5843 | bucket->SetFromString(info->translated_source() ? |
| 5844 | info->translated_source()->c_str() : NULL); |
| 5845 | return error::kNoError; |
| 5846 | } |
| 5847 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5848 | error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( |
| 5849 | uint32 immediate_data_size, const gles2::GetProgramInfoLog& c) { |
| 5850 | GLuint program = c.program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5851 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 5852 | Bucket* bucket = CreateBucket(bucket_id); |
| 5853 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 5854 | program, "glGetProgramInfoLog"); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5855 | if (!info || !info->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 5856 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5857 | return error::kNoError; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 5858 | } |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5859 | bucket->SetFromString(info->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5860 | return error::kNoError; |
| 5861 | } |
| 5862 | |
| 5863 | error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( |
| 5864 | uint32 immediate_data_size, const gles2::GetShaderInfoLog& c) { |
| 5865 | GLuint shader = c.shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5866 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 5867 | Bucket* bucket = CreateBucket(bucket_id); |
| 5868 | ShaderManager::ShaderInfo* info = GetShaderInfoNotProgram( |
| 5869 | shader, "glGetShaderInfoLog"); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5870 | if (!info || !info->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 5871 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5872 | return error::kNoError; |
| 5873 | } |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 5874 | bucket->SetFromString(info->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5875 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5876 | } |
| 5877 | |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 5878 | bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) { |
| 5879 | return state_.GetEnabled(cap); |
| 5880 | } |
| 5881 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5882 | bool GLES2DecoderImpl::DoIsBuffer(GLuint client_id) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5883 | const BufferManager::BufferInfo* buffer = GetBufferInfo(client_id); |
| 5884 | return buffer && buffer->IsValid() && !buffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5885 | } |
| 5886 | |
| 5887 | bool GLES2DecoderImpl::DoIsFramebuffer(GLuint client_id) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5888 | const FramebufferManager::FramebufferInfo* framebuffer = |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 5889 | GetFramebufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5890 | return framebuffer && framebuffer->IsValid() && !framebuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | bool GLES2DecoderImpl::DoIsProgram(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 5894 | // IsProgram is true for programs as soon as they are created, until they are |
| 5895 | // deleted and no longer in use. |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5896 | const ProgramManager::ProgramInfo* program = GetProgramInfo(client_id); |
| 5897 | return program != NULL && !program->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | bool GLES2DecoderImpl::DoIsRenderbuffer(GLuint client_id) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5901 | const RenderbufferManager::RenderbufferInfo* renderbuffer = |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 5902 | GetRenderbufferInfo(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5903 | return renderbuffer && renderbuffer->IsValid() && !renderbuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5904 | } |
| 5905 | |
| 5906 | bool GLES2DecoderImpl::DoIsShader(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 5907 | // IsShader is true for shaders as soon as they are created, until they |
| 5908 | // are deleted and not attached to any programs. |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5909 | const ShaderManager::ShaderInfo* shader = GetShaderInfo(client_id); |
| 5910 | return shader != NULL && !shader->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5911 | } |
| 5912 | |
| 5913 | bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 5914 | const TextureManager::TextureInfo* texture = GetTextureInfo(client_id); |
| 5915 | return texture && texture->IsValid() && !texture->IsDeleted(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5916 | } |
| 5917 | |
| 5918 | void GLES2DecoderImpl::DoAttachShader( |
| 5919 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5920 | ProgramManager::ProgramInfo* program_info = GetProgramInfoNotShader( |
| 5921 | program_client_id, "glAttachShader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5922 | if (!program_info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5923 | return; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5924 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5925 | ShaderManager::ShaderInfo* shader_info = GetShaderInfoNotProgram( |
| 5926 | shader_client_id, "glAttachShader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5927 | if (!shader_info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5928 | return; |
| 5929 | } |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5930 | if (!program_info->AttachShader(shader_manager(), shader_info)) { |
[email protected] | fb96c8e | 2010-08-12 04:10:31 | [diff] [blame] | 5931 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5932 | "glAttachShader", "can not attach more than" |
[email protected] | fb96c8e | 2010-08-12 04:10:31 | [diff] [blame] | 5933 | " one shader of the same type."); |
| 5934 | return; |
| 5935 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5936 | glAttachShader(program_info->service_id(), shader_info->service_id()); |
| 5937 | } |
| 5938 | |
| 5939 | void GLES2DecoderImpl::DoDetachShader( |
| 5940 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5941 | ProgramManager::ProgramInfo* program_info = GetProgramInfoNotShader( |
| 5942 | program_client_id, "glDetachShader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5943 | if (!program_info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5944 | return; |
| 5945 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5946 | ShaderManager::ShaderInfo* shader_info = GetShaderInfoNotProgram( |
| 5947 | shader_client_id, "glDetachShader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5948 | if (!shader_info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5949 | return; |
| 5950 | } |
[email protected] | 9a0ccd4 | 2011-03-16 23:58:22 | [diff] [blame] | 5951 | if (!program_info->DetachShader(shader_manager(), shader_info)) { |
| 5952 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5953 | "glDetachShader", "shader not attached to program"); |
[email protected] | 9a0ccd4 | 2011-03-16 23:58:22 | [diff] [blame] | 5954 | return; |
| 5955 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5956 | glDetachShader(program_info->service_id(), shader_info->service_id()); |
| 5957 | } |
| 5958 | |
| 5959 | void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5960 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 5961 | program_client_id, "glValidateProgram"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5962 | if (!info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5963 | return; |
| 5964 | } |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 5965 | info->Validate(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 5966 | } |
| 5967 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5968 | void GLES2DecoderImpl::DoGetVertexAttribfv( |
| 5969 | GLuint index, GLenum pname, GLfloat* params) { |
| 5970 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5971 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5972 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5973 | SetGLError(GL_INVALID_VALUE, "glGetVertexAttribfv", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5974 | return; |
| 5975 | } |
| 5976 | switch (pname) { |
| 5977 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { |
| 5978 | BufferManager::BufferInfo* buffer = info->buffer(); |
| 5979 | if (buffer && !buffer->IsDeleted()) { |
| 5980 | GLuint client_id; |
| 5981 | buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
| 5982 | *params = static_cast<GLfloat>(client_id); |
| 5983 | } |
| 5984 | break; |
| 5985 | } |
| 5986 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5987 | *params = static_cast<GLfloat>(info->enabled()); |
| 5988 | break; |
| 5989 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5990 | *params = static_cast<GLfloat>(info->size()); |
| 5991 | break; |
| 5992 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5993 | *params = static_cast<GLfloat>(info->gl_stride()); |
| 5994 | break; |
| 5995 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5996 | *params = static_cast<GLfloat>(info->type()); |
| 5997 | break; |
| 5998 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5999 | *params = static_cast<GLfloat>(info->normalized()); |
| 6000 | break; |
| 6001 | case GL_CURRENT_VERTEX_ATTRIB: |
| 6002 | params[0] = info->value().v[0]; |
| 6003 | params[1] = info->value().v[1]; |
| 6004 | params[2] = info->value().v[2]; |
| 6005 | params[3] = info->value().v[3]; |
| 6006 | break; |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6007 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: |
| 6008 | *params = static_cast<GLfloat>(info->divisor()); |
| 6009 | break; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6010 | default: |
| 6011 | NOTREACHED(); |
| 6012 | break; |
| 6013 | } |
| 6014 | } |
| 6015 | |
| 6016 | void GLES2DecoderImpl::DoGetVertexAttribiv( |
| 6017 | GLuint index, GLenum pname, GLint* params) { |
| 6018 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6019 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6020 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6021 | SetGLError(GL_INVALID_VALUE, "glGetVertexAttribiv", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6022 | return; |
| 6023 | } |
| 6024 | switch (pname) { |
| 6025 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { |
| 6026 | BufferManager::BufferInfo* buffer = info->buffer(); |
| 6027 | if (buffer && !buffer->IsDeleted()) { |
| 6028 | GLuint client_id; |
| 6029 | buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
| 6030 | *params = client_id; |
| 6031 | } |
| 6032 | break; |
| 6033 | } |
| 6034 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 6035 | *params = info->enabled(); |
| 6036 | break; |
| 6037 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 6038 | *params = info->size(); |
| 6039 | break; |
| 6040 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 6041 | *params = info->gl_stride(); |
| 6042 | break; |
| 6043 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 6044 | *params = info->type(); |
| 6045 | break; |
| 6046 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 6047 | *params = static_cast<GLint>(info->normalized()); |
| 6048 | break; |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6049 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: |
| 6050 | *params = info->divisor(); |
| 6051 | break; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6052 | case GL_CURRENT_VERTEX_ATTRIB: |
| 6053 | params[0] = static_cast<GLint>(info->value().v[0]); |
| 6054 | params[1] = static_cast<GLint>(info->value().v[1]); |
| 6055 | params[2] = static_cast<GLint>(info->value().v[2]); |
| 6056 | params[3] = static_cast<GLint>(info->value().v[3]); |
| 6057 | break; |
| 6058 | default: |
| 6059 | NOTREACHED(); |
| 6060 | break; |
| 6061 | } |
| 6062 | } |
| 6063 | |
| 6064 | void GLES2DecoderImpl::DoVertexAttrib1f(GLuint index, GLfloat v0) { |
| 6065 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6066 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6067 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6068 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib1f", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6069 | return; |
| 6070 | } |
| 6071 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 6072 | value.v[0] = v0; |
| 6073 | value.v[1] = 0.0f; |
| 6074 | value.v[2] = 0.0f; |
| 6075 | value.v[3] = 1.0f; |
| 6076 | info->set_value(value); |
| 6077 | glVertexAttrib1f(index, v0); |
| 6078 | } |
| 6079 | |
| 6080 | void GLES2DecoderImpl::DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) { |
| 6081 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6082 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6083 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6084 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib2f", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6085 | return; |
| 6086 | } |
| 6087 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 6088 | value.v[0] = v0; |
| 6089 | value.v[1] = v1; |
| 6090 | value.v[2] = 0.0f; |
| 6091 | value.v[3] = 1.0f; |
| 6092 | info->set_value(value); |
| 6093 | glVertexAttrib2f(index, v0, v1); |
| 6094 | } |
| 6095 | |
| 6096 | void GLES2DecoderImpl::DoVertexAttrib3f( |
| 6097 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) { |
| 6098 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6099 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6100 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6101 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib3f", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6102 | return; |
| 6103 | } |
| 6104 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 6105 | value.v[0] = v0; |
| 6106 | value.v[1] = v1; |
| 6107 | value.v[2] = v2; |
| 6108 | value.v[3] = 1.0f; |
| 6109 | info->set_value(value); |
| 6110 | glVertexAttrib3f(index, v0, v1, v2); |
| 6111 | } |
| 6112 | |
| 6113 | void GLES2DecoderImpl::DoVertexAttrib4f( |
| 6114 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { |
| 6115 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6116 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6117 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6118 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib4f", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6119 | return; |
| 6120 | } |
| 6121 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 6122 | value.v[0] = v0; |
| 6123 | value.v[1] = v1; |
| 6124 | value.v[2] = v2; |
| 6125 | value.v[3] = v3; |
| 6126 | info->set_value(value); |
| 6127 | glVertexAttrib4f(index, v0, v1, v2, v3); |
| 6128 | } |
| 6129 | |
| 6130 | void GLES2DecoderImpl::DoVertexAttrib1fv(GLuint index, const GLfloat* v) { |
| 6131 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6132 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6133 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6134 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib1fv", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6135 | return; |
| 6136 | } |
| 6137 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 6138 | value.v[0] = v[0]; |
| 6139 | value.v[1] = 0.0f; |
| 6140 | value.v[2] = 0.0f; |
| 6141 | value.v[3] = 1.0f; |
| 6142 | info->set_value(value); |
| 6143 | glVertexAttrib1fv(index, v); |
| 6144 | } |
| 6145 | |
| 6146 | void GLES2DecoderImpl::DoVertexAttrib2fv(GLuint index, const GLfloat* v) { |
| 6147 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6148 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6149 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6150 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib2fv", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6151 | return; |
| 6152 | } |
| 6153 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 6154 | value.v[0] = v[0]; |
| 6155 | value.v[1] = v[1]; |
| 6156 | value.v[2] = 0.0f; |
| 6157 | value.v[3] = 1.0f; |
| 6158 | info->set_value(value); |
| 6159 | glVertexAttrib2fv(index, v); |
| 6160 | } |
| 6161 | |
| 6162 | void GLES2DecoderImpl::DoVertexAttrib3fv(GLuint index, const GLfloat* v) { |
| 6163 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6164 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6165 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6166 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib3fv", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6167 | return; |
| 6168 | } |
| 6169 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 6170 | value.v[0] = v[0]; |
| 6171 | value.v[1] = v[1]; |
| 6172 | value.v[2] = v[2]; |
| 6173 | value.v[3] = 1.0f; |
| 6174 | info->set_value(value); |
| 6175 | glVertexAttrib3fv(index, v); |
| 6176 | } |
| 6177 | |
| 6178 | void GLES2DecoderImpl::DoVertexAttrib4fv(GLuint index, const GLfloat* v) { |
| 6179 | VertexAttribManager::VertexAttribInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6180 | state_.vertex_attrib_manager->GetVertexAttribInfo(index); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6181 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6182 | SetGLError(GL_INVALID_VALUE, "glVertexAttrib4fv", "index out of range"); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6183 | return; |
| 6184 | } |
| 6185 | VertexAttribManager::VertexAttribInfo::Vec4 value; |
| 6186 | value.v[0] = v[0]; |
| 6187 | value.v[1] = v[1]; |
| 6188 | value.v[2] = v[2]; |
| 6189 | value.v[3] = v[3]; |
| 6190 | info->set_value(value); |
| 6191 | glVertexAttrib4fv(index, v); |
| 6192 | } |
| 6193 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6194 | error::Error GLES2DecoderImpl::HandleVertexAttribPointer( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6195 | uint32 immediate_data_size, const gles2::VertexAttribPointer& c) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 6196 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6197 | if (!state_.bound_array_buffer || state_.bound_array_buffer->IsDeleted()) { |
| 6198 | if (state_.vertex_attrib_manager == default_vertex_attrib_manager_) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 6199 | SetGLError(GL_INVALID_VALUE, |
| 6200 | "glVertexAttribPointer", "no array buffer bound"); |
| 6201 | return error::kNoError; |
| 6202 | } else if (c.offset != 0) { |
| 6203 | SetGLError(GL_INVALID_VALUE, |
| 6204 | "glVertexAttribPointer", "client side arrays are not allowed"); |
| 6205 | return error::kNoError; |
| 6206 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6207 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6208 | |
| 6209 | GLuint indx = c.indx; |
| 6210 | GLint size = c.size; |
| 6211 | GLenum type = c.type; |
| 6212 | GLboolean normalized = c.normalized; |
| 6213 | GLsizei stride = c.stride; |
| 6214 | GLsizei offset = c.offset; |
| 6215 | const void* ptr = reinterpret_cast<const void*>(offset); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6216 | if (!validators_->vertex_attrib_type.IsValid(type)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 6217 | SetGLErrorInvalidEnum("glVertexAttribPointer", type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6218 | return error::kNoError; |
| 6219 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6220 | if (!validators_->vertex_attrib_size.IsValid(size)) { |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 6221 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6222 | "glVertexAttribPointer", "size GL_INVALID_VALUE"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6223 | return error::kNoError; |
| 6224 | } |
| 6225 | if (indx >= group_->max_vertex_attribs()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6226 | SetGLError(GL_INVALID_VALUE, "glVertexAttribPointer", "index out of range"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6227 | return error::kNoError; |
| 6228 | } |
| 6229 | if (stride < 0) { |
| 6230 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6231 | "glVertexAttribPointer", "stride < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6232 | return error::kNoError; |
| 6233 | } |
| 6234 | if (stride > 255) { |
| 6235 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6236 | "glVertexAttribPointer", "stride > 255"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6237 | return error::kNoError; |
| 6238 | } |
| 6239 | if (offset < 0) { |
| 6240 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6241 | "glVertexAttribPointer", "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6242 | return error::kNoError; |
| 6243 | } |
| 6244 | GLsizei component_size = |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 6245 | GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6246 | if (offset % component_size > 0) { |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 6247 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6248 | "glVertexAttribPointer", "offset not valid for type"); |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 6249 | return error::kNoError; |
| 6250 | } |
| 6251 | if (stride % component_size > 0) { |
| 6252 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6253 | "glVertexAttribPointer", "stride not valid for type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6254 | return error::kNoError; |
| 6255 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6256 | state_.vertex_attrib_manager->SetAttribInfo( |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6257 | indx, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6258 | state_.bound_array_buffer, |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6259 | size, |
| 6260 | type, |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6261 | normalized, |
| 6262 | stride, |
| 6263 | stride != 0 ? stride : component_size * size, |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6264 | offset); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6265 | if (type != GL_FIXED) { |
| 6266 | glVertexAttribPointer(indx, size, type, normalized, stride, ptr); |
| 6267 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6268 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6269 | } |
| 6270 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6271 | void GLES2DecoderImpl::DoViewport(GLint x, GLint y, GLsizei width, |
| 6272 | GLsizei height) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6273 | state_.viewport_x = x; |
| 6274 | state_.viewport_y = y; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6275 | state_.viewport_width = std::min(width, viewport_max_width_); |
| 6276 | state_.viewport_height = std::min(height, viewport_max_height_); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6277 | glViewport(x, y, width, height); |
| 6278 | } |
| 6279 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6280 | error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE( |
| 6281 | uint32 immediate_data_size, const gles2::VertexAttribDivisorANGLE& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6282 | if (!features().angle_instanced_arrays) { |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6283 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6284 | "glVertexAttribDivisorANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6285 | } |
| 6286 | GLuint index = c.index; |
| 6287 | GLuint divisor = c.divisor; |
| 6288 | if (index >= group_->max_vertex_attribs()) { |
| 6289 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6290 | "glVertexAttribDivisorANGLE", "index out of range"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6291 | return error::kNoError; |
| 6292 | } |
| 6293 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6294 | state_.vertex_attrib_manager->SetDivisor( |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6295 | index, |
| 6296 | divisor); |
| 6297 | glVertexAttribDivisorANGLE(index, divisor); |
| 6298 | return error::kNoError; |
| 6299 | } |
| 6300 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6301 | error::Error GLES2DecoderImpl::HandleReadPixels( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6302 | uint32 immediate_data_size, const gles2::ReadPixels& c) { |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 6303 | GLint x = c.x; |
| 6304 | GLint y = c.y; |
| 6305 | GLsizei width = c.width; |
| 6306 | GLsizei height = c.height; |
| 6307 | GLenum format = c.format; |
| 6308 | GLenum type = c.type; |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6309 | if (width < 0 || height < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6310 | SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6311 | return error::kNoError; |
| 6312 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 6313 | typedef gles2::ReadPixels::Result Result; |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 6314 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 6315 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6316 | width, height, format, type, state_.pack_alignment, &pixels_size, |
| 6317 | NULL, NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 6318 | return error::kOutOfBounds; |
| 6319 | } |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 6320 | void* pixels = GetSharedMemoryAs<void*>( |
| 6321 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 6322 | Result* result = GetSharedMemoryAs<Result*>( |
| 6323 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 6324 | if (!pixels || !result) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6325 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6326 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 6327 | |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6328 | if (!validators_->read_pixel_format.IsValid(format)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 6329 | SetGLErrorInvalidEnum("glReadPixels", format, "format"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6330 | return error::kNoError; |
| 6331 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6332 | if (!validators_->pixel_type.IsValid(type)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 6333 | SetGLErrorInvalidEnum("glReadPixels", type, "type"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 6334 | return error::kNoError; |
| 6335 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6336 | if (width == 0 || height == 0) { |
| 6337 | return error::kNoError; |
| 6338 | } |
| 6339 | |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6340 | // Get the size of the current fbo or backbuffer. |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 6341 | gfx::Size max_size = GetBoundReadFrameBufferSize(); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6342 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6343 | int32 max_x; |
| 6344 | int32 max_y; |
| 6345 | if (!SafeAddInt32(x, width, &max_x) || !SafeAddInt32(y, height, &max_y)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6346 | SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6347 | return error::kNoError; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 6348 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6349 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6350 | if (!CheckBoundFramebuffersValid("glReadPixels")) { |
| 6351 | return error::kNoError; |
| 6352 | } |
| 6353 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6354 | CopyRealGLErrorsToWrapper(); |
| 6355 | |
| 6356 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 6357 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 6358 | if (x < 0 || y < 0 || max_x > max_size.width() || max_y > max_size.height()) { |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6359 | // The user requested an out of range area. Get the results 1 line |
| 6360 | // at a time. |
| 6361 | uint32 temp_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 6362 | uint32 unpadded_row_size; |
| 6363 | uint32 padded_row_size; |
| 6364 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6365 | width, 2, format, type, state_.pack_alignment, &temp_size, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 6366 | &unpadded_row_size, &padded_row_size)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6367 | SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6368 | return error::kNoError; |
| 6369 | } |
| 6370 | |
| 6371 | GLint dest_x_offset = std::max(-x, 0); |
| 6372 | uint32 dest_row_offset; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 6373 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6374 | dest_x_offset, 1, format, type, state_.pack_alignment, &dest_row_offset, |
| 6375 | NULL, NULL)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6376 | SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6377 | return error::kNoError; |
| 6378 | } |
| 6379 | |
| 6380 | // Copy each row into the larger dest rect. |
| 6381 | int8* dst = static_cast<int8*>(pixels); |
| 6382 | GLint read_x = std::max(0, x); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 6383 | GLint read_end_x = std::max(0, std::min(max_size.width(), max_x)); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6384 | GLint read_width = read_end_x - read_x; |
| 6385 | for (GLint yy = 0; yy < height; ++yy) { |
| 6386 | GLint ry = y + yy; |
| 6387 | |
| 6388 | // Clear the row. |
| 6389 | memset(dst, 0, unpadded_row_size); |
| 6390 | |
| 6391 | // If the row is in range, copy it. |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 6392 | if (ry >= 0 && ry < max_size.height() && read_width > 0) { |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 6393 | glReadPixels( |
| 6394 | read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
| 6395 | } |
| 6396 | dst += padded_row_size; |
| 6397 | } |
| 6398 | } else { |
| 6399 | glReadPixels(x, y, width, height, format, type, pixels); |
| 6400 | } |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 6401 | GLenum error = PeekGLError(); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 6402 | if (error == GL_NO_ERROR) { |
| 6403 | *result = true; |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 6404 | |
| 6405 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 6406 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
[email protected] | 84eb425 | 2012-06-29 22:56:44 | [diff] [blame] | 6407 | if ((channels_exist & 0x0008) == 0 && |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6408 | workarounds().clear_alpha_in_readpixels) { |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 6409 | // Set the alpha to 255 because some drivers are buggy in this regard. |
| 6410 | uint32 temp_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 6411 | |
| 6412 | uint32 unpadded_row_size; |
| 6413 | uint32 padded_row_size; |
| 6414 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6415 | width, 2, format, type, state_.pack_alignment, &temp_size, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 6416 | &unpadded_row_size, &padded_row_size)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6417 | SetGLError(GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 6418 | return error::kNoError; |
| 6419 | } |
| 6420 | // NOTE: Assumes the type is GL_UNSIGNED_BYTE which was true at the time |
| 6421 | // of this implementation. |
| 6422 | if (type != GL_UNSIGNED_BYTE) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6423 | SetGLError( |
| 6424 | GL_INVALID_OPERATION, "glReadPixels", |
| 6425 | "unsupported readPixel format"); |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 6426 | return error::kNoError; |
| 6427 | } |
| 6428 | switch (format) { |
| 6429 | case GL_RGBA: |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 6430 | case GL_BGRA_EXT: |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 6431 | case GL_ALPHA: { |
| 6432 | int offset = (format == GL_ALPHA) ? 0 : 3; |
| 6433 | int step = (format == GL_ALPHA) ? 1 : 4; |
| 6434 | uint8* dst = static_cast<uint8*>(pixels) + offset; |
| 6435 | for (GLint yy = 0; yy < height; ++yy) { |
| 6436 | uint8* end = dst + unpadded_row_size; |
| 6437 | for (uint8* d = dst; d < end; d += step) { |
| 6438 | *d = 255; |
| 6439 | } |
| 6440 | dst += padded_row_size; |
| 6441 | } |
| 6442 | break; |
| 6443 | } |
| 6444 | default: |
| 6445 | break; |
| 6446 | } |
| 6447 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 6448 | } |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 6449 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6450 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6451 | } |
| 6452 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6453 | error::Error GLES2DecoderImpl::HandlePixelStorei( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6454 | uint32 immediate_data_size, const gles2::PixelStorei& c) { |
| 6455 | GLenum pname = c.pname; |
| 6456 | GLenum param = c.param; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6457 | if (!validators_->pixel_store.IsValid(pname)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 6458 | SetGLErrorInvalidEnum("glPixelStorei", pname, "pname"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 6459 | return error::kNoError; |
| 6460 | } |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 6461 | switch (pname) { |
| 6462 | case GL_PACK_ALIGNMENT: |
| 6463 | case GL_UNPACK_ALIGNMENT: |
| 6464 | if (!validators_->pixel_store_alignment.IsValid(param)) { |
| 6465 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6466 | "glPixelStore", "param GL_INVALID_VALUE"); |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 6467 | return error::kNoError; |
| 6468 | } |
[email protected] | 164d6d5 | 2012-05-05 00:55:03 | [diff] [blame] | 6469 | break; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 6470 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 6471 | unpack_flip_y_ = (param != 0); |
| 6472 | return error::kNoError; |
| 6473 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 6474 | unpack_premultiply_alpha_ = (param != 0); |
| 6475 | return error::kNoError; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 6476 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 6477 | unpack_unpremultiply_alpha_ = (param != 0); |
| 6478 | return error::kNoError; |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 6479 | default: |
| 6480 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6481 | } |
| 6482 | glPixelStorei(pname, param); |
| 6483 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6484 | case GL_PACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6485 | state_.pack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6486 | break; |
| 6487 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 6488 | state_.pack_reverse_row_order = (param != 0); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6489 | break; |
| 6490 | case GL_UNPACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6491 | state_.unpack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6492 | break; |
| 6493 | default: |
| 6494 | // Validation should have prevented us from getting here. |
| 6495 | NOTREACHED(); |
| 6496 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6497 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6498 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6499 | } |
| 6500 | |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 6501 | error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( |
| 6502 | uint32 immediate_data_size, const gles2::PostSubBufferCHROMIUM& c) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 6503 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandlePostSubBufferCHROMIUM"); |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 6504 | if (!surface_->HasExtension("GL_CHROMIUM_post_sub_buffer")) { |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 6505 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6506 | "glPostSubBufferCHROMIUM", "command not supported by surface"); |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 6507 | return error::kNoError; |
| 6508 | } |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 6509 | if (surface_->PostSubBuffer(c.x, c.y, c.width, c.height)) { |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 6510 | return error::kNoError; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 6511 | } else { |
| 6512 | LOG(ERROR) << "Context lost because PostSubBuffer failed."; |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 6513 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 6514 | } |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 6515 | } |
| 6516 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6517 | error::Error GLES2DecoderImpl::GetAttribLocationHelper( |
| 6518 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 6519 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 6520 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6521 | SetGLError(GL_INVALID_VALUE, "glGetAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 6522 | return error::kNoError; |
| 6523 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6524 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 6525 | client_id, "glGetAttribLocation"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6526 | if (!info) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6527 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6528 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6529 | if (!info->IsValid()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6530 | SetGLError( |
| 6531 | GL_INVALID_OPERATION, "glGetAttribLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 6532 | return error::kNoError; |
| 6533 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6534 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6535 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 6536 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6537 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6538 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6539 | // Require the client to init this incase the context is lost and we are no |
| 6540 | // longer executing commands. |
| 6541 | if (*location != -1) { |
| 6542 | return error::kGenericError; |
| 6543 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 6544 | *location = info->GetAttribLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6545 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6546 | } |
| 6547 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6548 | error::Error GLES2DecoderImpl::HandleGetAttribLocation( |
| 6549 | uint32 immediate_data_size, const gles2::GetAttribLocation& c) { |
| 6550 | uint32 name_size = c.data_size; |
| 6551 | const char* name = GetSharedMemoryAs<const char*>( |
| 6552 | c.name_shm_id, c.name_shm_offset, name_size); |
| 6553 | if (!name) { |
| 6554 | return error::kOutOfBounds; |
| 6555 | } |
| 6556 | String name_str(name, name_size); |
| 6557 | return GetAttribLocationHelper( |
| 6558 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 6559 | } |
| 6560 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6561 | error::Error GLES2DecoderImpl::HandleGetAttribLocationImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6562 | uint32 immediate_data_size, const gles2::GetAttribLocationImmediate& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6563 | uint32 name_size = c.data_size; |
| 6564 | const char* name = GetImmediateDataAs<const char*>( |
| 6565 | c, name_size, immediate_data_size); |
| 6566 | if (!name) { |
| 6567 | return error::kOutOfBounds; |
| 6568 | } |
| 6569 | String name_str(name, name_size); |
| 6570 | return GetAttribLocationHelper( |
| 6571 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 6572 | } |
| 6573 | |
| 6574 | error::Error GLES2DecoderImpl::HandleGetAttribLocationBucket( |
| 6575 | uint32 immediate_data_size, const gles2::GetAttribLocationBucket& c) { |
| 6576 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 6577 | if (!bucket) { |
| 6578 | return error::kInvalidArguments; |
| 6579 | } |
| 6580 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 6581 | if (!bucket->GetAsString(&name_str)) { |
| 6582 | return error::kInvalidArguments; |
| 6583 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6584 | return GetAttribLocationHelper( |
| 6585 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 6586 | } |
| 6587 | |
| 6588 | error::Error GLES2DecoderImpl::GetUniformLocationHelper( |
| 6589 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 6590 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 6591 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6592 | SetGLError(GL_INVALID_VALUE, "glGetUniformLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 6593 | return error::kNoError; |
| 6594 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6595 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 6596 | client_id, "glUniformLocation"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6597 | if (!info) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6598 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6599 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6600 | if (!info->IsValid()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6601 | SetGLError( |
| 6602 | GL_INVALID_OPERATION, "glGetUniformLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 6603 | return error::kNoError; |
| 6604 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6605 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6606 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 6607 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6608 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6609 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6610 | // Require the client to init this incase the context is lost an we are no |
| 6611 | // longer executing commands. |
| 6612 | if (*location != -1) { |
| 6613 | return error::kGenericError; |
| 6614 | } |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 6615 | *location = info->GetUniformFakeLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6616 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6617 | } |
| 6618 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6619 | error::Error GLES2DecoderImpl::HandleGetUniformLocation( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6620 | uint32 immediate_data_size, const gles2::GetUniformLocation& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6621 | uint32 name_size = c.data_size; |
| 6622 | const char* name = GetSharedMemoryAs<const char*>( |
| 6623 | c.name_shm_id, c.name_shm_offset, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6624 | if (!name) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6625 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6626 | } |
| 6627 | String name_str(name, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6628 | return GetUniformLocationHelper( |
| 6629 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6630 | } |
| 6631 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6632 | error::Error GLES2DecoderImpl::HandleGetUniformLocationImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6633 | uint32 immediate_data_size, const gles2::GetUniformLocationImmediate& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6634 | uint32 name_size = c.data_size; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6635 | const char* name = GetImmediateDataAs<const char*>( |
| 6636 | c, name_size, immediate_data_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6637 | if (!name) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6638 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6639 | } |
| 6640 | String name_str(name, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6641 | return GetUniformLocationHelper( |
| 6642 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 6643 | } |
| 6644 | |
| 6645 | error::Error GLES2DecoderImpl::HandleGetUniformLocationBucket( |
| 6646 | uint32 immediate_data_size, const gles2::GetUniformLocationBucket& c) { |
| 6647 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 6648 | if (!bucket) { |
| 6649 | return error::kInvalidArguments; |
| 6650 | } |
| 6651 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 6652 | if (!bucket->GetAsString(&name_str)) { |
| 6653 | return error::kInvalidArguments; |
| 6654 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6655 | return GetUniformLocationHelper( |
| 6656 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6657 | } |
| 6658 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6659 | error::Error GLES2DecoderImpl::HandleGetString( |
| 6660 | uint32 immediate_data_size, const gles2::GetString& c) { |
| 6661 | GLenum name = static_cast<GLenum>(c.name); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6662 | if (!validators_->string_type.IsValid(name)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 6663 | SetGLErrorInvalidEnum("glGetString", name, "name"); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6664 | return error::kNoError; |
| 6665 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6666 | const char* gl_str = reinterpret_cast<const char*>(glGetString(name)); |
| 6667 | const char* str = NULL; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 6668 | std::string extensions; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6669 | switch (name) { |
| 6670 | case GL_VERSION: |
| 6671 | str = "OpenGL ES 2.0 Chromium"; |
| 6672 | break; |
| 6673 | case GL_SHADING_LANGUAGE_VERSION: |
| 6674 | str = "OpenGL ES GLSL ES 1.0 Chromium"; |
| 6675 | break; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 6676 | case GL_RENDERER: |
| 6677 | str = "Chromium"; |
| 6678 | break; |
| 6679 | case GL_VENDOR: |
| 6680 | str = "Chromium"; |
| 6681 | break; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6682 | case GL_EXTENSIONS: |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 6683 | { |
| 6684 | // For WebGL contexts, strip out the OES derivatives extension if it has |
| 6685 | // not been enabled. |
| 6686 | if (force_webgl_glsl_validation_ && |
| 6687 | !derivatives_explicitly_enabled_) { |
| 6688 | extensions = feature_info_->extensions(); |
| 6689 | size_t offset = extensions.find(kOESDerivativeExtension); |
| 6690 | if (std::string::npos != offset) { |
| 6691 | extensions.replace(offset, |
| 6692 | offset + arraysize(kOESDerivativeExtension), |
| 6693 | std::string()); |
| 6694 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 6695 | } else { |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 6696 | extensions = feature_info_->extensions().c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 6697 | } |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 6698 | std::string surface_extensions = surface_->GetExtensions(); |
| 6699 | if (!surface_extensions.empty()) |
| 6700 | extensions += " " + surface_extensions; |
| 6701 | str = extensions.c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 6702 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6703 | break; |
| 6704 | default: |
| 6705 | str = gl_str; |
| 6706 | break; |
| 6707 | } |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6708 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6709 | bucket->SetFromString(str); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6710 | return error::kNoError; |
| 6711 | } |
| 6712 | |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6713 | void GLES2DecoderImpl::DoBufferData( |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 6714 | GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage) { |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6715 | if (!validators_->buffer_target.IsValid(target)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 6716 | SetGLErrorInvalidEnum("glBufferData", target, "target"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6717 | return; |
| 6718 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6719 | if (!validators_->buffer_usage.IsValid(usage)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 6720 | SetGLErrorInvalidEnum("glBufferData", usage, "usage"); |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6721 | return; |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6722 | } |
| 6723 | if (size < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6724 | SetGLError(GL_INVALID_VALUE, "glBufferData", "size < 0"); |
[email protected] | 037896bd | 2010-04-21 19:07:28 | [diff] [blame] | 6725 | return; |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6726 | } |
| 6727 | BufferManager::BufferInfo* info = GetBufferInfoForTarget(target); |
| 6728 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6729 | SetGLError(GL_INVALID_VALUE, "glBufferData", "unknown buffer"); |
[email protected] | 037896bd | 2010-04-21 19:07:28 | [diff] [blame] | 6730 | return; |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6731 | } |
| 6732 | // Clear the buffer to 0 if no initial data was passed in. |
| 6733 | scoped_array<int8> zero; |
| 6734 | if (!data) { |
| 6735 | zero.reset(new int8[size]); |
| 6736 | memset(zero.get(), 0, size); |
| 6737 | data = zero.get(); |
| 6738 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6739 | |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6740 | CopyRealGLErrorsToWrapper(); |
| 6741 | glBufferData(target, size, data, usage); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 6742 | GLenum error = PeekGLError(); |
| 6743 | if (error == GL_NO_ERROR) { |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6744 | buffer_manager()->SetInfo(info, size, usage); |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6745 | info->SetRange(0, size, data); |
[email protected] | a3937065 | 2012-09-25 21:52:13 | [diff] [blame] | 6746 | } else { |
| 6747 | buffer_manager()->SetInfo(info, 0, usage); |
[email protected] | 3b6ec20 | 2010-03-05 05:16:23 | [diff] [blame] | 6748 | } |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6749 | } |
| 6750 | |
| 6751 | error::Error GLES2DecoderImpl::HandleBufferData( |
| 6752 | uint32 immediate_data_size, const gles2::BufferData& c) { |
| 6753 | GLenum target = static_cast<GLenum>(c.target); |
| 6754 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
| 6755 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 6756 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 6757 | GLenum usage = static_cast<GLenum>(c.usage); |
| 6758 | const void* data = NULL; |
| 6759 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 6760 | data = GetSharedMemoryAs<const void*>(data_shm_id, data_shm_offset, size); |
| 6761 | if (!data) { |
| 6762 | return error::kOutOfBounds; |
| 6763 | } |
| 6764 | } |
| 6765 | DoBufferData(target, size, data, usage); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6766 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6767 | } |
| 6768 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6769 | error::Error GLES2DecoderImpl::HandleBufferDataImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6770 | uint32 immediate_data_size, const gles2::BufferDataImmediate& c) { |
| 6771 | GLenum target = static_cast<GLenum>(c.target); |
| 6772 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6773 | const void* data = GetImmediateDataAs<const void*>( |
| 6774 | c, size, immediate_data_size); |
| 6775 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6776 | return error::kOutOfBounds; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6777 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6778 | GLenum usage = static_cast<GLenum>(c.usage); |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6779 | DoBufferData(target, size, data, usage); |
| 6780 | return error::kNoError; |
| 6781 | } |
| 6782 | |
| 6783 | void GLES2DecoderImpl::DoBufferSubData( |
| 6784 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6785 | BufferManager::BufferInfo* info = GetBufferInfoForTarget(target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6786 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6787 | SetGLError(GL_INVALID_VALUE, "glBufferSubData", "unknown buffer"); |
[email protected] | 037896bd | 2010-04-21 19:07:28 | [diff] [blame] | 6788 | return; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6789 | } |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 6790 | if (!info->SetRange(offset, size, data)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6791 | SetGLError(GL_INVALID_VALUE, "glBufferSubData", "out of range"); |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6792 | return; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6793 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 6794 | glBufferSubData(target, offset, size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 6795 | } |
| 6796 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6797 | bool GLES2DecoderImpl::ClearLevel( |
| 6798 | unsigned service_id, |
| 6799 | unsigned bind_target, |
| 6800 | unsigned target, |
| 6801 | int level, |
| 6802 | unsigned format, |
| 6803 | unsigned type, |
| 6804 | int width, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6805 | int height, |
| 6806 | bool is_texture_immutable) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 6807 | uint32 channels = GLES2Util::GetChannelsForFormat(format); |
| 6808 | if (IsAngle() && (channels & GLES2Util::kDepth) != 0) { |
| 6809 | // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D |
| 6810 | // on depth formats. |
| 6811 | GLuint fb = 0; |
| 6812 | glGenFramebuffersEXT(1, &fb); |
| 6813 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); |
| 6814 | |
| 6815 | bool have_stencil = (channels & GLES2Util::kStencil) != 0; |
| 6816 | GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : |
| 6817 | GL_DEPTH_ATTACHMENT; |
| 6818 | |
| 6819 | glFramebufferTexture2DEXT( |
| 6820 | GL_DRAW_FRAMEBUFFER_EXT, attachment, target, service_id, level); |
| 6821 | // ANGLE promises a depth only attachment ok. |
| 6822 | if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != |
| 6823 | GL_FRAMEBUFFER_COMPLETE) { |
| 6824 | return false; |
| 6825 | } |
| 6826 | glClearStencil(0); |
| 6827 | glStencilMask(-1); |
| 6828 | glClearDepth(1.0f); |
| 6829 | glDepthMask(true); |
| 6830 | glDisable(GL_SCISSOR_TEST); |
| 6831 | glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); |
| 6832 | |
| 6833 | RestoreClearState(); |
| 6834 | |
| 6835 | glDeleteFramebuffersEXT(1, &fb); |
| 6836 | FramebufferManager::FramebufferInfo* framebuffer = |
| 6837 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 6838 | GLuint fb_service_id = |
| 6839 | framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); |
| 6840 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); |
| 6841 | return true; |
| 6842 | } |
| 6843 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 6844 | static const uint32 kMaxZeroSize = 1024 * 1024 * 4; |
| 6845 | |
| 6846 | uint32 size; |
| 6847 | uint32 padded_row_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 6848 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6849 | width, height, format, type, state_.unpack_alignment, &size, |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 6850 | NULL, &padded_row_size)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6851 | return false; |
| 6852 | } |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 6853 | |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 6854 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearLevel", "size", size); |
| 6855 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 6856 | int tile_height; |
| 6857 | |
| 6858 | if (size > kMaxZeroSize) { |
| 6859 | if (kMaxZeroSize < padded_row_size) { |
| 6860 | // That'd be an awfully large texture. |
| 6861 | return false; |
| 6862 | } |
| 6863 | // We should never have a large total size with a zero row size. |
| 6864 | DCHECK_GT(padded_row_size, 0U); |
| 6865 | tile_height = kMaxZeroSize / padded_row_size; |
| 6866 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6867 | width, tile_height, format, type, state_.unpack_alignment, &size, |
| 6868 | NULL, NULL)) { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 6869 | return false; |
| 6870 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6871 | } else { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 6872 | tile_height = height; |
| 6873 | } |
| 6874 | |
| 6875 | // Assumes the size has already been checked. |
| 6876 | scoped_array<char> zero(new char[size]); |
| 6877 | memset(zero.get(), 0, size); |
| 6878 | glBindTexture(bind_target, service_id); |
| 6879 | |
| 6880 | GLint y = 0; |
| 6881 | while (y < height) { |
| 6882 | GLint h = y + tile_height > height ? height - y : tile_height; |
| 6883 | if (is_texture_immutable || h != height) { |
| 6884 | glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); |
| 6885 | } else { |
| 6886 | WrappedTexImage2D( |
| 6887 | target, level, format, width, h, 0, format, type, zero.get()); |
| 6888 | } |
| 6889 | y += tile_height; |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 6890 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6891 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(bind_target); |
| 6892 | glBindTexture(bind_target, info ? info->service_id() : 0); |
| 6893 | return true; |
| 6894 | } |
| 6895 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6896 | namespace { |
| 6897 | |
| 6898 | const int kS3TCBlockWidth = 4; |
| 6899 | const int kS3TCBlockHeight = 4; |
| 6900 | const int kS3TCDXT1BlockSize = 8; |
| 6901 | const int kS3TCDXT3AndDXT5BlockSize = 16; |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 6902 | const int kETC1BlockWidth = 4; |
| 6903 | const int kETC1BlockHeight = 4; |
| 6904 | const int kETC1BlockSize = 8; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6905 | |
| 6906 | bool IsValidDXTSize(GLint level, GLsizei size) { |
[email protected] | 10b56de | 2012-07-14 02:09:51 | [diff] [blame] | 6907 | return (size == 1) || |
| 6908 | (size == 2) || !(size % kS3TCBlockWidth); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6909 | } |
| 6910 | |
| 6911 | } // anonymous namespace. |
| 6912 | |
| 6913 | bool GLES2DecoderImpl::ValidateCompressedTexFuncData( |
| 6914 | const char* function_name, |
| 6915 | GLsizei width, GLsizei height, GLenum format, size_t size) { |
| 6916 | unsigned int bytes_required = 0; |
| 6917 | |
| 6918 | switch (format) { |
| 6919 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 6920 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: { |
| 6921 | int num_blocks_across = |
| 6922 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 6923 | int num_blocks_down = |
| 6924 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 6925 | int num_blocks = num_blocks_across * num_blocks_down; |
| 6926 | bytes_required = num_blocks * kS3TCDXT1BlockSize; |
| 6927 | break; |
| 6928 | } |
| 6929 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 6930 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 6931 | int num_blocks_across = |
| 6932 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 6933 | int num_blocks_down = |
| 6934 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 6935 | int num_blocks = num_blocks_across * num_blocks_down; |
| 6936 | bytes_required = num_blocks * kS3TCDXT3AndDXT5BlockSize; |
| 6937 | break; |
| 6938 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 6939 | case GL_ETC1_RGB8_OES: { |
| 6940 | int num_blocks_across = |
| 6941 | (width + kETC1BlockWidth - 1) / kETC1BlockWidth; |
| 6942 | int num_blocks_down = |
| 6943 | (height + kETC1BlockHeight - 1) / kETC1BlockHeight; |
| 6944 | int num_blocks = num_blocks_across * num_blocks_down; |
| 6945 | bytes_required = num_blocks * kETC1BlockSize; |
| 6946 | break; |
| 6947 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6948 | default: |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 6949 | SetGLErrorInvalidEnum(function_name, format, "format"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6950 | return false; |
| 6951 | } |
| 6952 | |
| 6953 | if (size != bytes_required) { |
| 6954 | SetGLError( |
| 6955 | GL_INVALID_VALUE, function_name, "size is not correct for dimensions"); |
| 6956 | return false; |
| 6957 | } |
| 6958 | |
| 6959 | return true; |
| 6960 | } |
| 6961 | |
| 6962 | bool GLES2DecoderImpl::ValidateCompressedTexDimensions( |
| 6963 | const char* function_name, |
| 6964 | GLint level, GLsizei width, GLsizei height, GLenum format) { |
| 6965 | switch (format) { |
| 6966 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 6967 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 6968 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 6969 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 6970 | if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { |
| 6971 | SetGLError( |
| 6972 | GL_INVALID_OPERATION, function_name, |
| 6973 | "width or height invalid for level"); |
| 6974 | return false; |
| 6975 | } |
| 6976 | return true; |
| 6977 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 6978 | case GL_ETC1_RGB8_OES: |
| 6979 | if (width <= 0 || height <= 0) { |
| 6980 | SetGLError( |
| 6981 | GL_INVALID_OPERATION, function_name, |
| 6982 | "width or height invalid for level"); |
| 6983 | return false; |
| 6984 | } |
| 6985 | return true; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6986 | default: |
| 6987 | return false; |
| 6988 | } |
| 6989 | } |
| 6990 | |
| 6991 | bool GLES2DecoderImpl::ValidateCompressedTexSubDimensions( |
| 6992 | const char* function_name, |
| 6993 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 6994 | GLsizei width, GLsizei height, GLenum format, |
| 6995 | TextureManager::TextureInfo* texture) { |
| 6996 | if (xoffset < 0 || yoffset < 0) { |
| 6997 | SetGLError( |
| 6998 | GL_INVALID_VALUE, function_name, "xoffset or yoffset < 0"); |
| 6999 | return false; |
| 7000 | } |
| 7001 | |
| 7002 | switch (format) { |
| 7003 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 7004 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 7005 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 7006 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 7007 | const int kBlockWidth = 4; |
| 7008 | const int kBlockHeight = 4; |
| 7009 | if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) { |
| 7010 | SetGLError( |
| 7011 | GL_INVALID_OPERATION, function_name, |
| 7012 | "xoffset or yoffset not multiple of 4"); |
| 7013 | return false; |
| 7014 | } |
| 7015 | GLsizei tex_width = 0; |
| 7016 | GLsizei tex_height = 0; |
| 7017 | if (!texture->GetLevelSize(target, level, &tex_width, &tex_height) || |
| 7018 | width - xoffset > tex_width || |
| 7019 | height - yoffset > tex_height) { |
| 7020 | SetGLError( |
| 7021 | GL_INVALID_OPERATION, function_name, "dimensions out of range"); |
| 7022 | return false; |
| 7023 | } |
| 7024 | return ValidateCompressedTexDimensions( |
| 7025 | function_name, level, width, height, format); |
| 7026 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7027 | case GL_ETC1_RGB8_OES: { |
| 7028 | SetGLError( |
| 7029 | GL_INVALID_OPERATION, function_name, |
| 7030 | "TexsubImage2d not supported for ECT1_RGB8_OES textures"); |
| 7031 | return false; |
| 7032 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7033 | default: |
| 7034 | return false; |
| 7035 | } |
| 7036 | } |
| 7037 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7038 | error::Error GLES2DecoderImpl::DoCompressedTexImage2D( |
| 7039 | GLenum target, |
| 7040 | GLint level, |
| 7041 | GLenum internal_format, |
| 7042 | GLsizei width, |
| 7043 | GLsizei height, |
| 7044 | GLint border, |
| 7045 | GLsizei image_size, |
| 7046 | const void* data) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7047 | // TODO(gman): Validate image_size is correct for width, height and format. |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7048 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7049 | SetGLErrorInvalidEnum("glCompressedTexImage2D", target, "target"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7050 | return error::kNoError; |
| 7051 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7052 | if (!validators_->compressed_texture_format.IsValid( |
| 7053 | internal_format)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7054 | SetGLErrorInvalidEnum( |
| 7055 | "glCompressedTexImage2D", internal_format, "internal_format"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7056 | return error::kNoError; |
| 7057 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7058 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7059 | border != 0) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7060 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7061 | "glCompressedTexImage2D", "dimensions out of range"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7062 | return error::kNoError; |
| 7063 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 7064 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7065 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7066 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7067 | "glCompressedTexImage2D", "unknown texture target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7068 | return error::kNoError; |
| 7069 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 7070 | if (info->IsImmutable()) { |
| 7071 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7072 | "glCompressedTexImage2D", "texture is immutable"); |
| 7073 | return error::kNoError; |
| 7074 | } |
| 7075 | |
| 7076 | if (!ValidateCompressedTexDimensions( |
| 7077 | "glCompressedTexImage2D", level, width, height, internal_format) || |
| 7078 | !ValidateCompressedTexFuncData( |
| 7079 | "glCompressedTexImage2D", width, height, internal_format, image_size)) { |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 7080 | return error::kNoError; |
| 7081 | } |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 7082 | |
| 7083 | if (info->IsAttachedToFramebuffer()) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 7084 | clear_state_dirty_ = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 7085 | // TODO(gman): If textures tracked which framebuffers they were attached to |
| 7086 | // we could just mark those framebuffers as not complete. |
| 7087 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
| 7088 | } |
| 7089 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7090 | scoped_array<int8> zero; |
| 7091 | if (!data) { |
| 7092 | zero.reset(new int8[image_size]); |
| 7093 | memset(zero.get(), 0, image_size); |
| 7094 | data = zero.get(); |
| 7095 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7096 | CopyRealGLErrorsToWrapper(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7097 | glCompressedTexImage2D( |
| 7098 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 7099 | GLenum error = PeekGLError(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7100 | if (error == GL_NO_ERROR) { |
| 7101 | texture_manager()->SetLevelInfo( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7102 | info, target, level, internal_format, width, height, 1, border, 0, 0, |
| 7103 | true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7104 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7105 | return error::kNoError; |
| 7106 | } |
| 7107 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7108 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7109 | uint32 immediate_data_size, const gles2::CompressedTexImage2D& c) { |
| 7110 | GLenum target = static_cast<GLenum>(c.target); |
| 7111 | GLint level = static_cast<GLint>(c.level); |
| 7112 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 7113 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7114 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7115 | GLint border = static_cast<GLint>(c.border); |
| 7116 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
| 7117 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 7118 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 7119 | const void* data = NULL; |
| 7120 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 7121 | data = GetSharedMemoryAs<const void*>( |
| 7122 | data_shm_id, data_shm_offset, image_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7123 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7124 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7125 | } |
| 7126 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7127 | return DoCompressedTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7128 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7129 | } |
| 7130 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7131 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2DImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7132 | uint32 immediate_data_size, const gles2::CompressedTexImage2DImmediate& c) { |
| 7133 | GLenum target = static_cast<GLenum>(c.target); |
| 7134 | GLint level = static_cast<GLint>(c.level); |
| 7135 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 7136 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7137 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7138 | GLint border = static_cast<GLint>(c.border); |
| 7139 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 7140 | const void* data = GetImmediateDataAs<const void*>( |
| 7141 | c, image_size, immediate_data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7142 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7143 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7144 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7145 | return DoCompressedTexImage2D( |
| 7146 | target, level, internal_format, width, height, border, image_size, data); |
| 7147 | } |
| 7148 | |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7149 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2DBucket( |
| 7150 | uint32 immediate_data_size, const gles2::CompressedTexImage2DBucket& c) { |
| 7151 | GLenum target = static_cast<GLenum>(c.target); |
| 7152 | GLint level = static_cast<GLint>(c.level); |
| 7153 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 7154 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7155 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7156 | GLint border = static_cast<GLint>(c.border); |
| 7157 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7158 | if (!bucket) { |
| 7159 | return error::kInvalidArguments; |
| 7160 | } |
| 7161 | uint32 data_size = bucket->size(); |
| 7162 | GLsizei imageSize = data_size; |
| 7163 | const void* data = bucket->GetData(0, data_size); |
| 7164 | if (!data) { |
| 7165 | return error::kInvalidArguments; |
| 7166 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7167 | return DoCompressedTexImage2D( |
| 7168 | target, level, internal_format, width, height, border, |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7169 | imageSize, data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7170 | } |
| 7171 | |
| 7172 | error::Error GLES2DecoderImpl::HandleCompressedTexSubImage2DBucket( |
| 7173 | uint32 immediate_data_size, |
| 7174 | const gles2::CompressedTexSubImage2DBucket& c) { |
| 7175 | GLenum target = static_cast<GLenum>(c.target); |
| 7176 | GLint level = static_cast<GLint>(c.level); |
| 7177 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 7178 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 7179 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7180 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7181 | GLenum format = static_cast<GLenum>(c.format); |
| 7182 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7183 | if (!bucket) { |
| 7184 | return error::kInvalidArguments; |
| 7185 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7186 | uint32 data_size = bucket->size(); |
| 7187 | GLsizei imageSize = data_size; |
| 7188 | const void* data = bucket->GetData(0, data_size); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7189 | if (!data) { |
| 7190 | return error::kInvalidArguments; |
| 7191 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7192 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7193 | SetGLError( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7194 | GL_INVALID_ENUM, "glCompressedTexSubImage2D", "target"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7195 | return error::kNoError; |
| 7196 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7197 | if (!validators_->compressed_texture_format.IsValid(format)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7198 | SetGLErrorInvalidEnum("glCompressedTexSubImage2D", format, "format"); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7199 | return error::kNoError; |
| 7200 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7201 | if (width < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7202 | SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", "width < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7203 | return error::kNoError; |
| 7204 | } |
| 7205 | if (height < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7206 | SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", "height < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7207 | return error::kNoError; |
| 7208 | } |
| 7209 | if (imageSize < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7210 | SetGLError(GL_INVALID_VALUE, "glCompressedTexSubImage2D", "imageSize < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7211 | return error::kNoError; |
| 7212 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7213 | DoCompressedTexSubImage2D( |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7214 | target, level, xoffset, yoffset, width, height, format, imageSize, data); |
| 7215 | return error::kNoError; |
| 7216 | } |
| 7217 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7218 | bool GLES2DecoderImpl::ValidateTextureParameters( |
| 7219 | const char* function_name, |
| 7220 | GLenum target, GLenum format, GLenum type, GLint level) { |
| 7221 | if (!feature_info_->GetTextureFormatValidator(format).IsValid(type)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7222 | SetGLError(GL_INVALID_OPERATION, function_name, |
| 7223 | (std::string("invalid type ") + |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7224 | GLES2Util::GetStringEnum(type) + " for format " + |
| 7225 | GLES2Util::GetStringEnum(format)).c_str()); |
| 7226 | return false; |
| 7227 | } |
| 7228 | |
| 7229 | uint32 channels = GLES2Util::GetChannelsForFormat(format); |
| 7230 | if ((channels & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && level) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7231 | SetGLError(GL_INVALID_OPERATION, function_name, |
| 7232 | (std::string("invalid type ") + |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7233 | GLES2Util::GetStringEnum(type) + " for format " + |
| 7234 | GLES2Util::GetStringEnum(format)).c_str()); |
| 7235 | return false; |
| 7236 | } |
| 7237 | return true; |
| 7238 | } |
| 7239 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7240 | error::Error GLES2DecoderImpl::DoTexImage2D( |
| 7241 | GLenum target, |
| 7242 | GLint level, |
| 7243 | GLenum internal_format, |
| 7244 | GLsizei width, |
| 7245 | GLsizei height, |
| 7246 | GLint border, |
| 7247 | GLenum format, |
| 7248 | GLenum type, |
| 7249 | const void* pixels, |
| 7250 | uint32 pixels_size) { |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7251 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7252 | SetGLErrorInvalidEnum("glTexImage2D", target, "target"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7253 | return error::kNoError; |
| 7254 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7255 | if (!validators_->texture_format.IsValid(internal_format)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7256 | SetGLErrorInvalidEnum("glTexImage2D", internal_format, "internal_format"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7257 | return error::kNoError; |
| 7258 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7259 | if (!validators_->texture_format.IsValid(format)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7260 | SetGLErrorInvalidEnum("glTexImage2D", format, "format"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7261 | return error::kNoError; |
| 7262 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7263 | if (!validators_->pixel_type.IsValid(type)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7264 | SetGLErrorInvalidEnum("glTexImage2D", type, "type"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7265 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7266 | } |
[email protected] | 7b92c41 | 2010-07-20 17:48:25 | [diff] [blame] | 7267 | if (format != internal_format) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7268 | SetGLError(GL_INVALID_OPERATION, |
| 7269 | "glTexImage2D", "format != internalFormat"); |
[email protected] | 7b92c41 | 2010-07-20 17:48:25 | [diff] [blame] | 7270 | return error::kNoError; |
| 7271 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7272 | if (!ValidateTextureParameters("glTexImage2D", target, format, type, level)) { |
| 7273 | return error::kNoError; |
| 7274 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7275 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7276 | border != 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7277 | SetGLError(GL_INVALID_VALUE, "glTexImage2D", "dimensions out of range"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7278 | return error::kNoError; |
| 7279 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7280 | if ((GLES2Util::GetChannelsForFormat(format) & |
| 7281 | (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && pixels) { |
| 7282 | SetGLError( |
| 7283 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7284 | "glTexImage2D", "can not supply data for depth or stencil textures"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7285 | return error::kNoError; |
| 7286 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 7287 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7288 | if (!info) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7289 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7290 | "glTexImage2D", "unknown texture for target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7291 | return error::kNoError; |
| 7292 | } |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 7293 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 7294 | if (info->IsImmutable()) { |
| 7295 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7296 | "glTexImage2D", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 7297 | return error::kNoError; |
| 7298 | } |
| 7299 | |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 7300 | GLsizei tex_width = 0; |
| 7301 | GLsizei tex_height = 0; |
| 7302 | GLenum tex_type = 0; |
| 7303 | GLenum tex_format = 0; |
| 7304 | bool level_is_same = |
| 7305 | info->GetLevelSize(target, level, &tex_width, &tex_height) && |
| 7306 | info->GetLevelType(target, level, &tex_type, &tex_format) && |
| 7307 | width == tex_width && height == tex_height && |
| 7308 | type == tex_type && format == tex_format; |
| 7309 | |
| 7310 | if (level_is_same && !pixels) { |
[email protected] | 1bed622 | 2011-12-21 11:21:39 | [diff] [blame] | 7311 | // Just set the level info but mark the texture as uncleared. |
| 7312 | texture_manager()->SetLevelInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7313 | info, |
[email protected] | 1bed622 | 2011-12-21 11:21:39 | [diff] [blame] | 7314 | target, level, internal_format, width, height, 1, border, format, type, |
| 7315 | false); |
[email protected] | ea72ed22 | 2011-08-17 18:58:43 | [diff] [blame] | 7316 | tex_image_2d_failed_ = false; |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 7317 | return error::kNoError; |
| 7318 | } |
| 7319 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 7320 | if (info->IsAttachedToFramebuffer()) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 7321 | clear_state_dirty_ = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 7322 | // TODO(gman): If textures tracked which framebuffers they were attached to |
| 7323 | // we could just mark those framebuffers as not complete. |
| 7324 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 7325 | } |
| 7326 | |
[email protected] | 1bed622 | 2011-12-21 11:21:39 | [diff] [blame] | 7327 | if (!teximage2d_faster_than_texsubimage2d_ && level_is_same && pixels) { |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 7328 | glTexSubImage2D(target, level, 0, 0, width, height, format, type, pixels); |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 7329 | texture_manager()->SetLevelCleared(info, target, level); |
[email protected] | 0226c11 | 2011-07-22 03:25:07 | [diff] [blame] | 7330 | tex_image_2d_failed_ = false; |
| 7331 | return error::kNoError; |
[email protected] | 7488d96 | 2010-07-16 02:41:58 | [diff] [blame] | 7332 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 7333 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7334 | CopyRealGLErrorsToWrapper(); |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 7335 | WrappedTexImage2D( |
| 7336 | target, level, internal_format, width, height, border, format, type, |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7337 | pixels); |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 7338 | GLenum error = PeekGLError(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7339 | if (error == GL_NO_ERROR) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7340 | texture_manager()->SetLevelInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7341 | info, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7342 | target, level, internal_format, width, height, 1, border, format, type, |
| 7343 | pixels != NULL); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7344 | tex_image_2d_failed_ = false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7345 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7346 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7347 | } |
| 7348 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7349 | error::Error GLES2DecoderImpl::HandleTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7350 | uint32 immediate_data_size, const gles2::TexImage2D& c) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 7351 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7352 | tex_image_2d_failed_ = true; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7353 | GLenum target = static_cast<GLenum>(c.target); |
| 7354 | GLint level = static_cast<GLint>(c.level); |
| 7355 | GLint internal_format = static_cast<GLint>(c.internalformat); |
| 7356 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7357 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7358 | GLint border = static_cast<GLint>(c.border); |
| 7359 | GLenum format = static_cast<GLenum>(c.format); |
| 7360 | GLenum type = static_cast<GLenum>(c.type); |
| 7361 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 7362 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7363 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7364 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7365 | width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7366 | NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7367 | return error::kOutOfBounds; |
| 7368 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7369 | const void* pixels = NULL; |
| 7370 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 7371 | pixels = GetSharedMemoryAs<const void*>( |
| 7372 | pixels_shm_id, pixels_shm_offset, pixels_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7373 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7374 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7375 | } |
| 7376 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7377 | return DoTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7378 | target, level, internal_format, width, height, border, format, type, |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7379 | pixels, pixels_size); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7380 | } |
| 7381 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7382 | error::Error GLES2DecoderImpl::HandleTexImage2DImmediate( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7383 | uint32 immediate_data_size, const gles2::TexImage2DImmediate& c) { |
| 7384 | GLenum target = static_cast<GLenum>(c.target); |
| 7385 | GLint level = static_cast<GLint>(c.level); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7386 | GLint internal_format = static_cast<GLint>(c.internalformat); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7387 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7388 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7389 | GLint border = static_cast<GLint>(c.border); |
| 7390 | GLenum format = static_cast<GLenum>(c.format); |
| 7391 | GLenum type = static_cast<GLenum>(c.type); |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7392 | uint32 size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7393 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7394 | width, height, format, type, state_.unpack_alignment, &size, |
| 7395 | NULL, NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7396 | return error::kOutOfBounds; |
| 7397 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 7398 | const void* pixels = GetImmediateDataAs<const void*>( |
| 7399 | c, size, immediate_data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7400 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7401 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7402 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7403 | DoTexImage2D( |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7404 | target, level, internal_format, width, height, border, format, type, |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7405 | pixels, size); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7406 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7407 | } |
| 7408 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7409 | void GLES2DecoderImpl::DoCompressedTexSubImage2D( |
| 7410 | GLenum target, |
| 7411 | GLint level, |
| 7412 | GLint xoffset, |
| 7413 | GLint yoffset, |
| 7414 | GLsizei width, |
| 7415 | GLsizei height, |
| 7416 | GLenum format, |
| 7417 | GLsizei image_size, |
| 7418 | const void * data) { |
| 7419 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 7420 | if (!info) { |
| 7421 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7422 | "glCompressedTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7423 | return; |
| 7424 | } |
| 7425 | GLenum type = 0; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7426 | GLenum internal_format = 0; |
| 7427 | if (!info->GetLevelType(target, level, &type, &internal_format)) { |
| 7428 | SetGLError( |
| 7429 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7430 | "glCompressedTexSubImage2D", "level does not exist."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7431 | return; |
| 7432 | } |
| 7433 | if (internal_format != format) { |
| 7434 | SetGLError( |
| 7435 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7436 | "glCompressedTexSubImage2D", "format does not match internal format."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7437 | return; |
| 7438 | } |
| 7439 | if (!info->ValidForTexture( |
| 7440 | target, level, xoffset, yoffset, width, height, format, type)) { |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7441 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7442 | "glCompressedTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7443 | return; |
| 7444 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7445 | |
| 7446 | if (!ValidateCompressedTexFuncData( |
| 7447 | "glCompressedTexSubImage2D", width, height, format, image_size) || |
| 7448 | !ValidateCompressedTexSubDimensions( |
| 7449 | "glCompressedTexSubImage2D", |
| 7450 | target, level, xoffset, yoffset, width, height, format, info)) { |
| 7451 | return; |
| 7452 | } |
| 7453 | |
| 7454 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7455 | // Note: There is no need to deal with texture cleared tracking here |
| 7456 | // because the validation above means you can only get here if the level |
| 7457 | // is already a matching compressed format and in that case |
| 7458 | // CompressedTexImage2D already cleared the texture. |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7459 | glCompressedTexSubImage2D( |
| 7460 | target, level, xoffset, yoffset, width, height, format, image_size, data); |
| 7461 | } |
| 7462 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7463 | static void Clip( |
| 7464 | GLint start, GLint range, GLint sourceRange, |
| 7465 | GLint* out_start, GLint* out_range) { |
| 7466 | DCHECK(out_start); |
| 7467 | DCHECK(out_range); |
| 7468 | if (start < 0) { |
| 7469 | range += start; |
| 7470 | start = 0; |
| 7471 | } |
| 7472 | GLint end = start + range; |
| 7473 | if (end > sourceRange) { |
| 7474 | range -= end - sourceRange; |
| 7475 | } |
| 7476 | *out_start = start; |
| 7477 | *out_range = range; |
| 7478 | } |
| 7479 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7480 | void GLES2DecoderImpl::DoCopyTexImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 7481 | GLenum target, |
| 7482 | GLint level, |
| 7483 | GLenum internal_format, |
| 7484 | GLint x, |
| 7485 | GLint y, |
| 7486 | GLsizei width, |
| 7487 | GLsizei height, |
| 7488 | GLint border) { |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7489 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 7490 | if (!info) { |
| 7491 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7492 | "glCopyTexImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7493 | return; |
| 7494 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 7495 | if (info->IsImmutable()) { |
| 7496 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7497 | "glCopyTexImage2D", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 7498 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7499 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 7500 | border != 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7501 | SetGLError(GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range"); |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 7502 | return; |
| 7503 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7504 | if (!ValidateTextureParameters( |
| 7505 | "glCopyTexImage2D", target, internal_format, GL_UNSIGNED_BYTE, level)) { |
| 7506 | return; |
| 7507 | } |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 7508 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 7509 | // Check we have compatible formats. |
| 7510 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 7511 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 7512 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); |
| 7513 | |
| 7514 | if ((channels_needed & channels_exist) != channels_needed) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7515 | SetGLError(GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 7516 | return; |
| 7517 | } |
| 7518 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7519 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
| 7520 | SetGLError( |
| 7521 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7522 | "glCopyImage2D", "can not be used with depth or stencil textures"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7523 | return; |
| 7524 | } |
| 7525 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7526 | if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { |
| 7527 | return; |
| 7528 | } |
| 7529 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7530 | CopyRealGLErrorsToWrapper(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 7531 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7532 | gfx::Size size = GetBoundReadFrameBufferSize(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 7533 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 7534 | if (info->IsAttachedToFramebuffer()) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 7535 | clear_state_dirty_ = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 7536 | // TODO(gman): If textures tracked which framebuffers they were attached to |
| 7537 | // we could just mark those framebuffers as not complete. |
| 7538 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 7539 | } |
| 7540 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 7541 | // Clip to size to source dimensions |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7542 | GLint copyX = 0; |
| 7543 | GLint copyY = 0; |
| 7544 | GLint copyWidth = 0; |
| 7545 | GLint copyHeight = 0; |
| 7546 | Clip(x, width, size.width(), ©X, ©Width); |
| 7547 | Clip(y, height, size.height(), ©Y, ©Height); |
| 7548 | |
| 7549 | if (copyX != x || |
| 7550 | copyY != y || |
| 7551 | copyWidth != width || |
| 7552 | copyHeight != height) { |
| 7553 | // some part was clipped so clear the texture. |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7554 | if (!ClearLevel( |
| 7555 | info->service_id(), info->target(), |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7556 | target, level, internal_format, GL_UNSIGNED_BYTE, width, height, |
| 7557 | info->IsImmutable())) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7558 | SetGLError(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7559 | return; |
| 7560 | } |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7561 | if (copyHeight > 0 && copyWidth > 0) { |
| 7562 | GLint dx = copyX - x; |
| 7563 | GLint dy = copyY - y; |
| 7564 | GLint destX = dx; |
| 7565 | GLint destY = dy; |
| 7566 | glCopyTexSubImage2D(target, level, |
| 7567 | destX, destY, copyX, copyY, |
| 7568 | copyWidth, copyHeight); |
| 7569 | } |
| 7570 | } else { |
| 7571 | glCopyTexImage2D(target, level, internal_format, |
| 7572 | copyX, copyY, copyWidth, copyHeight, border); |
| 7573 | } |
[email protected] | 1002c2d | 2011-06-28 22:39:04 | [diff] [blame] | 7574 | GLenum error = PeekGLError(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7575 | if (error == GL_NO_ERROR) { |
| 7576 | texture_manager()->SetLevelInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7577 | info, target, level, internal_format, width, height, 1, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7578 | border, internal_format, GL_UNSIGNED_BYTE, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7579 | } |
| 7580 | } |
| 7581 | |
| 7582 | void GLES2DecoderImpl::DoCopyTexSubImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 7583 | GLenum target, |
| 7584 | GLint level, |
| 7585 | GLint xoffset, |
| 7586 | GLint yoffset, |
| 7587 | GLint x, |
| 7588 | GLint y, |
| 7589 | GLsizei width, |
| 7590 | GLsizei height) { |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7591 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 7592 | if (!info) { |
| 7593 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7594 | "glCopyTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7595 | return; |
| 7596 | } |
| 7597 | GLenum type = 0; |
| 7598 | GLenum format = 0; |
| 7599 | if (!info->GetLevelType(target, level, &type, &format) || |
| 7600 | !info->ValidForTexture( |
| 7601 | target, level, xoffset, yoffset, width, height, format, type)) { |
| 7602 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7603 | "glCopyTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7604 | return; |
| 7605 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 7606 | |
| 7607 | // Check we have compatible formats. |
| 7608 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 7609 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 7610 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(format); |
| 7611 | |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7612 | if (!channels_needed || |
| 7613 | (channels_needed & channels_exist) != channels_needed) { |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 7614 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7615 | GL_INVALID_OPERATION, "glCopyTexSubImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 7616 | return; |
| 7617 | } |
| 7618 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7619 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
| 7620 | SetGLError( |
| 7621 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7622 | "glCopySubImage2D", "can not be used with depth or stencil textures"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7623 | return; |
| 7624 | } |
| 7625 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7626 | if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) { |
| 7627 | return; |
| 7628 | } |
| 7629 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 7630 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7631 | gfx::Size size = GetBoundReadFrameBufferSize(); |
| 7632 | GLint copyX = 0; |
| 7633 | GLint copyY = 0; |
| 7634 | GLint copyWidth = 0; |
| 7635 | GLint copyHeight = 0; |
| 7636 | Clip(x, width, size.width(), ©X, ©Width); |
| 7637 | Clip(y, height, size.height(), ©Y, ©Height); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7638 | |
| 7639 | if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7640 | SetGLError(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", "dimensions too big"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7641 | return; |
| 7642 | } |
| 7643 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7644 | if (copyX != x || |
| 7645 | copyY != y || |
| 7646 | copyWidth != width || |
| 7647 | copyHeight != height) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7648 | // some part was clipped so clear the sub rect. |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7649 | uint32 pixels_size = 0; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7650 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7651 | width, height, format, type, state_.unpack_alignment, &pixels_size, |
| 7652 | NULL, NULL)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7653 | SetGLError( |
| 7654 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7655 | return; |
| 7656 | } |
| 7657 | scoped_array<char> zero(new char[pixels_size]); |
| 7658 | memset(zero.get(), 0, pixels_size); |
| 7659 | glTexSubImage2D( |
| 7660 | target, level, xoffset, yoffset, width, height, |
| 7661 | format, type, zero.get()); |
| 7662 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7663 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7664 | if (copyHeight > 0 && copyWidth > 0) { |
| 7665 | GLint dx = copyX - x; |
| 7666 | GLint dy = copyY - y; |
| 7667 | GLint destX = xoffset + dx; |
| 7668 | GLint destY = yoffset + dy; |
| 7669 | glCopyTexSubImage2D(target, level, |
| 7670 | destX, destY, copyX, copyY, |
| 7671 | copyWidth, copyHeight); |
| 7672 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7673 | } |
| 7674 | |
| 7675 | void GLES2DecoderImpl::DoTexSubImage2D( |
| 7676 | GLenum target, |
| 7677 | GLint level, |
| 7678 | GLint xoffset, |
| 7679 | GLint yoffset, |
| 7680 | GLsizei width, |
| 7681 | GLsizei height, |
| 7682 | GLenum format, |
| 7683 | GLenum type, |
| 7684 | const void * data) { |
| 7685 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 7686 | if (!info) { |
| 7687 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7688 | "glTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7689 | return; |
| 7690 | } |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7691 | GLenum current_type = 0; |
| 7692 | GLenum internal_format = 0; |
| 7693 | if (!info->GetLevelType(target, level, ¤t_type, &internal_format)) { |
| 7694 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7695 | GL_INVALID_OPERATION, "glTexSubImage2D", "level does not exist."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7696 | return; |
| 7697 | } |
| 7698 | if (format != internal_format) { |
| 7699 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7700 | "glTexSubImage2D", "format does not match internal format."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7701 | return; |
| 7702 | } |
| 7703 | if (type != current_type) { |
| 7704 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7705 | "glTexSubImage2D", "type does not match type of texture."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7706 | return; |
| 7707 | } |
| 7708 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7709 | if (!info->ValidForTexture( |
| 7710 | target, level, xoffset, yoffset, width, height, format, type)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7711 | SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7712 | return; |
| 7713 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 7714 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7715 | if ((GLES2Util::GetChannelsForFormat(format) & |
| 7716 | (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
| 7717 | SetGLError( |
| 7718 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7719 | "glTexSubImage2D", "can not supply data for depth or stencil textures"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7720 | return; |
| 7721 | } |
| 7722 | |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7723 | GLsizei tex_width = 0; |
| 7724 | GLsizei tex_height = 0; |
| 7725 | bool ok = info->GetLevelSize(target, level, &tex_width, &tex_height); |
| 7726 | DCHECK(ok); |
| 7727 | if (xoffset != 0 || yoffset != 0 || |
| 7728 | width != tex_width || height != tex_height) { |
| 7729 | if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7730 | SetGLError(GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 7731 | return; |
| 7732 | } |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 7733 | ScopedTextureUploadTimer timer(this); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7734 | glTexSubImage2D( |
| 7735 | target, level, xoffset, yoffset, width, height, format, type, data); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7736 | return; |
| 7737 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7738 | |
| 7739 | if (teximage2d_faster_than_texsubimage2d_ && !info->IsImmutable()) { |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 7740 | ScopedTextureUploadTimer timer(this); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7741 | // NOTE: In OpenGL ES 2.0 border is always zero and format is always the |
| 7742 | // same as internal_foramt. If that changes we'll need to look them up. |
| 7743 | WrappedTexImage2D( |
| 7744 | target, level, format, width, height, 0, format, type, data); |
| 7745 | } else { |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 7746 | ScopedTextureUploadTimer timer(this); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7747 | glTexSubImage2D( |
| 7748 | target, level, xoffset, yoffset, width, height, format, type, data); |
| 7749 | } |
| 7750 | texture_manager()->SetLevelCleared(info, target, level); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7751 | } |
| 7752 | |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7753 | error::Error GLES2DecoderImpl::HandleTexSubImage2D( |
| 7754 | uint32 immediate_data_size, const gles2::TexSubImage2D& c) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 7755 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7756 | GLboolean internal = static_cast<GLboolean>(c.internal); |
| 7757 | if (internal == GL_TRUE && tex_image_2d_failed_) |
| 7758 | return error::kNoError; |
| 7759 | |
| 7760 | GLenum target = static_cast<GLenum>(c.target); |
| 7761 | GLint level = static_cast<GLint>(c.level); |
| 7762 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 7763 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 7764 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7765 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7766 | GLenum format = static_cast<GLenum>(c.format); |
| 7767 | GLenum type = static_cast<GLenum>(c.type); |
| 7768 | uint32 data_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7769 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7770 | width, height, format, type, state_.unpack_alignment, &data_size, |
| 7771 | NULL, NULL)) { |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7772 | return error::kOutOfBounds; |
| 7773 | } |
| 7774 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 7775 | c.pixels_shm_id, c.pixels_shm_offset, data_size); |
| 7776 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7777 | SetGLErrorInvalidEnum("glTexSubImage2D", target, "target"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7778 | return error::kNoError; |
| 7779 | } |
| 7780 | if (width < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7781 | SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "width < 0"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7782 | return error::kNoError; |
| 7783 | } |
| 7784 | if (height < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7785 | SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "height < 0"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7786 | return error::kNoError; |
| 7787 | } |
| 7788 | if (!validators_->texture_format.IsValid(format)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7789 | SetGLErrorInvalidEnum("glTexSubImage2D", format, "format"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7790 | return error::kNoError; |
| 7791 | } |
| 7792 | if (!validators_->pixel_type.IsValid(type)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7793 | SetGLErrorInvalidEnum("glTexSubImage2D", type, "type"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7794 | return error::kNoError; |
| 7795 | } |
| 7796 | if (pixels == NULL) { |
| 7797 | return error::kOutOfBounds; |
| 7798 | } |
| 7799 | DoTexSubImage2D( |
| 7800 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
| 7801 | return error::kNoError; |
| 7802 | } |
| 7803 | |
| 7804 | error::Error GLES2DecoderImpl::HandleTexSubImage2DImmediate( |
| 7805 | uint32 immediate_data_size, const gles2::TexSubImage2DImmediate& c) { |
| 7806 | GLboolean internal = static_cast<GLboolean>(c.internal); |
| 7807 | if (internal == GL_TRUE && tex_image_2d_failed_) |
| 7808 | return error::kNoError; |
| 7809 | |
| 7810 | GLenum target = static_cast<GLenum>(c.target); |
| 7811 | GLint level = static_cast<GLint>(c.level); |
| 7812 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 7813 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 7814 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7815 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7816 | GLenum format = static_cast<GLenum>(c.format); |
| 7817 | GLenum type = static_cast<GLenum>(c.type); |
| 7818 | uint32 data_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7819 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7820 | width, height, format, type, state_.unpack_alignment, &data_size, |
| 7821 | NULL, NULL)) { |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7822 | return error::kOutOfBounds; |
| 7823 | } |
| 7824 | const void* pixels = GetImmediateDataAs<const void*>( |
| 7825 | c, data_size, immediate_data_size); |
| 7826 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7827 | SetGLErrorInvalidEnum("glTexSubImage2D", target, "target"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7828 | return error::kNoError; |
| 7829 | } |
| 7830 | if (width < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7831 | SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "width < 0"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7832 | return error::kNoError; |
| 7833 | } |
| 7834 | if (height < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7835 | SetGLError(GL_INVALID_VALUE, "glTexSubImage2D", "height < 0"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7836 | return error::kNoError; |
| 7837 | } |
| 7838 | if (!validators_->texture_format.IsValid(format)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7839 | SetGLErrorInvalidEnum("glTexSubImage2D", format, "format"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7840 | return error::kNoError; |
| 7841 | } |
| 7842 | if (!validators_->pixel_type.IsValid(type)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7843 | SetGLErrorInvalidEnum("glTexSubImage2D", type, "type"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 7844 | return error::kNoError; |
| 7845 | } |
| 7846 | if (pixels == NULL) { |
| 7847 | return error::kOutOfBounds; |
| 7848 | } |
| 7849 | DoTexSubImage2D( |
| 7850 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
| 7851 | return error::kNoError; |
| 7852 | } |
| 7853 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7854 | error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7855 | uint32 immediate_data_size, const gles2::GetVertexAttribPointerv& c) { |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7856 | GLuint index = static_cast<GLuint>(c.index); |
| 7857 | GLenum pname = static_cast<GLenum>(c.pname); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7858 | typedef gles2::GetVertexAttribPointerv::Result Result; |
| 7859 | Result* result = GetSharedMemoryAs<Result*>( |
| 7860 | c.pointer_shm_id, c.pointer_shm_offset, Result::ComputeSize(1)); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7861 | if (!result) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7862 | return error::kOutOfBounds; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7863 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 7864 | // Check that the client initialized the result. |
| 7865 | if (result->size != 0) { |
| 7866 | return error::kInvalidArguments; |
| 7867 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7868 | if (!validators_->vertex_pointer.IsValid(pname)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7869 | SetGLErrorInvalidEnum("glGetVertexAttribPointerv", pname, "pname"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7870 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7871 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 7872 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7873 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7874 | "glGetVertexAttribPointerv", "index out of range."); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7875 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 7876 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7877 | result->SetNumResults(1); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 7878 | *result->GetData() = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7879 | state_.vertex_attrib_manager->GetVertexAttribInfo(index)->offset(); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7880 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7881 | } |
| 7882 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7883 | bool GLES2DecoderImpl::GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7884 | GLuint program, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7885 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7886 | error::Error* error, GLint* real_location, |
| 7887 | GLuint* service_id, void** result_pointer, GLenum* result_type) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7888 | DCHECK(error); |
| 7889 | DCHECK(service_id); |
| 7890 | DCHECK(result_pointer); |
| 7891 | DCHECK(result_type); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7892 | DCHECK(real_location); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7893 | *error = error::kNoError; |
| 7894 | // Make sure we have enough room for the result on failure. |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7895 | SizedResult<GLint>* result; |
| 7896 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 7897 | shm_id, shm_offset, SizedResult<GLint>::ComputeSize(0)); |
| 7898 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7899 | *error = error::kOutOfBounds; |
| 7900 | return false; |
| 7901 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7902 | *result_pointer = result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7903 | // Set the result size to 0 so the client does not have to check for success. |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7904 | result->SetNumResults(0); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7905 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 7906 | program, "glGetUniform"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7907 | if (!info) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7908 | return false; |
| 7909 | } |
| 7910 | if (!info->IsValid()) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7911 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7912 | SetGLError(GL_INVALID_OPERATION, "glGetUniform", "program not linked"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7913 | return false; |
| 7914 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7915 | *service_id = info->service_id(); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 7916 | GLint array_index = -1; |
| 7917 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7918 | info->GetUniformInfoByFakeLocation( |
| 7919 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 7920 | if (!uniform_info) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7921 | // No such location. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7922 | SetGLError(GL_INVALID_OPERATION, "glGetUniform", "unknown location"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7923 | return false; |
| 7924 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 7925 | GLenum type = uniform_info->type; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 7926 | GLsizei size = GLES2Util::GetGLDataTypeSizeForUniforms(type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7927 | if (size == 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7928 | SetGLError(GL_INVALID_OPERATION, "glGetUniform", "unknown type"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7929 | return false; |
| 7930 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7931 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 7932 | shm_id, shm_offset, SizedResult<GLint>::ComputeSizeFromBytes(size)); |
| 7933 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7934 | *error = error::kOutOfBounds; |
| 7935 | return false; |
| 7936 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7937 | result->size = size; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7938 | *result_type = type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7939 | return true; |
| 7940 | } |
| 7941 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7942 | error::Error GLES2DecoderImpl::HandleGetUniformiv( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7943 | uint32 immediate_data_size, const gles2::GetUniformiv& c) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7944 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 7945 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7946 | GLuint service_id; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7947 | GLenum result_type; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7948 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7949 | Error error; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7950 | void* result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7951 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7952 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 7953 | &error, &real_location, &service_id, &result, &result_type)) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7954 | glGetUniformiv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7955 | service_id, real_location, |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7956 | static_cast<gles2::GetUniformiv::Result*>(result)->GetData()); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7957 | } |
| 7958 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7959 | } |
| 7960 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7961 | error::Error GLES2DecoderImpl::HandleGetUniformfv( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7962 | uint32 immediate_data_size, const gles2::GetUniformfv& c) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7963 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 7964 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7965 | GLuint service_id; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7966 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7967 | Error error; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7968 | typedef gles2::GetUniformfv::Result Result; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7969 | Result* result; |
| 7970 | GLenum result_type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7971 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7972 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 7973 | &error, &real_location, &service_id, |
| 7974 | reinterpret_cast<void**>(&result), &result_type)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7975 | if (result_type == GL_BOOL || result_type == GL_BOOL_VEC2 || |
| 7976 | result_type == GL_BOOL_VEC3 || result_type == GL_BOOL_VEC4) { |
| 7977 | GLsizei num_values = result->GetNumResults(); |
| 7978 | scoped_array<GLint> temp(new GLint[num_values]); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7979 | glGetUniformiv(service_id, real_location, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7980 | GLfloat* dst = result->GetData(); |
| 7981 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
| 7982 | dst[ii] = (temp[ii] != 0); |
| 7983 | } |
| 7984 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 7985 | glGetUniformfv(service_id, real_location, result->GetData()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 7986 | } |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 7987 | } |
| 7988 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7989 | } |
| 7990 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7991 | error::Error GLES2DecoderImpl::HandleGetShaderPrecisionFormat( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7992 | uint32 immediate_data_size, const gles2::GetShaderPrecisionFormat& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7993 | GLenum shader_type = static_cast<GLenum>(c.shadertype); |
| 7994 | GLenum precision_type = static_cast<GLenum>(c.precisiontype); |
| 7995 | typedef gles2::GetShaderPrecisionFormat::Result Result; |
| 7996 | Result* result = GetSharedMemoryAs<Result*>( |
| 7997 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7998 | if (!result) { |
| 7999 | return error::kOutOfBounds; |
| 8000 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8001 | // Check that the client initialized the result. |
| 8002 | if (result->success != 0) { |
| 8003 | return error::kInvalidArguments; |
| 8004 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8005 | if (!validators_->shader_type.IsValid(shader_type)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8006 | SetGLErrorInvalidEnum( |
| 8007 | "glGetShaderPrecisionFormat", shader_type, "shader_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8008 | return error::kNoError; |
| 8009 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8010 | if (!validators_->shader_precision.IsValid(precision_type)) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8011 | SetGLErrorInvalidEnum( |
| 8012 | "glGetShaderPrecisionFormat", precision_type, "precision_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8013 | return error::kNoError; |
| 8014 | } |
| 8015 | |
| 8016 | result->success = 1; // true |
| 8017 | switch (precision_type) { |
| 8018 | case GL_LOW_INT: |
| 8019 | case GL_MEDIUM_INT: |
| 8020 | case GL_HIGH_INT: |
[email protected] | 0a34b58 | 2012-04-09 22:42:56 | [diff] [blame] | 8021 | // These values are for a 32-bit twos-complement integer format. |
| 8022 | result->min_range = 31; |
| 8023 | result->max_range = 30; |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8024 | result->precision = 0; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 8025 | break; |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8026 | case GL_LOW_FLOAT: |
| 8027 | case GL_MEDIUM_FLOAT: |
| 8028 | case GL_HIGH_FLOAT: |
[email protected] | 0a34b58 | 2012-04-09 22:42:56 | [diff] [blame] | 8029 | // These values are for an IEEE single-precision floating-point format. |
| 8030 | result->min_range = 127; |
| 8031 | result->max_range = 127; |
| 8032 | result->precision = 23; |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8033 | break; |
| 8034 | default: |
| 8035 | NOTREACHED(); |
| 8036 | break; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8037 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8038 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8039 | } |
| 8040 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8041 | error::Error GLES2DecoderImpl::HandleGetAttachedShaders( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8042 | uint32 immediate_data_size, const gles2::GetAttachedShaders& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8043 | uint32 result_size = c.result_size; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 8044 | GLuint program = static_cast<GLuint>(c.program); |
| 8045 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 8046 | program, "glGetAttachedShaders"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8047 | if (!info) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8048 | return error::kNoError; |
| 8049 | } |
| 8050 | typedef gles2::GetAttachedShaders::Result Result; |
| 8051 | uint32 max_count = Result::ComputeMaxResults(result_size); |
| 8052 | Result* result = GetSharedMemoryAs<Result*>( |
| 8053 | c.result_shm_id, c.result_shm_offset, Result::ComputeSize(max_count)); |
| 8054 | if (!result) { |
| 8055 | return error::kOutOfBounds; |
| 8056 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8057 | // Check that the client initialized the result. |
| 8058 | if (result->size != 0) { |
| 8059 | return error::kInvalidArguments; |
| 8060 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8061 | GLsizei count = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8062 | glGetAttachedShaders( |
| 8063 | info->service_id(), max_count, &count, result->GetData()); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8064 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8065 | if (!shader_manager()->GetClientId(result->GetData()[ii], |
| 8066 | &result->GetData()[ii])) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8067 | NOTREACHED(); |
| 8068 | return error::kGenericError; |
| 8069 | } |
| 8070 | } |
| 8071 | result->SetNumResults(count); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8072 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8073 | } |
| 8074 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8075 | error::Error GLES2DecoderImpl::HandleGetActiveUniform( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8076 | uint32 immediate_data_size, const gles2::GetActiveUniform& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8077 | GLuint program = c.program; |
| 8078 | GLuint index = c.index; |
| 8079 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8080 | typedef gles2::GetActiveUniform::Result Result; |
| 8081 | Result* result = GetSharedMemoryAs<Result*>( |
| 8082 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8083 | if (!result) { |
| 8084 | return error::kOutOfBounds; |
| 8085 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8086 | // Check that the client initialized the result. |
| 8087 | if (result->success != 0) { |
| 8088 | return error::kInvalidArguments; |
| 8089 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 8090 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 8091 | program, "glGetActiveUniform"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8092 | if (!info) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8093 | return error::kNoError; |
| 8094 | } |
| 8095 | const ProgramManager::ProgramInfo::UniformInfo* uniform_info = |
| 8096 | info->GetUniformInfo(index); |
| 8097 | if (!uniform_info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8098 | SetGLError(GL_INVALID_VALUE, "glGetActiveUniform", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8099 | return error::kNoError; |
| 8100 | } |
| 8101 | result->success = 1; // true. |
| 8102 | result->size = uniform_info->size; |
| 8103 | result->type = uniform_info->type; |
| 8104 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 8105 | bucket->SetFromString(uniform_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8106 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8107 | } |
| 8108 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8109 | error::Error GLES2DecoderImpl::HandleGetActiveAttrib( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8110 | uint32 immediate_data_size, const gles2::GetActiveAttrib& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8111 | GLuint program = c.program; |
| 8112 | GLuint index = c.index; |
| 8113 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8114 | typedef gles2::GetActiveAttrib::Result Result; |
| 8115 | Result* result = GetSharedMemoryAs<Result*>( |
| 8116 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8117 | if (!result) { |
| 8118 | return error::kOutOfBounds; |
| 8119 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8120 | // Check that the client initialized the result. |
| 8121 | if (result->success != 0) { |
| 8122 | return error::kInvalidArguments; |
| 8123 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 8124 | ProgramManager::ProgramInfo* info = GetProgramInfoNotShader( |
| 8125 | program, "glGetActiveAttrib"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8126 | if (!info) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8127 | return error::kNoError; |
| 8128 | } |
| 8129 | const ProgramManager::ProgramInfo::VertexAttribInfo* attrib_info = |
| 8130 | info->GetAttribInfo(index); |
| 8131 | if (!attrib_info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8132 | SetGLError(GL_INVALID_VALUE, "glGetActiveAttrib", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8133 | return error::kNoError; |
| 8134 | } |
| 8135 | result->success = 1; // true. |
| 8136 | result->size = attrib_info->size; |
| 8137 | result->type = attrib_info->type; |
| 8138 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 8139 | bucket->SetFromString(attrib_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8140 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8141 | } |
| 8142 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8143 | error::Error GLES2DecoderImpl::HandleShaderBinary( |
| 8144 | uint32 immediate_data_size, const gles2::ShaderBinary& c) { |
| 8145 | #if 1 // No binary shader support. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8146 | SetGLError(GL_INVALID_OPERATION, "glShaderBinary", "not supported"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8147 | return error::kNoError; |
| 8148 | #else |
| 8149 | GLsizei n = static_cast<GLsizei>(c.n); |
| 8150 | if (n < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8151 | SetGLError(GL_INVALID_VALUE, "glShaderBinary", "n < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8152 | return error::kNoError; |
| 8153 | } |
| 8154 | GLsizei length = static_cast<GLsizei>(c.length); |
| 8155 | if (length < 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8156 | SetGLError(GL_INVALID_VALUE, "glShaderBinary", "length < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8157 | return error::kNoError; |
| 8158 | } |
| 8159 | uint32 data_size; |
| 8160 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 8161 | return error::kOutOfBounds; |
| 8162 | } |
| 8163 | const GLuint* shaders = GetSharedMemoryAs<const GLuint*>( |
| 8164 | c.shaders_shm_id, c.shaders_shm_offset, data_size); |
| 8165 | GLenum binaryformat = static_cast<GLenum>(c.binaryformat); |
| 8166 | const void* binary = GetSharedMemoryAs<const void*>( |
| 8167 | c.binary_shm_id, c.binary_shm_offset, length); |
| 8168 | if (shaders == NULL || binary == NULL) { |
| 8169 | return error::kOutOfBounds; |
| 8170 | } |
| 8171 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 8172 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8173 | ShaderManager::ShaderInfo* info = GetShaderInfo(shaders[ii]); |
| 8174 | if (!info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8175 | SetGLError(GL_INVALID_VALUE, "glShaderBinary", "unknown shader"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8176 | return error::kNoError; |
| 8177 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8178 | service_ids[ii] = info->service_id(); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8179 | } |
| 8180 | // TODO(gman): call glShaderBinary |
| 8181 | return error::kNoError; |
| 8182 | #endif |
| 8183 | } |
| 8184 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8185 | error::Error GLES2DecoderImpl::HandleSwapBuffers( |
| 8186 | uint32 immediate_data_size, const gles2::SwapBuffers& c) { |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8187 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 8188 | if (!is_offscreen && surface_->DeferSwapBuffers()) { |
| 8189 | return error::kDeferCommandUntilLater; |
| 8190 | } |
| 8191 | |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8192 | int this_frame_number = frame_number_++; |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 8193 | // TRACE_EVENT for gpu tests: |
| 8194 | TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffersLatency", |
| 8195 | "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
| 8196 | "width", (is_offscreen ? offscreen_size_.width() : |
| 8197 | surface_->GetSize().width())); |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8198 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleSwapBuffers", |
| 8199 | "offscreen", is_offscreen, |
| 8200 | "frame", this_frame_number); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8201 | // If offscreen then don't actually SwapBuffers to the display. Just copy |
| 8202 | // the rendered frame to another frame buffer. |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8203 | if (is_offscreen) { |
[email protected] | 111975c6 | 2012-09-06 01:37:31 | [diff] [blame] | 8204 | TRACE_EVENT2("gpu", "Offscreen", |
| 8205 | "width", offscreen_size_.width(), "height", offscreen_size_.height()); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8206 | if (offscreen_size_ != offscreen_saved_color_texture_->size()) { |
| 8207 | // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, |
| 8208 | // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will |
| 8209 | // fix this. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8210 | if (workarounds().needs_offscreen_buffer_workaround) { |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8211 | offscreen_saved_frame_buffer_->Create(); |
| 8212 | glFinish(); |
| 8213 | } |
| 8214 | |
| 8215 | // Allocate the offscreen saved color texture. |
| 8216 | DCHECK(offscreen_saved_color_format_); |
| 8217 | offscreen_saved_color_texture_->AllocateStorage( |
| 8218 | offscreen_size_, offscreen_saved_color_format_); |
| 8219 | |
| 8220 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 8221 | offscreen_saved_color_texture_.get()); |
| 8222 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 8223 | GL_FRAMEBUFFER_COMPLETE) { |
| 8224 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 8225 | << "because offscreen saved FBO was incomplete."; |
| 8226 | return error::kLostContext; |
| 8227 | } |
| 8228 | |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8229 | // Clear the offscreen color texture. |
| 8230 | // TODO(piman): Is this still necessary? |
| 8231 | { |
| 8232 | ScopedFrameBufferBinder binder(this, |
| 8233 | offscreen_saved_frame_buffer_->id()); |
| 8234 | glClearColor(0, 0, 0, 0); |
| 8235 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 8236 | glDisable(GL_SCISSOR_TEST); |
| 8237 | glClear(GL_COLOR_BUFFER_BIT); |
| 8238 | RestoreClearState(); |
| 8239 | } |
| 8240 | |
| 8241 | UpdateParentTextureInfo(); |
| 8242 | } |
| 8243 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8244 | ScopedGLErrorSuppressor suppressor(this); |
| 8245 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 8246 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 8247 | // For multisampled buffers, resolve the frame buffer. |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8248 | ScopedResolvedFrameBufferBinder binder(this, true, false); |
[email protected] | 89d6ed0 | 2011-04-20 00:23:23 | [diff] [blame] | 8249 | return error::kNoError; |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 8250 | } else { |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8251 | ScopedFrameBufferBinder binder(this, |
| 8252 | offscreen_target_frame_buffer_->id()); |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 8253 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8254 | if (offscreen_target_buffer_preserved_) { |
| 8255 | // Copy the target frame buffer to the saved offscreen texture. |
| 8256 | offscreen_saved_color_texture_->Copy( |
| 8257 | offscreen_saved_color_texture_->size(), |
| 8258 | offscreen_saved_color_format_); |
| 8259 | } else { |
| 8260 | // Flip the textures in the parent context via the texture manager. |
| 8261 | if (!!offscreen_saved_color_texture_info_.get()) |
| 8262 | offscreen_saved_color_texture_info_-> |
| 8263 | SetServiceId(offscreen_target_color_texture_->id()); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 8264 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8265 | offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); |
| 8266 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 8267 | offscreen_target_color_texture_.get()); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 8268 | } |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8269 | |
| 8270 | // Ensure the side effects of the copy are visible to the parent |
| 8271 | // context. There is no need to do this for ANGLE because it uses a |
| 8272 | // single D3D device for all contexts. |
| 8273 | if (!IsAngle()) |
| 8274 | glFlush(); |
[email protected] | 89d6ed0 | 2011-04-20 00:23:23 | [diff] [blame] | 8275 | return error::kNoError; |
[email protected] | 0c8c9d2 | 2010-06-25 17:36:39 | [diff] [blame] | 8276 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8277 | } else { |
[email protected] | 111975c6 | 2012-09-06 01:37:31 | [diff] [blame] | 8278 | TRACE_EVENT2("gpu", "Onscreen", |
| 8279 | "width", surface_->GetSize().width(), |
| 8280 | "height", surface_->GetSize().height()); |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 8281 | if (!surface_->SwapBuffers()) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 8282 | LOG(ERROR) << "Context lost because SwapBuffers failed."; |
[email protected] | 5259ead8 | 2010-09-10 18:02:02 | [diff] [blame] | 8283 | return error::kLostContext; |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 8284 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8285 | } |
| 8286 | |
[email protected] | 89d6ed0 | 2011-04-20 00:23:23 | [diff] [blame] | 8287 | return error::kNoError; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8288 | } |
| 8289 | |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 8290 | error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( |
| 8291 | uint32 immediate_data_size, const gles2::EnableFeatureCHROMIUM& c) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8292 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8293 | if (!bucket || bucket->size() == 0) { |
| 8294 | return error::kInvalidArguments; |
| 8295 | } |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 8296 | typedef gles2::EnableFeatureCHROMIUM::Result Result; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8297 | Result* result = GetSharedMemoryAs<Result*>( |
| 8298 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8299 | if (!result) { |
| 8300 | return error::kOutOfBounds; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 8301 | } |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8302 | // Check that the client initialized the result. |
| 8303 | if (*result != 0) { |
| 8304 | return error::kInvalidArguments; |
| 8305 | } |
| 8306 | std::string feature_str; |
| 8307 | if (!bucket->GetAsString(&feature_str)) { |
| 8308 | return error::kInvalidArguments; |
| 8309 | } |
| 8310 | |
| 8311 | // TODO(gman): make this some kind of table to function pointer thingy. |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 8312 | if (feature_str.compare("pepper3d_allow_buffers_on_multiple_targets") == 0) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8313 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 8314 | } else if (feature_str.compare("pepper3d_support_fixed_attribs") == 0) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 8315 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
| 8316 | // TODO(gman): decide how to remove the need for this const_cast. |
| 8317 | // I could make validators_ non const but that seems bad as this is the only |
| 8318 | // place it is needed. I could make some special friend class of validators |
| 8319 | // just to allow this to set them. That seems silly. I could refactor this |
| 8320 | // code to use the extension mechanism or the initialization attributes to |
| 8321 | // turn this feature on. Given that the only real point of this is to make |
| 8322 | // the conformance tests pass and given that there is lots of real work that |
| 8323 | // needs to be done it seems like refactoring for one to one of those |
| 8324 | // methods is a very low priority. |
| 8325 | const_cast<Validators*>(validators_)->vertex_attrib_type.AddValue(GL_FIXED); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8326 | } else if (feature_str.compare("webgl_enable_glsl_webgl_validation") == 0) { |
| 8327 | force_webgl_glsl_validation_ = true; |
| 8328 | InitializeShaderTranslator(); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8329 | } else { |
| 8330 | return error::kNoError; |
| 8331 | } |
| 8332 | |
| 8333 | *result = 1; // true. |
| 8334 | return error::kNoError; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 8335 | } |
| 8336 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8337 | error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( |
| 8338 | uint32 immediate_data_size, |
| 8339 | const gles2::GetRequestableExtensionsCHROMIUM& c) { |
| 8340 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8341 | FeatureInfo::Ref info(new FeatureInfo()); |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 8342 | info->Initialize(disallowed_features_, NULL); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8343 | bucket->SetFromString(info->extensions().c_str()); |
| 8344 | return error::kNoError; |
| 8345 | } |
| 8346 | |
| 8347 | error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( |
| 8348 | uint32 immediate_data_size, const gles2::RequestExtensionCHROMIUM& c) { |
| 8349 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8350 | if (!bucket || bucket->size() == 0) { |
| 8351 | return error::kInvalidArguments; |
| 8352 | } |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8353 | std::string feature_str; |
| 8354 | if (!bucket->GetAsString(&feature_str)) { |
| 8355 | return error::kInvalidArguments; |
| 8356 | } |
| 8357 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8358 | bool std_derivatives_enabled = features().oes_standard_derivatives; |
| 8359 | bool webglsl_enabled = features().chromium_webglsl; |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8360 | |
| 8361 | feature_info_->AddFeatures(feature_str.c_str()); |
| 8362 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8363 | bool initialization_required = false; |
| 8364 | if (force_webgl_glsl_validation_ && !derivatives_explicitly_enabled_) { |
| 8365 | size_t derivatives_offset = feature_str.find(kOESDerivativeExtension); |
| 8366 | if (std::string::npos != derivatives_offset) { |
| 8367 | derivatives_explicitly_enabled_ = true; |
| 8368 | initialization_required = true; |
| 8369 | } |
| 8370 | } |
| 8371 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8372 | // If we just enabled a feature which affects the shader translator, |
| 8373 | // we may need to re-initialize it. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8374 | if (std_derivatives_enabled != features().oes_standard_derivatives || |
| 8375 | webglsl_enabled != features().chromium_webglsl || |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8376 | initialization_required) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8377 | InitializeShaderTranslator(); |
| 8378 | } |
| 8379 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 8380 | UpdateCapabilities(); |
| 8381 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8382 | return error::kNoError; |
| 8383 | } |
| 8384 | |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8385 | error::Error GLES2DecoderImpl::HandleGetMultipleIntegervCHROMIUM( |
| 8386 | uint32 immediate_data_size, const gles2::GetMultipleIntegervCHROMIUM& c) { |
| 8387 | GLuint count = c.count; |
| 8388 | uint32 pnames_size; |
| 8389 | if (!SafeMultiplyUint32(count, sizeof(GLenum), &pnames_size)) { |
| 8390 | return error::kOutOfBounds; |
| 8391 | } |
| 8392 | const GLenum* pnames = GetSharedMemoryAs<const GLenum*>( |
| 8393 | c.pnames_shm_id, c.pnames_shm_offset, pnames_size); |
| 8394 | if (pnames == NULL) { |
| 8395 | return error::kOutOfBounds; |
| 8396 | } |
| 8397 | |
| 8398 | // We have to copy them since we use them twice so the client |
| 8399 | // can't change them between the time we validate them and the time we use |
| 8400 | // them. |
| 8401 | scoped_array<GLenum> enums(new GLenum[count]); |
| 8402 | memcpy(enums.get(), pnames, pnames_size); |
| 8403 | |
| 8404 | // Count up the space needed for the result. |
| 8405 | uint32 num_results = 0; |
| 8406 | for (GLuint ii = 0; ii < count; ++ii) { |
| 8407 | uint32 num = util_.GLGetNumValuesReturned(enums[ii]); |
| 8408 | if (num == 0) { |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8409 | SetGLErrorInvalidEnum("glGetMulitpleCHROMIUM", enums[ii], "pname"); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8410 | return error::kNoError; |
| 8411 | } |
| 8412 | // Num will never be more than 4. |
| 8413 | DCHECK_LE(num, 4u); |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 8414 | if (!SafeAddUint32(num_results, num, &num_results)) { |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8415 | return error::kOutOfBounds; |
| 8416 | } |
| 8417 | } |
| 8418 | |
| 8419 | uint32 result_size = 0; |
| 8420 | if (!SafeMultiplyUint32(num_results, sizeof(GLint), &result_size)) { |
| 8421 | return error::kOutOfBounds; |
| 8422 | } |
| 8423 | |
| 8424 | if (result_size != static_cast<uint32>(c.size)) { |
| 8425 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8426 | "glGetMulitpleCHROMIUM", "bad size GL_INVALID_VALUE"); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8427 | return error::kNoError; |
| 8428 | } |
| 8429 | |
| 8430 | GLint* results = GetSharedMemoryAs<GLint*>( |
| 8431 | c.results_shm_id, c.results_shm_offset, result_size); |
| 8432 | if (results == NULL) { |
| 8433 | return error::kOutOfBounds; |
| 8434 | } |
| 8435 | |
| 8436 | // Check the results have been cleared in case the context was lost. |
| 8437 | for (uint32 ii = 0; ii < num_results; ++ii) { |
| 8438 | if (results[ii]) { |
| 8439 | return error::kInvalidArguments; |
| 8440 | } |
| 8441 | } |
| 8442 | |
| 8443 | // Get each result. |
| 8444 | GLint* start = results; |
| 8445 | for (GLuint ii = 0; ii < count; ++ii) { |
| 8446 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 8447 | if (!state_.GetStateAsGLint(enums[ii], results, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 8448 | !GetHelper(enums[ii], results, &num_written)) { |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8449 | glGetIntegerv(enums[ii], results); |
| 8450 | } |
| 8451 | results += num_written; |
| 8452 | } |
| 8453 | |
| 8454 | // Just to verify. Should this be a DCHECK? |
| 8455 | if (static_cast<uint32>(results - start) != num_results) { |
| 8456 | return error::kOutOfBounds; |
| 8457 | } |
| 8458 | |
| 8459 | return error::kNoError; |
| 8460 | } |
| 8461 | |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 8462 | error::Error GLES2DecoderImpl::HandleGetProgramInfoCHROMIUM( |
| 8463 | uint32 immediate_data_size, const gles2::GetProgramInfoCHROMIUM& c) { |
| 8464 | GLuint program = static_cast<GLuint>(c.program); |
| 8465 | uint32 bucket_id = c.bucket_id; |
| 8466 | Bucket* bucket = CreateBucket(bucket_id); |
| 8467 | bucket->SetSize(sizeof(ProgramInfoHeader)); // in case we fail. |
| 8468 | ProgramManager::ProgramInfo* info = NULL; |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 8469 | info = GetProgramInfo(program); |
| 8470 | if (!info || !info->IsValid()) { |
| 8471 | return error::kNoError; |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 8472 | } |
[email protected] | 5d4c6b2 | 2012-02-07 08:22:28 | [diff] [blame] | 8473 | info->GetProgramInfo(program_manager(), bucket); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 8474 | return error::kNoError; |
| 8475 | } |
| 8476 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 8477 | error::ContextLostReason GLES2DecoderImpl::GetContextLostReason() { |
| 8478 | switch (reset_status_) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8479 | case GL_NO_ERROR: |
| 8480 | // TODO(kbr): improve the precision of the error code in this case. |
| 8481 | // Consider delegating to context for error code if MakeCurrent fails. |
| 8482 | return error::kUnknown; |
| 8483 | case GL_GUILTY_CONTEXT_RESET_ARB: |
| 8484 | return error::kGuilty; |
| 8485 | case GL_INNOCENT_CONTEXT_RESET_ARB: |
| 8486 | return error::kInnocent; |
| 8487 | case GL_UNKNOWN_CONTEXT_RESET_ARB: |
| 8488 | return error::kUnknown; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 8489 | } |
| 8490 | |
| 8491 | NOTREACHED(); |
| 8492 | return error::kUnknown; |
| 8493 | } |
| 8494 | |
| 8495 | bool GLES2DecoderImpl::WasContextLost() { |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 8496 | if (context_->WasAllocatedUsingRobustnessExtension()) { |
| 8497 | GLenum status = GL_NO_ERROR; |
| 8498 | if (has_robustness_extension_) |
| 8499 | status = glGetGraphicsResetStatusARB(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 8500 | if (status != GL_NO_ERROR) { |
| 8501 | // The graphics card was reset. Signal a lost context to the application. |
| 8502 | reset_status_ = status; |
| 8503 | LOG(ERROR) << (surface_->IsOffscreen() ? "Offscreen" : "Onscreen") |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 8504 | << " context lost via ARB/EXT_robustness. Reset status = 0x" |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 8505 | << std::hex << status << std::dec; |
| 8506 | return true; |
| 8507 | } |
| 8508 | } |
| 8509 | return false; |
| 8510 | } |
| 8511 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8512 | bool GLES2DecoderImpl::GenQueriesEXTHelper( |
| 8513 | GLsizei n, const GLuint* client_ids) { |
| 8514 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 8515 | if (query_manager_->GetQuery(client_ids[ii])) { |
| 8516 | return false; |
| 8517 | } |
| 8518 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8519 | // NOTE: We don't generate Query objects here. Only in BeginQueryEXT |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8520 | return true; |
| 8521 | } |
| 8522 | |
| 8523 | void GLES2DecoderImpl::DeleteQueriesEXTHelper( |
| 8524 | GLsizei n, const GLuint* client_ids) { |
| 8525 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 8526 | QueryManager::Query* query = query_manager_->GetQuery(client_ids[ii]); |
| 8527 | if (query && !query->IsDeleted()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8528 | if (query == state_.current_query) { |
| 8529 | state_.current_query = NULL; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8530 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8531 | query->Destroy(true); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8532 | query_manager_->RemoveQuery(client_ids[ii]); |
| 8533 | } |
| 8534 | } |
| 8535 | } |
| 8536 | |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 8537 | bool GLES2DecoderImpl::ProcessPendingQueries() { |
| 8538 | if (query_manager_.get() == NULL) { |
| 8539 | return false; |
| 8540 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8541 | if (!query_manager_->ProcessPendingQueries()) { |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 8542 | current_decoder_error_ = error::kOutOfBounds; |
| 8543 | } |
| 8544 | return query_manager_->HavePendingQueries(); |
| 8545 | } |
| 8546 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8547 | error::Error GLES2DecoderImpl::HandleBeginQueryEXT( |
| 8548 | uint32 immediate_data_size, const gles2::BeginQueryEXT& c) { |
| 8549 | GLenum target = static_cast<GLenum>(c.target); |
| 8550 | GLuint client_id = static_cast<GLuint>(c.id); |
| 8551 | int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id); |
| 8552 | uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 8553 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8554 | switch (target) { |
| 8555 | case GL_COMMANDS_ISSUED_CHROMIUM: |
[email protected] | fb4bf582 | 2012-10-23 21:25:55 | [diff] [blame] | 8556 | case GL_LATENCY_QUERY_CHROMIUM: |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8557 | break; |
| 8558 | default: |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8559 | if (!features().occlusion_query_boolean) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8560 | SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "not enabled"); |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8561 | return error::kNoError; |
| 8562 | } |
| 8563 | break; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8564 | } |
| 8565 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8566 | if (state_.current_query) { |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8567 | SetGLError( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8568 | GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8569 | return error::kNoError; |
| 8570 | } |
| 8571 | |
| 8572 | if (client_id == 0) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8573 | SetGLError(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8574 | return error::kNoError; |
| 8575 | } |
| 8576 | |
| 8577 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 8578 | if (!query) { |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8579 | // TODO(gman): Decide if we need this check. |
| 8580 | // |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8581 | // Checks id was made by glGenQueries |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8582 | // |
| 8583 | // From the POV of OpenGL ES 2.0 you need to call glGenQueriesEXT |
| 8584 | // for all Query ids but from the POV of the command buffer service maybe |
| 8585 | // you don't. |
| 8586 | // |
| 8587 | // The client can enforce this. I don't think the service cares. |
| 8588 | // |
| 8589 | // IdAllocatorInterface* id_allocator = |
| 8590 | // group_->GetIdAllocator(id_namespaces::kQueries); |
| 8591 | // if (!id_allocator->InUse(client_id)) { |
| 8592 | // SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8593 | // "glBeginQueryEXT", "id not made by glGenQueriesEXT"); |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8594 | // return error::kNoError; |
| 8595 | // } |
| 8596 | query = query_manager_->CreateQuery( |
| 8597 | target, client_id, sync_shm_id, sync_shm_offset); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8598 | } |
| 8599 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8600 | if (query->target() != target) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8601 | SetGLError( |
| 8602 | GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8603 | return error::kNoError; |
| 8604 | } else if (query->shm_id() != sync_shm_id || |
| 8605 | query->shm_offset() != sync_shm_offset) { |
| 8606 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 8607 | return error::kInvalidArguments; |
| 8608 | } |
| 8609 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8610 | if (!query_manager_->BeginQuery(query)) { |
| 8611 | return error::kOutOfBounds; |
| 8612 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8613 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8614 | state_.current_query = query; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8615 | return error::kNoError; |
| 8616 | } |
| 8617 | |
| 8618 | error::Error GLES2DecoderImpl::HandleEndQueryEXT( |
| 8619 | uint32 immediate_data_size, const gles2::EndQueryEXT& c) { |
| 8620 | GLenum target = static_cast<GLenum>(c.target); |
| 8621 | uint32 submit_count = static_cast<GLuint>(c.submit_count); |
| 8622 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8623 | if (!state_.current_query) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8624 | SetGLError(GL_INVALID_OPERATION, "glEndQueryEXT", "No active query"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8625 | return error::kNoError; |
| 8626 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8627 | if (state_.current_query->target() != target) { |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8628 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8629 | "glEndQueryEXT", "target does not match active query"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8630 | return error::kNoError; |
| 8631 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8632 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8633 | if (!query_manager_->EndQuery(state_.current_query, submit_count)) { |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 8634 | return error::kOutOfBounds; |
| 8635 | } |
| 8636 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8637 | state_.current_query = NULL; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 8638 | return error::kNoError; |
| 8639 | } |
| 8640 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8641 | bool GLES2DecoderImpl::GenVertexArraysOESHelper( |
| 8642 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8643 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 8644 | if (GetVertexAttribManager(client_ids[ii])) { |
| 8645 | return false; |
| 8646 | } |
| 8647 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 8648 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8649 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 8650 | // Emulated VAO |
| 8651 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 8652 | CreateVertexAttribManager(client_ids[ii], 0); |
| 8653 | } |
| 8654 | } else { |
| 8655 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 8656 | |
| 8657 | glGenVertexArraysOES(n, service_ids.get()); |
| 8658 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 8659 | CreateVertexAttribManager(client_ids[ii], service_ids[ii]); |
| 8660 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8661 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 8662 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8663 | return true; |
| 8664 | } |
| 8665 | |
| 8666 | void GLES2DecoderImpl::DeleteVertexArraysOESHelper( |
| 8667 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8668 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 8669 | VertexAttribManager* vao = |
| 8670 | GetVertexAttribManager(client_ids[ii]); |
| 8671 | if (vao && !vao->IsDeleted()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8672 | if (state_.vertex_attrib_manager == vao) { |
| 8673 | state_.vertex_attrib_manager = default_vertex_attrib_manager_; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8674 | } |
| 8675 | RemoveVertexAttribManager(client_ids[ii]); |
| 8676 | } |
| 8677 | } |
| 8678 | } |
| 8679 | |
| 8680 | void GLES2DecoderImpl::DoBindVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8681 | VertexAttribManager* vao = NULL; |
| 8682 | GLuint service_id = 0; |
| 8683 | if (client_id != 0) { |
| 8684 | vao = GetVertexAttribManager(client_id); |
| 8685 | if (!vao) { |
| 8686 | // Unlike most Bind* methods, the spec explicitly states that VertexArray |
| 8687 | // only allows names that have been previously generated. As such, we do |
| 8688 | // not generate new names here. |
| 8689 | SetGLError(GL_INVALID_OPERATION, |
| 8690 | "glBindVertexArrayOES", "" |
| 8691 | "bad vertex array id."); |
| 8692 | current_decoder_error_ = error::kNoError; |
| 8693 | return; |
| 8694 | } else { |
| 8695 | service_id = vao->service_id(); |
| 8696 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8697 | } else { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 8698 | vao = default_vertex_attrib_manager_; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8699 | } |
| 8700 | |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 8701 | // Only set the VAO state if it's changed |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8702 | if (state_.vertex_attrib_manager != vao) { |
| 8703 | state_.vertex_attrib_manager = vao; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8704 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 8705 | EmulateVertexArrayState(); |
| 8706 | } else { |
| 8707 | glBindVertexArrayOES(service_id); |
| 8708 | } |
| 8709 | } |
| 8710 | } |
| 8711 | |
| 8712 | // Used when OES_vertex_array_object isn't natively supported |
| 8713 | void GLES2DecoderImpl::EmulateVertexArrayState() { |
| 8714 | // Setup the Vertex attribute state |
| 8715 | for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) { |
| 8716 | RestoreStateForAttrib(vv); |
| 8717 | } |
| 8718 | |
| 8719 | // Setup the element buffer |
| 8720 | BufferManager::BufferInfo* element_array_buffer = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8721 | state_.vertex_attrib_manager->element_array_buffer(); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 8722 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 8723 | element_array_buffer ? element_array_buffer->service_id() : 0); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8724 | } |
| 8725 | |
| 8726 | bool GLES2DecoderImpl::DoIsVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8727 | const VertexAttribManager* vao = |
| 8728 | GetVertexAttribManager(client_id); |
| 8729 | return vao && vao->IsValid() && !vao->IsDeleted(); |
| 8730 | } |
| 8731 | |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8732 | error::Error GLES2DecoderImpl::HandleCreateStreamTextureCHROMIUM( |
| 8733 | uint32 immediate_data_size, |
| 8734 | const gles2::CreateStreamTextureCHROMIUM& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8735 | if (!features().chromium_stream_texture) { |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8736 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8737 | "glOpenStreamTextureCHROMIUM", "" |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8738 | "not supported."); |
| 8739 | return error::kNoError; |
| 8740 | } |
| 8741 | |
| 8742 | uint32 client_id = c.client_id; |
| 8743 | typedef gles2::CreateStreamTextureCHROMIUM::Result Result; |
| 8744 | Result* result = GetSharedMemoryAs<Result*>( |
| 8745 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8746 | |
[email protected] | e508126 | 2012-01-05 23:09:03 | [diff] [blame] | 8747 | if (!result) |
| 8748 | return error::kOutOfBounds; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8749 | *result = GL_ZERO; |
| 8750 | TextureManager::TextureInfo* info = |
| 8751 | texture_manager()->GetTextureInfo(client_id); |
| 8752 | if (!info) { |
| 8753 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8754 | "glCreateStreamTextureCHROMIUM", "" |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8755 | "bad texture id."); |
| 8756 | return error::kNoError; |
| 8757 | } |
| 8758 | |
| 8759 | if (info->IsStreamTexture()) { |
| 8760 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8761 | "glCreateStreamTextureCHROMIUM", "" |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8762 | "is already a stream texture."); |
| 8763 | return error::kNoError; |
| 8764 | } |
| 8765 | |
| 8766 | if (info->target() && info->target() != GL_TEXTURE_EXTERNAL_OES) { |
| 8767 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8768 | "glCreateStreamTextureCHROMIUM", "" |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8769 | "is already bound to incompatible target."); |
| 8770 | return error::kNoError; |
| 8771 | } |
| 8772 | |
| 8773 | if (!stream_texture_manager_) |
| 8774 | return error::kInvalidArguments; |
| 8775 | |
| 8776 | GLuint object_id = stream_texture_manager_->CreateStreamTexture( |
| 8777 | info->service_id(), client_id); |
| 8778 | |
| 8779 | if (object_id) { |
| 8780 | info->SetStreamTexture(true); |
| 8781 | } else { |
| 8782 | SetGLError(GL_OUT_OF_MEMORY, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8783 | "glCreateStreamTextureCHROMIUM", "" |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8784 | "failed to create platform texture."); |
| 8785 | } |
| 8786 | |
| 8787 | *result = object_id; |
| 8788 | return error::kNoError; |
| 8789 | } |
| 8790 | |
| 8791 | error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( |
| 8792 | uint32 immediate_data_size, |
| 8793 | const gles2::DestroyStreamTextureCHROMIUM& c) { |
| 8794 | GLuint client_id = c.texture; |
| 8795 | TextureManager::TextureInfo* info = |
| 8796 | texture_manager()->GetTextureInfo(client_id); |
| 8797 | if (info && info->IsStreamTexture()) { |
| 8798 | if (!stream_texture_manager_) |
| 8799 | return error::kInvalidArguments; |
| 8800 | |
| 8801 | stream_texture_manager_->DestroyStreamTexture(info->service_id()); |
| 8802 | info->SetStreamTexture(false); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8803 | texture_manager()->SetInfoTarget(info, 0); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8804 | } else { |
| 8805 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8806 | "glDestroyStreamTextureCHROMIUM", "bad texture id."); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 8807 | } |
| 8808 | |
| 8809 | return error::kNoError; |
| 8810 | } |
| 8811 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8812 | #if defined(OS_MACOSX) |
| 8813 | void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { |
| 8814 | TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( |
| 8815 | texture_id); |
| 8816 | if (it != texture_to_io_surface_map_.end()) { |
| 8817 | // Found a previous IOSurface bound to this texture; release it. |
| 8818 | CFTypeRef surface = it->second; |
| 8819 | CFRelease(surface); |
| 8820 | texture_to_io_surface_map_.erase(it); |
| 8821 | } |
| 8822 | } |
| 8823 | #endif |
| 8824 | |
| 8825 | void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( |
| 8826 | GLenum target, GLsizei width, GLsizei height, |
| 8827 | GLuint io_surface_id, GLuint plane) { |
| 8828 | #if defined(OS_MACOSX) |
| 8829 | if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8830 | SetGLError( |
| 8831 | GL_INVALID_OPERATION, |
| 8832 | "glTexImageIOSurface2DCHROMIUM", "only supported on desktop GL."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8833 | return; |
| 8834 | } |
| 8835 | |
| 8836 | IOSurfaceSupport* surface_support = IOSurfaceSupport::Initialize(); |
| 8837 | if (!surface_support) { |
| 8838 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8839 | "glTexImageIOSurface2DCHROMIUM", "only supported on 10.6."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8840 | return; |
| 8841 | } |
| 8842 | |
| 8843 | if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 8844 | // This might be supported in the future, and if we could require |
| 8845 | // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we |
| 8846 | // could delete a lot of code. For now, perform strict validation so we |
| 8847 | // know what's going on. |
| 8848 | SetGLError( |
| 8849 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8850 | "glTexImageIOSurface2DCHROMIUM", |
| 8851 | "requires TEXTURE_RECTANGLE_ARB target"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8852 | return; |
| 8853 | } |
| 8854 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 8855 | // Default target might be conceptually valid, but disallow it to avoid |
| 8856 | // accidents. |
| 8857 | TextureManager::TextureInfo* info = GetTextureInfoForTargetUnlessDefault( |
| 8858 | target); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8859 | if (!info) { |
| 8860 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8861 | "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8862 | return; |
| 8863 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8864 | |
| 8865 | // Look up the new IOSurface. Note that because of asynchrony |
| 8866 | // between processes this might fail; during live resizing the |
| 8867 | // plugin process might allocate and release an IOSurface before |
| 8868 | // this process gets a chance to look it up. Hold on to any old |
| 8869 | // IOSurface in this case. |
| 8870 | CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); |
| 8871 | if (!surface) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8872 | SetGLError( |
| 8873 | GL_INVALID_OPERATION, |
| 8874 | "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8875 | return; |
| 8876 | } |
| 8877 | |
| 8878 | // Release any IOSurface previously bound to this texture. |
| 8879 | ReleaseIOSurfaceForTexture(info->service_id()); |
| 8880 | |
| 8881 | // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. |
| 8882 | texture_to_io_surface_map_.insert( |
| 8883 | std::make_pair(info->service_id(), surface)); |
| 8884 | |
| 8885 | CGLContextObj context = |
| 8886 | static_cast<CGLContextObj>(context_->GetHandle()); |
| 8887 | |
| 8888 | CGLError err = surface_support->CGLTexImageIOSurface2D( |
| 8889 | context, |
| 8890 | target, |
| 8891 | GL_RGBA, |
| 8892 | width, |
| 8893 | height, |
| 8894 | GL_BGRA, |
| 8895 | GL_UNSIGNED_INT_8_8_8_8_REV, |
| 8896 | surface, |
| 8897 | plane); |
| 8898 | |
| 8899 | if (err != kCGLNoError) { |
| 8900 | SetGLError( |
| 8901 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8902 | "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8903 | return; |
| 8904 | } |
| 8905 | |
| 8906 | texture_manager()->SetLevelInfo( |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8907 | info, target, 0, GL_RGBA, width, height, 1, 0, |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8908 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); |
| 8909 | |
| 8910 | #else |
| 8911 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8912 | "glTexImageIOSurface2DCHROMIUM", "not supported."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 8913 | #endif |
| 8914 | } |
| 8915 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8916 | static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { |
| 8917 | switch (internalformat) { |
| 8918 | case GL_RGB565: |
| 8919 | return GL_RGB; |
| 8920 | case GL_RGBA4: |
| 8921 | return GL_RGBA; |
| 8922 | case GL_RGB5_A1: |
| 8923 | return GL_RGBA; |
| 8924 | case GL_RGB8_OES: |
| 8925 | return GL_RGB; |
| 8926 | case GL_RGBA8_OES: |
| 8927 | return GL_RGBA; |
| 8928 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 8929 | return GL_LUMINANCE_ALPHA; |
| 8930 | case GL_LUMINANCE8_EXT: |
| 8931 | return GL_LUMINANCE; |
| 8932 | case GL_ALPHA8_EXT: |
| 8933 | return GL_ALPHA; |
| 8934 | case GL_RGBA32F_EXT: |
| 8935 | return GL_RGBA; |
| 8936 | case GL_RGB32F_EXT: |
| 8937 | return GL_RGB; |
| 8938 | case GL_ALPHA32F_EXT: |
| 8939 | return GL_ALPHA; |
| 8940 | case GL_LUMINANCE32F_EXT: |
| 8941 | return GL_LUMINANCE; |
| 8942 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 8943 | return GL_LUMINANCE_ALPHA; |
| 8944 | case GL_RGBA16F_EXT: |
| 8945 | return GL_RGBA; |
| 8946 | case GL_RGB16F_EXT: |
| 8947 | return GL_RGB; |
| 8948 | case GL_ALPHA16F_EXT: |
| 8949 | return GL_ALPHA; |
| 8950 | case GL_LUMINANCE16F_EXT: |
| 8951 | return GL_LUMINANCE; |
| 8952 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 8953 | return GL_LUMINANCE_ALPHA; |
| 8954 | case GL_BGRA8_EXT: |
| 8955 | return GL_BGRA_EXT; |
| 8956 | default: |
| 8957 | return GL_NONE; |
| 8958 | } |
| 8959 | } |
| 8960 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8961 | void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 8962 | GLenum target, GLuint source_id, GLuint dest_id, GLint level, |
| 8963 | GLenum internal_format) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8964 | TextureManager::TextureInfo* dest_info = GetTextureInfo(dest_id); |
| 8965 | TextureManager::TextureInfo* source_info = GetTextureInfo(source_id); |
| 8966 | |
| 8967 | if (!source_info || !dest_info) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8968 | SetGLError(GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8969 | return; |
| 8970 | } |
| 8971 | |
| 8972 | if (GL_TEXTURE_2D != target) { |
| 8973 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8974 | "glCopyTextureCHROMIUM", "invalid texture target"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8975 | return; |
| 8976 | } |
| 8977 | |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 8978 | if (dest_info->target() != GL_TEXTURE_2D || |
| 8979 | source_info->target() != GL_TEXTURE_2D) { |
| 8980 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8981 | "glCopyTextureCHROMIUM", "invalid texture target binding"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 8982 | return; |
| 8983 | } |
| 8984 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8985 | int source_width, source_height, dest_width, dest_height; |
| 8986 | if (!source_info->GetLevelSize(GL_TEXTURE_2D, 0, &source_width, |
| 8987 | &source_height)) { |
| 8988 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8989 | "glCopyTextureChromium", "source texture has no level 0"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8990 | return; |
| 8991 | } |
| 8992 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8993 | // Check that this type of texture is allowed. |
| 8994 | if (!texture_manager()->ValidForTarget(GL_TEXTURE_2D, level, source_width, |
| 8995 | source_height, 1)) { |
| 8996 | SetGLError(GL_INVALID_VALUE, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8997 | "glCopyTextureCHROMIUM", "Bad dimensions"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8998 | return; |
| 8999 | } |
| 9000 | |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 9001 | // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 9002 | // needed because it takes 10s of milliseconds to initialize. |
| 9003 | if (!copy_texture_CHROMIUM_.get()) { |
| 9004 | CopyRealGLErrorsToWrapper(); |
| 9005 | copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
| 9006 | copy_texture_CHROMIUM_->Initialize(); |
| 9007 | RestoreCurrentFramebufferBindings(); |
| 9008 | if (PeekGLError() != GL_NO_ERROR) |
| 9009 | return; |
| 9010 | } |
| 9011 | |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9012 | GLenum dest_type; |
| 9013 | GLenum dest_internal_format; |
| 9014 | bool dest_level_defined = dest_info->GetLevelSize(GL_TEXTURE_2D, level, |
| 9015 | &dest_width, |
| 9016 | &dest_height); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9017 | |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9018 | if (dest_level_defined) { |
| 9019 | dest_info->GetLevelType(GL_TEXTURE_2D, level, &dest_type, |
| 9020 | &dest_internal_format); |
| 9021 | } else { |
| 9022 | GLenum source_internal_format; |
| 9023 | source_info->GetLevelType(GL_TEXTURE_2D, 0, &dest_type, |
| 9024 | &source_internal_format); |
| 9025 | } |
| 9026 | |
| 9027 | // Resize the destination texture to the dimensions of the source texture. |
| 9028 | if (!dest_level_defined || dest_width != source_width || |
| 9029 | dest_height != source_height || |
| 9030 | dest_internal_format != internal_format) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9031 | // Ensure that the glTexImage2D succeeds. |
| 9032 | CopyRealGLErrorsToWrapper(); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9033 | glBindTexture(GL_TEXTURE_2D, dest_info->service_id()); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9034 | WrappedTexImage2D( |
| 9035 | GL_TEXTURE_2D, level, internal_format, source_width, source_height, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9036 | 0, internal_format, dest_type, NULL); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9037 | GLenum error = PeekGLError(); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9038 | if (error != GL_NO_ERROR) { |
| 9039 | RestoreCurrentTexture2DBindings(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9040 | return; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9041 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9042 | |
| 9043 | texture_manager()->SetLevelInfo( |
| 9044 | dest_info, GL_TEXTURE_2D, level, internal_format, source_width, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9045 | source_height, 1, 0, internal_format, dest_type, true); |
[email protected] | f702471 | 2012-05-15 21:30:25 | [diff] [blame] | 9046 | } else { |
| 9047 | texture_manager()->SetLevelCleared(dest_info, GL_TEXTURE_2D, level); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9048 | } |
| 9049 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 9050 | clear_state_dirty_ = true; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9051 | glViewport(0, 0, source_width, source_height); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9052 | copy_texture_CHROMIUM_->DoCopyTexture(target, source_info->service_id(), |
| 9053 | dest_info->service_id(), level, |
| 9054 | unpack_flip_y_, |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 9055 | unpack_premultiply_alpha_, |
| 9056 | unpack_unpremultiply_alpha_); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9057 | glViewport( |
| 9058 | state_.viewport_x, state_.viewport_y, |
| 9059 | state_.viewport_width, state_.viewport_height); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9060 | |
| 9061 | // Restore all of the state touched by the extension. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9062 | if (state_.current_program) |
| 9063 | glUseProgram(state_.current_program->service_id()); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9064 | else |
| 9065 | glUseProgram(0); |
| 9066 | |
| 9067 | RestoreCurrentFramebufferBindings(); |
| 9068 | RestoreCurrentTexture2DBindings(); |
| 9069 | RestoreStateForAttrib( |
| 9070 | CopyTextureCHROMIUMResourceManager::kVertexPositionAttrib); |
| 9071 | RestoreStateForAttrib( |
| 9072 | CopyTextureCHROMIUMResourceManager::kVertexTextureAttrib); |
| 9073 | |
| 9074 | ApplyDirtyState(); |
| 9075 | } |
| 9076 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9077 | static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
| 9078 | switch (internalformat) { |
| 9079 | case GL_RGB565: |
| 9080 | return GL_UNSIGNED_SHORT_5_6_5; |
| 9081 | case GL_RGBA4: |
| 9082 | return GL_UNSIGNED_SHORT_4_4_4_4; |
| 9083 | case GL_RGB5_A1: |
| 9084 | return GL_UNSIGNED_SHORT_5_5_5_1; |
| 9085 | case GL_RGB8_OES: |
| 9086 | return GL_UNSIGNED_BYTE; |
| 9087 | case GL_RGBA8_OES: |
| 9088 | return GL_UNSIGNED_BYTE; |
| 9089 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 9090 | return GL_UNSIGNED_BYTE; |
| 9091 | case GL_LUMINANCE8_EXT: |
| 9092 | return GL_UNSIGNED_BYTE; |
| 9093 | case GL_ALPHA8_EXT: |
| 9094 | return GL_UNSIGNED_BYTE; |
| 9095 | case GL_RGBA32F_EXT: |
| 9096 | return GL_FLOAT; |
| 9097 | case GL_RGB32F_EXT: |
| 9098 | return GL_FLOAT; |
| 9099 | case GL_ALPHA32F_EXT: |
| 9100 | return GL_FLOAT; |
| 9101 | case GL_LUMINANCE32F_EXT: |
| 9102 | return GL_FLOAT; |
| 9103 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 9104 | return GL_FLOAT; |
| 9105 | case GL_RGBA16F_EXT: |
| 9106 | return GL_HALF_FLOAT_OES; |
| 9107 | case GL_RGB16F_EXT: |
| 9108 | return GL_HALF_FLOAT_OES; |
| 9109 | case GL_ALPHA16F_EXT: |
| 9110 | return GL_HALF_FLOAT_OES; |
| 9111 | case GL_LUMINANCE16F_EXT: |
| 9112 | return GL_HALF_FLOAT_OES; |
| 9113 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 9114 | return GL_HALF_FLOAT_OES; |
| 9115 | case GL_BGRA8_EXT: |
| 9116 | return GL_UNSIGNED_BYTE; |
| 9117 | default: |
| 9118 | return GL_NONE; |
| 9119 | } |
| 9120 | } |
| 9121 | |
| 9122 | void GLES2DecoderImpl::DoTexStorage2DEXT( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 9123 | GLenum target, |
| 9124 | GLint levels, |
| 9125 | GLenum internal_format, |
| 9126 | GLsizei width, |
| 9127 | GLsizei height) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 9128 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT"); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 9129 | if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9130 | TextureManager::ComputeMipMapCount(width, height, 1) < levels) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9131 | SetGLError( |
| 9132 | GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9133 | return; |
| 9134 | } |
| 9135 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 9136 | if (!info) { |
| 9137 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9138 | "glTexStorage2DEXT", "unknown texture for target"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9139 | return; |
| 9140 | } |
| 9141 | if (info->IsAttachedToFramebuffer()) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 9142 | clear_state_dirty_ = true; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9143 | } |
| 9144 | if (info->IsImmutable()) { |
| 9145 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9146 | "glTexStorage2DEXT", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9147 | return; |
| 9148 | } |
| 9149 | CopyRealGLErrorsToWrapper(); |
[email protected] | f0e6a34f | 2012-01-04 20:53:40 | [diff] [blame] | 9150 | glTexStorage2DEXT(target, levels, GetTexInternalFormat(internal_format), |
| 9151 | width, height); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9152 | GLenum error = PeekGLError(); |
| 9153 | if (error == GL_NO_ERROR) { |
| 9154 | GLenum format = ExtractFormatFromStorageFormat(internal_format); |
| 9155 | GLenum type = ExtractTypeFromStorageFormat(internal_format); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9156 | GLsizei level_width = width; |
| 9157 | GLsizei level_height = height; |
| 9158 | for (int ii = 0; ii < levels; ++ii) { |
| 9159 | texture_manager()->SetLevelInfo( |
[email protected] | e071ea7 | 2012-11-26 22:29:59 | [diff] [blame^] | 9160 | info, target, ii, format, level_width, level_height, 1, 0, format, |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 9161 | type, false); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9162 | level_width = std::max(1, level_width >> 1); |
| 9163 | level_height = std::max(1, level_height >> 1); |
| 9164 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9165 | info->SetImmutable(true); |
| 9166 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9167 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9168 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9169 | error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( |
| 9170 | uint32 immediate_data_size, const gles2::GenMailboxCHROMIUM& c) { |
| 9171 | MailboxName name; |
| 9172 | mailbox_manager()->GenerateMailboxName(&name); |
| 9173 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 9174 | Bucket* bucket = CreateBucket(bucket_id); |
| 9175 | |
| 9176 | bucket->SetSize(GL_MAILBOX_SIZE_CHROMIUM); |
| 9177 | bucket->SetData(&name, 0, GL_MAILBOX_SIZE_CHROMIUM); |
| 9178 | |
| 9179 | return error::kNoError; |
| 9180 | } |
| 9181 | |
| 9182 | void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, |
| 9183 | const GLbyte* mailbox) { |
| 9184 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 9185 | if (!info) { |
| 9186 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9187 | "glProduceTextureCHROMIUM", "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9188 | return; |
| 9189 | } |
| 9190 | |
| 9191 | TextureDefinition* definition = texture_manager()->Save(info); |
| 9192 | if (!definition) { |
| 9193 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9194 | "glProduceTextureCHROMIUM", "invalid texture"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9195 | return; |
| 9196 | } |
| 9197 | |
| 9198 | if (!group_->mailbox_manager()->ProduceTexture( |
| 9199 | target, |
| 9200 | *reinterpret_cast<const MailboxName*>(mailbox), |
| 9201 | definition, |
| 9202 | texture_manager())) { |
| 9203 | bool success = texture_manager()->Restore(info, definition); |
| 9204 | DCHECK(success); |
| 9205 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9206 | "glProduceTextureCHROMIUM", "invalid mailbox name"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9207 | return; |
| 9208 | } |
| 9209 | |
| 9210 | BindAndApplyTextureParameters(info); |
| 9211 | } |
| 9212 | |
| 9213 | void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, |
| 9214 | const GLbyte* mailbox) { |
| 9215 | TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); |
| 9216 | if (!info) { |
| 9217 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9218 | "glConsumeTextureCHROMIUM", "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9219 | return; |
| 9220 | } |
| 9221 | |
| 9222 | scoped_ptr<TextureDefinition> definition( |
| 9223 | group_->mailbox_manager()->ConsumeTexture( |
| 9224 | target, |
| 9225 | *reinterpret_cast<const MailboxName*>(mailbox))); |
| 9226 | if (!definition.get()) { |
| 9227 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9228 | "glConsumeTextureCHROMIUM", "invalid mailbox name"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9229 | return; |
| 9230 | } |
| 9231 | |
| 9232 | if (!texture_manager()->Restore(info, definition.release())) { |
| 9233 | SetGLError(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9234 | "glConsumeTextureCHROMIUM", "invalid texture"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9235 | return; |
| 9236 | } |
| 9237 | |
| 9238 | BindAndApplyTextureParameters(info); |
| 9239 | } |
| 9240 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 9241 | void GLES2DecoderImpl::DoInsertEventMarkerEXT( |
| 9242 | GLsizei length, const GLchar* marker) { |
| 9243 | if (!marker) { |
| 9244 | marker = ""; |
| 9245 | } |
| 9246 | debug_marker_manager_.SetMarker( |
| 9247 | length ? std::string(marker, length) : std::string(marker)); |
| 9248 | } |
| 9249 | |
| 9250 | void GLES2DecoderImpl::DoPushGroupMarkerEXT( |
| 9251 | GLsizei length, const GLchar* marker) { |
| 9252 | if (!marker) { |
| 9253 | marker = ""; |
| 9254 | } |
| 9255 | debug_marker_manager_.PushGroup( |
| 9256 | length ? std::string(marker, length) : std::string(marker)); |
| 9257 | } |
| 9258 | |
| 9259 | void GLES2DecoderImpl::DoPopGroupMarkerEXT(void) { |
| 9260 | debug_marker_manager_.PopGroup(); |
| 9261 | } |
| 9262 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 9263 | void GLES2DecoderImpl::DoBindTexImage2DCHROMIUM( |
| 9264 | GLenum target, GLint image_id) { |
| 9265 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM"); |
| 9266 | if (target != GL_TEXTURE_2D) { |
| 9267 | // This might be supported in the future. |
| 9268 | SetGLError( |
| 9269 | GL_INVALID_OPERATION, |
| 9270 | "glBindTexImage2DCHROMIUM", "requires TEXTURE_2D target"); |
| 9271 | return; |
| 9272 | } |
| 9273 | |
| 9274 | // Default target might be conceptually valid, but disallow it to avoid |
| 9275 | // accidents. |
| 9276 | TextureManager::TextureInfo* info = GetTextureInfoForTargetUnlessDefault( |
| 9277 | target); |
| 9278 | if (!info) { |
| 9279 | SetGLError(GL_INVALID_OPERATION, |
| 9280 | "glBindTexImage2DCHROMIUM", "no texture bound"); |
| 9281 | return; |
| 9282 | } |
| 9283 | |
| 9284 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 9285 | if (!gl_image) { |
| 9286 | SetGLError(GL_INVALID_OPERATION, |
| 9287 | "glBindTexImage2DCHROMIUM", |
| 9288 | "no image found with the given ID"); |
| 9289 | return; |
| 9290 | } |
| 9291 | |
| 9292 | if (!gl_image->BindTexImage()) { |
| 9293 | SetGLError(GL_INVALID_OPERATION, |
| 9294 | "glBindTexImage2DCHROMIUM", |
| 9295 | "fail to bind image with the given ID"); |
| 9296 | return; |
| 9297 | } |
| 9298 | |
| 9299 | gfx::Size size = gl_image->GetSize(); |
| 9300 | texture_manager()->SetLevelInfo( |
| 9301 | info, target, 0, GL_RGBA, size.width(), size.height(), 1, 0, |
| 9302 | GL_RGBA, GL_UNSIGNED_BYTE, true); |
| 9303 | texture_manager()->SetLevelImage(info, target, 0, gl_image); |
| 9304 | } |
| 9305 | |
| 9306 | void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( |
| 9307 | GLenum target, GLint image_id) { |
| 9308 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); |
| 9309 | if (target != GL_TEXTURE_2D) { |
| 9310 | // This might be supported in the future. |
| 9311 | SetGLError( |
| 9312 | GL_INVALID_OPERATION, |
| 9313 | "glReleaseTexImage2DCHROMIUM", "requires TEXTURE_2D target"); |
| 9314 | return; |
| 9315 | } |
| 9316 | |
| 9317 | // Default target might be conceptually valid, but disallow it to avoid |
| 9318 | // accidents. |
| 9319 | TextureManager::TextureInfo* info = GetTextureInfoForTargetUnlessDefault( |
| 9320 | target); |
| 9321 | if (!info) { |
| 9322 | SetGLError(GL_INVALID_OPERATION, |
| 9323 | "glReleaseTexImage2DCHROMIUM", "no texture bound"); |
| 9324 | return; |
| 9325 | } |
| 9326 | |
| 9327 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 9328 | if (!gl_image) { |
| 9329 | SetGLError(GL_INVALID_OPERATION, |
| 9330 | "glReleaseTexImage2DCHROMIUM", |
| 9331 | "no image found with the given ID"); |
| 9332 | return; |
| 9333 | } |
| 9334 | |
| 9335 | // Do nothing when image is not currently bound. |
| 9336 | if (info->GetLevelImage(target, 0) != gl_image) |
| 9337 | return; |
| 9338 | |
| 9339 | gl_image->ReleaseTexImage(); |
| 9340 | |
| 9341 | texture_manager()->SetLevelInfo( |
| 9342 | info, target, 0, GL_RGBA, 0, 0, 1, 0, |
| 9343 | GL_RGBA, GL_UNSIGNED_BYTE, false); |
| 9344 | } |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 9345 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 9346 | error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( |
| 9347 | uint32 immediate_data_size, const gles2::TraceBeginCHROMIUM& c) { |
| 9348 | Bucket* bucket = GetBucket(c.bucket_id); |
| 9349 | if (!bucket || bucket->size() == 0) { |
| 9350 | return error::kInvalidArguments; |
| 9351 | } |
| 9352 | std::string command_name; |
| 9353 | if (!bucket->GetAsString(&command_name)) { |
| 9354 | return error::kInvalidArguments; |
| 9355 | } |
| 9356 | |
| 9357 | linked_ptr<GPUTrace> trace(new GPUTrace(command_name)); |
| 9358 | trace->EnableStartTrace(); |
| 9359 | gpu_trace_stack_.push(trace); |
| 9360 | |
| 9361 | return error::kNoError; |
| 9362 | } |
| 9363 | |
| 9364 | void GLES2DecoderImpl::DoTraceEndCHROMIUM() { |
| 9365 | if (gpu_trace_stack_.empty()) { |
| 9366 | SetGLError(GL_INVALID_OPERATION, |
| 9367 | "glTraceEndCHROMIUM", "no trace begin found"); |
| 9368 | return; |
| 9369 | } |
| 9370 | |
| 9371 | linked_ptr<GPUTrace> trace = gpu_trace_stack_.top(); |
| 9372 | trace->EnableEndTrace(); |
| 9373 | gpu_trace_stack_.pop(); |
| 9374 | } |
| 9375 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9376 | // Include the auto-generated part of this file. We split this because it means |
| 9377 | // we can easily edit the non-auto generated parts right here in this file |
| 9378 | // instead of having to edit some template or the code generator. |
| 9379 | #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 9380 | |
| 9381 | } // namespace gles2 |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 9382 | } // namespace gpu |