[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] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 17 | #include "base/bind.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 18 | #include "base/command_line.h" |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 19 | #include "base/debug/trace_event.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 21 | #include "base/strings/string_number_conversions.h" |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 22 | #include "build/build_config.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 23 | #define GLES2_GPU_SERVICE 1 |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 24 | #include "gpu/command_buffer/common/debug_marker_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 25 | #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 26 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 27 | #include "gpu/command_buffer/common/id_allocator.h" |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 28 | #include "gpu/command_buffer/common/mailbox.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 29 | #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
| 30 | #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 31 | #include "gpu/command_buffer/service/buffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 32 | #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 33 | #include "gpu/command_buffer/service/context_group.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 34 | #include "gpu/command_buffer/service/context_state.h" |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 35 | #include "gpu/command_buffer/service/error_state.h" |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 36 | #include "gpu/command_buffer/service/feature_info.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 37 | #include "gpu/command_buffer/service/framebuffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 38 | #include "gpu/command_buffer/service/gl_utils.h" |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 39 | #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 40 | #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 41 | #include "gpu/command_buffer/service/gpu_state_tracer.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 42 | #include "gpu/command_buffer/service/gpu_switches.h" |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 43 | #include "gpu/command_buffer/service/gpu_tracer.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] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 55 | #include "gpu/command_buffer/service/texture_manager.h" |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 56 | #include "gpu/command_buffer/service/vertex_array_manager.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 57 | #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 58 | #include "ui/gl/gl_bindings.h" |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 59 | #include "ui/gl/gl_fence.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] | 423e644f | 2013-06-19 00:48:27 | [diff] [blame] | 63 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 64 | #if defined(OS_MACOSX) |
[email protected] | 423e644f | 2013-06-19 00:48:27 | [diff] [blame] | 65 | #include "ui/gl/io_surface_support_mac.h" |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 66 | #endif |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 67 | |
[email protected] | 6eb77535 | 2013-08-27 05:57:16 | [diff] [blame] | 68 | #if defined(OS_WIN) |
| 69 | #include "base/win/win_util.h" |
| 70 | #endif |
| 71 | |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 72 | // TODO(zmo): we can't include "City.h" due to type def conflicts. |
| 73 | extern uint64 CityHash64(const char*, size_t); |
| 74 | |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 75 | namespace gpu { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 76 | namespace gles2 { |
| 77 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 78 | namespace { |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 79 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 80 | static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 81 | static const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 82 | static const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 83 | |
[email protected] | 3d944a8 | 2013-02-12 19:09:02 | [diff] [blame] | 84 | #if !defined(ANGLE_SH_VERSION) || ANGLE_SH_VERSION < 108 |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 85 | khronos_uint64_t CityHashForAngle(const char* name, unsigned int len) { |
| 86 | return static_cast<khronos_uint64_t>( |
| 87 | CityHash64(name, static_cast<size_t>(len))); |
| 88 | } |
[email protected] | 3d944a8 | 2013-02-12 19:09:02 | [diff] [blame] | 89 | #endif |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 90 | |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 91 | static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, |
| 92 | GLint rangeMax, |
| 93 | GLint precision) { |
| 94 | return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); |
| 95 | } |
| 96 | |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 97 | static void GetShaderPrecisionFormatImpl(GLenum shader_type, |
| 98 | GLenum precision_type, |
| 99 | GLint *range, GLint *precision) { |
| 100 | switch (precision_type) { |
| 101 | case GL_LOW_INT: |
| 102 | case GL_MEDIUM_INT: |
| 103 | case GL_HIGH_INT: |
| 104 | // These values are for a 32-bit twos-complement integer format. |
| 105 | range[0] = 31; |
| 106 | range[1] = 30; |
| 107 | *precision = 0; |
| 108 | break; |
| 109 | case GL_LOW_FLOAT: |
| 110 | case GL_MEDIUM_FLOAT: |
| 111 | case GL_HIGH_FLOAT: |
| 112 | // These values are for an IEEE single-precision floating-point format. |
| 113 | range[0] = 127; |
| 114 | range[1] = 127; |
| 115 | *precision = 23; |
| 116 | break; |
| 117 | default: |
| 118 | NOTREACHED(); |
| 119 | break; |
| 120 | } |
| 121 | |
[email protected] | 8af4d5e | 2013-03-15 23:55:33 | [diff] [blame] | 122 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
| 123 | gfx::g_driver_gl.fn.glGetShaderPrecisionFormatFn) { |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 124 | // This function is sometimes defined even though it's really just |
| 125 | // a stub, so we need to set range and precision as if it weren't |
| 126 | // defined before calling it. |
[email protected] | 501b5740 | 2013-03-14 22:21:44 | [diff] [blame] | 127 | // On Mac OS with some GPUs, calling this generates a |
| 128 | // GL_INVALID_OPERATION error. Avoid calling it on non-GLES2 |
| 129 | // platforms. |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 130 | glGetShaderPrecisionFormat(shader_type, precision_type, |
| 131 | range, precision); |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 132 | |
| 133 | // TODO(brianderson): Make the following official workarounds. |
| 134 | |
| 135 | // Some drivers have bugs where they report the ranges as a negative number. |
| 136 | // Taking the absolute value here shouldn't hurt because negative numbers |
| 137 | // aren't expected anyway. |
| 138 | range[0] = abs(range[0]); |
| 139 | range[1] = abs(range[1]); |
| 140 | |
| 141 | // If the driver reports a precision for highp float that isn't actually |
| 142 | // highp, don't pretend like it's supported because shader compilation will |
| 143 | // fail anyway. |
| 144 | if (precision_type == GL_HIGH_FLOAT && |
| 145 | !PrecisionMeetsSpecForHighpFloat(range[0], range[1], *precision)) { |
| 146 | range[0] = 0; |
| 147 | range[1] = 0; |
| 148 | *precision = 0; |
| 149 | } |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 153 | } // namespace |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 154 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 155 | class GLES2DecoderImpl; |
| 156 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 157 | // Local versions of the SET_GL_ERROR macros |
| 158 | #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 159 | ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 160 | #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 161 | ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \ |
| 162 | function_name, value, label) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 163 | #define LOCAL_SET_GL_ERROR_INVALID_PARAM(error, function_name, pname) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 164 | ERRORSTATE_SET_GL_ERROR_INVALID_PARAM(state_.GetErrorState(), error, \ |
| 165 | function_name, pname) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 166 | #define LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 167 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(state_.GetErrorState(), \ |
| 168 | function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 169 | #define LOCAL_PEEK_GL_ERROR(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 170 | ERRORSTATE_PEEK_GL_ERROR(state_.GetErrorState(), function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 171 | #define LOCAL_CLEAR_REAL_GL_ERRORS(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 172 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(state_.GetErrorState(), function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 173 | #define LOCAL_PERFORMANCE_WARNING(msg) \ |
| 174 | PerformanceWarning(__FILE__, __LINE__, msg) |
| 175 | #define LOCAL_RENDER_WARNING(msg) \ |
| 176 | RenderWarning(__FILE__, __LINE__, msg) |
| 177 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 178 | // Check that certain assumptions the code makes are true. There are places in |
| 179 | // the code where shared memory is passed direclty to GL. Example, glUniformiv, |
| 180 | // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe |
| 181 | // a few others) are 32bits. If they are not 32bits the code will have to change |
| 182 | // to call those GL functions with service side memory and then copy the results |
| 183 | // to shared memory, converting the sizes. |
| 184 | COMPILE_ASSERT(sizeof(GLint) == sizeof(uint32), // NOLINT |
| 185 | GLint_not_same_size_as_uint32); |
| 186 | COMPILE_ASSERT(sizeof(GLsizei) == sizeof(uint32), // NOLINT |
| 187 | GLint_not_same_size_as_uint32); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 188 | COMPILE_ASSERT(sizeof(GLfloat) == sizeof(float), // NOLINT |
| 189 | GLfloat_not_same_size_as_float); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 190 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 191 | // TODO(kbr): the use of this anonymous namespace core dumps the |
| 192 | // linker on Mac OS X 10.6 when the symbol ordering file is used |
| 193 | // namespace { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 194 | |
| 195 | // Returns the address of the first byte after a struct. |
| 196 | template <typename T> |
| 197 | const void* AddressAfterStruct(const T& pod) { |
| 198 | return reinterpret_cast<const uint8*>(&pod) + sizeof(pod); |
| 199 | } |
| 200 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 201 | // Returns the address of the frst byte after the struct or NULL if size > |
| 202 | // immediate_data_size. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 203 | template <typename RETURN_TYPE, typename COMMAND_TYPE> |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 204 | RETURN_TYPE GetImmediateDataAs(const COMMAND_TYPE& pod, |
| 205 | uint32 size, |
| 206 | uint32 immediate_data_size) { |
| 207 | return (size <= immediate_data_size) ? |
| 208 | static_cast<RETURN_TYPE>(const_cast<void*>(AddressAfterStruct(pod))) : |
| 209 | NULL; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 210 | } |
| 211 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 212 | // Computes the data size for certain gl commands like glUniform. |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 213 | bool ComputeDataSize( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 214 | GLuint count, |
| 215 | size_t size, |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 216 | unsigned int elements_per_unit, |
| 217 | uint32* dst) { |
| 218 | uint32 value; |
| 219 | if (!SafeMultiplyUint32(count, size, &value)) { |
| 220 | return false; |
| 221 | } |
| 222 | if (!SafeMultiplyUint32(value, elements_per_unit, &value)) { |
| 223 | return false; |
| 224 | } |
| 225 | *dst = value; |
| 226 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | // A struct to hold info about each command. |
| 230 | struct CommandInfo { |
| 231 | int arg_flags; // How to handle the arguments for this command |
| 232 | int arg_count; // How many arguments are expected for this command. |
| 233 | }; |
| 234 | |
| 235 | // A table of CommandInfo for all the commands. |
| 236 | const CommandInfo g_command_info[] = { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 237 | #define GLES2_CMD_OP(name) { \ |
| 238 | cmds::name::kArgFlags, \ |
| 239 | sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 240 | |
| 241 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 242 | |
| 243 | #undef GLES2_CMD_OP |
| 244 | }; |
| 245 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 246 | // Return true if a character belongs to the ASCII subset as defined in |
| 247 | // GLSL ES 1.0 spec section 3.1. |
| 248 | static bool CharacterIsValidForGLES(unsigned char c) { |
| 249 | // Printing characters are valid except " $ ` @ \ ' DEL. |
| 250 | if (c >= 32 && c <= 126 && |
| 251 | c != '"' && |
| 252 | c != '$' && |
| 253 | c != '`' && |
| 254 | c != '@' && |
| 255 | c != '\\' && |
| 256 | c != '\'') { |
| 257 | return true; |
| 258 | } |
| 259 | // Horizontal tab, line feed, vertical tab, form feed, carriage return |
| 260 | // are also valid. |
| 261 | if (c >= 9 && c <= 13) { |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | static bool StringIsValidForGLES(const char* str) { |
| 269 | for (; *str; ++str) { |
| 270 | if (!CharacterIsValidForGLES(*str)) { |
| 271 | return false; |
| 272 | } |
| 273 | } |
| 274 | return true; |
| 275 | } |
| 276 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 277 | // Wrapper for glEnable/glDisable that doesn't suck. |
| 278 | static void EnableDisable(GLenum pname, bool enable) { |
| 279 | if (enable) { |
| 280 | glEnable(pname); |
| 281 | } else { |
| 282 | glDisable(pname); |
| 283 | } |
| 284 | } |
| 285 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 286 | // This class prevents any GL errors that occur when it is in scope from |
| 287 | // being reported to the client. |
| 288 | class ScopedGLErrorSuppressor { |
| 289 | public: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 290 | explicit ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 291 | const char* function_name, ErrorState* error_state); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 292 | ~ScopedGLErrorSuppressor(); |
| 293 | private: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 294 | const char* function_name_; |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 295 | ErrorState* error_state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 296 | DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); |
| 297 | }; |
| 298 | |
| 299 | // Temporarily changes a decoder's bound 2D texture and restore it when this |
| 300 | // object goes out of scope. Also temporarily switches to using active texture |
| 301 | // unit zero in case the client has changed that to something invalid. |
| 302 | class ScopedTexture2DBinder { |
| 303 | public: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 304 | ScopedTexture2DBinder(ContextState* state, GLuint id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 305 | ~ScopedTexture2DBinder(); |
| 306 | |
| 307 | private: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 308 | ContextState* state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 309 | DISALLOW_COPY_AND_ASSIGN(ScopedTexture2DBinder); |
| 310 | }; |
| 311 | |
| 312 | // Temporarily changes a decoder's bound render buffer and restore it when this |
| 313 | // object goes out of scope. |
| 314 | class ScopedRenderBufferBinder { |
| 315 | public: |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 316 | ScopedRenderBufferBinder(ContextState* state, GLuint id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 317 | ~ScopedRenderBufferBinder(); |
| 318 | |
| 319 | private: |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 320 | ContextState* state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 321 | DISALLOW_COPY_AND_ASSIGN(ScopedRenderBufferBinder); |
| 322 | }; |
| 323 | |
| 324 | // Temporarily changes a decoder's bound frame buffer and restore it when this |
| 325 | // object goes out of scope. |
| 326 | class ScopedFrameBufferBinder { |
| 327 | public: |
| 328 | ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
| 329 | ~ScopedFrameBufferBinder(); |
| 330 | |
| 331 | private: |
| 332 | GLES2DecoderImpl* decoder_; |
| 333 | DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); |
| 334 | }; |
| 335 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 336 | // Temporarily changes a decoder's bound frame buffer to a resolved version of |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 337 | // the multisampled offscreen render buffer if that buffer is multisampled, and, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 338 | // if it is bound or enforce_internal_framebuffer is true. If internal is |
| 339 | // true, the resolved framebuffer is not visible to the parent. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 340 | class ScopedResolvedFrameBufferBinder { |
| 341 | public: |
[email protected] | e7e3803 | 2011-07-26 17:25:25 | [diff] [blame] | 342 | ScopedResolvedFrameBufferBinder(GLES2DecoderImpl* decoder, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 343 | bool enforce_internal_framebuffer, |
| 344 | bool internal); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 345 | ~ScopedResolvedFrameBufferBinder(); |
| 346 | |
| 347 | private: |
| 348 | GLES2DecoderImpl* decoder_; |
| 349 | bool resolve_and_bind_; |
| 350 | DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); |
| 351 | }; |
| 352 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 353 | // Encapsulates an OpenGL texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 354 | class BackTexture { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 355 | public: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 356 | explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 357 | ~BackTexture(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 358 | |
| 359 | // Create a new render texture. |
| 360 | void Create(); |
| 361 | |
| 362 | // Set the initial size and format of a render texture or resize it. |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 363 | bool AllocateStorage(const gfx::Size& size, GLenum format, bool zero); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 364 | |
| 365 | // Copy the contents of the currently bound frame buffer. |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 366 | void Copy(const gfx::Size& size, GLenum format); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 367 | |
| 368 | // Destroy the render texture. This must be explicitly called before |
| 369 | // destroying this object. |
| 370 | void Destroy(); |
| 371 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 372 | // Invalidate the texture. This can be used when a context is lost and it is |
| 373 | // not possible to make it current in order to free the resource. |
| 374 | void Invalidate(); |
| 375 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 376 | GLuint id() const { |
| 377 | return id_; |
| 378 | } |
| 379 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 380 | gfx::Size size() const { |
| 381 | return size_; |
| 382 | } |
| 383 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 384 | size_t estimated_size() const { |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 385 | return memory_tracker_.GetMemRepresented(); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 386 | } |
| 387 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 388 | private: |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 389 | MemoryTypeTracker memory_tracker_; |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 390 | ContextState* state_; |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 391 | size_t bytes_allocated_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 392 | GLuint id_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 393 | gfx::Size size_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 394 | DISALLOW_COPY_AND_ASSIGN(BackTexture); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 395 | }; |
| 396 | |
| 397 | // Encapsulates an OpenGL render buffer of any format. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 398 | class BackRenderbuffer { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 399 | public: |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 400 | explicit BackRenderbuffer( |
| 401 | RenderbufferManager* renderbuffer_manager, |
| 402 | MemoryTracker* memory_tracker, |
| 403 | ContextState* state); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 404 | ~BackRenderbuffer(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 405 | |
| 406 | // Create a new render buffer. |
| 407 | void Create(); |
| 408 | |
| 409 | // Set the initial size and format of a render buffer or resize it. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 410 | bool AllocateStorage(const gfx::Size& size, GLenum format, GLsizei samples); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 411 | |
| 412 | // Destroy the render buffer. This must be explicitly called before destroying |
| 413 | // this object. |
| 414 | void Destroy(); |
| 415 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 416 | // Invalidate the render buffer. This can be used when a context is lost and |
| 417 | // it is not possible to make it current in order to free the resource. |
| 418 | void Invalidate(); |
| 419 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 420 | GLuint id() const { |
| 421 | return id_; |
| 422 | } |
| 423 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 424 | size_t estimated_size() const { |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 425 | return memory_tracker_.GetMemRepresented(); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 426 | } |
| 427 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 428 | private: |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 429 | RenderbufferManager* renderbuffer_manager_; |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 430 | MemoryTypeTracker memory_tracker_; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 431 | ContextState* state_; |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 432 | size_t bytes_allocated_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 433 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 434 | DISALLOW_COPY_AND_ASSIGN(BackRenderbuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 435 | }; |
| 436 | |
| 437 | // Encapsulates an OpenGL frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 438 | class BackFramebuffer { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 439 | public: |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 440 | explicit BackFramebuffer(GLES2DecoderImpl* decoder); |
| 441 | ~BackFramebuffer(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 442 | |
| 443 | // Create a new frame buffer. |
| 444 | void Create(); |
| 445 | |
| 446 | // Attach a color render buffer to a frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 447 | void AttachRenderTexture(BackTexture* texture); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 448 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 449 | // Attach a render buffer to a frame buffer. Note that this unbinds any |
| 450 | // currently bound frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 451 | void AttachRenderBuffer(GLenum target, BackRenderbuffer* render_buffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 452 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 453 | // Destroy the frame buffer. This must be explicitly called before destroying |
| 454 | // this object. |
| 455 | void Destroy(); |
| 456 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 457 | // Invalidate the frame buffer. This can be used when a context is lost and it |
| 458 | // is not possible to make it current in order to free the resource. |
| 459 | void Invalidate(); |
| 460 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 461 | // See glCheckFramebufferStatusEXT. |
| 462 | GLenum CheckStatus(); |
| 463 | |
| 464 | GLuint id() const { |
| 465 | return id_; |
| 466 | } |
| 467 | |
| 468 | private: |
| 469 | GLES2DecoderImpl* decoder_; |
| 470 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 471 | DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 472 | }; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 473 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 474 | struct FenceCallback { |
| 475 | explicit FenceCallback() |
| 476 | : fence(gfx::GLFence::Create()) { |
| 477 | DCHECK(fence); |
| 478 | } |
| 479 | void AddCallback(base::Closure cb) { |
| 480 | callbacks.push_back(cb); |
| 481 | } |
| 482 | std::vector<base::Closure> callbacks; |
| 483 | scoped_ptr<gfx::GLFence> fence; |
| 484 | }; |
| 485 | |
| 486 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 487 | // } // anonymous namespace. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 488 | |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 489 | bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, |
| 490 | uint32* service_texture_id) { |
| 491 | return false; |
| 492 | } |
| 493 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 494 | GLES2Decoder::GLES2Decoder() |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 495 | : initialized_(false), |
| 496 | debug_(false), |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 497 | log_commands_(false) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 498 | } |
| 499 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 500 | GLES2Decoder::~GLES2Decoder() { |
| 501 | } |
| 502 | |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 503 | bool GLES2Decoder::testing_force_is_angle_; |
| 504 | |
| 505 | void GLES2Decoder::set_testing_force_is_angle(bool force) { |
| 506 | testing_force_is_angle_ = force; |
| 507 | } |
| 508 | |
| 509 | bool GLES2Decoder::IsAngle() { |
| 510 | #if defined(OS_WIN) |
| 511 | return testing_force_is_angle_ || |
| 512 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2; |
| 513 | #else |
| 514 | return testing_force_is_angle_; |
| 515 | #endif |
| 516 | } |
| 517 | |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 518 | // This class implements GLES2Decoder so we don't have to expose all the GLES2 |
| 519 | // cmd stuff to outside this class. |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 520 | class GLES2DecoderImpl : public GLES2Decoder, |
| 521 | public FramebufferManager::TextureDetachObserver { |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 522 | public: |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 523 | // Used by PrepForSetUniformByLocation to validate types. |
| 524 | struct BaseUniformInfo { |
| 525 | const GLenum* const valid_types; |
| 526 | size_t num_valid_types; |
| 527 | }; |
| 528 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 529 | explicit GLES2DecoderImpl(ContextGroup* group); |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 530 | virtual ~GLES2DecoderImpl(); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 531 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 532 | // Overridden from AsyncAPIInterface. |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 533 | virtual Error DoCommand(unsigned int command, |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 534 | unsigned int arg_count, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 535 | const void* args) OVERRIDE; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 536 | |
| 537 | // Overridden from AsyncAPIInterface. |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 538 | virtual const char* GetCommandName(unsigned int command_id) const OVERRIDE; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 539 | |
| 540 | // Overridden from GLES2Decoder. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 541 | virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
| 542 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 543 | bool offscreen, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 544 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 545 | const DisallowedFeatures& disallowed_features, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 546 | const std::vector<int32>& attribs) OVERRIDE; |
| 547 | virtual void Destroy(bool have_context) OVERRIDE; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 548 | virtual void SetSurface( |
| 549 | const scoped_refptr<gfx::GLSurface>& surface) OVERRIDE; |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 550 | virtual bool ProduceFrontBuffer(const Mailbox& mailbox) OVERRIDE; |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 551 | virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) OVERRIDE; |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 552 | void UpdateParentTextureInfo(); |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 553 | virtual bool MakeCurrent() OVERRIDE; |
| 554 | virtual void ReleaseCurrent() OVERRIDE; |
| 555 | virtual GLES2Util* GetGLES2Util() OVERRIDE { return &util_; } |
| 556 | virtual gfx::GLContext* GetGLContext() OVERRIDE { return context_.get(); } |
| 557 | virtual ContextGroup* GetContextGroup() OVERRIDE { return group_.get(); } |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 558 | virtual void RestoreState() const OVERRIDE; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 559 | |
| 560 | virtual void RestoreActiveTexture() const OVERRIDE { |
| 561 | state_.RestoreActiveTexture(); |
| 562 | } |
[email protected] | 21700451 | 2013-05-10 21:25:55 | [diff] [blame] | 563 | virtual void RestoreAllTextureUnitBindings() const OVERRIDE { |
| 564 | state_.RestoreAllTextureUnitBindings(); |
| 565 | } |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 566 | virtual void RestoreAttribute(unsigned index) const OVERRIDE { |
| 567 | state_.RestoreAttribute(index); |
| 568 | } |
| 569 | virtual void RestoreBufferBindings() const OVERRIDE { |
| 570 | state_.RestoreBufferBindings(); |
| 571 | } |
| 572 | virtual void RestoreGlobalState() const OVERRIDE { |
| 573 | state_.RestoreGlobalState(); |
| 574 | } |
| 575 | virtual void RestoreProgramBindings() const OVERRIDE { |
| 576 | state_.RestoreProgramBindings(); |
| 577 | } |
| 578 | virtual void RestoreRenderbufferBindings() const OVERRIDE { |
| 579 | state_.RestoreRenderbufferBindings(); |
| 580 | } |
| 581 | virtual void RestoreTextureUnitBindings(unsigned unit) const OVERRIDE { |
| 582 | state_.RestoreTextureUnitBindings(unit); |
| 583 | } |
| 584 | virtual void RestoreFramebufferBindings() const OVERRIDE; |
| 585 | virtual void RestoreTextureState(unsigned service_id) const OVERRIDE; |
| 586 | |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 587 | virtual QueryManager* GetQueryManager() OVERRIDE { |
| 588 | return query_manager_.get(); |
| 589 | } |
| 590 | virtual VertexArrayManager* GetVertexArrayManager() OVERRIDE { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 591 | return vertex_array_manager_.get(); |
| 592 | } |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 593 | virtual bool ProcessPendingQueries() OVERRIDE; |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 594 | virtual bool HasMoreIdleWork() OVERRIDE; |
| 595 | virtual void PerformIdleWork() OVERRIDE; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 596 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 597 | virtual void WaitForReadPixels(base::Closure callback) OVERRIDE; |
| 598 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 599 | virtual void SetResizeCallback( |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 600 | const base::Callback<void(gfx::Size, float)>& callback) OVERRIDE; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 601 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 602 | virtual Logger* GetLogger() OVERRIDE; |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 603 | virtual ErrorState* GetErrorState() OVERRIDE; |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 604 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 605 | virtual void SetShaderCacheCallback( |
| 606 | const ShaderCacheCallback& callback) OVERRIDE; |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 607 | virtual void SetWaitSyncPointCallback( |
| 608 | const WaitSyncPointCallback& callback) OVERRIDE; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 609 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 610 | virtual AsyncPixelTransferManager* |
| 611 | GetAsyncPixelTransferManager() OVERRIDE; |
| 612 | virtual void ResetAsyncPixelTransferManagerForTest() OVERRIDE; |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 613 | virtual void SetAsyncPixelTransferManagerForTest( |
| 614 | AsyncPixelTransferManager* manager) OVERRIDE; |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 615 | void ProcessFinishedAsyncTransfers(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 616 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 617 | virtual bool GetServiceTextureId(uint32 client_texture_id, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 618 | uint32* service_texture_id) OVERRIDE; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 619 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 620 | virtual uint32 GetTextureUploadCount() OVERRIDE; |
| 621 | virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; |
| 622 | virtual base::TimeDelta GetTotalProcessingCommandsTime() OVERRIDE; |
[email protected] | dc25dda | 2012-09-27 21:36:30 | [diff] [blame] | 623 | virtual void AddProcessingCommandsTime(base::TimeDelta) OVERRIDE; |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 624 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 625 | // Restores the current state to the user's settings. |
| 626 | void RestoreCurrentFramebufferBindings(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 627 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 628 | // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
| 629 | void ApplyDirtyState(); |
| 630 | |
| 631 | // These check the state of the currently bound framebuffer or the |
| 632 | // backbuffer if no framebuffer is bound. |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 633 | // If all_draw_buffers is false, only check with COLOR_ATTACHMENT0, otherwise |
| 634 | // check with all attached and enabled color attachments. |
| 635 | bool BoundFramebufferHasColorAttachmentWithAlpha(bool all_draw_buffers); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 636 | bool BoundFramebufferHasDepthAttachment(); |
| 637 | bool BoundFramebufferHasStencilAttachment(); |
| 638 | |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 639 | virtual error::ContextLostReason GetContextLostReason() OVERRIDE; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 640 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 641 | // Overridden from FramebufferManager::TextureDetachObserver: |
| 642 | virtual void OnTextureRefDetachedFromFramebuffer( |
| 643 | TextureRef* texture) OVERRIDE; |
| 644 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 645 | private: |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 646 | friend class ScopedFrameBufferBinder; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 647 | friend class ScopedResolvedFrameBufferBinder; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 648 | friend class BackFramebuffer; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 649 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 650 | // Initialize or re-initialize the shader translator. |
| 651 | bool InitializeShaderTranslator(); |
| 652 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 653 | void UpdateCapabilities(); |
| 654 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 655 | // Helpers for the glGen and glDelete functions. |
| 656 | bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 657 | void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 658 | bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 659 | void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 660 | bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 661 | void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 662 | bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
| 663 | void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 664 | bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
| 665 | void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 666 | bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
| 667 | void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 668 | |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 669 | // Workarounds |
| 670 | void OnFboChanged() const; |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 671 | void OnUseFramebuffer() const; |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 672 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 673 | // TODO(gman): Cache these pointers? |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 674 | BufferManager* buffer_manager() { |
| 675 | return group_->buffer_manager(); |
| 676 | } |
| 677 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 678 | RenderbufferManager* renderbuffer_manager() { |
| 679 | return group_->renderbuffer_manager(); |
| 680 | } |
| 681 | |
| 682 | FramebufferManager* framebuffer_manager() { |
| 683 | return group_->framebuffer_manager(); |
| 684 | } |
| 685 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 686 | ProgramManager* program_manager() { |
| 687 | return group_->program_manager(); |
| 688 | } |
| 689 | |
| 690 | ShaderManager* shader_manager() { |
| 691 | return group_->shader_manager(); |
| 692 | } |
| 693 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 694 | const TextureManager* texture_manager() const { |
| 695 | return group_->texture_manager(); |
| 696 | } |
| 697 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 698 | TextureManager* texture_manager() { |
| 699 | return group_->texture_manager(); |
| 700 | } |
| 701 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 702 | MailboxManager* mailbox_manager() { |
| 703 | return group_->mailbox_manager(); |
| 704 | } |
| 705 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 706 | ImageManager* image_manager() { |
| 707 | return group_->image_manager(); |
| 708 | } |
| 709 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 710 | VertexArrayManager* vertex_array_manager() { |
| 711 | return vertex_array_manager_.get(); |
| 712 | } |
| 713 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 714 | MemoryTracker* memory_tracker() { |
| 715 | return group_->memory_tracker(); |
| 716 | } |
| 717 | |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 718 | StreamTextureManager* stream_texture_manager() const { |
| 719 | return group_->stream_texture_manager(); |
| 720 | } |
| 721 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 722 | bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
| 723 | MemoryTracker* tracker = memory_tracker(); |
| 724 | if (tracker) { |
| 725 | return tracker->EnsureGPUMemoryAvailable(estimated_size); |
| 726 | } |
| 727 | return true; |
| 728 | } |
| 729 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 730 | bool IsOffscreenBufferMultisampled() const { |
| 731 | return offscreen_target_samples_ > 1; |
| 732 | } |
| 733 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 734 | // Creates a Texture for the given texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 735 | TextureRef* CreateTexture( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 736 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 737 | return texture_manager()->CreateTexture(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | // Gets the texture info for the given texture. Returns NULL if none exists. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 741 | TextureRef* GetTexture(GLuint client_id) const { |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 742 | return texture_manager()->GetTexture(client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | // Deletes the texture info for the given texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 746 | void RemoveTexture(GLuint client_id) { |
| 747 | texture_manager()->RemoveTexture(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 748 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 749 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 750 | // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| 751 | // or regular back buffer). |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 752 | gfx::Size GetBoundReadFrameBufferSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 753 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 754 | // Get the format of the currently bound frame buffer (either FBO or regular |
| 755 | // back buffer) |
| 756 | GLenum GetBoundReadFrameBufferInternalFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 757 | GLenum GetBoundDrawFrameBufferInternalFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 758 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 759 | // Wrapper for CompressedTexImage2D commands. |
| 760 | error::Error DoCompressedTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 761 | GLenum target, |
| 762 | GLint level, |
| 763 | GLenum internal_format, |
| 764 | GLsizei width, |
| 765 | GLsizei height, |
| 766 | GLint border, |
| 767 | GLsizei image_size, |
| 768 | const void* data); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 769 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 770 | // Wrapper for CompressedTexSubImage2D. |
| 771 | void DoCompressedTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 772 | GLenum target, |
| 773 | GLint level, |
| 774 | GLint xoffset, |
| 775 | GLint yoffset, |
| 776 | GLsizei width, |
| 777 | GLsizei height, |
| 778 | GLenum format, |
| 779 | GLsizei imageSize, |
| 780 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 781 | |
| 782 | // Wrapper for CopyTexImage2D. |
| 783 | void DoCopyTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 784 | GLenum target, |
| 785 | GLint level, |
| 786 | GLenum internal_format, |
| 787 | GLint x, |
| 788 | GLint y, |
| 789 | GLsizei width, |
| 790 | GLsizei height, |
| 791 | GLint border); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 792 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 793 | // Wrapper for SwapBuffers. |
| 794 | void DoSwapBuffers(); |
| 795 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 796 | // Wrapper for CopyTexSubImage2D. |
| 797 | void DoCopyTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 798 | GLenum target, |
| 799 | GLint level, |
| 800 | GLint xoffset, |
| 801 | GLint yoffset, |
| 802 | GLint x, |
| 803 | GLint y, |
| 804 | GLsizei width, |
| 805 | GLsizei height); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 806 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 807 | // Validation for TexSubImage2D. |
| 808 | bool ValidateTexSubImage2D( |
| 809 | error::Error* error, |
| 810 | const char* function_name, |
| 811 | GLenum target, |
| 812 | GLint level, |
| 813 | GLint xoffset, |
| 814 | GLint yoffset, |
| 815 | GLsizei width, |
| 816 | GLsizei height, |
| 817 | GLenum format, |
| 818 | GLenum type, |
| 819 | const void * data); |
| 820 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 821 | // Wrapper for TexSubImage2D. |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 822 | error::Error DoTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 823 | GLenum target, |
| 824 | GLint level, |
| 825 | GLint xoffset, |
| 826 | GLint yoffset, |
| 827 | GLsizei width, |
| 828 | GLsizei height, |
| 829 | GLenum format, |
| 830 | GLenum type, |
| 831 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 832 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 833 | // Extra validation for async tex(Sub)Image2D. |
| 834 | bool ValidateAsyncTransfer( |
| 835 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 836 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 837 | GLenum target, |
| 838 | GLint level, |
| 839 | const void * data); |
| 840 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 841 | // Wrapper for TexImageIOSurface2DCHROMIUM. |
| 842 | void DoTexImageIOSurface2DCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 843 | GLenum target, |
| 844 | GLsizei width, |
| 845 | GLsizei height, |
| 846 | GLuint io_surface_id, |
| 847 | GLuint plane); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 848 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 849 | void DoCopyTextureCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 850 | GLenum target, |
| 851 | GLuint source_id, |
| 852 | GLuint target_id, |
| 853 | GLint level, |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 854 | GLenum internal_format, |
| 855 | GLenum dest_type); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 856 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 857 | // Wrapper for TexStorage2DEXT. |
| 858 | void DoTexStorage2DEXT( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 859 | GLenum target, |
| 860 | GLint levels, |
| 861 | GLenum internal_format, |
| 862 | GLsizei width, |
| 863 | GLsizei height); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 864 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 865 | void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 866 | void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 867 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 868 | void DoBindTexImage2DCHROMIUM( |
| 869 | GLenum target, |
| 870 | GLint image_id); |
| 871 | void DoReleaseTexImage2DCHROMIUM( |
| 872 | GLenum target, |
| 873 | GLint image_id); |
| 874 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 875 | void DoTraceEndCHROMIUM(void); |
| 876 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 877 | void DoDrawBuffersEXT(GLsizei count, const GLenum* bufs); |
| 878 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 879 | // Creates a Program for the given program. |
| 880 | Program* CreateProgram( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 881 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 882 | return program_manager()->CreateProgram(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 883 | } |
| 884 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 885 | // Gets the program info for the given program. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 886 | Program* GetProgram(GLuint client_id) { |
| 887 | return program_manager()->GetProgram(client_id); |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 888 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 889 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 890 | #if defined(NDEBUG) |
| 891 | void LogClientServiceMapping( |
| 892 | const char* /* function_name */, |
| 893 | GLuint /* client_id */, |
| 894 | GLuint /* service_id */) { |
| 895 | } |
| 896 | template<typename T> |
| 897 | void LogClientServiceForInfo( |
| 898 | T* /* info */, GLuint /* client_id */, const char* /* function_name */) { |
| 899 | } |
| 900 | #else |
| 901 | void LogClientServiceMapping( |
| 902 | const char* function_name, GLuint client_id, GLuint service_id) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 903 | if (service_logging_) { |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 904 | DLOG(INFO) << "[" << logger_.GetLogPrefix() << "] " << function_name |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 905 | << ": client_id = " << client_id |
| 906 | << ", service_id = " << service_id; |
| 907 | } |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 908 | } |
| 909 | template<typename T> |
| 910 | void LogClientServiceForInfo( |
| 911 | T* info, GLuint client_id, const char* function_name) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 912 | if (info) { |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 913 | LogClientServiceMapping(function_name, client_id, info->service_id()); |
| 914 | } |
| 915 | } |
| 916 | #endif |
| 917 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 918 | // Gets the program info for the given program. If it's not a program |
| 919 | // generates a GL error. Returns NULL if not program. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 920 | Program* GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 921 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 922 | Program* program = GetProgram(client_id); |
| 923 | if (!program) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 924 | if (GetShader(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 925 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 926 | GL_INVALID_OPERATION, function_name, "shader passed for program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 927 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 928 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 929 | } |
| 930 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 931 | LogClientServiceForInfo(program, client_id, function_name); |
| 932 | return program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 936 | // Creates a Shader for the given shader. |
| 937 | Shader* CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 938 | GLuint client_id, |
| 939 | GLuint service_id, |
| 940 | GLenum shader_type) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 941 | return shader_manager()->CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 942 | client_id, service_id, shader_type); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | // Gets the shader info for the given shader. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 946 | Shader* GetShader(GLuint client_id) { |
| 947 | return shader_manager()->GetShader(client_id); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 948 | } |
| 949 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 950 | // Gets the shader info for the given shader. If it's not a shader generates a |
| 951 | // GL error. Returns NULL if not shader. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 952 | Shader* GetShaderInfoNotProgram( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 953 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 954 | Shader* shader = GetShader(client_id); |
| 955 | if (!shader) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 956 | if (GetProgram(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 957 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 958 | GL_INVALID_OPERATION, function_name, "program passed for shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 959 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 960 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 961 | GL_INVALID_VALUE, function_name, "unknown shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 962 | } |
| 963 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 964 | LogClientServiceForInfo(shader, client_id, function_name); |
| 965 | return shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 966 | } |
| 967 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 968 | // Creates a buffer info for the given buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 969 | void CreateBuffer(GLuint client_id, GLuint service_id) { |
| 970 | return buffer_manager()->CreateBuffer(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 971 | } |
| 972 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 973 | // Gets the buffer info for the given buffer. |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 974 | Buffer* GetBuffer(GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 975 | Buffer* buffer = buffer_manager()->GetBuffer(client_id); |
| 976 | return buffer; |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 977 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 978 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 979 | // Removes any buffers in the VertexAtrribInfos and BufferInfos. This is used |
| 980 | // on glDeleteBuffers so we can make sure the user does not try to render |
| 981 | // with deleted buffers. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 982 | void RemoveBuffer(GLuint client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 983 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 984 | // Creates a framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 985 | void CreateFramebuffer(GLuint client_id, GLuint service_id) { |
| 986 | return framebuffer_manager()->CreateFramebuffer(client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | // Gets the framebuffer info for the given framebuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 990 | Framebuffer* GetFramebuffer(GLuint client_id) { |
| 991 | return framebuffer_manager()->GetFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | // Removes the framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 995 | void RemoveFramebuffer(GLuint client_id) { |
| 996 | framebuffer_manager()->RemoveFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | // Creates a renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1000 | void CreateRenderbuffer(GLuint client_id, GLuint service_id) { |
| 1001 | return renderbuffer_manager()->CreateRenderbuffer( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1002 | client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | // Gets the renderbuffer info for the given renderbuffer. |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1006 | Renderbuffer* GetRenderbuffer(GLuint client_id) { |
| 1007 | return renderbuffer_manager()->GetRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | // Removes the renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1011 | void RemoveRenderbuffer(GLuint client_id) { |
| 1012 | renderbuffer_manager()->RemoveRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1013 | } |
| 1014 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1015 | // Gets the vertex attrib manager for the given vertex array. |
| 1016 | VertexAttribManager* GetVertexAttribManager(GLuint client_id) { |
| 1017 | VertexAttribManager* info = |
| 1018 | vertex_array_manager()->GetVertexAttribManager(client_id); |
| 1019 | return info; |
| 1020 | } |
| 1021 | |
| 1022 | // Removes the vertex attrib manager for the given vertex array. |
| 1023 | void RemoveVertexAttribManager(GLuint client_id) { |
| 1024 | vertex_array_manager()->RemoveVertexAttribManager(client_id); |
| 1025 | } |
| 1026 | |
| 1027 | // Creates a vertex attrib manager for the given vertex array. |
| 1028 | void CreateVertexAttribManager(GLuint client_id, GLuint service_id) { |
| 1029 | return vertex_array_manager()->CreateVertexAttribManager( |
| 1030 | client_id, service_id, group_->max_vertex_attribs()); |
| 1031 | } |
| 1032 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1033 | void DoBindAttribLocation(GLuint client_id, GLuint index, const char* name); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 1034 | void DoBindUniformLocationCHROMIUM( |
| 1035 | GLuint client_id, GLint location, const char* name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1036 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 1037 | error::Error GetAttribLocationHelper( |
| 1038 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1039 | const std::string& name_str); |
| 1040 | |
| 1041 | error::Error GetUniformLocationHelper( |
| 1042 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1043 | const std::string& name_str); |
| 1044 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1045 | // Helper for glShaderSource. |
| 1046 | error::Error ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1047 | GLuint client_id, const char* data, uint32 data_size); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1048 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1049 | // Clear any textures used by the current program. |
| 1050 | bool ClearUnclearedTextures(); |
| 1051 | |
| 1052 | // Clear any uncleared level in texture. |
| 1053 | // Returns false if there was a generated GL error. |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 1054 | bool ClearTexture(Texture* texture); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1055 | |
| 1056 | // Clears any uncleared attachments attached to the given frame buffer. |
| 1057 | // Returns false if there was a generated GL error. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1058 | void ClearUnclearedAttachments(GLenum target, Framebuffer* framebuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1059 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1060 | // overridden from GLES2Decoder |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 1061 | virtual bool ClearLevel(unsigned service_id, |
| 1062 | unsigned bind_target, |
| 1063 | unsigned target, |
| 1064 | int level, |
| 1065 | unsigned format, |
| 1066 | unsigned type, |
| 1067 | int width, |
| 1068 | int height, |
| 1069 | bool is_texture_immutable) OVERRIDE; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1070 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 1071 | // Restore all GL state that affects clearing. |
| 1072 | void RestoreClearState(); |
| 1073 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1074 | // Remembers the state of some capabilities. |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1075 | // Returns: true if glEnable/glDisable should actually be called. |
| 1076 | bool SetCapabilityState(GLenum cap, bool enabled); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1077 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1078 | // Check that the currently bound framebuffers are valid. |
| 1079 | // Generates GL error if not. |
| 1080 | bool CheckBoundFramebuffersValid(const char* func_name); |
| 1081 | |
| 1082 | // Check if a framebuffer meets our requirements. |
| 1083 | bool CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1084 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1085 | GLenum target, |
| 1086 | const char* func_name); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1087 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1088 | // Checks if the current program exists and is valid. If not generates the |
| 1089 | // appropriate GL error. Returns true if the current program is in a usable |
| 1090 | // state. |
| 1091 | bool CheckCurrentProgram(const char* function_name); |
| 1092 | |
| 1093 | // Checks if the current program exists and is valid and that location is not |
| 1094 | // -1. If the current program is not valid generates the appropriate GL |
| 1095 | // error. Returns true if the current program is in a usable state and |
| 1096 | // location is not -1. |
| 1097 | bool CheckCurrentProgramForUniform(GLint location, const char* function_name); |
| 1098 | |
| 1099 | // Gets the type of a uniform for a location in the current program. Sets GL |
| 1100 | // errors if the current program is not valid. Returns true if the current |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1101 | // program is valid and the location exists. Adjusts count so it |
| 1102 | // does not overflow the uniform. |
| 1103 | bool PrepForSetUniformByLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1104 | GLint fake_location, const char* function_name, |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 1105 | const BaseUniformInfo& base_info, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1106 | GLint* real_location, GLenum* type, GLsizei* count); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1107 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1108 | // Gets the service id for any simulated backbuffer fbo. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1109 | GLuint GetBackbufferServiceId() const; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1110 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1111 | // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv |
| 1112 | bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); |
| 1113 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 1114 | // Helper for glGetVertexAttrib |
| 1115 | void GetVertexAttribHelper( |
| 1116 | const VertexAttrib* attrib, GLenum pname, GLint* param); |
| 1117 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1118 | // Wrapper for glCreateProgram |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1119 | bool CreateProgramHelper(GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1120 | |
| 1121 | // Wrapper for glCreateShader |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1122 | bool CreateShaderHelper(GLenum type, GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1123 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1124 | // Wrapper for glActiveTexture |
| 1125 | void DoActiveTexture(GLenum texture_unit); |
| 1126 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1127 | // Wrapper for glAttachShader |
| 1128 | void DoAttachShader(GLuint client_program_id, GLint client_shader_id); |
| 1129 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1130 | // Wrapper for glBindBuffer since we need to track the current targets. |
| 1131 | void DoBindBuffer(GLenum target, GLuint buffer); |
| 1132 | |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 1133 | // Wrapper for glBindFramebuffer since we need to track the current targets. |
| 1134 | void DoBindFramebuffer(GLenum target, GLuint framebuffer); |
| 1135 | |
| 1136 | // Wrapper for glBindRenderbuffer since we need to track the current targets. |
| 1137 | void DoBindRenderbuffer(GLenum target, GLuint renderbuffer); |
| 1138 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1139 | // Wrapper for glBindTexture since we need to track the current targets. |
| 1140 | void DoBindTexture(GLenum target, GLuint texture); |
| 1141 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1142 | // Wrapper for glBindVertexArrayOES |
| 1143 | void DoBindVertexArrayOES(GLuint array); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 1144 | void EmulateVertexArrayState(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1145 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1146 | // Wrapper for glBlitFramebufferEXT. |
| 1147 | void DoBlitFramebufferEXT( |
| 1148 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 1149 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 1150 | GLbitfield mask, GLenum filter); |
| 1151 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1152 | // Wrapper for glBufferSubData. |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 1153 | void DoBufferSubData( |
| 1154 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); |
| 1155 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1156 | // Wrapper for glCheckFramebufferStatus |
| 1157 | GLenum DoCheckFramebufferStatus(GLenum target); |
| 1158 | |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1159 | // Wrapper for glClear |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1160 | error::Error DoClear(GLbitfield mask); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1161 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1162 | // Wrappers for various state. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1163 | void DoDepthRangef(GLclampf znear, GLclampf zfar); |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 1164 | void DoSampleCoverage(GLclampf value, GLboolean invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1165 | |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1166 | // Wrapper for glCompileShader. |
| 1167 | void DoCompileShader(GLuint shader); |
| 1168 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1169 | // Helper for DeleteSharedIdsCHROMIUM commands. |
| 1170 | void DoDeleteSharedIdsCHROMIUM( |
| 1171 | GLuint namespace_id, GLsizei n, const GLuint* ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1172 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1173 | // Wrapper for glDetachShader |
| 1174 | void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
| 1175 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1176 | // Wrapper for glDisable |
| 1177 | void DoDisable(GLenum cap); |
| 1178 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1179 | // Wrapper for glDisableVertexAttribArray. |
| 1180 | void DoDisableVertexAttribArray(GLuint index); |
| 1181 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1182 | // Wrapper for glDiscardFramebufferEXT, since we need to track undefined |
| 1183 | // attachments. |
| 1184 | void DoDiscardFramebufferEXT(GLenum target, |
| 1185 | GLsizei numAttachments, |
| 1186 | const GLenum* attachments); |
| 1187 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1188 | // Wrapper for glEnable |
| 1189 | void DoEnable(GLenum cap); |
| 1190 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1191 | // Wrapper for glEnableVertexAttribArray. |
| 1192 | void DoEnableVertexAttribArray(GLuint index); |
| 1193 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1194 | // Wrapper for glFinish. |
| 1195 | void DoFinish(); |
| 1196 | |
| 1197 | // Wrapper for glFlush. |
| 1198 | void DoFlush(); |
| 1199 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1200 | // Wrapper for glFramebufferRenderbufffer. |
| 1201 | void DoFramebufferRenderbuffer( |
| 1202 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
| 1203 | GLuint renderbuffer); |
| 1204 | |
| 1205 | // Wrapper for glFramebufferTexture2D. |
| 1206 | void DoFramebufferTexture2D( |
| 1207 | GLenum target, GLenum attachment, GLenum textarget, GLuint texture, |
| 1208 | GLint level); |
| 1209 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1210 | // Wrapper for glFramebufferTexture2DMultisampleEXT. |
| 1211 | void DoFramebufferTexture2DMultisample( |
| 1212 | GLenum target, GLenum attachment, GLenum textarget, |
| 1213 | GLuint texture, GLint level, GLsizei samples); |
| 1214 | |
| 1215 | // Common implementation for both DoFramebufferTexture2D wrappers. |
| 1216 | void DoFramebufferTexture2DCommon(const char* name, |
| 1217 | GLenum target, GLenum attachment, GLenum textarget, |
| 1218 | GLuint texture, GLint level, GLsizei samples); |
| 1219 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1220 | // Wrapper for glGenerateMipmap |
| 1221 | void DoGenerateMipmap(GLenum target); |
| 1222 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1223 | // Helper for GenSharedIdsCHROMIUM commands. |
| 1224 | void DoGenSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1225 | GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids); |
| 1226 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1227 | // Helper for DoGetBooleanv, Floatv, and Intergerv to adjust pname |
| 1228 | // to account for different pname values defined in different extension |
| 1229 | // variants. |
| 1230 | GLenum AdjustGetPname(GLenum pname); |
| 1231 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1232 | // Wrapper for DoGetBooleanv. |
| 1233 | void DoGetBooleanv(GLenum pname, GLboolean* params); |
| 1234 | |
| 1235 | // Wrapper for DoGetFloatv. |
| 1236 | void DoGetFloatv(GLenum pname, GLfloat* params); |
| 1237 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1238 | // Wrapper for glGetFramebufferAttachmentParameteriv. |
| 1239 | void DoGetFramebufferAttachmentParameteriv( |
| 1240 | GLenum target, GLenum attachment, GLenum pname, GLint* params); |
| 1241 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1242 | // Wrapper for glGetIntegerv. |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1243 | void DoGetIntegerv(GLenum pname, GLint* params); |
| 1244 | |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1245 | // Gets the max value in a range in a buffer. |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1246 | GLuint DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1247 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); |
| 1248 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 1249 | // Wrapper for glGetBufferParameteriv. |
| 1250 | void DoGetBufferParameteriv( |
| 1251 | GLenum target, GLenum pname, GLint* params); |
| 1252 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1253 | // Wrapper for glGetProgramiv. |
| 1254 | void DoGetProgramiv( |
| 1255 | GLuint program_id, GLenum pname, GLint* params); |
| 1256 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1257 | // Wrapper for glRenderbufferParameteriv. |
| 1258 | void DoGetRenderbufferParameteriv( |
| 1259 | GLenum target, GLenum pname, GLint* params); |
| 1260 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 1261 | // Wrapper for glGetShaderiv |
| 1262 | void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); |
| 1263 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1264 | // Wrappers for glGetVertexAttrib. |
| 1265 | void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); |
| 1266 | void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); |
| 1267 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1268 | // Wrappers for glIsXXX functions. |
[email protected] | 3dc69c4 | 2012-05-12 02:29:24 | [diff] [blame] | 1269 | bool DoIsEnabled(GLenum cap); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1270 | bool DoIsBuffer(GLuint client_id); |
| 1271 | bool DoIsFramebuffer(GLuint client_id); |
| 1272 | bool DoIsProgram(GLuint client_id); |
| 1273 | bool DoIsRenderbuffer(GLuint client_id); |
| 1274 | bool DoIsShader(GLuint client_id); |
| 1275 | bool DoIsTexture(GLuint client_id); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1276 | bool DoIsVertexArrayOES(GLuint client_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1277 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1278 | // Wrapper for glLinkProgram |
| 1279 | void DoLinkProgram(GLuint program); |
| 1280 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1281 | // Helper for RegisterSharedIdsCHROMIUM. |
| 1282 | void DoRegisterSharedIdsCHROMIUM( |
| 1283 | GLuint namespace_id, GLsizei n, const GLuint* ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1284 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1285 | // Wrapper for glRenderbufferStorage. |
| 1286 | void DoRenderbufferStorage( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1287 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1288 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1289 | // Wrapper for glRenderbufferStorageMultisampleEXT. |
| 1290 | void DoRenderbufferStorageMultisample( |
| 1291 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1292 | GLsizei width, GLsizei height); |
| 1293 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 1294 | // Verifies that the currently bound multisample renderbuffer is valid |
| 1295 | // Very slow! Only done on platforms with driver bugs that return invalid |
| 1296 | // buffers under memory pressure |
| 1297 | bool VerifyMultisampleRenderbufferIntegrity( |
| 1298 | GLuint renderbuffer, GLenum format); |
| 1299 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1300 | // Wrapper for glReleaseShaderCompiler. |
| 1301 | void DoReleaseShaderCompiler() { } |
| 1302 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1303 | // Wrappers for glTexParameter functions. |
| 1304 | void DoTexParameterf(GLenum target, GLenum pname, GLfloat param); |
| 1305 | void DoTexParameteri(GLenum target, GLenum pname, GLint param); |
| 1306 | void DoTexParameterfv(GLenum target, GLenum pname, const GLfloat* params); |
| 1307 | void DoTexParameteriv(GLenum target, GLenum pname, const GLint* params); |
| 1308 | |
| 1309 | // Wrappers for glUniform1i and glUniform1iv as according to the GLES2 |
| 1310 | // spec only these 2 functions can be used to set sampler uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1311 | void DoUniform1i(GLint fake_location, GLint v0); |
| 1312 | void DoUniform1iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1313 | void DoUniform2iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1314 | void DoUniform3iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1315 | void DoUniform4iv(GLint fake_location, GLsizei count, const GLint* value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1316 | |
| 1317 | // Wrappers for glUniformfv because some drivers don't correctly accept |
| 1318 | // bool uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1319 | void DoUniform1fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1320 | void DoUniform2fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1321 | void DoUniform3fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1322 | void DoUniform4fv(GLint fake_location, GLsizei count, const GLfloat* value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1323 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1324 | void DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1325 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1326 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1327 | void DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1328 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1329 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1330 | void DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1331 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1332 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1333 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1334 | bool SetVertexAttribValue( |
| 1335 | const char* function_name, GLuint index, const GLfloat* value); |
| 1336 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1337 | // Wrappers for glVertexAttrib?? |
| 1338 | void DoVertexAttrib1f(GLuint index, GLfloat v0); |
| 1339 | void DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1); |
| 1340 | void DoVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2); |
| 1341 | void DoVertexAttrib4f( |
| 1342 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); |
| 1343 | void DoVertexAttrib1fv(GLuint index, const GLfloat *v); |
| 1344 | void DoVertexAttrib2fv(GLuint index, const GLfloat *v); |
| 1345 | void DoVertexAttrib3fv(GLuint index, const GLfloat *v); |
| 1346 | void DoVertexAttrib4fv(GLuint index, const GLfloat *v); |
| 1347 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1348 | // Wrapper for glViewport |
| 1349 | void DoViewport(GLint x, GLint y, GLsizei width, GLsizei height); |
| 1350 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1351 | // Wrapper for glUseProgram |
| 1352 | void DoUseProgram(GLuint program); |
| 1353 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1354 | // Wrapper for glValidateProgram. |
| 1355 | void DoValidateProgram(GLuint program_client_id); |
| 1356 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 1357 | void DoInsertEventMarkerEXT(GLsizei length, const GLchar* marker); |
| 1358 | void DoPushGroupMarkerEXT(GLsizei length, const GLchar* group); |
| 1359 | void DoPopGroupMarkerEXT(void); |
| 1360 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 1361 | // Gets the number of values that will be returned by glGetXXX. Returns |
| 1362 | // false if pname is unknown. |
| 1363 | bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values); |
| 1364 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1365 | // Checks if the current program and vertex attributes are valid for drawing. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1366 | bool IsDrawValid( |
| 1367 | const char* function_name, GLuint max_vertex_accessed, GLsizei primcount); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1368 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 1369 | // Returns true if successful, simulated will be true if attrib0 was |
| 1370 | // simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1371 | bool SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1372 | const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1373 | void RestoreStateForAttrib(GLuint attrib); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1374 | |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 1375 | // If texture is a stream texture, this will update the stream to the newest |
[email protected] | e8dc566 | 2013-10-17 23:28:29 | [diff] [blame] | 1376 | // buffer and bind the texture implicitly. |
| 1377 | void UpdateStreamTextureIfNeeded(Texture* texture, GLuint texture_unit_index); |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 1378 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1379 | // If an image is bound to texture, this will call Will/DidUseTexImage |
| 1380 | // if needed. |
| 1381 | void DoWillUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1382 | void DoDidUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1383 | |
| 1384 | // Returns false if textures were replaced. |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 1385 | bool PrepareTexturesForRender(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1386 | void RestoreStateForTextures(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1387 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1388 | // Returns true if GL_FIXED attribs were simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1389 | bool SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1390 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1391 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1392 | void RestoreStateForSimulatedFixedAttribs(); |
| 1393 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1394 | // Handle DrawArrays and DrawElements for both instanced and non-instanced |
| 1395 | // cases (primcount is 0 for non-instanced). |
| 1396 | error::Error DoDrawArrays( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1397 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1398 | bool instanced, GLenum mode, GLint first, GLsizei count, |
| 1399 | GLsizei primcount); |
| 1400 | error::Error DoDrawElements( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1401 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1402 | bool instanced, GLenum mode, GLsizei count, GLenum type, |
| 1403 | int32 offset, GLsizei primcount); |
| 1404 | |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1405 | GLenum GetBindTargetForSamplerType(GLenum type) { |
| 1406 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1407 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 1408 | switch (type) { |
| 1409 | case GL_SAMPLER_2D: |
| 1410 | return GL_TEXTURE_2D; |
| 1411 | case GL_SAMPLER_CUBE: |
| 1412 | return GL_TEXTURE_CUBE_MAP; |
| 1413 | case GL_SAMPLER_EXTERNAL_OES: |
| 1414 | return GL_TEXTURE_EXTERNAL_OES; |
| 1415 | case GL_SAMPLER_2D_RECT_ARB: |
| 1416 | return GL_TEXTURE_RECTANGLE_ARB; |
| 1417 | } |
| 1418 | |
| 1419 | NOTREACHED(); |
| 1420 | return 0; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1421 | } |
| 1422 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1423 | // Gets the framebuffer info for a particular target. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1424 | Framebuffer* GetFramebufferInfoForTarget(GLenum target) { |
| 1425 | Framebuffer* framebuffer = NULL; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1426 | switch (target) { |
| 1427 | case GL_FRAMEBUFFER: |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1428 | case GL_DRAW_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1429 | framebuffer = framebuffer_state_.bound_draw_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1430 | break; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1431 | case GL_READ_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1432 | framebuffer = framebuffer_state_.bound_read_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1433 | break; |
| 1434 | default: |
| 1435 | NOTREACHED(); |
| 1436 | break; |
| 1437 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1438 | return framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1439 | } |
| 1440 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1441 | Renderbuffer* GetRenderbufferInfoForTarget( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1442 | GLenum target) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1443 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1444 | switch (target) { |
| 1445 | case GL_RENDERBUFFER: |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 1446 | renderbuffer = state_.bound_renderbuffer.get(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1447 | break; |
| 1448 | default: |
| 1449 | NOTREACHED(); |
| 1450 | break; |
| 1451 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1452 | return renderbuffer; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1453 | } |
| 1454 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1455 | // Validates the program and location for a glGetUniform call and returns |
| 1456 | // a SizeResult setup to receive the result. Returns true if glGetUniform |
| 1457 | // should be called. |
| 1458 | bool GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1459 | GLuint program, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1460 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1461 | error::Error* error, GLint* real_location, GLuint* service_id, |
| 1462 | void** result, GLenum* result_type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1463 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1464 | // Computes the estimated memory used for the backbuffer and passes it to |
| 1465 | // the tracing system. |
[email protected] | 260ddc4e | 2012-06-28 00:01:53 | [diff] [blame] | 1466 | size_t GetBackbufferMemoryTotal(); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1467 | |
[email protected] | a10b4a0 | 2012-11-26 23:09:50 | [diff] [blame] | 1468 | virtual bool WasContextLost() OVERRIDE; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 1469 | virtual bool WasContextLostByRobustnessExtension() OVERRIDE; |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 1470 | virtual void LoseContext(uint32 reset_status) OVERRIDE; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1471 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1472 | #if defined(OS_MACOSX) |
| 1473 | void ReleaseIOSurfaceForTexture(GLuint texture_id); |
| 1474 | #endif |
| 1475 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 1476 | // Validates the combination of texture parameters. For example validates that |
| 1477 | // for a given format the specific type, level and targets are valid. |
| 1478 | // Synthesizes the correct GL error if invalid. Returns true if valid. |
| 1479 | bool ValidateTextureParameters( |
| 1480 | const char* function_name, |
| 1481 | GLenum target, GLenum format, GLenum type, GLint level); |
| 1482 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1483 | bool ValidateCompressedTexDimensions( |
| 1484 | const char* function_name, |
| 1485 | GLint level, GLsizei width, GLsizei height, GLenum format); |
| 1486 | bool ValidateCompressedTexFuncData( |
| 1487 | const char* function_name, |
| 1488 | GLsizei width, GLsizei height, GLenum format, size_t size); |
| 1489 | bool ValidateCompressedTexSubDimensions( |
| 1490 | const char* function_name, |
| 1491 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 1492 | GLsizei width, GLsizei height, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1493 | Texture* texture); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1494 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1495 | void RenderWarning(const char* filename, int line, const std::string& msg); |
| 1496 | void PerformanceWarning( |
| 1497 | const char* filename, int line, const std::string& msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 1498 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 1499 | const FeatureInfo::FeatureFlags& features() const { |
| 1500 | return feature_info_->feature_flags(); |
| 1501 | } |
| 1502 | |
| 1503 | const FeatureInfo::Workarounds& workarounds() const { |
| 1504 | return feature_info_->workarounds(); |
| 1505 | } |
| 1506 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1507 | bool ShouldDeferDraws() { |
| 1508 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1509 | framebuffer_state_.bound_draw_framebuffer.get() == NULL && |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1510 | surface_->DeferDraws(); |
| 1511 | } |
| 1512 | |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1513 | bool ShouldDeferReads() { |
| 1514 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1515 | framebuffer_state_.bound_read_framebuffer.get() == NULL && |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1516 | surface_->DeferDraws(); |
| 1517 | } |
| 1518 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 1519 | void ProcessPendingReadPixels(); |
| 1520 | void FinishReadPixels(const cmds::ReadPixels& c, GLuint buffer); |
| 1521 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1522 | // Generate a member function prototype for each command in an automated and |
| 1523 | // typesafe way. |
| 1524 | #define GLES2_CMD_OP(name) \ |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 1525 | Error Handle ## name( \ |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1526 | uint32 immediate_data_size, \ |
| 1527 | const cmds::name& args); \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1528 | |
| 1529 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 1530 | |
| 1531 | #undef GLES2_CMD_OP |
| 1532 | |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 1533 | // The GL context this decoder renders to on behalf of the client. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1534 | scoped_refptr<gfx::GLSurface> surface_; |
| 1535 | scoped_refptr<gfx::GLContext> context_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1536 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1537 | // The ContextGroup for this decoder uses to track resources. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1538 | scoped_refptr<ContextGroup> group_; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1539 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 1540 | DebugMarkerManager debug_marker_manager_; |
| 1541 | Logger logger_; |
| 1542 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1543 | // All the state for this context. |
| 1544 | ContextState state_; |
| 1545 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1546 | // Current width and height of the offscreen frame buffer. |
| 1547 | gfx::Size offscreen_size_; |
| 1548 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1549 | // Util to help with GL. |
| 1550 | GLES2Util util_; |
| 1551 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1552 | // unpack flip y as last set by glPixelStorei |
| 1553 | bool unpack_flip_y_; |
| 1554 | |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1555 | // unpack (un)premultiply alpha as last set by glPixelStorei |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1556 | bool unpack_premultiply_alpha_; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1557 | bool unpack_unpremultiply_alpha_; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1558 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1559 | // Default vertex attribs manager, used when no VAOs are bound. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1560 | scoped_refptr<VertexAttribManager> default_vertex_attrib_manager_; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1561 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1562 | // The buffer we bind to attrib 0 since OpenGL requires it (ES does not). |
| 1563 | GLuint attrib_0_buffer_id_; |
| 1564 | |
| 1565 | // The value currently in attrib_0. |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1566 | Vec4 attrib_0_value_; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1567 | |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 1568 | // Whether or not the attrib_0 buffer holds the attrib_0_value. |
| 1569 | bool attrib_0_buffer_matches_value_; |
| 1570 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1571 | // The size of attrib 0. |
| 1572 | GLsizei attrib_0_size_; |
| 1573 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1574 | // The buffer used to simulate GL_FIXED attribs. |
| 1575 | GLuint fixed_attrib_buffer_id_; |
| 1576 | |
| 1577 | // The size of fiixed attrib buffer. |
| 1578 | GLsizei fixed_attrib_buffer_size_; |
| 1579 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1580 | // The offscreen frame buffer that the client renders to. With EGL, the |
| 1581 | // depth and stencil buffers are separate. With regular GL there is a single |
| 1582 | // packed depth stencil buffer in offscreen_target_depth_render_buffer_. |
| 1583 | // offscreen_target_stencil_render_buffer_ is unused. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1584 | scoped_ptr<BackFramebuffer> offscreen_target_frame_buffer_; |
| 1585 | scoped_ptr<BackTexture> offscreen_target_color_texture_; |
| 1586 | scoped_ptr<BackRenderbuffer> offscreen_target_color_render_buffer_; |
| 1587 | scoped_ptr<BackRenderbuffer> offscreen_target_depth_render_buffer_; |
| 1588 | scoped_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1589 | GLenum offscreen_target_color_format_; |
| 1590 | GLenum offscreen_target_depth_format_; |
| 1591 | GLenum offscreen_target_stencil_format_; |
| 1592 | GLsizei offscreen_target_samples_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1593 | GLboolean offscreen_target_buffer_preserved_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1594 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1595 | // The copy that is saved when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1596 | scoped_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; |
| 1597 | scoped_ptr<BackTexture> offscreen_saved_color_texture_; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 1598 | scoped_refptr<TextureRef> |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1599 | offscreen_saved_color_texture_info_; |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1600 | |
| 1601 | // The copy that is used as the destination for multi-sample resolves. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1602 | scoped_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; |
| 1603 | scoped_ptr<BackTexture> offscreen_resolved_color_texture_; |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1604 | GLenum offscreen_saved_color_format_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1605 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1606 | scoped_ptr<QueryManager> query_manager_; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1607 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1608 | scoped_ptr<VertexArrayManager> vertex_array_manager_; |
| 1609 | |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 1610 | base::Callback<void(gfx::Size, float)> resize_callback_; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 1611 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 1612 | WaitSyncPointCallback wait_sync_point_callback_; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 1613 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 1614 | ShaderCacheCallback shader_cache_callback_; |
| 1615 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 1616 | scoped_ptr<AsyncPixelTransferManager> async_pixel_transfer_manager_; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 1617 | |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1618 | // The format of the back buffer_ |
| 1619 | GLenum back_buffer_color_format_; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1620 | bool back_buffer_has_depth_; |
| 1621 | bool back_buffer_has_stencil_; |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1622 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1623 | // Backbuffer attachments that are currently undefined. |
| 1624 | uint32 backbuffer_needs_clear_bits_; |
| 1625 | |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 1626 | // The current decoder error. |
| 1627 | error::Error current_decoder_error_; |
| 1628 | |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1629 | bool use_shader_translator_; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 1630 | scoped_refptr<ShaderTranslator> vertex_translator_; |
| 1631 | scoped_refptr<ShaderTranslator> fragment_translator_; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1632 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1633 | DisallowedFeatures disallowed_features_; |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1634 | |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 1635 | // Cached from ContextGroup |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1636 | const Validators* validators_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1637 | scoped_refptr<FeatureInfo> feature_info_; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1638 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1639 | int frame_number_; |
| 1640 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 1641 | bool has_robustness_extension_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1642 | GLenum reset_status_; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 1643 | bool reset_by_robustness_extension_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1644 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1645 | // These flags are used to override the state of the shared feature_info_ |
| 1646 | // member. Because the same FeatureInfo instance may be shared among many |
| 1647 | // contexts, the assumptions on the availablity of extensions in WebGL |
| 1648 | // contexts may be broken. These flags override the shared state to preserve |
| 1649 | // WebGL semantics. |
| 1650 | bool force_webgl_glsl_validation_; |
| 1651 | bool derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 1652 | bool frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 1653 | bool draw_buffers_explicitly_enabled_; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1654 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 1655 | bool compile_shader_always_succeeds_; |
| 1656 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1657 | // Log extra info. |
| 1658 | bool service_logging_; |
| 1659 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1660 | #if defined(OS_MACOSX) |
| 1661 | typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; |
| 1662 | TextureToIOSurfaceMap texture_to_io_surface_map_; |
| 1663 | #endif |
| 1664 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1665 | scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
| 1666 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1667 | // Cached values of the currently assigned viewport dimensions. |
| 1668 | GLsizei viewport_max_width_; |
| 1669 | GLsizei viewport_max_height_; |
| 1670 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1671 | // Command buffer stats. |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1672 | base::TimeDelta total_processing_commands_time_; |
| 1673 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 1674 | // States related to each manager. |
| 1675 | DecoderTextureState texture_state_; |
| 1676 | DecoderFramebufferState framebuffer_state_; |
| 1677 | |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 1678 | scoped_ptr<GPUTracer> gpu_tracer_; |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 1679 | scoped_ptr<GPUStateTracer> gpu_state_tracer_; |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 1680 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 1681 | std::queue<linked_ptr<FenceCallback> > pending_readpixel_fences_; |
| 1682 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 1683 | // Used to validate multisample renderbuffers if needed |
| 1684 | GLuint validation_texture_; |
| 1685 | GLuint validation_fbo_multisample_; |
| 1686 | GLuint validation_fbo_; |
| 1687 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1688 | DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
| 1689 | }; |
| 1690 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1691 | ScopedGLErrorSuppressor::ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1692 | const char* function_name, ErrorState* error_state) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1693 | : function_name_(function_name), |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1694 | error_state_(error_state) { |
| 1695 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1699 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1700 | } |
| 1701 | |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1702 | static void RestoreCurrentTexture2DBindings(ContextState* state) { |
| 1703 | TextureUnit& info = state->texture_units[0]; |
| 1704 | GLuint last_id; |
| 1705 | if (info.bound_texture_2d.get()) { |
| 1706 | last_id = info.bound_texture_2d->service_id(); |
| 1707 | } else { |
| 1708 | last_id = 0; |
| 1709 | } |
| 1710 | |
| 1711 | glBindTexture(GL_TEXTURE_2D, last_id); |
| 1712 | glActiveTexture(GL_TEXTURE0 + state->active_texture_unit); |
| 1713 | } |
| 1714 | |
| 1715 | ScopedTexture2DBinder::ScopedTexture2DBinder(ContextState* state, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1716 | GLuint id) |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1717 | : state_(state) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1718 | ScopedGLErrorSuppressor suppressor( |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1719 | "ScopedTexture2DBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1720 | |
| 1721 | // TODO(apatrick): Check if there are any other states that need to be reset |
| 1722 | // before binding a new texture. |
| 1723 | glActiveTexture(GL_TEXTURE0); |
| 1724 | glBindTexture(GL_TEXTURE_2D, id); |
| 1725 | } |
| 1726 | |
| 1727 | ScopedTexture2DBinder::~ScopedTexture2DBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1728 | ScopedGLErrorSuppressor suppressor( |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1729 | "ScopedTexture2DBinder::dtor", state_->GetErrorState()); |
| 1730 | RestoreCurrentTexture2DBindings(state_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1731 | } |
| 1732 | |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1733 | ScopedRenderBufferBinder::ScopedRenderBufferBinder(ContextState* state, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1734 | GLuint id) |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1735 | : state_(state) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1736 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1737 | "ScopedRenderBufferBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1738 | glBindRenderbufferEXT(GL_RENDERBUFFER, id); |
| 1739 | } |
| 1740 | |
| 1741 | ScopedRenderBufferBinder::~ScopedRenderBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1742 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1743 | "ScopedRenderBufferBinder::dtor", state_->GetErrorState()); |
| 1744 | state_->RestoreRenderbufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1745 | } |
| 1746 | |
| 1747 | ScopedFrameBufferBinder::ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 1748 | GLuint id) |
| 1749 | : decoder_(decoder) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1750 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1751 | "ScopedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1752 | glBindFramebufferEXT(GL_FRAMEBUFFER, id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 1753 | decoder->OnFboChanged(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | ScopedFrameBufferBinder::~ScopedFrameBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1757 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1758 | "ScopedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1759 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1760 | } |
| 1761 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1762 | ScopedResolvedFrameBufferBinder::ScopedResolvedFrameBufferBinder( |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1763 | GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 1764 | : decoder_(decoder) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1765 | resolve_and_bind_ = ( |
| 1766 | decoder_->offscreen_target_frame_buffer_.get() && |
| 1767 | decoder_->IsOffscreenBufferMultisampled() && |
| 1768 | (!decoder_->framebuffer_state_.bound_read_framebuffer.get() || |
| 1769 | enforce_internal_framebuffer)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1770 | if (!resolve_and_bind_) |
| 1771 | return; |
| 1772 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1773 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1774 | "ScopedResolvedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1775 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, |
| 1776 | decoder_->offscreen_target_frame_buffer_->id()); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1777 | GLuint targetid; |
| 1778 | if (internal) { |
| 1779 | if (!decoder_->offscreen_resolved_frame_buffer_.get()) { |
| 1780 | decoder_->offscreen_resolved_frame_buffer_.reset( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1781 | new BackFramebuffer(decoder_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1782 | decoder_->offscreen_resolved_frame_buffer_->Create(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1783 | decoder_->offscreen_resolved_color_texture_.reset( |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1784 | new BackTexture(decoder->memory_tracker(), &decoder->state_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1785 | decoder_->offscreen_resolved_color_texture_->Create(); |
| 1786 | |
| 1787 | DCHECK(decoder_->offscreen_saved_color_format_); |
| 1788 | decoder_->offscreen_resolved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 1789 | decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_, |
| 1790 | false); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1791 | decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( |
| 1792 | decoder_->offscreen_resolved_color_texture_.get()); |
| 1793 | if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != |
| 1794 | GL_FRAMEBUFFER_COMPLETE) { |
| 1795 | LOG(ERROR) << "ScopedResolvedFrameBufferBinder failed " |
| 1796 | << "because offscreen resolved FBO was incomplete."; |
| 1797 | return; |
| 1798 | } |
| 1799 | } |
| 1800 | targetid = decoder_->offscreen_resolved_frame_buffer_->id(); |
| 1801 | } else { |
| 1802 | targetid = decoder_->offscreen_saved_frame_buffer_->id(); |
| 1803 | } |
| 1804 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1805 | const int width = decoder_->offscreen_size_.width(); |
| 1806 | const int height = decoder_->offscreen_size_.height(); |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 1807 | glDisable(GL_SCISSOR_TEST); |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 1808 | if (GLES2Decoder::IsAngle()) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1809 | glBlitFramebufferANGLE(0, 0, width, height, 0, 0, width, height, |
| 1810 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 1811 | } else { |
| 1812 | glBlitFramebufferEXT(0, 0, width, height, 0, 0, width, height, |
| 1813 | GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 1814 | } |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1815 | glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { |
| 1819 | if (!resolve_and_bind_) |
| 1820 | return; |
| 1821 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1822 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1823 | "ScopedResolvedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1824 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 1825 | if (decoder_->state_.enable_flags.scissor_test) { |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 1826 | glEnable(GL_SCISSOR_TEST); |
| 1827 | } |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1828 | } |
| 1829 | |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1830 | BackTexture::BackTexture( |
| 1831 | MemoryTracker* memory_tracker, |
| 1832 | ContextState* state) |
| 1833 | : memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 1834 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 1835 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1836 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1837 | } |
| 1838 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1839 | BackTexture::~BackTexture() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1840 | // This does not destroy the render texture because that would require that |
| 1841 | // the associated GL context was current. Just check that it was explicitly |
| 1842 | // destroyed. |
| 1843 | DCHECK_EQ(id_, 0u); |
| 1844 | } |
| 1845 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1846 | void BackTexture::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1847 | ScopedGLErrorSuppressor suppressor("BackTexture::Create", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1848 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1849 | Destroy(); |
| 1850 | glGenTextures(1, &id_); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1851 | ScopedTexture2DBinder binder(state_, id_); |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1852 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1853 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1854 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1855 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
[email protected] | 6278880 | 2011-10-03 17:57:16 | [diff] [blame] | 1856 | |
| 1857 | // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 1858 | // never called on an offscreen context, no data will ever be uploaded to the |
| 1859 | // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 1860 | // is called). My idea is that some nvidia drivers might have a bug where |
| 1861 | // deleting a texture that has never been populated might cause a |
| 1862 | // crash. |
| 1863 | glTexImage2D( |
| 1864 | GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 1865 | |
| 1866 | bytes_allocated_ = 16u * 16u * 4u; |
| 1867 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1868 | } |
| 1869 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1870 | bool BackTexture::AllocateStorage( |
| 1871 | const gfx::Size& size, GLenum format, bool zero) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1872 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1873 | ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1874 | state_->GetErrorState()); |
| 1875 | ScopedTexture2DBinder binder(state_, id_); |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 1876 | uint32 image_size = 0; |
| 1877 | GLES2Util::ComputeImageDataSizes( |
| 1878 | size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size, |
| 1879 | NULL, NULL); |
| 1880 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 1881 | if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { |
| 1882 | return false; |
| 1883 | } |
| 1884 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 1885 | scoped_ptr<char[]> zero_data; |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 1886 | if (zero) { |
| 1887 | zero_data.reset(new char[image_size]); |
| 1888 | memset(zero_data.get(), 0, image_size); |
| 1889 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1890 | |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 1891 | glTexImage2D(GL_TEXTURE_2D, |
| 1892 | 0, // mip level |
| 1893 | format, |
| 1894 | size.width(), |
| 1895 | size.height(), |
| 1896 | 0, // border |
| 1897 | format, |
| 1898 | GL_UNSIGNED_BYTE, |
| 1899 | zero_data.get()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1900 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1901 | size_ = size; |
| 1902 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1903 | bool success = glGetError() == GL_NO_ERROR; |
| 1904 | if (success) { |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 1905 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1906 | bytes_allocated_ = image_size; |
| 1907 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1908 | } |
| 1909 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1910 | } |
| 1911 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1912 | void BackTexture::Copy(const gfx::Size& size, GLenum format) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1913 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1914 | ScopedGLErrorSuppressor suppressor("BackTexture::Copy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1915 | state_->GetErrorState()); |
| 1916 | ScopedTexture2DBinder binder(state_, id_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1917 | glCopyTexImage2D(GL_TEXTURE_2D, |
| 1918 | 0, // level |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1919 | format, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1920 | 0, 0, |
| 1921 | size.width(), |
| 1922 | size.height(), |
| 1923 | 0); // border |
| 1924 | } |
| 1925 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1926 | void BackTexture::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1927 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1928 | ScopedGLErrorSuppressor suppressor("BackTexture::Destroy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1929 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1930 | glDeleteTextures(1, &id_); |
| 1931 | id_ = 0; |
| 1932 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 1933 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1934 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1935 | } |
| 1936 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1937 | void BackTexture::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1938 | id_ = 0; |
| 1939 | } |
| 1940 | |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 1941 | BackRenderbuffer::BackRenderbuffer( |
| 1942 | RenderbufferManager* renderbuffer_manager, |
| 1943 | MemoryTracker* memory_tracker, |
| 1944 | ContextState* state) |
| 1945 | : renderbuffer_manager_(renderbuffer_manager), |
| 1946 | memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 1947 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 1948 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1949 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1950 | } |
| 1951 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1952 | BackRenderbuffer::~BackRenderbuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1953 | // This does not destroy the render buffer because that would require that |
| 1954 | // the associated GL context was current. Just check that it was explicitly |
| 1955 | // destroyed. |
| 1956 | DCHECK_EQ(id_, 0u); |
| 1957 | } |
| 1958 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1959 | void BackRenderbuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1960 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Create", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 1961 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1962 | Destroy(); |
| 1963 | glGenRenderbuffersEXT(1, &id_); |
| 1964 | } |
| 1965 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1966 | bool BackRenderbuffer::AllocateStorage(const gfx::Size& size, GLenum format, |
| 1967 | GLsizei samples) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1968 | ScopedGLErrorSuppressor suppressor( |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 1969 | "BackRenderbuffer::AllocateStorage", state_->GetErrorState()); |
| 1970 | ScopedRenderBufferBinder binder(state_, id_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 1971 | |
| 1972 | uint32 estimated_size = 0; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 1973 | if (!renderbuffer_manager_->ComputeEstimatedRenderbufferSize( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 1974 | size.width(), size.height(), samples, format, &estimated_size)) { |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 1975 | return false; |
| 1976 | } |
| 1977 | |
| 1978 | if (!memory_tracker_.EnsureGPUMemoryAvailable(estimated_size)) { |
| 1979 | return false; |
| 1980 | } |
| 1981 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1982 | if (samples <= 1) { |
| 1983 | glRenderbufferStorageEXT(GL_RENDERBUFFER, |
| 1984 | format, |
| 1985 | size.width(), |
| 1986 | size.height()); |
| 1987 | } else { |
[email protected] | 57edfdad | 2012-02-07 04:57:15 | [diff] [blame] | 1988 | if (GLES2Decoder::IsAngle()) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1989 | glRenderbufferStorageMultisampleANGLE(GL_RENDERBUFFER, |
| 1990 | samples, |
| 1991 | format, |
| 1992 | size.width(), |
| 1993 | size.height()); |
| 1994 | } else { |
| 1995 | glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, |
| 1996 | samples, |
| 1997 | format, |
| 1998 | size.width(), |
| 1999 | size.height()); |
| 2000 | } |
| 2001 | } |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2002 | bool success = glGetError() == GL_NO_ERROR; |
| 2003 | if (success) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2004 | // Mark the previously allocated bytes as free. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2005 | memory_tracker_.TrackMemFree(bytes_allocated_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2006 | bytes_allocated_ = estimated_size; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2007 | // Track the newly allocated bytes. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2008 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2009 | } |
| 2010 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2011 | } |
| 2012 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2013 | void BackRenderbuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2014 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2015 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Destroy", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2016 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2017 | glDeleteRenderbuffersEXT(1, &id_); |
| 2018 | id_ = 0; |
| 2019 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2020 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2021 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2022 | } |
| 2023 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2024 | void BackRenderbuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2025 | id_ = 0; |
| 2026 | } |
| 2027 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2028 | BackFramebuffer::BackFramebuffer(GLES2DecoderImpl* decoder) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2029 | : decoder_(decoder), |
| 2030 | id_(0) { |
| 2031 | } |
| 2032 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2033 | BackFramebuffer::~BackFramebuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2034 | // This does not destroy the frame buffer because that would require that |
| 2035 | // the associated GL context was current. Just check that it was explicitly |
| 2036 | // destroyed. |
| 2037 | DCHECK_EQ(id_, 0u); |
| 2038 | } |
| 2039 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2040 | void BackFramebuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2041 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Create", |
| 2042 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2043 | Destroy(); |
| 2044 | glGenFramebuffersEXT(1, &id_); |
| 2045 | } |
| 2046 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2047 | void BackFramebuffer::AttachRenderTexture(BackTexture* texture) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2048 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2049 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2050 | "BackFramebuffer::AttachRenderTexture", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2051 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2052 | GLuint attach_id = texture ? texture->id() : 0; |
| 2053 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 2054 | GL_COLOR_ATTACHMENT0, |
| 2055 | GL_TEXTURE_2D, |
| 2056 | attach_id, |
| 2057 | 0); |
| 2058 | } |
| 2059 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2060 | void BackFramebuffer::AttachRenderBuffer(GLenum target, |
| 2061 | BackRenderbuffer* render_buffer) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2062 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2063 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2064 | "BackFramebuffer::AttachRenderBuffer", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2065 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2066 | GLuint attach_id = render_buffer ? render_buffer->id() : 0; |
| 2067 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2068 | target, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2069 | GL_RENDERBUFFER, |
| 2070 | attach_id); |
| 2071 | } |
| 2072 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2073 | void BackFramebuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2074 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2075 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Destroy", |
| 2076 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2077 | glDeleteFramebuffersEXT(1, &id_); |
| 2078 | id_ = 0; |
| 2079 | } |
| 2080 | } |
| 2081 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2082 | void BackFramebuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2083 | id_ = 0; |
| 2084 | } |
| 2085 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2086 | GLenum BackFramebuffer::CheckStatus() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2087 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2088 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::CheckStatus", |
| 2089 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2090 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2091 | return glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 2092 | } |
| 2093 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2094 | GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) { |
| 2095 | return new GLES2DecoderImpl(group); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2096 | } |
| 2097 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2098 | GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2099 | : GLES2Decoder(), |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2100 | group_(group), |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 2101 | logger_(&debug_marker_manager_), |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 2102 | state_(group_->feature_info(), &logger_), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2103 | unpack_flip_y_(false), |
| 2104 | unpack_premultiply_alpha_(false), |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 2105 | unpack_unpremultiply_alpha_(false), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2106 | attrib_0_buffer_id_(0), |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 2107 | attrib_0_buffer_matches_value_(true), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2108 | attrib_0_size_(0), |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2109 | fixed_attrib_buffer_id_(0), |
| 2110 | fixed_attrib_buffer_size_(0), |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2111 | offscreen_target_color_format_(0), |
| 2112 | offscreen_target_depth_format_(0), |
| 2113 | offscreen_target_stencil_format_(0), |
| 2114 | offscreen_target_samples_(0), |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2115 | offscreen_target_buffer_preserved_(true), |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2116 | offscreen_saved_color_format_(0), |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 2117 | back_buffer_color_format_(0), |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2118 | back_buffer_has_depth_(false), |
| 2119 | back_buffer_has_stencil_(false), |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 2120 | backbuffer_needs_clear_bits_(0), |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 2121 | current_decoder_error_(error::kNoError), |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 2122 | use_shader_translator_(true), |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 2123 | validators_(group_->feature_info()->validators()), |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 2124 | feature_info_(group_->feature_info()), |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2125 | frame_number_(0), |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2126 | has_robustness_extension_(false), |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 2127 | reset_status_(GL_NO_ERROR), |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 2128 | reset_by_robustness_extension_(false), |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2129 | force_webgl_glsl_validation_(false), |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2130 | derivatives_explicitly_enabled_(false), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2131 | frag_depth_explicitly_enabled_(false), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 2132 | draw_buffers_explicitly_enabled_(false), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2133 | compile_shader_always_succeeds_(false), |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 2134 | service_logging_(CommandLine::ForCurrentProcess()->HasSwitch( |
| 2135 | switches::kEnableGPUServiceLoggingGPU)), |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2136 | viewport_max_width_(0), |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2137 | viewport_max_height_(0), |
| 2138 | validation_texture_(0), |
| 2139 | validation_fbo_multisample_(0), |
| 2140 | validation_fbo_(0) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2141 | DCHECK(group); |
| 2142 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2143 | attrib_0_value_.v[0] = 0.0f; |
| 2144 | attrib_0_value_.v[1] = 0.0f; |
| 2145 | attrib_0_value_.v[2] = 0.0f; |
| 2146 | attrib_0_value_.v[3] = 1.0f; |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2147 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2148 | // The shader translator is used for WebGL even when running on EGL |
| 2149 | // because additional restrictions are needed (like only enabling |
| 2150 | // GL_OES_standard_derivatives on demand). It is used for the unit |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 2151 | // tests because GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes |
| 2152 | // the empty string to CompileShader and this is not a valid shader. |
| 2153 | if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL || |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2154 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 2155 | switches::kDisableGLSLTranslator)) { |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2156 | use_shader_translator_ = false; |
| 2157 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 2158 | |
[email protected] | a3937065 | 2012-09-25 21:52:13 | [diff] [blame] | 2159 | // TODO(gman): Consider setting this based on GPU and/or driver. |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 2160 | if (IsAngle()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2161 | texture_state_.teximage2d_faster_than_texsubimage2d = false; |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 2162 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2163 | } |
| 2164 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2165 | GLES2DecoderImpl::~GLES2DecoderImpl() { |
| 2166 | } |
| 2167 | |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2168 | bool GLES2DecoderImpl::Initialize( |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2169 | const scoped_refptr<gfx::GLSurface>& surface, |
| 2170 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2171 | bool offscreen, |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2172 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2173 | const DisallowedFeatures& disallowed_features, |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2174 | const std::vector<int32>& attribs) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 2175 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2176 | DCHECK(context->IsCurrent(surface.get())); |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 2177 | DCHECK(!context_.get()); |
| 2178 | |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 2179 | set_initialized(); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 2180 | gpu_tracer_ = GPUTracer::Create(); |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 2181 | gpu_state_tracer_ = GPUStateTracer::Create(&state_); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 2182 | |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 2183 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2184 | switches::kEnableGPUDebugging)) { |
| 2185 | set_debug(true); |
| 2186 | } |
| 2187 | |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2188 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2189 | switches::kEnableGPUCommandLogging)) { |
| 2190 | set_log_commands(true); |
| 2191 | } |
| 2192 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2193 | compile_shader_always_succeeds_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 2194 | switches::kCompileShaderAlwaysSucceeds); |
| 2195 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 2196 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2197 | // Take ownership of the context and surface. The surface can be replaced with |
| 2198 | // SetSurface. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2199 | context_ = context; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2200 | surface_ = surface; |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2201 | |
[email protected] | 956aec5 | 2013-09-05 15:41:19 | [diff] [blame] | 2202 | if (!group_->Initialize(this, disallowed_features)) { |
[email protected] | 09ddb91f | 2011-04-14 23:16:22 | [diff] [blame] | 2203 | LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2204 | << "failed to initialize."; |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 2205 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2206 | Destroy(true); |
[email protected] | ae174109 | 2010-11-17 19:16:03 | [diff] [blame] | 2207 | return false; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2208 | } |
[email protected] | b64c2495 | 2012-04-19 03:20:27 | [diff] [blame] | 2209 | CHECK_GL_ERROR(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2210 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2211 | disallowed_features_ = disallowed_features; |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2212 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 2213 | state_.attrib_values.resize(group_->max_vertex_attribs()); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2214 | default_vertex_attrib_manager_ = new VertexAttribManager(); |
| 2215 | default_vertex_attrib_manager_->Initialize(group_->max_vertex_attribs()); |
| 2216 | |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 2217 | // vertex_attrib_manager is set to default_vertex_attrib_manager_ by this call |
| 2218 | DoBindVertexArrayOES(0); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 2219 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2220 | query_manager_.reset(new QueryManager(this, feature_info_.get())); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2221 | vertex_array_manager_.reset(new VertexArrayManager()); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 2222 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2223 | util_.set_num_compressed_texture_formats( |
| 2224 | validators_->compressed_texture_format.GetValues().size()); |
| 2225 | |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 2226 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2227 | // We have to enable vertex array 0 on OpenGL or it won't render. Note that |
| 2228 | // OpenGL ES 2.0 does not have this issue. |
| 2229 | glEnableVertexAttribArray(0); |
| 2230 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2231 | glGenBuffersARB(1, &attrib_0_buffer_id_); |
| 2232 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 2233 | glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); |
| 2234 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2235 | glGenBuffersARB(1, &fixed_attrib_buffer_id_); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 2236 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2237 | state_.texture_units.resize(group_->max_texture_units()); |
| 2238 | for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) { |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2239 | glActiveTexture(GL_TEXTURE0 + tt); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2240 | // We want the last bind to be 2D. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2241 | TextureRef* ref; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2242 | if (features().oes_egl_image_external) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2243 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2244 | GL_TEXTURE_EXTERNAL_OES); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2245 | state_.texture_units[tt].bound_texture_external_oes = ref; |
| 2246 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, ref->service_id()); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2247 | } |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2248 | if (features().arb_texture_rectangle) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2249 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2250 | GL_TEXTURE_RECTANGLE_ARB); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2251 | state_.texture_units[tt].bound_texture_rectangle_arb = ref; |
| 2252 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, ref->service_id()); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2253 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2254 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
| 2255 | state_.texture_units[tt].bound_texture_cube_map = ref; |
| 2256 | glBindTexture(GL_TEXTURE_CUBE_MAP, ref->service_id()); |
| 2257 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
| 2258 | state_.texture_units[tt].bound_texture_2d = ref; |
| 2259 | glBindTexture(GL_TEXTURE_2D, ref->service_id()); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 2260 | } |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2261 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2262 | CHECK_GL_ERROR(); |
| 2263 | |
[email protected] | 763eaf7 | 2013-08-16 00:58:56 | [diff] [blame] | 2264 | ContextCreationAttribHelper attrib_parser; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2265 | if (!attrib_parser.Parse(attribs)) |
| 2266 | return false; |
[email protected] | 41c5636 | 2011-06-14 16:47:43 | [diff] [blame] | 2267 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2268 | if (offscreen) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2269 | if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && |
[email protected] | b060965 | 2012-12-14 07:24:54 | [diff] [blame] | 2270 | features().chromium_framebuffer_multisample) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2271 | // Per ext_framebuffer_multisample spec, need max bound on sample count. |
[email protected] | 0b1e9d7 | 2010-11-11 16:29:43 | [diff] [blame] | 2272 | // max_sample_count must be initialized to a sane value. If |
| 2273 | // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
| 2274 | GLint max_sample_count = 1; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2275 | glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
| 2276 | offscreen_target_samples_ = std::min(attrib_parser.samples_, |
| 2277 | max_sample_count); |
| 2278 | } else { |
| 2279 | offscreen_target_samples_ = 1; |
| 2280 | } |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2281 | offscreen_target_buffer_preserved_ = attrib_parser.buffer_preserved_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2282 | |
| 2283 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 2284 | const bool rgb8_supported = |
| 2285 | context_->HasExtension("GL_OES_rgb8_rgba8"); |
| 2286 | // The only available default render buffer formats in GLES2 have very |
| 2287 | // little precision. Don't enable multisampling unless 8-bit render |
| 2288 | // buffer formats are available--instead fall back to 8-bit textures. |
| 2289 | if (rgb8_supported && offscreen_target_samples_ > 1) { |
| 2290 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2291 | GL_RGBA8 : GL_RGB8; |
| 2292 | } else { |
| 2293 | offscreen_target_samples_ = 1; |
| 2294 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2295 | GL_RGBA : GL_RGB; |
| 2296 | } |
| 2297 | |
| 2298 | // ANGLE only supports packed depth/stencil formats, so use it if it is |
| 2299 | // available. |
| 2300 | const bool depth24_stencil8_supported = |
| 2301 | context_->HasExtension("GL_OES_packed_depth_stencil"); |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2302 | VLOG(1) << "GL_OES_packed_depth_stencil " |
| 2303 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2304 | if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && |
| 2305 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2306 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2307 | offscreen_target_stencil_format_ = 0; |
| 2308 | } else { |
| 2309 | // It may be the case that this depth/stencil combination is not |
| 2310 | // supported, but this will be checked later by CheckFramebufferStatus. |
| 2311 | offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? |
| 2312 | GL_DEPTH_COMPONENT16 : 0; |
| 2313 | offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? |
| 2314 | GL_STENCIL_INDEX8 : 0; |
| 2315 | } |
| 2316 | } else { |
| 2317 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2318 | GL_RGBA : GL_RGB; |
| 2319 | |
| 2320 | // If depth is requested at all, use the packed depth stencil format if |
| 2321 | // it's available, as some desktop GL drivers don't support any non-packed |
| 2322 | // formats for depth attachments. |
| 2323 | const bool depth24_stencil8_supported = |
| 2324 | context_->HasExtension("GL_EXT_packed_depth_stencil"); |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2325 | VLOG(1) << "GL_EXT_packed_depth_stencil " |
| 2326 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2327 | |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2328 | if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && |
| 2329 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2330 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2331 | offscreen_target_stencil_format_ = 0; |
| 2332 | } else { |
| 2333 | offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? |
| 2334 | GL_DEPTH_COMPONENT : 0; |
| 2335 | offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? |
| 2336 | GL_STENCIL_INDEX : 0; |
| 2337 | } |
| 2338 | } |
| 2339 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2340 | offscreen_saved_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2341 | GL_RGBA : GL_RGB; |
| 2342 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2343 | // Create the target frame buffer. This is the one that the client renders |
| 2344 | // directly to. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2345 | offscreen_target_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2346 | offscreen_target_frame_buffer_->Create(); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2347 | // Due to GLES2 format limitations, either the color texture (for |
| 2348 | // non-multisampling) or the color render buffer (for multisampling) will be |
| 2349 | // attached to the offscreen frame buffer. The render buffer has more |
| 2350 | // limited formats available to it, but the texture can't do multisampling. |
| 2351 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2352 | offscreen_target_color_render_buffer_.reset(new BackRenderbuffer( |
| 2353 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2354 | offscreen_target_color_render_buffer_->Create(); |
| 2355 | } else { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2356 | offscreen_target_color_texture_.reset(new BackTexture( |
| 2357 | memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2358 | offscreen_target_color_texture_->Create(); |
| 2359 | } |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2360 | offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer( |
| 2361 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2362 | offscreen_target_depth_render_buffer_->Create(); |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2363 | offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer( |
| 2364 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2365 | offscreen_target_stencil_render_buffer_->Create(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2366 | |
| 2367 | // Create the saved offscreen texture. The target frame buffer is copied |
| 2368 | // here when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2369 | offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2370 | offscreen_saved_frame_buffer_->Create(); |
| 2371 | // |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2372 | offscreen_saved_color_texture_.reset(new BackTexture( |
| 2373 | memory_tracker(), &state_)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2374 | offscreen_saved_color_texture_->Create(); |
| 2375 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2376 | // Allocate the render buffers at their initial size and check the status |
| 2377 | // of the frame buffers is okay. |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2378 | if (!ResizeOffscreenFrameBuffer(size)) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 2379 | LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2380 | Destroy(true); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2381 | return false; |
| 2382 | } |
| 2383 | |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2384 | // Allocate the offscreen saved color texture. |
| 2385 | DCHECK(offscreen_saved_color_format_); |
| 2386 | offscreen_saved_color_texture_->AllocateStorage( |
| 2387 | gfx::Size(1, 1), offscreen_saved_color_format_, true); |
| 2388 | |
| 2389 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 2390 | offscreen_saved_color_texture_.get()); |
| 2391 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 2392 | GL_FRAMEBUFFER_COMPLETE) { |
| 2393 | LOG(ERROR) << "Offscreen saved FBO was incomplete."; |
| 2394 | Destroy(true); |
| 2395 | return false; |
| 2396 | } |
| 2397 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2398 | // Bind to the new default frame buffer (the offscreen target frame buffer). |
| 2399 | // This should now be associated with ID zero. |
| 2400 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 2401 | } else { |
| 2402 | glBindFramebufferEXT(GL_FRAMEBUFFER, GetBackbufferServiceId()); |
| 2403 | // These are NOT if the back buffer has these proprorties. They are |
| 2404 | // if we want the command buffer to enforce them regardless of what |
| 2405 | // the real backbuffer is assuming the real back buffer gives us more than |
| 2406 | // we ask for. In other words, if we ask for RGB and we get RGBA then we'll |
| 2407 | // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we |
| 2408 | // can't do anything about that. |
| 2409 | |
| 2410 | GLint v = 0; |
| 2411 | glGetIntegerv(GL_ALPHA_BITS, &v); |
| 2412 | // This checks if the user requested RGBA and we have RGBA then RGBA. If the |
| 2413 | // user requested RGB then RGB. If the user did not specify a preference |
| 2414 | // than use whatever we were given. Same for DEPTH and STENCIL. |
| 2415 | back_buffer_color_format_ = |
| 2416 | (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB; |
| 2417 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 2418 | back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0; |
| 2419 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 2420 | back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2421 | } |
| 2422 | |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2423 | // OpenGL ES 2.0 implicitly enables the desktop GL capability |
| 2424 | // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact |
| 2425 | // isn't well documented; it was discovered in the Khronos OpenGL ES |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2426 | // mailing list archives. It also implicitly enables the desktop GL |
| 2427 | // capability GL_POINT_SPRITE to provide access to the gl_PointCoord |
| 2428 | // variable in fragment shaders. |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2429 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2430 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2431 | glEnable(GL_POINT_SPRITE); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2432 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2433 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2434 | has_robustness_extension_ = |
| 2435 | context->HasExtension("GL_ARB_robustness") || |
| 2436 | context->HasExtension("GL_EXT_robustness"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2437 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2438 | if (!InitializeShaderTranslator()) { |
| 2439 | return false; |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2440 | } |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2441 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2442 | state_.viewport_width = size.width(); |
| 2443 | state_.viewport_height = size.height(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2444 | |
[email protected] | 5904806b | 2012-05-08 18:10:22 | [diff] [blame] | 2445 | GLint viewport_params[4] = { 0 }; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2446 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2447 | viewport_max_width_ = viewport_params[0]; |
| 2448 | viewport_max_height_ = viewport_params[1]; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2449 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2450 | state_.scissor_width = state_.viewport_width; |
| 2451 | state_.scissor_height = state_.viewport_height; |
| 2452 | |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2453 | // Set all the default state because some GL drivers get it wrong. |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 2454 | state_.InitCapabilities(); |
| 2455 | state_.InitState(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2456 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2457 | |
| 2458 | DoBindBuffer(GL_ARRAY_BUFFER, 0); |
| 2459 | DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 2460 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2461 | DoBindRenderbuffer(GL_RENDERBUFFER, 0); |
| 2462 | |
[email protected] | 88cfd13 | 2013-07-11 00:59:00 | [diff] [blame] | 2463 | bool call_gl_clear = true; |
| 2464 | #if defined(OS_ANDROID) |
| 2465 | // Temporary workaround for Android WebView because this clear ignores the |
| 2466 | // clip and corrupts that external UI of the App. Not calling glClear is ok |
| 2467 | // because the system already clears the buffer before each draw. Proper |
| 2468 | // fix might be setting the scissor clip properly before initialize. See |
| 2469 | // crbug.com/259023 for details. |
| 2470 | call_gl_clear = surface_->GetHandle(); |
| 2471 | #endif |
| 2472 | if (call_gl_clear) { |
| 2473 | // Clear the backbuffer. |
| 2474 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 2475 | } |
[email protected] | 561cc0a6 | 2013-05-07 18:34:45 | [diff] [blame] | 2476 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2477 | if (feature_info_->workarounds().reverse_point_sprite_coord_origin) { |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2478 | glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); |
| 2479 | } |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2480 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 2481 | if (feature_info_->workarounds().unbind_fbo_on_context_switch) { |
| 2482 | context_->SetUnbindFboOnMakeCurrent(); |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2483 | } |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2484 | |
[email protected] | 40245ccf | 2013-11-13 04:00:49 | [diff] [blame] | 2485 | if (feature_info_->workarounds().release_image_after_use) { |
| 2486 | image_manager()->SetReleaseAfterUse(); |
| 2487 | } |
| 2488 | |
[email protected] | 97419c0 | 2013-04-10 02:52:38 | [diff] [blame] | 2489 | // Only compositor contexts are known to use only the subset of GL |
| 2490 | // that can be safely migrated between the iGPU and the dGPU. Mark |
| 2491 | // those contexts as safe to forcibly transition between the GPUs. |
| 2492 | // http://crbug.com/180876, http://crbug.com/227228 |
| 2493 | if (!offscreen) |
| 2494 | context_->SetSafeToForceGpuSwitch(); |
| 2495 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 2496 | async_pixel_transfer_manager_.reset( |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 2497 | AsyncPixelTransferManager::Create(context.get())); |
| 2498 | async_pixel_transfer_manager_->Initialize(texture_manager()); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 2499 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 2500 | framebuffer_manager()->AddObserver(this); |
| 2501 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2502 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2503 | } |
| 2504 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2505 | void GLES2DecoderImpl::UpdateCapabilities() { |
| 2506 | util_.set_num_compressed_texture_formats( |
| 2507 | validators_->compressed_texture_format.GetValues().size()); |
| 2508 | util_.set_num_shader_binary_formats( |
| 2509 | validators_->shader_binary_format.GetValues().size()); |
| 2510 | } |
| 2511 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2512 | bool GLES2DecoderImpl::InitializeShaderTranslator() { |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 2513 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::InitializeShaderTranslator"); |
| 2514 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2515 | if (!use_shader_translator_) { |
| 2516 | return true; |
| 2517 | } |
| 2518 | ShBuiltInResources resources; |
| 2519 | ShInitBuiltInResources(&resources); |
| 2520 | resources.MaxVertexAttribs = group_->max_vertex_attribs(); |
| 2521 | resources.MaxVertexUniformVectors = |
| 2522 | group_->max_vertex_uniform_vectors(); |
| 2523 | resources.MaxVaryingVectors = group_->max_varying_vectors(); |
| 2524 | resources.MaxVertexTextureImageUnits = |
| 2525 | group_->max_vertex_texture_image_units(); |
| 2526 | resources.MaxCombinedTextureImageUnits = group_->max_texture_units(); |
| 2527 | resources.MaxTextureImageUnits = group_->max_texture_image_units(); |
| 2528 | resources.MaxFragmentUniformVectors = |
| 2529 | group_->max_fragment_uniform_vectors(); |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 2530 | resources.MaxDrawBuffers = group_->max_draw_buffers(); |
[email protected] | a0b7814 | 2013-05-23 00:47:24 | [diff] [blame] | 2531 | resources.MaxExpressionComplexity = 256; |
| 2532 | resources.MaxCallStackDepth = 256; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2533 | |
[email protected] | 9e98f61b | 2013-03-05 02:21:14 | [diff] [blame] | 2534 | #if (ANGLE_SH_VERSION >= 110) |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 2535 | GLint range[2] = { 0, 0 }; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 2536 | GLint precision = 0; |
| 2537 | GetShaderPrecisionFormatImpl(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, |
| 2538 | range, &precision); |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 2539 | resources.FragmentPrecisionHigh = |
| 2540 | PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision); |
[email protected] | 9e98f61b | 2013-03-05 02:21:14 | [diff] [blame] | 2541 | #endif |
| 2542 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2543 | if (force_webgl_glsl_validation_) { |
| 2544 | resources.OES_standard_derivatives = derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2545 | resources.EXT_frag_depth = frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 2546 | resources.EXT_draw_buffers = draw_buffers_explicitly_enabled_; |
[email protected] | cd8f189 | 2013-09-05 00:14:44 | [diff] [blame] | 2547 | if (!draw_buffers_explicitly_enabled_) |
| 2548 | resources.MaxDrawBuffers = 1; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2549 | } else { |
| 2550 | resources.OES_standard_derivatives = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2551 | features().oes_standard_derivatives ? 1 : 0; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2552 | resources.ARB_texture_rectangle = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2553 | features().arb_texture_rectangle ? 1 : 0; |
[email protected] | 70e7bb1 | 2012-09-29 14:01:06 | [diff] [blame] | 2554 | resources.OES_EGL_image_external = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2555 | features().oes_egl_image_external ? 1 : 0; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 2556 | resources.EXT_draw_buffers = |
| 2557 | features().ext_draw_buffers ? 1 : 0; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2558 | resources.EXT_frag_depth = |
| 2559 | features().ext_frag_depth ? 1 : 0; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2560 | } |
| 2561 | |
[email protected] | 26b6144 | 2013-03-17 16:12:01 | [diff] [blame] | 2562 | ShShaderSpec shader_spec = force_webgl_glsl_validation_ ? SH_WEBGL_SPEC |
| 2563 | : SH_GLES2_SPEC; |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2564 | if (shader_spec == SH_WEBGL_SPEC && features().enable_shader_name_hashing) |
[email protected] | 3d944a8 | 2013-02-12 19:09:02 | [diff] [blame] | 2565 | #if !defined(ANGLE_SH_VERSION) || ANGLE_SH_VERSION < 108 |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2566 | resources.HashFunction = &CityHashForAngle; |
[email protected] | 3d944a8 | 2013-02-12 19:09:02 | [diff] [blame] | 2567 | #else |
| 2568 | resources.HashFunction = &CityHash64; |
| 2569 | #endif |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2570 | else |
| 2571 | resources.HashFunction = NULL; |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2572 | ShaderTranslatorInterface::GlslImplementationType implementation_type = |
| 2573 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? |
| 2574 | ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2575 | int driver_bug_workarounds = 0; |
| 2576 | if (workarounds().needs_glsl_built_in_function_emulation) |
| 2577 | driver_bug_workarounds |= SH_EMULATE_BUILT_IN_FUNCTIONS; |
[email protected] | 81187c6 | 2013-09-09 23:54:54 | [diff] [blame] | 2578 | if (workarounds().init_gl_position_in_vertex_shader) |
| 2579 | driver_bug_workarounds |= SH_INIT_GL_POSITION; |
[email protected] | f0c8760 | 2013-10-17 19:34:11 | [diff] [blame] | 2580 | if (workarounds().unfold_short_circuit_as_ternary_operation) |
| 2581 | driver_bug_workarounds |= SH_UNFOLD_SHORT_CIRCUIT; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2582 | |
| 2583 | ShaderTranslatorCache* cache = ShaderTranslatorCache::GetInstance(); |
| 2584 | vertex_translator_ = cache->GetTranslator( |
| 2585 | SH_VERTEX_SHADER, shader_spec, &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2586 | implementation_type, |
| 2587 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2588 | if (!vertex_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2589 | LOG(ERROR) << "Could not initialize vertex shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2590 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2591 | return false; |
| 2592 | } |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2593 | |
| 2594 | fragment_translator_ = cache->GetTranslator( |
| 2595 | SH_FRAGMENT_SHADER, shader_spec, &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2596 | implementation_type, |
| 2597 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2598 | if (!fragment_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2599 | LOG(ERROR) << "Could not initialize fragment shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2600 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2601 | return false; |
| 2602 | } |
| 2603 | return true; |
| 2604 | } |
| 2605 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2606 | bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2607 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2608 | if (GetBuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2609 | return false; |
| 2610 | } |
| 2611 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2612 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2613 | glGenBuffersARB(n, service_ids.get()); |
| 2614 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2615 | CreateBuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2616 | } |
| 2617 | return true; |
| 2618 | } |
| 2619 | |
| 2620 | bool GLES2DecoderImpl::GenFramebuffersHelper( |
| 2621 | GLsizei n, const GLuint* client_ids) { |
| 2622 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2623 | if (GetFramebuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2624 | return false; |
| 2625 | } |
| 2626 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2627 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2628 | glGenFramebuffersEXT(n, service_ids.get()); |
| 2629 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2630 | CreateFramebuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2631 | } |
| 2632 | return true; |
| 2633 | } |
| 2634 | |
| 2635 | bool GLES2DecoderImpl::GenRenderbuffersHelper( |
| 2636 | GLsizei n, const GLuint* client_ids) { |
| 2637 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2638 | if (GetRenderbuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2639 | return false; |
| 2640 | } |
| 2641 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2642 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2643 | glGenRenderbuffersEXT(n, service_ids.get()); |
| 2644 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2645 | CreateRenderbuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2646 | } |
| 2647 | return true; |
| 2648 | } |
| 2649 | |
| 2650 | bool GLES2DecoderImpl::GenTexturesHelper(GLsizei n, const GLuint* client_ids) { |
| 2651 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2652 | if (GetTexture(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2653 | return false; |
| 2654 | } |
| 2655 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2656 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2657 | glGenTextures(n, service_ids.get()); |
| 2658 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2659 | CreateTexture(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2660 | } |
| 2661 | return true; |
| 2662 | } |
| 2663 | |
| 2664 | void GLES2DecoderImpl::DeleteBuffersHelper( |
| 2665 | GLsizei n, const GLuint* client_ids) { |
| 2666 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 2667 | Buffer* buffer = GetBuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2668 | if (buffer && !buffer->IsDeleted()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2669 | state_.vertex_attrib_manager->Unbind(buffer); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2670 | if (state_.bound_array_buffer.get() == buffer) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2671 | state_.bound_array_buffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2672 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2673 | RemoveBuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2674 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2675 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2676 | } |
| 2677 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2678 | void GLES2DecoderImpl::DeleteFramebuffersHelper( |
| 2679 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2680 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2681 | features().chromium_framebuffer_multisample; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2682 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2683 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2684 | Framebuffer* framebuffer = |
| 2685 | GetFramebuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2686 | if (framebuffer && !framebuffer->IsDeleted()) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2687 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2688 | framebuffer_state_.bound_draw_framebuffer = NULL; |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2689 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2690 | GLenum target = supports_separate_framebuffer_binds ? |
| 2691 | GL_DRAW_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2692 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
| 2693 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2694 | if (framebuffer == framebuffer_state_.bound_read_framebuffer.get()) { |
| 2695 | framebuffer_state_.bound_read_framebuffer = NULL; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2696 | GLenum target = supports_separate_framebuffer_binds ? |
| 2697 | GL_READ_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2698 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2699 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 2700 | OnFboChanged(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2701 | RemoveFramebuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2702 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2703 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2704 | } |
| 2705 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2706 | void GLES2DecoderImpl::DeleteRenderbuffersHelper( |
| 2707 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2708 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2709 | features().chromium_framebuffer_multisample; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2710 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2711 | Renderbuffer* renderbuffer = |
| 2712 | GetRenderbuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2713 | if (renderbuffer && !renderbuffer->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2714 | if (state_.bound_renderbuffer.get() == renderbuffer) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2715 | state_.bound_renderbuffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2716 | } |
| 2717 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2718 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2719 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 2720 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2721 | ->UnbindRenderbuffer(GL_READ_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2722 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2723 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2724 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2725 | ->UnbindRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2726 | } |
| 2727 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2728 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2729 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2730 | ->UnbindRenderbuffer(GL_FRAMEBUFFER, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2731 | } |
| 2732 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2733 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2734 | RemoveRenderbuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2735 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2736 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2737 | } |
| 2738 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2739 | void GLES2DecoderImpl::DeleteTexturesHelper( |
| 2740 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2741 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2742 | features().chromium_framebuffer_multisample; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2743 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2744 | TextureRef* texture_ref = GetTexture(client_ids[ii]); |
| 2745 | if (texture_ref) { |
| 2746 | Texture* texture = texture_ref->texture(); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2747 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2748 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2749 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2750 | // Unbind texture_ref from texture_ref units. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2751 | for (size_t jj = 0; jj < state_.texture_units.size(); ++jj) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2752 | state_.texture_units[jj].Unbind(texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2753 | } |
| 2754 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2755 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2756 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 2757 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2758 | ->UnbindTexture(GL_READ_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2759 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2760 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2761 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2762 | ->UnbindTexture(GL_DRAW_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2763 | } |
| 2764 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2765 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2766 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2767 | ->UnbindTexture(GL_FRAMEBUFFER, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2768 | } |
| 2769 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2770 | #if defined(OS_MACOSX) |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 2771 | GLuint service_id = texture->service_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2772 | if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { |
| 2773 | ReleaseIOSurfaceForTexture(service_id); |
| 2774 | } |
| 2775 | #endif |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2776 | RemoveTexture(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2777 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2778 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2779 | } |
| 2780 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 2781 | // } // anonymous namespace |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2782 | |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2783 | bool GLES2DecoderImpl::MakeCurrent() { |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2784 | if (!context_.get() || !context_->MakeCurrent(surface_.get())) |
| 2785 | return false; |
| 2786 | |
| 2787 | if (WasContextLost()) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2788 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during MakeCurrent."; |
[email protected] | e9f0ca8 | 2013-04-01 23:52:29 | [diff] [blame] | 2789 | |
| 2790 | // Some D3D drivers cannot recover from device lost in the GPU process |
| 2791 | // sandbox. Allow a new GPU process to launch. |
| 2792 | if (workarounds().exit_on_context_lost) { |
| 2793 | LOG(ERROR) << "Exiting GPU process because some drivers cannot reset" |
| 2794 | << " a D3D device in the Chrome GPU process sandbox."; |
[email protected] | 6eb77535 | 2013-08-27 05:57:16 | [diff] [blame] | 2795 | #if defined(OS_WIN) |
| 2796 | base::win::SetShouldCrashOnProcessDetach(false); |
| 2797 | #endif |
[email protected] | e9f0ca8 | 2013-04-01 23:52:29 | [diff] [blame] | 2798 | exit(0); |
| 2799 | } |
| 2800 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2801 | return false; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2802 | } |
| 2803 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 2804 | ProcessFinishedAsyncTransfers(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 2805 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 2806 | // Rebind the FBO if it was unbound by the context. |
| 2807 | if (workarounds().unbind_fbo_on_context_switch) |
| 2808 | RestoreFramebufferBindings(); |
| 2809 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2810 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2811 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 2812 | return true; |
| 2813 | } |
| 2814 | |
| 2815 | void GLES2DecoderImpl::ProcessFinishedAsyncTransfers() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 2816 | ProcessPendingReadPixels(); |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 2817 | if (engine() && query_manager_.get()) |
| 2818 | query_manager_->ProcessPendingTransferQueries(); |
| 2819 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 2820 | // TODO(epenner): Is there a better place to do this? |
| 2821 | // This needs to occur before we execute any batch of commands |
| 2822 | // from the client, as the client may have recieved an async |
| 2823 | // completion while issuing those commands. |
| 2824 | // "DidFlushStart" would be ideal if we had such a callback. |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 2825 | async_pixel_transfer_manager_->BindCompletedAsyncTransfers(); |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2826 | } |
| 2827 | |
[email protected] | a96a602 | 2011-11-04 00:58:12 | [diff] [blame] | 2828 | void GLES2DecoderImpl::ReleaseCurrent() { |
| 2829 | if (context_.get()) |
| 2830 | context_->ReleaseCurrent(surface_.get()); |
| 2831 | } |
| 2832 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2833 | static void RebindCurrentFramebuffer( |
| 2834 | GLenum target, |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 2835 | Framebuffer* framebuffer, |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2836 | GLuint back_buffer_service_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 2837 | GLuint framebuffer_id = framebuffer ? framebuffer->service_id() : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2838 | |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2839 | if (framebuffer_id == 0) { |
| 2840 | framebuffer_id = back_buffer_service_id; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2841 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2842 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2843 | glBindFramebufferEXT(target, framebuffer_id); |
| 2844 | } |
| 2845 | |
| 2846 | void GLES2DecoderImpl::RestoreCurrentFramebufferBindings() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2847 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2848 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2849 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2850 | RebindCurrentFramebuffer( |
| 2851 | GL_FRAMEBUFFER, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2852 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2853 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2854 | } else { |
| 2855 | RebindCurrentFramebuffer( |
| 2856 | GL_READ_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2857 | framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2858 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2859 | RebindCurrentFramebuffer( |
| 2860 | GL_DRAW_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2861 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2862 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2863 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 2864 | OnFboChanged(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2865 | } |
| 2866 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2867 | bool GLES2DecoderImpl::CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2868 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2869 | GLenum target, const char* func_name) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2870 | if (!framebuffer) { |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 2871 | if (backbuffer_needs_clear_bits_) { |
| 2872 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
| 2873 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
| 2874 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 2875 | glClearStencil(0); |
| 2876 | glStencilMask(-1); |
| 2877 | glClearDepth(1.0f); |
| 2878 | glDepthMask(true); |
| 2879 | glDisable(GL_SCISSOR_TEST); |
| 2880 | glClear(backbuffer_needs_clear_bits_); |
| 2881 | backbuffer_needs_clear_bits_ = 0; |
| 2882 | RestoreClearState(); |
| 2883 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2884 | return true; |
| 2885 | } |
| 2886 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2887 | if (framebuffer_manager()->IsComplete(framebuffer)) { |
| 2888 | return true; |
| 2889 | } |
| 2890 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2891 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 2892 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2893 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 2894 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, "framebuffer incomplete"); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 2895 | return false; |
| 2896 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2897 | |
| 2898 | // Are all the attachments cleared? |
| 2899 | if (renderbuffer_manager()->HaveUnclearedRenderbuffers() || |
| 2900 | texture_manager()->HaveUnclearedMips()) { |
| 2901 | if (!framebuffer->IsCleared()) { |
| 2902 | // Can we clear them? |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 2903 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 2904 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2905 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 2906 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 2907 | "framebuffer incomplete (clear)"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2908 | return false; |
| 2909 | } |
| 2910 | ClearUnclearedAttachments(target, framebuffer); |
| 2911 | } |
| 2912 | } |
| 2913 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2914 | if (!framebuffer_manager()->IsComplete(framebuffer)) { |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 2915 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 2916 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2917 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 2918 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 2919 | "framebuffer incomplete (check)"); |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2920 | return false; |
| 2921 | } |
| 2922 | framebuffer_manager()->MarkAsComplete(framebuffer); |
| 2923 | } |
| 2924 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2925 | // NOTE: At this point we don't know if the framebuffer is complete but |
| 2926 | // we DO know that everything that needs to be cleared has been cleared. |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 2927 | return true; |
| 2928 | } |
| 2929 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2930 | bool GLES2DecoderImpl::CheckBoundFramebuffersValid(const char* func_name) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2931 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 2932 | bool valid = CheckFramebufferValid( |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2933 | framebuffer_state_.bound_draw_framebuffer.get(), GL_FRAMEBUFFER_EXT, |
| 2934 | func_name); |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 2935 | |
| 2936 | if (valid) |
| 2937 | OnUseFramebuffer(); |
| 2938 | |
| 2939 | return valid; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2940 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2941 | return CheckFramebufferValid(framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2942 | GL_DRAW_FRAMEBUFFER_EXT, |
| 2943 | func_name) && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2944 | CheckFramebufferValid(framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2945 | GL_READ_FRAMEBUFFER_EXT, |
| 2946 | func_name); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2947 | } |
| 2948 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2949 | gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2950 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2951 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2952 | if (framebuffer != NULL) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2953 | const Framebuffer::Attachment* attachment = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2954 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2955 | if (attachment) { |
| 2956 | return gfx::Size(attachment->width(), attachment->height()); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2957 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2958 | return gfx::Size(0, 0); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2959 | } else if (offscreen_target_frame_buffer_.get()) { |
| 2960 | return offscreen_size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2961 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 2962 | return surface_->GetSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2963 | } |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2964 | } |
| 2965 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2966 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2967 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2968 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2969 | if (framebuffer != NULL) { |
| 2970 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2971 | } else if (offscreen_target_frame_buffer_.get()) { |
| 2972 | return offscreen_target_color_format_; |
| 2973 | } else { |
| 2974 | return back_buffer_color_format_; |
| 2975 | } |
| 2976 | } |
| 2977 | |
| 2978 | GLenum GLES2DecoderImpl::GetBoundDrawFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2979 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2980 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2981 | if (framebuffer != NULL) { |
| 2982 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2983 | } else if (offscreen_target_frame_buffer_.get()) { |
| 2984 | return offscreen_target_color_format_; |
| 2985 | } else { |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 2986 | return back_buffer_color_format_; |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 2987 | } |
| 2988 | } |
| 2989 | |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 2990 | void GLES2DecoderImpl::UpdateParentTextureInfo() { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 2991 | if (!offscreen_saved_color_texture_info_.get()) |
| 2992 | return; |
| 2993 | GLenum target = offscreen_saved_color_texture_info_->texture()->target(); |
| 2994 | glBindTexture(target, offscreen_saved_color_texture_info_->service_id()); |
| 2995 | texture_manager()->SetLevelInfo( |
| 2996 | offscreen_saved_color_texture_info_.get(), |
| 2997 | GL_TEXTURE_2D, |
| 2998 | 0, // level |
| 2999 | GL_RGBA, |
| 3000 | offscreen_size_.width(), |
| 3001 | offscreen_size_.height(), |
| 3002 | 1, // depth |
| 3003 | 0, // border |
| 3004 | GL_RGBA, |
| 3005 | GL_UNSIGNED_BYTE, |
| 3006 | true); |
| 3007 | texture_manager()->SetParameter( |
| 3008 | "UpdateParentTextureInfo", |
| 3009 | GetErrorState(), |
| 3010 | offscreen_saved_color_texture_info_.get(), |
| 3011 | GL_TEXTURE_MAG_FILTER, |
| 3012 | GL_NEAREST); |
| 3013 | texture_manager()->SetParameter( |
| 3014 | "UpdateParentTextureInfo", |
| 3015 | GetErrorState(), |
| 3016 | offscreen_saved_color_texture_info_.get(), |
| 3017 | GL_TEXTURE_MIN_FILTER, |
| 3018 | GL_NEAREST); |
| 3019 | texture_manager()->SetParameter( |
| 3020 | "UpdateParentTextureInfo", |
| 3021 | GetErrorState(), |
| 3022 | offscreen_saved_color_texture_info_.get(), |
| 3023 | GL_TEXTURE_WRAP_S, |
| 3024 | GL_CLAMP_TO_EDGE); |
| 3025 | texture_manager()->SetParameter( |
| 3026 | "UpdateParentTextureInfo", |
| 3027 | GetErrorState(), |
| 3028 | offscreen_saved_color_texture_info_.get(), |
| 3029 | GL_TEXTURE_WRAP_T, |
| 3030 | GL_CLAMP_TO_EDGE); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3031 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 3032 | &state_, target); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3033 | glBindTexture(target, texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3034 | } |
| 3035 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3036 | void GLES2DecoderImpl::SetResizeCallback( |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3037 | const base::Callback<void(gfx::Size, float)>& callback) { |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3038 | resize_callback_ = callback; |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3039 | } |
| 3040 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 3041 | Logger* GLES2DecoderImpl::GetLogger() { |
| 3042 | return &logger_; |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 3043 | } |
| 3044 | |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 3045 | ErrorState* GLES2DecoderImpl::GetErrorState() { |
| 3046 | return state_.GetErrorState(); |
| 3047 | } |
| 3048 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 3049 | void GLES2DecoderImpl::SetShaderCacheCallback( |
| 3050 | const ShaderCacheCallback& callback) { |
| 3051 | shader_cache_callback_ = callback; |
| 3052 | } |
| 3053 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 3054 | void GLES2DecoderImpl::SetWaitSyncPointCallback( |
| 3055 | const WaitSyncPointCallback& callback) { |
| 3056 | wait_sync_point_callback_ = callback; |
| 3057 | } |
| 3058 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3059 | AsyncPixelTransferManager* |
| 3060 | GLES2DecoderImpl::GetAsyncPixelTransferManager() { |
| 3061 | return async_pixel_transfer_manager_.get(); |
| 3062 | } |
| 3063 | |
| 3064 | void GLES2DecoderImpl::ResetAsyncPixelTransferManagerForTest() { |
| 3065 | async_pixel_transfer_manager_.reset(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 3066 | } |
| 3067 | |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 3068 | void GLES2DecoderImpl::SetAsyncPixelTransferManagerForTest( |
| 3069 | AsyncPixelTransferManager* manager) { |
| 3070 | async_pixel_transfer_manager_ = make_scoped_ptr(manager); |
| 3071 | } |
| 3072 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3073 | bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, |
| 3074 | uint32* service_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3075 | TextureRef* texture_ref = texture_manager()->GetTexture(client_texture_id); |
| 3076 | if (texture_ref) { |
| 3077 | *service_texture_id = texture_ref->service_id(); |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3078 | return true; |
| 3079 | } |
| 3080 | return false; |
| 3081 | } |
| 3082 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3083 | uint32 GLES2DecoderImpl::GetTextureUploadCount() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3084 | return texture_state_.texture_upload_count + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3085 | async_pixel_transfer_manager_->GetTextureUploadCount(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | base::TimeDelta GLES2DecoderImpl::GetTotalTextureUploadTime() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3089 | return texture_state_.total_texture_upload_time + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3090 | async_pixel_transfer_manager_->GetTotalTextureUploadTime(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3091 | } |
| 3092 | |
| 3093 | base::TimeDelta GLES2DecoderImpl::GetTotalProcessingCommandsTime() { |
| 3094 | return total_processing_commands_time_; |
| 3095 | } |
| 3096 | |
[email protected] | dc25dda | 2012-09-27 21:36:30 | [diff] [blame] | 3097 | void GLES2DecoderImpl::AddProcessingCommandsTime(base::TimeDelta time) { |
| 3098 | total_processing_commands_time_ += time; |
| 3099 | } |
| 3100 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3101 | void GLES2DecoderImpl::Destroy(bool have_context) { |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 3102 | if (!initialized()) |
| 3103 | return; |
| 3104 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3105 | DCHECK(!have_context || context_->IsCurrent(NULL)); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3106 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3107 | // Unbind everything. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3108 | state_.vertex_attrib_manager = NULL; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 3109 | default_vertex_attrib_manager_ = NULL; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3110 | state_.texture_units.clear(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3111 | state_.bound_array_buffer = NULL; |
| 3112 | state_.current_query = NULL; |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3113 | framebuffer_state_.bound_read_framebuffer = NULL; |
| 3114 | framebuffer_state_.bound_draw_framebuffer = NULL; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3115 | state_.bound_renderbuffer = NULL; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3116 | |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 3117 | if (offscreen_saved_color_texture_info_.get()) { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3118 | DCHECK(offscreen_target_color_texture_); |
| 3119 | DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), |
| 3120 | offscreen_saved_color_texture_->id()); |
| 3121 | offscreen_saved_color_texture_->Invalidate(); |
| 3122 | offscreen_saved_color_texture_info_ = NULL; |
| 3123 | } |
[email protected] | eadc9679 | 2010-10-27 19:39:39 | [diff] [blame] | 3124 | if (have_context) { |
[email protected] | c322e88 | 2012-05-23 18:06:18 | [diff] [blame] | 3125 | if (copy_texture_CHROMIUM_.get()) { |
| 3126 | copy_texture_CHROMIUM_->Destroy(); |
| 3127 | copy_texture_CHROMIUM_.reset(); |
| 3128 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3129 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3130 | if (state_.current_program.get()) { |
| 3131 | program_manager()->UnuseProgram(shader_manager(), |
| 3132 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 3133 | } |
| 3134 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3135 | if (attrib_0_buffer_id_) { |
| 3136 | glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
| 3137 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 3138 | if (fixed_attrib_buffer_id_) { |
| 3139 | glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); |
| 3140 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3141 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 3142 | if (validation_texture_) { |
| 3143 | glDeleteTextures(1, &validation_texture_); |
| 3144 | glDeleteFramebuffersEXT(1, &validation_fbo_multisample_); |
| 3145 | glDeleteFramebuffersEXT(1, &validation_fbo_); |
| 3146 | } |
| 3147 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3148 | if (offscreen_target_frame_buffer_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3149 | offscreen_target_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3150 | if (offscreen_target_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3151 | offscreen_target_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3152 | if (offscreen_target_color_render_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3153 | offscreen_target_color_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3154 | if (offscreen_target_depth_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3155 | offscreen_target_depth_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3156 | if (offscreen_target_stencil_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3157 | offscreen_target_stencil_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3158 | if (offscreen_saved_frame_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3159 | offscreen_saved_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3160 | if (offscreen_saved_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3161 | offscreen_saved_color_texture_->Destroy(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3162 | if (offscreen_resolved_frame_buffer_.get()) |
| 3163 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3164 | if (offscreen_resolved_color_texture_.get()) |
| 3165 | offscreen_resolved_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3166 | } else { |
| 3167 | if (offscreen_target_frame_buffer_.get()) |
| 3168 | offscreen_target_frame_buffer_->Invalidate(); |
| 3169 | if (offscreen_target_color_texture_.get()) |
| 3170 | offscreen_target_color_texture_->Invalidate(); |
| 3171 | if (offscreen_target_color_render_buffer_.get()) |
| 3172 | offscreen_target_color_render_buffer_->Invalidate(); |
| 3173 | if (offscreen_target_depth_render_buffer_.get()) |
| 3174 | offscreen_target_depth_render_buffer_->Invalidate(); |
| 3175 | if (offscreen_target_stencil_render_buffer_.get()) |
| 3176 | offscreen_target_stencil_render_buffer_->Invalidate(); |
| 3177 | if (offscreen_saved_frame_buffer_.get()) |
| 3178 | offscreen_saved_frame_buffer_->Invalidate(); |
| 3179 | if (offscreen_saved_color_texture_.get()) |
| 3180 | offscreen_saved_color_texture_->Invalidate(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3181 | if (offscreen_resolved_frame_buffer_.get()) |
| 3182 | offscreen_resolved_frame_buffer_->Invalidate(); |
| 3183 | if (offscreen_resolved_color_texture_.get()) |
| 3184 | offscreen_resolved_color_texture_->Invalidate(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 3185 | } |
[email protected] | 83a52d03 | 2013-07-24 10:30:37 | [diff] [blame] | 3186 | |
| 3187 | // Current program must be cleared after calling ProgramManager::UnuseProgram. |
| 3188 | // Otherwise, we can leak objects. http://crbug.com/258772. |
| 3189 | // state_.current_program must be reset before group_ is reset because |
| 3190 | // the later deletes the ProgramManager object that referred by |
| 3191 | // state_.current_program object. |
| 3192 | state_.current_program = NULL; |
| 3193 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3194 | copy_texture_CHROMIUM_.reset(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3195 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3196 | if (query_manager_.get()) { |
| 3197 | query_manager_->Destroy(have_context); |
| 3198 | query_manager_.reset(); |
| 3199 | } |
| 3200 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 3201 | if (vertex_array_manager_ .get()) { |
| 3202 | vertex_array_manager_->Destroy(have_context); |
| 3203 | vertex_array_manager_.reset(); |
| 3204 | } |
| 3205 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3206 | offscreen_target_frame_buffer_.reset(); |
| 3207 | offscreen_target_color_texture_.reset(); |
| 3208 | offscreen_target_color_render_buffer_.reset(); |
| 3209 | offscreen_target_depth_render_buffer_.reset(); |
| 3210 | offscreen_target_stencil_render_buffer_.reset(); |
| 3211 | offscreen_saved_frame_buffer_.reset(); |
| 3212 | offscreen_saved_color_texture_.reset(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3213 | offscreen_resolved_frame_buffer_.reset(); |
| 3214 | offscreen_resolved_color_texture_.reset(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3215 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3216 | // Should destroy the transfer manager before the texture manager held |
| 3217 | // by the context group. |
| 3218 | async_pixel_transfer_manager_.reset(); |
| 3219 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 3220 | framebuffer_manager()->RemoveObserver(this); |
| 3221 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3222 | if (group_.get()) { |
[email protected] | 2d9d3b9 | 2013-01-18 01:07:23 | [diff] [blame] | 3223 | group_->Destroy(this, have_context); |
| 3224 | group_ = NULL; |
| 3225 | } |
| 3226 | |
| 3227 | if (context_.get()) { |
| 3228 | context_->ReleaseCurrent(NULL); |
| 3229 | context_ = NULL; |
| 3230 | } |
| 3231 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3232 | #if defined(OS_MACOSX) |
| 3233 | for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); |
| 3234 | it != texture_to_io_surface_map_.end(); ++it) { |
| 3235 | CFRelease(it->second); |
| 3236 | } |
| 3237 | texture_to_io_surface_map_.clear(); |
| 3238 | #endif |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3239 | } |
| 3240 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3241 | void GLES2DecoderImpl::SetSurface( |
| 3242 | const scoped_refptr<gfx::GLSurface>& surface) { |
| 3243 | DCHECK(context_->IsCurrent(NULL)); |
| 3244 | DCHECK(surface_.get()); |
| 3245 | surface_ = surface; |
| 3246 | RestoreCurrentFramebufferBindings(); |
| 3247 | } |
| 3248 | |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3249 | bool GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) { |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 3250 | if (!offscreen_saved_color_texture_.get()) |
| 3251 | return false; |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3252 | if (!offscreen_saved_color_texture_info_.get()) { |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3253 | GLuint service_id = offscreen_saved_color_texture_->id(); |
[email protected] | f4647693 | 2013-06-08 05:36:07 | [diff] [blame] | 3254 | offscreen_saved_color_texture_info_ = TextureRef::Create( |
| 3255 | texture_manager(), 0, service_id); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3256 | texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), |
| 3257 | GL_TEXTURE_2D); |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 3258 | UpdateParentTextureInfo(); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3259 | } |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3260 | gpu::gles2::MailboxName name; |
| 3261 | memcpy(name.key, mailbox.name, sizeof(mailbox.name)); |
| 3262 | return mailbox_manager()->ProduceTexture( |
| 3263 | GL_TEXTURE_2D, name, offscreen_saved_color_texture_info_->texture()); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3264 | } |
| 3265 | |
[email protected] | 260ddc4e | 2012-06-28 00:01:53 | [diff] [blame] | 3266 | size_t GLES2DecoderImpl::GetBackbufferMemoryTotal() { |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 3267 | size_t total = 0; |
| 3268 | if (offscreen_target_frame_buffer_.get()) { |
| 3269 | if (offscreen_target_color_texture_.get()) { |
| 3270 | total += offscreen_target_color_texture_->estimated_size(); |
| 3271 | } |
| 3272 | if (offscreen_target_color_render_buffer_.get()) { |
| 3273 | total += offscreen_target_color_render_buffer_->estimated_size(); |
| 3274 | } |
| 3275 | if (offscreen_target_depth_render_buffer_.get()) { |
| 3276 | total += offscreen_target_depth_render_buffer_->estimated_size(); |
| 3277 | } |
| 3278 | if (offscreen_target_stencil_render_buffer_.get()) { |
| 3279 | total += offscreen_target_stencil_render_buffer_->estimated_size(); |
| 3280 | } |
| 3281 | if (offscreen_saved_color_texture_.get()) { |
| 3282 | total += offscreen_saved_color_texture_->estimated_size(); |
| 3283 | } |
| 3284 | if (offscreen_resolved_color_texture_.get()) { |
| 3285 | total += offscreen_resolved_color_texture_->estimated_size(); |
| 3286 | } |
| 3287 | } else { |
| 3288 | gfx::Size size = surface_->GetSize(); |
| 3289 | total += size.width() * size.height() * |
| 3290 | GLES2Util::RenderbufferBytesPerPixel(back_buffer_color_format_); |
| 3291 | } |
[email protected] | 260ddc4e | 2012-06-28 00:01:53 | [diff] [blame] | 3292 | return total; |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 3293 | } |
| 3294 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3295 | bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 3296 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3297 | if (!is_offscreen) { |
| 3298 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " |
| 3299 | << " with an onscreen framebuffer."; |
| 3300 | return false; |
| 3301 | } |
| 3302 | |
| 3303 | if (offscreen_size_ == size) |
| 3304 | return true; |
| 3305 | |
| 3306 | offscreen_size_ = size; |
| 3307 | int w = offscreen_size_.width(); |
| 3308 | int h = offscreen_size_.height(); |
| 3309 | if (w < 0 || h < 0 || h >= (INT_MAX / 4) / (w ? w : 1)) { |
| 3310 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3311 | << "to allocate storage due to excessive dimensions."; |
| 3312 | return false; |
| 3313 | } |
| 3314 | |
| 3315 | // Reallocate the offscreen target buffers. |
| 3316 | DCHECK(offscreen_target_color_format_); |
| 3317 | if (IsOffscreenBufferMultisampled()) { |
| 3318 | if (!offscreen_target_color_render_buffer_->AllocateStorage( |
| 3319 | offscreen_size_, offscreen_target_color_format_, |
| 3320 | offscreen_target_samples_)) { |
| 3321 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3322 | << "to allocate storage for offscreen target color buffer."; |
| 3323 | return false; |
| 3324 | } |
| 3325 | } else { |
| 3326 | if (!offscreen_target_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 3327 | offscreen_size_, offscreen_target_color_format_, false)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3328 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3329 | << "to allocate storage for offscreen target color texture."; |
| 3330 | return false; |
| 3331 | } |
| 3332 | } |
| 3333 | if (offscreen_target_depth_format_ && |
| 3334 | !offscreen_target_depth_render_buffer_->AllocateStorage( |
| 3335 | offscreen_size_, offscreen_target_depth_format_, |
| 3336 | offscreen_target_samples_)) { |
| 3337 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3338 | << "to allocate storage for offscreen target depth buffer."; |
| 3339 | return false; |
| 3340 | } |
| 3341 | if (offscreen_target_stencil_format_ && |
| 3342 | !offscreen_target_stencil_render_buffer_->AllocateStorage( |
| 3343 | offscreen_size_, offscreen_target_stencil_format_, |
| 3344 | offscreen_target_samples_)) { |
| 3345 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3346 | << "to allocate storage for offscreen target stencil buffer."; |
| 3347 | return false; |
| 3348 | } |
| 3349 | |
| 3350 | // Attach the offscreen target buffers to the target frame buffer. |
| 3351 | if (IsOffscreenBufferMultisampled()) { |
| 3352 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3353 | GL_COLOR_ATTACHMENT0, |
| 3354 | offscreen_target_color_render_buffer_.get()); |
| 3355 | } else { |
| 3356 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 3357 | offscreen_target_color_texture_.get()); |
| 3358 | } |
| 3359 | if (offscreen_target_depth_format_) { |
| 3360 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3361 | GL_DEPTH_ATTACHMENT, |
| 3362 | offscreen_target_depth_render_buffer_.get()); |
| 3363 | } |
| 3364 | const bool packed_depth_stencil = |
| 3365 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 3366 | if (packed_depth_stencil) { |
| 3367 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3368 | GL_STENCIL_ATTACHMENT, |
| 3369 | offscreen_target_depth_render_buffer_.get()); |
| 3370 | } else if (offscreen_target_stencil_format_) { |
| 3371 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3372 | GL_STENCIL_ATTACHMENT, |
| 3373 | offscreen_target_stencil_render_buffer_.get()); |
| 3374 | } |
| 3375 | |
| 3376 | if (offscreen_target_frame_buffer_->CheckStatus() != |
| 3377 | GL_FRAMEBUFFER_COMPLETE) { |
| 3378 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3379 | << "because offscreen FBO was incomplete."; |
| 3380 | return false; |
| 3381 | } |
| 3382 | |
| 3383 | // Clear the target frame buffer. |
| 3384 | { |
| 3385 | ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); |
| 3386 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
| 3387 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
| 3388 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 3389 | glClearStencil(0); |
| 3390 | glStencilMaskSeparate(GL_FRONT, -1); |
| 3391 | glStencilMaskSeparate(GL_BACK, -1); |
| 3392 | glClearDepth(0); |
| 3393 | glDepthMask(GL_TRUE); |
| 3394 | glDisable(GL_SCISSOR_TEST); |
| 3395 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 3396 | RestoreClearState(); |
| 3397 | } |
[email protected] | d85ef76d | 2011-09-08 22:21:43 | [diff] [blame] | 3398 | |
| 3399 | // Destroy the offscreen resolved framebuffers. |
| 3400 | if (offscreen_resolved_frame_buffer_.get()) |
| 3401 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3402 | if (offscreen_resolved_color_texture_.get()) |
| 3403 | offscreen_resolved_color_texture_->Destroy(); |
| 3404 | offscreen_resolved_color_texture_.reset(); |
| 3405 | offscreen_resolved_frame_buffer_.reset(); |
| 3406 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3407 | return true; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3408 | } |
| 3409 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3410 | error::Error GLES2DecoderImpl::HandleResizeCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3411 | uint32 immediate_data_size, const cmds::ResizeCHROMIUM& c) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 3412 | if (!offscreen_target_frame_buffer_.get() && surface_->DeferDraws()) |
[email protected] | 45212087 | 2012-09-27 15:21:02 | [diff] [blame] | 3413 | return error::kDeferCommandUntilLater; |
| 3414 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3415 | GLuint width = static_cast<GLuint>(c.width); |
| 3416 | GLuint height = static_cast<GLuint>(c.height); |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3417 | GLfloat scale_factor = c.scale_factor; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3418 | TRACE_EVENT2("gpu", "glResizeChromium", "width", width, "height", height); |
[email protected] | d16aa4b | 2013-02-14 22:35:41 | [diff] [blame] | 3419 | |
| 3420 | width = std::max(1U, width); |
| 3421 | height = std::max(1U, height); |
| 3422 | |
[email protected] | a0d98916 | 2011-11-22 13:15:07 | [diff] [blame] | 3423 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && \ |
| 3424 | !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3425 | // Make sure that we are done drawing to the back buffer before resizing. |
| 3426 | glFinish(); |
| 3427 | #endif |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3428 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3429 | if (is_offscreen) { |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3430 | if (!ResizeOffscreenFrameBuffer(gfx::Size(width, height))) { |
| 3431 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because " |
| 3432 | << "ResizeOffscreenFrameBuffer failed."; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3433 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3434 | } |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3435 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3436 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3437 | if (!resize_callback_.is_null()) { |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3438 | resize_callback_.Run(gfx::Size(width, height), scale_factor); |
[email protected] | 0e9346b | 2013-03-16 16:35:44 | [diff] [blame] | 3439 | DCHECK(context_->IsCurrent(surface_.get())); |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3440 | if (!context_->IsCurrent(surface_.get())) { |
| 3441 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because context no longer " |
| 3442 | << "current after resize callback."; |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3443 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3444 | } |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3445 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3446 | |
| 3447 | return error::kNoError; |
[email protected] | 43ecf37 | 2010-11-16 19:19:39 | [diff] [blame] | 3448 | } |
| 3449 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3450 | const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { |
| 3451 | if (command_id > kStartPoint && command_id < kNumCommands) { |
| 3452 | return gles2::GetCommandName(static_cast<CommandId>(command_id)); |
| 3453 | } |
| 3454 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 3455 | } |
| 3456 | |
| 3457 | // Decode command with its arguments, and call the corresponding GL function. |
| 3458 | // Note: args is a pointer to the command buffer. As such, it could be changed |
| 3459 | // by a (malicious) client at any time, so if validation has to happen, it |
| 3460 | // should operate on a copy of them. |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3461 | error::Error GLES2DecoderImpl::DoCommand( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3462 | unsigned int command, |
| 3463 | unsigned int arg_count, |
| 3464 | const void* cmd_data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3465 | error::Error result = error::kNoError; |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 3466 | if (log_commands()) { |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 3467 | // TODO(notme): Change this to a LOG/VLOG that works in release. Tried |
| 3468 | // LOG(INFO), tried VLOG(1), no luck. |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 3469 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "]" << "cmd: " |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 3470 | << GetCommandName(command); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3471 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3472 | unsigned int command_index = command - kStartPoint - 1; |
| 3473 | if (command_index < arraysize(g_command_info)) { |
| 3474 | const CommandInfo& info = g_command_info[command_index]; |
| 3475 | unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
| 3476 | if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
| 3477 | (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3478 | uint32 immediate_data_size = |
| 3479 | (arg_count - info_arg_count) * sizeof(CommandBufferEntry); // NOLINT |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3480 | switch (command) { |
| 3481 | #define GLES2_CMD_OP(name) \ |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3482 | case cmds::name::kCmdId: \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3483 | result = Handle ## name( \ |
| 3484 | immediate_data_size, \ |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3485 | *static_cast<const gles2::cmds::name*>(cmd_data)); \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3486 | break; \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3487 | |
| 3488 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3489 | #undef GLES2_CMD_OP |
[email protected] | bf0985e | 2009-12-17 03:04:38 | [diff] [blame] | 3490 | } |
| 3491 | if (debug()) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3492 | GLenum error; |
| 3493 | while ((error = glGetError()) != GL_NO_ERROR) { |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 3494 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "] " |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 3495 | << "GL ERROR: " << GLES2Util::GetStringEnum(error) << " : " |
| 3496 | << GetCommandName(command); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3497 | LOCAL_SET_GL_ERROR(error, "DoCommand", "GL error from driver"); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3498 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3499 | } |
| 3500 | } else { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3501 | result = error::kInvalidArguments; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3502 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3503 | } else { |
| 3504 | result = DoCommonCommand(command, arg_count, cmd_data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3505 | } |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 3506 | if (result == error::kNoError && current_decoder_error_ != error::kNoError) { |
| 3507 | result = current_decoder_error_; |
| 3508 | current_decoder_error_ = error::kNoError; |
| 3509 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3510 | return result; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3511 | } |
| 3512 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3513 | void GLES2DecoderImpl::RemoveBuffer(GLuint client_id) { |
| 3514 | buffer_manager()->RemoveBuffer(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3515 | } |
| 3516 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3517 | bool GLES2DecoderImpl::CreateProgramHelper(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3518 | if (GetProgram(client_id)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3519 | return false; |
| 3520 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3521 | GLuint service_id = glCreateProgram(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3522 | if (service_id != 0) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3523 | CreateProgram(client_id, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3524 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3525 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3526 | } |
| 3527 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3528 | bool GLES2DecoderImpl::CreateShaderHelper(GLenum type, GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3529 | if (GetShader(client_id)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3530 | return false; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3531 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3532 | GLuint service_id = glCreateShader(type); |
| 3533 | if (service_id != 0) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3534 | CreateShader(client_id, service_id, type); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3535 | } |
| 3536 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3537 | } |
| 3538 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3539 | void GLES2DecoderImpl::DoFinish() { |
| 3540 | glFinish(); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 3541 | ProcessPendingReadPixels(); |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 3542 | ProcessPendingQueries(); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3543 | } |
| 3544 | |
| 3545 | void GLES2DecoderImpl::DoFlush() { |
| 3546 | glFlush(); |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 3547 | ProcessPendingQueries(); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3548 | } |
| 3549 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3550 | void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3551 | GLuint texture_index = texture_unit - GL_TEXTURE0; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3552 | if (texture_index >= state_.texture_units.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3553 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 3554 | "glActiveTexture", texture_unit, "texture_unit"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3555 | return; |
| 3556 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3557 | state_.active_texture_unit = texture_index; |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3558 | glActiveTexture(texture_unit); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3559 | } |
| 3560 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3561 | void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3562 | Buffer* buffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3563 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3564 | if (client_id != 0) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3565 | buffer = GetBuffer(client_id); |
| 3566 | if (!buffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3567 | if (!group_->bind_generates_resource()) { |
[email protected] | f4eac070 | 2012-03-30 17:55:15 | [diff] [blame] | 3568 | LOG(ERROR) << "glBindBuffer: id not generated by glGenBuffers"; |
| 3569 | current_decoder_error_ = error::kGenericError; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3570 | return; |
| 3571 | } |
| 3572 | |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3573 | // It's a new id so make a buffer buffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3574 | glGenBuffersARB(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3575 | CreateBuffer(client_id, service_id); |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3576 | buffer = GetBuffer(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3577 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3578 | group_->GetIdAllocator(id_namespaces::kBuffers); |
| 3579 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3580 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3581 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3582 | LogClientServiceForInfo(buffer, client_id, "glBindBuffer"); |
| 3583 | if (buffer) { |
| 3584 | if (!buffer_manager()->SetTarget(buffer, target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3585 | LOCAL_SET_GL_ERROR( |
| 3586 | GL_INVALID_OPERATION, |
| 3587 | "glBindBuffer", "buffer bound to more than 1 target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3588 | return; |
| 3589 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3590 | service_id = buffer->service_id(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3591 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3592 | switch (target) { |
| 3593 | case GL_ARRAY_BUFFER: |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3594 | state_.bound_array_buffer = buffer; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3595 | break; |
| 3596 | case GL_ELEMENT_ARRAY_BUFFER: |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3597 | state_.vertex_attrib_manager->SetElementArrayBuffer(buffer); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3598 | break; |
| 3599 | default: |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3600 | NOTREACHED(); // Validation should prevent us getting here. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3601 | break; |
| 3602 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3603 | glBindBuffer(target, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3604 | } |
| 3605 | |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 3606 | bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha( |
| 3607 | bool all_draw_buffers) { |
| 3608 | Framebuffer* framebuffer = |
| 3609 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 3610 | if (!all_draw_buffers || !framebuffer) { |
| 3611 | return (GLES2Util::GetChannelsForFormat( |
| 3612 | GetBoundDrawFrameBufferInternalFormat()) & 0x0008) != 0; |
| 3613 | } |
| 3614 | return framebuffer->HasAlphaMRT(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3618 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3619 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3620 | if (framebuffer) { |
| 3621 | return framebuffer->HasDepthAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3622 | } |
| 3623 | if (offscreen_target_frame_buffer_.get()) { |
| 3624 | return offscreen_target_depth_format_ != 0; |
| 3625 | } |
| 3626 | return back_buffer_has_depth_; |
| 3627 | } |
| 3628 | |
| 3629 | bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3630 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3631 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3632 | if (framebuffer) { |
| 3633 | return framebuffer->HasStencilAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3634 | } |
| 3635 | if (offscreen_target_frame_buffer_.get()) { |
| 3636 | return offscreen_target_stencil_format_ != 0 || |
| 3637 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 3638 | } |
| 3639 | return back_buffer_has_stencil_; |
| 3640 | } |
| 3641 | |
| 3642 | void GLES2DecoderImpl::ApplyDirtyState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3643 | if (framebuffer_state_.clear_state_dirty) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3644 | glColorMask( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3645 | state_.color_mask_red, state_.color_mask_green, state_.color_mask_blue, |
| 3646 | state_.color_mask_alpha && |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 3647 | BoundFramebufferHasColorAttachmentWithAlpha(true)); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3648 | bool have_depth = BoundFramebufferHasDepthAttachment(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3649 | glDepthMask(state_.depth_mask && have_depth); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 3650 | EnableDisable(GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3651 | bool have_stencil = BoundFramebufferHasStencilAttachment(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3652 | glStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 3653 | GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3654 | glStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 3655 | GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 3656 | EnableDisable( |
| 3657 | GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil); |
| 3658 | EnableDisable(GL_CULL_FACE, state_.enable_flags.cull_face); |
| 3659 | EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test); |
| 3660 | EnableDisable(GL_BLEND, state_.enable_flags.blend); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3661 | framebuffer_state_.clear_state_dirty = false; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3662 | } |
| 3663 | } |
| 3664 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3665 | GLuint GLES2DecoderImpl::GetBackbufferServiceId() const { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3666 | return (offscreen_target_frame_buffer_.get()) |
| 3667 | ? offscreen_target_frame_buffer_->id() |
| 3668 | : (surface_.get() ? surface_->GetBackingFrameBufferObject() : 0); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | void GLES2DecoderImpl::RestoreState() const { |
[email protected] | 962bfbe7 | 2013-05-24 11:16:14 | [diff] [blame] | 3672 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::RestoreState", |
| 3673 | "context", logger_.GetLogPrefix()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3674 | // Restore the Framebuffer first because of bugs in Intel drivers. |
| 3675 | // Intel drivers incorrectly clip the viewport settings to |
| 3676 | // the size of the current framebuffer object. |
| 3677 | RestoreFramebufferBindings(); |
| 3678 | state_.RestoreState(); |
| 3679 | } |
| 3680 | |
| 3681 | void GLES2DecoderImpl::RestoreFramebufferBindings() const { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3682 | GLuint service_id = |
| 3683 | framebuffer_state_.bound_draw_framebuffer.get() |
| 3684 | ? framebuffer_state_.bound_draw_framebuffer->service_id() |
| 3685 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3686 | if (!features().chromium_framebuffer_multisample) { |
| 3687 | glBindFramebufferEXT(GL_FRAMEBUFFER, service_id); |
| 3688 | } else { |
| 3689 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, service_id); |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3690 | service_id = framebuffer_state_.bound_read_framebuffer.get() |
| 3691 | ? framebuffer_state_.bound_read_framebuffer->service_id() |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3692 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3693 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, service_id); |
| 3694 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3695 | OnFboChanged(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3696 | } |
| 3697 | |
| 3698 | void GLES2DecoderImpl::RestoreTextureState(unsigned service_id) const { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 3699 | Texture* texture = texture_manager()->GetTextureForServiceId(service_id); |
| 3700 | if (texture) { |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3701 | GLenum target = texture->target(); |
| 3702 | glBindTexture(target, service_id); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3703 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3704 | target, GL_TEXTURE_WRAP_S, texture->wrap_s()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3705 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3706 | target, GL_TEXTURE_WRAP_T, texture->wrap_t()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3707 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3708 | target, GL_TEXTURE_MIN_FILTER, texture->min_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3709 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3710 | target, GL_TEXTURE_MAG_FILTER, texture->mag_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3711 | RestoreTextureUnitBindings(state_.active_texture_unit); |
| 3712 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | void GLES2DecoderImpl::OnFboChanged() const { |
| 3716 | if (workarounds().restore_scissor_on_fbo_change) |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3717 | state_.fbo_binding_for_scissor_workaround_dirty_ = true; |
| 3718 | } |
| 3719 | |
| 3720 | // Called after the FBO is checked for completeness. |
| 3721 | void GLES2DecoderImpl::OnUseFramebuffer() const { |
| 3722 | if (state_.fbo_binding_for_scissor_workaround_dirty_) { |
| 3723 | state_.fbo_binding_for_scissor_workaround_dirty_ = false; |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 3724 | // The driver forgets the correct scissor when modifying the FBO binding. |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3725 | glScissor(state_.scissor_x, |
| 3726 | state_.scissor_y, |
| 3727 | state_.scissor_width, |
| 3728 | state_.scissor_height); |
| 3729 | |
| 3730 | // crbug.com/222018 - Also on QualComm, the flush here avoids flicker, |
| 3731 | // it's unclear how this bug works. |
| 3732 | glFlush(); |
| 3733 | } |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3734 | } |
| 3735 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3736 | void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3737 | Framebuffer* framebuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3738 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3739 | if (client_id != 0) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3740 | framebuffer = GetFramebuffer(client_id); |
| 3741 | if (!framebuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3742 | if (!group_->bind_generates_resource()) { |
[email protected] | f4eac070 | 2012-03-30 17:55:15 | [diff] [blame] | 3743 | LOG(ERROR) |
| 3744 | << "glBindFramebuffer: id not generated by glGenFramebuffers"; |
| 3745 | current_decoder_error_ = error::kGenericError; |
| 3746 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3747 | } |
| 3748 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3749 | // It's a new id so make a framebuffer framebuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3750 | glGenFramebuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3751 | CreateFramebuffer(client_id, service_id); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3752 | framebuffer = GetFramebuffer(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3753 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3754 | group_->GetIdAllocator(id_namespaces::kFramebuffers); |
| 3755 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3756 | } else { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3757 | service_id = framebuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3758 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3759 | framebuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3760 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3761 | LogClientServiceForInfo(framebuffer, client_id, "glBindFramebuffer"); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3762 | |
| 3763 | if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3764 | framebuffer_state_.bound_draw_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3765 | } |
| 3766 | if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3767 | framebuffer_state_.bound_read_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3768 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3769 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3770 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3771 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3772 | // If we are rendering to the backbuffer get the FBO id for any simulated |
| 3773 | // backbuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3774 | if (framebuffer == NULL) { |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3775 | service_id = GetBackbufferServiceId(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3776 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3777 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3778 | glBindFramebufferEXT(target, service_id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3779 | OnFboChanged(); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 3780 | } |
| 3781 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3782 | void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3783 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3784 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3785 | if (client_id != 0) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3786 | renderbuffer = GetRenderbuffer(client_id); |
| 3787 | if (!renderbuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3788 | if (!group_->bind_generates_resource()) { |
[email protected] | f4eac070 | 2012-03-30 17:55:15 | [diff] [blame] | 3789 | LOG(ERROR) |
| 3790 | << "glBindRenderbuffer: id not generated by glGenRenderbuffers"; |
| 3791 | current_decoder_error_ = error::kGenericError; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3792 | return; |
| 3793 | } |
| 3794 | |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3795 | // It's a new id so make a renderbuffer renderbuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3796 | glGenRenderbuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3797 | CreateRenderbuffer(client_id, service_id); |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3798 | renderbuffer = GetRenderbuffer(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3799 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3800 | group_->GetIdAllocator(id_namespaces::kRenderbuffers); |
| 3801 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3802 | } else { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3803 | service_id = renderbuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3804 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3805 | renderbuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3806 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3807 | LogClientServiceForInfo(renderbuffer, client_id, "glBindRenerbuffer"); |
| 3808 | state_.bound_renderbuffer = renderbuffer; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3809 | glBindRenderbufferEXT(target, service_id); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 3810 | } |
| 3811 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3812 | void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3813 | TextureRef* texture_ref = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3814 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3815 | if (client_id != 0) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3816 | texture_ref = GetTexture(client_id); |
| 3817 | if (!texture_ref) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3818 | if (!group_->bind_generates_resource()) { |
[email protected] | f4eac070 | 2012-03-30 17:55:15 | [diff] [blame] | 3819 | LOG(ERROR) << "glBindTexture: id not generated by glGenTextures"; |
| 3820 | current_decoder_error_ = error::kGenericError; |
| 3821 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3822 | } |
| 3823 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 3824 | // It's a new id so make a texture texture for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3825 | glGenTextures(1, &service_id); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3826 | DCHECK_NE(0u, service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3827 | CreateTexture(client_id, service_id); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3828 | texture_ref = GetTexture(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3829 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3830 | group_->GetIdAllocator(id_namespaces::kTextures); |
| 3831 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3832 | } |
| 3833 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3834 | texture_ref = texture_manager()->GetDefaultTextureInfo(target); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3835 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3836 | Texture* texture = texture_ref->texture(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3837 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3838 | // Check the texture exists |
| 3839 | // Check that we are not trying to bind it to a different target. |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 3840 | if (texture->target() != 0 && texture->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3841 | LOCAL_SET_GL_ERROR( |
| 3842 | GL_INVALID_OPERATION, |
| 3843 | "glBindTexture", "texture bound to more than 1 target."); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3844 | return; |
| 3845 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 3846 | if (texture->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3847 | LOCAL_SET_GL_ERROR( |
| 3848 | GL_INVALID_OPERATION, |
| 3849 | "glBindTexture", "illegal target for stream texture."); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 3850 | return; |
| 3851 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 3852 | LogClientServiceForInfo(texture, client_id, "glBindTexture"); |
| 3853 | if (texture->target() == 0) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3854 | texture_manager()->SetTarget(texture_ref, target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3855 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 3856 | glBindTexture(target, texture->service_id()); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 3857 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3858 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3859 | unit.bind_target = target; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3860 | switch (target) { |
| 3861 | case GL_TEXTURE_2D: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3862 | unit.bound_texture_2d = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3863 | break; |
| 3864 | case GL_TEXTURE_CUBE_MAP: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3865 | unit.bound_texture_cube_map = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3866 | break; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3867 | case GL_TEXTURE_EXTERNAL_OES: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3868 | unit.bound_texture_external_oes = texture_ref; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3869 | break; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3870 | case GL_TEXTURE_RECTANGLE_ARB: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3871 | unit.bound_texture_rectangle_arb = texture_ref; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3872 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3873 | default: |
| 3874 | NOTREACHED(); // Validation should prevent us getting here. |
| 3875 | break; |
| 3876 | } |
| 3877 | } |
| 3878 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3879 | void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3880 | if (state_.vertex_attrib_manager->Enable(index, false)) { |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 3881 | if (index != 0 || |
| 3882 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3883 | glDisableVertexAttribArray(index); |
| 3884 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3885 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3886 | LOCAL_SET_GL_ERROR( |
| 3887 | GL_INVALID_VALUE, |
| 3888 | "glDisableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3889 | } |
| 3890 | } |
| 3891 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3892 | void GLES2DecoderImpl::DoDiscardFramebufferEXT(GLenum target, |
| 3893 | GLsizei numAttachments, |
| 3894 | const GLenum* attachments) { |
[email protected] | 680aa41 | 2013-10-31 18:08:01 | [diff] [blame] | 3895 | if (!features().ext_discard_framebuffer) { |
| 3896 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 3897 | "glDiscardFramebufferEXT", |
| 3898 | "function not available"); |
| 3899 | return; |
| 3900 | } |
| 3901 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3902 | Framebuffer* framebuffer = |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3903 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 3904 | |
| 3905 | // Validates the attachments. If one of them fails |
| 3906 | // the whole command fails. |
| 3907 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 3908 | if ((framebuffer && |
| 3909 | !validators_->attachment.IsValid(attachments[i])) || |
| 3910 | (!framebuffer && |
| 3911 | !validators_->backbuffer_attachment.IsValid(attachments[i]))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3912 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 3913 | "glDiscardFramebufferEXT", attachments[i], "attachments"); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3914 | return; |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | // Marks each one of them as not cleared |
| 3919 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 3920 | if (framebuffer) { |
| 3921 | framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), |
| 3922 | texture_manager(), |
| 3923 | attachments[i], |
| 3924 | false); |
| 3925 | } else { |
| 3926 | switch (attachments[i]) { |
| 3927 | case GL_COLOR_EXT: |
| 3928 | backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| 3929 | break; |
| 3930 | case GL_DEPTH_EXT: |
| 3931 | backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
| 3932 | case GL_STENCIL_EXT: |
| 3933 | backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
| 3934 | break; |
| 3935 | default: |
| 3936 | NOTREACHED(); |
| 3937 | break; |
| 3938 | } |
| 3939 | } |
| 3940 | } |
| 3941 | |
[email protected] | d49c540 | 2013-09-11 15:39:02 | [diff] [blame] | 3942 | // If the default framebuffer is bound but we are still rendering to an |
| 3943 | // FBO, translate attachment names that refer to default framebuffer |
| 3944 | // channels to corresponding framebuffer attachments. |
| 3945 | scoped_ptr<GLenum[]> translated_attachments(new GLenum[numAttachments]); |
| 3946 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 3947 | GLenum attachment = attachments[i]; |
| 3948 | if (!framebuffer && GetBackbufferServiceId()) { |
| 3949 | switch (attachment) { |
| 3950 | case GL_COLOR_EXT: |
| 3951 | attachment = GL_COLOR_ATTACHMENT0; |
| 3952 | break; |
| 3953 | case GL_DEPTH_EXT: |
| 3954 | attachment = GL_DEPTH_ATTACHMENT; |
| 3955 | break; |
| 3956 | case GL_STENCIL_EXT: |
| 3957 | attachment = GL_STENCIL_ATTACHMENT; |
| 3958 | break; |
| 3959 | default: |
| 3960 | NOTREACHED(); |
| 3961 | return; |
| 3962 | } |
| 3963 | } |
| 3964 | translated_attachments[i] = attachment; |
| 3965 | } |
| 3966 | |
| 3967 | glDiscardFramebufferEXT(target, numAttachments, translated_attachments.get()); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3968 | } |
| 3969 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3970 | void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3971 | if (state_.vertex_attrib_manager->Enable(index, true)) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3972 | glEnableVertexAttribArray(index); |
| 3973 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3974 | LOCAL_SET_GL_ERROR( |
| 3975 | GL_INVALID_VALUE, "glEnableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3976 | } |
| 3977 | } |
| 3978 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3979 | void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3980 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 3981 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3982 | if (!texture_ref || |
| 3983 | !texture_manager()->CanGenerateMipmaps(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3984 | LOCAL_SET_GL_ERROR( |
| 3985 | GL_INVALID_OPERATION, "glGenerateMipmap", "Can not generate mips"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3986 | return; |
| 3987 | } |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 3988 | |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 3989 | if (target == GL_TEXTURE_CUBE_MAP) { |
| 3990 | for (int i = 0; i < 6; ++i) { |
| 3991 | GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3992 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, face, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3993 | LOCAL_SET_GL_ERROR( |
| 3994 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 3995 | return; |
| 3996 | } |
| 3997 | } |
| 3998 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3999 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4000 | LOCAL_SET_GL_ERROR( |
| 4001 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4002 | return; |
| 4003 | } |
[email protected] | 7687479c | 2012-05-14 23:54:04 | [diff] [blame] | 4004 | } |
| 4005 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4006 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glGenerateMipmap"); |
[email protected] | 59f3ca0 | 2011-03-26 22:24:19 | [diff] [blame] | 4007 | // Workaround for Mac driver bug. In the large scheme of things setting |
| 4008 | // glTexParamter twice for glGenerateMipmap is probably not a lage performance |
[email protected] | a8bad26 | 2011-10-21 18:28:56 | [diff] [blame] | 4009 | // hit so there's probably no need to make this conditional. The bug appears |
| 4010 | // to be that if the filtering mode is set to something that doesn't require |
| 4011 | // mipmaps for rendering, or is never set to something other than the default, |
| 4012 | // then glGenerateMipmap misbehaves. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4013 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4014 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 4015 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4016 | glGenerateMipmapEXT(target); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4017 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4018 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, |
| 4019 | texture_ref->texture()->min_filter()); |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4020 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4021 | GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4022 | if (error == GL_NO_ERROR) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4023 | texture_manager()->MarkMipmapsGenerated(texture_ref); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4024 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4025 | } |
| 4026 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4027 | bool GLES2DecoderImpl::GetHelper( |
| 4028 | GLenum pname, GLint* params, GLsizei* num_written) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4029 | DCHECK(num_written); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 4030 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 4031 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4032 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 4033 | *num_written = 1; |
| 4034 | if (params) { |
| 4035 | *params = GL_RGBA; // We don't support other formats. |
| 4036 | } |
| 4037 | return true; |
| 4038 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 4039 | *num_written = 1; |
| 4040 | if (params) { |
| 4041 | *params = GL_UNSIGNED_BYTE; // We don't support other types. |
| 4042 | } |
| 4043 | return true; |
| 4044 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 4045 | *num_written = 1; |
| 4046 | if (params) { |
| 4047 | *params = group_->max_fragment_uniform_vectors(); |
| 4048 | } |
| 4049 | return true; |
| 4050 | case GL_MAX_VARYING_VECTORS: |
| 4051 | *num_written = 1; |
| 4052 | if (params) { |
| 4053 | *params = group_->max_varying_vectors(); |
| 4054 | } |
| 4055 | return true; |
| 4056 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 4057 | *num_written = 1; |
| 4058 | if (params) { |
| 4059 | *params = group_->max_vertex_uniform_vectors(); |
| 4060 | } |
| 4061 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4062 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4063 | } |
| 4064 | switch (pname) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 4065 | case GL_MAX_VIEWPORT_DIMS: |
| 4066 | if (offscreen_target_frame_buffer_.get()) { |
| 4067 | *num_written = 2; |
| 4068 | if (params) { |
| 4069 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4070 | params[1] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4071 | } |
| 4072 | return true; |
| 4073 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4074 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4075 | case GL_MAX_SAMPLES: |
| 4076 | *num_written = 1; |
| 4077 | if (params) { |
| 4078 | params[0] = renderbuffer_manager()->max_samples(); |
| 4079 | } |
| 4080 | return true; |
| 4081 | case GL_MAX_RENDERBUFFER_SIZE: |
| 4082 | *num_written = 1; |
| 4083 | if (params) { |
| 4084 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4085 | } |
| 4086 | return true; |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4087 | case GL_MAX_TEXTURE_SIZE: |
| 4088 | *num_written = 1; |
| 4089 | if (params) { |
| 4090 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_2D); |
| 4091 | } |
| 4092 | return true; |
| 4093 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 4094 | *num_written = 1; |
| 4095 | if (params) { |
| 4096 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP); |
| 4097 | } |
| 4098 | return true; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 4099 | case GL_MAX_COLOR_ATTACHMENTS_EXT: |
| 4100 | *num_written = 1; |
| 4101 | if (params) { |
| 4102 | params[0] = group_->max_color_attachments(); |
| 4103 | } |
| 4104 | return true; |
| 4105 | case GL_MAX_DRAW_BUFFERS_ARB: |
| 4106 | *num_written = 1; |
| 4107 | if (params) { |
| 4108 | params[0] = group_->max_draw_buffers(); |
| 4109 | } |
| 4110 | return true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4111 | case GL_ALPHA_BITS: |
| 4112 | *num_written = 1; |
| 4113 | if (params) { |
| 4114 | GLint v = 0; |
| 4115 | glGetIntegerv(GL_ALPHA_BITS, &v); |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 4116 | params[0] = BoundFramebufferHasColorAttachmentWithAlpha(false) ? v : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4117 | } |
| 4118 | return true; |
| 4119 | case GL_DEPTH_BITS: |
| 4120 | *num_written = 1; |
| 4121 | if (params) { |
| 4122 | GLint v = 0; |
| 4123 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 4124 | params[0] = BoundFramebufferHasDepthAttachment() ? v : 0; |
| 4125 | } |
| 4126 | return true; |
| 4127 | case GL_STENCIL_BITS: |
| 4128 | *num_written = 1; |
| 4129 | if (params) { |
| 4130 | GLint v = 0; |
| 4131 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 4132 | params[0] = BoundFramebufferHasStencilAttachment() ? v : 0; |
| 4133 | } |
| 4134 | return true; |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 4135 | case GL_COMPRESSED_TEXTURE_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4136 | *num_written = validators_->compressed_texture_format.GetValues().size(); |
| 4137 | if (params) { |
| 4138 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 4139 | params[ii] = validators_->compressed_texture_format.GetValues()[ii]; |
| 4140 | } |
| 4141 | } |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 4142 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4143 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 4144 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4145 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4146 | *params = validators_->compressed_texture_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4147 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4148 | return true; |
| 4149 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 4150 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4151 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4152 | *params = validators_->shader_binary_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4153 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4154 | return true; |
| 4155 | case GL_SHADER_BINARY_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4156 | *num_written = validators_->shader_binary_format.GetValues().size(); |
| 4157 | if (params) { |
| 4158 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 4159 | params[ii] = validators_->shader_binary_format.GetValues()[ii]; |
| 4160 | } |
| 4161 | } |
| 4162 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4163 | case GL_SHADER_COMPILER: |
| 4164 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4165 | if (params) { |
| 4166 | *params = GL_TRUE; |
| 4167 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4168 | return true; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4169 | case GL_ARRAY_BUFFER_BINDING: |
| 4170 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4171 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4172 | if (state_.bound_array_buffer.get()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4173 | GLuint client_id = 0; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4174 | buffer_manager()->GetClientId(state_.bound_array_buffer->service_id(), |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4175 | &client_id); |
| 4176 | *params = client_id; |
| 4177 | } else { |
| 4178 | *params = 0; |
| 4179 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4180 | } |
| 4181 | return true; |
| 4182 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 4183 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4184 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4185 | if (state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4186 | GLuint client_id = 0; |
| 4187 | buffer_manager()->GetClientId( |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 4188 | state_.vertex_attrib_manager->element_array_buffer()-> |
| 4189 | service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4190 | *params = client_id; |
| 4191 | } else { |
| 4192 | *params = 0; |
| 4193 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4194 | } |
| 4195 | return true; |
| 4196 | case GL_FRAMEBUFFER_BINDING: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4197 | // case GL_DRAW_FRAMEBUFFER_BINDING_EXT: (same as GL_FRAMEBUFFER_BINDING) |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4198 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4199 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4200 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4201 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4202 | if (framebuffer) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4203 | GLuint client_id = 0; |
| 4204 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4205 | framebuffer->service_id(), &client_id); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4206 | *params = client_id; |
| 4207 | } else { |
| 4208 | *params = 0; |
| 4209 | } |
| 4210 | } |
| 4211 | return true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4212 | case GL_READ_FRAMEBUFFER_BINDING_EXT: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4213 | *num_written = 1; |
| 4214 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4215 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4216 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4217 | if (framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4218 | GLuint client_id = 0; |
| 4219 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4220 | framebuffer->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4221 | *params = client_id; |
| 4222 | } else { |
| 4223 | *params = 0; |
| 4224 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4225 | } |
| 4226 | return true; |
| 4227 | case GL_RENDERBUFFER_BINDING: |
| 4228 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4229 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4230 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4231 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4232 | if (renderbuffer) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4233 | *params = renderbuffer->client_id(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4234 | } else { |
| 4235 | *params = 0; |
| 4236 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4237 | } |
| 4238 | return true; |
| 4239 | case GL_CURRENT_PROGRAM: |
| 4240 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4241 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4242 | if (state_.current_program.get()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4243 | GLuint client_id = 0; |
| 4244 | program_manager()->GetClientId( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4245 | state_.current_program->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4246 | *params = client_id; |
| 4247 | } else { |
| 4248 | *params = 0; |
| 4249 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4250 | } |
| 4251 | return true; |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 4252 | case GL_VERTEX_ARRAY_BINDING_OES: |
| 4253 | *num_written = 1; |
| 4254 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4255 | if (state_.vertex_attrib_manager.get() != |
| 4256 | default_vertex_attrib_manager_.get()) { |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 4257 | GLuint client_id = 0; |
| 4258 | vertex_array_manager_->GetClientId( |
| 4259 | state_.vertex_attrib_manager->service_id(), &client_id); |
| 4260 | *params = client_id; |
| 4261 | } else { |
| 4262 | *params = 0; |
| 4263 | } |
| 4264 | } |
| 4265 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4266 | case GL_TEXTURE_BINDING_2D: |
| 4267 | *num_written = 1; |
| 4268 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4269 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4270 | if (unit.bound_texture_2d.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4271 | *params = unit.bound_texture_2d->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4272 | } else { |
| 4273 | *params = 0; |
| 4274 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4275 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4276 | return true; |
| 4277 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 4278 | *num_written = 1; |
| 4279 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4280 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4281 | if (unit.bound_texture_cube_map.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4282 | *params = unit.bound_texture_cube_map->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4283 | } else { |
| 4284 | *params = 0; |
| 4285 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4286 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4287 | return true; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4288 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 4289 | *num_written = 1; |
| 4290 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4291 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4292 | if (unit.bound_texture_external_oes.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4293 | *params = unit.bound_texture_external_oes->client_id(); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4294 | } else { |
| 4295 | *params = 0; |
| 4296 | } |
| 4297 | } |
| 4298 | return true; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4299 | case GL_TEXTURE_BINDING_RECTANGLE_ARB: |
| 4300 | *num_written = 1; |
| 4301 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4302 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4303 | if (unit.bound_texture_rectangle_arb.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4304 | *params = unit.bound_texture_rectangle_arb->client_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4305 | } else { |
| 4306 | *params = 0; |
| 4307 | } |
| 4308 | } |
| 4309 | return true; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 4310 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 4311 | *num_written = 1; |
| 4312 | if (params) { |
| 4313 | params[0] = unpack_flip_y_; |
| 4314 | } |
| 4315 | return true; |
| 4316 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 4317 | *num_written = 1; |
| 4318 | if (params) { |
| 4319 | params[0] = unpack_premultiply_alpha_; |
| 4320 | } |
| 4321 | return true; |
| 4322 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 4323 | *num_written = 1; |
| 4324 | if (params) { |
| 4325 | params[0] = unpack_unpremultiply_alpha_; |
| 4326 | } |
| 4327 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4328 | default: |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 4329 | if (pname >= GL_DRAW_BUFFER0_ARB && |
| 4330 | pname < GL_DRAW_BUFFER0_ARB + group_->max_draw_buffers()) { |
| 4331 | *num_written = 1; |
| 4332 | if (params) { |
| 4333 | Framebuffer* framebuffer = |
| 4334 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 4335 | if (framebuffer) { |
| 4336 | params[0] = framebuffer->GetDrawBuffer(pname); |
| 4337 | } else { // backbuffer |
| 4338 | if (pname == GL_DRAW_BUFFER0_ARB) |
| 4339 | params[0] = group_->draw_buffer(); |
| 4340 | else |
| 4341 | params[0] = GL_NONE; |
| 4342 | } |
| 4343 | } |
| 4344 | return true; |
| 4345 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4346 | *num_written = util_.GLGetNumValuesReturned(pname); |
[email protected] | c5d79834 | 2010-09-24 20:42:53 | [diff] [blame] | 4347 | return false; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4348 | } |
| 4349 | } |
| 4350 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4351 | bool GLES2DecoderImpl::GetNumValuesReturnedForGLGet( |
| 4352 | GLenum pname, GLsizei* num_values) { |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4353 | if (state_.GetStateAsGLint(pname, NULL, num_values)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4354 | return true; |
| 4355 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4356 | return GetHelper(pname, NULL, num_values); |
| 4357 | } |
| 4358 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4359 | GLenum GLES2DecoderImpl::AdjustGetPname(GLenum pname) { |
| 4360 | if (GL_MAX_SAMPLES == pname && |
| 4361 | features().use_img_for_multisampled_render_to_texture) { |
| 4362 | return GL_MAX_SAMPLES_IMG; |
| 4363 | } |
| 4364 | return pname; |
| 4365 | } |
| 4366 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4367 | void GLES2DecoderImpl::DoGetBooleanv(GLenum pname, GLboolean* params) { |
| 4368 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4369 | GLsizei num_written = 0; |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4370 | if (GetNumValuesReturnedForGLGet(pname, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 4371 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4372 | if (!state_.GetStateAsGLint(pname, values.get(), &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4373 | GetHelper(pname, values.get(), &num_written); |
| 4374 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4375 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 4376 | params[ii] = static_cast<GLboolean>(values[ii]); |
| 4377 | } |
| 4378 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4379 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4380 | glGetBooleanv(pname, params); |
| 4381 | } |
| 4382 | } |
| 4383 | |
| 4384 | void GLES2DecoderImpl::DoGetFloatv(GLenum pname, GLfloat* params) { |
| 4385 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4386 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4387 | if (!state_.GetStateAsGLfloat(pname, params, &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4388 | if (GetHelper(pname, NULL, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 4389 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4390 | GetHelper(pname, values.get(), &num_written); |
| 4391 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 4392 | params[ii] = static_cast<GLfloat>(values[ii]); |
| 4393 | } |
| 4394 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4395 | pname = AdjustGetPname(pname); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4396 | glGetFloatv(pname, params); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4397 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4398 | } |
| 4399 | } |
| 4400 | |
| 4401 | void GLES2DecoderImpl::DoGetIntegerv(GLenum pname, GLint* params) { |
| 4402 | DCHECK(params); |
| 4403 | GLsizei num_written; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4404 | if (!state_.GetStateAsGLint(pname, params, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4405 | !GetHelper(pname, params, &num_written)) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4406 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4407 | glGetIntegerv(pname, params); |
| 4408 | } |
| 4409 | } |
| 4410 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 4411 | void GLES2DecoderImpl::DoGetProgramiv( |
| 4412 | GLuint program_id, GLenum pname, GLint* params) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4413 | Program* program = GetProgramInfoNotShader(program_id, "glGetProgramiv"); |
| 4414 | if (!program) { |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 4415 | return; |
| 4416 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4417 | program->GetProgramiv(pname, params); |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 4418 | } |
| 4419 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 4420 | void GLES2DecoderImpl::DoGetBufferParameteriv( |
| 4421 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 4422 | // Just delegate it. Some validation is actually done before this. |
| 4423 | buffer_manager()->ValidateAndDoGetBufferParameteriv( |
| 4424 | &state_, target, pname, params); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 4425 | } |
| 4426 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4427 | void GLES2DecoderImpl::DoBindAttribLocation( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4428 | GLuint program_id, GLuint index, const char* name) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4429 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4430 | LOCAL_SET_GL_ERROR( |
| 4431 | GL_INVALID_VALUE, "glBindAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4432 | return; |
| 4433 | } |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 4434 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4435 | LOCAL_SET_GL_ERROR( |
| 4436 | GL_INVALID_OPERATION, "glBindAttribLocation", "reserved prefix"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 4437 | return; |
| 4438 | } |
| 4439 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4440 | LOCAL_SET_GL_ERROR( |
| 4441 | GL_INVALID_VALUE, "glBindAttribLocation", "index out of range"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 4442 | return; |
| 4443 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4444 | Program* program = GetProgramInfoNotShader( |
| 4445 | program_id, "glBindAttribLocation"); |
| 4446 | if (!program) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4447 | return; |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4448 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4449 | program->SetAttribLocationBinding(name, static_cast<GLint>(index)); |
| 4450 | glBindAttribLocation(program->service_id(), index, name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4451 | } |
| 4452 | |
| 4453 | error::Error GLES2DecoderImpl::HandleBindAttribLocation( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4454 | uint32 immediate_data_size, const cmds::BindAttribLocation& c) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4455 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4456 | GLuint index = static_cast<GLuint>(c.index); |
| 4457 | uint32 name_size = c.data_size; |
| 4458 | const char* name = GetSharedMemoryAs<const char*>( |
| 4459 | c.name_shm_id, c.name_shm_offset, name_size); |
| 4460 | if (name == NULL) { |
| 4461 | return error::kOutOfBounds; |
| 4462 | } |
| 4463 | String name_str(name, name_size); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4464 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4465 | return error::kNoError; |
| 4466 | } |
| 4467 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4468 | error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4469 | uint32 immediate_data_size, const cmds::BindAttribLocationBucket& c) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4470 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4471 | GLuint index = static_cast<GLuint>(c.index); |
| 4472 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 4473 | if (!bucket || bucket->size() == 0) { |
| 4474 | return error::kInvalidArguments; |
| 4475 | } |
| 4476 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 4477 | if (!bucket->GetAsString(&name_str)) { |
| 4478 | return error::kInvalidArguments; |
| 4479 | } |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4480 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4481 | return error::kNoError; |
| 4482 | } |
| 4483 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4484 | void GLES2DecoderImpl::DoBindUniformLocationCHROMIUM( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4485 | GLuint program_id, GLint location, const char* name) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4486 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4487 | LOCAL_SET_GL_ERROR( |
| 4488 | GL_INVALID_VALUE, |
| 4489 | "glBindUniformLocationCHROMIUM", "Invalid character"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4490 | return; |
| 4491 | } |
| 4492 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4493 | LOCAL_SET_GL_ERROR( |
| 4494 | GL_INVALID_OPERATION, |
| 4495 | "glBindUniformLocationCHROMIUM", "reserved prefix"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4496 | return; |
| 4497 | } |
| 4498 | if (location < 0 || static_cast<uint32>(location) >= |
| 4499 | (group_->max_fragment_uniform_vectors() + |
| 4500 | group_->max_vertex_uniform_vectors()) * 4) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4501 | LOCAL_SET_GL_ERROR( |
| 4502 | GL_INVALID_VALUE, |
| 4503 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4504 | return; |
| 4505 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4506 | Program* program = GetProgramInfoNotShader( |
| 4507 | program_id, "glBindUniformLocationCHROMIUM"); |
| 4508 | if (!program) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4509 | return; |
| 4510 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4511 | if (!program->SetUniformLocationBinding(name, location)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4512 | LOCAL_SET_GL_ERROR( |
| 4513 | GL_INVALID_VALUE, |
| 4514 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4519 | uint32 immediate_data_size, const cmds::BindUniformLocationCHROMIUM& c) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4520 | GLuint program = static_cast<GLuint>(c.program); |
| 4521 | GLint location = static_cast<GLint>(c.location); |
| 4522 | uint32 name_size = c.data_size; |
| 4523 | const char* name = GetSharedMemoryAs<const char*>( |
| 4524 | c.name_shm_id, c.name_shm_offset, name_size); |
| 4525 | if (name == NULL) { |
| 4526 | return error::kOutOfBounds; |
| 4527 | } |
| 4528 | String name_str(name, name_size); |
| 4529 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 4530 | return error::kNoError; |
| 4531 | } |
| 4532 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4533 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUMBucket( |
| 4534 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4535 | const cmds::BindUniformLocationCHROMIUMBucket& c) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4536 | GLuint program = static_cast<GLuint>(c.program); |
| 4537 | GLint location = static_cast<GLint>(c.location); |
| 4538 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 4539 | if (!bucket || bucket->size() == 0) { |
| 4540 | return error::kInvalidArguments; |
| 4541 | } |
| 4542 | std::string name_str; |
| 4543 | if (!bucket->GetAsString(&name_str)) { |
| 4544 | return error::kInvalidArguments; |
| 4545 | } |
| 4546 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 4547 | return error::kNoError; |
| 4548 | } |
| 4549 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4550 | error::Error GLES2DecoderImpl::HandleDeleteShader( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4551 | uint32 immediate_data_size, const cmds::DeleteShader& c) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4552 | GLuint client_id = c.shader; |
| 4553 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4554 | Shader* shader = GetShader(client_id); |
| 4555 | if (shader) { |
| 4556 | if (!shader->IsDeleted()) { |
| 4557 | glDeleteShader(shader->service_id()); |
| 4558 | shader_manager()->MarkAsDeleted(shader); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4559 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4560 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4561 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteShader", "unknown shader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4562 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4563 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4564 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4565 | } |
| 4566 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4567 | error::Error GLES2DecoderImpl::HandleDeleteProgram( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4568 | uint32 immediate_data_size, const cmds::DeleteProgram& c) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4569 | GLuint client_id = c.program; |
| 4570 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4571 | Program* program = GetProgram(client_id); |
| 4572 | if (program) { |
| 4573 | if (!program->IsDeleted()) { |
| 4574 | program_manager()->MarkAsDeleted(shader_manager(), program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4575 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4576 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4577 | LOCAL_SET_GL_ERROR( |
| 4578 | GL_INVALID_VALUE, "glDeleteProgram", "unknown program"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4579 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4580 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4581 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4582 | } |
| 4583 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4584 | void GLES2DecoderImpl::DoDeleteSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4585 | GLuint namespace_id, GLsizei n, const GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 4586 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4587 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4588 | id_allocator->FreeID(ids[ii]); |
| 4589 | } |
| 4590 | } |
| 4591 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4592 | error::Error GLES2DecoderImpl::HandleDeleteSharedIdsCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4593 | uint32 immediate_data_size, const cmds::DeleteSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4594 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 4595 | GLsizei n = static_cast<GLsizei>(c.n); |
| 4596 | uint32 data_size; |
| 4597 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 4598 | return error::kOutOfBounds; |
| 4599 | } |
| 4600 | const GLuint* ids = GetSharedMemoryAs<const GLuint*>( |
| 4601 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 4602 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4603 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "DeleteSharedIdsCHROMIUM", "n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4604 | return error::kNoError; |
| 4605 | } |
| 4606 | if (ids == NULL) { |
| 4607 | return error::kOutOfBounds; |
| 4608 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4609 | DoDeleteSharedIdsCHROMIUM(namespace_id, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4610 | return error::kNoError; |
| 4611 | } |
| 4612 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4613 | void GLES2DecoderImpl::DoGenSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4614 | GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 4615 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4616 | if (id_offset == 0) { |
| 4617 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4618 | ids[ii] = id_allocator->AllocateID(); |
| 4619 | } |
| 4620 | } else { |
| 4621 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4622 | ids[ii] = id_allocator->AllocateIDAtOrAbove(id_offset); |
| 4623 | id_offset = ids[ii] + 1; |
| 4624 | } |
| 4625 | } |
| 4626 | } |
| 4627 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4628 | error::Error GLES2DecoderImpl::HandleGenSharedIdsCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4629 | uint32 immediate_data_size, const cmds::GenSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4630 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 4631 | GLuint id_offset = static_cast<GLuint>(c.id_offset); |
| 4632 | GLsizei n = static_cast<GLsizei>(c.n); |
| 4633 | uint32 data_size; |
| 4634 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 4635 | return error::kOutOfBounds; |
| 4636 | } |
| 4637 | GLuint* ids = GetSharedMemoryAs<GLuint*>( |
| 4638 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 4639 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4640 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "GenSharedIdsCHROMIUM", "n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4641 | return error::kNoError; |
| 4642 | } |
| 4643 | if (ids == NULL) { |
| 4644 | return error::kOutOfBounds; |
| 4645 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4646 | DoGenSharedIdsCHROMIUM(namespace_id, id_offset, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4647 | return error::kNoError; |
| 4648 | } |
| 4649 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4650 | void GLES2DecoderImpl::DoRegisterSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4651 | GLuint namespace_id, GLsizei n, const GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 4652 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4653 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4654 | if (!id_allocator->MarkAsUsed(ids[ii])) { |
| 4655 | for (GLsizei jj = 0; jj < ii; ++jj) { |
| 4656 | id_allocator->FreeID(ids[jj]); |
| 4657 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4658 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4659 | GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM", |
| 4660 | "attempt to register id that already exists"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4661 | return; |
| 4662 | } |
| 4663 | } |
| 4664 | } |
| 4665 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4666 | error::Error GLES2DecoderImpl::HandleRegisterSharedIdsCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4667 | uint32 immediate_data_size, const cmds::RegisterSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4668 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 4669 | GLsizei n = static_cast<GLsizei>(c.n); |
| 4670 | uint32 data_size; |
| 4671 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 4672 | return error::kOutOfBounds; |
| 4673 | } |
| 4674 | GLuint* ids = GetSharedMemoryAs<GLuint*>( |
| 4675 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 4676 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4677 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM", "n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4678 | return error::kNoError; |
| 4679 | } |
| 4680 | if (ids == NULL) { |
| 4681 | return error::kOutOfBounds; |
| 4682 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4683 | DoRegisterSharedIdsCHROMIUM(namespace_id, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4684 | return error::kNoError; |
| 4685 | } |
| 4686 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 4687 | error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 4688 | DCHECK(!ShouldDeferDraws()); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4689 | if (CheckBoundFramebuffersValid("glClear")) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4690 | ApplyDirtyState(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4691 | glClear(mask); |
| 4692 | } |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 4693 | return error::kNoError; |
| 4694 | } |
| 4695 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4696 | void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
| 4697 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4698 | GLuint client_renderbuffer_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4699 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 4700 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4701 | LOCAL_SET_GL_ERROR( |
| 4702 | GL_INVALID_OPERATION, |
| 4703 | "glFramebufferRenderbuffer", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4704 | return; |
| 4705 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4706 | GLuint service_id = 0; |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4707 | Renderbuffer* renderbuffer = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4708 | if (client_renderbuffer_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4709 | renderbuffer = GetRenderbuffer(client_renderbuffer_id); |
| 4710 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4711 | LOCAL_SET_GL_ERROR( |
| 4712 | GL_INVALID_OPERATION, |
| 4713 | "glFramebufferRenderbuffer", "unknown renderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4714 | return; |
| 4715 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4716 | service_id = renderbuffer->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4717 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4718 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glFramebufferRenderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4719 | glFramebufferRenderbufferEXT( |
| 4720 | target, attachment, renderbuffertarget, service_id); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4721 | GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferRenderbuffer"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4722 | if (error == GL_NO_ERROR) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4723 | framebuffer->AttachRenderbuffer(attachment, renderbuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4724 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4725 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4726 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4727 | } |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 4728 | OnFboChanged(); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4729 | } |
| 4730 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4731 | void GLES2DecoderImpl::DoDisable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4732 | if (SetCapabilityState(cap, false)) { |
| 4733 | glDisable(cap); |
| 4734 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4735 | } |
| 4736 | |
| 4737 | void GLES2DecoderImpl::DoEnable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4738 | if (SetCapabilityState(cap, true)) { |
| 4739 | glEnable(cap); |
| 4740 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4741 | } |
| 4742 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4743 | void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { |
| 4744 | state_.z_near = std::min(1.0f, std::max(0.0f, znear)); |
| 4745 | state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); |
| 4746 | glDepthRange(znear, zfar); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4747 | } |
| 4748 | |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 4749 | void GLES2DecoderImpl::DoSampleCoverage(GLclampf value, GLboolean invert) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4750 | state_.sample_coverage_value = std::min(1.0f, std::max(0.0f, value)); |
| 4751 | state_.sample_coverage_invert = (invert != 0); |
| 4752 | glSampleCoverage(state_.sample_coverage_value, invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4753 | } |
| 4754 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4755 | // Assumes framebuffer is complete. |
| 4756 | void GLES2DecoderImpl::ClearUnclearedAttachments( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4757 | GLenum target, Framebuffer* framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4758 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4759 | // bind this to the DRAW point, clear then bind back to READ |
| 4760 | // TODO(gman): I don't think there is any guarantee that an FBO that |
| 4761 | // is complete on the READ attachment will be complete as a DRAW |
| 4762 | // attachment. |
| 4763 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4764 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffer->service_id()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4765 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4766 | GLbitfield clear_bits = 0; |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4767 | if (framebuffer->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4768 | glClearColor( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4769 | 0.0f, 0.0f, 0.0f, |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4770 | (GLES2Util::GetChannelsForFormat( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4771 | framebuffer->GetColorAttachmentFormat()) & 0x0008) != 0 ? 0.0f : |
| 4772 | 1.0f); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4773 | glColorMask(true, true, true, true); |
| 4774 | clear_bits |= GL_COLOR_BUFFER_BIT; |
| 4775 | } |
| 4776 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4777 | if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
| 4778 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4779 | glClearStencil(0); |
| 4780 | glStencilMask(-1); |
| 4781 | clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 4782 | } |
| 4783 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4784 | if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
| 4785 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4786 | glClearDepth(1.0f); |
| 4787 | glDepthMask(true); |
| 4788 | clear_bits |= GL_DEPTH_BUFFER_BIT; |
| 4789 | } |
| 4790 | |
| 4791 | glDisable(GL_SCISSOR_TEST); |
| 4792 | glClear(clear_bits); |
| 4793 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 4794 | framebuffer_manager()->MarkAttachmentsAsCleared( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4795 | framebuffer, renderbuffer_manager(), texture_manager()); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4796 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 4797 | RestoreClearState(); |
| 4798 | |
| 4799 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4800 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, framebuffer->service_id()); |
| 4801 | Framebuffer* draw_framebuffer = |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 4802 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4803 | GLuint service_id = draw_framebuffer ? draw_framebuffer->service_id() : |
| 4804 | GetBackbufferServiceId(); |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 4805 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, service_id); |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 4806 | } |
| 4807 | } |
| 4808 | |
| 4809 | void GLES2DecoderImpl::RestoreClearState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4810 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4811 | glClearColor( |
| 4812 | state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, |
| 4813 | state_.color_clear_alpha); |
| 4814 | glClearStencil(state_.stencil_clear); |
| 4815 | glClearDepth(state_.depth_clear); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 4816 | if (state_.enable_flags.scissor_test) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4817 | glEnable(GL_SCISSOR_TEST); |
| 4818 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4819 | } |
| 4820 | |
| 4821 | GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4822 | Framebuffer* framebuffer = |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4823 | GetFramebufferInfoForTarget(target); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4824 | if (!framebuffer) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4825 | return GL_FRAMEBUFFER_COMPLETE; |
| 4826 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4827 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 4828 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
| 4829 | return completeness; |
| 4830 | } |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 4831 | return framebuffer->GetStatus(texture_manager(), target); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4832 | } |
| 4833 | |
| 4834 | void GLES2DecoderImpl::DoFramebufferTexture2D( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4835 | GLenum target, GLenum attachment, GLenum textarget, |
| 4836 | GLuint client_texture_id, GLint level) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4837 | DoFramebufferTexture2DCommon( |
| 4838 | "glFramebufferTexture2D", target, attachment, |
| 4839 | textarget, client_texture_id, level, 0); |
| 4840 | } |
| 4841 | |
| 4842 | void GLES2DecoderImpl::DoFramebufferTexture2DMultisample( |
| 4843 | GLenum target, GLenum attachment, GLenum textarget, |
| 4844 | GLuint client_texture_id, GLint level, GLsizei samples) { |
| 4845 | if (!features().multisampled_render_to_texture) { |
| 4846 | LOCAL_SET_GL_ERROR( |
| 4847 | GL_INVALID_OPERATION, |
| 4848 | "glFramebufferTexture2DMultisample", "function not available"); |
| 4849 | return; |
| 4850 | } |
| 4851 | DoFramebufferTexture2DCommon( |
| 4852 | "glFramebufferTexture2DMultisample", target, attachment, |
| 4853 | textarget, client_texture_id, level, samples); |
| 4854 | } |
| 4855 | |
| 4856 | void GLES2DecoderImpl::DoFramebufferTexture2DCommon( |
| 4857 | const char* name, GLenum target, GLenum attachment, GLenum textarget, |
| 4858 | GLuint client_texture_id, GLint level, GLsizei samples) { |
| 4859 | if (samples > renderbuffer_manager()->max_samples()) { |
| 4860 | LOCAL_SET_GL_ERROR( |
| 4861 | GL_INVALID_VALUE, |
| 4862 | "glFramebufferTexture2DMultisample", "samples too large"); |
| 4863 | return; |
| 4864 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4865 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 4866 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4867 | LOCAL_SET_GL_ERROR( |
| 4868 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4869 | name, "no framebuffer bound."); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4870 | return; |
| 4871 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4872 | GLuint service_id = 0; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4873 | TextureRef* texture_ref = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4874 | if (client_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4875 | texture_ref = GetTexture(client_texture_id); |
| 4876 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4877 | LOCAL_SET_GL_ERROR( |
| 4878 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4879 | name, "unknown texture_ref"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4880 | return; |
| 4881 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4882 | service_id = texture_ref->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4883 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4884 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4885 | if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4886 | LOCAL_SET_GL_ERROR( |
| 4887 | GL_INVALID_VALUE, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4888 | name, "level out of range"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4889 | return; |
| 4890 | } |
| 4891 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 4892 | if (texture_ref) |
| 4893 | DoWillUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 4894 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4895 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); |
| 4896 | if (0 == samples) { |
| 4897 | glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
| 4898 | } else { |
| 4899 | if (features().use_img_for_multisampled_render_to_texture) { |
| 4900 | glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, |
| 4901 | service_id, level, samples); |
| 4902 | } else { |
| 4903 | glFramebufferTexture2DMultisampleEXT(target, attachment, textarget, |
| 4904 | service_id, level, samples); |
| 4905 | } |
| 4906 | } |
| 4907 | GLenum error = LOCAL_PEEK_GL_ERROR(name); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4908 | if (error == GL_NO_ERROR) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4909 | framebuffer->AttachTexture(attachment, texture_ref, textarget, level, |
| 4910 | samples); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4911 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4912 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4913 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4914 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 4915 | |
| 4916 | if (texture_ref) |
| 4917 | DoDidUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 4918 | |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 4919 | OnFboChanged(); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4920 | } |
| 4921 | |
| 4922 | void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( |
| 4923 | GLenum target, GLenum attachment, GLenum pname, GLint* params) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4924 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 4925 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4926 | LOCAL_SET_GL_ERROR( |
| 4927 | GL_INVALID_OPERATION, |
| 4928 | "glFramebufferAttachmentParameteriv", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4929 | return; |
| 4930 | } |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 4931 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4932 | const Framebuffer::Attachment* attachment_object = |
| 4933 | framebuffer->GetAttachment(attachment); |
| 4934 | *params = attachment_object ? attachment_object->object_name() : 0; |
| 4935 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4936 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT && |
| 4937 | features().use_img_for_multisampled_render_to_texture) { |
| 4938 | pname = GL_TEXTURE_SAMPLES_IMG; |
| 4939 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4940 | glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 4941 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4942 | } |
| 4943 | |
| 4944 | void GLES2DecoderImpl::DoGetRenderbufferParameteriv( |
| 4945 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4946 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4947 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4948 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4949 | LOCAL_SET_GL_ERROR( |
| 4950 | GL_INVALID_OPERATION, |
| 4951 | "glGetRenderbufferParameteriv", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4952 | return; |
| 4953 | } |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4954 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4955 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 4956 | *params = renderbuffer->internal_format(); |
| 4957 | break; |
| 4958 | case GL_RENDERBUFFER_WIDTH: |
| 4959 | *params = renderbuffer->width(); |
| 4960 | break; |
| 4961 | case GL_RENDERBUFFER_HEIGHT: |
| 4962 | *params = renderbuffer->height(); |
| 4963 | break; |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4964 | case GL_RENDERBUFFER_SAMPLES_EXT: |
| 4965 | if (features().use_img_for_multisampled_render_to_texture) { |
| 4966 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_IMG, |
| 4967 | params); |
| 4968 | } else { |
| 4969 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_EXT, |
| 4970 | params); |
| 4971 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4972 | default: |
| 4973 | glGetRenderbufferParameterivEXT(target, pname, params); |
| 4974 | break; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 4975 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4976 | } |
| 4977 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4978 | void GLES2DecoderImpl::DoBlitFramebufferEXT( |
| 4979 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 4980 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 4981 | GLbitfield mask, GLenum filter) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 4982 | DCHECK(!ShouldDeferReads() && !ShouldDeferDraws()); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4983 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4984 | LOCAL_SET_GL_ERROR( |
| 4985 | GL_INVALID_OPERATION, |
| 4986 | "glBlitFramebufferEXT", "function not available"); |
[email protected] | 680aa41 | 2013-10-31 18:08:01 | [diff] [blame] | 4987 | return; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4988 | } |
[email protected] | 0c16343f | 2013-03-08 20:40:16 | [diff] [blame] | 4989 | |
| 4990 | if (!CheckBoundFramebuffersValid("glBlitFramebufferEXT")) { |
| 4991 | return; |
| 4992 | } |
| 4993 | |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4994 | glDisable(GL_SCISSOR_TEST); |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 4995 | if (IsAngle()) { |
| 4996 | glBlitFramebufferANGLE( |
| 4997 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 4998 | } else { |
| 4999 | glBlitFramebufferEXT( |
| 5000 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 5001 | } |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 5002 | EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | void GLES2DecoderImpl::DoRenderbufferStorageMultisample( |
| 5006 | GLenum target, GLsizei samples, GLenum internalformat, |
| 5007 | GLsizei width, GLsizei height) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5008 | if (!features().chromium_framebuffer_multisample && |
| 5009 | !features().multisampled_render_to_texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5010 | LOCAL_SET_GL_ERROR( |
| 5011 | GL_INVALID_OPERATION, |
| 5012 | "glRenderbufferStorageMultisample", "function not available"); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5013 | return; |
| 5014 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5015 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5016 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5017 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5018 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5019 | LOCAL_SET_GL_ERROR( |
| 5020 | GL_INVALID_OPERATION, |
| 5021 | "glRenderbufferStorageMultisample", "no renderbuffer bound"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5022 | return; |
| 5023 | } |
| 5024 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5025 | if (samples > renderbuffer_manager()->max_samples()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5026 | LOCAL_SET_GL_ERROR( |
| 5027 | GL_INVALID_VALUE, |
| 5028 | "glRenderbufferStorageMultisample", "samples too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5029 | return; |
| 5030 | } |
| 5031 | |
| 5032 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 5033 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5034 | LOCAL_SET_GL_ERROR( |
| 5035 | GL_INVALID_VALUE, |
| 5036 | "glRenderbufferStorageMultisample", "dimensions too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5037 | return; |
| 5038 | } |
| 5039 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5040 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5041 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 5042 | width, height, samples, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5043 | LOCAL_SET_GL_ERROR( |
| 5044 | GL_OUT_OF_MEMORY, |
| 5045 | "glRenderbufferStorageMultsample", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5046 | return; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5047 | } |
| 5048 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5049 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5050 | LOCAL_SET_GL_ERROR( |
| 5051 | GL_OUT_OF_MEMORY, |
| 5052 | "glRenderbufferStorageMultsample", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5053 | return; |
| 5054 | } |
| 5055 | |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5056 | GLenum impl_format = |
| 5057 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5058 | internalformat); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5059 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorageMultisample"); |
[email protected] | 866b91c5 | 2011-03-23 14:38:08 | [diff] [blame] | 5060 | if (IsAngle()) { |
| 5061 | glRenderbufferStorageMultisampleANGLE( |
| 5062 | target, samples, impl_format, width, height); |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5063 | } else if (features().use_img_for_multisampled_render_to_texture) { |
| 5064 | glRenderbufferStorageMultisampleIMG( |
| 5065 | target, samples, impl_format, width, height); |
[email protected] | 866b91c5 | 2011-03-23 14:38:08 | [diff] [blame] | 5066 | } else { |
| 5067 | glRenderbufferStorageMultisampleEXT( |
| 5068 | target, samples, impl_format, width, height); |
| 5069 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5070 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisample"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5071 | if (error == GL_NO_ERROR) { |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5072 | |
| 5073 | if (workarounds().validate_multisample_buffer_allocation) { |
| 5074 | if (!VerifyMultisampleRenderbufferIntegrity( |
| 5075 | renderbuffer->service_id(), impl_format)) { |
| 5076 | LOCAL_SET_GL_ERROR( |
| 5077 | GL_OUT_OF_MEMORY, |
| 5078 | "glRenderbufferStorageMultisample", "out of memory"); |
| 5079 | return; |
| 5080 | } |
| 5081 | } |
| 5082 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5083 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 5084 | // attached to we could just mark those framebuffers as not complete. |
| 5085 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5086 | renderbuffer_manager()->SetInfo( |
| 5087 | renderbuffer, samples, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5088 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5089 | } |
| 5090 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5091 | // This function validates the allocation of a multisampled renderbuffer |
| 5092 | // by clearing it to a key color, blitting the contents to a texture, and |
| 5093 | // reading back the color to ensure it matches the key. |
| 5094 | bool GLES2DecoderImpl::VerifyMultisampleRenderbufferIntegrity( |
| 5095 | GLuint renderbuffer, GLenum format) { |
| 5096 | |
| 5097 | // Only validate color buffers. |
| 5098 | // These formats have been selected because they are very common or are known |
| 5099 | // to be used by the WebGL backbuffer. If problems are observed with other |
| 5100 | // color formats they can be added here. |
| 5101 | switch(format) { |
| 5102 | case GL_RGB: |
| 5103 | case GL_RGB8: |
| 5104 | case GL_RGBA: |
| 5105 | case GL_RGBA8: |
| 5106 | break; |
| 5107 | default: |
| 5108 | return true; |
| 5109 | } |
| 5110 | |
| 5111 | GLint draw_framebuffer, read_framebuffer; |
| 5112 | |
| 5113 | // Cache framebuffer and texture bindings. |
| 5114 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_framebuffer); |
| 5115 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_framebuffer); |
| 5116 | |
| 5117 | if (!validation_texture_) { |
| 5118 | GLint bound_texture; |
| 5119 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
| 5120 | |
| 5121 | // Create additional resources needed for the verification. |
| 5122 | glGenTextures(1, &validation_texture_); |
| 5123 | glGenFramebuffersEXT(1, &validation_fbo_multisample_); |
| 5124 | glGenFramebuffersEXT(1, &validation_fbo_); |
| 5125 | |
| 5126 | // Texture only needs to be 1x1. |
| 5127 | glBindTexture(GL_TEXTURE_2D, validation_texture_); |
| 5128 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, |
| 5129 | GL_UNSIGNED_BYTE, NULL); |
| 5130 | |
| 5131 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 5132 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5133 | GL_TEXTURE_2D, validation_texture_, 0); |
| 5134 | |
| 5135 | glBindTexture(GL_TEXTURE_2D, bound_texture); |
| 5136 | } |
| 5137 | |
| 5138 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 5139 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5140 | GL_RENDERBUFFER, renderbuffer); |
| 5141 | |
| 5142 | // Cache current state and reset it to the values we require. |
| 5143 | GLboolean scissor_enabled = false; |
| 5144 | glGetBooleanv(GL_SCISSOR_TEST, &scissor_enabled); |
| 5145 | if (scissor_enabled) |
| 5146 | glDisable(GL_SCISSOR_TEST); |
| 5147 | |
| 5148 | GLboolean color_mask[4] = {true, true, true, true}; |
| 5149 | glGetBooleanv(GL_COLOR_WRITEMASK, color_mask); |
| 5150 | glColorMask(true, true, true, true); |
| 5151 | |
| 5152 | GLfloat clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 5153 | glGetFloatv(GL_COLOR_CLEAR_VALUE, clear_color); |
| 5154 | glClearColor(1.0f, 0.0f, 1.0f, 1.0f); |
| 5155 | |
| 5156 | // Clear the buffer to the desired key color. |
| 5157 | glClear(GL_COLOR_BUFFER_BIT); |
| 5158 | |
| 5159 | // Blit from the multisample buffer to a standard texture. |
| 5160 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, validation_fbo_multisample_); |
| 5161 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, validation_fbo_); |
| 5162 | |
| 5163 | glBlitFramebufferEXT(0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
| 5164 | |
| 5165 | // Read a pixel from the buffer. |
| 5166 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 5167 | |
| 5168 | unsigned char pixel[3] = {0, 0, 0}; |
| 5169 | glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixel); |
| 5170 | |
| 5171 | // Detach the renderbuffer. |
| 5172 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 5173 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5174 | GL_RENDERBUFFER, 0); |
| 5175 | |
| 5176 | // Restore cached state. |
| 5177 | if (scissor_enabled) |
| 5178 | glEnable(GL_SCISSOR_TEST); |
| 5179 | |
| 5180 | glColorMask(color_mask[0], color_mask[1], color_mask[2], color_mask[3]); |
| 5181 | glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); |
| 5182 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, draw_framebuffer); |
| 5183 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, read_framebuffer); |
| 5184 | |
| 5185 | // Return true if the pixel matched the desired key color. |
| 5186 | return (pixel[0] == 0xFF && |
| 5187 | pixel[1] == 0x00 && |
| 5188 | pixel[2] == 0xFF); |
| 5189 | } |
| 5190 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5191 | void GLES2DecoderImpl::DoRenderbufferStorage( |
| 5192 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5193 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5194 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5195 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5196 | LOCAL_SET_GL_ERROR( |
| 5197 | GL_INVALID_OPERATION, |
| 5198 | "glRenderbufferStorage", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5199 | return; |
| 5200 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5201 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5202 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 5203 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5204 | LOCAL_SET_GL_ERROR( |
| 5205 | GL_INVALID_VALUE, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5206 | return; |
| 5207 | } |
| 5208 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5209 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5210 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 5211 | width, height, 1, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5212 | LOCAL_SET_GL_ERROR( |
| 5213 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5214 | return; |
| 5215 | } |
| 5216 | |
| 5217 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5218 | LOCAL_SET_GL_ERROR( |
| 5219 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5220 | return; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 5221 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5222 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5223 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorage"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5224 | glRenderbufferStorageEXT( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5225 | target, |
| 5226 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5227 | internalformat), |
| 5228 | width, |
| 5229 | height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5230 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorage"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5231 | if (error == GL_NO_ERROR) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5232 | // TODO(gman): If tetxures tracked which framebuffers they were attached to |
| 5233 | // we could just mark those framebuffers as not complete. |
| 5234 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5235 | renderbuffer_manager()->SetInfo( |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5236 | renderbuffer, 1, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5237 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5238 | } |
| 5239 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5240 | void GLES2DecoderImpl::DoLinkProgram(GLuint program_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 5241 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoLinkProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5242 | Program* program = GetProgramInfoNotShader( |
| 5243 | program_id, "glLinkProgram"); |
| 5244 | if (!program) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 5245 | return; |
| 5246 | } |
[email protected] | 05afda1 | 2011-01-20 00:17:34 | [diff] [blame] | 5247 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5248 | LogClientServiceForInfo(program, program_id, "glLinkProgram"); |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 5249 | ShaderTranslator* vertex_translator = NULL; |
| 5250 | ShaderTranslator* fragment_translator = NULL; |
| 5251 | if (use_shader_translator_) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5252 | vertex_translator = vertex_translator_.get(); |
| 5253 | fragment_translator = fragment_translator_.get(); |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 5254 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5255 | if (program->Link(shader_manager(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5256 | vertex_translator, |
| 5257 | fragment_translator, |
| 5258 | feature_info_.get(), |
| 5259 | shader_cache_callback_)) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5260 | if (program == state_.current_program.get()) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 5261 | if (workarounds().use_current_program_after_successful_link) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5262 | glUseProgram(program->service_id()); |
[email protected] | c2a3caf1 | 2012-10-23 19:32:00 | [diff] [blame] | 5263 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5264 | program_manager()->ClearUniforms(program); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 5265 | } |
| 5266 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5267 | }; |
| 5268 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5269 | void GLES2DecoderImpl::DoTexParameterf( |
| 5270 | GLenum target, GLenum pname, GLfloat param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5271 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5272 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5273 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5274 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterf", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5275 | return; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5276 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5277 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5278 | texture_manager()->SetParameter( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5279 | "glTexParameterf", GetErrorState(), texture, pname, |
| 5280 | static_cast<GLint>(param)); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5281 | } |
| 5282 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5283 | void GLES2DecoderImpl::DoTexParameteri( |
| 5284 | GLenum target, GLenum pname, GLint param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5285 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5286 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5287 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5288 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5289 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5290 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5291 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5292 | texture_manager()->SetParameter( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5293 | "glTexParameteri", GetErrorState(), texture, pname, param); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | void GLES2DecoderImpl::DoTexParameterfv( |
| 5297 | GLenum target, GLenum pname, const GLfloat* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5298 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5299 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5300 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5301 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5302 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5303 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5304 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5305 | texture_manager()->SetParameter( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5306 | "glTexParameterfv", GetErrorState(), texture, pname, |
| 5307 | static_cast<GLint>(params[0])); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5308 | } |
| 5309 | |
| 5310 | void GLES2DecoderImpl::DoTexParameteriv( |
| 5311 | GLenum target, GLenum pname, const GLint* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5312 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5313 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5314 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5315 | LOCAL_SET_GL_ERROR( |
| 5316 | GL_INVALID_VALUE, "glTexParameteriv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5317 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5318 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5319 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5320 | texture_manager()->SetParameter( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5321 | "glTexParameteriv", GetErrorState(), texture, pname, *params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5322 | } |
| 5323 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5324 | bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5325 | if (!state_.current_program.get()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5326 | // The program does not exist. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5327 | LOCAL_SET_GL_ERROR( |
| 5328 | GL_INVALID_OPERATION, function_name, "no program in use"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5329 | return false; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5330 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5331 | if (!state_.current_program->InUse()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5332 | LOCAL_SET_GL_ERROR( |
| 5333 | GL_INVALID_OPERATION, function_name, "program not linked"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5334 | return false; |
| 5335 | } |
| 5336 | return true; |
| 5337 | } |
| 5338 | |
| 5339 | bool GLES2DecoderImpl::CheckCurrentProgramForUniform( |
| 5340 | GLint location, const char* function_name) { |
| 5341 | if (!CheckCurrentProgram(function_name)) { |
| 5342 | return false; |
| 5343 | } |
| 5344 | return location != -1; |
| 5345 | } |
| 5346 | |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5347 | namespace { |
| 5348 | |
| 5349 | static const GLenum valid_int_vec1_types_list[] = { |
| 5350 | GL_INT, |
| 5351 | GL_BOOL, |
| 5352 | GL_SAMPLER_2D, |
| 5353 | GL_SAMPLER_2D_RECT_ARB, |
| 5354 | GL_SAMPLER_CUBE, |
| 5355 | GL_SAMPLER_EXTERNAL_OES, |
| 5356 | }; |
| 5357 | |
| 5358 | static const GLenum valid_int_vec2_types_list[] = { |
| 5359 | GL_INT_VEC2, |
| 5360 | GL_BOOL_VEC2, |
| 5361 | }; |
| 5362 | |
| 5363 | static const GLenum valid_int_vec3_types_list[] = { |
| 5364 | GL_INT_VEC3, |
| 5365 | GL_BOOL_VEC3, |
| 5366 | }; |
| 5367 | |
| 5368 | static const GLenum valid_int_vec4_types_list[] = { |
| 5369 | GL_INT_VEC4, |
| 5370 | GL_BOOL_VEC4, |
| 5371 | }; |
| 5372 | |
| 5373 | static const GLenum valid_float_vec1_types_list[] = { |
| 5374 | GL_FLOAT, |
| 5375 | GL_BOOL, |
| 5376 | }; |
| 5377 | |
| 5378 | static const GLenum valid_float_vec2_types_list[] = { |
| 5379 | GL_FLOAT_VEC2, |
| 5380 | GL_BOOL_VEC2, |
| 5381 | }; |
| 5382 | |
| 5383 | static const GLenum valid_float_vec3_types_list[] = { |
| 5384 | GL_FLOAT_VEC3, |
| 5385 | GL_BOOL_VEC3, |
| 5386 | }; |
| 5387 | |
| 5388 | static const GLenum valid_float_vec4_types_list[] = { |
| 5389 | GL_FLOAT_VEC4, |
| 5390 | GL_BOOL_VEC4, |
| 5391 | }; |
| 5392 | |
| 5393 | static const GLenum valid_float_mat2_types_list[] = { |
| 5394 | GL_FLOAT_MAT2, |
| 5395 | }; |
| 5396 | |
| 5397 | static const GLenum valid_float_mat3_types_list[] = { |
| 5398 | GL_FLOAT_MAT3, |
| 5399 | }; |
| 5400 | |
| 5401 | static const GLenum valid_float_mat4_types_list[] = { |
| 5402 | GL_FLOAT_MAT4, |
| 5403 | }; |
| 5404 | |
| 5405 | static const GLES2DecoderImpl::BaseUniformInfo valid_int_vec1_base_info = { |
| 5406 | valid_int_vec1_types_list, |
| 5407 | arraysize(valid_int_vec1_types_list), |
| 5408 | }; |
| 5409 | |
| 5410 | static const GLES2DecoderImpl::BaseUniformInfo valid_int_vec2_base_info = { |
| 5411 | valid_int_vec2_types_list, |
| 5412 | arraysize(valid_int_vec2_types_list), |
| 5413 | }; |
| 5414 | |
| 5415 | static const GLES2DecoderImpl::BaseUniformInfo valid_int_vec3_base_info = { |
| 5416 | valid_int_vec3_types_list, |
| 5417 | arraysize(valid_int_vec3_types_list), |
| 5418 | }; |
| 5419 | |
| 5420 | static const GLES2DecoderImpl::BaseUniformInfo valid_int_vec4_base_info = { |
| 5421 | valid_int_vec4_types_list, |
| 5422 | arraysize(valid_int_vec4_types_list), |
| 5423 | }; |
| 5424 | |
| 5425 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_vec1_base_info = { |
| 5426 | valid_float_vec1_types_list, |
| 5427 | arraysize(valid_float_vec1_types_list), |
| 5428 | }; |
| 5429 | |
| 5430 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_vec2_base_info = { |
| 5431 | valid_float_vec2_types_list, |
| 5432 | arraysize(valid_float_vec2_types_list), |
| 5433 | }; |
| 5434 | |
| 5435 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_vec3_base_info = { |
| 5436 | valid_float_vec3_types_list, |
| 5437 | arraysize(valid_float_vec3_types_list), |
| 5438 | }; |
| 5439 | |
| 5440 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_vec4_base_info = { |
| 5441 | valid_float_vec4_types_list, |
| 5442 | arraysize(valid_float_vec4_types_list), |
| 5443 | }; |
| 5444 | |
| 5445 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_mat2_base_info = { |
| 5446 | valid_float_mat2_types_list, |
| 5447 | arraysize(valid_float_mat2_types_list), |
| 5448 | }; |
| 5449 | |
| 5450 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_mat3_base_info = { |
| 5451 | valid_float_mat3_types_list, |
| 5452 | arraysize(valid_float_mat3_types_list), |
| 5453 | }; |
| 5454 | |
| 5455 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_mat4_base_info = { |
| 5456 | valid_float_mat4_types_list, |
| 5457 | arraysize(valid_float_mat4_types_list), |
| 5458 | }; |
| 5459 | |
| 5460 | } // anonymous namespace. |
| 5461 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5462 | bool GLES2DecoderImpl::PrepForSetUniformByLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5463 | GLint fake_location, const char* function_name, |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5464 | const GLES2DecoderImpl::BaseUniformInfo& base_info, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5465 | GLint* real_location, GLenum* type, GLsizei* count) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5466 | DCHECK(type); |
| 5467 | DCHECK(count); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5468 | DCHECK(real_location); |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5469 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5470 | if (!CheckCurrentProgramForUniform(fake_location, function_name)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5471 | return false; |
| 5472 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5473 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5474 | const Program::UniformInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5475 | state_.current_program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5476 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5477 | if (!info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5478 | LOCAL_SET_GL_ERROR( |
| 5479 | GL_INVALID_OPERATION, function_name, "unknown location"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5480 | return false; |
| 5481 | } |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5482 | bool okay = false; |
| 5483 | for (size_t ii = 0; ii < base_info.num_valid_types; ++ii) { |
| 5484 | if (base_info.valid_types[ii] == info->type) { |
| 5485 | okay = true; |
| 5486 | break; |
| 5487 | } |
| 5488 | } |
| 5489 | if (!okay) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5490 | LOCAL_SET_GL_ERROR( |
| 5491 | GL_INVALID_OPERATION, function_name, |
| 5492 | "wrong uniform function for type"); |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5493 | return false; |
| 5494 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5495 | if (*count > 1 && !info->is_array) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5496 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5497 | GL_INVALID_OPERATION, function_name, "count > 1 for non-array"); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5498 | return false; |
| 5499 | } |
| 5500 | *count = std::min(info->size - array_index, *count); |
| 5501 | if (*count <= 0) { |
| 5502 | return false; |
| 5503 | } |
| 5504 | *type = info->type; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5505 | return true; |
| 5506 | } |
| 5507 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5508 | void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) { |
| 5509 | GLenum type = 0; |
| 5510 | GLsizei count = 1; |
| 5511 | GLint real_location = -1; |
| 5512 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5513 | fake_location, "glUniform1iv", valid_int_vec1_base_info, |
| 5514 | &real_location, &type, &count)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5515 | return; |
| 5516 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5517 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5518 | state_.texture_units.size(), fake_location, 1, &v0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5519 | LOCAL_SET_GL_ERROR( |
| 5520 | GL_INVALID_VALUE, "glUniform1i", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 5521 | return; |
| 5522 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5523 | glUniform1i(real_location, v0); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5524 | } |
| 5525 | |
| 5526 | void GLES2DecoderImpl::DoUniform1iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5527 | GLint fake_location, GLsizei count, const GLint *value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5528 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5529 | GLint real_location = -1; |
| 5530 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5531 | fake_location, "glUniform1iv", valid_int_vec1_base_info, |
| 5532 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5533 | return; |
| 5534 | } |
[email protected] | 7472711 | 2012-06-13 21:18:08 | [diff] [blame] | 5535 | if (type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || |
| 5536 | type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5537 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5538 | state_.texture_units.size(), fake_location, count, value)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5539 | LOCAL_SET_GL_ERROR( |
| 5540 | GL_INVALID_VALUE, "glUniform1iv", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 5541 | return; |
| 5542 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5543 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5544 | glUniform1iv(real_location, count, value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5545 | } |
| 5546 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5547 | void GLES2DecoderImpl::DoUniform1fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5548 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5549 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5550 | GLint real_location = -1; |
| 5551 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5552 | fake_location, "glUniform1fv", valid_float_vec1_base_info, |
| 5553 | &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5554 | return; |
| 5555 | } |
| 5556 | if (type == GL_BOOL) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5557 | scoped_ptr<GLint[]> temp(new GLint[count]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5558 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5559 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5560 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5561 | DoUniform1iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5562 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5563 | glUniform1fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5564 | } |
| 5565 | } |
| 5566 | |
| 5567 | void GLES2DecoderImpl::DoUniform2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5568 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5569 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5570 | GLint real_location = -1; |
| 5571 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5572 | fake_location, "glUniform2fv", valid_float_vec2_base_info, |
| 5573 | &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5574 | return; |
| 5575 | } |
| 5576 | if (type == GL_BOOL_VEC2) { |
| 5577 | GLsizei num_values = count * 2; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5578 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5579 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5580 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5581 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5582 | glUniform2iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5583 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5584 | glUniform2fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5585 | } |
| 5586 | } |
| 5587 | |
| 5588 | void GLES2DecoderImpl::DoUniform3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5589 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5590 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5591 | GLint real_location = -1; |
| 5592 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5593 | fake_location, "glUniform3fv", valid_float_vec3_base_info, |
| 5594 | &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5595 | return; |
| 5596 | } |
| 5597 | if (type == GL_BOOL_VEC3) { |
| 5598 | GLsizei num_values = count * 3; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5599 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5600 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5601 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5602 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5603 | glUniform3iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5604 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5605 | glUniform3fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5606 | } |
| 5607 | } |
| 5608 | |
| 5609 | void GLES2DecoderImpl::DoUniform4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5610 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5611 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5612 | GLint real_location = -1; |
| 5613 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5614 | fake_location, "glUniform4fv", valid_float_vec4_base_info, |
| 5615 | &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5616 | return; |
| 5617 | } |
| 5618 | if (type == GL_BOOL_VEC4) { |
| 5619 | GLsizei num_values = count * 4; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5620 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5621 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5622 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5623 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5624 | glUniform4iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5625 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5626 | glUniform4fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5627 | } |
| 5628 | } |
| 5629 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5630 | void GLES2DecoderImpl::DoUniform2iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5631 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5632 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5633 | GLint real_location = -1; |
| 5634 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5635 | fake_location, "glUniform2iv", valid_int_vec2_base_info, |
| 5636 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5637 | return; |
| 5638 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5639 | glUniform2iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5640 | } |
| 5641 | |
| 5642 | void GLES2DecoderImpl::DoUniform3iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5643 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5644 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5645 | GLint real_location = -1; |
| 5646 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5647 | fake_location, "glUniform3iv", valid_int_vec3_base_info, |
| 5648 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5649 | return; |
| 5650 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5651 | glUniform3iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5652 | } |
| 5653 | |
| 5654 | void GLES2DecoderImpl::DoUniform4iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5655 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5656 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5657 | GLint real_location = -1; |
| 5658 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5659 | fake_location, "glUniform4iv", valid_int_vec4_base_info, |
| 5660 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5661 | return; |
| 5662 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5663 | glUniform4iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5664 | } |
| 5665 | |
| 5666 | void GLES2DecoderImpl::DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5667 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 5668 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5669 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5670 | GLint real_location = -1; |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5671 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5672 | fake_location, "glUniformMatrix2fv", valid_float_mat2_base_info, |
| 5673 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5674 | return; |
| 5675 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5676 | glUniformMatrix2fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5677 | } |
| 5678 | |
| 5679 | void GLES2DecoderImpl::DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5680 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 5681 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5682 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5683 | GLint real_location = -1; |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5684 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5685 | fake_location, "glUniformMatrix3fv", valid_float_mat3_base_info, |
| 5686 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5687 | return; |
| 5688 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5689 | glUniformMatrix3fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5690 | } |
| 5691 | |
| 5692 | void GLES2DecoderImpl::DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5693 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 5694 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5695 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5696 | GLint real_location = -1; |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5697 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5698 | fake_location, "glUniformMatrix4fv", valid_float_mat4_base_info, |
| 5699 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5700 | return; |
| 5701 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5702 | glUniformMatrix4fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5703 | } |
| 5704 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5705 | void GLES2DecoderImpl::DoUseProgram(GLuint program_id) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5706 | GLuint service_id = 0; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5707 | Program* program = NULL; |
| 5708 | if (program_id) { |
| 5709 | program = GetProgramInfoNotShader(program_id, "glUseProgram"); |
| 5710 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5711 | return; |
| 5712 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5713 | if (!program->IsValid()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5714 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5715 | LOCAL_SET_GL_ERROR( |
| 5716 | GL_INVALID_OPERATION, "glUseProgram", "program not linked"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5717 | return; |
| 5718 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5719 | service_id = program->service_id(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5720 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5721 | if (state_.current_program.get()) { |
| 5722 | program_manager()->UnuseProgram(shader_manager(), |
| 5723 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5724 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5725 | state_.current_program = program; |
| 5726 | LogClientServiceMapping("glUseProgram", program_id, service_id); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 5727 | glUseProgram(service_id); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5728 | if (state_.current_program.get()) { |
| 5729 | program_manager()->UseProgram(state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5730 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5731 | } |
| 5732 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5733 | void GLES2DecoderImpl::RenderWarning( |
| 5734 | const char* filename, int line, const std::string& msg) { |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 5735 | logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5736 | } |
| 5737 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5738 | void GLES2DecoderImpl::PerformanceWarning( |
| 5739 | const char* filename, int line, const std::string& msg) { |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5740 | logger_.LogMessage(filename, line, |
| 5741 | std::string("PERFORMANCE WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5742 | } |
| 5743 | |
[email protected] | e8dc566 | 2013-10-17 23:28:29 | [diff] [blame] | 5744 | void GLES2DecoderImpl::UpdateStreamTextureIfNeeded(Texture* texture, |
| 5745 | GLuint texture_unit_index) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 5746 | if (texture && texture->IsStreamTexture()) { |
| 5747 | DCHECK(stream_texture_manager()); |
| 5748 | StreamTexture* stream_tex = |
| 5749 | stream_texture_manager()->LookupStreamTexture(texture->service_id()); |
[email protected] | e8dc566 | 2013-10-17 23:28:29 | [diff] [blame] | 5750 | if (stream_tex) { |
| 5751 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 5752 | stream_tex->Update(); |
[email protected] | e8dc566 | 2013-10-17 23:28:29 | [diff] [blame] | 5753 | } |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 5754 | } |
| 5755 | } |
| 5756 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5757 | void GLES2DecoderImpl::DoWillUseTexImageIfNeeded( |
| 5758 | Texture* texture, GLenum textarget) { |
| 5759 | // This might be supported in the future. |
| 5760 | if (textarget != GL_TEXTURE_2D) |
| 5761 | return; |
| 5762 | // Image is already in use if texture is attached to a framebuffer. |
| 5763 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 5764 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 5765 | if (image) { |
| 5766 | ScopedGLErrorSuppressor suppressor( |
| 5767 | "GLES2DecoderImpl::DoWillUseTexImageIfNeeded", |
| 5768 | GetErrorState()); |
| 5769 | glBindTexture(textarget, texture->service_id()); |
| 5770 | image->WillUseTexImage(); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 5771 | RestoreCurrentTexture2DBindings(&state_); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5772 | } |
| 5773 | } |
| 5774 | } |
| 5775 | |
| 5776 | void GLES2DecoderImpl::DoDidUseTexImageIfNeeded( |
| 5777 | Texture* texture, GLenum textarget) { |
| 5778 | // This might be supported in the future. |
| 5779 | if (textarget != GL_TEXTURE_2D) |
| 5780 | return; |
| 5781 | // Image is still in use if texture is attached to a framebuffer. |
| 5782 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 5783 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 5784 | if (image) { |
| 5785 | ScopedGLErrorSuppressor suppressor( |
| 5786 | "GLES2DecoderImpl::DoDidUseTexImageIfNeeded", |
| 5787 | GetErrorState()); |
| 5788 | glBindTexture(textarget, texture->service_id()); |
| 5789 | image->DidUseTexImage(); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 5790 | RestoreCurrentTexture2DBindings(&state_); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5791 | } |
| 5792 | } |
| 5793 | } |
| 5794 | |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 5795 | bool GLES2DecoderImpl::PrepareTexturesForRender() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5796 | DCHECK(state_.current_program.get()); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5797 | if (!texture_manager()->HaveUnrenderableTextures() && |
| 5798 | !texture_manager()->HaveImages() && |
| 5799 | !features().oes_egl_image_external) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 5800 | return true; |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5801 | } |
[email protected] | e2367b4 | 2013-05-31 03:37:21 | [diff] [blame] | 5802 | |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5803 | bool textures_set = false; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5804 | const Program::SamplerIndices& sampler_indices = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5805 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5806 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5807 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5808 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5809 | DCHECK(uniform_info); |
| 5810 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 5811 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5812 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5813 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5814 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 5815 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5816 | GLenum textarget = GetBindTargetForSamplerType(uniform_info->type); |
| 5817 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5818 | textures_set = true; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5819 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 5820 | glBindTexture( |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5821 | textarget, |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 5822 | texture_manager()->black_texture_id(uniform_info->type)); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5823 | LOCAL_RENDER_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5824 | std::string("texture bound to texture unit ") + |
| 5825 | base::IntToString(texture_unit_index) + |
[email protected] | ad9b7f8b | 2013-06-17 07:36:29 | [diff] [blame] | 5826 | " is not renderable. It maybe non-power-of-2 and have" |
| 5827 | " incompatible texture filtering or is not" |
| 5828 | " 'texture complete'"); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5829 | continue; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5830 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5831 | |
| 5832 | Texture* texture = texture_ref->texture(); |
| 5833 | if (textarget == GL_TEXTURE_2D) { |
| 5834 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 5835 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 5836 | ScopedGLErrorSuppressor suppressor( |
| 5837 | "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); |
| 5838 | textures_set = true; |
| 5839 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 5840 | image->WillUseTexImage(); |
| 5841 | continue; |
| 5842 | } |
| 5843 | } |
| 5844 | |
| 5845 | UpdateStreamTextureIfNeeded(texture, texture_unit_index); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5846 | } |
| 5847 | // else: should this be an error? |
| 5848 | } |
| 5849 | } |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 5850 | return !textures_set; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5851 | } |
| 5852 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5853 | void GLES2DecoderImpl::RestoreStateForTextures() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5854 | DCHECK(state_.current_program.get()); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5855 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5856 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5857 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5858 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5859 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5860 | DCHECK(uniform_info); |
| 5861 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 5862 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5863 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5864 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5865 | TextureRef* texture_ref = |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5866 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5867 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5868 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5869 | // Get the texture_ref info that was previously bound here. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5870 | texture_ref = texture_unit.bind_target == GL_TEXTURE_2D |
| 5871 | ? texture_unit.bound_texture_2d.get() |
| 5872 | : texture_unit.bound_texture_cube_map.get(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5873 | glBindTexture(texture_unit.bind_target, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5874 | texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5875 | continue; |
| 5876 | } |
| 5877 | |
| 5878 | Texture* texture = texture_ref->texture(); |
| 5879 | if (texture_unit.bind_target == GL_TEXTURE_2D) { |
| 5880 | gfx::GLImage* image = texture->GetLevelImage( |
| 5881 | texture_unit.bind_target, 0); |
| 5882 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 5883 | ScopedGLErrorSuppressor suppressor( |
| 5884 | "GLES2DecoderImpl::RestoreStateForTextures", GetErrorState()); |
| 5885 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 5886 | image->DidUseTexImage(); |
| 5887 | continue; |
| 5888 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5889 | } |
| 5890 | } |
| 5891 | } |
| 5892 | } |
| 5893 | // Set the active texture back to whatever the user had it as. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5894 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5895 | } |
| 5896 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5897 | bool GLES2DecoderImpl::ClearUnclearedTextures() { |
| 5898 | // Only check if there are some uncleared textures. |
| 5899 | if (!texture_manager()->HaveUnsafeTextures()) { |
| 5900 | return true; |
| 5901 | } |
| 5902 | |
| 5903 | // 1: Check all textures we are about to render with. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5904 | if (state_.current_program.get()) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5905 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5906 | state_.current_program->sampler_indices(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5907 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5908 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5909 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5910 | DCHECK(uniform_info); |
| 5911 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 5912 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5913 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5914 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5915 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 5916 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5917 | if (texture_ref && !texture_ref->texture()->SafeToRenderFrom()) { |
| 5918 | if (!texture_manager()->ClearRenderableLevels(this, texture_ref)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5919 | return false; |
| 5920 | } |
| 5921 | } |
| 5922 | } |
| 5923 | } |
| 5924 | } |
| 5925 | } |
| 5926 | return true; |
| 5927 | } |
| 5928 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5929 | bool GLES2DecoderImpl::IsDrawValid( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5930 | const char* function_name, GLuint max_vertex_accessed, GLsizei primcount) { |
[email protected] | 689fa1c5 | 2010-06-09 18:35:03 | [diff] [blame] | 5931 | // NOTE: We specifically do not check current_program->IsValid() because |
| 5932 | // it could never be invalid since glUseProgram would have failed. While |
| 5933 | // glLinkProgram could later mark the program as invalid the previous |
| 5934 | // valid program will still function if it is still the current program. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5935 | if (!state_.current_program.get()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5936 | // The program does not exist. |
| 5937 | // But GL says no ERROR. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5938 | LOCAL_RENDER_WARNING("Drawing with no current shader program."); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5939 | return false; |
| 5940 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 5941 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5942 | return state_.vertex_attrib_manager |
| 5943 | ->ValidateBindings(function_name, |
| 5944 | this, |
| 5945 | feature_info_.get(), |
| 5946 | state_.current_program.get(), |
| 5947 | max_vertex_accessed, |
| 5948 | primcount); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5949 | } |
| 5950 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5951 | bool GLES2DecoderImpl::SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5952 | const char* function_name, GLuint max_vertex_accessed, bool* simulated) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5953 | DCHECK(simulated); |
| 5954 | *simulated = false; |
| 5955 | |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5956 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5957 | return true; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5958 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 5959 | const VertexAttrib* attrib = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5960 | state_.vertex_attrib_manager->GetVertexAttrib(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5961 | // 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] | 5962 | bool attrib_0_used = |
| 5963 | state_.current_program->GetAttribInfoByLocation(0) != NULL; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 5964 | if (attrib->enabled() && attrib_0_used) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5965 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5966 | } |
| 5967 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 5968 | // Make a buffer with a single repeated vec4 value enough to |
| 5969 | // simulate the constant value that is supposed to be here. |
| 5970 | // This is required to emulate GLES2 on GL. |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5971 | GLuint num_vertices = max_vertex_accessed + 1; |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 5972 | uint32 size_needed = 0; |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5973 | |
| 5974 | if (num_vertices == 0 || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 5975 | !SafeMultiplyUint32(num_vertices, sizeof(Vec4), &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5976 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5977 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5978 | return false; |
| 5979 | } |
| 5980 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5981 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5982 | "Attribute 0 is disabled. This has signficant performance penalty"); |
| 5983 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5984 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5985 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 5986 | |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 5987 | bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; |
| 5988 | if (new_buffer) { |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 5989 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5990 | GLenum error = glGetError(); |
| 5991 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5992 | LOCAL_SET_GL_ERROR( |
| 5993 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 5994 | return false; |
| 5995 | } |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 5996 | } |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 5997 | |
| 5998 | const Vec4& value = state_.attrib_values[0]; |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 5999 | if (new_buffer || |
| 6000 | (attrib_0_used && |
| 6001 | (!attrib_0_buffer_matches_value_ || |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6002 | (value.v[0] != attrib_0_value_.v[0] || |
| 6003 | value.v[1] != attrib_0_value_.v[1] || |
| 6004 | value.v[2] != attrib_0_value_.v[2] || |
| 6005 | value.v[3] != attrib_0_value_.v[3])))) { |
| 6006 | std::vector<Vec4> temp(num_vertices, value); |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6007 | glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); |
| 6008 | attrib_0_buffer_matches_value_ = true; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6009 | attrib_0_value_ = value; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6010 | attrib_0_size_ = size_needed; |
| 6011 | } |
| 6012 | |
| 6013 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 6014 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6015 | if (attrib->divisor()) |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6016 | glVertexAttribDivisorANGLE(0, 0); |
| 6017 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6018 | *simulated = true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6019 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6020 | } |
| 6021 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6022 | void GLES2DecoderImpl::RestoreStateForAttrib(GLuint attrib_index) { |
| 6023 | const VertexAttrib* attrib = |
| 6024 | state_.vertex_attrib_manager->GetVertexAttrib(attrib_index); |
| 6025 | const void* ptr = reinterpret_cast<const void*>(attrib->offset()); |
| 6026 | Buffer* buffer = attrib->buffer(); |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 6027 | glBindBuffer(GL_ARRAY_BUFFER, buffer ? buffer->service_id() : 0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6028 | glVertexAttribPointer( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6029 | attrib_index, attrib->size(), attrib->type(), attrib->normalized(), |
| 6030 | attrib->gl_stride(), ptr); |
| 6031 | if (attrib->divisor()) |
| 6032 | glVertexAttribDivisorANGLE(attrib_index, attrib->divisor()); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6033 | glBindBuffer( |
| 6034 | GL_ARRAY_BUFFER, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6035 | state_.bound_array_buffer.get() ? state_.bound_array_buffer->service_id() |
| 6036 | : 0); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6037 | |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6038 | // Never touch vertex attribute 0's state (in particular, never |
| 6039 | // disable it) when running on desktop GL because it will never be |
| 6040 | // re-enabled. |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6041 | if (attrib_index != 0 || |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6042 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6043 | if (attrib->enabled()) { |
| 6044 | glEnableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6045 | } else { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6046 | glDisableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6047 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6048 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6049 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6050 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6051 | bool GLES2DecoderImpl::SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6052 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6053 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6054 | DCHECK(simulated); |
| 6055 | *simulated = false; |
| 6056 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
| 6057 | return true; |
| 6058 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6059 | if (!state_.vertex_attrib_manager->HaveFixedAttribs()) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6060 | return true; |
| 6061 | } |
| 6062 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6063 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6064 | "GL_FIXED attributes have a signficant performance penalty"); |
| 6065 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6066 | // NOTE: we could be smart and try to check if a buffer is used |
| 6067 | // twice in 2 different attribs, find the overlapping parts and therefore |
| 6068 | // duplicate the minimum amount of data but this whole code path is not meant |
| 6069 | // to be used normally. It's just here to pass that OpenGL ES 2.0 conformance |
| 6070 | // tests so we just add to the buffer attrib used. |
| 6071 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6072 | GLuint elements_needed = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6073 | const VertexAttribManager::VertexAttribList& enabled_attribs = |
| 6074 | state_.vertex_attrib_manager->GetEnabledVertexAttribs(); |
| 6075 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 6076 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 6077 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6078 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6079 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 6080 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
| 6081 | max_vertex_accessed); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6082 | GLuint num_vertices = max_accessed + 1; |
| 6083 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6084 | LOCAL_SET_GL_ERROR( |
| 6085 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6086 | return false; |
| 6087 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6088 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6089 | attrib->CanAccess(max_accessed) && |
| 6090 | attrib->type() == GL_FIXED) { |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6091 | uint32 elements_used = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6092 | if (!SafeMultiplyUint32(num_vertices, attrib->size(), &elements_used) || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6093 | !SafeAddUint32(elements_needed, elements_used, &elements_needed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6094 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6095 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6096 | return false; |
| 6097 | } |
| 6098 | } |
| 6099 | } |
| 6100 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6101 | const uint32 kSizeOfFloat = sizeof(float); // NOLINT |
| 6102 | uint32 size_needed = 0; |
| 6103 | if (!SafeMultiplyUint32(elements_needed, kSizeOfFloat, &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6104 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6105 | LOCAL_SET_GL_ERROR( |
| 6106 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6107 | return false; |
| 6108 | } |
| 6109 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6110 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6111 | |
| 6112 | glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6113 | if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6114 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6115 | GLenum error = glGetError(); |
| 6116 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6117 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6118 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6119 | return false; |
| 6120 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | // Copy the elements and convert to float |
| 6124 | GLintptr offset = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6125 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 6126 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 6127 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6128 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6129 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 6130 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6131 | max_vertex_accessed); |
| 6132 | GLuint num_vertices = max_accessed + 1; |
| 6133 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6134 | LOCAL_SET_GL_ERROR( |
| 6135 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6136 | return false; |
| 6137 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6138 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6139 | attrib->CanAccess(max_accessed) && |
| 6140 | attrib->type() == GL_FIXED) { |
| 6141 | int num_elements = attrib->size() * kSizeOfFloat; |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6142 | int size = num_elements * num_vertices; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6143 | scoped_ptr<float[]> data(new float[size]); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6144 | const int32* src = reinterpret_cast<const int32 *>( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6145 | attrib->buffer()->GetRange(attrib->offset(), size)); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6146 | const int32* end = src + num_elements; |
| 6147 | float* dst = data.get(); |
| 6148 | while (src != end) { |
| 6149 | *dst++ = static_cast<float>(*src++) / 65536.0f; |
| 6150 | } |
| 6151 | glBufferSubData(GL_ARRAY_BUFFER, offset, size, data.get()); |
| 6152 | glVertexAttribPointer( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6153 | attrib->index(), attrib->size(), GL_FLOAT, false, 0, |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6154 | reinterpret_cast<GLvoid*>(offset)); |
| 6155 | offset += size; |
| 6156 | } |
| 6157 | } |
| 6158 | *simulated = true; |
| 6159 | return true; |
| 6160 | } |
| 6161 | |
| 6162 | void GLES2DecoderImpl::RestoreStateForSimulatedFixedAttribs() { |
| 6163 | // There's no need to call glVertexAttribPointer because we shadow all the |
| 6164 | // settings and passing GL_FIXED to it will not work. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6165 | glBindBuffer( |
| 6166 | GL_ARRAY_BUFFER, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6167 | state_.bound_array_buffer.get() ? state_.bound_array_buffer->service_id() |
| 6168 | : 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6169 | } |
| 6170 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6171 | error::Error GLES2DecoderImpl::DoDrawArrays( |
| 6172 | const char* function_name, |
| 6173 | bool instanced, |
| 6174 | GLenum mode, |
| 6175 | GLint first, |
| 6176 | GLsizei count, |
| 6177 | GLsizei primcount) { |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 6178 | if (ShouldDeferDraws()) |
| 6179 | return error::kDeferCommandUntilLater; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6180 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6181 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6182 | return error::kNoError; |
| 6183 | } |
| 6184 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6185 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6186 | return error::kNoError; |
| 6187 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6188 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6189 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6190 | return error::kNoError; |
| 6191 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6192 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6193 | return error::kNoError; |
| 6194 | } |
| 6195 | // We have to check this here because the prototype for glDrawArrays |
| 6196 | // is GLint not GLsizei. |
| 6197 | if (first < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6198 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "first < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6199 | return error::kNoError; |
| 6200 | } |
| 6201 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6202 | if (count == 0 || (instanced && primcount == 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6203 | LOCAL_RENDER_WARNING("Render count or primcount is 0."); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6204 | return error::kNoError; |
| 6205 | } |
| 6206 | |
| 6207 | GLuint max_vertex_accessed = first + count - 1; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6208 | if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6209 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6210 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6211 | return error::kNoError; |
| 6212 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6213 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6214 | if (!SimulateAttrib0( |
| 6215 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6216 | return error::kNoError; |
| 6217 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6218 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6219 | if (SimulateFixedAttribs( |
| 6220 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 6221 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6222 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6223 | ApplyDirtyState(); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6224 | if (!instanced) { |
| 6225 | glDrawArrays(mode, first, count); |
| 6226 | } else { |
| 6227 | glDrawArraysInstancedANGLE(mode, first, count, primcount); |
| 6228 | } |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 6229 | ProcessPendingQueries(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6230 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6231 | RestoreStateForTextures(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6232 | } |
| 6233 | if (simulated_fixed_attribs) { |
| 6234 | RestoreStateForSimulatedFixedAttribs(); |
| 6235 | } |
| 6236 | } |
| 6237 | if (simulated_attrib_0) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6238 | RestoreStateForAttrib(0); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6239 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6240 | } |
| 6241 | return error::kNoError; |
| 6242 | } |
| 6243 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6244 | error::Error GLES2DecoderImpl::HandleDrawArrays( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6245 | uint32 immediate_data_size, const cmds::DrawArrays& c) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6246 | return DoDrawArrays("glDrawArrays", |
| 6247 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6248 | static_cast<GLenum>(c.mode), |
| 6249 | static_cast<GLint>(c.first), |
| 6250 | static_cast<GLsizei>(c.count), |
| 6251 | 0); |
| 6252 | } |
| 6253 | |
| 6254 | error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6255 | uint32 immediate_data_size, const cmds::DrawArraysInstancedANGLE& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6256 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6257 | LOCAL_SET_GL_ERROR( |
| 6258 | GL_INVALID_OPERATION, |
| 6259 | "glDrawArraysInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6260 | return error::kNoError; |
| 6261 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6262 | return DoDrawArrays("glDrawArraysIntancedANGLE", |
| 6263 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6264 | static_cast<GLenum>(c.mode), |
| 6265 | static_cast<GLint>(c.first), |
| 6266 | static_cast<GLsizei>(c.count), |
| 6267 | static_cast<GLsizei>(c.primcount)); |
| 6268 | } |
| 6269 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6270 | error::Error GLES2DecoderImpl::DoDrawElements( |
| 6271 | const char* function_name, |
| 6272 | bool instanced, |
| 6273 | GLenum mode, |
| 6274 | GLsizei count, |
| 6275 | GLenum type, |
| 6276 | int32 offset, |
| 6277 | GLsizei primcount) { |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 6278 | if (ShouldDeferDraws()) |
| 6279 | return error::kDeferCommandUntilLater; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6280 | if (!state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6281 | LOCAL_SET_GL_ERROR( |
| 6282 | GL_INVALID_OPERATION, function_name, "No element array buffer bound"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6283 | return error::kNoError; |
| 6284 | } |
| 6285 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6286 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6287 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6288 | return error::kNoError; |
| 6289 | } |
| 6290 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6291 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6292 | return error::kNoError; |
| 6293 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6294 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6295 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6296 | return error::kNoError; |
| 6297 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6298 | if (!validators_->index_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6299 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6300 | return error::kNoError; |
| 6301 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6302 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6303 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6304 | return error::kNoError; |
| 6305 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6306 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6307 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 6308 | return error::kNoError; |
| 6309 | } |
| 6310 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6311 | if (count == 0 || (instanced && primcount == 0)) { |
[email protected] | 6c788fb7 | 2010-08-26 02:16:31 | [diff] [blame] | 6312 | return error::kNoError; |
| 6313 | } |
| 6314 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6315 | GLuint max_vertex_accessed; |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6316 | Buffer* element_array_buffer = |
| 6317 | state_.vertex_attrib_manager->element_array_buffer(); |
| 6318 | |
| 6319 | if (!element_array_buffer->GetMaxValueForRange( |
| 6320 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6321 | LOCAL_SET_GL_ERROR( |
| 6322 | GL_INVALID_OPERATION, function_name, "range out of bounds for buffer"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6323 | return error::kNoError; |
| 6324 | } |
| 6325 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6326 | if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6327 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6328 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6329 | return error::kNoError; |
| 6330 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6331 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6332 | if (!SimulateAttrib0( |
| 6333 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6334 | return error::kNoError; |
| 6335 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6336 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6337 | if (SimulateFixedAttribs( |
| 6338 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 6339 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6340 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 6341 | ApplyDirtyState(); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6342 | // TODO(gman): Refactor to hide these details in BufferManager or |
| 6343 | // VertexAttribManager. |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6344 | const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6345 | bool used_client_side_array = false; |
| 6346 | if (element_array_buffer->IsClientSideArray()) { |
| 6347 | used_client_side_array = true; |
| 6348 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 6349 | indices = element_array_buffer->GetRange(offset, 0); |
| 6350 | } |
| 6351 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6352 | if (!instanced) { |
| 6353 | glDrawElements(mode, count, type, indices); |
| 6354 | } else { |
| 6355 | glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); |
| 6356 | } |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6357 | |
| 6358 | if (used_client_side_array) { |
| 6359 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 6360 | element_array_buffer->service_id()); |
| 6361 | } |
| 6362 | |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 6363 | ProcessPendingQueries(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6364 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6365 | RestoreStateForTextures(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6366 | } |
| 6367 | if (simulated_fixed_attribs) { |
| 6368 | RestoreStateForSimulatedFixedAttribs(); |
| 6369 | } |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6370 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6371 | if (simulated_attrib_0) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6372 | RestoreStateForAttrib(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6373 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6374 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6375 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6376 | } |
| 6377 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6378 | error::Error GLES2DecoderImpl::HandleDrawElements( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6379 | uint32 immediate_data_size, const cmds::DrawElements& c) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6380 | return DoDrawElements("glDrawElements", |
| 6381 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6382 | static_cast<GLenum>(c.mode), |
| 6383 | static_cast<GLsizei>(c.count), |
| 6384 | static_cast<GLenum>(c.type), |
| 6385 | static_cast<int32>(c.index_offset), |
| 6386 | 0); |
| 6387 | } |
| 6388 | |
| 6389 | error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6390 | uint32 immediate_data_size, const cmds::DrawElementsInstancedANGLE& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6391 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6392 | LOCAL_SET_GL_ERROR( |
| 6393 | GL_INVALID_OPERATION, |
| 6394 | "glDrawElementsInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6395 | return error::kNoError; |
| 6396 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6397 | return DoDrawElements("glDrawElementsInstancedANGLE", |
| 6398 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6399 | static_cast<GLenum>(c.mode), |
| 6400 | static_cast<GLsizei>(c.count), |
| 6401 | static_cast<GLenum>(c.type), |
| 6402 | static_cast<int32>(c.index_offset), |
| 6403 | static_cast<GLsizei>(c.primcount)); |
| 6404 | } |
| 6405 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 6406 | GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 6407 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { |
| 6408 | GLuint max_vertex_accessed = 0; |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 6409 | Buffer* buffer = GetBuffer(buffer_id); |
| 6410 | if (!buffer) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6411 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6412 | LOCAL_SET_GL_ERROR( |
| 6413 | GL_INVALID_VALUE, "GetMaxValueInBufferCHROMIUM", "unknown buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 6414 | } else { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 6415 | if (!buffer->GetMaxValueForRange( |
| 6416 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6417 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6418 | LOCAL_SET_GL_ERROR( |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 6419 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6420 | "GetMaxValueInBufferCHROMIUM", "range out of bounds for buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 6421 | } |
| 6422 | } |
| 6423 | return max_vertex_accessed; |
| 6424 | } |
| 6425 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6426 | // Calls glShaderSource for the various versions of the ShaderSource command. |
| 6427 | // Assumes that data / data_size points to a piece of memory that is in range |
| 6428 | // of whatever context it came from (shared memory, immediate memory, bucket |
| 6429 | // memory.) |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6430 | error::Error GLES2DecoderImpl::ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6431 | GLuint client_id, const char* data, uint32 data_size) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 6432 | std::string str(data, data + data_size); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6433 | Shader* shader = GetShaderInfoNotProgram(client_id, "glShaderSource"); |
| 6434 | if (!shader) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6435 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6436 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6437 | // Note: We don't actually call glShaderSource here. We wait until |
| 6438 | // the call to glCompileShader. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6439 | shader->UpdateSource(str.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6440 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6441 | } |
| 6442 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6443 | error::Error GLES2DecoderImpl::HandleShaderSource( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6444 | uint32 immediate_data_size, const cmds::ShaderSource& c) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6445 | uint32 data_size = c.data_size; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6446 | const char* data = GetSharedMemoryAs<const char*>( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6447 | c.data_shm_id, c.data_shm_offset, data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6448 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6449 | return error::kOutOfBounds; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6450 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6451 | return ShaderSourceHelper(c.shader, data, data_size); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6452 | } |
| 6453 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6454 | error::Error GLES2DecoderImpl::HandleShaderSourceBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6455 | uint32 immediate_data_size, const cmds::ShaderSourceBucket& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6456 | Bucket* bucket = GetBucket(c.data_bucket_id); |
| 6457 | if (!bucket || bucket->size() == 0) { |
| 6458 | return error::kInvalidArguments; |
| 6459 | } |
| 6460 | return ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6461 | c.shader, bucket->GetDataAs<const char*>(0, bucket->size() - 1), |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6462 | bucket->size() - 1); |
| 6463 | } |
| 6464 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6465 | void GLES2DecoderImpl::DoCompileShader(GLuint client_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 6466 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompileShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6467 | Shader* shader = GetShaderInfoNotProgram(client_id, "glCompileShader"); |
| 6468 | if (!shader) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6469 | return; |
| 6470 | } |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 6471 | ShaderTranslator* translator = NULL; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 6472 | if (use_shader_translator_) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6473 | translator = shader->shader_type() == GL_VERTEX_SHADER ? |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 6474 | vertex_translator_.get() : fragment_translator_.get(); |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 6475 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 6476 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6477 | program_manager()->DoCompileShader(shader, translator, feature_info_.get()); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6478 | }; |
| 6479 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6480 | void GLES2DecoderImpl::DoGetShaderiv( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6481 | GLuint shader_id, GLenum pname, GLint* params) { |
| 6482 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderiv"); |
| 6483 | if (!shader) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6484 | return; |
| 6485 | } |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6486 | switch (pname) { |
| 6487 | case GL_SHADER_SOURCE_LENGTH: |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6488 | *params = shader->source() ? shader->source()->size() + 1 : 0; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6489 | return; |
| 6490 | case GL_COMPILE_STATUS: |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6491 | *params = compile_shader_always_succeeds_ ? true : shader->IsValid(); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 6492 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6493 | case GL_INFO_LOG_LENGTH: |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6494 | *params = shader->log_info() ? shader->log_info()->size() + 1 : 0; |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 6495 | return; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6496 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6497 | *params = shader->translated_source() ? |
| 6498 | shader->translated_source()->size() + 1 : 0; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6499 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6500 | default: |
| 6501 | break; |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6502 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6503 | glGetShaderiv(shader->service_id(), pname, params); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6504 | } |
| 6505 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6506 | error::Error GLES2DecoderImpl::HandleGetShaderSource( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6507 | uint32 immediate_data_size, const cmds::GetShaderSource& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6508 | GLuint shader_id = c.shader; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6509 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6510 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6511 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderSource"); |
| 6512 | if (!shader || !shader->source()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6513 | bucket->SetSize(0); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6514 | return error::kNoError; |
| 6515 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6516 | bucket->SetFromString(shader->source()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6517 | return error::kNoError; |
| 6518 | } |
| 6519 | |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6520 | error::Error GLES2DecoderImpl::HandleGetTranslatedShaderSourceANGLE( |
| 6521 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6522 | const cmds::GetTranslatedShaderSourceANGLE& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6523 | GLuint shader_id = c.shader; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6524 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6525 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6526 | Shader* shader = GetShaderInfoNotProgram( |
| 6527 | shader_id, "glTranslatedGetShaderSourceANGLE"); |
| 6528 | if (!shader) { |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6529 | bucket->SetSize(0); |
| 6530 | return error::kNoError; |
| 6531 | } |
| 6532 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6533 | bucket->SetFromString(shader->translated_source() ? |
| 6534 | shader->translated_source()->c_str() : NULL); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6535 | return error::kNoError; |
| 6536 | } |
| 6537 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6538 | error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6539 | uint32 immediate_data_size, const cmds::GetProgramInfoLog& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6540 | GLuint program_id = c.program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6541 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6542 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6543 | Program* program = GetProgramInfoNotShader( |
| 6544 | program_id, "glGetProgramInfoLog"); |
| 6545 | if (!program || !program->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 6546 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6547 | return error::kNoError; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6548 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6549 | bucket->SetFromString(program->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6550 | return error::kNoError; |
| 6551 | } |
| 6552 | |
| 6553 | error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6554 | uint32 immediate_data_size, const cmds::GetShaderInfoLog& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6555 | GLuint shader_id = c.shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6556 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6557 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6558 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderInfoLog"); |
| 6559 | if (!shader || !shader->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 6560 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6561 | return error::kNoError; |
| 6562 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6563 | bucket->SetFromString(shader->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6564 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6565 | } |
| 6566 | |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 6567 | bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) { |
| 6568 | return state_.GetEnabled(cap); |
| 6569 | } |
| 6570 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6571 | bool GLES2DecoderImpl::DoIsBuffer(GLuint client_id) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 6572 | const Buffer* buffer = GetBuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6573 | return buffer && buffer->IsValid() && !buffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6574 | } |
| 6575 | |
| 6576 | bool GLES2DecoderImpl::DoIsFramebuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6577 | const Framebuffer* framebuffer = |
| 6578 | GetFramebuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6579 | return framebuffer && framebuffer->IsValid() && !framebuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6580 | } |
| 6581 | |
| 6582 | bool GLES2DecoderImpl::DoIsProgram(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 6583 | // IsProgram is true for programs as soon as they are created, until they are |
| 6584 | // deleted and no longer in use. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6585 | const Program* program = GetProgram(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6586 | return program != NULL && !program->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6587 | } |
| 6588 | |
| 6589 | bool GLES2DecoderImpl::DoIsRenderbuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6590 | const Renderbuffer* renderbuffer = |
| 6591 | GetRenderbuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6592 | return renderbuffer && renderbuffer->IsValid() && !renderbuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6593 | } |
| 6594 | |
| 6595 | bool GLES2DecoderImpl::DoIsShader(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 6596 | // IsShader is true for shaders as soon as they are created, until they |
| 6597 | // are deleted and not attached to any programs. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6598 | const Shader* shader = GetShader(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6599 | return shader != NULL && !shader->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6600 | } |
| 6601 | |
| 6602 | bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6603 | const TextureRef* texture_ref = GetTexture(client_id); |
| 6604 | return texture_ref && texture_ref->texture()->IsValid(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6605 | } |
| 6606 | |
| 6607 | void GLES2DecoderImpl::DoAttachShader( |
| 6608 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6609 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6610 | program_client_id, "glAttachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6611 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6612 | return; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6613 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6614 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glAttachShader"); |
| 6615 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6616 | return; |
| 6617 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6618 | if (!program->AttachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6619 | LOCAL_SET_GL_ERROR( |
| 6620 | GL_INVALID_OPERATION, |
| 6621 | "glAttachShader", |
| 6622 | "can not attach more than one shader of the same type."); |
[email protected] | fb96c8e | 2010-08-12 04:10:31 | [diff] [blame] | 6623 | return; |
| 6624 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6625 | glAttachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6626 | } |
| 6627 | |
| 6628 | void GLES2DecoderImpl::DoDetachShader( |
| 6629 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6630 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6631 | program_client_id, "glDetachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6632 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6633 | return; |
| 6634 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6635 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glDetachShader"); |
| 6636 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6637 | return; |
| 6638 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6639 | if (!program->DetachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6640 | LOCAL_SET_GL_ERROR( |
| 6641 | GL_INVALID_OPERATION, |
| 6642 | "glDetachShader", "shader not attached to program"); |
[email protected] | 9a0ccd4 | 2011-03-16 23:58:22 | [diff] [blame] | 6643 | return; |
| 6644 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6645 | glDetachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6646 | } |
| 6647 | |
| 6648 | void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6649 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6650 | program_client_id, "glValidateProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6651 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6652 | return; |
| 6653 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6654 | program->Validate(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6655 | } |
| 6656 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6657 | void GLES2DecoderImpl::GetVertexAttribHelper( |
| 6658 | const VertexAttrib* attrib, GLenum pname, GLint* params) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6659 | switch (pname) { |
| 6660 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6661 | Buffer* buffer = attrib->buffer(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6662 | if (buffer && !buffer->IsDeleted()) { |
| 6663 | GLuint client_id; |
| 6664 | buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
| 6665 | *params = client_id; |
| 6666 | } |
| 6667 | break; |
| 6668 | } |
| 6669 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6670 | *params = attrib->enabled(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6671 | break; |
| 6672 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6673 | *params = attrib->size(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6674 | break; |
| 6675 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6676 | *params = attrib->gl_stride(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6677 | break; |
| 6678 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6679 | *params = attrib->type(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6680 | break; |
| 6681 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6682 | *params = attrib->normalized(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6683 | break; |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6684 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6685 | *params = attrib->divisor(); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6686 | break; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6687 | default: |
| 6688 | NOTREACHED(); |
| 6689 | break; |
| 6690 | } |
| 6691 | } |
| 6692 | |
| 6693 | void GLES2DecoderImpl::DoGetVertexAttribfv( |
| 6694 | GLuint index, GLenum pname, GLfloat* params) { |
| 6695 | VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| 6696 | if (!attrib) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6697 | LOCAL_SET_GL_ERROR( |
| 6698 | GL_INVALID_VALUE, "glGetVertexAttribfv", "index out of range"); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6699 | return; |
| 6700 | } |
| 6701 | switch (pname) { |
| 6702 | case GL_CURRENT_VERTEX_ATTRIB: { |
| 6703 | const Vec4& value = state_.attrib_values[index]; |
| 6704 | params[0] = value.v[0]; |
| 6705 | params[1] = value.v[1]; |
| 6706 | params[2] = value.v[2]; |
| 6707 | params[3] = value.v[3]; |
| 6708 | break; |
| 6709 | } |
| 6710 | default: { |
| 6711 | GLint value = 0; |
| 6712 | GetVertexAttribHelper(attrib, pname, &value); |
| 6713 | *params = static_cast<GLfloat>(value); |
| 6714 | break; |
| 6715 | } |
| 6716 | } |
| 6717 | } |
| 6718 | |
| 6719 | void GLES2DecoderImpl::DoGetVertexAttribiv( |
| 6720 | GLuint index, GLenum pname, GLint* params) { |
| 6721 | VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| 6722 | if (!attrib) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6723 | LOCAL_SET_GL_ERROR( |
| 6724 | GL_INVALID_VALUE, "glGetVertexAttribiv", "index out of range"); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6725 | return; |
| 6726 | } |
| 6727 | switch (pname) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6728 | case GL_CURRENT_VERTEX_ATTRIB: { |
| 6729 | const Vec4& value = state_.attrib_values[index]; |
| 6730 | params[0] = static_cast<GLint>(value.v[0]); |
| 6731 | params[1] = static_cast<GLint>(value.v[1]); |
| 6732 | params[2] = static_cast<GLint>(value.v[2]); |
| 6733 | params[3] = static_cast<GLint>(value.v[3]); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6734 | break; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6735 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6736 | default: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6737 | GetVertexAttribHelper(attrib, pname, params); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6738 | break; |
| 6739 | } |
| 6740 | } |
| 6741 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6742 | bool GLES2DecoderImpl::SetVertexAttribValue( |
| 6743 | const char* function_name, GLuint index, const GLfloat* value) { |
| 6744 | if (index >= state_.attrib_values.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6745 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "index out of range"); |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6746 | return false; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6747 | } |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6748 | Vec4& v = state_.attrib_values[index]; |
| 6749 | v.v[0] = value[0]; |
| 6750 | v.v[1] = value[1]; |
| 6751 | v.v[2] = value[2]; |
| 6752 | v.v[3] = value[3]; |
| 6753 | return true; |
| 6754 | } |
| 6755 | |
| 6756 | void GLES2DecoderImpl::DoVertexAttrib1f(GLuint index, GLfloat v0) { |
| 6757 | GLfloat v[4] = { v0, 0.0f, 0.0f, 1.0f, }; |
| 6758 | if (SetVertexAttribValue("glVertexAttrib1f", index, v)) { |
| 6759 | glVertexAttrib1f(index, v0); |
| 6760 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6761 | } |
| 6762 | |
| 6763 | void GLES2DecoderImpl::DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6764 | GLfloat v[4] = { v0, v1, 0.0f, 1.0f, }; |
| 6765 | if (SetVertexAttribValue("glVertexAttrib2f", index, v)) { |
| 6766 | glVertexAttrib2f(index, v0, v1); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6767 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6768 | } |
| 6769 | |
| 6770 | void GLES2DecoderImpl::DoVertexAttrib3f( |
| 6771 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6772 | GLfloat v[4] = { v0, v1, v2, 1.0f, }; |
| 6773 | if (SetVertexAttribValue("glVertexAttrib3f", index, v)) { |
| 6774 | glVertexAttrib3f(index, v0, v1, v2); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6775 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6776 | } |
| 6777 | |
| 6778 | void GLES2DecoderImpl::DoVertexAttrib4f( |
| 6779 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6780 | GLfloat v[4] = { v0, v1, v2, v3, }; |
| 6781 | if (SetVertexAttribValue("glVertexAttrib4f", index, v)) { |
| 6782 | glVertexAttrib4f(index, v0, v1, v2, v3); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6783 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6784 | } |
| 6785 | |
| 6786 | void GLES2DecoderImpl::DoVertexAttrib1fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6787 | GLfloat t[4] = { v[0], 0.0f, 0.0f, 1.0f, }; |
| 6788 | if (SetVertexAttribValue("glVertexAttrib1fv", index, t)) { |
| 6789 | glVertexAttrib1fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6790 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6791 | } |
| 6792 | |
| 6793 | void GLES2DecoderImpl::DoVertexAttrib2fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6794 | GLfloat t[4] = { v[0], v[1], 0.0f, 1.0f, }; |
| 6795 | if (SetVertexAttribValue("glVertexAttrib2fv", index, t)) { |
| 6796 | glVertexAttrib2fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6797 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6798 | } |
| 6799 | |
| 6800 | void GLES2DecoderImpl::DoVertexAttrib3fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6801 | GLfloat t[4] = { v[0], v[1], v[2], 1.0f, }; |
| 6802 | if (SetVertexAttribValue("glVertexAttrib3fv", index, t)) { |
| 6803 | glVertexAttrib3fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6804 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6805 | } |
| 6806 | |
| 6807 | void GLES2DecoderImpl::DoVertexAttrib4fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6808 | if (SetVertexAttribValue("glVertexAttrib4fv", index, v)) { |
| 6809 | glVertexAttrib4fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6810 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6811 | } |
| 6812 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6813 | error::Error GLES2DecoderImpl::HandleVertexAttribPointer( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6814 | uint32 immediate_data_size, const cmds::VertexAttribPointer& c) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 6815 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6816 | if (!state_.bound_array_buffer.get() || |
| 6817 | state_.bound_array_buffer->IsDeleted()) { |
| 6818 | if (state_.vertex_attrib_manager.get() == |
| 6819 | default_vertex_attrib_manager_.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6820 | LOCAL_SET_GL_ERROR( |
| 6821 | GL_INVALID_VALUE, "glVertexAttribPointer", "no array buffer bound"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 6822 | return error::kNoError; |
| 6823 | } else if (c.offset != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6824 | LOCAL_SET_GL_ERROR( |
| 6825 | GL_INVALID_VALUE, |
| 6826 | "glVertexAttribPointer", "client side arrays are not allowed"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 6827 | return error::kNoError; |
| 6828 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6829 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6830 | |
| 6831 | GLuint indx = c.indx; |
| 6832 | GLint size = c.size; |
| 6833 | GLenum type = c.type; |
| 6834 | GLboolean normalized = c.normalized; |
| 6835 | GLsizei stride = c.stride; |
| 6836 | GLsizei offset = c.offset; |
| 6837 | const void* ptr = reinterpret_cast<const void*>(offset); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6838 | if (!validators_->vertex_attrib_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6839 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glVertexAttribPointer", type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6840 | return error::kNoError; |
| 6841 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6842 | if (!validators_->vertex_attrib_size.IsValid(size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6843 | LOCAL_SET_GL_ERROR( |
| 6844 | GL_INVALID_VALUE, "glVertexAttribPointer", "size GL_INVALID_VALUE"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6845 | return error::kNoError; |
| 6846 | } |
| 6847 | if (indx >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6848 | LOCAL_SET_GL_ERROR( |
| 6849 | GL_INVALID_VALUE, "glVertexAttribPointer", "index out of range"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6850 | return error::kNoError; |
| 6851 | } |
| 6852 | if (stride < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6853 | LOCAL_SET_GL_ERROR( |
| 6854 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6855 | return error::kNoError; |
| 6856 | } |
| 6857 | if (stride > 255) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6858 | LOCAL_SET_GL_ERROR( |
| 6859 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride > 255"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6860 | return error::kNoError; |
| 6861 | } |
| 6862 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6863 | LOCAL_SET_GL_ERROR( |
| 6864 | GL_INVALID_VALUE, "glVertexAttribPointer", "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6865 | return error::kNoError; |
| 6866 | } |
| 6867 | GLsizei component_size = |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 6868 | GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6869 | if (offset % component_size > 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6870 | LOCAL_SET_GL_ERROR( |
| 6871 | GL_INVALID_OPERATION, |
| 6872 | "glVertexAttribPointer", "offset not valid for type"); |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 6873 | return error::kNoError; |
| 6874 | } |
| 6875 | if (stride % component_size > 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6876 | LOCAL_SET_GL_ERROR( |
| 6877 | GL_INVALID_OPERATION, |
| 6878 | "glVertexAttribPointer", "stride not valid for type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6879 | return error::kNoError; |
| 6880 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6881 | state_.vertex_attrib_manager |
| 6882 | ->SetAttribInfo(indx, |
| 6883 | state_.bound_array_buffer.get(), |
| 6884 | size, |
| 6885 | type, |
| 6886 | normalized, |
| 6887 | stride, |
| 6888 | stride != 0 ? stride : component_size * size, |
| 6889 | offset); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6890 | if (type != GL_FIXED) { |
| 6891 | glVertexAttribPointer(indx, size, type, normalized, stride, ptr); |
| 6892 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6893 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6894 | } |
| 6895 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6896 | void GLES2DecoderImpl::DoViewport(GLint x, GLint y, GLsizei width, |
| 6897 | GLsizei height) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6898 | state_.viewport_x = x; |
| 6899 | state_.viewport_y = y; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6900 | state_.viewport_width = std::min(width, viewport_max_width_); |
| 6901 | state_.viewport_height = std::min(height, viewport_max_height_); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6902 | glViewport(x, y, width, height); |
| 6903 | } |
| 6904 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6905 | error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6906 | uint32 immediate_data_size, const cmds::VertexAttribDivisorANGLE& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6907 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6908 | LOCAL_SET_GL_ERROR( |
| 6909 | GL_INVALID_OPERATION, |
| 6910 | "glVertexAttribDivisorANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6911 | } |
| 6912 | GLuint index = c.index; |
| 6913 | GLuint divisor = c.divisor; |
| 6914 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6915 | LOCAL_SET_GL_ERROR( |
| 6916 | GL_INVALID_VALUE, |
| 6917 | "glVertexAttribDivisorANGLE", "index out of range"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6918 | return error::kNoError; |
| 6919 | } |
| 6920 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6921 | state_.vertex_attrib_manager->SetDivisor( |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6922 | index, |
| 6923 | divisor); |
| 6924 | glVertexAttribDivisorANGLE(index, divisor); |
| 6925 | return error::kNoError; |
| 6926 | } |
| 6927 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 6928 | void GLES2DecoderImpl::FinishReadPixels( |
| 6929 | const cmds::ReadPixels& c, |
| 6930 | GLuint buffer) { |
| 6931 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::FinishReadPixels"); |
| 6932 | GLsizei width = c.width; |
| 6933 | GLsizei height = c.height; |
| 6934 | GLenum format = c.format; |
| 6935 | GLenum type = c.type; |
| 6936 | typedef cmds::ReadPixels::Result Result; |
| 6937 | uint32 pixels_size; |
| 6938 | Result* result = NULL; |
| 6939 | if (c.result_shm_id != 0) { |
| 6940 | result = GetSharedMemoryAs<Result*>( |
| 6941 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 6942 | if (!result) { |
| 6943 | if (buffer != 0) { |
| 6944 | glDeleteBuffersARB(1, &buffer); |
| 6945 | } |
| 6946 | return; |
| 6947 | } |
| 6948 | } |
| 6949 | GLES2Util::ComputeImageDataSizes( |
| 6950 | width, height, format, type, state_.pack_alignment, &pixels_size, |
| 6951 | NULL, NULL); |
| 6952 | void* pixels = GetSharedMemoryAs<void*>( |
| 6953 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| 6954 | if (!pixels) { |
| 6955 | if (buffer != 0) { |
| 6956 | glDeleteBuffersARB(1, &buffer); |
| 6957 | } |
| 6958 | return; |
| 6959 | } |
| 6960 | |
| 6961 | if (buffer != 0) { |
| 6962 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
[email protected] | e585f9e2 | 2013-08-27 02:50:33 | [diff] [blame] | 6963 | void* data; |
| 6964 | if (features().map_buffer_range) { |
| 6965 | data = glMapBufferRange( |
| 6966 | GL_PIXEL_PACK_BUFFER_ARB, 0, pixels_size, GL_MAP_READ_BIT); |
| 6967 | } else { |
| 6968 | data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); |
| 6969 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 6970 | memcpy(pixels, data, pixels_size); |
| 6971 | // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't |
| 6972 | // have to restore the state. |
| 6973 | glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); |
| 6974 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 6975 | glDeleteBuffersARB(1, &buffer); |
| 6976 | } |
| 6977 | |
| 6978 | if (result != NULL) { |
| 6979 | *result = true; |
| 6980 | } |
| 6981 | |
| 6982 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 6983 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 6984 | if ((channels_exist & 0x0008) == 0 && |
| 6985 | workarounds().clear_alpha_in_readpixels) { |
| 6986 | // Set the alpha to 255 because some drivers are buggy in this regard. |
| 6987 | uint32 temp_size; |
| 6988 | |
| 6989 | uint32 unpadded_row_size; |
| 6990 | uint32 padded_row_size; |
| 6991 | if (!GLES2Util::ComputeImageDataSizes( |
| 6992 | width, 2, format, type, state_.pack_alignment, &temp_size, |
| 6993 | &unpadded_row_size, &padded_row_size)) { |
| 6994 | return; |
| 6995 | } |
| 6996 | // NOTE: Assumes the type is GL_UNSIGNED_BYTE which was true at the time |
| 6997 | // of this implementation. |
| 6998 | if (type != GL_UNSIGNED_BYTE) { |
| 6999 | return; |
| 7000 | } |
| 7001 | switch (format) { |
| 7002 | case GL_RGBA: |
| 7003 | case GL_BGRA_EXT: |
| 7004 | case GL_ALPHA: { |
| 7005 | int offset = (format == GL_ALPHA) ? 0 : 3; |
| 7006 | int step = (format == GL_ALPHA) ? 1 : 4; |
| 7007 | uint8* dst = static_cast<uint8*>(pixels) + offset; |
| 7008 | for (GLint yy = 0; yy < height; ++yy) { |
| 7009 | uint8* end = dst + unpadded_row_size; |
| 7010 | for (uint8* d = dst; d < end; d += step) { |
| 7011 | *d = 255; |
| 7012 | } |
| 7013 | dst += padded_row_size; |
| 7014 | } |
| 7015 | break; |
| 7016 | } |
| 7017 | default: |
| 7018 | break; |
| 7019 | } |
| 7020 | } |
| 7021 | } |
| 7022 | |
| 7023 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7024 | error::Error GLES2DecoderImpl::HandleReadPixels( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7025 | uint32 immediate_data_size, const cmds::ReadPixels& c) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 7026 | if (ShouldDeferReads()) |
| 7027 | return error::kDeferCommandUntilLater; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7028 | GLint x = c.x; |
| 7029 | GLint y = c.y; |
| 7030 | GLsizei width = c.width; |
| 7031 | GLsizei height = c.height; |
| 7032 | GLenum format = c.format; |
| 7033 | GLenum type = c.type; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7034 | GLboolean async = c.async; |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7035 | if (width < 0 || height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7036 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7037 | return error::kNoError; |
| 7038 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7039 | typedef cmds::ReadPixels::Result Result; |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7040 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7041 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7042 | width, height, format, type, state_.pack_alignment, &pixels_size, |
| 7043 | NULL, NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7044 | return error::kOutOfBounds; |
| 7045 | } |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7046 | void* pixels = GetSharedMemoryAs<void*>( |
| 7047 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7048 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7049 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7050 | } |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7051 | Result* result = NULL; |
| 7052 | if (c.result_shm_id != 0) { |
| 7053 | result = GetSharedMemoryAs<Result*>( |
| 7054 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7055 | if (!result) { |
| 7056 | return error::kOutOfBounds; |
| 7057 | } |
| 7058 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7059 | |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7060 | if (!validators_->read_pixel_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7061 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", format, "format"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7062 | return error::kNoError; |
| 7063 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7064 | if (!validators_->pixel_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7065 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", type, "type"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 7066 | return error::kNoError; |
| 7067 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7068 | if (width == 0 || height == 0) { |
| 7069 | return error::kNoError; |
| 7070 | } |
| 7071 | |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7072 | // Get the size of the current fbo or backbuffer. |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 7073 | gfx::Size max_size = GetBoundReadFrameBufferSize(); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7074 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 7075 | int32 max_x; |
| 7076 | int32 max_y; |
| 7077 | if (!SafeAddInt32(x, width, &max_x) || !SafeAddInt32(y, height, &max_y)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7078 | LOCAL_SET_GL_ERROR( |
| 7079 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7080 | return error::kNoError; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7081 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7082 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7083 | if (!CheckBoundFramebuffersValid("glReadPixels")) { |
| 7084 | return error::kNoError; |
| 7085 | } |
| 7086 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7087 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixel"); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7088 | |
| 7089 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 7090 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7091 | 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] | 7092 | // The user requested an out of range area. Get the results 1 line |
| 7093 | // at a time. |
| 7094 | uint32 temp_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7095 | uint32 unpadded_row_size; |
| 7096 | uint32 padded_row_size; |
| 7097 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7098 | width, 2, format, type, state_.pack_alignment, &temp_size, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7099 | &unpadded_row_size, &padded_row_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7100 | LOCAL_SET_GL_ERROR( |
| 7101 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7102 | return error::kNoError; |
| 7103 | } |
| 7104 | |
| 7105 | GLint dest_x_offset = std::max(-x, 0); |
| 7106 | uint32 dest_row_offset; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7107 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7108 | dest_x_offset, 1, format, type, state_.pack_alignment, &dest_row_offset, |
| 7109 | NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7110 | LOCAL_SET_GL_ERROR( |
| 7111 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7112 | return error::kNoError; |
| 7113 | } |
| 7114 | |
| 7115 | // Copy each row into the larger dest rect. |
| 7116 | int8* dst = static_cast<int8*>(pixels); |
| 7117 | GLint read_x = std::max(0, x); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7118 | 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] | 7119 | GLint read_width = read_end_x - read_x; |
| 7120 | for (GLint yy = 0; yy < height; ++yy) { |
| 7121 | GLint ry = y + yy; |
| 7122 | |
| 7123 | // Clear the row. |
| 7124 | memset(dst, 0, unpadded_row_size); |
| 7125 | |
| 7126 | // If the row is in range, copy it. |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7127 | if (ry >= 0 && ry < max_size.height() && read_width > 0) { |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7128 | glReadPixels( |
| 7129 | read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
| 7130 | } |
| 7131 | dst += padded_row_size; |
| 7132 | } |
| 7133 | } else { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7134 | if (async && features().use_async_readpixels) { |
| 7135 | GLuint buffer; |
| 7136 | glGenBuffersARB(1, &buffer); |
| 7137 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
| 7138 | glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, GL_STREAM_READ); |
| 7139 | GLenum error = glGetError(); |
| 7140 | if (error == GL_NO_ERROR) { |
| 7141 | glReadPixels(x, y, width, height, format, type, 0); |
| 7142 | pending_readpixel_fences_.push(linked_ptr<FenceCallback>( |
| 7143 | new FenceCallback())); |
| 7144 | WaitForReadPixels(base::Bind( |
| 7145 | &GLES2DecoderImpl::FinishReadPixels, |
| 7146 | base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 7147 | <GLES2DecoderImpl>(this), |
| 7148 | c, buffer)); |
| 7149 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7150 | return error::kNoError; |
| 7151 | } |
| 7152 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7153 | glReadPixels(x, y, width, height, format, type, pixels); |
| 7154 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7155 | GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7156 | if (error == GL_NO_ERROR) { |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7157 | if (result != NULL) { |
| 7158 | *result = true; |
| 7159 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7160 | FinishReadPixels(c, 0); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7161 | } |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 7162 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7163 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7164 | } |
| 7165 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7166 | error::Error GLES2DecoderImpl::HandlePixelStorei( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7167 | uint32 immediate_data_size, const cmds::PixelStorei& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7168 | GLenum pname = c.pname; |
| 7169 | GLenum param = c.param; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7170 | if (!validators_->pixel_store.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7171 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glPixelStorei", pname, "pname"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 7172 | return error::kNoError; |
| 7173 | } |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7174 | switch (pname) { |
| 7175 | case GL_PACK_ALIGNMENT: |
| 7176 | case GL_UNPACK_ALIGNMENT: |
| 7177 | if (!validators_->pixel_store_alignment.IsValid(param)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7178 | LOCAL_SET_GL_ERROR( |
| 7179 | GL_INVALID_VALUE, "glPixelStore", "param GL_INVALID_VALUE"); |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7180 | return error::kNoError; |
| 7181 | } |
[email protected] | 164d6d5 | 2012-05-05 00:55:03 | [diff] [blame] | 7182 | break; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 7183 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 7184 | unpack_flip_y_ = (param != 0); |
| 7185 | return error::kNoError; |
| 7186 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 7187 | unpack_premultiply_alpha_ = (param != 0); |
| 7188 | return error::kNoError; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 7189 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 7190 | unpack_unpremultiply_alpha_ = (param != 0); |
| 7191 | return error::kNoError; |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7192 | default: |
| 7193 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7194 | } |
| 7195 | glPixelStorei(pname, param); |
| 7196 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7197 | case GL_PACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7198 | state_.pack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7199 | break; |
| 7200 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 7201 | state_.pack_reverse_row_order = (param != 0); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7202 | break; |
| 7203 | case GL_UNPACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7204 | state_.unpack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7205 | break; |
| 7206 | default: |
| 7207 | // Validation should have prevented us from getting here. |
| 7208 | NOTREACHED(); |
| 7209 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7210 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7211 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7212 | } |
| 7213 | |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7214 | error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7215 | uint32 immediate_data_size, const cmds::PostSubBufferCHROMIUM& c) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 7216 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandlePostSubBufferCHROMIUM"); |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 7217 | if (!surface_->HasExtension("GL_CHROMIUM_post_sub_buffer")) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7218 | LOCAL_SET_GL_ERROR( |
| 7219 | GL_INVALID_OPERATION, |
| 7220 | "glPostSubBufferCHROMIUM", "command not supported by surface"); |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7221 | return error::kNoError; |
| 7222 | } |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 7223 | bool is_tracing; |
| 7224 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 7225 | &is_tracing); |
| 7226 | if (is_tracing) { |
| 7227 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 7228 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 7229 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 7230 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 7231 | } |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 7232 | if (surface_->PostSubBuffer(c.x, c.y, c.width, c.height)) { |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7233 | return error::kNoError; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 7234 | } else { |
| 7235 | LOG(ERROR) << "Context lost because PostSubBuffer failed."; |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7236 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 7237 | } |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7238 | } |
| 7239 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7240 | error::Error GLES2DecoderImpl::GetAttribLocationHelper( |
| 7241 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 7242 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7243 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7244 | LOCAL_SET_GL_ERROR( |
| 7245 | GL_INVALID_VALUE, "glGetAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7246 | return error::kNoError; |
| 7247 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7248 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7249 | client_id, "glGetAttribLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7250 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7251 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7252 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7253 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7254 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7255 | GL_INVALID_OPERATION, "glGetAttribLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7256 | return error::kNoError; |
| 7257 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7258 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7259 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 7260 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7261 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7262 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7263 | // Require the client to init this incase the context is lost and we are no |
| 7264 | // longer executing commands. |
| 7265 | if (*location != -1) { |
| 7266 | return error::kGenericError; |
| 7267 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7268 | *location = program->GetAttribLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7269 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7270 | } |
| 7271 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7272 | error::Error GLES2DecoderImpl::HandleGetAttribLocation( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7273 | uint32 immediate_data_size, const cmds::GetAttribLocation& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7274 | uint32 name_size = c.data_size; |
| 7275 | const char* name = GetSharedMemoryAs<const char*>( |
| 7276 | c.name_shm_id, c.name_shm_offset, name_size); |
| 7277 | if (!name) { |
| 7278 | return error::kOutOfBounds; |
| 7279 | } |
| 7280 | String name_str(name, name_size); |
| 7281 | return GetAttribLocationHelper( |
| 7282 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 7283 | } |
| 7284 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7285 | error::Error GLES2DecoderImpl::HandleGetAttribLocationBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7286 | uint32 immediate_data_size, const cmds::GetAttribLocationBucket& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7287 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 7288 | if (!bucket) { |
| 7289 | return error::kInvalidArguments; |
| 7290 | } |
| 7291 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7292 | if (!bucket->GetAsString(&name_str)) { |
| 7293 | return error::kInvalidArguments; |
| 7294 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7295 | return GetAttribLocationHelper( |
| 7296 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 7297 | } |
| 7298 | |
| 7299 | error::Error GLES2DecoderImpl::GetUniformLocationHelper( |
| 7300 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 7301 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7302 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7303 | LOCAL_SET_GL_ERROR( |
| 7304 | GL_INVALID_VALUE, "glGetUniformLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7305 | return error::kNoError; |
| 7306 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7307 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7308 | client_id, "glUniformLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7309 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7310 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7311 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7312 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7313 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7314 | GL_INVALID_OPERATION, "glGetUniformLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7315 | return error::kNoError; |
| 7316 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7317 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7318 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 7319 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7320 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7321 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7322 | // Require the client to init this incase the context is lost an we are no |
| 7323 | // longer executing commands. |
| 7324 | if (*location != -1) { |
| 7325 | return error::kGenericError; |
| 7326 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7327 | *location = program->GetUniformFakeLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7328 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7329 | } |
| 7330 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7331 | error::Error GLES2DecoderImpl::HandleGetUniformLocation( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7332 | uint32 immediate_data_size, const cmds::GetUniformLocation& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7333 | uint32 name_size = c.data_size; |
| 7334 | const char* name = GetSharedMemoryAs<const char*>( |
| 7335 | c.name_shm_id, c.name_shm_offset, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7336 | if (!name) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7337 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7338 | } |
| 7339 | String name_str(name, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7340 | return GetUniformLocationHelper( |
| 7341 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7342 | } |
| 7343 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7344 | error::Error GLES2DecoderImpl::HandleGetUniformLocationBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7345 | uint32 immediate_data_size, const cmds::GetUniformLocationBucket& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7346 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 7347 | if (!bucket) { |
| 7348 | return error::kInvalidArguments; |
| 7349 | } |
| 7350 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7351 | if (!bucket->GetAsString(&name_str)) { |
| 7352 | return error::kInvalidArguments; |
| 7353 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7354 | return GetUniformLocationHelper( |
| 7355 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7356 | } |
| 7357 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7358 | error::Error GLES2DecoderImpl::HandleGetString( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7359 | uint32 immediate_data_size, const cmds::GetString& c) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7360 | GLenum name = static_cast<GLenum>(c.name); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7361 | if (!validators_->string_type.IsValid(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7362 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glGetString", name, "name"); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7363 | return error::kNoError; |
| 7364 | } |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 7365 | const char* str = reinterpret_cast<const char*>(glGetString(name)); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7366 | std::string extensions; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7367 | switch (name) { |
| 7368 | case GL_VERSION: |
| 7369 | str = "OpenGL ES 2.0 Chromium"; |
| 7370 | break; |
| 7371 | case GL_SHADING_LANGUAGE_VERSION: |
| 7372 | str = "OpenGL ES GLSL ES 1.0 Chromium"; |
| 7373 | break; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 7374 | case GL_RENDERER: |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 7375 | case GL_VENDOR: |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 7376 | // Return the unmasked VENDOR/RENDERER string for WebGL contexts. |
| 7377 | // They are used by WEBGL_debug_renderer_info. |
| 7378 | if (!force_webgl_glsl_validation_) |
| 7379 | str = "Chromium"; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 7380 | break; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7381 | case GL_EXTENSIONS: |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7382 | { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7383 | // For WebGL contexts, strip out the OES derivatives and |
| 7384 | // EXT frag depth extensions if they have not been enabled. |
| 7385 | if (force_webgl_glsl_validation_) { |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7386 | extensions = feature_info_->extensions(); |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7387 | if (!derivatives_explicitly_enabled_) { |
| 7388 | size_t offset = extensions.find(kOESDerivativeExtension); |
| 7389 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 7390 | extensions.replace(offset, arraysize(kOESDerivativeExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7391 | std::string()); |
| 7392 | } |
| 7393 | } |
| 7394 | if (!frag_depth_explicitly_enabled_) { |
| 7395 | size_t offset = extensions.find(kEXTFragDepthExtension); |
| 7396 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 7397 | extensions.replace(offset, arraysize(kEXTFragDepthExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7398 | std::string()); |
| 7399 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7400 | } |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 7401 | if (!draw_buffers_explicitly_enabled_) { |
| 7402 | size_t offset = extensions.find(kEXTDrawBuffersExtension); |
| 7403 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 7404 | extensions.replace(offset, arraysize(kEXTDrawBuffersExtension), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 7405 | std::string()); |
| 7406 | } |
| 7407 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7408 | } else { |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 7409 | extensions = feature_info_->extensions().c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7410 | } |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 7411 | std::string surface_extensions = surface_->GetExtensions(); |
| 7412 | if (!surface_extensions.empty()) |
| 7413 | extensions += " " + surface_extensions; |
| 7414 | str = extensions.c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7415 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7416 | break; |
| 7417 | default: |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7418 | break; |
| 7419 | } |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7420 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7421 | bucket->SetFromString(str); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7422 | return error::kNoError; |
| 7423 | } |
| 7424 | |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 7425 | error::Error GLES2DecoderImpl::HandleBufferData( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7426 | uint32 immediate_data_size, const cmds::BufferData& c) { |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 7427 | GLenum target = static_cast<GLenum>(c.target); |
| 7428 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
| 7429 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 7430 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 7431 | GLenum usage = static_cast<GLenum>(c.usage); |
| 7432 | const void* data = NULL; |
| 7433 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 7434 | data = GetSharedMemoryAs<const void*>(data_shm_id, data_shm_offset, size); |
| 7435 | if (!data) { |
| 7436 | return error::kOutOfBounds; |
| 7437 | } |
| 7438 | } |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 7439 | buffer_manager()->ValidateAndDoBufferData(&state_, target, size, data, usage); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7440 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7441 | } |
| 7442 | |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 7443 | void GLES2DecoderImpl::DoBufferSubData( |
| 7444 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 7445 | // Just delegate it. Some validation is actually done before this. |
| 7446 | buffer_manager()->ValidateAndDoBufferSubData( |
| 7447 | &state_, target, offset, size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7448 | } |
| 7449 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7450 | bool GLES2DecoderImpl::ClearLevel( |
| 7451 | unsigned service_id, |
| 7452 | unsigned bind_target, |
| 7453 | unsigned target, |
| 7454 | int level, |
| 7455 | unsigned format, |
| 7456 | unsigned type, |
| 7457 | int width, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7458 | int height, |
| 7459 | bool is_texture_immutable) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7460 | uint32 channels = GLES2Util::GetChannelsForFormat(format); |
| 7461 | if (IsAngle() && (channels & GLES2Util::kDepth) != 0) { |
| 7462 | // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D |
| 7463 | // on depth formats. |
| 7464 | GLuint fb = 0; |
| 7465 | glGenFramebuffersEXT(1, &fb); |
| 7466 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); |
| 7467 | |
| 7468 | bool have_stencil = (channels & GLES2Util::kStencil) != 0; |
| 7469 | GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : |
| 7470 | GL_DEPTH_ATTACHMENT; |
| 7471 | |
| 7472 | glFramebufferTexture2DEXT( |
| 7473 | GL_DRAW_FRAMEBUFFER_EXT, attachment, target, service_id, level); |
| 7474 | // ANGLE promises a depth only attachment ok. |
| 7475 | if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != |
| 7476 | GL_FRAMEBUFFER_COMPLETE) { |
| 7477 | return false; |
| 7478 | } |
| 7479 | glClearStencil(0); |
| 7480 | glStencilMask(-1); |
| 7481 | glClearDepth(1.0f); |
| 7482 | glDepthMask(true); |
| 7483 | glDisable(GL_SCISSOR_TEST); |
| 7484 | glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); |
| 7485 | |
| 7486 | RestoreClearState(); |
| 7487 | |
| 7488 | glDeleteFramebuffersEXT(1, &fb); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7489 | Framebuffer* framebuffer = |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7490 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 7491 | GLuint fb_service_id = |
| 7492 | framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); |
| 7493 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); |
| 7494 | return true; |
| 7495 | } |
| 7496 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7497 | static const uint32 kMaxZeroSize = 1024 * 1024 * 4; |
| 7498 | |
| 7499 | uint32 size; |
| 7500 | uint32 padded_row_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7501 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7502 | width, height, format, type, state_.unpack_alignment, &size, |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7503 | NULL, &padded_row_size)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7504 | return false; |
| 7505 | } |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7506 | |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 7507 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearLevel", "size", size); |
| 7508 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7509 | int tile_height; |
| 7510 | |
| 7511 | if (size > kMaxZeroSize) { |
| 7512 | if (kMaxZeroSize < padded_row_size) { |
| 7513 | // That'd be an awfully large texture. |
| 7514 | return false; |
| 7515 | } |
| 7516 | // We should never have a large total size with a zero row size. |
| 7517 | DCHECK_GT(padded_row_size, 0U); |
| 7518 | tile_height = kMaxZeroSize / padded_row_size; |
| 7519 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7520 | width, tile_height, format, type, state_.unpack_alignment, &size, |
| 7521 | NULL, NULL)) { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7522 | return false; |
| 7523 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7524 | } else { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7525 | tile_height = height; |
| 7526 | } |
| 7527 | |
| 7528 | // Assumes the size has already been checked. |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 7529 | scoped_ptr<char[]> zero(new char[size]); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7530 | memset(zero.get(), 0, size); |
| 7531 | glBindTexture(bind_target, service_id); |
| 7532 | |
| 7533 | GLint y = 0; |
| 7534 | while (y < height) { |
| 7535 | GLint h = y + tile_height > height ? height - y : tile_height; |
| 7536 | if (is_texture_immutable || h != height) { |
| 7537 | glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); |
| 7538 | } else { |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 7539 | glTexImage2D( |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7540 | target, level, format, width, h, 0, format, type, zero.get()); |
| 7541 | } |
| 7542 | y += tile_height; |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7543 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7544 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 7545 | &state_, bind_target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 7546 | glBindTexture(bind_target, texture ? texture->service_id() : 0); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7547 | return true; |
| 7548 | } |
| 7549 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7550 | namespace { |
| 7551 | |
| 7552 | const int kS3TCBlockWidth = 4; |
| 7553 | const int kS3TCBlockHeight = 4; |
| 7554 | const int kS3TCDXT1BlockSize = 8; |
| 7555 | const int kS3TCDXT3AndDXT5BlockSize = 16; |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7556 | const int kETC1BlockWidth = 4; |
| 7557 | const int kETC1BlockHeight = 4; |
| 7558 | const int kETC1BlockSize = 8; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7559 | |
| 7560 | bool IsValidDXTSize(GLint level, GLsizei size) { |
[email protected] | 10b56de | 2012-07-14 02:09:51 | [diff] [blame] | 7561 | return (size == 1) || |
| 7562 | (size == 2) || !(size % kS3TCBlockWidth); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7563 | } |
| 7564 | |
| 7565 | } // anonymous namespace. |
| 7566 | |
| 7567 | bool GLES2DecoderImpl::ValidateCompressedTexFuncData( |
| 7568 | const char* function_name, |
| 7569 | GLsizei width, GLsizei height, GLenum format, size_t size) { |
| 7570 | unsigned int bytes_required = 0; |
| 7571 | |
| 7572 | switch (format) { |
| 7573 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 7574 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: { |
| 7575 | int num_blocks_across = |
| 7576 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 7577 | int num_blocks_down = |
| 7578 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 7579 | int num_blocks = num_blocks_across * num_blocks_down; |
| 7580 | bytes_required = num_blocks * kS3TCDXT1BlockSize; |
| 7581 | break; |
| 7582 | } |
| 7583 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 7584 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 7585 | int num_blocks_across = |
| 7586 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 7587 | int num_blocks_down = |
| 7588 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 7589 | int num_blocks = num_blocks_across * num_blocks_down; |
| 7590 | bytes_required = num_blocks * kS3TCDXT3AndDXT5BlockSize; |
| 7591 | break; |
| 7592 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7593 | case GL_ETC1_RGB8_OES: { |
| 7594 | int num_blocks_across = |
| 7595 | (width + kETC1BlockWidth - 1) / kETC1BlockWidth; |
| 7596 | int num_blocks_down = |
| 7597 | (height + kETC1BlockHeight - 1) / kETC1BlockHeight; |
| 7598 | int num_blocks = num_blocks_across * num_blocks_down; |
| 7599 | bytes_required = num_blocks * kETC1BlockSize; |
| 7600 | break; |
| 7601 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7602 | default: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7603 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7604 | return false; |
| 7605 | } |
| 7606 | |
| 7607 | if (size != bytes_required) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7608 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7609 | GL_INVALID_VALUE, function_name, "size is not correct for dimensions"); |
| 7610 | return false; |
| 7611 | } |
| 7612 | |
| 7613 | return true; |
| 7614 | } |
| 7615 | |
| 7616 | bool GLES2DecoderImpl::ValidateCompressedTexDimensions( |
| 7617 | const char* function_name, |
| 7618 | GLint level, GLsizei width, GLsizei height, GLenum format) { |
| 7619 | switch (format) { |
| 7620 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 7621 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 7622 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 7623 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 7624 | if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7625 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7626 | GL_INVALID_OPERATION, function_name, |
| 7627 | "width or height invalid for level"); |
| 7628 | return false; |
| 7629 | } |
| 7630 | return true; |
| 7631 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7632 | case GL_ETC1_RGB8_OES: |
| 7633 | if (width <= 0 || height <= 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7634 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7635 | GL_INVALID_OPERATION, function_name, |
| 7636 | "width or height invalid for level"); |
| 7637 | return false; |
| 7638 | } |
| 7639 | return true; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7640 | default: |
| 7641 | return false; |
| 7642 | } |
| 7643 | } |
| 7644 | |
| 7645 | bool GLES2DecoderImpl::ValidateCompressedTexSubDimensions( |
| 7646 | const char* function_name, |
| 7647 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 7648 | GLsizei width, GLsizei height, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7649 | Texture* texture) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7650 | if (xoffset < 0 || yoffset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7651 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7652 | GL_INVALID_VALUE, function_name, "xoffset or yoffset < 0"); |
| 7653 | return false; |
| 7654 | } |
| 7655 | |
| 7656 | switch (format) { |
| 7657 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 7658 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 7659 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 7660 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 7661 | const int kBlockWidth = 4; |
| 7662 | const int kBlockHeight = 4; |
| 7663 | if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7664 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7665 | GL_INVALID_OPERATION, function_name, |
| 7666 | "xoffset or yoffset not multiple of 4"); |
| 7667 | return false; |
| 7668 | } |
| 7669 | GLsizei tex_width = 0; |
| 7670 | GLsizei tex_height = 0; |
| 7671 | if (!texture->GetLevelSize(target, level, &tex_width, &tex_height) || |
| 7672 | width - xoffset > tex_width || |
| 7673 | height - yoffset > tex_height) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7674 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7675 | GL_INVALID_OPERATION, function_name, "dimensions out of range"); |
| 7676 | return false; |
| 7677 | } |
| 7678 | return ValidateCompressedTexDimensions( |
| 7679 | function_name, level, width, height, format); |
| 7680 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7681 | case GL_ETC1_RGB8_OES: { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7682 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7683 | GL_INVALID_OPERATION, function_name, |
| 7684 | "TexsubImage2d not supported for ECT1_RGB8_OES textures"); |
| 7685 | return false; |
| 7686 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7687 | default: |
| 7688 | return false; |
| 7689 | } |
| 7690 | } |
| 7691 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7692 | error::Error GLES2DecoderImpl::DoCompressedTexImage2D( |
| 7693 | GLenum target, |
| 7694 | GLint level, |
| 7695 | GLenum internal_format, |
| 7696 | GLsizei width, |
| 7697 | GLsizei height, |
| 7698 | GLint border, |
| 7699 | GLsizei image_size, |
| 7700 | const void* data) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7701 | // TODO(gman): Validate image_size is correct for width, height and format. |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7702 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7703 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 7704 | "glCompressedTexImage2D", target, "target"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7705 | return error::kNoError; |
| 7706 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7707 | if (!validators_->compressed_texture_format.IsValid( |
| 7708 | internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7709 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7710 | "glCompressedTexImage2D", internal_format, "internal_format"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7711 | return error::kNoError; |
| 7712 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7713 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7714 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7715 | LOCAL_SET_GL_ERROR( |
| 7716 | GL_INVALID_VALUE, |
| 7717 | "glCompressedTexImage2D", "dimensions out of range"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7718 | return error::kNoError; |
| 7719 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7720 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 7721 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7722 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7723 | LOCAL_SET_GL_ERROR( |
| 7724 | GL_INVALID_VALUE, |
| 7725 | "glCompressedTexImage2D", "unknown texture target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7726 | return error::kNoError; |
| 7727 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7728 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 7729 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7730 | LOCAL_SET_GL_ERROR( |
| 7731 | GL_INVALID_OPERATION, |
| 7732 | "glCompressedTexImage2D", "texture is immutable"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7733 | return error::kNoError; |
| 7734 | } |
| 7735 | |
| 7736 | if (!ValidateCompressedTexDimensions( |
| 7737 | "glCompressedTexImage2D", level, width, height, internal_format) || |
| 7738 | !ValidateCompressedTexFuncData( |
| 7739 | "glCompressedTexImage2D", width, height, internal_format, image_size)) { |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 7740 | return error::kNoError; |
| 7741 | } |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 7742 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 7743 | if (!EnsureGPUMemoryAvailable(image_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7744 | LOCAL_SET_GL_ERROR( |
| 7745 | GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 7746 | return error::kNoError; |
| 7747 | } |
| 7748 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 7749 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7750 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 7751 | } |
| 7752 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 7753 | scoped_ptr<int8[]> zero; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7754 | if (!data) { |
| 7755 | zero.reset(new int8[image_size]); |
| 7756 | memset(zero.get(), 0, image_size); |
| 7757 | data = zero.get(); |
| 7758 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7759 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7760 | glCompressedTexImage2D( |
| 7761 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7762 | GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7763 | if (error == GL_NO_ERROR) { |
| 7764 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7765 | texture_ref, target, level, internal_format, |
| 7766 | width, height, 1, border, 0, 0, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7767 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7768 | return error::kNoError; |
| 7769 | } |
| 7770 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7771 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7772 | uint32 immediate_data_size, const cmds::CompressedTexImage2D& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7773 | GLenum target = static_cast<GLenum>(c.target); |
| 7774 | GLint level = static_cast<GLint>(c.level); |
| 7775 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 7776 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7777 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7778 | GLint border = static_cast<GLint>(c.border); |
| 7779 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
| 7780 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 7781 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 7782 | const void* data = NULL; |
| 7783 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 7784 | data = GetSharedMemoryAs<const void*>( |
| 7785 | data_shm_id, data_shm_offset, image_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7786 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7787 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7788 | } |
| 7789 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7790 | return DoCompressedTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7791 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7792 | } |
| 7793 | |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7794 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2DBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7795 | uint32 immediate_data_size, const cmds::CompressedTexImage2DBucket& c) { |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7796 | GLenum target = static_cast<GLenum>(c.target); |
| 7797 | GLint level = static_cast<GLint>(c.level); |
| 7798 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 7799 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7800 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7801 | GLint border = static_cast<GLint>(c.border); |
| 7802 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7803 | if (!bucket) { |
| 7804 | return error::kInvalidArguments; |
| 7805 | } |
| 7806 | uint32 data_size = bucket->size(); |
| 7807 | GLsizei imageSize = data_size; |
| 7808 | const void* data = bucket->GetData(0, data_size); |
| 7809 | if (!data) { |
| 7810 | return error::kInvalidArguments; |
| 7811 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7812 | return DoCompressedTexImage2D( |
| 7813 | target, level, internal_format, width, height, border, |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7814 | imageSize, data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7815 | } |
| 7816 | |
| 7817 | error::Error GLES2DecoderImpl::HandleCompressedTexSubImage2DBucket( |
| 7818 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7819 | const cmds::CompressedTexSubImage2DBucket& c) { |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7820 | GLenum target = static_cast<GLenum>(c.target); |
| 7821 | GLint level = static_cast<GLint>(c.level); |
| 7822 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 7823 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 7824 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7825 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7826 | GLenum format = static_cast<GLenum>(c.format); |
| 7827 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7828 | if (!bucket) { |
| 7829 | return error::kInvalidArguments; |
| 7830 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7831 | uint32 data_size = bucket->size(); |
| 7832 | GLsizei imageSize = data_size; |
| 7833 | const void* data = bucket->GetData(0, data_size); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 7834 | if (!data) { |
| 7835 | return error::kInvalidArguments; |
| 7836 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7837 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7838 | LOCAL_SET_GL_ERROR( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7839 | GL_INVALID_ENUM, "glCompressedTexSubImage2D", "target"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7840 | return error::kNoError; |
| 7841 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7842 | if (!validators_->compressed_texture_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7843 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 7844 | "glCompressedTexSubImage2D", format, "format"); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7845 | return error::kNoError; |
| 7846 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7847 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7848 | LOCAL_SET_GL_ERROR( |
| 7849 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "width < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7850 | return error::kNoError; |
| 7851 | } |
| 7852 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7853 | LOCAL_SET_GL_ERROR( |
| 7854 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "height < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7855 | return error::kNoError; |
| 7856 | } |
| 7857 | if (imageSize < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7858 | LOCAL_SET_GL_ERROR( |
| 7859 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "imageSize < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7860 | return error::kNoError; |
| 7861 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7862 | DoCompressedTexSubImage2D( |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 7863 | target, level, xoffset, yoffset, width, height, format, imageSize, data); |
| 7864 | return error::kNoError; |
| 7865 | } |
| 7866 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7867 | error::Error GLES2DecoderImpl::HandleTexImage2D( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7868 | uint32 immediate_data_size, const cmds::TexImage2D& c) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 7869 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D"); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7870 | // Set as failed for now, but if it successed, this will be set to not failed. |
| 7871 | texture_state_.tex_image_2d_failed = true; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7872 | GLenum target = static_cast<GLenum>(c.target); |
| 7873 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7874 | // TODO(kloveless): Change TexImage2D command to use unsigned integer |
| 7875 | // for internalformat. |
| 7876 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7877 | GLsizei width = static_cast<GLsizei>(c.width); |
| 7878 | GLsizei height = static_cast<GLsizei>(c.height); |
| 7879 | GLint border = static_cast<GLint>(c.border); |
| 7880 | GLenum format = static_cast<GLenum>(c.format); |
| 7881 | GLenum type = static_cast<GLenum>(c.type); |
| 7882 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 7883 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7884 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7885 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7886 | width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7887 | NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7888 | return error::kOutOfBounds; |
| 7889 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7890 | const void* pixels = NULL; |
| 7891 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 7892 | pixels = GetSharedMemoryAs<const void*>( |
| 7893 | pixels_shm_id, pixels_shm_offset, pixels_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7894 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7895 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7896 | } |
| 7897 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 7898 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7899 | TextureManager::DoTextImage2DArguments args = { |
| 7900 | target, level, internal_format, width, height, border, format, type, |
| 7901 | pixels, pixels_size}; |
| 7902 | texture_manager()->ValidateAndDoTexImage2D( |
| 7903 | &texture_state_, &state_, &framebuffer_state_, args); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 7904 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7905 | } |
| 7906 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7907 | void GLES2DecoderImpl::DoCompressedTexSubImage2D( |
| 7908 | GLenum target, |
| 7909 | GLint level, |
| 7910 | GLint xoffset, |
| 7911 | GLint yoffset, |
| 7912 | GLsizei width, |
| 7913 | GLsizei height, |
| 7914 | GLenum format, |
| 7915 | GLsizei image_size, |
| 7916 | const void * data) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7917 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 7918 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7919 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7920 | LOCAL_SET_GL_ERROR( |
| 7921 | GL_INVALID_OPERATION, |
| 7922 | "glCompressedTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7923 | return; |
| 7924 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7925 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7926 | GLenum type = 0; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7927 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 7928 | if (!texture->GetLevelType(target, level, &type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7929 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7930 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7931 | "glCompressedTexSubImage2D", "level does not exist."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7932 | return; |
| 7933 | } |
| 7934 | if (internal_format != format) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7935 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7936 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7937 | "glCompressedTexSubImage2D", "format does not match internal format."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7938 | return; |
| 7939 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 7940 | if (!texture->ValidForTexture( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 7941 | target, level, xoffset, yoffset, width, height, format, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7942 | LOCAL_SET_GL_ERROR( |
| 7943 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7944 | return; |
| 7945 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7946 | |
| 7947 | if (!ValidateCompressedTexFuncData( |
| 7948 | "glCompressedTexSubImage2D", width, height, format, image_size) || |
| 7949 | !ValidateCompressedTexSubDimensions( |
| 7950 | "glCompressedTexSubImage2D", |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 7951 | target, level, xoffset, yoffset, width, height, format, texture)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7952 | return; |
| 7953 | } |
| 7954 | |
| 7955 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7956 | // Note: There is no need to deal with texture cleared tracking here |
| 7957 | // because the validation above means you can only get here if the level |
| 7958 | // is already a matching compressed format and in that case |
| 7959 | // CompressedTexImage2D already cleared the texture. |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7960 | glCompressedTexSubImage2D( |
| 7961 | target, level, xoffset, yoffset, width, height, format, image_size, data); |
| 7962 | } |
| 7963 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 7964 | static void Clip( |
| 7965 | GLint start, GLint range, GLint sourceRange, |
| 7966 | GLint* out_start, GLint* out_range) { |
| 7967 | DCHECK(out_start); |
| 7968 | DCHECK(out_range); |
| 7969 | if (start < 0) { |
| 7970 | range += start; |
| 7971 | start = 0; |
| 7972 | } |
| 7973 | GLint end = start + range; |
| 7974 | if (end > sourceRange) { |
| 7975 | range -= end - sourceRange; |
| 7976 | } |
| 7977 | *out_start = start; |
| 7978 | *out_range = range; |
| 7979 | } |
| 7980 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7981 | void GLES2DecoderImpl::DoCopyTexImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 7982 | GLenum target, |
| 7983 | GLint level, |
| 7984 | GLenum internal_format, |
| 7985 | GLint x, |
| 7986 | GLint y, |
| 7987 | GLsizei width, |
| 7988 | GLsizei height, |
| 7989 | GLint border) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 7990 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7991 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 7992 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7993 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7994 | LOCAL_SET_GL_ERROR( |
| 7995 | GL_INVALID_OPERATION, |
| 7996 | "glCopyTexImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7997 | return; |
| 7998 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7999 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8000 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8001 | LOCAL_SET_GL_ERROR( |
| 8002 | GL_INVALID_OPERATION, "glCopyTexImage2D", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8003 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8004 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8005 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8006 | LOCAL_SET_GL_ERROR( |
| 8007 | GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range"); |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8008 | return; |
| 8009 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8010 | if (!texture_manager()->ValidateTextureParameters( |
| 8011 | state_.GetErrorState(), "glCopyTexImage2D", target, internal_format, |
| 8012 | GL_UNSIGNED_BYTE, level)) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8013 | return; |
| 8014 | } |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8015 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8016 | // Check we have compatible formats. |
| 8017 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 8018 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 8019 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); |
| 8020 | |
| 8021 | if ((channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8022 | LOCAL_SET_GL_ERROR( |
| 8023 | GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8024 | return; |
| 8025 | } |
| 8026 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8027 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8028 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8029 | GL_INVALID_OPERATION, |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8030 | "glCopyTexImage2D", "can not be used with depth or stencil textures"); |
| 8031 | return; |
| 8032 | } |
| 8033 | |
| 8034 | uint32 estimated_size = 0; |
| 8035 | if (!GLES2Util::ComputeImageDataSizes( |
| 8036 | width, height, internal_format, GL_UNSIGNED_BYTE, state_.unpack_alignment, |
| 8037 | &estimated_size, NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8038 | LOCAL_SET_GL_ERROR( |
| 8039 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8040 | return; |
| 8041 | } |
| 8042 | |
| 8043 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8044 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "out of memory"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8045 | return; |
| 8046 | } |
| 8047 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 8048 | if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { |
| 8049 | return; |
| 8050 | } |
| 8051 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8052 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTexImage2D"); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8053 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8054 | gfx::Size size = GetBoundReadFrameBufferSize(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8055 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8056 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8057 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 8058 | } |
| 8059 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8060 | // Clip to size to source dimensions |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8061 | GLint copyX = 0; |
| 8062 | GLint copyY = 0; |
| 8063 | GLint copyWidth = 0; |
| 8064 | GLint copyHeight = 0; |
| 8065 | Clip(x, width, size.width(), ©X, ©Width); |
| 8066 | Clip(y, height, size.height(), ©Y, ©Height); |
| 8067 | |
| 8068 | if (copyX != x || |
| 8069 | copyY != y || |
| 8070 | copyWidth != width || |
| 8071 | copyHeight != height) { |
| 8072 | // some part was clipped so clear the texture. |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8073 | if (!ClearLevel( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8074 | texture->service_id(), texture->target(), |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8075 | target, level, internal_format, GL_UNSIGNED_BYTE, width, height, |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8076 | texture->IsImmutable())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8077 | LOCAL_SET_GL_ERROR( |
| 8078 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8079 | return; |
| 8080 | } |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8081 | if (copyHeight > 0 && copyWidth > 0) { |
| 8082 | GLint dx = copyX - x; |
| 8083 | GLint dy = copyY - y; |
| 8084 | GLint destX = dx; |
| 8085 | GLint destY = dy; |
| 8086 | glCopyTexSubImage2D(target, level, |
| 8087 | destX, destY, copyX, copyY, |
| 8088 | copyWidth, copyHeight); |
| 8089 | } |
| 8090 | } else { |
| 8091 | glCopyTexImage2D(target, level, internal_format, |
| 8092 | copyX, copyY, copyWidth, copyHeight, border); |
| 8093 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8094 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8095 | if (error == GL_NO_ERROR) { |
| 8096 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8097 | texture_ref, target, level, internal_format, width, height, 1, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8098 | border, internal_format, GL_UNSIGNED_BYTE, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8099 | } |
| 8100 | } |
| 8101 | |
| 8102 | void GLES2DecoderImpl::DoCopyTexSubImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 8103 | GLenum target, |
| 8104 | GLint level, |
| 8105 | GLint xoffset, |
| 8106 | GLint yoffset, |
| 8107 | GLint x, |
| 8108 | GLint y, |
| 8109 | GLsizei width, |
| 8110 | GLsizei height) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 8111 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8112 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8113 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8114 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8115 | LOCAL_SET_GL_ERROR( |
| 8116 | GL_INVALID_OPERATION, |
| 8117 | "glCopyTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8118 | return; |
| 8119 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8120 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8121 | GLenum type = 0; |
| 8122 | GLenum format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8123 | if (!texture->GetLevelType(target, level, &type, &format) || |
| 8124 | !texture->ValidForTexture( |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8125 | target, level, xoffset, yoffset, width, height, format, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8126 | LOCAL_SET_GL_ERROR( |
| 8127 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8128 | return; |
| 8129 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 8130 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8131 | LOCAL_SET_GL_ERROR( |
| 8132 | GL_INVALID_OPERATION, |
| 8133 | "glCopyTexSubImage2D", "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 8134 | return; |
| 8135 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8136 | |
| 8137 | // Check we have compatible formats. |
| 8138 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 8139 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 8140 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(format); |
| 8141 | |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8142 | if (!channels_needed || |
| 8143 | (channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8144 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8145 | GL_INVALID_OPERATION, "glCopyTexSubImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8146 | return; |
| 8147 | } |
| 8148 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8149 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8150 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8151 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8152 | "glCopySubImage2D", "can not be used with depth or stencil textures"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8153 | return; |
| 8154 | } |
| 8155 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 8156 | if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) { |
| 8157 | return; |
| 8158 | } |
| 8159 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8160 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8161 | gfx::Size size = GetBoundReadFrameBufferSize(); |
| 8162 | GLint copyX = 0; |
| 8163 | GLint copyY = 0; |
| 8164 | GLint copyWidth = 0; |
| 8165 | GLint copyHeight = 0; |
| 8166 | Clip(x, width, size.width(), ©X, ©Width); |
| 8167 | Clip(y, height, size.height(), ©Y, ©Height); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8168 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8169 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8170 | LOCAL_SET_GL_ERROR( |
| 8171 | GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", "dimensions too big"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8172 | return; |
| 8173 | } |
| 8174 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8175 | if (copyX != x || |
| 8176 | copyY != y || |
| 8177 | copyWidth != width || |
| 8178 | copyHeight != height) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8179 | // some part was clipped so clear the sub rect. |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8180 | uint32 pixels_size = 0; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8181 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8182 | width, height, format, type, state_.unpack_alignment, &pixels_size, |
| 8183 | NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8184 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8185 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8186 | return; |
| 8187 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8188 | scoped_ptr<char[]> zero(new char[pixels_size]); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8189 | memset(zero.get(), 0, pixels_size); |
| 8190 | glTexSubImage2D( |
| 8191 | target, level, xoffset, yoffset, width, height, |
| 8192 | format, type, zero.get()); |
| 8193 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8194 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8195 | if (copyHeight > 0 && copyWidth > 0) { |
| 8196 | GLint dx = copyX - x; |
| 8197 | GLint dy = copyY - y; |
| 8198 | GLint destX = xoffset + dx; |
| 8199 | GLint destY = yoffset + dy; |
| 8200 | glCopyTexSubImage2D(target, level, |
| 8201 | destX, destY, copyX, copyY, |
| 8202 | copyWidth, copyHeight); |
| 8203 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8204 | } |
| 8205 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8206 | bool GLES2DecoderImpl::ValidateTexSubImage2D( |
| 8207 | error::Error* error, |
| 8208 | const char* function_name, |
| 8209 | GLenum target, |
| 8210 | GLint level, |
| 8211 | GLint xoffset, |
| 8212 | GLint yoffset, |
| 8213 | GLsizei width, |
| 8214 | GLsizei height, |
| 8215 | GLenum format, |
| 8216 | GLenum type, |
| 8217 | const void * data) { |
| 8218 | (*error) = error::kNoError; |
| 8219 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8220 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8221 | return false; |
| 8222 | } |
| 8223 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8224 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "width < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8225 | return false; |
| 8226 | } |
| 8227 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8228 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "height < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8229 | return false; |
| 8230 | } |
| 8231 | if (!validators_->texture_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8232 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8233 | return false; |
| 8234 | } |
| 8235 | if (!validators_->pixel_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8236 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, type, "type"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8237 | return false; |
| 8238 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8239 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8240 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8241 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8242 | LOCAL_SET_GL_ERROR( |
| 8243 | GL_INVALID_OPERATION, |
| 8244 | function_name, "unknown texture for target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8245 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8246 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8247 | Texture* texture = texture_ref->texture(); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8248 | GLenum current_type = 0; |
| 8249 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8250 | if (!texture->GetLevelType(target, level, ¤t_type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8251 | LOCAL_SET_GL_ERROR( |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8252 | GL_INVALID_OPERATION, function_name, "level does not exist."); |
| 8253 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8254 | } |
| 8255 | if (format != internal_format) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8256 | LOCAL_SET_GL_ERROR( |
| 8257 | GL_INVALID_OPERATION, |
| 8258 | function_name, "format does not match internal format."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8259 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8260 | } |
| 8261 | if (type != current_type) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8262 | LOCAL_SET_GL_ERROR( |
| 8263 | GL_INVALID_OPERATION, |
| 8264 | function_name, "type does not match type of texture."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8265 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8266 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 8267 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8268 | LOCAL_SET_GL_ERROR( |
| 8269 | GL_INVALID_OPERATION, |
| 8270 | function_name, "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 8271 | return false; |
| 8272 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8273 | if (!texture->ValidForTexture( |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8274 | target, level, xoffset, yoffset, width, height, format, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8275 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "bad dimensions."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8276 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8277 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8278 | if ((GLES2Util::GetChannelsForFormat(format) & |
| 8279 | (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8280 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8281 | GL_INVALID_OPERATION, |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8282 | function_name, "can not supply data for depth or stencil textures"); |
| 8283 | return false; |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8284 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8285 | if (data == NULL) { |
| 8286 | (*error) = error::kOutOfBounds; |
| 8287 | return false; |
| 8288 | } |
| 8289 | return true; |
| 8290 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8291 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8292 | error::Error GLES2DecoderImpl::DoTexSubImage2D( |
| 8293 | GLenum target, |
| 8294 | GLint level, |
| 8295 | GLint xoffset, |
| 8296 | GLint yoffset, |
| 8297 | GLsizei width, |
| 8298 | GLsizei height, |
| 8299 | GLenum format, |
| 8300 | GLenum type, |
| 8301 | const void * data) { |
| 8302 | error::Error error = error::kNoError; |
| 8303 | if (!ValidateTexSubImage2D(&error, "glTexSubImage2D", target, level, |
| 8304 | xoffset, yoffset, width, height, format, type, data)) { |
| 8305 | return error; |
| 8306 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8307 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8308 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8309 | Texture* texture = texture_ref->texture(); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8310 | GLsizei tex_width = 0; |
| 8311 | GLsizei tex_height = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8312 | bool ok = texture->GetLevelSize(target, level, &tex_width, &tex_height); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8313 | DCHECK(ok); |
| 8314 | if (xoffset != 0 || yoffset != 0 || |
| 8315 | width != tex_width || height != tex_height) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8316 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, |
| 8317 | target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8318 | LOCAL_SET_GL_ERROR( |
| 8319 | GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8320 | return error::kNoError; |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 8321 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8322 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8323 | glTexSubImage2D( |
| 8324 | target, level, xoffset, yoffset, width, height, format, type, data); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8325 | return error::kNoError; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8326 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8327 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8328 | if (texture_state_.teximage2d_faster_than_texsubimage2d && |
| 8329 | !texture->IsImmutable()) { |
| 8330 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8331 | // NOTE: In OpenGL ES 2.0 border is always zero and format is always the |
| 8332 | // same as internal_foramt. If that changes we'll need to look them up. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 8333 | glTexImage2D( |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8334 | target, level, format, width, height, 0, format, type, data); |
| 8335 | } else { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8336 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8337 | glTexSubImage2D( |
| 8338 | target, level, xoffset, yoffset, width, height, format, type, data); |
| 8339 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8340 | texture_manager()->SetLevelCleared(texture_ref, target, level, true); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8341 | return error::kNoError; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8342 | } |
| 8343 | |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8344 | error::Error GLES2DecoderImpl::HandleTexSubImage2D( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8345 | uint32 immediate_data_size, const cmds::TexSubImage2D& c) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 8346 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8347 | GLboolean internal = static_cast<GLboolean>(c.internal); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8348 | if (internal == GL_TRUE && texture_state_.tex_image_2d_failed) |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8349 | return error::kNoError; |
| 8350 | |
| 8351 | GLenum target = static_cast<GLenum>(c.target); |
| 8352 | GLint level = static_cast<GLint>(c.level); |
| 8353 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 8354 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 8355 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8356 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8357 | GLenum format = static_cast<GLenum>(c.format); |
| 8358 | GLenum type = static_cast<GLenum>(c.type); |
| 8359 | uint32 data_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8360 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8361 | width, height, format, type, state_.unpack_alignment, &data_size, |
| 8362 | NULL, NULL)) { |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8363 | return error::kOutOfBounds; |
| 8364 | } |
| 8365 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 8366 | c.pixels_shm_id, c.pixels_shm_offset, data_size); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8367 | return DoTexSubImage2D( |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8368 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8369 | } |
| 8370 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8371 | error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8372 | uint32 immediate_data_size, const cmds::GetVertexAttribPointerv& c) { |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8373 | GLuint index = static_cast<GLuint>(c.index); |
| 8374 | GLenum pname = static_cast<GLenum>(c.pname); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8375 | typedef cmds::GetVertexAttribPointerv::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8376 | Result* result = GetSharedMemoryAs<Result*>( |
| 8377 | c.pointer_shm_id, c.pointer_shm_offset, Result::ComputeSize(1)); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8378 | if (!result) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8379 | return error::kOutOfBounds; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8380 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8381 | // Check that the client initialized the result. |
| 8382 | if (result->size != 0) { |
| 8383 | return error::kInvalidArguments; |
| 8384 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8385 | if (!validators_->vertex_pointer.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8386 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 8387 | "glGetVertexAttribPointerv", pname, "pname"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8388 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8389 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 8390 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8391 | LOCAL_SET_GL_ERROR( |
| 8392 | GL_INVALID_VALUE, "glGetVertexAttribPointerv", "index out of range."); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8393 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8394 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8395 | result->SetNumResults(1); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 8396 | *result->GetData() = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8397 | state_.vertex_attrib_manager->GetVertexAttrib(index)->offset(); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8398 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8399 | } |
| 8400 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8401 | bool GLES2DecoderImpl::GetUniformSetup( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8402 | GLuint program_id, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8403 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8404 | error::Error* error, GLint* real_location, |
| 8405 | GLuint* service_id, void** result_pointer, GLenum* result_type) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8406 | DCHECK(error); |
| 8407 | DCHECK(service_id); |
| 8408 | DCHECK(result_pointer); |
| 8409 | DCHECK(result_type); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8410 | DCHECK(real_location); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8411 | *error = error::kNoError; |
| 8412 | // Make sure we have enough room for the result on failure. |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8413 | SizedResult<GLint>* result; |
| 8414 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 8415 | shm_id, shm_offset, SizedResult<GLint>::ComputeSize(0)); |
| 8416 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8417 | *error = error::kOutOfBounds; |
| 8418 | return false; |
| 8419 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8420 | *result_pointer = result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8421 | // 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] | 8422 | result->SetNumResults(0); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8423 | Program* program = GetProgramInfoNotShader(program_id, "glGetUniform"); |
| 8424 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8425 | return false; |
| 8426 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8427 | if (!program->IsValid()) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8428 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8429 | LOCAL_SET_GL_ERROR( |
| 8430 | GL_INVALID_OPERATION, "glGetUniform", "program not linked"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8431 | return false; |
| 8432 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8433 | *service_id = program->service_id(); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 8434 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8435 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8436 | program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8437 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 8438 | if (!uniform_info) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8439 | // No such location. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8440 | LOCAL_SET_GL_ERROR( |
| 8441 | GL_INVALID_OPERATION, "glGetUniform", "unknown location"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8442 | return false; |
| 8443 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 8444 | GLenum type = uniform_info->type; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 8445 | GLsizei size = GLES2Util::GetGLDataTypeSizeForUniforms(type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8446 | if (size == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8447 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glGetUniform", "unknown type"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8448 | return false; |
| 8449 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8450 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 8451 | shm_id, shm_offset, SizedResult<GLint>::ComputeSizeFromBytes(size)); |
| 8452 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8453 | *error = error::kOutOfBounds; |
| 8454 | return false; |
| 8455 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8456 | result->size = size; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8457 | *result_type = type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8458 | return true; |
| 8459 | } |
| 8460 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8461 | error::Error GLES2DecoderImpl::HandleGetUniformiv( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8462 | uint32 immediate_data_size, const cmds::GetUniformiv& c) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8463 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 8464 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8465 | GLuint service_id; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8466 | GLenum result_type; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8467 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8468 | Error error; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8469 | void* result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8470 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8471 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 8472 | &error, &real_location, &service_id, &result, &result_type)) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8473 | glGetUniformiv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8474 | service_id, real_location, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8475 | static_cast<cmds::GetUniformiv::Result*>(result)->GetData()); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8476 | } |
| 8477 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8478 | } |
| 8479 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8480 | error::Error GLES2DecoderImpl::HandleGetUniformfv( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8481 | uint32 immediate_data_size, const cmds::GetUniformfv& c) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8482 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 8483 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8484 | GLuint service_id; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8485 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8486 | Error error; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8487 | typedef cmds::GetUniformfv::Result Result; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8488 | Result* result; |
| 8489 | GLenum result_type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8490 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8491 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 8492 | &error, &real_location, &service_id, |
| 8493 | reinterpret_cast<void**>(&result), &result_type)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8494 | if (result_type == GL_BOOL || result_type == GL_BOOL_VEC2 || |
| 8495 | result_type == GL_BOOL_VEC3 || result_type == GL_BOOL_VEC4) { |
| 8496 | GLsizei num_values = result->GetNumResults(); |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8497 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8498 | glGetUniformiv(service_id, real_location, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8499 | GLfloat* dst = result->GetData(); |
| 8500 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
| 8501 | dst[ii] = (temp[ii] != 0); |
| 8502 | } |
| 8503 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8504 | glGetUniformfv(service_id, real_location, result->GetData()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8505 | } |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8506 | } |
| 8507 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8508 | } |
| 8509 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8510 | error::Error GLES2DecoderImpl::HandleGetShaderPrecisionFormat( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8511 | uint32 immediate_data_size, const cmds::GetShaderPrecisionFormat& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8512 | GLenum shader_type = static_cast<GLenum>(c.shadertype); |
| 8513 | GLenum precision_type = static_cast<GLenum>(c.precisiontype); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8514 | typedef cmds::GetShaderPrecisionFormat::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8515 | Result* result = GetSharedMemoryAs<Result*>( |
| 8516 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8517 | if (!result) { |
| 8518 | return error::kOutOfBounds; |
| 8519 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8520 | // Check that the client initialized the result. |
| 8521 | if (result->success != 0) { |
| 8522 | return error::kInvalidArguments; |
| 8523 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8524 | if (!validators_->shader_type.IsValid(shader_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8525 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8526 | "glGetShaderPrecisionFormat", shader_type, "shader_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8527 | return error::kNoError; |
| 8528 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8529 | if (!validators_->shader_precision.IsValid(precision_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8530 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8531 | "glGetShaderPrecisionFormat", precision_type, "precision_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8532 | return error::kNoError; |
| 8533 | } |
| 8534 | |
| 8535 | result->success = 1; // true |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 8536 | |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 8537 | GLint range[2] = { 0, 0 }; |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 8538 | GLint precision = 0; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 8539 | GetShaderPrecisionFormatImpl(shader_type, precision_type, range, &precision); |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 8540 | |
| 8541 | result->min_range = range[0]; |
| 8542 | result->max_range = range[1]; |
| 8543 | result->precision = precision; |
| 8544 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8545 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8546 | } |
| 8547 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8548 | error::Error GLES2DecoderImpl::HandleGetAttachedShaders( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8549 | uint32 immediate_data_size, const cmds::GetAttachedShaders& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8550 | uint32 result_size = c.result_size; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8551 | GLuint program_id = static_cast<GLuint>(c.program); |
| 8552 | Program* program = GetProgramInfoNotShader( |
| 8553 | program_id, "glGetAttachedShaders"); |
| 8554 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8555 | return error::kNoError; |
| 8556 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8557 | typedef cmds::GetAttachedShaders::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8558 | uint32 max_count = Result::ComputeMaxResults(result_size); |
| 8559 | Result* result = GetSharedMemoryAs<Result*>( |
| 8560 | c.result_shm_id, c.result_shm_offset, Result::ComputeSize(max_count)); |
| 8561 | if (!result) { |
| 8562 | return error::kOutOfBounds; |
| 8563 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8564 | // Check that the client initialized the result. |
| 8565 | if (result->size != 0) { |
| 8566 | return error::kInvalidArguments; |
| 8567 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8568 | GLsizei count = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8569 | glGetAttachedShaders( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8570 | program->service_id(), max_count, &count, result->GetData()); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8571 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8572 | if (!shader_manager()->GetClientId(result->GetData()[ii], |
| 8573 | &result->GetData()[ii])) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8574 | NOTREACHED(); |
| 8575 | return error::kGenericError; |
| 8576 | } |
| 8577 | } |
| 8578 | result->SetNumResults(count); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8579 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8580 | } |
| 8581 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8582 | error::Error GLES2DecoderImpl::HandleGetActiveUniform( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8583 | uint32 immediate_data_size, const cmds::GetActiveUniform& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8584 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8585 | GLuint index = c.index; |
| 8586 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8587 | typedef cmds::GetActiveUniform::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8588 | Result* result = GetSharedMemoryAs<Result*>( |
| 8589 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8590 | if (!result) { |
| 8591 | return error::kOutOfBounds; |
| 8592 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8593 | // Check that the client initialized the result. |
| 8594 | if (result->success != 0) { |
| 8595 | return error::kInvalidArguments; |
| 8596 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8597 | Program* program = GetProgramInfoNotShader( |
| 8598 | program_id, "glGetActiveUniform"); |
| 8599 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8600 | return error::kNoError; |
| 8601 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8602 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8603 | program->GetUniformInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8604 | if (!uniform_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8605 | LOCAL_SET_GL_ERROR( |
| 8606 | GL_INVALID_VALUE, "glGetActiveUniform", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8607 | return error::kNoError; |
| 8608 | } |
| 8609 | result->success = 1; // true. |
| 8610 | result->size = uniform_info->size; |
| 8611 | result->type = uniform_info->type; |
| 8612 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 8613 | bucket->SetFromString(uniform_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8614 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8615 | } |
| 8616 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8617 | error::Error GLES2DecoderImpl::HandleGetActiveAttrib( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8618 | uint32 immediate_data_size, const cmds::GetActiveAttrib& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8619 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8620 | GLuint index = c.index; |
| 8621 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8622 | typedef cmds::GetActiveAttrib::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8623 | Result* result = GetSharedMemoryAs<Result*>( |
| 8624 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8625 | if (!result) { |
| 8626 | return error::kOutOfBounds; |
| 8627 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8628 | // Check that the client initialized the result. |
| 8629 | if (result->success != 0) { |
| 8630 | return error::kInvalidArguments; |
| 8631 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8632 | Program* program = GetProgramInfoNotShader( |
| 8633 | program_id, "glGetActiveAttrib"); |
| 8634 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8635 | return error::kNoError; |
| 8636 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8637 | const Program::VertexAttrib* attrib_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8638 | program->GetAttribInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8639 | if (!attrib_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8640 | LOCAL_SET_GL_ERROR( |
| 8641 | GL_INVALID_VALUE, "glGetActiveAttrib", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8642 | return error::kNoError; |
| 8643 | } |
| 8644 | result->success = 1; // true. |
| 8645 | result->size = attrib_info->size; |
| 8646 | result->type = attrib_info->type; |
| 8647 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 8648 | bucket->SetFromString(attrib_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8649 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8650 | } |
| 8651 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8652 | error::Error GLES2DecoderImpl::HandleShaderBinary( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8653 | uint32 immediate_data_size, const cmds::ShaderBinary& c) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8654 | #if 1 // No binary shader support. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8655 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glShaderBinary", "not supported"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8656 | return error::kNoError; |
| 8657 | #else |
| 8658 | GLsizei n = static_cast<GLsizei>(c.n); |
| 8659 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8660 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "n < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8661 | return error::kNoError; |
| 8662 | } |
| 8663 | GLsizei length = static_cast<GLsizei>(c.length); |
| 8664 | if (length < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8665 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "length < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8666 | return error::kNoError; |
| 8667 | } |
| 8668 | uint32 data_size; |
| 8669 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 8670 | return error::kOutOfBounds; |
| 8671 | } |
| 8672 | const GLuint* shaders = GetSharedMemoryAs<const GLuint*>( |
| 8673 | c.shaders_shm_id, c.shaders_shm_offset, data_size); |
| 8674 | GLenum binaryformat = static_cast<GLenum>(c.binaryformat); |
| 8675 | const void* binary = GetSharedMemoryAs<const void*>( |
| 8676 | c.binary_shm_id, c.binary_shm_offset, length); |
| 8677 | if (shaders == NULL || binary == NULL) { |
| 8678 | return error::kOutOfBounds; |
| 8679 | } |
| 8680 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 8681 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8682 | Shader* shader = GetShader(shaders[ii]); |
| 8683 | if (!shader) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8684 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "unknown shader"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8685 | return error::kNoError; |
| 8686 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8687 | service_ids[ii] = shader->service_id(); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8688 | } |
| 8689 | // TODO(gman): call glShaderBinary |
| 8690 | return error::kNoError; |
| 8691 | #endif |
| 8692 | } |
| 8693 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 8694 | void GLES2DecoderImpl::DoSwapBuffers() { |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8695 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 8696 | |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8697 | int this_frame_number = frame_number_++; |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 8698 | // TRACE_EVENT for gpu tests: |
| 8699 | TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffersLatency", |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 8700 | TRACE_EVENT_SCOPE_THREAD, |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 8701 | "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
| 8702 | "width", (is_offscreen ? offscreen_size_.width() : |
| 8703 | surface_->GetSize().width())); |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 8704 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoSwapBuffers", |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8705 | "offscreen", is_offscreen, |
| 8706 | "frame", this_frame_number); |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 8707 | bool is_tracing; |
| 8708 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 8709 | &is_tracing); |
| 8710 | if (is_tracing) { |
| 8711 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 8712 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 8713 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 8714 | } |
| 8715 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8716 | // If offscreen then don't actually SwapBuffers to the display. Just copy |
| 8717 | // the rendered frame to another frame buffer. |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8718 | if (is_offscreen) { |
[email protected] | 111975c6 | 2012-09-06 01:37:31 | [diff] [blame] | 8719 | TRACE_EVENT2("gpu", "Offscreen", |
| 8720 | "width", offscreen_size_.width(), "height", offscreen_size_.height()); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8721 | if (offscreen_size_ != offscreen_saved_color_texture_->size()) { |
| 8722 | // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, |
| 8723 | // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will |
| 8724 | // fix this. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8725 | if (workarounds().needs_offscreen_buffer_workaround) { |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8726 | offscreen_saved_frame_buffer_->Create(); |
| 8727 | glFinish(); |
| 8728 | } |
| 8729 | |
| 8730 | // Allocate the offscreen saved color texture. |
| 8731 | DCHECK(offscreen_saved_color_format_); |
| 8732 | offscreen_saved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 8733 | offscreen_size_, offscreen_saved_color_format_, false); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8734 | |
| 8735 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 8736 | offscreen_saved_color_texture_.get()); |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 8737 | if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { |
| 8738 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 8739 | GL_FRAMEBUFFER_COMPLETE) { |
| 8740 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 8741 | << "because offscreen saved FBO was incomplete."; |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 8742 | LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
| 8743 | return; |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 8744 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8745 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 8746 | // Clear the offscreen color texture. |
| 8747 | // TODO(piman): Is this still necessary? |
| 8748 | { |
| 8749 | ScopedFrameBufferBinder binder(this, |
| 8750 | offscreen_saved_frame_buffer_->id()); |
| 8751 | glClearColor(0, 0, 0, 0); |
| 8752 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 8753 | glDisable(GL_SCISSOR_TEST); |
| 8754 | glClear(GL_COLOR_BUFFER_BIT); |
| 8755 | RestoreClearState(); |
| 8756 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8757 | } |
| 8758 | |
| 8759 | UpdateParentTextureInfo(); |
| 8760 | } |
| 8761 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 8762 | if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 8763 | return; |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8764 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 8765 | "GLES2DecoderImpl::DoSwapBuffers", GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8766 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 8767 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 8768 | // For multisampled buffers, resolve the frame buffer. |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8769 | ScopedResolvedFrameBufferBinder binder(this, true, false); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 8770 | } else { |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8771 | ScopedFrameBufferBinder binder(this, |
| 8772 | offscreen_target_frame_buffer_->id()); |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 8773 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8774 | if (offscreen_target_buffer_preserved_) { |
| 8775 | // Copy the target frame buffer to the saved offscreen texture. |
| 8776 | offscreen_saved_color_texture_->Copy( |
| 8777 | offscreen_saved_color_texture_->size(), |
| 8778 | offscreen_saved_color_format_); |
| 8779 | } else { |
| 8780 | // Flip the textures in the parent context via the texture manager. |
| 8781 | if (!!offscreen_saved_color_texture_info_.get()) |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8782 | offscreen_saved_color_texture_info_->texture()-> |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8783 | SetServiceId(offscreen_target_color_texture_->id()); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 8784 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8785 | offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); |
| 8786 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 8787 | offscreen_target_color_texture_.get()); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 8788 | } |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8789 | |
| 8790 | // Ensure the side effects of the copy are visible to the parent |
| 8791 | // context. There is no need to do this for ANGLE because it uses a |
| 8792 | // single D3D device for all contexts. |
| 8793 | if (!IsAngle()) |
| 8794 | glFlush(); |
[email protected] | 0c8c9d2 | 2010-06-25 17:36:39 | [diff] [blame] | 8795 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8796 | } else { |
[email protected] | 111975c6 | 2012-09-06 01:37:31 | [diff] [blame] | 8797 | TRACE_EVENT2("gpu", "Onscreen", |
| 8798 | "width", surface_->GetSize().width(), |
| 8799 | "height", surface_->GetSize().height()); |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 8800 | if (!surface_->SwapBuffers()) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 8801 | LOG(ERROR) << "Context lost because SwapBuffers failed."; |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 8802 | LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 8803 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8804 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8805 | } |
| 8806 | |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 8807 | error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8808 | uint32 immediate_data_size, const cmds::EnableFeatureCHROMIUM& c) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8809 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8810 | if (!bucket || bucket->size() == 0) { |
| 8811 | return error::kInvalidArguments; |
| 8812 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8813 | typedef cmds::EnableFeatureCHROMIUM::Result Result; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8814 | Result* result = GetSharedMemoryAs<Result*>( |
| 8815 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8816 | if (!result) { |
| 8817 | return error::kOutOfBounds; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 8818 | } |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8819 | // Check that the client initialized the result. |
| 8820 | if (*result != 0) { |
| 8821 | return error::kInvalidArguments; |
| 8822 | } |
| 8823 | std::string feature_str; |
| 8824 | if (!bucket->GetAsString(&feature_str)) { |
| 8825 | return error::kInvalidArguments; |
| 8826 | } |
| 8827 | |
| 8828 | // TODO(gman): make this some kind of table to function pointer thingy. |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 8829 | if (feature_str.compare("pepper3d_allow_buffers_on_multiple_targets") == 0) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8830 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 8831 | } else if (feature_str.compare("pepper3d_support_fixed_attribs") == 0) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 8832 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
| 8833 | // TODO(gman): decide how to remove the need for this const_cast. |
| 8834 | // I could make validators_ non const but that seems bad as this is the only |
| 8835 | // place it is needed. I could make some special friend class of validators |
| 8836 | // just to allow this to set them. That seems silly. I could refactor this |
| 8837 | // code to use the extension mechanism or the initialization attributes to |
| 8838 | // turn this feature on. Given that the only real point of this is to make |
| 8839 | // the conformance tests pass and given that there is lots of real work that |
| 8840 | // needs to be done it seems like refactoring for one to one of those |
| 8841 | // methods is a very low priority. |
| 8842 | const_cast<Validators*>(validators_)->vertex_attrib_type.AddValue(GL_FIXED); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8843 | } else if (feature_str.compare("webgl_enable_glsl_webgl_validation") == 0) { |
| 8844 | force_webgl_glsl_validation_ = true; |
| 8845 | InitializeShaderTranslator(); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8846 | } else { |
| 8847 | return error::kNoError; |
| 8848 | } |
| 8849 | |
| 8850 | *result = 1; // true. |
| 8851 | return error::kNoError; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 8852 | } |
| 8853 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8854 | error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( |
| 8855 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8856 | const cmds::GetRequestableExtensionsCHROMIUM& c) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8857 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8858 | scoped_refptr<FeatureInfo> info(new FeatureInfo()); |
[email protected] | 956aec5 | 2013-09-05 15:41:19 | [diff] [blame] | 8859 | info->Initialize(disallowed_features_); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8860 | bucket->SetFromString(info->extensions().c_str()); |
| 8861 | return error::kNoError; |
| 8862 | } |
| 8863 | |
| 8864 | error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8865 | uint32 immediate_data_size, const cmds::RequestExtensionCHROMIUM& c) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8866 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8867 | if (!bucket || bucket->size() == 0) { |
| 8868 | return error::kInvalidArguments; |
| 8869 | } |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8870 | std::string feature_str; |
| 8871 | if (!bucket->GetAsString(&feature_str)) { |
| 8872 | return error::kInvalidArguments; |
| 8873 | } |
| 8874 | |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 8875 | bool desire_webgl_glsl_validation = |
| 8876 | feature_str.find("GL_CHROMIUM_webglsl") != std::string::npos; |
| 8877 | bool desire_standard_derivatives = false; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8878 | bool desire_frag_depth = false; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 8879 | bool desire_draw_buffers = false; |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 8880 | if (force_webgl_glsl_validation_) { |
| 8881 | desire_standard_derivatives = |
| 8882 | feature_str.find("GL_OES_standard_derivatives") != std::string::npos; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8883 | desire_frag_depth = |
| 8884 | feature_str.find("GL_EXT_frag_depth") != std::string::npos; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 8885 | desire_draw_buffers = |
| 8886 | feature_str.find("GL_EXT_draw_buffers") != std::string::npos; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8887 | } |
| 8888 | |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 8889 | if (desire_webgl_glsl_validation != force_webgl_glsl_validation_ || |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8890 | desire_standard_derivatives != derivatives_explicitly_enabled_ || |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 8891 | desire_frag_depth != frag_depth_explicitly_enabled_ || |
| 8892 | desire_draw_buffers != draw_buffers_explicitly_enabled_) { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8893 | force_webgl_glsl_validation_ |= desire_webgl_glsl_validation; |
| 8894 | derivatives_explicitly_enabled_ |= desire_standard_derivatives; |
| 8895 | frag_depth_explicitly_enabled_ |= desire_frag_depth; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 8896 | draw_buffers_explicitly_enabled_ |= desire_draw_buffers; |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8897 | InitializeShaderTranslator(); |
| 8898 | } |
| 8899 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 8900 | UpdateCapabilities(); |
| 8901 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 8902 | return error::kNoError; |
| 8903 | } |
| 8904 | |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8905 | error::Error GLES2DecoderImpl::HandleGetMultipleIntegervCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8906 | uint32 immediate_data_size, const cmds::GetMultipleIntegervCHROMIUM& c) { |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8907 | GLuint count = c.count; |
| 8908 | uint32 pnames_size; |
| 8909 | if (!SafeMultiplyUint32(count, sizeof(GLenum), &pnames_size)) { |
| 8910 | return error::kOutOfBounds; |
| 8911 | } |
| 8912 | const GLenum* pnames = GetSharedMemoryAs<const GLenum*>( |
| 8913 | c.pnames_shm_id, c.pnames_shm_offset, pnames_size); |
| 8914 | if (pnames == NULL) { |
| 8915 | return error::kOutOfBounds; |
| 8916 | } |
| 8917 | |
| 8918 | // We have to copy them since we use them twice so the client |
| 8919 | // can't change them between the time we validate them and the time we use |
| 8920 | // them. |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8921 | scoped_ptr<GLenum[]> enums(new GLenum[count]); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8922 | memcpy(enums.get(), pnames, pnames_size); |
| 8923 | |
| 8924 | // Count up the space needed for the result. |
| 8925 | uint32 num_results = 0; |
| 8926 | for (GLuint ii = 0; ii < count; ++ii) { |
| 8927 | uint32 num = util_.GLGetNumValuesReturned(enums[ii]); |
| 8928 | if (num == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8929 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 8930 | "glGetMulitpleCHROMIUM", enums[ii], "pname"); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8931 | return error::kNoError; |
| 8932 | } |
| 8933 | // Num will never be more than 4. |
| 8934 | DCHECK_LE(num, 4u); |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 8935 | if (!SafeAddUint32(num_results, num, &num_results)) { |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8936 | return error::kOutOfBounds; |
| 8937 | } |
| 8938 | } |
| 8939 | |
| 8940 | uint32 result_size = 0; |
| 8941 | if (!SafeMultiplyUint32(num_results, sizeof(GLint), &result_size)) { |
| 8942 | return error::kOutOfBounds; |
| 8943 | } |
| 8944 | |
| 8945 | if (result_size != static_cast<uint32>(c.size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8946 | LOCAL_SET_GL_ERROR( |
| 8947 | GL_INVALID_VALUE, |
| 8948 | "glGetMulitpleCHROMIUM", "bad size GL_INVALID_VALUE"); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8949 | return error::kNoError; |
| 8950 | } |
| 8951 | |
| 8952 | GLint* results = GetSharedMemoryAs<GLint*>( |
| 8953 | c.results_shm_id, c.results_shm_offset, result_size); |
| 8954 | if (results == NULL) { |
| 8955 | return error::kOutOfBounds; |
| 8956 | } |
| 8957 | |
| 8958 | // Check the results have been cleared in case the context was lost. |
| 8959 | for (uint32 ii = 0; ii < num_results; ++ii) { |
| 8960 | if (results[ii]) { |
| 8961 | return error::kInvalidArguments; |
| 8962 | } |
| 8963 | } |
| 8964 | |
| 8965 | // Get each result. |
| 8966 | GLint* start = results; |
| 8967 | for (GLuint ii = 0; ii < count; ++ii) { |
| 8968 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 8969 | if (!state_.GetStateAsGLint(enums[ii], results, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 8970 | !GetHelper(enums[ii], results, &num_written)) { |
[email protected] | b0ce098 | 2013-05-13 18:51:48 | [diff] [blame] | 8971 | DoGetIntegerv(enums[ii], results); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 8972 | } |
| 8973 | results += num_written; |
| 8974 | } |
| 8975 | |
| 8976 | // Just to verify. Should this be a DCHECK? |
| 8977 | if (static_cast<uint32>(results - start) != num_results) { |
| 8978 | return error::kOutOfBounds; |
| 8979 | } |
| 8980 | |
| 8981 | return error::kNoError; |
| 8982 | } |
| 8983 | |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 8984 | error::Error GLES2DecoderImpl::HandleGetProgramInfoCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8985 | uint32 immediate_data_size, const cmds::GetProgramInfoCHROMIUM& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8986 | GLuint program_id = static_cast<GLuint>(c.program); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 8987 | uint32 bucket_id = c.bucket_id; |
| 8988 | Bucket* bucket = CreateBucket(bucket_id); |
| 8989 | bucket->SetSize(sizeof(ProgramInfoHeader)); // in case we fail. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8990 | Program* program = NULL; |
| 8991 | program = GetProgram(program_id); |
| 8992 | if (!program || !program->IsValid()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 8993 | return error::kNoError; |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 8994 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8995 | program->GetProgramInfo(program_manager(), bucket); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 8996 | return error::kNoError; |
| 8997 | } |
| 8998 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 8999 | error::ContextLostReason GLES2DecoderImpl::GetContextLostReason() { |
| 9000 | switch (reset_status_) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9001 | case GL_NO_ERROR: |
| 9002 | // TODO(kbr): improve the precision of the error code in this case. |
| 9003 | // Consider delegating to context for error code if MakeCurrent fails. |
| 9004 | return error::kUnknown; |
| 9005 | case GL_GUILTY_CONTEXT_RESET_ARB: |
| 9006 | return error::kGuilty; |
| 9007 | case GL_INNOCENT_CONTEXT_RESET_ARB: |
| 9008 | return error::kInnocent; |
| 9009 | case GL_UNKNOWN_CONTEXT_RESET_ARB: |
| 9010 | return error::kUnknown; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9011 | } |
| 9012 | |
| 9013 | NOTREACHED(); |
| 9014 | return error::kUnknown; |
| 9015 | } |
| 9016 | |
| 9017 | bool GLES2DecoderImpl::WasContextLost() { |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9018 | if (reset_status_ != GL_NO_ERROR) { |
| 9019 | return true; |
| 9020 | } |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 9021 | if (context_->WasAllocatedUsingRobustnessExtension()) { |
| 9022 | GLenum status = GL_NO_ERROR; |
| 9023 | if (has_robustness_extension_) |
| 9024 | status = glGetGraphicsResetStatusARB(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9025 | if (status != GL_NO_ERROR) { |
| 9026 | // The graphics card was reset. Signal a lost context to the application. |
| 9027 | reset_status_ = status; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 9028 | reset_by_robustness_extension_ = true; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9029 | LOG(ERROR) << (surface_->IsOffscreen() ? "Offscreen" : "Onscreen") |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9030 | << " context lost via ARB/EXT_robustness. Reset status = " |
| 9031 | << GLES2Util::GetStringEnum(status); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9032 | return true; |
| 9033 | } |
| 9034 | } |
| 9035 | return false; |
| 9036 | } |
| 9037 | |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 9038 | bool GLES2DecoderImpl::WasContextLostByRobustnessExtension() { |
| 9039 | return WasContextLost() && reset_by_robustness_extension_; |
| 9040 | } |
| 9041 | |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9042 | void GLES2DecoderImpl::LoseContext(uint32 reset_status) { |
| 9043 | // Only loses the context once. |
| 9044 | if (reset_status_ != GL_NO_ERROR) { |
| 9045 | return; |
| 9046 | } |
| 9047 | |
| 9048 | // Marks this context as lost. |
| 9049 | reset_status_ = reset_status; |
| 9050 | current_decoder_error_ = error::kLostContext; |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9051 | } |
| 9052 | |
| 9053 | error::Error GLES2DecoderImpl::HandleLoseContextCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9054 | uint32 immediate_data_size, const cmds::LoseContextCHROMIUM& c) { |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9055 | GLenum current = static_cast<GLenum>(c.current); |
| 9056 | GLenum other = static_cast<GLenum>(c.other); |
| 9057 | if (!validators_->reset_status.IsValid(current)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9058 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 9059 | "glLoseContextCHROMIUM", current, "current"); |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9060 | } |
| 9061 | if (!validators_->reset_status.IsValid(other)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9062 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glLoseContextCHROMIUM", other, "other"); |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9063 | } |
| 9064 | group_->LoseContexts(other); |
| 9065 | reset_status_ = current; |
| 9066 | current_decoder_error_ = error::kLostContext; |
| 9067 | return error::kLostContext; |
| 9068 | } |
| 9069 | |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 9070 | error::Error GLES2DecoderImpl::HandleInsertSyncPointCHROMIUM( |
| 9071 | uint32 immediate_data_size, const cmds::InsertSyncPointCHROMIUM& c) { |
| 9072 | return error::kUnknownCommand; |
| 9073 | } |
| 9074 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 9075 | error::Error GLES2DecoderImpl::HandleWaitSyncPointCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9076 | uint32 immediate_data_size, const cmds::WaitSyncPointCHROMIUM& c) { |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 9077 | if (wait_sync_point_callback_.is_null()) |
| 9078 | return error::kNoError; |
| 9079 | |
| 9080 | return wait_sync_point_callback_.Run(c.sync_point) ? |
| 9081 | error::kNoError : error::kDeferCommandUntilLater; |
| 9082 | } |
| 9083 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9084 | bool GLES2DecoderImpl::GenQueriesEXTHelper( |
| 9085 | GLsizei n, const GLuint* client_ids) { |
| 9086 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9087 | if (query_manager_->GetQuery(client_ids[ii])) { |
| 9088 | return false; |
| 9089 | } |
| 9090 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9091 | // NOTE: We don't generate Query objects here. Only in BeginQueryEXT |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9092 | return true; |
| 9093 | } |
| 9094 | |
| 9095 | void GLES2DecoderImpl::DeleteQueriesEXTHelper( |
| 9096 | GLsizei n, const GLuint* client_ids) { |
| 9097 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9098 | QueryManager::Query* query = query_manager_->GetQuery(client_ids[ii]); |
| 9099 | if (query && !query->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9100 | if (query == state_.current_query.get()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9101 | state_.current_query = NULL; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9102 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9103 | query->Destroy(true); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9104 | query_manager_->RemoveQuery(client_ids[ii]); |
| 9105 | } |
| 9106 | } |
| 9107 | } |
| 9108 | |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 9109 | bool GLES2DecoderImpl::ProcessPendingQueries() { |
| 9110 | if (query_manager_.get() == NULL) { |
| 9111 | return false; |
| 9112 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9113 | if (!query_manager_->ProcessPendingQueries()) { |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 9114 | current_decoder_error_ = error::kOutOfBounds; |
| 9115 | } |
| 9116 | return query_manager_->HavePendingQueries(); |
| 9117 | } |
| 9118 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9119 | // Note that if there are no pending readpixels right now, |
| 9120 | // this function will call the callback immediately. |
| 9121 | void GLES2DecoderImpl::WaitForReadPixels(base::Closure callback) { |
| 9122 | if (features().use_async_readpixels && !pending_readpixel_fences_.empty()) { |
| 9123 | pending_readpixel_fences_.back()->callbacks.push_back(callback); |
| 9124 | } else { |
| 9125 | callback.Run(); |
| 9126 | } |
| 9127 | } |
| 9128 | |
| 9129 | void GLES2DecoderImpl::ProcessPendingReadPixels() { |
| 9130 | while (!pending_readpixel_fences_.empty() && |
| 9131 | pending_readpixel_fences_.front()->fence->HasCompleted()) { |
| 9132 | std::vector<base::Closure> callbacks = |
| 9133 | pending_readpixel_fences_.front()->callbacks; |
| 9134 | pending_readpixel_fences_.pop(); |
| 9135 | for (size_t i = 0; i < callbacks.size(); i++) { |
| 9136 | callbacks[i].Run(); |
| 9137 | } |
| 9138 | } |
| 9139 | } |
| 9140 | |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9141 | bool GLES2DecoderImpl::HasMoreIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9142 | return !pending_readpixel_fences_.empty() || |
| 9143 | async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9144 | } |
| 9145 | |
| 9146 | void GLES2DecoderImpl::PerformIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9147 | ProcessPendingReadPixels(); |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 9148 | if (!async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers()) |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9149 | return; |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 9150 | async_pixel_transfer_manager_->ProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9151 | ProcessFinishedAsyncTransfers(); |
| 9152 | } |
| 9153 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9154 | error::Error GLES2DecoderImpl::HandleBeginQueryEXT( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9155 | uint32 immediate_data_size, const cmds::BeginQueryEXT& c) { |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9156 | GLenum target = static_cast<GLenum>(c.target); |
| 9157 | GLuint client_id = static_cast<GLuint>(c.id); |
| 9158 | int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id); |
| 9159 | uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 9160 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9161 | switch (target) { |
| 9162 | case GL_COMMANDS_ISSUED_CHROMIUM: |
[email protected] | fb4bf582 | 2012-10-23 21:25:55 | [diff] [blame] | 9163 | case GL_LATENCY_QUERY_CHROMIUM: |
[email protected] | 5537605d | 2013-08-27 05:22:31 | [diff] [blame] | 9164 | case GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM: |
| 9165 | case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM: |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 9166 | case GL_GET_ERROR_QUERY_CHROMIUM: |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9167 | break; |
| 9168 | default: |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9169 | if (!features().occlusion_query_boolean) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9170 | LOCAL_SET_GL_ERROR( |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 9171 | GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 9172 | "not enabled for occlusion queries"); |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9173 | return error::kNoError; |
| 9174 | } |
| 9175 | break; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9176 | } |
| 9177 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9178 | // TODO(hubbe): Make it possible to have one query per type running at the |
| 9179 | // same time. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9180 | if (state_.current_query.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9181 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9182 | GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9183 | return error::kNoError; |
| 9184 | } |
| 9185 | |
| 9186 | if (client_id == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9187 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9188 | return error::kNoError; |
| 9189 | } |
| 9190 | |
| 9191 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 9192 | if (!query) { |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9193 | // TODO(gman): Decide if we need this check. |
| 9194 | // |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9195 | // Checks id was made by glGenQueries |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9196 | // |
| 9197 | // From the POV of OpenGL ES 2.0 you need to call glGenQueriesEXT |
| 9198 | // for all Query ids but from the POV of the command buffer service maybe |
| 9199 | // you don't. |
| 9200 | // |
| 9201 | // The client can enforce this. I don't think the service cares. |
| 9202 | // |
| 9203 | // IdAllocatorInterface* id_allocator = |
| 9204 | // group_->GetIdAllocator(id_namespaces::kQueries); |
| 9205 | // if (!id_allocator->InUse(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9206 | // LOCAL_SET_GL_ERROR( |
| 9207 | // GL_INVALID_OPERATION, |
| 9208 | // "glBeginQueryEXT", "id not made by glGenQueriesEXT"); |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9209 | // return error::kNoError; |
| 9210 | // } |
| 9211 | query = query_manager_->CreateQuery( |
| 9212 | target, client_id, sync_shm_id, sync_shm_offset); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9213 | } |
| 9214 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9215 | if (query->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9216 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9217 | GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9218 | return error::kNoError; |
| 9219 | } else if (query->shm_id() != sync_shm_id || |
| 9220 | query->shm_offset() != sync_shm_offset) { |
| 9221 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 9222 | return error::kInvalidArguments; |
| 9223 | } |
| 9224 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9225 | if (!query_manager_->BeginQuery(query)) { |
| 9226 | return error::kOutOfBounds; |
| 9227 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9228 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9229 | state_.current_query = query; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9230 | return error::kNoError; |
| 9231 | } |
| 9232 | |
| 9233 | error::Error GLES2DecoderImpl::HandleEndQueryEXT( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9234 | uint32 immediate_data_size, const cmds::EndQueryEXT& c) { |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9235 | GLenum target = static_cast<GLenum>(c.target); |
| 9236 | uint32 submit_count = static_cast<GLuint>(c.submit_count); |
| 9237 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9238 | if (!state_.current_query.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9239 | LOCAL_SET_GL_ERROR( |
| 9240 | GL_INVALID_OPERATION, "glEndQueryEXT", "No active query"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9241 | return error::kNoError; |
| 9242 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9243 | if (state_.current_query->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9244 | LOCAL_SET_GL_ERROR( |
| 9245 | GL_INVALID_OPERATION, |
| 9246 | "glEndQueryEXT", "target does not match active query"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9247 | return error::kNoError; |
| 9248 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9249 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9250 | if (!query_manager_->EndQuery(state_.current_query.get(), submit_count)) { |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9251 | return error::kOutOfBounds; |
| 9252 | } |
| 9253 | |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 9254 | query_manager_->ProcessPendingTransferQueries(); |
| 9255 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9256 | state_.current_query = NULL; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9257 | return error::kNoError; |
| 9258 | } |
| 9259 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9260 | bool GLES2DecoderImpl::GenVertexArraysOESHelper( |
| 9261 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9262 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9263 | if (GetVertexAttribManager(client_ids[ii])) { |
| 9264 | return false; |
| 9265 | } |
| 9266 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9267 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9268 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9269 | // Emulated VAO |
| 9270 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9271 | CreateVertexAttribManager(client_ids[ii], 0); |
| 9272 | } |
| 9273 | } else { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 9274 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9275 | |
| 9276 | glGenVertexArraysOES(n, service_ids.get()); |
| 9277 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9278 | CreateVertexAttribManager(client_ids[ii], service_ids[ii]); |
| 9279 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9280 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9281 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9282 | return true; |
| 9283 | } |
| 9284 | |
| 9285 | void GLES2DecoderImpl::DeleteVertexArraysOESHelper( |
| 9286 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9287 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9288 | VertexAttribManager* vao = |
| 9289 | GetVertexAttribManager(client_ids[ii]); |
| 9290 | if (vao && !vao->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9291 | if (state_.vertex_attrib_manager.get() == vao) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9292 | state_.vertex_attrib_manager = default_vertex_attrib_manager_; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9293 | } |
| 9294 | RemoveVertexAttribManager(client_ids[ii]); |
| 9295 | } |
| 9296 | } |
| 9297 | } |
| 9298 | |
| 9299 | void GLES2DecoderImpl::DoBindVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9300 | VertexAttribManager* vao = NULL; |
| 9301 | GLuint service_id = 0; |
| 9302 | if (client_id != 0) { |
| 9303 | vao = GetVertexAttribManager(client_id); |
| 9304 | if (!vao) { |
| 9305 | // Unlike most Bind* methods, the spec explicitly states that VertexArray |
| 9306 | // only allows names that have been previously generated. As such, we do |
| 9307 | // not generate new names here. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9308 | LOCAL_SET_GL_ERROR( |
| 9309 | GL_INVALID_OPERATION, |
| 9310 | "glBindVertexArrayOES", "bad vertex array id."); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9311 | current_decoder_error_ = error::kNoError; |
| 9312 | return; |
| 9313 | } else { |
| 9314 | service_id = vao->service_id(); |
| 9315 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9316 | } else { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9317 | vao = default_vertex_attrib_manager_.get(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9318 | } |
| 9319 | |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9320 | // Only set the VAO state if it's changed |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9321 | if (state_.vertex_attrib_manager.get() != vao) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9322 | state_.vertex_attrib_manager = vao; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9323 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9324 | EmulateVertexArrayState(); |
| 9325 | } else { |
| 9326 | glBindVertexArrayOES(service_id); |
| 9327 | } |
| 9328 | } |
| 9329 | } |
| 9330 | |
| 9331 | // Used when OES_vertex_array_object isn't natively supported |
| 9332 | void GLES2DecoderImpl::EmulateVertexArrayState() { |
| 9333 | // Setup the Vertex attribute state |
| 9334 | for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) { |
| 9335 | RestoreStateForAttrib(vv); |
| 9336 | } |
| 9337 | |
| 9338 | // Setup the element buffer |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 9339 | Buffer* element_array_buffer = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9340 | state_.vertex_attrib_manager->element_array_buffer(); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9341 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 9342 | element_array_buffer ? element_array_buffer->service_id() : 0); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9343 | } |
| 9344 | |
| 9345 | bool GLES2DecoderImpl::DoIsVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9346 | const VertexAttribManager* vao = |
| 9347 | GetVertexAttribManager(client_id); |
| 9348 | return vao && vao->IsValid() && !vao->IsDeleted(); |
| 9349 | } |
| 9350 | |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9351 | error::Error GLES2DecoderImpl::HandleCreateStreamTextureCHROMIUM( |
| 9352 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9353 | const cmds::CreateStreamTextureCHROMIUM& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9354 | if (!features().chromium_stream_texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9355 | LOCAL_SET_GL_ERROR( |
| 9356 | GL_INVALID_OPERATION, |
| 9357 | "glOpenStreamTextureCHROMIUM", "not supported."); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9358 | return error::kNoError; |
| 9359 | } |
| 9360 | |
| 9361 | uint32 client_id = c.client_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9362 | typedef cmds::CreateStreamTextureCHROMIUM::Result Result; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9363 | Result* result = GetSharedMemoryAs<Result*>( |
| 9364 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9365 | |
[email protected] | e508126 | 2012-01-05 23:09:03 | [diff] [blame] | 9366 | if (!result) |
| 9367 | return error::kOutOfBounds; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9368 | *result = GL_ZERO; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9369 | TextureRef* texture_ref = texture_manager()->GetTexture(client_id); |
| 9370 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9371 | LOCAL_SET_GL_ERROR( |
| 9372 | GL_INVALID_VALUE, |
| 9373 | "glCreateStreamTextureCHROMIUM", "bad texture id."); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9374 | return error::kNoError; |
| 9375 | } |
| 9376 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9377 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9378 | if (texture->IsStreamTexture()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9379 | LOCAL_SET_GL_ERROR( |
| 9380 | GL_INVALID_OPERATION, |
| 9381 | "glCreateStreamTextureCHROMIUM", "is already a stream texture."); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9382 | return error::kNoError; |
| 9383 | } |
| 9384 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9385 | if (texture->target() && texture->target() != GL_TEXTURE_EXTERNAL_OES) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9386 | LOCAL_SET_GL_ERROR( |
| 9387 | GL_INVALID_OPERATION, |
| 9388 | "glCreateStreamTextureCHROMIUM", |
| 9389 | "is already bound to incompatible target."); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9390 | return error::kNoError; |
| 9391 | } |
| 9392 | |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 9393 | if (!stream_texture_manager()) |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9394 | return error::kInvalidArguments; |
| 9395 | |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 9396 | GLuint object_id = stream_texture_manager()->CreateStreamTexture( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9397 | texture->service_id(), client_id); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9398 | |
| 9399 | if (object_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9400 | texture_manager()->SetStreamTexture(texture_ref, true); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9401 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9402 | LOCAL_SET_GL_ERROR( |
| 9403 | GL_OUT_OF_MEMORY, |
| 9404 | "glCreateStreamTextureCHROMIUM", "failed to create platform texture."); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9405 | } |
| 9406 | |
| 9407 | *result = object_id; |
| 9408 | return error::kNoError; |
| 9409 | } |
| 9410 | |
| 9411 | error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( |
| 9412 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9413 | const cmds::DestroyStreamTextureCHROMIUM& c) { |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9414 | GLuint client_id = c.texture; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9415 | TextureRef* texture_ref = texture_manager()->GetTexture(client_id); |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 9416 | if (texture_ref && texture_manager()->IsStreamTextureOwner(texture_ref)) { |
| 9417 | if (!stream_texture_manager()) |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9418 | return error::kInvalidArguments; |
| 9419 | |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 9420 | stream_texture_manager()->DestroyStreamTexture(texture_ref->service_id()); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9421 | texture_manager()->SetStreamTexture(texture_ref, false); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9422 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9423 | LOCAL_SET_GL_ERROR( |
| 9424 | GL_INVALID_VALUE, |
| 9425 | "glDestroyStreamTextureCHROMIUM", "bad texture id."); |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 9426 | } |
| 9427 | |
| 9428 | return error::kNoError; |
| 9429 | } |
| 9430 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9431 | #if defined(OS_MACOSX) |
| 9432 | void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { |
| 9433 | TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( |
| 9434 | texture_id); |
| 9435 | if (it != texture_to_io_surface_map_.end()) { |
| 9436 | // Found a previous IOSurface bound to this texture; release it. |
| 9437 | CFTypeRef surface = it->second; |
| 9438 | CFRelease(surface); |
| 9439 | texture_to_io_surface_map_.erase(it); |
| 9440 | } |
| 9441 | } |
| 9442 | #endif |
| 9443 | |
| 9444 | void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( |
| 9445 | GLenum target, GLsizei width, GLsizei height, |
| 9446 | GLuint io_surface_id, GLuint plane) { |
| 9447 | #if defined(OS_MACOSX) |
| 9448 | if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9449 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9450 | GL_INVALID_OPERATION, |
| 9451 | "glTexImageIOSurface2DCHROMIUM", "only supported on desktop GL."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9452 | return; |
| 9453 | } |
| 9454 | |
| 9455 | IOSurfaceSupport* surface_support = IOSurfaceSupport::Initialize(); |
| 9456 | if (!surface_support) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9457 | LOCAL_SET_GL_ERROR( |
| 9458 | GL_INVALID_OPERATION, |
| 9459 | "glTexImageIOSurface2DCHROMIUM", "only supported on 10.6."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9460 | return; |
| 9461 | } |
| 9462 | |
| 9463 | if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 9464 | // This might be supported in the future, and if we could require |
| 9465 | // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we |
| 9466 | // could delete a lot of code. For now, perform strict validation so we |
| 9467 | // know what's going on. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9468 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9469 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9470 | "glTexImageIOSurface2DCHROMIUM", |
| 9471 | "requires TEXTURE_RECTANGLE_ARB target"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9472 | return; |
| 9473 | } |
| 9474 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 9475 | // Default target might be conceptually valid, but disallow it to avoid |
| 9476 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9477 | TextureRef* texture_ref = |
| 9478 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9479 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9480 | LOCAL_SET_GL_ERROR( |
| 9481 | GL_INVALID_OPERATION, |
| 9482 | "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9483 | return; |
| 9484 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9485 | |
| 9486 | // Look up the new IOSurface. Note that because of asynchrony |
| 9487 | // between processes this might fail; during live resizing the |
| 9488 | // plugin process might allocate and release an IOSurface before |
| 9489 | // this process gets a chance to look it up. Hold on to any old |
| 9490 | // IOSurface in this case. |
| 9491 | CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); |
| 9492 | if (!surface) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9493 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9494 | GL_INVALID_OPERATION, |
| 9495 | "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9496 | return; |
| 9497 | } |
| 9498 | |
| 9499 | // Release any IOSurface previously bound to this texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9500 | ReleaseIOSurfaceForTexture(texture_ref->service_id()); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9501 | |
| 9502 | // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. |
| 9503 | texture_to_io_surface_map_.insert( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9504 | std::make_pair(texture_ref->service_id(), surface)); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9505 | |
| 9506 | CGLContextObj context = |
| 9507 | static_cast<CGLContextObj>(context_->GetHandle()); |
| 9508 | |
| 9509 | CGLError err = surface_support->CGLTexImageIOSurface2D( |
| 9510 | context, |
| 9511 | target, |
| 9512 | GL_RGBA, |
| 9513 | width, |
| 9514 | height, |
| 9515 | GL_BGRA, |
| 9516 | GL_UNSIGNED_INT_8_8_8_8_REV, |
| 9517 | surface, |
| 9518 | plane); |
| 9519 | |
| 9520 | if (err != kCGLNoError) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9521 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9522 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9523 | "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9524 | return; |
| 9525 | } |
| 9526 | |
| 9527 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9528 | texture_ref, target, 0, GL_RGBA, width, height, 1, 0, |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9529 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); |
| 9530 | |
| 9531 | #else |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9532 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9533 | "glTexImageIOSurface2DCHROMIUM", "not supported."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9534 | #endif |
| 9535 | } |
| 9536 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9537 | static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { |
| 9538 | switch (internalformat) { |
| 9539 | case GL_RGB565: |
| 9540 | return GL_RGB; |
| 9541 | case GL_RGBA4: |
| 9542 | return GL_RGBA; |
| 9543 | case GL_RGB5_A1: |
| 9544 | return GL_RGBA; |
| 9545 | case GL_RGB8_OES: |
| 9546 | return GL_RGB; |
| 9547 | case GL_RGBA8_OES: |
| 9548 | return GL_RGBA; |
| 9549 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 9550 | return GL_LUMINANCE_ALPHA; |
| 9551 | case GL_LUMINANCE8_EXT: |
| 9552 | return GL_LUMINANCE; |
| 9553 | case GL_ALPHA8_EXT: |
| 9554 | return GL_ALPHA; |
| 9555 | case GL_RGBA32F_EXT: |
| 9556 | return GL_RGBA; |
| 9557 | case GL_RGB32F_EXT: |
| 9558 | return GL_RGB; |
| 9559 | case GL_ALPHA32F_EXT: |
| 9560 | return GL_ALPHA; |
| 9561 | case GL_LUMINANCE32F_EXT: |
| 9562 | return GL_LUMINANCE; |
| 9563 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 9564 | return GL_LUMINANCE_ALPHA; |
| 9565 | case GL_RGBA16F_EXT: |
| 9566 | return GL_RGBA; |
| 9567 | case GL_RGB16F_EXT: |
| 9568 | return GL_RGB; |
| 9569 | case GL_ALPHA16F_EXT: |
| 9570 | return GL_ALPHA; |
| 9571 | case GL_LUMINANCE16F_EXT: |
| 9572 | return GL_LUMINANCE; |
| 9573 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 9574 | return GL_LUMINANCE_ALPHA; |
| 9575 | case GL_BGRA8_EXT: |
| 9576 | return GL_BGRA_EXT; |
| 9577 | default: |
| 9578 | return GL_NONE; |
| 9579 | } |
| 9580 | } |
| 9581 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9582 | void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9583 | GLenum target, GLuint source_id, GLuint dest_id, GLint level, |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 9584 | GLenum internal_format, GLenum dest_type) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9585 | TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 9586 | TextureRef* source_texture_ref = GetTexture(source_id); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9587 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9588 | if (!source_texture_ref || !dest_texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9589 | LOCAL_SET_GL_ERROR( |
| 9590 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9591 | return; |
| 9592 | } |
| 9593 | |
| 9594 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9595 | LOCAL_SET_GL_ERROR( |
| 9596 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid texture target"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9597 | return; |
| 9598 | } |
| 9599 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9600 | Texture* source_texture = source_texture_ref->texture(); |
| 9601 | Texture* dest_texture = dest_texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9602 | if (dest_texture->target() != GL_TEXTURE_2D || |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 9603 | (source_texture->target() != GL_TEXTURE_2D && |
| 9604 | source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 9605 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 9606 | "glCopyTextureCHROMIUM", |
| 9607 | "invalid texture target binding"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9608 | return; |
| 9609 | } |
| 9610 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9611 | int source_width, source_height, dest_width, dest_height; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9612 | |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 9613 | if (source_texture->IsStreamTexture()) { |
| 9614 | DCHECK_EQ(source_texture->target(), |
| 9615 | static_cast<GLenum>(GL_TEXTURE_EXTERNAL_OES)); |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 9616 | DCHECK(stream_texture_manager()); |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 9617 | StreamTexture* stream_tex = |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 9618 | stream_texture_manager()->LookupStreamTexture( |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 9619 | source_texture->service_id()); |
| 9620 | if (!stream_tex) { |
| 9621 | LOCAL_SET_GL_ERROR( |
| 9622 | GL_INVALID_VALUE, |
| 9623 | "glCopyTextureChromium", "Stream texture lookup failed"); |
| 9624 | return; |
| 9625 | } |
| 9626 | gfx::Size size = stream_tex->GetSize(); |
| 9627 | source_width = size.width(); |
| 9628 | source_height = size.height(); |
| 9629 | if (source_width <= 0 || source_height <= 0) { |
| 9630 | LOCAL_SET_GL_ERROR( |
| 9631 | GL_INVALID_VALUE, |
| 9632 | "glCopyTextureChromium", "invalid streamtexture size"); |
| 9633 | return; |
| 9634 | } |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 9635 | } else { |
| 9636 | if (!source_texture->GetLevelSize( |
| 9637 | source_texture->target(), 0, &source_width, &source_height)) { |
| 9638 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 9639 | "glCopyTextureChromium", |
| 9640 | "source texture has no level 0"); |
| 9641 | return; |
| 9642 | } |
| 9643 | |
| 9644 | // Check that this type of texture is allowed. |
| 9645 | if (!texture_manager()->ValidForTarget( |
| 9646 | source_texture->target(), level, source_width, source_height, 1)) { |
| 9647 | LOCAL_SET_GL_ERROR( |
| 9648 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); |
| 9649 | return; |
| 9650 | } |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 9651 | } |
| 9652 | |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 9653 | // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 9654 | // needed because it takes 10s of milliseconds to initialize. |
| 9655 | if (!copy_texture_CHROMIUM_.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9656 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 9657 | copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
[email protected] | 07a0cc3 | 2013-02-28 00:36:27 | [diff] [blame] | 9658 | copy_texture_CHROMIUM_->Initialize(this); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 9659 | RestoreCurrentFramebufferBindings(); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9660 | if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 9661 | return; |
| 9662 | } |
| 9663 | |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 9664 | GLenum dest_type_previous; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9665 | GLenum dest_internal_format; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9666 | bool dest_level_defined = dest_texture->GetLevelSize( |
| 9667 | GL_TEXTURE_2D, level, &dest_width, &dest_height); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9668 | |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9669 | if (dest_level_defined) { |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 9670 | dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9671 | &dest_internal_format); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9672 | } |
| 9673 | |
| 9674 | // Resize the destination texture to the dimensions of the source texture. |
| 9675 | if (!dest_level_defined || dest_width != source_width || |
| 9676 | dest_height != source_height || |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 9677 | dest_internal_format != internal_format || |
| 9678 | dest_type_previous != dest_type) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9679 | // Ensure that the glTexImage2D succeeds. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9680 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9681 | glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 9682 | glTexImage2D( |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9683 | GL_TEXTURE_2D, level, internal_format, source_width, source_height, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9684 | 0, internal_format, dest_type, NULL); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9685 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9686 | if (error != GL_NO_ERROR) { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 9687 | RestoreCurrentTexture2DBindings(&state_); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9688 | return; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9689 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9690 | |
| 9691 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9692 | dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9693 | source_height, 1, 0, internal_format, dest_type, true); |
[email protected] | f702471 | 2012-05-15 21:30:25 | [diff] [blame] | 9694 | } else { |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9695 | texture_manager()->SetLevelCleared( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9696 | dest_texture_ref, GL_TEXTURE_2D, level, true); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9697 | } |
| 9698 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 9699 | DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 9700 | |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 9701 | // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 9702 | // before presenting. |
| 9703 | if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
| 9704 | // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
| 9705 | // instead of using default matrix crbug.com/226218. |
| 9706 | const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
| 9707 | 0.0f, 1.0f, 0.0f, 0.0f, |
| 9708 | 0.0f, 0.0f, 1.0f, 0.0f, |
| 9709 | 0.0f, 0.0f, 0.0f, 1.0f}; |
| 9710 | copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| 9711 | this, |
| 9712 | source_texture->target(), |
| 9713 | dest_texture->target(), |
| 9714 | source_texture->service_id(), |
| 9715 | dest_texture->service_id(), level, |
| 9716 | source_width, source_height, |
| 9717 | unpack_flip_y_, |
| 9718 | unpack_premultiply_alpha_, |
| 9719 | unpack_unpremultiply_alpha_, |
| 9720 | default_matrix); |
| 9721 | } else { |
| 9722 | copy_texture_CHROMIUM_->DoCopyTexture( |
| 9723 | this, |
| 9724 | source_texture->target(), |
| 9725 | dest_texture->target(), |
| 9726 | source_texture->service_id(), |
| 9727 | dest_texture->service_id(), level, |
| 9728 | source_width, source_height, |
| 9729 | unpack_flip_y_, |
| 9730 | unpack_premultiply_alpha_, |
| 9731 | unpack_unpremultiply_alpha_); |
| 9732 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 9733 | |
| 9734 | DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9735 | } |
| 9736 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9737 | static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
| 9738 | switch (internalformat) { |
| 9739 | case GL_RGB565: |
| 9740 | return GL_UNSIGNED_SHORT_5_6_5; |
| 9741 | case GL_RGBA4: |
| 9742 | return GL_UNSIGNED_SHORT_4_4_4_4; |
| 9743 | case GL_RGB5_A1: |
| 9744 | return GL_UNSIGNED_SHORT_5_5_5_1; |
| 9745 | case GL_RGB8_OES: |
| 9746 | return GL_UNSIGNED_BYTE; |
| 9747 | case GL_RGBA8_OES: |
| 9748 | return GL_UNSIGNED_BYTE; |
| 9749 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 9750 | return GL_UNSIGNED_BYTE; |
| 9751 | case GL_LUMINANCE8_EXT: |
| 9752 | return GL_UNSIGNED_BYTE; |
| 9753 | case GL_ALPHA8_EXT: |
| 9754 | return GL_UNSIGNED_BYTE; |
| 9755 | case GL_RGBA32F_EXT: |
| 9756 | return GL_FLOAT; |
| 9757 | case GL_RGB32F_EXT: |
| 9758 | return GL_FLOAT; |
| 9759 | case GL_ALPHA32F_EXT: |
| 9760 | return GL_FLOAT; |
| 9761 | case GL_LUMINANCE32F_EXT: |
| 9762 | return GL_FLOAT; |
| 9763 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 9764 | return GL_FLOAT; |
| 9765 | case GL_RGBA16F_EXT: |
| 9766 | return GL_HALF_FLOAT_OES; |
| 9767 | case GL_RGB16F_EXT: |
| 9768 | return GL_HALF_FLOAT_OES; |
| 9769 | case GL_ALPHA16F_EXT: |
| 9770 | return GL_HALF_FLOAT_OES; |
| 9771 | case GL_LUMINANCE16F_EXT: |
| 9772 | return GL_HALF_FLOAT_OES; |
| 9773 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 9774 | return GL_HALF_FLOAT_OES; |
| 9775 | case GL_BGRA8_EXT: |
| 9776 | return GL_UNSIGNED_BYTE; |
| 9777 | default: |
| 9778 | return GL_NONE; |
| 9779 | } |
| 9780 | } |
| 9781 | |
| 9782 | void GLES2DecoderImpl::DoTexStorage2DEXT( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 9783 | GLenum target, |
| 9784 | GLint levels, |
| 9785 | GLenum internal_format, |
| 9786 | GLsizei width, |
| 9787 | GLsizei height) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 9788 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT"); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 9789 | if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 9790 | TextureManager::ComputeMipMapCount(target, width, height, 1) < levels) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9791 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9792 | GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9793 | return; |
| 9794 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9795 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9796 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9797 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9798 | LOCAL_SET_GL_ERROR( |
| 9799 | GL_INVALID_OPERATION, |
| 9800 | "glTexStorage2DEXT", "unknown texture for target"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9801 | return; |
| 9802 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9803 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9804 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9805 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9806 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9807 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9808 | LOCAL_SET_GL_ERROR( |
| 9809 | GL_INVALID_OPERATION, |
| 9810 | "glTexStorage2DEXT", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9811 | return; |
| 9812 | } |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9813 | |
| 9814 | GLenum format = ExtractFormatFromStorageFormat(internal_format); |
| 9815 | GLenum type = ExtractTypeFromStorageFormat(internal_format); |
| 9816 | |
| 9817 | { |
| 9818 | GLsizei level_width = width; |
| 9819 | GLsizei level_height = height; |
| 9820 | uint32 estimated_size = 0; |
| 9821 | for (int ii = 0; ii < levels; ++ii) { |
| 9822 | uint32 level_size = 0; |
| 9823 | if (!GLES2Util::ComputeImageDataSizes( |
| 9824 | level_width, level_height, format, type, state_.unpack_alignment, |
| 9825 | &estimated_size, NULL, NULL) || |
| 9826 | !SafeAddUint32(estimated_size, level_size, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9827 | LOCAL_SET_GL_ERROR( |
| 9828 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9829 | return; |
| 9830 | } |
| 9831 | level_width = std::max(1, level_width >> 1); |
| 9832 | level_height = std::max(1, level_height >> 1); |
| 9833 | } |
| 9834 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9835 | LOCAL_SET_GL_ERROR( |
| 9836 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9837 | return; |
| 9838 | } |
| 9839 | } |
| 9840 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9841 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage2DEXT"); |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 9842 | glTexStorage2DEXT(target, levels, internal_format, width, height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9843 | GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage2DEXT"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9844 | if (error == GL_NO_ERROR) { |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9845 | GLsizei level_width = width; |
| 9846 | GLsizei level_height = height; |
| 9847 | for (int ii = 0; ii < levels; ++ii) { |
| 9848 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9849 | texture_ref, target, ii, format, |
| 9850 | level_width, level_height, 1, 0, format, type, false); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9851 | level_width = std::max(1, level_width >> 1); |
| 9852 | level_height = std::max(1, level_height >> 1); |
| 9853 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9854 | texture->SetImmutable(true); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9855 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9856 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9857 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9858 | error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9859 | uint32 immediate_data_size, const cmds::GenMailboxCHROMIUM& c) { |
[email protected] | baed42c | 2013-10-01 05:06:35 | [diff] [blame] | 9860 | return error::kUnknownCommand; |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9861 | } |
| 9862 | |
| 9863 | void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, |
| 9864 | const GLbyte* mailbox) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 9865 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 9866 | "context", logger_.GetLogPrefix(), |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 9867 | "mailbox[0]", static_cast<unsigned char>(mailbox[0])); |
| 9868 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9869 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9870 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9871 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9872 | LOCAL_SET_GL_ERROR( |
| 9873 | GL_INVALID_OPERATION, |
| 9874 | "glProduceTextureCHROMIUM", "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9875 | return; |
| 9876 | } |
| 9877 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 9878 | Texture* produced = texture_manager()->Produce(texture_ref); |
| 9879 | if (!produced) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9880 | LOCAL_SET_GL_ERROR( |
| 9881 | GL_INVALID_OPERATION, |
| 9882 | "glProduceTextureCHROMIUM", "invalid texture"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9883 | return; |
| 9884 | } |
| 9885 | |
| 9886 | if (!group_->mailbox_manager()->ProduceTexture( |
| 9887 | target, |
| 9888 | *reinterpret_cast<const MailboxName*>(mailbox), |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 9889 | produced)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9890 | LOCAL_SET_GL_ERROR( |
| 9891 | GL_INVALID_OPERATION, |
| 9892 | "glProduceTextureCHROMIUM", "invalid mailbox name"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9893 | return; |
| 9894 | } |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9895 | } |
| 9896 | |
| 9897 | void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, |
| 9898 | const GLbyte* mailbox) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 9899 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 9900 | "context", logger_.GetLogPrefix(), |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 9901 | "mailbox[0]", static_cast<unsigned char>(mailbox[0])); |
| 9902 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 9903 | scoped_refptr<TextureRef> texture_ref = |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9904 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9905 | if (!texture_ref.get()) { |
| 9906 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 9907 | "glConsumeTextureCHROMIUM", |
| 9908 | "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9909 | return; |
| 9910 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 9911 | GLuint client_id = texture_ref->client_id(); |
| 9912 | if (!client_id) { |
| 9913 | LOCAL_SET_GL_ERROR( |
| 9914 | GL_INVALID_OPERATION, |
| 9915 | "glConsumeTextureCHROMIUM", "unknown texture for target"); |
| 9916 | return; |
| 9917 | } |
| 9918 | Texture* texture = |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9919 | group_->mailbox_manager()->ConsumeTexture( |
| 9920 | target, |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 9921 | *reinterpret_cast<const MailboxName*>(mailbox)); |
| 9922 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9923 | LOCAL_SET_GL_ERROR( |
| 9924 | GL_INVALID_OPERATION, |
| 9925 | "glConsumeTextureCHROMIUM", "invalid mailbox name"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9926 | return; |
| 9927 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 9928 | if (texture->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9929 | LOCAL_SET_GL_ERROR( |
| 9930 | GL_INVALID_OPERATION, |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 9931 | "glConsumeTextureCHROMIUM", "invalid target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9932 | return; |
| 9933 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 9934 | |
| 9935 | DeleteTexturesHelper(1, &client_id); |
| 9936 | texture_ref = texture_manager()->Consume(client_id, texture); |
| 9937 | glBindTexture(target, texture_ref->service_id()); |
| 9938 | |
| 9939 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
| 9940 | unit.bind_target = target; |
| 9941 | switch (target) { |
| 9942 | case GL_TEXTURE_2D: |
| 9943 | unit.bound_texture_2d = texture_ref; |
| 9944 | break; |
| 9945 | case GL_TEXTURE_CUBE_MAP: |
| 9946 | unit.bound_texture_cube_map = texture_ref; |
| 9947 | break; |
| 9948 | case GL_TEXTURE_EXTERNAL_OES: |
| 9949 | unit.bound_texture_external_oes = texture_ref; |
| 9950 | break; |
| 9951 | case GL_TEXTURE_RECTANGLE_ARB: |
| 9952 | unit.bound_texture_rectangle_arb = texture_ref; |
| 9953 | break; |
| 9954 | default: |
| 9955 | NOTREACHED(); // Validation should prevent us getting here. |
| 9956 | break; |
| 9957 | } |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 9958 | } |
| 9959 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 9960 | void GLES2DecoderImpl::DoInsertEventMarkerEXT( |
| 9961 | GLsizei length, const GLchar* marker) { |
| 9962 | if (!marker) { |
| 9963 | marker = ""; |
| 9964 | } |
| 9965 | debug_marker_manager_.SetMarker( |
| 9966 | length ? std::string(marker, length) : std::string(marker)); |
| 9967 | } |
| 9968 | |
| 9969 | void GLES2DecoderImpl::DoPushGroupMarkerEXT( |
| 9970 | GLsizei length, const GLchar* marker) { |
| 9971 | if (!marker) { |
| 9972 | marker = ""; |
| 9973 | } |
| 9974 | debug_marker_manager_.PushGroup( |
| 9975 | length ? std::string(marker, length) : std::string(marker)); |
| 9976 | } |
| 9977 | |
| 9978 | void GLES2DecoderImpl::DoPopGroupMarkerEXT(void) { |
| 9979 | debug_marker_manager_.PopGroup(); |
| 9980 | } |
| 9981 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 9982 | void GLES2DecoderImpl::DoBindTexImage2DCHROMIUM( |
| 9983 | GLenum target, GLint image_id) { |
| 9984 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM"); |
| 9985 | if (target != GL_TEXTURE_2D) { |
| 9986 | // This might be supported in the future. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9987 | LOCAL_SET_GL_ERROR( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 9988 | GL_INVALID_OPERATION, |
| 9989 | "glBindTexImage2DCHROMIUM", "requires TEXTURE_2D target"); |
| 9990 | return; |
| 9991 | } |
| 9992 | |
| 9993 | // Default target might be conceptually valid, but disallow it to avoid |
| 9994 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9995 | TextureRef* texture_ref = |
| 9996 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9997 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9998 | LOCAL_SET_GL_ERROR( |
| 9999 | GL_INVALID_OPERATION, |
| 10000 | "glBindTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10001 | return; |
| 10002 | } |
| 10003 | |
| 10004 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 10005 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10006 | LOCAL_SET_GL_ERROR( |
| 10007 | GL_INVALID_OPERATION, |
| 10008 | "glBindTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10009 | return; |
| 10010 | } |
| 10011 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10012 | { |
| 10013 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 10014 | "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10015 | if (!gl_image->BindTexImage()) { |
| 10016 | LOCAL_SET_GL_ERROR( |
| 10017 | GL_INVALID_OPERATION, |
| 10018 | "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID"); |
| 10019 | return; |
| 10020 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10021 | } |
| 10022 | |
| 10023 | gfx::Size size = gl_image->GetSize(); |
| 10024 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10025 | texture_ref, target, 0, GL_RGBA, size.width(), size.height(), 1, 0, |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10026 | GL_RGBA, GL_UNSIGNED_BYTE, true); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10027 | texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10028 | } |
| 10029 | |
| 10030 | void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( |
| 10031 | GLenum target, GLint image_id) { |
| 10032 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); |
| 10033 | if (target != GL_TEXTURE_2D) { |
| 10034 | // This might be supported in the future. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10035 | LOCAL_SET_GL_ERROR( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10036 | GL_INVALID_OPERATION, |
| 10037 | "glReleaseTexImage2DCHROMIUM", "requires TEXTURE_2D target"); |
| 10038 | return; |
| 10039 | } |
| 10040 | |
| 10041 | // Default target might be conceptually valid, but disallow it to avoid |
| 10042 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10043 | TextureRef* texture_ref = |
| 10044 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10045 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10046 | LOCAL_SET_GL_ERROR( |
| 10047 | GL_INVALID_OPERATION, |
| 10048 | "glReleaseTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10049 | return; |
| 10050 | } |
| 10051 | |
| 10052 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 10053 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10054 | LOCAL_SET_GL_ERROR( |
| 10055 | GL_INVALID_OPERATION, |
| 10056 | "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10057 | return; |
| 10058 | } |
| 10059 | |
| 10060 | // Do nothing when image is not currently bound. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10061 | if (texture_ref->texture()->GetLevelImage(target, 0) != gl_image) |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10062 | return; |
| 10063 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10064 | { |
| 10065 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 10066 | "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10067 | gl_image->ReleaseTexImage(); |
| 10068 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10069 | |
| 10070 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10071 | texture_ref, target, 0, GL_RGBA, 0, 0, 1, 0, |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10072 | GL_RGBA, GL_UNSIGNED_BYTE, false); |
| 10073 | } |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 10074 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10075 | error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10076 | uint32 immediate_data_size, const cmds::TraceBeginCHROMIUM& c) { |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10077 | Bucket* bucket = GetBucket(c.bucket_id); |
| 10078 | if (!bucket || bucket->size() == 0) { |
| 10079 | return error::kInvalidArguments; |
| 10080 | } |
| 10081 | std::string command_name; |
| 10082 | if (!bucket->GetAsString(&command_name)) { |
| 10083 | return error::kInvalidArguments; |
| 10084 | } |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10085 | TRACE_EVENT_COPY_ASYNC_BEGIN0("gpu", command_name.c_str(), this); |
| 10086 | if (!gpu_tracer_->Begin(command_name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10087 | LOCAL_SET_GL_ERROR( |
| 10088 | GL_INVALID_OPERATION, |
| 10089 | "glTraceBeginCHROMIUM", "unable to create begin trace"); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10090 | return error::kNoError; |
| 10091 | } |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10092 | return error::kNoError; |
| 10093 | } |
| 10094 | |
| 10095 | void GLES2DecoderImpl::DoTraceEndCHROMIUM() { |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10096 | if (gpu_tracer_->CurrentName().empty()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10097 | LOCAL_SET_GL_ERROR( |
| 10098 | GL_INVALID_OPERATION, |
| 10099 | "glTraceEndCHROMIUM", "no trace begin found"); |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10100 | return; |
| 10101 | } |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10102 | TRACE_EVENT_COPY_ASYNC_END0("gpu", gpu_tracer_->CurrentName().c_str(), this); |
| 10103 | gpu_tracer_->End(); |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10104 | } |
| 10105 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 10106 | void GLES2DecoderImpl::DoDrawBuffersEXT( |
| 10107 | GLsizei count, const GLenum* bufs) { |
| 10108 | if (count > static_cast<GLsizei>(group_->max_draw_buffers())) { |
| 10109 | LOCAL_SET_GL_ERROR( |
| 10110 | GL_INVALID_VALUE, |
| 10111 | "glDrawBuffersEXT", "greater than GL_MAX_DRAW_BUFFERS_EXT"); |
| 10112 | return; |
| 10113 | } |
| 10114 | |
| 10115 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 10116 | if (framebuffer) { |
| 10117 | for (GLsizei i = 0; i < count; ++i) { |
| 10118 | if (bufs[i] != static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i) && |
| 10119 | bufs[i] != GL_NONE) { |
| 10120 | LOCAL_SET_GL_ERROR( |
| 10121 | GL_INVALID_OPERATION, |
| 10122 | "glDrawBuffersEXT", |
| 10123 | "bufs[i] not GL_NONE or GL_COLOR_ATTACHMENTi_EXT"); |
| 10124 | return; |
| 10125 | } |
| 10126 | } |
| 10127 | glDrawBuffersARB(count, bufs); |
| 10128 | framebuffer->SetDrawBuffers(count, bufs); |
| 10129 | } else { // backbuffer |
| 10130 | if (count > 1 || |
| 10131 | (bufs[0] != GL_BACK && bufs[0] != GL_NONE)) { |
| 10132 | LOCAL_SET_GL_ERROR( |
| 10133 | GL_INVALID_OPERATION, |
| 10134 | "glDrawBuffersEXT", |
| 10135 | "more than one buffer or bufs not GL_NONE or GL_BACK"); |
| 10136 | return; |
| 10137 | } |
| 10138 | GLenum mapped_buf = bufs[0]; |
| 10139 | if (GetBackbufferServiceId() != 0 && // emulated backbuffer |
| 10140 | bufs[0] == GL_BACK) { |
| 10141 | mapped_buf = GL_COLOR_ATTACHMENT0; |
| 10142 | } |
| 10143 | glDrawBuffersARB(count, &mapped_buf); |
| 10144 | group_->set_draw_buffer(bufs[0]); |
| 10145 | } |
| 10146 | } |
| 10147 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10148 | bool GLES2DecoderImpl::ValidateAsyncTransfer( |
| 10149 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10150 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10151 | GLenum target, |
| 10152 | GLint level, |
| 10153 | const void * data) { |
| 10154 | // We only support async uploads to 2D textures for now. |
| 10155 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10156 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10157 | return false; |
| 10158 | } |
| 10159 | // We only support uploads to level zero for now. |
| 10160 | if (level != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10161 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "level != 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10162 | return false; |
| 10163 | } |
| 10164 | // A transfer buffer must be bound, even for asyncTexImage2D. |
| 10165 | if (data == NULL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10166 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, "buffer == 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10167 | return false; |
| 10168 | } |
| 10169 | // We only support one async transfer in progress. |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10170 | if (!texture_ref || |
| 10171 | async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10172 | LOCAL_SET_GL_ERROR( |
| 10173 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10174 | function_name, "transfer already in progress"); |
| 10175 | return false; |
| 10176 | } |
| 10177 | return true; |
| 10178 | } |
| 10179 | |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10180 | error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10181 | uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) { |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10182 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10183 | GLenum target = static_cast<GLenum>(c.target); |
| 10184 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10185 | // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use |
| 10186 | // unsigned integer for internalformat. |
| 10187 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10188 | GLsizei width = static_cast<GLsizei>(c.width); |
| 10189 | GLsizei height = static_cast<GLsizei>(c.height); |
| 10190 | GLint border = static_cast<GLint>(c.border); |
| 10191 | GLenum format = static_cast<GLenum>(c.format); |
| 10192 | GLenum type = static_cast<GLenum>(c.type); |
| 10193 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 10194 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
| 10195 | uint32 pixels_size; |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10196 | |
| 10197 | // TODO(epenner): Move this and copies of this memory validation |
| 10198 | // into ValidateTexImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10199 | if (!GLES2Util::ComputeImageDataSizes( |
| 10200 | width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, |
| 10201 | NULL)) { |
| 10202 | return error::kOutOfBounds; |
| 10203 | } |
| 10204 | const void* pixels = NULL; |
| 10205 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 10206 | pixels = GetSharedMemoryAs<const void*>( |
| 10207 | pixels_shm_id, pixels_shm_offset, pixels_size); |
| 10208 | if (!pixels) { |
| 10209 | return error::kOutOfBounds; |
| 10210 | } |
| 10211 | } |
| 10212 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10213 | TextureManager::DoTextImage2DArguments args = { |
| 10214 | target, level, internal_format, width, height, border, format, type, |
| 10215 | pixels, pixels_size}; |
| 10216 | TextureRef* texture_ref; |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10217 | // All the normal glTexSubImage2D validation. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10218 | if (!texture_manager()->ValidateTexImage2D( |
| 10219 | &state_, "glAsyncTexImage2DCHROMIUM", args, &texture_ref)) { |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10220 | return error::kNoError; |
| 10221 | } |
| 10222 | |
| 10223 | // Extra async validation. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10224 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10225 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10226 | "glAsyncTexImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10227 | return error::kNoError; |
| 10228 | |
| 10229 | // Don't allow async redefinition of a textures. |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10230 | if (texture->IsDefined()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10231 | LOCAL_SET_GL_ERROR( |
| 10232 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10233 | "glAsyncTexImage2DCHROMIUM", "already defined"); |
| 10234 | return error::kNoError; |
| 10235 | } |
| 10236 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10237 | if (!EnsureGPUMemoryAvailable(pixels_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10238 | LOCAL_SET_GL_ERROR( |
| 10239 | GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10240 | return error::kNoError; |
| 10241 | } |
| 10242 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10243 | // We know the memory/size is safe, so get the real shared memory since |
| 10244 | // it might need to be duped to prevent use-after-free of the memory. |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 10245 | gpu::Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10246 | base::SharedMemory* shared_memory = buffer.shared_memory; |
| 10247 | uint32 shm_size = buffer.size; |
| 10248 | uint32 shm_data_offset = c.pixels_shm_offset; |
| 10249 | uint32 shm_data_size = pixels_size; |
| 10250 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10251 | // Setup the parameters. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 10252 | AsyncTexImage2DParams tex_params = { |
| 10253 | target, level, static_cast<GLenum>(internal_format), |
| 10254 | width, height, border, format, type}; |
| 10255 | AsyncMemoryParams mem_params = { |
| 10256 | shared_memory, shm_size, shm_data_offset, shm_data_size}; |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10257 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10258 | // Set up the async state if needed, and make the texture |
| 10259 | // immutable so the async state stays valid. The level info |
| 10260 | // is set up lazily when the transfer completes. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10261 | AsyncPixelTransferDelegate* delegate = |
| 10262 | async_pixel_transfer_manager_->CreatePixelTransferDelegate(texture_ref, |
| 10263 | tex_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10264 | texture->SetImmutable(true); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10265 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10266 | delegate->AsyncTexImage2D( |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10267 | tex_params, |
| 10268 | mem_params, |
| 10269 | base::Bind(&TextureManager::SetLevelInfoFromParams, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10270 | // The callback is only invoked if the transfer delegate still |
| 10271 | // exists, which implies through manager->texture_ref->state |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10272 | // ownership that both of these pointers are valid. |
| 10273 | base::Unretained(texture_manager()), |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10274 | base::Unretained(texture_ref), |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10275 | tex_params)); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10276 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10277 | } |
| 10278 | |
| 10279 | error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10280 | uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) { |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10281 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10282 | GLenum target = static_cast<GLenum>(c.target); |
| 10283 | GLint level = static_cast<GLint>(c.level); |
| 10284 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 10285 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 10286 | GLsizei width = static_cast<GLsizei>(c.width); |
| 10287 | GLsizei height = static_cast<GLsizei>(c.height); |
| 10288 | GLenum format = static_cast<GLenum>(c.format); |
| 10289 | GLenum type = static_cast<GLenum>(c.type); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10290 | |
| 10291 | // TODO(epenner): Move this and copies of this memory validation |
| 10292 | // into ValidateTexSubImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10293 | uint32 data_size; |
| 10294 | if (!GLES2Util::ComputeImageDataSizes( |
| 10295 | width, height, format, type, state_.unpack_alignment, &data_size, |
| 10296 | NULL, NULL)) { |
| 10297 | return error::kOutOfBounds; |
| 10298 | } |
| 10299 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 10300 | c.data_shm_id, c.data_shm_offset, data_size); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10301 | |
| 10302 | // All the normal glTexSubImage2D validation. |
| 10303 | error::Error error = error::kNoError; |
| 10304 | if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2DCHROMIUM", |
| 10305 | target, level, xoffset, yoffset, width, height, format, type, pixels)) { |
| 10306 | return error; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10307 | } |
| 10308 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10309 | // Extra async validation. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10310 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10311 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10312 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10313 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10314 | "glAsyncTexSubImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10315 | return error::kNoError; |
| 10316 | |
| 10317 | // Guarantee async textures are always 'cleared' as follows: |
| 10318 | // - AsyncTexImage2D can not redefine an existing texture |
| 10319 | // - AsyncTexImage2D must initialize the entire image via non-null buffer. |
| 10320 | // - AsyncTexSubImage2D clears synchronously if not already cleared. |
| 10321 | // - Textures become immutable after an async call. |
| 10322 | // This way we know in all cases that an async texture is always clear. |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10323 | if (!texture->SafeToRenderFrom()) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10324 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, |
| 10325 | target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10326 | LOCAL_SET_GL_ERROR( |
| 10327 | GL_OUT_OF_MEMORY, |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 10328 | "glAsyncTexSubImage2DCHROMIUM", "dimensions too big"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10329 | return error::kNoError; |
| 10330 | } |
| 10331 | } |
| 10332 | |
| 10333 | // We know the memory/size is safe, so get the real shared memory since |
| 10334 | // it might need to be duped to prevent use-after-free of the memory. |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 10335 | gpu::Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10336 | base::SharedMemory* shared_memory = buffer.shared_memory; |
| 10337 | uint32 shm_size = buffer.size; |
| 10338 | uint32 shm_data_offset = c.data_shm_offset; |
| 10339 | uint32 shm_data_size = data_size; |
| 10340 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10341 | // Setup the parameters. |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 10342 | AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10343 | width, height, format, type}; |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 10344 | AsyncMemoryParams mem_params = {shared_memory, shm_size, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10345 | shm_data_offset, shm_data_size}; |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10346 | AsyncPixelTransferDelegate* delegate = |
| 10347 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 10348 | if (!delegate) { |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10349 | // TODO(epenner): We may want to enforce exclusive use |
| 10350 | // of async APIs in which case this should become an error, |
| 10351 | // (the texture should have been async defined). |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 10352 | AsyncTexImage2DParams define_params = {target, level, |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10353 | 0, 0, 0, 0, 0, 0}; |
| 10354 | texture->GetLevelSize(target, level, &define_params.width, |
| 10355 | &define_params.height); |
| 10356 | texture->GetLevelType(target, level, &define_params.type, |
| 10357 | &define_params.internal_format); |
| 10358 | // Set up the async state if needed, and make the texture |
| 10359 | // immutable so the async state stays valid. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10360 | delegate = async_pixel_transfer_manager_->CreatePixelTransferDelegate( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10361 | texture_ref, define_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10362 | texture->SetImmutable(true); |
| 10363 | } |
| 10364 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10365 | delegate->AsyncTexSubImage2D(tex_params, mem_params); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10366 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10367 | } |
| 10368 | |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 10369 | error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM( |
| 10370 | uint32 immediate_data_size, const cmds::WaitAsyncTexImage2DCHROMIUM& c) { |
| 10371 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); |
| 10372 | GLenum target = static_cast<GLenum>(c.target); |
| 10373 | |
| 10374 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10375 | LOCAL_SET_GL_ERROR( |
| 10376 | GL_INVALID_ENUM, "glWaitAsyncTexImage2DCHROMIUM", "target"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 10377 | return error::kNoError; |
| 10378 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10379 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10380 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10381 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10382 | LOCAL_SET_GL_ERROR( |
| 10383 | GL_INVALID_OPERATION, |
| 10384 | "glWaitAsyncTexImage2DCHROMIUM", "unknown texture"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 10385 | return error::kNoError; |
| 10386 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10387 | AsyncPixelTransferDelegate* delegate = |
| 10388 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 10389 | if (!delegate) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10390 | LOCAL_SET_GL_ERROR( |
| 10391 | GL_INVALID_OPERATION, |
| 10392 | "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); |
| 10393 | return error::kNoError; |
| 10394 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10395 | delegate->WaitForTransferCompletion(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 10396 | ProcessFinishedAsyncTransfers(); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 10397 | return error::kNoError; |
| 10398 | } |
| 10399 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 10400 | void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( |
| 10401 | TextureRef* texture_ref) { |
| 10402 | Texture* texture = texture_ref->texture(); |
| 10403 | DoDidUseTexImageIfNeeded(texture, texture->target()); |
| 10404 | } |
| 10405 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 10406 | // Include the auto-generated part of this file. We split this because it means |
| 10407 | // we can easily edit the non-auto generated parts right here in this file |
| 10408 | // instead of having to edit some template or the code generator. |
| 10409 | #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 10410 | |
| 10411 | } // namespace gles2 |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 10412 | } // namespace gpu |