[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] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 20 | #include "base/debug/trace_event_synthetic_delay.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 21 | #include "base/memory/scoped_ptr.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 22 | #include "base/strings/string_number_conversions.h" |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 23 | #include "base/strings/string_split.h" |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 24 | #include "build/build_config.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 25 | #define GLES2_GPU_SERVICE 1 |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 26 | #include "gpu/command_buffer/common/debug_marker_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 27 | #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 28 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 29 | #include "gpu/command_buffer/common/id_allocator.h" |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 30 | #include "gpu/command_buffer/common/mailbox.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 31 | #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
| 32 | #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 33 | #include "gpu/command_buffer/service/buffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 34 | #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 35 | #include "gpu/command_buffer/service/context_group.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 36 | #include "gpu/command_buffer/service/context_state.h" |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 37 | #include "gpu/command_buffer/service/error_state.h" |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 38 | #include "gpu/command_buffer/service/feature_info.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 39 | #include "gpu/command_buffer/service/framebuffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 40 | #include "gpu/command_buffer/service/gl_utils.h" |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 41 | #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 42 | #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 43 | #include "gpu/command_buffer/service/gpu_state_tracer.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 44 | #include "gpu/command_buffer/service/gpu_switches.h" |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 45 | #include "gpu/command_buffer/service/gpu_tracer.h" |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 46 | #include "gpu/command_buffer/service/image_manager.h" |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 47 | #include "gpu/command_buffer/service/mailbox_manager.h" |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 48 | #include "gpu/command_buffer/service/memory_tracking.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 49 | #include "gpu/command_buffer/service/program_manager.h" |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 50 | #include "gpu/command_buffer/service/query_manager.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 51 | #include "gpu/command_buffer/service/renderbuffer_manager.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 52 | #include "gpu/command_buffer/service/shader_manager.h" |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 53 | #include "gpu/command_buffer/service/shader_translator.h" |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 54 | #include "gpu/command_buffer/service/shader_translator_cache.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 { |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 231 | uint8 arg_flags; // How to handle the arguments for this command |
| 232 | uint8 cmd_flags; // How to handle this command |
| 233 | uint16 arg_count; // How many arguments are expected for this command. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 234 | }; |
| 235 | |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 236 | // cmds::name::cmd_flags, |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 237 | // A table of CommandInfo for all the commands. |
| 238 | const CommandInfo g_command_info[] = { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 239 | #define GLES2_CMD_OP(name) { \ |
| 240 | cmds::name::kArgFlags, \ |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 241 | cmds::name::cmd_flags, \ |
| 242 | sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, }, /* NOLINT */ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 243 | |
| 244 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 245 | |
| 246 | #undef GLES2_CMD_OP |
| 247 | }; |
| 248 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 249 | // Return true if a character belongs to the ASCII subset as defined in |
| 250 | // GLSL ES 1.0 spec section 3.1. |
| 251 | static bool CharacterIsValidForGLES(unsigned char c) { |
| 252 | // Printing characters are valid except " $ ` @ \ ' DEL. |
| 253 | if (c >= 32 && c <= 126 && |
| 254 | c != '"' && |
| 255 | c != '$' && |
| 256 | c != '`' && |
| 257 | c != '@' && |
| 258 | c != '\\' && |
| 259 | c != '\'') { |
| 260 | return true; |
| 261 | } |
| 262 | // Horizontal tab, line feed, vertical tab, form feed, carriage return |
| 263 | // are also valid. |
| 264 | if (c >= 9 && c <= 13) { |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | return false; |
| 269 | } |
| 270 | |
| 271 | static bool StringIsValidForGLES(const char* str) { |
| 272 | for (; *str; ++str) { |
| 273 | if (!CharacterIsValidForGLES(*str)) { |
| 274 | return false; |
| 275 | } |
| 276 | } |
| 277 | return true; |
| 278 | } |
| 279 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 280 | // Wrapper for glEnable/glDisable that doesn't suck. |
| 281 | static void EnableDisable(GLenum pname, bool enable) { |
| 282 | if (enable) { |
| 283 | glEnable(pname); |
| 284 | } else { |
| 285 | glDisable(pname); |
| 286 | } |
| 287 | } |
| 288 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 289 | // This class prevents any GL errors that occur when it is in scope from |
| 290 | // being reported to the client. |
| 291 | class ScopedGLErrorSuppressor { |
| 292 | public: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 293 | explicit ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 294 | const char* function_name, ErrorState* error_state); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 295 | ~ScopedGLErrorSuppressor(); |
| 296 | private: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 297 | const char* function_name_; |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 298 | ErrorState* error_state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 299 | DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); |
| 300 | }; |
| 301 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 302 | // Temporarily changes a decoder's bound texture and restore it when this |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 303 | // object goes out of scope. Also temporarily switches to using active texture |
| 304 | // unit zero in case the client has changed that to something invalid. |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 305 | class ScopedTextureBinder { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 306 | public: |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 307 | ScopedTextureBinder(ContextState* state, GLuint id, GLenum target); |
| 308 | ~ScopedTextureBinder(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 309 | |
| 310 | private: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 311 | ContextState* state_; |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 312 | GLenum target_; |
| 313 | DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | // Temporarily changes a decoder's bound render buffer and restore it when this |
| 317 | // object goes out of scope. |
| 318 | class ScopedRenderBufferBinder { |
| 319 | public: |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 320 | ScopedRenderBufferBinder(ContextState* state, GLuint id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 321 | ~ScopedRenderBufferBinder(); |
| 322 | |
| 323 | private: |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 324 | ContextState* state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 325 | DISALLOW_COPY_AND_ASSIGN(ScopedRenderBufferBinder); |
| 326 | }; |
| 327 | |
| 328 | // Temporarily changes a decoder's bound frame buffer and restore it when this |
| 329 | // object goes out of scope. |
| 330 | class ScopedFrameBufferBinder { |
| 331 | public: |
| 332 | ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
| 333 | ~ScopedFrameBufferBinder(); |
| 334 | |
| 335 | private: |
| 336 | GLES2DecoderImpl* decoder_; |
| 337 | DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); |
| 338 | }; |
| 339 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 340 | // Temporarily changes a decoder's bound frame buffer to a resolved version of |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 341 | // the multisampled offscreen render buffer if that buffer is multisampled, and, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 342 | // if it is bound or enforce_internal_framebuffer is true. If internal is |
| 343 | // true, the resolved framebuffer is not visible to the parent. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 344 | class ScopedResolvedFrameBufferBinder { |
| 345 | public: |
[email protected] | e7e3803 | 2011-07-26 17:25:25 | [diff] [blame] | 346 | ScopedResolvedFrameBufferBinder(GLES2DecoderImpl* decoder, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 347 | bool enforce_internal_framebuffer, |
| 348 | bool internal); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 349 | ~ScopedResolvedFrameBufferBinder(); |
| 350 | |
| 351 | private: |
| 352 | GLES2DecoderImpl* decoder_; |
| 353 | bool resolve_and_bind_; |
| 354 | DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); |
| 355 | }; |
| 356 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 357 | // Encapsulates an OpenGL texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 358 | class BackTexture { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 359 | public: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 360 | explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 361 | ~BackTexture(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 362 | |
| 363 | // Create a new render texture. |
| 364 | void Create(); |
| 365 | |
| 366 | // Set the initial size and format of a render texture or resize it. |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 367 | bool AllocateStorage(const gfx::Size& size, GLenum format, bool zero); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 368 | |
| 369 | // Copy the contents of the currently bound frame buffer. |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 370 | void Copy(const gfx::Size& size, GLenum format); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 371 | |
| 372 | // Destroy the render texture. This must be explicitly called before |
| 373 | // destroying this object. |
| 374 | void Destroy(); |
| 375 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 376 | // Invalidate the texture. This can be used when a context is lost and it is |
| 377 | // not possible to make it current in order to free the resource. |
| 378 | void Invalidate(); |
| 379 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 380 | GLuint id() const { |
| 381 | return id_; |
| 382 | } |
| 383 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 384 | gfx::Size size() const { |
| 385 | return size_; |
| 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] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 410 | bool AllocateStorage(const FeatureInfo* feature_info, |
| 411 | const gfx::Size& size, |
| 412 | GLenum format, |
| 413 | GLsizei samples); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 414 | |
| 415 | // Destroy the render buffer. This must be explicitly called before destroying |
| 416 | // this object. |
| 417 | void Destroy(); |
| 418 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 419 | // Invalidate the render buffer. This can be used when a context is lost and |
| 420 | // it is not possible to make it current in order to free the resource. |
| 421 | void Invalidate(); |
| 422 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 423 | GLuint id() const { |
| 424 | return id_; |
| 425 | } |
| 426 | |
| 427 | private: |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 428 | RenderbufferManager* renderbuffer_manager_; |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 429 | MemoryTypeTracker memory_tracker_; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 430 | ContextState* state_; |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 431 | size_t bytes_allocated_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 432 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 433 | DISALLOW_COPY_AND_ASSIGN(BackRenderbuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 434 | }; |
| 435 | |
| 436 | // Encapsulates an OpenGL frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 437 | class BackFramebuffer { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 438 | public: |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 439 | explicit BackFramebuffer(GLES2DecoderImpl* decoder); |
| 440 | ~BackFramebuffer(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 441 | |
| 442 | // Create a new frame buffer. |
| 443 | void Create(); |
| 444 | |
| 445 | // Attach a color render buffer to a frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 446 | void AttachRenderTexture(BackTexture* texture); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 447 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 448 | // Attach a render buffer to a frame buffer. Note that this unbinds any |
| 449 | // currently bound frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 450 | void AttachRenderBuffer(GLenum target, BackRenderbuffer* render_buffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 451 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 452 | // Destroy the frame buffer. This must be explicitly called before destroying |
| 453 | // this object. |
| 454 | void Destroy(); |
| 455 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 456 | // Invalidate the frame buffer. This can be used when a context is lost and it |
| 457 | // is not possible to make it current in order to free the resource. |
| 458 | void Invalidate(); |
| 459 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 460 | // See glCheckFramebufferStatusEXT. |
| 461 | GLenum CheckStatus(); |
| 462 | |
| 463 | GLuint id() const { |
| 464 | return id_; |
| 465 | } |
| 466 | |
| 467 | private: |
| 468 | GLES2DecoderImpl* decoder_; |
| 469 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 470 | DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 471 | }; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 472 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 473 | struct FenceCallback { |
| 474 | explicit FenceCallback() |
| 475 | : fence(gfx::GLFence::Create()) { |
| 476 | DCHECK(fence); |
| 477 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 478 | std::vector<base::Closure> callbacks; |
| 479 | scoped_ptr<gfx::GLFence> fence; |
| 480 | }; |
| 481 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 482 | // } // anonymous namespace. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 483 | |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 484 | bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, |
| 485 | uint32* service_texture_id) { |
| 486 | return false; |
| 487 | } |
| 488 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 489 | GLES2Decoder::GLES2Decoder() |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 490 | : initialized_(false), |
| 491 | debug_(false), |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 492 | log_commands_(false) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 493 | } |
| 494 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 495 | GLES2Decoder::~GLES2Decoder() { |
| 496 | } |
| 497 | |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 498 | void GLES2Decoder::BeginDecoding() {} |
| 499 | |
| 500 | void GLES2Decoder::EndDecoding() {} |
| 501 | |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 502 | // This class implements GLES2Decoder so we don't have to expose all the GLES2 |
| 503 | // cmd stuff to outside this class. |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 504 | class GLES2DecoderImpl : public GLES2Decoder, |
| 505 | public FramebufferManager::TextureDetachObserver { |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 506 | public: |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 507 | // Used by PrepForSetUniformByLocation to validate types. |
| 508 | struct BaseUniformInfo { |
| 509 | const GLenum* const valid_types; |
| 510 | size_t num_valid_types; |
| 511 | }; |
| 512 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 513 | explicit GLES2DecoderImpl(ContextGroup* group); |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 514 | virtual ~GLES2DecoderImpl(); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 515 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 516 | // Overridden from AsyncAPIInterface. |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 517 | virtual Error DoCommand(unsigned int command, |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 518 | unsigned int arg_count, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 519 | const void* args) OVERRIDE; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 520 | |
| 521 | // Overridden from AsyncAPIInterface. |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 522 | virtual const char* GetCommandName(unsigned int command_id) const OVERRIDE; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 523 | |
| 524 | // Overridden from GLES2Decoder. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 525 | virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
| 526 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 527 | bool offscreen, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 528 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 529 | const DisallowedFeatures& disallowed_features, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 530 | const std::vector<int32>& attribs) OVERRIDE; |
| 531 | virtual void Destroy(bool have_context) OVERRIDE; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 532 | virtual void SetSurface( |
| 533 | const scoped_refptr<gfx::GLSurface>& surface) OVERRIDE; |
[email protected] | aba551b | 2014-02-08 03:38:32 | [diff] [blame] | 534 | virtual void ProduceFrontBuffer(const Mailbox& mailbox) OVERRIDE; |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 535 | virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) OVERRIDE; |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 536 | void UpdateParentTextureInfo(); |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 537 | virtual bool MakeCurrent() OVERRIDE; |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 538 | virtual GLES2Util* GetGLES2Util() OVERRIDE { return &util_; } |
| 539 | virtual gfx::GLContext* GetGLContext() OVERRIDE { return context_.get(); } |
| 540 | virtual ContextGroup* GetContextGroup() OVERRIDE { return group_.get(); } |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 541 | virtual Capabilities GetCapabilities() OVERRIDE; |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 542 | virtual void RestoreState(const ContextState* prev_state) const OVERRIDE; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 543 | |
| 544 | virtual void RestoreActiveTexture() const OVERRIDE { |
| 545 | state_.RestoreActiveTexture(); |
| 546 | } |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 547 | virtual void RestoreAllTextureUnitBindings( |
| 548 | const ContextState* prev_state) const OVERRIDE { |
| 549 | state_.RestoreAllTextureUnitBindings(prev_state); |
[email protected] | 21700451 | 2013-05-10 21:25:55 | [diff] [blame] | 550 | } |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 551 | virtual void RestoreAttribute(unsigned index) const OVERRIDE { |
| 552 | state_.RestoreAttribute(index); |
| 553 | } |
| 554 | virtual void RestoreBufferBindings() const OVERRIDE { |
| 555 | state_.RestoreBufferBindings(); |
| 556 | } |
| 557 | virtual void RestoreGlobalState() const OVERRIDE { |
| 558 | state_.RestoreGlobalState(); |
| 559 | } |
| 560 | virtual void RestoreProgramBindings() const OVERRIDE { |
| 561 | state_.RestoreProgramBindings(); |
| 562 | } |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 563 | virtual void RestoreTextureUnitBindings(unsigned unit) const OVERRIDE { |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 564 | state_.RestoreTextureUnitBindings(unit, NULL); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 565 | } |
| 566 | virtual void RestoreFramebufferBindings() const OVERRIDE; |
| 567 | virtual void RestoreTextureState(unsigned service_id) const OVERRIDE; |
| 568 | |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 569 | virtual void ClearAllAttributes() const OVERRIDE; |
| 570 | virtual void RestoreAllAttributes() const OVERRIDE; |
| 571 | |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 572 | virtual QueryManager* GetQueryManager() OVERRIDE { |
| 573 | return query_manager_.get(); |
| 574 | } |
| 575 | virtual VertexArrayManager* GetVertexArrayManager() OVERRIDE { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 576 | return vertex_array_manager_.get(); |
| 577 | } |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 578 | virtual bool ProcessPendingQueries() OVERRIDE; |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 579 | virtual bool HasMoreIdleWork() OVERRIDE; |
| 580 | virtual void PerformIdleWork() OVERRIDE; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 581 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 582 | virtual void WaitForReadPixels(base::Closure callback) OVERRIDE; |
| 583 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 584 | virtual void SetResizeCallback( |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 585 | const base::Callback<void(gfx::Size, float)>& callback) OVERRIDE; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 586 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 587 | virtual Logger* GetLogger() OVERRIDE; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 588 | |
| 589 | virtual void BeginDecoding() OVERRIDE; |
| 590 | virtual void EndDecoding() OVERRIDE; |
| 591 | |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 592 | virtual ErrorState* GetErrorState() OVERRIDE; |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 593 | virtual const ContextState* GetContextState() OVERRIDE { return &state_; } |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 594 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 595 | virtual void SetShaderCacheCallback( |
| 596 | const ShaderCacheCallback& callback) OVERRIDE; |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 597 | virtual void SetWaitSyncPointCallback( |
| 598 | const WaitSyncPointCallback& callback) OVERRIDE; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 599 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 600 | virtual AsyncPixelTransferManager* |
| 601 | GetAsyncPixelTransferManager() OVERRIDE; |
| 602 | virtual void ResetAsyncPixelTransferManagerForTest() OVERRIDE; |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 603 | virtual void SetAsyncPixelTransferManagerForTest( |
| 604 | AsyncPixelTransferManager* manager) OVERRIDE; |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 605 | void ProcessFinishedAsyncTransfers(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 606 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 607 | virtual bool GetServiceTextureId(uint32 client_texture_id, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 608 | uint32* service_texture_id) OVERRIDE; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 609 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 610 | virtual uint32 GetTextureUploadCount() OVERRIDE; |
| 611 | virtual base::TimeDelta GetTotalTextureUploadTime() OVERRIDE; |
| 612 | virtual base::TimeDelta GetTotalProcessingCommandsTime() OVERRIDE; |
[email protected] | dc25dda | 2012-09-27 21:36:30 | [diff] [blame] | 613 | virtual void AddProcessingCommandsTime(base::TimeDelta) OVERRIDE; |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 614 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 615 | // Restores the current state to the user's settings. |
| 616 | void RestoreCurrentFramebufferBindings(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 617 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 618 | // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
| 619 | void ApplyDirtyState(); |
| 620 | |
| 621 | // These check the state of the currently bound framebuffer or the |
| 622 | // backbuffer if no framebuffer is bound. |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 623 | // If all_draw_buffers is false, only check with COLOR_ATTACHMENT0, otherwise |
| 624 | // check with all attached and enabled color attachments. |
| 625 | bool BoundFramebufferHasColorAttachmentWithAlpha(bool all_draw_buffers); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 626 | bool BoundFramebufferHasDepthAttachment(); |
| 627 | bool BoundFramebufferHasStencilAttachment(); |
| 628 | |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 629 | virtual error::ContextLostReason GetContextLostReason() OVERRIDE; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 630 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 631 | // Overridden from FramebufferManager::TextureDetachObserver: |
| 632 | virtual void OnTextureRefDetachedFromFramebuffer( |
| 633 | TextureRef* texture) OVERRIDE; |
| 634 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 635 | // Helpers to facilitate calling into compatible extensions. |
| 636 | static void RenderbufferStorageMultisampleHelper( |
| 637 | const FeatureInfo* feature_info, |
| 638 | GLenum target, |
| 639 | GLsizei samples, |
| 640 | GLenum internal_format, |
| 641 | GLsizei width, |
| 642 | GLsizei height); |
| 643 | |
| 644 | void BlitFramebufferHelper(GLint srcX0, |
| 645 | GLint srcY0, |
| 646 | GLint srcX1, |
| 647 | GLint srcY1, |
| 648 | GLint dstX0, |
| 649 | GLint dstY0, |
| 650 | GLint dstX1, |
| 651 | GLint dstY1, |
| 652 | GLbitfield mask, |
| 653 | GLenum filter); |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 654 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 655 | private: |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 656 | friend class ScopedFrameBufferBinder; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 657 | friend class ScopedResolvedFrameBufferBinder; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 658 | friend class BackFramebuffer; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 659 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 660 | // Initialize or re-initialize the shader translator. |
| 661 | bool InitializeShaderTranslator(); |
| 662 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 663 | void UpdateCapabilities(); |
| 664 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 665 | // Helpers for the glGen and glDelete functions. |
| 666 | bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 667 | void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 668 | bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 669 | void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 670 | bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 671 | void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 672 | bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
| 673 | void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 674 | bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
| 675 | void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 676 | bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
| 677 | void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 678 | |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 679 | // Workarounds |
| 680 | void OnFboChanged() const; |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 681 | void OnUseFramebuffer() const; |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 682 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 683 | // TODO(gman): Cache these pointers? |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 684 | BufferManager* buffer_manager() { |
| 685 | return group_->buffer_manager(); |
| 686 | } |
| 687 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 688 | RenderbufferManager* renderbuffer_manager() { |
| 689 | return group_->renderbuffer_manager(); |
| 690 | } |
| 691 | |
| 692 | FramebufferManager* framebuffer_manager() { |
| 693 | return group_->framebuffer_manager(); |
| 694 | } |
| 695 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 696 | ProgramManager* program_manager() { |
| 697 | return group_->program_manager(); |
| 698 | } |
| 699 | |
| 700 | ShaderManager* shader_manager() { |
| 701 | return group_->shader_manager(); |
| 702 | } |
| 703 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 704 | const TextureManager* texture_manager() const { |
| 705 | return group_->texture_manager(); |
| 706 | } |
| 707 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 708 | TextureManager* texture_manager() { |
| 709 | return group_->texture_manager(); |
| 710 | } |
| 711 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 712 | MailboxManager* mailbox_manager() { |
| 713 | return group_->mailbox_manager(); |
| 714 | } |
| 715 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 716 | ImageManager* image_manager() { |
| 717 | return group_->image_manager(); |
| 718 | } |
| 719 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 720 | VertexArrayManager* vertex_array_manager() { |
| 721 | return vertex_array_manager_.get(); |
| 722 | } |
| 723 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 724 | MemoryTracker* memory_tracker() { |
| 725 | return group_->memory_tracker(); |
| 726 | } |
| 727 | |
| 728 | bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
| 729 | MemoryTracker* tracker = memory_tracker(); |
| 730 | if (tracker) { |
| 731 | return tracker->EnsureGPUMemoryAvailable(estimated_size); |
| 732 | } |
| 733 | return true; |
| 734 | } |
| 735 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 736 | bool IsOffscreenBufferMultisampled() const { |
| 737 | return offscreen_target_samples_ > 1; |
| 738 | } |
| 739 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 740 | // Creates a Texture for the given texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 741 | TextureRef* CreateTexture( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 742 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 743 | return texture_manager()->CreateTexture(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | // Gets the texture info for the given texture. Returns NULL if none exists. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 747 | TextureRef* GetTexture(GLuint client_id) const { |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 748 | return texture_manager()->GetTexture(client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | // Deletes the texture info for the given texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 752 | void RemoveTexture(GLuint client_id) { |
| 753 | texture_manager()->RemoveTexture(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 754 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 755 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 756 | // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| 757 | // or regular back buffer). |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 758 | gfx::Size GetBoundReadFrameBufferSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 759 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 760 | // Get the format of the currently bound frame buffer (either FBO or regular |
| 761 | // back buffer) |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 762 | GLenum GetBoundReadFrameBufferTextureType(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 763 | GLenum GetBoundReadFrameBufferInternalFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 764 | GLenum GetBoundDrawFrameBufferInternalFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 765 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 766 | // Wrapper for CompressedTexImage2D commands. |
| 767 | error::Error DoCompressedTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 768 | GLenum target, |
| 769 | GLint level, |
| 770 | GLenum internal_format, |
| 771 | GLsizei width, |
| 772 | GLsizei height, |
| 773 | GLint border, |
| 774 | GLsizei image_size, |
| 775 | const void* data); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 776 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 777 | // Wrapper for CompressedTexSubImage2D. |
| 778 | void DoCompressedTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 779 | GLenum target, |
| 780 | GLint level, |
| 781 | GLint xoffset, |
| 782 | GLint yoffset, |
| 783 | GLsizei width, |
| 784 | GLsizei height, |
| 785 | GLenum format, |
| 786 | GLsizei imageSize, |
| 787 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 788 | |
| 789 | // Wrapper for CopyTexImage2D. |
| 790 | void DoCopyTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 791 | GLenum target, |
| 792 | GLint level, |
| 793 | GLenum internal_format, |
| 794 | GLint x, |
| 795 | GLint y, |
| 796 | GLsizei width, |
| 797 | GLsizei height, |
| 798 | GLint border); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 799 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 800 | // Wrapper for SwapBuffers. |
| 801 | void DoSwapBuffers(); |
| 802 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 803 | // Wrapper for CopyTexSubImage2D. |
| 804 | void DoCopyTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 805 | GLenum target, |
| 806 | GLint level, |
| 807 | GLint xoffset, |
| 808 | GLint yoffset, |
| 809 | GLint x, |
| 810 | GLint y, |
| 811 | GLsizei width, |
| 812 | GLsizei height); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 813 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 814 | // Validation for TexSubImage2D. |
| 815 | bool ValidateTexSubImage2D( |
| 816 | error::Error* error, |
| 817 | const char* function_name, |
| 818 | GLenum target, |
| 819 | GLint level, |
| 820 | GLint xoffset, |
| 821 | GLint yoffset, |
| 822 | GLsizei width, |
| 823 | GLsizei height, |
| 824 | GLenum format, |
| 825 | GLenum type, |
| 826 | const void * data); |
| 827 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 828 | // Wrapper for TexSubImage2D. |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 829 | error::Error DoTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 830 | GLenum target, |
| 831 | GLint level, |
| 832 | GLint xoffset, |
| 833 | GLint yoffset, |
| 834 | GLsizei width, |
| 835 | GLsizei height, |
| 836 | GLenum format, |
| 837 | GLenum type, |
| 838 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 839 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 840 | // Extra validation for async tex(Sub)Image2D. |
| 841 | bool ValidateAsyncTransfer( |
| 842 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 843 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 844 | GLenum target, |
| 845 | GLint level, |
| 846 | const void * data); |
| 847 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 848 | // Wrapper for TexImageIOSurface2DCHROMIUM. |
| 849 | void DoTexImageIOSurface2DCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 850 | GLenum target, |
| 851 | GLsizei width, |
| 852 | GLsizei height, |
| 853 | GLuint io_surface_id, |
| 854 | GLuint plane); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 855 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 856 | void DoCopyTextureCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 857 | GLenum target, |
| 858 | GLuint source_id, |
| 859 | GLuint target_id, |
| 860 | GLint level, |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 861 | GLenum internal_format, |
| 862 | GLenum dest_type); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 863 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 864 | // Wrapper for TexStorage2DEXT. |
| 865 | void DoTexStorage2DEXT( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 866 | GLenum target, |
| 867 | GLint levels, |
| 868 | GLenum internal_format, |
| 869 | GLsizei width, |
| 870 | GLsizei height); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 871 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 872 | void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 873 | void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
| 874 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 875 | void DoBindTexImage2DCHROMIUM( |
| 876 | GLenum target, |
| 877 | GLint image_id); |
| 878 | void DoReleaseTexImage2DCHROMIUM( |
| 879 | GLenum target, |
| 880 | GLint image_id); |
| 881 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 882 | void DoTraceEndCHROMIUM(void); |
| 883 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 884 | void DoDrawBuffersEXT(GLsizei count, const GLenum* bufs); |
| 885 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 886 | // Creates a Program for the given program. |
| 887 | Program* CreateProgram( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 888 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 889 | return program_manager()->CreateProgram(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 890 | } |
| 891 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 892 | // Gets the program info for the given program. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 893 | Program* GetProgram(GLuint client_id) { |
| 894 | return program_manager()->GetProgram(client_id); |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 895 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 896 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 897 | #if defined(NDEBUG) |
| 898 | void LogClientServiceMapping( |
| 899 | const char* /* function_name */, |
| 900 | GLuint /* client_id */, |
| 901 | GLuint /* service_id */) { |
| 902 | } |
| 903 | template<typename T> |
| 904 | void LogClientServiceForInfo( |
| 905 | T* /* info */, GLuint /* client_id */, const char* /* function_name */) { |
| 906 | } |
| 907 | #else |
| 908 | void LogClientServiceMapping( |
| 909 | const char* function_name, GLuint client_id, GLuint service_id) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 910 | if (service_logging_) { |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 911 | VLOG(1) << "[" << logger_.GetLogPrefix() << "] " << function_name |
| 912 | << ": client_id = " << client_id |
| 913 | << ", service_id = " << service_id; |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 914 | } |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 915 | } |
| 916 | template<typename T> |
| 917 | void LogClientServiceForInfo( |
| 918 | T* info, GLuint client_id, const char* function_name) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 919 | if (info) { |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 920 | LogClientServiceMapping(function_name, client_id, info->service_id()); |
| 921 | } |
| 922 | } |
| 923 | #endif |
| 924 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 925 | // Gets the program info for the given program. If it's not a program |
| 926 | // generates a GL error. Returns NULL if not program. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 927 | Program* GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 928 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 929 | Program* program = GetProgram(client_id); |
| 930 | if (!program) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 931 | if (GetShader(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 932 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 933 | GL_INVALID_OPERATION, function_name, "shader passed for program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 934 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 935 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 936 | } |
| 937 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 938 | LogClientServiceForInfo(program, client_id, function_name); |
| 939 | return program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 943 | // Creates a Shader for the given shader. |
| 944 | Shader* CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 945 | GLuint client_id, |
| 946 | GLuint service_id, |
| 947 | GLenum shader_type) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 948 | return shader_manager()->CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 949 | client_id, service_id, shader_type); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | // Gets the shader info for the given shader. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 953 | Shader* GetShader(GLuint client_id) { |
| 954 | return shader_manager()->GetShader(client_id); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 955 | } |
| 956 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 957 | // Gets the shader info for the given shader. If it's not a shader generates a |
| 958 | // GL error. Returns NULL if not shader. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 959 | Shader* GetShaderInfoNotProgram( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 960 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 961 | Shader* shader = GetShader(client_id); |
| 962 | if (!shader) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 963 | if (GetProgram(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 964 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 965 | GL_INVALID_OPERATION, function_name, "program passed for shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 966 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 967 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 968 | GL_INVALID_VALUE, function_name, "unknown shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 969 | } |
| 970 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 971 | LogClientServiceForInfo(shader, client_id, function_name); |
| 972 | return shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 973 | } |
| 974 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 975 | // Creates a buffer info for the given buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 976 | void CreateBuffer(GLuint client_id, GLuint service_id) { |
| 977 | return buffer_manager()->CreateBuffer(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 978 | } |
| 979 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 980 | // Gets the buffer info for the given buffer. |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 981 | Buffer* GetBuffer(GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 982 | Buffer* buffer = buffer_manager()->GetBuffer(client_id); |
| 983 | return buffer; |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 984 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 985 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 986 | // Removes any buffers in the VertexAtrribInfos and BufferInfos. This is used |
| 987 | // on glDeleteBuffers so we can make sure the user does not try to render |
| 988 | // with deleted buffers. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 989 | void RemoveBuffer(GLuint client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 990 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 991 | // Creates a framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 992 | void CreateFramebuffer(GLuint client_id, GLuint service_id) { |
| 993 | return framebuffer_manager()->CreateFramebuffer(client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | // Gets the framebuffer info for the given framebuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 997 | Framebuffer* GetFramebuffer(GLuint client_id) { |
| 998 | return framebuffer_manager()->GetFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | // Removes the framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1002 | void RemoveFramebuffer(GLuint client_id) { |
| 1003 | framebuffer_manager()->RemoveFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | // Creates a renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1007 | void CreateRenderbuffer(GLuint client_id, GLuint service_id) { |
| 1008 | return renderbuffer_manager()->CreateRenderbuffer( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1009 | client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | // Gets the renderbuffer info for the given renderbuffer. |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1013 | Renderbuffer* GetRenderbuffer(GLuint client_id) { |
| 1014 | return renderbuffer_manager()->GetRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | // Removes the renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1018 | void RemoveRenderbuffer(GLuint client_id) { |
| 1019 | renderbuffer_manager()->RemoveRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1020 | } |
| 1021 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1022 | // Gets the vertex attrib manager for the given vertex array. |
| 1023 | VertexAttribManager* GetVertexAttribManager(GLuint client_id) { |
| 1024 | VertexAttribManager* info = |
| 1025 | vertex_array_manager()->GetVertexAttribManager(client_id); |
| 1026 | return info; |
| 1027 | } |
| 1028 | |
| 1029 | // Removes the vertex attrib manager for the given vertex array. |
| 1030 | void RemoveVertexAttribManager(GLuint client_id) { |
| 1031 | vertex_array_manager()->RemoveVertexAttribManager(client_id); |
| 1032 | } |
| 1033 | |
| 1034 | // Creates a vertex attrib manager for the given vertex array. |
| 1035 | void CreateVertexAttribManager(GLuint client_id, GLuint service_id) { |
| 1036 | return vertex_array_manager()->CreateVertexAttribManager( |
| 1037 | client_id, service_id, group_->max_vertex_attribs()); |
| 1038 | } |
| 1039 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1040 | void DoBindAttribLocation(GLuint client_id, GLuint index, const char* name); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 1041 | void DoBindUniformLocationCHROMIUM( |
| 1042 | GLuint client_id, GLint location, const char* name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1043 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 1044 | error::Error GetAttribLocationHelper( |
| 1045 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1046 | const std::string& name_str); |
| 1047 | |
| 1048 | error::Error GetUniformLocationHelper( |
| 1049 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1050 | const std::string& name_str); |
| 1051 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1052 | // Helper for glShaderSource. |
| 1053 | error::Error ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1054 | GLuint client_id, const char* data, uint32 data_size); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1055 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1056 | // Clear any textures used by the current program. |
| 1057 | bool ClearUnclearedTextures(); |
| 1058 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1059 | // Clears any uncleared attachments attached to the given frame buffer. |
| 1060 | // Returns false if there was a generated GL error. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1061 | void ClearUnclearedAttachments(GLenum target, Framebuffer* framebuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1062 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1063 | // overridden from GLES2Decoder |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 1064 | virtual bool ClearLevel(unsigned service_id, |
| 1065 | unsigned bind_target, |
| 1066 | unsigned target, |
| 1067 | int level, |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 1068 | unsigned internal_format, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 1069 | unsigned format, |
| 1070 | unsigned type, |
| 1071 | int width, |
| 1072 | int height, |
| 1073 | bool is_texture_immutable) OVERRIDE; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1074 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 1075 | // Restore all GL state that affects clearing. |
| 1076 | void RestoreClearState(); |
| 1077 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1078 | // Remembers the state of some capabilities. |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1079 | // Returns: true if glEnable/glDisable should actually be called. |
| 1080 | bool SetCapabilityState(GLenum cap, bool enabled); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1081 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1082 | // Check that the currently bound framebuffers are valid. |
| 1083 | // Generates GL error if not. |
| 1084 | bool CheckBoundFramebuffersValid(const char* func_name); |
| 1085 | |
| 1086 | // Check if a framebuffer meets our requirements. |
| 1087 | bool CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1088 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1089 | GLenum target, |
| 1090 | const char* func_name); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1091 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1092 | // Checks if the current program exists and is valid. If not generates the |
| 1093 | // appropriate GL error. Returns true if the current program is in a usable |
| 1094 | // state. |
| 1095 | bool CheckCurrentProgram(const char* function_name); |
| 1096 | |
| 1097 | // Checks if the current program exists and is valid and that location is not |
| 1098 | // -1. If the current program is not valid generates the appropriate GL |
| 1099 | // error. Returns true if the current program is in a usable state and |
| 1100 | // location is not -1. |
| 1101 | bool CheckCurrentProgramForUniform(GLint location, const char* function_name); |
| 1102 | |
| 1103 | // Gets the type of a uniform for a location in the current program. Sets GL |
| 1104 | // errors if the current program is not valid. Returns true if the current |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1105 | // program is valid and the location exists. Adjusts count so it |
| 1106 | // does not overflow the uniform. |
| 1107 | bool PrepForSetUniformByLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1108 | GLint fake_location, const char* function_name, |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 1109 | const BaseUniformInfo& base_info, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1110 | GLint* real_location, GLenum* type, GLsizei* count); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1111 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1112 | // Gets the service id for any simulated backbuffer fbo. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1113 | GLuint GetBackbufferServiceId() const; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1114 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1115 | // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv |
| 1116 | bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); |
| 1117 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 1118 | // Helper for glGetVertexAttrib |
| 1119 | void GetVertexAttribHelper( |
| 1120 | const VertexAttrib* attrib, GLenum pname, GLint* param); |
| 1121 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1122 | // Wrapper for glCreateProgram |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1123 | bool CreateProgramHelper(GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1124 | |
| 1125 | // Wrapper for glCreateShader |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1126 | bool CreateShaderHelper(GLenum type, GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1127 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1128 | // Wrapper for glActiveTexture |
| 1129 | void DoActiveTexture(GLenum texture_unit); |
| 1130 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1131 | // Wrapper for glAttachShader |
| 1132 | void DoAttachShader(GLuint client_program_id, GLint client_shader_id); |
| 1133 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1134 | // Wrapper for glBindBuffer since we need to track the current targets. |
| 1135 | void DoBindBuffer(GLenum target, GLuint buffer); |
| 1136 | |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 1137 | // Wrapper for glBindFramebuffer since we need to track the current targets. |
| 1138 | void DoBindFramebuffer(GLenum target, GLuint framebuffer); |
| 1139 | |
| 1140 | // Wrapper for glBindRenderbuffer since we need to track the current targets. |
| 1141 | void DoBindRenderbuffer(GLenum target, GLuint renderbuffer); |
| 1142 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1143 | // Wrapper for glBindTexture since we need to track the current targets. |
| 1144 | void DoBindTexture(GLenum target, GLuint texture); |
| 1145 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1146 | // Wrapper for glBindVertexArrayOES |
| 1147 | void DoBindVertexArrayOES(GLuint array); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 1148 | void EmulateVertexArrayState(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1149 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1150 | // Wrapper for glBlitFramebufferCHROMIUM. |
| 1151 | void DoBlitFramebufferCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1152 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 1153 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 1154 | GLbitfield mask, GLenum filter); |
| 1155 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1156 | // Wrapper for glBufferSubData. |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 1157 | void DoBufferSubData( |
| 1158 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); |
| 1159 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1160 | // Wrapper for glCheckFramebufferStatus |
| 1161 | GLenum DoCheckFramebufferStatus(GLenum target); |
| 1162 | |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1163 | // Wrapper for glClear |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1164 | error::Error DoClear(GLbitfield mask); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1165 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1166 | // Wrappers for various state. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1167 | void DoDepthRangef(GLclampf znear, GLclampf zfar); |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 1168 | void DoSampleCoverage(GLclampf value, GLboolean invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1169 | |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1170 | // Wrapper for glCompileShader. |
| 1171 | void DoCompileShader(GLuint shader); |
| 1172 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1173 | // Helper for DeleteSharedIdsCHROMIUM commands. |
| 1174 | void DoDeleteSharedIdsCHROMIUM( |
| 1175 | GLuint namespace_id, GLsizei n, const GLuint* ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1176 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1177 | // Wrapper for glDetachShader |
| 1178 | void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
| 1179 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1180 | // Wrapper for glDisable |
| 1181 | void DoDisable(GLenum cap); |
| 1182 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1183 | // Wrapper for glDisableVertexAttribArray. |
| 1184 | void DoDisableVertexAttribArray(GLuint index); |
| 1185 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1186 | // Wrapper for glDiscardFramebufferEXT, since we need to track undefined |
| 1187 | // attachments. |
| 1188 | void DoDiscardFramebufferEXT(GLenum target, |
| 1189 | GLsizei numAttachments, |
| 1190 | const GLenum* attachments); |
| 1191 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1192 | // Wrapper for glEnable |
| 1193 | void DoEnable(GLenum cap); |
| 1194 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1195 | // Wrapper for glEnableVertexAttribArray. |
| 1196 | void DoEnableVertexAttribArray(GLuint index); |
| 1197 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1198 | // Wrapper for glFinish. |
| 1199 | void DoFinish(); |
| 1200 | |
| 1201 | // Wrapper for glFlush. |
| 1202 | void DoFlush(); |
| 1203 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1204 | // Wrapper for glFramebufferRenderbufffer. |
| 1205 | void DoFramebufferRenderbuffer( |
| 1206 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
| 1207 | GLuint renderbuffer); |
| 1208 | |
| 1209 | // Wrapper for glFramebufferTexture2D. |
| 1210 | void DoFramebufferTexture2D( |
| 1211 | GLenum target, GLenum attachment, GLenum textarget, GLuint texture, |
| 1212 | GLint level); |
| 1213 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1214 | // Wrapper for glFramebufferTexture2DMultisampleEXT. |
| 1215 | void DoFramebufferTexture2DMultisample( |
| 1216 | GLenum target, GLenum attachment, GLenum textarget, |
| 1217 | GLuint texture, GLint level, GLsizei samples); |
| 1218 | |
| 1219 | // Common implementation for both DoFramebufferTexture2D wrappers. |
| 1220 | void DoFramebufferTexture2DCommon(const char* name, |
| 1221 | GLenum target, GLenum attachment, GLenum textarget, |
| 1222 | GLuint texture, GLint level, GLsizei samples); |
| 1223 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1224 | // Wrapper for glGenerateMipmap |
| 1225 | void DoGenerateMipmap(GLenum target); |
| 1226 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1227 | // Helper for GenSharedIdsCHROMIUM commands. |
| 1228 | void DoGenSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1229 | GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids); |
| 1230 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1231 | // Helper for DoGetBooleanv, Floatv, and Intergerv to adjust pname |
| 1232 | // to account for different pname values defined in different extension |
| 1233 | // variants. |
| 1234 | GLenum AdjustGetPname(GLenum pname); |
| 1235 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1236 | // Wrapper for DoGetBooleanv. |
| 1237 | void DoGetBooleanv(GLenum pname, GLboolean* params); |
| 1238 | |
| 1239 | // Wrapper for DoGetFloatv. |
| 1240 | void DoGetFloatv(GLenum pname, GLfloat* params); |
| 1241 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1242 | // Wrapper for glGetFramebufferAttachmentParameteriv. |
| 1243 | void DoGetFramebufferAttachmentParameteriv( |
| 1244 | GLenum target, GLenum attachment, GLenum pname, GLint* params); |
| 1245 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1246 | // Wrapper for glGetIntegerv. |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1247 | void DoGetIntegerv(GLenum pname, GLint* params); |
| 1248 | |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1249 | // Gets the max value in a range in a buffer. |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1250 | GLuint DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1251 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); |
| 1252 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 1253 | // Wrapper for glGetBufferParameteriv. |
| 1254 | void DoGetBufferParameteriv( |
| 1255 | GLenum target, GLenum pname, GLint* params); |
| 1256 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1257 | // Wrapper for glGetProgramiv. |
| 1258 | void DoGetProgramiv( |
| 1259 | GLuint program_id, GLenum pname, GLint* params); |
| 1260 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1261 | // Wrapper for glRenderbufferParameteriv. |
| 1262 | void DoGetRenderbufferParameteriv( |
| 1263 | GLenum target, GLenum pname, GLint* params); |
| 1264 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 1265 | // Wrapper for glGetShaderiv |
| 1266 | void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); |
| 1267 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1268 | // Wrappers for glGetVertexAttrib. |
| 1269 | void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); |
| 1270 | void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); |
| 1271 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1272 | // Wrappers for glIsXXX functions. |
[email protected] | 3dc69c4 | 2012-05-12 02:29:24 | [diff] [blame] | 1273 | bool DoIsEnabled(GLenum cap); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1274 | bool DoIsBuffer(GLuint client_id); |
| 1275 | bool DoIsFramebuffer(GLuint client_id); |
| 1276 | bool DoIsProgram(GLuint client_id); |
| 1277 | bool DoIsRenderbuffer(GLuint client_id); |
| 1278 | bool DoIsShader(GLuint client_id); |
| 1279 | bool DoIsTexture(GLuint client_id); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1280 | bool DoIsVertexArrayOES(GLuint client_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1281 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1282 | // Wrapper for glLinkProgram |
| 1283 | void DoLinkProgram(GLuint program); |
| 1284 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1285 | // Helper for RegisterSharedIdsCHROMIUM. |
| 1286 | void DoRegisterSharedIdsCHROMIUM( |
| 1287 | GLuint namespace_id, GLsizei n, const GLuint* ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 1288 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1289 | // Wrapper for glRenderbufferStorage. |
| 1290 | void DoRenderbufferStorage( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1291 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1292 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1293 | // Handler for glRenderbufferStorageMultisampleCHROMIUM. |
| 1294 | void DoRenderbufferStorageMultisampleCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1295 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1296 | GLsizei width, GLsizei height); |
| 1297 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1298 | // Handler for glRenderbufferStorageMultisampleEXT |
| 1299 | // (multisampled_render_to_texture). |
| 1300 | void DoRenderbufferStorageMultisampleEXT( |
| 1301 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1302 | GLsizei width, GLsizei height); |
| 1303 | |
| 1304 | // Common validation for multisample extensions. |
| 1305 | bool ValidateRenderbufferStorageMultisample(GLsizei samples, |
| 1306 | GLenum internalformat, |
| 1307 | GLsizei width, |
| 1308 | GLsizei height); |
| 1309 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 1310 | // Verifies that the currently bound multisample renderbuffer is valid |
| 1311 | // Very slow! Only done on platforms with driver bugs that return invalid |
| 1312 | // buffers under memory pressure |
| 1313 | bool VerifyMultisampleRenderbufferIntegrity( |
| 1314 | GLuint renderbuffer, GLenum format); |
| 1315 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1316 | // Wrapper for glReleaseShaderCompiler. |
| 1317 | void DoReleaseShaderCompiler() { } |
| 1318 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1319 | // Wrappers for glTexParameter functions. |
| 1320 | void DoTexParameterf(GLenum target, GLenum pname, GLfloat param); |
| 1321 | void DoTexParameteri(GLenum target, GLenum pname, GLint param); |
| 1322 | void DoTexParameterfv(GLenum target, GLenum pname, const GLfloat* params); |
| 1323 | void DoTexParameteriv(GLenum target, GLenum pname, const GLint* params); |
| 1324 | |
| 1325 | // Wrappers for glUniform1i and glUniform1iv as according to the GLES2 |
| 1326 | // spec only these 2 functions can be used to set sampler uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1327 | void DoUniform1i(GLint fake_location, GLint v0); |
| 1328 | void DoUniform1iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1329 | void DoUniform2iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1330 | void DoUniform3iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1331 | void DoUniform4iv(GLint fake_location, GLsizei count, const GLint* value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1332 | |
| 1333 | // Wrappers for glUniformfv because some drivers don't correctly accept |
| 1334 | // bool uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1335 | void DoUniform1fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1336 | void DoUniform2fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1337 | void DoUniform3fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1338 | void DoUniform4fv(GLint fake_location, GLsizei count, const GLfloat* value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1339 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1340 | void DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1341 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1342 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1343 | void DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1344 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1345 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1346 | void DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1347 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1348 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1349 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1350 | bool SetVertexAttribValue( |
| 1351 | const char* function_name, GLuint index, const GLfloat* value); |
| 1352 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1353 | // Wrappers for glVertexAttrib?? |
| 1354 | void DoVertexAttrib1f(GLuint index, GLfloat v0); |
| 1355 | void DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1); |
| 1356 | void DoVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2); |
| 1357 | void DoVertexAttrib4f( |
| 1358 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); |
| 1359 | void DoVertexAttrib1fv(GLuint index, const GLfloat *v); |
| 1360 | void DoVertexAttrib2fv(GLuint index, const GLfloat *v); |
| 1361 | void DoVertexAttrib3fv(GLuint index, const GLfloat *v); |
| 1362 | void DoVertexAttrib4fv(GLuint index, const GLfloat *v); |
| 1363 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1364 | // Wrapper for glViewport |
| 1365 | void DoViewport(GLint x, GLint y, GLsizei width, GLsizei height); |
| 1366 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1367 | // Wrapper for glUseProgram |
| 1368 | void DoUseProgram(GLuint program); |
| 1369 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1370 | // Wrapper for glValidateProgram. |
| 1371 | void DoValidateProgram(GLuint program_client_id); |
| 1372 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 1373 | void DoInsertEventMarkerEXT(GLsizei length, const GLchar* marker); |
| 1374 | void DoPushGroupMarkerEXT(GLsizei length, const GLchar* group); |
| 1375 | void DoPopGroupMarkerEXT(void); |
| 1376 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 1377 | // Gets the number of values that will be returned by glGetXXX. Returns |
| 1378 | // false if pname is unknown. |
| 1379 | bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values); |
| 1380 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1381 | // Checks if the current program and vertex attributes are valid for drawing. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1382 | bool IsDrawValid( |
| 1383 | const char* function_name, GLuint max_vertex_accessed, GLsizei primcount); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1384 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 1385 | // Returns true if successful, simulated will be true if attrib0 was |
| 1386 | // simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1387 | bool SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1388 | const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1389 | void RestoreStateForAttrib(GLuint attrib); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1390 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1391 | // If an image is bound to texture, this will call Will/DidUseTexImage |
| 1392 | // if needed. |
| 1393 | void DoWillUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1394 | void DoDidUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1395 | |
| 1396 | // Returns false if textures were replaced. |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 1397 | bool PrepareTexturesForRender(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1398 | void RestoreStateForTextures(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1399 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1400 | // Returns true if GL_FIXED attribs were simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1401 | bool SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1402 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1403 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1404 | void RestoreStateForSimulatedFixedAttribs(); |
| 1405 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1406 | // Handle DrawArrays and DrawElements for both instanced and non-instanced |
| 1407 | // cases (primcount is 0 for non-instanced). |
| 1408 | error::Error DoDrawArrays( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1409 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1410 | bool instanced, GLenum mode, GLint first, GLsizei count, |
| 1411 | GLsizei primcount); |
| 1412 | error::Error DoDrawElements( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1413 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1414 | bool instanced, GLenum mode, GLsizei count, GLenum type, |
| 1415 | int32 offset, GLsizei primcount); |
| 1416 | |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1417 | GLenum GetBindTargetForSamplerType(GLenum type) { |
| 1418 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1419 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 1420 | switch (type) { |
| 1421 | case GL_SAMPLER_2D: |
| 1422 | return GL_TEXTURE_2D; |
| 1423 | case GL_SAMPLER_CUBE: |
| 1424 | return GL_TEXTURE_CUBE_MAP; |
| 1425 | case GL_SAMPLER_EXTERNAL_OES: |
| 1426 | return GL_TEXTURE_EXTERNAL_OES; |
| 1427 | case GL_SAMPLER_2D_RECT_ARB: |
| 1428 | return GL_TEXTURE_RECTANGLE_ARB; |
| 1429 | } |
| 1430 | |
| 1431 | NOTREACHED(); |
| 1432 | return 0; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1433 | } |
| 1434 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1435 | // Gets the framebuffer info for a particular target. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1436 | Framebuffer* GetFramebufferInfoForTarget(GLenum target) { |
| 1437 | Framebuffer* framebuffer = NULL; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1438 | switch (target) { |
| 1439 | case GL_FRAMEBUFFER: |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1440 | case GL_DRAW_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1441 | framebuffer = framebuffer_state_.bound_draw_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1442 | break; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1443 | case GL_READ_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1444 | framebuffer = framebuffer_state_.bound_read_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1445 | break; |
| 1446 | default: |
| 1447 | NOTREACHED(); |
| 1448 | break; |
| 1449 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1450 | return framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1451 | } |
| 1452 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1453 | Renderbuffer* GetRenderbufferInfoForTarget( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1454 | GLenum target) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1455 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1456 | switch (target) { |
| 1457 | case GL_RENDERBUFFER: |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 1458 | renderbuffer = state_.bound_renderbuffer.get(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1459 | break; |
| 1460 | default: |
| 1461 | NOTREACHED(); |
| 1462 | break; |
| 1463 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1464 | return renderbuffer; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1465 | } |
| 1466 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1467 | // Validates the program and location for a glGetUniform call and returns |
| 1468 | // a SizeResult setup to receive the result. Returns true if glGetUniform |
| 1469 | // should be called. |
| 1470 | bool GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1471 | GLuint program, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1472 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1473 | error::Error* error, GLint* real_location, GLuint* service_id, |
| 1474 | void** result, GLenum* result_type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1475 | |
[email protected] | a10b4a0 | 2012-11-26 23:09:50 | [diff] [blame] | 1476 | virtual bool WasContextLost() OVERRIDE; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 1477 | virtual bool WasContextLostByRobustnessExtension() OVERRIDE; |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 1478 | virtual void LoseContext(uint32 reset_status) OVERRIDE; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1479 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1480 | #if defined(OS_MACOSX) |
| 1481 | void ReleaseIOSurfaceForTexture(GLuint texture_id); |
| 1482 | #endif |
| 1483 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1484 | bool ValidateCompressedTexDimensions( |
| 1485 | const char* function_name, |
| 1486 | GLint level, GLsizei width, GLsizei height, GLenum format); |
| 1487 | bool ValidateCompressedTexFuncData( |
| 1488 | const char* function_name, |
| 1489 | GLsizei width, GLsizei height, GLenum format, size_t size); |
| 1490 | bool ValidateCompressedTexSubDimensions( |
| 1491 | const char* function_name, |
| 1492 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 1493 | GLsizei width, GLsizei height, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1494 | Texture* texture); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1495 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1496 | void RenderWarning(const char* filename, int line, const std::string& msg); |
| 1497 | void PerformanceWarning( |
| 1498 | const char* filename, int line, const std::string& msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 1499 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 1500 | const FeatureInfo::FeatureFlags& features() const { |
| 1501 | return feature_info_->feature_flags(); |
| 1502 | } |
| 1503 | |
| 1504 | const FeatureInfo::Workarounds& workarounds() const { |
| 1505 | return feature_info_->workarounds(); |
| 1506 | } |
| 1507 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1508 | bool ShouldDeferDraws() { |
| 1509 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1510 | framebuffer_state_.bound_draw_framebuffer.get() == NULL && |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1511 | surface_->DeferDraws(); |
| 1512 | } |
| 1513 | |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1514 | bool ShouldDeferReads() { |
| 1515 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1516 | framebuffer_state_.bound_read_framebuffer.get() == NULL && |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1517 | surface_->DeferDraws(); |
| 1518 | } |
| 1519 | |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 1520 | error::Error WillAccessBoundFramebufferForDraw() { |
| 1521 | if (ShouldDeferDraws()) |
| 1522 | return error::kDeferCommandUntilLater; |
| 1523 | if (!offscreen_target_frame_buffer_.get() && |
| 1524 | !framebuffer_state_.bound_draw_framebuffer.get() && |
| 1525 | !surface_->SetBackbufferAllocation(true)) |
| 1526 | return error::kLostContext; |
| 1527 | return error::kNoError; |
| 1528 | } |
| 1529 | |
| 1530 | error::Error WillAccessBoundFramebufferForRead() { |
| 1531 | if (ShouldDeferReads()) |
| 1532 | return error::kDeferCommandUntilLater; |
| 1533 | if (!offscreen_target_frame_buffer_.get() && |
| 1534 | !framebuffer_state_.bound_read_framebuffer.get() && |
| 1535 | !surface_->SetBackbufferAllocation(true)) |
| 1536 | return error::kLostContext; |
| 1537 | return error::kNoError; |
| 1538 | } |
| 1539 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 1540 | void ProcessPendingReadPixels(); |
| 1541 | void FinishReadPixels(const cmds::ReadPixels& c, GLuint buffer); |
| 1542 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1543 | // Generate a member function prototype for each command in an automated and |
| 1544 | // typesafe way. |
| 1545 | #define GLES2_CMD_OP(name) \ |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 1546 | Error Handle ## name( \ |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1547 | uint32 immediate_data_size, \ |
| 1548 | const cmds::name& args); \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1549 | |
| 1550 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 1551 | |
| 1552 | #undef GLES2_CMD_OP |
| 1553 | |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 1554 | // The GL context this decoder renders to on behalf of the client. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1555 | scoped_refptr<gfx::GLSurface> surface_; |
| 1556 | scoped_refptr<gfx::GLContext> context_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1557 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1558 | // The ContextGroup for this decoder uses to track resources. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1559 | scoped_refptr<ContextGroup> group_; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1560 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 1561 | DebugMarkerManager debug_marker_manager_; |
| 1562 | Logger logger_; |
| 1563 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1564 | // All the state for this context. |
| 1565 | ContextState state_; |
| 1566 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1567 | // Current width and height of the offscreen frame buffer. |
| 1568 | gfx::Size offscreen_size_; |
| 1569 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1570 | // Util to help with GL. |
| 1571 | GLES2Util util_; |
| 1572 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1573 | // unpack flip y as last set by glPixelStorei |
| 1574 | bool unpack_flip_y_; |
| 1575 | |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1576 | // unpack (un)premultiply alpha as last set by glPixelStorei |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1577 | bool unpack_premultiply_alpha_; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1578 | bool unpack_unpremultiply_alpha_; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1579 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1580 | // Default vertex attribs manager, used when no VAOs are bound. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1581 | scoped_refptr<VertexAttribManager> default_vertex_attrib_manager_; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1582 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1583 | // The buffer we bind to attrib 0 since OpenGL requires it (ES does not). |
| 1584 | GLuint attrib_0_buffer_id_; |
| 1585 | |
| 1586 | // The value currently in attrib_0. |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1587 | Vec4 attrib_0_value_; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1588 | |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 1589 | // Whether or not the attrib_0 buffer holds the attrib_0_value. |
| 1590 | bool attrib_0_buffer_matches_value_; |
| 1591 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1592 | // The size of attrib 0. |
| 1593 | GLsizei attrib_0_size_; |
| 1594 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1595 | // The buffer used to simulate GL_FIXED attribs. |
| 1596 | GLuint fixed_attrib_buffer_id_; |
| 1597 | |
| 1598 | // The size of fiixed attrib buffer. |
| 1599 | GLsizei fixed_attrib_buffer_size_; |
| 1600 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1601 | // The offscreen frame buffer that the client renders to. With EGL, the |
| 1602 | // depth and stencil buffers are separate. With regular GL there is a single |
| 1603 | // packed depth stencil buffer in offscreen_target_depth_render_buffer_. |
| 1604 | // offscreen_target_stencil_render_buffer_ is unused. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1605 | scoped_ptr<BackFramebuffer> offscreen_target_frame_buffer_; |
| 1606 | scoped_ptr<BackTexture> offscreen_target_color_texture_; |
| 1607 | scoped_ptr<BackRenderbuffer> offscreen_target_color_render_buffer_; |
| 1608 | scoped_ptr<BackRenderbuffer> offscreen_target_depth_render_buffer_; |
| 1609 | scoped_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1610 | GLenum offscreen_target_color_format_; |
| 1611 | GLenum offscreen_target_depth_format_; |
| 1612 | GLenum offscreen_target_stencil_format_; |
| 1613 | GLsizei offscreen_target_samples_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1614 | GLboolean offscreen_target_buffer_preserved_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1615 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1616 | // The copy that is saved when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1617 | scoped_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; |
| 1618 | scoped_ptr<BackTexture> offscreen_saved_color_texture_; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 1619 | scoped_refptr<TextureRef> |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1620 | offscreen_saved_color_texture_info_; |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1621 | |
| 1622 | // The copy that is used as the destination for multi-sample resolves. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1623 | scoped_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; |
| 1624 | scoped_ptr<BackTexture> offscreen_resolved_color_texture_; |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1625 | GLenum offscreen_saved_color_format_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1626 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1627 | scoped_ptr<QueryManager> query_manager_; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1628 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1629 | scoped_ptr<VertexArrayManager> vertex_array_manager_; |
| 1630 | |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 1631 | base::Callback<void(gfx::Size, float)> resize_callback_; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 1632 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 1633 | WaitSyncPointCallback wait_sync_point_callback_; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 1634 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 1635 | ShaderCacheCallback shader_cache_callback_; |
| 1636 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 1637 | scoped_ptr<AsyncPixelTransferManager> async_pixel_transfer_manager_; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 1638 | |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1639 | // The format of the back buffer_ |
| 1640 | GLenum back_buffer_color_format_; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1641 | bool back_buffer_has_depth_; |
| 1642 | bool back_buffer_has_stencil_; |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1643 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1644 | // Backbuffer attachments that are currently undefined. |
| 1645 | uint32 backbuffer_needs_clear_bits_; |
| 1646 | |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 1647 | // The current decoder error. |
| 1648 | error::Error current_decoder_error_; |
| 1649 | |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1650 | bool use_shader_translator_; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 1651 | scoped_refptr<ShaderTranslator> vertex_translator_; |
| 1652 | scoped_refptr<ShaderTranslator> fragment_translator_; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1653 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1654 | DisallowedFeatures disallowed_features_; |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1655 | |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 1656 | // Cached from ContextGroup |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1657 | const Validators* validators_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1658 | scoped_refptr<FeatureInfo> feature_info_; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1659 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1660 | int frame_number_; |
| 1661 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 1662 | bool has_robustness_extension_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1663 | GLenum reset_status_; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 1664 | bool reset_by_robustness_extension_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1665 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1666 | // These flags are used to override the state of the shared feature_info_ |
| 1667 | // member. Because the same FeatureInfo instance may be shared among many |
| 1668 | // contexts, the assumptions on the availablity of extensions in WebGL |
| 1669 | // contexts may be broken. These flags override the shared state to preserve |
| 1670 | // WebGL semantics. |
| 1671 | bool force_webgl_glsl_validation_; |
| 1672 | bool derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 1673 | bool frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 1674 | bool draw_buffers_explicitly_enabled_; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1675 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 1676 | bool compile_shader_always_succeeds_; |
| 1677 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1678 | // Log extra info. |
| 1679 | bool service_logging_; |
| 1680 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1681 | #if defined(OS_MACOSX) |
| 1682 | typedef std::map<GLuint, CFTypeRef> TextureToIOSurfaceMap; |
| 1683 | TextureToIOSurfaceMap texture_to_io_surface_map_; |
| 1684 | #endif |
| 1685 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1686 | scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
| 1687 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1688 | // Cached values of the currently assigned viewport dimensions. |
| 1689 | GLsizei viewport_max_width_; |
| 1690 | GLsizei viewport_max_height_; |
| 1691 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1692 | // Command buffer stats. |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1693 | base::TimeDelta total_processing_commands_time_; |
| 1694 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 1695 | // States related to each manager. |
| 1696 | DecoderTextureState texture_state_; |
| 1697 | DecoderFramebufferState framebuffer_state_; |
| 1698 | |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 1699 | scoped_ptr<GPUTracer> gpu_tracer_; |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 1700 | scoped_ptr<GPUStateTracer> gpu_state_tracer_; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 1701 | int gpu_trace_level_; |
| 1702 | bool gpu_trace_commands_; |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 1703 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 1704 | std::queue<linked_ptr<FenceCallback> > pending_readpixel_fences_; |
| 1705 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 1706 | // Used to validate multisample renderbuffers if needed |
| 1707 | GLuint validation_texture_; |
| 1708 | GLuint validation_fbo_multisample_; |
| 1709 | GLuint validation_fbo_; |
| 1710 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1711 | DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
| 1712 | }; |
| 1713 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1714 | ScopedGLErrorSuppressor::ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1715 | const char* function_name, ErrorState* error_state) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1716 | : function_name_(function_name), |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1717 | error_state_(error_state) { |
| 1718 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1719 | } |
| 1720 | |
| 1721 | ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1722 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1723 | } |
| 1724 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1725 | static void RestoreCurrentTextureBindings(ContextState* state, GLenum target) { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1726 | TextureUnit& info = state->texture_units[0]; |
| 1727 | GLuint last_id; |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1728 | scoped_refptr<TextureRef> texture_ref; |
| 1729 | switch (target) { |
| 1730 | case GL_TEXTURE_2D: |
| 1731 | texture_ref = info.bound_texture_2d; |
| 1732 | break; |
| 1733 | case GL_TEXTURE_CUBE_MAP: |
| 1734 | texture_ref = info.bound_texture_cube_map; |
| 1735 | break; |
| 1736 | case GL_TEXTURE_EXTERNAL_OES: |
| 1737 | texture_ref = info.bound_texture_external_oes; |
| 1738 | break; |
| 1739 | case GL_TEXTURE_RECTANGLE_ARB: |
| 1740 | texture_ref = info.bound_texture_rectangle_arb; |
| 1741 | break; |
| 1742 | default: |
| 1743 | NOTREACHED(); |
| 1744 | break; |
| 1745 | } |
| 1746 | if (texture_ref.get()) { |
| 1747 | last_id = texture_ref->service_id(); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1748 | } else { |
| 1749 | last_id = 0; |
| 1750 | } |
| 1751 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1752 | glBindTexture(target, last_id); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1753 | glActiveTexture(GL_TEXTURE0 + state->active_texture_unit); |
| 1754 | } |
| 1755 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1756 | ScopedTextureBinder::ScopedTextureBinder(ContextState* state, |
| 1757 | GLuint id, |
| 1758 | GLenum target) |
| 1759 | : state_(state), |
| 1760 | target_(target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1761 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1762 | "ScopedTextureBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1763 | |
| 1764 | // TODO(apatrick): Check if there are any other states that need to be reset |
| 1765 | // before binding a new texture. |
| 1766 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1767 | glBindTexture(target, id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1768 | } |
| 1769 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1770 | ScopedTextureBinder::~ScopedTextureBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1771 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1772 | "ScopedTextureBinder::dtor", state_->GetErrorState()); |
| 1773 | RestoreCurrentTextureBindings(state_, target_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1774 | } |
| 1775 | |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1776 | ScopedRenderBufferBinder::ScopedRenderBufferBinder(ContextState* state, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1777 | GLuint id) |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1778 | : state_(state) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1779 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1780 | "ScopedRenderBufferBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1781 | glBindRenderbufferEXT(GL_RENDERBUFFER, id); |
| 1782 | } |
| 1783 | |
| 1784 | ScopedRenderBufferBinder::~ScopedRenderBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1785 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1786 | "ScopedRenderBufferBinder::dtor", state_->GetErrorState()); |
| 1787 | state_->RestoreRenderbufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | ScopedFrameBufferBinder::ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 1791 | GLuint id) |
| 1792 | : decoder_(decoder) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1793 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1794 | "ScopedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1795 | glBindFramebufferEXT(GL_FRAMEBUFFER, id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 1796 | decoder->OnFboChanged(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | ScopedFrameBufferBinder::~ScopedFrameBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1800 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1801 | "ScopedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1802 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1803 | } |
| 1804 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1805 | ScopedResolvedFrameBufferBinder::ScopedResolvedFrameBufferBinder( |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1806 | GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 1807 | : decoder_(decoder) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1808 | resolve_and_bind_ = ( |
| 1809 | decoder_->offscreen_target_frame_buffer_.get() && |
| 1810 | decoder_->IsOffscreenBufferMultisampled() && |
| 1811 | (!decoder_->framebuffer_state_.bound_read_framebuffer.get() || |
| 1812 | enforce_internal_framebuffer)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1813 | if (!resolve_and_bind_) |
| 1814 | return; |
| 1815 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1816 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1817 | "ScopedResolvedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1818 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, |
| 1819 | decoder_->offscreen_target_frame_buffer_->id()); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1820 | GLuint targetid; |
| 1821 | if (internal) { |
| 1822 | if (!decoder_->offscreen_resolved_frame_buffer_.get()) { |
| 1823 | decoder_->offscreen_resolved_frame_buffer_.reset( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1824 | new BackFramebuffer(decoder_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1825 | decoder_->offscreen_resolved_frame_buffer_->Create(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1826 | decoder_->offscreen_resolved_color_texture_.reset( |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1827 | new BackTexture(decoder->memory_tracker(), &decoder->state_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1828 | decoder_->offscreen_resolved_color_texture_->Create(); |
| 1829 | |
| 1830 | DCHECK(decoder_->offscreen_saved_color_format_); |
| 1831 | decoder_->offscreen_resolved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 1832 | decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_, |
| 1833 | false); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1834 | decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( |
| 1835 | decoder_->offscreen_resolved_color_texture_.get()); |
| 1836 | if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != |
| 1837 | GL_FRAMEBUFFER_COMPLETE) { |
| 1838 | LOG(ERROR) << "ScopedResolvedFrameBufferBinder failed " |
| 1839 | << "because offscreen resolved FBO was incomplete."; |
| 1840 | return; |
| 1841 | } |
| 1842 | } |
| 1843 | targetid = decoder_->offscreen_resolved_frame_buffer_->id(); |
| 1844 | } else { |
| 1845 | targetid = decoder_->offscreen_saved_frame_buffer_->id(); |
| 1846 | } |
| 1847 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1848 | const int width = decoder_->offscreen_size_.width(); |
| 1849 | const int height = decoder_->offscreen_size_.height(); |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 1850 | glDisable(GL_SCISSOR_TEST); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 1851 | decoder->BlitFramebufferHelper(0, |
| 1852 | 0, |
| 1853 | width, |
| 1854 | height, |
| 1855 | 0, |
| 1856 | 0, |
| 1857 | width, |
| 1858 | height, |
| 1859 | GL_COLOR_BUFFER_BIT, |
| 1860 | GL_NEAREST); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1861 | glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { |
| 1865 | if (!resolve_and_bind_) |
| 1866 | return; |
| 1867 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1868 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1869 | "ScopedResolvedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1870 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 1871 | if (decoder_->state_.enable_flags.scissor_test) { |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 1872 | glEnable(GL_SCISSOR_TEST); |
| 1873 | } |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1874 | } |
| 1875 | |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1876 | BackTexture::BackTexture( |
| 1877 | MemoryTracker* memory_tracker, |
| 1878 | ContextState* state) |
| 1879 | : memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 1880 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 1881 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1882 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1883 | } |
| 1884 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1885 | BackTexture::~BackTexture() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1886 | // This does not destroy the render texture because that would require that |
| 1887 | // the associated GL context was current. Just check that it was explicitly |
| 1888 | // destroyed. |
| 1889 | DCHECK_EQ(id_, 0u); |
| 1890 | } |
| 1891 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1892 | void BackTexture::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1893 | ScopedGLErrorSuppressor suppressor("BackTexture::Create", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1894 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1895 | Destroy(); |
| 1896 | glGenTextures(1, &id_); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1897 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1898 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 1899 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 1900 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 1901 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
[email protected] | 6278880 | 2011-10-03 17:57:16 | [diff] [blame] | 1902 | |
| 1903 | // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 1904 | // never called on an offscreen context, no data will ever be uploaded to the |
| 1905 | // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 1906 | // is called). My idea is that some nvidia drivers might have a bug where |
| 1907 | // deleting a texture that has never been populated might cause a |
| 1908 | // crash. |
| 1909 | glTexImage2D( |
| 1910 | 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] | 1911 | |
| 1912 | bytes_allocated_ = 16u * 16u * 4u; |
| 1913 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1914 | } |
| 1915 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1916 | bool BackTexture::AllocateStorage( |
| 1917 | const gfx::Size& size, GLenum format, bool zero) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1918 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1919 | ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1920 | state_->GetErrorState()); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1921 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 1922 | uint32 image_size = 0; |
| 1923 | GLES2Util::ComputeImageDataSizes( |
| 1924 | size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size, |
| 1925 | NULL, NULL); |
| 1926 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 1927 | if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { |
| 1928 | return false; |
| 1929 | } |
| 1930 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 1931 | scoped_ptr<char[]> zero_data; |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 1932 | if (zero) { |
| 1933 | zero_data.reset(new char[image_size]); |
| 1934 | memset(zero_data.get(), 0, image_size); |
| 1935 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1936 | |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 1937 | glTexImage2D(GL_TEXTURE_2D, |
| 1938 | 0, // mip level |
| 1939 | format, |
| 1940 | size.width(), |
| 1941 | size.height(), |
| 1942 | 0, // border |
| 1943 | format, |
| 1944 | GL_UNSIGNED_BYTE, |
| 1945 | zero_data.get()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1946 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1947 | size_ = size; |
| 1948 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1949 | bool success = glGetError() == GL_NO_ERROR; |
| 1950 | if (success) { |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 1951 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1952 | bytes_allocated_ = image_size; |
| 1953 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 1954 | } |
| 1955 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1956 | } |
| 1957 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1958 | void BackTexture::Copy(const gfx::Size& size, GLenum format) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1959 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1960 | ScopedGLErrorSuppressor suppressor("BackTexture::Copy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1961 | state_->GetErrorState()); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1962 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1963 | glCopyTexImage2D(GL_TEXTURE_2D, |
| 1964 | 0, // level |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 1965 | format, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1966 | 0, 0, |
| 1967 | size.width(), |
| 1968 | size.height(), |
| 1969 | 0); // border |
| 1970 | } |
| 1971 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1972 | void BackTexture::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1973 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1974 | ScopedGLErrorSuppressor suppressor("BackTexture::Destroy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1975 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1976 | glDeleteTextures(1, &id_); |
| 1977 | id_ = 0; |
| 1978 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 1979 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 1980 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1981 | } |
| 1982 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1983 | void BackTexture::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1984 | id_ = 0; |
| 1985 | } |
| 1986 | |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 1987 | BackRenderbuffer::BackRenderbuffer( |
| 1988 | RenderbufferManager* renderbuffer_manager, |
| 1989 | MemoryTracker* memory_tracker, |
| 1990 | ContextState* state) |
| 1991 | : renderbuffer_manager_(renderbuffer_manager), |
| 1992 | memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 1993 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 1994 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 1995 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1996 | } |
| 1997 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1998 | BackRenderbuffer::~BackRenderbuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1999 | // This does not destroy the render buffer because that would require that |
| 2000 | // the associated GL context was current. Just check that it was explicitly |
| 2001 | // destroyed. |
| 2002 | DCHECK_EQ(id_, 0u); |
| 2003 | } |
| 2004 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2005 | void BackRenderbuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2006 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Create", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2007 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2008 | Destroy(); |
| 2009 | glGenRenderbuffersEXT(1, &id_); |
| 2010 | } |
| 2011 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2012 | bool BackRenderbuffer::AllocateStorage(const FeatureInfo* feature_info, |
| 2013 | const gfx::Size& size, |
| 2014 | GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2015 | GLsizei samples) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2016 | ScopedGLErrorSuppressor suppressor( |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2017 | "BackRenderbuffer::AllocateStorage", state_->GetErrorState()); |
| 2018 | ScopedRenderBufferBinder binder(state_, id_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2019 | |
| 2020 | uint32 estimated_size = 0; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2021 | if (!renderbuffer_manager_->ComputeEstimatedRenderbufferSize( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 2022 | size.width(), size.height(), samples, format, &estimated_size)) { |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2023 | return false; |
| 2024 | } |
| 2025 | |
| 2026 | if (!memory_tracker_.EnsureGPUMemoryAvailable(estimated_size)) { |
| 2027 | return false; |
| 2028 | } |
| 2029 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2030 | if (samples <= 1) { |
| 2031 | glRenderbufferStorageEXT(GL_RENDERBUFFER, |
| 2032 | format, |
| 2033 | size.width(), |
| 2034 | size.height()); |
| 2035 | } else { |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2036 | GLES2DecoderImpl::RenderbufferStorageMultisampleHelper(feature_info, |
| 2037 | GL_RENDERBUFFER, |
| 2038 | samples, |
| 2039 | format, |
| 2040 | size.width(), |
| 2041 | size.height()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2042 | } |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2043 | bool success = glGetError() == GL_NO_ERROR; |
| 2044 | if (success) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2045 | // Mark the previously allocated bytes as free. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2046 | memory_tracker_.TrackMemFree(bytes_allocated_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2047 | bytes_allocated_ = estimated_size; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2048 | // Track the newly allocated bytes. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2049 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2050 | } |
| 2051 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2052 | } |
| 2053 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2054 | void BackRenderbuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2055 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2056 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Destroy", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2057 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2058 | glDeleteRenderbuffersEXT(1, &id_); |
| 2059 | id_ = 0; |
| 2060 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2061 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2062 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2063 | } |
| 2064 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2065 | void BackRenderbuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2066 | id_ = 0; |
| 2067 | } |
| 2068 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2069 | BackFramebuffer::BackFramebuffer(GLES2DecoderImpl* decoder) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2070 | : decoder_(decoder), |
| 2071 | id_(0) { |
| 2072 | } |
| 2073 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2074 | BackFramebuffer::~BackFramebuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2075 | // This does not destroy the frame buffer because that would require that |
| 2076 | // the associated GL context was current. Just check that it was explicitly |
| 2077 | // destroyed. |
| 2078 | DCHECK_EQ(id_, 0u); |
| 2079 | } |
| 2080 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2081 | void BackFramebuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2082 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Create", |
| 2083 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2084 | Destroy(); |
| 2085 | glGenFramebuffersEXT(1, &id_); |
| 2086 | } |
| 2087 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2088 | void BackFramebuffer::AttachRenderTexture(BackTexture* texture) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2089 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2090 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2091 | "BackFramebuffer::AttachRenderTexture", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2092 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2093 | GLuint attach_id = texture ? texture->id() : 0; |
| 2094 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 2095 | GL_COLOR_ATTACHMENT0, |
| 2096 | GL_TEXTURE_2D, |
| 2097 | attach_id, |
| 2098 | 0); |
| 2099 | } |
| 2100 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2101 | void BackFramebuffer::AttachRenderBuffer(GLenum target, |
| 2102 | BackRenderbuffer* render_buffer) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2103 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2104 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2105 | "BackFramebuffer::AttachRenderBuffer", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2106 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2107 | GLuint attach_id = render_buffer ? render_buffer->id() : 0; |
| 2108 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2109 | target, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2110 | GL_RENDERBUFFER, |
| 2111 | attach_id); |
| 2112 | } |
| 2113 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2114 | void BackFramebuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2115 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2116 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Destroy", |
| 2117 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2118 | glDeleteFramebuffersEXT(1, &id_); |
| 2119 | id_ = 0; |
| 2120 | } |
| 2121 | } |
| 2122 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2123 | void BackFramebuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2124 | id_ = 0; |
| 2125 | } |
| 2126 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2127 | GLenum BackFramebuffer::CheckStatus() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2128 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2129 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::CheckStatus", |
| 2130 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2131 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2132 | return glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 2133 | } |
| 2134 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2135 | GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) { |
| 2136 | return new GLES2DecoderImpl(group); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2137 | } |
| 2138 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2139 | GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2140 | : GLES2Decoder(), |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2141 | group_(group), |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 2142 | logger_(&debug_marker_manager_), |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 2143 | state_(group_->feature_info(), &logger_), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2144 | unpack_flip_y_(false), |
| 2145 | unpack_premultiply_alpha_(false), |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 2146 | unpack_unpremultiply_alpha_(false), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2147 | attrib_0_buffer_id_(0), |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 2148 | attrib_0_buffer_matches_value_(true), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2149 | attrib_0_size_(0), |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2150 | fixed_attrib_buffer_id_(0), |
| 2151 | fixed_attrib_buffer_size_(0), |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2152 | offscreen_target_color_format_(0), |
| 2153 | offscreen_target_depth_format_(0), |
| 2154 | offscreen_target_stencil_format_(0), |
| 2155 | offscreen_target_samples_(0), |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2156 | offscreen_target_buffer_preserved_(true), |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2157 | offscreen_saved_color_format_(0), |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 2158 | back_buffer_color_format_(0), |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2159 | back_buffer_has_depth_(false), |
| 2160 | back_buffer_has_stencil_(false), |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 2161 | backbuffer_needs_clear_bits_(0), |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 2162 | current_decoder_error_(error::kNoError), |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 2163 | use_shader_translator_(true), |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 2164 | validators_(group_->feature_info()->validators()), |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 2165 | feature_info_(group_->feature_info()), |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2166 | frame_number_(0), |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2167 | has_robustness_extension_(false), |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 2168 | reset_status_(GL_NO_ERROR), |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 2169 | reset_by_robustness_extension_(false), |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2170 | force_webgl_glsl_validation_(false), |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2171 | derivatives_explicitly_enabled_(false), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2172 | frag_depth_explicitly_enabled_(false), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 2173 | draw_buffers_explicitly_enabled_(false), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2174 | compile_shader_always_succeeds_(false), |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 2175 | service_logging_(CommandLine::ForCurrentProcess()->HasSwitch( |
| 2176 | switches::kEnableGPUServiceLoggingGPU)), |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2177 | viewport_max_width_(0), |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2178 | viewport_max_height_(0), |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 2179 | texture_state_(group_->feature_info() |
| 2180 | ->workarounds() |
| 2181 | .texsubimage2d_faster_than_teximage2d), |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2182 | validation_texture_(0), |
| 2183 | validation_fbo_multisample_(0), |
| 2184 | validation_fbo_(0) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2185 | DCHECK(group); |
| 2186 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2187 | attrib_0_value_.v[0] = 0.0f; |
| 2188 | attrib_0_value_.v[1] = 0.0f; |
| 2189 | attrib_0_value_.v[2] = 0.0f; |
| 2190 | attrib_0_value_.v[3] = 1.0f; |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2191 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2192 | // The shader translator is used for WebGL even when running on EGL |
| 2193 | // because additional restrictions are needed (like only enabling |
| 2194 | // GL_OES_standard_derivatives on demand). It is used for the unit |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 2195 | // tests because GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes |
| 2196 | // the empty string to CompileShader and this is not a valid shader. |
| 2197 | if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL || |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2198 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 2199 | switches::kDisableGLSLTranslator)) { |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2200 | use_shader_translator_ = false; |
| 2201 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2202 | } |
| 2203 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2204 | GLES2DecoderImpl::~GLES2DecoderImpl() { |
| 2205 | } |
| 2206 | |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2207 | bool GLES2DecoderImpl::Initialize( |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2208 | const scoped_refptr<gfx::GLSurface>& surface, |
| 2209 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2210 | bool offscreen, |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2211 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2212 | const DisallowedFeatures& disallowed_features, |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2213 | const std::vector<int32>& attribs) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 2214 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2215 | DCHECK(context->IsCurrent(surface.get())); |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 2216 | DCHECK(!context_.get()); |
| 2217 | |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 2218 | set_initialized(); |
[email protected] | bccc0f3 | 2014-01-10 03:18:08 | [diff] [blame] | 2219 | gpu_tracer_ = GPUTracer::Create(this); |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 2220 | gpu_state_tracer_ = GPUStateTracer::Create(&state_); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 2221 | // TODO(vmiura): Enable changing gpu_trace_level_ at runtime |
| 2222 | gpu_trace_level_ = 2; |
| 2223 | gpu_trace_commands_ = false; |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 2224 | |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 2225 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2226 | switches::kEnableGPUDebugging)) { |
| 2227 | set_debug(true); |
| 2228 | } |
| 2229 | |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2230 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2231 | switches::kEnableGPUCommandLogging)) { |
| 2232 | set_log_commands(true); |
| 2233 | } |
| 2234 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2235 | compile_shader_always_succeeds_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 2236 | switches::kCompileShaderAlwaysSucceeds); |
| 2237 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 2238 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2239 | // Take ownership of the context and surface. The surface can be replaced with |
| 2240 | // SetSurface. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2241 | context_ = context; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2242 | surface_ = surface; |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2243 | |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 2244 | ContextCreationAttribHelper attrib_parser; |
| 2245 | if (!attrib_parser.Parse(attribs)) |
| 2246 | return false; |
| 2247 | |
| 2248 | // If the failIfMajorPerformanceCaveat context creation attribute was true |
| 2249 | // and we are using a software renderer, fail. |
| 2250 | if (attrib_parser.fail_if_major_perf_caveat_ && |
| 2251 | feature_info_->feature_flags().is_swiftshader) { |
| 2252 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
| 2253 | Destroy(true); |
| 2254 | return false; |
| 2255 | } |
| 2256 | |
[email protected] | 956aec5 | 2013-09-05 15:41:19 | [diff] [blame] | 2257 | if (!group_->Initialize(this, disallowed_features)) { |
[email protected] | 09ddb91f | 2011-04-14 23:16:22 | [diff] [blame] | 2258 | LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2259 | << "failed to initialize."; |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 2260 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2261 | Destroy(true); |
[email protected] | ae174109 | 2010-11-17 19:16:03 | [diff] [blame] | 2262 | return false; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2263 | } |
[email protected] | b64c2495 | 2012-04-19 03:20:27 | [diff] [blame] | 2264 | CHECK_GL_ERROR(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2265 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2266 | disallowed_features_ = disallowed_features; |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2267 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 2268 | state_.attrib_values.resize(group_->max_vertex_attribs()); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2269 | default_vertex_attrib_manager_ = new VertexAttribManager(); |
| 2270 | default_vertex_attrib_manager_->Initialize(group_->max_vertex_attribs()); |
| 2271 | |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 2272 | // vertex_attrib_manager is set to default_vertex_attrib_manager_ by this call |
| 2273 | DoBindVertexArrayOES(0); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 2274 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2275 | query_manager_.reset(new QueryManager(this, feature_info_.get())); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2276 | vertex_array_manager_.reset(new VertexArrayManager()); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 2277 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2278 | util_.set_num_compressed_texture_formats( |
| 2279 | validators_->compressed_texture_format.GetValues().size()); |
| 2280 | |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 2281 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2282 | // We have to enable vertex array 0 on OpenGL or it won't render. Note that |
| 2283 | // OpenGL ES 2.0 does not have this issue. |
| 2284 | glEnableVertexAttribArray(0); |
| 2285 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2286 | glGenBuffersARB(1, &attrib_0_buffer_id_); |
| 2287 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 2288 | glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); |
| 2289 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2290 | glGenBuffersARB(1, &fixed_attrib_buffer_id_); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 2291 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2292 | state_.texture_units.resize(group_->max_texture_units()); |
| 2293 | for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) { |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2294 | glActiveTexture(GL_TEXTURE0 + tt); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2295 | // We want the last bind to be 2D. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2296 | TextureRef* ref; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2297 | if (features().oes_egl_image_external) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2298 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2299 | GL_TEXTURE_EXTERNAL_OES); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2300 | state_.texture_units[tt].bound_texture_external_oes = ref; |
| 2301 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, ref->service_id()); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2302 | } |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2303 | if (features().arb_texture_rectangle) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2304 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2305 | GL_TEXTURE_RECTANGLE_ARB); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2306 | state_.texture_units[tt].bound_texture_rectangle_arb = ref; |
| 2307 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, ref->service_id()); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2308 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2309 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
| 2310 | state_.texture_units[tt].bound_texture_cube_map = ref; |
| 2311 | glBindTexture(GL_TEXTURE_CUBE_MAP, ref->service_id()); |
| 2312 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
| 2313 | state_.texture_units[tt].bound_texture_2d = ref; |
| 2314 | glBindTexture(GL_TEXTURE_2D, ref->service_id()); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 2315 | } |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2316 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2317 | CHECK_GL_ERROR(); |
| 2318 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2319 | if (offscreen) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2320 | if (attrib_parser.samples_ > 0 && attrib_parser.sample_buffers_ > 0 && |
[email protected] | b060965 | 2012-12-14 07:24:54 | [diff] [blame] | 2321 | features().chromium_framebuffer_multisample) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2322 | // Per ext_framebuffer_multisample spec, need max bound on sample count. |
[email protected] | 0b1e9d7 | 2010-11-11 16:29:43 | [diff] [blame] | 2323 | // max_sample_count must be initialized to a sane value. If |
| 2324 | // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
| 2325 | GLint max_sample_count = 1; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2326 | glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
| 2327 | offscreen_target_samples_ = std::min(attrib_parser.samples_, |
| 2328 | max_sample_count); |
| 2329 | } else { |
| 2330 | offscreen_target_samples_ = 1; |
| 2331 | } |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2332 | offscreen_target_buffer_preserved_ = attrib_parser.buffer_preserved_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2333 | |
| 2334 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 2335 | const bool rgb8_supported = |
| 2336 | context_->HasExtension("GL_OES_rgb8_rgba8"); |
| 2337 | // The only available default render buffer formats in GLES2 have very |
| 2338 | // little precision. Don't enable multisampling unless 8-bit render |
| 2339 | // buffer formats are available--instead fall back to 8-bit textures. |
| 2340 | if (rgb8_supported && offscreen_target_samples_ > 1) { |
| 2341 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2342 | GL_RGBA8 : GL_RGB8; |
| 2343 | } else { |
| 2344 | offscreen_target_samples_ = 1; |
| 2345 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2346 | GL_RGBA : GL_RGB; |
| 2347 | } |
| 2348 | |
| 2349 | // ANGLE only supports packed depth/stencil formats, so use it if it is |
| 2350 | // available. |
| 2351 | const bool depth24_stencil8_supported = |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2352 | feature_info_->feature_flags().packed_depth24_stencil8; |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2353 | VLOG(1) << "GL_OES_packed_depth_stencil " |
| 2354 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2355 | if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && |
| 2356 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2357 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2358 | offscreen_target_stencil_format_ = 0; |
| 2359 | } else { |
| 2360 | // It may be the case that this depth/stencil combination is not |
| 2361 | // supported, but this will be checked later by CheckFramebufferStatus. |
| 2362 | offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? |
| 2363 | GL_DEPTH_COMPONENT16 : 0; |
| 2364 | offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? |
| 2365 | GL_STENCIL_INDEX8 : 0; |
| 2366 | } |
| 2367 | } else { |
| 2368 | offscreen_target_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2369 | GL_RGBA : GL_RGB; |
| 2370 | |
| 2371 | // If depth is requested at all, use the packed depth stencil format if |
| 2372 | // it's available, as some desktop GL drivers don't support any non-packed |
| 2373 | // formats for depth attachments. |
| 2374 | const bool depth24_stencil8_supported = |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2375 | feature_info_->feature_flags().packed_depth24_stencil8; |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2376 | VLOG(1) << "GL_EXT_packed_depth_stencil " |
| 2377 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2378 | |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2379 | if ((attrib_parser.depth_size_ > 0 || attrib_parser.stencil_size_ > 0) && |
| 2380 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2381 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2382 | offscreen_target_stencil_format_ = 0; |
| 2383 | } else { |
| 2384 | offscreen_target_depth_format_ = attrib_parser.depth_size_ > 0 ? |
| 2385 | GL_DEPTH_COMPONENT : 0; |
| 2386 | offscreen_target_stencil_format_ = attrib_parser.stencil_size_ > 0 ? |
| 2387 | GL_STENCIL_INDEX : 0; |
| 2388 | } |
| 2389 | } |
| 2390 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2391 | offscreen_saved_color_format_ = attrib_parser.alpha_size_ > 0 ? |
| 2392 | GL_RGBA : GL_RGB; |
| 2393 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2394 | // Create the target frame buffer. This is the one that the client renders |
| 2395 | // directly to. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2396 | offscreen_target_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2397 | offscreen_target_frame_buffer_->Create(); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2398 | // Due to GLES2 format limitations, either the color texture (for |
| 2399 | // non-multisampling) or the color render buffer (for multisampling) will be |
| 2400 | // attached to the offscreen frame buffer. The render buffer has more |
| 2401 | // limited formats available to it, but the texture can't do multisampling. |
| 2402 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2403 | offscreen_target_color_render_buffer_.reset(new BackRenderbuffer( |
| 2404 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2405 | offscreen_target_color_render_buffer_->Create(); |
| 2406 | } else { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2407 | offscreen_target_color_texture_.reset(new BackTexture( |
| 2408 | memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2409 | offscreen_target_color_texture_->Create(); |
| 2410 | } |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2411 | offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer( |
| 2412 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2413 | offscreen_target_depth_render_buffer_->Create(); |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2414 | offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer( |
| 2415 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2416 | offscreen_target_stencil_render_buffer_->Create(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2417 | |
| 2418 | // Create the saved offscreen texture. The target frame buffer is copied |
| 2419 | // here when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2420 | offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2421 | offscreen_saved_frame_buffer_->Create(); |
| 2422 | // |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2423 | offscreen_saved_color_texture_.reset(new BackTexture( |
| 2424 | memory_tracker(), &state_)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2425 | offscreen_saved_color_texture_->Create(); |
| 2426 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2427 | // Allocate the render buffers at their initial size and check the status |
| 2428 | // of the frame buffers is okay. |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2429 | if (!ResizeOffscreenFrameBuffer(size)) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 2430 | LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2431 | Destroy(true); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2432 | return false; |
| 2433 | } |
| 2434 | |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2435 | // Allocate the offscreen saved color texture. |
| 2436 | DCHECK(offscreen_saved_color_format_); |
| 2437 | offscreen_saved_color_texture_->AllocateStorage( |
| 2438 | gfx::Size(1, 1), offscreen_saved_color_format_, true); |
| 2439 | |
| 2440 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 2441 | offscreen_saved_color_texture_.get()); |
| 2442 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 2443 | GL_FRAMEBUFFER_COMPLETE) { |
| 2444 | LOG(ERROR) << "Offscreen saved FBO was incomplete."; |
| 2445 | Destroy(true); |
| 2446 | return false; |
| 2447 | } |
| 2448 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2449 | // Bind to the new default frame buffer (the offscreen target frame buffer). |
| 2450 | // This should now be associated with ID zero. |
| 2451 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 2452 | } else { |
| 2453 | glBindFramebufferEXT(GL_FRAMEBUFFER, GetBackbufferServiceId()); |
| 2454 | // These are NOT if the back buffer has these proprorties. They are |
| 2455 | // if we want the command buffer to enforce them regardless of what |
| 2456 | // the real backbuffer is assuming the real back buffer gives us more than |
| 2457 | // we ask for. In other words, if we ask for RGB and we get RGBA then we'll |
| 2458 | // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we |
| 2459 | // can't do anything about that. |
| 2460 | |
| 2461 | GLint v = 0; |
| 2462 | glGetIntegerv(GL_ALPHA_BITS, &v); |
| 2463 | // This checks if the user requested RGBA and we have RGBA then RGBA. If the |
| 2464 | // user requested RGB then RGB. If the user did not specify a preference |
| 2465 | // than use whatever we were given. Same for DEPTH and STENCIL. |
| 2466 | back_buffer_color_format_ = |
| 2467 | (attrib_parser.alpha_size_ != 0 && v > 0) ? GL_RGBA : GL_RGB; |
| 2468 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 2469 | back_buffer_has_depth_ = attrib_parser.depth_size_ != 0 && v > 0; |
| 2470 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 2471 | back_buffer_has_stencil_ = attrib_parser.stencil_size_ != 0 && v > 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2472 | } |
| 2473 | |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2474 | // OpenGL ES 2.0 implicitly enables the desktop GL capability |
| 2475 | // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact |
| 2476 | // isn't well documented; it was discovered in the Khronos OpenGL ES |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2477 | // mailing list archives. It also implicitly enables the desktop GL |
| 2478 | // capability GL_POINT_SPRITE to provide access to the gl_PointCoord |
| 2479 | // variable in fragment shaders. |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2480 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2481 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2482 | glEnable(GL_POINT_SPRITE); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2483 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2484 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2485 | has_robustness_extension_ = |
| 2486 | context->HasExtension("GL_ARB_robustness") || |
| 2487 | context->HasExtension("GL_EXT_robustness"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2488 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2489 | if (!InitializeShaderTranslator()) { |
| 2490 | return false; |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2491 | } |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2492 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2493 | state_.viewport_width = size.width(); |
| 2494 | state_.viewport_height = size.height(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2495 | |
[email protected] | 5904806b | 2012-05-08 18:10:22 | [diff] [blame] | 2496 | GLint viewport_params[4] = { 0 }; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2497 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2498 | viewport_max_width_ = viewport_params[0]; |
| 2499 | viewport_max_height_ = viewport_params[1]; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2500 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2501 | state_.scissor_width = state_.viewport_width; |
| 2502 | state_.scissor_height = state_.viewport_height; |
| 2503 | |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2504 | // Set all the default state because some GL drivers get it wrong. |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 2505 | state_.InitCapabilities(); |
| 2506 | state_.InitState(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2507 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2508 | |
| 2509 | DoBindBuffer(GL_ARRAY_BUFFER, 0); |
| 2510 | DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 2511 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2512 | DoBindRenderbuffer(GL_RENDERBUFFER, 0); |
| 2513 | |
[email protected] | 88cfd13 | 2013-07-11 00:59:00 | [diff] [blame] | 2514 | bool call_gl_clear = true; |
| 2515 | #if defined(OS_ANDROID) |
| 2516 | // Temporary workaround for Android WebView because this clear ignores the |
| 2517 | // clip and corrupts that external UI of the App. Not calling glClear is ok |
| 2518 | // because the system already clears the buffer before each draw. Proper |
| 2519 | // fix might be setting the scissor clip properly before initialize. See |
| 2520 | // crbug.com/259023 for details. |
| 2521 | call_gl_clear = surface_->GetHandle(); |
| 2522 | #endif |
| 2523 | if (call_gl_clear) { |
| 2524 | // Clear the backbuffer. |
| 2525 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 2526 | } |
[email protected] | 561cc0a6 | 2013-05-07 18:34:45 | [diff] [blame] | 2527 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2528 | if (feature_info_->workarounds().reverse_point_sprite_coord_origin) { |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2529 | glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); |
| 2530 | } |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2531 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 2532 | if (feature_info_->workarounds().unbind_fbo_on_context_switch) { |
| 2533 | context_->SetUnbindFboOnMakeCurrent(); |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2534 | } |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2535 | |
[email protected] | 40245ccf | 2013-11-13 04:00:49 | [diff] [blame] | 2536 | if (feature_info_->workarounds().release_image_after_use) { |
| 2537 | image_manager()->SetReleaseAfterUse(); |
| 2538 | } |
| 2539 | |
[email protected] | 97419c0 | 2013-04-10 02:52:38 | [diff] [blame] | 2540 | // Only compositor contexts are known to use only the subset of GL |
| 2541 | // that can be safely migrated between the iGPU and the dGPU. Mark |
| 2542 | // those contexts as safe to forcibly transition between the GPUs. |
| 2543 | // http://crbug.com/180876, http://crbug.com/227228 |
| 2544 | if (!offscreen) |
| 2545 | context_->SetSafeToForceGpuSwitch(); |
| 2546 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 2547 | async_pixel_transfer_manager_.reset( |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 2548 | AsyncPixelTransferManager::Create(context.get())); |
| 2549 | async_pixel_transfer_manager_->Initialize(texture_manager()); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 2550 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 2551 | framebuffer_manager()->AddObserver(this); |
| 2552 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2553 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2554 | } |
| 2555 | |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2556 | Capabilities GLES2DecoderImpl::GetCapabilities() { |
| 2557 | DCHECK(initialized()); |
| 2558 | |
| 2559 | Capabilities caps; |
| 2560 | |
| 2561 | caps.fast_npot_mo8_textures = |
| 2562 | feature_info_->workarounds().enable_chromium_fast_npot_mo8_textures; |
| 2563 | caps.egl_image_external = |
| 2564 | feature_info_->feature_flags().oes_egl_image_external; |
| 2565 | caps.texture_format_bgra8888 = |
| 2566 | feature_info_->feature_flags().ext_texture_format_bgra8888; |
| 2567 | caps.texture_format_etc1 = |
| 2568 | feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; |
| 2569 | caps.texture_rectangle = feature_info_->feature_flags().arb_texture_rectangle; |
| 2570 | caps.texture_usage = feature_info_->feature_flags().angle_texture_usage; |
| 2571 | caps.texture_storage = feature_info_->feature_flags().ext_texture_storage; |
| 2572 | caps.discard_framebuffer = |
| 2573 | feature_info_->feature_flags().ext_discard_framebuffer; |
| 2574 | |
| 2575 | #if defined(OS_MACOSX) |
| 2576 | // This is unconditionally true on mac, no need to test for it at runtime. |
| 2577 | caps.iosurface = true; |
| 2578 | #endif |
| 2579 | |
[email protected] | 35387b3b | 2014-01-11 22:50:11 | [diff] [blame] | 2580 | caps.post_sub_buffer = surface_->HasExtension("GL_CHROMIUM_post_sub_buffer"); |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2581 | |
| 2582 | return caps; |
| 2583 | } |
| 2584 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2585 | void GLES2DecoderImpl::UpdateCapabilities() { |
| 2586 | util_.set_num_compressed_texture_formats( |
| 2587 | validators_->compressed_texture_format.GetValues().size()); |
| 2588 | util_.set_num_shader_binary_formats( |
| 2589 | validators_->shader_binary_format.GetValues().size()); |
| 2590 | } |
| 2591 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2592 | bool GLES2DecoderImpl::InitializeShaderTranslator() { |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 2593 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::InitializeShaderTranslator"); |
| 2594 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2595 | if (!use_shader_translator_) { |
| 2596 | return true; |
| 2597 | } |
| 2598 | ShBuiltInResources resources; |
| 2599 | ShInitBuiltInResources(&resources); |
| 2600 | resources.MaxVertexAttribs = group_->max_vertex_attribs(); |
| 2601 | resources.MaxVertexUniformVectors = |
| 2602 | group_->max_vertex_uniform_vectors(); |
| 2603 | resources.MaxVaryingVectors = group_->max_varying_vectors(); |
| 2604 | resources.MaxVertexTextureImageUnits = |
| 2605 | group_->max_vertex_texture_image_units(); |
| 2606 | resources.MaxCombinedTextureImageUnits = group_->max_texture_units(); |
| 2607 | resources.MaxTextureImageUnits = group_->max_texture_image_units(); |
| 2608 | resources.MaxFragmentUniformVectors = |
| 2609 | group_->max_fragment_uniform_vectors(); |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 2610 | resources.MaxDrawBuffers = group_->max_draw_buffers(); |
[email protected] | a0b7814 | 2013-05-23 00:47:24 | [diff] [blame] | 2611 | resources.MaxExpressionComplexity = 256; |
| 2612 | resources.MaxCallStackDepth = 256; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2613 | |
[email protected] | 9e98f61b | 2013-03-05 02:21:14 | [diff] [blame] | 2614 | #if (ANGLE_SH_VERSION >= 110) |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 2615 | GLint range[2] = { 0, 0 }; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 2616 | GLint precision = 0; |
| 2617 | GetShaderPrecisionFormatImpl(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, |
| 2618 | range, &precision); |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 2619 | resources.FragmentPrecisionHigh = |
| 2620 | PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision); |
[email protected] | 9e98f61b | 2013-03-05 02:21:14 | [diff] [blame] | 2621 | #endif |
| 2622 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2623 | if (force_webgl_glsl_validation_) { |
| 2624 | resources.OES_standard_derivatives = derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2625 | resources.EXT_frag_depth = frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 2626 | resources.EXT_draw_buffers = draw_buffers_explicitly_enabled_; |
[email protected] | cd8f189 | 2013-09-05 00:14:44 | [diff] [blame] | 2627 | if (!draw_buffers_explicitly_enabled_) |
| 2628 | resources.MaxDrawBuffers = 1; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2629 | } else { |
| 2630 | resources.OES_standard_derivatives = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2631 | features().oes_standard_derivatives ? 1 : 0; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2632 | resources.ARB_texture_rectangle = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2633 | features().arb_texture_rectangle ? 1 : 0; |
[email protected] | 70e7bb1 | 2012-09-29 14:01:06 | [diff] [blame] | 2634 | resources.OES_EGL_image_external = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2635 | features().oes_egl_image_external ? 1 : 0; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 2636 | resources.EXT_draw_buffers = |
| 2637 | features().ext_draw_buffers ? 1 : 0; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2638 | resources.EXT_frag_depth = |
| 2639 | features().ext_frag_depth ? 1 : 0; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2640 | } |
| 2641 | |
[email protected] | 26b6144 | 2013-03-17 16:12:01 | [diff] [blame] | 2642 | ShShaderSpec shader_spec = force_webgl_glsl_validation_ ? SH_WEBGL_SPEC |
| 2643 | : SH_GLES2_SPEC; |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2644 | if (shader_spec == SH_WEBGL_SPEC && features().enable_shader_name_hashing) |
[email protected] | 3d944a8 | 2013-02-12 19:09:02 | [diff] [blame] | 2645 | #if !defined(ANGLE_SH_VERSION) || ANGLE_SH_VERSION < 108 |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2646 | resources.HashFunction = &CityHashForAngle; |
[email protected] | 3d944a8 | 2013-02-12 19:09:02 | [diff] [blame] | 2647 | #else |
| 2648 | resources.HashFunction = &CityHash64; |
| 2649 | #endif |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2650 | else |
| 2651 | resources.HashFunction = NULL; |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2652 | ShaderTranslatorInterface::GlslImplementationType implementation_type = |
| 2653 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? |
| 2654 | ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2655 | int driver_bug_workarounds = 0; |
| 2656 | if (workarounds().needs_glsl_built_in_function_emulation) |
| 2657 | driver_bug_workarounds |= SH_EMULATE_BUILT_IN_FUNCTIONS; |
[email protected] | 81187c6 | 2013-09-09 23:54:54 | [diff] [blame] | 2658 | if (workarounds().init_gl_position_in_vertex_shader) |
| 2659 | driver_bug_workarounds |= SH_INIT_GL_POSITION; |
[email protected] | f0c8760 | 2013-10-17 19:34:11 | [diff] [blame] | 2660 | if (workarounds().unfold_short_circuit_as_ternary_operation) |
| 2661 | driver_bug_workarounds |= SH_UNFOLD_SHORT_CIRCUIT; |
[email protected] | b03219d | 2014-02-12 11:17:05 | [diff] [blame] | 2662 | if (workarounds().init_varyings_without_static_use) |
| 2663 | driver_bug_workarounds |= SH_INIT_VARYINGS_WITHOUT_STATIC_USE; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2664 | |
| 2665 | ShaderTranslatorCache* cache = ShaderTranslatorCache::GetInstance(); |
| 2666 | vertex_translator_ = cache->GetTranslator( |
| 2667 | SH_VERTEX_SHADER, shader_spec, &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2668 | implementation_type, |
| 2669 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2670 | if (!vertex_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2671 | LOG(ERROR) << "Could not initialize vertex shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2672 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2673 | return false; |
| 2674 | } |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2675 | |
| 2676 | fragment_translator_ = cache->GetTranslator( |
| 2677 | SH_FRAGMENT_SHADER, shader_spec, &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2678 | implementation_type, |
| 2679 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2680 | if (!fragment_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2681 | LOG(ERROR) << "Could not initialize fragment shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2682 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2683 | return false; |
| 2684 | } |
| 2685 | return true; |
| 2686 | } |
| 2687 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2688 | bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2689 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2690 | if (GetBuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2691 | return false; |
| 2692 | } |
| 2693 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2694 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2695 | glGenBuffersARB(n, service_ids.get()); |
| 2696 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2697 | CreateBuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2698 | } |
| 2699 | return true; |
| 2700 | } |
| 2701 | |
| 2702 | bool GLES2DecoderImpl::GenFramebuffersHelper( |
| 2703 | GLsizei n, const GLuint* client_ids) { |
| 2704 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2705 | if (GetFramebuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2706 | return false; |
| 2707 | } |
| 2708 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2709 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2710 | glGenFramebuffersEXT(n, service_ids.get()); |
| 2711 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2712 | CreateFramebuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2713 | } |
| 2714 | return true; |
| 2715 | } |
| 2716 | |
| 2717 | bool GLES2DecoderImpl::GenRenderbuffersHelper( |
| 2718 | GLsizei n, const GLuint* client_ids) { |
| 2719 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2720 | if (GetRenderbuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2721 | return false; |
| 2722 | } |
| 2723 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2724 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2725 | glGenRenderbuffersEXT(n, service_ids.get()); |
| 2726 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2727 | CreateRenderbuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2728 | } |
| 2729 | return true; |
| 2730 | } |
| 2731 | |
| 2732 | bool GLES2DecoderImpl::GenTexturesHelper(GLsizei n, const GLuint* client_ids) { |
| 2733 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2734 | if (GetTexture(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2735 | return false; |
| 2736 | } |
| 2737 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2738 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2739 | glGenTextures(n, service_ids.get()); |
| 2740 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2741 | CreateTexture(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2742 | } |
| 2743 | return true; |
| 2744 | } |
| 2745 | |
| 2746 | void GLES2DecoderImpl::DeleteBuffersHelper( |
| 2747 | GLsizei n, const GLuint* client_ids) { |
| 2748 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 2749 | Buffer* buffer = GetBuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2750 | if (buffer && !buffer->IsDeleted()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2751 | state_.vertex_attrib_manager->Unbind(buffer); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2752 | if (state_.bound_array_buffer.get() == buffer) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2753 | state_.bound_array_buffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2754 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2755 | RemoveBuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2756 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2757 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2758 | } |
| 2759 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2760 | void GLES2DecoderImpl::DeleteFramebuffersHelper( |
| 2761 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2762 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2763 | features().chromium_framebuffer_multisample; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2764 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2765 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2766 | Framebuffer* framebuffer = |
| 2767 | GetFramebuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2768 | if (framebuffer && !framebuffer->IsDeleted()) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2769 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2770 | framebuffer_state_.bound_draw_framebuffer = NULL; |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2771 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2772 | GLenum target = supports_separate_framebuffer_binds ? |
| 2773 | GL_DRAW_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2774 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
| 2775 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2776 | if (framebuffer == framebuffer_state_.bound_read_framebuffer.get()) { |
| 2777 | framebuffer_state_.bound_read_framebuffer = NULL; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2778 | GLenum target = supports_separate_framebuffer_binds ? |
| 2779 | GL_READ_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2780 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2781 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 2782 | OnFboChanged(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2783 | RemoveFramebuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2784 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2785 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2786 | } |
| 2787 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2788 | void GLES2DecoderImpl::DeleteRenderbuffersHelper( |
| 2789 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2790 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2791 | features().chromium_framebuffer_multisample; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2792 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2793 | Renderbuffer* renderbuffer = |
| 2794 | GetRenderbuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2795 | if (renderbuffer && !renderbuffer->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2796 | if (state_.bound_renderbuffer.get() == renderbuffer) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2797 | state_.bound_renderbuffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2798 | } |
| 2799 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2800 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2801 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 2802 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2803 | ->UnbindRenderbuffer(GL_READ_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2804 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2805 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2806 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2807 | ->UnbindRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2808 | } |
| 2809 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2810 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2811 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2812 | ->UnbindRenderbuffer(GL_FRAMEBUFFER, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2813 | } |
| 2814 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2815 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2816 | RemoveRenderbuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2817 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2818 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2819 | } |
| 2820 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2821 | void GLES2DecoderImpl::DeleteTexturesHelper( |
| 2822 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2823 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2824 | features().chromium_framebuffer_multisample; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2825 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2826 | TextureRef* texture_ref = GetTexture(client_ids[ii]); |
| 2827 | if (texture_ref) { |
| 2828 | Texture* texture = texture_ref->texture(); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2829 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2830 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2831 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2832 | // Unbind texture_ref from texture_ref units. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2833 | for (size_t jj = 0; jj < state_.texture_units.size(); ++jj) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2834 | state_.texture_units[jj].Unbind(texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2835 | } |
| 2836 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2837 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2838 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 2839 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2840 | ->UnbindTexture(GL_READ_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2841 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2842 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2843 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2844 | ->UnbindTexture(GL_DRAW_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2845 | } |
| 2846 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2847 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2848 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2849 | ->UnbindTexture(GL_FRAMEBUFFER, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2850 | } |
| 2851 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2852 | #if defined(OS_MACOSX) |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 2853 | GLuint service_id = texture->service_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2854 | if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { |
| 2855 | ReleaseIOSurfaceForTexture(service_id); |
| 2856 | } |
| 2857 | #endif |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2858 | RemoveTexture(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2859 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2860 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2861 | } |
| 2862 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 2863 | // } // anonymous namespace |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2864 | |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2865 | bool GLES2DecoderImpl::MakeCurrent() { |
[email protected] | 177d134 | 2013-12-07 04:20:34 | [diff] [blame] | 2866 | if (!context_.get()) |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2867 | return false; |
| 2868 | |
[email protected] | 177d134 | 2013-12-07 04:20:34 | [diff] [blame] | 2869 | if (!context_->MakeCurrent(surface_.get()) || WasContextLost()) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2870 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during MakeCurrent."; |
[email protected] | e9f0ca8 | 2013-04-01 23:52:29 | [diff] [blame] | 2871 | |
| 2872 | // Some D3D drivers cannot recover from device lost in the GPU process |
| 2873 | // sandbox. Allow a new GPU process to launch. |
| 2874 | if (workarounds().exit_on_context_lost) { |
| 2875 | LOG(ERROR) << "Exiting GPU process because some drivers cannot reset" |
| 2876 | << " a D3D device in the Chrome GPU process sandbox."; |
[email protected] | 6eb77535 | 2013-08-27 05:57:16 | [diff] [blame] | 2877 | #if defined(OS_WIN) |
| 2878 | base::win::SetShouldCrashOnProcessDetach(false); |
| 2879 | #endif |
[email protected] | e9f0ca8 | 2013-04-01 23:52:29 | [diff] [blame] | 2880 | exit(0); |
| 2881 | } |
| 2882 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2883 | return false; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2884 | } |
| 2885 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 2886 | ProcessFinishedAsyncTransfers(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 2887 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 2888 | // Rebind the FBO if it was unbound by the context. |
| 2889 | if (workarounds().unbind_fbo_on_context_switch) |
| 2890 | RestoreFramebufferBindings(); |
| 2891 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2892 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2893 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 2894 | return true; |
| 2895 | } |
| 2896 | |
| 2897 | void GLES2DecoderImpl::ProcessFinishedAsyncTransfers() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 2898 | ProcessPendingReadPixels(); |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 2899 | if (engine() && query_manager_.get()) |
| 2900 | query_manager_->ProcessPendingTransferQueries(); |
| 2901 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 2902 | // TODO(epenner): Is there a better place to do this? |
| 2903 | // This needs to occur before we execute any batch of commands |
| 2904 | // from the client, as the client may have recieved an async |
| 2905 | // completion while issuing those commands. |
| 2906 | // "DidFlushStart" would be ideal if we had such a callback. |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 2907 | async_pixel_transfer_manager_->BindCompletedAsyncTransfers(); |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2908 | } |
| 2909 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2910 | static void RebindCurrentFramebuffer( |
| 2911 | GLenum target, |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 2912 | Framebuffer* framebuffer, |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2913 | GLuint back_buffer_service_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 2914 | GLuint framebuffer_id = framebuffer ? framebuffer->service_id() : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2915 | |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2916 | if (framebuffer_id == 0) { |
| 2917 | framebuffer_id = back_buffer_service_id; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2918 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2919 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2920 | glBindFramebufferEXT(target, framebuffer_id); |
| 2921 | } |
| 2922 | |
| 2923 | void GLES2DecoderImpl::RestoreCurrentFramebufferBindings() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2924 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2925 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2926 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2927 | RebindCurrentFramebuffer( |
| 2928 | GL_FRAMEBUFFER, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2929 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2930 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2931 | } else { |
| 2932 | RebindCurrentFramebuffer( |
| 2933 | GL_READ_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2934 | framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2935 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2936 | RebindCurrentFramebuffer( |
| 2937 | GL_DRAW_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2938 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 2939 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2940 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 2941 | OnFboChanged(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2942 | } |
| 2943 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2944 | bool GLES2DecoderImpl::CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2945 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2946 | GLenum target, const char* func_name) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2947 | if (!framebuffer) { |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 2948 | if (backbuffer_needs_clear_bits_) { |
| 2949 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
| 2950 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
| 2951 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 2952 | glClearStencil(0); |
| 2953 | glStencilMask(-1); |
| 2954 | glClearDepth(1.0f); |
| 2955 | glDepthMask(true); |
| 2956 | glDisable(GL_SCISSOR_TEST); |
| 2957 | glClear(backbuffer_needs_clear_bits_); |
| 2958 | backbuffer_needs_clear_bits_ = 0; |
| 2959 | RestoreClearState(); |
| 2960 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2961 | return true; |
| 2962 | } |
| 2963 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2964 | if (framebuffer_manager()->IsComplete(framebuffer)) { |
| 2965 | return true; |
| 2966 | } |
| 2967 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2968 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 2969 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2970 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 2971 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, "framebuffer incomplete"); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 2972 | return false; |
| 2973 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2974 | |
| 2975 | // Are all the attachments cleared? |
| 2976 | if (renderbuffer_manager()->HaveUnclearedRenderbuffers() || |
| 2977 | texture_manager()->HaveUnclearedMips()) { |
| 2978 | if (!framebuffer->IsCleared()) { |
| 2979 | // Can we clear them? |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 2980 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 2981 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2982 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 2983 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 2984 | "framebuffer incomplete (clear)"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 2985 | return false; |
| 2986 | } |
| 2987 | ClearUnclearedAttachments(target, framebuffer); |
| 2988 | } |
| 2989 | } |
| 2990 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2991 | if (!framebuffer_manager()->IsComplete(framebuffer)) { |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 2992 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 2993 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2994 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 2995 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 2996 | "framebuffer incomplete (check)"); |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 2997 | return false; |
| 2998 | } |
| 2999 | framebuffer_manager()->MarkAsComplete(framebuffer); |
| 3000 | } |
| 3001 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3002 | // NOTE: At this point we don't know if the framebuffer is complete but |
| 3003 | // we DO know that everything that needs to be cleared has been cleared. |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 3004 | return true; |
| 3005 | } |
| 3006 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3007 | bool GLES2DecoderImpl::CheckBoundFramebuffersValid(const char* func_name) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3008 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3009 | bool valid = CheckFramebufferValid( |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3010 | framebuffer_state_.bound_draw_framebuffer.get(), GL_FRAMEBUFFER_EXT, |
| 3011 | func_name); |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3012 | |
| 3013 | if (valid) |
| 3014 | OnUseFramebuffer(); |
| 3015 | |
| 3016 | return valid; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3017 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3018 | return CheckFramebufferValid(framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3019 | GL_DRAW_FRAMEBUFFER_EXT, |
| 3020 | func_name) && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3021 | CheckFramebufferValid(framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3022 | GL_READ_FRAMEBUFFER_EXT, |
| 3023 | func_name); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3024 | } |
| 3025 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3026 | gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3027 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3028 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3029 | if (framebuffer != NULL) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3030 | const Framebuffer::Attachment* attachment = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3031 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3032 | if (attachment) { |
| 3033 | return gfx::Size(attachment->width(), attachment->height()); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 3034 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3035 | return gfx::Size(0, 0); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3036 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3037 | return offscreen_size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3038 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 3039 | return surface_->GetSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 3040 | } |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 3041 | } |
| 3042 | |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 3043 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferTextureType() { |
| 3044 | Framebuffer* framebuffer = |
| 3045 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
| 3046 | if (framebuffer != NULL) { |
| 3047 | return framebuffer->GetColorAttachmentTextureType(); |
| 3048 | } else { |
| 3049 | return GL_UNSIGNED_BYTE; |
| 3050 | } |
| 3051 | } |
| 3052 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3053 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3054 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3055 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3056 | if (framebuffer != NULL) { |
| 3057 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3058 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3059 | return offscreen_target_color_format_; |
| 3060 | } else { |
| 3061 | return back_buffer_color_format_; |
| 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | GLenum GLES2DecoderImpl::GetBoundDrawFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3066 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3067 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3068 | if (framebuffer != NULL) { |
| 3069 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3070 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3071 | return offscreen_target_color_format_; |
| 3072 | } else { |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 3073 | return back_buffer_color_format_; |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3074 | } |
| 3075 | } |
| 3076 | |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 3077 | void GLES2DecoderImpl::UpdateParentTextureInfo() { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3078 | if (!offscreen_saved_color_texture_info_.get()) |
| 3079 | return; |
| 3080 | GLenum target = offscreen_saved_color_texture_info_->texture()->target(); |
| 3081 | glBindTexture(target, offscreen_saved_color_texture_info_->service_id()); |
| 3082 | texture_manager()->SetLevelInfo( |
| 3083 | offscreen_saved_color_texture_info_.get(), |
| 3084 | GL_TEXTURE_2D, |
| 3085 | 0, // level |
| 3086 | GL_RGBA, |
| 3087 | offscreen_size_.width(), |
| 3088 | offscreen_size_.height(), |
| 3089 | 1, // depth |
| 3090 | 0, // border |
| 3091 | GL_RGBA, |
| 3092 | GL_UNSIGNED_BYTE, |
| 3093 | true); |
| 3094 | texture_manager()->SetParameter( |
| 3095 | "UpdateParentTextureInfo", |
| 3096 | GetErrorState(), |
| 3097 | offscreen_saved_color_texture_info_.get(), |
| 3098 | GL_TEXTURE_MAG_FILTER, |
| 3099 | GL_NEAREST); |
| 3100 | texture_manager()->SetParameter( |
| 3101 | "UpdateParentTextureInfo", |
| 3102 | GetErrorState(), |
| 3103 | offscreen_saved_color_texture_info_.get(), |
| 3104 | GL_TEXTURE_MIN_FILTER, |
| 3105 | GL_NEAREST); |
| 3106 | texture_manager()->SetParameter( |
| 3107 | "UpdateParentTextureInfo", |
| 3108 | GetErrorState(), |
| 3109 | offscreen_saved_color_texture_info_.get(), |
| 3110 | GL_TEXTURE_WRAP_S, |
| 3111 | GL_CLAMP_TO_EDGE); |
| 3112 | texture_manager()->SetParameter( |
| 3113 | "UpdateParentTextureInfo", |
| 3114 | GetErrorState(), |
| 3115 | offscreen_saved_color_texture_info_.get(), |
| 3116 | GL_TEXTURE_WRAP_T, |
| 3117 | GL_CLAMP_TO_EDGE); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3118 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 3119 | &state_, target); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3120 | glBindTexture(target, texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3121 | } |
| 3122 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3123 | void GLES2DecoderImpl::SetResizeCallback( |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3124 | const base::Callback<void(gfx::Size, float)>& callback) { |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3125 | resize_callback_ = callback; |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3126 | } |
| 3127 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 3128 | Logger* GLES2DecoderImpl::GetLogger() { |
| 3129 | return &logger_; |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 3130 | } |
| 3131 | |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3132 | void GLES2DecoderImpl::BeginDecoding() { |
| 3133 | gpu_tracer_->BeginDecoding(); |
| 3134 | gpu_trace_commands_ = gpu_tracer_->IsTracing(); |
| 3135 | } |
| 3136 | |
| 3137 | void GLES2DecoderImpl::EndDecoding() { |
| 3138 | gpu_tracer_->EndDecoding(); |
| 3139 | } |
| 3140 | |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 3141 | ErrorState* GLES2DecoderImpl::GetErrorState() { |
| 3142 | return state_.GetErrorState(); |
| 3143 | } |
| 3144 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 3145 | void GLES2DecoderImpl::SetShaderCacheCallback( |
| 3146 | const ShaderCacheCallback& callback) { |
| 3147 | shader_cache_callback_ = callback; |
| 3148 | } |
| 3149 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 3150 | void GLES2DecoderImpl::SetWaitSyncPointCallback( |
| 3151 | const WaitSyncPointCallback& callback) { |
| 3152 | wait_sync_point_callback_ = callback; |
| 3153 | } |
| 3154 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3155 | AsyncPixelTransferManager* |
| 3156 | GLES2DecoderImpl::GetAsyncPixelTransferManager() { |
| 3157 | return async_pixel_transfer_manager_.get(); |
| 3158 | } |
| 3159 | |
| 3160 | void GLES2DecoderImpl::ResetAsyncPixelTransferManagerForTest() { |
| 3161 | async_pixel_transfer_manager_.reset(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 3162 | } |
| 3163 | |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 3164 | void GLES2DecoderImpl::SetAsyncPixelTransferManagerForTest( |
| 3165 | AsyncPixelTransferManager* manager) { |
| 3166 | async_pixel_transfer_manager_ = make_scoped_ptr(manager); |
| 3167 | } |
| 3168 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3169 | bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, |
| 3170 | uint32* service_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3171 | TextureRef* texture_ref = texture_manager()->GetTexture(client_texture_id); |
| 3172 | if (texture_ref) { |
| 3173 | *service_texture_id = texture_ref->service_id(); |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3174 | return true; |
| 3175 | } |
| 3176 | return false; |
| 3177 | } |
| 3178 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3179 | uint32 GLES2DecoderImpl::GetTextureUploadCount() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3180 | return texture_state_.texture_upload_count + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3181 | async_pixel_transfer_manager_->GetTextureUploadCount(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | base::TimeDelta GLES2DecoderImpl::GetTotalTextureUploadTime() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3185 | return texture_state_.total_texture_upload_time + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3186 | async_pixel_transfer_manager_->GetTotalTextureUploadTime(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3187 | } |
| 3188 | |
| 3189 | base::TimeDelta GLES2DecoderImpl::GetTotalProcessingCommandsTime() { |
| 3190 | return total_processing_commands_time_; |
| 3191 | } |
| 3192 | |
[email protected] | dc25dda | 2012-09-27 21:36:30 | [diff] [blame] | 3193 | void GLES2DecoderImpl::AddProcessingCommandsTime(base::TimeDelta time) { |
| 3194 | total_processing_commands_time_ += time; |
| 3195 | } |
| 3196 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3197 | void GLES2DecoderImpl::Destroy(bool have_context) { |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 3198 | if (!initialized()) |
| 3199 | return; |
| 3200 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3201 | DCHECK(!have_context || context_->IsCurrent(NULL)); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3202 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3203 | // Unbind everything. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3204 | state_.vertex_attrib_manager = NULL; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 3205 | default_vertex_attrib_manager_ = NULL; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3206 | state_.texture_units.clear(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3207 | state_.bound_array_buffer = NULL; |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 3208 | state_.current_queries.clear(); |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3209 | framebuffer_state_.bound_read_framebuffer = NULL; |
| 3210 | framebuffer_state_.bound_draw_framebuffer = NULL; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3211 | state_.bound_renderbuffer = NULL; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3212 | |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 3213 | if (offscreen_saved_color_texture_info_.get()) { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3214 | DCHECK(offscreen_target_color_texture_); |
| 3215 | DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), |
| 3216 | offscreen_saved_color_texture_->id()); |
| 3217 | offscreen_saved_color_texture_->Invalidate(); |
| 3218 | offscreen_saved_color_texture_info_ = NULL; |
| 3219 | } |
[email protected] | eadc9679 | 2010-10-27 19:39:39 | [diff] [blame] | 3220 | if (have_context) { |
[email protected] | c322e88 | 2012-05-23 18:06:18 | [diff] [blame] | 3221 | if (copy_texture_CHROMIUM_.get()) { |
| 3222 | copy_texture_CHROMIUM_->Destroy(); |
| 3223 | copy_texture_CHROMIUM_.reset(); |
| 3224 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3225 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3226 | if (state_.current_program.get()) { |
| 3227 | program_manager()->UnuseProgram(shader_manager(), |
| 3228 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 3229 | } |
| 3230 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3231 | if (attrib_0_buffer_id_) { |
| 3232 | glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
| 3233 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 3234 | if (fixed_attrib_buffer_id_) { |
| 3235 | glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); |
| 3236 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3237 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 3238 | if (validation_texture_) { |
| 3239 | glDeleteTextures(1, &validation_texture_); |
| 3240 | glDeleteFramebuffersEXT(1, &validation_fbo_multisample_); |
| 3241 | glDeleteFramebuffersEXT(1, &validation_fbo_); |
| 3242 | } |
| 3243 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3244 | if (offscreen_target_frame_buffer_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3245 | offscreen_target_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3246 | if (offscreen_target_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3247 | offscreen_target_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3248 | if (offscreen_target_color_render_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3249 | offscreen_target_color_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3250 | if (offscreen_target_depth_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3251 | offscreen_target_depth_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3252 | if (offscreen_target_stencil_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3253 | offscreen_target_stencil_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3254 | if (offscreen_saved_frame_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3255 | offscreen_saved_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3256 | if (offscreen_saved_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3257 | offscreen_saved_color_texture_->Destroy(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3258 | if (offscreen_resolved_frame_buffer_.get()) |
| 3259 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3260 | if (offscreen_resolved_color_texture_.get()) |
| 3261 | offscreen_resolved_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3262 | } else { |
| 3263 | if (offscreen_target_frame_buffer_.get()) |
| 3264 | offscreen_target_frame_buffer_->Invalidate(); |
| 3265 | if (offscreen_target_color_texture_.get()) |
| 3266 | offscreen_target_color_texture_->Invalidate(); |
| 3267 | if (offscreen_target_color_render_buffer_.get()) |
| 3268 | offscreen_target_color_render_buffer_->Invalidate(); |
| 3269 | if (offscreen_target_depth_render_buffer_.get()) |
| 3270 | offscreen_target_depth_render_buffer_->Invalidate(); |
| 3271 | if (offscreen_target_stencil_render_buffer_.get()) |
| 3272 | offscreen_target_stencil_render_buffer_->Invalidate(); |
| 3273 | if (offscreen_saved_frame_buffer_.get()) |
| 3274 | offscreen_saved_frame_buffer_->Invalidate(); |
| 3275 | if (offscreen_saved_color_texture_.get()) |
| 3276 | offscreen_saved_color_texture_->Invalidate(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3277 | if (offscreen_resolved_frame_buffer_.get()) |
| 3278 | offscreen_resolved_frame_buffer_->Invalidate(); |
| 3279 | if (offscreen_resolved_color_texture_.get()) |
| 3280 | offscreen_resolved_color_texture_->Invalidate(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 3281 | } |
[email protected] | 83a52d03 | 2013-07-24 10:30:37 | [diff] [blame] | 3282 | |
| 3283 | // Current program must be cleared after calling ProgramManager::UnuseProgram. |
| 3284 | // Otherwise, we can leak objects. http://crbug.com/258772. |
| 3285 | // state_.current_program must be reset before group_ is reset because |
| 3286 | // the later deletes the ProgramManager object that referred by |
| 3287 | // state_.current_program object. |
| 3288 | state_.current_program = NULL; |
| 3289 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3290 | copy_texture_CHROMIUM_.reset(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3291 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3292 | if (query_manager_.get()) { |
| 3293 | query_manager_->Destroy(have_context); |
| 3294 | query_manager_.reset(); |
| 3295 | } |
| 3296 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 3297 | if (vertex_array_manager_ .get()) { |
| 3298 | vertex_array_manager_->Destroy(have_context); |
| 3299 | vertex_array_manager_.reset(); |
| 3300 | } |
| 3301 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3302 | offscreen_target_frame_buffer_.reset(); |
| 3303 | offscreen_target_color_texture_.reset(); |
| 3304 | offscreen_target_color_render_buffer_.reset(); |
| 3305 | offscreen_target_depth_render_buffer_.reset(); |
| 3306 | offscreen_target_stencil_render_buffer_.reset(); |
| 3307 | offscreen_saved_frame_buffer_.reset(); |
| 3308 | offscreen_saved_color_texture_.reset(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3309 | offscreen_resolved_frame_buffer_.reset(); |
| 3310 | offscreen_resolved_color_texture_.reset(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3311 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3312 | // Should destroy the transfer manager before the texture manager held |
| 3313 | // by the context group. |
| 3314 | async_pixel_transfer_manager_.reset(); |
| 3315 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3316 | if (group_.get()) { |
[email protected] | ac5e402 | 2014-01-24 12:44:39 | [diff] [blame] | 3317 | framebuffer_manager()->RemoveObserver(this); |
[email protected] | 2d9d3b9 | 2013-01-18 01:07:23 | [diff] [blame] | 3318 | group_->Destroy(this, have_context); |
| 3319 | group_ = NULL; |
| 3320 | } |
| 3321 | |
| 3322 | if (context_.get()) { |
| 3323 | context_->ReleaseCurrent(NULL); |
| 3324 | context_ = NULL; |
| 3325 | } |
| 3326 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3327 | #if defined(OS_MACOSX) |
| 3328 | for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); |
| 3329 | it != texture_to_io_surface_map_.end(); ++it) { |
| 3330 | CFRelease(it->second); |
| 3331 | } |
| 3332 | texture_to_io_surface_map_.clear(); |
| 3333 | #endif |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3334 | } |
| 3335 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3336 | void GLES2DecoderImpl::SetSurface( |
| 3337 | const scoped_refptr<gfx::GLSurface>& surface) { |
| 3338 | DCHECK(context_->IsCurrent(NULL)); |
| 3339 | DCHECK(surface_.get()); |
| 3340 | surface_ = surface; |
| 3341 | RestoreCurrentFramebufferBindings(); |
| 3342 | } |
| 3343 | |
[email protected] | aba551b | 2014-02-08 03:38:32 | [diff] [blame] | 3344 | void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) { |
| 3345 | if (!offscreen_saved_color_texture_.get()) { |
| 3346 | LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context"; |
| 3347 | return; |
| 3348 | } |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3349 | if (!offscreen_saved_color_texture_info_.get()) { |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3350 | GLuint service_id = offscreen_saved_color_texture_->id(); |
[email protected] | f4647693 | 2013-06-08 05:36:07 | [diff] [blame] | 3351 | offscreen_saved_color_texture_info_ = TextureRef::Create( |
| 3352 | texture_manager(), 0, service_id); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3353 | texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), |
| 3354 | GL_TEXTURE_2D); |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 3355 | UpdateParentTextureInfo(); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3356 | } |
[email protected] | aba551b | 2014-02-08 03:38:32 | [diff] [blame] | 3357 | mailbox_manager()->ProduceTexture( |
| 3358 | GL_TEXTURE_2D, mailbox, offscreen_saved_color_texture_info_->texture()); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3359 | } |
| 3360 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3361 | bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 3362 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3363 | if (!is_offscreen) { |
| 3364 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " |
| 3365 | << " with an onscreen framebuffer."; |
| 3366 | return false; |
| 3367 | } |
| 3368 | |
| 3369 | if (offscreen_size_ == size) |
| 3370 | return true; |
| 3371 | |
| 3372 | offscreen_size_ = size; |
| 3373 | int w = offscreen_size_.width(); |
| 3374 | int h = offscreen_size_.height(); |
| 3375 | if (w < 0 || h < 0 || h >= (INT_MAX / 4) / (w ? w : 1)) { |
| 3376 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3377 | << "to allocate storage due to excessive dimensions."; |
| 3378 | return false; |
| 3379 | } |
| 3380 | |
| 3381 | // Reallocate the offscreen target buffers. |
| 3382 | DCHECK(offscreen_target_color_format_); |
| 3383 | if (IsOffscreenBufferMultisampled()) { |
| 3384 | if (!offscreen_target_color_render_buffer_->AllocateStorage( |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 3385 | feature_info_, offscreen_size_, offscreen_target_color_format_, |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3386 | offscreen_target_samples_)) { |
| 3387 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3388 | << "to allocate storage for offscreen target color buffer."; |
| 3389 | return false; |
| 3390 | } |
| 3391 | } else { |
| 3392 | if (!offscreen_target_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 3393 | offscreen_size_, offscreen_target_color_format_, false)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3394 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3395 | << "to allocate storage for offscreen target color texture."; |
| 3396 | return false; |
| 3397 | } |
| 3398 | } |
| 3399 | if (offscreen_target_depth_format_ && |
| 3400 | !offscreen_target_depth_render_buffer_->AllocateStorage( |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 3401 | feature_info_, offscreen_size_, offscreen_target_depth_format_, |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3402 | offscreen_target_samples_)) { |
| 3403 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3404 | << "to allocate storage for offscreen target depth buffer."; |
| 3405 | return false; |
| 3406 | } |
| 3407 | if (offscreen_target_stencil_format_ && |
| 3408 | !offscreen_target_stencil_render_buffer_->AllocateStorage( |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 3409 | feature_info_, offscreen_size_, offscreen_target_stencil_format_, |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3410 | offscreen_target_samples_)) { |
| 3411 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3412 | << "to allocate storage for offscreen target stencil buffer."; |
| 3413 | return false; |
| 3414 | } |
| 3415 | |
| 3416 | // Attach the offscreen target buffers to the target frame buffer. |
| 3417 | if (IsOffscreenBufferMultisampled()) { |
| 3418 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3419 | GL_COLOR_ATTACHMENT0, |
| 3420 | offscreen_target_color_render_buffer_.get()); |
| 3421 | } else { |
| 3422 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 3423 | offscreen_target_color_texture_.get()); |
| 3424 | } |
| 3425 | if (offscreen_target_depth_format_) { |
| 3426 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3427 | GL_DEPTH_ATTACHMENT, |
| 3428 | offscreen_target_depth_render_buffer_.get()); |
| 3429 | } |
| 3430 | const bool packed_depth_stencil = |
| 3431 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 3432 | if (packed_depth_stencil) { |
| 3433 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3434 | GL_STENCIL_ATTACHMENT, |
| 3435 | offscreen_target_depth_render_buffer_.get()); |
| 3436 | } else if (offscreen_target_stencil_format_) { |
| 3437 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3438 | GL_STENCIL_ATTACHMENT, |
| 3439 | offscreen_target_stencil_render_buffer_.get()); |
| 3440 | } |
| 3441 | |
| 3442 | if (offscreen_target_frame_buffer_->CheckStatus() != |
| 3443 | GL_FRAMEBUFFER_COMPLETE) { |
| 3444 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3445 | << "because offscreen FBO was incomplete."; |
| 3446 | return false; |
| 3447 | } |
| 3448 | |
| 3449 | // Clear the target frame buffer. |
| 3450 | { |
| 3451 | ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); |
| 3452 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
| 3453 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
| 3454 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 3455 | glClearStencil(0); |
| 3456 | glStencilMaskSeparate(GL_FRONT, -1); |
| 3457 | glStencilMaskSeparate(GL_BACK, -1); |
| 3458 | glClearDepth(0); |
| 3459 | glDepthMask(GL_TRUE); |
| 3460 | glDisable(GL_SCISSOR_TEST); |
| 3461 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 3462 | RestoreClearState(); |
| 3463 | } |
[email protected] | d85ef76d | 2011-09-08 22:21:43 | [diff] [blame] | 3464 | |
| 3465 | // Destroy the offscreen resolved framebuffers. |
| 3466 | if (offscreen_resolved_frame_buffer_.get()) |
| 3467 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3468 | if (offscreen_resolved_color_texture_.get()) |
| 3469 | offscreen_resolved_color_texture_->Destroy(); |
| 3470 | offscreen_resolved_color_texture_.reset(); |
| 3471 | offscreen_resolved_frame_buffer_.reset(); |
| 3472 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3473 | return true; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3474 | } |
| 3475 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3476 | error::Error GLES2DecoderImpl::HandleResizeCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3477 | uint32 immediate_data_size, const cmds::ResizeCHROMIUM& c) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 3478 | if (!offscreen_target_frame_buffer_.get() && surface_->DeferDraws()) |
[email protected] | 45212087 | 2012-09-27 15:21:02 | [diff] [blame] | 3479 | return error::kDeferCommandUntilLater; |
| 3480 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3481 | GLuint width = static_cast<GLuint>(c.width); |
| 3482 | GLuint height = static_cast<GLuint>(c.height); |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3483 | GLfloat scale_factor = c.scale_factor; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3484 | TRACE_EVENT2("gpu", "glResizeChromium", "width", width, "height", height); |
[email protected] | d16aa4b | 2013-02-14 22:35:41 | [diff] [blame] | 3485 | |
| 3486 | width = std::max(1U, width); |
| 3487 | height = std::max(1U, height); |
| 3488 | |
[email protected] | a0d98916 | 2011-11-22 13:15:07 | [diff] [blame] | 3489 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && \ |
| 3490 | !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3491 | // Make sure that we are done drawing to the back buffer before resizing. |
| 3492 | glFinish(); |
| 3493 | #endif |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3494 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3495 | if (is_offscreen) { |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3496 | if (!ResizeOffscreenFrameBuffer(gfx::Size(width, height))) { |
| 3497 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because " |
| 3498 | << "ResizeOffscreenFrameBuffer failed."; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3499 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3500 | } |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3501 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3502 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3503 | if (!resize_callback_.is_null()) { |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3504 | resize_callback_.Run(gfx::Size(width, height), scale_factor); |
[email protected] | 0e9346b | 2013-03-16 16:35:44 | [diff] [blame] | 3505 | DCHECK(context_->IsCurrent(surface_.get())); |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3506 | if (!context_->IsCurrent(surface_.get())) { |
| 3507 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because context no longer " |
| 3508 | << "current after resize callback."; |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3509 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3510 | } |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3511 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3512 | |
| 3513 | return error::kNoError; |
[email protected] | 43ecf37 | 2010-11-16 19:19:39 | [diff] [blame] | 3514 | } |
| 3515 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3516 | const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { |
| 3517 | if (command_id > kStartPoint && command_id < kNumCommands) { |
| 3518 | return gles2::GetCommandName(static_cast<CommandId>(command_id)); |
| 3519 | } |
| 3520 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 3521 | } |
| 3522 | |
| 3523 | // Decode command with its arguments, and call the corresponding GL function. |
| 3524 | // Note: args is a pointer to the command buffer. As such, it could be changed |
| 3525 | // by a (malicious) client at any time, so if validation has to happen, it |
| 3526 | // should operate on a copy of them. |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3527 | error::Error GLES2DecoderImpl::DoCommand( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3528 | unsigned int command, |
| 3529 | unsigned int arg_count, |
| 3530 | const void* cmd_data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3531 | error::Error result = error::kNoError; |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 3532 | if (log_commands()) { |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 3533 | // TODO(notme): Change this to a LOG/VLOG that works in release. Tried |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 3534 | // VLOG(1), no luck. |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 3535 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "]" << "cmd: " |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 3536 | << GetCommandName(command); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3537 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3538 | unsigned int command_index = command - kStartPoint - 1; |
| 3539 | if (command_index < arraysize(g_command_info)) { |
| 3540 | const CommandInfo& info = g_command_info[command_index]; |
| 3541 | unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
| 3542 | if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
| 3543 | (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3544 | bool doing_gpu_trace = false; |
| 3545 | if (gpu_trace_commands_) { |
| 3546 | if (CMD_FLAG_GET_TRACE_LEVEL(info.cmd_flags) <= gpu_trace_level_) { |
| 3547 | doing_gpu_trace = true; |
| 3548 | gpu_tracer_->Begin(GetCommandName(command), kTraceDecoder); |
| 3549 | } |
| 3550 | } |
| 3551 | |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3552 | uint32 immediate_data_size = |
| 3553 | (arg_count - info_arg_count) * sizeof(CommandBufferEntry); // NOLINT |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3554 | switch (command) { |
| 3555 | #define GLES2_CMD_OP(name) \ |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3556 | case cmds::name::kCmdId: \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3557 | result = Handle ## name( \ |
| 3558 | immediate_data_size, \ |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3559 | *static_cast<const gles2::cmds::name*>(cmd_data)); \ |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3560 | break; \ |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3561 | |
| 3562 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3563 | #undef GLES2_CMD_OP |
[email protected] | bf0985e | 2009-12-17 03:04:38 | [diff] [blame] | 3564 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3565 | |
| 3566 | if (doing_gpu_trace) |
| 3567 | gpu_tracer_->End(kTraceDecoder); |
| 3568 | |
[email protected] | bf0985e | 2009-12-17 03:04:38 | [diff] [blame] | 3569 | if (debug()) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3570 | GLenum error; |
| 3571 | while ((error = glGetError()) != GL_NO_ERROR) { |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 3572 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "] " |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 3573 | << "GL ERROR: " << GLES2Util::GetStringEnum(error) << " : " |
| 3574 | << GetCommandName(command); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3575 | LOCAL_SET_GL_ERROR(error, "DoCommand", "GL error from driver"); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3576 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3577 | } |
| 3578 | } else { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3579 | result = error::kInvalidArguments; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3580 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3581 | } else { |
| 3582 | result = DoCommonCommand(command, arg_count, cmd_data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3583 | } |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 3584 | if (result == error::kNoError && current_decoder_error_ != error::kNoError) { |
| 3585 | result = current_decoder_error_; |
| 3586 | current_decoder_error_ = error::kNoError; |
| 3587 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3588 | return result; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3589 | } |
| 3590 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3591 | void GLES2DecoderImpl::RemoveBuffer(GLuint client_id) { |
| 3592 | buffer_manager()->RemoveBuffer(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3593 | } |
| 3594 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3595 | bool GLES2DecoderImpl::CreateProgramHelper(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3596 | if (GetProgram(client_id)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3597 | return false; |
| 3598 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3599 | GLuint service_id = glCreateProgram(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3600 | if (service_id != 0) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3601 | CreateProgram(client_id, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3602 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3603 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3604 | } |
| 3605 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3606 | bool GLES2DecoderImpl::CreateShaderHelper(GLenum type, GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3607 | if (GetShader(client_id)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3608 | return false; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3609 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3610 | GLuint service_id = glCreateShader(type); |
| 3611 | if (service_id != 0) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3612 | CreateShader(client_id, service_id, type); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3613 | } |
| 3614 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3615 | } |
| 3616 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3617 | void GLES2DecoderImpl::DoFinish() { |
| 3618 | glFinish(); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 3619 | ProcessPendingReadPixels(); |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 3620 | ProcessPendingQueries(); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3621 | } |
| 3622 | |
| 3623 | void GLES2DecoderImpl::DoFlush() { |
| 3624 | glFlush(); |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 3625 | ProcessPendingQueries(); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3626 | } |
| 3627 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3628 | void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3629 | GLuint texture_index = texture_unit - GL_TEXTURE0; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3630 | if (texture_index >= state_.texture_units.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3631 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 3632 | "glActiveTexture", texture_unit, "texture_unit"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3633 | return; |
| 3634 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3635 | state_.active_texture_unit = texture_index; |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3636 | glActiveTexture(texture_unit); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3637 | } |
| 3638 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3639 | void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3640 | Buffer* buffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3641 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3642 | if (client_id != 0) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3643 | buffer = GetBuffer(client_id); |
| 3644 | if (!buffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3645 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 3646 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 3647 | "glBindBuffer", |
| 3648 | "id not generated by glGenBuffers"); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3649 | return; |
| 3650 | } |
| 3651 | |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3652 | // It's a new id so make a buffer buffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3653 | glGenBuffersARB(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3654 | CreateBuffer(client_id, service_id); |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3655 | buffer = GetBuffer(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3656 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3657 | group_->GetIdAllocator(id_namespaces::kBuffers); |
| 3658 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3659 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3660 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3661 | LogClientServiceForInfo(buffer, client_id, "glBindBuffer"); |
| 3662 | if (buffer) { |
| 3663 | if (!buffer_manager()->SetTarget(buffer, target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3664 | LOCAL_SET_GL_ERROR( |
| 3665 | GL_INVALID_OPERATION, |
| 3666 | "glBindBuffer", "buffer bound to more than 1 target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3667 | return; |
| 3668 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3669 | service_id = buffer->service_id(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3670 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3671 | switch (target) { |
| 3672 | case GL_ARRAY_BUFFER: |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3673 | state_.bound_array_buffer = buffer; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3674 | break; |
| 3675 | case GL_ELEMENT_ARRAY_BUFFER: |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3676 | state_.vertex_attrib_manager->SetElementArrayBuffer(buffer); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3677 | break; |
| 3678 | default: |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3679 | NOTREACHED(); // Validation should prevent us getting here. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3680 | break; |
| 3681 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3682 | glBindBuffer(target, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3683 | } |
| 3684 | |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 3685 | bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha( |
| 3686 | bool all_draw_buffers) { |
| 3687 | Framebuffer* framebuffer = |
| 3688 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 3689 | if (!all_draw_buffers || !framebuffer) { |
| 3690 | return (GLES2Util::GetChannelsForFormat( |
| 3691 | GetBoundDrawFrameBufferInternalFormat()) & 0x0008) != 0; |
| 3692 | } |
| 3693 | return framebuffer->HasAlphaMRT(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3694 | } |
| 3695 | |
| 3696 | bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3697 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3698 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3699 | if (framebuffer) { |
| 3700 | return framebuffer->HasDepthAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3701 | } |
| 3702 | if (offscreen_target_frame_buffer_.get()) { |
| 3703 | return offscreen_target_depth_format_ != 0; |
| 3704 | } |
| 3705 | return back_buffer_has_depth_; |
| 3706 | } |
| 3707 | |
| 3708 | bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3709 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3710 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3711 | if (framebuffer) { |
| 3712 | return framebuffer->HasStencilAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3713 | } |
| 3714 | if (offscreen_target_frame_buffer_.get()) { |
| 3715 | return offscreen_target_stencil_format_ != 0 || |
| 3716 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 3717 | } |
| 3718 | return back_buffer_has_stencil_; |
| 3719 | } |
| 3720 | |
| 3721 | void GLES2DecoderImpl::ApplyDirtyState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3722 | if (framebuffer_state_.clear_state_dirty) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3723 | glColorMask( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3724 | state_.color_mask_red, state_.color_mask_green, state_.color_mask_blue, |
| 3725 | state_.color_mask_alpha && |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 3726 | BoundFramebufferHasColorAttachmentWithAlpha(true)); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3727 | bool have_depth = BoundFramebufferHasDepthAttachment(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3728 | glDepthMask(state_.depth_mask && have_depth); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 3729 | EnableDisable(GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3730 | bool have_stencil = BoundFramebufferHasStencilAttachment(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3731 | glStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 3732 | GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3733 | glStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 3734 | GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 3735 | EnableDisable( |
| 3736 | GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil); |
| 3737 | EnableDisable(GL_CULL_FACE, state_.enable_flags.cull_face); |
| 3738 | EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test); |
| 3739 | EnableDisable(GL_BLEND, state_.enable_flags.blend); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3740 | framebuffer_state_.clear_state_dirty = false; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3741 | } |
| 3742 | } |
| 3743 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3744 | GLuint GLES2DecoderImpl::GetBackbufferServiceId() const { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3745 | return (offscreen_target_frame_buffer_.get()) |
| 3746 | ? offscreen_target_frame_buffer_->id() |
| 3747 | : (surface_.get() ? surface_->GetBackingFrameBufferObject() : 0); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3748 | } |
| 3749 | |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 3750 | void GLES2DecoderImpl::RestoreState(const ContextState* prev_state) const { |
[email protected] | 962bfbe7 | 2013-05-24 11:16:14 | [diff] [blame] | 3751 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::RestoreState", |
| 3752 | "context", logger_.GetLogPrefix()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3753 | // Restore the Framebuffer first because of bugs in Intel drivers. |
| 3754 | // Intel drivers incorrectly clip the viewport settings to |
| 3755 | // the size of the current framebuffer object. |
| 3756 | RestoreFramebufferBindings(); |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 3757 | state_.RestoreState(prev_state); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3758 | } |
| 3759 | |
| 3760 | void GLES2DecoderImpl::RestoreFramebufferBindings() const { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3761 | GLuint service_id = |
| 3762 | framebuffer_state_.bound_draw_framebuffer.get() |
| 3763 | ? framebuffer_state_.bound_draw_framebuffer->service_id() |
| 3764 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3765 | if (!features().chromium_framebuffer_multisample) { |
| 3766 | glBindFramebufferEXT(GL_FRAMEBUFFER, service_id); |
| 3767 | } else { |
| 3768 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, service_id); |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3769 | service_id = framebuffer_state_.bound_read_framebuffer.get() |
| 3770 | ? framebuffer_state_.bound_read_framebuffer->service_id() |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3771 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3772 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, service_id); |
| 3773 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3774 | OnFboChanged(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3775 | } |
| 3776 | |
| 3777 | void GLES2DecoderImpl::RestoreTextureState(unsigned service_id) const { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 3778 | Texture* texture = texture_manager()->GetTextureForServiceId(service_id); |
| 3779 | if (texture) { |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3780 | GLenum target = texture->target(); |
| 3781 | glBindTexture(target, service_id); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3782 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3783 | target, GL_TEXTURE_WRAP_S, texture->wrap_s()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3784 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3785 | target, GL_TEXTURE_WRAP_T, texture->wrap_t()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3786 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3787 | target, GL_TEXTURE_MIN_FILTER, texture->min_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3788 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 3789 | target, GL_TEXTURE_MAG_FILTER, texture->mag_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 3790 | RestoreTextureUnitBindings(state_.active_texture_unit); |
| 3791 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3792 | } |
| 3793 | |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 3794 | void GLES2DecoderImpl::ClearAllAttributes() const { |
| 3795 | for (uint32 i = 0; i < group_->max_vertex_attribs(); ++i) { |
| 3796 | if (i != 0) // Never disable attribute 0 |
| 3797 | glDisableVertexAttribArray(i); |
| 3798 | if(features().angle_instanced_arrays) |
| 3799 | glVertexAttribDivisorANGLE(i, 0); |
| 3800 | } |
| 3801 | } |
| 3802 | |
| 3803 | void GLES2DecoderImpl::RestoreAllAttributes() const { |
| 3804 | for (uint32 i = 0; i < group_->max_vertex_attribs(); ++i) |
| 3805 | RestoreAttribute(i); |
| 3806 | } |
| 3807 | |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3808 | void GLES2DecoderImpl::OnFboChanged() const { |
| 3809 | if (workarounds().restore_scissor_on_fbo_change) |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3810 | state_.fbo_binding_for_scissor_workaround_dirty_ = true; |
| 3811 | } |
| 3812 | |
| 3813 | // Called after the FBO is checked for completeness. |
| 3814 | void GLES2DecoderImpl::OnUseFramebuffer() const { |
| 3815 | if (state_.fbo_binding_for_scissor_workaround_dirty_) { |
| 3816 | state_.fbo_binding_for_scissor_workaround_dirty_ = false; |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 3817 | // The driver forgets the correct scissor when modifying the FBO binding. |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3818 | glScissor(state_.scissor_x, |
| 3819 | state_.scissor_y, |
| 3820 | state_.scissor_width, |
| 3821 | state_.scissor_height); |
| 3822 | |
| 3823 | // crbug.com/222018 - Also on QualComm, the flush here avoids flicker, |
| 3824 | // it's unclear how this bug works. |
| 3825 | glFlush(); |
| 3826 | } |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3827 | } |
| 3828 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3829 | void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3830 | Framebuffer* framebuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3831 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3832 | if (client_id != 0) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3833 | framebuffer = GetFramebuffer(client_id); |
| 3834 | if (!framebuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3835 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 3836 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 3837 | "glBindFramebuffer", |
| 3838 | "id not generated by glGenFramebuffers"); |
| 3839 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3840 | } |
| 3841 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3842 | // It's a new id so make a framebuffer framebuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3843 | glGenFramebuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3844 | CreateFramebuffer(client_id, service_id); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3845 | framebuffer = GetFramebuffer(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3846 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3847 | group_->GetIdAllocator(id_namespaces::kFramebuffers); |
| 3848 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3849 | } else { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3850 | service_id = framebuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3851 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3852 | framebuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3853 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3854 | LogClientServiceForInfo(framebuffer, client_id, "glBindFramebuffer"); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3855 | |
| 3856 | if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3857 | framebuffer_state_.bound_draw_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3858 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3859 | |
| 3860 | // vmiura: This looks like dup code |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3861 | if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3862 | framebuffer_state_.bound_read_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3863 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3864 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3865 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3866 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3867 | // If we are rendering to the backbuffer get the FBO id for any simulated |
| 3868 | // backbuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3869 | if (framebuffer == NULL) { |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3870 | service_id = GetBackbufferServiceId(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3871 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3872 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3873 | glBindFramebufferEXT(target, service_id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3874 | OnFboChanged(); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 3875 | } |
| 3876 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3877 | void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3878 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3879 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3880 | if (client_id != 0) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3881 | renderbuffer = GetRenderbuffer(client_id); |
| 3882 | if (!renderbuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3883 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 3884 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 3885 | "glBindRenderbuffer", |
| 3886 | "id not generated by glGenRenderbuffers"); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3887 | return; |
| 3888 | } |
| 3889 | |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3890 | // It's a new id so make a renderbuffer renderbuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3891 | glGenRenderbuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3892 | CreateRenderbuffer(client_id, service_id); |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3893 | renderbuffer = GetRenderbuffer(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3894 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3895 | group_->GetIdAllocator(id_namespaces::kRenderbuffers); |
| 3896 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3897 | } else { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3898 | service_id = renderbuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3899 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3900 | renderbuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3901 | } |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 3902 | LogClientServiceForInfo(renderbuffer, client_id, "glBindRenderbuffer"); |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 3903 | state_.bound_renderbuffer = renderbuffer; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3904 | glBindRenderbufferEXT(target, service_id); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 3905 | } |
| 3906 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3907 | void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3908 | TextureRef* texture_ref = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3909 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3910 | if (client_id != 0) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3911 | texture_ref = GetTexture(client_id); |
| 3912 | if (!texture_ref) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3913 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 3914 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 3915 | "glBindTexture", |
| 3916 | "id not generated by glGenTextures"); |
| 3917 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3918 | } |
| 3919 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 3920 | // It's a new id so make a texture texture for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3921 | glGenTextures(1, &service_id); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3922 | DCHECK_NE(0u, service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3923 | CreateTexture(client_id, service_id); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3924 | texture_ref = GetTexture(client_id); |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 3925 | IdAllocatorInterface* id_allocator = |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 3926 | group_->GetIdAllocator(id_namespaces::kTextures); |
| 3927 | id_allocator->MarkAsUsed(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3928 | } |
| 3929 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3930 | texture_ref = texture_manager()->GetDefaultTextureInfo(target); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3931 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3932 | Texture* texture = texture_ref->texture(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3933 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3934 | // Check the texture exists |
| 3935 | // Check that we are not trying to bind it to a different target. |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 3936 | if (texture->target() != 0 && texture->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3937 | LOCAL_SET_GL_ERROR( |
| 3938 | GL_INVALID_OPERATION, |
| 3939 | "glBindTexture", "texture bound to more than 1 target."); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 3940 | return; |
| 3941 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 3942 | LogClientServiceForInfo(texture, client_id, "glBindTexture"); |
| 3943 | if (texture->target() == 0) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3944 | texture_manager()->SetTarget(texture_ref, target); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3945 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 3946 | glBindTexture(target, texture->service_id()); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 3947 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3948 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3949 | unit.bind_target = target; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3950 | switch (target) { |
| 3951 | case GL_TEXTURE_2D: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3952 | unit.bound_texture_2d = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3953 | break; |
| 3954 | case GL_TEXTURE_CUBE_MAP: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3955 | unit.bound_texture_cube_map = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3956 | break; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3957 | case GL_TEXTURE_EXTERNAL_OES: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3958 | unit.bound_texture_external_oes = texture_ref; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 3959 | break; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3960 | case GL_TEXTURE_RECTANGLE_ARB: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3961 | unit.bound_texture_rectangle_arb = texture_ref; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3962 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3963 | default: |
| 3964 | NOTREACHED(); // Validation should prevent us getting here. |
| 3965 | break; |
| 3966 | } |
| 3967 | } |
| 3968 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3969 | void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3970 | if (state_.vertex_attrib_manager->Enable(index, false)) { |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 3971 | if (index != 0 || |
| 3972 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3973 | glDisableVertexAttribArray(index); |
| 3974 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3975 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3976 | LOCAL_SET_GL_ERROR( |
| 3977 | GL_INVALID_VALUE, |
| 3978 | "glDisableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3979 | } |
| 3980 | } |
| 3981 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3982 | void GLES2DecoderImpl::DoDiscardFramebufferEXT(GLenum target, |
| 3983 | GLsizei numAttachments, |
| 3984 | const GLenum* attachments) { |
[email protected] | 680aa41 | 2013-10-31 18:08:01 | [diff] [blame] | 3985 | if (!features().ext_discard_framebuffer) { |
| 3986 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 3987 | "glDiscardFramebufferEXT", |
| 3988 | "function not available"); |
| 3989 | return; |
| 3990 | } |
| 3991 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3992 | Framebuffer* framebuffer = |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3993 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 3994 | |
| 3995 | // Validates the attachments. If one of them fails |
| 3996 | // the whole command fails. |
| 3997 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 3998 | if ((framebuffer && |
| 3999 | !validators_->attachment.IsValid(attachments[i])) || |
| 4000 | (!framebuffer && |
| 4001 | !validators_->backbuffer_attachment.IsValid(attachments[i]))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4002 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 4003 | "glDiscardFramebufferEXT", attachments[i], "attachments"); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4004 | return; |
| 4005 | } |
| 4006 | } |
| 4007 | |
| 4008 | // Marks each one of them as not cleared |
| 4009 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4010 | if (framebuffer) { |
| 4011 | framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), |
| 4012 | texture_manager(), |
| 4013 | attachments[i], |
| 4014 | false); |
| 4015 | } else { |
| 4016 | switch (attachments[i]) { |
| 4017 | case GL_COLOR_EXT: |
| 4018 | backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| 4019 | break; |
| 4020 | case GL_DEPTH_EXT: |
| 4021 | backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
| 4022 | case GL_STENCIL_EXT: |
| 4023 | backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
| 4024 | break; |
| 4025 | default: |
| 4026 | NOTREACHED(); |
| 4027 | break; |
| 4028 | } |
| 4029 | } |
| 4030 | } |
| 4031 | |
[email protected] | d49c540 | 2013-09-11 15:39:02 | [diff] [blame] | 4032 | // If the default framebuffer is bound but we are still rendering to an |
| 4033 | // FBO, translate attachment names that refer to default framebuffer |
| 4034 | // channels to corresponding framebuffer attachments. |
| 4035 | scoped_ptr<GLenum[]> translated_attachments(new GLenum[numAttachments]); |
| 4036 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4037 | GLenum attachment = attachments[i]; |
| 4038 | if (!framebuffer && GetBackbufferServiceId()) { |
| 4039 | switch (attachment) { |
| 4040 | case GL_COLOR_EXT: |
| 4041 | attachment = GL_COLOR_ATTACHMENT0; |
| 4042 | break; |
| 4043 | case GL_DEPTH_EXT: |
| 4044 | attachment = GL_DEPTH_ATTACHMENT; |
| 4045 | break; |
| 4046 | case GL_STENCIL_EXT: |
| 4047 | attachment = GL_STENCIL_ATTACHMENT; |
| 4048 | break; |
| 4049 | default: |
| 4050 | NOTREACHED(); |
| 4051 | return; |
| 4052 | } |
| 4053 | } |
| 4054 | translated_attachments[i] = attachment; |
| 4055 | } |
| 4056 | |
| 4057 | glDiscardFramebufferEXT(target, numAttachments, translated_attachments.get()); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4058 | } |
| 4059 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4060 | void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4061 | if (state_.vertex_attrib_manager->Enable(index, true)) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4062 | glEnableVertexAttribArray(index); |
| 4063 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4064 | LOCAL_SET_GL_ERROR( |
| 4065 | GL_INVALID_VALUE, "glEnableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4066 | } |
| 4067 | } |
| 4068 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4069 | void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4070 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 4071 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4072 | if (!texture_ref || |
| 4073 | !texture_manager()->CanGenerateMipmaps(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4074 | LOCAL_SET_GL_ERROR( |
| 4075 | GL_INVALID_OPERATION, "glGenerateMipmap", "Can not generate mips"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4076 | return; |
| 4077 | } |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4078 | |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4079 | if (target == GL_TEXTURE_CUBE_MAP) { |
| 4080 | for (int i = 0; i < 6; ++i) { |
| 4081 | GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4082 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, face, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4083 | LOCAL_SET_GL_ERROR( |
| 4084 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4085 | return; |
| 4086 | } |
| 4087 | } |
| 4088 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4089 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4090 | LOCAL_SET_GL_ERROR( |
| 4091 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4092 | return; |
| 4093 | } |
[email protected] | 7687479c | 2012-05-14 23:54:04 | [diff] [blame] | 4094 | } |
| 4095 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4096 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glGenerateMipmap"); |
[email protected] | 59f3ca0 | 2011-03-26 22:24:19 | [diff] [blame] | 4097 | // Workaround for Mac driver bug. In the large scheme of things setting |
| 4098 | // glTexParamter twice for glGenerateMipmap is probably not a lage performance |
[email protected] | a8bad26 | 2011-10-21 18:28:56 | [diff] [blame] | 4099 | // hit so there's probably no need to make this conditional. The bug appears |
| 4100 | // to be that if the filtering mode is set to something that doesn't require |
| 4101 | // mipmaps for rendering, or is never set to something other than the default, |
| 4102 | // then glGenerateMipmap misbehaves. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4103 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4104 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 4105 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4106 | glGenerateMipmapEXT(target); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4107 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4108 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, |
| 4109 | texture_ref->texture()->min_filter()); |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4110 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4111 | GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4112 | if (error == GL_NO_ERROR) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4113 | texture_manager()->MarkMipmapsGenerated(texture_ref); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4114 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4115 | } |
| 4116 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4117 | bool GLES2DecoderImpl::GetHelper( |
| 4118 | GLenum pname, GLint* params, GLsizei* num_written) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4119 | DCHECK(num_written); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 4120 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 4121 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4122 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 4123 | *num_written = 1; |
| 4124 | if (params) { |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 4125 | *params = GLES2Util::GetPreferredGLReadPixelsFormat( |
| 4126 | GetBoundReadFrameBufferInternalFormat()); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4127 | } |
| 4128 | return true; |
| 4129 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 4130 | *num_written = 1; |
| 4131 | if (params) { |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 4132 | *params = GLES2Util::GetPreferredGLReadPixelsType( |
| 4133 | GetBoundReadFrameBufferInternalFormat(), |
| 4134 | GetBoundReadFrameBufferTextureType()); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4135 | } |
| 4136 | return true; |
| 4137 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 4138 | *num_written = 1; |
| 4139 | if (params) { |
| 4140 | *params = group_->max_fragment_uniform_vectors(); |
| 4141 | } |
| 4142 | return true; |
| 4143 | case GL_MAX_VARYING_VECTORS: |
| 4144 | *num_written = 1; |
| 4145 | if (params) { |
| 4146 | *params = group_->max_varying_vectors(); |
| 4147 | } |
| 4148 | return true; |
| 4149 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 4150 | *num_written = 1; |
| 4151 | if (params) { |
| 4152 | *params = group_->max_vertex_uniform_vectors(); |
| 4153 | } |
| 4154 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4155 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4156 | } |
| 4157 | switch (pname) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 4158 | case GL_MAX_VIEWPORT_DIMS: |
| 4159 | if (offscreen_target_frame_buffer_.get()) { |
| 4160 | *num_written = 2; |
| 4161 | if (params) { |
| 4162 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4163 | params[1] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4164 | } |
| 4165 | return true; |
| 4166 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4167 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4168 | case GL_MAX_SAMPLES: |
| 4169 | *num_written = 1; |
| 4170 | if (params) { |
| 4171 | params[0] = renderbuffer_manager()->max_samples(); |
| 4172 | } |
| 4173 | return true; |
| 4174 | case GL_MAX_RENDERBUFFER_SIZE: |
| 4175 | *num_written = 1; |
| 4176 | if (params) { |
| 4177 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4178 | } |
| 4179 | return true; |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4180 | case GL_MAX_TEXTURE_SIZE: |
| 4181 | *num_written = 1; |
| 4182 | if (params) { |
| 4183 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_2D); |
| 4184 | } |
| 4185 | return true; |
| 4186 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 4187 | *num_written = 1; |
| 4188 | if (params) { |
| 4189 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP); |
| 4190 | } |
| 4191 | return true; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 4192 | case GL_MAX_COLOR_ATTACHMENTS_EXT: |
| 4193 | *num_written = 1; |
| 4194 | if (params) { |
| 4195 | params[0] = group_->max_color_attachments(); |
| 4196 | } |
| 4197 | return true; |
| 4198 | case GL_MAX_DRAW_BUFFERS_ARB: |
| 4199 | *num_written = 1; |
| 4200 | if (params) { |
| 4201 | params[0] = group_->max_draw_buffers(); |
| 4202 | } |
| 4203 | return true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4204 | case GL_ALPHA_BITS: |
| 4205 | *num_written = 1; |
| 4206 | if (params) { |
| 4207 | GLint v = 0; |
| 4208 | glGetIntegerv(GL_ALPHA_BITS, &v); |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 4209 | params[0] = BoundFramebufferHasColorAttachmentWithAlpha(false) ? v : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4210 | } |
| 4211 | return true; |
| 4212 | case GL_DEPTH_BITS: |
| 4213 | *num_written = 1; |
| 4214 | if (params) { |
| 4215 | GLint v = 0; |
| 4216 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 4217 | params[0] = BoundFramebufferHasDepthAttachment() ? v : 0; |
| 4218 | } |
| 4219 | return true; |
| 4220 | case GL_STENCIL_BITS: |
| 4221 | *num_written = 1; |
| 4222 | if (params) { |
| 4223 | GLint v = 0; |
| 4224 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 4225 | params[0] = BoundFramebufferHasStencilAttachment() ? v : 0; |
| 4226 | } |
| 4227 | return true; |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 4228 | case GL_COMPRESSED_TEXTURE_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4229 | *num_written = validators_->compressed_texture_format.GetValues().size(); |
| 4230 | if (params) { |
| 4231 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 4232 | params[ii] = validators_->compressed_texture_format.GetValues()[ii]; |
| 4233 | } |
| 4234 | } |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 4235 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4236 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 4237 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4238 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4239 | *params = validators_->compressed_texture_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4240 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4241 | return true; |
| 4242 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 4243 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4244 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4245 | *params = validators_->shader_binary_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4246 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4247 | return true; |
| 4248 | case GL_SHADER_BINARY_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4249 | *num_written = validators_->shader_binary_format.GetValues().size(); |
| 4250 | if (params) { |
| 4251 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 4252 | params[ii] = validators_->shader_binary_format.GetValues()[ii]; |
| 4253 | } |
| 4254 | } |
| 4255 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4256 | case GL_SHADER_COMPILER: |
| 4257 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4258 | if (params) { |
| 4259 | *params = GL_TRUE; |
| 4260 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4261 | return true; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4262 | case GL_ARRAY_BUFFER_BINDING: |
| 4263 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4264 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4265 | if (state_.bound_array_buffer.get()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4266 | GLuint client_id = 0; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4267 | buffer_manager()->GetClientId(state_.bound_array_buffer->service_id(), |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4268 | &client_id); |
| 4269 | *params = client_id; |
| 4270 | } else { |
| 4271 | *params = 0; |
| 4272 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4273 | } |
| 4274 | return true; |
| 4275 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 4276 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4277 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4278 | if (state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4279 | GLuint client_id = 0; |
| 4280 | buffer_manager()->GetClientId( |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 4281 | state_.vertex_attrib_manager->element_array_buffer()-> |
| 4282 | service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4283 | *params = client_id; |
| 4284 | } else { |
| 4285 | *params = 0; |
| 4286 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4287 | } |
| 4288 | return true; |
| 4289 | case GL_FRAMEBUFFER_BINDING: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4290 | // case GL_DRAW_FRAMEBUFFER_BINDING_EXT: (same as GL_FRAMEBUFFER_BINDING) |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4291 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4292 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4293 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4294 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4295 | if (framebuffer) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4296 | GLuint client_id = 0; |
| 4297 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4298 | framebuffer->service_id(), &client_id); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4299 | *params = client_id; |
| 4300 | } else { |
| 4301 | *params = 0; |
| 4302 | } |
| 4303 | } |
| 4304 | return true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4305 | case GL_READ_FRAMEBUFFER_BINDING_EXT: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4306 | *num_written = 1; |
| 4307 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4308 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4309 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4310 | if (framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4311 | GLuint client_id = 0; |
| 4312 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4313 | framebuffer->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4314 | *params = client_id; |
| 4315 | } else { |
| 4316 | *params = 0; |
| 4317 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4318 | } |
| 4319 | return true; |
| 4320 | case GL_RENDERBUFFER_BINDING: |
| 4321 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4322 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4323 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4324 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4325 | if (renderbuffer) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4326 | *params = renderbuffer->client_id(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4327 | } else { |
| 4328 | *params = 0; |
| 4329 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4330 | } |
| 4331 | return true; |
| 4332 | case GL_CURRENT_PROGRAM: |
| 4333 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4334 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4335 | if (state_.current_program.get()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4336 | GLuint client_id = 0; |
| 4337 | program_manager()->GetClientId( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4338 | state_.current_program->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4339 | *params = client_id; |
| 4340 | } else { |
| 4341 | *params = 0; |
| 4342 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4343 | } |
| 4344 | return true; |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 4345 | case GL_VERTEX_ARRAY_BINDING_OES: |
| 4346 | *num_written = 1; |
| 4347 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4348 | if (state_.vertex_attrib_manager.get() != |
| 4349 | default_vertex_attrib_manager_.get()) { |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 4350 | GLuint client_id = 0; |
| 4351 | vertex_array_manager_->GetClientId( |
| 4352 | state_.vertex_attrib_manager->service_id(), &client_id); |
| 4353 | *params = client_id; |
| 4354 | } else { |
| 4355 | *params = 0; |
| 4356 | } |
| 4357 | } |
| 4358 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4359 | case GL_TEXTURE_BINDING_2D: |
| 4360 | *num_written = 1; |
| 4361 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4362 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4363 | if (unit.bound_texture_2d.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4364 | *params = unit.bound_texture_2d->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4365 | } else { |
| 4366 | *params = 0; |
| 4367 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4368 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4369 | return true; |
| 4370 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 4371 | *num_written = 1; |
| 4372 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4373 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4374 | if (unit.bound_texture_cube_map.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4375 | *params = unit.bound_texture_cube_map->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4376 | } else { |
| 4377 | *params = 0; |
| 4378 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4379 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4380 | return true; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4381 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 4382 | *num_written = 1; |
| 4383 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4384 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4385 | if (unit.bound_texture_external_oes.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4386 | *params = unit.bound_texture_external_oes->client_id(); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4387 | } else { |
| 4388 | *params = 0; |
| 4389 | } |
| 4390 | } |
| 4391 | return true; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4392 | case GL_TEXTURE_BINDING_RECTANGLE_ARB: |
| 4393 | *num_written = 1; |
| 4394 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4395 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4396 | if (unit.bound_texture_rectangle_arb.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4397 | *params = unit.bound_texture_rectangle_arb->client_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4398 | } else { |
| 4399 | *params = 0; |
| 4400 | } |
| 4401 | } |
| 4402 | return true; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 4403 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 4404 | *num_written = 1; |
| 4405 | if (params) { |
| 4406 | params[0] = unpack_flip_y_; |
| 4407 | } |
| 4408 | return true; |
| 4409 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 4410 | *num_written = 1; |
| 4411 | if (params) { |
| 4412 | params[0] = unpack_premultiply_alpha_; |
| 4413 | } |
| 4414 | return true; |
| 4415 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 4416 | *num_written = 1; |
| 4417 | if (params) { |
| 4418 | params[0] = unpack_unpremultiply_alpha_; |
| 4419 | } |
| 4420 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4421 | default: |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 4422 | if (pname >= GL_DRAW_BUFFER0_ARB && |
| 4423 | pname < GL_DRAW_BUFFER0_ARB + group_->max_draw_buffers()) { |
| 4424 | *num_written = 1; |
| 4425 | if (params) { |
| 4426 | Framebuffer* framebuffer = |
| 4427 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 4428 | if (framebuffer) { |
| 4429 | params[0] = framebuffer->GetDrawBuffer(pname); |
| 4430 | } else { // backbuffer |
| 4431 | if (pname == GL_DRAW_BUFFER0_ARB) |
| 4432 | params[0] = group_->draw_buffer(); |
| 4433 | else |
| 4434 | params[0] = GL_NONE; |
| 4435 | } |
| 4436 | } |
| 4437 | return true; |
| 4438 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4439 | *num_written = util_.GLGetNumValuesReturned(pname); |
[email protected] | c5d79834 | 2010-09-24 20:42:53 | [diff] [blame] | 4440 | return false; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4441 | } |
| 4442 | } |
| 4443 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4444 | bool GLES2DecoderImpl::GetNumValuesReturnedForGLGet( |
| 4445 | GLenum pname, GLsizei* num_values) { |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4446 | if (state_.GetStateAsGLint(pname, NULL, num_values)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4447 | return true; |
| 4448 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4449 | return GetHelper(pname, NULL, num_values); |
| 4450 | } |
| 4451 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4452 | GLenum GLES2DecoderImpl::AdjustGetPname(GLenum pname) { |
| 4453 | if (GL_MAX_SAMPLES == pname && |
| 4454 | features().use_img_for_multisampled_render_to_texture) { |
| 4455 | return GL_MAX_SAMPLES_IMG; |
| 4456 | } |
| 4457 | return pname; |
| 4458 | } |
| 4459 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4460 | void GLES2DecoderImpl::DoGetBooleanv(GLenum pname, GLboolean* params) { |
| 4461 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4462 | GLsizei num_written = 0; |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4463 | if (GetNumValuesReturnedForGLGet(pname, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 4464 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4465 | if (!state_.GetStateAsGLint(pname, values.get(), &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4466 | GetHelper(pname, values.get(), &num_written); |
| 4467 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4468 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 4469 | params[ii] = static_cast<GLboolean>(values[ii]); |
| 4470 | } |
| 4471 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4472 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4473 | glGetBooleanv(pname, params); |
| 4474 | } |
| 4475 | } |
| 4476 | |
| 4477 | void GLES2DecoderImpl::DoGetFloatv(GLenum pname, GLfloat* params) { |
| 4478 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4479 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4480 | if (!state_.GetStateAsGLfloat(pname, params, &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4481 | if (GetHelper(pname, NULL, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 4482 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4483 | GetHelper(pname, values.get(), &num_written); |
| 4484 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 4485 | params[ii] = static_cast<GLfloat>(values[ii]); |
| 4486 | } |
| 4487 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4488 | pname = AdjustGetPname(pname); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4489 | glGetFloatv(pname, params); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4490 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4491 | } |
| 4492 | } |
| 4493 | |
| 4494 | void GLES2DecoderImpl::DoGetIntegerv(GLenum pname, GLint* params) { |
| 4495 | DCHECK(params); |
| 4496 | GLsizei num_written; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4497 | if (!state_.GetStateAsGLint(pname, params, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4498 | !GetHelper(pname, params, &num_written)) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4499 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4500 | glGetIntegerv(pname, params); |
| 4501 | } |
| 4502 | } |
| 4503 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 4504 | void GLES2DecoderImpl::DoGetProgramiv( |
| 4505 | GLuint program_id, GLenum pname, GLint* params) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4506 | Program* program = GetProgramInfoNotShader(program_id, "glGetProgramiv"); |
| 4507 | if (!program) { |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 4508 | return; |
| 4509 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4510 | program->GetProgramiv(pname, params); |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 4511 | } |
| 4512 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 4513 | void GLES2DecoderImpl::DoGetBufferParameteriv( |
| 4514 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 4515 | // Just delegate it. Some validation is actually done before this. |
| 4516 | buffer_manager()->ValidateAndDoGetBufferParameteriv( |
| 4517 | &state_, target, pname, params); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 4518 | } |
| 4519 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4520 | void GLES2DecoderImpl::DoBindAttribLocation( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4521 | GLuint program_id, GLuint index, const char* name) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4522 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4523 | LOCAL_SET_GL_ERROR( |
| 4524 | GL_INVALID_VALUE, "glBindAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4525 | return; |
| 4526 | } |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 4527 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4528 | LOCAL_SET_GL_ERROR( |
| 4529 | GL_INVALID_OPERATION, "glBindAttribLocation", "reserved prefix"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 4530 | return; |
| 4531 | } |
| 4532 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4533 | LOCAL_SET_GL_ERROR( |
| 4534 | GL_INVALID_VALUE, "glBindAttribLocation", "index out of range"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 4535 | return; |
| 4536 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4537 | Program* program = GetProgramInfoNotShader( |
| 4538 | program_id, "glBindAttribLocation"); |
| 4539 | if (!program) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4540 | return; |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4541 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4542 | program->SetAttribLocationBinding(name, static_cast<GLint>(index)); |
| 4543 | glBindAttribLocation(program->service_id(), index, name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | error::Error GLES2DecoderImpl::HandleBindAttribLocation( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4547 | uint32 immediate_data_size, const cmds::BindAttribLocation& c) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4548 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4549 | GLuint index = static_cast<GLuint>(c.index); |
| 4550 | uint32 name_size = c.data_size; |
| 4551 | const char* name = GetSharedMemoryAs<const char*>( |
| 4552 | c.name_shm_id, c.name_shm_offset, name_size); |
| 4553 | if (name == NULL) { |
| 4554 | return error::kOutOfBounds; |
| 4555 | } |
| 4556 | String name_str(name, name_size); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4557 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4558 | return error::kNoError; |
| 4559 | } |
| 4560 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4561 | error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4562 | uint32 immediate_data_size, const cmds::BindAttribLocationBucket& c) { |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4563 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4564 | GLuint index = static_cast<GLuint>(c.index); |
| 4565 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 4566 | if (!bucket || bucket->size() == 0) { |
| 4567 | return error::kInvalidArguments; |
| 4568 | } |
| 4569 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 4570 | if (!bucket->GetAsString(&name_str)) { |
| 4571 | return error::kInvalidArguments; |
| 4572 | } |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4573 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4574 | return error::kNoError; |
| 4575 | } |
| 4576 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4577 | void GLES2DecoderImpl::DoBindUniformLocationCHROMIUM( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4578 | GLuint program_id, GLint location, const char* name) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4579 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4580 | LOCAL_SET_GL_ERROR( |
| 4581 | GL_INVALID_VALUE, |
| 4582 | "glBindUniformLocationCHROMIUM", "Invalid character"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4583 | return; |
| 4584 | } |
| 4585 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4586 | LOCAL_SET_GL_ERROR( |
| 4587 | GL_INVALID_OPERATION, |
| 4588 | "glBindUniformLocationCHROMIUM", "reserved prefix"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4589 | return; |
| 4590 | } |
| 4591 | if (location < 0 || static_cast<uint32>(location) >= |
| 4592 | (group_->max_fragment_uniform_vectors() + |
| 4593 | group_->max_vertex_uniform_vectors()) * 4) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4594 | LOCAL_SET_GL_ERROR( |
| 4595 | GL_INVALID_VALUE, |
| 4596 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4597 | return; |
| 4598 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4599 | Program* program = GetProgramInfoNotShader( |
| 4600 | program_id, "glBindUniformLocationCHROMIUM"); |
| 4601 | if (!program) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4602 | return; |
| 4603 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4604 | if (!program->SetUniformLocationBinding(name, location)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4605 | LOCAL_SET_GL_ERROR( |
| 4606 | GL_INVALID_VALUE, |
| 4607 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4608 | } |
| 4609 | } |
| 4610 | |
| 4611 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4612 | uint32 immediate_data_size, const cmds::BindUniformLocationCHROMIUM& c) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4613 | GLuint program = static_cast<GLuint>(c.program); |
| 4614 | GLint location = static_cast<GLint>(c.location); |
| 4615 | uint32 name_size = c.data_size; |
| 4616 | const char* name = GetSharedMemoryAs<const char*>( |
| 4617 | c.name_shm_id, c.name_shm_offset, name_size); |
| 4618 | if (name == NULL) { |
| 4619 | return error::kOutOfBounds; |
| 4620 | } |
| 4621 | String name_str(name, name_size); |
| 4622 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 4623 | return error::kNoError; |
| 4624 | } |
| 4625 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4626 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUMBucket( |
| 4627 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4628 | const cmds::BindUniformLocationCHROMIUMBucket& c) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4629 | GLuint program = static_cast<GLuint>(c.program); |
| 4630 | GLint location = static_cast<GLint>(c.location); |
| 4631 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 4632 | if (!bucket || bucket->size() == 0) { |
| 4633 | return error::kInvalidArguments; |
| 4634 | } |
| 4635 | std::string name_str; |
| 4636 | if (!bucket->GetAsString(&name_str)) { |
| 4637 | return error::kInvalidArguments; |
| 4638 | } |
| 4639 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 4640 | return error::kNoError; |
| 4641 | } |
| 4642 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4643 | error::Error GLES2DecoderImpl::HandleDeleteShader( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4644 | uint32 immediate_data_size, const cmds::DeleteShader& c) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4645 | GLuint client_id = c.shader; |
| 4646 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4647 | Shader* shader = GetShader(client_id); |
| 4648 | if (shader) { |
| 4649 | if (!shader->IsDeleted()) { |
| 4650 | glDeleteShader(shader->service_id()); |
| 4651 | shader_manager()->MarkAsDeleted(shader); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4652 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4653 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4654 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteShader", "unknown shader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4655 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4656 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4657 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4658 | } |
| 4659 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4660 | error::Error GLES2DecoderImpl::HandleDeleteProgram( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4661 | uint32 immediate_data_size, const cmds::DeleteProgram& c) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4662 | GLuint client_id = c.program; |
| 4663 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4664 | Program* program = GetProgram(client_id); |
| 4665 | if (program) { |
| 4666 | if (!program->IsDeleted()) { |
| 4667 | program_manager()->MarkAsDeleted(shader_manager(), program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4668 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4669 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4670 | LOCAL_SET_GL_ERROR( |
| 4671 | GL_INVALID_VALUE, "glDeleteProgram", "unknown program"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4672 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4673 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4674 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4675 | } |
| 4676 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4677 | void GLES2DecoderImpl::DoDeleteSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4678 | GLuint namespace_id, GLsizei n, const GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 4679 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4680 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4681 | id_allocator->FreeID(ids[ii]); |
| 4682 | } |
| 4683 | } |
| 4684 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4685 | error::Error GLES2DecoderImpl::HandleDeleteSharedIdsCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4686 | uint32 immediate_data_size, const cmds::DeleteSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4687 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 4688 | GLsizei n = static_cast<GLsizei>(c.n); |
| 4689 | uint32 data_size; |
| 4690 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 4691 | return error::kOutOfBounds; |
| 4692 | } |
| 4693 | const GLuint* ids = GetSharedMemoryAs<const GLuint*>( |
| 4694 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 4695 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4696 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "DeleteSharedIdsCHROMIUM", "n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4697 | return error::kNoError; |
| 4698 | } |
| 4699 | if (ids == NULL) { |
| 4700 | return error::kOutOfBounds; |
| 4701 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4702 | DoDeleteSharedIdsCHROMIUM(namespace_id, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4703 | return error::kNoError; |
| 4704 | } |
| 4705 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4706 | void GLES2DecoderImpl::DoGenSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4707 | GLuint namespace_id, GLuint id_offset, GLsizei n, GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 4708 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4709 | if (id_offset == 0) { |
| 4710 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4711 | ids[ii] = id_allocator->AllocateID(); |
| 4712 | } |
| 4713 | } else { |
| 4714 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4715 | ids[ii] = id_allocator->AllocateIDAtOrAbove(id_offset); |
| 4716 | id_offset = ids[ii] + 1; |
| 4717 | } |
| 4718 | } |
| 4719 | } |
| 4720 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4721 | error::Error GLES2DecoderImpl::HandleGenSharedIdsCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4722 | uint32 immediate_data_size, const cmds::GenSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4723 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 4724 | GLuint id_offset = static_cast<GLuint>(c.id_offset); |
| 4725 | GLsizei n = static_cast<GLsizei>(c.n); |
| 4726 | uint32 data_size; |
| 4727 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 4728 | return error::kOutOfBounds; |
| 4729 | } |
| 4730 | GLuint* ids = GetSharedMemoryAs<GLuint*>( |
| 4731 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 4732 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4733 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "GenSharedIdsCHROMIUM", "n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4734 | return error::kNoError; |
| 4735 | } |
| 4736 | if (ids == NULL) { |
| 4737 | return error::kOutOfBounds; |
| 4738 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4739 | DoGenSharedIdsCHROMIUM(namespace_id, id_offset, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4740 | return error::kNoError; |
| 4741 | } |
| 4742 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4743 | void GLES2DecoderImpl::DoRegisterSharedIdsCHROMIUM( |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4744 | GLuint namespace_id, GLsizei n, const GLuint* ids) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 4745 | IdAllocatorInterface* id_allocator = group_->GetIdAllocator(namespace_id); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4746 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 4747 | if (!id_allocator->MarkAsUsed(ids[ii])) { |
| 4748 | for (GLsizei jj = 0; jj < ii; ++jj) { |
| 4749 | id_allocator->FreeID(ids[jj]); |
| 4750 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4751 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4752 | GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM", |
| 4753 | "attempt to register id that already exists"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4754 | return; |
| 4755 | } |
| 4756 | } |
| 4757 | } |
| 4758 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4759 | error::Error GLES2DecoderImpl::HandleRegisterSharedIdsCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4760 | uint32 immediate_data_size, const cmds::RegisterSharedIdsCHROMIUM& c) { |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4761 | GLuint namespace_id = static_cast<GLuint>(c.namespace_id); |
| 4762 | GLsizei n = static_cast<GLsizei>(c.n); |
| 4763 | uint32 data_size; |
| 4764 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 4765 | return error::kOutOfBounds; |
| 4766 | } |
| 4767 | GLuint* ids = GetSharedMemoryAs<GLuint*>( |
| 4768 | c.ids_shm_id, c.ids_shm_offset, data_size); |
| 4769 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4770 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "RegisterSharedIdsCHROMIUM", "n < 0"); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4771 | return error::kNoError; |
| 4772 | } |
| 4773 | if (ids == NULL) { |
| 4774 | return error::kOutOfBounds; |
| 4775 | } |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 4776 | DoRegisterSharedIdsCHROMIUM(namespace_id, n, ids); |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 4777 | return error::kNoError; |
| 4778 | } |
| 4779 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 4780 | error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 4781 | DCHECK(!ShouldDeferDraws()); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4782 | if (CheckBoundFramebuffersValid("glClear")) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4783 | ApplyDirtyState(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 4784 | glClear(mask); |
| 4785 | } |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 4786 | return error::kNoError; |
| 4787 | } |
| 4788 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4789 | void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
| 4790 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4791 | GLuint client_renderbuffer_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4792 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 4793 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4794 | LOCAL_SET_GL_ERROR( |
| 4795 | GL_INVALID_OPERATION, |
| 4796 | "glFramebufferRenderbuffer", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4797 | return; |
| 4798 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4799 | GLuint service_id = 0; |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4800 | Renderbuffer* renderbuffer = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4801 | if (client_renderbuffer_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4802 | renderbuffer = GetRenderbuffer(client_renderbuffer_id); |
| 4803 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4804 | LOCAL_SET_GL_ERROR( |
| 4805 | GL_INVALID_OPERATION, |
| 4806 | "glFramebufferRenderbuffer", "unknown renderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4807 | return; |
| 4808 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4809 | service_id = renderbuffer->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4810 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4811 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glFramebufferRenderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4812 | glFramebufferRenderbufferEXT( |
| 4813 | target, attachment, renderbuffertarget, service_id); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4814 | GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferRenderbuffer"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 4815 | if (error == GL_NO_ERROR) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4816 | framebuffer->AttachRenderbuffer(attachment, renderbuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4817 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4818 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4819 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4820 | } |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 4821 | OnFboChanged(); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4822 | } |
| 4823 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4824 | void GLES2DecoderImpl::DoDisable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4825 | if (SetCapabilityState(cap, false)) { |
| 4826 | glDisable(cap); |
| 4827 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | void GLES2DecoderImpl::DoEnable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4831 | if (SetCapabilityState(cap, true)) { |
| 4832 | glEnable(cap); |
| 4833 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4834 | } |
| 4835 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4836 | void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { |
| 4837 | state_.z_near = std::min(1.0f, std::max(0.0f, znear)); |
| 4838 | state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); |
| 4839 | glDepthRange(znear, zfar); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4840 | } |
| 4841 | |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 4842 | void GLES2DecoderImpl::DoSampleCoverage(GLclampf value, GLboolean invert) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4843 | state_.sample_coverage_value = std::min(1.0f, std::max(0.0f, value)); |
| 4844 | state_.sample_coverage_invert = (invert != 0); |
| 4845 | glSampleCoverage(state_.sample_coverage_value, invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4846 | } |
| 4847 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4848 | // Assumes framebuffer is complete. |
| 4849 | void GLES2DecoderImpl::ClearUnclearedAttachments( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4850 | GLenum target, Framebuffer* framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4851 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4852 | // bind this to the DRAW point, clear then bind back to READ |
| 4853 | // TODO(gman): I don't think there is any guarantee that an FBO that |
| 4854 | // is complete on the READ attachment will be complete as a DRAW |
| 4855 | // attachment. |
| 4856 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4857 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffer->service_id()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4858 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4859 | GLbitfield clear_bits = 0; |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4860 | if (framebuffer->HasUnclearedAttachment(GL_COLOR_ATTACHMENT0)) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4861 | glClearColor( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4862 | 0.0f, 0.0f, 0.0f, |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4863 | (GLES2Util::GetChannelsForFormat( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4864 | framebuffer->GetColorAttachmentFormat()) & 0x0008) != 0 ? 0.0f : |
| 4865 | 1.0f); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4866 | glColorMask(true, true, true, true); |
| 4867 | clear_bits |= GL_COLOR_BUFFER_BIT; |
| 4868 | } |
| 4869 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4870 | if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
| 4871 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4872 | glClearStencil(0); |
| 4873 | glStencilMask(-1); |
| 4874 | clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 4875 | } |
| 4876 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4877 | if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
| 4878 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4879 | glClearDepth(1.0f); |
| 4880 | glDepthMask(true); |
| 4881 | clear_bits |= GL_DEPTH_BUFFER_BIT; |
| 4882 | } |
| 4883 | |
| 4884 | glDisable(GL_SCISSOR_TEST); |
| 4885 | glClear(clear_bits); |
| 4886 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 4887 | framebuffer_manager()->MarkAttachmentsAsCleared( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4888 | framebuffer, renderbuffer_manager(), texture_manager()); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4889 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 4890 | RestoreClearState(); |
| 4891 | |
| 4892 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4893 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, framebuffer->service_id()); |
| 4894 | Framebuffer* draw_framebuffer = |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 4895 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4896 | GLuint service_id = draw_framebuffer ? draw_framebuffer->service_id() : |
| 4897 | GetBackbufferServiceId(); |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 4898 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, service_id); |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 4899 | } |
| 4900 | } |
| 4901 | |
| 4902 | void GLES2DecoderImpl::RestoreClearState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4903 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4904 | glClearColor( |
| 4905 | state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, |
| 4906 | state_.color_clear_alpha); |
| 4907 | glClearStencil(state_.stencil_clear); |
| 4908 | glClearDepth(state_.depth_clear); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 4909 | if (state_.enable_flags.scissor_test) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 4910 | glEnable(GL_SCISSOR_TEST); |
| 4911 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4912 | } |
| 4913 | |
| 4914 | GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4915 | Framebuffer* framebuffer = |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4916 | GetFramebufferInfoForTarget(target); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4917 | if (!framebuffer) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4918 | return GL_FRAMEBUFFER_COMPLETE; |
| 4919 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4920 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 4921 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
| 4922 | return completeness; |
| 4923 | } |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 4924 | return framebuffer->GetStatus(texture_manager(), target); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | void GLES2DecoderImpl::DoFramebufferTexture2D( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4928 | GLenum target, GLenum attachment, GLenum textarget, |
| 4929 | GLuint client_texture_id, GLint level) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4930 | DoFramebufferTexture2DCommon( |
| 4931 | "glFramebufferTexture2D", target, attachment, |
| 4932 | textarget, client_texture_id, level, 0); |
| 4933 | } |
| 4934 | |
| 4935 | void GLES2DecoderImpl::DoFramebufferTexture2DMultisample( |
| 4936 | GLenum target, GLenum attachment, GLenum textarget, |
| 4937 | GLuint client_texture_id, GLint level, GLsizei samples) { |
| 4938 | if (!features().multisampled_render_to_texture) { |
| 4939 | LOCAL_SET_GL_ERROR( |
| 4940 | GL_INVALID_OPERATION, |
| 4941 | "glFramebufferTexture2DMultisample", "function not available"); |
| 4942 | return; |
| 4943 | } |
| 4944 | DoFramebufferTexture2DCommon( |
| 4945 | "glFramebufferTexture2DMultisample", target, attachment, |
| 4946 | textarget, client_texture_id, level, samples); |
| 4947 | } |
| 4948 | |
| 4949 | void GLES2DecoderImpl::DoFramebufferTexture2DCommon( |
| 4950 | const char* name, GLenum target, GLenum attachment, GLenum textarget, |
| 4951 | GLuint client_texture_id, GLint level, GLsizei samples) { |
| 4952 | if (samples > renderbuffer_manager()->max_samples()) { |
| 4953 | LOCAL_SET_GL_ERROR( |
| 4954 | GL_INVALID_VALUE, |
| 4955 | "glFramebufferTexture2DMultisample", "samples too large"); |
| 4956 | return; |
| 4957 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4958 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 4959 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4960 | LOCAL_SET_GL_ERROR( |
| 4961 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4962 | name, "no framebuffer bound."); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4963 | return; |
| 4964 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4965 | GLuint service_id = 0; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4966 | TextureRef* texture_ref = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4967 | if (client_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4968 | texture_ref = GetTexture(client_texture_id); |
| 4969 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4970 | LOCAL_SET_GL_ERROR( |
| 4971 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4972 | name, "unknown texture_ref"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4973 | return; |
| 4974 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4975 | service_id = texture_ref->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4976 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4977 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4978 | if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4979 | LOCAL_SET_GL_ERROR( |
| 4980 | GL_INVALID_VALUE, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4981 | name, "level out of range"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4982 | return; |
| 4983 | } |
| 4984 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 4985 | if (texture_ref) |
| 4986 | DoWillUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 4987 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4988 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); |
| 4989 | if (0 == samples) { |
| 4990 | glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
| 4991 | } else { |
| 4992 | if (features().use_img_for_multisampled_render_to_texture) { |
| 4993 | glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, |
| 4994 | service_id, level, samples); |
| 4995 | } else { |
| 4996 | glFramebufferTexture2DMultisampleEXT(target, attachment, textarget, |
| 4997 | service_id, level, samples); |
| 4998 | } |
| 4999 | } |
| 5000 | GLenum error = LOCAL_PEEK_GL_ERROR(name); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5001 | if (error == GL_NO_ERROR) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5002 | framebuffer->AttachTexture(attachment, texture_ref, textarget, level, |
| 5003 | samples); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5004 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 5005 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5006 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5007 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5008 | |
| 5009 | if (texture_ref) |
| 5010 | DoDidUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 5011 | |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 5012 | OnFboChanged(); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5013 | } |
| 5014 | |
| 5015 | void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( |
| 5016 | GLenum target, GLenum attachment, GLenum pname, GLint* params) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5017 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5018 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5019 | LOCAL_SET_GL_ERROR( |
| 5020 | GL_INVALID_OPERATION, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5021 | "glGetFramebufferAttachmentParameteriv", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5022 | return; |
| 5023 | } |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 5024 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5025 | const Framebuffer::Attachment* attachment_object = |
| 5026 | framebuffer->GetAttachment(attachment); |
| 5027 | *params = attachment_object ? attachment_object->object_name() : 0; |
| 5028 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5029 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT && |
| 5030 | features().use_img_for_multisampled_render_to_texture) { |
| 5031 | pname = GL_TEXTURE_SAMPLES_IMG; |
| 5032 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5033 | glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 5034 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5035 | } |
| 5036 | |
| 5037 | void GLES2DecoderImpl::DoGetRenderbufferParameteriv( |
| 5038 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5039 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5040 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5041 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5042 | LOCAL_SET_GL_ERROR( |
| 5043 | GL_INVALID_OPERATION, |
| 5044 | "glGetRenderbufferParameteriv", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5045 | return; |
| 5046 | } |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 5047 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5048 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5049 | *params = renderbuffer->internal_format(); |
| 5050 | break; |
| 5051 | case GL_RENDERBUFFER_WIDTH: |
| 5052 | *params = renderbuffer->width(); |
| 5053 | break; |
| 5054 | case GL_RENDERBUFFER_HEIGHT: |
| 5055 | *params = renderbuffer->height(); |
| 5056 | break; |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5057 | case GL_RENDERBUFFER_SAMPLES_EXT: |
| 5058 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5059 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_IMG, |
| 5060 | params); |
| 5061 | } else { |
| 5062 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_EXT, |
| 5063 | params); |
| 5064 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5065 | default: |
| 5066 | glGetRenderbufferParameterivEXT(target, pname, params); |
| 5067 | break; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 5068 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5069 | } |
| 5070 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5071 | void GLES2DecoderImpl::DoBlitFramebufferCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5072 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 5073 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 5074 | GLbitfield mask, GLenum filter) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 5075 | DCHECK(!ShouldDeferReads() && !ShouldDeferDraws()); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 5076 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5077 | LOCAL_SET_GL_ERROR( |
| 5078 | GL_INVALID_OPERATION, |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5079 | "glBlitFramebufferCHROMIUM", "function not available"); |
[email protected] | 680aa41 | 2013-10-31 18:08:01 | [diff] [blame] | 5080 | return; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5081 | } |
[email protected] | 0c16343f | 2013-03-08 20:40:16 | [diff] [blame] | 5082 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5083 | if (!CheckBoundFramebuffersValid("glBlitFramebufferCHROMIUM")) { |
[email protected] | 0c16343f | 2013-03-08 20:40:16 | [diff] [blame] | 5084 | return; |
| 5085 | } |
| 5086 | |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 5087 | glDisable(GL_SCISSOR_TEST); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5088 | BlitFramebufferHelper( |
| 5089 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 5090 | EnableDisable(GL_SCISSOR_TEST, state_.enable_flags.scissor_test); |
| 5091 | } |
| 5092 | |
| 5093 | void GLES2DecoderImpl::RenderbufferStorageMultisampleHelper( |
| 5094 | const FeatureInfo* feature_info, |
| 5095 | GLenum target, |
| 5096 | GLsizei samples, |
| 5097 | GLenum internal_format, |
| 5098 | GLsizei width, |
| 5099 | GLsizei height) { |
| 5100 | // TODO(sievers): This could be resolved at the GL binding level, but the |
| 5101 | // binding process is currently a bit too 'brute force'. |
| 5102 | if (feature_info->feature_flags().is_angle) { |
| 5103 | glRenderbufferStorageMultisampleANGLE( |
| 5104 | target, samples, internal_format, width, height); |
| 5105 | } else if (feature_info->feature_flags().use_core_framebuffer_multisample) { |
| 5106 | glRenderbufferStorageMultisample( |
| 5107 | target, samples, internal_format, width, height); |
| 5108 | } else { |
| 5109 | glRenderbufferStorageMultisampleEXT( |
| 5110 | target, samples, internal_format, width, height); |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | void GLES2DecoderImpl::BlitFramebufferHelper(GLint srcX0, |
| 5115 | GLint srcY0, |
| 5116 | GLint srcX1, |
| 5117 | GLint srcY1, |
| 5118 | GLint dstX0, |
| 5119 | GLint dstY0, |
| 5120 | GLint dstX1, |
| 5121 | GLint dstY1, |
| 5122 | GLbitfield mask, |
| 5123 | GLenum filter) { |
| 5124 | // TODO(sievers): This could be resolved at the GL binding level, but the |
| 5125 | // binding process is currently a bit too 'brute force'. |
| 5126 | if (feature_info_->feature_flags().is_angle) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 5127 | glBlitFramebufferANGLE( |
| 5128 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5129 | } else if (feature_info_->feature_flags().use_core_framebuffer_multisample) { |
| 5130 | glBlitFramebuffer( |
| 5131 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 5132 | } else { |
| 5133 | glBlitFramebufferEXT( |
| 5134 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 5135 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5136 | } |
| 5137 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5138 | bool GLES2DecoderImpl::ValidateRenderbufferStorageMultisample( |
| 5139 | GLsizei samples, |
| 5140 | GLenum internalformat, |
| 5141 | GLsizei width, |
| 5142 | GLsizei height) { |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5143 | if (samples > renderbuffer_manager()->max_samples()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5144 | LOCAL_SET_GL_ERROR( |
| 5145 | GL_INVALID_VALUE, |
| 5146 | "glRenderbufferStorageMultisample", "samples too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5147 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5148 | } |
| 5149 | |
| 5150 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 5151 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5152 | LOCAL_SET_GL_ERROR( |
| 5153 | GL_INVALID_VALUE, |
| 5154 | "glRenderbufferStorageMultisample", "dimensions too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5155 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5156 | } |
| 5157 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5158 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5159 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 5160 | width, height, samples, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5161 | LOCAL_SET_GL_ERROR( |
| 5162 | GL_OUT_OF_MEMORY, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5163 | "glRenderbufferStorageMultisample", "dimensions too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5164 | return false; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5165 | } |
| 5166 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5167 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5168 | LOCAL_SET_GL_ERROR( |
| 5169 | GL_OUT_OF_MEMORY, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5170 | "glRenderbufferStorageMultisample", "out of memory"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5171 | return false; |
| 5172 | } |
| 5173 | |
| 5174 | return true; |
| 5175 | } |
| 5176 | |
| 5177 | void GLES2DecoderImpl::DoRenderbufferStorageMultisampleCHROMIUM( |
| 5178 | GLenum target, GLsizei samples, GLenum internalformat, |
| 5179 | GLsizei width, GLsizei height) { |
| 5180 | if (!features().chromium_framebuffer_multisample) { |
| 5181 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 5182 | "glRenderbufferStorageMultisampleCHROMIUM", |
| 5183 | "function not available"); |
| 5184 | return; |
| 5185 | } |
| 5186 | |
| 5187 | Renderbuffer* renderbuffer = GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5188 | if (!renderbuffer) { |
| 5189 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 5190 | "glRenderbufferStorageMultisampleCHROMIUM", |
| 5191 | "no renderbuffer bound"); |
| 5192 | return; |
| 5193 | } |
| 5194 | |
| 5195 | if (!ValidateRenderbufferStorageMultisample( |
| 5196 | samples, internalformat, width, height)) { |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5197 | return; |
| 5198 | } |
| 5199 | |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5200 | GLenum impl_format = |
| 5201 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5202 | internalformat); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5203 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER( |
| 5204 | "glRenderbufferStorageMultisampleCHROMIUM"); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5205 | RenderbufferStorageMultisampleHelper( |
| 5206 | feature_info_, target, samples, impl_format, width, height); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5207 | GLenum error = |
| 5208 | LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleCHROMIUM"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5209 | if (error == GL_NO_ERROR) { |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5210 | |
| 5211 | if (workarounds().validate_multisample_buffer_allocation) { |
| 5212 | if (!VerifyMultisampleRenderbufferIntegrity( |
| 5213 | renderbuffer->service_id(), impl_format)) { |
| 5214 | LOCAL_SET_GL_ERROR( |
| 5215 | GL_OUT_OF_MEMORY, |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5216 | "glRenderbufferStorageMultisampleCHROMIUM", "out of memory"); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5217 | return; |
| 5218 | } |
| 5219 | } |
| 5220 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5221 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 5222 | // attached to we could just mark those framebuffers as not complete. |
| 5223 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5224 | renderbuffer_manager()->SetInfo( |
| 5225 | renderbuffer, samples, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5226 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5227 | } |
| 5228 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5229 | // This is the handler for multisampled_render_to_texture extensions. |
| 5230 | void GLES2DecoderImpl::DoRenderbufferStorageMultisampleEXT( |
| 5231 | GLenum target, GLsizei samples, GLenum internalformat, |
| 5232 | GLsizei width, GLsizei height) { |
| 5233 | if (!features().multisampled_render_to_texture) { |
| 5234 | LOCAL_SET_GL_ERROR( |
| 5235 | GL_INVALID_OPERATION, |
| 5236 | "glRenderbufferStorageMultisampleEXT", "function not available"); |
| 5237 | return; |
| 5238 | } |
| 5239 | |
| 5240 | Renderbuffer* renderbuffer = GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5241 | if (!renderbuffer) { |
| 5242 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 5243 | "glRenderbufferStorageMultisampleEXT", |
| 5244 | "no renderbuffer bound"); |
| 5245 | return; |
| 5246 | } |
| 5247 | |
| 5248 | if (!ValidateRenderbufferStorageMultisample( |
| 5249 | samples, internalformat, width, height)) { |
| 5250 | return; |
| 5251 | } |
| 5252 | |
| 5253 | GLenum impl_format = |
| 5254 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5255 | internalformat); |
| 5256 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorageMultisampleEXT"); |
| 5257 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5258 | glRenderbufferStorageMultisampleIMG( |
| 5259 | target, samples, impl_format, width, height); |
| 5260 | } else { |
| 5261 | glRenderbufferStorageMultisampleEXT( |
| 5262 | target, samples, impl_format, width, height); |
| 5263 | } |
| 5264 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleEXT"); |
| 5265 | if (error == GL_NO_ERROR) { |
| 5266 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 5267 | // attached to we could just mark those framebuffers as not complete. |
| 5268 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
| 5269 | renderbuffer_manager()->SetInfo( |
| 5270 | renderbuffer, samples, internalformat, width, height); |
| 5271 | } |
| 5272 | } |
| 5273 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5274 | // This function validates the allocation of a multisampled renderbuffer |
| 5275 | // by clearing it to a key color, blitting the contents to a texture, and |
| 5276 | // reading back the color to ensure it matches the key. |
| 5277 | bool GLES2DecoderImpl::VerifyMultisampleRenderbufferIntegrity( |
| 5278 | GLuint renderbuffer, GLenum format) { |
| 5279 | |
| 5280 | // Only validate color buffers. |
| 5281 | // These formats have been selected because they are very common or are known |
| 5282 | // to be used by the WebGL backbuffer. If problems are observed with other |
| 5283 | // color formats they can be added here. |
| 5284 | switch(format) { |
| 5285 | case GL_RGB: |
| 5286 | case GL_RGB8: |
| 5287 | case GL_RGBA: |
| 5288 | case GL_RGBA8: |
| 5289 | break; |
| 5290 | default: |
| 5291 | return true; |
| 5292 | } |
| 5293 | |
| 5294 | GLint draw_framebuffer, read_framebuffer; |
| 5295 | |
| 5296 | // Cache framebuffer and texture bindings. |
| 5297 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_framebuffer); |
| 5298 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_framebuffer); |
| 5299 | |
| 5300 | if (!validation_texture_) { |
| 5301 | GLint bound_texture; |
| 5302 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
| 5303 | |
| 5304 | // Create additional resources needed for the verification. |
| 5305 | glGenTextures(1, &validation_texture_); |
| 5306 | glGenFramebuffersEXT(1, &validation_fbo_multisample_); |
| 5307 | glGenFramebuffersEXT(1, &validation_fbo_); |
| 5308 | |
| 5309 | // Texture only needs to be 1x1. |
| 5310 | glBindTexture(GL_TEXTURE_2D, validation_texture_); |
| 5311 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, |
| 5312 | GL_UNSIGNED_BYTE, NULL); |
| 5313 | |
| 5314 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 5315 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5316 | GL_TEXTURE_2D, validation_texture_, 0); |
| 5317 | |
| 5318 | glBindTexture(GL_TEXTURE_2D, bound_texture); |
| 5319 | } |
| 5320 | |
| 5321 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 5322 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5323 | GL_RENDERBUFFER, renderbuffer); |
| 5324 | |
| 5325 | // Cache current state and reset it to the values we require. |
| 5326 | GLboolean scissor_enabled = false; |
| 5327 | glGetBooleanv(GL_SCISSOR_TEST, &scissor_enabled); |
| 5328 | if (scissor_enabled) |
| 5329 | glDisable(GL_SCISSOR_TEST); |
| 5330 | |
| 5331 | GLboolean color_mask[4] = {true, true, true, true}; |
| 5332 | glGetBooleanv(GL_COLOR_WRITEMASK, color_mask); |
| 5333 | glColorMask(true, true, true, true); |
| 5334 | |
| 5335 | GLfloat clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 5336 | glGetFloatv(GL_COLOR_CLEAR_VALUE, clear_color); |
| 5337 | glClearColor(1.0f, 0.0f, 1.0f, 1.0f); |
| 5338 | |
| 5339 | // Clear the buffer to the desired key color. |
| 5340 | glClear(GL_COLOR_BUFFER_BIT); |
| 5341 | |
| 5342 | // Blit from the multisample buffer to a standard texture. |
| 5343 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, validation_fbo_multisample_); |
| 5344 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, validation_fbo_); |
| 5345 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5346 | BlitFramebufferHelper( |
| 5347 | 0, 0, 1, 1, 0, 0, 1, 1, GL_COLOR_BUFFER_BIT, GL_NEAREST); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5348 | |
| 5349 | // Read a pixel from the buffer. |
| 5350 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 5351 | |
| 5352 | unsigned char pixel[3] = {0, 0, 0}; |
| 5353 | glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixel); |
| 5354 | |
| 5355 | // Detach the renderbuffer. |
| 5356 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 5357 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5358 | GL_RENDERBUFFER, 0); |
| 5359 | |
| 5360 | // Restore cached state. |
| 5361 | if (scissor_enabled) |
| 5362 | glEnable(GL_SCISSOR_TEST); |
| 5363 | |
| 5364 | glColorMask(color_mask[0], color_mask[1], color_mask[2], color_mask[3]); |
| 5365 | glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); |
| 5366 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, draw_framebuffer); |
| 5367 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, read_framebuffer); |
| 5368 | |
| 5369 | // Return true if the pixel matched the desired key color. |
| 5370 | return (pixel[0] == 0xFF && |
| 5371 | pixel[1] == 0x00 && |
| 5372 | pixel[2] == 0xFF); |
| 5373 | } |
| 5374 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5375 | void GLES2DecoderImpl::DoRenderbufferStorage( |
| 5376 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5377 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5378 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5379 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5380 | LOCAL_SET_GL_ERROR( |
| 5381 | GL_INVALID_OPERATION, |
| 5382 | "glRenderbufferStorage", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5383 | return; |
| 5384 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5385 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5386 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 5387 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5388 | LOCAL_SET_GL_ERROR( |
| 5389 | GL_INVALID_VALUE, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5390 | return; |
| 5391 | } |
| 5392 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5393 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5394 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 5395 | width, height, 1, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5396 | LOCAL_SET_GL_ERROR( |
| 5397 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5398 | return; |
| 5399 | } |
| 5400 | |
| 5401 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5402 | LOCAL_SET_GL_ERROR( |
| 5403 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5404 | return; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 5405 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5406 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5407 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorage"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5408 | glRenderbufferStorageEXT( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5409 | target, |
| 5410 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5411 | internalformat), |
| 5412 | width, |
| 5413 | height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5414 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorage"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5415 | if (error == GL_NO_ERROR) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5416 | // TODO(gman): If tetxures tracked which framebuffers they were attached to |
| 5417 | // we could just mark those framebuffers as not complete. |
| 5418 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5419 | renderbuffer_manager()->SetInfo( |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5420 | renderbuffer, 1, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5421 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5422 | } |
| 5423 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5424 | void GLES2DecoderImpl::DoLinkProgram(GLuint program_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 5425 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoLinkProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5426 | Program* program = GetProgramInfoNotShader( |
| 5427 | program_id, "glLinkProgram"); |
| 5428 | if (!program) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 5429 | return; |
| 5430 | } |
[email protected] | 05afda1 | 2011-01-20 00:17:34 | [diff] [blame] | 5431 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5432 | LogClientServiceForInfo(program, program_id, "glLinkProgram"); |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 5433 | ShaderTranslator* vertex_translator = NULL; |
| 5434 | ShaderTranslator* fragment_translator = NULL; |
| 5435 | if (use_shader_translator_) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5436 | vertex_translator = vertex_translator_.get(); |
| 5437 | fragment_translator = fragment_translator_.get(); |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 5438 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5439 | if (program->Link(shader_manager(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5440 | vertex_translator, |
| 5441 | fragment_translator, |
[email protected] | 00840153 | 2014-02-07 00:10:50 | [diff] [blame] | 5442 | workarounds().count_all_in_varyings_packing ? |
| 5443 | Program::kCountAll : Program::kCountOnlyStaticallyUsed, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5444 | shader_cache_callback_)) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5445 | if (program == state_.current_program.get()) { |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 5446 | if (workarounds().use_current_program_after_successful_link) |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5447 | glUseProgram(program->service_id()); |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 5448 | if (workarounds().clear_uniforms_before_first_program_use) |
| 5449 | program_manager()->ClearUniforms(program); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 5450 | } |
| 5451 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5452 | }; |
| 5453 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5454 | void GLES2DecoderImpl::DoTexParameterf( |
| 5455 | GLenum target, GLenum pname, GLfloat param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5456 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5457 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5458 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5459 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterf", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5460 | return; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5461 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5462 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5463 | texture_manager()->SetParameter( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5464 | "glTexParameterf", GetErrorState(), texture, pname, |
| 5465 | static_cast<GLint>(param)); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5466 | } |
| 5467 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5468 | void GLES2DecoderImpl::DoTexParameteri( |
| 5469 | GLenum target, GLenum pname, GLint param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5470 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5471 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5472 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5473 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5474 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5475 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5476 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5477 | texture_manager()->SetParameter( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5478 | "glTexParameteri", GetErrorState(), texture, pname, param); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5479 | } |
| 5480 | |
| 5481 | void GLES2DecoderImpl::DoTexParameterfv( |
| 5482 | GLenum target, GLenum pname, const GLfloat* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5483 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5484 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5485 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5486 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5487 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5488 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5489 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5490 | texture_manager()->SetParameter( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5491 | "glTexParameterfv", GetErrorState(), texture, pname, |
| 5492 | static_cast<GLint>(params[0])); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5493 | } |
| 5494 | |
| 5495 | void GLES2DecoderImpl::DoTexParameteriv( |
| 5496 | GLenum target, GLenum pname, const GLint* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5497 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5498 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5499 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5500 | LOCAL_SET_GL_ERROR( |
| 5501 | GL_INVALID_VALUE, "glTexParameteriv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5502 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5503 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5504 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5505 | texture_manager()->SetParameter( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5506 | "glTexParameteriv", GetErrorState(), texture, pname, *params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5507 | } |
| 5508 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5509 | bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5510 | if (!state_.current_program.get()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5511 | // The program does not exist. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5512 | LOCAL_SET_GL_ERROR( |
| 5513 | GL_INVALID_OPERATION, function_name, "no program in use"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5514 | return false; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5515 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5516 | if (!state_.current_program->InUse()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5517 | LOCAL_SET_GL_ERROR( |
| 5518 | GL_INVALID_OPERATION, function_name, "program not linked"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5519 | return false; |
| 5520 | } |
| 5521 | return true; |
| 5522 | } |
| 5523 | |
| 5524 | bool GLES2DecoderImpl::CheckCurrentProgramForUniform( |
| 5525 | GLint location, const char* function_name) { |
| 5526 | if (!CheckCurrentProgram(function_name)) { |
| 5527 | return false; |
| 5528 | } |
| 5529 | return location != -1; |
| 5530 | } |
| 5531 | |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5532 | namespace { |
| 5533 | |
| 5534 | static const GLenum valid_int_vec1_types_list[] = { |
| 5535 | GL_INT, |
| 5536 | GL_BOOL, |
| 5537 | GL_SAMPLER_2D, |
| 5538 | GL_SAMPLER_2D_RECT_ARB, |
| 5539 | GL_SAMPLER_CUBE, |
| 5540 | GL_SAMPLER_EXTERNAL_OES, |
| 5541 | }; |
| 5542 | |
| 5543 | static const GLenum valid_int_vec2_types_list[] = { |
| 5544 | GL_INT_VEC2, |
| 5545 | GL_BOOL_VEC2, |
| 5546 | }; |
| 5547 | |
| 5548 | static const GLenum valid_int_vec3_types_list[] = { |
| 5549 | GL_INT_VEC3, |
| 5550 | GL_BOOL_VEC3, |
| 5551 | }; |
| 5552 | |
| 5553 | static const GLenum valid_int_vec4_types_list[] = { |
| 5554 | GL_INT_VEC4, |
| 5555 | GL_BOOL_VEC4, |
| 5556 | }; |
| 5557 | |
| 5558 | static const GLenum valid_float_vec1_types_list[] = { |
| 5559 | GL_FLOAT, |
| 5560 | GL_BOOL, |
| 5561 | }; |
| 5562 | |
| 5563 | static const GLenum valid_float_vec2_types_list[] = { |
| 5564 | GL_FLOAT_VEC2, |
| 5565 | GL_BOOL_VEC2, |
| 5566 | }; |
| 5567 | |
| 5568 | static const GLenum valid_float_vec3_types_list[] = { |
| 5569 | GL_FLOAT_VEC3, |
| 5570 | GL_BOOL_VEC3, |
| 5571 | }; |
| 5572 | |
| 5573 | static const GLenum valid_float_vec4_types_list[] = { |
| 5574 | GL_FLOAT_VEC4, |
| 5575 | GL_BOOL_VEC4, |
| 5576 | }; |
| 5577 | |
| 5578 | static const GLenum valid_float_mat2_types_list[] = { |
| 5579 | GL_FLOAT_MAT2, |
| 5580 | }; |
| 5581 | |
| 5582 | static const GLenum valid_float_mat3_types_list[] = { |
| 5583 | GL_FLOAT_MAT3, |
| 5584 | }; |
| 5585 | |
| 5586 | static const GLenum valid_float_mat4_types_list[] = { |
| 5587 | GL_FLOAT_MAT4, |
| 5588 | }; |
| 5589 | |
| 5590 | static const GLES2DecoderImpl::BaseUniformInfo valid_int_vec1_base_info = { |
| 5591 | valid_int_vec1_types_list, |
| 5592 | arraysize(valid_int_vec1_types_list), |
| 5593 | }; |
| 5594 | |
| 5595 | static const GLES2DecoderImpl::BaseUniformInfo valid_int_vec2_base_info = { |
| 5596 | valid_int_vec2_types_list, |
| 5597 | arraysize(valid_int_vec2_types_list), |
| 5598 | }; |
| 5599 | |
| 5600 | static const GLES2DecoderImpl::BaseUniformInfo valid_int_vec3_base_info = { |
| 5601 | valid_int_vec3_types_list, |
| 5602 | arraysize(valid_int_vec3_types_list), |
| 5603 | }; |
| 5604 | |
| 5605 | static const GLES2DecoderImpl::BaseUniformInfo valid_int_vec4_base_info = { |
| 5606 | valid_int_vec4_types_list, |
| 5607 | arraysize(valid_int_vec4_types_list), |
| 5608 | }; |
| 5609 | |
| 5610 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_vec1_base_info = { |
| 5611 | valid_float_vec1_types_list, |
| 5612 | arraysize(valid_float_vec1_types_list), |
| 5613 | }; |
| 5614 | |
| 5615 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_vec2_base_info = { |
| 5616 | valid_float_vec2_types_list, |
| 5617 | arraysize(valid_float_vec2_types_list), |
| 5618 | }; |
| 5619 | |
| 5620 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_vec3_base_info = { |
| 5621 | valid_float_vec3_types_list, |
| 5622 | arraysize(valid_float_vec3_types_list), |
| 5623 | }; |
| 5624 | |
| 5625 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_vec4_base_info = { |
| 5626 | valid_float_vec4_types_list, |
| 5627 | arraysize(valid_float_vec4_types_list), |
| 5628 | }; |
| 5629 | |
| 5630 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_mat2_base_info = { |
| 5631 | valid_float_mat2_types_list, |
| 5632 | arraysize(valid_float_mat2_types_list), |
| 5633 | }; |
| 5634 | |
| 5635 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_mat3_base_info = { |
| 5636 | valid_float_mat3_types_list, |
| 5637 | arraysize(valid_float_mat3_types_list), |
| 5638 | }; |
| 5639 | |
| 5640 | static const GLES2DecoderImpl::BaseUniformInfo valid_float_mat4_base_info = { |
| 5641 | valid_float_mat4_types_list, |
| 5642 | arraysize(valid_float_mat4_types_list), |
| 5643 | }; |
| 5644 | |
| 5645 | } // anonymous namespace. |
| 5646 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5647 | bool GLES2DecoderImpl::PrepForSetUniformByLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5648 | GLint fake_location, const char* function_name, |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5649 | const GLES2DecoderImpl::BaseUniformInfo& base_info, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5650 | GLint* real_location, GLenum* type, GLsizei* count) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5651 | DCHECK(type); |
| 5652 | DCHECK(count); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5653 | DCHECK(real_location); |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5654 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5655 | if (!CheckCurrentProgramForUniform(fake_location, function_name)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5656 | return false; |
| 5657 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5658 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5659 | const Program::UniformInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5660 | state_.current_program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5661 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5662 | if (!info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5663 | LOCAL_SET_GL_ERROR( |
| 5664 | GL_INVALID_OPERATION, function_name, "unknown location"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5665 | return false; |
| 5666 | } |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5667 | bool okay = false; |
| 5668 | for (size_t ii = 0; ii < base_info.num_valid_types; ++ii) { |
| 5669 | if (base_info.valid_types[ii] == info->type) { |
| 5670 | okay = true; |
| 5671 | break; |
| 5672 | } |
| 5673 | } |
| 5674 | if (!okay) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5675 | LOCAL_SET_GL_ERROR( |
| 5676 | GL_INVALID_OPERATION, function_name, |
| 5677 | "wrong uniform function for type"); |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5678 | return false; |
| 5679 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5680 | if (*count > 1 && !info->is_array) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5681 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5682 | GL_INVALID_OPERATION, function_name, "count > 1 for non-array"); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5683 | return false; |
| 5684 | } |
| 5685 | *count = std::min(info->size - array_index, *count); |
| 5686 | if (*count <= 0) { |
| 5687 | return false; |
| 5688 | } |
| 5689 | *type = info->type; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5690 | return true; |
| 5691 | } |
| 5692 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5693 | void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) { |
| 5694 | GLenum type = 0; |
| 5695 | GLsizei count = 1; |
| 5696 | GLint real_location = -1; |
| 5697 | if (!PrepForSetUniformByLocation( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5698 | fake_location, "glUniform1i", valid_int_vec1_base_info, |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5699 | &real_location, &type, &count)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5700 | return; |
| 5701 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5702 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5703 | state_.texture_units.size(), fake_location, 1, &v0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5704 | LOCAL_SET_GL_ERROR( |
| 5705 | GL_INVALID_VALUE, "glUniform1i", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 5706 | return; |
| 5707 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5708 | glUniform1i(real_location, v0); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | void GLES2DecoderImpl::DoUniform1iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5712 | GLint fake_location, GLsizei count, const GLint *value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5713 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5714 | GLint real_location = -1; |
| 5715 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5716 | fake_location, "glUniform1iv", valid_int_vec1_base_info, |
| 5717 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5718 | return; |
| 5719 | } |
[email protected] | 7472711 | 2012-06-13 21:18:08 | [diff] [blame] | 5720 | if (type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || |
| 5721 | type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5722 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5723 | state_.texture_units.size(), fake_location, count, value)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5724 | LOCAL_SET_GL_ERROR( |
| 5725 | GL_INVALID_VALUE, "glUniform1iv", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 5726 | return; |
| 5727 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5728 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5729 | glUniform1iv(real_location, count, value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5730 | } |
| 5731 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5732 | void GLES2DecoderImpl::DoUniform1fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5733 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5734 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5735 | GLint real_location = -1; |
| 5736 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5737 | fake_location, "glUniform1fv", valid_float_vec1_base_info, |
| 5738 | &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5739 | return; |
| 5740 | } |
| 5741 | if (type == GL_BOOL) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5742 | scoped_ptr<GLint[]> temp(new GLint[count]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5743 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5744 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5745 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5746 | DoUniform1iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5747 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5748 | glUniform1fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5749 | } |
| 5750 | } |
| 5751 | |
| 5752 | void GLES2DecoderImpl::DoUniform2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5753 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5754 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5755 | GLint real_location = -1; |
| 5756 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5757 | fake_location, "glUniform2fv", valid_float_vec2_base_info, |
| 5758 | &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5759 | return; |
| 5760 | } |
| 5761 | if (type == GL_BOOL_VEC2) { |
| 5762 | GLsizei num_values = count * 2; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5763 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5764 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5765 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5766 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5767 | glUniform2iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5768 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5769 | glUniform2fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5770 | } |
| 5771 | } |
| 5772 | |
| 5773 | void GLES2DecoderImpl::DoUniform3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5774 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5775 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5776 | GLint real_location = -1; |
| 5777 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5778 | fake_location, "glUniform3fv", valid_float_vec3_base_info, |
| 5779 | &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5780 | return; |
| 5781 | } |
| 5782 | if (type == GL_BOOL_VEC3) { |
| 5783 | GLsizei num_values = count * 3; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5784 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5785 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5786 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5787 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5788 | glUniform3iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5789 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5790 | glUniform3fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | void GLES2DecoderImpl::DoUniform4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5795 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5796 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5797 | GLint real_location = -1; |
| 5798 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5799 | fake_location, "glUniform4fv", valid_float_vec4_base_info, |
| 5800 | &real_location, &type, &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5801 | return; |
| 5802 | } |
| 5803 | if (type == GL_BOOL_VEC4) { |
| 5804 | GLsizei num_values = count * 4; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5805 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5806 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5807 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5808 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5809 | glUniform4iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5810 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5811 | glUniform4fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5812 | } |
| 5813 | } |
| 5814 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5815 | void GLES2DecoderImpl::DoUniform2iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5816 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5817 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5818 | GLint real_location = -1; |
| 5819 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5820 | fake_location, "glUniform2iv", valid_int_vec2_base_info, |
| 5821 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5822 | return; |
| 5823 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5824 | glUniform2iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5825 | } |
| 5826 | |
| 5827 | void GLES2DecoderImpl::DoUniform3iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5828 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5829 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5830 | GLint real_location = -1; |
| 5831 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5832 | fake_location, "glUniform3iv", valid_int_vec3_base_info, |
| 5833 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5834 | return; |
| 5835 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5836 | glUniform3iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5837 | } |
| 5838 | |
| 5839 | void GLES2DecoderImpl::DoUniform4iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5840 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5841 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5842 | GLint real_location = -1; |
| 5843 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5844 | fake_location, "glUniform4iv", valid_int_vec4_base_info, |
| 5845 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5846 | return; |
| 5847 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5848 | glUniform4iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5849 | } |
| 5850 | |
| 5851 | void GLES2DecoderImpl::DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5852 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 5853 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5854 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5855 | GLint real_location = -1; |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5856 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5857 | fake_location, "glUniformMatrix2fv", valid_float_mat2_base_info, |
| 5858 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5859 | return; |
| 5860 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5861 | glUniformMatrix2fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | void GLES2DecoderImpl::DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5865 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 5866 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5867 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5868 | GLint real_location = -1; |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5869 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5870 | fake_location, "glUniformMatrix3fv", valid_float_mat3_base_info, |
| 5871 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5872 | return; |
| 5873 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5874 | glUniformMatrix3fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5875 | } |
| 5876 | |
| 5877 | void GLES2DecoderImpl::DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5878 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 5879 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5880 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5881 | GLint real_location = -1; |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5882 | if (!PrepForSetUniformByLocation( |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5883 | fake_location, "glUniformMatrix4fv", valid_float_mat4_base_info, |
| 5884 | &real_location, &type, &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5885 | return; |
| 5886 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5887 | glUniformMatrix4fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5888 | } |
| 5889 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5890 | void GLES2DecoderImpl::DoUseProgram(GLuint program_id) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5891 | GLuint service_id = 0; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5892 | Program* program = NULL; |
| 5893 | if (program_id) { |
| 5894 | program = GetProgramInfoNotShader(program_id, "glUseProgram"); |
| 5895 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5896 | return; |
| 5897 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5898 | if (!program->IsValid()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5899 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5900 | LOCAL_SET_GL_ERROR( |
| 5901 | GL_INVALID_OPERATION, "glUseProgram", "program not linked"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5902 | return; |
| 5903 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5904 | service_id = program->service_id(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5905 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5906 | if (state_.current_program.get()) { |
| 5907 | program_manager()->UnuseProgram(shader_manager(), |
| 5908 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5909 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5910 | state_.current_program = program; |
| 5911 | LogClientServiceMapping("glUseProgram", program_id, service_id); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 5912 | glUseProgram(service_id); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5913 | if (state_.current_program.get()) { |
| 5914 | program_manager()->UseProgram(state_.current_program.get()); |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 5915 | if (workarounds().clear_uniforms_before_first_program_use) |
| 5916 | program_manager()->ClearUniforms(program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5917 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5918 | } |
| 5919 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5920 | void GLES2DecoderImpl::RenderWarning( |
| 5921 | const char* filename, int line, const std::string& msg) { |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 5922 | logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5923 | } |
| 5924 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5925 | void GLES2DecoderImpl::PerformanceWarning( |
| 5926 | const char* filename, int line, const std::string& msg) { |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5927 | logger_.LogMessage(filename, line, |
| 5928 | std::string("PERFORMANCE WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5929 | } |
| 5930 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5931 | void GLES2DecoderImpl::DoWillUseTexImageIfNeeded( |
| 5932 | Texture* texture, GLenum textarget) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5933 | // Image is already in use if texture is attached to a framebuffer. |
| 5934 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 5935 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 5936 | if (image) { |
| 5937 | ScopedGLErrorSuppressor suppressor( |
| 5938 | "GLES2DecoderImpl::DoWillUseTexImageIfNeeded", |
| 5939 | GetErrorState()); |
| 5940 | glBindTexture(textarget, texture->service_id()); |
| 5941 | image->WillUseTexImage(); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 5942 | RestoreCurrentTextureBindings(&state_, textarget); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5943 | } |
| 5944 | } |
| 5945 | } |
| 5946 | |
| 5947 | void GLES2DecoderImpl::DoDidUseTexImageIfNeeded( |
| 5948 | Texture* texture, GLenum textarget) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5949 | // Image is still in use if texture is attached to a framebuffer. |
| 5950 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 5951 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 5952 | if (image) { |
| 5953 | ScopedGLErrorSuppressor suppressor( |
| 5954 | "GLES2DecoderImpl::DoDidUseTexImageIfNeeded", |
| 5955 | GetErrorState()); |
| 5956 | glBindTexture(textarget, texture->service_id()); |
| 5957 | image->DidUseTexImage(); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 5958 | RestoreCurrentTextureBindings(&state_, textarget); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5959 | } |
| 5960 | } |
| 5961 | } |
| 5962 | |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 5963 | bool GLES2DecoderImpl::PrepareTexturesForRender() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5964 | DCHECK(state_.current_program.get()); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5965 | if (!texture_manager()->HaveUnrenderableTextures() && |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 5966 | !texture_manager()->HaveImages()) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 5967 | return true; |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5968 | } |
[email protected] | e2367b4 | 2013-05-31 03:37:21 | [diff] [blame] | 5969 | |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5970 | bool textures_set = false; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5971 | const Program::SamplerIndices& sampler_indices = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5972 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5973 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5974 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5975 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5976 | DCHECK(uniform_info); |
| 5977 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 5978 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5979 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5980 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5981 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 5982 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5983 | GLenum textarget = GetBindTargetForSamplerType(uniform_info->type); |
| 5984 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 5985 | textures_set = true; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5986 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 5987 | glBindTexture( |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5988 | textarget, |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 5989 | texture_manager()->black_texture_id(uniform_info->type)); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5990 | LOCAL_RENDER_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 5991 | std::string("texture bound to texture unit ") + |
| 5992 | base::IntToString(texture_unit_index) + |
[email protected] | ad9b7f8b | 2013-06-17 07:36:29 | [diff] [blame] | 5993 | " is not renderable. It maybe non-power-of-2 and have" |
| 5994 | " incompatible texture filtering or is not" |
| 5995 | " 'texture complete'"); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5996 | continue; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5997 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5998 | |
[email protected] | 4e7b8920 | 2014-01-28 01:44:06 | [diff] [blame] | 5999 | if (textarget != GL_TEXTURE_CUBE_MAP) { |
| 6000 | Texture* texture = texture_ref->texture(); |
| 6001 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6002 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 6003 | ScopedGLErrorSuppressor suppressor( |
| 6004 | "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); |
| 6005 | textures_set = true; |
| 6006 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6007 | image->WillUseTexImage(); |
| 6008 | continue; |
| 6009 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6010 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6011 | } |
| 6012 | // else: should this be an error? |
| 6013 | } |
| 6014 | } |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6015 | return !textures_set; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6016 | } |
| 6017 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6018 | void GLES2DecoderImpl::RestoreStateForTextures() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6019 | DCHECK(state_.current_program.get()); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6020 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6021 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6022 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6023 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6024 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6025 | DCHECK(uniform_info); |
| 6026 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6027 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6028 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6029 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6030 | TextureRef* texture_ref = |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6031 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6032 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6033 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6034 | // Get the texture_ref info that was previously bound here. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6035 | texture_ref = texture_unit.bind_target == GL_TEXTURE_2D |
| 6036 | ? texture_unit.bound_texture_2d.get() |
| 6037 | : texture_unit.bound_texture_cube_map.get(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6038 | glBindTexture(texture_unit.bind_target, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6039 | texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6040 | continue; |
| 6041 | } |
| 6042 | |
[email protected] | 4e7b8920 | 2014-01-28 01:44:06 | [diff] [blame] | 6043 | if (texture_unit.bind_target != GL_TEXTURE_CUBE_MAP) { |
| 6044 | Texture* texture = texture_ref->texture(); |
| 6045 | gfx::GLImage* image = |
| 6046 | texture->GetLevelImage(texture_unit.bind_target, 0); |
| 6047 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 6048 | ScopedGLErrorSuppressor suppressor( |
| 6049 | "GLES2DecoderImpl::RestoreStateForTextures", GetErrorState()); |
| 6050 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6051 | image->DidUseTexImage(); |
| 6052 | continue; |
| 6053 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6054 | } |
| 6055 | } |
| 6056 | } |
| 6057 | } |
| 6058 | // Set the active texture back to whatever the user had it as. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6059 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6060 | } |
| 6061 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6062 | bool GLES2DecoderImpl::ClearUnclearedTextures() { |
| 6063 | // Only check if there are some uncleared textures. |
| 6064 | if (!texture_manager()->HaveUnsafeTextures()) { |
| 6065 | return true; |
| 6066 | } |
| 6067 | |
| 6068 | // 1: Check all textures we are about to render with. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6069 | if (state_.current_program.get()) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6070 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6071 | state_.current_program->sampler_indices(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6072 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6073 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6074 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6075 | DCHECK(uniform_info); |
| 6076 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6077 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6078 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6079 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6080 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 6081 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6082 | if (texture_ref && !texture_ref->texture()->SafeToRenderFrom()) { |
| 6083 | if (!texture_manager()->ClearRenderableLevels(this, texture_ref)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6084 | return false; |
| 6085 | } |
| 6086 | } |
| 6087 | } |
| 6088 | } |
| 6089 | } |
| 6090 | } |
| 6091 | return true; |
| 6092 | } |
| 6093 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6094 | bool GLES2DecoderImpl::IsDrawValid( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6095 | const char* function_name, GLuint max_vertex_accessed, GLsizei primcount) { |
[email protected] | 689fa1c5 | 2010-06-09 18:35:03 | [diff] [blame] | 6096 | // NOTE: We specifically do not check current_program->IsValid() because |
| 6097 | // it could never be invalid since glUseProgram would have failed. While |
| 6098 | // glLinkProgram could later mark the program as invalid the previous |
| 6099 | // valid program will still function if it is still the current program. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6100 | if (!state_.current_program.get()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6101 | // The program does not exist. |
| 6102 | // But GL says no ERROR. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6103 | LOCAL_RENDER_WARNING("Drawing with no current shader program."); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6104 | return false; |
| 6105 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6106 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6107 | return state_.vertex_attrib_manager |
| 6108 | ->ValidateBindings(function_name, |
| 6109 | this, |
| 6110 | feature_info_.get(), |
| 6111 | state_.current_program.get(), |
| 6112 | max_vertex_accessed, |
| 6113 | primcount); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6114 | } |
| 6115 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6116 | bool GLES2DecoderImpl::SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6117 | const char* function_name, GLuint max_vertex_accessed, bool* simulated) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6118 | DCHECK(simulated); |
| 6119 | *simulated = false; |
| 6120 | |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6121 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6122 | return true; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6123 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6124 | const VertexAttrib* attrib = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6125 | state_.vertex_attrib_manager->GetVertexAttrib(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6126 | // 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] | 6127 | bool attrib_0_used = |
| 6128 | state_.current_program->GetAttribInfoByLocation(0) != NULL; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6129 | if (attrib->enabled() && attrib_0_used) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6130 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6131 | } |
| 6132 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6133 | // Make a buffer with a single repeated vec4 value enough to |
| 6134 | // simulate the constant value that is supposed to be here. |
| 6135 | // This is required to emulate GLES2 on GL. |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6136 | GLuint num_vertices = max_vertex_accessed + 1; |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6137 | uint32 size_needed = 0; |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6138 | |
| 6139 | if (num_vertices == 0 || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6140 | !SafeMultiplyUint32(num_vertices, sizeof(Vec4), &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6141 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6142 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6143 | return false; |
| 6144 | } |
| 6145 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6146 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6147 | "Attribute 0 is disabled. This has signficant performance penalty"); |
| 6148 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6149 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6150 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 6151 | |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 6152 | bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; |
| 6153 | if (new_buffer) { |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6154 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6155 | GLenum error = glGetError(); |
| 6156 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6157 | LOCAL_SET_GL_ERROR( |
| 6158 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6159 | return false; |
| 6160 | } |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6161 | } |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6162 | |
| 6163 | const Vec4& value = state_.attrib_values[0]; |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 6164 | if (new_buffer || |
| 6165 | (attrib_0_used && |
| 6166 | (!attrib_0_buffer_matches_value_ || |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6167 | (value.v[0] != attrib_0_value_.v[0] || |
| 6168 | value.v[1] != attrib_0_value_.v[1] || |
| 6169 | value.v[2] != attrib_0_value_.v[2] || |
| 6170 | value.v[3] != attrib_0_value_.v[3])))) { |
| 6171 | std::vector<Vec4> temp(num_vertices, value); |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6172 | glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); |
| 6173 | attrib_0_buffer_matches_value_ = true; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6174 | attrib_0_value_ = value; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6175 | attrib_0_size_ = size_needed; |
| 6176 | } |
| 6177 | |
| 6178 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 6179 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6180 | if (attrib->divisor()) |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6181 | glVertexAttribDivisorANGLE(0, 0); |
| 6182 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6183 | *simulated = true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6184 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6185 | } |
| 6186 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6187 | void GLES2DecoderImpl::RestoreStateForAttrib(GLuint attrib_index) { |
| 6188 | const VertexAttrib* attrib = |
| 6189 | state_.vertex_attrib_manager->GetVertexAttrib(attrib_index); |
| 6190 | const void* ptr = reinterpret_cast<const void*>(attrib->offset()); |
| 6191 | Buffer* buffer = attrib->buffer(); |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 6192 | glBindBuffer(GL_ARRAY_BUFFER, buffer ? buffer->service_id() : 0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6193 | glVertexAttribPointer( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6194 | attrib_index, attrib->size(), attrib->type(), attrib->normalized(), |
| 6195 | attrib->gl_stride(), ptr); |
| 6196 | if (attrib->divisor()) |
| 6197 | glVertexAttribDivisorANGLE(attrib_index, attrib->divisor()); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6198 | glBindBuffer( |
| 6199 | GL_ARRAY_BUFFER, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6200 | state_.bound_array_buffer.get() ? state_.bound_array_buffer->service_id() |
| 6201 | : 0); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6202 | |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6203 | // Never touch vertex attribute 0's state (in particular, never |
| 6204 | // disable it) when running on desktop GL because it will never be |
| 6205 | // re-enabled. |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6206 | if (attrib_index != 0 || |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6207 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6208 | if (attrib->enabled()) { |
| 6209 | glEnableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6210 | } else { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6211 | glDisableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6212 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6213 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6214 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6215 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6216 | bool GLES2DecoderImpl::SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6217 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6218 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6219 | DCHECK(simulated); |
| 6220 | *simulated = false; |
| 6221 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
| 6222 | return true; |
| 6223 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6224 | if (!state_.vertex_attrib_manager->HaveFixedAttribs()) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6225 | return true; |
| 6226 | } |
| 6227 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6228 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6229 | "GL_FIXED attributes have a signficant performance penalty"); |
| 6230 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6231 | // NOTE: we could be smart and try to check if a buffer is used |
| 6232 | // twice in 2 different attribs, find the overlapping parts and therefore |
| 6233 | // duplicate the minimum amount of data but this whole code path is not meant |
| 6234 | // to be used normally. It's just here to pass that OpenGL ES 2.0 conformance |
| 6235 | // tests so we just add to the buffer attrib used. |
| 6236 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6237 | GLuint elements_needed = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6238 | const VertexAttribManager::VertexAttribList& enabled_attribs = |
| 6239 | state_.vertex_attrib_manager->GetEnabledVertexAttribs(); |
| 6240 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 6241 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 6242 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6243 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6244 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 6245 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
| 6246 | max_vertex_accessed); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6247 | GLuint num_vertices = max_accessed + 1; |
| 6248 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6249 | LOCAL_SET_GL_ERROR( |
| 6250 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6251 | return false; |
| 6252 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6253 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6254 | attrib->CanAccess(max_accessed) && |
| 6255 | attrib->type() == GL_FIXED) { |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6256 | uint32 elements_used = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6257 | if (!SafeMultiplyUint32(num_vertices, attrib->size(), &elements_used) || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6258 | !SafeAddUint32(elements_needed, elements_used, &elements_needed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6259 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6260 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6261 | return false; |
| 6262 | } |
| 6263 | } |
| 6264 | } |
| 6265 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6266 | const uint32 kSizeOfFloat = sizeof(float); // NOLINT |
| 6267 | uint32 size_needed = 0; |
| 6268 | if (!SafeMultiplyUint32(elements_needed, kSizeOfFloat, &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6269 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6270 | LOCAL_SET_GL_ERROR( |
| 6271 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6272 | return false; |
| 6273 | } |
| 6274 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6275 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6276 | |
| 6277 | glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6278 | if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6279 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6280 | GLenum error = glGetError(); |
| 6281 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6282 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6283 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6284 | return false; |
| 6285 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6286 | } |
| 6287 | |
| 6288 | // Copy the elements and convert to float |
| 6289 | GLintptr offset = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6290 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 6291 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 6292 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6293 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6294 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 6295 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6296 | max_vertex_accessed); |
| 6297 | GLuint num_vertices = max_accessed + 1; |
| 6298 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6299 | LOCAL_SET_GL_ERROR( |
| 6300 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6301 | return false; |
| 6302 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6303 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6304 | attrib->CanAccess(max_accessed) && |
| 6305 | attrib->type() == GL_FIXED) { |
| 6306 | int num_elements = attrib->size() * kSizeOfFloat; |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6307 | int size = num_elements * num_vertices; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6308 | scoped_ptr<float[]> data(new float[size]); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6309 | const int32* src = reinterpret_cast<const int32 *>( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6310 | attrib->buffer()->GetRange(attrib->offset(), size)); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6311 | const int32* end = src + num_elements; |
| 6312 | float* dst = data.get(); |
| 6313 | while (src != end) { |
| 6314 | *dst++ = static_cast<float>(*src++) / 65536.0f; |
| 6315 | } |
| 6316 | glBufferSubData(GL_ARRAY_BUFFER, offset, size, data.get()); |
| 6317 | glVertexAttribPointer( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6318 | attrib->index(), attrib->size(), GL_FLOAT, false, 0, |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6319 | reinterpret_cast<GLvoid*>(offset)); |
| 6320 | offset += size; |
| 6321 | } |
| 6322 | } |
| 6323 | *simulated = true; |
| 6324 | return true; |
| 6325 | } |
| 6326 | |
| 6327 | void GLES2DecoderImpl::RestoreStateForSimulatedFixedAttribs() { |
| 6328 | // There's no need to call glVertexAttribPointer because we shadow all the |
| 6329 | // settings and passing GL_FIXED to it will not work. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6330 | glBindBuffer( |
| 6331 | GL_ARRAY_BUFFER, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6332 | state_.bound_array_buffer.get() ? state_.bound_array_buffer->service_id() |
| 6333 | : 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6334 | } |
| 6335 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6336 | error::Error GLES2DecoderImpl::DoDrawArrays( |
| 6337 | const char* function_name, |
| 6338 | bool instanced, |
| 6339 | GLenum mode, |
| 6340 | GLint first, |
| 6341 | GLsizei count, |
| 6342 | GLsizei primcount) { |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 6343 | error::Error error = WillAccessBoundFramebufferForDraw(); |
| 6344 | if (error != error::kNoError) |
| 6345 | return error; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6346 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6347 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6348 | return error::kNoError; |
| 6349 | } |
| 6350 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6351 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6352 | return error::kNoError; |
| 6353 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6354 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6355 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6356 | return error::kNoError; |
| 6357 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6358 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6359 | return error::kNoError; |
| 6360 | } |
| 6361 | // We have to check this here because the prototype for glDrawArrays |
| 6362 | // is GLint not GLsizei. |
| 6363 | if (first < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6364 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "first < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6365 | return error::kNoError; |
| 6366 | } |
| 6367 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6368 | if (count == 0 || (instanced && primcount == 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6369 | LOCAL_RENDER_WARNING("Render count or primcount is 0."); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6370 | return error::kNoError; |
| 6371 | } |
| 6372 | |
| 6373 | GLuint max_vertex_accessed = first + count - 1; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6374 | if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6375 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6376 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6377 | return error::kNoError; |
| 6378 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6379 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6380 | if (!SimulateAttrib0( |
| 6381 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6382 | return error::kNoError; |
| 6383 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6384 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6385 | if (SimulateFixedAttribs( |
| 6386 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 6387 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6388 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6389 | ApplyDirtyState(); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6390 | if (!instanced) { |
| 6391 | glDrawArrays(mode, first, count); |
| 6392 | } else { |
| 6393 | glDrawArraysInstancedANGLE(mode, first, count, primcount); |
| 6394 | } |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 6395 | ProcessPendingQueries(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6396 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6397 | RestoreStateForTextures(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6398 | } |
| 6399 | if (simulated_fixed_attribs) { |
| 6400 | RestoreStateForSimulatedFixedAttribs(); |
| 6401 | } |
| 6402 | } |
| 6403 | if (simulated_attrib_0) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6404 | RestoreStateForAttrib(0); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6405 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6406 | } |
| 6407 | return error::kNoError; |
| 6408 | } |
| 6409 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6410 | error::Error GLES2DecoderImpl::HandleDrawArrays( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6411 | uint32 immediate_data_size, const cmds::DrawArrays& c) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6412 | return DoDrawArrays("glDrawArrays", |
| 6413 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6414 | static_cast<GLenum>(c.mode), |
| 6415 | static_cast<GLint>(c.first), |
| 6416 | static_cast<GLsizei>(c.count), |
| 6417 | 0); |
| 6418 | } |
| 6419 | |
| 6420 | error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6421 | uint32 immediate_data_size, const cmds::DrawArraysInstancedANGLE& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6422 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6423 | LOCAL_SET_GL_ERROR( |
| 6424 | GL_INVALID_OPERATION, |
| 6425 | "glDrawArraysInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6426 | return error::kNoError; |
| 6427 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6428 | return DoDrawArrays("glDrawArraysIntancedANGLE", |
| 6429 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6430 | static_cast<GLenum>(c.mode), |
| 6431 | static_cast<GLint>(c.first), |
| 6432 | static_cast<GLsizei>(c.count), |
| 6433 | static_cast<GLsizei>(c.primcount)); |
| 6434 | } |
| 6435 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6436 | error::Error GLES2DecoderImpl::DoDrawElements( |
| 6437 | const char* function_name, |
| 6438 | bool instanced, |
| 6439 | GLenum mode, |
| 6440 | GLsizei count, |
| 6441 | GLenum type, |
| 6442 | int32 offset, |
| 6443 | GLsizei primcount) { |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 6444 | error::Error error = WillAccessBoundFramebufferForDraw(); |
| 6445 | if (error != error::kNoError) |
| 6446 | return error; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6447 | if (!state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6448 | LOCAL_SET_GL_ERROR( |
| 6449 | GL_INVALID_OPERATION, function_name, "No element array buffer bound"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6450 | return error::kNoError; |
| 6451 | } |
| 6452 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6453 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6454 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6455 | return error::kNoError; |
| 6456 | } |
| 6457 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6458 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6459 | return error::kNoError; |
| 6460 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6461 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6462 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6463 | return error::kNoError; |
| 6464 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6465 | if (!validators_->index_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6466 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6467 | return error::kNoError; |
| 6468 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6469 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6470 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6471 | return error::kNoError; |
| 6472 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6473 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6474 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 6475 | return error::kNoError; |
| 6476 | } |
| 6477 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6478 | if (count == 0 || (instanced && primcount == 0)) { |
[email protected] | 6c788fb7 | 2010-08-26 02:16:31 | [diff] [blame] | 6479 | return error::kNoError; |
| 6480 | } |
| 6481 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6482 | GLuint max_vertex_accessed; |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6483 | Buffer* element_array_buffer = |
| 6484 | state_.vertex_attrib_manager->element_array_buffer(); |
| 6485 | |
| 6486 | if (!element_array_buffer->GetMaxValueForRange( |
| 6487 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6488 | LOCAL_SET_GL_ERROR( |
| 6489 | GL_INVALID_OPERATION, function_name, "range out of bounds for buffer"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6490 | return error::kNoError; |
| 6491 | } |
| 6492 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6493 | if (IsDrawValid(function_name, max_vertex_accessed, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6494 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6495 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6496 | return error::kNoError; |
| 6497 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6498 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6499 | if (!SimulateAttrib0( |
| 6500 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6501 | return error::kNoError; |
| 6502 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6503 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6504 | if (SimulateFixedAttribs( |
| 6505 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 6506 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6507 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 6508 | ApplyDirtyState(); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6509 | // TODO(gman): Refactor to hide these details in BufferManager or |
| 6510 | // VertexAttribManager. |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6511 | const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6512 | bool used_client_side_array = false; |
| 6513 | if (element_array_buffer->IsClientSideArray()) { |
| 6514 | used_client_side_array = true; |
| 6515 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 6516 | indices = element_array_buffer->GetRange(offset, 0); |
| 6517 | } |
| 6518 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6519 | if (!instanced) { |
| 6520 | glDrawElements(mode, count, type, indices); |
| 6521 | } else { |
| 6522 | glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); |
| 6523 | } |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6524 | |
| 6525 | if (used_client_side_array) { |
| 6526 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 6527 | element_array_buffer->service_id()); |
| 6528 | } |
| 6529 | |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 6530 | ProcessPendingQueries(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6531 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6532 | RestoreStateForTextures(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6533 | } |
| 6534 | if (simulated_fixed_attribs) { |
| 6535 | RestoreStateForSimulatedFixedAttribs(); |
| 6536 | } |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6537 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6538 | if (simulated_attrib_0) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6539 | RestoreStateForAttrib(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6540 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6541 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6542 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6543 | } |
| 6544 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6545 | error::Error GLES2DecoderImpl::HandleDrawElements( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6546 | uint32 immediate_data_size, const cmds::DrawElements& c) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6547 | return DoDrawElements("glDrawElements", |
| 6548 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6549 | static_cast<GLenum>(c.mode), |
| 6550 | static_cast<GLsizei>(c.count), |
| 6551 | static_cast<GLenum>(c.type), |
| 6552 | static_cast<int32>(c.index_offset), |
| 6553 | 0); |
| 6554 | } |
| 6555 | |
| 6556 | error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6557 | uint32 immediate_data_size, const cmds::DrawElementsInstancedANGLE& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6558 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6559 | LOCAL_SET_GL_ERROR( |
| 6560 | GL_INVALID_OPERATION, |
| 6561 | "glDrawElementsInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6562 | return error::kNoError; |
| 6563 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6564 | return DoDrawElements("glDrawElementsInstancedANGLE", |
| 6565 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6566 | static_cast<GLenum>(c.mode), |
| 6567 | static_cast<GLsizei>(c.count), |
| 6568 | static_cast<GLenum>(c.type), |
| 6569 | static_cast<int32>(c.index_offset), |
| 6570 | static_cast<GLsizei>(c.primcount)); |
| 6571 | } |
| 6572 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 6573 | GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 6574 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { |
| 6575 | GLuint max_vertex_accessed = 0; |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 6576 | Buffer* buffer = GetBuffer(buffer_id); |
| 6577 | if (!buffer) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6578 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6579 | LOCAL_SET_GL_ERROR( |
| 6580 | GL_INVALID_VALUE, "GetMaxValueInBufferCHROMIUM", "unknown buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 6581 | } else { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 6582 | if (!buffer->GetMaxValueForRange( |
| 6583 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6584 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6585 | LOCAL_SET_GL_ERROR( |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 6586 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6587 | "GetMaxValueInBufferCHROMIUM", "range out of bounds for buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 6588 | } |
| 6589 | } |
| 6590 | return max_vertex_accessed; |
| 6591 | } |
| 6592 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6593 | // Calls glShaderSource for the various versions of the ShaderSource command. |
| 6594 | // Assumes that data / data_size points to a piece of memory that is in range |
| 6595 | // of whatever context it came from (shared memory, immediate memory, bucket |
| 6596 | // memory.) |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6597 | error::Error GLES2DecoderImpl::ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6598 | GLuint client_id, const char* data, uint32 data_size) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 6599 | std::string str(data, data + data_size); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6600 | Shader* shader = GetShaderInfoNotProgram(client_id, "glShaderSource"); |
| 6601 | if (!shader) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6602 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6603 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6604 | // Note: We don't actually call glShaderSource here. We wait until |
| 6605 | // the call to glCompileShader. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6606 | shader->UpdateSource(str.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6607 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6608 | } |
| 6609 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6610 | error::Error GLES2DecoderImpl::HandleShaderSource( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6611 | uint32 immediate_data_size, const cmds::ShaderSource& c) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6612 | uint32 data_size = c.data_size; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6613 | const char* data = GetSharedMemoryAs<const char*>( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6614 | c.data_shm_id, c.data_shm_offset, data_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6615 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6616 | return error::kOutOfBounds; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6617 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6618 | return ShaderSourceHelper(c.shader, data, data_size); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6619 | } |
| 6620 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6621 | error::Error GLES2DecoderImpl::HandleShaderSourceBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6622 | uint32 immediate_data_size, const cmds::ShaderSourceBucket& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6623 | Bucket* bucket = GetBucket(c.data_bucket_id); |
| 6624 | if (!bucket || bucket->size() == 0) { |
| 6625 | return error::kInvalidArguments; |
| 6626 | } |
| 6627 | return ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6628 | c.shader, bucket->GetDataAs<const char*>(0, bucket->size() - 1), |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6629 | bucket->size() - 1); |
| 6630 | } |
| 6631 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6632 | void GLES2DecoderImpl::DoCompileShader(GLuint client_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 6633 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompileShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6634 | Shader* shader = GetShaderInfoNotProgram(client_id, "glCompileShader"); |
| 6635 | if (!shader) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6636 | return; |
| 6637 | } |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 6638 | ShaderTranslator* translator = NULL; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 6639 | if (use_shader_translator_) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6640 | translator = shader->shader_type() == GL_VERTEX_SHADER ? |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 6641 | vertex_translator_.get() : fragment_translator_.get(); |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 6642 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 6643 | |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 6644 | program_manager()->DoCompileShader( |
| 6645 | shader, |
| 6646 | translator, |
| 6647 | feature_info_->feature_flags().angle_translated_shader_source ? |
| 6648 | ProgramManager::kANGLE : ProgramManager::kGL); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6649 | }; |
| 6650 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6651 | void GLES2DecoderImpl::DoGetShaderiv( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6652 | GLuint shader_id, GLenum pname, GLint* params) { |
| 6653 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderiv"); |
| 6654 | if (!shader) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6655 | return; |
| 6656 | } |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6657 | switch (pname) { |
| 6658 | case GL_SHADER_SOURCE_LENGTH: |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6659 | *params = shader->source() ? shader->source()->size() + 1 : 0; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6660 | return; |
| 6661 | case GL_COMPILE_STATUS: |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6662 | *params = compile_shader_always_succeeds_ ? true : shader->IsValid(); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 6663 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6664 | case GL_INFO_LOG_LENGTH: |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6665 | *params = shader->log_info() ? shader->log_info()->size() + 1 : 0; |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 6666 | return; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6667 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6668 | *params = shader->translated_source() ? |
| 6669 | shader->translated_source()->size() + 1 : 0; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6670 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6671 | default: |
| 6672 | break; |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6673 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6674 | glGetShaderiv(shader->service_id(), pname, params); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6675 | } |
| 6676 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6677 | error::Error GLES2DecoderImpl::HandleGetShaderSource( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6678 | uint32 immediate_data_size, const cmds::GetShaderSource& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6679 | GLuint shader_id = c.shader; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6680 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6681 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6682 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderSource"); |
| 6683 | if (!shader || !shader->source()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6684 | bucket->SetSize(0); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6685 | return error::kNoError; |
| 6686 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6687 | bucket->SetFromString(shader->source()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6688 | return error::kNoError; |
| 6689 | } |
| 6690 | |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6691 | error::Error GLES2DecoderImpl::HandleGetTranslatedShaderSourceANGLE( |
| 6692 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6693 | const cmds::GetTranslatedShaderSourceANGLE& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6694 | GLuint shader_id = c.shader; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6695 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6696 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6697 | Shader* shader = GetShaderInfoNotProgram( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 6698 | shader_id, "glGetTranslatedShaderSourceANGLE"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6699 | if (!shader) { |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6700 | bucket->SetSize(0); |
| 6701 | return error::kNoError; |
| 6702 | } |
| 6703 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6704 | bucket->SetFromString(shader->translated_source() ? |
| 6705 | shader->translated_source()->c_str() : NULL); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6706 | return error::kNoError; |
| 6707 | } |
| 6708 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6709 | error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6710 | uint32 immediate_data_size, const cmds::GetProgramInfoLog& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6711 | GLuint program_id = c.program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6712 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6713 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6714 | Program* program = GetProgramInfoNotShader( |
| 6715 | program_id, "glGetProgramInfoLog"); |
| 6716 | if (!program || !program->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 6717 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6718 | return error::kNoError; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6719 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6720 | bucket->SetFromString(program->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6721 | return error::kNoError; |
| 6722 | } |
| 6723 | |
| 6724 | error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6725 | uint32 immediate_data_size, const cmds::GetShaderInfoLog& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6726 | GLuint shader_id = c.shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6727 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6728 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6729 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderInfoLog"); |
| 6730 | if (!shader || !shader->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 6731 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6732 | return error::kNoError; |
| 6733 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6734 | bucket->SetFromString(shader->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6735 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6736 | } |
| 6737 | |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 6738 | bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) { |
| 6739 | return state_.GetEnabled(cap); |
| 6740 | } |
| 6741 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6742 | bool GLES2DecoderImpl::DoIsBuffer(GLuint client_id) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 6743 | const Buffer* buffer = GetBuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6744 | return buffer && buffer->IsValid() && !buffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6745 | } |
| 6746 | |
| 6747 | bool GLES2DecoderImpl::DoIsFramebuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6748 | const Framebuffer* framebuffer = |
| 6749 | GetFramebuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6750 | return framebuffer && framebuffer->IsValid() && !framebuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6751 | } |
| 6752 | |
| 6753 | bool GLES2DecoderImpl::DoIsProgram(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 6754 | // IsProgram is true for programs as soon as they are created, until they are |
| 6755 | // deleted and no longer in use. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6756 | const Program* program = GetProgram(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6757 | return program != NULL && !program->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6758 | } |
| 6759 | |
| 6760 | bool GLES2DecoderImpl::DoIsRenderbuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6761 | const Renderbuffer* renderbuffer = |
| 6762 | GetRenderbuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6763 | return renderbuffer && renderbuffer->IsValid() && !renderbuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6764 | } |
| 6765 | |
| 6766 | bool GLES2DecoderImpl::DoIsShader(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 6767 | // IsShader is true for shaders as soon as they are created, until they |
| 6768 | // are deleted and not attached to any programs. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6769 | const Shader* shader = GetShader(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6770 | return shader != NULL && !shader->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6771 | } |
| 6772 | |
| 6773 | bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6774 | const TextureRef* texture_ref = GetTexture(client_id); |
| 6775 | return texture_ref && texture_ref->texture()->IsValid(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6776 | } |
| 6777 | |
| 6778 | void GLES2DecoderImpl::DoAttachShader( |
| 6779 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6780 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6781 | program_client_id, "glAttachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6782 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6783 | return; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6784 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6785 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glAttachShader"); |
| 6786 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6787 | return; |
| 6788 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6789 | if (!program->AttachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6790 | LOCAL_SET_GL_ERROR( |
| 6791 | GL_INVALID_OPERATION, |
| 6792 | "glAttachShader", |
| 6793 | "can not attach more than one shader of the same type."); |
[email protected] | fb96c8e | 2010-08-12 04:10:31 | [diff] [blame] | 6794 | return; |
| 6795 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6796 | glAttachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6797 | } |
| 6798 | |
| 6799 | void GLES2DecoderImpl::DoDetachShader( |
| 6800 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6801 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6802 | program_client_id, "glDetachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6803 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6804 | return; |
| 6805 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6806 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glDetachShader"); |
| 6807 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6808 | return; |
| 6809 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6810 | if (!program->DetachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6811 | LOCAL_SET_GL_ERROR( |
| 6812 | GL_INVALID_OPERATION, |
| 6813 | "glDetachShader", "shader not attached to program"); |
[email protected] | 9a0ccd4 | 2011-03-16 23:58:22 | [diff] [blame] | 6814 | return; |
| 6815 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6816 | glDetachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6817 | } |
| 6818 | |
| 6819 | void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6820 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6821 | program_client_id, "glValidateProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6822 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6823 | return; |
| 6824 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6825 | program->Validate(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6826 | } |
| 6827 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6828 | void GLES2DecoderImpl::GetVertexAttribHelper( |
| 6829 | const VertexAttrib* attrib, GLenum pname, GLint* params) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6830 | switch (pname) { |
| 6831 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6832 | Buffer* buffer = attrib->buffer(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6833 | if (buffer && !buffer->IsDeleted()) { |
| 6834 | GLuint client_id; |
| 6835 | buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
| 6836 | *params = client_id; |
| 6837 | } |
| 6838 | break; |
| 6839 | } |
| 6840 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6841 | *params = attrib->enabled(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6842 | break; |
| 6843 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6844 | *params = attrib->size(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6845 | break; |
| 6846 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6847 | *params = attrib->gl_stride(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6848 | break; |
| 6849 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6850 | *params = attrib->type(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6851 | break; |
| 6852 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6853 | *params = attrib->normalized(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6854 | break; |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6855 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6856 | *params = attrib->divisor(); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6857 | break; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6858 | default: |
| 6859 | NOTREACHED(); |
| 6860 | break; |
| 6861 | } |
| 6862 | } |
| 6863 | |
| 6864 | void GLES2DecoderImpl::DoGetVertexAttribfv( |
| 6865 | GLuint index, GLenum pname, GLfloat* params) { |
| 6866 | VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| 6867 | if (!attrib) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6868 | LOCAL_SET_GL_ERROR( |
| 6869 | GL_INVALID_VALUE, "glGetVertexAttribfv", "index out of range"); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6870 | return; |
| 6871 | } |
| 6872 | switch (pname) { |
| 6873 | case GL_CURRENT_VERTEX_ATTRIB: { |
| 6874 | const Vec4& value = state_.attrib_values[index]; |
| 6875 | params[0] = value.v[0]; |
| 6876 | params[1] = value.v[1]; |
| 6877 | params[2] = value.v[2]; |
| 6878 | params[3] = value.v[3]; |
| 6879 | break; |
| 6880 | } |
| 6881 | default: { |
| 6882 | GLint value = 0; |
| 6883 | GetVertexAttribHelper(attrib, pname, &value); |
| 6884 | *params = static_cast<GLfloat>(value); |
| 6885 | break; |
| 6886 | } |
| 6887 | } |
| 6888 | } |
| 6889 | |
| 6890 | void GLES2DecoderImpl::DoGetVertexAttribiv( |
| 6891 | GLuint index, GLenum pname, GLint* params) { |
| 6892 | VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| 6893 | if (!attrib) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6894 | LOCAL_SET_GL_ERROR( |
| 6895 | GL_INVALID_VALUE, "glGetVertexAttribiv", "index out of range"); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6896 | return; |
| 6897 | } |
| 6898 | switch (pname) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6899 | case GL_CURRENT_VERTEX_ATTRIB: { |
| 6900 | const Vec4& value = state_.attrib_values[index]; |
| 6901 | params[0] = static_cast<GLint>(value.v[0]); |
| 6902 | params[1] = static_cast<GLint>(value.v[1]); |
| 6903 | params[2] = static_cast<GLint>(value.v[2]); |
| 6904 | params[3] = static_cast<GLint>(value.v[3]); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6905 | break; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6906 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6907 | default: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6908 | GetVertexAttribHelper(attrib, pname, params); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6909 | break; |
| 6910 | } |
| 6911 | } |
| 6912 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6913 | bool GLES2DecoderImpl::SetVertexAttribValue( |
| 6914 | const char* function_name, GLuint index, const GLfloat* value) { |
| 6915 | if (index >= state_.attrib_values.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6916 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "index out of range"); |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6917 | return false; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6918 | } |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6919 | Vec4& v = state_.attrib_values[index]; |
| 6920 | v.v[0] = value[0]; |
| 6921 | v.v[1] = value[1]; |
| 6922 | v.v[2] = value[2]; |
| 6923 | v.v[3] = value[3]; |
| 6924 | return true; |
| 6925 | } |
| 6926 | |
| 6927 | void GLES2DecoderImpl::DoVertexAttrib1f(GLuint index, GLfloat v0) { |
| 6928 | GLfloat v[4] = { v0, 0.0f, 0.0f, 1.0f, }; |
| 6929 | if (SetVertexAttribValue("glVertexAttrib1f", index, v)) { |
| 6930 | glVertexAttrib1f(index, v0); |
| 6931 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6932 | } |
| 6933 | |
| 6934 | void GLES2DecoderImpl::DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6935 | GLfloat v[4] = { v0, v1, 0.0f, 1.0f, }; |
| 6936 | if (SetVertexAttribValue("glVertexAttrib2f", index, v)) { |
| 6937 | glVertexAttrib2f(index, v0, v1); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6938 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6939 | } |
| 6940 | |
| 6941 | void GLES2DecoderImpl::DoVertexAttrib3f( |
| 6942 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6943 | GLfloat v[4] = { v0, v1, v2, 1.0f, }; |
| 6944 | if (SetVertexAttribValue("glVertexAttrib3f", index, v)) { |
| 6945 | glVertexAttrib3f(index, v0, v1, v2); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6946 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6947 | } |
| 6948 | |
| 6949 | void GLES2DecoderImpl::DoVertexAttrib4f( |
| 6950 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6951 | GLfloat v[4] = { v0, v1, v2, v3, }; |
| 6952 | if (SetVertexAttribValue("glVertexAttrib4f", index, v)) { |
| 6953 | glVertexAttrib4f(index, v0, v1, v2, v3); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6954 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6955 | } |
| 6956 | |
| 6957 | void GLES2DecoderImpl::DoVertexAttrib1fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6958 | GLfloat t[4] = { v[0], 0.0f, 0.0f, 1.0f, }; |
| 6959 | if (SetVertexAttribValue("glVertexAttrib1fv", index, t)) { |
| 6960 | glVertexAttrib1fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6961 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6962 | } |
| 6963 | |
| 6964 | void GLES2DecoderImpl::DoVertexAttrib2fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6965 | GLfloat t[4] = { v[0], v[1], 0.0f, 1.0f, }; |
| 6966 | if (SetVertexAttribValue("glVertexAttrib2fv", index, t)) { |
| 6967 | glVertexAttrib2fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6968 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6969 | } |
| 6970 | |
| 6971 | void GLES2DecoderImpl::DoVertexAttrib3fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6972 | GLfloat t[4] = { v[0], v[1], v[2], 1.0f, }; |
| 6973 | if (SetVertexAttribValue("glVertexAttrib3fv", index, t)) { |
| 6974 | glVertexAttrib3fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6975 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6976 | } |
| 6977 | |
| 6978 | void GLES2DecoderImpl::DoVertexAttrib4fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6979 | if (SetVertexAttribValue("glVertexAttrib4fv", index, v)) { |
| 6980 | glVertexAttrib4fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6981 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6982 | } |
| 6983 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6984 | error::Error GLES2DecoderImpl::HandleVertexAttribPointer( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6985 | uint32 immediate_data_size, const cmds::VertexAttribPointer& c) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 6986 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6987 | if (!state_.bound_array_buffer.get() || |
| 6988 | state_.bound_array_buffer->IsDeleted()) { |
| 6989 | if (state_.vertex_attrib_manager.get() == |
| 6990 | default_vertex_attrib_manager_.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6991 | LOCAL_SET_GL_ERROR( |
| 6992 | GL_INVALID_VALUE, "glVertexAttribPointer", "no array buffer bound"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 6993 | return error::kNoError; |
| 6994 | } else if (c.offset != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6995 | LOCAL_SET_GL_ERROR( |
| 6996 | GL_INVALID_VALUE, |
| 6997 | "glVertexAttribPointer", "client side arrays are not allowed"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 6998 | return error::kNoError; |
| 6999 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7000 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7001 | |
| 7002 | GLuint indx = c.indx; |
| 7003 | GLint size = c.size; |
| 7004 | GLenum type = c.type; |
| 7005 | GLboolean normalized = c.normalized; |
| 7006 | GLsizei stride = c.stride; |
| 7007 | GLsizei offset = c.offset; |
| 7008 | const void* ptr = reinterpret_cast<const void*>(offset); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7009 | if (!validators_->vertex_attrib_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7010 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glVertexAttribPointer", type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7011 | return error::kNoError; |
| 7012 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7013 | if (!validators_->vertex_attrib_size.IsValid(size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7014 | LOCAL_SET_GL_ERROR( |
| 7015 | GL_INVALID_VALUE, "glVertexAttribPointer", "size GL_INVALID_VALUE"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7016 | return error::kNoError; |
| 7017 | } |
| 7018 | if (indx >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7019 | LOCAL_SET_GL_ERROR( |
| 7020 | GL_INVALID_VALUE, "glVertexAttribPointer", "index out of range"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7021 | return error::kNoError; |
| 7022 | } |
| 7023 | if (stride < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7024 | LOCAL_SET_GL_ERROR( |
| 7025 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7026 | return error::kNoError; |
| 7027 | } |
| 7028 | if (stride > 255) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7029 | LOCAL_SET_GL_ERROR( |
| 7030 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride > 255"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7031 | return error::kNoError; |
| 7032 | } |
| 7033 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7034 | LOCAL_SET_GL_ERROR( |
| 7035 | GL_INVALID_VALUE, "glVertexAttribPointer", "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7036 | return error::kNoError; |
| 7037 | } |
| 7038 | GLsizei component_size = |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 7039 | GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7040 | if (offset % component_size > 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7041 | LOCAL_SET_GL_ERROR( |
| 7042 | GL_INVALID_OPERATION, |
| 7043 | "glVertexAttribPointer", "offset not valid for type"); |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 7044 | return error::kNoError; |
| 7045 | } |
| 7046 | if (stride % component_size > 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7047 | LOCAL_SET_GL_ERROR( |
| 7048 | GL_INVALID_OPERATION, |
| 7049 | "glVertexAttribPointer", "stride not valid for type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7050 | return error::kNoError; |
| 7051 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 7052 | state_.vertex_attrib_manager |
| 7053 | ->SetAttribInfo(indx, |
| 7054 | state_.bound_array_buffer.get(), |
| 7055 | size, |
| 7056 | type, |
| 7057 | normalized, |
| 7058 | stride, |
| 7059 | stride != 0 ? stride : component_size * size, |
| 7060 | offset); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7061 | if (type != GL_FIXED) { |
| 7062 | glVertexAttribPointer(indx, size, type, normalized, stride, ptr); |
| 7063 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7064 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7065 | } |
| 7066 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 7067 | void GLES2DecoderImpl::DoViewport(GLint x, GLint y, GLsizei width, |
| 7068 | GLsizei height) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7069 | state_.viewport_x = x; |
| 7070 | state_.viewport_y = y; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 7071 | state_.viewport_width = std::min(width, viewport_max_width_); |
| 7072 | state_.viewport_height = std::min(height, viewport_max_height_); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 7073 | glViewport(x, y, width, height); |
| 7074 | } |
| 7075 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7076 | error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7077 | uint32 immediate_data_size, const cmds::VertexAttribDivisorANGLE& c) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 7078 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7079 | LOCAL_SET_GL_ERROR( |
| 7080 | GL_INVALID_OPERATION, |
| 7081 | "glVertexAttribDivisorANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7082 | } |
| 7083 | GLuint index = c.index; |
| 7084 | GLuint divisor = c.divisor; |
| 7085 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7086 | LOCAL_SET_GL_ERROR( |
| 7087 | GL_INVALID_VALUE, |
| 7088 | "glVertexAttribDivisorANGLE", "index out of range"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7089 | return error::kNoError; |
| 7090 | } |
| 7091 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7092 | state_.vertex_attrib_manager->SetDivisor( |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7093 | index, |
| 7094 | divisor); |
| 7095 | glVertexAttribDivisorANGLE(index, divisor); |
| 7096 | return error::kNoError; |
| 7097 | } |
| 7098 | |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7099 | template <typename pixel_data_type> |
| 7100 | static void WriteAlphaData( |
| 7101 | void *pixels, uint32 row_count, uint32 channel_count, |
| 7102 | uint32 alpha_channel_index, uint32 unpadded_row_size, |
| 7103 | uint32 padded_row_size, pixel_data_type alpha_value) { |
| 7104 | DCHECK_GT(channel_count, 0U); |
| 7105 | DCHECK_EQ(unpadded_row_size % sizeof(pixel_data_type), 0U); |
| 7106 | uint32 unpadded_row_size_in_elements = |
| 7107 | unpadded_row_size / sizeof(pixel_data_type); |
| 7108 | DCHECK_EQ(padded_row_size % sizeof(pixel_data_type), 0U); |
| 7109 | uint32 padded_row_size_in_elements = |
| 7110 | padded_row_size / sizeof(pixel_data_type); |
| 7111 | pixel_data_type* dst = |
| 7112 | static_cast<pixel_data_type*>(pixels) + alpha_channel_index; |
| 7113 | for (uint32 yy = 0; yy < row_count; ++yy) { |
| 7114 | pixel_data_type* end = dst + unpadded_row_size_in_elements; |
| 7115 | for (pixel_data_type* d = dst; d < end; d += channel_count) { |
| 7116 | *d = alpha_value; |
| 7117 | } |
| 7118 | dst += padded_row_size_in_elements; |
| 7119 | } |
| 7120 | } |
| 7121 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7122 | void GLES2DecoderImpl::FinishReadPixels( |
| 7123 | const cmds::ReadPixels& c, |
| 7124 | GLuint buffer) { |
| 7125 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::FinishReadPixels"); |
| 7126 | GLsizei width = c.width; |
| 7127 | GLsizei height = c.height; |
| 7128 | GLenum format = c.format; |
| 7129 | GLenum type = c.type; |
| 7130 | typedef cmds::ReadPixels::Result Result; |
| 7131 | uint32 pixels_size; |
| 7132 | Result* result = NULL; |
| 7133 | if (c.result_shm_id != 0) { |
| 7134 | result = GetSharedMemoryAs<Result*>( |
| 7135 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7136 | if (!result) { |
| 7137 | if (buffer != 0) { |
| 7138 | glDeleteBuffersARB(1, &buffer); |
| 7139 | } |
| 7140 | return; |
| 7141 | } |
| 7142 | } |
| 7143 | GLES2Util::ComputeImageDataSizes( |
| 7144 | width, height, format, type, state_.pack_alignment, &pixels_size, |
| 7145 | NULL, NULL); |
| 7146 | void* pixels = GetSharedMemoryAs<void*>( |
| 7147 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| 7148 | if (!pixels) { |
| 7149 | if (buffer != 0) { |
| 7150 | glDeleteBuffersARB(1, &buffer); |
| 7151 | } |
| 7152 | return; |
| 7153 | } |
| 7154 | |
| 7155 | if (buffer != 0) { |
| 7156 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
[email protected] | e585f9e2 | 2013-08-27 02:50:33 | [diff] [blame] | 7157 | void* data; |
| 7158 | if (features().map_buffer_range) { |
| 7159 | data = glMapBufferRange( |
| 7160 | GL_PIXEL_PACK_BUFFER_ARB, 0, pixels_size, GL_MAP_READ_BIT); |
| 7161 | } else { |
| 7162 | data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); |
| 7163 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7164 | memcpy(pixels, data, pixels_size); |
| 7165 | // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't |
| 7166 | // have to restore the state. |
| 7167 | glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); |
| 7168 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7169 | glDeleteBuffersARB(1, &buffer); |
| 7170 | } |
| 7171 | |
| 7172 | if (result != NULL) { |
| 7173 | *result = true; |
| 7174 | } |
| 7175 | |
| 7176 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 7177 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 7178 | if ((channels_exist & 0x0008) == 0 && |
| 7179 | workarounds().clear_alpha_in_readpixels) { |
| 7180 | // Set the alpha to 255 because some drivers are buggy in this regard. |
| 7181 | uint32 temp_size; |
| 7182 | |
| 7183 | uint32 unpadded_row_size; |
| 7184 | uint32 padded_row_size; |
| 7185 | if (!GLES2Util::ComputeImageDataSizes( |
| 7186 | width, 2, format, type, state_.pack_alignment, &temp_size, |
| 7187 | &unpadded_row_size, &padded_row_size)) { |
| 7188 | return; |
| 7189 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7190 | |
| 7191 | uint32 channel_count = 0; |
| 7192 | uint32 alpha_channel = 0; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7193 | switch (format) { |
| 7194 | case GL_RGBA: |
| 7195 | case GL_BGRA_EXT: |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7196 | channel_count = 4; |
| 7197 | alpha_channel = 3; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7198 | break; |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7199 | case GL_ALPHA: |
| 7200 | channel_count = 1; |
| 7201 | alpha_channel = 0; |
| 7202 | break; |
| 7203 | } |
| 7204 | |
| 7205 | if (channel_count > 0) { |
| 7206 | switch (type) { |
| 7207 | case GL_UNSIGNED_BYTE: |
| 7208 | WriteAlphaData<uint8>( |
| 7209 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 7210 | padded_row_size, 0xFF); |
| 7211 | break; |
| 7212 | case GL_FLOAT: |
| 7213 | WriteAlphaData<float>( |
| 7214 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 7215 | padded_row_size, 1.0f); |
| 7216 | break; |
| 7217 | case GL_HALF_FLOAT: |
| 7218 | WriteAlphaData<uint16>( |
| 7219 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 7220 | padded_row_size, 0x3C00); |
| 7221 | break; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7222 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7223 | } |
| 7224 | } |
| 7225 | } |
| 7226 | |
| 7227 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7228 | error::Error GLES2DecoderImpl::HandleReadPixels( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7229 | uint32 immediate_data_size, const cmds::ReadPixels& c) { |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 7230 | error::Error fbo_error = WillAccessBoundFramebufferForRead(); |
| 7231 | if (fbo_error != error::kNoError) |
| 7232 | return fbo_error; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7233 | GLint x = c.x; |
| 7234 | GLint y = c.y; |
| 7235 | GLsizei width = c.width; |
| 7236 | GLsizei height = c.height; |
| 7237 | GLenum format = c.format; |
| 7238 | GLenum type = c.type; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7239 | GLboolean async = c.async; |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7240 | if (width < 0 || height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7241 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7242 | return error::kNoError; |
| 7243 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7244 | typedef cmds::ReadPixels::Result Result; |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7245 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7246 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7247 | width, height, format, type, state_.pack_alignment, &pixels_size, |
| 7248 | NULL, NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7249 | return error::kOutOfBounds; |
| 7250 | } |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7251 | void* pixels = GetSharedMemoryAs<void*>( |
| 7252 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7253 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7254 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7255 | } |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7256 | Result* result = NULL; |
| 7257 | if (c.result_shm_id != 0) { |
| 7258 | result = GetSharedMemoryAs<Result*>( |
| 7259 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7260 | if (!result) { |
| 7261 | return error::kOutOfBounds; |
| 7262 | } |
| 7263 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7264 | |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7265 | if (!validators_->read_pixel_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7266 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", format, "format"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7267 | return error::kNoError; |
| 7268 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7269 | if (!validators_->read_pixel_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7270 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", type, "type"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 7271 | return error::kNoError; |
| 7272 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7273 | if ((format != GL_RGBA && format != GL_BGRA_EXT && format != GL_RGB && |
| 7274 | format != GL_ALPHA) || type != GL_UNSIGNED_BYTE) { |
| 7275 | // format and type are acceptable enums but not guaranteed to be supported |
| 7276 | // for this framebuffer. Have to ask gl if they are valid. |
| 7277 | GLint preferred_format = 0; |
| 7278 | DoGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &preferred_format); |
| 7279 | GLint preferred_type = 0; |
| 7280 | DoGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &preferred_type); |
| 7281 | if (format != static_cast<GLenum>(preferred_format) || |
| 7282 | type != static_cast<GLenum>(preferred_type)) { |
| 7283 | LOCAL_SET_GL_ERROR( |
| 7284 | GL_INVALID_OPERATION, "glReadPixels", "format and type incompatible " |
| 7285 | "with the current read framebuffer"); |
| 7286 | return error::kNoError; |
| 7287 | } |
| 7288 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7289 | if (width == 0 || height == 0) { |
| 7290 | return error::kNoError; |
| 7291 | } |
| 7292 | |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7293 | // Get the size of the current fbo or backbuffer. |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 7294 | gfx::Size max_size = GetBoundReadFrameBufferSize(); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7295 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 7296 | int32 max_x; |
| 7297 | int32 max_y; |
| 7298 | if (!SafeAddInt32(x, width, &max_x) || !SafeAddInt32(y, height, &max_y)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7299 | LOCAL_SET_GL_ERROR( |
| 7300 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7301 | return error::kNoError; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7302 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7303 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7304 | if (!CheckBoundFramebuffersValid("glReadPixels")) { |
| 7305 | return error::kNoError; |
| 7306 | } |
| 7307 | |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7308 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7309 | |
| 7310 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 7311 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7312 | 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] | 7313 | // The user requested an out of range area. Get the results 1 line |
| 7314 | // at a time. |
| 7315 | uint32 temp_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7316 | uint32 unpadded_row_size; |
| 7317 | uint32 padded_row_size; |
| 7318 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7319 | width, 2, format, type, state_.pack_alignment, &temp_size, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7320 | &unpadded_row_size, &padded_row_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7321 | LOCAL_SET_GL_ERROR( |
| 7322 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7323 | return error::kNoError; |
| 7324 | } |
| 7325 | |
| 7326 | GLint dest_x_offset = std::max(-x, 0); |
| 7327 | uint32 dest_row_offset; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7328 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7329 | dest_x_offset, 1, format, type, state_.pack_alignment, &dest_row_offset, |
| 7330 | NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7331 | LOCAL_SET_GL_ERROR( |
| 7332 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7333 | return error::kNoError; |
| 7334 | } |
| 7335 | |
| 7336 | // Copy each row into the larger dest rect. |
| 7337 | int8* dst = static_cast<int8*>(pixels); |
| 7338 | GLint read_x = std::max(0, x); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7339 | 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] | 7340 | GLint read_width = read_end_x - read_x; |
| 7341 | for (GLint yy = 0; yy < height; ++yy) { |
| 7342 | GLint ry = y + yy; |
| 7343 | |
| 7344 | // Clear the row. |
| 7345 | memset(dst, 0, unpadded_row_size); |
| 7346 | |
| 7347 | // If the row is in range, copy it. |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7348 | if (ry >= 0 && ry < max_size.height() && read_width > 0) { |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7349 | glReadPixels( |
| 7350 | read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
| 7351 | } |
| 7352 | dst += padded_row_size; |
| 7353 | } |
| 7354 | } else { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7355 | if (async && features().use_async_readpixels) { |
| 7356 | GLuint buffer; |
| 7357 | glGenBuffersARB(1, &buffer); |
| 7358 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
| 7359 | glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, GL_STREAM_READ); |
| 7360 | GLenum error = glGetError(); |
| 7361 | if (error == GL_NO_ERROR) { |
| 7362 | glReadPixels(x, y, width, height, format, type, 0); |
| 7363 | pending_readpixel_fences_.push(linked_ptr<FenceCallback>( |
| 7364 | new FenceCallback())); |
| 7365 | WaitForReadPixels(base::Bind( |
| 7366 | &GLES2DecoderImpl::FinishReadPixels, |
| 7367 | base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 7368 | <GLES2DecoderImpl>(this), |
| 7369 | c, buffer)); |
| 7370 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7371 | return error::kNoError; |
| 7372 | } |
| 7373 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7374 | glReadPixels(x, y, width, height, format, type, pixels); |
| 7375 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7376 | GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7377 | if (error == GL_NO_ERROR) { |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7378 | if (result != NULL) { |
| 7379 | *result = true; |
| 7380 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7381 | FinishReadPixels(c, 0); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7382 | } |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 7383 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7384 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7385 | } |
| 7386 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7387 | error::Error GLES2DecoderImpl::HandlePixelStorei( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7388 | uint32 immediate_data_size, const cmds::PixelStorei& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7389 | GLenum pname = c.pname; |
| 7390 | GLenum param = c.param; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7391 | if (!validators_->pixel_store.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7392 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glPixelStorei", pname, "pname"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 7393 | return error::kNoError; |
| 7394 | } |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7395 | switch (pname) { |
| 7396 | case GL_PACK_ALIGNMENT: |
| 7397 | case GL_UNPACK_ALIGNMENT: |
| 7398 | if (!validators_->pixel_store_alignment.IsValid(param)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7399 | LOCAL_SET_GL_ERROR( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7400 | GL_INVALID_VALUE, "glPixelStorei", "param GL_INVALID_VALUE"); |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7401 | return error::kNoError; |
| 7402 | } |
[email protected] | 164d6d5 | 2012-05-05 00:55:03 | [diff] [blame] | 7403 | break; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 7404 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 7405 | unpack_flip_y_ = (param != 0); |
| 7406 | return error::kNoError; |
| 7407 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 7408 | unpack_premultiply_alpha_ = (param != 0); |
| 7409 | return error::kNoError; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 7410 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 7411 | unpack_unpremultiply_alpha_ = (param != 0); |
| 7412 | return error::kNoError; |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7413 | default: |
| 7414 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7415 | } |
| 7416 | glPixelStorei(pname, param); |
| 7417 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7418 | case GL_PACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7419 | state_.pack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7420 | break; |
| 7421 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 7422 | state_.pack_reverse_row_order = (param != 0); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7423 | break; |
| 7424 | case GL_UNPACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7425 | state_.unpack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7426 | break; |
| 7427 | default: |
| 7428 | // Validation should have prevented us from getting here. |
| 7429 | NOTREACHED(); |
| 7430 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7431 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7432 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7433 | } |
| 7434 | |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7435 | error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7436 | uint32 immediate_data_size, const cmds::PostSubBufferCHROMIUM& c) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 7437 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandlePostSubBufferCHROMIUM"); |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 7438 | if (!surface_->HasExtension("GL_CHROMIUM_post_sub_buffer")) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7439 | LOCAL_SET_GL_ERROR( |
| 7440 | GL_INVALID_OPERATION, |
| 7441 | "glPostSubBufferCHROMIUM", "command not supported by surface"); |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7442 | return error::kNoError; |
| 7443 | } |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 7444 | bool is_tracing; |
| 7445 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 7446 | &is_tracing); |
| 7447 | if (is_tracing) { |
| 7448 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 7449 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 7450 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 7451 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 7452 | } |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 7453 | if (surface_->PostSubBuffer(c.x, c.y, c.width, c.height)) { |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7454 | return error::kNoError; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 7455 | } else { |
| 7456 | LOG(ERROR) << "Context lost because PostSubBuffer failed."; |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7457 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 7458 | } |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7459 | } |
| 7460 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7461 | error::Error GLES2DecoderImpl::GetAttribLocationHelper( |
| 7462 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 7463 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7464 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7465 | LOCAL_SET_GL_ERROR( |
| 7466 | GL_INVALID_VALUE, "glGetAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7467 | return error::kNoError; |
| 7468 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7469 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7470 | client_id, "glGetAttribLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7471 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7472 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7473 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7474 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7475 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7476 | GL_INVALID_OPERATION, "glGetAttribLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7477 | return error::kNoError; |
| 7478 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7479 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7480 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 7481 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7482 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7483 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7484 | // Require the client to init this incase the context is lost and we are no |
| 7485 | // longer executing commands. |
| 7486 | if (*location != -1) { |
| 7487 | return error::kGenericError; |
| 7488 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7489 | *location = program->GetAttribLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7490 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7491 | } |
| 7492 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7493 | error::Error GLES2DecoderImpl::HandleGetAttribLocation( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7494 | uint32 immediate_data_size, const cmds::GetAttribLocation& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7495 | uint32 name_size = c.data_size; |
| 7496 | const char* name = GetSharedMemoryAs<const char*>( |
| 7497 | c.name_shm_id, c.name_shm_offset, name_size); |
| 7498 | if (!name) { |
| 7499 | return error::kOutOfBounds; |
| 7500 | } |
| 7501 | String name_str(name, name_size); |
| 7502 | return GetAttribLocationHelper( |
| 7503 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 7504 | } |
| 7505 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7506 | error::Error GLES2DecoderImpl::HandleGetAttribLocationBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7507 | uint32 immediate_data_size, const cmds::GetAttribLocationBucket& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7508 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 7509 | if (!bucket) { |
| 7510 | return error::kInvalidArguments; |
| 7511 | } |
| 7512 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7513 | if (!bucket->GetAsString(&name_str)) { |
| 7514 | return error::kInvalidArguments; |
| 7515 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7516 | return GetAttribLocationHelper( |
| 7517 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 7518 | } |
| 7519 | |
| 7520 | error::Error GLES2DecoderImpl::GetUniformLocationHelper( |
| 7521 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 7522 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7523 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7524 | LOCAL_SET_GL_ERROR( |
| 7525 | GL_INVALID_VALUE, "glGetUniformLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7526 | return error::kNoError; |
| 7527 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7528 | Program* program = GetProgramInfoNotShader( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7529 | client_id, "glGetUniformLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7530 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7531 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7532 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7533 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7534 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7535 | GL_INVALID_OPERATION, "glGetUniformLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7536 | return error::kNoError; |
| 7537 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7538 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7539 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 7540 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7541 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7542 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7543 | // Require the client to init this incase the context is lost an we are no |
| 7544 | // longer executing commands. |
| 7545 | if (*location != -1) { |
| 7546 | return error::kGenericError; |
| 7547 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7548 | *location = program->GetUniformFakeLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7549 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7550 | } |
| 7551 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7552 | error::Error GLES2DecoderImpl::HandleGetUniformLocation( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7553 | uint32 immediate_data_size, const cmds::GetUniformLocation& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7554 | uint32 name_size = c.data_size; |
| 7555 | const char* name = GetSharedMemoryAs<const char*>( |
| 7556 | c.name_shm_id, c.name_shm_offset, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7557 | if (!name) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7558 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7559 | } |
| 7560 | String name_str(name, name_size); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7561 | return GetUniformLocationHelper( |
| 7562 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7563 | } |
| 7564 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7565 | error::Error GLES2DecoderImpl::HandleGetUniformLocationBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7566 | uint32 immediate_data_size, const cmds::GetUniformLocationBucket& c) { |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7567 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 7568 | if (!bucket) { |
| 7569 | return error::kInvalidArguments; |
| 7570 | } |
| 7571 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7572 | if (!bucket->GetAsString(&name_str)) { |
| 7573 | return error::kInvalidArguments; |
| 7574 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7575 | return GetUniformLocationHelper( |
| 7576 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7577 | } |
| 7578 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7579 | error::Error GLES2DecoderImpl::HandleGetString( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7580 | uint32 immediate_data_size, const cmds::GetString& c) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7581 | GLenum name = static_cast<GLenum>(c.name); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7582 | if (!validators_->string_type.IsValid(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7583 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glGetString", name, "name"); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7584 | return error::kNoError; |
| 7585 | } |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 7586 | const char* str = reinterpret_cast<const char*>(glGetString(name)); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7587 | std::string extensions; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7588 | switch (name) { |
| 7589 | case GL_VERSION: |
| 7590 | str = "OpenGL ES 2.0 Chromium"; |
| 7591 | break; |
| 7592 | case GL_SHADING_LANGUAGE_VERSION: |
| 7593 | str = "OpenGL ES GLSL ES 1.0 Chromium"; |
| 7594 | break; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 7595 | case GL_RENDERER: |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 7596 | case GL_VENDOR: |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 7597 | // Return the unmasked VENDOR/RENDERER string for WebGL contexts. |
| 7598 | // They are used by WEBGL_debug_renderer_info. |
| 7599 | if (!force_webgl_glsl_validation_) |
| 7600 | str = "Chromium"; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 7601 | break; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7602 | case GL_EXTENSIONS: |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7603 | { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7604 | // For WebGL contexts, strip out the OES derivatives and |
| 7605 | // EXT frag depth extensions if they have not been enabled. |
| 7606 | if (force_webgl_glsl_validation_) { |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7607 | extensions = feature_info_->extensions(); |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7608 | if (!derivatives_explicitly_enabled_) { |
| 7609 | size_t offset = extensions.find(kOESDerivativeExtension); |
| 7610 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 7611 | extensions.replace(offset, arraysize(kOESDerivativeExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7612 | std::string()); |
| 7613 | } |
| 7614 | } |
| 7615 | if (!frag_depth_explicitly_enabled_) { |
| 7616 | size_t offset = extensions.find(kEXTFragDepthExtension); |
| 7617 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 7618 | extensions.replace(offset, arraysize(kEXTFragDepthExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7619 | std::string()); |
| 7620 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7621 | } |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 7622 | if (!draw_buffers_explicitly_enabled_) { |
| 7623 | size_t offset = extensions.find(kEXTDrawBuffersExtension); |
| 7624 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 7625 | extensions.replace(offset, arraysize(kEXTDrawBuffersExtension), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 7626 | std::string()); |
| 7627 | } |
| 7628 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7629 | } else { |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 7630 | extensions = feature_info_->extensions().c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7631 | } |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 7632 | std::string surface_extensions = surface_->GetExtensions(); |
| 7633 | if (!surface_extensions.empty()) |
| 7634 | extensions += " " + surface_extensions; |
| 7635 | str = extensions.c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7636 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7637 | break; |
| 7638 | default: |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7639 | break; |
| 7640 | } |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7641 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7642 | bucket->SetFromString(str); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7643 | return error::kNoError; |
| 7644 | } |
| 7645 | |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 7646 | error::Error GLES2DecoderImpl::HandleBufferData( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7647 | uint32 immediate_data_size, const cmds::BufferData& c) { |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 7648 | GLenum target = static_cast<GLenum>(c.target); |
| 7649 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
| 7650 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 7651 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 7652 | GLenum usage = static_cast<GLenum>(c.usage); |
| 7653 | const void* data = NULL; |
| 7654 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 7655 | data = GetSharedMemoryAs<const void*>(data_shm_id, data_shm_offset, size); |
| 7656 | if (!data) { |
| 7657 | return error::kOutOfBounds; |
| 7658 | } |
| 7659 | } |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 7660 | buffer_manager()->ValidateAndDoBufferData(&state_, target, size, data, usage); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7661 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7662 | } |
| 7663 | |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 7664 | void GLES2DecoderImpl::DoBufferSubData( |
| 7665 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 7666 | // Just delegate it. Some validation is actually done before this. |
| 7667 | buffer_manager()->ValidateAndDoBufferSubData( |
| 7668 | &state_, target, offset, size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7669 | } |
| 7670 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7671 | bool GLES2DecoderImpl::ClearLevel( |
| 7672 | unsigned service_id, |
| 7673 | unsigned bind_target, |
| 7674 | unsigned target, |
| 7675 | int level, |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 7676 | unsigned internal_format, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7677 | unsigned format, |
| 7678 | unsigned type, |
| 7679 | int width, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7680 | int height, |
| 7681 | bool is_texture_immutable) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7682 | uint32 channels = GLES2Util::GetChannelsForFormat(format); |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 7683 | if (feature_info_->feature_flags().angle_depth_texture && |
| 7684 | (channels & GLES2Util::kDepth) != 0) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7685 | // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D |
| 7686 | // on depth formats. |
| 7687 | GLuint fb = 0; |
| 7688 | glGenFramebuffersEXT(1, &fb); |
| 7689 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); |
| 7690 | |
| 7691 | bool have_stencil = (channels & GLES2Util::kStencil) != 0; |
| 7692 | GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : |
| 7693 | GL_DEPTH_ATTACHMENT; |
| 7694 | |
| 7695 | glFramebufferTexture2DEXT( |
| 7696 | GL_DRAW_FRAMEBUFFER_EXT, attachment, target, service_id, level); |
| 7697 | // ANGLE promises a depth only attachment ok. |
| 7698 | if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != |
| 7699 | GL_FRAMEBUFFER_COMPLETE) { |
| 7700 | return false; |
| 7701 | } |
| 7702 | glClearStencil(0); |
| 7703 | glStencilMask(-1); |
| 7704 | glClearDepth(1.0f); |
| 7705 | glDepthMask(true); |
| 7706 | glDisable(GL_SCISSOR_TEST); |
| 7707 | glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); |
| 7708 | |
| 7709 | RestoreClearState(); |
| 7710 | |
| 7711 | glDeleteFramebuffersEXT(1, &fb); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7712 | Framebuffer* framebuffer = |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7713 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 7714 | GLuint fb_service_id = |
| 7715 | framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); |
| 7716 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); |
| 7717 | return true; |
| 7718 | } |
| 7719 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7720 | static const uint32 kMaxZeroSize = 1024 * 1024 * 4; |
| 7721 | |
| 7722 | uint32 size; |
| 7723 | uint32 padded_row_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7724 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7725 | width, height, format, type, state_.unpack_alignment, &size, |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7726 | NULL, &padded_row_size)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7727 | return false; |
| 7728 | } |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7729 | |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 7730 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearLevel", "size", size); |
| 7731 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7732 | int tile_height; |
| 7733 | |
| 7734 | if (size > kMaxZeroSize) { |
| 7735 | if (kMaxZeroSize < padded_row_size) { |
| 7736 | // That'd be an awfully large texture. |
| 7737 | return false; |
| 7738 | } |
| 7739 | // We should never have a large total size with a zero row size. |
| 7740 | DCHECK_GT(padded_row_size, 0U); |
| 7741 | tile_height = kMaxZeroSize / padded_row_size; |
| 7742 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7743 | width, tile_height, format, type, state_.unpack_alignment, &size, |
| 7744 | NULL, NULL)) { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7745 | return false; |
| 7746 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7747 | } else { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7748 | tile_height = height; |
| 7749 | } |
| 7750 | |
| 7751 | // Assumes the size has already been checked. |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 7752 | scoped_ptr<char[]> zero(new char[size]); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7753 | memset(zero.get(), 0, size); |
| 7754 | glBindTexture(bind_target, service_id); |
| 7755 | |
| 7756 | GLint y = 0; |
| 7757 | while (y < height) { |
| 7758 | GLint h = y + tile_height > height ? height - y : tile_height; |
| 7759 | if (is_texture_immutable || h != height) { |
| 7760 | glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); |
| 7761 | } else { |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 7762 | glTexImage2D( |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 7763 | target, level, internal_format, width, h, 0, format, type, |
| 7764 | zero.get()); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 7765 | } |
| 7766 | y += tile_height; |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7767 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7768 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 7769 | &state_, bind_target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 7770 | glBindTexture(bind_target, texture ? texture->service_id() : 0); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7771 | return true; |
| 7772 | } |
| 7773 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7774 | namespace { |
| 7775 | |
| 7776 | const int kS3TCBlockWidth = 4; |
| 7777 | const int kS3TCBlockHeight = 4; |
| 7778 | const int kS3TCDXT1BlockSize = 8; |
| 7779 | const int kS3TCDXT3AndDXT5BlockSize = 16; |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7780 | const int kETC1BlockWidth = 4; |
| 7781 | const int kETC1BlockHeight = 4; |
| 7782 | const int kETC1BlockSize = 8; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7783 | |
| 7784 | bool IsValidDXTSize(GLint level, GLsizei size) { |
[email protected] | 10b56de | 2012-07-14 02:09:51 | [diff] [blame] | 7785 | return (size == 1) || |
| 7786 | (size == 2) || !(size % kS3TCBlockWidth); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7787 | } |
| 7788 | |
| 7789 | } // anonymous namespace. |
| 7790 | |
| 7791 | bool GLES2DecoderImpl::ValidateCompressedTexFuncData( |
| 7792 | const char* function_name, |
| 7793 | GLsizei width, GLsizei height, GLenum format, size_t size) { |
| 7794 | unsigned int bytes_required = 0; |
| 7795 | |
| 7796 | switch (format) { |
| 7797 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 7798 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: { |
| 7799 | int num_blocks_across = |
| 7800 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 7801 | int num_blocks_down = |
| 7802 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 7803 | int num_blocks = num_blocks_across * num_blocks_down; |
| 7804 | bytes_required = num_blocks * kS3TCDXT1BlockSize; |
| 7805 | break; |
| 7806 | } |
| 7807 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 7808 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 7809 | int num_blocks_across = |
| 7810 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 7811 | int num_blocks_down = |
| 7812 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 7813 | int num_blocks = num_blocks_across * num_blocks_down; |
| 7814 | bytes_required = num_blocks * kS3TCDXT3AndDXT5BlockSize; |
| 7815 | break; |
| 7816 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7817 | case GL_ETC1_RGB8_OES: { |
| 7818 | int num_blocks_across = |
| 7819 | (width + kETC1BlockWidth - 1) / kETC1BlockWidth; |
| 7820 | int num_blocks_down = |
| 7821 | (height + kETC1BlockHeight - 1) / kETC1BlockHeight; |
| 7822 | int num_blocks = num_blocks_across * num_blocks_down; |
| 7823 | bytes_required = num_blocks * kETC1BlockSize; |
| 7824 | break; |
| 7825 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7826 | default: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7827 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7828 | return false; |
| 7829 | } |
| 7830 | |
| 7831 | if (size != bytes_required) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7832 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7833 | GL_INVALID_VALUE, function_name, "size is not correct for dimensions"); |
| 7834 | return false; |
| 7835 | } |
| 7836 | |
| 7837 | return true; |
| 7838 | } |
| 7839 | |
| 7840 | bool GLES2DecoderImpl::ValidateCompressedTexDimensions( |
| 7841 | const char* function_name, |
| 7842 | GLint level, GLsizei width, GLsizei height, GLenum format) { |
| 7843 | switch (format) { |
| 7844 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 7845 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 7846 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 7847 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 7848 | if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7849 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7850 | GL_INVALID_OPERATION, function_name, |
| 7851 | "width or height invalid for level"); |
| 7852 | return false; |
| 7853 | } |
| 7854 | return true; |
| 7855 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7856 | case GL_ETC1_RGB8_OES: |
| 7857 | if (width <= 0 || height <= 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7858 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7859 | GL_INVALID_OPERATION, function_name, |
| 7860 | "width or height invalid for level"); |
| 7861 | return false; |
| 7862 | } |
| 7863 | return true; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7864 | default: |
| 7865 | return false; |
| 7866 | } |
| 7867 | } |
| 7868 | |
| 7869 | bool GLES2DecoderImpl::ValidateCompressedTexSubDimensions( |
| 7870 | const char* function_name, |
| 7871 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 7872 | GLsizei width, GLsizei height, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7873 | Texture* texture) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7874 | if (xoffset < 0 || yoffset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7875 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7876 | GL_INVALID_VALUE, function_name, "xoffset or yoffset < 0"); |
| 7877 | return false; |
| 7878 | } |
| 7879 | |
| 7880 | switch (format) { |
| 7881 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 7882 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 7883 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 7884 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 7885 | const int kBlockWidth = 4; |
| 7886 | const int kBlockHeight = 4; |
| 7887 | if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7888 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7889 | GL_INVALID_OPERATION, function_name, |
| 7890 | "xoffset or yoffset not multiple of 4"); |
| 7891 | return false; |
| 7892 | } |
| 7893 | GLsizei tex_width = 0; |
| 7894 | GLsizei tex_height = 0; |
| 7895 | if (!texture->GetLevelSize(target, level, &tex_width, &tex_height) || |
| 7896 | width - xoffset > tex_width || |
| 7897 | height - yoffset > tex_height) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7898 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7899 | GL_INVALID_OPERATION, function_name, "dimensions out of range"); |
| 7900 | return false; |
| 7901 | } |
| 7902 | return ValidateCompressedTexDimensions( |
| 7903 | function_name, level, width, height, format); |
| 7904 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7905 | case GL_ETC1_RGB8_OES: { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7906 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7907 | GL_INVALID_OPERATION, function_name, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7908 | "not supported for ECT1_RGB8_OES textures"); |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 7909 | return false; |
| 7910 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7911 | default: |
| 7912 | return false; |
| 7913 | } |
| 7914 | } |
| 7915 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7916 | error::Error GLES2DecoderImpl::DoCompressedTexImage2D( |
| 7917 | GLenum target, |
| 7918 | GLint level, |
| 7919 | GLenum internal_format, |
| 7920 | GLsizei width, |
| 7921 | GLsizei height, |
| 7922 | GLint border, |
| 7923 | GLsizei image_size, |
| 7924 | const void* data) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7925 | // TODO(gman): Validate image_size is correct for width, height and format. |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7926 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7927 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 7928 | "glCompressedTexImage2D", target, "target"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7929 | return error::kNoError; |
| 7930 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7931 | if (!validators_->compressed_texture_format.IsValid( |
| 7932 | internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7933 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 7934 | "glCompressedTexImage2D", internal_format, "internal_format"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7935 | return error::kNoError; |
| 7936 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 7937 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7938 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7939 | LOCAL_SET_GL_ERROR( |
| 7940 | GL_INVALID_VALUE, |
| 7941 | "glCompressedTexImage2D", "dimensions out of range"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7942 | return error::kNoError; |
| 7943 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7944 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 7945 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7946 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7947 | LOCAL_SET_GL_ERROR( |
| 7948 | GL_INVALID_VALUE, |
| 7949 | "glCompressedTexImage2D", "unknown texture target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7950 | return error::kNoError; |
| 7951 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7952 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 7953 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7954 | LOCAL_SET_GL_ERROR( |
| 7955 | GL_INVALID_OPERATION, |
| 7956 | "glCompressedTexImage2D", "texture is immutable"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7957 | return error::kNoError; |
| 7958 | } |
| 7959 | |
| 7960 | if (!ValidateCompressedTexDimensions( |
| 7961 | "glCompressedTexImage2D", level, width, height, internal_format) || |
| 7962 | !ValidateCompressedTexFuncData( |
| 7963 | "glCompressedTexImage2D", width, height, internal_format, image_size)) { |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 7964 | return error::kNoError; |
| 7965 | } |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 7966 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 7967 | if (!EnsureGPUMemoryAvailable(image_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7968 | LOCAL_SET_GL_ERROR( |
| 7969 | GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 7970 | return error::kNoError; |
| 7971 | } |
| 7972 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 7973 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 7974 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 7975 | } |
| 7976 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 7977 | scoped_ptr<int8[]> zero; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7978 | if (!data) { |
| 7979 | zero.reset(new int8[image_size]); |
| 7980 | memset(zero.get(), 0, image_size); |
| 7981 | data = zero.get(); |
| 7982 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7983 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7984 | glCompressedTexImage2D( |
| 7985 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7986 | GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7987 | if (error == GL_NO_ERROR) { |
| 7988 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7989 | texture_ref, target, level, internal_format, |
| 7990 | width, height, 1, border, 0, 0, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 7991 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 7992 | return error::kNoError; |
| 7993 | } |
| 7994 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7995 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7996 | uint32 immediate_data_size, const cmds::CompressedTexImage2D& c) { |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7997 | GLenum target = static_cast<GLenum>(c.target); |
| 7998 | GLint level = static_cast<GLint>(c.level); |
| 7999 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 8000 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8001 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8002 | GLint border = static_cast<GLint>(c.border); |
| 8003 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
| 8004 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 8005 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 8006 | const void* data = NULL; |
| 8007 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 8008 | data = GetSharedMemoryAs<const void*>( |
| 8009 | data_shm_id, data_shm_offset, image_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 8010 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8011 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8012 | } |
| 8013 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8014 | return DoCompressedTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8015 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8016 | } |
| 8017 | |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8018 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2DBucket( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8019 | uint32 immediate_data_size, const cmds::CompressedTexImage2DBucket& c) { |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8020 | GLenum target = static_cast<GLenum>(c.target); |
| 8021 | GLint level = static_cast<GLint>(c.level); |
| 8022 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 8023 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8024 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8025 | GLint border = static_cast<GLint>(c.border); |
| 8026 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8027 | if (!bucket) { |
| 8028 | return error::kInvalidArguments; |
| 8029 | } |
| 8030 | uint32 data_size = bucket->size(); |
| 8031 | GLsizei imageSize = data_size; |
| 8032 | const void* data = bucket->GetData(0, data_size); |
| 8033 | if (!data) { |
| 8034 | return error::kInvalidArguments; |
| 8035 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8036 | return DoCompressedTexImage2D( |
| 8037 | target, level, internal_format, width, height, border, |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8038 | imageSize, data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8039 | } |
| 8040 | |
| 8041 | error::Error GLES2DecoderImpl::HandleCompressedTexSubImage2DBucket( |
| 8042 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8043 | const cmds::CompressedTexSubImage2DBucket& c) { |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8044 | GLenum target = static_cast<GLenum>(c.target); |
| 8045 | GLint level = static_cast<GLint>(c.level); |
| 8046 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 8047 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 8048 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8049 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8050 | GLenum format = static_cast<GLenum>(c.format); |
| 8051 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8052 | if (!bucket) { |
| 8053 | return error::kInvalidArguments; |
| 8054 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8055 | uint32 data_size = bucket->size(); |
| 8056 | GLsizei imageSize = data_size; |
| 8057 | const void* data = bucket->GetData(0, data_size); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8058 | if (!data) { |
| 8059 | return error::kInvalidArguments; |
| 8060 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8061 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8062 | LOCAL_SET_GL_ERROR( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8063 | GL_INVALID_ENUM, "glCompressedTexSubImage2D", "target"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8064 | return error::kNoError; |
| 8065 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8066 | if (!validators_->compressed_texture_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8067 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 8068 | "glCompressedTexSubImage2D", format, "format"); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8069 | return error::kNoError; |
| 8070 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8071 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8072 | LOCAL_SET_GL_ERROR( |
| 8073 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "width < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8074 | return error::kNoError; |
| 8075 | } |
| 8076 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8077 | LOCAL_SET_GL_ERROR( |
| 8078 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "height < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8079 | return error::kNoError; |
| 8080 | } |
| 8081 | if (imageSize < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8082 | LOCAL_SET_GL_ERROR( |
| 8083 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "imageSize < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8084 | return error::kNoError; |
| 8085 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8086 | DoCompressedTexSubImage2D( |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8087 | target, level, xoffset, yoffset, width, height, format, imageSize, data); |
| 8088 | return error::kNoError; |
| 8089 | } |
| 8090 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8091 | error::Error GLES2DecoderImpl::HandleTexImage2D( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8092 | uint32 immediate_data_size, const cmds::TexImage2D& c) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 8093 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D"); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8094 | // Set as failed for now, but if it successed, this will be set to not failed. |
| 8095 | texture_state_.tex_image_2d_failed = true; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8096 | GLenum target = static_cast<GLenum>(c.target); |
| 8097 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8098 | // TODO(kloveless): Change TexImage2D command to use unsigned integer |
| 8099 | // for internalformat. |
| 8100 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8101 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8102 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8103 | GLint border = static_cast<GLint>(c.border); |
| 8104 | GLenum format = static_cast<GLenum>(c.format); |
| 8105 | GLenum type = static_cast<GLenum>(c.type); |
| 8106 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 8107 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 8108 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8109 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8110 | width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8111 | NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 8112 | return error::kOutOfBounds; |
| 8113 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8114 | const void* pixels = NULL; |
| 8115 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 8116 | pixels = GetSharedMemoryAs<const void*>( |
| 8117 | pixels_shm_id, pixels_shm_offset, pixels_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 8118 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8119 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8120 | } |
| 8121 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8122 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8123 | TextureManager::DoTextImage2DArguments args = { |
| 8124 | target, level, internal_format, width, height, border, format, type, |
| 8125 | pixels, pixels_size}; |
| 8126 | texture_manager()->ValidateAndDoTexImage2D( |
| 8127 | &texture_state_, &state_, &framebuffer_state_, args); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8128 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8129 | } |
| 8130 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8131 | void GLES2DecoderImpl::DoCompressedTexSubImage2D( |
| 8132 | GLenum target, |
| 8133 | GLint level, |
| 8134 | GLint xoffset, |
| 8135 | GLint yoffset, |
| 8136 | GLsizei width, |
| 8137 | GLsizei height, |
| 8138 | GLenum format, |
| 8139 | GLsizei image_size, |
| 8140 | const void * data) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8141 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8142 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8143 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8144 | LOCAL_SET_GL_ERROR( |
| 8145 | GL_INVALID_OPERATION, |
| 8146 | "glCompressedTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8147 | return; |
| 8148 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8149 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8150 | GLenum type = 0; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8151 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8152 | if (!texture->GetLevelType(target, level, &type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8153 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8154 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8155 | "glCompressedTexSubImage2D", "level does not exist."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8156 | return; |
| 8157 | } |
| 8158 | if (internal_format != format) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8159 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8160 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8161 | "glCompressedTexSubImage2D", "format does not match internal format."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8162 | return; |
| 8163 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8164 | if (!texture->ValidForTexture( |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8165 | target, level, xoffset, yoffset, width, height, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8166 | LOCAL_SET_GL_ERROR( |
| 8167 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8168 | return; |
| 8169 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8170 | |
| 8171 | if (!ValidateCompressedTexFuncData( |
| 8172 | "glCompressedTexSubImage2D", width, height, format, image_size) || |
| 8173 | !ValidateCompressedTexSubDimensions( |
| 8174 | "glCompressedTexSubImage2D", |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8175 | target, level, xoffset, yoffset, width, height, format, texture)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8176 | return; |
| 8177 | } |
| 8178 | |
| 8179 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8180 | // Note: There is no need to deal with texture cleared tracking here |
| 8181 | // because the validation above means you can only get here if the level |
| 8182 | // is already a matching compressed format and in that case |
| 8183 | // CompressedTexImage2D already cleared the texture. |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8184 | glCompressedTexSubImage2D( |
| 8185 | target, level, xoffset, yoffset, width, height, format, image_size, data); |
| 8186 | } |
| 8187 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8188 | static void Clip( |
| 8189 | GLint start, GLint range, GLint sourceRange, |
| 8190 | GLint* out_start, GLint* out_range) { |
| 8191 | DCHECK(out_start); |
| 8192 | DCHECK(out_range); |
| 8193 | if (start < 0) { |
| 8194 | range += start; |
| 8195 | start = 0; |
| 8196 | } |
| 8197 | GLint end = start + range; |
| 8198 | if (end > sourceRange) { |
| 8199 | range -= end - sourceRange; |
| 8200 | } |
| 8201 | *out_start = start; |
| 8202 | *out_range = range; |
| 8203 | } |
| 8204 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8205 | void GLES2DecoderImpl::DoCopyTexImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 8206 | GLenum target, |
| 8207 | GLint level, |
| 8208 | GLenum internal_format, |
| 8209 | GLint x, |
| 8210 | GLint y, |
| 8211 | GLsizei width, |
| 8212 | GLsizei height, |
| 8213 | GLint border) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 8214 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8215 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8216 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8217 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8218 | LOCAL_SET_GL_ERROR( |
| 8219 | GL_INVALID_OPERATION, |
| 8220 | "glCopyTexImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8221 | return; |
| 8222 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8223 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8224 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8225 | LOCAL_SET_GL_ERROR( |
| 8226 | GL_INVALID_OPERATION, "glCopyTexImage2D", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8227 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8228 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8229 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8230 | LOCAL_SET_GL_ERROR( |
| 8231 | GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range"); |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8232 | return; |
| 8233 | } |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8234 | if (!texture_manager()->ValidateFormatAndTypeCombination( |
| 8235 | state_.GetErrorState(), "glCopyTexImage2D", internal_format, |
| 8236 | GL_UNSIGNED_BYTE)) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8237 | return; |
| 8238 | } |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8239 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8240 | // Check we have compatible formats. |
| 8241 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 8242 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 8243 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); |
| 8244 | |
| 8245 | if ((channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8246 | LOCAL_SET_GL_ERROR( |
| 8247 | GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8248 | return; |
| 8249 | } |
| 8250 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8251 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8252 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8253 | GL_INVALID_OPERATION, |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8254 | "glCopyTexImage2D", "can not be used with depth or stencil textures"); |
| 8255 | return; |
| 8256 | } |
| 8257 | |
| 8258 | uint32 estimated_size = 0; |
| 8259 | if (!GLES2Util::ComputeImageDataSizes( |
| 8260 | width, height, internal_format, GL_UNSIGNED_BYTE, state_.unpack_alignment, |
| 8261 | &estimated_size, NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8262 | LOCAL_SET_GL_ERROR( |
| 8263 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8264 | return; |
| 8265 | } |
| 8266 | |
| 8267 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8268 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "out of memory"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8269 | return; |
| 8270 | } |
| 8271 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 8272 | if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { |
| 8273 | return; |
| 8274 | } |
| 8275 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8276 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTexImage2D"); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8277 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8278 | gfx::Size size = GetBoundReadFrameBufferSize(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8279 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8280 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8281 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 8282 | } |
| 8283 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8284 | // Clip to size to source dimensions |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8285 | GLint copyX = 0; |
| 8286 | GLint copyY = 0; |
| 8287 | GLint copyWidth = 0; |
| 8288 | GLint copyHeight = 0; |
| 8289 | Clip(x, width, size.width(), ©X, ©Width); |
| 8290 | Clip(y, height, size.height(), ©Y, ©Height); |
| 8291 | |
| 8292 | if (copyX != x || |
| 8293 | copyY != y || |
| 8294 | copyWidth != width || |
| 8295 | copyHeight != height) { |
| 8296 | // some part was clipped so clear the texture. |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8297 | if (!ClearLevel( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8298 | texture->service_id(), texture->target(), |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 8299 | target, level, internal_format, internal_format, GL_UNSIGNED_BYTE, |
| 8300 | width, height, texture->IsImmutable())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8301 | LOCAL_SET_GL_ERROR( |
| 8302 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8303 | return; |
| 8304 | } |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8305 | if (copyHeight > 0 && copyWidth > 0) { |
| 8306 | GLint dx = copyX - x; |
| 8307 | GLint dy = copyY - y; |
| 8308 | GLint destX = dx; |
| 8309 | GLint destY = dy; |
| 8310 | glCopyTexSubImage2D(target, level, |
| 8311 | destX, destY, copyX, copyY, |
| 8312 | copyWidth, copyHeight); |
| 8313 | } |
| 8314 | } else { |
| 8315 | glCopyTexImage2D(target, level, internal_format, |
| 8316 | copyX, copyY, copyWidth, copyHeight, border); |
| 8317 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8318 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8319 | if (error == GL_NO_ERROR) { |
| 8320 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8321 | texture_ref, target, level, internal_format, width, height, 1, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8322 | border, internal_format, GL_UNSIGNED_BYTE, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8323 | } |
| 8324 | } |
| 8325 | |
| 8326 | void GLES2DecoderImpl::DoCopyTexSubImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 8327 | GLenum target, |
| 8328 | GLint level, |
| 8329 | GLint xoffset, |
| 8330 | GLint yoffset, |
| 8331 | GLint x, |
| 8332 | GLint y, |
| 8333 | GLsizei width, |
| 8334 | GLsizei height) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 8335 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8336 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8337 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8338 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8339 | LOCAL_SET_GL_ERROR( |
| 8340 | GL_INVALID_OPERATION, |
| 8341 | "glCopyTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8342 | return; |
| 8343 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8344 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8345 | GLenum type = 0; |
| 8346 | GLenum format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8347 | if (!texture->GetLevelType(target, level, &type, &format) || |
| 8348 | !texture->ValidForTexture( |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8349 | target, level, xoffset, yoffset, width, height, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8350 | LOCAL_SET_GL_ERROR( |
| 8351 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8352 | return; |
| 8353 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 8354 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8355 | LOCAL_SET_GL_ERROR( |
| 8356 | GL_INVALID_OPERATION, |
| 8357 | "glCopyTexSubImage2D", "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 8358 | return; |
| 8359 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8360 | |
| 8361 | // Check we have compatible formats. |
| 8362 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 8363 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 8364 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(format); |
| 8365 | |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8366 | if (!channels_needed || |
| 8367 | (channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8368 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8369 | GL_INVALID_OPERATION, "glCopyTexSubImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8370 | return; |
| 8371 | } |
| 8372 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8373 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8374 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8375 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8376 | "glCopySubImage2D", "can not be used with depth or stencil textures"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8377 | return; |
| 8378 | } |
| 8379 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 8380 | if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) { |
| 8381 | return; |
| 8382 | } |
| 8383 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8384 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8385 | gfx::Size size = GetBoundReadFrameBufferSize(); |
| 8386 | GLint copyX = 0; |
| 8387 | GLint copyY = 0; |
| 8388 | GLint copyWidth = 0; |
| 8389 | GLint copyHeight = 0; |
| 8390 | Clip(x, width, size.width(), ©X, ©Width); |
| 8391 | Clip(y, height, size.height(), ©Y, ©Height); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8392 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8393 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8394 | LOCAL_SET_GL_ERROR( |
| 8395 | GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", "dimensions too big"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8396 | return; |
| 8397 | } |
| 8398 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8399 | if (copyX != x || |
| 8400 | copyY != y || |
| 8401 | copyWidth != width || |
| 8402 | copyHeight != height) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8403 | // some part was clipped so clear the sub rect. |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8404 | uint32 pixels_size = 0; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8405 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8406 | width, height, format, type, state_.unpack_alignment, &pixels_size, |
| 8407 | NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8408 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8409 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8410 | return; |
| 8411 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8412 | scoped_ptr<char[]> zero(new char[pixels_size]); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8413 | memset(zero.get(), 0, pixels_size); |
| 8414 | glTexSubImage2D( |
| 8415 | target, level, xoffset, yoffset, width, height, |
| 8416 | format, type, zero.get()); |
| 8417 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8418 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8419 | if (copyHeight > 0 && copyWidth > 0) { |
| 8420 | GLint dx = copyX - x; |
| 8421 | GLint dy = copyY - y; |
| 8422 | GLint destX = xoffset + dx; |
| 8423 | GLint destY = yoffset + dy; |
| 8424 | glCopyTexSubImage2D(target, level, |
| 8425 | destX, destY, copyX, copyY, |
| 8426 | copyWidth, copyHeight); |
| 8427 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8428 | } |
| 8429 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8430 | bool GLES2DecoderImpl::ValidateTexSubImage2D( |
| 8431 | error::Error* error, |
| 8432 | const char* function_name, |
| 8433 | GLenum target, |
| 8434 | GLint level, |
| 8435 | GLint xoffset, |
| 8436 | GLint yoffset, |
| 8437 | GLsizei width, |
| 8438 | GLsizei height, |
| 8439 | GLenum format, |
| 8440 | GLenum type, |
| 8441 | const void * data) { |
| 8442 | (*error) = error::kNoError; |
| 8443 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8444 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8445 | return false; |
| 8446 | } |
| 8447 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8448 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "width < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8449 | return false; |
| 8450 | } |
| 8451 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8452 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "height < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8453 | return false; |
| 8454 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8455 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8456 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8457 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8458 | LOCAL_SET_GL_ERROR( |
| 8459 | GL_INVALID_OPERATION, |
| 8460 | function_name, "unknown texture for target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8461 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8462 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8463 | Texture* texture = texture_ref->texture(); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8464 | GLenum current_type = 0; |
| 8465 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8466 | if (!texture->GetLevelType(target, level, ¤t_type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8467 | LOCAL_SET_GL_ERROR( |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8468 | GL_INVALID_OPERATION, function_name, "level does not exist."); |
| 8469 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8470 | } |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8471 | if (!texture_manager()->ValidateTextureParameters(state_.GetErrorState(), |
| 8472 | function_name, format, type, internal_format, level)) { |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8473 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8474 | } |
| 8475 | if (type != current_type) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8476 | LOCAL_SET_GL_ERROR( |
| 8477 | GL_INVALID_OPERATION, |
| 8478 | function_name, "type does not match type of texture."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8479 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8480 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 8481 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8482 | LOCAL_SET_GL_ERROR( |
| 8483 | GL_INVALID_OPERATION, |
| 8484 | function_name, "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 8485 | return false; |
| 8486 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8487 | if (!texture->ValidForTexture( |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8488 | target, level, xoffset, yoffset, width, height, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8489 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "bad dimensions."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8490 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8491 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8492 | if ((GLES2Util::GetChannelsForFormat(format) & |
| 8493 | (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8494 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8495 | GL_INVALID_OPERATION, |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8496 | function_name, "can not supply data for depth or stencil textures"); |
| 8497 | return false; |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8498 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8499 | if (data == NULL) { |
| 8500 | (*error) = error::kOutOfBounds; |
| 8501 | return false; |
| 8502 | } |
| 8503 | return true; |
| 8504 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8505 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8506 | error::Error GLES2DecoderImpl::DoTexSubImage2D( |
| 8507 | GLenum target, |
| 8508 | GLint level, |
| 8509 | GLint xoffset, |
| 8510 | GLint yoffset, |
| 8511 | GLsizei width, |
| 8512 | GLsizei height, |
| 8513 | GLenum format, |
| 8514 | GLenum type, |
| 8515 | const void * data) { |
| 8516 | error::Error error = error::kNoError; |
| 8517 | if (!ValidateTexSubImage2D(&error, "glTexSubImage2D", target, level, |
| 8518 | xoffset, yoffset, width, height, format, type, data)) { |
| 8519 | return error; |
| 8520 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8521 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8522 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8523 | Texture* texture = texture_ref->texture(); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8524 | GLsizei tex_width = 0; |
| 8525 | GLsizei tex_height = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8526 | bool ok = texture->GetLevelSize(target, level, &tex_width, &tex_height); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8527 | DCHECK(ok); |
| 8528 | if (xoffset != 0 || yoffset != 0 || |
| 8529 | width != tex_width || height != tex_height) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8530 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, |
| 8531 | target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8532 | LOCAL_SET_GL_ERROR( |
| 8533 | GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8534 | return error::kNoError; |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 8535 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8536 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8537 | glTexSubImage2D( |
| 8538 | target, level, xoffset, yoffset, width, height, format, type, data); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8539 | return error::kNoError; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8540 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8541 | |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 8542 | if (!texture_state_.texsubimage2d_faster_than_teximage2d && |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8543 | !texture->IsImmutable()) { |
| 8544 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 8545 | GLenum internal_format; |
| 8546 | GLenum tex_type; |
| 8547 | texture->GetLevelType(target, level, &tex_type, &internal_format); |
| 8548 | // NOTE: In OpenGL ES 2.0 border is always zero. If that changes we'll need |
| 8549 | // to look it up. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 8550 | glTexImage2D( |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 8551 | target, level, internal_format, width, height, 0, format, type, data); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8552 | } else { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8553 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8554 | glTexSubImage2D( |
| 8555 | target, level, xoffset, yoffset, width, height, format, type, data); |
| 8556 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8557 | texture_manager()->SetLevelCleared(texture_ref, target, level, true); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8558 | return error::kNoError; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8559 | } |
| 8560 | |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8561 | error::Error GLES2DecoderImpl::HandleTexSubImage2D( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8562 | uint32 immediate_data_size, const cmds::TexSubImage2D& c) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 8563 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8564 | GLboolean internal = static_cast<GLboolean>(c.internal); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8565 | if (internal == GL_TRUE && texture_state_.tex_image_2d_failed) |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8566 | return error::kNoError; |
| 8567 | |
| 8568 | GLenum target = static_cast<GLenum>(c.target); |
| 8569 | GLint level = static_cast<GLint>(c.level); |
| 8570 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 8571 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 8572 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8573 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8574 | GLenum format = static_cast<GLenum>(c.format); |
| 8575 | GLenum type = static_cast<GLenum>(c.type); |
| 8576 | uint32 data_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8577 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8578 | width, height, format, type, state_.unpack_alignment, &data_size, |
| 8579 | NULL, NULL)) { |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8580 | return error::kOutOfBounds; |
| 8581 | } |
| 8582 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 8583 | c.pixels_shm_id, c.pixels_shm_offset, data_size); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8584 | return DoTexSubImage2D( |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8585 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8586 | } |
| 8587 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8588 | error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8589 | uint32 immediate_data_size, const cmds::GetVertexAttribPointerv& c) { |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8590 | GLuint index = static_cast<GLuint>(c.index); |
| 8591 | GLenum pname = static_cast<GLenum>(c.pname); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8592 | typedef cmds::GetVertexAttribPointerv::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8593 | Result* result = GetSharedMemoryAs<Result*>( |
| 8594 | c.pointer_shm_id, c.pointer_shm_offset, Result::ComputeSize(1)); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8595 | if (!result) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8596 | return error::kOutOfBounds; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8597 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8598 | // Check that the client initialized the result. |
| 8599 | if (result->size != 0) { |
| 8600 | return error::kInvalidArguments; |
| 8601 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8602 | if (!validators_->vertex_pointer.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8603 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 8604 | "glGetVertexAttribPointerv", pname, "pname"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8605 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8606 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 8607 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8608 | LOCAL_SET_GL_ERROR( |
| 8609 | GL_INVALID_VALUE, "glGetVertexAttribPointerv", "index out of range."); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8610 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 8611 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8612 | result->SetNumResults(1); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 8613 | *result->GetData() = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8614 | state_.vertex_attrib_manager->GetVertexAttrib(index)->offset(); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8615 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8616 | } |
| 8617 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8618 | bool GLES2DecoderImpl::GetUniformSetup( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8619 | GLuint program_id, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8620 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8621 | error::Error* error, GLint* real_location, |
| 8622 | GLuint* service_id, void** result_pointer, GLenum* result_type) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8623 | DCHECK(error); |
| 8624 | DCHECK(service_id); |
| 8625 | DCHECK(result_pointer); |
| 8626 | DCHECK(result_type); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8627 | DCHECK(real_location); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8628 | *error = error::kNoError; |
| 8629 | // Make sure we have enough room for the result on failure. |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8630 | SizedResult<GLint>* result; |
| 8631 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 8632 | shm_id, shm_offset, SizedResult<GLint>::ComputeSize(0)); |
| 8633 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8634 | *error = error::kOutOfBounds; |
| 8635 | return false; |
| 8636 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8637 | *result_pointer = result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8638 | // 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] | 8639 | result->SetNumResults(0); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8640 | Program* program = GetProgramInfoNotShader(program_id, "glGetUniform"); |
| 8641 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8642 | return false; |
| 8643 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8644 | if (!program->IsValid()) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8645 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8646 | LOCAL_SET_GL_ERROR( |
| 8647 | GL_INVALID_OPERATION, "glGetUniform", "program not linked"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8648 | return false; |
| 8649 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8650 | *service_id = program->service_id(); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 8651 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8652 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8653 | program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8654 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 8655 | if (!uniform_info) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8656 | // No such location. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8657 | LOCAL_SET_GL_ERROR( |
| 8658 | GL_INVALID_OPERATION, "glGetUniform", "unknown location"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8659 | return false; |
| 8660 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 8661 | GLenum type = uniform_info->type; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 8662 | GLsizei size = GLES2Util::GetGLDataTypeSizeForUniforms(type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8663 | if (size == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8664 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glGetUniform", "unknown type"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8665 | return false; |
| 8666 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8667 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 8668 | shm_id, shm_offset, SizedResult<GLint>::ComputeSizeFromBytes(size)); |
| 8669 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8670 | *error = error::kOutOfBounds; |
| 8671 | return false; |
| 8672 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8673 | result->size = size; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8674 | *result_type = type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8675 | return true; |
| 8676 | } |
| 8677 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8678 | error::Error GLES2DecoderImpl::HandleGetUniformiv( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8679 | uint32 immediate_data_size, const cmds::GetUniformiv& c) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8680 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 8681 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8682 | GLuint service_id; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8683 | GLenum result_type; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8684 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8685 | Error error; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8686 | void* result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8687 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8688 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 8689 | &error, &real_location, &service_id, &result, &result_type)) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8690 | glGetUniformiv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8691 | service_id, real_location, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8692 | static_cast<cmds::GetUniformiv::Result*>(result)->GetData()); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8693 | } |
| 8694 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8695 | } |
| 8696 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8697 | error::Error GLES2DecoderImpl::HandleGetUniformfv( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8698 | uint32 immediate_data_size, const cmds::GetUniformfv& c) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8699 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 8700 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8701 | GLuint service_id; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8702 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8703 | Error error; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8704 | typedef cmds::GetUniformfv::Result Result; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8705 | Result* result; |
| 8706 | GLenum result_type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8707 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8708 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 8709 | &error, &real_location, &service_id, |
| 8710 | reinterpret_cast<void**>(&result), &result_type)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8711 | if (result_type == GL_BOOL || result_type == GL_BOOL_VEC2 || |
| 8712 | result_type == GL_BOOL_VEC3 || result_type == GL_BOOL_VEC4) { |
| 8713 | GLsizei num_values = result->GetNumResults(); |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8714 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8715 | glGetUniformiv(service_id, real_location, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8716 | GLfloat* dst = result->GetData(); |
| 8717 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
| 8718 | dst[ii] = (temp[ii] != 0); |
| 8719 | } |
| 8720 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 8721 | glGetUniformfv(service_id, real_location, result->GetData()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 8722 | } |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 8723 | } |
| 8724 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8725 | } |
| 8726 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8727 | error::Error GLES2DecoderImpl::HandleGetShaderPrecisionFormat( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8728 | uint32 immediate_data_size, const cmds::GetShaderPrecisionFormat& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8729 | GLenum shader_type = static_cast<GLenum>(c.shadertype); |
| 8730 | GLenum precision_type = static_cast<GLenum>(c.precisiontype); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8731 | typedef cmds::GetShaderPrecisionFormat::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8732 | Result* result = GetSharedMemoryAs<Result*>( |
| 8733 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8734 | if (!result) { |
| 8735 | return error::kOutOfBounds; |
| 8736 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8737 | // Check that the client initialized the result. |
| 8738 | if (result->success != 0) { |
| 8739 | return error::kInvalidArguments; |
| 8740 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8741 | if (!validators_->shader_type.IsValid(shader_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8742 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8743 | "glGetShaderPrecisionFormat", shader_type, "shader_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8744 | return error::kNoError; |
| 8745 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8746 | if (!validators_->shader_precision.IsValid(precision_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8747 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8748 | "glGetShaderPrecisionFormat", precision_type, "precision_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8749 | return error::kNoError; |
| 8750 | } |
| 8751 | |
| 8752 | result->success = 1; // true |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 8753 | |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 8754 | GLint range[2] = { 0, 0 }; |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 8755 | GLint precision = 0; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 8756 | GetShaderPrecisionFormatImpl(shader_type, precision_type, range, &precision); |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 8757 | |
| 8758 | result->min_range = range[0]; |
| 8759 | result->max_range = range[1]; |
| 8760 | result->precision = precision; |
| 8761 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8762 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8763 | } |
| 8764 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8765 | error::Error GLES2DecoderImpl::HandleGetAttachedShaders( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8766 | uint32 immediate_data_size, const cmds::GetAttachedShaders& c) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8767 | uint32 result_size = c.result_size; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8768 | GLuint program_id = static_cast<GLuint>(c.program); |
| 8769 | Program* program = GetProgramInfoNotShader( |
| 8770 | program_id, "glGetAttachedShaders"); |
| 8771 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8772 | return error::kNoError; |
| 8773 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8774 | typedef cmds::GetAttachedShaders::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8775 | uint32 max_count = Result::ComputeMaxResults(result_size); |
| 8776 | Result* result = GetSharedMemoryAs<Result*>( |
| 8777 | c.result_shm_id, c.result_shm_offset, Result::ComputeSize(max_count)); |
| 8778 | if (!result) { |
| 8779 | return error::kOutOfBounds; |
| 8780 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8781 | // Check that the client initialized the result. |
| 8782 | if (result->size != 0) { |
| 8783 | return error::kInvalidArguments; |
| 8784 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8785 | GLsizei count = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8786 | glGetAttachedShaders( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8787 | program->service_id(), max_count, &count, result->GetData()); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8788 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 8789 | if (!shader_manager()->GetClientId(result->GetData()[ii], |
| 8790 | &result->GetData()[ii])) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8791 | NOTREACHED(); |
| 8792 | return error::kGenericError; |
| 8793 | } |
| 8794 | } |
| 8795 | result->SetNumResults(count); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8796 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8797 | } |
| 8798 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8799 | error::Error GLES2DecoderImpl::HandleGetActiveUniform( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8800 | uint32 immediate_data_size, const cmds::GetActiveUniform& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8801 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8802 | GLuint index = c.index; |
| 8803 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8804 | typedef cmds::GetActiveUniform::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8805 | Result* result = GetSharedMemoryAs<Result*>( |
| 8806 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8807 | if (!result) { |
| 8808 | return error::kOutOfBounds; |
| 8809 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8810 | // Check that the client initialized the result. |
| 8811 | if (result->success != 0) { |
| 8812 | return error::kInvalidArguments; |
| 8813 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8814 | Program* program = GetProgramInfoNotShader( |
| 8815 | program_id, "glGetActiveUniform"); |
| 8816 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8817 | return error::kNoError; |
| 8818 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8819 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8820 | program->GetUniformInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8821 | if (!uniform_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8822 | LOCAL_SET_GL_ERROR( |
| 8823 | GL_INVALID_VALUE, "glGetActiveUniform", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8824 | return error::kNoError; |
| 8825 | } |
| 8826 | result->success = 1; // true. |
| 8827 | result->size = uniform_info->size; |
| 8828 | result->type = uniform_info->type; |
| 8829 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 8830 | bucket->SetFromString(uniform_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8831 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8832 | } |
| 8833 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8834 | error::Error GLES2DecoderImpl::HandleGetActiveAttrib( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8835 | uint32 immediate_data_size, const cmds::GetActiveAttrib& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8836 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8837 | GLuint index = c.index; |
| 8838 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8839 | typedef cmds::GetActiveAttrib::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8840 | Result* result = GetSharedMemoryAs<Result*>( |
| 8841 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8842 | if (!result) { |
| 8843 | return error::kOutOfBounds; |
| 8844 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 8845 | // Check that the client initialized the result. |
| 8846 | if (result->success != 0) { |
| 8847 | return error::kInvalidArguments; |
| 8848 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8849 | Program* program = GetProgramInfoNotShader( |
| 8850 | program_id, "glGetActiveAttrib"); |
| 8851 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8852 | return error::kNoError; |
| 8853 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8854 | const Program::VertexAttrib* attrib_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8855 | program->GetAttribInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8856 | if (!attrib_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8857 | LOCAL_SET_GL_ERROR( |
| 8858 | GL_INVALID_VALUE, "glGetActiveAttrib", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8859 | return error::kNoError; |
| 8860 | } |
| 8861 | result->success = 1; // true. |
| 8862 | result->size = attrib_info->size; |
| 8863 | result->type = attrib_info->type; |
| 8864 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 8865 | bucket->SetFromString(attrib_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8866 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8867 | } |
| 8868 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8869 | error::Error GLES2DecoderImpl::HandleShaderBinary( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8870 | uint32 immediate_data_size, const cmds::ShaderBinary& c) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8871 | #if 1 // No binary shader support. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8872 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glShaderBinary", "not supported"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8873 | return error::kNoError; |
| 8874 | #else |
| 8875 | GLsizei n = static_cast<GLsizei>(c.n); |
| 8876 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8877 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "n < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8878 | return error::kNoError; |
| 8879 | } |
| 8880 | GLsizei length = static_cast<GLsizei>(c.length); |
| 8881 | if (length < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8882 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "length < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8883 | return error::kNoError; |
| 8884 | } |
| 8885 | uint32 data_size; |
| 8886 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 8887 | return error::kOutOfBounds; |
| 8888 | } |
| 8889 | const GLuint* shaders = GetSharedMemoryAs<const GLuint*>( |
| 8890 | c.shaders_shm_id, c.shaders_shm_offset, data_size); |
| 8891 | GLenum binaryformat = static_cast<GLenum>(c.binaryformat); |
| 8892 | const void* binary = GetSharedMemoryAs<const void*>( |
| 8893 | c.binary_shm_id, c.binary_shm_offset, length); |
| 8894 | if (shaders == NULL || binary == NULL) { |
| 8895 | return error::kOutOfBounds; |
| 8896 | } |
| 8897 | scoped_array<GLuint> service_ids(new GLuint[n]); |
| 8898 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8899 | Shader* shader = GetShader(shaders[ii]); |
| 8900 | if (!shader) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8901 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "unknown shader"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8902 | return error::kNoError; |
| 8903 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8904 | service_ids[ii] = shader->service_id(); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 8905 | } |
| 8906 | // TODO(gman): call glShaderBinary |
| 8907 | return error::kNoError; |
| 8908 | #endif |
| 8909 | } |
| 8910 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 8911 | void GLES2DecoderImpl::DoSwapBuffers() { |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8912 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 8913 | |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8914 | int this_frame_number = frame_number_++; |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 8915 | // TRACE_EVENT for gpu tests: |
| 8916 | TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffersLatency", |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 8917 | TRACE_EVENT_SCOPE_THREAD, |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 8918 | "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
| 8919 | "width", (is_offscreen ? offscreen_size_.width() : |
| 8920 | surface_->GetSize().width())); |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 8921 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoSwapBuffers", |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8922 | "offscreen", is_offscreen, |
| 8923 | "frame", this_frame_number); |
[email protected] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 8924 | { |
| 8925 | TRACE_EVENT_SYNTHETIC_DELAY("gpu.SwapBuffers"); |
| 8926 | } |
| 8927 | |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 8928 | bool is_tracing; |
| 8929 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 8930 | &is_tracing); |
| 8931 | if (is_tracing) { |
| 8932 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 8933 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 8934 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 8935 | } |
| 8936 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8937 | // If offscreen then don't actually SwapBuffers to the display. Just copy |
| 8938 | // the rendered frame to another frame buffer. |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 8939 | if (is_offscreen) { |
[email protected] | 111975c6 | 2012-09-06 01:37:31 | [diff] [blame] | 8940 | TRACE_EVENT2("gpu", "Offscreen", |
| 8941 | "width", offscreen_size_.width(), "height", offscreen_size_.height()); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8942 | if (offscreen_size_ != offscreen_saved_color_texture_->size()) { |
| 8943 | // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, |
| 8944 | // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will |
| 8945 | // fix this. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8946 | if (workarounds().needs_offscreen_buffer_workaround) { |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8947 | offscreen_saved_frame_buffer_->Create(); |
| 8948 | glFinish(); |
| 8949 | } |
| 8950 | |
| 8951 | // Allocate the offscreen saved color texture. |
| 8952 | DCHECK(offscreen_saved_color_format_); |
| 8953 | offscreen_saved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 8954 | offscreen_size_, offscreen_saved_color_format_, false); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8955 | |
| 8956 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 8957 | offscreen_saved_color_texture_.get()); |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 8958 | if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { |
| 8959 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 8960 | GL_FRAMEBUFFER_COMPLETE) { |
| 8961 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 8962 | << "because offscreen saved FBO was incomplete."; |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 8963 | LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
| 8964 | return; |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 8965 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8966 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 8967 | // Clear the offscreen color texture. |
| 8968 | // TODO(piman): Is this still necessary? |
| 8969 | { |
| 8970 | ScopedFrameBufferBinder binder(this, |
| 8971 | offscreen_saved_frame_buffer_->id()); |
| 8972 | glClearColor(0, 0, 0, 0); |
| 8973 | glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 8974 | glDisable(GL_SCISSOR_TEST); |
| 8975 | glClear(GL_COLOR_BUFFER_BIT); |
| 8976 | RestoreClearState(); |
| 8977 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 8978 | } |
| 8979 | |
| 8980 | UpdateParentTextureInfo(); |
| 8981 | } |
| 8982 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 8983 | if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 8984 | return; |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8985 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 8986 | "GLES2DecoderImpl::DoSwapBuffers", GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 8987 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 8988 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 8989 | // For multisampled buffers, resolve the frame buffer. |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8990 | ScopedResolvedFrameBufferBinder binder(this, true, false); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 8991 | } else { |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8992 | ScopedFrameBufferBinder binder(this, |
| 8993 | offscreen_target_frame_buffer_->id()); |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 8994 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 8995 | if (offscreen_target_buffer_preserved_) { |
| 8996 | // Copy the target frame buffer to the saved offscreen texture. |
| 8997 | offscreen_saved_color_texture_->Copy( |
| 8998 | offscreen_saved_color_texture_->size(), |
| 8999 | offscreen_saved_color_format_); |
| 9000 | } else { |
| 9001 | // Flip the textures in the parent context via the texture manager. |
| 9002 | if (!!offscreen_saved_color_texture_info_.get()) |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9003 | offscreen_saved_color_texture_info_->texture()-> |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9004 | SetServiceId(offscreen_target_color_texture_->id()); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 9005 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9006 | offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); |
| 9007 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 9008 | offscreen_target_color_texture_.get()); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 9009 | } |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9010 | |
| 9011 | // Ensure the side effects of the copy are visible to the parent |
| 9012 | // context. There is no need to do this for ANGLE because it uses a |
| 9013 | // single D3D device for all contexts. |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 9014 | if (!feature_info_->feature_flags().is_angle) |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9015 | glFlush(); |
[email protected] | 0c8c9d2 | 2010-06-25 17:36:39 | [diff] [blame] | 9016 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9017 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 9018 | if (!surface_->SwapBuffers()) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 9019 | LOG(ERROR) << "Context lost because SwapBuffers failed."; |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9020 | LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 9021 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9022 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9023 | } |
| 9024 | |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 9025 | error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9026 | uint32 immediate_data_size, const cmds::EnableFeatureCHROMIUM& c) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9027 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9028 | if (!bucket || bucket->size() == 0) { |
| 9029 | return error::kInvalidArguments; |
| 9030 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9031 | typedef cmds::EnableFeatureCHROMIUM::Result Result; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9032 | Result* result = GetSharedMemoryAs<Result*>( |
| 9033 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9034 | if (!result) { |
| 9035 | return error::kOutOfBounds; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 9036 | } |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9037 | // Check that the client initialized the result. |
| 9038 | if (*result != 0) { |
| 9039 | return error::kInvalidArguments; |
| 9040 | } |
| 9041 | std::string feature_str; |
| 9042 | if (!bucket->GetAsString(&feature_str)) { |
| 9043 | return error::kInvalidArguments; |
| 9044 | } |
| 9045 | |
| 9046 | // TODO(gman): make this some kind of table to function pointer thingy. |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 9047 | if (feature_str.compare("pepper3d_allow_buffers_on_multiple_targets") == 0) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9048 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 9049 | } else if (feature_str.compare("pepper3d_support_fixed_attribs") == 0) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 9050 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
| 9051 | // TODO(gman): decide how to remove the need for this const_cast. |
| 9052 | // I could make validators_ non const but that seems bad as this is the only |
| 9053 | // place it is needed. I could make some special friend class of validators |
| 9054 | // just to allow this to set them. That seems silly. I could refactor this |
| 9055 | // code to use the extension mechanism or the initialization attributes to |
| 9056 | // turn this feature on. Given that the only real point of this is to make |
| 9057 | // the conformance tests pass and given that there is lots of real work that |
| 9058 | // needs to be done it seems like refactoring for one to one of those |
| 9059 | // methods is a very low priority. |
| 9060 | const_cast<Validators*>(validators_)->vertex_attrib_type.AddValue(GL_FIXED); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 9061 | } else if (feature_str.compare("webgl_enable_glsl_webgl_validation") == 0) { |
| 9062 | force_webgl_glsl_validation_ = true; |
| 9063 | InitializeShaderTranslator(); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9064 | } else { |
| 9065 | return error::kNoError; |
| 9066 | } |
| 9067 | |
| 9068 | *result = 1; // true. |
| 9069 | return error::kNoError; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 9070 | } |
| 9071 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9072 | error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( |
| 9073 | uint32 immediate_data_size, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9074 | const cmds::GetRequestableExtensionsCHROMIUM& c) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9075 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9076 | scoped_refptr<FeatureInfo> info(new FeatureInfo()); |
[email protected] | 956aec5 | 2013-09-05 15:41:19 | [diff] [blame] | 9077 | info->Initialize(disallowed_features_); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9078 | bucket->SetFromString(info->extensions().c_str()); |
| 9079 | return error::kNoError; |
| 9080 | } |
| 9081 | |
| 9082 | error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9083 | uint32 immediate_data_size, const cmds::RequestExtensionCHROMIUM& c) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9084 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9085 | if (!bucket || bucket->size() == 0) { |
| 9086 | return error::kInvalidArguments; |
| 9087 | } |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9088 | std::string feature_str; |
| 9089 | if (!bucket->GetAsString(&feature_str)) { |
| 9090 | return error::kInvalidArguments; |
| 9091 | } |
| 9092 | |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 9093 | bool desire_webgl_glsl_validation = |
| 9094 | feature_str.find("GL_CHROMIUM_webglsl") != std::string::npos; |
| 9095 | bool desire_standard_derivatives = false; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9096 | bool desire_frag_depth = false; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9097 | bool desire_draw_buffers = false; |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 9098 | if (force_webgl_glsl_validation_) { |
| 9099 | desire_standard_derivatives = |
| 9100 | feature_str.find("GL_OES_standard_derivatives") != std::string::npos; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9101 | desire_frag_depth = |
| 9102 | feature_str.find("GL_EXT_frag_depth") != std::string::npos; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9103 | desire_draw_buffers = |
| 9104 | feature_str.find("GL_EXT_draw_buffers") != std::string::npos; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 9105 | } |
| 9106 | |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 9107 | if (desire_webgl_glsl_validation != force_webgl_glsl_validation_ || |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9108 | desire_standard_derivatives != derivatives_explicitly_enabled_ || |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9109 | desire_frag_depth != frag_depth_explicitly_enabled_ || |
| 9110 | desire_draw_buffers != draw_buffers_explicitly_enabled_) { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9111 | force_webgl_glsl_validation_ |= desire_webgl_glsl_validation; |
| 9112 | derivatives_explicitly_enabled_ |= desire_standard_derivatives; |
| 9113 | frag_depth_explicitly_enabled_ |= desire_frag_depth; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9114 | draw_buffers_explicitly_enabled_ |= desire_draw_buffers; |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9115 | InitializeShaderTranslator(); |
| 9116 | } |
| 9117 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 9118 | UpdateCapabilities(); |
| 9119 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9120 | return error::kNoError; |
| 9121 | } |
| 9122 | |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9123 | error::Error GLES2DecoderImpl::HandleGetMultipleIntegervCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9124 | uint32 immediate_data_size, const cmds::GetMultipleIntegervCHROMIUM& c) { |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9125 | GLuint count = c.count; |
| 9126 | uint32 pnames_size; |
| 9127 | if (!SafeMultiplyUint32(count, sizeof(GLenum), &pnames_size)) { |
| 9128 | return error::kOutOfBounds; |
| 9129 | } |
| 9130 | const GLenum* pnames = GetSharedMemoryAs<const GLenum*>( |
| 9131 | c.pnames_shm_id, c.pnames_shm_offset, pnames_size); |
| 9132 | if (pnames == NULL) { |
| 9133 | return error::kOutOfBounds; |
| 9134 | } |
| 9135 | |
| 9136 | // We have to copy them since we use them twice so the client |
| 9137 | // can't change them between the time we validate them and the time we use |
| 9138 | // them. |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 9139 | scoped_ptr<GLenum[]> enums(new GLenum[count]); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9140 | memcpy(enums.get(), pnames, pnames_size); |
| 9141 | |
| 9142 | // Count up the space needed for the result. |
| 9143 | uint32 num_results = 0; |
| 9144 | for (GLuint ii = 0; ii < count; ++ii) { |
| 9145 | uint32 num = util_.GLGetNumValuesReturned(enums[ii]); |
| 9146 | if (num == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9147 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 9148 | "glGetMultipleCHROMIUM", enums[ii], "pname"); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9149 | return error::kNoError; |
| 9150 | } |
| 9151 | // Num will never be more than 4. |
| 9152 | DCHECK_LE(num, 4u); |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 9153 | if (!SafeAddUint32(num_results, num, &num_results)) { |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9154 | return error::kOutOfBounds; |
| 9155 | } |
| 9156 | } |
| 9157 | |
| 9158 | uint32 result_size = 0; |
| 9159 | if (!SafeMultiplyUint32(num_results, sizeof(GLint), &result_size)) { |
| 9160 | return error::kOutOfBounds; |
| 9161 | } |
| 9162 | |
| 9163 | if (result_size != static_cast<uint32>(c.size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9164 | LOCAL_SET_GL_ERROR( |
| 9165 | GL_INVALID_VALUE, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 9166 | "glGetMultipleCHROMIUM", "bad size GL_INVALID_VALUE"); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9167 | return error::kNoError; |
| 9168 | } |
| 9169 | |
| 9170 | GLint* results = GetSharedMemoryAs<GLint*>( |
| 9171 | c.results_shm_id, c.results_shm_offset, result_size); |
| 9172 | if (results == NULL) { |
| 9173 | return error::kOutOfBounds; |
| 9174 | } |
| 9175 | |
| 9176 | // Check the results have been cleared in case the context was lost. |
| 9177 | for (uint32 ii = 0; ii < num_results; ++ii) { |
| 9178 | if (results[ii]) { |
| 9179 | return error::kInvalidArguments; |
| 9180 | } |
| 9181 | } |
| 9182 | |
| 9183 | // Get each result. |
| 9184 | GLint* start = results; |
| 9185 | for (GLuint ii = 0; ii < count; ++ii) { |
| 9186 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 9187 | if (!state_.GetStateAsGLint(enums[ii], results, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 9188 | !GetHelper(enums[ii], results, &num_written)) { |
[email protected] | b0ce098 | 2013-05-13 18:51:48 | [diff] [blame] | 9189 | DoGetIntegerv(enums[ii], results); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9190 | } |
| 9191 | results += num_written; |
| 9192 | } |
| 9193 | |
| 9194 | // Just to verify. Should this be a DCHECK? |
| 9195 | if (static_cast<uint32>(results - start) != num_results) { |
| 9196 | return error::kOutOfBounds; |
| 9197 | } |
| 9198 | |
| 9199 | return error::kNoError; |
| 9200 | } |
| 9201 | |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9202 | error::Error GLES2DecoderImpl::HandleGetProgramInfoCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9203 | uint32 immediate_data_size, const cmds::GetProgramInfoCHROMIUM& c) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9204 | GLuint program_id = static_cast<GLuint>(c.program); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9205 | uint32 bucket_id = c.bucket_id; |
| 9206 | Bucket* bucket = CreateBucket(bucket_id); |
| 9207 | bucket->SetSize(sizeof(ProgramInfoHeader)); // in case we fail. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9208 | Program* program = NULL; |
| 9209 | program = GetProgram(program_id); |
| 9210 | if (!program || !program->IsValid()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 9211 | return error::kNoError; |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9212 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9213 | program->GetProgramInfo(program_manager(), bucket); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9214 | return error::kNoError; |
| 9215 | } |
| 9216 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9217 | error::ContextLostReason GLES2DecoderImpl::GetContextLostReason() { |
| 9218 | switch (reset_status_) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9219 | case GL_NO_ERROR: |
| 9220 | // TODO(kbr): improve the precision of the error code in this case. |
| 9221 | // Consider delegating to context for error code if MakeCurrent fails. |
| 9222 | return error::kUnknown; |
| 9223 | case GL_GUILTY_CONTEXT_RESET_ARB: |
| 9224 | return error::kGuilty; |
| 9225 | case GL_INNOCENT_CONTEXT_RESET_ARB: |
| 9226 | return error::kInnocent; |
| 9227 | case GL_UNKNOWN_CONTEXT_RESET_ARB: |
| 9228 | return error::kUnknown; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9229 | } |
| 9230 | |
| 9231 | NOTREACHED(); |
| 9232 | return error::kUnknown; |
| 9233 | } |
| 9234 | |
| 9235 | bool GLES2DecoderImpl::WasContextLost() { |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9236 | if (reset_status_ != GL_NO_ERROR) { |
| 9237 | return true; |
| 9238 | } |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 9239 | if (context_->WasAllocatedUsingRobustnessExtension()) { |
| 9240 | GLenum status = GL_NO_ERROR; |
| 9241 | if (has_robustness_extension_) |
| 9242 | status = glGetGraphicsResetStatusARB(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9243 | if (status != GL_NO_ERROR) { |
| 9244 | // The graphics card was reset. Signal a lost context to the application. |
| 9245 | reset_status_ = status; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 9246 | reset_by_robustness_extension_ = true; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9247 | LOG(ERROR) << (surface_->IsOffscreen() ? "Offscreen" : "Onscreen") |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9248 | << " context lost via ARB/EXT_robustness. Reset status = " |
| 9249 | << GLES2Util::GetStringEnum(status); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9250 | return true; |
| 9251 | } |
| 9252 | } |
| 9253 | return false; |
| 9254 | } |
| 9255 | |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 9256 | bool GLES2DecoderImpl::WasContextLostByRobustnessExtension() { |
| 9257 | return WasContextLost() && reset_by_robustness_extension_; |
| 9258 | } |
| 9259 | |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9260 | void GLES2DecoderImpl::LoseContext(uint32 reset_status) { |
| 9261 | // Only loses the context once. |
| 9262 | if (reset_status_ != GL_NO_ERROR) { |
| 9263 | return; |
| 9264 | } |
| 9265 | |
| 9266 | // Marks this context as lost. |
| 9267 | reset_status_ = reset_status; |
| 9268 | current_decoder_error_ = error::kLostContext; |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9269 | } |
| 9270 | |
| 9271 | error::Error GLES2DecoderImpl::HandleLoseContextCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9272 | uint32 immediate_data_size, const cmds::LoseContextCHROMIUM& c) { |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9273 | GLenum current = static_cast<GLenum>(c.current); |
| 9274 | GLenum other = static_cast<GLenum>(c.other); |
| 9275 | if (!validators_->reset_status.IsValid(current)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9276 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 9277 | "glLoseContextCHROMIUM", current, "current"); |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9278 | } |
| 9279 | if (!validators_->reset_status.IsValid(other)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9280 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glLoseContextCHROMIUM", other, "other"); |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9281 | } |
| 9282 | group_->LoseContexts(other); |
| 9283 | reset_status_ = current; |
| 9284 | current_decoder_error_ = error::kLostContext; |
| 9285 | return error::kLostContext; |
| 9286 | } |
| 9287 | |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 9288 | error::Error GLES2DecoderImpl::HandleInsertSyncPointCHROMIUM( |
| 9289 | uint32 immediate_data_size, const cmds::InsertSyncPointCHROMIUM& c) { |
| 9290 | return error::kUnknownCommand; |
| 9291 | } |
| 9292 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 9293 | error::Error GLES2DecoderImpl::HandleWaitSyncPointCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9294 | uint32 immediate_data_size, const cmds::WaitSyncPointCHROMIUM& c) { |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 9295 | if (wait_sync_point_callback_.is_null()) |
| 9296 | return error::kNoError; |
| 9297 | |
| 9298 | return wait_sync_point_callback_.Run(c.sync_point) ? |
| 9299 | error::kNoError : error::kDeferCommandUntilLater; |
| 9300 | } |
| 9301 | |
[email protected] | 5dfc457b | 2013-12-13 11:13:07 | [diff] [blame] | 9302 | error::Error GLES2DecoderImpl::HandleDiscardBackbufferCHROMIUM( |
| 9303 | uint32 immediate_data_size, const cmds::DiscardBackbufferCHROMIUM& c) { |
| 9304 | if (surface_->DeferDraws()) |
| 9305 | return error::kDeferCommandUntilLater; |
| 9306 | if (!surface_->SetBackbufferAllocation(false)) |
| 9307 | return error::kLostContext; |
| 9308 | backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| 9309 | backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
| 9310 | backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
| 9311 | return error::kNoError; |
| 9312 | } |
| 9313 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9314 | bool GLES2DecoderImpl::GenQueriesEXTHelper( |
| 9315 | GLsizei n, const GLuint* client_ids) { |
| 9316 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9317 | if (query_manager_->GetQuery(client_ids[ii])) { |
| 9318 | return false; |
| 9319 | } |
| 9320 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9321 | // NOTE: We don't generate Query objects here. Only in BeginQueryEXT |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9322 | return true; |
| 9323 | } |
| 9324 | |
| 9325 | void GLES2DecoderImpl::DeleteQueriesEXTHelper( |
| 9326 | GLsizei n, const GLuint* client_ids) { |
| 9327 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9328 | QueryManager::Query* query = query_manager_->GetQuery(client_ids[ii]); |
| 9329 | if (query && !query->IsDeleted()) { |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9330 | ContextState::QueryMap::iterator it = |
| 9331 | state_.current_queries.find(query->target()); |
| 9332 | if (it != state_.current_queries.end()) |
| 9333 | state_.current_queries.erase(it); |
| 9334 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9335 | query->Destroy(true); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9336 | query_manager_->RemoveQuery(client_ids[ii]); |
| 9337 | } |
| 9338 | } |
| 9339 | } |
| 9340 | |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 9341 | bool GLES2DecoderImpl::ProcessPendingQueries() { |
| 9342 | if (query_manager_.get() == NULL) { |
| 9343 | return false; |
| 9344 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9345 | if (!query_manager_->ProcessPendingQueries()) { |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 9346 | current_decoder_error_ = error::kOutOfBounds; |
| 9347 | } |
| 9348 | return query_manager_->HavePendingQueries(); |
| 9349 | } |
| 9350 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9351 | // Note that if there are no pending readpixels right now, |
| 9352 | // this function will call the callback immediately. |
| 9353 | void GLES2DecoderImpl::WaitForReadPixels(base::Closure callback) { |
| 9354 | if (features().use_async_readpixels && !pending_readpixel_fences_.empty()) { |
| 9355 | pending_readpixel_fences_.back()->callbacks.push_back(callback); |
| 9356 | } else { |
| 9357 | callback.Run(); |
| 9358 | } |
| 9359 | } |
| 9360 | |
| 9361 | void GLES2DecoderImpl::ProcessPendingReadPixels() { |
| 9362 | while (!pending_readpixel_fences_.empty() && |
| 9363 | pending_readpixel_fences_.front()->fence->HasCompleted()) { |
| 9364 | std::vector<base::Closure> callbacks = |
| 9365 | pending_readpixel_fences_.front()->callbacks; |
| 9366 | pending_readpixel_fences_.pop(); |
| 9367 | for (size_t i = 0; i < callbacks.size(); i++) { |
| 9368 | callbacks[i].Run(); |
| 9369 | } |
| 9370 | } |
| 9371 | } |
| 9372 | |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9373 | bool GLES2DecoderImpl::HasMoreIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9374 | return !pending_readpixel_fences_.empty() || |
| 9375 | async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9376 | } |
| 9377 | |
| 9378 | void GLES2DecoderImpl::PerformIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9379 | ProcessPendingReadPixels(); |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 9380 | if (!async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers()) |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9381 | return; |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 9382 | async_pixel_transfer_manager_->ProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9383 | ProcessFinishedAsyncTransfers(); |
| 9384 | } |
| 9385 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9386 | error::Error GLES2DecoderImpl::HandleBeginQueryEXT( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9387 | uint32 immediate_data_size, const cmds::BeginQueryEXT& c) { |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9388 | GLenum target = static_cast<GLenum>(c.target); |
| 9389 | GLuint client_id = static_cast<GLuint>(c.id); |
| 9390 | int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id); |
| 9391 | uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 9392 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9393 | switch (target) { |
| 9394 | case GL_COMMANDS_ISSUED_CHROMIUM: |
[email protected] | fb4bf582 | 2012-10-23 21:25:55 | [diff] [blame] | 9395 | case GL_LATENCY_QUERY_CHROMIUM: |
[email protected] | 5537605d | 2013-08-27 05:22:31 | [diff] [blame] | 9396 | case GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM: |
| 9397 | case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM: |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 9398 | case GL_GET_ERROR_QUERY_CHROMIUM: |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9399 | break; |
| 9400 | default: |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9401 | if (!features().occlusion_query_boolean) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9402 | LOCAL_SET_GL_ERROR( |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 9403 | GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 9404 | "not enabled for occlusion queries"); |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9405 | return error::kNoError; |
| 9406 | } |
| 9407 | break; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9408 | } |
| 9409 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9410 | if (state_.current_queries.find(target) != state_.current_queries.end()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9411 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9412 | GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9413 | return error::kNoError; |
| 9414 | } |
| 9415 | |
| 9416 | if (client_id == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9417 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9418 | return error::kNoError; |
| 9419 | } |
| 9420 | |
| 9421 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 9422 | if (!query) { |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9423 | // TODO(gman): Decide if we need this check. |
| 9424 | // |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9425 | // Checks id was made by glGenQueries |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9426 | // |
| 9427 | // From the POV of OpenGL ES 2.0 you need to call glGenQueriesEXT |
| 9428 | // for all Query ids but from the POV of the command buffer service maybe |
| 9429 | // you don't. |
| 9430 | // |
| 9431 | // The client can enforce this. I don't think the service cares. |
| 9432 | // |
| 9433 | // IdAllocatorInterface* id_allocator = |
| 9434 | // group_->GetIdAllocator(id_namespaces::kQueries); |
| 9435 | // if (!id_allocator->InUse(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9436 | // LOCAL_SET_GL_ERROR( |
| 9437 | // GL_INVALID_OPERATION, |
| 9438 | // "glBeginQueryEXT", "id not made by glGenQueriesEXT"); |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9439 | // return error::kNoError; |
| 9440 | // } |
| 9441 | query = query_manager_->CreateQuery( |
| 9442 | target, client_id, sync_shm_id, sync_shm_offset); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9443 | } |
| 9444 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9445 | if (query->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9446 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9447 | GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9448 | return error::kNoError; |
| 9449 | } else if (query->shm_id() != sync_shm_id || |
| 9450 | query->shm_offset() != sync_shm_offset) { |
| 9451 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 9452 | return error::kInvalidArguments; |
| 9453 | } |
| 9454 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9455 | if (!query_manager_->BeginQuery(query)) { |
| 9456 | return error::kOutOfBounds; |
| 9457 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9458 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9459 | state_.current_queries[target] = query; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9460 | return error::kNoError; |
| 9461 | } |
| 9462 | |
| 9463 | error::Error GLES2DecoderImpl::HandleEndQueryEXT( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9464 | uint32 immediate_data_size, const cmds::EndQueryEXT& c) { |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9465 | GLenum target = static_cast<GLenum>(c.target); |
| 9466 | uint32 submit_count = static_cast<GLuint>(c.submit_count); |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9467 | ContextState::QueryMap::iterator it = state_.current_queries.find(target); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9468 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9469 | if (it == state_.current_queries.end()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9470 | LOCAL_SET_GL_ERROR( |
| 9471 | GL_INVALID_OPERATION, "glEndQueryEXT", "No active query"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9472 | return error::kNoError; |
| 9473 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9474 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9475 | QueryManager::Query* query = it->second.get(); |
| 9476 | if (!query_manager_->EndQuery(query, submit_count)) { |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9477 | return error::kOutOfBounds; |
| 9478 | } |
| 9479 | |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 9480 | query_manager_->ProcessPendingTransferQueries(); |
| 9481 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9482 | state_.current_queries.erase(it); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9483 | return error::kNoError; |
| 9484 | } |
| 9485 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9486 | bool GLES2DecoderImpl::GenVertexArraysOESHelper( |
| 9487 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9488 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9489 | if (GetVertexAttribManager(client_ids[ii])) { |
| 9490 | return false; |
| 9491 | } |
| 9492 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9493 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9494 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9495 | // Emulated VAO |
| 9496 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9497 | CreateVertexAttribManager(client_ids[ii], 0); |
| 9498 | } |
| 9499 | } else { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 9500 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9501 | |
| 9502 | glGenVertexArraysOES(n, service_ids.get()); |
| 9503 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9504 | CreateVertexAttribManager(client_ids[ii], service_ids[ii]); |
| 9505 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9506 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9507 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9508 | return true; |
| 9509 | } |
| 9510 | |
| 9511 | void GLES2DecoderImpl::DeleteVertexArraysOESHelper( |
| 9512 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9513 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9514 | VertexAttribManager* vao = |
| 9515 | GetVertexAttribManager(client_ids[ii]); |
| 9516 | if (vao && !vao->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9517 | if (state_.vertex_attrib_manager.get() == vao) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9518 | state_.vertex_attrib_manager = default_vertex_attrib_manager_; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9519 | } |
| 9520 | RemoveVertexAttribManager(client_ids[ii]); |
| 9521 | } |
| 9522 | } |
| 9523 | } |
| 9524 | |
| 9525 | void GLES2DecoderImpl::DoBindVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9526 | VertexAttribManager* vao = NULL; |
| 9527 | GLuint service_id = 0; |
| 9528 | if (client_id != 0) { |
| 9529 | vao = GetVertexAttribManager(client_id); |
| 9530 | if (!vao) { |
| 9531 | // Unlike most Bind* methods, the spec explicitly states that VertexArray |
| 9532 | // only allows names that have been previously generated. As such, we do |
| 9533 | // not generate new names here. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9534 | LOCAL_SET_GL_ERROR( |
| 9535 | GL_INVALID_OPERATION, |
| 9536 | "glBindVertexArrayOES", "bad vertex array id."); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9537 | current_decoder_error_ = error::kNoError; |
| 9538 | return; |
| 9539 | } else { |
| 9540 | service_id = vao->service_id(); |
| 9541 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9542 | } else { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9543 | vao = default_vertex_attrib_manager_.get(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9544 | } |
| 9545 | |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9546 | // Only set the VAO state if it's changed |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9547 | if (state_.vertex_attrib_manager.get() != vao) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9548 | state_.vertex_attrib_manager = vao; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9549 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9550 | EmulateVertexArrayState(); |
| 9551 | } else { |
| 9552 | glBindVertexArrayOES(service_id); |
| 9553 | } |
| 9554 | } |
| 9555 | } |
| 9556 | |
| 9557 | // Used when OES_vertex_array_object isn't natively supported |
| 9558 | void GLES2DecoderImpl::EmulateVertexArrayState() { |
| 9559 | // Setup the Vertex attribute state |
| 9560 | for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) { |
| 9561 | RestoreStateForAttrib(vv); |
| 9562 | } |
| 9563 | |
| 9564 | // Setup the element buffer |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 9565 | Buffer* element_array_buffer = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9566 | state_.vertex_attrib_manager->element_array_buffer(); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9567 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 9568 | element_array_buffer ? element_array_buffer->service_id() : 0); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9569 | } |
| 9570 | |
| 9571 | bool GLES2DecoderImpl::DoIsVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9572 | const VertexAttribManager* vao = |
| 9573 | GetVertexAttribManager(client_id); |
| 9574 | return vao && vao->IsValid() && !vao->IsDeleted(); |
| 9575 | } |
| 9576 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9577 | #if defined(OS_MACOSX) |
| 9578 | void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { |
| 9579 | TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( |
| 9580 | texture_id); |
| 9581 | if (it != texture_to_io_surface_map_.end()) { |
| 9582 | // Found a previous IOSurface bound to this texture; release it. |
| 9583 | CFTypeRef surface = it->second; |
| 9584 | CFRelease(surface); |
| 9585 | texture_to_io_surface_map_.erase(it); |
| 9586 | } |
| 9587 | } |
| 9588 | #endif |
| 9589 | |
| 9590 | void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( |
| 9591 | GLenum target, GLsizei width, GLsizei height, |
| 9592 | GLuint io_surface_id, GLuint plane) { |
| 9593 | #if defined(OS_MACOSX) |
| 9594 | if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9595 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9596 | GL_INVALID_OPERATION, |
| 9597 | "glTexImageIOSurface2DCHROMIUM", "only supported on desktop GL."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9598 | return; |
| 9599 | } |
| 9600 | |
| 9601 | IOSurfaceSupport* surface_support = IOSurfaceSupport::Initialize(); |
| 9602 | if (!surface_support) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9603 | LOCAL_SET_GL_ERROR( |
| 9604 | GL_INVALID_OPERATION, |
| 9605 | "glTexImageIOSurface2DCHROMIUM", "only supported on 10.6."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9606 | return; |
| 9607 | } |
| 9608 | |
| 9609 | if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 9610 | // This might be supported in the future, and if we could require |
| 9611 | // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we |
| 9612 | // could delete a lot of code. For now, perform strict validation so we |
| 9613 | // know what's going on. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9614 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9615 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9616 | "glTexImageIOSurface2DCHROMIUM", |
| 9617 | "requires TEXTURE_RECTANGLE_ARB target"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9618 | return; |
| 9619 | } |
| 9620 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 9621 | // Default target might be conceptually valid, but disallow it to avoid |
| 9622 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9623 | TextureRef* texture_ref = |
| 9624 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9625 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9626 | LOCAL_SET_GL_ERROR( |
| 9627 | GL_INVALID_OPERATION, |
| 9628 | "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9629 | return; |
| 9630 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9631 | |
| 9632 | // Look up the new IOSurface. Note that because of asynchrony |
| 9633 | // between processes this might fail; during live resizing the |
| 9634 | // plugin process might allocate and release an IOSurface before |
| 9635 | // this process gets a chance to look it up. Hold on to any old |
| 9636 | // IOSurface in this case. |
| 9637 | CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); |
| 9638 | if (!surface) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9639 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9640 | GL_INVALID_OPERATION, |
| 9641 | "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9642 | return; |
| 9643 | } |
| 9644 | |
| 9645 | // Release any IOSurface previously bound to this texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9646 | ReleaseIOSurfaceForTexture(texture_ref->service_id()); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9647 | |
| 9648 | // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. |
| 9649 | texture_to_io_surface_map_.insert( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9650 | std::make_pair(texture_ref->service_id(), surface)); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9651 | |
| 9652 | CGLContextObj context = |
| 9653 | static_cast<CGLContextObj>(context_->GetHandle()); |
| 9654 | |
| 9655 | CGLError err = surface_support->CGLTexImageIOSurface2D( |
| 9656 | context, |
| 9657 | target, |
| 9658 | GL_RGBA, |
| 9659 | width, |
| 9660 | height, |
| 9661 | GL_BGRA, |
| 9662 | GL_UNSIGNED_INT_8_8_8_8_REV, |
| 9663 | surface, |
| 9664 | plane); |
| 9665 | |
| 9666 | if (err != kCGLNoError) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9667 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9668 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9669 | "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9670 | return; |
| 9671 | } |
| 9672 | |
| 9673 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9674 | texture_ref, target, 0, GL_RGBA, width, height, 1, 0, |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9675 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); |
| 9676 | |
| 9677 | #else |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9678 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9679 | "glTexImageIOSurface2DCHROMIUM", "not supported."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 9680 | #endif |
| 9681 | } |
| 9682 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9683 | static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { |
| 9684 | switch (internalformat) { |
| 9685 | case GL_RGB565: |
| 9686 | return GL_RGB; |
| 9687 | case GL_RGBA4: |
| 9688 | return GL_RGBA; |
| 9689 | case GL_RGB5_A1: |
| 9690 | return GL_RGBA; |
| 9691 | case GL_RGB8_OES: |
| 9692 | return GL_RGB; |
| 9693 | case GL_RGBA8_OES: |
| 9694 | return GL_RGBA; |
| 9695 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 9696 | return GL_LUMINANCE_ALPHA; |
| 9697 | case GL_LUMINANCE8_EXT: |
| 9698 | return GL_LUMINANCE; |
| 9699 | case GL_ALPHA8_EXT: |
| 9700 | return GL_ALPHA; |
| 9701 | case GL_RGBA32F_EXT: |
| 9702 | return GL_RGBA; |
| 9703 | case GL_RGB32F_EXT: |
| 9704 | return GL_RGB; |
| 9705 | case GL_ALPHA32F_EXT: |
| 9706 | return GL_ALPHA; |
| 9707 | case GL_LUMINANCE32F_EXT: |
| 9708 | return GL_LUMINANCE; |
| 9709 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 9710 | return GL_LUMINANCE_ALPHA; |
| 9711 | case GL_RGBA16F_EXT: |
| 9712 | return GL_RGBA; |
| 9713 | case GL_RGB16F_EXT: |
| 9714 | return GL_RGB; |
| 9715 | case GL_ALPHA16F_EXT: |
| 9716 | return GL_ALPHA; |
| 9717 | case GL_LUMINANCE16F_EXT: |
| 9718 | return GL_LUMINANCE; |
| 9719 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 9720 | return GL_LUMINANCE_ALPHA; |
| 9721 | case GL_BGRA8_EXT: |
| 9722 | return GL_BGRA_EXT; |
| 9723 | default: |
| 9724 | return GL_NONE; |
| 9725 | } |
| 9726 | } |
| 9727 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9728 | void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9729 | GLenum target, GLuint source_id, GLuint dest_id, GLint level, |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 9730 | GLenum internal_format, GLenum dest_type) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9731 | TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 9732 | TextureRef* source_texture_ref = GetTexture(source_id); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9733 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9734 | if (!source_texture_ref || !dest_texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9735 | LOCAL_SET_GL_ERROR( |
| 9736 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9737 | return; |
| 9738 | } |
| 9739 | |
| 9740 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9741 | LOCAL_SET_GL_ERROR( |
| 9742 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid texture target"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9743 | return; |
| 9744 | } |
| 9745 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9746 | Texture* source_texture = source_texture_ref->texture(); |
| 9747 | Texture* dest_texture = dest_texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9748 | if (dest_texture->target() != GL_TEXTURE_2D || |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 9749 | (source_texture->target() != GL_TEXTURE_2D && |
| 9750 | source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 9751 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 9752 | "glCopyTextureCHROMIUM", |
| 9753 | "invalid texture target binding"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9754 | return; |
| 9755 | } |
| 9756 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9757 | int source_width, source_height, dest_width, dest_height; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9758 | |
[email protected] | 3e0dfd7 | 2014-02-21 06:28:41 | [diff] [blame^] | 9759 | gfx::GLImage* image = |
| 9760 | source_texture->GetLevelImage(source_texture->target(), 0); |
| 9761 | if (image) { |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 9762 | gfx::Size size = image->GetSize(); |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 9763 | source_width = size.width(); |
| 9764 | source_height = size.height(); |
| 9765 | if (source_width <= 0 || source_height <= 0) { |
| 9766 | LOCAL_SET_GL_ERROR( |
| 9767 | GL_INVALID_VALUE, |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 9768 | "glCopyTextureChromium", "invalid image size"); |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 9769 | return; |
| 9770 | } |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 9771 | } else { |
| 9772 | if (!source_texture->GetLevelSize( |
| 9773 | source_texture->target(), 0, &source_width, &source_height)) { |
| 9774 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 9775 | "glCopyTextureChromium", |
| 9776 | "source texture has no level 0"); |
| 9777 | return; |
| 9778 | } |
| 9779 | |
| 9780 | // Check that this type of texture is allowed. |
| 9781 | if (!texture_manager()->ValidForTarget( |
| 9782 | source_texture->target(), level, source_width, source_height, 1)) { |
| 9783 | LOCAL_SET_GL_ERROR( |
| 9784 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); |
| 9785 | return; |
| 9786 | } |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 9787 | } |
| 9788 | |
[email protected] | 04b5b37d | 2014-02-07 02:11:51 | [diff] [blame] | 9789 | // Clear the source texture if necessary. |
| 9790 | if (!texture_manager()->ClearTextureLevel( |
| 9791 | this, source_texture_ref, source_texture->target(), 0)) { |
| 9792 | LOCAL_SET_GL_ERROR( |
| 9793 | GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", "dimensions too big"); |
| 9794 | return; |
| 9795 | } |
| 9796 | |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 9797 | // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 9798 | // needed because it takes 10s of milliseconds to initialize. |
| 9799 | if (!copy_texture_CHROMIUM_.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9800 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 9801 | copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
[email protected] | 07a0cc3 | 2013-02-28 00:36:27 | [diff] [blame] | 9802 | copy_texture_CHROMIUM_->Initialize(this); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 9803 | RestoreCurrentFramebufferBindings(); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9804 | if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 9805 | return; |
| 9806 | } |
| 9807 | |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 9808 | GLenum dest_type_previous; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9809 | GLenum dest_internal_format; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9810 | bool dest_level_defined = dest_texture->GetLevelSize( |
| 9811 | GL_TEXTURE_2D, level, &dest_width, &dest_height); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9812 | |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9813 | if (dest_level_defined) { |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 9814 | dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9815 | &dest_internal_format); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9816 | } |
| 9817 | |
| 9818 | // Resize the destination texture to the dimensions of the source texture. |
| 9819 | if (!dest_level_defined || dest_width != source_width || |
| 9820 | dest_height != source_height || |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 9821 | dest_internal_format != internal_format || |
| 9822 | dest_type_previous != dest_type) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9823 | // Ensure that the glTexImage2D succeeds. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9824 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9825 | glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 9826 | glTexImage2D( |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9827 | GL_TEXTURE_2D, level, internal_format, source_width, source_height, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9828 | 0, internal_format, dest_type, NULL); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9829 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9830 | if (error != GL_NO_ERROR) { |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 9831 | RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9832 | return; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9833 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9834 | |
| 9835 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9836 | dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 9837 | source_height, 1, 0, internal_format, dest_type, true); |
[email protected] | f702471 | 2012-05-15 21:30:25 | [diff] [blame] | 9838 | } else { |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9839 | texture_manager()->SetLevelCleared( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9840 | dest_texture_ref, GL_TEXTURE_2D, level, true); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9841 | } |
| 9842 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 9843 | DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 9844 | |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 9845 | // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 9846 | // before presenting. |
| 9847 | if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
| 9848 | // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
| 9849 | // instead of using default matrix crbug.com/226218. |
| 9850 | const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
| 9851 | 0.0f, 1.0f, 0.0f, 0.0f, |
| 9852 | 0.0f, 0.0f, 1.0f, 0.0f, |
| 9853 | 0.0f, 0.0f, 0.0f, 1.0f}; |
| 9854 | copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| 9855 | this, |
| 9856 | source_texture->target(), |
| 9857 | dest_texture->target(), |
| 9858 | source_texture->service_id(), |
| 9859 | dest_texture->service_id(), level, |
| 9860 | source_width, source_height, |
| 9861 | unpack_flip_y_, |
| 9862 | unpack_premultiply_alpha_, |
| 9863 | unpack_unpremultiply_alpha_, |
| 9864 | default_matrix); |
| 9865 | } else { |
| 9866 | copy_texture_CHROMIUM_->DoCopyTexture( |
| 9867 | this, |
| 9868 | source_texture->target(), |
| 9869 | dest_texture->target(), |
| 9870 | source_texture->service_id(), |
| 9871 | dest_texture->service_id(), level, |
| 9872 | source_width, source_height, |
| 9873 | unpack_flip_y_, |
| 9874 | unpack_premultiply_alpha_, |
| 9875 | unpack_unpremultiply_alpha_); |
| 9876 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 9877 | |
| 9878 | DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 9879 | } |
| 9880 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9881 | static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
| 9882 | switch (internalformat) { |
| 9883 | case GL_RGB565: |
| 9884 | return GL_UNSIGNED_SHORT_5_6_5; |
| 9885 | case GL_RGBA4: |
| 9886 | return GL_UNSIGNED_SHORT_4_4_4_4; |
| 9887 | case GL_RGB5_A1: |
| 9888 | return GL_UNSIGNED_SHORT_5_5_5_1; |
| 9889 | case GL_RGB8_OES: |
| 9890 | return GL_UNSIGNED_BYTE; |
| 9891 | case GL_RGBA8_OES: |
| 9892 | return GL_UNSIGNED_BYTE; |
| 9893 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 9894 | return GL_UNSIGNED_BYTE; |
| 9895 | case GL_LUMINANCE8_EXT: |
| 9896 | return GL_UNSIGNED_BYTE; |
| 9897 | case GL_ALPHA8_EXT: |
| 9898 | return GL_UNSIGNED_BYTE; |
| 9899 | case GL_RGBA32F_EXT: |
| 9900 | return GL_FLOAT; |
| 9901 | case GL_RGB32F_EXT: |
| 9902 | return GL_FLOAT; |
| 9903 | case GL_ALPHA32F_EXT: |
| 9904 | return GL_FLOAT; |
| 9905 | case GL_LUMINANCE32F_EXT: |
| 9906 | return GL_FLOAT; |
| 9907 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 9908 | return GL_FLOAT; |
| 9909 | case GL_RGBA16F_EXT: |
| 9910 | return GL_HALF_FLOAT_OES; |
| 9911 | case GL_RGB16F_EXT: |
| 9912 | return GL_HALF_FLOAT_OES; |
| 9913 | case GL_ALPHA16F_EXT: |
| 9914 | return GL_HALF_FLOAT_OES; |
| 9915 | case GL_LUMINANCE16F_EXT: |
| 9916 | return GL_HALF_FLOAT_OES; |
| 9917 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 9918 | return GL_HALF_FLOAT_OES; |
| 9919 | case GL_BGRA8_EXT: |
| 9920 | return GL_UNSIGNED_BYTE; |
| 9921 | default: |
| 9922 | return GL_NONE; |
| 9923 | } |
| 9924 | } |
| 9925 | |
| 9926 | void GLES2DecoderImpl::DoTexStorage2DEXT( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 9927 | GLenum target, |
| 9928 | GLint levels, |
| 9929 | GLenum internal_format, |
| 9930 | GLsizei width, |
| 9931 | GLsizei height) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 9932 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT"); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 9933 | if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 9934 | TextureManager::ComputeMipMapCount(target, width, height, 1) < levels) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9935 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9936 | GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9937 | return; |
| 9938 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9939 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9940 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9941 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9942 | LOCAL_SET_GL_ERROR( |
| 9943 | GL_INVALID_OPERATION, |
| 9944 | "glTexStorage2DEXT", "unknown texture for target"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9945 | return; |
| 9946 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9947 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9948 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9949 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9950 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9951 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9952 | LOCAL_SET_GL_ERROR( |
| 9953 | GL_INVALID_OPERATION, |
| 9954 | "glTexStorage2DEXT", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9955 | return; |
| 9956 | } |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9957 | |
| 9958 | GLenum format = ExtractFormatFromStorageFormat(internal_format); |
| 9959 | GLenum type = ExtractTypeFromStorageFormat(internal_format); |
| 9960 | |
| 9961 | { |
| 9962 | GLsizei level_width = width; |
| 9963 | GLsizei level_height = height; |
| 9964 | uint32 estimated_size = 0; |
| 9965 | for (int ii = 0; ii < levels; ++ii) { |
| 9966 | uint32 level_size = 0; |
| 9967 | if (!GLES2Util::ComputeImageDataSizes( |
| 9968 | level_width, level_height, format, type, state_.unpack_alignment, |
| 9969 | &estimated_size, NULL, NULL) || |
| 9970 | !SafeAddUint32(estimated_size, level_size, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9971 | LOCAL_SET_GL_ERROR( |
| 9972 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9973 | return; |
| 9974 | } |
| 9975 | level_width = std::max(1, level_width >> 1); |
| 9976 | level_height = std::max(1, level_height >> 1); |
| 9977 | } |
| 9978 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9979 | LOCAL_SET_GL_ERROR( |
| 9980 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9981 | return; |
| 9982 | } |
| 9983 | } |
| 9984 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9985 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage2DEXT"); |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 9986 | glTexStorage2DEXT(target, levels, internal_format, width, height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9987 | GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage2DEXT"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9988 | if (error == GL_NO_ERROR) { |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9989 | GLsizei level_width = width; |
| 9990 | GLsizei level_height = height; |
| 9991 | for (int ii = 0; ii < levels; ++ii) { |
| 9992 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9993 | texture_ref, target, ii, format, |
| 9994 | level_width, level_height, 1, 0, format, type, false); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9995 | level_width = std::max(1, level_width >> 1); |
| 9996 | level_height = std::max(1, level_height >> 1); |
| 9997 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9998 | texture->SetImmutable(true); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9999 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10000 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10001 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10002 | error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10003 | uint32 immediate_data_size, const cmds::GenMailboxCHROMIUM& c) { |
[email protected] | baed42c | 2013-10-01 05:06:35 | [diff] [blame] | 10004 | return error::kUnknownCommand; |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10005 | } |
| 10006 | |
| 10007 | void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10008 | const GLbyte* data) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10009 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 10010 | "context", logger_.GetLogPrefix(), |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10011 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10012 | |
| 10013 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
| 10014 | DLOG_IF(ERROR, !mailbox.Verify()) << "ProduceTextureCHROMIUM was passed a " |
| 10015 | "mailbox that was not generated by " |
| 10016 | "GenMailboxCHROMIUM."; |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10017 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10018 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10019 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10020 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10021 | LOCAL_SET_GL_ERROR( |
| 10022 | GL_INVALID_OPERATION, |
| 10023 | "glProduceTextureCHROMIUM", "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10024 | return; |
| 10025 | } |
| 10026 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10027 | Texture* produced = texture_manager()->Produce(texture_ref); |
| 10028 | if (!produced) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10029 | LOCAL_SET_GL_ERROR( |
| 10030 | GL_INVALID_OPERATION, |
| 10031 | "glProduceTextureCHROMIUM", "invalid texture"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10032 | return; |
| 10033 | } |
| 10034 | |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10035 | group_->mailbox_manager()->ProduceTexture(target, mailbox, produced); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10036 | } |
| 10037 | |
| 10038 | void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10039 | const GLbyte* data) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10040 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 10041 | "context", logger_.GetLogPrefix(), |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10042 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10043 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
| 10044 | DLOG_IF(ERROR, !mailbox.Verify()) << "ConsumeTextureCHROMIUM was passed a " |
| 10045 | "mailbox that was not generated by " |
| 10046 | "GenMailboxCHROMIUM."; |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10047 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10048 | scoped_refptr<TextureRef> texture_ref = |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10049 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 10050 | if (!texture_ref.get()) { |
| 10051 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10052 | "glConsumeTextureCHROMIUM", |
| 10053 | "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10054 | return; |
| 10055 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10056 | GLuint client_id = texture_ref->client_id(); |
| 10057 | if (!client_id) { |
| 10058 | LOCAL_SET_GL_ERROR( |
| 10059 | GL_INVALID_OPERATION, |
| 10060 | "glConsumeTextureCHROMIUM", "unknown texture for target"); |
| 10061 | return; |
| 10062 | } |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10063 | Texture* texture = group_->mailbox_manager()->ConsumeTexture(target, mailbox); |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10064 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10065 | LOCAL_SET_GL_ERROR( |
| 10066 | GL_INVALID_OPERATION, |
| 10067 | "glConsumeTextureCHROMIUM", "invalid mailbox name"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10068 | return; |
| 10069 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10070 | if (texture->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10071 | LOCAL_SET_GL_ERROR( |
| 10072 | GL_INVALID_OPERATION, |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10073 | "glConsumeTextureCHROMIUM", "invalid target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10074 | return; |
| 10075 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10076 | |
| 10077 | DeleteTexturesHelper(1, &client_id); |
| 10078 | texture_ref = texture_manager()->Consume(client_id, texture); |
| 10079 | glBindTexture(target, texture_ref->service_id()); |
| 10080 | |
| 10081 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
| 10082 | unit.bind_target = target; |
| 10083 | switch (target) { |
| 10084 | case GL_TEXTURE_2D: |
| 10085 | unit.bound_texture_2d = texture_ref; |
| 10086 | break; |
| 10087 | case GL_TEXTURE_CUBE_MAP: |
| 10088 | unit.bound_texture_cube_map = texture_ref; |
| 10089 | break; |
| 10090 | case GL_TEXTURE_EXTERNAL_OES: |
| 10091 | unit.bound_texture_external_oes = texture_ref; |
| 10092 | break; |
| 10093 | case GL_TEXTURE_RECTANGLE_ARB: |
| 10094 | unit.bound_texture_rectangle_arb = texture_ref; |
| 10095 | break; |
| 10096 | default: |
| 10097 | NOTREACHED(); // Validation should prevent us getting here. |
| 10098 | break; |
| 10099 | } |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10100 | } |
| 10101 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 10102 | void GLES2DecoderImpl::DoInsertEventMarkerEXT( |
| 10103 | GLsizei length, const GLchar* marker) { |
| 10104 | if (!marker) { |
| 10105 | marker = ""; |
| 10106 | } |
| 10107 | debug_marker_manager_.SetMarker( |
| 10108 | length ? std::string(marker, length) : std::string(marker)); |
| 10109 | } |
| 10110 | |
| 10111 | void GLES2DecoderImpl::DoPushGroupMarkerEXT( |
| 10112 | GLsizei length, const GLchar* marker) { |
| 10113 | if (!marker) { |
| 10114 | marker = ""; |
| 10115 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 10116 | std::string name = length ? std::string(marker, length) : std::string(marker); |
| 10117 | debug_marker_manager_.PushGroup(name); |
| 10118 | gpu_tracer_->Begin(name, kTraceGroupMarker); |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 10119 | } |
| 10120 | |
| 10121 | void GLES2DecoderImpl::DoPopGroupMarkerEXT(void) { |
| 10122 | debug_marker_manager_.PopGroup(); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 10123 | gpu_tracer_->End(kTraceGroupMarker); |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 10124 | } |
| 10125 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10126 | void GLES2DecoderImpl::DoBindTexImage2DCHROMIUM( |
| 10127 | GLenum target, GLint image_id) { |
| 10128 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10129 | |
[email protected] | bc26e8d | 2014-01-29 00:40:30 | [diff] [blame] | 10130 | if (target == GL_TEXTURE_CUBE_MAP) { |
| 10131 | LOCAL_SET_GL_ERROR( |
| 10132 | GL_INVALID_ENUM, |
| 10133 | "glBindTexImage2DCHROMIUM", "invalid target"); |
| 10134 | return; |
| 10135 | } |
| 10136 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10137 | // Default target might be conceptually valid, but disallow it to avoid |
| 10138 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10139 | TextureRef* texture_ref = |
| 10140 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10141 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10142 | LOCAL_SET_GL_ERROR( |
| 10143 | GL_INVALID_OPERATION, |
| 10144 | "glBindTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10145 | return; |
| 10146 | } |
| 10147 | |
| 10148 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 10149 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10150 | LOCAL_SET_GL_ERROR( |
| 10151 | GL_INVALID_OPERATION, |
| 10152 | "glBindTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10153 | return; |
| 10154 | } |
| 10155 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10156 | { |
| 10157 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 10158 | "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | 3c58012 | 2013-11-22 07:52:26 | [diff] [blame] | 10159 | if (!gl_image->BindTexImage(target)) { |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10160 | LOCAL_SET_GL_ERROR( |
| 10161 | GL_INVALID_OPERATION, |
| 10162 | "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID"); |
| 10163 | return; |
| 10164 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10165 | } |
| 10166 | |
| 10167 | gfx::Size size = gl_image->GetSize(); |
| 10168 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10169 | texture_ref, target, 0, GL_RGBA, size.width(), size.height(), 1, 0, |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10170 | GL_RGBA, GL_UNSIGNED_BYTE, true); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10171 | texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10172 | } |
| 10173 | |
| 10174 | void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( |
| 10175 | GLenum target, GLint image_id) { |
| 10176 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10177 | |
| 10178 | // Default target might be conceptually valid, but disallow it to avoid |
| 10179 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10180 | TextureRef* texture_ref = |
| 10181 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10182 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10183 | LOCAL_SET_GL_ERROR( |
| 10184 | GL_INVALID_OPERATION, |
| 10185 | "glReleaseTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10186 | return; |
| 10187 | } |
| 10188 | |
| 10189 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 10190 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10191 | LOCAL_SET_GL_ERROR( |
| 10192 | GL_INVALID_OPERATION, |
| 10193 | "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10194 | return; |
| 10195 | } |
| 10196 | |
| 10197 | // Do nothing when image is not currently bound. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10198 | if (texture_ref->texture()->GetLevelImage(target, 0) != gl_image) |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10199 | return; |
| 10200 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10201 | { |
| 10202 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 10203 | "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | 3c58012 | 2013-11-22 07:52:26 | [diff] [blame] | 10204 | gl_image->ReleaseTexImage(target); |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10205 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10206 | |
| 10207 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10208 | texture_ref, target, 0, GL_RGBA, 0, 0, 1, 0, |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10209 | GL_RGBA, GL_UNSIGNED_BYTE, false); |
| 10210 | } |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 10211 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10212 | error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10213 | uint32 immediate_data_size, const cmds::TraceBeginCHROMIUM& c) { |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10214 | Bucket* bucket = GetBucket(c.bucket_id); |
| 10215 | if (!bucket || bucket->size() == 0) { |
| 10216 | return error::kInvalidArguments; |
| 10217 | } |
| 10218 | std::string command_name; |
| 10219 | if (!bucket->GetAsString(&command_name)) { |
| 10220 | return error::kInvalidArguments; |
| 10221 | } |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10222 | TRACE_EVENT_COPY_ASYNC_BEGIN0("gpu", command_name.c_str(), this); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 10223 | if (!gpu_tracer_->Begin(command_name, kTraceCHROMIUM)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10224 | LOCAL_SET_GL_ERROR( |
| 10225 | GL_INVALID_OPERATION, |
| 10226 | "glTraceBeginCHROMIUM", "unable to create begin trace"); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10227 | return error::kNoError; |
| 10228 | } |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10229 | return error::kNoError; |
| 10230 | } |
| 10231 | |
| 10232 | void GLES2DecoderImpl::DoTraceEndCHROMIUM() { |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10233 | if (gpu_tracer_->CurrentName().empty()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10234 | LOCAL_SET_GL_ERROR( |
| 10235 | GL_INVALID_OPERATION, |
| 10236 | "glTraceEndCHROMIUM", "no trace begin found"); |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10237 | return; |
| 10238 | } |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10239 | TRACE_EVENT_COPY_ASYNC_END0("gpu", gpu_tracer_->CurrentName().c_str(), this); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 10240 | gpu_tracer_->End(kTraceCHROMIUM); |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10241 | } |
| 10242 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 10243 | void GLES2DecoderImpl::DoDrawBuffersEXT( |
| 10244 | GLsizei count, const GLenum* bufs) { |
| 10245 | if (count > static_cast<GLsizei>(group_->max_draw_buffers())) { |
| 10246 | LOCAL_SET_GL_ERROR( |
| 10247 | GL_INVALID_VALUE, |
| 10248 | "glDrawBuffersEXT", "greater than GL_MAX_DRAW_BUFFERS_EXT"); |
| 10249 | return; |
| 10250 | } |
| 10251 | |
| 10252 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 10253 | if (framebuffer) { |
| 10254 | for (GLsizei i = 0; i < count; ++i) { |
| 10255 | if (bufs[i] != static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i) && |
| 10256 | bufs[i] != GL_NONE) { |
| 10257 | LOCAL_SET_GL_ERROR( |
| 10258 | GL_INVALID_OPERATION, |
| 10259 | "glDrawBuffersEXT", |
| 10260 | "bufs[i] not GL_NONE or GL_COLOR_ATTACHMENTi_EXT"); |
| 10261 | return; |
| 10262 | } |
| 10263 | } |
| 10264 | glDrawBuffersARB(count, bufs); |
| 10265 | framebuffer->SetDrawBuffers(count, bufs); |
| 10266 | } else { // backbuffer |
| 10267 | if (count > 1 || |
| 10268 | (bufs[0] != GL_BACK && bufs[0] != GL_NONE)) { |
| 10269 | LOCAL_SET_GL_ERROR( |
| 10270 | GL_INVALID_OPERATION, |
| 10271 | "glDrawBuffersEXT", |
| 10272 | "more than one buffer or bufs not GL_NONE or GL_BACK"); |
| 10273 | return; |
| 10274 | } |
| 10275 | GLenum mapped_buf = bufs[0]; |
| 10276 | if (GetBackbufferServiceId() != 0 && // emulated backbuffer |
| 10277 | bufs[0] == GL_BACK) { |
| 10278 | mapped_buf = GL_COLOR_ATTACHMENT0; |
| 10279 | } |
| 10280 | glDrawBuffersARB(count, &mapped_buf); |
| 10281 | group_->set_draw_buffer(bufs[0]); |
| 10282 | } |
| 10283 | } |
| 10284 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10285 | bool GLES2DecoderImpl::ValidateAsyncTransfer( |
| 10286 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10287 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10288 | GLenum target, |
| 10289 | GLint level, |
| 10290 | const void * data) { |
| 10291 | // We only support async uploads to 2D textures for now. |
| 10292 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10293 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10294 | return false; |
| 10295 | } |
| 10296 | // We only support uploads to level zero for now. |
| 10297 | if (level != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10298 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "level != 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10299 | return false; |
| 10300 | } |
| 10301 | // A transfer buffer must be bound, even for asyncTexImage2D. |
| 10302 | if (data == NULL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10303 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, "buffer == 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10304 | return false; |
| 10305 | } |
| 10306 | // We only support one async transfer in progress. |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10307 | if (!texture_ref || |
| 10308 | async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10309 | LOCAL_SET_GL_ERROR( |
| 10310 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10311 | function_name, "transfer already in progress"); |
| 10312 | return false; |
| 10313 | } |
| 10314 | return true; |
| 10315 | } |
| 10316 | |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10317 | error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10318 | uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) { |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10319 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10320 | GLenum target = static_cast<GLenum>(c.target); |
| 10321 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10322 | // TODO(kloveless): Change HandleAsyncTexImage2DCHROMIUM command to use |
| 10323 | // unsigned integer for internalformat. |
| 10324 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10325 | GLsizei width = static_cast<GLsizei>(c.width); |
| 10326 | GLsizei height = static_cast<GLsizei>(c.height); |
| 10327 | GLint border = static_cast<GLint>(c.border); |
| 10328 | GLenum format = static_cast<GLenum>(c.format); |
| 10329 | GLenum type = static_cast<GLenum>(c.type); |
| 10330 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 10331 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
| 10332 | uint32 pixels_size; |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10333 | |
| 10334 | // TODO(epenner): Move this and copies of this memory validation |
| 10335 | // into ValidateTexImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10336 | if (!GLES2Util::ComputeImageDataSizes( |
| 10337 | width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, |
| 10338 | NULL)) { |
| 10339 | return error::kOutOfBounds; |
| 10340 | } |
| 10341 | const void* pixels = NULL; |
| 10342 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 10343 | pixels = GetSharedMemoryAs<const void*>( |
| 10344 | pixels_shm_id, pixels_shm_offset, pixels_size); |
| 10345 | if (!pixels) { |
| 10346 | return error::kOutOfBounds; |
| 10347 | } |
| 10348 | } |
| 10349 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10350 | TextureManager::DoTextImage2DArguments args = { |
| 10351 | target, level, internal_format, width, height, border, format, type, |
| 10352 | pixels, pixels_size}; |
| 10353 | TextureRef* texture_ref; |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10354 | // All the normal glTexSubImage2D validation. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10355 | if (!texture_manager()->ValidateTexImage2D( |
| 10356 | &state_, "glAsyncTexImage2DCHROMIUM", args, &texture_ref)) { |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10357 | return error::kNoError; |
| 10358 | } |
| 10359 | |
| 10360 | // Extra async validation. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10361 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10362 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10363 | "glAsyncTexImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10364 | return error::kNoError; |
| 10365 | |
| 10366 | // Don't allow async redefinition of a textures. |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10367 | if (texture->IsDefined()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10368 | LOCAL_SET_GL_ERROR( |
| 10369 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10370 | "glAsyncTexImage2DCHROMIUM", "already defined"); |
| 10371 | return error::kNoError; |
| 10372 | } |
| 10373 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10374 | if (!EnsureGPUMemoryAvailable(pixels_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10375 | LOCAL_SET_GL_ERROR( |
| 10376 | GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10377 | return error::kNoError; |
| 10378 | } |
| 10379 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10380 | // We know the memory/size is safe, so get the real shared memory since |
| 10381 | // 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] | 10382 | gpu::Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10383 | base::SharedMemory* shared_memory = buffer.shared_memory; |
| 10384 | uint32 shm_size = buffer.size; |
| 10385 | uint32 shm_data_offset = c.pixels_shm_offset; |
| 10386 | uint32 shm_data_size = pixels_size; |
| 10387 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10388 | // Setup the parameters. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 10389 | AsyncTexImage2DParams tex_params = { |
| 10390 | target, level, static_cast<GLenum>(internal_format), |
| 10391 | width, height, border, format, type}; |
| 10392 | AsyncMemoryParams mem_params = { |
| 10393 | shared_memory, shm_size, shm_data_offset, shm_data_size}; |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10394 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10395 | // Set up the async state if needed, and make the texture |
| 10396 | // immutable so the async state stays valid. The level info |
| 10397 | // is set up lazily when the transfer completes. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10398 | AsyncPixelTransferDelegate* delegate = |
| 10399 | async_pixel_transfer_manager_->CreatePixelTransferDelegate(texture_ref, |
| 10400 | tex_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10401 | texture->SetImmutable(true); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10402 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10403 | delegate->AsyncTexImage2D( |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10404 | tex_params, |
| 10405 | mem_params, |
| 10406 | base::Bind(&TextureManager::SetLevelInfoFromParams, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10407 | // The callback is only invoked if the transfer delegate still |
| 10408 | // exists, which implies through manager->texture_ref->state |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10409 | // ownership that both of these pointers are valid. |
| 10410 | base::Unretained(texture_manager()), |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10411 | base::Unretained(texture_ref), |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10412 | tex_params)); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10413 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10414 | } |
| 10415 | |
| 10416 | error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10417 | uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) { |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10418 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10419 | GLenum target = static_cast<GLenum>(c.target); |
| 10420 | GLint level = static_cast<GLint>(c.level); |
| 10421 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 10422 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 10423 | GLsizei width = static_cast<GLsizei>(c.width); |
| 10424 | GLsizei height = static_cast<GLsizei>(c.height); |
| 10425 | GLenum format = static_cast<GLenum>(c.format); |
| 10426 | GLenum type = static_cast<GLenum>(c.type); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10427 | |
| 10428 | // TODO(epenner): Move this and copies of this memory validation |
| 10429 | // into ValidateTexSubImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10430 | uint32 data_size; |
| 10431 | if (!GLES2Util::ComputeImageDataSizes( |
| 10432 | width, height, format, type, state_.unpack_alignment, &data_size, |
| 10433 | NULL, NULL)) { |
| 10434 | return error::kOutOfBounds; |
| 10435 | } |
| 10436 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 10437 | c.data_shm_id, c.data_shm_offset, data_size); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10438 | |
| 10439 | // All the normal glTexSubImage2D validation. |
| 10440 | error::Error error = error::kNoError; |
| 10441 | if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2DCHROMIUM", |
| 10442 | target, level, xoffset, yoffset, width, height, format, type, pixels)) { |
| 10443 | return error; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10444 | } |
| 10445 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10446 | // Extra async validation. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10447 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10448 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10449 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10450 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10451 | "glAsyncTexSubImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10452 | return error::kNoError; |
| 10453 | |
| 10454 | // Guarantee async textures are always 'cleared' as follows: |
| 10455 | // - AsyncTexImage2D can not redefine an existing texture |
| 10456 | // - AsyncTexImage2D must initialize the entire image via non-null buffer. |
| 10457 | // - AsyncTexSubImage2D clears synchronously if not already cleared. |
| 10458 | // - Textures become immutable after an async call. |
| 10459 | // 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] | 10460 | if (!texture->SafeToRenderFrom()) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10461 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, |
| 10462 | target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10463 | LOCAL_SET_GL_ERROR( |
| 10464 | GL_OUT_OF_MEMORY, |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 10465 | "glAsyncTexSubImage2DCHROMIUM", "dimensions too big"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10466 | return error::kNoError; |
| 10467 | } |
| 10468 | } |
| 10469 | |
| 10470 | // We know the memory/size is safe, so get the real shared memory since |
| 10471 | // 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] | 10472 | gpu::Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10473 | base::SharedMemory* shared_memory = buffer.shared_memory; |
| 10474 | uint32 shm_size = buffer.size; |
| 10475 | uint32 shm_data_offset = c.data_shm_offset; |
| 10476 | uint32 shm_data_size = data_size; |
| 10477 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10478 | // Setup the parameters. |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 10479 | AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10480 | width, height, format, type}; |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 10481 | AsyncMemoryParams mem_params = {shared_memory, shm_size, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10482 | shm_data_offset, shm_data_size}; |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10483 | AsyncPixelTransferDelegate* delegate = |
| 10484 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 10485 | if (!delegate) { |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10486 | // TODO(epenner): We may want to enforce exclusive use |
| 10487 | // of async APIs in which case this should become an error, |
| 10488 | // (the texture should have been async defined). |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 10489 | AsyncTexImage2DParams define_params = {target, level, |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10490 | 0, 0, 0, 0, 0, 0}; |
| 10491 | texture->GetLevelSize(target, level, &define_params.width, |
| 10492 | &define_params.height); |
| 10493 | texture->GetLevelType(target, level, &define_params.type, |
| 10494 | &define_params.internal_format); |
| 10495 | // Set up the async state if needed, and make the texture |
| 10496 | // immutable so the async state stays valid. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10497 | delegate = async_pixel_transfer_manager_->CreatePixelTransferDelegate( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10498 | texture_ref, define_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 10499 | texture->SetImmutable(true); |
| 10500 | } |
| 10501 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10502 | delegate->AsyncTexSubImage2D(tex_params, mem_params); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10503 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10504 | } |
| 10505 | |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 10506 | error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM( |
| 10507 | uint32 immediate_data_size, const cmds::WaitAsyncTexImage2DCHROMIUM& c) { |
| 10508 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); |
| 10509 | GLenum target = static_cast<GLenum>(c.target); |
| 10510 | |
| 10511 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10512 | LOCAL_SET_GL_ERROR( |
| 10513 | GL_INVALID_ENUM, "glWaitAsyncTexImage2DCHROMIUM", "target"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 10514 | return error::kNoError; |
| 10515 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10516 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10517 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10518 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10519 | LOCAL_SET_GL_ERROR( |
| 10520 | GL_INVALID_OPERATION, |
| 10521 | "glWaitAsyncTexImage2DCHROMIUM", "unknown texture"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 10522 | return error::kNoError; |
| 10523 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10524 | AsyncPixelTransferDelegate* delegate = |
| 10525 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 10526 | if (!delegate) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10527 | LOCAL_SET_GL_ERROR( |
| 10528 | GL_INVALID_OPERATION, |
| 10529 | "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); |
| 10530 | return error::kNoError; |
| 10531 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 10532 | delegate->WaitForTransferCompletion(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 10533 | ProcessFinishedAsyncTransfers(); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 10534 | return error::kNoError; |
| 10535 | } |
| 10536 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 10537 | void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( |
| 10538 | TextureRef* texture_ref) { |
| 10539 | Texture* texture = texture_ref->texture(); |
| 10540 | DoDidUseTexImageIfNeeded(texture, texture->target()); |
| 10541 | } |
| 10542 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 10543 | // Include the auto-generated part of this file. We split this because it means |
| 10544 | // we can easily edit the non-auto generated parts right here in this file |
| 10545 | // instead of having to edit some template or the code generator. |
| 10546 | #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 10547 | |
| 10548 | } // namespace gles2 |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 10549 | } // namespace gpu |