[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] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 18 | #include "base/callback_helpers.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 19 | #include "base/command_line.h" |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 20 | #include "base/debug/trace_event.h" |
[email protected] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 21 | #include "base/debug/trace_event_synthetic_delay.h" |
[email protected] | 5aa95ac | 2014-08-14 15:20:56 | [diff] [blame] | 22 | #include "base/float_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 23 | #include "base/memory/scoped_ptr.h" |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 24 | #include "base/numerics/safe_math.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 25 | #include "base/strings/string_number_conversions.h" |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 26 | #include "base/strings/string_split.h" |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 27 | #include "build/build_config.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 28 | #define GLES2_GPU_SERVICE 1 |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 29 | #include "gpu/command_buffer/common/debug_marker_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 30 | #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 31 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 32 | #include "gpu/command_buffer/common/id_allocator.h" |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 33 | #include "gpu/command_buffer/common/mailbox.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 34 | #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
| 35 | #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 36 | #include "gpu/command_buffer/service/buffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 37 | #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 38 | #include "gpu/command_buffer/service/context_group.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 39 | #include "gpu/command_buffer/service/context_state.h" |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 40 | #include "gpu/command_buffer/service/error_state.h" |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 41 | #include "gpu/command_buffer/service/feature_info.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 42 | #include "gpu/command_buffer/service/framebuffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 43 | #include "gpu/command_buffer/service/gl_utils.h" |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 44 | #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 45 | #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 46 | #include "gpu/command_buffer/service/gpu_state_tracer.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 47 | #include "gpu/command_buffer/service/gpu_switches.h" |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 48 | #include "gpu/command_buffer/service/gpu_tracer.h" |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 49 | #include "gpu/command_buffer/service/image_manager.h" |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 50 | #include "gpu/command_buffer/service/mailbox_manager.h" |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 51 | #include "gpu/command_buffer/service/memory_tracking.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 52 | #include "gpu/command_buffer/service/program_manager.h" |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 53 | #include "gpu/command_buffer/service/query_manager.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 54 | #include "gpu/command_buffer/service/renderbuffer_manager.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 55 | #include "gpu/command_buffer/service/shader_manager.h" |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 56 | #include "gpu/command_buffer/service/shader_translator.h" |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 57 | #include "gpu/command_buffer/service/shader_translator_cache.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 58 | #include "gpu/command_buffer/service/texture_manager.h" |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 59 | #include "gpu/command_buffer/service/vertex_array_manager.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 60 | #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
[email protected] | 6896d7f | 2014-04-28 20:24:15 | [diff] [blame] | 61 | #include "third_party/smhasher/src/City.h" |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 62 | #include "ui/gl/gl_fence.h" |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 63 | #include "ui/gl/gl_image.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 64 | #include "ui/gl/gl_implementation.h" |
| 65 | #include "ui/gl/gl_surface.h" |
[email protected] | 423e644f | 2013-06-19 00:48:27 | [diff] [blame] | 66 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 67 | #if defined(OS_MACOSX) |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 68 | #include <IOSurface/IOSurfaceAPI.h> |
| 69 | // Note that this must be included after gl_bindings.h to avoid conflicts. |
| 70 | #include <OpenGL/CGLIOSurface.h> |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 71 | #endif |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 72 | |
[email protected] | 6eb77535 | 2013-08-27 05:57:16 | [diff] [blame] | 73 | #if defined(OS_WIN) |
| 74 | #include "base/win/win_util.h" |
| 75 | #endif |
| 76 | |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 77 | namespace gpu { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 78 | namespace gles2 { |
| 79 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 80 | namespace { |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 81 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 82 | static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 83 | static const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 84 | static const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 85 | static const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 86 | |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 87 | static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, |
| 88 | GLint rangeMax, |
| 89 | GLint precision) { |
| 90 | return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); |
| 91 | } |
| 92 | |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 93 | static void GetShaderPrecisionFormatImpl(GLenum shader_type, |
| 94 | GLenum precision_type, |
| 95 | GLint *range, GLint *precision) { |
| 96 | switch (precision_type) { |
| 97 | case GL_LOW_INT: |
| 98 | case GL_MEDIUM_INT: |
| 99 | case GL_HIGH_INT: |
| 100 | // These values are for a 32-bit twos-complement integer format. |
| 101 | range[0] = 31; |
| 102 | range[1] = 30; |
| 103 | *precision = 0; |
| 104 | break; |
| 105 | case GL_LOW_FLOAT: |
| 106 | case GL_MEDIUM_FLOAT: |
| 107 | case GL_HIGH_FLOAT: |
| 108 | // These values are for an IEEE single-precision floating-point format. |
| 109 | range[0] = 127; |
| 110 | range[1] = 127; |
| 111 | *precision = 23; |
| 112 | break; |
| 113 | default: |
| 114 | NOTREACHED(); |
| 115 | break; |
| 116 | } |
| 117 | |
[email protected] | 8af4d5e | 2013-03-15 23:55:33 | [diff] [blame] | 118 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
| 119 | gfx::g_driver_gl.fn.glGetShaderPrecisionFormatFn) { |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 120 | // This function is sometimes defined even though it's really just |
| 121 | // a stub, so we need to set range and precision as if it weren't |
| 122 | // defined before calling it. |
[email protected] | 501b5740 | 2013-03-14 22:21:44 | [diff] [blame] | 123 | // On Mac OS with some GPUs, calling this generates a |
| 124 | // GL_INVALID_OPERATION error. Avoid calling it on non-GLES2 |
| 125 | // platforms. |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 126 | glGetShaderPrecisionFormat(shader_type, precision_type, |
| 127 | range, precision); |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 128 | |
| 129 | // TODO(brianderson): Make the following official workarounds. |
| 130 | |
| 131 | // Some drivers have bugs where they report the ranges as a negative number. |
| 132 | // Taking the absolute value here shouldn't hurt because negative numbers |
| 133 | // aren't expected anyway. |
| 134 | range[0] = abs(range[0]); |
| 135 | range[1] = abs(range[1]); |
| 136 | |
| 137 | // If the driver reports a precision for highp float that isn't actually |
| 138 | // highp, don't pretend like it's supported because shader compilation will |
| 139 | // fail anyway. |
| 140 | if (precision_type == GL_HIGH_FLOAT && |
| 141 | !PrecisionMeetsSpecForHighpFloat(range[0], range[1], *precision)) { |
| 142 | range[0] = 0; |
| 143 | range[1] = 0; |
| 144 | *precision = 0; |
| 145 | } |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
[email protected] | d286ebbc | 2014-07-03 17:19:10 | [diff] [blame] | 149 | static gfx::OverlayTransform GetGFXOverlayTransform(GLenum plane_transform) { |
| 150 | switch (plane_transform) { |
| 151 | case GL_OVERLAY_TRANSFORM_NONE_CHROMIUM: |
| 152 | return gfx::OVERLAY_TRANSFORM_NONE; |
| 153 | case GL_OVERLAY_TRANSFORM_FLIP_HORIZONTAL_CHROMIUM: |
| 154 | return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; |
| 155 | case GL_OVERLAY_TRANSFORM_FLIP_VERTICAL_CHROMIUM: |
| 156 | return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL; |
| 157 | case GL_OVERLAY_TRANSFORM_ROTATE_90_CHROMIUM: |
| 158 | return gfx::OVERLAY_TRANSFORM_ROTATE_90; |
| 159 | case GL_OVERLAY_TRANSFORM_ROTATE_180_CHROMIUM: |
| 160 | return gfx::OVERLAY_TRANSFORM_ROTATE_180; |
| 161 | case GL_OVERLAY_TRANSFORM_ROTATE_270_CHROMIUM: |
| 162 | return gfx::OVERLAY_TRANSFORM_ROTATE_270; |
| 163 | default: |
| 164 | return gfx::OVERLAY_TRANSFORM_INVALID; |
| 165 | } |
| 166 | } |
| 167 | |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 168 | } // namespace |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 169 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 170 | class GLES2DecoderImpl; |
| 171 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 172 | // Local versions of the SET_GL_ERROR macros |
| 173 | #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 174 | ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 175 | #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 176 | ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \ |
| 177 | function_name, value, label) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 178 | #define LOCAL_SET_GL_ERROR_INVALID_PARAM(error, function_name, pname) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 179 | ERRORSTATE_SET_GL_ERROR_INVALID_PARAM(state_.GetErrorState(), error, \ |
| 180 | function_name, pname) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 181 | #define LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 182 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(state_.GetErrorState(), \ |
| 183 | function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 184 | #define LOCAL_PEEK_GL_ERROR(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 185 | ERRORSTATE_PEEK_GL_ERROR(state_.GetErrorState(), function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 186 | #define LOCAL_CLEAR_REAL_GL_ERRORS(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 187 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(state_.GetErrorState(), function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 188 | #define LOCAL_PERFORMANCE_WARNING(msg) \ |
| 189 | PerformanceWarning(__FILE__, __LINE__, msg) |
| 190 | #define LOCAL_RENDER_WARNING(msg) \ |
| 191 | RenderWarning(__FILE__, __LINE__, msg) |
| 192 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 193 | // Check that certain assumptions the code makes are true. There are places in |
| 194 | // the code where shared memory is passed direclty to GL. Example, glUniformiv, |
| 195 | // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe |
| 196 | // a few others) are 32bits. If they are not 32bits the code will have to change |
| 197 | // to call those GL functions with service side memory and then copy the results |
| 198 | // to shared memory, converting the sizes. |
| 199 | COMPILE_ASSERT(sizeof(GLint) == sizeof(uint32), // NOLINT |
| 200 | GLint_not_same_size_as_uint32); |
| 201 | COMPILE_ASSERT(sizeof(GLsizei) == sizeof(uint32), // NOLINT |
| 202 | GLint_not_same_size_as_uint32); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 203 | COMPILE_ASSERT(sizeof(GLfloat) == sizeof(float), // NOLINT |
| 204 | GLfloat_not_same_size_as_float); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 205 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 206 | // TODO(kbr): the use of this anonymous namespace core dumps the |
| 207 | // linker on Mac OS X 10.6 when the symbol ordering file is used |
| 208 | // namespace { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 209 | |
| 210 | // Returns the address of the first byte after a struct. |
| 211 | template <typename T> |
| 212 | const void* AddressAfterStruct(const T& pod) { |
| 213 | return reinterpret_cast<const uint8*>(&pod) + sizeof(pod); |
| 214 | } |
| 215 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 216 | // Returns the address of the frst byte after the struct or NULL if size > |
| 217 | // immediate_data_size. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 218 | template <typename RETURN_TYPE, typename COMMAND_TYPE> |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 219 | RETURN_TYPE GetImmediateDataAs(const COMMAND_TYPE& pod, |
| 220 | uint32 size, |
| 221 | uint32 immediate_data_size) { |
| 222 | return (size <= immediate_data_size) ? |
| 223 | static_cast<RETURN_TYPE>(const_cast<void*>(AddressAfterStruct(pod))) : |
| 224 | NULL; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 225 | } |
| 226 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 227 | // Computes the data size for certain gl commands like glUniform. |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 228 | bool ComputeDataSize( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 229 | GLuint count, |
| 230 | size_t size, |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 231 | unsigned int elements_per_unit, |
| 232 | uint32* dst) { |
| 233 | uint32 value; |
| 234 | if (!SafeMultiplyUint32(count, size, &value)) { |
| 235 | return false; |
| 236 | } |
| 237 | if (!SafeMultiplyUint32(value, elements_per_unit, &value)) { |
| 238 | return false; |
| 239 | } |
| 240 | *dst = value; |
| 241 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 242 | } |
| 243 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 244 | // Return true if a character belongs to the ASCII subset as defined in |
| 245 | // GLSL ES 1.0 spec section 3.1. |
| 246 | static bool CharacterIsValidForGLES(unsigned char c) { |
| 247 | // Printing characters are valid except " $ ` @ \ ' DEL. |
| 248 | if (c >= 32 && c <= 126 && |
| 249 | c != '"' && |
| 250 | c != '$' && |
| 251 | c != '`' && |
| 252 | c != '@' && |
| 253 | c != '\\' && |
| 254 | c != '\'') { |
| 255 | return true; |
| 256 | } |
| 257 | // Horizontal tab, line feed, vertical tab, form feed, carriage return |
| 258 | // are also valid. |
| 259 | if (c >= 9 && c <= 13) { |
| 260 | return true; |
| 261 | } |
| 262 | |
| 263 | return false; |
| 264 | } |
| 265 | |
| 266 | static bool StringIsValidForGLES(const char* str) { |
| 267 | for (; *str; ++str) { |
| 268 | if (!CharacterIsValidForGLES(*str)) { |
| 269 | return false; |
| 270 | } |
| 271 | } |
| 272 | return true; |
| 273 | } |
| 274 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 275 | // This class prevents any GL errors that occur when it is in scope from |
| 276 | // being reported to the client. |
| 277 | class ScopedGLErrorSuppressor { |
| 278 | public: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 279 | explicit ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 280 | const char* function_name, ErrorState* error_state); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 281 | ~ScopedGLErrorSuppressor(); |
| 282 | private: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 283 | const char* function_name_; |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 284 | ErrorState* error_state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 285 | DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); |
| 286 | }; |
| 287 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 288 | // Temporarily changes a decoder's bound texture and restore it when this |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 289 | // object goes out of scope. Also temporarily switches to using active texture |
| 290 | // unit zero in case the client has changed that to something invalid. |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 291 | class ScopedTextureBinder { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 292 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 293 | explicit ScopedTextureBinder(ContextState* state, GLuint id, GLenum target); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 294 | ~ScopedTextureBinder(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 295 | |
| 296 | private: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 297 | ContextState* state_; |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 298 | GLenum target_; |
| 299 | DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 300 | }; |
| 301 | |
| 302 | // Temporarily changes a decoder's bound render buffer and restore it when this |
| 303 | // object goes out of scope. |
| 304 | class ScopedRenderBufferBinder { |
| 305 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 306 | explicit ScopedRenderBufferBinder(ContextState* state, GLuint id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 307 | ~ScopedRenderBufferBinder(); |
| 308 | |
| 309 | private: |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 310 | ContextState* state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 311 | DISALLOW_COPY_AND_ASSIGN(ScopedRenderBufferBinder); |
| 312 | }; |
| 313 | |
| 314 | // Temporarily changes a decoder's bound frame buffer and restore it when this |
| 315 | // object goes out of scope. |
| 316 | class ScopedFrameBufferBinder { |
| 317 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 318 | explicit ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 319 | ~ScopedFrameBufferBinder(); |
| 320 | |
| 321 | private: |
| 322 | GLES2DecoderImpl* decoder_; |
| 323 | DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); |
| 324 | }; |
| 325 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 326 | // Temporarily changes a decoder's bound frame buffer to a resolved version of |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 327 | // the multisampled offscreen render buffer if that buffer is multisampled, and, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 328 | // if it is bound or enforce_internal_framebuffer is true. If internal is |
| 329 | // true, the resolved framebuffer is not visible to the parent. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 330 | class ScopedResolvedFrameBufferBinder { |
| 331 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 332 | explicit ScopedResolvedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 333 | bool enforce_internal_framebuffer, |
| 334 | bool internal); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 335 | ~ScopedResolvedFrameBufferBinder(); |
| 336 | |
| 337 | private: |
| 338 | GLES2DecoderImpl* decoder_; |
| 339 | bool resolve_and_bind_; |
| 340 | DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); |
| 341 | }; |
| 342 | |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 343 | class ScopedModifyPixels { |
| 344 | public: |
| 345 | explicit ScopedModifyPixels(TextureRef* ref); |
| 346 | ~ScopedModifyPixels(); |
| 347 | |
| 348 | private: |
| 349 | TextureRef* ref_; |
| 350 | }; |
| 351 | |
| 352 | ScopedModifyPixels::ScopedModifyPixels(TextureRef* ref) : ref_(ref) { |
| 353 | if (ref_) |
| 354 | ref_->texture()->OnWillModifyPixels(); |
| 355 | } |
| 356 | |
| 357 | ScopedModifyPixels::~ScopedModifyPixels() { |
| 358 | if (ref_) |
| 359 | ref_->texture()->OnDidModifyPixels(); |
| 360 | } |
| 361 | |
| 362 | class ScopedRenderTo { |
| 363 | public: |
| 364 | explicit ScopedRenderTo(Framebuffer* framebuffer); |
| 365 | ~ScopedRenderTo(); |
| 366 | |
| 367 | private: |
| 368 | const Framebuffer* framebuffer_; |
| 369 | }; |
| 370 | |
| 371 | ScopedRenderTo::ScopedRenderTo(Framebuffer* framebuffer) |
| 372 | : framebuffer_(framebuffer) { |
| 373 | if (framebuffer) |
| 374 | framebuffer_->OnWillRenderTo(); |
| 375 | } |
| 376 | |
| 377 | ScopedRenderTo::~ScopedRenderTo() { |
| 378 | if (framebuffer_) |
| 379 | framebuffer_->OnDidRenderTo(); |
| 380 | } |
| 381 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 382 | // Encapsulates an OpenGL texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 383 | class BackTexture { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 384 | public: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 385 | explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 386 | ~BackTexture(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 387 | |
| 388 | // Create a new render texture. |
| 389 | void Create(); |
| 390 | |
| 391 | // Set the initial size and format of a render texture or resize it. |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 392 | bool AllocateStorage(const gfx::Size& size, GLenum format, bool zero); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 393 | |
| 394 | // Copy the contents of the currently bound frame buffer. |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 395 | void Copy(const gfx::Size& size, GLenum format); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 396 | |
| 397 | // Destroy the render texture. This must be explicitly called before |
| 398 | // destroying this object. |
| 399 | void Destroy(); |
| 400 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 401 | // Invalidate the texture. This can be used when a context is lost and it is |
| 402 | // not possible to make it current in order to free the resource. |
| 403 | void Invalidate(); |
| 404 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 405 | GLuint id() const { |
| 406 | return id_; |
| 407 | } |
| 408 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 409 | gfx::Size size() const { |
| 410 | return size_; |
| 411 | } |
| 412 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 413 | private: |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 414 | MemoryTypeTracker memory_tracker_; |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 415 | ContextState* state_; |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 416 | size_t bytes_allocated_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 417 | GLuint id_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 418 | gfx::Size size_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 419 | DISALLOW_COPY_AND_ASSIGN(BackTexture); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 420 | }; |
| 421 | |
| 422 | // Encapsulates an OpenGL render buffer of any format. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 423 | class BackRenderbuffer { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 424 | public: |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 425 | explicit BackRenderbuffer( |
| 426 | RenderbufferManager* renderbuffer_manager, |
| 427 | MemoryTracker* memory_tracker, |
| 428 | ContextState* state); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 429 | ~BackRenderbuffer(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 430 | |
| 431 | // Create a new render buffer. |
| 432 | void Create(); |
| 433 | |
| 434 | // Set the initial size and format of a render buffer or resize it. |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 435 | bool AllocateStorage(const FeatureInfo* feature_info, |
| 436 | const gfx::Size& size, |
| 437 | GLenum format, |
| 438 | GLsizei samples); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 439 | |
| 440 | // Destroy the render buffer. This must be explicitly called before destroying |
| 441 | // this object. |
| 442 | void Destroy(); |
| 443 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 444 | // Invalidate the render buffer. This can be used when a context is lost and |
| 445 | // it is not possible to make it current in order to free the resource. |
| 446 | void Invalidate(); |
| 447 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 448 | GLuint id() const { |
| 449 | return id_; |
| 450 | } |
| 451 | |
| 452 | private: |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 453 | RenderbufferManager* renderbuffer_manager_; |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 454 | MemoryTypeTracker memory_tracker_; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 455 | ContextState* state_; |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 456 | size_t bytes_allocated_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 457 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 458 | DISALLOW_COPY_AND_ASSIGN(BackRenderbuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 459 | }; |
| 460 | |
| 461 | // Encapsulates an OpenGL frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 462 | class BackFramebuffer { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 463 | public: |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 464 | explicit BackFramebuffer(GLES2DecoderImpl* decoder); |
| 465 | ~BackFramebuffer(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 466 | |
| 467 | // Create a new frame buffer. |
| 468 | void Create(); |
| 469 | |
| 470 | // Attach a color render buffer to a frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 471 | void AttachRenderTexture(BackTexture* texture); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 472 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 473 | // Attach a render buffer to a frame buffer. Note that this unbinds any |
| 474 | // currently bound frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 475 | void AttachRenderBuffer(GLenum target, BackRenderbuffer* render_buffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 476 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 477 | // Destroy the frame buffer. This must be explicitly called before destroying |
| 478 | // this object. |
| 479 | void Destroy(); |
| 480 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 481 | // Invalidate the frame buffer. This can be used when a context is lost and it |
| 482 | // is not possible to make it current in order to free the resource. |
| 483 | void Invalidate(); |
| 484 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 485 | // See glCheckFramebufferStatusEXT. |
| 486 | GLenum CheckStatus(); |
| 487 | |
| 488 | GLuint id() const { |
| 489 | return id_; |
| 490 | } |
| 491 | |
| 492 | private: |
| 493 | GLES2DecoderImpl* decoder_; |
| 494 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 495 | DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 496 | }; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 497 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 498 | struct FenceCallback { |
| 499 | explicit FenceCallback() |
| 500 | : fence(gfx::GLFence::Create()) { |
| 501 | DCHECK(fence); |
| 502 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 503 | std::vector<base::Closure> callbacks; |
| 504 | scoped_ptr<gfx::GLFence> fence; |
| 505 | }; |
| 506 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 507 | class AsyncUploadTokenCompletionObserver |
| 508 | : public AsyncPixelTransferCompletionObserver { |
| 509 | public: |
| 510 | explicit AsyncUploadTokenCompletionObserver(uint32 async_upload_token) |
| 511 | : async_upload_token_(async_upload_token) { |
| 512 | } |
| 513 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 514 | virtual void DidComplete(const AsyncMemoryParams& mem_params) override { |
dcheng | 6ef3c555 | 2014-08-30 05:34:19 | [diff] [blame] | 515 | DCHECK(mem_params.buffer().get()); |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 516 | void* data = mem_params.GetDataAddress(); |
| 517 | AsyncUploadSync* sync = static_cast<AsyncUploadSync*>(data); |
| 518 | sync->SetAsyncUploadToken(async_upload_token_); |
| 519 | } |
| 520 | |
| 521 | private: |
| 522 | virtual ~AsyncUploadTokenCompletionObserver() { |
| 523 | } |
| 524 | |
| 525 | uint32 async_upload_token_; |
| 526 | |
| 527 | DISALLOW_COPY_AND_ASSIGN(AsyncUploadTokenCompletionObserver); |
| 528 | }; |
| 529 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 530 | // } // anonymous namespace. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 531 | |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 532 | // static |
| 533 | const unsigned int GLES2Decoder::kDefaultStencilMask = |
| 534 | static_cast<unsigned int>(-1); |
| 535 | |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 536 | bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, |
| 537 | uint32* service_texture_id) { |
| 538 | return false; |
| 539 | } |
| 540 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 541 | GLES2Decoder::GLES2Decoder() |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 542 | : initialized_(false), |
| 543 | debug_(false), |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 544 | log_commands_(false) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 545 | } |
| 546 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 547 | GLES2Decoder::~GLES2Decoder() { |
| 548 | } |
| 549 | |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 550 | void GLES2Decoder::BeginDecoding() {} |
| 551 | |
| 552 | void GLES2Decoder::EndDecoding() {} |
| 553 | |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 554 | // This class implements GLES2Decoder so we don't have to expose all the GLES2 |
| 555 | // cmd stuff to outside this class. |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 556 | class GLES2DecoderImpl : public GLES2Decoder, |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 557 | public FramebufferManager::TextureDetachObserver, |
| 558 | public ErrorStateClient { |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 559 | public: |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 560 | explicit GLES2DecoderImpl(ContextGroup* group); |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 561 | virtual ~GLES2DecoderImpl(); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 562 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 563 | // Overridden from AsyncAPIInterface. |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 564 | virtual Error DoCommand(unsigned int command, |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 565 | unsigned int arg_count, |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 566 | const void* args) override; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 567 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 568 | virtual error::Error DoCommands(unsigned int num_commands, |
| 569 | const void* buffer, |
| 570 | int num_entries, |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 571 | int* entries_processed) override; |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 572 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 573 | template <bool DebugImpl> |
| 574 | error::Error DoCommandsImpl(unsigned int num_commands, |
| 575 | const void* buffer, |
| 576 | int num_entries, |
| 577 | int* entries_processed); |
| 578 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 579 | // Overridden from AsyncAPIInterface. |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 580 | virtual const char* GetCommandName(unsigned int command_id) const override; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 581 | |
| 582 | // Overridden from GLES2Decoder. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 583 | virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
| 584 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 585 | bool offscreen, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 586 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 587 | const DisallowedFeatures& disallowed_features, |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 588 | const std::vector<int32>& attribs) override; |
| 589 | virtual void Destroy(bool have_context) override; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 590 | virtual void SetSurface( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 591 | const scoped_refptr<gfx::GLSurface>& surface) override; |
| 592 | virtual void ProduceFrontBuffer(const Mailbox& mailbox) override; |
| 593 | virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 594 | void UpdateParentTextureInfo(); |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 595 | virtual bool MakeCurrent() override; |
| 596 | virtual GLES2Util* GetGLES2Util() override { return &util_; } |
| 597 | virtual gfx::GLContext* GetGLContext() override { return context_.get(); } |
| 598 | virtual ContextGroup* GetContextGroup() override { return group_.get(); } |
| 599 | virtual Capabilities GetCapabilities() override; |
| 600 | virtual void RestoreState(const ContextState* prev_state) override; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 601 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 602 | virtual void RestoreActiveTexture() const override { |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 603 | state_.RestoreActiveTexture(); |
| 604 | } |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 605 | virtual void RestoreAllTextureUnitBindings( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 606 | const ContextState* prev_state) const override { |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 607 | state_.RestoreAllTextureUnitBindings(prev_state); |
[email protected] | 21700451 | 2013-05-10 21:25:55 | [diff] [blame] | 608 | } |
[email protected] | 4b2d2b26 | 2014-03-21 22:05:27 | [diff] [blame] | 609 | virtual void RestoreActiveTextureUnitBinding( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 610 | unsigned int target) const override { |
[email protected] | 4b2d2b26 | 2014-03-21 22:05:27 | [diff] [blame] | 611 | state_.RestoreActiveTextureUnitBinding(target); |
| 612 | } |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 613 | virtual void RestoreBufferBindings() const override { |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 614 | state_.RestoreBufferBindings(); |
| 615 | } |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 616 | virtual void RestoreGlobalState() const override { |
[email protected] | 88ba52f | 2014-04-09 12:39:34 | [diff] [blame] | 617 | state_.RestoreGlobalState(NULL); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 618 | } |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 619 | virtual void RestoreProgramBindings() const override { |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 620 | state_.RestoreProgramBindings(); |
| 621 | } |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 622 | virtual void RestoreTextureUnitBindings(unsigned unit) const override { |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 623 | state_.RestoreTextureUnitBindings(unit, NULL); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 624 | } |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 625 | virtual void RestoreFramebufferBindings() const override; |
| 626 | virtual void RestoreRenderbufferBindings() override; |
| 627 | virtual void RestoreTextureState(unsigned service_id) const override; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 628 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 629 | virtual void ClearAllAttributes() const override; |
| 630 | virtual void RestoreAllAttributes() const override; |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 631 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 632 | virtual QueryManager* GetQueryManager() override { |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 633 | return query_manager_.get(); |
| 634 | } |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 635 | virtual VertexArrayManager* GetVertexArrayManager() override { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 636 | return vertex_array_manager_.get(); |
| 637 | } |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 638 | virtual ImageManager* GetImageManager() override { |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 639 | return image_manager_.get(); |
| 640 | } |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 641 | virtual bool ProcessPendingQueries() override; |
| 642 | virtual bool HasMoreIdleWork() override; |
| 643 | virtual void PerformIdleWork() override; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 644 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 645 | virtual void WaitForReadPixels(base::Closure callback) override; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 646 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 647 | virtual void SetResizeCallback( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 648 | const base::Callback<void(gfx::Size, float)>& callback) override; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 649 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 650 | virtual Logger* GetLogger() override; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 651 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 652 | virtual void BeginDecoding() override; |
| 653 | virtual void EndDecoding() override; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 654 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 655 | virtual ErrorState* GetErrorState() override; |
| 656 | virtual const ContextState* GetContextState() override { return &state_; } |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 657 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 658 | virtual void SetShaderCacheCallback( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 659 | const ShaderCacheCallback& callback) override; |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 660 | virtual void SetWaitSyncPointCallback( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 661 | const WaitSyncPointCallback& callback) override; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 662 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 663 | virtual AsyncPixelTransferManager* |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 664 | GetAsyncPixelTransferManager() override; |
| 665 | virtual void ResetAsyncPixelTransferManagerForTest() override; |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 666 | virtual void SetAsyncPixelTransferManagerForTest( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 667 | AsyncPixelTransferManager* manager) override; |
| 668 | virtual void SetIgnoreCachedStateForTest(bool ignore) override; |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 669 | void ProcessFinishedAsyncTransfers(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 670 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 671 | virtual bool GetServiceTextureId(uint32 client_texture_id, |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 672 | uint32* service_texture_id) override; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 673 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 674 | virtual uint32 GetTextureUploadCount() override; |
| 675 | virtual base::TimeDelta GetTotalTextureUploadTime() override; |
| 676 | virtual base::TimeDelta GetTotalProcessingCommandsTime() override; |
| 677 | virtual void AddProcessingCommandsTime(base::TimeDelta) override; |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 678 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 679 | // Restores the current state to the user's settings. |
| 680 | void RestoreCurrentFramebufferBindings(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 681 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 682 | // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
| 683 | void ApplyDirtyState(); |
| 684 | |
| 685 | // These check the state of the currently bound framebuffer or the |
| 686 | // backbuffer if no framebuffer is bound. |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 687 | // If all_draw_buffers is false, only check with COLOR_ATTACHMENT0, otherwise |
| 688 | // check with all attached and enabled color attachments. |
| 689 | bool BoundFramebufferHasColorAttachmentWithAlpha(bool all_draw_buffers); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 690 | bool BoundFramebufferHasDepthAttachment(); |
| 691 | bool BoundFramebufferHasStencilAttachment(); |
| 692 | |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 693 | virtual error::ContextLostReason GetContextLostReason() override; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 694 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 695 | // Overridden from FramebufferManager::TextureDetachObserver: |
| 696 | virtual void OnTextureRefDetachedFromFramebuffer( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 697 | TextureRef* texture) override; |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 698 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 699 | // Overriden from ErrorStateClient. |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 700 | virtual void OnOutOfMemoryError() override; |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 701 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 702 | // Ensure Renderbuffer corresponding to last DoBindRenderbuffer() is bound. |
| 703 | void EnsureRenderbufferBound(); |
| 704 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 705 | // Helpers to facilitate calling into compatible extensions. |
| 706 | static void RenderbufferStorageMultisampleHelper( |
| 707 | const FeatureInfo* feature_info, |
| 708 | GLenum target, |
| 709 | GLsizei samples, |
| 710 | GLenum internal_format, |
| 711 | GLsizei width, |
| 712 | GLsizei height); |
| 713 | |
| 714 | void BlitFramebufferHelper(GLint srcX0, |
| 715 | GLint srcY0, |
| 716 | GLint srcX1, |
| 717 | GLint srcY1, |
| 718 | GLint dstX0, |
| 719 | GLint dstY0, |
| 720 | GLint dstX1, |
| 721 | GLint dstY1, |
| 722 | GLbitfield mask, |
| 723 | GLenum filter); |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 724 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 725 | private: |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 726 | friend class ScopedFrameBufferBinder; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 727 | friend class ScopedResolvedFrameBufferBinder; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 728 | friend class BackFramebuffer; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 729 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 730 | // Initialize or re-initialize the shader translator. |
| 731 | bool InitializeShaderTranslator(); |
| 732 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 733 | void UpdateCapabilities(); |
| 734 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 735 | // Helpers for the glGen and glDelete functions. |
| 736 | bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 737 | void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 738 | bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 739 | void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 740 | bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 741 | void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 742 | bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
| 743 | void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 744 | bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
| 745 | void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 746 | bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
| 747 | void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 748 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 749 | // Helper for async upload token completion notification callback. |
| 750 | base::Closure AsyncUploadTokenCompletionClosure(uint32 async_upload_token, |
| 751 | uint32 sync_data_shm_id, |
| 752 | uint32 sync_data_shm_offset); |
| 753 | |
| 754 | |
| 755 | |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 756 | // Workarounds |
| 757 | void OnFboChanged() const; |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 758 | void OnUseFramebuffer() const; |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 759 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 760 | // TODO(gman): Cache these pointers? |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 761 | BufferManager* buffer_manager() { |
| 762 | return group_->buffer_manager(); |
| 763 | } |
| 764 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 765 | RenderbufferManager* renderbuffer_manager() { |
| 766 | return group_->renderbuffer_manager(); |
| 767 | } |
| 768 | |
| 769 | FramebufferManager* framebuffer_manager() { |
| 770 | return group_->framebuffer_manager(); |
| 771 | } |
| 772 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 773 | ProgramManager* program_manager() { |
| 774 | return group_->program_manager(); |
| 775 | } |
| 776 | |
| 777 | ShaderManager* shader_manager() { |
| 778 | return group_->shader_manager(); |
| 779 | } |
| 780 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 781 | ShaderTranslatorCache* shader_translator_cache() { |
| 782 | return group_->shader_translator_cache(); |
| 783 | } |
| 784 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 785 | const TextureManager* texture_manager() const { |
| 786 | return group_->texture_manager(); |
| 787 | } |
| 788 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 789 | TextureManager* texture_manager() { |
| 790 | return group_->texture_manager(); |
| 791 | } |
| 792 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 793 | MailboxManager* mailbox_manager() { |
| 794 | return group_->mailbox_manager(); |
| 795 | } |
| 796 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 797 | ImageManager* image_manager() { return image_manager_.get(); } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 798 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 799 | VertexArrayManager* vertex_array_manager() { |
| 800 | return vertex_array_manager_.get(); |
| 801 | } |
| 802 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 803 | MemoryTracker* memory_tracker() { |
| 804 | return group_->memory_tracker(); |
| 805 | } |
| 806 | |
| 807 | bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
| 808 | MemoryTracker* tracker = memory_tracker(); |
| 809 | if (tracker) { |
| 810 | return tracker->EnsureGPUMemoryAvailable(estimated_size); |
| 811 | } |
| 812 | return true; |
| 813 | } |
| 814 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 815 | bool IsOffscreenBufferMultisampled() const { |
| 816 | return offscreen_target_samples_ > 1; |
| 817 | } |
| 818 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 819 | // Creates a Texture for the given texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 820 | TextureRef* CreateTexture( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 821 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 822 | return texture_manager()->CreateTexture(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | // Gets the texture info for the given texture. Returns NULL if none exists. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 826 | TextureRef* GetTexture(GLuint client_id) const { |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 827 | return texture_manager()->GetTexture(client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | // Deletes the texture info for the given texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 831 | void RemoveTexture(GLuint client_id) { |
| 832 | texture_manager()->RemoveTexture(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 833 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 834 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 835 | // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| 836 | // or regular back buffer). |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 837 | gfx::Size GetBoundReadFrameBufferSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 838 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 839 | // Get the format of the currently bound frame buffer (either FBO or regular |
| 840 | // back buffer) |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 841 | GLenum GetBoundReadFrameBufferTextureType(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 842 | GLenum GetBoundReadFrameBufferInternalFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 843 | GLenum GetBoundDrawFrameBufferInternalFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 844 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 845 | // Wrapper for CompressedTexImage2D commands. |
| 846 | error::Error DoCompressedTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 847 | GLenum target, |
| 848 | GLint level, |
| 849 | GLenum internal_format, |
| 850 | GLsizei width, |
| 851 | GLsizei height, |
| 852 | GLint border, |
| 853 | GLsizei image_size, |
| 854 | const void* data); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 855 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 856 | // Wrapper for CompressedTexSubImage2D. |
| 857 | void DoCompressedTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 858 | GLenum target, |
| 859 | GLint level, |
| 860 | GLint xoffset, |
| 861 | GLint yoffset, |
| 862 | GLsizei width, |
| 863 | GLsizei height, |
| 864 | GLenum format, |
| 865 | GLsizei imageSize, |
| 866 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 867 | |
| 868 | // Wrapper for CopyTexImage2D. |
| 869 | void DoCopyTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 870 | GLenum target, |
| 871 | GLint level, |
| 872 | GLenum internal_format, |
| 873 | GLint x, |
| 874 | GLint y, |
| 875 | GLsizei width, |
| 876 | GLsizei height, |
| 877 | GLint border); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 878 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 879 | // Wrapper for SwapBuffers. |
| 880 | void DoSwapBuffers(); |
| 881 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 882 | // Wrapper for CopyTexSubImage2D. |
| 883 | void DoCopyTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 884 | GLenum target, |
| 885 | GLint level, |
| 886 | GLint xoffset, |
| 887 | GLint yoffset, |
| 888 | GLint x, |
| 889 | GLint y, |
| 890 | GLsizei width, |
| 891 | GLsizei height); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 892 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 893 | // Validation for TexSubImage2D. |
| 894 | bool ValidateTexSubImage2D( |
| 895 | error::Error* error, |
| 896 | const char* function_name, |
| 897 | GLenum target, |
| 898 | GLint level, |
| 899 | GLint xoffset, |
| 900 | GLint yoffset, |
| 901 | GLsizei width, |
| 902 | GLsizei height, |
| 903 | GLenum format, |
| 904 | GLenum type, |
| 905 | const void * data); |
| 906 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 907 | // Wrapper for TexSubImage2D. |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 908 | error::Error DoTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 909 | GLenum target, |
| 910 | GLint level, |
| 911 | GLint xoffset, |
| 912 | GLint yoffset, |
| 913 | GLsizei width, |
| 914 | GLsizei height, |
| 915 | GLenum format, |
| 916 | GLenum type, |
| 917 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 918 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 919 | // Extra validation for async tex(Sub)Image2D. |
| 920 | bool ValidateAsyncTransfer( |
| 921 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 922 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 923 | GLenum target, |
| 924 | GLint level, |
| 925 | const void * data); |
| 926 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 927 | // Wrapper for TexImageIOSurface2DCHROMIUM. |
| 928 | void DoTexImageIOSurface2DCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 929 | GLenum target, |
| 930 | GLsizei width, |
| 931 | GLsizei height, |
| 932 | GLuint io_surface_id, |
| 933 | GLuint plane); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 934 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 935 | void DoCopyTextureCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 936 | GLenum target, |
| 937 | GLuint source_id, |
| 938 | GLuint target_id, |
| 939 | GLint level, |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 940 | GLenum internal_format, |
| 941 | GLenum dest_type); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 942 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 943 | // Wrapper for TexStorage2DEXT. |
| 944 | void DoTexStorage2DEXT( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 945 | GLenum target, |
| 946 | GLint levels, |
| 947 | GLenum internal_format, |
| 948 | GLsizei width, |
| 949 | GLsizei height); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 950 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 951 | void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 952 | void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, |
| 953 | const GLbyte* key); |
| 954 | void ProduceTextureRef(std::string func_name, TextureRef* texture_ref, |
| 955 | GLenum target, const GLbyte* data); |
| 956 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 957 | void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 958 | void DoCreateAndConsumeTextureCHROMIUM(GLenum target, const GLbyte* key, |
| 959 | GLuint client_id); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 960 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 961 | void DoBindTexImage2DCHROMIUM( |
| 962 | GLenum target, |
| 963 | GLint image_id); |
| 964 | void DoReleaseTexImage2DCHROMIUM( |
| 965 | GLenum target, |
| 966 | GLint image_id); |
| 967 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 968 | void DoTraceEndCHROMIUM(void); |
| 969 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 970 | void DoDrawBuffersEXT(GLsizei count, const GLenum* bufs); |
| 971 | |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 972 | void DoLoseContextCHROMIUM(GLenum current, GLenum other); |
| 973 | |
kkinnunen | 337d5963 | 2014-08-26 10:19:57 | [diff] [blame] | 974 | void DoMatrixLoadfCHROMIUM(GLenum matrix_mode, const GLfloat* matrix); |
| 975 | void DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode); |
| 976 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 977 | // Creates a Program for the given program. |
| 978 | Program* CreateProgram( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 979 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 980 | return program_manager()->CreateProgram(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 981 | } |
| 982 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 983 | // Gets the program info for the given program. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 984 | Program* GetProgram(GLuint client_id) { |
| 985 | return program_manager()->GetProgram(client_id); |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 986 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 987 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 988 | #if defined(NDEBUG) |
| 989 | void LogClientServiceMapping( |
| 990 | const char* /* function_name */, |
| 991 | GLuint /* client_id */, |
| 992 | GLuint /* service_id */) { |
| 993 | } |
| 994 | template<typename T> |
| 995 | void LogClientServiceForInfo( |
| 996 | T* /* info */, GLuint /* client_id */, const char* /* function_name */) { |
| 997 | } |
| 998 | #else |
| 999 | void LogClientServiceMapping( |
| 1000 | const char* function_name, GLuint client_id, GLuint service_id) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 1001 | if (service_logging_) { |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 1002 | VLOG(1) << "[" << logger_.GetLogPrefix() << "] " << function_name |
| 1003 | << ": client_id = " << client_id |
| 1004 | << ", service_id = " << service_id; |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 1005 | } |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1006 | } |
| 1007 | template<typename T> |
| 1008 | void LogClientServiceForInfo( |
| 1009 | T* info, GLuint client_id, const char* function_name) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 1010 | if (info) { |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1011 | LogClientServiceMapping(function_name, client_id, info->service_id()); |
| 1012 | } |
| 1013 | } |
| 1014 | #endif |
| 1015 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1016 | // Gets the program info for the given program. If it's not a program |
| 1017 | // generates a GL error. Returns NULL if not program. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1018 | Program* GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1019 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1020 | Program* program = GetProgram(client_id); |
| 1021 | if (!program) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1022 | if (GetShader(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1023 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1024 | GL_INVALID_OPERATION, function_name, "shader passed for program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1025 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1026 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1027 | } |
| 1028 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1029 | LogClientServiceForInfo(program, client_id, function_name); |
| 1030 | return program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1034 | // Creates a Shader for the given shader. |
| 1035 | Shader* CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 1036 | GLuint client_id, |
| 1037 | GLuint service_id, |
| 1038 | GLenum shader_type) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1039 | return shader_manager()->CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 1040 | client_id, service_id, shader_type); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1041 | } |
| 1042 | |
| 1043 | // Gets the shader info for the given shader. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1044 | Shader* GetShader(GLuint client_id) { |
| 1045 | return shader_manager()->GetShader(client_id); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1046 | } |
| 1047 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1048 | // Gets the shader info for the given shader. If it's not a shader generates a |
| 1049 | // GL error. Returns NULL if not shader. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1050 | Shader* GetShaderInfoNotProgram( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1051 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1052 | Shader* shader = GetShader(client_id); |
| 1053 | if (!shader) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1054 | if (GetProgram(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1055 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1056 | GL_INVALID_OPERATION, function_name, "program passed for shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1057 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1058 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1059 | GL_INVALID_VALUE, function_name, "unknown shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1060 | } |
| 1061 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1062 | LogClientServiceForInfo(shader, client_id, function_name); |
| 1063 | return shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1064 | } |
| 1065 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1066 | // Creates a buffer info for the given buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1067 | void CreateBuffer(GLuint client_id, GLuint service_id) { |
| 1068 | return buffer_manager()->CreateBuffer(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1069 | } |
| 1070 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1071 | // Gets the buffer info for the given buffer. |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 1072 | Buffer* GetBuffer(GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 1073 | Buffer* buffer = buffer_manager()->GetBuffer(client_id); |
| 1074 | return buffer; |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 1075 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1076 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1077 | // Removes any buffers in the VertexAtrribInfos and BufferInfos. This is used |
| 1078 | // on glDeleteBuffers so we can make sure the user does not try to render |
| 1079 | // with deleted buffers. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1080 | void RemoveBuffer(GLuint client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1081 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1082 | // Creates a framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1083 | void CreateFramebuffer(GLuint client_id, GLuint service_id) { |
| 1084 | return framebuffer_manager()->CreateFramebuffer(client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | // Gets the framebuffer info for the given framebuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1088 | Framebuffer* GetFramebuffer(GLuint client_id) { |
| 1089 | return framebuffer_manager()->GetFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | // Removes the framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1093 | void RemoveFramebuffer(GLuint client_id) { |
| 1094 | framebuffer_manager()->RemoveFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | // Creates a renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1098 | void CreateRenderbuffer(GLuint client_id, GLuint service_id) { |
| 1099 | return renderbuffer_manager()->CreateRenderbuffer( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1100 | client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | // Gets the renderbuffer info for the given renderbuffer. |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1104 | Renderbuffer* GetRenderbuffer(GLuint client_id) { |
| 1105 | return renderbuffer_manager()->GetRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | // Removes the renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1109 | void RemoveRenderbuffer(GLuint client_id) { |
| 1110 | renderbuffer_manager()->RemoveRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1111 | } |
| 1112 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1113 | // Gets the vertex attrib manager for the given vertex array. |
| 1114 | VertexAttribManager* GetVertexAttribManager(GLuint client_id) { |
| 1115 | VertexAttribManager* info = |
| 1116 | vertex_array_manager()->GetVertexAttribManager(client_id); |
| 1117 | return info; |
| 1118 | } |
| 1119 | |
| 1120 | // Removes the vertex attrib manager for the given vertex array. |
| 1121 | void RemoveVertexAttribManager(GLuint client_id) { |
| 1122 | vertex_array_manager()->RemoveVertexAttribManager(client_id); |
| 1123 | } |
| 1124 | |
| 1125 | // Creates a vertex attrib manager for the given vertex array. |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 1126 | scoped_refptr<VertexAttribManager> CreateVertexAttribManager( |
| 1127 | GLuint client_id, |
| 1128 | GLuint service_id, |
| 1129 | bool client_visible) { |
| 1130 | return vertex_array_manager()->CreateVertexAttribManager( |
| 1131 | client_id, service_id, group_->max_vertex_attribs(), client_visible); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1132 | } |
| 1133 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1134 | void DoBindAttribLocation(GLuint client_id, GLuint index, const char* name); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 1135 | void DoBindUniformLocationCHROMIUM( |
| 1136 | GLuint client_id, GLint location, const char* name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1137 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 1138 | error::Error GetAttribLocationHelper( |
| 1139 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1140 | const std::string& name_str); |
| 1141 | |
| 1142 | error::Error GetUniformLocationHelper( |
| 1143 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1144 | const std::string& name_str); |
| 1145 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1146 | // Helper for glShaderSource. |
| 1147 | error::Error ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1148 | GLuint client_id, const char* data, uint32 data_size); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1149 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1150 | // Clear any textures used by the current program. |
| 1151 | bool ClearUnclearedTextures(); |
| 1152 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1153 | // Clears any uncleared attachments attached to the given frame buffer. |
| 1154 | // Returns false if there was a generated GL error. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1155 | void ClearUnclearedAttachments(GLenum target, Framebuffer* framebuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1156 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1157 | // overridden from GLES2Decoder |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 1158 | virtual bool ClearLevel(unsigned service_id, |
| 1159 | unsigned bind_target, |
| 1160 | unsigned target, |
| 1161 | int level, |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 1162 | unsigned internal_format, |
[email protected] | b8e97b6 | 2012-09-30 15:09:00 | [diff] [blame] | 1163 | unsigned format, |
| 1164 | unsigned type, |
| 1165 | int width, |
| 1166 | int height, |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 1167 | bool is_texture_immutable) override; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1168 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 1169 | // Restore all GL state that affects clearing. |
| 1170 | void RestoreClearState(); |
| 1171 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1172 | // Remembers the state of some capabilities. |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1173 | // Returns: true if glEnable/glDisable should actually be called. |
| 1174 | bool SetCapabilityState(GLenum cap, bool enabled); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1175 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1176 | // Check that the currently bound framebuffers are valid. |
| 1177 | // Generates GL error if not. |
| 1178 | bool CheckBoundFramebuffersValid(const char* func_name); |
| 1179 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 1180 | // Check that the currently bound read framebuffer has a color image |
| 1181 | // attached. Generates GL error if not. |
| 1182 | bool CheckBoundReadFramebufferColorAttachment(const char* func_name); |
| 1183 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 1184 | // Check that the currently bound read framebuffer's color image |
| 1185 | // isn't the target texture of the glCopyTex{Sub}Image2D. |
| 1186 | bool FormsTextureCopyingFeedbackLoop(TextureRef* texture, GLint level); |
| 1187 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1188 | // Check if a framebuffer meets our requirements. |
| 1189 | bool CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1190 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1191 | GLenum target, |
| 1192 | const char* func_name); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1193 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1194 | // Checks if the current program exists and is valid. If not generates the |
| 1195 | // appropriate GL error. Returns true if the current program is in a usable |
| 1196 | // state. |
| 1197 | bool CheckCurrentProgram(const char* function_name); |
| 1198 | |
| 1199 | // Checks if the current program exists and is valid and that location is not |
| 1200 | // -1. If the current program is not valid generates the appropriate GL |
| 1201 | // error. Returns true if the current program is in a usable state and |
| 1202 | // location is not -1. |
| 1203 | bool CheckCurrentProgramForUniform(GLint location, const char* function_name); |
| 1204 | |
zmo | f9a81360f | 2014-10-17 00:06:14 | [diff] [blame] | 1205 | // Checks if the current program samples a texture that is also the color |
| 1206 | // image of the current bound framebuffer, i.e., the source and destination |
| 1207 | // of the draw operation are the same. |
| 1208 | bool CheckDrawingFeedbackLoops(); |
| 1209 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1210 | // Gets the type of a uniform for a location in the current program. Sets GL |
| 1211 | // errors if the current program is not valid. Returns true if the current |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1212 | // program is valid and the location exists. Adjusts count so it |
| 1213 | // does not overflow the uniform. |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 1214 | bool PrepForSetUniformByLocation(GLint fake_location, |
| 1215 | const char* function_name, |
| 1216 | Program::UniformApiType api_type, |
| 1217 | GLint* real_location, |
| 1218 | GLenum* type, |
| 1219 | GLsizei* count); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1220 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1221 | // Gets the service id for any simulated backbuffer fbo. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1222 | GLuint GetBackbufferServiceId() const; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1223 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1224 | // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv |
| 1225 | bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); |
| 1226 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 1227 | // Helper for glGetVertexAttrib |
| 1228 | void GetVertexAttribHelper( |
| 1229 | const VertexAttrib* attrib, GLenum pname, GLint* param); |
| 1230 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1231 | // Wrapper for glCreateProgram |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1232 | bool CreateProgramHelper(GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1233 | |
| 1234 | // Wrapper for glCreateShader |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1235 | bool CreateShaderHelper(GLenum type, GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1236 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1237 | // Wrapper for glActiveTexture |
| 1238 | void DoActiveTexture(GLenum texture_unit); |
| 1239 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1240 | // Wrapper for glAttachShader |
| 1241 | void DoAttachShader(GLuint client_program_id, GLint client_shader_id); |
| 1242 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1243 | // Wrapper for glBindBuffer since we need to track the current targets. |
| 1244 | void DoBindBuffer(GLenum target, GLuint buffer); |
| 1245 | |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 1246 | // Wrapper for glBindFramebuffer since we need to track the current targets. |
| 1247 | void DoBindFramebuffer(GLenum target, GLuint framebuffer); |
| 1248 | |
| 1249 | // Wrapper for glBindRenderbuffer since we need to track the current targets. |
| 1250 | void DoBindRenderbuffer(GLenum target, GLuint renderbuffer); |
| 1251 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1252 | // Wrapper for glBindTexture since we need to track the current targets. |
| 1253 | void DoBindTexture(GLenum target, GLuint texture); |
| 1254 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1255 | // Wrapper for glBindVertexArrayOES |
| 1256 | void DoBindVertexArrayOES(GLuint array); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 1257 | void EmulateVertexArrayState(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1258 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1259 | // Wrapper for glBlitFramebufferCHROMIUM. |
| 1260 | void DoBlitFramebufferCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1261 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 1262 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 1263 | GLbitfield mask, GLenum filter); |
| 1264 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1265 | // Wrapper for glBufferSubData. |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 1266 | void DoBufferSubData( |
| 1267 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); |
| 1268 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1269 | // Wrapper for glCheckFramebufferStatus |
| 1270 | GLenum DoCheckFramebufferStatus(GLenum target); |
| 1271 | |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1272 | // Wrapper for glClear |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1273 | error::Error DoClear(GLbitfield mask); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1274 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1275 | // Wrappers for various state. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1276 | void DoDepthRangef(GLclampf znear, GLclampf zfar); |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 1277 | void DoSampleCoverage(GLclampf value, GLboolean invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1278 | |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1279 | // Wrapper for glCompileShader. |
| 1280 | void DoCompileShader(GLuint shader); |
| 1281 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1282 | // Wrapper for glDetachShader |
| 1283 | void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
| 1284 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1285 | // Wrapper for glDisable |
| 1286 | void DoDisable(GLenum cap); |
| 1287 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1288 | // Wrapper for glDisableVertexAttribArray. |
| 1289 | void DoDisableVertexAttribArray(GLuint index); |
| 1290 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1291 | // Wrapper for glDiscardFramebufferEXT, since we need to track undefined |
| 1292 | // attachments. |
| 1293 | void DoDiscardFramebufferEXT(GLenum target, |
| 1294 | GLsizei numAttachments, |
| 1295 | const GLenum* attachments); |
| 1296 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1297 | // Wrapper for glEnable |
| 1298 | void DoEnable(GLenum cap); |
| 1299 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1300 | // Wrapper for glEnableVertexAttribArray. |
| 1301 | void DoEnableVertexAttribArray(GLuint index); |
| 1302 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1303 | // Wrapper for glFinish. |
| 1304 | void DoFinish(); |
| 1305 | |
| 1306 | // Wrapper for glFlush. |
| 1307 | void DoFlush(); |
| 1308 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1309 | // Wrapper for glFramebufferRenderbufffer. |
| 1310 | void DoFramebufferRenderbuffer( |
| 1311 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
| 1312 | GLuint renderbuffer); |
| 1313 | |
| 1314 | // Wrapper for glFramebufferTexture2D. |
| 1315 | void DoFramebufferTexture2D( |
| 1316 | GLenum target, GLenum attachment, GLenum textarget, GLuint texture, |
| 1317 | GLint level); |
| 1318 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1319 | // Wrapper for glFramebufferTexture2DMultisampleEXT. |
| 1320 | void DoFramebufferTexture2DMultisample( |
| 1321 | GLenum target, GLenum attachment, GLenum textarget, |
| 1322 | GLuint texture, GLint level, GLsizei samples); |
| 1323 | |
| 1324 | // Common implementation for both DoFramebufferTexture2D wrappers. |
| 1325 | void DoFramebufferTexture2DCommon(const char* name, |
| 1326 | GLenum target, GLenum attachment, GLenum textarget, |
| 1327 | GLuint texture, GLint level, GLsizei samples); |
| 1328 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1329 | // Wrapper for glGenerateMipmap |
| 1330 | void DoGenerateMipmap(GLenum target); |
| 1331 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1332 | // Helper for DoGetBooleanv, Floatv, and Intergerv to adjust pname |
| 1333 | // to account for different pname values defined in different extension |
| 1334 | // variants. |
| 1335 | GLenum AdjustGetPname(GLenum pname); |
| 1336 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1337 | // Wrapper for DoGetBooleanv. |
| 1338 | void DoGetBooleanv(GLenum pname, GLboolean* params); |
| 1339 | |
| 1340 | // Wrapper for DoGetFloatv. |
| 1341 | void DoGetFloatv(GLenum pname, GLfloat* params); |
| 1342 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1343 | // Wrapper for glGetFramebufferAttachmentParameteriv. |
| 1344 | void DoGetFramebufferAttachmentParameteriv( |
| 1345 | GLenum target, GLenum attachment, GLenum pname, GLint* params); |
| 1346 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1347 | // Wrapper for glGetIntegerv. |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1348 | void DoGetIntegerv(GLenum pname, GLint* params); |
| 1349 | |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1350 | // Gets the max value in a range in a buffer. |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1351 | GLuint DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1352 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); |
| 1353 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 1354 | // Wrapper for glGetBufferParameteriv. |
| 1355 | void DoGetBufferParameteriv( |
| 1356 | GLenum target, GLenum pname, GLint* params); |
| 1357 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1358 | // Wrapper for glGetProgramiv. |
| 1359 | void DoGetProgramiv( |
| 1360 | GLuint program_id, GLenum pname, GLint* params); |
| 1361 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1362 | // Wrapper for glRenderbufferParameteriv. |
| 1363 | void DoGetRenderbufferParameteriv( |
| 1364 | GLenum target, GLenum pname, GLint* params); |
| 1365 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 1366 | // Wrapper for glGetShaderiv |
| 1367 | void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); |
| 1368 | |
[email protected] | 4c6f546 | 2014-03-05 00:26:56 | [diff] [blame] | 1369 | // Wrappers for glGetTexParameter. |
| 1370 | void DoGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params); |
| 1371 | void DoGetTexParameteriv(GLenum target, GLenum pname, GLint* params); |
| 1372 | void InitTextureMaxAnisotropyIfNeeded(GLenum target, GLenum pname); |
| 1373 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1374 | // Wrappers for glGetVertexAttrib. |
| 1375 | void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); |
| 1376 | void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); |
| 1377 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1378 | // Wrappers for glIsXXX functions. |
[email protected] | 3dc69c4 | 2012-05-12 02:29:24 | [diff] [blame] | 1379 | bool DoIsEnabled(GLenum cap); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1380 | bool DoIsBuffer(GLuint client_id); |
| 1381 | bool DoIsFramebuffer(GLuint client_id); |
| 1382 | bool DoIsProgram(GLuint client_id); |
| 1383 | bool DoIsRenderbuffer(GLuint client_id); |
| 1384 | bool DoIsShader(GLuint client_id); |
| 1385 | bool DoIsTexture(GLuint client_id); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1386 | bool DoIsVertexArrayOES(GLuint client_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1387 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1388 | // Wrapper for glLinkProgram |
| 1389 | void DoLinkProgram(GLuint program); |
| 1390 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1391 | // Wrapper for glRenderbufferStorage. |
| 1392 | void DoRenderbufferStorage( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1393 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1394 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1395 | // Handler for glRenderbufferStorageMultisampleCHROMIUM. |
| 1396 | void DoRenderbufferStorageMultisampleCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1397 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1398 | GLsizei width, GLsizei height); |
| 1399 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1400 | // Handler for glRenderbufferStorageMultisampleEXT |
| 1401 | // (multisampled_render_to_texture). |
| 1402 | void DoRenderbufferStorageMultisampleEXT( |
| 1403 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1404 | GLsizei width, GLsizei height); |
| 1405 | |
| 1406 | // Common validation for multisample extensions. |
| 1407 | bool ValidateRenderbufferStorageMultisample(GLsizei samples, |
| 1408 | GLenum internalformat, |
| 1409 | GLsizei width, |
| 1410 | GLsizei height); |
| 1411 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 1412 | // Verifies that the currently bound multisample renderbuffer is valid |
| 1413 | // Very slow! Only done on platforms with driver bugs that return invalid |
| 1414 | // buffers under memory pressure |
| 1415 | bool VerifyMultisampleRenderbufferIntegrity( |
| 1416 | GLuint renderbuffer, GLenum format); |
| 1417 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1418 | // Wrapper for glReleaseShaderCompiler. |
| 1419 | void DoReleaseShaderCompiler() { } |
| 1420 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1421 | // Wrappers for glTexParameter functions. |
| 1422 | void DoTexParameterf(GLenum target, GLenum pname, GLfloat param); |
| 1423 | void DoTexParameteri(GLenum target, GLenum pname, GLint param); |
| 1424 | void DoTexParameterfv(GLenum target, GLenum pname, const GLfloat* params); |
| 1425 | void DoTexParameteriv(GLenum target, GLenum pname, const GLint* params); |
| 1426 | |
| 1427 | // Wrappers for glUniform1i and glUniform1iv as according to the GLES2 |
| 1428 | // spec only these 2 functions can be used to set sampler uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1429 | void DoUniform1i(GLint fake_location, GLint v0); |
| 1430 | void DoUniform1iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1431 | void DoUniform2iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1432 | void DoUniform3iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1433 | void DoUniform4iv(GLint fake_location, GLsizei count, const GLint* value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1434 | |
| 1435 | // Wrappers for glUniformfv because some drivers don't correctly accept |
| 1436 | // bool uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1437 | void DoUniform1fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1438 | void DoUniform2fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1439 | void DoUniform3fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1440 | void DoUniform4fv(GLint fake_location, GLsizei count, const GLfloat* value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1441 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1442 | void DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1443 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1444 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1445 | void DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1446 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1447 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1448 | void DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1449 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1450 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1451 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1452 | bool SetVertexAttribValue( |
| 1453 | const char* function_name, GLuint index, const GLfloat* value); |
| 1454 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1455 | // Wrappers for glVertexAttrib?? |
| 1456 | void DoVertexAttrib1f(GLuint index, GLfloat v0); |
| 1457 | void DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1); |
| 1458 | void DoVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2); |
| 1459 | void DoVertexAttrib4f( |
| 1460 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); |
| 1461 | void DoVertexAttrib1fv(GLuint index, const GLfloat *v); |
| 1462 | void DoVertexAttrib2fv(GLuint index, const GLfloat *v); |
| 1463 | void DoVertexAttrib3fv(GLuint index, const GLfloat *v); |
| 1464 | void DoVertexAttrib4fv(GLuint index, const GLfloat *v); |
| 1465 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1466 | // Wrapper for glViewport |
| 1467 | void DoViewport(GLint x, GLint y, GLsizei width, GLsizei height); |
| 1468 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1469 | // Wrapper for glUseProgram |
| 1470 | void DoUseProgram(GLuint program); |
| 1471 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1472 | // Wrapper for glValidateProgram. |
| 1473 | void DoValidateProgram(GLuint program_client_id); |
| 1474 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 1475 | void DoInsertEventMarkerEXT(GLsizei length, const GLchar* marker); |
| 1476 | void DoPushGroupMarkerEXT(GLsizei length, const GLchar* group); |
| 1477 | void DoPopGroupMarkerEXT(void); |
| 1478 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 1479 | // Gets the number of values that will be returned by glGetXXX. Returns |
| 1480 | // false if pname is unknown. |
| 1481 | bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values); |
| 1482 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1483 | // Checks if the current program and vertex attributes are valid for drawing. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1484 | bool IsDrawValid( |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 1485 | const char* function_name, GLuint max_vertex_accessed, bool instanced, |
| 1486 | GLsizei primcount); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1487 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 1488 | // Returns true if successful, simulated will be true if attrib0 was |
| 1489 | // simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1490 | bool SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1491 | const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 1492 | void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1493 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1494 | // If an image is bound to texture, this will call Will/DidUseTexImage |
| 1495 | // if needed. |
| 1496 | void DoWillUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1497 | void DoDidUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1498 | |
| 1499 | // Returns false if textures were replaced. |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 1500 | bool PrepareTexturesForRender(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1501 | void RestoreStateForTextures(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1502 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1503 | // Returns true if GL_FIXED attribs were simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1504 | bool SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1505 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1506 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1507 | void RestoreStateForSimulatedFixedAttribs(); |
| 1508 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1509 | // Handle DrawArrays and DrawElements for both instanced and non-instanced |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 1510 | // cases (primcount is always 1 for non-instanced). |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1511 | error::Error DoDrawArrays( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1512 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1513 | bool instanced, GLenum mode, GLint first, GLsizei count, |
| 1514 | GLsizei primcount); |
| 1515 | error::Error DoDrawElements( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1516 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1517 | bool instanced, GLenum mode, GLsizei count, GLenum type, |
| 1518 | int32 offset, GLsizei primcount); |
| 1519 | |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1520 | GLenum GetBindTargetForSamplerType(GLenum type) { |
| 1521 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1522 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 1523 | switch (type) { |
| 1524 | case GL_SAMPLER_2D: |
| 1525 | return GL_TEXTURE_2D; |
| 1526 | case GL_SAMPLER_CUBE: |
| 1527 | return GL_TEXTURE_CUBE_MAP; |
| 1528 | case GL_SAMPLER_EXTERNAL_OES: |
| 1529 | return GL_TEXTURE_EXTERNAL_OES; |
| 1530 | case GL_SAMPLER_2D_RECT_ARB: |
| 1531 | return GL_TEXTURE_RECTANGLE_ARB; |
| 1532 | } |
| 1533 | |
| 1534 | NOTREACHED(); |
| 1535 | return 0; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1536 | } |
| 1537 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1538 | // Gets the framebuffer info for a particular target. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1539 | Framebuffer* GetFramebufferInfoForTarget(GLenum target) { |
| 1540 | Framebuffer* framebuffer = NULL; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1541 | switch (target) { |
| 1542 | case GL_FRAMEBUFFER: |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1543 | case GL_DRAW_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1544 | framebuffer = framebuffer_state_.bound_draw_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1545 | break; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1546 | case GL_READ_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1547 | framebuffer = framebuffer_state_.bound_read_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1548 | break; |
| 1549 | default: |
| 1550 | NOTREACHED(); |
| 1551 | break; |
| 1552 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1553 | return framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1554 | } |
| 1555 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1556 | Renderbuffer* GetRenderbufferInfoForTarget( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1557 | GLenum target) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1558 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1559 | switch (target) { |
| 1560 | case GL_RENDERBUFFER: |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 1561 | renderbuffer = state_.bound_renderbuffer.get(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1562 | break; |
| 1563 | default: |
| 1564 | NOTREACHED(); |
| 1565 | break; |
| 1566 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1567 | return renderbuffer; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1568 | } |
| 1569 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1570 | // Validates the program and location for a glGetUniform call and returns |
| 1571 | // a SizeResult setup to receive the result. Returns true if glGetUniform |
| 1572 | // should be called. |
| 1573 | bool GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1574 | GLuint program, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1575 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1576 | error::Error* error, GLint* real_location, GLuint* service_id, |
| 1577 | void** result, GLenum* result_type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1578 | |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 1579 | void MaybeExitOnContextLost(); |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 1580 | virtual bool WasContextLost() override; |
| 1581 | virtual bool WasContextLostByRobustnessExtension() override; |
| 1582 | virtual void LoseContext(uint32 reset_status) override; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1583 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1584 | #if defined(OS_MACOSX) |
| 1585 | void ReleaseIOSurfaceForTexture(GLuint texture_id); |
| 1586 | #endif |
| 1587 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1588 | bool ValidateCompressedTexDimensions( |
| 1589 | const char* function_name, |
| 1590 | GLint level, GLsizei width, GLsizei height, GLenum format); |
| 1591 | bool ValidateCompressedTexFuncData( |
| 1592 | const char* function_name, |
| 1593 | GLsizei width, GLsizei height, GLenum format, size_t size); |
| 1594 | bool ValidateCompressedTexSubDimensions( |
| 1595 | const char* function_name, |
| 1596 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 1597 | GLsizei width, GLsizei height, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1598 | Texture* texture); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1599 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1600 | void RenderWarning(const char* filename, int line, const std::string& msg); |
| 1601 | void PerformanceWarning( |
| 1602 | const char* filename, int line, const std::string& msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 1603 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 1604 | const FeatureInfo::FeatureFlags& features() const { |
| 1605 | return feature_info_->feature_flags(); |
| 1606 | } |
| 1607 | |
| 1608 | const FeatureInfo::Workarounds& workarounds() const { |
| 1609 | return feature_info_->workarounds(); |
| 1610 | } |
| 1611 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1612 | bool ShouldDeferDraws() { |
| 1613 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1614 | framebuffer_state_.bound_draw_framebuffer.get() == NULL && |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1615 | surface_->DeferDraws(); |
| 1616 | } |
| 1617 | |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1618 | bool ShouldDeferReads() { |
| 1619 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1620 | framebuffer_state_.bound_read_framebuffer.get() == NULL && |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1621 | surface_->DeferDraws(); |
| 1622 | } |
| 1623 | |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 1624 | error::Error WillAccessBoundFramebufferForDraw() { |
| 1625 | if (ShouldDeferDraws()) |
| 1626 | return error::kDeferCommandUntilLater; |
| 1627 | if (!offscreen_target_frame_buffer_.get() && |
| 1628 | !framebuffer_state_.bound_draw_framebuffer.get() && |
| 1629 | !surface_->SetBackbufferAllocation(true)) |
| 1630 | return error::kLostContext; |
| 1631 | return error::kNoError; |
| 1632 | } |
| 1633 | |
| 1634 | error::Error WillAccessBoundFramebufferForRead() { |
| 1635 | if (ShouldDeferReads()) |
| 1636 | return error::kDeferCommandUntilLater; |
| 1637 | if (!offscreen_target_frame_buffer_.get() && |
| 1638 | !framebuffer_state_.bound_read_framebuffer.get() && |
| 1639 | !surface_->SetBackbufferAllocation(true)) |
| 1640 | return error::kLostContext; |
| 1641 | return error::kNoError; |
| 1642 | } |
| 1643 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 1644 | // Set remaining commands to process to 0 to force DoCommands to return |
| 1645 | // and allow context preemption and GPU watchdog checks in GpuScheduler(). |
| 1646 | void ExitCommandProcessingEarly() { commands_to_process_ = 0; } |
| 1647 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 1648 | void ProcessPendingReadPixels(); |
| 1649 | void FinishReadPixels(const cmds::ReadPixels& c, GLuint buffer); |
| 1650 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1651 | // Generate a member function prototype for each command in an automated and |
| 1652 | // typesafe way. |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 1653 | #define GLES2_CMD_OP(name) \ |
| 1654 | Error Handle##name(uint32 immediate_data_size, const void* data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1655 | |
| 1656 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 1657 | |
| 1658 | #undef GLES2_CMD_OP |
| 1659 | |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 1660 | // The GL context this decoder renders to on behalf of the client. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1661 | scoped_refptr<gfx::GLSurface> surface_; |
| 1662 | scoped_refptr<gfx::GLContext> context_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1663 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1664 | // The ContextGroup for this decoder uses to track resources. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1665 | scoped_refptr<ContextGroup> group_; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1666 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 1667 | DebugMarkerManager debug_marker_manager_; |
| 1668 | Logger logger_; |
| 1669 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1670 | // All the state for this context. |
| 1671 | ContextState state_; |
| 1672 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1673 | // Current width and height of the offscreen frame buffer. |
| 1674 | gfx::Size offscreen_size_; |
| 1675 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1676 | // Util to help with GL. |
| 1677 | GLES2Util util_; |
| 1678 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1679 | // unpack flip y as last set by glPixelStorei |
| 1680 | bool unpack_flip_y_; |
| 1681 | |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1682 | // unpack (un)premultiply alpha as last set by glPixelStorei |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1683 | bool unpack_premultiply_alpha_; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1684 | bool unpack_unpremultiply_alpha_; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1685 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1686 | // The buffer we bind to attrib 0 since OpenGL requires it (ES does not). |
| 1687 | GLuint attrib_0_buffer_id_; |
| 1688 | |
| 1689 | // The value currently in attrib_0. |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1690 | Vec4 attrib_0_value_; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1691 | |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 1692 | // Whether or not the attrib_0 buffer holds the attrib_0_value. |
| 1693 | bool attrib_0_buffer_matches_value_; |
| 1694 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1695 | // The size of attrib 0. |
| 1696 | GLsizei attrib_0_size_; |
| 1697 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1698 | // The buffer used to simulate GL_FIXED attribs. |
| 1699 | GLuint fixed_attrib_buffer_id_; |
| 1700 | |
| 1701 | // The size of fiixed attrib buffer. |
| 1702 | GLsizei fixed_attrib_buffer_size_; |
| 1703 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1704 | // The offscreen frame buffer that the client renders to. With EGL, the |
| 1705 | // depth and stencil buffers are separate. With regular GL there is a single |
| 1706 | // packed depth stencil buffer in offscreen_target_depth_render_buffer_. |
| 1707 | // offscreen_target_stencil_render_buffer_ is unused. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1708 | scoped_ptr<BackFramebuffer> offscreen_target_frame_buffer_; |
| 1709 | scoped_ptr<BackTexture> offscreen_target_color_texture_; |
| 1710 | scoped_ptr<BackRenderbuffer> offscreen_target_color_render_buffer_; |
| 1711 | scoped_ptr<BackRenderbuffer> offscreen_target_depth_render_buffer_; |
| 1712 | scoped_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1713 | GLenum offscreen_target_color_format_; |
| 1714 | GLenum offscreen_target_depth_format_; |
| 1715 | GLenum offscreen_target_stencil_format_; |
| 1716 | GLsizei offscreen_target_samples_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1717 | GLboolean offscreen_target_buffer_preserved_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1718 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1719 | // The copy that is saved when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1720 | scoped_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; |
| 1721 | scoped_ptr<BackTexture> offscreen_saved_color_texture_; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 1722 | scoped_refptr<TextureRef> |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1723 | offscreen_saved_color_texture_info_; |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1724 | |
| 1725 | // The copy that is used as the destination for multi-sample resolves. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1726 | scoped_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; |
| 1727 | scoped_ptr<BackTexture> offscreen_resolved_color_texture_; |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1728 | GLenum offscreen_saved_color_format_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1729 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1730 | scoped_ptr<QueryManager> query_manager_; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1731 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1732 | scoped_ptr<VertexArrayManager> vertex_array_manager_; |
| 1733 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 1734 | scoped_ptr<ImageManager> image_manager_; |
| 1735 | |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 1736 | base::Callback<void(gfx::Size, float)> resize_callback_; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 1737 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 1738 | WaitSyncPointCallback wait_sync_point_callback_; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 1739 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 1740 | ShaderCacheCallback shader_cache_callback_; |
| 1741 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 1742 | scoped_ptr<AsyncPixelTransferManager> async_pixel_transfer_manager_; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 1743 | |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1744 | // The format of the back buffer_ |
| 1745 | GLenum back_buffer_color_format_; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1746 | bool back_buffer_has_depth_; |
| 1747 | bool back_buffer_has_stencil_; |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1748 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 1749 | bool surfaceless_; |
| 1750 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1751 | // Backbuffer attachments that are currently undefined. |
| 1752 | uint32 backbuffer_needs_clear_bits_; |
| 1753 | |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 1754 | // The current decoder error communicates the decoder error through command |
| 1755 | // processing functions that do not return the error value. Should be set only |
| 1756 | // if not returning an error. |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 1757 | error::Error current_decoder_error_; |
| 1758 | |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1759 | bool use_shader_translator_; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 1760 | scoped_refptr<ShaderTranslator> vertex_translator_; |
| 1761 | scoped_refptr<ShaderTranslator> fragment_translator_; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1762 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1763 | DisallowedFeatures disallowed_features_; |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1764 | |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 1765 | // Cached from ContextGroup |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1766 | const Validators* validators_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1767 | scoped_refptr<FeatureInfo> feature_info_; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1768 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1769 | int frame_number_; |
| 1770 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 1771 | // Number of commands remaining to be processed in DoCommands(). |
| 1772 | int commands_to_process_; |
| 1773 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 1774 | bool has_robustness_extension_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1775 | GLenum reset_status_; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 1776 | bool reset_by_robustness_extension_; |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 1777 | bool supports_post_sub_buffer_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1778 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1779 | // These flags are used to override the state of the shared feature_info_ |
| 1780 | // member. Because the same FeatureInfo instance may be shared among many |
| 1781 | // contexts, the assumptions on the availablity of extensions in WebGL |
| 1782 | // contexts may be broken. These flags override the shared state to preserve |
| 1783 | // WebGL semantics. |
| 1784 | bool force_webgl_glsl_validation_; |
| 1785 | bool derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 1786 | bool frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 1787 | bool draw_buffers_explicitly_enabled_; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 1788 | bool shader_texture_lod_explicitly_enabled_; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1789 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 1790 | bool compile_shader_always_succeeds_; |
| 1791 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 1792 | // An optional behaviour to lose the context and group when OOM. |
| 1793 | bool lose_context_when_out_of_memory_; |
| 1794 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1795 | // Log extra info. |
| 1796 | bool service_logging_; |
| 1797 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1798 | #if defined(OS_MACOSX) |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 1799 | typedef std::map<GLuint, IOSurfaceRef> TextureToIOSurfaceMap; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1800 | TextureToIOSurfaceMap texture_to_io_surface_map_; |
| 1801 | #endif |
| 1802 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1803 | scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
| 1804 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1805 | // Cached values of the currently assigned viewport dimensions. |
| 1806 | GLsizei viewport_max_width_; |
| 1807 | GLsizei viewport_max_height_; |
| 1808 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1809 | // Command buffer stats. |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1810 | base::TimeDelta total_processing_commands_time_; |
| 1811 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 1812 | // States related to each manager. |
| 1813 | DecoderTextureState texture_state_; |
| 1814 | DecoderFramebufferState framebuffer_state_; |
| 1815 | |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 1816 | scoped_ptr<GPUTracer> gpu_tracer_; |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 1817 | scoped_ptr<GPUStateTracer> gpu_state_tracer_; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 1818 | const unsigned char* cb_command_trace_category_; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 1819 | int gpu_trace_level_; |
| 1820 | bool gpu_trace_commands_; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 1821 | bool gpu_debug_commands_; |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 1822 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 1823 | std::queue<linked_ptr<FenceCallback> > pending_readpixel_fences_; |
| 1824 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 1825 | // Used to validate multisample renderbuffers if needed |
| 1826 | GLuint validation_texture_; |
| 1827 | GLuint validation_fbo_multisample_; |
| 1828 | GLuint validation_fbo_; |
| 1829 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 1830 | typedef gpu::gles2::GLES2Decoder::Error (GLES2DecoderImpl::*CmdHandler)( |
| 1831 | uint32 immediate_data_size, |
| 1832 | const void* data); |
| 1833 | |
| 1834 | // A struct to hold info about each command. |
| 1835 | struct CommandInfo { |
| 1836 | CmdHandler cmd_handler; |
| 1837 | uint8 arg_flags; // How to handle the arguments for this command |
| 1838 | uint8 cmd_flags; // How to handle this command |
| 1839 | uint16 arg_count; // How many arguments are expected for this command. |
| 1840 | }; |
| 1841 | |
| 1842 | // A table of CommandInfo for all the commands. |
| 1843 | static const CommandInfo command_info[kNumCommands - kStartPoint]; |
| 1844 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1845 | DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
| 1846 | }; |
| 1847 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 1848 | const GLES2DecoderImpl::CommandInfo GLES2DecoderImpl::command_info[] = { |
| 1849 | #define GLES2_CMD_OP(name) \ |
| 1850 | { \ |
| 1851 | &GLES2DecoderImpl::Handle##name, cmds::name::kArgFlags, \ |
| 1852 | cmds::name::cmd_flags, \ |
| 1853 | sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ |
| 1854 | } \ |
| 1855 | , /* NOLINT */ |
| 1856 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 1857 | #undef GLES2_CMD_OP |
| 1858 | }; |
| 1859 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1860 | ScopedGLErrorSuppressor::ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1861 | const char* function_name, ErrorState* error_state) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1862 | : function_name_(function_name), |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1863 | error_state_(error_state) { |
| 1864 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1868 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1869 | } |
| 1870 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1871 | static void RestoreCurrentTextureBindings(ContextState* state, GLenum target) { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1872 | TextureUnit& info = state->texture_units[0]; |
| 1873 | GLuint last_id; |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1874 | scoped_refptr<TextureRef> texture_ref; |
| 1875 | switch (target) { |
| 1876 | case GL_TEXTURE_2D: |
| 1877 | texture_ref = info.bound_texture_2d; |
| 1878 | break; |
| 1879 | case GL_TEXTURE_CUBE_MAP: |
| 1880 | texture_ref = info.bound_texture_cube_map; |
| 1881 | break; |
| 1882 | case GL_TEXTURE_EXTERNAL_OES: |
| 1883 | texture_ref = info.bound_texture_external_oes; |
| 1884 | break; |
| 1885 | case GL_TEXTURE_RECTANGLE_ARB: |
| 1886 | texture_ref = info.bound_texture_rectangle_arb; |
| 1887 | break; |
| 1888 | default: |
| 1889 | NOTREACHED(); |
| 1890 | break; |
| 1891 | } |
| 1892 | if (texture_ref.get()) { |
| 1893 | last_id = texture_ref->service_id(); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1894 | } else { |
| 1895 | last_id = 0; |
| 1896 | } |
| 1897 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1898 | glBindTexture(target, last_id); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1899 | glActiveTexture(GL_TEXTURE0 + state->active_texture_unit); |
| 1900 | } |
| 1901 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1902 | ScopedTextureBinder::ScopedTextureBinder(ContextState* state, |
| 1903 | GLuint id, |
| 1904 | GLenum target) |
| 1905 | : state_(state), |
| 1906 | target_(target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1907 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1908 | "ScopedTextureBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1909 | |
| 1910 | // TODO(apatrick): Check if there are any other states that need to be reset |
| 1911 | // before binding a new texture. |
| 1912 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1913 | glBindTexture(target, id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1914 | } |
| 1915 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1916 | ScopedTextureBinder::~ScopedTextureBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1917 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1918 | "ScopedTextureBinder::dtor", state_->GetErrorState()); |
| 1919 | RestoreCurrentTextureBindings(state_, target_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1920 | } |
| 1921 | |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1922 | ScopedRenderBufferBinder::ScopedRenderBufferBinder(ContextState* state, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1923 | GLuint id) |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1924 | : state_(state) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1925 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1926 | "ScopedRenderBufferBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1927 | glBindRenderbufferEXT(GL_RENDERBUFFER, id); |
| 1928 | } |
| 1929 | |
| 1930 | ScopedRenderBufferBinder::~ScopedRenderBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1931 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1932 | "ScopedRenderBufferBinder::dtor", state_->GetErrorState()); |
| 1933 | state_->RestoreRenderbufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | ScopedFrameBufferBinder::ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 1937 | GLuint id) |
| 1938 | : decoder_(decoder) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1939 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1940 | "ScopedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1941 | glBindFramebufferEXT(GL_FRAMEBUFFER, id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 1942 | decoder->OnFboChanged(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | ScopedFrameBufferBinder::~ScopedFrameBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1946 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1947 | "ScopedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1948 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1949 | } |
| 1950 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1951 | ScopedResolvedFrameBufferBinder::ScopedResolvedFrameBufferBinder( |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1952 | GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 1953 | : decoder_(decoder) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1954 | resolve_and_bind_ = ( |
| 1955 | decoder_->offscreen_target_frame_buffer_.get() && |
| 1956 | decoder_->IsOffscreenBufferMultisampled() && |
| 1957 | (!decoder_->framebuffer_state_.bound_read_framebuffer.get() || |
| 1958 | enforce_internal_framebuffer)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1959 | if (!resolve_and_bind_) |
| 1960 | return; |
| 1961 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1962 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1963 | "ScopedResolvedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1964 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, |
| 1965 | decoder_->offscreen_target_frame_buffer_->id()); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1966 | GLuint targetid; |
| 1967 | if (internal) { |
| 1968 | if (!decoder_->offscreen_resolved_frame_buffer_.get()) { |
| 1969 | decoder_->offscreen_resolved_frame_buffer_.reset( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1970 | new BackFramebuffer(decoder_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1971 | decoder_->offscreen_resolved_frame_buffer_->Create(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1972 | decoder_->offscreen_resolved_color_texture_.reset( |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1973 | new BackTexture(decoder->memory_tracker(), &decoder->state_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1974 | decoder_->offscreen_resolved_color_texture_->Create(); |
| 1975 | |
| 1976 | DCHECK(decoder_->offscreen_saved_color_format_); |
| 1977 | decoder_->offscreen_resolved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 1978 | decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_, |
| 1979 | false); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1980 | decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( |
| 1981 | decoder_->offscreen_resolved_color_texture_.get()); |
| 1982 | if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != |
| 1983 | GL_FRAMEBUFFER_COMPLETE) { |
| 1984 | LOG(ERROR) << "ScopedResolvedFrameBufferBinder failed " |
| 1985 | << "because offscreen resolved FBO was incomplete."; |
| 1986 | return; |
| 1987 | } |
| 1988 | } |
| 1989 | targetid = decoder_->offscreen_resolved_frame_buffer_->id(); |
| 1990 | } else { |
| 1991 | targetid = decoder_->offscreen_saved_frame_buffer_->id(); |
| 1992 | } |
| 1993 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1994 | const int width = decoder_->offscreen_size_.width(); |
| 1995 | const int height = decoder_->offscreen_size_.height(); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 1996 | decoder->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 1997 | decoder->BlitFramebufferHelper(0, |
| 1998 | 0, |
| 1999 | width, |
| 2000 | height, |
| 2001 | 0, |
| 2002 | 0, |
| 2003 | width, |
| 2004 | height, |
| 2005 | GL_COLOR_BUFFER_BIT, |
| 2006 | GL_NEAREST); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2007 | glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { |
| 2011 | if (!resolve_and_bind_) |
| 2012 | return; |
| 2013 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2014 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2015 | "ScopedResolvedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2016 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 2017 | if (decoder_->state_.enable_flags.scissor_test) { |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 2018 | decoder_->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 2019 | } |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2020 | } |
| 2021 | |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2022 | BackTexture::BackTexture( |
| 2023 | MemoryTracker* memory_tracker, |
| 2024 | ContextState* state) |
| 2025 | : memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 2026 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2027 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 2028 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2029 | } |
| 2030 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2031 | BackTexture::~BackTexture() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2032 | // This does not destroy the render texture because that would require that |
| 2033 | // the associated GL context was current. Just check that it was explicitly |
| 2034 | // destroyed. |
| 2035 | DCHECK_EQ(id_, 0u); |
| 2036 | } |
| 2037 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2038 | void BackTexture::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2039 | ScopedGLErrorSuppressor suppressor("BackTexture::Create", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2040 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2041 | Destroy(); |
| 2042 | glGenTextures(1, &id_); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2043 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | eeeb07b9 | 2014-08-16 07:46:26 | [diff] [blame] | 2044 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 2045 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 2046 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 2047 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
[email protected] | 6278880 | 2011-10-03 17:57:16 | [diff] [blame] | 2048 | |
| 2049 | // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 2050 | // never called on an offscreen context, no data will ever be uploaded to the |
| 2051 | // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 2052 | // is called). My idea is that some nvidia drivers might have a bug where |
| 2053 | // deleting a texture that has never been populated might cause a |
| 2054 | // crash. |
| 2055 | glTexImage2D( |
| 2056 | 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] | 2057 | |
| 2058 | bytes_allocated_ = 16u * 16u * 4u; |
| 2059 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2060 | } |
| 2061 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2062 | bool BackTexture::AllocateStorage( |
| 2063 | const gfx::Size& size, GLenum format, bool zero) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2064 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2065 | ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2066 | state_->GetErrorState()); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2067 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2068 | uint32 image_size = 0; |
| 2069 | GLES2Util::ComputeImageDataSizes( |
| 2070 | size.width(), size.height(), format, GL_UNSIGNED_BYTE, 8, &image_size, |
| 2071 | NULL, NULL); |
| 2072 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2073 | if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { |
| 2074 | return false; |
| 2075 | } |
| 2076 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2077 | scoped_ptr<char[]> zero_data; |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2078 | if (zero) { |
| 2079 | zero_data.reset(new char[image_size]); |
| 2080 | memset(zero_data.get(), 0, image_size); |
| 2081 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2082 | |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 2083 | glTexImage2D(GL_TEXTURE_2D, |
| 2084 | 0, // mip level |
| 2085 | format, |
| 2086 | size.width(), |
| 2087 | size.height(), |
| 2088 | 0, // border |
| 2089 | format, |
| 2090 | GL_UNSIGNED_BYTE, |
| 2091 | zero_data.get()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2092 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2093 | size_ = size; |
| 2094 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2095 | bool success = glGetError() == GL_NO_ERROR; |
| 2096 | if (success) { |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2097 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2098 | bytes_allocated_ = image_size; |
| 2099 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2100 | } |
| 2101 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2102 | } |
| 2103 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2104 | void BackTexture::Copy(const gfx::Size& size, GLenum format) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2105 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2106 | ScopedGLErrorSuppressor suppressor("BackTexture::Copy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2107 | state_->GetErrorState()); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2108 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2109 | glCopyTexImage2D(GL_TEXTURE_2D, |
| 2110 | 0, // level |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 2111 | format, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2112 | 0, 0, |
| 2113 | size.width(), |
| 2114 | size.height(), |
| 2115 | 0); // border |
| 2116 | } |
| 2117 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2118 | void BackTexture::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2119 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2120 | ScopedGLErrorSuppressor suppressor("BackTexture::Destroy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2121 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2122 | glDeleteTextures(1, &id_); |
| 2123 | id_ = 0; |
| 2124 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2125 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2126 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2127 | } |
| 2128 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2129 | void BackTexture::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2130 | id_ = 0; |
| 2131 | } |
| 2132 | |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2133 | BackRenderbuffer::BackRenderbuffer( |
| 2134 | RenderbufferManager* renderbuffer_manager, |
| 2135 | MemoryTracker* memory_tracker, |
| 2136 | ContextState* state) |
| 2137 | : renderbuffer_manager_(renderbuffer_manager), |
| 2138 | memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 2139 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2140 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 2141 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2142 | } |
| 2143 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2144 | BackRenderbuffer::~BackRenderbuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2145 | // This does not destroy the render buffer because that would require that |
| 2146 | // the associated GL context was current. Just check that it was explicitly |
| 2147 | // destroyed. |
| 2148 | DCHECK_EQ(id_, 0u); |
| 2149 | } |
| 2150 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2151 | void BackRenderbuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2152 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Create", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2153 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2154 | Destroy(); |
| 2155 | glGenRenderbuffersEXT(1, &id_); |
| 2156 | } |
| 2157 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2158 | bool BackRenderbuffer::AllocateStorage(const FeatureInfo* feature_info, |
| 2159 | const gfx::Size& size, |
| 2160 | GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2161 | GLsizei samples) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2162 | ScopedGLErrorSuppressor suppressor( |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2163 | "BackRenderbuffer::AllocateStorage", state_->GetErrorState()); |
| 2164 | ScopedRenderBufferBinder binder(state_, id_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2165 | |
| 2166 | uint32 estimated_size = 0; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2167 | if (!renderbuffer_manager_->ComputeEstimatedRenderbufferSize( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 2168 | size.width(), size.height(), samples, format, &estimated_size)) { |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2169 | return false; |
| 2170 | } |
| 2171 | |
| 2172 | if (!memory_tracker_.EnsureGPUMemoryAvailable(estimated_size)) { |
| 2173 | return false; |
| 2174 | } |
| 2175 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2176 | if (samples <= 1) { |
| 2177 | glRenderbufferStorageEXT(GL_RENDERBUFFER, |
| 2178 | format, |
| 2179 | size.width(), |
| 2180 | size.height()); |
| 2181 | } else { |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2182 | GLES2DecoderImpl::RenderbufferStorageMultisampleHelper(feature_info, |
| 2183 | GL_RENDERBUFFER, |
| 2184 | samples, |
| 2185 | format, |
| 2186 | size.width(), |
| 2187 | size.height()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2188 | } |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2189 | bool success = glGetError() == GL_NO_ERROR; |
| 2190 | if (success) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2191 | // Mark the previously allocated bytes as free. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2192 | memory_tracker_.TrackMemFree(bytes_allocated_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2193 | bytes_allocated_ = estimated_size; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2194 | // Track the newly allocated bytes. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2195 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2196 | } |
| 2197 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2198 | } |
| 2199 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2200 | void BackRenderbuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2201 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2202 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Destroy", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2203 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2204 | glDeleteRenderbuffersEXT(1, &id_); |
| 2205 | id_ = 0; |
| 2206 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2207 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2208 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2209 | } |
| 2210 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2211 | void BackRenderbuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2212 | id_ = 0; |
| 2213 | } |
| 2214 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2215 | BackFramebuffer::BackFramebuffer(GLES2DecoderImpl* decoder) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2216 | : decoder_(decoder), |
| 2217 | id_(0) { |
| 2218 | } |
| 2219 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2220 | BackFramebuffer::~BackFramebuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2221 | // This does not destroy the frame buffer because that would require that |
| 2222 | // the associated GL context was current. Just check that it was explicitly |
| 2223 | // destroyed. |
| 2224 | DCHECK_EQ(id_, 0u); |
| 2225 | } |
| 2226 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2227 | void BackFramebuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2228 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Create", |
| 2229 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2230 | Destroy(); |
| 2231 | glGenFramebuffersEXT(1, &id_); |
| 2232 | } |
| 2233 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2234 | void BackFramebuffer::AttachRenderTexture(BackTexture* texture) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2235 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2236 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2237 | "BackFramebuffer::AttachRenderTexture", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2238 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2239 | GLuint attach_id = texture ? texture->id() : 0; |
| 2240 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 2241 | GL_COLOR_ATTACHMENT0, |
| 2242 | GL_TEXTURE_2D, |
| 2243 | attach_id, |
| 2244 | 0); |
| 2245 | } |
| 2246 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2247 | void BackFramebuffer::AttachRenderBuffer(GLenum target, |
| 2248 | BackRenderbuffer* render_buffer) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2249 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2250 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2251 | "BackFramebuffer::AttachRenderBuffer", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2252 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2253 | GLuint attach_id = render_buffer ? render_buffer->id() : 0; |
| 2254 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2255 | target, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2256 | GL_RENDERBUFFER, |
| 2257 | attach_id); |
| 2258 | } |
| 2259 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2260 | void BackFramebuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2261 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2262 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Destroy", |
| 2263 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2264 | glDeleteFramebuffersEXT(1, &id_); |
| 2265 | id_ = 0; |
| 2266 | } |
| 2267 | } |
| 2268 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2269 | void BackFramebuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2270 | id_ = 0; |
| 2271 | } |
| 2272 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2273 | GLenum BackFramebuffer::CheckStatus() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2274 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2275 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::CheckStatus", |
| 2276 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2277 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2278 | return glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 2279 | } |
| 2280 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2281 | GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) { |
| 2282 | return new GLES2DecoderImpl(group); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2283 | } |
| 2284 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2285 | GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2286 | : GLES2Decoder(), |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2287 | group_(group), |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 2288 | logger_(&debug_marker_manager_), |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2289 | state_(group_->feature_info(), this, &logger_), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2290 | unpack_flip_y_(false), |
| 2291 | unpack_premultiply_alpha_(false), |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 2292 | unpack_unpremultiply_alpha_(false), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2293 | attrib_0_buffer_id_(0), |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 2294 | attrib_0_buffer_matches_value_(true), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2295 | attrib_0_size_(0), |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2296 | fixed_attrib_buffer_id_(0), |
| 2297 | fixed_attrib_buffer_size_(0), |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2298 | offscreen_target_color_format_(0), |
| 2299 | offscreen_target_depth_format_(0), |
| 2300 | offscreen_target_stencil_format_(0), |
| 2301 | offscreen_target_samples_(0), |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2302 | offscreen_target_buffer_preserved_(true), |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2303 | offscreen_saved_color_format_(0), |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 2304 | back_buffer_color_format_(0), |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2305 | back_buffer_has_depth_(false), |
| 2306 | back_buffer_has_stencil_(false), |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2307 | surfaceless_(false), |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 2308 | backbuffer_needs_clear_bits_(0), |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 2309 | current_decoder_error_(error::kNoError), |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 2310 | use_shader_translator_(true), |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 2311 | validators_(group_->feature_info()->validators()), |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 2312 | feature_info_(group_->feature_info()), |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2313 | frame_number_(0), |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2314 | has_robustness_extension_(false), |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 2315 | reset_status_(GL_NO_ERROR), |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 2316 | reset_by_robustness_extension_(false), |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 2317 | supports_post_sub_buffer_(false), |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2318 | force_webgl_glsl_validation_(false), |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2319 | derivatives_explicitly_enabled_(false), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2320 | frag_depth_explicitly_enabled_(false), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 2321 | draw_buffers_explicitly_enabled_(false), |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 2322 | shader_texture_lod_explicitly_enabled_(false), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2323 | compile_shader_always_succeeds_(false), |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2324 | lose_context_when_out_of_memory_(false), |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 2325 | service_logging_(CommandLine::ForCurrentProcess()->HasSwitch( |
| 2326 | switches::kEnableGPUServiceLoggingGPU)), |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2327 | viewport_max_width_(0), |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2328 | viewport_max_height_(0), |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 2329 | texture_state_(group_->feature_info() |
| 2330 | ->workarounds() |
| 2331 | .texsubimage2d_faster_than_teximage2d), |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 2332 | cb_command_trace_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 2333 | TRACE_DISABLED_BY_DEFAULT("cb_command"))), |
| 2334 | gpu_trace_level_(2), |
| 2335 | gpu_trace_commands_(false), |
| 2336 | gpu_debug_commands_(false), |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2337 | validation_texture_(0), |
| 2338 | validation_fbo_multisample_(0), |
| 2339 | validation_fbo_(0) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2340 | DCHECK(group); |
| 2341 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2342 | attrib_0_value_.v[0] = 0.0f; |
| 2343 | attrib_0_value_.v[1] = 0.0f; |
| 2344 | attrib_0_value_.v[2] = 0.0f; |
| 2345 | attrib_0_value_.v[3] = 1.0f; |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2346 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2347 | // The shader translator is used for WebGL even when running on EGL |
| 2348 | // because additional restrictions are needed (like only enabling |
| 2349 | // GL_OES_standard_derivatives on demand). It is used for the unit |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 2350 | // tests because GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes |
| 2351 | // the empty string to CompileShader and this is not a valid shader. |
| 2352 | if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL || |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2353 | CommandLine::ForCurrentProcess()->HasSwitch( |
| 2354 | switches::kDisableGLSLTranslator)) { |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2355 | use_shader_translator_ = false; |
| 2356 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2357 | } |
| 2358 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2359 | GLES2DecoderImpl::~GLES2DecoderImpl() { |
| 2360 | } |
| 2361 | |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2362 | bool GLES2DecoderImpl::Initialize( |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2363 | const scoped_refptr<gfx::GLSurface>& surface, |
| 2364 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2365 | bool offscreen, |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2366 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2367 | const DisallowedFeatures& disallowed_features, |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2368 | const std::vector<int32>& attribs) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 2369 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2370 | DCHECK(context->IsCurrent(surface.get())); |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 2371 | DCHECK(!context_.get()); |
| 2372 | |
jbauman | a760469 | 2014-10-17 02:00:39 | [diff] [blame^] | 2373 | surfaceless_ = surface->IsSurfaceless() && !offscreen; |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2374 | |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 2375 | set_initialized(); |
[email protected] | b4af07d | 2014-08-20 00:11:57 | [diff] [blame] | 2376 | gpu_tracer_.reset(new GPUTracer(this)); |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 2377 | gpu_state_tracer_ = GPUStateTracer::Create(&state_); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 2378 | |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 2379 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2380 | switches::kEnableGPUDebugging)) { |
| 2381 | set_debug(true); |
| 2382 | } |
| 2383 | |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2384 | if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 2385 | switches::kEnableGPUCommandLogging)) { |
| 2386 | set_log_commands(true); |
| 2387 | } |
| 2388 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2389 | compile_shader_always_succeeds_ = CommandLine::ForCurrentProcess()->HasSwitch( |
| 2390 | switches::kCompileShaderAlwaysSucceeds); |
| 2391 | |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 2392 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2393 | // Take ownership of the context and surface. The surface can be replaced with |
| 2394 | // SetSurface. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2395 | context_ = context; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2396 | surface_ = surface; |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2397 | |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 2398 | ContextCreationAttribHelper attrib_parser; |
| 2399 | if (!attrib_parser.Parse(attribs)) |
| 2400 | return false; |
| 2401 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2402 | // Save the loseContextWhenOutOfMemory context creation attribute. |
| 2403 | lose_context_when_out_of_memory_ = |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2404 | attrib_parser.lose_context_when_out_of_memory; |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2405 | |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 2406 | // If the failIfMajorPerformanceCaveat context creation attribute was true |
| 2407 | // and we are using a software renderer, fail. |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2408 | if (attrib_parser.fail_if_major_perf_caveat && |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 2409 | feature_info_->feature_flags().is_swiftshader) { |
| 2410 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
| 2411 | Destroy(true); |
| 2412 | return false; |
| 2413 | } |
| 2414 | |
[email protected] | 956aec5 | 2013-09-05 15:41:19 | [diff] [blame] | 2415 | if (!group_->Initialize(this, disallowed_features)) { |
[email protected] | 09ddb91f | 2011-04-14 23:16:22 | [diff] [blame] | 2416 | LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2417 | << "failed to initialize."; |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 2418 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2419 | Destroy(true); |
[email protected] | ae174109 | 2010-11-17 19:16:03 | [diff] [blame] | 2420 | return false; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2421 | } |
[email protected] | b64c2495 | 2012-04-19 03:20:27 | [diff] [blame] | 2422 | CHECK_GL_ERROR(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2423 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2424 | disallowed_features_ = disallowed_features; |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2425 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 2426 | state_.attrib_values.resize(group_->max_vertex_attribs()); |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 2427 | vertex_array_manager_.reset(new VertexArrayManager()); |
| 2428 | |
| 2429 | GLuint default_vertex_attrib_service_id = 0; |
| 2430 | if (features().native_vertex_array_object) { |
| 2431 | glGenVertexArraysOES(1, &default_vertex_attrib_service_id); |
| 2432 | glBindVertexArrayOES(default_vertex_attrib_service_id); |
| 2433 | } |
| 2434 | |
| 2435 | state_.default_vertex_attrib_manager = |
| 2436 | CreateVertexAttribManager(0, default_vertex_attrib_service_id, false); |
| 2437 | |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 2438 | state_.default_vertex_attrib_manager->Initialize( |
[email protected] | 94ba2e0 | 2014-03-12 10:32:00 | [diff] [blame] | 2439 | group_->max_vertex_attribs(), |
| 2440 | feature_info_->workarounds().init_vertex_attributes); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2441 | |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 2442 | // vertex_attrib_manager is set to default_vertex_attrib_manager by this call |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 2443 | DoBindVertexArrayOES(0); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 2444 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2445 | query_manager_.reset(new QueryManager(this, feature_info_.get())); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 2446 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 2447 | image_manager_.reset(new ImageManager); |
| 2448 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2449 | util_.set_num_compressed_texture_formats( |
| 2450 | validators_->compressed_texture_format.GetValues().size()); |
| 2451 | |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 2452 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2453 | // We have to enable vertex array 0 on OpenGL or it won't render. Note that |
| 2454 | // OpenGL ES 2.0 does not have this issue. |
| 2455 | glEnableVertexAttribArray(0); |
| 2456 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2457 | glGenBuffersARB(1, &attrib_0_buffer_id_); |
| 2458 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 2459 | glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); |
| 2460 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2461 | glGenBuffersARB(1, &fixed_attrib_buffer_id_); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 2462 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2463 | state_.texture_units.resize(group_->max_texture_units()); |
| 2464 | for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) { |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2465 | glActiveTexture(GL_TEXTURE0 + tt); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2466 | // We want the last bind to be 2D. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2467 | TextureRef* ref; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2468 | if (features().oes_egl_image_external) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2469 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2470 | GL_TEXTURE_EXTERNAL_OES); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2471 | state_.texture_units[tt].bound_texture_external_oes = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2472 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, ref ? ref->service_id() : 0); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2473 | } |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2474 | if (features().arb_texture_rectangle) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2475 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2476 | GL_TEXTURE_RECTANGLE_ARB); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2477 | state_.texture_units[tt].bound_texture_rectangle_arb = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2478 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, ref ? ref->service_id() : 0); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2479 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2480 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
| 2481 | state_.texture_units[tt].bound_texture_cube_map = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2482 | glBindTexture(GL_TEXTURE_CUBE_MAP, ref ? ref->service_id() : 0); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2483 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
| 2484 | state_.texture_units[tt].bound_texture_2d = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2485 | glBindTexture(GL_TEXTURE_2D, ref ? ref->service_id() : 0); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 2486 | } |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2487 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2488 | CHECK_GL_ERROR(); |
| 2489 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2490 | if (offscreen) { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2491 | if (attrib_parser.samples > 0 && attrib_parser.sample_buffers > 0 && |
[email protected] | b060965 | 2012-12-14 07:24:54 | [diff] [blame] | 2492 | features().chromium_framebuffer_multisample) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2493 | // Per ext_framebuffer_multisample spec, need max bound on sample count. |
[email protected] | 0b1e9d7 | 2010-11-11 16:29:43 | [diff] [blame] | 2494 | // max_sample_count must be initialized to a sane value. If |
| 2495 | // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
| 2496 | GLint max_sample_count = 1; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2497 | glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2498 | offscreen_target_samples_ = std::min(attrib_parser.samples, |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2499 | max_sample_count); |
| 2500 | } else { |
| 2501 | offscreen_target_samples_ = 1; |
| 2502 | } |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2503 | offscreen_target_buffer_preserved_ = attrib_parser.buffer_preserved; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2504 | |
| 2505 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 2506 | const bool rgb8_supported = |
| 2507 | context_->HasExtension("GL_OES_rgb8_rgba8"); |
| 2508 | // The only available default render buffer formats in GLES2 have very |
| 2509 | // little precision. Don't enable multisampling unless 8-bit render |
| 2510 | // buffer formats are available--instead fall back to 8-bit textures. |
| 2511 | if (rgb8_supported && offscreen_target_samples_ > 1) { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2512 | offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2513 | GL_RGBA8 : GL_RGB8; |
| 2514 | } else { |
| 2515 | offscreen_target_samples_ = 1; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2516 | offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2517 | GL_RGBA : GL_RGB; |
| 2518 | } |
| 2519 | |
| 2520 | // ANGLE only supports packed depth/stencil formats, so use it if it is |
| 2521 | // available. |
| 2522 | const bool depth24_stencil8_supported = |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2523 | feature_info_->feature_flags().packed_depth24_stencil8; |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2524 | VLOG(1) << "GL_OES_packed_depth_stencil " |
| 2525 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2526 | if ((attrib_parser.depth_size > 0 || attrib_parser.stencil_size > 0) && |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2527 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2528 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2529 | offscreen_target_stencil_format_ = 0; |
| 2530 | } else { |
| 2531 | // It may be the case that this depth/stencil combination is not |
| 2532 | // supported, but this will be checked later by CheckFramebufferStatus. |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2533 | offscreen_target_depth_format_ = attrib_parser.depth_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2534 | GL_DEPTH_COMPONENT16 : 0; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2535 | offscreen_target_stencil_format_ = attrib_parser.stencil_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2536 | GL_STENCIL_INDEX8 : 0; |
| 2537 | } |
| 2538 | } else { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2539 | offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2540 | GL_RGBA : GL_RGB; |
| 2541 | |
| 2542 | // If depth is requested at all, use the packed depth stencil format if |
| 2543 | // it's available, as some desktop GL drivers don't support any non-packed |
| 2544 | // formats for depth attachments. |
| 2545 | const bool depth24_stencil8_supported = |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2546 | feature_info_->feature_flags().packed_depth24_stencil8; |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2547 | VLOG(1) << "GL_EXT_packed_depth_stencil " |
| 2548 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2549 | |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2550 | if ((attrib_parser.depth_size > 0 || attrib_parser.stencil_size > 0) && |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2551 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2552 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2553 | offscreen_target_stencil_format_ = 0; |
| 2554 | } else { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2555 | offscreen_target_depth_format_ = attrib_parser.depth_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2556 | GL_DEPTH_COMPONENT : 0; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2557 | offscreen_target_stencil_format_ = attrib_parser.stencil_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2558 | GL_STENCIL_INDEX : 0; |
| 2559 | } |
| 2560 | } |
| 2561 | |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2562 | offscreen_saved_color_format_ = attrib_parser.alpha_size > 0 ? |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2563 | GL_RGBA : GL_RGB; |
| 2564 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2565 | // Create the target frame buffer. This is the one that the client renders |
| 2566 | // directly to. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2567 | offscreen_target_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2568 | offscreen_target_frame_buffer_->Create(); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2569 | // Due to GLES2 format limitations, either the color texture (for |
| 2570 | // non-multisampling) or the color render buffer (for multisampling) will be |
| 2571 | // attached to the offscreen frame buffer. The render buffer has more |
| 2572 | // limited formats available to it, but the texture can't do multisampling. |
| 2573 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2574 | offscreen_target_color_render_buffer_.reset(new BackRenderbuffer( |
| 2575 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2576 | offscreen_target_color_render_buffer_->Create(); |
| 2577 | } else { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2578 | offscreen_target_color_texture_.reset(new BackTexture( |
| 2579 | memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2580 | offscreen_target_color_texture_->Create(); |
| 2581 | } |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2582 | offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer( |
| 2583 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2584 | offscreen_target_depth_render_buffer_->Create(); |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2585 | offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer( |
| 2586 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2587 | offscreen_target_stencil_render_buffer_->Create(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2588 | |
| 2589 | // Create the saved offscreen texture. The target frame buffer is copied |
| 2590 | // here when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2591 | offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2592 | offscreen_saved_frame_buffer_->Create(); |
| 2593 | // |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2594 | offscreen_saved_color_texture_.reset(new BackTexture( |
| 2595 | memory_tracker(), &state_)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2596 | offscreen_saved_color_texture_->Create(); |
| 2597 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2598 | // Allocate the render buffers at their initial size and check the status |
| 2599 | // of the frame buffers is okay. |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2600 | if (!ResizeOffscreenFrameBuffer(size)) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 2601 | LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2602 | Destroy(true); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2603 | return false; |
| 2604 | } |
| 2605 | |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2606 | // Allocate the offscreen saved color texture. |
| 2607 | DCHECK(offscreen_saved_color_format_); |
| 2608 | offscreen_saved_color_texture_->AllocateStorage( |
| 2609 | gfx::Size(1, 1), offscreen_saved_color_format_, true); |
| 2610 | |
| 2611 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 2612 | offscreen_saved_color_texture_.get()); |
| 2613 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 2614 | GL_FRAMEBUFFER_COMPLETE) { |
| 2615 | LOG(ERROR) << "Offscreen saved FBO was incomplete."; |
| 2616 | Destroy(true); |
| 2617 | return false; |
| 2618 | } |
| 2619 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2620 | // Bind to the new default frame buffer (the offscreen target frame buffer). |
| 2621 | // This should now be associated with ID zero. |
| 2622 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 2623 | } else { |
| 2624 | glBindFramebufferEXT(GL_FRAMEBUFFER, GetBackbufferServiceId()); |
| 2625 | // These are NOT if the back buffer has these proprorties. They are |
| 2626 | // if we want the command buffer to enforce them regardless of what |
| 2627 | // the real backbuffer is assuming the real back buffer gives us more than |
| 2628 | // we ask for. In other words, if we ask for RGB and we get RGBA then we'll |
| 2629 | // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we |
| 2630 | // can't do anything about that. |
| 2631 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2632 | if (!surfaceless_) { |
| 2633 | GLint v = 0; |
| 2634 | glGetIntegerv(GL_ALPHA_BITS, &v); |
| 2635 | // This checks if the user requested RGBA and we have RGBA then RGBA. If |
| 2636 | // the user requested RGB then RGB. If the user did not specify a |
| 2637 | // preference than use whatever we were given. Same for DEPTH and STENCIL. |
| 2638 | back_buffer_color_format_ = |
| 2639 | (attrib_parser.alpha_size != 0 && v > 0) ? GL_RGBA : GL_RGB; |
| 2640 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 2641 | back_buffer_has_depth_ = attrib_parser.depth_size != 0 && v > 0; |
| 2642 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 2643 | back_buffer_has_stencil_ = attrib_parser.stencil_size != 0 && v > 0; |
| 2644 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2645 | } |
| 2646 | |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2647 | // OpenGL ES 2.0 implicitly enables the desktop GL capability |
| 2648 | // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact |
| 2649 | // isn't well documented; it was discovered in the Khronos OpenGL ES |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2650 | // mailing list archives. It also implicitly enables the desktop GL |
| 2651 | // capability GL_POINT_SPRITE to provide access to the gl_PointCoord |
| 2652 | // variable in fragment shaders. |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2653 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2654 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2655 | glEnable(GL_POINT_SPRITE); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2656 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2657 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2658 | has_robustness_extension_ = |
| 2659 | context->HasExtension("GL_ARB_robustness") || |
| 2660 | context->HasExtension("GL_EXT_robustness"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2661 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2662 | if (!InitializeShaderTranslator()) { |
| 2663 | return false; |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2664 | } |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2665 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2666 | state_.viewport_width = size.width(); |
| 2667 | state_.viewport_height = size.height(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2668 | |
[email protected] | 5904806b | 2012-05-08 18:10:22 | [diff] [blame] | 2669 | GLint viewport_params[4] = { 0 }; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2670 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2671 | viewport_max_width_ = viewport_params[0]; |
| 2672 | viewport_max_height_ = viewport_params[1]; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2673 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2674 | state_.scissor_width = state_.viewport_width; |
| 2675 | state_.scissor_height = state_.viewport_height; |
| 2676 | |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2677 | // Set all the default state because some GL drivers get it wrong. |
[email protected] | 88ba52f | 2014-04-09 12:39:34 | [diff] [blame] | 2678 | state_.InitCapabilities(NULL); |
| 2679 | state_.InitState(NULL); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2680 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2681 | |
| 2682 | DoBindBuffer(GL_ARRAY_BUFFER, 0); |
| 2683 | DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 2684 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2685 | DoBindRenderbuffer(GL_RENDERBUFFER, 0); |
| 2686 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2687 | bool call_gl_clear = !surfaceless_; |
[email protected] | 88cfd13 | 2013-07-11 00:59:00 | [diff] [blame] | 2688 | #if defined(OS_ANDROID) |
| 2689 | // Temporary workaround for Android WebView because this clear ignores the |
| 2690 | // clip and corrupts that external UI of the App. Not calling glClear is ok |
| 2691 | // because the system already clears the buffer before each draw. Proper |
| 2692 | // fix might be setting the scissor clip properly before initialize. See |
| 2693 | // crbug.com/259023 for details. |
| 2694 | call_gl_clear = surface_->GetHandle(); |
| 2695 | #endif |
| 2696 | if (call_gl_clear) { |
| 2697 | // Clear the backbuffer. |
| 2698 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 2699 | } |
[email protected] | 561cc0a6 | 2013-05-07 18:34:45 | [diff] [blame] | 2700 | |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 2701 | supports_post_sub_buffer_ = surface->SupportsPostSubBuffer(); |
| 2702 | if (feature_info_->workarounds() |
| 2703 | .disable_post_sub_buffers_for_onscreen_surfaces && |
| 2704 | !surface->IsOffscreen()) |
| 2705 | supports_post_sub_buffer_ = false; |
| 2706 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2707 | if (feature_info_->workarounds().reverse_point_sprite_coord_origin) { |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2708 | glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); |
| 2709 | } |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2710 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 2711 | if (feature_info_->workarounds().unbind_fbo_on_context_switch) { |
| 2712 | context_->SetUnbindFboOnMakeCurrent(); |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2713 | } |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2714 | |
[email protected] | 97419c0 | 2013-04-10 02:52:38 | [diff] [blame] | 2715 | // Only compositor contexts are known to use only the subset of GL |
| 2716 | // that can be safely migrated between the iGPU and the dGPU. Mark |
| 2717 | // those contexts as safe to forcibly transition between the GPUs. |
| 2718 | // http://crbug.com/180876, http://crbug.com/227228 |
| 2719 | if (!offscreen) |
| 2720 | context_->SetSafeToForceGpuSwitch(); |
| 2721 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 2722 | async_pixel_transfer_manager_.reset( |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 2723 | AsyncPixelTransferManager::Create(context.get())); |
| 2724 | async_pixel_transfer_manager_->Initialize(texture_manager()); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 2725 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 2726 | framebuffer_manager()->AddObserver(this); |
| 2727 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2728 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2729 | } |
| 2730 | |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2731 | Capabilities GLES2DecoderImpl::GetCapabilities() { |
| 2732 | DCHECK(initialized()); |
| 2733 | |
| 2734 | Capabilities caps; |
| 2735 | |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2736 | caps.egl_image_external = |
| 2737 | feature_info_->feature_flags().oes_egl_image_external; |
| 2738 | caps.texture_format_bgra8888 = |
| 2739 | feature_info_->feature_flags().ext_texture_format_bgra8888; |
| 2740 | caps.texture_format_etc1 = |
| 2741 | feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; |
aelias | d880a3d | 2014-08-26 00:46:20 | [diff] [blame] | 2742 | caps.texture_format_etc1_npot = |
| 2743 | caps.texture_format_etc1 && !workarounds().etc1_power_of_two_only; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2744 | caps.texture_rectangle = feature_info_->feature_flags().arb_texture_rectangle; |
| 2745 | caps.texture_usage = feature_info_->feature_flags().angle_texture_usage; |
| 2746 | caps.texture_storage = feature_info_->feature_flags().ext_texture_storage; |
| 2747 | caps.discard_framebuffer = |
| 2748 | feature_info_->feature_flags().ext_discard_framebuffer; |
[email protected] | 12c99ab0 | 2014-04-22 10:12:35 | [diff] [blame] | 2749 | caps.sync_query = feature_info_->feature_flags().chromium_sync_query; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2750 | |
| 2751 | #if defined(OS_MACOSX) |
| 2752 | // This is unconditionally true on mac, no need to test for it at runtime. |
| 2753 | caps.iosurface = true; |
| 2754 | #endif |
| 2755 | |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 2756 | caps.post_sub_buffer = supports_post_sub_buffer_; |
reveman | 34010918 | 2014-09-30 15:36:45 | [diff] [blame] | 2757 | caps.image = true; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2758 | |
ed | fad658b | 2014-10-10 08:59:52 | [diff] [blame] | 2759 | caps.blend_minmax = feature_info_->feature_flags().ext_blend_minmax; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2760 | return caps; |
| 2761 | } |
| 2762 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2763 | void GLES2DecoderImpl::UpdateCapabilities() { |
| 2764 | util_.set_num_compressed_texture_formats( |
| 2765 | validators_->compressed_texture_format.GetValues().size()); |
| 2766 | util_.set_num_shader_binary_formats( |
| 2767 | validators_->shader_binary_format.GetValues().size()); |
| 2768 | } |
| 2769 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2770 | bool GLES2DecoderImpl::InitializeShaderTranslator() { |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 2771 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::InitializeShaderTranslator"); |
| 2772 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2773 | if (!use_shader_translator_) { |
| 2774 | return true; |
| 2775 | } |
| 2776 | ShBuiltInResources resources; |
| 2777 | ShInitBuiltInResources(&resources); |
| 2778 | resources.MaxVertexAttribs = group_->max_vertex_attribs(); |
| 2779 | resources.MaxVertexUniformVectors = |
| 2780 | group_->max_vertex_uniform_vectors(); |
| 2781 | resources.MaxVaryingVectors = group_->max_varying_vectors(); |
| 2782 | resources.MaxVertexTextureImageUnits = |
| 2783 | group_->max_vertex_texture_image_units(); |
| 2784 | resources.MaxCombinedTextureImageUnits = group_->max_texture_units(); |
| 2785 | resources.MaxTextureImageUnits = group_->max_texture_image_units(); |
| 2786 | resources.MaxFragmentUniformVectors = |
| 2787 | group_->max_fragment_uniform_vectors(); |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 2788 | resources.MaxDrawBuffers = group_->max_draw_buffers(); |
[email protected] | a0b7814 | 2013-05-23 00:47:24 | [diff] [blame] | 2789 | resources.MaxExpressionComplexity = 256; |
| 2790 | resources.MaxCallStackDepth = 256; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2791 | |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 2792 | GLint range[2] = { 0, 0 }; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 2793 | GLint precision = 0; |
| 2794 | GetShaderPrecisionFormatImpl(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, |
| 2795 | range, &precision); |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 2796 | resources.FragmentPrecisionHigh = |
| 2797 | PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision); |
[email protected] | 9e98f61b | 2013-03-05 02:21:14 | [diff] [blame] | 2798 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2799 | if (force_webgl_glsl_validation_) { |
| 2800 | resources.OES_standard_derivatives = derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2801 | resources.EXT_frag_depth = frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 2802 | resources.EXT_draw_buffers = draw_buffers_explicitly_enabled_; |
[email protected] | cd8f189 | 2013-09-05 00:14:44 | [diff] [blame] | 2803 | if (!draw_buffers_explicitly_enabled_) |
| 2804 | resources.MaxDrawBuffers = 1; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 2805 | resources.EXT_shader_texture_lod = shader_texture_lod_explicitly_enabled_; |
oetuaho | 0decd44 | 2014-10-13 08:40:46 | [diff] [blame] | 2806 | resources.NV_draw_buffers = |
| 2807 | draw_buffers_explicitly_enabled_ && features().nv_draw_buffers; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2808 | } else { |
| 2809 | resources.OES_standard_derivatives = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2810 | features().oes_standard_derivatives ? 1 : 0; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2811 | resources.ARB_texture_rectangle = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2812 | features().arb_texture_rectangle ? 1 : 0; |
[email protected] | 70e7bb1 | 2012-09-29 14:01:06 | [diff] [blame] | 2813 | resources.OES_EGL_image_external = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2814 | features().oes_egl_image_external ? 1 : 0; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 2815 | resources.EXT_draw_buffers = |
| 2816 | features().ext_draw_buffers ? 1 : 0; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2817 | resources.EXT_frag_depth = |
| 2818 | features().ext_frag_depth ? 1 : 0; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 2819 | resources.EXT_shader_texture_lod = |
| 2820 | features().ext_shader_texture_lod ? 1 : 0; |
oetuaho | 0decd44 | 2014-10-13 08:40:46 | [diff] [blame] | 2821 | resources.NV_draw_buffers = |
| 2822 | features().nv_draw_buffers ? 1 : 0; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2823 | } |
| 2824 | |
[email protected] | 26b6144 | 2013-03-17 16:12:01 | [diff] [blame] | 2825 | ShShaderSpec shader_spec = force_webgl_glsl_validation_ ? SH_WEBGL_SPEC |
| 2826 | : SH_GLES2_SPEC; |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2827 | if (shader_spec == SH_WEBGL_SPEC && features().enable_shader_name_hashing) |
[email protected] | 3d944a8 | 2013-02-12 19:09:02 | [diff] [blame] | 2828 | resources.HashFunction = &CityHash64; |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2829 | else |
| 2830 | resources.HashFunction = NULL; |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2831 | ShaderTranslatorInterface::GlslImplementationType implementation_type = |
| 2832 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? |
| 2833 | ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2834 | int driver_bug_workarounds = 0; |
| 2835 | if (workarounds().needs_glsl_built_in_function_emulation) |
| 2836 | driver_bug_workarounds |= SH_EMULATE_BUILT_IN_FUNCTIONS; |
[email protected] | 81187c6 | 2013-09-09 23:54:54 | [diff] [blame] | 2837 | if (workarounds().init_gl_position_in_vertex_shader) |
| 2838 | driver_bug_workarounds |= SH_INIT_GL_POSITION; |
[email protected] | f0c8760 | 2013-10-17 19:34:11 | [diff] [blame] | 2839 | if (workarounds().unfold_short_circuit_as_ternary_operation) |
| 2840 | driver_bug_workarounds |= SH_UNFOLD_SHORT_CIRCUIT; |
[email protected] | b03219d | 2014-02-12 11:17:05 | [diff] [blame] | 2841 | if (workarounds().init_varyings_without_static_use) |
| 2842 | driver_bug_workarounds |= SH_INIT_VARYINGS_WITHOUT_STATIC_USE; |
[email protected] | f4db2b1 | 2014-03-01 03:57:06 | [diff] [blame] | 2843 | if (workarounds().unroll_for_loop_with_sampler_array_index) |
| 2844 | driver_bug_workarounds |= SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX; |
[email protected] | 711e9080 | 2014-07-22 20:40:25 | [diff] [blame] | 2845 | if (workarounds().scalarize_vec_and_mat_constructor_args) |
| 2846 | driver_bug_workarounds |= SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS; |
[email protected] | fa6d398 | 2014-08-18 18:10:27 | [diff] [blame] | 2847 | if (workarounds().regenerate_struct_names) |
| 2848 | driver_bug_workarounds |= SH_REGENERATE_STRUCT_NAMES; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2849 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 2850 | vertex_translator_ = shader_translator_cache()->GetTranslator( |
[email protected] | aeecc6b | 2014-07-03 17:18:26 | [diff] [blame] | 2851 | GL_VERTEX_SHADER, |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 2852 | shader_spec, |
| 2853 | &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2854 | implementation_type, |
| 2855 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2856 | if (!vertex_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2857 | LOG(ERROR) << "Could not initialize vertex shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2858 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2859 | return false; |
| 2860 | } |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2861 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 2862 | fragment_translator_ = shader_translator_cache()->GetTranslator( |
[email protected] | aeecc6b | 2014-07-03 17:18:26 | [diff] [blame] | 2863 | GL_FRAGMENT_SHADER, |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 2864 | shader_spec, |
| 2865 | &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2866 | implementation_type, |
| 2867 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2868 | if (!fragment_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2869 | LOG(ERROR) << "Could not initialize fragment shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2870 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2871 | return false; |
| 2872 | } |
| 2873 | return true; |
| 2874 | } |
| 2875 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2876 | bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2877 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2878 | if (GetBuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2879 | return false; |
| 2880 | } |
| 2881 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2882 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2883 | glGenBuffersARB(n, service_ids.get()); |
| 2884 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2885 | CreateBuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2886 | } |
| 2887 | return true; |
| 2888 | } |
| 2889 | |
| 2890 | bool GLES2DecoderImpl::GenFramebuffersHelper( |
| 2891 | GLsizei n, const GLuint* client_ids) { |
| 2892 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2893 | if (GetFramebuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2894 | return false; |
| 2895 | } |
| 2896 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2897 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2898 | glGenFramebuffersEXT(n, service_ids.get()); |
| 2899 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2900 | CreateFramebuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2901 | } |
| 2902 | return true; |
| 2903 | } |
| 2904 | |
| 2905 | bool GLES2DecoderImpl::GenRenderbuffersHelper( |
| 2906 | GLsizei n, const GLuint* client_ids) { |
| 2907 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2908 | if (GetRenderbuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2909 | return false; |
| 2910 | } |
| 2911 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2912 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2913 | glGenRenderbuffersEXT(n, service_ids.get()); |
| 2914 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2915 | CreateRenderbuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2916 | } |
| 2917 | return true; |
| 2918 | } |
| 2919 | |
| 2920 | bool GLES2DecoderImpl::GenTexturesHelper(GLsizei n, const GLuint* client_ids) { |
| 2921 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2922 | if (GetTexture(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2923 | return false; |
| 2924 | } |
| 2925 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2926 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2927 | glGenTextures(n, service_ids.get()); |
| 2928 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2929 | CreateTexture(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2930 | } |
| 2931 | return true; |
| 2932 | } |
| 2933 | |
| 2934 | void GLES2DecoderImpl::DeleteBuffersHelper( |
| 2935 | GLsizei n, const GLuint* client_ids) { |
| 2936 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 2937 | Buffer* buffer = GetBuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2938 | if (buffer && !buffer->IsDeleted()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2939 | state_.vertex_attrib_manager->Unbind(buffer); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2940 | if (state_.bound_array_buffer.get() == buffer) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2941 | state_.bound_array_buffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2942 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2943 | RemoveBuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2944 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2945 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2946 | } |
| 2947 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2948 | void GLES2DecoderImpl::DeleteFramebuffersHelper( |
| 2949 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2950 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2951 | features().chromium_framebuffer_multisample; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2952 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2953 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2954 | Framebuffer* framebuffer = |
| 2955 | GetFramebuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2956 | if (framebuffer && !framebuffer->IsDeleted()) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2957 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2958 | framebuffer_state_.bound_draw_framebuffer = NULL; |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2959 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2960 | GLenum target = supports_separate_framebuffer_binds ? |
| 2961 | GL_DRAW_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2962 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
| 2963 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2964 | if (framebuffer == framebuffer_state_.bound_read_framebuffer.get()) { |
| 2965 | framebuffer_state_.bound_read_framebuffer = NULL; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2966 | GLenum target = supports_separate_framebuffer_binds ? |
| 2967 | GL_READ_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 2968 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2969 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 2970 | OnFboChanged(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2971 | RemoveFramebuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2972 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2973 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 2974 | } |
| 2975 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2976 | void GLES2DecoderImpl::DeleteRenderbuffersHelper( |
| 2977 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2978 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2979 | features().chromium_framebuffer_multisample; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 2980 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2981 | Renderbuffer* renderbuffer = |
| 2982 | GetRenderbuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2983 | if (renderbuffer && !renderbuffer->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2984 | if (state_.bound_renderbuffer.get() == renderbuffer) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2985 | state_.bound_renderbuffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2986 | } |
| 2987 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 2988 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2989 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 2990 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2991 | ->UnbindRenderbuffer(GL_READ_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2992 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2993 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2994 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2995 | ->UnbindRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 2996 | } |
| 2997 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2998 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 2999 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3000 | ->UnbindRenderbuffer(GL_FRAMEBUFFER, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3001 | } |
| 3002 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3003 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3004 | RemoveRenderbuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3005 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 3006 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3007 | } |
| 3008 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3009 | void GLES2DecoderImpl::DeleteTexturesHelper( |
| 3010 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3011 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3012 | features().chromium_framebuffer_multisample; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3013 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3014 | TextureRef* texture_ref = GetTexture(client_ids[ii]); |
| 3015 | if (texture_ref) { |
| 3016 | Texture* texture = texture_ref->texture(); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3017 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3018 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3019 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3020 | // Unbind texture_ref from texture_ref units. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3021 | for (size_t jj = 0; jj < state_.texture_units.size(); ++jj) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3022 | state_.texture_units[jj].Unbind(texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3023 | } |
| 3024 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3025 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3026 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 3027 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3028 | ->UnbindTexture(GL_READ_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3029 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3030 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3031 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3032 | ->UnbindTexture(GL_DRAW_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3033 | } |
| 3034 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3035 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3036 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3037 | ->UnbindTexture(GL_FRAMEBUFFER, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3038 | } |
| 3039 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3040 | #if defined(OS_MACOSX) |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 3041 | GLuint service_id = texture->service_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3042 | if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { |
| 3043 | ReleaseIOSurfaceForTexture(service_id); |
| 3044 | } |
| 3045 | #endif |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3046 | RemoveTexture(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3047 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3048 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3049 | } |
| 3050 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 3051 | // } // anonymous namespace |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3052 | |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 3053 | bool GLES2DecoderImpl::MakeCurrent() { |
[email protected] | 177d134 | 2013-12-07 04:20:34 | [diff] [blame] | 3054 | if (!context_.get()) |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3055 | return false; |
| 3056 | |
[email protected] | 177d134 | 2013-12-07 04:20:34 | [diff] [blame] | 3057 | if (!context_->MakeCurrent(surface_.get()) || WasContextLost()) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 3058 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during MakeCurrent."; |
[email protected] | e9f0ca8 | 2013-04-01 23:52:29 | [diff] [blame] | 3059 | |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 3060 | MaybeExitOnContextLost(); |
[email protected] | e9f0ca8 | 2013-04-01 23:52:29 | [diff] [blame] | 3061 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3062 | return false; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 3063 | } |
| 3064 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 3065 | ProcessFinishedAsyncTransfers(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 3066 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 3067 | // Rebind the FBO if it was unbound by the context. |
| 3068 | if (workarounds().unbind_fbo_on_context_switch) |
| 3069 | RestoreFramebufferBindings(); |
| 3070 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3071 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3072 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 3073 | return true; |
| 3074 | } |
| 3075 | |
| 3076 | void GLES2DecoderImpl::ProcessFinishedAsyncTransfers() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 3077 | ProcessPendingReadPixels(); |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 3078 | if (engine() && query_manager_.get()) |
| 3079 | query_manager_->ProcessPendingTransferQueries(); |
| 3080 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 3081 | // TODO(epenner): Is there a better place to do this? |
| 3082 | // This needs to occur before we execute any batch of commands |
| 3083 | // from the client, as the client may have recieved an async |
| 3084 | // completion while issuing those commands. |
| 3085 | // "DidFlushStart" would be ideal if we had such a callback. |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3086 | async_pixel_transfer_manager_->BindCompletedAsyncTransfers(); |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 3087 | } |
| 3088 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3089 | static void RebindCurrentFramebuffer( |
| 3090 | GLenum target, |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3091 | Framebuffer* framebuffer, |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3092 | GLuint back_buffer_service_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3093 | GLuint framebuffer_id = framebuffer ? framebuffer->service_id() : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3094 | |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3095 | if (framebuffer_id == 0) { |
| 3096 | framebuffer_id = back_buffer_service_id; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3097 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3098 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3099 | glBindFramebufferEXT(target, framebuffer_id); |
| 3100 | } |
| 3101 | |
| 3102 | void GLES2DecoderImpl::RestoreCurrentFramebufferBindings() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3103 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3104 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3105 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3106 | RebindCurrentFramebuffer( |
| 3107 | GL_FRAMEBUFFER, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3108 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3109 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3110 | } else { |
| 3111 | RebindCurrentFramebuffer( |
| 3112 | GL_READ_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3113 | framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3114 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3115 | RebindCurrentFramebuffer( |
| 3116 | GL_DRAW_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3117 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3118 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3119 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3120 | OnFboChanged(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3121 | } |
| 3122 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3123 | bool GLES2DecoderImpl::CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3124 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3125 | GLenum target, const char* func_name) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3126 | if (!framebuffer) { |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 3127 | if (surfaceless_) |
| 3128 | return false; |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3129 | if (backbuffer_needs_clear_bits_) { |
| 3130 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
| 3131 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3132 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3133 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 3134 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 3135 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3136 | glClearDepth(1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3137 | state_.SetDeviceDepthMask(GL_TRUE); |
| 3138 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 3139 | bool reset_draw_buffer = false; |
| 3140 | if ((backbuffer_needs_clear_bits_ | GL_COLOR_BUFFER_BIT) != 0 && |
| 3141 | group_->draw_buffer() == GL_NONE) { |
| 3142 | reset_draw_buffer = true; |
| 3143 | GLenum buf = GL_BACK; |
| 3144 | if (GetBackbufferServiceId() != 0) // emulated backbuffer |
| 3145 | buf = GL_COLOR_ATTACHMENT0; |
| 3146 | glDrawBuffersARB(1, &buf); |
| 3147 | } |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3148 | glClear(backbuffer_needs_clear_bits_); |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 3149 | if (reset_draw_buffer) { |
| 3150 | GLenum buf = GL_NONE; |
| 3151 | glDrawBuffersARB(1, &buf); |
| 3152 | } |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3153 | backbuffer_needs_clear_bits_ = 0; |
| 3154 | RestoreClearState(); |
| 3155 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3156 | return true; |
| 3157 | } |
| 3158 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 3159 | if (framebuffer_manager()->IsComplete(framebuffer)) { |
| 3160 | return true; |
| 3161 | } |
| 3162 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3163 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 3164 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3165 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3166 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, "framebuffer incomplete"); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 3167 | return false; |
| 3168 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3169 | |
| 3170 | // Are all the attachments cleared? |
| 3171 | if (renderbuffer_manager()->HaveUnclearedRenderbuffers() || |
| 3172 | texture_manager()->HaveUnclearedMips()) { |
| 3173 | if (!framebuffer->IsCleared()) { |
| 3174 | // Can we clear them? |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 3175 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 3176 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3177 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3178 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 3179 | "framebuffer incomplete (clear)"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3180 | return false; |
| 3181 | } |
| 3182 | ClearUnclearedAttachments(target, framebuffer); |
| 3183 | } |
| 3184 | } |
| 3185 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 3186 | if (!framebuffer_manager()->IsComplete(framebuffer)) { |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 3187 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 3188 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3189 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3190 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 3191 | "framebuffer incomplete (check)"); |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 3192 | return false; |
| 3193 | } |
| 3194 | framebuffer_manager()->MarkAsComplete(framebuffer); |
| 3195 | } |
| 3196 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3197 | // NOTE: At this point we don't know if the framebuffer is complete but |
| 3198 | // we DO know that everything that needs to be cleared has been cleared. |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 3199 | return true; |
| 3200 | } |
| 3201 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3202 | bool GLES2DecoderImpl::CheckBoundFramebuffersValid(const char* func_name) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3203 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3204 | bool valid = CheckFramebufferValid( |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3205 | framebuffer_state_.bound_draw_framebuffer.get(), GL_FRAMEBUFFER_EXT, |
| 3206 | func_name); |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3207 | |
| 3208 | if (valid) |
| 3209 | OnUseFramebuffer(); |
| 3210 | |
| 3211 | return valid; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3212 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3213 | return CheckFramebufferValid(framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3214 | GL_DRAW_FRAMEBUFFER_EXT, |
| 3215 | func_name) && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3216 | CheckFramebufferValid(framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3217 | GL_READ_FRAMEBUFFER_EXT, |
| 3218 | func_name); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3219 | } |
| 3220 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 3221 | bool GLES2DecoderImpl::CheckBoundReadFramebufferColorAttachment( |
| 3222 | const char* func_name) { |
| 3223 | Framebuffer* framebuffer = features().chromium_framebuffer_multisample ? |
| 3224 | framebuffer_state_.bound_read_framebuffer.get() : |
| 3225 | framebuffer_state_.bound_draw_framebuffer.get(); |
| 3226 | if (!framebuffer) |
| 3227 | return true; |
| 3228 | if (framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL) { |
| 3229 | LOCAL_SET_GL_ERROR( |
| 3230 | GL_INVALID_OPERATION, func_name, "no color image attached"); |
| 3231 | return false; |
| 3232 | } |
| 3233 | return true; |
| 3234 | } |
| 3235 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 3236 | bool GLES2DecoderImpl::FormsTextureCopyingFeedbackLoop( |
| 3237 | TextureRef* texture, GLint level) { |
| 3238 | Framebuffer* framebuffer = features().chromium_framebuffer_multisample ? |
| 3239 | framebuffer_state_.bound_read_framebuffer.get() : |
| 3240 | framebuffer_state_.bound_draw_framebuffer.get(); |
| 3241 | if (!framebuffer) |
| 3242 | return false; |
| 3243 | const Framebuffer::Attachment* attachment = framebuffer->GetAttachment( |
| 3244 | GL_COLOR_ATTACHMENT0); |
| 3245 | if (!attachment) |
| 3246 | return false; |
| 3247 | return attachment->FormsFeedbackLoop(texture, level); |
| 3248 | } |
| 3249 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3250 | gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3251 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3252 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3253 | if (framebuffer != NULL) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3254 | const Framebuffer::Attachment* attachment = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3255 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3256 | if (attachment) { |
| 3257 | return gfx::Size(attachment->width(), attachment->height()); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 3258 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3259 | return gfx::Size(0, 0); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3260 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3261 | return offscreen_size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3262 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 3263 | return surface_->GetSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 3264 | } |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 3265 | } |
| 3266 | |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 3267 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferTextureType() { |
| 3268 | Framebuffer* framebuffer = |
| 3269 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
| 3270 | if (framebuffer != NULL) { |
| 3271 | return framebuffer->GetColorAttachmentTextureType(); |
| 3272 | } else { |
| 3273 | return GL_UNSIGNED_BYTE; |
| 3274 | } |
| 3275 | } |
| 3276 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3277 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3278 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3279 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3280 | if (framebuffer != NULL) { |
| 3281 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3282 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3283 | return offscreen_target_color_format_; |
| 3284 | } else { |
| 3285 | return back_buffer_color_format_; |
| 3286 | } |
| 3287 | } |
| 3288 | |
| 3289 | GLenum GLES2DecoderImpl::GetBoundDrawFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3290 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3291 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3292 | if (framebuffer != NULL) { |
| 3293 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3294 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3295 | return offscreen_target_color_format_; |
| 3296 | } else { |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 3297 | return back_buffer_color_format_; |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3298 | } |
| 3299 | } |
| 3300 | |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 3301 | void GLES2DecoderImpl::UpdateParentTextureInfo() { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3302 | if (!offscreen_saved_color_texture_info_.get()) |
| 3303 | return; |
| 3304 | GLenum target = offscreen_saved_color_texture_info_->texture()->target(); |
| 3305 | glBindTexture(target, offscreen_saved_color_texture_info_->service_id()); |
| 3306 | texture_manager()->SetLevelInfo( |
| 3307 | offscreen_saved_color_texture_info_.get(), |
| 3308 | GL_TEXTURE_2D, |
| 3309 | 0, // level |
| 3310 | GL_RGBA, |
| 3311 | offscreen_size_.width(), |
| 3312 | offscreen_size_.height(), |
| 3313 | 1, // depth |
| 3314 | 0, // border |
| 3315 | GL_RGBA, |
| 3316 | GL_UNSIGNED_BYTE, |
| 3317 | true); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3318 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3319 | "UpdateParentTextureInfo", |
| 3320 | GetErrorState(), |
| 3321 | offscreen_saved_color_texture_info_.get(), |
| 3322 | GL_TEXTURE_MAG_FILTER, |
[email protected] | eeeb07b9 | 2014-08-16 07:46:26 | [diff] [blame] | 3323 | GL_LINEAR); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3324 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3325 | "UpdateParentTextureInfo", |
| 3326 | GetErrorState(), |
| 3327 | offscreen_saved_color_texture_info_.get(), |
| 3328 | GL_TEXTURE_MIN_FILTER, |
[email protected] | eeeb07b9 | 2014-08-16 07:46:26 | [diff] [blame] | 3329 | GL_LINEAR); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3330 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3331 | "UpdateParentTextureInfo", |
| 3332 | GetErrorState(), |
| 3333 | offscreen_saved_color_texture_info_.get(), |
| 3334 | GL_TEXTURE_WRAP_S, |
| 3335 | GL_CLAMP_TO_EDGE); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3336 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3337 | "UpdateParentTextureInfo", |
| 3338 | GetErrorState(), |
| 3339 | offscreen_saved_color_texture_info_.get(), |
| 3340 | GL_TEXTURE_WRAP_T, |
| 3341 | GL_CLAMP_TO_EDGE); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3342 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 3343 | &state_, target); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3344 | glBindTexture(target, texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3345 | } |
| 3346 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3347 | void GLES2DecoderImpl::SetResizeCallback( |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3348 | const base::Callback<void(gfx::Size, float)>& callback) { |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3349 | resize_callback_ = callback; |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3350 | } |
| 3351 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 3352 | Logger* GLES2DecoderImpl::GetLogger() { |
| 3353 | return &logger_; |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 3354 | } |
| 3355 | |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3356 | void GLES2DecoderImpl::BeginDecoding() { |
| 3357 | gpu_tracer_->BeginDecoding(); |
| 3358 | gpu_trace_commands_ = gpu_tracer_->IsTracing(); |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3359 | gpu_debug_commands_ = log_commands() || debug() || gpu_trace_commands_ || |
| 3360 | (*cb_command_trace_category_ != 0); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | void GLES2DecoderImpl::EndDecoding() { |
| 3364 | gpu_tracer_->EndDecoding(); |
| 3365 | } |
| 3366 | |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 3367 | ErrorState* GLES2DecoderImpl::GetErrorState() { |
| 3368 | return state_.GetErrorState(); |
| 3369 | } |
| 3370 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 3371 | void GLES2DecoderImpl::SetShaderCacheCallback( |
| 3372 | const ShaderCacheCallback& callback) { |
| 3373 | shader_cache_callback_ = callback; |
| 3374 | } |
| 3375 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 3376 | void GLES2DecoderImpl::SetWaitSyncPointCallback( |
| 3377 | const WaitSyncPointCallback& callback) { |
| 3378 | wait_sync_point_callback_ = callback; |
| 3379 | } |
| 3380 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3381 | AsyncPixelTransferManager* |
| 3382 | GLES2DecoderImpl::GetAsyncPixelTransferManager() { |
| 3383 | return async_pixel_transfer_manager_.get(); |
| 3384 | } |
| 3385 | |
| 3386 | void GLES2DecoderImpl::ResetAsyncPixelTransferManagerForTest() { |
| 3387 | async_pixel_transfer_manager_.reset(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 3388 | } |
| 3389 | |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 3390 | void GLES2DecoderImpl::SetAsyncPixelTransferManagerForTest( |
| 3391 | AsyncPixelTransferManager* manager) { |
| 3392 | async_pixel_transfer_manager_ = make_scoped_ptr(manager); |
| 3393 | } |
| 3394 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3395 | bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, |
| 3396 | uint32* service_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3397 | TextureRef* texture_ref = texture_manager()->GetTexture(client_texture_id); |
| 3398 | if (texture_ref) { |
| 3399 | *service_texture_id = texture_ref->service_id(); |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3400 | return true; |
| 3401 | } |
| 3402 | return false; |
| 3403 | } |
| 3404 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3405 | uint32 GLES2DecoderImpl::GetTextureUploadCount() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3406 | return texture_state_.texture_upload_count + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3407 | async_pixel_transfer_manager_->GetTextureUploadCount(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | base::TimeDelta GLES2DecoderImpl::GetTotalTextureUploadTime() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3411 | return texture_state_.total_texture_upload_time + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3412 | async_pixel_transfer_manager_->GetTotalTextureUploadTime(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | base::TimeDelta GLES2DecoderImpl::GetTotalProcessingCommandsTime() { |
| 3416 | return total_processing_commands_time_; |
| 3417 | } |
| 3418 | |
[email protected] | dc25dda | 2012-09-27 21:36:30 | [diff] [blame] | 3419 | void GLES2DecoderImpl::AddProcessingCommandsTime(base::TimeDelta time) { |
| 3420 | total_processing_commands_time_ += time; |
| 3421 | } |
| 3422 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3423 | void GLES2DecoderImpl::Destroy(bool have_context) { |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 3424 | if (!initialized()) |
| 3425 | return; |
| 3426 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3427 | DCHECK(!have_context || context_->IsCurrent(NULL)); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3428 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3429 | // Unbind everything. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3430 | state_.vertex_attrib_manager = NULL; |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 3431 | state_.default_vertex_attrib_manager = NULL; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3432 | state_.texture_units.clear(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3433 | state_.bound_array_buffer = NULL; |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 3434 | state_.current_queries.clear(); |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3435 | framebuffer_state_.bound_read_framebuffer = NULL; |
| 3436 | framebuffer_state_.bound_draw_framebuffer = NULL; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3437 | state_.bound_renderbuffer = NULL; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3438 | |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 3439 | if (offscreen_saved_color_texture_info_.get()) { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3440 | DCHECK(offscreen_target_color_texture_); |
| 3441 | DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), |
| 3442 | offscreen_saved_color_texture_->id()); |
| 3443 | offscreen_saved_color_texture_->Invalidate(); |
| 3444 | offscreen_saved_color_texture_info_ = NULL; |
| 3445 | } |
[email protected] | eadc9679 | 2010-10-27 19:39:39 | [diff] [blame] | 3446 | if (have_context) { |
[email protected] | c322e88 | 2012-05-23 18:06:18 | [diff] [blame] | 3447 | if (copy_texture_CHROMIUM_.get()) { |
| 3448 | copy_texture_CHROMIUM_->Destroy(); |
| 3449 | copy_texture_CHROMIUM_.reset(); |
| 3450 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3451 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3452 | if (state_.current_program.get()) { |
| 3453 | program_manager()->UnuseProgram(shader_manager(), |
| 3454 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 3455 | } |
| 3456 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3457 | if (attrib_0_buffer_id_) { |
| 3458 | glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
| 3459 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 3460 | if (fixed_attrib_buffer_id_) { |
| 3461 | glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); |
| 3462 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3463 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 3464 | if (validation_texture_) { |
| 3465 | glDeleteTextures(1, &validation_texture_); |
| 3466 | glDeleteFramebuffersEXT(1, &validation_fbo_multisample_); |
| 3467 | glDeleteFramebuffersEXT(1, &validation_fbo_); |
| 3468 | } |
| 3469 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3470 | if (offscreen_target_frame_buffer_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3471 | offscreen_target_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3472 | if (offscreen_target_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3473 | offscreen_target_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3474 | if (offscreen_target_color_render_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3475 | offscreen_target_color_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3476 | if (offscreen_target_depth_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3477 | offscreen_target_depth_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3478 | if (offscreen_target_stencil_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3479 | offscreen_target_stencil_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3480 | if (offscreen_saved_frame_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3481 | offscreen_saved_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3482 | if (offscreen_saved_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3483 | offscreen_saved_color_texture_->Destroy(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3484 | if (offscreen_resolved_frame_buffer_.get()) |
| 3485 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3486 | if (offscreen_resolved_color_texture_.get()) |
| 3487 | offscreen_resolved_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3488 | } else { |
| 3489 | if (offscreen_target_frame_buffer_.get()) |
| 3490 | offscreen_target_frame_buffer_->Invalidate(); |
| 3491 | if (offscreen_target_color_texture_.get()) |
| 3492 | offscreen_target_color_texture_->Invalidate(); |
| 3493 | if (offscreen_target_color_render_buffer_.get()) |
| 3494 | offscreen_target_color_render_buffer_->Invalidate(); |
| 3495 | if (offscreen_target_depth_render_buffer_.get()) |
| 3496 | offscreen_target_depth_render_buffer_->Invalidate(); |
| 3497 | if (offscreen_target_stencil_render_buffer_.get()) |
| 3498 | offscreen_target_stencil_render_buffer_->Invalidate(); |
| 3499 | if (offscreen_saved_frame_buffer_.get()) |
| 3500 | offscreen_saved_frame_buffer_->Invalidate(); |
| 3501 | if (offscreen_saved_color_texture_.get()) |
| 3502 | offscreen_saved_color_texture_->Invalidate(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3503 | if (offscreen_resolved_frame_buffer_.get()) |
| 3504 | offscreen_resolved_frame_buffer_->Invalidate(); |
| 3505 | if (offscreen_resolved_color_texture_.get()) |
| 3506 | offscreen_resolved_color_texture_->Invalidate(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 3507 | } |
[email protected] | 83a52d03 | 2013-07-24 10:30:37 | [diff] [blame] | 3508 | |
| 3509 | // Current program must be cleared after calling ProgramManager::UnuseProgram. |
| 3510 | // Otherwise, we can leak objects. http://crbug.com/258772. |
| 3511 | // state_.current_program must be reset before group_ is reset because |
| 3512 | // the later deletes the ProgramManager object that referred by |
| 3513 | // state_.current_program object. |
| 3514 | state_.current_program = NULL; |
| 3515 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3516 | copy_texture_CHROMIUM_.reset(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3517 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3518 | if (query_manager_.get()) { |
| 3519 | query_manager_->Destroy(have_context); |
| 3520 | query_manager_.reset(); |
| 3521 | } |
| 3522 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 3523 | if (vertex_array_manager_ .get()) { |
| 3524 | vertex_array_manager_->Destroy(have_context); |
| 3525 | vertex_array_manager_.reset(); |
| 3526 | } |
| 3527 | |
[email protected] | d2eaf52f | 2014-07-31 15:01:24 | [diff] [blame] | 3528 | if (image_manager_.get()) { |
| 3529 | image_manager_->Destroy(have_context); |
| 3530 | image_manager_.reset(); |
| 3531 | } |
| 3532 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3533 | offscreen_target_frame_buffer_.reset(); |
| 3534 | offscreen_target_color_texture_.reset(); |
| 3535 | offscreen_target_color_render_buffer_.reset(); |
| 3536 | offscreen_target_depth_render_buffer_.reset(); |
| 3537 | offscreen_target_stencil_render_buffer_.reset(); |
| 3538 | offscreen_saved_frame_buffer_.reset(); |
| 3539 | offscreen_saved_color_texture_.reset(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3540 | offscreen_resolved_frame_buffer_.reset(); |
| 3541 | offscreen_resolved_color_texture_.reset(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3542 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 3543 | // Need to release these before releasing |group_| which may own the |
| 3544 | // ShaderTranslatorCache. |
| 3545 | fragment_translator_ = NULL; |
| 3546 | vertex_translator_ = NULL; |
| 3547 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3548 | // Should destroy the transfer manager before the texture manager held |
| 3549 | // by the context group. |
| 3550 | async_pixel_transfer_manager_.reset(); |
| 3551 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3552 | if (group_.get()) { |
[email protected] | ac5e402 | 2014-01-24 12:44:39 | [diff] [blame] | 3553 | framebuffer_manager()->RemoveObserver(this); |
[email protected] | 2d9d3b9 | 2013-01-18 01:07:23 | [diff] [blame] | 3554 | group_->Destroy(this, have_context); |
| 3555 | group_ = NULL; |
| 3556 | } |
| 3557 | |
| 3558 | if (context_.get()) { |
| 3559 | context_->ReleaseCurrent(NULL); |
| 3560 | context_ = NULL; |
| 3561 | } |
| 3562 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3563 | #if defined(OS_MACOSX) |
| 3564 | for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); |
| 3565 | it != texture_to_io_surface_map_.end(); ++it) { |
| 3566 | CFRelease(it->second); |
| 3567 | } |
| 3568 | texture_to_io_surface_map_.clear(); |
| 3569 | #endif |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3570 | } |
| 3571 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3572 | void GLES2DecoderImpl::SetSurface( |
| 3573 | const scoped_refptr<gfx::GLSurface>& surface) { |
| 3574 | DCHECK(context_->IsCurrent(NULL)); |
| 3575 | DCHECK(surface_.get()); |
| 3576 | surface_ = surface; |
| 3577 | RestoreCurrentFramebufferBindings(); |
| 3578 | } |
| 3579 | |
[email protected] | aba551b | 2014-02-08 03:38:32 | [diff] [blame] | 3580 | void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) { |
| 3581 | if (!offscreen_saved_color_texture_.get()) { |
| 3582 | LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context"; |
| 3583 | return; |
| 3584 | } |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3585 | if (!offscreen_saved_color_texture_info_.get()) { |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3586 | GLuint service_id = offscreen_saved_color_texture_->id(); |
[email protected] | f4647693 | 2013-06-08 05:36:07 | [diff] [blame] | 3587 | offscreen_saved_color_texture_info_ = TextureRef::Create( |
| 3588 | texture_manager(), 0, service_id); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3589 | texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), |
| 3590 | GL_TEXTURE_2D); |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 3591 | UpdateParentTextureInfo(); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3592 | } |
[email protected] | aba551b | 2014-02-08 03:38:32 | [diff] [blame] | 3593 | mailbox_manager()->ProduceTexture( |
| 3594 | GL_TEXTURE_2D, mailbox, offscreen_saved_color_texture_info_->texture()); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3595 | } |
| 3596 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3597 | bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 3598 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3599 | if (!is_offscreen) { |
| 3600 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " |
| 3601 | << " with an onscreen framebuffer."; |
| 3602 | return false; |
| 3603 | } |
| 3604 | |
| 3605 | if (offscreen_size_ == size) |
| 3606 | return true; |
| 3607 | |
| 3608 | offscreen_size_ = size; |
| 3609 | int w = offscreen_size_.width(); |
| 3610 | int h = offscreen_size_.height(); |
| 3611 | if (w < 0 || h < 0 || h >= (INT_MAX / 4) / (w ? w : 1)) { |
| 3612 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3613 | << "to allocate storage due to excessive dimensions."; |
| 3614 | return false; |
| 3615 | } |
| 3616 | |
| 3617 | // Reallocate the offscreen target buffers. |
| 3618 | DCHECK(offscreen_target_color_format_); |
| 3619 | if (IsOffscreenBufferMultisampled()) { |
| 3620 | if (!offscreen_target_color_render_buffer_->AllocateStorage( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 3621 | feature_info_.get(), |
| 3622 | offscreen_size_, |
| 3623 | offscreen_target_color_format_, |
| 3624 | offscreen_target_samples_)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3625 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3626 | << "to allocate storage for offscreen target color buffer."; |
| 3627 | return false; |
| 3628 | } |
| 3629 | } else { |
| 3630 | if (!offscreen_target_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 3631 | offscreen_size_, offscreen_target_color_format_, false)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3632 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3633 | << "to allocate storage for offscreen target color texture."; |
| 3634 | return false; |
| 3635 | } |
| 3636 | } |
| 3637 | if (offscreen_target_depth_format_ && |
| 3638 | !offscreen_target_depth_render_buffer_->AllocateStorage( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 3639 | feature_info_.get(), |
| 3640 | offscreen_size_, |
| 3641 | offscreen_target_depth_format_, |
| 3642 | offscreen_target_samples_)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3643 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3644 | << "to allocate storage for offscreen target depth buffer."; |
| 3645 | return false; |
| 3646 | } |
| 3647 | if (offscreen_target_stencil_format_ && |
| 3648 | !offscreen_target_stencil_render_buffer_->AllocateStorage( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 3649 | feature_info_.get(), |
| 3650 | offscreen_size_, |
| 3651 | offscreen_target_stencil_format_, |
| 3652 | offscreen_target_samples_)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3653 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3654 | << "to allocate storage for offscreen target stencil buffer."; |
| 3655 | return false; |
| 3656 | } |
| 3657 | |
| 3658 | // Attach the offscreen target buffers to the target frame buffer. |
| 3659 | if (IsOffscreenBufferMultisampled()) { |
| 3660 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3661 | GL_COLOR_ATTACHMENT0, |
| 3662 | offscreen_target_color_render_buffer_.get()); |
| 3663 | } else { |
| 3664 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 3665 | offscreen_target_color_texture_.get()); |
| 3666 | } |
| 3667 | if (offscreen_target_depth_format_) { |
| 3668 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3669 | GL_DEPTH_ATTACHMENT, |
| 3670 | offscreen_target_depth_render_buffer_.get()); |
| 3671 | } |
| 3672 | const bool packed_depth_stencil = |
| 3673 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 3674 | if (packed_depth_stencil) { |
| 3675 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3676 | GL_STENCIL_ATTACHMENT, |
| 3677 | offscreen_target_depth_render_buffer_.get()); |
| 3678 | } else if (offscreen_target_stencil_format_) { |
| 3679 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3680 | GL_STENCIL_ATTACHMENT, |
| 3681 | offscreen_target_stencil_render_buffer_.get()); |
| 3682 | } |
| 3683 | |
| 3684 | if (offscreen_target_frame_buffer_->CheckStatus() != |
| 3685 | GL_FRAMEBUFFER_COMPLETE) { |
| 3686 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3687 | << "because offscreen FBO was incomplete."; |
| 3688 | return false; |
| 3689 | } |
| 3690 | |
| 3691 | // Clear the target frame buffer. |
| 3692 | { |
| 3693 | ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); |
| 3694 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
| 3695 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3696 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3697 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 3698 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 3699 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3700 | glClearDepth(0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3701 | state_.SetDeviceDepthMask(GL_TRUE); |
| 3702 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3703 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 3704 | RestoreClearState(); |
| 3705 | } |
[email protected] | d85ef76d | 2011-09-08 22:21:43 | [diff] [blame] | 3706 | |
| 3707 | // Destroy the offscreen resolved framebuffers. |
| 3708 | if (offscreen_resolved_frame_buffer_.get()) |
| 3709 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3710 | if (offscreen_resolved_color_texture_.get()) |
| 3711 | offscreen_resolved_color_texture_->Destroy(); |
| 3712 | offscreen_resolved_color_texture_.reset(); |
| 3713 | offscreen_resolved_frame_buffer_.reset(); |
| 3714 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3715 | return true; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3716 | } |
| 3717 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 3718 | error::Error GLES2DecoderImpl::HandleResizeCHROMIUM(uint32 immediate_data_size, |
| 3719 | const void* cmd_data) { |
| 3720 | const gles2::cmds::ResizeCHROMIUM& c = |
| 3721 | *static_cast<const gles2::cmds::ResizeCHROMIUM*>(cmd_data); |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 3722 | if (!offscreen_target_frame_buffer_.get() && surface_->DeferDraws()) |
[email protected] | 45212087 | 2012-09-27 15:21:02 | [diff] [blame] | 3723 | return error::kDeferCommandUntilLater; |
| 3724 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3725 | GLuint width = static_cast<GLuint>(c.width); |
| 3726 | GLuint height = static_cast<GLuint>(c.height); |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3727 | GLfloat scale_factor = c.scale_factor; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3728 | TRACE_EVENT2("gpu", "glResizeChromium", "width", width, "height", height); |
[email protected] | d16aa4b | 2013-02-14 22:35:41 | [diff] [blame] | 3729 | |
| 3730 | width = std::max(1U, width); |
| 3731 | height = std::max(1U, height); |
| 3732 | |
[email protected] | a0d98916 | 2011-11-22 13:15:07 | [diff] [blame] | 3733 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && \ |
| 3734 | !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3735 | // Make sure that we are done drawing to the back buffer before resizing. |
| 3736 | glFinish(); |
| 3737 | #endif |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3738 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3739 | if (is_offscreen) { |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3740 | if (!ResizeOffscreenFrameBuffer(gfx::Size(width, height))) { |
| 3741 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because " |
| 3742 | << "ResizeOffscreenFrameBuffer failed."; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3743 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3744 | } |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3745 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3746 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3747 | if (!resize_callback_.is_null()) { |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3748 | resize_callback_.Run(gfx::Size(width, height), scale_factor); |
[email protected] | 0e9346b | 2013-03-16 16:35:44 | [diff] [blame] | 3749 | DCHECK(context_->IsCurrent(surface_.get())); |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3750 | if (!context_->IsCurrent(surface_.get())) { |
| 3751 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because context no longer " |
| 3752 | << "current after resize callback."; |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3753 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3754 | } |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3755 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3756 | |
| 3757 | return error::kNoError; |
[email protected] | 43ecf37 | 2010-11-16 19:19:39 | [diff] [blame] | 3758 | } |
| 3759 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3760 | const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { |
| 3761 | if (command_id > kStartPoint && command_id < kNumCommands) { |
| 3762 | return gles2::GetCommandName(static_cast<CommandId>(command_id)); |
| 3763 | } |
| 3764 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 3765 | } |
| 3766 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3767 | // Decode a command, and call the corresponding GL functions. |
| 3768 | // NOTE: DoCommand() is slower than calling DoCommands() on larger batches |
| 3769 | // of commands at once, and is now only used for tests that need to track |
| 3770 | // individual commands. |
| 3771 | error::Error GLES2DecoderImpl::DoCommand(unsigned int command, |
| 3772 | unsigned int arg_count, |
| 3773 | const void* cmd_data) { |
| 3774 | return DoCommands(1, cmd_data, arg_count + 1, 0); |
| 3775 | } |
| 3776 | |
| 3777 | // Decode multiple commands, and call the corresponding GL functions. |
| 3778 | // NOTE: 'buffer' is a pointer to the command buffer. As such, it could be |
| 3779 | // changed by a (malicious) client at any time, so if validation has to happen, |
| 3780 | // it should operate on a copy of them. |
| 3781 | // NOTE: This is duplicating code from AsyncAPIInterface::DoCommands() in the |
| 3782 | // interest of performance in this critical execution loop. |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3783 | template <bool DebugImpl> |
| 3784 | error::Error GLES2DecoderImpl::DoCommandsImpl(unsigned int num_commands, |
| 3785 | const void* buffer, |
| 3786 | int num_entries, |
| 3787 | int* entries_processed) { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3788 | commands_to_process_ = num_commands; |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3789 | error::Error result = error::kNoError; |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3790 | const CommandBufferEntry* cmd_data = |
| 3791 | static_cast<const CommandBufferEntry*>(buffer); |
| 3792 | int process_pos = 0; |
| 3793 | unsigned int command = 0; |
| 3794 | |
| 3795 | while (process_pos < num_entries && result == error::kNoError && |
| 3796 | commands_to_process_--) { |
| 3797 | const unsigned int size = cmd_data->value_header.size; |
| 3798 | command = cmd_data->value_header.command; |
| 3799 | |
| 3800 | if (size == 0) { |
| 3801 | result = error::kInvalidSize; |
| 3802 | break; |
| 3803 | } |
| 3804 | |
| 3805 | if (static_cast<int>(size) + process_pos > num_entries) { |
| 3806 | result = error::kOutOfBounds; |
| 3807 | break; |
| 3808 | } |
| 3809 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3810 | if (DebugImpl) { |
| 3811 | TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cb_command"), |
| 3812 | GetCommandName(command)); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3813 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3814 | if (log_commands()) { |
| 3815 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "]" |
| 3816 | << "cmd: " << GetCommandName(command); |
| 3817 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3818 | } |
| 3819 | |
| 3820 | const unsigned int arg_count = size - 1; |
| 3821 | unsigned int command_index = command - kStartPoint - 1; |
| 3822 | if (command_index < arraysize(command_info)) { |
| 3823 | const CommandInfo& info = command_info[command_index]; |
| 3824 | unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
| 3825 | if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
| 3826 | (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
| 3827 | bool doing_gpu_trace = false; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3828 | if (DebugImpl && gpu_trace_commands_) { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3829 | if (CMD_FLAG_GET_TRACE_LEVEL(info.cmd_flags) <= gpu_trace_level_) { |
| 3830 | doing_gpu_trace = true; |
| 3831 | gpu_tracer_->Begin(GetCommandName(command), kTraceDecoder); |
| 3832 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3833 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3834 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3835 | uint32 immediate_data_size = (arg_count - info_arg_count) * |
| 3836 | sizeof(CommandBufferEntry); // NOLINT |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3837 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3838 | result = (this->*info.cmd_handler)(immediate_data_size, cmd_data); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3839 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3840 | if (DebugImpl && doing_gpu_trace) |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3841 | gpu_tracer_->End(kTraceDecoder); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3842 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3843 | if (DebugImpl && debug()) { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3844 | GLenum error; |
| 3845 | while ((error = glGetError()) != GL_NO_ERROR) { |
| 3846 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "] " |
| 3847 | << "GL ERROR: " << GLES2Util::GetStringEnum(error) |
| 3848 | << " : " << GetCommandName(command); |
| 3849 | LOCAL_SET_GL_ERROR(error, "DoCommand", "GL error from driver"); |
| 3850 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3851 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3852 | } else { |
| 3853 | result = error::kInvalidArguments; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3854 | } |
| 3855 | } else { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3856 | result = DoCommonCommand(command, arg_count, cmd_data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3857 | } |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3858 | |
| 3859 | if (DebugImpl) { |
| 3860 | TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("cb_command"), |
| 3861 | GetCommandName(command)); |
| 3862 | } |
| 3863 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3864 | if (result == error::kNoError && |
| 3865 | current_decoder_error_ != error::kNoError) { |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 3866 | result = current_decoder_error_; |
| 3867 | current_decoder_error_ = error::kNoError; |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3868 | } |
| 3869 | |
| 3870 | if (result != error::kDeferCommandUntilLater) { |
| 3871 | process_pos += size; |
| 3872 | cmd_data += size; |
| 3873 | } |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 3874 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3875 | |
| 3876 | if (entries_processed) |
| 3877 | *entries_processed = process_pos; |
| 3878 | |
| 3879 | if (error::IsError(result)) { |
| 3880 | LOG(ERROR) << "Error: " << result << " for Command " |
| 3881 | << GetCommandName(command); |
| 3882 | } |
| 3883 | |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3884 | return result; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3885 | } |
| 3886 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3887 | error::Error GLES2DecoderImpl::DoCommands(unsigned int num_commands, |
| 3888 | const void* buffer, |
| 3889 | int num_entries, |
| 3890 | int* entries_processed) { |
| 3891 | if (gpu_debug_commands_) { |
| 3892 | return DoCommandsImpl<true>( |
| 3893 | num_commands, buffer, num_entries, entries_processed); |
| 3894 | } else { |
| 3895 | return DoCommandsImpl<false>( |
| 3896 | num_commands, buffer, num_entries, entries_processed); |
| 3897 | } |
| 3898 | } |
| 3899 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3900 | void GLES2DecoderImpl::RemoveBuffer(GLuint client_id) { |
| 3901 | buffer_manager()->RemoveBuffer(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3902 | } |
| 3903 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3904 | bool GLES2DecoderImpl::CreateProgramHelper(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3905 | if (GetProgram(client_id)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3906 | return false; |
| 3907 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3908 | GLuint service_id = glCreateProgram(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3909 | if (service_id != 0) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3910 | CreateProgram(client_id, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3911 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3912 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3913 | } |
| 3914 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3915 | bool GLES2DecoderImpl::CreateShaderHelper(GLenum type, GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3916 | if (GetShader(client_id)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3917 | return false; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3918 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3919 | GLuint service_id = glCreateShader(type); |
| 3920 | if (service_id != 0) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3921 | CreateShader(client_id, service_id, type); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3922 | } |
| 3923 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3924 | } |
| 3925 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3926 | void GLES2DecoderImpl::DoFinish() { |
| 3927 | glFinish(); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 3928 | ProcessPendingReadPixels(); |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 3929 | ProcessPendingQueries(); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | void GLES2DecoderImpl::DoFlush() { |
| 3933 | glFlush(); |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 3934 | ProcessPendingQueries(); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3935 | } |
| 3936 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3937 | void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3938 | GLuint texture_index = texture_unit - GL_TEXTURE0; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3939 | if (texture_index >= state_.texture_units.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3940 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 3941 | "glActiveTexture", texture_unit, "texture_unit"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3942 | return; |
| 3943 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3944 | state_.active_texture_unit = texture_index; |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 3945 | glActiveTexture(texture_unit); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 3946 | } |
| 3947 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3948 | void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3949 | Buffer* buffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3950 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3951 | if (client_id != 0) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3952 | buffer = GetBuffer(client_id); |
| 3953 | if (!buffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3954 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 3955 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 3956 | "glBindBuffer", |
| 3957 | "id not generated by glGenBuffers"); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 3958 | return; |
| 3959 | } |
| 3960 | |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3961 | // It's a new id so make a buffer buffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3962 | glGenBuffersARB(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3963 | CreateBuffer(client_id, service_id); |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3964 | buffer = GetBuffer(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3965 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3966 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3967 | LogClientServiceForInfo(buffer, client_id, "glBindBuffer"); |
| 3968 | if (buffer) { |
| 3969 | if (!buffer_manager()->SetTarget(buffer, target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3970 | LOCAL_SET_GL_ERROR( |
| 3971 | GL_INVALID_OPERATION, |
| 3972 | "glBindBuffer", "buffer bound to more than 1 target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3973 | return; |
| 3974 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3975 | service_id = buffer->service_id(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3976 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3977 | switch (target) { |
| 3978 | case GL_ARRAY_BUFFER: |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3979 | state_.bound_array_buffer = buffer; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3980 | break; |
| 3981 | case GL_ELEMENT_ARRAY_BUFFER: |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 3982 | state_.vertex_attrib_manager->SetElementArrayBuffer(buffer); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3983 | break; |
| 3984 | default: |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3985 | NOTREACHED(); // Validation should prevent us getting here. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3986 | break; |
| 3987 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 3988 | glBindBuffer(target, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3989 | } |
| 3990 | |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 3991 | bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha( |
| 3992 | bool all_draw_buffers) { |
| 3993 | Framebuffer* framebuffer = |
| 3994 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 3995 | if (!all_draw_buffers || !framebuffer) { |
| 3996 | return (GLES2Util::GetChannelsForFormat( |
| 3997 | GetBoundDrawFrameBufferInternalFormat()) & 0x0008) != 0; |
| 3998 | } |
| 3999 | return framebuffer->HasAlphaMRT(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4003 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4004 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4005 | if (framebuffer) { |
| 4006 | return framebuffer->HasDepthAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4007 | } |
| 4008 | if (offscreen_target_frame_buffer_.get()) { |
| 4009 | return offscreen_target_depth_format_ != 0; |
| 4010 | } |
| 4011 | return back_buffer_has_depth_; |
| 4012 | } |
| 4013 | |
| 4014 | bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4015 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4016 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4017 | if (framebuffer) { |
| 4018 | return framebuffer->HasStencilAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4019 | } |
| 4020 | if (offscreen_target_frame_buffer_.get()) { |
| 4021 | return offscreen_target_stencil_format_ != 0 || |
| 4022 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 4023 | } |
| 4024 | return back_buffer_has_stencil_; |
| 4025 | } |
| 4026 | |
| 4027 | void GLES2DecoderImpl::ApplyDirtyState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4028 | if (framebuffer_state_.clear_state_dirty) { |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4029 | bool have_alpha = BoundFramebufferHasColorAttachmentWithAlpha(true); |
| 4030 | state_.SetDeviceColorMask(state_.color_mask_red, |
| 4031 | state_.color_mask_green, |
| 4032 | state_.color_mask_blue, |
| 4033 | state_.color_mask_alpha && have_alpha); |
| 4034 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4035 | bool have_depth = BoundFramebufferHasDepthAttachment(); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4036 | state_.SetDeviceDepthMask(state_.depth_mask && have_depth); |
| 4037 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4038 | bool have_stencil = BoundFramebufferHasStencilAttachment(); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4039 | state_.SetDeviceStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4040 | GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4041 | state_.SetDeviceStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4042 | GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4043 | |
| 4044 | state_.SetDeviceCapabilityState( |
| 4045 | GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth); |
| 4046 | state_.SetDeviceCapabilityState( |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 4047 | GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4048 | framebuffer_state_.clear_state_dirty = false; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4049 | } |
| 4050 | } |
| 4051 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4052 | GLuint GLES2DecoderImpl::GetBackbufferServiceId() const { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4053 | return (offscreen_target_frame_buffer_.get()) |
| 4054 | ? offscreen_target_frame_buffer_->id() |
| 4055 | : (surface_.get() ? surface_->GetBackingFrameBufferObject() : 0); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4056 | } |
| 4057 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4058 | void GLES2DecoderImpl::RestoreState(const ContextState* prev_state) { |
[email protected] | 962bfbe7 | 2013-05-24 11:16:14 | [diff] [blame] | 4059 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::RestoreState", |
| 4060 | "context", logger_.GetLogPrefix()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4061 | // Restore the Framebuffer first because of bugs in Intel drivers. |
| 4062 | // Intel drivers incorrectly clip the viewport settings to |
| 4063 | // the size of the current framebuffer object. |
| 4064 | RestoreFramebufferBindings(); |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 4065 | state_.RestoreState(prev_state); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4066 | } |
| 4067 | |
| 4068 | void GLES2DecoderImpl::RestoreFramebufferBindings() const { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4069 | GLuint service_id = |
| 4070 | framebuffer_state_.bound_draw_framebuffer.get() |
| 4071 | ? framebuffer_state_.bound_draw_framebuffer->service_id() |
| 4072 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4073 | if (!features().chromium_framebuffer_multisample) { |
| 4074 | glBindFramebufferEXT(GL_FRAMEBUFFER, service_id); |
| 4075 | } else { |
| 4076 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, service_id); |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4077 | service_id = framebuffer_state_.bound_read_framebuffer.get() |
| 4078 | ? framebuffer_state_.bound_read_framebuffer->service_id() |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4079 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4080 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, service_id); |
| 4081 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4082 | OnFboChanged(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4083 | } |
| 4084 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4085 | void GLES2DecoderImpl::RestoreRenderbufferBindings() { |
| 4086 | state_.RestoreRenderbufferBindings(); |
| 4087 | } |
| 4088 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4089 | void GLES2DecoderImpl::RestoreTextureState(unsigned service_id) const { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4090 | Texture* texture = texture_manager()->GetTextureForServiceId(service_id); |
| 4091 | if (texture) { |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4092 | GLenum target = texture->target(); |
| 4093 | glBindTexture(target, service_id); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4094 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4095 | target, GL_TEXTURE_WRAP_S, texture->wrap_s()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4096 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4097 | target, GL_TEXTURE_WRAP_T, texture->wrap_t()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4098 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4099 | target, GL_TEXTURE_MIN_FILTER, texture->min_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4100 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4101 | target, GL_TEXTURE_MAG_FILTER, texture->mag_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4102 | RestoreTextureUnitBindings(state_.active_texture_unit); |
| 4103 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4104 | } |
| 4105 | |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4106 | void GLES2DecoderImpl::ClearAllAttributes() const { |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 4107 | // Must use native VAO 0, as RestoreAllAttributes can't fully restore |
| 4108 | // other VAOs. |
| 4109 | if (feature_info_->feature_flags().native_vertex_array_object) |
| 4110 | glBindVertexArrayOES(0); |
| 4111 | |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4112 | for (uint32 i = 0; i < group_->max_vertex_attribs(); ++i) { |
| 4113 | if (i != 0) // Never disable attribute 0 |
| 4114 | glDisableVertexAttribArray(i); |
| 4115 | if(features().angle_instanced_arrays) |
| 4116 | glVertexAttribDivisorANGLE(i, 0); |
| 4117 | } |
| 4118 | } |
| 4119 | |
| 4120 | void GLES2DecoderImpl::RestoreAllAttributes() const { |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 4121 | state_.RestoreVertexAttribs(); |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4122 | } |
| 4123 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4124 | void GLES2DecoderImpl::SetIgnoreCachedStateForTest(bool ignore) { |
| 4125 | state_.SetIgnoreCachedStateForTest(ignore); |
| 4126 | } |
| 4127 | |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4128 | void GLES2DecoderImpl::OnFboChanged() const { |
| 4129 | if (workarounds().restore_scissor_on_fbo_change) |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 4130 | state_.fbo_binding_for_scissor_workaround_dirty_ = true; |
| 4131 | } |
| 4132 | |
| 4133 | // Called after the FBO is checked for completeness. |
| 4134 | void GLES2DecoderImpl::OnUseFramebuffer() const { |
| 4135 | if (state_.fbo_binding_for_scissor_workaround_dirty_) { |
| 4136 | state_.fbo_binding_for_scissor_workaround_dirty_ = false; |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 4137 | // The driver forgets the correct scissor when modifying the FBO binding. |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 4138 | glScissor(state_.scissor_x, |
| 4139 | state_.scissor_y, |
| 4140 | state_.scissor_width, |
| 4141 | state_.scissor_height); |
| 4142 | |
| 4143 | // crbug.com/222018 - Also on QualComm, the flush here avoids flicker, |
| 4144 | // it's unclear how this bug works. |
| 4145 | glFlush(); |
| 4146 | } |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 4147 | } |
| 4148 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4149 | void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4150 | Framebuffer* framebuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4151 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4152 | if (client_id != 0) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4153 | framebuffer = GetFramebuffer(client_id); |
| 4154 | if (!framebuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4155 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4156 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4157 | "glBindFramebuffer", |
| 4158 | "id not generated by glGenFramebuffers"); |
| 4159 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4160 | } |
| 4161 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4162 | // It's a new id so make a framebuffer framebuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4163 | glGenFramebuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4164 | CreateFramebuffer(client_id, service_id); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4165 | framebuffer = GetFramebuffer(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4166 | } else { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4167 | service_id = framebuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4168 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4169 | framebuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4170 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4171 | LogClientServiceForInfo(framebuffer, client_id, "glBindFramebuffer"); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4172 | |
| 4173 | if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4174 | framebuffer_state_.bound_draw_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4175 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 4176 | |
| 4177 | // vmiura: This looks like dup code |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4178 | if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4179 | framebuffer_state_.bound_read_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4180 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 4181 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4182 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4183 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 4184 | // If we are rendering to the backbuffer get the FBO id for any simulated |
| 4185 | // backbuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4186 | if (framebuffer == NULL) { |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 4187 | service_id = GetBackbufferServiceId(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4188 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 4189 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4190 | glBindFramebufferEXT(target, service_id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4191 | OnFboChanged(); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 4192 | } |
| 4193 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4194 | void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4195 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4196 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4197 | if (client_id != 0) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4198 | renderbuffer = GetRenderbuffer(client_id); |
| 4199 | if (!renderbuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4200 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4201 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4202 | "glBindRenderbuffer", |
| 4203 | "id not generated by glGenRenderbuffers"); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4204 | return; |
| 4205 | } |
| 4206 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4207 | // It's a new id so make a renderbuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4208 | glGenRenderbuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4209 | CreateRenderbuffer(client_id, service_id); |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4210 | renderbuffer = GetRenderbuffer(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4211 | } else { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4212 | service_id = renderbuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4213 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4214 | renderbuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4215 | } |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 4216 | LogClientServiceForInfo(renderbuffer, client_id, "glBindRenderbuffer"); |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4217 | state_.bound_renderbuffer = renderbuffer; |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4218 | state_.bound_renderbuffer_valid = true; |
| 4219 | glBindRenderbufferEXT(GL_RENDERBUFFER, service_id); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 4220 | } |
| 4221 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4222 | void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4223 | TextureRef* texture_ref = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4224 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4225 | if (client_id != 0) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4226 | texture_ref = GetTexture(client_id); |
| 4227 | if (!texture_ref) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4228 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4229 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4230 | "glBindTexture", |
| 4231 | "id not generated by glGenTextures"); |
| 4232 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4233 | } |
| 4234 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 4235 | // It's a new id so make a texture texture for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4236 | glGenTextures(1, &service_id); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4237 | DCHECK_NE(0u, service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4238 | CreateTexture(client_id, service_id); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4239 | texture_ref = GetTexture(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4240 | } |
| 4241 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4242 | texture_ref = texture_manager()->GetDefaultTextureInfo(target); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4243 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4244 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 4245 | // Check the texture exists |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 4246 | if (texture_ref) { |
| 4247 | Texture* texture = texture_ref->texture(); |
| 4248 | // Check that we are not trying to bind it to a different target. |
| 4249 | if (texture->target() != 0 && texture->target() != target) { |
| 4250 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4251 | "glBindTexture", |
| 4252 | "texture bound to more than 1 target."); |
| 4253 | return; |
| 4254 | } |
| 4255 | LogClientServiceForInfo(texture, client_id, "glBindTexture"); |
| 4256 | if (texture->target() == 0) { |
| 4257 | texture_manager()->SetTarget(texture_ref, target); |
| 4258 | } |
| 4259 | glBindTexture(target, texture->service_id()); |
| 4260 | } else { |
| 4261 | glBindTexture(target, 0); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 4262 | } |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 4263 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4264 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4265 | unit.bind_target = target; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4266 | switch (target) { |
| 4267 | case GL_TEXTURE_2D: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4268 | unit.bound_texture_2d = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4269 | break; |
| 4270 | case GL_TEXTURE_CUBE_MAP: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4271 | unit.bound_texture_cube_map = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4272 | break; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4273 | case GL_TEXTURE_EXTERNAL_OES: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4274 | unit.bound_texture_external_oes = texture_ref; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4275 | break; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4276 | case GL_TEXTURE_RECTANGLE_ARB: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4277 | unit.bound_texture_rectangle_arb = texture_ref; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4278 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4279 | default: |
| 4280 | NOTREACHED(); // Validation should prevent us getting here. |
| 4281 | break; |
| 4282 | } |
| 4283 | } |
| 4284 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4285 | void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4286 | if (state_.vertex_attrib_manager->Enable(index, false)) { |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 4287 | if (index != 0 || |
| 4288 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4289 | glDisableVertexAttribArray(index); |
| 4290 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4291 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4292 | LOCAL_SET_GL_ERROR( |
| 4293 | GL_INVALID_VALUE, |
| 4294 | "glDisableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4295 | } |
| 4296 | } |
| 4297 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4298 | void GLES2DecoderImpl::DoDiscardFramebufferEXT(GLenum target, |
| 4299 | GLsizei numAttachments, |
| 4300 | const GLenum* attachments) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4301 | Framebuffer* framebuffer = |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4302 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 4303 | |
| 4304 | // Validates the attachments. If one of them fails |
| 4305 | // the whole command fails. |
| 4306 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4307 | if ((framebuffer && |
| 4308 | !validators_->attachment.IsValid(attachments[i])) || |
| 4309 | (!framebuffer && |
| 4310 | !validators_->backbuffer_attachment.IsValid(attachments[i]))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4311 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 4312 | "glDiscardFramebufferEXT", attachments[i], "attachments"); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4313 | return; |
| 4314 | } |
| 4315 | } |
| 4316 | |
| 4317 | // Marks each one of them as not cleared |
| 4318 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4319 | if (framebuffer) { |
| 4320 | framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), |
| 4321 | texture_manager(), |
| 4322 | attachments[i], |
| 4323 | false); |
| 4324 | } else { |
| 4325 | switch (attachments[i]) { |
| 4326 | case GL_COLOR_EXT: |
| 4327 | backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| 4328 | break; |
| 4329 | case GL_DEPTH_EXT: |
| 4330 | backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
| 4331 | case GL_STENCIL_EXT: |
| 4332 | backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
| 4333 | break; |
| 4334 | default: |
| 4335 | NOTREACHED(); |
| 4336 | break; |
| 4337 | } |
| 4338 | } |
| 4339 | } |
| 4340 | |
[email protected] | d49c540 | 2013-09-11 15:39:02 | [diff] [blame] | 4341 | // If the default framebuffer is bound but we are still rendering to an |
| 4342 | // FBO, translate attachment names that refer to default framebuffer |
| 4343 | // channels to corresponding framebuffer attachments. |
| 4344 | scoped_ptr<GLenum[]> translated_attachments(new GLenum[numAttachments]); |
| 4345 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4346 | GLenum attachment = attachments[i]; |
| 4347 | if (!framebuffer && GetBackbufferServiceId()) { |
| 4348 | switch (attachment) { |
| 4349 | case GL_COLOR_EXT: |
| 4350 | attachment = GL_COLOR_ATTACHMENT0; |
| 4351 | break; |
| 4352 | case GL_DEPTH_EXT: |
| 4353 | attachment = GL_DEPTH_ATTACHMENT; |
| 4354 | break; |
| 4355 | case GL_STENCIL_EXT: |
| 4356 | attachment = GL_STENCIL_ATTACHMENT; |
| 4357 | break; |
| 4358 | default: |
| 4359 | NOTREACHED(); |
| 4360 | return; |
| 4361 | } |
| 4362 | } |
| 4363 | translated_attachments[i] = attachment; |
| 4364 | } |
| 4365 | |
boliu | 2e7d8a7a | 2014-10-16 20:35:20 | [diff] [blame] | 4366 | ScopedRenderTo do_render(framebuffer); |
[email protected] | d49c540 | 2013-09-11 15:39:02 | [diff] [blame] | 4367 | glDiscardFramebufferEXT(target, numAttachments, translated_attachments.get()); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4368 | } |
| 4369 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4370 | void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4371 | if (state_.vertex_attrib_manager->Enable(index, true)) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4372 | glEnableVertexAttribArray(index); |
| 4373 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4374 | LOCAL_SET_GL_ERROR( |
| 4375 | GL_INVALID_VALUE, "glEnableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4376 | } |
| 4377 | } |
| 4378 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4379 | void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4380 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 4381 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4382 | if (!texture_ref || |
| 4383 | !texture_manager()->CanGenerateMipmaps(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4384 | LOCAL_SET_GL_ERROR( |
| 4385 | GL_INVALID_OPERATION, "glGenerateMipmap", "Can not generate mips"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4386 | return; |
| 4387 | } |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4388 | |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4389 | if (target == GL_TEXTURE_CUBE_MAP) { |
| 4390 | for (int i = 0; i < 6; ++i) { |
| 4391 | GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4392 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, face, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4393 | LOCAL_SET_GL_ERROR( |
| 4394 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4395 | return; |
| 4396 | } |
| 4397 | } |
| 4398 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4399 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4400 | LOCAL_SET_GL_ERROR( |
| 4401 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4402 | return; |
| 4403 | } |
[email protected] | 7687479c | 2012-05-14 23:54:04 | [diff] [blame] | 4404 | } |
| 4405 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4406 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glGenerateMipmap"); |
[email protected] | 59f3ca0 | 2011-03-26 22:24:19 | [diff] [blame] | 4407 | // Workaround for Mac driver bug. In the large scheme of things setting |
| 4408 | // glTexParamter twice for glGenerateMipmap is probably not a lage performance |
[email protected] | a8bad26 | 2011-10-21 18:28:56 | [diff] [blame] | 4409 | // hit so there's probably no need to make this conditional. The bug appears |
| 4410 | // to be that if the filtering mode is set to something that doesn't require |
| 4411 | // mipmaps for rendering, or is never set to something other than the default, |
| 4412 | // then glGenerateMipmap misbehaves. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4413 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4414 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 4415 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4416 | glGenerateMipmapEXT(target); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4417 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4418 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, |
| 4419 | texture_ref->texture()->min_filter()); |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4420 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4421 | GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4422 | if (error == GL_NO_ERROR) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4423 | texture_manager()->MarkMipmapsGenerated(texture_ref); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4424 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4425 | } |
| 4426 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4427 | bool GLES2DecoderImpl::GetHelper( |
| 4428 | GLenum pname, GLint* params, GLsizei* num_written) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4429 | DCHECK(num_written); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 4430 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 4431 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4432 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 4433 | *num_written = 1; |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 4434 | // Return the GL implementation's preferred format and (see below type) |
| 4435 | // if we have the GL extension that exposes this. This allows the GPU |
| 4436 | // client to use the implementation's preferred format for glReadPixels |
| 4437 | // for optimisation. |
| 4438 | // |
| 4439 | // A conflicting extension (GL_ARB_ES2_compatibility) specifies an error |
| 4440 | // case when requested on integer/floating point buffers but which is |
| 4441 | // acceptable on GLES2 and with the GL_OES_read_format extension. |
| 4442 | // |
| 4443 | // Therefore if an error occurs we swallow the error and use the |
| 4444 | // internal implementation. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4445 | if (params) { |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 4446 | if (context_->HasExtension("GL_OES_read_format")) { |
| 4447 | ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::GetHelper", |
| 4448 | GetErrorState()); |
| 4449 | glGetIntegerv(pname, params); |
| 4450 | if (glGetError() == GL_NO_ERROR) |
| 4451 | return true; |
| 4452 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 4453 | *params = GLES2Util::GetPreferredGLReadPixelsFormat( |
| 4454 | GetBoundReadFrameBufferInternalFormat()); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4455 | } |
| 4456 | return true; |
| 4457 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 4458 | *num_written = 1; |
| 4459 | if (params) { |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 4460 | if (context_->HasExtension("GL_OES_read_format")) { |
| 4461 | ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::GetHelper", |
| 4462 | GetErrorState()); |
| 4463 | glGetIntegerv(pname, params); |
| 4464 | if (glGetError() == GL_NO_ERROR) |
| 4465 | return true; |
| 4466 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 4467 | *params = GLES2Util::GetPreferredGLReadPixelsType( |
| 4468 | GetBoundReadFrameBufferInternalFormat(), |
| 4469 | GetBoundReadFrameBufferTextureType()); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4470 | } |
| 4471 | return true; |
| 4472 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 4473 | *num_written = 1; |
| 4474 | if (params) { |
| 4475 | *params = group_->max_fragment_uniform_vectors(); |
| 4476 | } |
| 4477 | return true; |
| 4478 | case GL_MAX_VARYING_VECTORS: |
| 4479 | *num_written = 1; |
| 4480 | if (params) { |
| 4481 | *params = group_->max_varying_vectors(); |
| 4482 | } |
| 4483 | return true; |
| 4484 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 4485 | *num_written = 1; |
| 4486 | if (params) { |
| 4487 | *params = group_->max_vertex_uniform_vectors(); |
| 4488 | } |
| 4489 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4490 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4491 | } |
| 4492 | switch (pname) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 4493 | case GL_MAX_VIEWPORT_DIMS: |
| 4494 | if (offscreen_target_frame_buffer_.get()) { |
| 4495 | *num_written = 2; |
| 4496 | if (params) { |
| 4497 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4498 | params[1] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4499 | } |
| 4500 | return true; |
| 4501 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4502 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4503 | case GL_MAX_SAMPLES: |
| 4504 | *num_written = 1; |
| 4505 | if (params) { |
| 4506 | params[0] = renderbuffer_manager()->max_samples(); |
| 4507 | } |
| 4508 | return true; |
| 4509 | case GL_MAX_RENDERBUFFER_SIZE: |
| 4510 | *num_written = 1; |
| 4511 | if (params) { |
| 4512 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4513 | } |
| 4514 | return true; |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4515 | case GL_MAX_TEXTURE_SIZE: |
| 4516 | *num_written = 1; |
| 4517 | if (params) { |
| 4518 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_2D); |
| 4519 | } |
| 4520 | return true; |
| 4521 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 4522 | *num_written = 1; |
| 4523 | if (params) { |
| 4524 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP); |
| 4525 | } |
| 4526 | return true; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 4527 | case GL_MAX_COLOR_ATTACHMENTS_EXT: |
| 4528 | *num_written = 1; |
| 4529 | if (params) { |
| 4530 | params[0] = group_->max_color_attachments(); |
| 4531 | } |
| 4532 | return true; |
| 4533 | case GL_MAX_DRAW_BUFFERS_ARB: |
| 4534 | *num_written = 1; |
| 4535 | if (params) { |
| 4536 | params[0] = group_->max_draw_buffers(); |
| 4537 | } |
| 4538 | return true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4539 | case GL_ALPHA_BITS: |
| 4540 | *num_written = 1; |
| 4541 | if (params) { |
| 4542 | GLint v = 0; |
| 4543 | glGetIntegerv(GL_ALPHA_BITS, &v); |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 4544 | params[0] = BoundFramebufferHasColorAttachmentWithAlpha(false) ? v : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4545 | } |
| 4546 | return true; |
| 4547 | case GL_DEPTH_BITS: |
| 4548 | *num_written = 1; |
| 4549 | if (params) { |
| 4550 | GLint v = 0; |
| 4551 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 4552 | params[0] = BoundFramebufferHasDepthAttachment() ? v : 0; |
| 4553 | } |
| 4554 | return true; |
| 4555 | case GL_STENCIL_BITS: |
| 4556 | *num_written = 1; |
| 4557 | if (params) { |
| 4558 | GLint v = 0; |
| 4559 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 4560 | params[0] = BoundFramebufferHasStencilAttachment() ? v : 0; |
| 4561 | } |
| 4562 | return true; |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 4563 | case GL_COMPRESSED_TEXTURE_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4564 | *num_written = validators_->compressed_texture_format.GetValues().size(); |
| 4565 | if (params) { |
| 4566 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 4567 | params[ii] = validators_->compressed_texture_format.GetValues()[ii]; |
| 4568 | } |
| 4569 | } |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 4570 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4571 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 4572 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4573 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4574 | *params = validators_->compressed_texture_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4575 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4576 | return true; |
| 4577 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 4578 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4579 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4580 | *params = validators_->shader_binary_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4581 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4582 | return true; |
| 4583 | case GL_SHADER_BINARY_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4584 | *num_written = validators_->shader_binary_format.GetValues().size(); |
| 4585 | if (params) { |
| 4586 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 4587 | params[ii] = validators_->shader_binary_format.GetValues()[ii]; |
| 4588 | } |
| 4589 | } |
| 4590 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4591 | case GL_SHADER_COMPILER: |
| 4592 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4593 | if (params) { |
| 4594 | *params = GL_TRUE; |
| 4595 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4596 | return true; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4597 | case GL_ARRAY_BUFFER_BINDING: |
| 4598 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4599 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4600 | if (state_.bound_array_buffer.get()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4601 | GLuint client_id = 0; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4602 | buffer_manager()->GetClientId(state_.bound_array_buffer->service_id(), |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4603 | &client_id); |
| 4604 | *params = client_id; |
| 4605 | } else { |
| 4606 | *params = 0; |
| 4607 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4608 | } |
| 4609 | return true; |
| 4610 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 4611 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4612 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4613 | if (state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4614 | GLuint client_id = 0; |
| 4615 | buffer_manager()->GetClientId( |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 4616 | state_.vertex_attrib_manager->element_array_buffer()-> |
| 4617 | service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4618 | *params = client_id; |
| 4619 | } else { |
| 4620 | *params = 0; |
| 4621 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4622 | } |
| 4623 | return true; |
| 4624 | case GL_FRAMEBUFFER_BINDING: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4625 | // case GL_DRAW_FRAMEBUFFER_BINDING_EXT: (same as GL_FRAMEBUFFER_BINDING) |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4626 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4627 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4628 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4629 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4630 | if (framebuffer) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4631 | GLuint client_id = 0; |
| 4632 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4633 | framebuffer->service_id(), &client_id); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4634 | *params = client_id; |
| 4635 | } else { |
| 4636 | *params = 0; |
| 4637 | } |
| 4638 | } |
| 4639 | return true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4640 | case GL_READ_FRAMEBUFFER_BINDING_EXT: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4641 | *num_written = 1; |
| 4642 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4643 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4644 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4645 | if (framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4646 | GLuint client_id = 0; |
| 4647 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4648 | framebuffer->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4649 | *params = client_id; |
| 4650 | } else { |
| 4651 | *params = 0; |
| 4652 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4653 | } |
| 4654 | return true; |
| 4655 | case GL_RENDERBUFFER_BINDING: |
| 4656 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4657 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4658 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4659 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4660 | if (renderbuffer) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4661 | *params = renderbuffer->client_id(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4662 | } else { |
| 4663 | *params = 0; |
| 4664 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4665 | } |
| 4666 | return true; |
| 4667 | case GL_CURRENT_PROGRAM: |
| 4668 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4669 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4670 | if (state_.current_program.get()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4671 | GLuint client_id = 0; |
| 4672 | program_manager()->GetClientId( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4673 | state_.current_program->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4674 | *params = client_id; |
| 4675 | } else { |
| 4676 | *params = 0; |
| 4677 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4678 | } |
| 4679 | return true; |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 4680 | case GL_VERTEX_ARRAY_BINDING_OES: |
| 4681 | *num_written = 1; |
| 4682 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4683 | if (state_.vertex_attrib_manager.get() != |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 4684 | state_.default_vertex_attrib_manager.get()) { |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 4685 | GLuint client_id = 0; |
| 4686 | vertex_array_manager_->GetClientId( |
| 4687 | state_.vertex_attrib_manager->service_id(), &client_id); |
| 4688 | *params = client_id; |
| 4689 | } else { |
| 4690 | *params = 0; |
| 4691 | } |
| 4692 | } |
| 4693 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4694 | case GL_TEXTURE_BINDING_2D: |
| 4695 | *num_written = 1; |
| 4696 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4697 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4698 | if (unit.bound_texture_2d.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4699 | *params = unit.bound_texture_2d->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4700 | } else { |
| 4701 | *params = 0; |
| 4702 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4703 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4704 | return true; |
| 4705 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 4706 | *num_written = 1; |
| 4707 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4708 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4709 | if (unit.bound_texture_cube_map.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4710 | *params = unit.bound_texture_cube_map->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4711 | } else { |
| 4712 | *params = 0; |
| 4713 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4714 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4715 | return true; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4716 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 4717 | *num_written = 1; |
| 4718 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4719 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4720 | if (unit.bound_texture_external_oes.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4721 | *params = unit.bound_texture_external_oes->client_id(); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4722 | } else { |
| 4723 | *params = 0; |
| 4724 | } |
| 4725 | } |
| 4726 | return true; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4727 | case GL_TEXTURE_BINDING_RECTANGLE_ARB: |
| 4728 | *num_written = 1; |
| 4729 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4730 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4731 | if (unit.bound_texture_rectangle_arb.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4732 | *params = unit.bound_texture_rectangle_arb->client_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4733 | } else { |
| 4734 | *params = 0; |
| 4735 | } |
| 4736 | } |
| 4737 | return true; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 4738 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 4739 | *num_written = 1; |
| 4740 | if (params) { |
| 4741 | params[0] = unpack_flip_y_; |
| 4742 | } |
| 4743 | return true; |
| 4744 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 4745 | *num_written = 1; |
| 4746 | if (params) { |
| 4747 | params[0] = unpack_premultiply_alpha_; |
| 4748 | } |
| 4749 | return true; |
| 4750 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 4751 | *num_written = 1; |
| 4752 | if (params) { |
| 4753 | params[0] = unpack_unpremultiply_alpha_; |
| 4754 | } |
| 4755 | return true; |
[email protected] | 6eda682 | 2014-04-03 23:00:50 | [diff] [blame] | 4756 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 4757 | *num_written = 1; |
| 4758 | if (params) { |
| 4759 | params[0] = group_->bind_generates_resource() ? 1 : 0; |
| 4760 | } |
| 4761 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4762 | default: |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 4763 | if (pname >= GL_DRAW_BUFFER0_ARB && |
| 4764 | pname < GL_DRAW_BUFFER0_ARB + group_->max_draw_buffers()) { |
| 4765 | *num_written = 1; |
| 4766 | if (params) { |
| 4767 | Framebuffer* framebuffer = |
| 4768 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 4769 | if (framebuffer) { |
| 4770 | params[0] = framebuffer->GetDrawBuffer(pname); |
| 4771 | } else { // backbuffer |
| 4772 | if (pname == GL_DRAW_BUFFER0_ARB) |
| 4773 | params[0] = group_->draw_buffer(); |
| 4774 | else |
| 4775 | params[0] = GL_NONE; |
| 4776 | } |
| 4777 | } |
| 4778 | return true; |
| 4779 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4780 | *num_written = util_.GLGetNumValuesReturned(pname); |
[email protected] | c5d79834 | 2010-09-24 20:42:53 | [diff] [blame] | 4781 | return false; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4782 | } |
| 4783 | } |
| 4784 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4785 | bool GLES2DecoderImpl::GetNumValuesReturnedForGLGet( |
| 4786 | GLenum pname, GLsizei* num_values) { |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4787 | if (state_.GetStateAsGLint(pname, NULL, num_values)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4788 | return true; |
| 4789 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4790 | return GetHelper(pname, NULL, num_values); |
| 4791 | } |
| 4792 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4793 | GLenum GLES2DecoderImpl::AdjustGetPname(GLenum pname) { |
| 4794 | if (GL_MAX_SAMPLES == pname && |
| 4795 | features().use_img_for_multisampled_render_to_texture) { |
| 4796 | return GL_MAX_SAMPLES_IMG; |
| 4797 | } |
| 4798 | return pname; |
| 4799 | } |
| 4800 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4801 | void GLES2DecoderImpl::DoGetBooleanv(GLenum pname, GLboolean* params) { |
| 4802 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4803 | GLsizei num_written = 0; |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4804 | if (GetNumValuesReturnedForGLGet(pname, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 4805 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4806 | if (!state_.GetStateAsGLint(pname, values.get(), &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4807 | GetHelper(pname, values.get(), &num_written); |
| 4808 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4809 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 4810 | params[ii] = static_cast<GLboolean>(values[ii]); |
| 4811 | } |
| 4812 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4813 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4814 | glGetBooleanv(pname, params); |
| 4815 | } |
| 4816 | } |
| 4817 | |
| 4818 | void GLES2DecoderImpl::DoGetFloatv(GLenum pname, GLfloat* params) { |
| 4819 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4820 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4821 | if (!state_.GetStateAsGLfloat(pname, params, &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4822 | if (GetHelper(pname, NULL, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 4823 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4824 | GetHelper(pname, values.get(), &num_written); |
| 4825 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 4826 | params[ii] = static_cast<GLfloat>(values[ii]); |
| 4827 | } |
| 4828 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4829 | pname = AdjustGetPname(pname); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4830 | glGetFloatv(pname, params); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4831 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4832 | } |
| 4833 | } |
| 4834 | |
| 4835 | void GLES2DecoderImpl::DoGetIntegerv(GLenum pname, GLint* params) { |
| 4836 | DCHECK(params); |
| 4837 | GLsizei num_written; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4838 | if (!state_.GetStateAsGLint(pname, params, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4839 | !GetHelper(pname, params, &num_written)) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4840 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4841 | glGetIntegerv(pname, params); |
| 4842 | } |
| 4843 | } |
| 4844 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 4845 | void GLES2DecoderImpl::DoGetProgramiv( |
| 4846 | GLuint program_id, GLenum pname, GLint* params) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4847 | Program* program = GetProgramInfoNotShader(program_id, "glGetProgramiv"); |
| 4848 | if (!program) { |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 4849 | return; |
| 4850 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4851 | program->GetProgramiv(pname, params); |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 4852 | } |
| 4853 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 4854 | void GLES2DecoderImpl::DoGetBufferParameteriv( |
| 4855 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 4856 | // Just delegate it. Some validation is actually done before this. |
| 4857 | buffer_manager()->ValidateAndDoGetBufferParameteriv( |
| 4858 | &state_, target, pname, params); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 4859 | } |
| 4860 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4861 | void GLES2DecoderImpl::DoBindAttribLocation( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4862 | GLuint program_id, GLuint index, const char* name) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4863 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4864 | LOCAL_SET_GL_ERROR( |
| 4865 | GL_INVALID_VALUE, "glBindAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4866 | return; |
| 4867 | } |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 4868 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4869 | LOCAL_SET_GL_ERROR( |
| 4870 | GL_INVALID_OPERATION, "glBindAttribLocation", "reserved prefix"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 4871 | return; |
| 4872 | } |
| 4873 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4874 | LOCAL_SET_GL_ERROR( |
| 4875 | GL_INVALID_VALUE, "glBindAttribLocation", "index out of range"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 4876 | return; |
| 4877 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4878 | Program* program = GetProgramInfoNotShader( |
| 4879 | program_id, "glBindAttribLocation"); |
| 4880 | if (!program) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4881 | return; |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4882 | } |
zmo | 460b593e | 2014-10-13 23:07:45 | [diff] [blame] | 4883 | // At this point, the program's shaders may not be translated yet, |
| 4884 | // therefore, we may not find the hashed attribute name. |
| 4885 | // glBindAttribLocation call with original name is useless. |
| 4886 | // So instead, we should simply cache the binding, and then call |
| 4887 | // Program::ExecuteBindAttribLocationCalls() right before link. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4888 | program->SetAttribLocationBinding(name, static_cast<GLint>(index)); |
zmo | 460b593e | 2014-10-13 23:07:45 | [diff] [blame] | 4889 | // TODO(zmo): Get rid of the following glBindAttribLocation call. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4890 | glBindAttribLocation(program->service_id(), index, name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4891 | } |
| 4892 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4893 | error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 4894 | uint32 immediate_data_size, |
| 4895 | const void* cmd_data) { |
| 4896 | const gles2::cmds::BindAttribLocationBucket& c = |
| 4897 | *static_cast<const gles2::cmds::BindAttribLocationBucket*>(cmd_data); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4898 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4899 | GLuint index = static_cast<GLuint>(c.index); |
| 4900 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 4901 | if (!bucket || bucket->size() == 0) { |
| 4902 | return error::kInvalidArguments; |
| 4903 | } |
| 4904 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 4905 | if (!bucket->GetAsString(&name_str)) { |
| 4906 | return error::kInvalidArguments; |
| 4907 | } |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 4908 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 4909 | return error::kNoError; |
| 4910 | } |
| 4911 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4912 | void GLES2DecoderImpl::DoBindUniformLocationCHROMIUM( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4913 | GLuint program_id, GLint location, const char* name) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4914 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4915 | LOCAL_SET_GL_ERROR( |
| 4916 | GL_INVALID_VALUE, |
| 4917 | "glBindUniformLocationCHROMIUM", "Invalid character"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4918 | return; |
| 4919 | } |
| 4920 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4921 | LOCAL_SET_GL_ERROR( |
| 4922 | GL_INVALID_OPERATION, |
| 4923 | "glBindUniformLocationCHROMIUM", "reserved prefix"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4924 | return; |
| 4925 | } |
| 4926 | if (location < 0 || static_cast<uint32>(location) >= |
| 4927 | (group_->max_fragment_uniform_vectors() + |
| 4928 | group_->max_vertex_uniform_vectors()) * 4) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4929 | LOCAL_SET_GL_ERROR( |
| 4930 | GL_INVALID_VALUE, |
| 4931 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4932 | return; |
| 4933 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4934 | Program* program = GetProgramInfoNotShader( |
| 4935 | program_id, "glBindUniformLocationCHROMIUM"); |
| 4936 | if (!program) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4937 | return; |
| 4938 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4939 | if (!program->SetUniformLocationBinding(name, location)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4940 | LOCAL_SET_GL_ERROR( |
| 4941 | GL_INVALID_VALUE, |
| 4942 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4943 | } |
| 4944 | } |
| 4945 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4946 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUMBucket( |
| 4947 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 4948 | const void* cmd_data) { |
| 4949 | const gles2::cmds::BindUniformLocationCHROMIUMBucket& c = |
| 4950 | *static_cast<const gles2::cmds::BindUniformLocationCHROMIUMBucket*>( |
| 4951 | cmd_data); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 4952 | GLuint program = static_cast<GLuint>(c.program); |
| 4953 | GLint location = static_cast<GLint>(c.location); |
| 4954 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 4955 | if (!bucket || bucket->size() == 0) { |
| 4956 | return error::kInvalidArguments; |
| 4957 | } |
| 4958 | std::string name_str; |
| 4959 | if (!bucket->GetAsString(&name_str)) { |
| 4960 | return error::kInvalidArguments; |
| 4961 | } |
| 4962 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 4963 | return error::kNoError; |
| 4964 | } |
| 4965 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 4966 | error::Error GLES2DecoderImpl::HandleDeleteShader(uint32 immediate_data_size, |
| 4967 | const void* cmd_data) { |
| 4968 | const gles2::cmds::DeleteShader& c = |
| 4969 | *static_cast<const gles2::cmds::DeleteShader*>(cmd_data); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4970 | GLuint client_id = c.shader; |
| 4971 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4972 | Shader* shader = GetShader(client_id); |
| 4973 | if (shader) { |
| 4974 | if (!shader->IsDeleted()) { |
| 4975 | glDeleteShader(shader->service_id()); |
| 4976 | shader_manager()->MarkAsDeleted(shader); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4977 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4978 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4979 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteShader", "unknown shader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4980 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4981 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4982 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4983 | } |
| 4984 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 4985 | error::Error GLES2DecoderImpl::HandleDeleteProgram(uint32 immediate_data_size, |
| 4986 | const void* cmd_data) { |
| 4987 | const gles2::cmds::DeleteProgram& c = |
| 4988 | *static_cast<const gles2::cmds::DeleteProgram*>(cmd_data); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4989 | GLuint client_id = c.program; |
| 4990 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 4991 | Program* program = GetProgram(client_id); |
| 4992 | if (program) { |
| 4993 | if (!program->IsDeleted()) { |
| 4994 | program_manager()->MarkAsDeleted(shader_manager(), program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 4995 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4996 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4997 | LOCAL_SET_GL_ERROR( |
| 4998 | GL_INVALID_VALUE, "glDeleteProgram", "unknown program"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4999 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5000 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5001 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5002 | } |
| 5003 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 5004 | error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 5005 | DCHECK(!ShouldDeferDraws()); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5006 | if (CheckBoundFramebuffersValid("glClear")) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5007 | ApplyDirtyState(); |
boliu | 2e7d8a7a | 2014-10-16 20:35:20 | [diff] [blame] | 5008 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 5009 | glClear(mask); |
| 5010 | } |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 5011 | return error::kNoError; |
| 5012 | } |
| 5013 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5014 | void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
| 5015 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5016 | GLuint client_renderbuffer_id) { |
[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, |
| 5021 | "glFramebufferRenderbuffer", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5022 | return; |
| 5023 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5024 | GLuint service_id = 0; |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5025 | Renderbuffer* renderbuffer = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5026 | if (client_renderbuffer_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5027 | renderbuffer = GetRenderbuffer(client_renderbuffer_id); |
| 5028 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5029 | LOCAL_SET_GL_ERROR( |
| 5030 | GL_INVALID_OPERATION, |
| 5031 | "glFramebufferRenderbuffer", "unknown renderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5032 | return; |
| 5033 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5034 | service_id = renderbuffer->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5035 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5036 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glFramebufferRenderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5037 | glFramebufferRenderbufferEXT( |
| 5038 | target, attachment, renderbuffertarget, service_id); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5039 | GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferRenderbuffer"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5040 | if (error == GL_NO_ERROR) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5041 | framebuffer->AttachRenderbuffer(attachment, renderbuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5042 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 5043 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5044 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5045 | } |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 5046 | OnFboChanged(); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5047 | } |
| 5048 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5049 | void GLES2DecoderImpl::DoDisable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5050 | if (SetCapabilityState(cap, false)) { |
| 5051 | glDisable(cap); |
| 5052 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | void GLES2DecoderImpl::DoEnable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5056 | if (SetCapabilityState(cap, true)) { |
| 5057 | glEnable(cap); |
| 5058 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5059 | } |
| 5060 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 5061 | void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { |
| 5062 | state_.z_near = std::min(1.0f, std::max(0.0f, znear)); |
| 5063 | state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); |
| 5064 | glDepthRange(znear, zfar); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5065 | } |
| 5066 | |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 5067 | void GLES2DecoderImpl::DoSampleCoverage(GLclampf value, GLboolean invert) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 5068 | state_.sample_coverage_value = std::min(1.0f, std::max(0.0f, value)); |
| 5069 | state_.sample_coverage_invert = (invert != 0); |
| 5070 | glSampleCoverage(state_.sample_coverage_value, invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5071 | } |
| 5072 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5073 | // Assumes framebuffer is complete. |
| 5074 | void GLES2DecoderImpl::ClearUnclearedAttachments( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5075 | GLenum target, Framebuffer* framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5076 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5077 | // bind this to the DRAW point, clear then bind back to READ |
| 5078 | // TODO(gman): I don't think there is any guarantee that an FBO that |
| 5079 | // is complete on the READ attachment will be complete as a DRAW |
| 5080 | // attachment. |
| 5081 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5082 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffer->service_id()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5083 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5084 | GLbitfield clear_bits = 0; |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 5085 | if (framebuffer->HasUnclearedColorAttachments()) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5086 | glClearColor( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5087 | 0.0f, 0.0f, 0.0f, |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5088 | (GLES2Util::GetChannelsForFormat( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5089 | framebuffer->GetColorAttachmentFormat()) & 0x0008) != 0 ? 0.0f : |
| 5090 | 1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5091 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5092 | clear_bits |= GL_COLOR_BUFFER_BIT; |
[email protected] | 0e58af8 | 2014-08-08 14:02:53 | [diff] [blame] | 5093 | if (feature_info_->feature_flags().ext_draw_buffers) |
| 5094 | framebuffer->PrepareDrawBuffersForClear(); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5095 | } |
| 5096 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5097 | if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
| 5098 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5099 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 5100 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 5101 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5102 | clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 5103 | } |
| 5104 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5105 | if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
| 5106 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5107 | glClearDepth(1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5108 | state_.SetDeviceDepthMask(GL_TRUE); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5109 | clear_bits |= GL_DEPTH_BUFFER_BIT; |
| 5110 | } |
| 5111 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5112 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5113 | glClear(clear_bits); |
| 5114 | |
[email protected] | 0e58af8 | 2014-08-08 14:02:53 | [diff] [blame] | 5115 | if ((clear_bits | GL_COLOR_BUFFER_BIT) != 0 && |
| 5116 | feature_info_->feature_flags().ext_draw_buffers) |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 5117 | framebuffer->RestoreDrawBuffersAfterClear(); |
| 5118 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5119 | framebuffer_manager()->MarkAttachmentsAsCleared( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5120 | framebuffer, renderbuffer_manager(), texture_manager()); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5121 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 5122 | RestoreClearState(); |
| 5123 | |
| 5124 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5125 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, framebuffer->service_id()); |
| 5126 | Framebuffer* draw_framebuffer = |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 5127 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5128 | GLuint service_id = draw_framebuffer ? draw_framebuffer->service_id() : |
| 5129 | GetBackbufferServiceId(); |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 5130 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, service_id); |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 5131 | } |
| 5132 | } |
| 5133 | |
| 5134 | void GLES2DecoderImpl::RestoreClearState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5135 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5136 | glClearColor( |
| 5137 | state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, |
| 5138 | state_.color_clear_alpha); |
| 5139 | glClearStencil(state_.stencil_clear); |
| 5140 | glClearDepth(state_.depth_clear); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 5141 | if (state_.enable_flags.scissor_test) { |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5142 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5143 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5147 | Framebuffer* framebuffer = |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5148 | GetFramebufferInfoForTarget(target); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5149 | if (!framebuffer) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5150 | return GL_FRAMEBUFFER_COMPLETE; |
| 5151 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5152 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 5153 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
| 5154 | return completeness; |
| 5155 | } |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 5156 | return framebuffer->GetStatus(texture_manager(), target); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | void GLES2DecoderImpl::DoFramebufferTexture2D( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5160 | GLenum target, GLenum attachment, GLenum textarget, |
| 5161 | GLuint client_texture_id, GLint level) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5162 | DoFramebufferTexture2DCommon( |
| 5163 | "glFramebufferTexture2D", target, attachment, |
| 5164 | textarget, client_texture_id, level, 0); |
| 5165 | } |
| 5166 | |
| 5167 | void GLES2DecoderImpl::DoFramebufferTexture2DMultisample( |
| 5168 | GLenum target, GLenum attachment, GLenum textarget, |
| 5169 | GLuint client_texture_id, GLint level, GLsizei samples) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5170 | DoFramebufferTexture2DCommon( |
| 5171 | "glFramebufferTexture2DMultisample", target, attachment, |
| 5172 | textarget, client_texture_id, level, samples); |
| 5173 | } |
| 5174 | |
| 5175 | void GLES2DecoderImpl::DoFramebufferTexture2DCommon( |
| 5176 | const char* name, GLenum target, GLenum attachment, GLenum textarget, |
| 5177 | GLuint client_texture_id, GLint level, GLsizei samples) { |
| 5178 | if (samples > renderbuffer_manager()->max_samples()) { |
| 5179 | LOCAL_SET_GL_ERROR( |
| 5180 | GL_INVALID_VALUE, |
| 5181 | "glFramebufferTexture2DMultisample", "samples too large"); |
| 5182 | return; |
| 5183 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5184 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5185 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5186 | LOCAL_SET_GL_ERROR( |
| 5187 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5188 | name, "no framebuffer bound."); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5189 | return; |
| 5190 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5191 | GLuint service_id = 0; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5192 | TextureRef* texture_ref = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5193 | if (client_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5194 | texture_ref = GetTexture(client_texture_id); |
| 5195 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5196 | LOCAL_SET_GL_ERROR( |
| 5197 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5198 | name, "unknown texture_ref"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5199 | return; |
| 5200 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5201 | service_id = texture_ref->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5202 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5203 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 5204 | if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5205 | LOCAL_SET_GL_ERROR( |
| 5206 | GL_INVALID_VALUE, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5207 | name, "level out of range"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5208 | return; |
| 5209 | } |
| 5210 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5211 | if (texture_ref) |
| 5212 | DoWillUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 5213 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5214 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); |
| 5215 | if (0 == samples) { |
| 5216 | glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
| 5217 | } else { |
| 5218 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5219 | glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, |
| 5220 | service_id, level, samples); |
| 5221 | } else { |
| 5222 | glFramebufferTexture2DMultisampleEXT(target, attachment, textarget, |
| 5223 | service_id, level, samples); |
| 5224 | } |
| 5225 | } |
| 5226 | GLenum error = LOCAL_PEEK_GL_ERROR(name); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5227 | if (error == GL_NO_ERROR) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5228 | framebuffer->AttachTexture(attachment, texture_ref, textarget, level, |
| 5229 | samples); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5230 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 5231 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5232 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5233 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5234 | |
| 5235 | if (texture_ref) |
| 5236 | DoDidUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 5237 | |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 5238 | OnFboChanged(); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5239 | } |
| 5240 | |
| 5241 | void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( |
| 5242 | GLenum target, GLenum attachment, GLenum pname, GLint* params) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5243 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5244 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5245 | LOCAL_SET_GL_ERROR( |
| 5246 | GL_INVALID_OPERATION, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5247 | "glGetFramebufferAttachmentParameteriv", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5248 | return; |
| 5249 | } |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 5250 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5251 | const Framebuffer::Attachment* attachment_object = |
| 5252 | framebuffer->GetAttachment(attachment); |
| 5253 | *params = attachment_object ? attachment_object->object_name() : 0; |
| 5254 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5255 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT && |
| 5256 | features().use_img_for_multisampled_render_to_texture) { |
| 5257 | pname = GL_TEXTURE_SAMPLES_IMG; |
| 5258 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5259 | glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 5260 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5261 | } |
| 5262 | |
| 5263 | void GLES2DecoderImpl::DoGetRenderbufferParameteriv( |
| 5264 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5265 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5266 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5267 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5268 | LOCAL_SET_GL_ERROR( |
| 5269 | GL_INVALID_OPERATION, |
| 5270 | "glGetRenderbufferParameteriv", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5271 | return; |
| 5272 | } |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5273 | |
| 5274 | EnsureRenderbufferBound(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 5275 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5276 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5277 | *params = renderbuffer->internal_format(); |
| 5278 | break; |
| 5279 | case GL_RENDERBUFFER_WIDTH: |
| 5280 | *params = renderbuffer->width(); |
| 5281 | break; |
| 5282 | case GL_RENDERBUFFER_HEIGHT: |
| 5283 | *params = renderbuffer->height(); |
| 5284 | break; |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5285 | case GL_RENDERBUFFER_SAMPLES_EXT: |
| 5286 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5287 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_IMG, |
| 5288 | params); |
| 5289 | } else { |
| 5290 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_EXT, |
| 5291 | params); |
| 5292 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5293 | default: |
| 5294 | glGetRenderbufferParameterivEXT(target, pname, params); |
| 5295 | break; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 5296 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5297 | } |
| 5298 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5299 | void GLES2DecoderImpl::DoBlitFramebufferCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5300 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 5301 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 5302 | GLbitfield mask, GLenum filter) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 5303 | DCHECK(!ShouldDeferReads() && !ShouldDeferDraws()); |
[email protected] | 0c16343f | 2013-03-08 20:40:16 | [diff] [blame] | 5304 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5305 | if (!CheckBoundFramebuffersValid("glBlitFramebufferCHROMIUM")) { |
[email protected] | 0c16343f | 2013-03-08 20:40:16 | [diff] [blame] | 5306 | return; |
| 5307 | } |
| 5308 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5309 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
boliu | 2e7d8a7a | 2014-10-16 20:35:20 | [diff] [blame] | 5310 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5311 | BlitFramebufferHelper( |
| 5312 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5313 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, |
| 5314 | state_.enable_flags.scissor_test); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5315 | } |
| 5316 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5317 | void GLES2DecoderImpl::EnsureRenderbufferBound() { |
| 5318 | if (!state_.bound_renderbuffer_valid) { |
| 5319 | state_.bound_renderbuffer_valid = true; |
| 5320 | glBindRenderbufferEXT(GL_RENDERBUFFER, |
| 5321 | state_.bound_renderbuffer.get() |
| 5322 | ? state_.bound_renderbuffer->service_id() |
| 5323 | : 0); |
| 5324 | } |
| 5325 | } |
| 5326 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5327 | void GLES2DecoderImpl::RenderbufferStorageMultisampleHelper( |
| 5328 | const FeatureInfo* feature_info, |
| 5329 | GLenum target, |
| 5330 | GLsizei samples, |
| 5331 | GLenum internal_format, |
| 5332 | GLsizei width, |
| 5333 | GLsizei height) { |
| 5334 | // TODO(sievers): This could be resolved at the GL binding level, but the |
| 5335 | // binding process is currently a bit too 'brute force'. |
| 5336 | if (feature_info->feature_flags().is_angle) { |
| 5337 | glRenderbufferStorageMultisampleANGLE( |
| 5338 | target, samples, internal_format, width, height); |
| 5339 | } else if (feature_info->feature_flags().use_core_framebuffer_multisample) { |
| 5340 | glRenderbufferStorageMultisample( |
| 5341 | target, samples, internal_format, width, height); |
| 5342 | } else { |
| 5343 | glRenderbufferStorageMultisampleEXT( |
| 5344 | target, samples, internal_format, width, height); |
| 5345 | } |
| 5346 | } |
| 5347 | |
| 5348 | void GLES2DecoderImpl::BlitFramebufferHelper(GLint srcX0, |
| 5349 | GLint srcY0, |
| 5350 | GLint srcX1, |
| 5351 | GLint srcY1, |
| 5352 | GLint dstX0, |
| 5353 | GLint dstY0, |
| 5354 | GLint dstX1, |
| 5355 | GLint dstY1, |
| 5356 | GLbitfield mask, |
| 5357 | GLenum filter) { |
| 5358 | // TODO(sievers): This could be resolved at the GL binding level, but the |
| 5359 | // binding process is currently a bit too 'brute force'. |
| 5360 | if (feature_info_->feature_flags().is_angle) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 5361 | glBlitFramebufferANGLE( |
| 5362 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5363 | } else if (feature_info_->feature_flags().use_core_framebuffer_multisample) { |
| 5364 | glBlitFramebuffer( |
| 5365 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 5366 | } else { |
| 5367 | glBlitFramebufferEXT( |
| 5368 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 5369 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5370 | } |
| 5371 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5372 | bool GLES2DecoderImpl::ValidateRenderbufferStorageMultisample( |
| 5373 | GLsizei samples, |
| 5374 | GLenum internalformat, |
| 5375 | GLsizei width, |
| 5376 | GLsizei height) { |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5377 | if (samples > renderbuffer_manager()->max_samples()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5378 | LOCAL_SET_GL_ERROR( |
| 5379 | GL_INVALID_VALUE, |
| 5380 | "glRenderbufferStorageMultisample", "samples too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5381 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 5385 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5386 | LOCAL_SET_GL_ERROR( |
| 5387 | GL_INVALID_VALUE, |
| 5388 | "glRenderbufferStorageMultisample", "dimensions too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5389 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5390 | } |
| 5391 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5392 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5393 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 5394 | width, height, samples, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5395 | LOCAL_SET_GL_ERROR( |
| 5396 | GL_OUT_OF_MEMORY, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5397 | "glRenderbufferStorageMultisample", "dimensions too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5398 | return false; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5399 | } |
| 5400 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 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, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5404 | "glRenderbufferStorageMultisample", "out of memory"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5405 | return false; |
| 5406 | } |
| 5407 | |
| 5408 | return true; |
| 5409 | } |
| 5410 | |
| 5411 | void GLES2DecoderImpl::DoRenderbufferStorageMultisampleCHROMIUM( |
| 5412 | GLenum target, GLsizei samples, GLenum internalformat, |
| 5413 | GLsizei width, GLsizei height) { |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5414 | Renderbuffer* renderbuffer = GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5415 | if (!renderbuffer) { |
| 5416 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 5417 | "glRenderbufferStorageMultisampleCHROMIUM", |
| 5418 | "no renderbuffer bound"); |
| 5419 | return; |
| 5420 | } |
| 5421 | |
| 5422 | if (!ValidateRenderbufferStorageMultisample( |
| 5423 | samples, internalformat, width, height)) { |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5424 | return; |
| 5425 | } |
| 5426 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5427 | EnsureRenderbufferBound(); |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5428 | GLenum impl_format = |
| 5429 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5430 | internalformat); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5431 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER( |
| 5432 | "glRenderbufferStorageMultisampleCHROMIUM"); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5433 | RenderbufferStorageMultisampleHelper( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 5434 | feature_info_.get(), target, samples, impl_format, width, height); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5435 | GLenum error = |
| 5436 | LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleCHROMIUM"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5437 | if (error == GL_NO_ERROR) { |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5438 | |
| 5439 | if (workarounds().validate_multisample_buffer_allocation) { |
| 5440 | if (!VerifyMultisampleRenderbufferIntegrity( |
| 5441 | renderbuffer->service_id(), impl_format)) { |
| 5442 | LOCAL_SET_GL_ERROR( |
| 5443 | GL_OUT_OF_MEMORY, |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5444 | "glRenderbufferStorageMultisampleCHROMIUM", "out of memory"); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5445 | return; |
| 5446 | } |
| 5447 | } |
| 5448 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5449 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 5450 | // attached to we could just mark those framebuffers as not complete. |
| 5451 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5452 | renderbuffer_manager()->SetInfo( |
| 5453 | renderbuffer, samples, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5454 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5455 | } |
| 5456 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5457 | // This is the handler for multisampled_render_to_texture extensions. |
| 5458 | void GLES2DecoderImpl::DoRenderbufferStorageMultisampleEXT( |
| 5459 | GLenum target, GLsizei samples, GLenum internalformat, |
| 5460 | GLsizei width, GLsizei height) { |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5461 | Renderbuffer* renderbuffer = GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5462 | if (!renderbuffer) { |
| 5463 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 5464 | "glRenderbufferStorageMultisampleEXT", |
| 5465 | "no renderbuffer bound"); |
| 5466 | return; |
| 5467 | } |
| 5468 | |
| 5469 | if (!ValidateRenderbufferStorageMultisample( |
| 5470 | samples, internalformat, width, height)) { |
| 5471 | return; |
| 5472 | } |
| 5473 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5474 | EnsureRenderbufferBound(); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5475 | GLenum impl_format = |
| 5476 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5477 | internalformat); |
| 5478 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorageMultisampleEXT"); |
| 5479 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5480 | glRenderbufferStorageMultisampleIMG( |
| 5481 | target, samples, impl_format, width, height); |
| 5482 | } else { |
| 5483 | glRenderbufferStorageMultisampleEXT( |
| 5484 | target, samples, impl_format, width, height); |
| 5485 | } |
| 5486 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleEXT"); |
| 5487 | if (error == GL_NO_ERROR) { |
| 5488 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 5489 | // attached to we could just mark those framebuffers as not complete. |
| 5490 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
| 5491 | renderbuffer_manager()->SetInfo( |
| 5492 | renderbuffer, samples, internalformat, width, height); |
| 5493 | } |
| 5494 | } |
| 5495 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5496 | // This function validates the allocation of a multisampled renderbuffer |
| 5497 | // by clearing it to a key color, blitting the contents to a texture, and |
| 5498 | // reading back the color to ensure it matches the key. |
| 5499 | bool GLES2DecoderImpl::VerifyMultisampleRenderbufferIntegrity( |
| 5500 | GLuint renderbuffer, GLenum format) { |
| 5501 | |
| 5502 | // Only validate color buffers. |
| 5503 | // These formats have been selected because they are very common or are known |
| 5504 | // to be used by the WebGL backbuffer. If problems are observed with other |
| 5505 | // color formats they can be added here. |
| 5506 | switch(format) { |
| 5507 | case GL_RGB: |
| 5508 | case GL_RGB8: |
| 5509 | case GL_RGBA: |
| 5510 | case GL_RGBA8: |
| 5511 | break; |
| 5512 | default: |
| 5513 | return true; |
| 5514 | } |
| 5515 | |
| 5516 | GLint draw_framebuffer, read_framebuffer; |
| 5517 | |
| 5518 | // Cache framebuffer and texture bindings. |
| 5519 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_framebuffer); |
| 5520 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_framebuffer); |
| 5521 | |
| 5522 | if (!validation_texture_) { |
| 5523 | GLint bound_texture; |
| 5524 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
| 5525 | |
| 5526 | // Create additional resources needed for the verification. |
| 5527 | glGenTextures(1, &validation_texture_); |
| 5528 | glGenFramebuffersEXT(1, &validation_fbo_multisample_); |
| 5529 | glGenFramebuffersEXT(1, &validation_fbo_); |
| 5530 | |
| 5531 | // Texture only needs to be 1x1. |
| 5532 | glBindTexture(GL_TEXTURE_2D, validation_texture_); |
| 5533 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, |
| 5534 | GL_UNSIGNED_BYTE, NULL); |
| 5535 | |
| 5536 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 5537 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5538 | GL_TEXTURE_2D, validation_texture_, 0); |
| 5539 | |
| 5540 | glBindTexture(GL_TEXTURE_2D, bound_texture); |
| 5541 | } |
| 5542 | |
| 5543 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 5544 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5545 | GL_RENDERBUFFER, renderbuffer); |
| 5546 | |
| 5547 | // Cache current state and reset it to the values we require. |
| 5548 | GLboolean scissor_enabled = false; |
| 5549 | glGetBooleanv(GL_SCISSOR_TEST, &scissor_enabled); |
| 5550 | if (scissor_enabled) |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5551 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5552 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5553 | GLboolean color_mask[4] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE}; |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5554 | glGetBooleanv(GL_COLOR_WRITEMASK, color_mask); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5555 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5556 | |
| 5557 | GLfloat clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 5558 | glGetFloatv(GL_COLOR_CLEAR_VALUE, clear_color); |
| 5559 | glClearColor(1.0f, 0.0f, 1.0f, 1.0f); |
| 5560 | |
| 5561 | // Clear the buffer to the desired key color. |
| 5562 | glClear(GL_COLOR_BUFFER_BIT); |
| 5563 | |
| 5564 | // Blit from the multisample buffer to a standard texture. |
| 5565 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, validation_fbo_multisample_); |
| 5566 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, validation_fbo_); |
| 5567 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5568 | BlitFramebufferHelper( |
| 5569 | 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] | 5570 | |
| 5571 | // Read a pixel from the buffer. |
| 5572 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 5573 | |
| 5574 | unsigned char pixel[3] = {0, 0, 0}; |
| 5575 | glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixel); |
| 5576 | |
| 5577 | // Detach the renderbuffer. |
| 5578 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 5579 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5580 | GL_RENDERBUFFER, 0); |
| 5581 | |
| 5582 | // Restore cached state. |
| 5583 | if (scissor_enabled) |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5584 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5585 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5586 | state_.SetDeviceColorMask( |
| 5587 | color_mask[0], color_mask[1], color_mask[2], color_mask[3]); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5588 | glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); |
| 5589 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, draw_framebuffer); |
| 5590 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, read_framebuffer); |
| 5591 | |
| 5592 | // Return true if the pixel matched the desired key color. |
| 5593 | return (pixel[0] == 0xFF && |
| 5594 | pixel[1] == 0x00 && |
| 5595 | pixel[2] == 0xFF); |
| 5596 | } |
| 5597 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5598 | void GLES2DecoderImpl::DoRenderbufferStorage( |
| 5599 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5600 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5601 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5602 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5603 | LOCAL_SET_GL_ERROR( |
| 5604 | GL_INVALID_OPERATION, |
| 5605 | "glRenderbufferStorage", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5606 | return; |
| 5607 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5608 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5609 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 5610 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5611 | LOCAL_SET_GL_ERROR( |
| 5612 | GL_INVALID_VALUE, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5613 | return; |
| 5614 | } |
| 5615 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5616 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5617 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 5618 | width, height, 1, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5619 | LOCAL_SET_GL_ERROR( |
| 5620 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5621 | return; |
| 5622 | } |
| 5623 | |
| 5624 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5625 | LOCAL_SET_GL_ERROR( |
| 5626 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5627 | return; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 5628 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5629 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5630 | EnsureRenderbufferBound(); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5631 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorage"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5632 | glRenderbufferStorageEXT( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5633 | target, |
| 5634 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5635 | internalformat), |
| 5636 | width, |
| 5637 | height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5638 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorage"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5639 | if (error == GL_NO_ERROR) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5640 | // TODO(gman): If tetxures tracked which framebuffers they were attached to |
| 5641 | // we could just mark those framebuffers as not complete. |
| 5642 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5643 | renderbuffer_manager()->SetInfo( |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5644 | renderbuffer, 1, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5645 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5646 | } |
| 5647 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5648 | void GLES2DecoderImpl::DoLinkProgram(GLuint program_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 5649 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoLinkProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5650 | Program* program = GetProgramInfoNotShader( |
| 5651 | program_id, "glLinkProgram"); |
| 5652 | if (!program) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 5653 | return; |
| 5654 | } |
[email protected] | 05afda1 | 2011-01-20 00:17:34 | [diff] [blame] | 5655 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5656 | LogClientServiceForInfo(program, program_id, "glLinkProgram"); |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 5657 | ShaderTranslator* vertex_translator = NULL; |
| 5658 | ShaderTranslator* fragment_translator = NULL; |
| 5659 | if (use_shader_translator_) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5660 | vertex_translator = vertex_translator_.get(); |
| 5661 | fragment_translator = fragment_translator_.get(); |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 5662 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5663 | if (program->Link(shader_manager(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5664 | vertex_translator, |
| 5665 | fragment_translator, |
[email protected] | 00840153 | 2014-02-07 00:10:50 | [diff] [blame] | 5666 | workarounds().count_all_in_varyings_packing ? |
| 5667 | Program::kCountAll : Program::kCountOnlyStaticallyUsed, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5668 | shader_cache_callback_)) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5669 | if (program == state_.current_program.get()) { |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 5670 | if (workarounds().use_current_program_after_successful_link) |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5671 | glUseProgram(program->service_id()); |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 5672 | if (workarounds().clear_uniforms_before_first_program_use) |
| 5673 | program_manager()->ClearUniforms(program); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 5674 | } |
| 5675 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 5676 | |
| 5677 | // LinkProgram can be very slow. Exit command processing to allow for |
| 5678 | // context preemption and GPU watchdog checks. |
| 5679 | ExitCommandProcessingEarly(); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5680 | }; |
| 5681 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5682 | void GLES2DecoderImpl::DoTexParameterf( |
| 5683 | GLenum target, GLenum pname, GLfloat param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5684 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5685 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5686 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5687 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterf", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5688 | return; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5689 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5690 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 5691 | texture_manager()->SetParameterf( |
| 5692 | "glTexParameterf", GetErrorState(), texture, pname, param); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5693 | } |
| 5694 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5695 | void GLES2DecoderImpl::DoTexParameteri( |
| 5696 | GLenum target, GLenum pname, GLint param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5697 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5698 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5699 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5700 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5701 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5702 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5703 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 5704 | texture_manager()->SetParameteri( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5705 | "glTexParameteri", GetErrorState(), texture, pname, param); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | void GLES2DecoderImpl::DoTexParameterfv( |
| 5709 | GLenum target, GLenum pname, const GLfloat* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5710 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5711 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5712 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5713 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5714 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5715 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5716 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 5717 | texture_manager()->SetParameterf( |
| 5718 | "glTexParameterfv", GetErrorState(), texture, pname, *params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5719 | } |
| 5720 | |
| 5721 | void GLES2DecoderImpl::DoTexParameteriv( |
| 5722 | GLenum target, GLenum pname, const GLint* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5723 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5724 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5725 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5726 | LOCAL_SET_GL_ERROR( |
| 5727 | GL_INVALID_VALUE, "glTexParameteriv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5728 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5729 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5730 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 5731 | texture_manager()->SetParameteri( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5732 | "glTexParameteriv", GetErrorState(), texture, pname, *params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5733 | } |
| 5734 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5735 | bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5736 | if (!state_.current_program.get()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5737 | // The program does not exist. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5738 | LOCAL_SET_GL_ERROR( |
| 5739 | GL_INVALID_OPERATION, function_name, "no program in use"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5740 | return false; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5741 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5742 | if (!state_.current_program->InUse()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5743 | LOCAL_SET_GL_ERROR( |
| 5744 | GL_INVALID_OPERATION, function_name, "program not linked"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5745 | return false; |
| 5746 | } |
| 5747 | return true; |
| 5748 | } |
| 5749 | |
| 5750 | bool GLES2DecoderImpl::CheckCurrentProgramForUniform( |
| 5751 | GLint location, const char* function_name) { |
| 5752 | if (!CheckCurrentProgram(function_name)) { |
| 5753 | return false; |
| 5754 | } |
| 5755 | return location != -1; |
| 5756 | } |
| 5757 | |
zmo | f9a81360f | 2014-10-17 00:06:14 | [diff] [blame] | 5758 | bool GLES2DecoderImpl::CheckDrawingFeedbackLoops() { |
| 5759 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 5760 | if (!framebuffer) |
| 5761 | return false; |
| 5762 | const Framebuffer::Attachment* attachment = |
| 5763 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
| 5764 | if (!attachment) |
| 5765 | return false; |
| 5766 | |
| 5767 | DCHECK(state_.current_program.get()); |
| 5768 | const Program::SamplerIndices& sampler_indices = |
| 5769 | state_.current_program->sampler_indices(); |
| 5770 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 5771 | const Program::UniformInfo* uniform_info = |
| 5772 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
| 5773 | DCHECK(uniform_info); |
| 5774 | if (uniform_info->type != GL_SAMPLER_2D) |
| 5775 | continue; |
| 5776 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 5777 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
| 5778 | if (texture_unit_index >= state_.texture_units.size()) |
| 5779 | continue; |
| 5780 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
| 5781 | TextureRef* texture_ref = |
| 5782 | texture_unit.GetInfoForSamplerType(GL_SAMPLER_2D).get(); |
| 5783 | if (attachment->IsTexture(texture_ref)) |
| 5784 | return true; |
| 5785 | } |
| 5786 | } |
| 5787 | return false; |
| 5788 | } |
| 5789 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5790 | bool GLES2DecoderImpl::PrepForSetUniformByLocation( |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5791 | GLint fake_location, |
| 5792 | const char* function_name, |
| 5793 | Program::UniformApiType api_type, |
| 5794 | GLint* real_location, |
| 5795 | GLenum* type, |
| 5796 | GLsizei* count) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5797 | DCHECK(type); |
| 5798 | DCHECK(count); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5799 | DCHECK(real_location); |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5800 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5801 | if (!CheckCurrentProgramForUniform(fake_location, function_name)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5802 | return false; |
| 5803 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5804 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5805 | const Program::UniformInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5806 | state_.current_program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5807 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5808 | if (!info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5809 | LOCAL_SET_GL_ERROR( |
| 5810 | GL_INVALID_OPERATION, function_name, "unknown location"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5811 | return false; |
| 5812 | } |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5813 | |
| 5814 | if ((api_type & info->accepts_api_type) == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5815 | LOCAL_SET_GL_ERROR( |
| 5816 | GL_INVALID_OPERATION, function_name, |
| 5817 | "wrong uniform function for type"); |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 5818 | return false; |
| 5819 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5820 | if (*count > 1 && !info->is_array) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5821 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5822 | GL_INVALID_OPERATION, function_name, "count > 1 for non-array"); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5823 | return false; |
| 5824 | } |
| 5825 | *count = std::min(info->size - array_index, *count); |
| 5826 | if (*count <= 0) { |
| 5827 | return false; |
| 5828 | } |
| 5829 | *type = info->type; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5830 | return true; |
| 5831 | } |
| 5832 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5833 | void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) { |
| 5834 | GLenum type = 0; |
| 5835 | GLsizei count = 1; |
| 5836 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5837 | if (!PrepForSetUniformByLocation(fake_location, |
| 5838 | "glUniform1i", |
| 5839 | Program::kUniform1i, |
| 5840 | &real_location, |
| 5841 | &type, |
| 5842 | &count)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5843 | return; |
| 5844 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5845 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5846 | state_.texture_units.size(), fake_location, 1, &v0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5847 | LOCAL_SET_GL_ERROR( |
| 5848 | GL_INVALID_VALUE, "glUniform1i", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 5849 | return; |
| 5850 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5851 | glUniform1i(real_location, v0); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5852 | } |
| 5853 | |
| 5854 | void GLES2DecoderImpl::DoUniform1iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5855 | GLint fake_location, GLsizei count, const GLint *value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5856 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5857 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5858 | if (!PrepForSetUniformByLocation(fake_location, |
| 5859 | "glUniform1iv", |
| 5860 | Program::kUniform1i, |
| 5861 | &real_location, |
| 5862 | &type, |
| 5863 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5864 | return; |
| 5865 | } |
[email protected] | 7472711 | 2012-06-13 21:18:08 | [diff] [blame] | 5866 | if (type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || |
| 5867 | type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5868 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 5869 | state_.texture_units.size(), fake_location, count, value)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5870 | LOCAL_SET_GL_ERROR( |
| 5871 | GL_INVALID_VALUE, "glUniform1iv", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 5872 | return; |
| 5873 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5874 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5875 | glUniform1iv(real_location, count, value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5876 | } |
| 5877 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5878 | void GLES2DecoderImpl::DoUniform1fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5879 | GLint fake_location, GLsizei count, 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] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5882 | if (!PrepForSetUniformByLocation(fake_location, |
| 5883 | "glUniform1fv", |
| 5884 | Program::kUniform1f, |
| 5885 | &real_location, |
| 5886 | &type, |
| 5887 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5888 | return; |
| 5889 | } |
| 5890 | if (type == GL_BOOL) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5891 | scoped_ptr<GLint[]> temp(new GLint[count]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5892 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5893 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5894 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5895 | DoUniform1iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5896 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5897 | glUniform1fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5898 | } |
| 5899 | } |
| 5900 | |
| 5901 | void GLES2DecoderImpl::DoUniform2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5902 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5903 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5904 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5905 | if (!PrepForSetUniformByLocation(fake_location, |
| 5906 | "glUniform2fv", |
| 5907 | Program::kUniform2f, |
| 5908 | &real_location, |
| 5909 | &type, |
| 5910 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5911 | return; |
| 5912 | } |
| 5913 | if (type == GL_BOOL_VEC2) { |
| 5914 | GLsizei num_values = count * 2; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5915 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5916 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5917 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5918 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5919 | glUniform2iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5920 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5921 | glUniform2fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5922 | } |
| 5923 | } |
| 5924 | |
| 5925 | void GLES2DecoderImpl::DoUniform3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5926 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5927 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5928 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5929 | if (!PrepForSetUniformByLocation(fake_location, |
| 5930 | "glUniform3fv", |
| 5931 | Program::kUniform3f, |
| 5932 | &real_location, |
| 5933 | &type, |
| 5934 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5935 | return; |
| 5936 | } |
| 5937 | if (type == GL_BOOL_VEC3) { |
| 5938 | GLsizei num_values = count * 3; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5939 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5940 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5941 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5942 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5943 | glUniform3iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5944 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5945 | glUniform3fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5946 | } |
| 5947 | } |
| 5948 | |
| 5949 | void GLES2DecoderImpl::DoUniform4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5950 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5951 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5952 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5953 | if (!PrepForSetUniformByLocation(fake_location, |
| 5954 | "glUniform4fv", |
| 5955 | Program::kUniform4f, |
| 5956 | &real_location, |
| 5957 | &type, |
| 5958 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5959 | return; |
| 5960 | } |
| 5961 | if (type == GL_BOOL_VEC4) { |
| 5962 | GLsizei num_values = count * 4; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5963 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5964 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 5965 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5966 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5967 | glUniform4iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5968 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5969 | glUniform4fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5970 | } |
| 5971 | } |
| 5972 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5973 | void GLES2DecoderImpl::DoUniform2iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5974 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5975 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5976 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5977 | if (!PrepForSetUniformByLocation(fake_location, |
| 5978 | "glUniform2iv", |
| 5979 | Program::kUniform2i, |
| 5980 | &real_location, |
| 5981 | &type, |
| 5982 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5983 | return; |
| 5984 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5985 | glUniform2iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5986 | } |
| 5987 | |
| 5988 | void GLES2DecoderImpl::DoUniform3iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5989 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5990 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 5991 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 5992 | if (!PrepForSetUniformByLocation(fake_location, |
| 5993 | "glUniform3iv", |
| 5994 | Program::kUniform3i, |
| 5995 | &real_location, |
| 5996 | &type, |
| 5997 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 5998 | return; |
| 5999 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6000 | glUniform3iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6001 | } |
| 6002 | |
| 6003 | void GLES2DecoderImpl::DoUniform4iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6004 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6005 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6006 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6007 | if (!PrepForSetUniformByLocation(fake_location, |
| 6008 | "glUniform4iv", |
| 6009 | Program::kUniform4i, |
| 6010 | &real_location, |
| 6011 | &type, |
| 6012 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6013 | return; |
| 6014 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6015 | glUniform4iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6016 | } |
| 6017 | |
| 6018 | void GLES2DecoderImpl::DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6019 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 6020 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6021 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6022 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6023 | if (!PrepForSetUniformByLocation(fake_location, |
| 6024 | "glUniformMatrix2fv", |
| 6025 | Program::kUniformMatrix2f, |
| 6026 | &real_location, |
| 6027 | &type, |
| 6028 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6029 | return; |
| 6030 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6031 | glUniformMatrix2fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6032 | } |
| 6033 | |
| 6034 | void GLES2DecoderImpl::DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6035 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 6036 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6037 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6038 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6039 | if (!PrepForSetUniformByLocation(fake_location, |
| 6040 | "glUniformMatrix3fv", |
| 6041 | Program::kUniformMatrix3f, |
| 6042 | &real_location, |
| 6043 | &type, |
| 6044 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6045 | return; |
| 6046 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6047 | glUniformMatrix3fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6048 | } |
| 6049 | |
| 6050 | void GLES2DecoderImpl::DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6051 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 6052 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6053 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6054 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6055 | if (!PrepForSetUniformByLocation(fake_location, |
| 6056 | "glUniformMatrix4fv", |
| 6057 | Program::kUniformMatrix4f, |
| 6058 | &real_location, |
| 6059 | &type, |
| 6060 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6061 | return; |
| 6062 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6063 | glUniformMatrix4fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6064 | } |
| 6065 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6066 | void GLES2DecoderImpl::DoUseProgram(GLuint program_id) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6067 | GLuint service_id = 0; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6068 | Program* program = NULL; |
| 6069 | if (program_id) { |
| 6070 | program = GetProgramInfoNotShader(program_id, "glUseProgram"); |
| 6071 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6072 | return; |
| 6073 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6074 | if (!program->IsValid()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6075 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6076 | LOCAL_SET_GL_ERROR( |
| 6077 | GL_INVALID_OPERATION, "glUseProgram", "program not linked"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6078 | return; |
| 6079 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6080 | service_id = program->service_id(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6081 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6082 | if (state_.current_program.get()) { |
| 6083 | program_manager()->UnuseProgram(shader_manager(), |
| 6084 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 6085 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6086 | state_.current_program = program; |
| 6087 | LogClientServiceMapping("glUseProgram", program_id, service_id); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 6088 | glUseProgram(service_id); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6089 | if (state_.current_program.get()) { |
| 6090 | program_manager()->UseProgram(state_.current_program.get()); |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 6091 | if (workarounds().clear_uniforms_before_first_program_use) |
| 6092 | program_manager()->ClearUniforms(program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 6093 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6094 | } |
| 6095 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6096 | void GLES2DecoderImpl::RenderWarning( |
| 6097 | const char* filename, int line, const std::string& msg) { |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 6098 | logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6099 | } |
| 6100 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6101 | void GLES2DecoderImpl::PerformanceWarning( |
| 6102 | const char* filename, int line, const std::string& msg) { |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 6103 | logger_.LogMessage(filename, line, |
| 6104 | std::string("PERFORMANCE WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6105 | } |
| 6106 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6107 | void GLES2DecoderImpl::DoWillUseTexImageIfNeeded( |
| 6108 | Texture* texture, GLenum textarget) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6109 | // Image is already in use if texture is attached to a framebuffer. |
| 6110 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 6111 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6112 | if (image) { |
| 6113 | ScopedGLErrorSuppressor suppressor( |
| 6114 | "GLES2DecoderImpl::DoWillUseTexImageIfNeeded", |
| 6115 | GetErrorState()); |
| 6116 | glBindTexture(textarget, texture->service_id()); |
| 6117 | image->WillUseTexImage(); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 6118 | RestoreCurrentTextureBindings(&state_, textarget); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6119 | } |
| 6120 | } |
| 6121 | } |
| 6122 | |
| 6123 | void GLES2DecoderImpl::DoDidUseTexImageIfNeeded( |
| 6124 | Texture* texture, GLenum textarget) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6125 | // Image is still in use if texture is attached to a framebuffer. |
| 6126 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 6127 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6128 | if (image) { |
| 6129 | ScopedGLErrorSuppressor suppressor( |
| 6130 | "GLES2DecoderImpl::DoDidUseTexImageIfNeeded", |
| 6131 | GetErrorState()); |
| 6132 | glBindTexture(textarget, texture->service_id()); |
| 6133 | image->DidUseTexImage(); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 6134 | RestoreCurrentTextureBindings(&state_, textarget); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6135 | } |
| 6136 | } |
| 6137 | } |
| 6138 | |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6139 | bool GLES2DecoderImpl::PrepareTexturesForRender() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6140 | DCHECK(state_.current_program.get()); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6141 | if (!texture_manager()->HaveUnrenderableTextures() && |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 6142 | !texture_manager()->HaveImages()) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6143 | return true; |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 6144 | } |
[email protected] | e2367b4 | 2013-05-31 03:37:21 | [diff] [blame] | 6145 | |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 6146 | bool textures_set = false; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6147 | const Program::SamplerIndices& sampler_indices = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6148 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6149 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6150 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6151 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6152 | DCHECK(uniform_info); |
| 6153 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6154 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6155 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6156 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6157 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 6158 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6159 | GLenum textarget = GetBindTargetForSamplerType(uniform_info->type); |
| 6160 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 6161 | textures_set = true; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6162 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6163 | glBindTexture( |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6164 | textarget, |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 6165 | texture_manager()->black_texture_id(uniform_info->type)); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6166 | LOCAL_RENDER_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6167 | std::string("texture bound to texture unit ") + |
| 6168 | base::IntToString(texture_unit_index) + |
[email protected] | ad9b7f8b | 2013-06-17 07:36:29 | [diff] [blame] | 6169 | " is not renderable. It maybe non-power-of-2 and have" |
| 6170 | " incompatible texture filtering or is not" |
| 6171 | " 'texture complete'"); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6172 | continue; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6173 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6174 | |
[email protected] | 4e7b8920 | 2014-01-28 01:44:06 | [diff] [blame] | 6175 | if (textarget != GL_TEXTURE_CUBE_MAP) { |
| 6176 | Texture* texture = texture_ref->texture(); |
| 6177 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6178 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 6179 | ScopedGLErrorSuppressor suppressor( |
| 6180 | "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); |
| 6181 | textures_set = true; |
| 6182 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6183 | image->WillUseTexImage(); |
| 6184 | continue; |
| 6185 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6186 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6187 | } |
| 6188 | // else: should this be an error? |
| 6189 | } |
| 6190 | } |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6191 | return !textures_set; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6192 | } |
| 6193 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6194 | void GLES2DecoderImpl::RestoreStateForTextures() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6195 | DCHECK(state_.current_program.get()); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6196 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6197 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6198 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6199 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6200 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6201 | DCHECK(uniform_info); |
| 6202 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6203 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6204 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6205 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6206 | TextureRef* texture_ref = |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6207 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6208 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6209 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6210 | // Get the texture_ref info that was previously bound here. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6211 | texture_ref = texture_unit.bind_target == GL_TEXTURE_2D |
| 6212 | ? texture_unit.bound_texture_2d.get() |
| 6213 | : texture_unit.bound_texture_cube_map.get(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6214 | glBindTexture(texture_unit.bind_target, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6215 | texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6216 | continue; |
| 6217 | } |
| 6218 | |
[email protected] | 4e7b8920 | 2014-01-28 01:44:06 | [diff] [blame] | 6219 | if (texture_unit.bind_target != GL_TEXTURE_CUBE_MAP) { |
| 6220 | Texture* texture = texture_ref->texture(); |
| 6221 | gfx::GLImage* image = |
| 6222 | texture->GetLevelImage(texture_unit.bind_target, 0); |
| 6223 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 6224 | ScopedGLErrorSuppressor suppressor( |
| 6225 | "GLES2DecoderImpl::RestoreStateForTextures", GetErrorState()); |
| 6226 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6227 | image->DidUseTexImage(); |
| 6228 | continue; |
| 6229 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6230 | } |
| 6231 | } |
| 6232 | } |
| 6233 | } |
| 6234 | // Set the active texture back to whatever the user had it as. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6235 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6236 | } |
| 6237 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6238 | bool GLES2DecoderImpl::ClearUnclearedTextures() { |
| 6239 | // Only check if there are some uncleared textures. |
| 6240 | if (!texture_manager()->HaveUnsafeTextures()) { |
| 6241 | return true; |
| 6242 | } |
| 6243 | |
| 6244 | // 1: Check all textures we are about to render with. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6245 | if (state_.current_program.get()) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6246 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6247 | state_.current_program->sampler_indices(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6248 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6249 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6250 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6251 | DCHECK(uniform_info); |
| 6252 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6253 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6254 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6255 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6256 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 6257 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6258 | if (texture_ref && !texture_ref->texture()->SafeToRenderFrom()) { |
| 6259 | if (!texture_manager()->ClearRenderableLevels(this, texture_ref)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6260 | return false; |
| 6261 | } |
| 6262 | } |
| 6263 | } |
| 6264 | } |
| 6265 | } |
| 6266 | } |
| 6267 | return true; |
| 6268 | } |
| 6269 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6270 | bool GLES2DecoderImpl::IsDrawValid( |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6271 | const char* function_name, GLuint max_vertex_accessed, bool instanced, |
| 6272 | GLsizei primcount) { |
| 6273 | DCHECK(instanced || primcount == 1); |
| 6274 | |
[email protected] | 689fa1c5 | 2010-06-09 18:35:03 | [diff] [blame] | 6275 | // NOTE: We specifically do not check current_program->IsValid() because |
| 6276 | // it could never be invalid since glUseProgram would have failed. While |
| 6277 | // glLinkProgram could later mark the program as invalid the previous |
| 6278 | // valid program will still function if it is still the current program. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6279 | if (!state_.current_program.get()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6280 | // The program does not exist. |
| 6281 | // But GL says no ERROR. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6282 | LOCAL_RENDER_WARNING("Drawing with no current shader program."); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6283 | return false; |
| 6284 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6285 | |
zmo | f9a81360f | 2014-10-17 00:06:14 | [diff] [blame] | 6286 | if (CheckDrawingFeedbackLoops()) { |
| 6287 | LOCAL_SET_GL_ERROR( |
| 6288 | GL_INVALID_OPERATION, function_name, |
| 6289 | "Source and destination textures of the draw are the same."); |
| 6290 | return false; |
| 6291 | } |
| 6292 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6293 | return state_.vertex_attrib_manager |
| 6294 | ->ValidateBindings(function_name, |
| 6295 | this, |
| 6296 | feature_info_.get(), |
| 6297 | state_.current_program.get(), |
| 6298 | max_vertex_accessed, |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6299 | instanced, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6300 | primcount); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6301 | } |
| 6302 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6303 | bool GLES2DecoderImpl::SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6304 | const char* function_name, GLuint max_vertex_accessed, bool* simulated) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6305 | DCHECK(simulated); |
| 6306 | *simulated = false; |
| 6307 | |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6308 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6309 | return true; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6310 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6311 | const VertexAttrib* attrib = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6312 | state_.vertex_attrib_manager->GetVertexAttrib(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6313 | // 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] | 6314 | bool attrib_0_used = |
| 6315 | state_.current_program->GetAttribInfoByLocation(0) != NULL; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6316 | if (attrib->enabled() && attrib_0_used) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6317 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6318 | } |
| 6319 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6320 | // Make a buffer with a single repeated vec4 value enough to |
| 6321 | // simulate the constant value that is supposed to be here. |
| 6322 | // This is required to emulate GLES2 on GL. |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6323 | GLuint num_vertices = max_vertex_accessed + 1; |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6324 | uint32 size_needed = 0; |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6325 | |
| 6326 | if (num_vertices == 0 || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6327 | !SafeMultiplyUint32(num_vertices, sizeof(Vec4), &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6328 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6329 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6330 | return false; |
| 6331 | } |
| 6332 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6333 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6334 | "Attribute 0 is disabled. This has signficant performance penalty"); |
| 6335 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6336 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6337 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 6338 | |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 6339 | bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; |
| 6340 | if (new_buffer) { |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6341 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6342 | GLenum error = glGetError(); |
| 6343 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6344 | LOCAL_SET_GL_ERROR( |
| 6345 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6346 | return false; |
| 6347 | } |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6348 | } |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6349 | |
| 6350 | const Vec4& value = state_.attrib_values[0]; |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 6351 | if (new_buffer || |
| 6352 | (attrib_0_used && |
| 6353 | (!attrib_0_buffer_matches_value_ || |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6354 | (value.v[0] != attrib_0_value_.v[0] || |
| 6355 | value.v[1] != attrib_0_value_.v[1] || |
| 6356 | value.v[2] != attrib_0_value_.v[2] || |
| 6357 | value.v[3] != attrib_0_value_.v[3])))) { |
| 6358 | std::vector<Vec4> temp(num_vertices, value); |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6359 | glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); |
| 6360 | attrib_0_buffer_matches_value_ = true; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6361 | attrib_0_value_ = value; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6362 | attrib_0_size_ = size_needed; |
| 6363 | } |
| 6364 | |
| 6365 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 6366 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6367 | if (attrib->divisor()) |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6368 | glVertexAttribDivisorANGLE(0, 0); |
| 6369 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6370 | *simulated = true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6371 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6372 | } |
| 6373 | |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 6374 | void GLES2DecoderImpl::RestoreStateForAttrib( |
| 6375 | GLuint attrib_index, bool restore_array_binding) { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6376 | const VertexAttrib* attrib = |
| 6377 | state_.vertex_attrib_manager->GetVertexAttrib(attrib_index); |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 6378 | if (restore_array_binding) { |
| 6379 | const void* ptr = reinterpret_cast<const void*>(attrib->offset()); |
| 6380 | Buffer* buffer = attrib->buffer(); |
| 6381 | glBindBuffer(GL_ARRAY_BUFFER, buffer ? buffer->service_id() : 0); |
| 6382 | glVertexAttribPointer( |
| 6383 | attrib_index, attrib->size(), attrib->type(), attrib->normalized(), |
| 6384 | attrib->gl_stride(), ptr); |
| 6385 | } |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6386 | if (attrib->divisor()) |
| 6387 | glVertexAttribDivisorANGLE(attrib_index, attrib->divisor()); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6388 | glBindBuffer( |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 6389 | GL_ARRAY_BUFFER, state_.bound_array_buffer.get() ? |
| 6390 | state_.bound_array_buffer->service_id() : 0); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6391 | |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6392 | // Never touch vertex attribute 0's state (in particular, never |
| 6393 | // disable it) when running on desktop GL because it will never be |
| 6394 | // re-enabled. |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6395 | if (attrib_index != 0 || |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6396 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6397 | if (attrib->enabled()) { |
| 6398 | glEnableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6399 | } else { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6400 | glDisableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6401 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6402 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6403 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6404 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6405 | bool GLES2DecoderImpl::SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6406 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6407 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6408 | DCHECK(simulated); |
| 6409 | *simulated = false; |
| 6410 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
| 6411 | return true; |
| 6412 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6413 | if (!state_.vertex_attrib_manager->HaveFixedAttribs()) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6414 | return true; |
| 6415 | } |
| 6416 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6417 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6418 | "GL_FIXED attributes have a signficant performance penalty"); |
| 6419 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6420 | // NOTE: we could be smart and try to check if a buffer is used |
| 6421 | // twice in 2 different attribs, find the overlapping parts and therefore |
| 6422 | // duplicate the minimum amount of data but this whole code path is not meant |
| 6423 | // to be used normally. It's just here to pass that OpenGL ES 2.0 conformance |
| 6424 | // tests so we just add to the buffer attrib used. |
| 6425 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6426 | GLuint elements_needed = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6427 | const VertexAttribManager::VertexAttribList& enabled_attribs = |
| 6428 | state_.vertex_attrib_manager->GetEnabledVertexAttribs(); |
| 6429 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 6430 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 6431 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6432 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6433 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 6434 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
| 6435 | max_vertex_accessed); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6436 | GLuint num_vertices = max_accessed + 1; |
| 6437 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6438 | LOCAL_SET_GL_ERROR( |
| 6439 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6440 | return false; |
| 6441 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6442 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6443 | attrib->CanAccess(max_accessed) && |
| 6444 | attrib->type() == GL_FIXED) { |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6445 | uint32 elements_used = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6446 | if (!SafeMultiplyUint32(num_vertices, attrib->size(), &elements_used) || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6447 | !SafeAddUint32(elements_needed, elements_used, &elements_needed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6448 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6449 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6450 | return false; |
| 6451 | } |
| 6452 | } |
| 6453 | } |
| 6454 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6455 | const uint32 kSizeOfFloat = sizeof(float); // NOLINT |
| 6456 | uint32 size_needed = 0; |
| 6457 | if (!SafeMultiplyUint32(elements_needed, kSizeOfFloat, &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6458 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6459 | LOCAL_SET_GL_ERROR( |
| 6460 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6461 | return false; |
| 6462 | } |
| 6463 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6464 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6465 | |
| 6466 | glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6467 | if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6468 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6469 | GLenum error = glGetError(); |
| 6470 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6471 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6472 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6473 | return false; |
| 6474 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6475 | } |
| 6476 | |
| 6477 | // Copy the elements and convert to float |
| 6478 | GLintptr offset = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6479 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 6480 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 6481 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6482 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6483 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 6484 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6485 | max_vertex_accessed); |
| 6486 | GLuint num_vertices = max_accessed + 1; |
| 6487 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6488 | LOCAL_SET_GL_ERROR( |
| 6489 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6490 | return false; |
| 6491 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6492 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6493 | attrib->CanAccess(max_accessed) && |
| 6494 | attrib->type() == GL_FIXED) { |
| 6495 | int num_elements = attrib->size() * kSizeOfFloat; |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6496 | int size = num_elements * num_vertices; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6497 | scoped_ptr<float[]> data(new float[size]); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6498 | const int32* src = reinterpret_cast<const int32 *>( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6499 | attrib->buffer()->GetRange(attrib->offset(), size)); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6500 | const int32* end = src + num_elements; |
| 6501 | float* dst = data.get(); |
| 6502 | while (src != end) { |
| 6503 | *dst++ = static_cast<float>(*src++) / 65536.0f; |
| 6504 | } |
| 6505 | glBufferSubData(GL_ARRAY_BUFFER, offset, size, data.get()); |
| 6506 | glVertexAttribPointer( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6507 | attrib->index(), attrib->size(), GL_FLOAT, false, 0, |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6508 | reinterpret_cast<GLvoid*>(offset)); |
| 6509 | offset += size; |
| 6510 | } |
| 6511 | } |
| 6512 | *simulated = true; |
| 6513 | return true; |
| 6514 | } |
| 6515 | |
| 6516 | void GLES2DecoderImpl::RestoreStateForSimulatedFixedAttribs() { |
| 6517 | // There's no need to call glVertexAttribPointer because we shadow all the |
| 6518 | // settings and passing GL_FIXED to it will not work. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6519 | glBindBuffer( |
| 6520 | GL_ARRAY_BUFFER, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6521 | state_.bound_array_buffer.get() ? state_.bound_array_buffer->service_id() |
| 6522 | : 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6523 | } |
| 6524 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6525 | error::Error GLES2DecoderImpl::DoDrawArrays( |
| 6526 | const char* function_name, |
| 6527 | bool instanced, |
| 6528 | GLenum mode, |
| 6529 | GLint first, |
| 6530 | GLsizei count, |
| 6531 | GLsizei primcount) { |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 6532 | error::Error error = WillAccessBoundFramebufferForDraw(); |
| 6533 | if (error != error::kNoError) |
| 6534 | return error; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6535 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6536 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6537 | return error::kNoError; |
| 6538 | } |
| 6539 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6540 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6541 | return error::kNoError; |
| 6542 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6543 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6544 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6545 | return error::kNoError; |
| 6546 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6547 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6548 | return error::kNoError; |
| 6549 | } |
| 6550 | // We have to check this here because the prototype for glDrawArrays |
| 6551 | // is GLint not GLsizei. |
| 6552 | if (first < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6553 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "first < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6554 | return error::kNoError; |
| 6555 | } |
| 6556 | |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6557 | if (count == 0 || primcount == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6558 | LOCAL_RENDER_WARNING("Render count or primcount is 0."); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6559 | return error::kNoError; |
| 6560 | } |
| 6561 | |
| 6562 | GLuint max_vertex_accessed = first + count - 1; |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6563 | if (IsDrawValid(function_name, max_vertex_accessed, instanced, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6564 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6565 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6566 | return error::kNoError; |
| 6567 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6568 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6569 | if (!SimulateAttrib0( |
| 6570 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6571 | return error::kNoError; |
| 6572 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6573 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6574 | if (SimulateFixedAttribs( |
| 6575 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 6576 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6577 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6578 | ApplyDirtyState(); |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 6579 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6580 | if (!instanced) { |
| 6581 | glDrawArrays(mode, first, count); |
| 6582 | } else { |
| 6583 | glDrawArraysInstancedANGLE(mode, first, count, primcount); |
| 6584 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6585 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6586 | RestoreStateForTextures(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6587 | } |
| 6588 | if (simulated_fixed_attribs) { |
| 6589 | RestoreStateForSimulatedFixedAttribs(); |
| 6590 | } |
| 6591 | } |
| 6592 | if (simulated_attrib_0) { |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 6593 | // We don't have to restore attrib 0 generic data at the end of this |
| 6594 | // function even if it is simulated. This is because we will simulate |
| 6595 | // it in each draw call, and attrib 0 generic data queries use cached |
| 6596 | // values instead of passing down to the underlying driver. |
| 6597 | RestoreStateForAttrib(0, false); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6598 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6599 | } |
| 6600 | return error::kNoError; |
| 6601 | } |
| 6602 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6603 | error::Error GLES2DecoderImpl::HandleDrawArrays(uint32 immediate_data_size, |
| 6604 | const void* cmd_data) { |
| 6605 | const cmds::DrawArrays& c = *static_cast<const cmds::DrawArrays*>(cmd_data); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6606 | return DoDrawArrays("glDrawArrays", |
| 6607 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6608 | static_cast<GLenum>(c.mode), |
| 6609 | static_cast<GLint>(c.first), |
| 6610 | static_cast<GLsizei>(c.count), |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6611 | 1); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6612 | } |
| 6613 | |
| 6614 | error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6615 | uint32 immediate_data_size, |
| 6616 | const void* cmd_data) { |
| 6617 | const gles2::cmds::DrawArraysInstancedANGLE& c = |
| 6618 | *static_cast<const gles2::cmds::DrawArraysInstancedANGLE*>(cmd_data); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6619 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6620 | LOCAL_SET_GL_ERROR( |
| 6621 | GL_INVALID_OPERATION, |
| 6622 | "glDrawArraysInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6623 | return error::kNoError; |
| 6624 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6625 | return DoDrawArrays("glDrawArraysIntancedANGLE", |
| 6626 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6627 | static_cast<GLenum>(c.mode), |
| 6628 | static_cast<GLint>(c.first), |
| 6629 | static_cast<GLsizei>(c.count), |
| 6630 | static_cast<GLsizei>(c.primcount)); |
| 6631 | } |
| 6632 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6633 | error::Error GLES2DecoderImpl::DoDrawElements( |
| 6634 | const char* function_name, |
| 6635 | bool instanced, |
| 6636 | GLenum mode, |
| 6637 | GLsizei count, |
| 6638 | GLenum type, |
| 6639 | int32 offset, |
| 6640 | GLsizei primcount) { |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 6641 | error::Error error = WillAccessBoundFramebufferForDraw(); |
| 6642 | if (error != error::kNoError) |
| 6643 | return error; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6644 | if (!state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6645 | LOCAL_SET_GL_ERROR( |
| 6646 | GL_INVALID_OPERATION, function_name, "No element array buffer bound"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6647 | return error::kNoError; |
| 6648 | } |
| 6649 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6650 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6651 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6652 | return error::kNoError; |
| 6653 | } |
| 6654 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6655 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6656 | return error::kNoError; |
| 6657 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6658 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6659 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6660 | return error::kNoError; |
| 6661 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6662 | if (!validators_->index_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6663 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6664 | return error::kNoError; |
| 6665 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6666 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6667 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6668 | return error::kNoError; |
| 6669 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6670 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6671 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 6672 | return error::kNoError; |
| 6673 | } |
| 6674 | |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6675 | if (count == 0 || primcount == 0) { |
[email protected] | 6c788fb7 | 2010-08-26 02:16:31 | [diff] [blame] | 6676 | return error::kNoError; |
| 6677 | } |
| 6678 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6679 | GLuint max_vertex_accessed; |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6680 | Buffer* element_array_buffer = |
| 6681 | state_.vertex_attrib_manager->element_array_buffer(); |
| 6682 | |
| 6683 | if (!element_array_buffer->GetMaxValueForRange( |
| 6684 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6685 | LOCAL_SET_GL_ERROR( |
| 6686 | GL_INVALID_OPERATION, function_name, "range out of bounds for buffer"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6687 | return error::kNoError; |
| 6688 | } |
| 6689 | |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6690 | if (IsDrawValid(function_name, max_vertex_accessed, instanced, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6691 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6692 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6693 | return error::kNoError; |
| 6694 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6695 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6696 | if (!SimulateAttrib0( |
| 6697 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6698 | return error::kNoError; |
| 6699 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6700 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6701 | if (SimulateFixedAttribs( |
| 6702 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 6703 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6704 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 6705 | ApplyDirtyState(); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6706 | // TODO(gman): Refactor to hide these details in BufferManager or |
| 6707 | // VertexAttribManager. |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6708 | const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6709 | bool used_client_side_array = false; |
| 6710 | if (element_array_buffer->IsClientSideArray()) { |
| 6711 | used_client_side_array = true; |
| 6712 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 6713 | indices = element_array_buffer->GetRange(offset, 0); |
| 6714 | } |
| 6715 | |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 6716 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6717 | if (!instanced) { |
| 6718 | glDrawElements(mode, count, type, indices); |
| 6719 | } else { |
| 6720 | glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); |
| 6721 | } |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6722 | |
| 6723 | if (used_client_side_array) { |
| 6724 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 6725 | element_array_buffer->service_id()); |
| 6726 | } |
| 6727 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6728 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6729 | RestoreStateForTextures(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6730 | } |
| 6731 | if (simulated_fixed_attribs) { |
| 6732 | RestoreStateForSimulatedFixedAttribs(); |
| 6733 | } |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 6734 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6735 | if (simulated_attrib_0) { |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 6736 | // We don't have to restore attrib 0 generic data at the end of this |
| 6737 | // function even if it is simulated. This is because we will simulate |
| 6738 | // it in each draw call, and attrib 0 generic data queries use cached |
| 6739 | // values instead of passing down to the underlying driver. |
| 6740 | RestoreStateForAttrib(0, false); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6741 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6742 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6743 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6744 | } |
| 6745 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6746 | error::Error GLES2DecoderImpl::HandleDrawElements(uint32 immediate_data_size, |
| 6747 | const void* cmd_data) { |
| 6748 | const gles2::cmds::DrawElements& c = |
| 6749 | *static_cast<const gles2::cmds::DrawElements*>(cmd_data); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6750 | return DoDrawElements("glDrawElements", |
| 6751 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6752 | static_cast<GLenum>(c.mode), |
| 6753 | static_cast<GLsizei>(c.count), |
| 6754 | static_cast<GLenum>(c.type), |
| 6755 | static_cast<int32>(c.index_offset), |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6756 | 1); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6757 | } |
| 6758 | |
| 6759 | error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6760 | uint32 immediate_data_size, |
| 6761 | const void* cmd_data) { |
| 6762 | const gles2::cmds::DrawElementsInstancedANGLE& c = |
| 6763 | *static_cast<const gles2::cmds::DrawElementsInstancedANGLE*>(cmd_data); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6764 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6765 | LOCAL_SET_GL_ERROR( |
| 6766 | GL_INVALID_OPERATION, |
| 6767 | "glDrawElementsInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6768 | return error::kNoError; |
| 6769 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6770 | return DoDrawElements("glDrawElementsInstancedANGLE", |
| 6771 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6772 | static_cast<GLenum>(c.mode), |
| 6773 | static_cast<GLsizei>(c.count), |
| 6774 | static_cast<GLenum>(c.type), |
| 6775 | static_cast<int32>(c.index_offset), |
| 6776 | static_cast<GLsizei>(c.primcount)); |
| 6777 | } |
| 6778 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 6779 | GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 6780 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { |
| 6781 | GLuint max_vertex_accessed = 0; |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 6782 | Buffer* buffer = GetBuffer(buffer_id); |
| 6783 | if (!buffer) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6784 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6785 | LOCAL_SET_GL_ERROR( |
| 6786 | GL_INVALID_VALUE, "GetMaxValueInBufferCHROMIUM", "unknown buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 6787 | } else { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 6788 | if (!buffer->GetMaxValueForRange( |
| 6789 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6790 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6791 | LOCAL_SET_GL_ERROR( |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 6792 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6793 | "GetMaxValueInBufferCHROMIUM", "range out of bounds for buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 6794 | } |
| 6795 | } |
| 6796 | return max_vertex_accessed; |
| 6797 | } |
| 6798 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6799 | // Calls glShaderSource for the various versions of the ShaderSource command. |
| 6800 | // Assumes that data / data_size points to a piece of memory that is in range |
| 6801 | // of whatever context it came from (shared memory, immediate memory, bucket |
| 6802 | // memory.) |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6803 | error::Error GLES2DecoderImpl::ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6804 | GLuint client_id, const char* data, uint32 data_size) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 6805 | std::string str(data, data + data_size); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6806 | Shader* shader = GetShaderInfoNotProgram(client_id, "glShaderSource"); |
| 6807 | if (!shader) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6808 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6809 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6810 | // Note: We don't actually call glShaderSource here. We wait until |
| 6811 | // the call to glCompileShader. |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6812 | shader->set_source(str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 6813 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6814 | } |
| 6815 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6816 | error::Error GLES2DecoderImpl::HandleShaderSourceBucket( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6817 | uint32 immediate_data_size, |
| 6818 | const void* cmd_data) { |
| 6819 | const gles2::cmds::ShaderSourceBucket& c = |
| 6820 | *static_cast<const gles2::cmds::ShaderSourceBucket*>(cmd_data); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6821 | Bucket* bucket = GetBucket(c.data_bucket_id); |
| 6822 | if (!bucket || bucket->size() == 0) { |
| 6823 | return error::kInvalidArguments; |
| 6824 | } |
| 6825 | return ShaderSourceHelper( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6826 | c.shader, bucket->GetDataAs<const char*>(0, bucket->size() - 1), |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 6827 | bucket->size() - 1); |
| 6828 | } |
| 6829 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6830 | void GLES2DecoderImpl::DoCompileShader(GLuint client_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 6831 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompileShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6832 | Shader* shader = GetShaderInfoNotProgram(client_id, "glCompileShader"); |
| 6833 | if (!shader) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6834 | return; |
| 6835 | } |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 6836 | ShaderTranslator* translator = NULL; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 6837 | if (use_shader_translator_) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6838 | translator = shader->shader_type() == GL_VERTEX_SHADER ? |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 6839 | vertex_translator_.get() : fragment_translator_.get(); |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 6840 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 6841 | |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6842 | shader->DoCompile( |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 6843 | translator, |
| 6844 | feature_info_->feature_flags().angle_translated_shader_source ? |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6845 | Shader::kANGLE : Shader::kGL); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 6846 | |
| 6847 | // CompileShader can be very slow. Exit command processing to allow for |
| 6848 | // context preemption and GPU watchdog checks. |
| 6849 | ExitCommandProcessingEarly(); |
| 6850 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6851 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6852 | void GLES2DecoderImpl::DoGetShaderiv( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6853 | GLuint shader_id, GLenum pname, GLint* params) { |
| 6854 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderiv"); |
| 6855 | if (!shader) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6856 | return; |
| 6857 | } |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6858 | switch (pname) { |
| 6859 | case GL_SHADER_SOURCE_LENGTH: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6860 | *params = shader->source().size(); |
| 6861 | if (*params) |
| 6862 | ++(*params); |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6863 | return; |
| 6864 | case GL_COMPILE_STATUS: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6865 | *params = compile_shader_always_succeeds_ ? true : shader->valid(); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 6866 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6867 | case GL_INFO_LOG_LENGTH: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6868 | *params = shader->log_info().size(); |
| 6869 | if (*params) |
| 6870 | ++(*params); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 6871 | return; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6872 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6873 | *params = shader->translated_source().size(); |
| 6874 | if (*params) |
| 6875 | ++(*params); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6876 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 6877 | default: |
| 6878 | break; |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6879 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6880 | glGetShaderiv(shader->service_id(), pname, params); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 6881 | } |
| 6882 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6883 | error::Error GLES2DecoderImpl::HandleGetShaderSource(uint32 immediate_data_size, |
| 6884 | const void* cmd_data) { |
| 6885 | const gles2::cmds::GetShaderSource& c = |
| 6886 | *static_cast<const gles2::cmds::GetShaderSource*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6887 | GLuint shader_id = c.shader; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6888 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6889 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6890 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderSource"); |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6891 | if (!shader || shader->source().empty()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6892 | bucket->SetSize(0); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6893 | return error::kNoError; |
| 6894 | } |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6895 | bucket->SetFromString(shader->source().c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6896 | return error::kNoError; |
| 6897 | } |
| 6898 | |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6899 | error::Error GLES2DecoderImpl::HandleGetTranslatedShaderSourceANGLE( |
| 6900 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6901 | const void* cmd_data) { |
| 6902 | const gles2::cmds::GetTranslatedShaderSourceANGLE& c = |
| 6903 | *static_cast<const gles2::cmds::GetTranslatedShaderSourceANGLE*>( |
| 6904 | cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6905 | GLuint shader_id = c.shader; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6906 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6907 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6908 | Shader* shader = GetShaderInfoNotProgram( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 6909 | shader_id, "glGetTranslatedShaderSourceANGLE"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6910 | if (!shader) { |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6911 | bucket->SetSize(0); |
| 6912 | return error::kNoError; |
| 6913 | } |
| 6914 | |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6915 | bucket->SetFromString(shader->translated_source().c_str()); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 6916 | return error::kNoError; |
| 6917 | } |
| 6918 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6919 | error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6920 | uint32 immediate_data_size, |
| 6921 | const void* cmd_data) { |
| 6922 | const gles2::cmds::GetProgramInfoLog& c = |
| 6923 | *static_cast<const gles2::cmds::GetProgramInfoLog*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6924 | GLuint program_id = c.program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6925 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6926 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6927 | Program* program = GetProgramInfoNotShader( |
| 6928 | program_id, "glGetProgramInfoLog"); |
| 6929 | if (!program || !program->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 6930 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6931 | return error::kNoError; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 6932 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6933 | bucket->SetFromString(program->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6934 | return error::kNoError; |
| 6935 | } |
| 6936 | |
| 6937 | error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6938 | uint32 immediate_data_size, |
| 6939 | const void* cmd_data) { |
| 6940 | const gles2::cmds::GetShaderInfoLog& c = |
| 6941 | *static_cast<const gles2::cmds::GetShaderInfoLog*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6942 | GLuint shader_id = c.shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6943 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 6944 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6945 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderInfoLog"); |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6946 | if (!shader) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 6947 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6948 | return error::kNoError; |
| 6949 | } |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 6950 | bucket->SetFromString(shader->log_info().c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6951 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 6952 | } |
| 6953 | |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 6954 | bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) { |
| 6955 | return state_.GetEnabled(cap); |
| 6956 | } |
| 6957 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6958 | bool GLES2DecoderImpl::DoIsBuffer(GLuint client_id) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 6959 | const Buffer* buffer = GetBuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6960 | return buffer && buffer->IsValid() && !buffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6961 | } |
| 6962 | |
| 6963 | bool GLES2DecoderImpl::DoIsFramebuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6964 | const Framebuffer* framebuffer = |
| 6965 | GetFramebuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6966 | return framebuffer && framebuffer->IsValid() && !framebuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6967 | } |
| 6968 | |
| 6969 | bool GLES2DecoderImpl::DoIsProgram(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 6970 | // IsProgram is true for programs as soon as they are created, until they are |
| 6971 | // deleted and no longer in use. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6972 | const Program* program = GetProgram(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6973 | return program != NULL && !program->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6974 | } |
| 6975 | |
| 6976 | bool GLES2DecoderImpl::DoIsRenderbuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6977 | const Renderbuffer* renderbuffer = |
| 6978 | GetRenderbuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6979 | return renderbuffer && renderbuffer->IsValid() && !renderbuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6980 | } |
| 6981 | |
| 6982 | bool GLES2DecoderImpl::DoIsShader(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 6983 | // IsShader is true for shaders as soon as they are created, until they |
| 6984 | // are deleted and not attached to any programs. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6985 | const Shader* shader = GetShader(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 6986 | return shader != NULL && !shader->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 6987 | } |
| 6988 | |
| 6989 | bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6990 | const TextureRef* texture_ref = GetTexture(client_id); |
| 6991 | return texture_ref && texture_ref->texture()->IsValid(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6992 | } |
| 6993 | |
| 6994 | void GLES2DecoderImpl::DoAttachShader( |
| 6995 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6996 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 6997 | program_client_id, "glAttachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6998 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6999 | return; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7000 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7001 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glAttachShader"); |
| 7002 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7003 | return; |
| 7004 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7005 | if (!program->AttachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7006 | LOCAL_SET_GL_ERROR( |
| 7007 | GL_INVALID_OPERATION, |
| 7008 | "glAttachShader", |
| 7009 | "can not attach more than one shader of the same type."); |
[email protected] | fb96c8e | 2010-08-12 04:10:31 | [diff] [blame] | 7010 | return; |
| 7011 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7012 | glAttachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7013 | } |
| 7014 | |
| 7015 | void GLES2DecoderImpl::DoDetachShader( |
| 7016 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7017 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7018 | program_client_id, "glDetachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7019 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7020 | return; |
| 7021 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7022 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glDetachShader"); |
| 7023 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7024 | return; |
| 7025 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7026 | if (!program->DetachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7027 | LOCAL_SET_GL_ERROR( |
| 7028 | GL_INVALID_OPERATION, |
| 7029 | "glDetachShader", "shader not attached to program"); |
[email protected] | 9a0ccd4 | 2011-03-16 23:58:22 | [diff] [blame] | 7030 | return; |
| 7031 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7032 | glDetachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7033 | } |
| 7034 | |
| 7035 | void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7036 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7037 | program_client_id, "glValidateProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7038 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7039 | return; |
| 7040 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7041 | program->Validate(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7042 | } |
| 7043 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7044 | void GLES2DecoderImpl::GetVertexAttribHelper( |
| 7045 | const VertexAttrib* attrib, GLenum pname, GLint* params) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7046 | switch (pname) { |
| 7047 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7048 | Buffer* buffer = attrib->buffer(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7049 | if (buffer && !buffer->IsDeleted()) { |
| 7050 | GLuint client_id; |
| 7051 | buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
| 7052 | *params = client_id; |
| 7053 | } |
| 7054 | break; |
| 7055 | } |
| 7056 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7057 | *params = attrib->enabled(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7058 | break; |
| 7059 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7060 | *params = attrib->size(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7061 | break; |
| 7062 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7063 | *params = attrib->gl_stride(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7064 | break; |
| 7065 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7066 | *params = attrib->type(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7067 | break; |
| 7068 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7069 | *params = attrib->normalized(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7070 | break; |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7071 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7072 | *params = attrib->divisor(); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7073 | break; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7074 | default: |
| 7075 | NOTREACHED(); |
| 7076 | break; |
| 7077 | } |
| 7078 | } |
| 7079 | |
[email protected] | 4c6f546 | 2014-03-05 00:26:56 | [diff] [blame] | 7080 | void GLES2DecoderImpl::DoGetTexParameterfv( |
| 7081 | GLenum target, GLenum pname, GLfloat* params) { |
| 7082 | InitTextureMaxAnisotropyIfNeeded(target, pname); |
| 7083 | glGetTexParameterfv(target, pname, params); |
| 7084 | } |
| 7085 | |
| 7086 | void GLES2DecoderImpl::DoGetTexParameteriv( |
| 7087 | GLenum target, GLenum pname, GLint* params) { |
| 7088 | InitTextureMaxAnisotropyIfNeeded(target, pname); |
| 7089 | glGetTexParameteriv(target, pname, params); |
| 7090 | } |
| 7091 | |
| 7092 | void GLES2DecoderImpl::InitTextureMaxAnisotropyIfNeeded( |
| 7093 | GLenum target, GLenum pname) { |
| 7094 | if (!workarounds().init_texture_max_anisotropy) |
| 7095 | return; |
| 7096 | if (pname != GL_TEXTURE_MAX_ANISOTROPY_EXT || |
| 7097 | !validators_->texture_parameter.IsValid(pname)) { |
| 7098 | return; |
| 7099 | } |
| 7100 | |
| 7101 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 7102 | &state_, target); |
| 7103 | if (!texture_ref) { |
| 7104 | LOCAL_SET_GL_ERROR( |
| 7105 | GL_INVALID_OPERATION, |
| 7106 | "glGetTexParamter{fi}v", "unknown texture for target"); |
| 7107 | return; |
| 7108 | } |
| 7109 | Texture* texture = texture_ref->texture(); |
| 7110 | texture->InitTextureMaxAnisotropyIfNeeded(target); |
| 7111 | } |
| 7112 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7113 | void GLES2DecoderImpl::DoGetVertexAttribfv( |
| 7114 | GLuint index, GLenum pname, GLfloat* params) { |
| 7115 | VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| 7116 | if (!attrib) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7117 | LOCAL_SET_GL_ERROR( |
| 7118 | GL_INVALID_VALUE, "glGetVertexAttribfv", "index out of range"); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7119 | return; |
| 7120 | } |
| 7121 | switch (pname) { |
| 7122 | case GL_CURRENT_VERTEX_ATTRIB: { |
| 7123 | const Vec4& value = state_.attrib_values[index]; |
| 7124 | params[0] = value.v[0]; |
| 7125 | params[1] = value.v[1]; |
| 7126 | params[2] = value.v[2]; |
| 7127 | params[3] = value.v[3]; |
| 7128 | break; |
| 7129 | } |
| 7130 | default: { |
| 7131 | GLint value = 0; |
| 7132 | GetVertexAttribHelper(attrib, pname, &value); |
| 7133 | *params = static_cast<GLfloat>(value); |
| 7134 | break; |
| 7135 | } |
| 7136 | } |
| 7137 | } |
| 7138 | |
| 7139 | void GLES2DecoderImpl::DoGetVertexAttribiv( |
| 7140 | GLuint index, GLenum pname, GLint* params) { |
| 7141 | VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| 7142 | if (!attrib) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7143 | LOCAL_SET_GL_ERROR( |
| 7144 | GL_INVALID_VALUE, "glGetVertexAttribiv", "index out of range"); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7145 | return; |
| 7146 | } |
| 7147 | switch (pname) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7148 | case GL_CURRENT_VERTEX_ATTRIB: { |
| 7149 | const Vec4& value = state_.attrib_values[index]; |
| 7150 | params[0] = static_cast<GLint>(value.v[0]); |
| 7151 | params[1] = static_cast<GLint>(value.v[1]); |
| 7152 | params[2] = static_cast<GLint>(value.v[2]); |
| 7153 | params[3] = static_cast<GLint>(value.v[3]); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7154 | break; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7155 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7156 | default: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7157 | GetVertexAttribHelper(attrib, pname, params); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7158 | break; |
| 7159 | } |
| 7160 | } |
| 7161 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7162 | bool GLES2DecoderImpl::SetVertexAttribValue( |
| 7163 | const char* function_name, GLuint index, const GLfloat* value) { |
| 7164 | if (index >= state_.attrib_values.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7165 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "index out of range"); |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7166 | return false; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7167 | } |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7168 | Vec4& v = state_.attrib_values[index]; |
| 7169 | v.v[0] = value[0]; |
| 7170 | v.v[1] = value[1]; |
| 7171 | v.v[2] = value[2]; |
| 7172 | v.v[3] = value[3]; |
| 7173 | return true; |
| 7174 | } |
| 7175 | |
| 7176 | void GLES2DecoderImpl::DoVertexAttrib1f(GLuint index, GLfloat v0) { |
| 7177 | GLfloat v[4] = { v0, 0.0f, 0.0f, 1.0f, }; |
| 7178 | if (SetVertexAttribValue("glVertexAttrib1f", index, v)) { |
| 7179 | glVertexAttrib1f(index, v0); |
| 7180 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | void GLES2DecoderImpl::DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7184 | GLfloat v[4] = { v0, v1, 0.0f, 1.0f, }; |
| 7185 | if (SetVertexAttribValue("glVertexAttrib2f", index, v)) { |
| 7186 | glVertexAttrib2f(index, v0, v1); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7187 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7188 | } |
| 7189 | |
| 7190 | void GLES2DecoderImpl::DoVertexAttrib3f( |
| 7191 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7192 | GLfloat v[4] = { v0, v1, v2, 1.0f, }; |
| 7193 | if (SetVertexAttribValue("glVertexAttrib3f", index, v)) { |
| 7194 | glVertexAttrib3f(index, v0, v1, v2); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7195 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7196 | } |
| 7197 | |
| 7198 | void GLES2DecoderImpl::DoVertexAttrib4f( |
| 7199 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7200 | GLfloat v[4] = { v0, v1, v2, v3, }; |
| 7201 | if (SetVertexAttribValue("glVertexAttrib4f", index, v)) { |
| 7202 | glVertexAttrib4f(index, v0, v1, v2, v3); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7203 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7204 | } |
| 7205 | |
| 7206 | void GLES2DecoderImpl::DoVertexAttrib1fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7207 | GLfloat t[4] = { v[0], 0.0f, 0.0f, 1.0f, }; |
| 7208 | if (SetVertexAttribValue("glVertexAttrib1fv", index, t)) { |
| 7209 | glVertexAttrib1fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7210 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7211 | } |
| 7212 | |
| 7213 | void GLES2DecoderImpl::DoVertexAttrib2fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7214 | GLfloat t[4] = { v[0], v[1], 0.0f, 1.0f, }; |
| 7215 | if (SetVertexAttribValue("glVertexAttrib2fv", index, t)) { |
| 7216 | glVertexAttrib2fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7217 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7218 | } |
| 7219 | |
| 7220 | void GLES2DecoderImpl::DoVertexAttrib3fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7221 | GLfloat t[4] = { v[0], v[1], v[2], 1.0f, }; |
| 7222 | if (SetVertexAttribValue("glVertexAttrib3fv", index, t)) { |
| 7223 | glVertexAttrib3fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7224 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7225 | } |
| 7226 | |
| 7227 | void GLES2DecoderImpl::DoVertexAttrib4fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7228 | if (SetVertexAttribValue("glVertexAttrib4fv", index, v)) { |
| 7229 | glVertexAttrib4fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7230 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7231 | } |
| 7232 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7233 | error::Error GLES2DecoderImpl::HandleVertexAttribPointer( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7234 | uint32 immediate_data_size, |
| 7235 | const void* cmd_data) { |
| 7236 | const gles2::cmds::VertexAttribPointer& c = |
| 7237 | *static_cast<const gles2::cmds::VertexAttribPointer*>(cmd_data); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 7238 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 7239 | if (!state_.bound_array_buffer.get() || |
| 7240 | state_.bound_array_buffer->IsDeleted()) { |
| 7241 | if (state_.vertex_attrib_manager.get() == |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 7242 | state_.default_vertex_attrib_manager.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7243 | LOCAL_SET_GL_ERROR( |
| 7244 | GL_INVALID_VALUE, "glVertexAttribPointer", "no array buffer bound"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 7245 | return error::kNoError; |
| 7246 | } else if (c.offset != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7247 | LOCAL_SET_GL_ERROR( |
| 7248 | GL_INVALID_VALUE, |
| 7249 | "glVertexAttribPointer", "client side arrays are not allowed"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 7250 | return error::kNoError; |
| 7251 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7252 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7253 | |
| 7254 | GLuint indx = c.indx; |
| 7255 | GLint size = c.size; |
| 7256 | GLenum type = c.type; |
| 7257 | GLboolean normalized = c.normalized; |
| 7258 | GLsizei stride = c.stride; |
| 7259 | GLsizei offset = c.offset; |
| 7260 | const void* ptr = reinterpret_cast<const void*>(offset); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7261 | if (!validators_->vertex_attrib_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7262 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glVertexAttribPointer", type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7263 | return error::kNoError; |
| 7264 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7265 | if (!validators_->vertex_attrib_size.IsValid(size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7266 | LOCAL_SET_GL_ERROR( |
| 7267 | GL_INVALID_VALUE, "glVertexAttribPointer", "size GL_INVALID_VALUE"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7268 | return error::kNoError; |
| 7269 | } |
| 7270 | if (indx >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7271 | LOCAL_SET_GL_ERROR( |
| 7272 | GL_INVALID_VALUE, "glVertexAttribPointer", "index out of range"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7273 | return error::kNoError; |
| 7274 | } |
| 7275 | if (stride < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7276 | LOCAL_SET_GL_ERROR( |
| 7277 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7278 | return error::kNoError; |
| 7279 | } |
| 7280 | if (stride > 255) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7281 | LOCAL_SET_GL_ERROR( |
| 7282 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride > 255"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7283 | return error::kNoError; |
| 7284 | } |
| 7285 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7286 | LOCAL_SET_GL_ERROR( |
| 7287 | GL_INVALID_VALUE, "glVertexAttribPointer", "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7288 | return error::kNoError; |
| 7289 | } |
| 7290 | GLsizei component_size = |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 7291 | GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type); |
[email protected] | a07a2360 | 2014-08-05 11:36:12 | [diff] [blame] | 7292 | // component_size must be a power of two to use & as optimized modulo. |
| 7293 | DCHECK(GLES2Util::IsPOT(component_size)); |
| 7294 | if (offset & (component_size - 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7295 | LOCAL_SET_GL_ERROR( |
| 7296 | GL_INVALID_OPERATION, |
| 7297 | "glVertexAttribPointer", "offset not valid for type"); |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 7298 | return error::kNoError; |
| 7299 | } |
[email protected] | a07a2360 | 2014-08-05 11:36:12 | [diff] [blame] | 7300 | if (stride & (component_size - 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7301 | LOCAL_SET_GL_ERROR( |
| 7302 | GL_INVALID_OPERATION, |
| 7303 | "glVertexAttribPointer", "stride not valid for type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7304 | return error::kNoError; |
| 7305 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 7306 | state_.vertex_attrib_manager |
| 7307 | ->SetAttribInfo(indx, |
| 7308 | state_.bound_array_buffer.get(), |
| 7309 | size, |
| 7310 | type, |
| 7311 | normalized, |
| 7312 | stride, |
| 7313 | stride != 0 ? stride : component_size * size, |
| 7314 | offset); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7315 | if (type != GL_FIXED) { |
| 7316 | glVertexAttribPointer(indx, size, type, normalized, stride, ptr); |
| 7317 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7318 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7319 | } |
| 7320 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 7321 | void GLES2DecoderImpl::DoViewport(GLint x, GLint y, GLsizei width, |
| 7322 | GLsizei height) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7323 | state_.viewport_x = x; |
| 7324 | state_.viewport_y = y; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 7325 | state_.viewport_width = std::min(width, viewport_max_width_); |
| 7326 | state_.viewport_height = std::min(height, viewport_max_height_); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 7327 | glViewport(x, y, width, height); |
| 7328 | } |
| 7329 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7330 | error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7331 | uint32 immediate_data_size, |
| 7332 | const void* cmd_data) { |
| 7333 | const gles2::cmds::VertexAttribDivisorANGLE& c = |
| 7334 | *static_cast<const gles2::cmds::VertexAttribDivisorANGLE*>(cmd_data); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 7335 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7336 | LOCAL_SET_GL_ERROR( |
| 7337 | GL_INVALID_OPERATION, |
| 7338 | "glVertexAttribDivisorANGLE", "function not available"); |
[email protected] | cedee33 | 2014-05-23 07:07:53 | [diff] [blame] | 7339 | return error::kNoError; |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7340 | } |
| 7341 | GLuint index = c.index; |
| 7342 | GLuint divisor = c.divisor; |
| 7343 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7344 | LOCAL_SET_GL_ERROR( |
| 7345 | GL_INVALID_VALUE, |
| 7346 | "glVertexAttribDivisorANGLE", "index out of range"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7347 | return error::kNoError; |
| 7348 | } |
| 7349 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7350 | state_.vertex_attrib_manager->SetDivisor( |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7351 | index, |
| 7352 | divisor); |
| 7353 | glVertexAttribDivisorANGLE(index, divisor); |
| 7354 | return error::kNoError; |
| 7355 | } |
| 7356 | |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7357 | template <typename pixel_data_type> |
| 7358 | static void WriteAlphaData( |
| 7359 | void *pixels, uint32 row_count, uint32 channel_count, |
| 7360 | uint32 alpha_channel_index, uint32 unpadded_row_size, |
| 7361 | uint32 padded_row_size, pixel_data_type alpha_value) { |
| 7362 | DCHECK_GT(channel_count, 0U); |
| 7363 | DCHECK_EQ(unpadded_row_size % sizeof(pixel_data_type), 0U); |
| 7364 | uint32 unpadded_row_size_in_elements = |
| 7365 | unpadded_row_size / sizeof(pixel_data_type); |
| 7366 | DCHECK_EQ(padded_row_size % sizeof(pixel_data_type), 0U); |
| 7367 | uint32 padded_row_size_in_elements = |
| 7368 | padded_row_size / sizeof(pixel_data_type); |
| 7369 | pixel_data_type* dst = |
| 7370 | static_cast<pixel_data_type*>(pixels) + alpha_channel_index; |
| 7371 | for (uint32 yy = 0; yy < row_count; ++yy) { |
| 7372 | pixel_data_type* end = dst + unpadded_row_size_in_elements; |
| 7373 | for (pixel_data_type* d = dst; d < end; d += channel_count) { |
| 7374 | *d = alpha_value; |
| 7375 | } |
| 7376 | dst += padded_row_size_in_elements; |
| 7377 | } |
| 7378 | } |
| 7379 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7380 | void GLES2DecoderImpl::FinishReadPixels( |
| 7381 | const cmds::ReadPixels& c, |
| 7382 | GLuint buffer) { |
| 7383 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::FinishReadPixels"); |
| 7384 | GLsizei width = c.width; |
| 7385 | GLsizei height = c.height; |
| 7386 | GLenum format = c.format; |
| 7387 | GLenum type = c.type; |
| 7388 | typedef cmds::ReadPixels::Result Result; |
| 7389 | uint32 pixels_size; |
| 7390 | Result* result = NULL; |
| 7391 | if (c.result_shm_id != 0) { |
| 7392 | result = GetSharedMemoryAs<Result*>( |
| 7393 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7394 | if (!result) { |
| 7395 | if (buffer != 0) { |
| 7396 | glDeleteBuffersARB(1, &buffer); |
| 7397 | } |
| 7398 | return; |
| 7399 | } |
| 7400 | } |
| 7401 | GLES2Util::ComputeImageDataSizes( |
| 7402 | width, height, format, type, state_.pack_alignment, &pixels_size, |
| 7403 | NULL, NULL); |
| 7404 | void* pixels = GetSharedMemoryAs<void*>( |
| 7405 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| 7406 | if (!pixels) { |
| 7407 | if (buffer != 0) { |
| 7408 | glDeleteBuffersARB(1, &buffer); |
| 7409 | } |
| 7410 | return; |
| 7411 | } |
| 7412 | |
| 7413 | if (buffer != 0) { |
| 7414 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
[email protected] | e585f9e2 | 2013-08-27 02:50:33 | [diff] [blame] | 7415 | void* data; |
| 7416 | if (features().map_buffer_range) { |
| 7417 | data = glMapBufferRange( |
| 7418 | GL_PIXEL_PACK_BUFFER_ARB, 0, pixels_size, GL_MAP_READ_BIT); |
| 7419 | } else { |
| 7420 | data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); |
| 7421 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7422 | memcpy(pixels, data, pixels_size); |
| 7423 | // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't |
| 7424 | // have to restore the state. |
| 7425 | glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); |
| 7426 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7427 | glDeleteBuffersARB(1, &buffer); |
| 7428 | } |
| 7429 | |
| 7430 | if (result != NULL) { |
| 7431 | *result = true; |
| 7432 | } |
| 7433 | |
| 7434 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 7435 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 7436 | if ((channels_exist & 0x0008) == 0 && |
| 7437 | workarounds().clear_alpha_in_readpixels) { |
| 7438 | // Set the alpha to 255 because some drivers are buggy in this regard. |
| 7439 | uint32 temp_size; |
| 7440 | |
| 7441 | uint32 unpadded_row_size; |
| 7442 | uint32 padded_row_size; |
| 7443 | if (!GLES2Util::ComputeImageDataSizes( |
| 7444 | width, 2, format, type, state_.pack_alignment, &temp_size, |
| 7445 | &unpadded_row_size, &padded_row_size)) { |
| 7446 | return; |
| 7447 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7448 | |
| 7449 | uint32 channel_count = 0; |
| 7450 | uint32 alpha_channel = 0; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7451 | switch (format) { |
| 7452 | case GL_RGBA: |
| 7453 | case GL_BGRA_EXT: |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7454 | channel_count = 4; |
| 7455 | alpha_channel = 3; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7456 | break; |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7457 | case GL_ALPHA: |
| 7458 | channel_count = 1; |
| 7459 | alpha_channel = 0; |
| 7460 | break; |
| 7461 | } |
| 7462 | |
| 7463 | if (channel_count > 0) { |
| 7464 | switch (type) { |
| 7465 | case GL_UNSIGNED_BYTE: |
| 7466 | WriteAlphaData<uint8>( |
| 7467 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 7468 | padded_row_size, 0xFF); |
| 7469 | break; |
| 7470 | case GL_FLOAT: |
| 7471 | WriteAlphaData<float>( |
| 7472 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 7473 | padded_row_size, 1.0f); |
| 7474 | break; |
| 7475 | case GL_HALF_FLOAT: |
| 7476 | WriteAlphaData<uint16>( |
| 7477 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 7478 | padded_row_size, 0x3C00); |
| 7479 | break; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7480 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7481 | } |
| 7482 | } |
| 7483 | } |
| 7484 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7485 | error::Error GLES2DecoderImpl::HandleReadPixels(uint32 immediate_data_size, |
| 7486 | const void* cmd_data) { |
| 7487 | const gles2::cmds::ReadPixels& c = |
| 7488 | *static_cast<const gles2::cmds::ReadPixels*>(cmd_data); |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 7489 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleReadPixels"); |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 7490 | error::Error fbo_error = WillAccessBoundFramebufferForRead(); |
| 7491 | if (fbo_error != error::kNoError) |
| 7492 | return fbo_error; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7493 | GLint x = c.x; |
| 7494 | GLint y = c.y; |
| 7495 | GLsizei width = c.width; |
| 7496 | GLsizei height = c.height; |
| 7497 | GLenum format = c.format; |
| 7498 | GLenum type = c.type; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7499 | GLboolean async = c.async; |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7500 | if (width < 0 || height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7501 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7502 | return error::kNoError; |
| 7503 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7504 | typedef cmds::ReadPixels::Result Result; |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7505 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7506 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7507 | width, height, format, type, state_.pack_alignment, &pixels_size, |
| 7508 | NULL, NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7509 | return error::kOutOfBounds; |
| 7510 | } |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7511 | void* pixels = GetSharedMemoryAs<void*>( |
| 7512 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7513 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7514 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7515 | } |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7516 | Result* result = NULL; |
| 7517 | if (c.result_shm_id != 0) { |
| 7518 | result = GetSharedMemoryAs<Result*>( |
| 7519 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7520 | if (!result) { |
| 7521 | return error::kOutOfBounds; |
| 7522 | } |
| 7523 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7524 | |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7525 | if (!validators_->read_pixel_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7526 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", format, "format"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7527 | return error::kNoError; |
| 7528 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7529 | if (!validators_->read_pixel_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7530 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", type, "type"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 7531 | return error::kNoError; |
| 7532 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7533 | if ((format != GL_RGBA && format != GL_BGRA_EXT && format != GL_RGB && |
| 7534 | format != GL_ALPHA) || type != GL_UNSIGNED_BYTE) { |
| 7535 | // format and type are acceptable enums but not guaranteed to be supported |
| 7536 | // for this framebuffer. Have to ask gl if they are valid. |
| 7537 | GLint preferred_format = 0; |
| 7538 | DoGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &preferred_format); |
| 7539 | GLint preferred_type = 0; |
| 7540 | DoGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &preferred_type); |
| 7541 | if (format != static_cast<GLenum>(preferred_format) || |
| 7542 | type != static_cast<GLenum>(preferred_type)) { |
| 7543 | LOCAL_SET_GL_ERROR( |
| 7544 | GL_INVALID_OPERATION, "glReadPixels", "format and type incompatible " |
| 7545 | "with the current read framebuffer"); |
| 7546 | return error::kNoError; |
| 7547 | } |
| 7548 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7549 | if (width == 0 || height == 0) { |
| 7550 | return error::kNoError; |
| 7551 | } |
| 7552 | |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7553 | // Get the size of the current fbo or backbuffer. |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 7554 | gfx::Size max_size = GetBoundReadFrameBufferSize(); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7555 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 7556 | int32 max_x; |
| 7557 | int32 max_y; |
| 7558 | if (!SafeAddInt32(x, width, &max_x) || !SafeAddInt32(y, height, &max_y)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7559 | LOCAL_SET_GL_ERROR( |
| 7560 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7561 | return error::kNoError; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7562 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7563 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 7564 | if (!CheckBoundReadFramebufferColorAttachment("glReadPixels")) { |
| 7565 | return error::kNoError; |
| 7566 | } |
| 7567 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7568 | if (!CheckBoundFramebuffersValid("glReadPixels")) { |
| 7569 | return error::kNoError; |
| 7570 | } |
| 7571 | |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7572 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7573 | |
| 7574 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 7575 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7576 | 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] | 7577 | // The user requested an out of range area. Get the results 1 line |
| 7578 | // at a time. |
| 7579 | uint32 temp_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7580 | uint32 unpadded_row_size; |
| 7581 | uint32 padded_row_size; |
| 7582 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7583 | width, 2, format, type, state_.pack_alignment, &temp_size, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7584 | &unpadded_row_size, &padded_row_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7585 | LOCAL_SET_GL_ERROR( |
| 7586 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7587 | return error::kNoError; |
| 7588 | } |
| 7589 | |
| 7590 | GLint dest_x_offset = std::max(-x, 0); |
| 7591 | uint32 dest_row_offset; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7592 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7593 | dest_x_offset, 1, format, type, state_.pack_alignment, &dest_row_offset, |
| 7594 | NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7595 | LOCAL_SET_GL_ERROR( |
| 7596 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7597 | return error::kNoError; |
| 7598 | } |
| 7599 | |
| 7600 | // Copy each row into the larger dest rect. |
| 7601 | int8* dst = static_cast<int8*>(pixels); |
| 7602 | GLint read_x = std::max(0, x); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7603 | 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] | 7604 | GLint read_width = read_end_x - read_x; |
| 7605 | for (GLint yy = 0; yy < height; ++yy) { |
| 7606 | GLint ry = y + yy; |
| 7607 | |
| 7608 | // Clear the row. |
| 7609 | memset(dst, 0, unpadded_row_size); |
| 7610 | |
| 7611 | // If the row is in range, copy it. |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7612 | if (ry >= 0 && ry < max_size.height() && read_width > 0) { |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7613 | glReadPixels( |
| 7614 | read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
| 7615 | } |
| 7616 | dst += padded_row_size; |
| 7617 | } |
| 7618 | } else { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7619 | if (async && features().use_async_readpixels) { |
| 7620 | GLuint buffer; |
| 7621 | glGenBuffersARB(1, &buffer); |
| 7622 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
| 7623 | glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, GL_STREAM_READ); |
| 7624 | GLenum error = glGetError(); |
| 7625 | if (error == GL_NO_ERROR) { |
| 7626 | glReadPixels(x, y, width, height, format, type, 0); |
| 7627 | pending_readpixel_fences_.push(linked_ptr<FenceCallback>( |
| 7628 | new FenceCallback())); |
| 7629 | WaitForReadPixels(base::Bind( |
| 7630 | &GLES2DecoderImpl::FinishReadPixels, |
| 7631 | base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 7632 | <GLES2DecoderImpl>(this), |
| 7633 | c, buffer)); |
| 7634 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7635 | return error::kNoError; |
[email protected] | 77bfe744 | 2014-03-01 02:42:59 | [diff] [blame] | 7636 | } else { |
| 7637 | // On error, unbind pack buffer and fall through to sync readpixels |
| 7638 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7639 | } |
| 7640 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7641 | glReadPixels(x, y, width, height, format, type, pixels); |
| 7642 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7643 | GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7644 | if (error == GL_NO_ERROR) { |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7645 | if (result != NULL) { |
| 7646 | *result = true; |
| 7647 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7648 | FinishReadPixels(c, 0); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7649 | } |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 7650 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7651 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7652 | } |
| 7653 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7654 | error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, |
| 7655 | const void* cmd_data) { |
| 7656 | const gles2::cmds::PixelStorei& c = |
| 7657 | *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7658 | GLenum pname = c.pname; |
| 7659 | GLenum param = c.param; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7660 | if (!validators_->pixel_store.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7661 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glPixelStorei", pname, "pname"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 7662 | return error::kNoError; |
| 7663 | } |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7664 | switch (pname) { |
| 7665 | case GL_PACK_ALIGNMENT: |
| 7666 | case GL_UNPACK_ALIGNMENT: |
| 7667 | if (!validators_->pixel_store_alignment.IsValid(param)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7668 | LOCAL_SET_GL_ERROR( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7669 | GL_INVALID_VALUE, "glPixelStorei", "param GL_INVALID_VALUE"); |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7670 | return error::kNoError; |
| 7671 | } |
[email protected] | 164d6d5 | 2012-05-05 00:55:03 | [diff] [blame] | 7672 | break; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 7673 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 7674 | unpack_flip_y_ = (param != 0); |
| 7675 | return error::kNoError; |
| 7676 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 7677 | unpack_premultiply_alpha_ = (param != 0); |
| 7678 | return error::kNoError; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 7679 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 7680 | unpack_unpremultiply_alpha_ = (param != 0); |
| 7681 | return error::kNoError; |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7682 | default: |
| 7683 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7684 | } |
| 7685 | glPixelStorei(pname, param); |
| 7686 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7687 | case GL_PACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7688 | state_.pack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7689 | break; |
| 7690 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 7691 | state_.pack_reverse_row_order = (param != 0); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7692 | break; |
| 7693 | case GL_UNPACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7694 | state_.unpack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7695 | break; |
| 7696 | default: |
| 7697 | // Validation should have prevented us from getting here. |
| 7698 | NOTREACHED(); |
| 7699 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7700 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7701 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7702 | } |
| 7703 | |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7704 | error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7705 | uint32 immediate_data_size, |
| 7706 | const void* cmd_data) { |
| 7707 | const gles2::cmds::PostSubBufferCHROMIUM& c = |
| 7708 | *static_cast<const gles2::cmds::PostSubBufferCHROMIUM*>(cmd_data); |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 7709 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandlePostSubBufferCHROMIUM"); |
[email protected] | a36ed483 | 2014-04-24 16:40:27 | [diff] [blame] | 7710 | { |
| 7711 | TRACE_EVENT_SYNTHETIC_DELAY("gpu.PresentingFrame"); |
| 7712 | } |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 7713 | if (!supports_post_sub_buffer_) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7714 | LOCAL_SET_GL_ERROR( |
| 7715 | GL_INVALID_OPERATION, |
| 7716 | "glPostSubBufferCHROMIUM", "command not supported by surface"); |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7717 | return error::kNoError; |
| 7718 | } |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 7719 | bool is_tracing; |
| 7720 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 7721 | &is_tracing); |
| 7722 | if (is_tracing) { |
| 7723 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 7724 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 7725 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 7726 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 7727 | } |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 7728 | if (surface_->PostSubBuffer(c.x, c.y, c.width, c.height)) { |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7729 | return error::kNoError; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 7730 | } else { |
| 7731 | LOG(ERROR) << "Context lost because PostSubBuffer failed."; |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7732 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 7733 | } |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7734 | } |
| 7735 | |
[email protected] | 957f064 | 2014-04-09 16:50:01 | [diff] [blame] | 7736 | error::Error GLES2DecoderImpl::HandleScheduleOverlayPlaneCHROMIUM( |
| 7737 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7738 | const void* cmd_data) { |
| 7739 | const gles2::cmds::ScheduleOverlayPlaneCHROMIUM& c = |
| 7740 | *static_cast<const gles2::cmds::ScheduleOverlayPlaneCHROMIUM*>(cmd_data); |
[email protected] | d286ebbc | 2014-07-03 17:19:10 | [diff] [blame] | 7741 | TextureRef* ref = texture_manager()->GetTexture(c.overlay_texture_id); |
| 7742 | if (!ref) { |
| 7743 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 7744 | "glScheduleOverlayPlaneCHROMIUM", |
| 7745 | "unknown texture"); |
| 7746 | return error::kNoError; |
| 7747 | } |
| 7748 | gfx::GLImage* image = |
| 7749 | ref->texture()->GetLevelImage(ref->texture()->target(), 0); |
| 7750 | if (!image) { |
| 7751 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 7752 | "glScheduleOverlayPlaneCHROMIUM", |
| 7753 | "unsupported texture format"); |
| 7754 | return error::kNoError; |
| 7755 | } |
| 7756 | gfx::OverlayTransform transform = GetGFXOverlayTransform(c.plane_transform); |
| 7757 | if (transform == gfx::OVERLAY_TRANSFORM_INVALID) { |
| 7758 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, |
| 7759 | "glScheduleOverlayPlaneCHROMIUM", |
| 7760 | "invalid transform enum"); |
| 7761 | return error::kNoError; |
| 7762 | } |
| 7763 | if (!surface_->ScheduleOverlayPlane( |
| 7764 | c.plane_z_order, |
| 7765 | transform, |
| 7766 | image, |
| 7767 | gfx::Rect(c.bounds_x, c.bounds_y, c.bounds_width, c.bounds_height), |
| 7768 | gfx::RectF(c.uv_x, c.uv_y, c.uv_width, c.uv_height))) { |
| 7769 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 7770 | "glScheduleOverlayPlaneCHROMIUM", |
| 7771 | "failed to schedule overlay"); |
| 7772 | } |
[email protected] | 957f064 | 2014-04-09 16:50:01 | [diff] [blame] | 7773 | return error::kNoError; |
| 7774 | } |
| 7775 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7776 | error::Error GLES2DecoderImpl::GetAttribLocationHelper( |
| 7777 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 7778 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7779 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7780 | LOCAL_SET_GL_ERROR( |
| 7781 | GL_INVALID_VALUE, "glGetAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7782 | return error::kNoError; |
| 7783 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7784 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7785 | client_id, "glGetAttribLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7786 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7787 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7788 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7789 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7790 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7791 | GL_INVALID_OPERATION, "glGetAttribLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7792 | return error::kNoError; |
| 7793 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7794 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7795 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 7796 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7797 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7798 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7799 | // Require the client to init this incase the context is lost and we are no |
| 7800 | // longer executing commands. |
| 7801 | if (*location != -1) { |
| 7802 | return error::kGenericError; |
| 7803 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7804 | *location = program->GetAttribLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7805 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7806 | } |
| 7807 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7808 | error::Error GLES2DecoderImpl::HandleGetAttribLocation( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7809 | uint32 immediate_data_size, |
| 7810 | const void* cmd_data) { |
| 7811 | const gles2::cmds::GetAttribLocation& c = |
| 7812 | *static_cast<const gles2::cmds::GetAttribLocation*>(cmd_data); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7813 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 7814 | if (!bucket) { |
| 7815 | return error::kInvalidArguments; |
| 7816 | } |
| 7817 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7818 | if (!bucket->GetAsString(&name_str)) { |
| 7819 | return error::kInvalidArguments; |
| 7820 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7821 | return GetAttribLocationHelper( |
| 7822 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 7823 | } |
| 7824 | |
| 7825 | error::Error GLES2DecoderImpl::GetUniformLocationHelper( |
| 7826 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 7827 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7828 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7829 | LOCAL_SET_GL_ERROR( |
| 7830 | GL_INVALID_VALUE, "glGetUniformLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 7831 | return error::kNoError; |
| 7832 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7833 | Program* program = GetProgramInfoNotShader( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7834 | client_id, "glGetUniformLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7835 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7836 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7837 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7838 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7839 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7840 | GL_INVALID_OPERATION, "glGetUniformLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 7841 | return error::kNoError; |
| 7842 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7843 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7844 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 7845 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7846 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7847 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7848 | // Require the client to init this incase the context is lost an we are no |
| 7849 | // longer executing commands. |
| 7850 | if (*location != -1) { |
| 7851 | return error::kGenericError; |
| 7852 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7853 | *location = program->GetUniformFakeLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7854 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7855 | } |
| 7856 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7857 | error::Error GLES2DecoderImpl::HandleGetUniformLocation( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7858 | uint32 immediate_data_size, |
| 7859 | const void* cmd_data) { |
| 7860 | const gles2::cmds::GetUniformLocation& c = |
| 7861 | *static_cast<const gles2::cmds::GetUniformLocation*>(cmd_data); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7862 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 7863 | if (!bucket) { |
| 7864 | return error::kInvalidArguments; |
| 7865 | } |
| 7866 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7867 | if (!bucket->GetAsString(&name_str)) { |
| 7868 | return error::kInvalidArguments; |
| 7869 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7870 | return GetUniformLocationHelper( |
| 7871 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7872 | } |
| 7873 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7874 | error::Error GLES2DecoderImpl::HandleGetString(uint32 immediate_data_size, |
| 7875 | const void* cmd_data) { |
| 7876 | const gles2::cmds::GetString& c = |
| 7877 | *static_cast<const gles2::cmds::GetString*>(cmd_data); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7878 | GLenum name = static_cast<GLenum>(c.name); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7879 | if (!validators_->string_type.IsValid(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7880 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glGetString", name, "name"); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7881 | return error::kNoError; |
| 7882 | } |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 7883 | const char* str = reinterpret_cast<const char*>(glGetString(name)); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7884 | std::string extensions; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7885 | switch (name) { |
| 7886 | case GL_VERSION: |
| 7887 | str = "OpenGL ES 2.0 Chromium"; |
| 7888 | break; |
| 7889 | case GL_SHADING_LANGUAGE_VERSION: |
| 7890 | str = "OpenGL ES GLSL ES 1.0 Chromium"; |
| 7891 | break; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 7892 | case GL_RENDERER: |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 7893 | case GL_VENDOR: |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 7894 | // Return the unmasked VENDOR/RENDERER string for WebGL contexts. |
| 7895 | // They are used by WEBGL_debug_renderer_info. |
| 7896 | if (!force_webgl_glsl_validation_) |
| 7897 | str = "Chromium"; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 7898 | break; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7899 | case GL_EXTENSIONS: |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7900 | { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7901 | // For WebGL contexts, strip out the OES derivatives and |
| 7902 | // EXT frag depth extensions if they have not been enabled. |
| 7903 | if (force_webgl_glsl_validation_) { |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7904 | extensions = feature_info_->extensions(); |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7905 | if (!derivatives_explicitly_enabled_) { |
| 7906 | size_t offset = extensions.find(kOESDerivativeExtension); |
| 7907 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 7908 | extensions.replace(offset, arraysize(kOESDerivativeExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7909 | std::string()); |
| 7910 | } |
| 7911 | } |
| 7912 | if (!frag_depth_explicitly_enabled_) { |
| 7913 | size_t offset = extensions.find(kEXTFragDepthExtension); |
| 7914 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 7915 | extensions.replace(offset, arraysize(kEXTFragDepthExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 7916 | std::string()); |
| 7917 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7918 | } |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 7919 | if (!draw_buffers_explicitly_enabled_) { |
| 7920 | size_t offset = extensions.find(kEXTDrawBuffersExtension); |
| 7921 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 7922 | extensions.replace(offset, arraysize(kEXTDrawBuffersExtension), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 7923 | std::string()); |
| 7924 | } |
| 7925 | } |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 7926 | if (!shader_texture_lod_explicitly_enabled_) { |
| 7927 | size_t offset = extensions.find(kEXTShaderTextureLodExtension); |
| 7928 | if (std::string::npos != offset) { |
| 7929 | extensions.replace(offset, |
| 7930 | arraysize(kEXTShaderTextureLodExtension), |
| 7931 | std::string()); |
| 7932 | } |
| 7933 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7934 | } else { |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 7935 | extensions = feature_info_->extensions().c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7936 | } |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 7937 | if (supports_post_sub_buffer_) |
| 7938 | extensions += " GL_CHROMIUM_post_sub_buffer"; |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 7939 | str = extensions.c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 7940 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7941 | break; |
| 7942 | default: |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7943 | break; |
| 7944 | } |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7945 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7946 | bucket->SetFromString(str); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7947 | return error::kNoError; |
| 7948 | } |
| 7949 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7950 | error::Error GLES2DecoderImpl::HandleBufferData(uint32 immediate_data_size, |
| 7951 | const void* cmd_data) { |
| 7952 | const gles2::cmds::BufferData& c = |
| 7953 | *static_cast<const gles2::cmds::BufferData*>(cmd_data); |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 7954 | GLenum target = static_cast<GLenum>(c.target); |
| 7955 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
| 7956 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 7957 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 7958 | GLenum usage = static_cast<GLenum>(c.usage); |
| 7959 | const void* data = NULL; |
| 7960 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 7961 | data = GetSharedMemoryAs<const void*>(data_shm_id, data_shm_offset, size); |
| 7962 | if (!data) { |
| 7963 | return error::kOutOfBounds; |
| 7964 | } |
| 7965 | } |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 7966 | buffer_manager()->ValidateAndDoBufferData(&state_, target, size, data, usage); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7967 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7968 | } |
| 7969 | |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 7970 | void GLES2DecoderImpl::DoBufferSubData( |
| 7971 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 7972 | // Just delegate it. Some validation is actually done before this. |
| 7973 | buffer_manager()->ValidateAndDoBufferSubData( |
| 7974 | &state_, target, offset, size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7975 | } |
| 7976 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7977 | bool GLES2DecoderImpl::ClearLevel( |
| 7978 | unsigned service_id, |
| 7979 | unsigned bind_target, |
| 7980 | unsigned target, |
| 7981 | int level, |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 7982 | unsigned internal_format, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7983 | unsigned format, |
| 7984 | unsigned type, |
| 7985 | int width, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 7986 | int height, |
| 7987 | bool is_texture_immutable) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7988 | uint32 channels = GLES2Util::GetChannelsForFormat(format); |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 7989 | if (feature_info_->feature_flags().angle_depth_texture && |
| 7990 | (channels & GLES2Util::kDepth) != 0) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 7991 | // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D |
| 7992 | // on depth formats. |
| 7993 | GLuint fb = 0; |
| 7994 | glGenFramebuffersEXT(1, &fb); |
| 7995 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); |
| 7996 | |
| 7997 | bool have_stencil = (channels & GLES2Util::kStencil) != 0; |
| 7998 | GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : |
| 7999 | GL_DEPTH_ATTACHMENT; |
| 8000 | |
| 8001 | glFramebufferTexture2DEXT( |
| 8002 | GL_DRAW_FRAMEBUFFER_EXT, attachment, target, service_id, level); |
| 8003 | // ANGLE promises a depth only attachment ok. |
| 8004 | if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != |
| 8005 | GL_FRAMEBUFFER_COMPLETE) { |
| 8006 | return false; |
| 8007 | } |
| 8008 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 8009 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 8010 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8011 | glClearDepth(1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 8012 | state_.SetDeviceDepthMask(GL_TRUE); |
| 8013 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8014 | glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); |
| 8015 | |
| 8016 | RestoreClearState(); |
| 8017 | |
| 8018 | glDeleteFramebuffersEXT(1, &fb); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8019 | Framebuffer* framebuffer = |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8020 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 8021 | GLuint fb_service_id = |
| 8022 | framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); |
| 8023 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); |
| 8024 | return true; |
| 8025 | } |
| 8026 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8027 | static const uint32 kMaxZeroSize = 1024 * 1024 * 4; |
| 8028 | |
| 8029 | uint32 size; |
| 8030 | uint32 padded_row_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8031 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8032 | width, height, format, type, state_.unpack_alignment, &size, |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8033 | NULL, &padded_row_size)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8034 | return false; |
| 8035 | } |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8036 | |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 8037 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearLevel", "size", size); |
| 8038 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8039 | int tile_height; |
| 8040 | |
| 8041 | if (size > kMaxZeroSize) { |
| 8042 | if (kMaxZeroSize < padded_row_size) { |
| 8043 | // That'd be an awfully large texture. |
| 8044 | return false; |
| 8045 | } |
| 8046 | // We should never have a large total size with a zero row size. |
| 8047 | DCHECK_GT(padded_row_size, 0U); |
| 8048 | tile_height = kMaxZeroSize / padded_row_size; |
| 8049 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8050 | width, tile_height, format, type, state_.unpack_alignment, &size, |
| 8051 | NULL, NULL)) { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8052 | return false; |
| 8053 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8054 | } else { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8055 | tile_height = height; |
| 8056 | } |
| 8057 | |
| 8058 | // Assumes the size has already been checked. |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8059 | scoped_ptr<char[]> zero(new char[size]); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8060 | memset(zero.get(), 0, size); |
| 8061 | glBindTexture(bind_target, service_id); |
| 8062 | |
| 8063 | GLint y = 0; |
| 8064 | while (y < height) { |
| 8065 | GLint h = y + tile_height > height ? height - y : tile_height; |
| 8066 | if (is_texture_immutable || h != height) { |
| 8067 | glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); |
| 8068 | } else { |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 8069 | glTexImage2D( |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 8070 | target, level, internal_format, width, h, 0, format, type, |
| 8071 | zero.get()); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8072 | } |
| 8073 | y += tile_height; |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8074 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8075 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 8076 | &state_, bind_target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8077 | glBindTexture(bind_target, texture ? texture->service_id() : 0); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8078 | return true; |
| 8079 | } |
| 8080 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8081 | namespace { |
| 8082 | |
| 8083 | const int kS3TCBlockWidth = 4; |
| 8084 | const int kS3TCBlockHeight = 4; |
| 8085 | const int kS3TCDXT1BlockSize = 8; |
| 8086 | const int kS3TCDXT3AndDXT5BlockSize = 16; |
| 8087 | |
| 8088 | bool IsValidDXTSize(GLint level, GLsizei size) { |
[email protected] | 10b56de | 2012-07-14 02:09:51 | [diff] [blame] | 8089 | return (size == 1) || |
| 8090 | (size == 2) || !(size % kS3TCBlockWidth); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8091 | } |
| 8092 | |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8093 | bool IsValidPVRTCSize(GLint level, GLsizei size) { |
[email protected] | a07a2360 | 2014-08-05 11:36:12 | [diff] [blame] | 8094 | return GLES2Util::IsPOT(size); |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8095 | } |
| 8096 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8097 | } // anonymous namespace. |
| 8098 | |
| 8099 | bool GLES2DecoderImpl::ValidateCompressedTexFuncData( |
| 8100 | const char* function_name, |
| 8101 | GLsizei width, GLsizei height, GLenum format, size_t size) { |
| 8102 | unsigned int bytes_required = 0; |
| 8103 | |
| 8104 | switch (format) { |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8105 | case GL_ATC_RGB_AMD: |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8106 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8107 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 8108 | case GL_ETC1_RGB8_OES: { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8109 | int num_blocks_across = |
| 8110 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 8111 | int num_blocks_down = |
| 8112 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 8113 | int num_blocks = num_blocks_across * num_blocks_down; |
| 8114 | bytes_required = num_blocks * kS3TCDXT1BlockSize; |
| 8115 | break; |
| 8116 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8117 | case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
| 8118 | case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8119 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 8120 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 8121 | int num_blocks_across = |
| 8122 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 8123 | int num_blocks_down = |
| 8124 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 8125 | int num_blocks = num_blocks_across * num_blocks_down; |
| 8126 | bytes_required = num_blocks * kS3TCDXT3AndDXT5BlockSize; |
| 8127 | break; |
| 8128 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8129 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 8130 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: { |
| 8131 | bytes_required = (std::max(width, 8) * std::max(height, 8) * 4 + 7)/8; |
| 8132 | break; |
| 8133 | } |
| 8134 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 8135 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: { |
| 8136 | bytes_required = (std::max(width, 16) * std::max(height, 8) * 2 + 7)/8; |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8137 | break; |
| 8138 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8139 | default: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8140 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8141 | return false; |
| 8142 | } |
| 8143 | |
| 8144 | if (size != bytes_required) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8145 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8146 | GL_INVALID_VALUE, function_name, "size is not correct for dimensions"); |
| 8147 | return false; |
| 8148 | } |
| 8149 | |
| 8150 | return true; |
| 8151 | } |
| 8152 | |
| 8153 | bool GLES2DecoderImpl::ValidateCompressedTexDimensions( |
| 8154 | const char* function_name, |
| 8155 | GLint level, GLsizei width, GLsizei height, GLenum format) { |
| 8156 | switch (format) { |
| 8157 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 8158 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 8159 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 8160 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 8161 | if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8162 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8163 | GL_INVALID_OPERATION, function_name, |
| 8164 | "width or height invalid for level"); |
| 8165 | return false; |
| 8166 | } |
| 8167 | return true; |
| 8168 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8169 | case GL_ATC_RGB_AMD: |
| 8170 | case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
| 8171 | case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
| 8172 | case GL_ETC1_RGB8_OES: { |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8173 | if (width <= 0 || height <= 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8174 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8175 | GL_INVALID_OPERATION, function_name, |
| 8176 | "width or height invalid for level"); |
| 8177 | return false; |
| 8178 | } |
| 8179 | return true; |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8180 | } |
| 8181 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 8182 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 8183 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
| 8184 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: { |
| 8185 | if (!IsValidPVRTCSize(level, width) || |
| 8186 | !IsValidPVRTCSize(level, height)) { |
| 8187 | LOCAL_SET_GL_ERROR( |
| 8188 | GL_INVALID_OPERATION, function_name, |
| 8189 | "width or height invalid for level"); |
| 8190 | return false; |
| 8191 | } |
| 8192 | return true; |
| 8193 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8194 | default: |
| 8195 | return false; |
| 8196 | } |
| 8197 | } |
| 8198 | |
| 8199 | bool GLES2DecoderImpl::ValidateCompressedTexSubDimensions( |
| 8200 | const char* function_name, |
| 8201 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 8202 | GLsizei width, GLsizei height, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8203 | Texture* texture) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8204 | if (xoffset < 0 || yoffset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8205 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8206 | GL_INVALID_VALUE, function_name, "xoffset or yoffset < 0"); |
| 8207 | return false; |
| 8208 | } |
| 8209 | |
| 8210 | switch (format) { |
| 8211 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 8212 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 8213 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 8214 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 8215 | const int kBlockWidth = 4; |
| 8216 | const int kBlockHeight = 4; |
| 8217 | if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8218 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8219 | GL_INVALID_OPERATION, function_name, |
| 8220 | "xoffset or yoffset not multiple of 4"); |
| 8221 | return false; |
| 8222 | } |
| 8223 | GLsizei tex_width = 0; |
| 8224 | GLsizei tex_height = 0; |
| 8225 | if (!texture->GetLevelSize(target, level, &tex_width, &tex_height) || |
| 8226 | width - xoffset > tex_width || |
| 8227 | height - yoffset > tex_height) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8228 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8229 | GL_INVALID_OPERATION, function_name, "dimensions out of range"); |
| 8230 | return false; |
| 8231 | } |
| 8232 | return ValidateCompressedTexDimensions( |
| 8233 | function_name, level, width, height, format); |
| 8234 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8235 | case GL_ATC_RGB_AMD: |
| 8236 | case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
| 8237 | case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: { |
| 8238 | LOCAL_SET_GL_ERROR( |
| 8239 | GL_INVALID_OPERATION, function_name, |
| 8240 | "not supported for ATC textures"); |
| 8241 | return false; |
| 8242 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8243 | case GL_ETC1_RGB8_OES: { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8244 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8245 | GL_INVALID_OPERATION, function_name, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 8246 | "not supported for ECT1_RGB8_OES textures"); |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8247 | return false; |
| 8248 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8249 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 8250 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 8251 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
| 8252 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: { |
| 8253 | if ((xoffset != 0) || (yoffset != 0)) { |
| 8254 | LOCAL_SET_GL_ERROR( |
| 8255 | GL_INVALID_OPERATION, function_name, |
| 8256 | "xoffset and yoffset must be zero"); |
| 8257 | return false; |
| 8258 | } |
| 8259 | GLsizei tex_width = 0; |
| 8260 | GLsizei tex_height = 0; |
| 8261 | if (!texture->GetLevelSize(target, level, &tex_width, &tex_height) || |
| 8262 | width != tex_width || |
| 8263 | height != tex_height) { |
| 8264 | LOCAL_SET_GL_ERROR( |
| 8265 | GL_INVALID_OPERATION, function_name, |
| 8266 | "dimensions must match existing texture level dimensions"); |
| 8267 | return false; |
| 8268 | } |
| 8269 | return ValidateCompressedTexDimensions( |
| 8270 | function_name, level, width, height, format); |
| 8271 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8272 | default: |
| 8273 | return false; |
| 8274 | } |
| 8275 | } |
| 8276 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8277 | error::Error GLES2DecoderImpl::DoCompressedTexImage2D( |
| 8278 | GLenum target, |
| 8279 | GLint level, |
| 8280 | GLenum internal_format, |
| 8281 | GLsizei width, |
| 8282 | GLsizei height, |
| 8283 | GLint border, |
| 8284 | GLsizei image_size, |
| 8285 | const void* data) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8286 | // TODO(gman): Validate image_size is correct for width, height and format. |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8287 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8288 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 8289 | "glCompressedTexImage2D", target, "target"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8290 | return error::kNoError; |
| 8291 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8292 | if (!validators_->compressed_texture_format.IsValid( |
| 8293 | internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8294 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8295 | "glCompressedTexImage2D", internal_format, "internal_format"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8296 | return error::kNoError; |
| 8297 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8298 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8299 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8300 | LOCAL_SET_GL_ERROR( |
| 8301 | GL_INVALID_VALUE, |
| 8302 | "glCompressedTexImage2D", "dimensions out of range"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8303 | return error::kNoError; |
| 8304 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8305 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8306 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8307 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8308 | LOCAL_SET_GL_ERROR( |
| 8309 | GL_INVALID_VALUE, |
| 8310 | "glCompressedTexImage2D", "unknown texture target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8311 | return error::kNoError; |
| 8312 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8313 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8314 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8315 | LOCAL_SET_GL_ERROR( |
| 8316 | GL_INVALID_OPERATION, |
| 8317 | "glCompressedTexImage2D", "texture is immutable"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8318 | return error::kNoError; |
| 8319 | } |
| 8320 | |
| 8321 | if (!ValidateCompressedTexDimensions( |
| 8322 | "glCompressedTexImage2D", level, width, height, internal_format) || |
| 8323 | !ValidateCompressedTexFuncData( |
| 8324 | "glCompressedTexImage2D", width, height, internal_format, image_size)) { |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8325 | return error::kNoError; |
| 8326 | } |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 8327 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8328 | if (!EnsureGPUMemoryAvailable(image_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8329 | LOCAL_SET_GL_ERROR( |
| 8330 | GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8331 | return error::kNoError; |
| 8332 | } |
| 8333 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8334 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8335 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 8336 | } |
| 8337 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8338 | scoped_ptr<int8[]> zero; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8339 | if (!data) { |
| 8340 | zero.reset(new int8[image_size]); |
| 8341 | memset(zero.get(), 0, image_size); |
| 8342 | data = zero.get(); |
| 8343 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8344 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8345 | glCompressedTexImage2D( |
| 8346 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8347 | GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8348 | if (error == GL_NO_ERROR) { |
| 8349 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8350 | texture_ref, target, level, internal_format, |
| 8351 | width, height, 1, border, 0, 0, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8352 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 8353 | |
| 8354 | // This may be a slow command. Exit command processing to allow for |
| 8355 | // context preemption and GPU watchdog checks. |
| 8356 | ExitCommandProcessingEarly(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8357 | return error::kNoError; |
| 8358 | } |
| 8359 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8360 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8361 | uint32 immediate_data_size, |
| 8362 | const void* cmd_data) { |
| 8363 | const gles2::cmds::CompressedTexImage2D& c = |
| 8364 | *static_cast<const gles2::cmds::CompressedTexImage2D*>(cmd_data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8365 | GLenum target = static_cast<GLenum>(c.target); |
| 8366 | GLint level = static_cast<GLint>(c.level); |
| 8367 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 8368 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8369 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8370 | GLint border = static_cast<GLint>(c.border); |
| 8371 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
| 8372 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 8373 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 8374 | const void* data = NULL; |
| 8375 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 8376 | data = GetSharedMemoryAs<const void*>( |
| 8377 | data_shm_id, data_shm_offset, image_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 8378 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8379 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8380 | } |
| 8381 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8382 | return DoCompressedTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8383 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8384 | } |
| 8385 | |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8386 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2DBucket( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8387 | uint32 immediate_data_size, |
| 8388 | const void* cmd_data) { |
| 8389 | const gles2::cmds::CompressedTexImage2DBucket& c = |
| 8390 | *static_cast<const gles2::cmds::CompressedTexImage2DBucket*>(cmd_data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8391 | GLenum target = static_cast<GLenum>(c.target); |
| 8392 | GLint level = static_cast<GLint>(c.level); |
| 8393 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 8394 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8395 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8396 | GLint border = static_cast<GLint>(c.border); |
| 8397 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8398 | if (!bucket) { |
| 8399 | return error::kInvalidArguments; |
| 8400 | } |
| 8401 | uint32 data_size = bucket->size(); |
| 8402 | GLsizei imageSize = data_size; |
| 8403 | const void* data = bucket->GetData(0, data_size); |
| 8404 | if (!data) { |
| 8405 | return error::kInvalidArguments; |
| 8406 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8407 | return DoCompressedTexImage2D( |
| 8408 | target, level, internal_format, width, height, border, |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8409 | imageSize, data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8410 | } |
| 8411 | |
| 8412 | error::Error GLES2DecoderImpl::HandleCompressedTexSubImage2DBucket( |
| 8413 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8414 | const void* cmd_data) { |
| 8415 | const gles2::cmds::CompressedTexSubImage2DBucket& c = |
| 8416 | *static_cast<const gles2::cmds::CompressedTexSubImage2DBucket*>(cmd_data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8417 | GLenum target = static_cast<GLenum>(c.target); |
| 8418 | GLint level = static_cast<GLint>(c.level); |
| 8419 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 8420 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 8421 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8422 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8423 | GLenum format = static_cast<GLenum>(c.format); |
| 8424 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8425 | if (!bucket) { |
| 8426 | return error::kInvalidArguments; |
| 8427 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8428 | uint32 data_size = bucket->size(); |
| 8429 | GLsizei imageSize = data_size; |
| 8430 | const void* data = bucket->GetData(0, data_size); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8431 | if (!data) { |
| 8432 | return error::kInvalidArguments; |
| 8433 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8434 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8435 | LOCAL_SET_GL_ERROR( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8436 | GL_INVALID_ENUM, "glCompressedTexSubImage2D", "target"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8437 | return error::kNoError; |
| 8438 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8439 | if (!validators_->compressed_texture_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8440 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 8441 | "glCompressedTexSubImage2D", format, "format"); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8442 | return error::kNoError; |
| 8443 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8444 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8445 | LOCAL_SET_GL_ERROR( |
| 8446 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "width < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8447 | return error::kNoError; |
| 8448 | } |
| 8449 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8450 | LOCAL_SET_GL_ERROR( |
| 8451 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "height < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8452 | return error::kNoError; |
| 8453 | } |
| 8454 | if (imageSize < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8455 | LOCAL_SET_GL_ERROR( |
| 8456 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "imageSize < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8457 | return error::kNoError; |
| 8458 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8459 | DoCompressedTexSubImage2D( |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8460 | target, level, xoffset, yoffset, width, height, format, imageSize, data); |
| 8461 | return error::kNoError; |
| 8462 | } |
| 8463 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8464 | error::Error GLES2DecoderImpl::HandleTexImage2D(uint32 immediate_data_size, |
| 8465 | const void* cmd_data) { |
| 8466 | const gles2::cmds::TexImage2D& c = |
| 8467 | *static_cast<const gles2::cmds::TexImage2D*>(cmd_data); |
[email protected] | 67f92942 | 2014-05-17 15:33:13 | [diff] [blame] | 8468 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexImage2D", |
| 8469 | "width", c.width, "height", c.height); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8470 | // Set as failed for now, but if it successed, this will be set to not failed. |
| 8471 | texture_state_.tex_image_2d_failed = true; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8472 | GLenum target = static_cast<GLenum>(c.target); |
| 8473 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8474 | // TODO(kloveless): Change TexImage2D command to use unsigned integer |
| 8475 | // for internalformat. |
| 8476 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8477 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8478 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8479 | GLint border = static_cast<GLint>(c.border); |
| 8480 | GLenum format = static_cast<GLenum>(c.format); |
| 8481 | GLenum type = static_cast<GLenum>(c.type); |
| 8482 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 8483 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 8484 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8485 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8486 | width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8487 | NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 8488 | return error::kOutOfBounds; |
| 8489 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8490 | const void* pixels = NULL; |
| 8491 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 8492 | pixels = GetSharedMemoryAs<const void*>( |
| 8493 | pixels_shm_id, pixels_shm_offset, pixels_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 8494 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8495 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8496 | } |
| 8497 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8498 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8499 | TextureManager::DoTextImage2DArguments args = { |
| 8500 | target, level, internal_format, width, height, border, format, type, |
| 8501 | pixels, pixels_size}; |
| 8502 | texture_manager()->ValidateAndDoTexImage2D( |
| 8503 | &texture_state_, &state_, &framebuffer_state_, args); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 8504 | |
| 8505 | // This may be a slow command. Exit command processing to allow for |
| 8506 | // context preemption and GPU watchdog checks. |
| 8507 | ExitCommandProcessingEarly(); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8508 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8509 | } |
| 8510 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8511 | void GLES2DecoderImpl::DoCompressedTexSubImage2D( |
| 8512 | GLenum target, |
| 8513 | GLint level, |
| 8514 | GLint xoffset, |
| 8515 | GLint yoffset, |
| 8516 | GLsizei width, |
| 8517 | GLsizei height, |
| 8518 | GLenum format, |
| 8519 | GLsizei image_size, |
| 8520 | const void * data) { |
[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 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8524 | LOCAL_SET_GL_ERROR( |
| 8525 | GL_INVALID_OPERATION, |
| 8526 | "glCompressedTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8527 | return; |
| 8528 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8529 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8530 | GLenum type = 0; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8531 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8532 | if (!texture->GetLevelType(target, level, &type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8533 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8534 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8535 | "glCompressedTexSubImage2D", "level does not exist."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8536 | return; |
| 8537 | } |
| 8538 | if (internal_format != format) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8539 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8540 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8541 | "glCompressedTexSubImage2D", "format does not match internal format."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8542 | return; |
| 8543 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8544 | if (!texture->ValidForTexture( |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8545 | target, level, xoffset, yoffset, width, height, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8546 | LOCAL_SET_GL_ERROR( |
| 8547 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8548 | return; |
| 8549 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8550 | |
| 8551 | if (!ValidateCompressedTexFuncData( |
| 8552 | "glCompressedTexSubImage2D", width, height, format, image_size) || |
| 8553 | !ValidateCompressedTexSubDimensions( |
| 8554 | "glCompressedTexSubImage2D", |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8555 | target, level, xoffset, yoffset, width, height, format, texture)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8556 | return; |
| 8557 | } |
| 8558 | |
| 8559 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8560 | // Note: There is no need to deal with texture cleared tracking here |
| 8561 | // because the validation above means you can only get here if the level |
| 8562 | // is already a matching compressed format and in that case |
| 8563 | // CompressedTexImage2D already cleared the texture. |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8564 | glCompressedTexSubImage2D( |
| 8565 | target, level, xoffset, yoffset, width, height, format, image_size, data); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 8566 | |
| 8567 | // This may be a slow command. Exit command processing to allow for |
| 8568 | // context preemption and GPU watchdog checks. |
| 8569 | ExitCommandProcessingEarly(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8570 | } |
| 8571 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8572 | static void Clip( |
| 8573 | GLint start, GLint range, GLint sourceRange, |
| 8574 | GLint* out_start, GLint* out_range) { |
| 8575 | DCHECK(out_start); |
| 8576 | DCHECK(out_range); |
| 8577 | if (start < 0) { |
| 8578 | range += start; |
| 8579 | start = 0; |
| 8580 | } |
| 8581 | GLint end = start + range; |
| 8582 | if (end > sourceRange) { |
| 8583 | range -= end - sourceRange; |
| 8584 | } |
| 8585 | *out_start = start; |
| 8586 | *out_range = range; |
| 8587 | } |
| 8588 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8589 | void GLES2DecoderImpl::DoCopyTexImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 8590 | GLenum target, |
| 8591 | GLint level, |
| 8592 | GLenum internal_format, |
| 8593 | GLint x, |
| 8594 | GLint y, |
| 8595 | GLsizei width, |
| 8596 | GLsizei height, |
| 8597 | GLint border) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 8598 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8599 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8600 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8601 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8602 | LOCAL_SET_GL_ERROR( |
| 8603 | GL_INVALID_OPERATION, |
| 8604 | "glCopyTexImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8605 | return; |
| 8606 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8607 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8608 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8609 | LOCAL_SET_GL_ERROR( |
| 8610 | GL_INVALID_OPERATION, "glCopyTexImage2D", "texture is immutable"); |
[email protected] | cedee33 | 2014-05-23 07:07:53 | [diff] [blame] | 8611 | return; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8612 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8613 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8614 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8615 | LOCAL_SET_GL_ERROR( |
| 8616 | GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range"); |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8617 | return; |
| 8618 | } |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8619 | if (!texture_manager()->ValidateFormatAndTypeCombination( |
| 8620 | state_.GetErrorState(), "glCopyTexImage2D", internal_format, |
| 8621 | GL_UNSIGNED_BYTE)) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8622 | return; |
| 8623 | } |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8624 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8625 | // Check we have compatible formats. |
| 8626 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 8627 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 8628 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); |
| 8629 | |
| 8630 | if ((channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8631 | LOCAL_SET_GL_ERROR( |
| 8632 | GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8633 | return; |
| 8634 | } |
| 8635 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8636 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8637 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8638 | GL_INVALID_OPERATION, |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8639 | "glCopyTexImage2D", "can not be used with depth or stencil textures"); |
| 8640 | return; |
| 8641 | } |
| 8642 | |
| 8643 | uint32 estimated_size = 0; |
| 8644 | if (!GLES2Util::ComputeImageDataSizes( |
| 8645 | width, height, internal_format, GL_UNSIGNED_BYTE, state_.unpack_alignment, |
| 8646 | &estimated_size, NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8647 | LOCAL_SET_GL_ERROR( |
| 8648 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8649 | return; |
| 8650 | } |
| 8651 | |
| 8652 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8653 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "out of memory"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8654 | return; |
| 8655 | } |
| 8656 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 8657 | if (!CheckBoundReadFramebufferColorAttachment("glCopyTexImage2D")) { |
| 8658 | return; |
| 8659 | } |
| 8660 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 8661 | if (FormsTextureCopyingFeedbackLoop(texture_ref, level)) { |
| 8662 | LOCAL_SET_GL_ERROR( |
| 8663 | GL_INVALID_OPERATION, |
| 8664 | "glCopyTexImage2D", "source and destination textures are the same"); |
| 8665 | return; |
| 8666 | } |
| 8667 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 8668 | if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { |
| 8669 | return; |
| 8670 | } |
| 8671 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8672 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTexImage2D"); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8673 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8674 | gfx::Size size = GetBoundReadFrameBufferSize(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8675 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8676 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8677 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 8678 | } |
| 8679 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8680 | // Clip to size to source dimensions |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8681 | GLint copyX = 0; |
| 8682 | GLint copyY = 0; |
| 8683 | GLint copyWidth = 0; |
| 8684 | GLint copyHeight = 0; |
| 8685 | Clip(x, width, size.width(), ©X, ©Width); |
| 8686 | Clip(y, height, size.height(), ©Y, ©Height); |
| 8687 | |
| 8688 | if (copyX != x || |
| 8689 | copyY != y || |
| 8690 | copyWidth != width || |
| 8691 | copyHeight != height) { |
| 8692 | // some part was clipped so clear the texture. |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8693 | if (!ClearLevel( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8694 | texture->service_id(), texture->target(), |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 8695 | target, level, internal_format, internal_format, GL_UNSIGNED_BYTE, |
| 8696 | width, height, texture->IsImmutable())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8697 | LOCAL_SET_GL_ERROR( |
| 8698 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8699 | return; |
| 8700 | } |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8701 | if (copyHeight > 0 && copyWidth > 0) { |
| 8702 | GLint dx = copyX - x; |
| 8703 | GLint dy = copyY - y; |
| 8704 | GLint destX = dx; |
| 8705 | GLint destY = dy; |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 8706 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8707 | glCopyTexSubImage2D(target, level, |
| 8708 | destX, destY, copyX, copyY, |
| 8709 | copyWidth, copyHeight); |
| 8710 | } |
| 8711 | } else { |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 8712 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8713 | glCopyTexImage2D(target, level, internal_format, |
| 8714 | copyX, copyY, copyWidth, copyHeight, border); |
| 8715 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8716 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8717 | if (error == GL_NO_ERROR) { |
| 8718 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8719 | texture_ref, target, level, internal_format, width, height, 1, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8720 | border, internal_format, GL_UNSIGNED_BYTE, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8721 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 8722 | |
| 8723 | // This may be a slow command. Exit command processing to allow for |
| 8724 | // context preemption and GPU watchdog checks. |
| 8725 | ExitCommandProcessingEarly(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8726 | } |
| 8727 | |
| 8728 | void GLES2DecoderImpl::DoCopyTexSubImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 8729 | GLenum target, |
| 8730 | GLint level, |
| 8731 | GLint xoffset, |
| 8732 | GLint yoffset, |
| 8733 | GLint x, |
| 8734 | GLint y, |
| 8735 | GLsizei width, |
| 8736 | GLsizei height) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 8737 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8738 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8739 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8740 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8741 | LOCAL_SET_GL_ERROR( |
| 8742 | GL_INVALID_OPERATION, |
| 8743 | "glCopyTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8744 | return; |
| 8745 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8746 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8747 | GLenum type = 0; |
| 8748 | GLenum format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8749 | if (!texture->GetLevelType(target, level, &type, &format) || |
| 8750 | !texture->ValidForTexture( |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8751 | target, level, xoffset, yoffset, width, height, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8752 | LOCAL_SET_GL_ERROR( |
| 8753 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8754 | return; |
| 8755 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 8756 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8757 | LOCAL_SET_GL_ERROR( |
| 8758 | GL_INVALID_OPERATION, |
| 8759 | "glCopyTexSubImage2D", "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 8760 | return; |
| 8761 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8762 | |
| 8763 | // Check we have compatible formats. |
| 8764 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 8765 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 8766 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(format); |
| 8767 | |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8768 | if (!channels_needed || |
| 8769 | (channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8770 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8771 | GL_INVALID_OPERATION, "glCopyTexSubImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8772 | return; |
| 8773 | } |
| 8774 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8775 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8776 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8777 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8778 | "glCopySubImage2D", "can not be used with depth or stencil textures"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8779 | return; |
| 8780 | } |
| 8781 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 8782 | if (!CheckBoundReadFramebufferColorAttachment("glCopyTexSubImage2D")) { |
| 8783 | return; |
| 8784 | } |
| 8785 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 8786 | if (FormsTextureCopyingFeedbackLoop(texture_ref, level)) { |
| 8787 | LOCAL_SET_GL_ERROR( |
| 8788 | GL_INVALID_OPERATION, |
| 8789 | "glCopyTexSubImage2D", "source and destination textures are the same"); |
| 8790 | return; |
| 8791 | } |
| 8792 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 8793 | if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) { |
| 8794 | return; |
| 8795 | } |
| 8796 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8797 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8798 | gfx::Size size = GetBoundReadFrameBufferSize(); |
| 8799 | GLint copyX = 0; |
| 8800 | GLint copyY = 0; |
| 8801 | GLint copyWidth = 0; |
| 8802 | GLint copyHeight = 0; |
| 8803 | Clip(x, width, size.width(), ©X, ©Width); |
| 8804 | Clip(y, height, size.height(), ©Y, ©Height); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8805 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8806 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8807 | LOCAL_SET_GL_ERROR( |
| 8808 | GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", "dimensions too big"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8809 | return; |
| 8810 | } |
| 8811 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8812 | if (copyX != x || |
| 8813 | copyY != y || |
| 8814 | copyWidth != width || |
| 8815 | copyHeight != height) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8816 | // some part was clipped so clear the sub rect. |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8817 | uint32 pixels_size = 0; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8818 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8819 | width, height, format, type, state_.unpack_alignment, &pixels_size, |
| 8820 | NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8821 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8822 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8823 | return; |
| 8824 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8825 | scoped_ptr<char[]> zero(new char[pixels_size]); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8826 | memset(zero.get(), 0, pixels_size); |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 8827 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8828 | glTexSubImage2D( |
| 8829 | target, level, xoffset, yoffset, width, height, |
| 8830 | format, type, zero.get()); |
| 8831 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8832 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8833 | if (copyHeight > 0 && copyWidth > 0) { |
| 8834 | GLint dx = copyX - x; |
| 8835 | GLint dy = copyY - y; |
| 8836 | GLint destX = xoffset + dx; |
| 8837 | GLint destY = yoffset + dy; |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 8838 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8839 | glCopyTexSubImage2D(target, level, |
| 8840 | destX, destY, copyX, copyY, |
| 8841 | copyWidth, copyHeight); |
| 8842 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 8843 | |
| 8844 | // This may be a slow command. Exit command processing to allow for |
| 8845 | // context preemption and GPU watchdog checks. |
| 8846 | ExitCommandProcessingEarly(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8847 | } |
| 8848 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8849 | bool GLES2DecoderImpl::ValidateTexSubImage2D( |
| 8850 | error::Error* error, |
| 8851 | const char* function_name, |
| 8852 | GLenum target, |
| 8853 | GLint level, |
| 8854 | GLint xoffset, |
| 8855 | GLint yoffset, |
| 8856 | GLsizei width, |
| 8857 | GLsizei height, |
| 8858 | GLenum format, |
| 8859 | GLenum type, |
| 8860 | const void * data) { |
| 8861 | (*error) = error::kNoError; |
| 8862 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8863 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8864 | return false; |
| 8865 | } |
| 8866 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8867 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "width < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8868 | return false; |
| 8869 | } |
| 8870 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8871 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "height < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8872 | return false; |
| 8873 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8874 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8875 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8876 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8877 | LOCAL_SET_GL_ERROR( |
| 8878 | GL_INVALID_OPERATION, |
| 8879 | function_name, "unknown texture for target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8880 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8881 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8882 | Texture* texture = texture_ref->texture(); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8883 | GLenum current_type = 0; |
| 8884 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8885 | if (!texture->GetLevelType(target, level, ¤t_type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8886 | LOCAL_SET_GL_ERROR( |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8887 | GL_INVALID_OPERATION, function_name, "level does not exist."); |
| 8888 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8889 | } |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8890 | if (!texture_manager()->ValidateTextureParameters(state_.GetErrorState(), |
| 8891 | function_name, format, type, internal_format, level)) { |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8892 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8893 | } |
| 8894 | if (type != current_type) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8895 | LOCAL_SET_GL_ERROR( |
| 8896 | GL_INVALID_OPERATION, |
| 8897 | function_name, "type does not match type of texture."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8898 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8899 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 8900 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8901 | LOCAL_SET_GL_ERROR( |
| 8902 | GL_INVALID_OPERATION, |
| 8903 | function_name, "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 8904 | return false; |
| 8905 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8906 | if (!texture->ValidForTexture( |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8907 | target, level, xoffset, yoffset, width, height, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8908 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "bad dimensions."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8909 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8910 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8911 | if ((GLES2Util::GetChannelsForFormat(format) & |
| 8912 | (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8913 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8914 | GL_INVALID_OPERATION, |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8915 | function_name, "can not supply data for depth or stencil textures"); |
| 8916 | return false; |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8917 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8918 | if (data == NULL) { |
| 8919 | (*error) = error::kOutOfBounds; |
| 8920 | return false; |
| 8921 | } |
| 8922 | return true; |
| 8923 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8924 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8925 | error::Error GLES2DecoderImpl::DoTexSubImage2D( |
| 8926 | GLenum target, |
| 8927 | GLint level, |
| 8928 | GLint xoffset, |
| 8929 | GLint yoffset, |
| 8930 | GLsizei width, |
| 8931 | GLsizei height, |
| 8932 | GLenum format, |
| 8933 | GLenum type, |
| 8934 | const void * data) { |
| 8935 | error::Error error = error::kNoError; |
| 8936 | if (!ValidateTexSubImage2D(&error, "glTexSubImage2D", target, level, |
| 8937 | xoffset, yoffset, width, height, format, type, data)) { |
| 8938 | return error; |
| 8939 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8940 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8941 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8942 | Texture* texture = texture_ref->texture(); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8943 | GLsizei tex_width = 0; |
| 8944 | GLsizei tex_height = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8945 | bool ok = texture->GetLevelSize(target, level, &tex_width, &tex_height); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8946 | DCHECK(ok); |
| 8947 | if (xoffset != 0 || yoffset != 0 || |
| 8948 | width != tex_width || height != tex_height) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8949 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, |
| 8950 | target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8951 | LOCAL_SET_GL_ERROR( |
| 8952 | GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8953 | return error::kNoError; |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 8954 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8955 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8956 | glTexSubImage2D( |
| 8957 | target, level, xoffset, yoffset, width, height, format, type, data); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8958 | return error::kNoError; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8959 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8960 | |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 8961 | if (!texture_state_.texsubimage2d_faster_than_teximage2d && |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8962 | !texture->IsImmutable()) { |
| 8963 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 8964 | GLenum internal_format; |
| 8965 | GLenum tex_type; |
| 8966 | texture->GetLevelType(target, level, &tex_type, &internal_format); |
| 8967 | // NOTE: In OpenGL ES 2.0 border is always zero. If that changes we'll need |
| 8968 | // to look it up. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 8969 | glTexImage2D( |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 8970 | target, level, internal_format, width, height, 0, format, type, data); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8971 | } else { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8972 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8973 | glTexSubImage2D( |
| 8974 | target, level, xoffset, yoffset, width, height, format, type, data); |
| 8975 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8976 | texture_manager()->SetLevelCleared(texture_ref, target, level, true); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 8977 | |
| 8978 | // This may be a slow command. Exit command processing to allow for |
| 8979 | // context preemption and GPU watchdog checks. |
| 8980 | ExitCommandProcessingEarly(); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8981 | return error::kNoError; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8982 | } |
| 8983 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8984 | error::Error GLES2DecoderImpl::HandleTexSubImage2D(uint32 immediate_data_size, |
| 8985 | const void* cmd_data) { |
| 8986 | const gles2::cmds::TexSubImage2D& c = |
| 8987 | *static_cast<const gles2::cmds::TexSubImage2D*>(cmd_data); |
[email protected] | 67f92942 | 2014-05-17 15:33:13 | [diff] [blame] | 8988 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexSubImage2D", |
| 8989 | "width", c.width, "height", c.height); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8990 | GLboolean internal = static_cast<GLboolean>(c.internal); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8991 | if (internal == GL_TRUE && texture_state_.tex_image_2d_failed) |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 8992 | return error::kNoError; |
| 8993 | |
| 8994 | GLenum target = static_cast<GLenum>(c.target); |
| 8995 | GLint level = static_cast<GLint>(c.level); |
| 8996 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 8997 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 8998 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8999 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9000 | GLenum format = static_cast<GLenum>(c.format); |
| 9001 | GLenum type = static_cast<GLenum>(c.type); |
| 9002 | uint32 data_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 9003 | if (!GLES2Util::ComputeImageDataSizes( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9004 | width, height, format, type, state_.unpack_alignment, &data_size, |
| 9005 | NULL, NULL)) { |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 9006 | return error::kOutOfBounds; |
| 9007 | } |
| 9008 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 9009 | c.pixels_shm_id, c.pixels_shm_offset, data_size); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9010 | return DoTexSubImage2D( |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 9011 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 9012 | } |
| 9013 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9014 | error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9015 | uint32 immediate_data_size, |
| 9016 | const void* cmd_data) { |
| 9017 | const gles2::cmds::GetVertexAttribPointerv& c = |
| 9018 | *static_cast<const gles2::cmds::GetVertexAttribPointerv*>(cmd_data); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9019 | GLuint index = static_cast<GLuint>(c.index); |
| 9020 | GLenum pname = static_cast<GLenum>(c.pname); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9021 | typedef cmds::GetVertexAttribPointerv::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9022 | Result* result = GetSharedMemoryAs<Result*>( |
| 9023 | c.pointer_shm_id, c.pointer_shm_offset, Result::ComputeSize(1)); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9024 | if (!result) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9025 | return error::kOutOfBounds; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9026 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9027 | // Check that the client initialized the result. |
| 9028 | if (result->size != 0) { |
| 9029 | return error::kInvalidArguments; |
| 9030 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9031 | if (!validators_->vertex_pointer.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9032 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 9033 | "glGetVertexAttribPointerv", pname, "pname"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9034 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9035 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 9036 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9037 | LOCAL_SET_GL_ERROR( |
| 9038 | GL_INVALID_VALUE, "glGetVertexAttribPointerv", "index out of range."); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9039 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9040 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9041 | result->SetNumResults(1); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 9042 | *result->GetData() = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9043 | state_.vertex_attrib_manager->GetVertexAttrib(index)->offset(); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9044 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9045 | } |
| 9046 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9047 | bool GLES2DecoderImpl::GetUniformSetup( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9048 | GLuint program_id, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9049 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9050 | error::Error* error, GLint* real_location, |
| 9051 | GLuint* service_id, void** result_pointer, GLenum* result_type) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9052 | DCHECK(error); |
| 9053 | DCHECK(service_id); |
| 9054 | DCHECK(result_pointer); |
| 9055 | DCHECK(result_type); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9056 | DCHECK(real_location); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9057 | *error = error::kNoError; |
| 9058 | // Make sure we have enough room for the result on failure. |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9059 | SizedResult<GLint>* result; |
| 9060 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 9061 | shm_id, shm_offset, SizedResult<GLint>::ComputeSize(0)); |
| 9062 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9063 | *error = error::kOutOfBounds; |
| 9064 | return false; |
| 9065 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9066 | *result_pointer = result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9067 | // 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] | 9068 | result->SetNumResults(0); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9069 | Program* program = GetProgramInfoNotShader(program_id, "glGetUniform"); |
| 9070 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 9071 | return false; |
| 9072 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9073 | if (!program->IsValid()) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9074 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9075 | LOCAL_SET_GL_ERROR( |
| 9076 | GL_INVALID_OPERATION, "glGetUniform", "program not linked"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9077 | return false; |
| 9078 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9079 | *service_id = program->service_id(); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 9080 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9081 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9082 | program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9083 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 9084 | if (!uniform_info) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9085 | // No such location. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9086 | LOCAL_SET_GL_ERROR( |
| 9087 | GL_INVALID_OPERATION, "glGetUniform", "unknown location"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9088 | return false; |
| 9089 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 9090 | GLenum type = uniform_info->type; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 9091 | GLsizei size = GLES2Util::GetGLDataTypeSizeForUniforms(type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9092 | if (size == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9093 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glGetUniform", "unknown type"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9094 | return false; |
| 9095 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9096 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 9097 | shm_id, shm_offset, SizedResult<GLint>::ComputeSizeFromBytes(size)); |
| 9098 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9099 | *error = error::kOutOfBounds; |
| 9100 | return false; |
| 9101 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9102 | result->size = size; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9103 | *result_type = type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9104 | return true; |
| 9105 | } |
| 9106 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9107 | error::Error GLES2DecoderImpl::HandleGetUniformiv(uint32 immediate_data_size, |
| 9108 | const void* cmd_data) { |
| 9109 | const gles2::cmds::GetUniformiv& c = |
| 9110 | *static_cast<const gles2::cmds::GetUniformiv*>(cmd_data); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9111 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 9112 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9113 | GLuint service_id; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9114 | GLenum result_type; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9115 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9116 | Error error; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9117 | void* result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9118 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9119 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 9120 | &error, &real_location, &service_id, &result, &result_type)) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9121 | glGetUniformiv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9122 | service_id, real_location, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9123 | static_cast<cmds::GetUniformiv::Result*>(result)->GetData()); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9124 | } |
| 9125 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9126 | } |
| 9127 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9128 | error::Error GLES2DecoderImpl::HandleGetUniformfv(uint32 immediate_data_size, |
| 9129 | const void* cmd_data) { |
| 9130 | const gles2::cmds::GetUniformfv& c = |
| 9131 | *static_cast<const gles2::cmds::GetUniformfv*>(cmd_data); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9132 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 9133 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9134 | GLuint service_id; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9135 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9136 | Error error; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9137 | typedef cmds::GetUniformfv::Result Result; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9138 | Result* result; |
| 9139 | GLenum result_type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9140 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9141 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 9142 | &error, &real_location, &service_id, |
| 9143 | reinterpret_cast<void**>(&result), &result_type)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9144 | if (result_type == GL_BOOL || result_type == GL_BOOL_VEC2 || |
| 9145 | result_type == GL_BOOL_VEC3 || result_type == GL_BOOL_VEC4) { |
| 9146 | GLsizei num_values = result->GetNumResults(); |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 9147 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9148 | glGetUniformiv(service_id, real_location, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9149 | GLfloat* dst = result->GetData(); |
| 9150 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
| 9151 | dst[ii] = (temp[ii] != 0); |
| 9152 | } |
| 9153 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9154 | glGetUniformfv(service_id, real_location, result->GetData()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9155 | } |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9156 | } |
| 9157 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9158 | } |
| 9159 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9160 | error::Error GLES2DecoderImpl::HandleGetShaderPrecisionFormat( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9161 | uint32 immediate_data_size, |
| 9162 | const void* cmd_data) { |
| 9163 | const gles2::cmds::GetShaderPrecisionFormat& c = |
| 9164 | *static_cast<const gles2::cmds::GetShaderPrecisionFormat*>(cmd_data); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9165 | GLenum shader_type = static_cast<GLenum>(c.shadertype); |
| 9166 | GLenum precision_type = static_cast<GLenum>(c.precisiontype); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9167 | typedef cmds::GetShaderPrecisionFormat::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9168 | Result* result = GetSharedMemoryAs<Result*>( |
| 9169 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9170 | if (!result) { |
| 9171 | return error::kOutOfBounds; |
| 9172 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9173 | // Check that the client initialized the result. |
| 9174 | if (result->success != 0) { |
| 9175 | return error::kInvalidArguments; |
| 9176 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9177 | if (!validators_->shader_type.IsValid(shader_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9178 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 9179 | "glGetShaderPrecisionFormat", shader_type, "shader_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 9180 | return error::kNoError; |
| 9181 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9182 | if (!validators_->shader_precision.IsValid(precision_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9183 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 9184 | "glGetShaderPrecisionFormat", precision_type, "precision_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 9185 | return error::kNoError; |
| 9186 | } |
| 9187 | |
| 9188 | result->success = 1; // true |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 9189 | |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 9190 | GLint range[2] = { 0, 0 }; |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 9191 | GLint precision = 0; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 9192 | GetShaderPrecisionFormatImpl(shader_type, precision_type, range, &precision); |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 9193 | |
| 9194 | result->min_range = range[0]; |
| 9195 | result->max_range = range[1]; |
| 9196 | result->precision = precision; |
| 9197 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9198 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9199 | } |
| 9200 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9201 | error::Error GLES2DecoderImpl::HandleGetAttachedShaders( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9202 | uint32 immediate_data_size, |
| 9203 | const void* cmd_data) { |
| 9204 | const gles2::cmds::GetAttachedShaders& c = |
| 9205 | *static_cast<const gles2::cmds::GetAttachedShaders*>(cmd_data); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9206 | uint32 result_size = c.result_size; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9207 | GLuint program_id = static_cast<GLuint>(c.program); |
| 9208 | Program* program = GetProgramInfoNotShader( |
| 9209 | program_id, "glGetAttachedShaders"); |
| 9210 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9211 | return error::kNoError; |
| 9212 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9213 | typedef cmds::GetAttachedShaders::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9214 | uint32 max_count = Result::ComputeMaxResults(result_size); |
| 9215 | Result* result = GetSharedMemoryAs<Result*>( |
| 9216 | c.result_shm_id, c.result_shm_offset, Result::ComputeSize(max_count)); |
| 9217 | if (!result) { |
| 9218 | return error::kOutOfBounds; |
| 9219 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9220 | // Check that the client initialized the result. |
| 9221 | if (result->size != 0) { |
| 9222 | return error::kInvalidArguments; |
| 9223 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9224 | GLsizei count = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 9225 | glGetAttachedShaders( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9226 | program->service_id(), max_count, &count, result->GetData()); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9227 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 9228 | if (!shader_manager()->GetClientId(result->GetData()[ii], |
| 9229 | &result->GetData()[ii])) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9230 | NOTREACHED(); |
| 9231 | return error::kGenericError; |
| 9232 | } |
| 9233 | } |
| 9234 | result->SetNumResults(count); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9235 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9236 | } |
| 9237 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9238 | error::Error GLES2DecoderImpl::HandleGetActiveUniform( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9239 | uint32 immediate_data_size, |
| 9240 | const void* cmd_data) { |
| 9241 | const gles2::cmds::GetActiveUniform& c = |
| 9242 | *static_cast<const gles2::cmds::GetActiveUniform*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9243 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9244 | GLuint index = c.index; |
| 9245 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9246 | typedef cmds::GetActiveUniform::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9247 | Result* result = GetSharedMemoryAs<Result*>( |
| 9248 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9249 | if (!result) { |
| 9250 | return error::kOutOfBounds; |
| 9251 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9252 | // Check that the client initialized the result. |
| 9253 | if (result->success != 0) { |
| 9254 | return error::kInvalidArguments; |
| 9255 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9256 | Program* program = GetProgramInfoNotShader( |
| 9257 | program_id, "glGetActiveUniform"); |
| 9258 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9259 | return error::kNoError; |
| 9260 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9261 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9262 | program->GetUniformInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9263 | if (!uniform_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9264 | LOCAL_SET_GL_ERROR( |
| 9265 | GL_INVALID_VALUE, "glGetActiveUniform", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9266 | return error::kNoError; |
| 9267 | } |
| 9268 | result->success = 1; // true. |
| 9269 | result->size = uniform_info->size; |
| 9270 | result->type = uniform_info->type; |
| 9271 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 9272 | bucket->SetFromString(uniform_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9273 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9274 | } |
| 9275 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9276 | error::Error GLES2DecoderImpl::HandleGetActiveAttrib(uint32 immediate_data_size, |
| 9277 | const void* cmd_data) { |
| 9278 | const gles2::cmds::GetActiveAttrib& c = |
| 9279 | *static_cast<const gles2::cmds::GetActiveAttrib*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9280 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9281 | GLuint index = c.index; |
| 9282 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9283 | typedef cmds::GetActiveAttrib::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9284 | Result* result = GetSharedMemoryAs<Result*>( |
| 9285 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9286 | if (!result) { |
| 9287 | return error::kOutOfBounds; |
| 9288 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9289 | // Check that the client initialized the result. |
| 9290 | if (result->success != 0) { |
| 9291 | return error::kInvalidArguments; |
| 9292 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9293 | Program* program = GetProgramInfoNotShader( |
| 9294 | program_id, "glGetActiveAttrib"); |
| 9295 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9296 | return error::kNoError; |
| 9297 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9298 | const Program::VertexAttrib* attrib_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9299 | program->GetAttribInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9300 | if (!attrib_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9301 | LOCAL_SET_GL_ERROR( |
| 9302 | GL_INVALID_VALUE, "glGetActiveAttrib", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9303 | return error::kNoError; |
| 9304 | } |
| 9305 | result->success = 1; // true. |
| 9306 | result->size = attrib_info->size; |
| 9307 | result->type = attrib_info->type; |
| 9308 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 9309 | bucket->SetFromString(attrib_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9310 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9311 | } |
| 9312 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9313 | error::Error GLES2DecoderImpl::HandleShaderBinary(uint32 immediate_data_size, |
| 9314 | const void* cmd_data) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9315 | #if 1 // No binary shader support. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9316 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glShaderBinary", "not supported"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9317 | return error::kNoError; |
| 9318 | #else |
| 9319 | GLsizei n = static_cast<GLsizei>(c.n); |
| 9320 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9321 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "n < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9322 | return error::kNoError; |
| 9323 | } |
| 9324 | GLsizei length = static_cast<GLsizei>(c.length); |
| 9325 | if (length < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9326 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "length < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9327 | return error::kNoError; |
| 9328 | } |
| 9329 | uint32 data_size; |
| 9330 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 9331 | return error::kOutOfBounds; |
| 9332 | } |
| 9333 | const GLuint* shaders = GetSharedMemoryAs<const GLuint*>( |
| 9334 | c.shaders_shm_id, c.shaders_shm_offset, data_size); |
| 9335 | GLenum binaryformat = static_cast<GLenum>(c.binaryformat); |
| 9336 | const void* binary = GetSharedMemoryAs<const void*>( |
| 9337 | c.binary_shm_id, c.binary_shm_offset, length); |
| 9338 | if (shaders == NULL || binary == NULL) { |
| 9339 | return error::kOutOfBounds; |
| 9340 | } |
[email protected] | 0782b14b | 2014-05-24 13:04:16 | [diff] [blame] | 9341 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9342 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9343 | Shader* shader = GetShader(shaders[ii]); |
| 9344 | if (!shader) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9345 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "unknown shader"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9346 | return error::kNoError; |
| 9347 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9348 | service_ids[ii] = shader->service_id(); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9349 | } |
| 9350 | // TODO(gman): call glShaderBinary |
| 9351 | return error::kNoError; |
| 9352 | #endif |
| 9353 | } |
| 9354 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9355 | void GLES2DecoderImpl::DoSwapBuffers() { |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 9356 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 9357 | |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 9358 | int this_frame_number = frame_number_++; |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 9359 | // TRACE_EVENT for gpu tests: |
| 9360 | TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffersLatency", |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 9361 | TRACE_EVENT_SCOPE_THREAD, |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 9362 | "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
| 9363 | "width", (is_offscreen ? offscreen_size_.width() : |
| 9364 | surface_->GetSize().width())); |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9365 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoSwapBuffers", |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 9366 | "offscreen", is_offscreen, |
| 9367 | "frame", this_frame_number); |
[email protected] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 9368 | { |
[email protected] | a36ed483 | 2014-04-24 16:40:27 | [diff] [blame] | 9369 | TRACE_EVENT_SYNTHETIC_DELAY("gpu.PresentingFrame"); |
[email protected] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 9370 | } |
| 9371 | |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 9372 | bool is_tracing; |
| 9373 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 9374 | &is_tracing); |
| 9375 | if (is_tracing) { |
| 9376 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 9377 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 9378 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 9379 | } |
| 9380 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9381 | // If offscreen then don't actually SwapBuffers to the display. Just copy |
| 9382 | // the rendered frame to another frame buffer. |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 9383 | if (is_offscreen) { |
[email protected] | 111975c6 | 2012-09-06 01:37:31 | [diff] [blame] | 9384 | TRACE_EVENT2("gpu", "Offscreen", |
| 9385 | "width", offscreen_size_.width(), "height", offscreen_size_.height()); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9386 | if (offscreen_size_ != offscreen_saved_color_texture_->size()) { |
| 9387 | // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, |
| 9388 | // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will |
| 9389 | // fix this. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9390 | if (workarounds().needs_offscreen_buffer_workaround) { |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9391 | offscreen_saved_frame_buffer_->Create(); |
| 9392 | glFinish(); |
| 9393 | } |
| 9394 | |
| 9395 | // Allocate the offscreen saved color texture. |
| 9396 | DCHECK(offscreen_saved_color_format_); |
| 9397 | offscreen_saved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 9398 | offscreen_size_, offscreen_saved_color_format_, false); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9399 | |
| 9400 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 9401 | offscreen_saved_color_texture_.get()); |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9402 | if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { |
| 9403 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 9404 | GL_FRAMEBUFFER_COMPLETE) { |
| 9405 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 9406 | << "because offscreen saved FBO was incomplete."; |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9407 | LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
| 9408 | return; |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9409 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9410 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9411 | // Clear the offscreen color texture. |
| 9412 | // TODO(piman): Is this still necessary? |
| 9413 | { |
| 9414 | ScopedFrameBufferBinder binder(this, |
| 9415 | offscreen_saved_frame_buffer_->id()); |
| 9416 | glClearColor(0, 0, 0, 0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 9417 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 9418 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9419 | glClear(GL_COLOR_BUFFER_BIT); |
| 9420 | RestoreClearState(); |
| 9421 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9422 | } |
| 9423 | |
| 9424 | UpdateParentTextureInfo(); |
| 9425 | } |
| 9426 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9427 | if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9428 | return; |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9429 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 9430 | "GLES2DecoderImpl::DoSwapBuffers", GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9431 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 9432 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 9433 | // For multisampled buffers, resolve the frame buffer. |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 9434 | ScopedResolvedFrameBufferBinder binder(this, true, false); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 9435 | } else { |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9436 | ScopedFrameBufferBinder binder(this, |
| 9437 | offscreen_target_frame_buffer_->id()); |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 9438 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9439 | if (offscreen_target_buffer_preserved_) { |
| 9440 | // Copy the target frame buffer to the saved offscreen texture. |
| 9441 | offscreen_saved_color_texture_->Copy( |
| 9442 | offscreen_saved_color_texture_->size(), |
| 9443 | offscreen_saved_color_format_); |
| 9444 | } else { |
| 9445 | // Flip the textures in the parent context via the texture manager. |
| 9446 | if (!!offscreen_saved_color_texture_info_.get()) |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9447 | offscreen_saved_color_texture_info_->texture()-> |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9448 | SetServiceId(offscreen_target_color_texture_->id()); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 9449 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9450 | offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); |
| 9451 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 9452 | offscreen_target_color_texture_.get()); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 9453 | } |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9454 | |
| 9455 | // Ensure the side effects of the copy are visible to the parent |
| 9456 | // context. There is no need to do this for ANGLE because it uses a |
| 9457 | // single D3D device for all contexts. |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 9458 | if (!feature_info_->feature_flags().is_angle) |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9459 | glFlush(); |
[email protected] | 0c8c9d2 | 2010-06-25 17:36:39 | [diff] [blame] | 9460 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9461 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 9462 | if (!surface_->SwapBuffers()) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 9463 | LOG(ERROR) << "Context lost because SwapBuffers failed."; |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9464 | LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 9465 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9466 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 9467 | |
| 9468 | // This may be a slow command. Exit command processing to allow for |
| 9469 | // context preemption and GPU watchdog checks. |
| 9470 | ExitCommandProcessingEarly(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9471 | } |
| 9472 | |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 9473 | error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9474 | uint32 immediate_data_size, |
| 9475 | const void* cmd_data) { |
| 9476 | const gles2::cmds::EnableFeatureCHROMIUM& c = |
| 9477 | *static_cast<const gles2::cmds::EnableFeatureCHROMIUM*>(cmd_data); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9478 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9479 | if (!bucket || bucket->size() == 0) { |
| 9480 | return error::kInvalidArguments; |
| 9481 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9482 | typedef cmds::EnableFeatureCHROMIUM::Result Result; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9483 | Result* result = GetSharedMemoryAs<Result*>( |
| 9484 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9485 | if (!result) { |
| 9486 | return error::kOutOfBounds; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 9487 | } |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9488 | // Check that the client initialized the result. |
| 9489 | if (*result != 0) { |
| 9490 | return error::kInvalidArguments; |
| 9491 | } |
| 9492 | std::string feature_str; |
| 9493 | if (!bucket->GetAsString(&feature_str)) { |
| 9494 | return error::kInvalidArguments; |
| 9495 | } |
| 9496 | |
| 9497 | // TODO(gman): make this some kind of table to function pointer thingy. |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 9498 | if (feature_str.compare("pepper3d_allow_buffers_on_multiple_targets") == 0) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9499 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 9500 | } else if (feature_str.compare("pepper3d_support_fixed_attribs") == 0) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 9501 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
| 9502 | // TODO(gman): decide how to remove the need for this const_cast. |
| 9503 | // I could make validators_ non const but that seems bad as this is the only |
| 9504 | // place it is needed. I could make some special friend class of validators |
| 9505 | // just to allow this to set them. That seems silly. I could refactor this |
| 9506 | // code to use the extension mechanism or the initialization attributes to |
| 9507 | // turn this feature on. Given that the only real point of this is to make |
| 9508 | // the conformance tests pass and given that there is lots of real work that |
| 9509 | // needs to be done it seems like refactoring for one to one of those |
| 9510 | // methods is a very low priority. |
| 9511 | const_cast<Validators*>(validators_)->vertex_attrib_type.AddValue(GL_FIXED); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 9512 | } else if (feature_str.compare("webgl_enable_glsl_webgl_validation") == 0) { |
| 9513 | force_webgl_glsl_validation_ = true; |
| 9514 | InitializeShaderTranslator(); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9515 | } else { |
| 9516 | return error::kNoError; |
| 9517 | } |
| 9518 | |
| 9519 | *result = 1; // true. |
| 9520 | return error::kNoError; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 9521 | } |
| 9522 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9523 | error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( |
| 9524 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9525 | const void* cmd_data) { |
| 9526 | const gles2::cmds::GetRequestableExtensionsCHROMIUM& c = |
| 9527 | *static_cast<const gles2::cmds::GetRequestableExtensionsCHROMIUM*>( |
| 9528 | cmd_data); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9529 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9530 | scoped_refptr<FeatureInfo> info(new FeatureInfo()); |
[email protected] | 956aec5 | 2013-09-05 15:41:19 | [diff] [blame] | 9531 | info->Initialize(disallowed_features_); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9532 | bucket->SetFromString(info->extensions().c_str()); |
| 9533 | return error::kNoError; |
| 9534 | } |
| 9535 | |
| 9536 | error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9537 | uint32 immediate_data_size, |
| 9538 | const void* cmd_data) { |
| 9539 | const gles2::cmds::RequestExtensionCHROMIUM& c = |
| 9540 | *static_cast<const gles2::cmds::RequestExtensionCHROMIUM*>(cmd_data); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9541 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9542 | if (!bucket || bucket->size() == 0) { |
| 9543 | return error::kInvalidArguments; |
| 9544 | } |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9545 | std::string feature_str; |
| 9546 | if (!bucket->GetAsString(&feature_str)) { |
| 9547 | return error::kInvalidArguments; |
| 9548 | } |
| 9549 | |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 9550 | bool desire_webgl_glsl_validation = |
| 9551 | feature_str.find("GL_CHROMIUM_webglsl") != std::string::npos; |
| 9552 | bool desire_standard_derivatives = false; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9553 | bool desire_frag_depth = false; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9554 | bool desire_draw_buffers = false; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 9555 | bool desire_shader_texture_lod = false; |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 9556 | if (force_webgl_glsl_validation_) { |
| 9557 | desire_standard_derivatives = |
| 9558 | feature_str.find("GL_OES_standard_derivatives") != std::string::npos; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9559 | desire_frag_depth = |
| 9560 | feature_str.find("GL_EXT_frag_depth") != std::string::npos; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9561 | desire_draw_buffers = |
| 9562 | feature_str.find("GL_EXT_draw_buffers") != std::string::npos; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 9563 | desire_shader_texture_lod = |
| 9564 | feature_str.find("GL_EXT_shader_texture_lod") != std::string::npos; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 9565 | } |
| 9566 | |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 9567 | if (desire_webgl_glsl_validation != force_webgl_glsl_validation_ || |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9568 | desire_standard_derivatives != derivatives_explicitly_enabled_ || |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9569 | desire_frag_depth != frag_depth_explicitly_enabled_ || |
| 9570 | desire_draw_buffers != draw_buffers_explicitly_enabled_) { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9571 | force_webgl_glsl_validation_ |= desire_webgl_glsl_validation; |
| 9572 | derivatives_explicitly_enabled_ |= desire_standard_derivatives; |
| 9573 | frag_depth_explicitly_enabled_ |= desire_frag_depth; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9574 | draw_buffers_explicitly_enabled_ |= desire_draw_buffers; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 9575 | shader_texture_lod_explicitly_enabled_ |= desire_shader_texture_lod; |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9576 | InitializeShaderTranslator(); |
| 9577 | } |
| 9578 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 9579 | UpdateCapabilities(); |
| 9580 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9581 | return error::kNoError; |
| 9582 | } |
| 9583 | |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9584 | error::Error GLES2DecoderImpl::HandleGetMultipleIntegervCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9585 | uint32 immediate_data_size, |
| 9586 | const void* cmd_data) { |
| 9587 | const gles2::cmds::GetMultipleIntegervCHROMIUM& c = |
| 9588 | *static_cast<const gles2::cmds::GetMultipleIntegervCHROMIUM*>(cmd_data); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9589 | GLuint count = c.count; |
| 9590 | uint32 pnames_size; |
| 9591 | if (!SafeMultiplyUint32(count, sizeof(GLenum), &pnames_size)) { |
| 9592 | return error::kOutOfBounds; |
| 9593 | } |
| 9594 | const GLenum* pnames = GetSharedMemoryAs<const GLenum*>( |
| 9595 | c.pnames_shm_id, c.pnames_shm_offset, pnames_size); |
| 9596 | if (pnames == NULL) { |
| 9597 | return error::kOutOfBounds; |
| 9598 | } |
| 9599 | |
| 9600 | // We have to copy them since we use them twice so the client |
| 9601 | // can't change them between the time we validate them and the time we use |
| 9602 | // them. |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 9603 | scoped_ptr<GLenum[]> enums(new GLenum[count]); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9604 | memcpy(enums.get(), pnames, pnames_size); |
| 9605 | |
| 9606 | // Count up the space needed for the result. |
| 9607 | uint32 num_results = 0; |
| 9608 | for (GLuint ii = 0; ii < count; ++ii) { |
| 9609 | uint32 num = util_.GLGetNumValuesReturned(enums[ii]); |
| 9610 | if (num == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9611 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 9612 | "glGetMultipleCHROMIUM", enums[ii], "pname"); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9613 | return error::kNoError; |
| 9614 | } |
| 9615 | // Num will never be more than 4. |
| 9616 | DCHECK_LE(num, 4u); |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 9617 | if (!SafeAddUint32(num_results, num, &num_results)) { |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9618 | return error::kOutOfBounds; |
| 9619 | } |
| 9620 | } |
| 9621 | |
| 9622 | uint32 result_size = 0; |
| 9623 | if (!SafeMultiplyUint32(num_results, sizeof(GLint), &result_size)) { |
| 9624 | return error::kOutOfBounds; |
| 9625 | } |
| 9626 | |
| 9627 | if (result_size != static_cast<uint32>(c.size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9628 | LOCAL_SET_GL_ERROR( |
| 9629 | GL_INVALID_VALUE, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 9630 | "glGetMultipleCHROMIUM", "bad size GL_INVALID_VALUE"); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9631 | return error::kNoError; |
| 9632 | } |
| 9633 | |
| 9634 | GLint* results = GetSharedMemoryAs<GLint*>( |
| 9635 | c.results_shm_id, c.results_shm_offset, result_size); |
| 9636 | if (results == NULL) { |
| 9637 | return error::kOutOfBounds; |
| 9638 | } |
| 9639 | |
| 9640 | // Check the results have been cleared in case the context was lost. |
| 9641 | for (uint32 ii = 0; ii < num_results; ++ii) { |
| 9642 | if (results[ii]) { |
| 9643 | return error::kInvalidArguments; |
| 9644 | } |
| 9645 | } |
| 9646 | |
| 9647 | // Get each result. |
| 9648 | GLint* start = results; |
| 9649 | for (GLuint ii = 0; ii < count; ++ii) { |
| 9650 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 9651 | if (!state_.GetStateAsGLint(enums[ii], results, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 9652 | !GetHelper(enums[ii], results, &num_written)) { |
[email protected] | b0ce098 | 2013-05-13 18:51:48 | [diff] [blame] | 9653 | DoGetIntegerv(enums[ii], results); |
[email protected] | 372e041 | 2011-06-28 16:08:56 | [diff] [blame] | 9654 | } |
| 9655 | results += num_written; |
| 9656 | } |
| 9657 | |
| 9658 | // Just to verify. Should this be a DCHECK? |
| 9659 | if (static_cast<uint32>(results - start) != num_results) { |
| 9660 | return error::kOutOfBounds; |
| 9661 | } |
| 9662 | |
| 9663 | return error::kNoError; |
| 9664 | } |
| 9665 | |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9666 | error::Error GLES2DecoderImpl::HandleGetProgramInfoCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9667 | uint32 immediate_data_size, |
| 9668 | const void* cmd_data) { |
| 9669 | const gles2::cmds::GetProgramInfoCHROMIUM& c = |
| 9670 | *static_cast<const gles2::cmds::GetProgramInfoCHROMIUM*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9671 | GLuint program_id = static_cast<GLuint>(c.program); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9672 | uint32 bucket_id = c.bucket_id; |
| 9673 | Bucket* bucket = CreateBucket(bucket_id); |
| 9674 | bucket->SetSize(sizeof(ProgramInfoHeader)); // in case we fail. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9675 | Program* program = NULL; |
| 9676 | program = GetProgram(program_id); |
| 9677 | if (!program || !program->IsValid()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 9678 | return error::kNoError; |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9679 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9680 | program->GetProgramInfo(program_manager(), bucket); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9681 | return error::kNoError; |
| 9682 | } |
| 9683 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9684 | error::ContextLostReason GLES2DecoderImpl::GetContextLostReason() { |
| 9685 | switch (reset_status_) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9686 | case GL_NO_ERROR: |
| 9687 | // TODO(kbr): improve the precision of the error code in this case. |
| 9688 | // Consider delegating to context for error code if MakeCurrent fails. |
| 9689 | return error::kUnknown; |
| 9690 | case GL_GUILTY_CONTEXT_RESET_ARB: |
| 9691 | return error::kGuilty; |
| 9692 | case GL_INNOCENT_CONTEXT_RESET_ARB: |
| 9693 | return error::kInnocent; |
| 9694 | case GL_UNKNOWN_CONTEXT_RESET_ARB: |
| 9695 | return error::kUnknown; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9696 | } |
| 9697 | |
| 9698 | NOTREACHED(); |
| 9699 | return error::kUnknown; |
| 9700 | } |
| 9701 | |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 9702 | void GLES2DecoderImpl::MaybeExitOnContextLost() { |
| 9703 | // Some D3D drivers cannot recover from device lost in the GPU process |
| 9704 | // sandbox. Allow a new GPU process to launch. |
| 9705 | if (workarounds().exit_on_context_lost) { |
| 9706 | LOG(ERROR) << "Exiting GPU process because some drivers cannot reset" |
| 9707 | << " a D3D device in the Chrome GPU process sandbox."; |
| 9708 | #if defined(OS_WIN) |
| 9709 | base::win::SetShouldCrashOnProcessDetach(false); |
| 9710 | #endif |
| 9711 | exit(0); |
| 9712 | } |
| 9713 | } |
| 9714 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9715 | bool GLES2DecoderImpl::WasContextLost() { |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9716 | if (reset_status_ != GL_NO_ERROR) { |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 9717 | MaybeExitOnContextLost(); |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9718 | return true; |
| 9719 | } |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 9720 | if (context_->WasAllocatedUsingRobustnessExtension()) { |
| 9721 | GLenum status = GL_NO_ERROR; |
| 9722 | if (has_robustness_extension_) |
| 9723 | status = glGetGraphicsResetStatusARB(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9724 | if (status != GL_NO_ERROR) { |
| 9725 | // The graphics card was reset. Signal a lost context to the application. |
| 9726 | reset_status_ = status; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 9727 | reset_by_robustness_extension_ = true; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9728 | LOG(ERROR) << (surface_->IsOffscreen() ? "Offscreen" : "Onscreen") |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9729 | << " context lost via ARB/EXT_robustness. Reset status = " |
| 9730 | << GLES2Util::GetStringEnum(status); |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 9731 | MaybeExitOnContextLost(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9732 | return true; |
| 9733 | } |
| 9734 | } |
| 9735 | return false; |
| 9736 | } |
| 9737 | |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 9738 | bool GLES2DecoderImpl::WasContextLostByRobustnessExtension() { |
| 9739 | return WasContextLost() && reset_by_robustness_extension_; |
| 9740 | } |
| 9741 | |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9742 | void GLES2DecoderImpl::LoseContext(uint32 reset_status) { |
| 9743 | // Only loses the context once. |
| 9744 | if (reset_status_ != GL_NO_ERROR) { |
| 9745 | return; |
| 9746 | } |
| 9747 | |
| 9748 | // Marks this context as lost. |
| 9749 | reset_status_ = reset_status; |
| 9750 | current_decoder_error_ = error::kLostContext; |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 9751 | } |
| 9752 | |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 9753 | error::Error GLES2DecoderImpl::HandleInsertSyncPointCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9754 | uint32 immediate_data_size, |
| 9755 | const void* cmd_data) { |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 9756 | return error::kUnknownCommand; |
| 9757 | } |
| 9758 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 9759 | error::Error GLES2DecoderImpl::HandleWaitSyncPointCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9760 | uint32 immediate_data_size, |
| 9761 | const void* cmd_data) { |
| 9762 | const gles2::cmds::WaitSyncPointCHROMIUM& c = |
| 9763 | *static_cast<const gles2::cmds::WaitSyncPointCHROMIUM*>(cmd_data); |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 9764 | group_->mailbox_manager()->PullTextureUpdates(); |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 9765 | if (wait_sync_point_callback_.is_null()) |
| 9766 | return error::kNoError; |
| 9767 | |
| 9768 | return wait_sync_point_callback_.Run(c.sync_point) ? |
| 9769 | error::kNoError : error::kDeferCommandUntilLater; |
| 9770 | } |
| 9771 | |
[email protected] | 5dfc457b | 2013-12-13 11:13:07 | [diff] [blame] | 9772 | error::Error GLES2DecoderImpl::HandleDiscardBackbufferCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9773 | uint32 immediate_data_size, |
| 9774 | const void* cmd_data) { |
[email protected] | 5dfc457b | 2013-12-13 11:13:07 | [diff] [blame] | 9775 | if (surface_->DeferDraws()) |
| 9776 | return error::kDeferCommandUntilLater; |
| 9777 | if (!surface_->SetBackbufferAllocation(false)) |
| 9778 | return error::kLostContext; |
| 9779 | backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| 9780 | backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
| 9781 | backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
| 9782 | return error::kNoError; |
| 9783 | } |
| 9784 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9785 | bool GLES2DecoderImpl::GenQueriesEXTHelper( |
| 9786 | GLsizei n, const GLuint* client_ids) { |
| 9787 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9788 | if (query_manager_->GetQuery(client_ids[ii])) { |
| 9789 | return false; |
| 9790 | } |
| 9791 | } |
[email protected] | 4eea7e6 | 2014-04-22 21:14:43 | [diff] [blame] | 9792 | query_manager_->GenQueries(n, client_ids); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9793 | return true; |
| 9794 | } |
| 9795 | |
| 9796 | void GLES2DecoderImpl::DeleteQueriesEXTHelper( |
| 9797 | GLsizei n, const GLuint* client_ids) { |
| 9798 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9799 | QueryManager::Query* query = query_manager_->GetQuery(client_ids[ii]); |
| 9800 | if (query && !query->IsDeleted()) { |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9801 | ContextState::QueryMap::iterator it = |
| 9802 | state_.current_queries.find(query->target()); |
| 9803 | if (it != state_.current_queries.end()) |
| 9804 | state_.current_queries.erase(it); |
| 9805 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9806 | query->Destroy(true); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9807 | } |
[email protected] | 4eea7e6 | 2014-04-22 21:14:43 | [diff] [blame] | 9808 | query_manager_->RemoveQuery(client_ids[ii]); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9809 | } |
| 9810 | } |
| 9811 | |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 9812 | bool GLES2DecoderImpl::ProcessPendingQueries() { |
| 9813 | if (query_manager_.get() == NULL) { |
| 9814 | return false; |
| 9815 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9816 | if (!query_manager_->ProcessPendingQueries()) { |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 9817 | current_decoder_error_ = error::kOutOfBounds; |
| 9818 | } |
| 9819 | return query_manager_->HavePendingQueries(); |
| 9820 | } |
| 9821 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9822 | // Note that if there are no pending readpixels right now, |
| 9823 | // this function will call the callback immediately. |
| 9824 | void GLES2DecoderImpl::WaitForReadPixels(base::Closure callback) { |
| 9825 | if (features().use_async_readpixels && !pending_readpixel_fences_.empty()) { |
| 9826 | pending_readpixel_fences_.back()->callbacks.push_back(callback); |
| 9827 | } else { |
| 9828 | callback.Run(); |
| 9829 | } |
| 9830 | } |
| 9831 | |
| 9832 | void GLES2DecoderImpl::ProcessPendingReadPixels() { |
| 9833 | while (!pending_readpixel_fences_.empty() && |
| 9834 | pending_readpixel_fences_.front()->fence->HasCompleted()) { |
| 9835 | std::vector<base::Closure> callbacks = |
| 9836 | pending_readpixel_fences_.front()->callbacks; |
| 9837 | pending_readpixel_fences_.pop(); |
| 9838 | for (size_t i = 0; i < callbacks.size(); i++) { |
| 9839 | callbacks[i].Run(); |
| 9840 | } |
| 9841 | } |
| 9842 | } |
| 9843 | |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9844 | bool GLES2DecoderImpl::HasMoreIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9845 | return !pending_readpixel_fences_.empty() || |
| 9846 | async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9847 | } |
| 9848 | |
| 9849 | void GLES2DecoderImpl::PerformIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 9850 | ProcessPendingReadPixels(); |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 9851 | if (!async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers()) |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9852 | return; |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 9853 | async_pixel_transfer_manager_->ProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 9854 | ProcessFinishedAsyncTransfers(); |
| 9855 | } |
| 9856 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9857 | error::Error GLES2DecoderImpl::HandleBeginQueryEXT(uint32 immediate_data_size, |
| 9858 | const void* cmd_data) { |
| 9859 | const gles2::cmds::BeginQueryEXT& c = |
| 9860 | *static_cast<const gles2::cmds::BeginQueryEXT*>(cmd_data); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9861 | GLenum target = static_cast<GLenum>(c.target); |
| 9862 | GLuint client_id = static_cast<GLuint>(c.id); |
| 9863 | int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id); |
| 9864 | uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 9865 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9866 | switch (target) { |
| 9867 | case GL_COMMANDS_ISSUED_CHROMIUM: |
[email protected] | fb4bf582 | 2012-10-23 21:25:55 | [diff] [blame] | 9868 | case GL_LATENCY_QUERY_CHROMIUM: |
[email protected] | 5537605d | 2013-08-27 05:22:31 | [diff] [blame] | 9869 | case GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM: |
| 9870 | case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM: |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 9871 | case GL_GET_ERROR_QUERY_CHROMIUM: |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9872 | break; |
[email protected] | 6a25ae42 | 2014-04-17 23:48:27 | [diff] [blame] | 9873 | case GL_COMMANDS_COMPLETED_CHROMIUM: |
| 9874 | if (!features().chromium_sync_query) { |
| 9875 | LOCAL_SET_GL_ERROR( |
| 9876 | GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 9877 | "not enabled for commands completed queries"); |
| 9878 | return error::kNoError; |
| 9879 | } |
| 9880 | break; |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9881 | default: |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9882 | if (!features().occlusion_query_boolean) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9883 | LOCAL_SET_GL_ERROR( |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 9884 | GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 9885 | "not enabled for occlusion queries"); |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9886 | return error::kNoError; |
| 9887 | } |
| 9888 | break; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9889 | } |
| 9890 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9891 | if (state_.current_queries.find(target) != state_.current_queries.end()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9892 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9893 | GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9894 | return error::kNoError; |
| 9895 | } |
| 9896 | |
| 9897 | if (client_id == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9898 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9899 | return error::kNoError; |
| 9900 | } |
| 9901 | |
| 9902 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 9903 | if (!query) { |
[email protected] | 4eea7e6 | 2014-04-22 21:14:43 | [diff] [blame] | 9904 | if (!query_manager_->IsValidQuery(client_id)) { |
| 9905 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 9906 | "glBeginQueryEXT", |
| 9907 | "id not made by glGenQueriesEXT"); |
| 9908 | return error::kNoError; |
| 9909 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9910 | query = query_manager_->CreateQuery( |
| 9911 | target, client_id, sync_shm_id, sync_shm_offset); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9912 | } |
| 9913 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9914 | if (query->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9915 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9916 | GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9917 | return error::kNoError; |
| 9918 | } else if (query->shm_id() != sync_shm_id || |
| 9919 | query->shm_offset() != sync_shm_offset) { |
| 9920 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 9921 | return error::kInvalidArguments; |
| 9922 | } |
| 9923 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9924 | if (!query_manager_->BeginQuery(query)) { |
| 9925 | return error::kOutOfBounds; |
| 9926 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9927 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9928 | state_.current_queries[target] = query; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9929 | return error::kNoError; |
| 9930 | } |
| 9931 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9932 | error::Error GLES2DecoderImpl::HandleEndQueryEXT(uint32 immediate_data_size, |
| 9933 | const void* cmd_data) { |
| 9934 | const gles2::cmds::EndQueryEXT& c = |
| 9935 | *static_cast<const gles2::cmds::EndQueryEXT*>(cmd_data); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9936 | GLenum target = static_cast<GLenum>(c.target); |
| 9937 | uint32 submit_count = static_cast<GLuint>(c.submit_count); |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9938 | ContextState::QueryMap::iterator it = state_.current_queries.find(target); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9939 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9940 | if (it == state_.current_queries.end()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9941 | LOCAL_SET_GL_ERROR( |
| 9942 | GL_INVALID_OPERATION, "glEndQueryEXT", "No active query"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9943 | return error::kNoError; |
| 9944 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9945 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9946 | QueryManager::Query* query = it->second.get(); |
| 9947 | if (!query_manager_->EndQuery(query, submit_count)) { |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 9948 | return error::kOutOfBounds; |
| 9949 | } |
| 9950 | |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 9951 | query_manager_->ProcessPendingTransferQueries(); |
| 9952 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 9953 | state_.current_queries.erase(it); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 9954 | return error::kNoError; |
| 9955 | } |
| 9956 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9957 | bool GLES2DecoderImpl::GenVertexArraysOESHelper( |
| 9958 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9959 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9960 | if (GetVertexAttribManager(client_ids[ii])) { |
| 9961 | return false; |
| 9962 | } |
| 9963 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9964 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9965 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9966 | // Emulated VAO |
| 9967 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 9968 | CreateVertexAttribManager(client_ids[ii], 0, true); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9969 | } |
| 9970 | } else { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 9971 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9972 | |
| 9973 | glGenVertexArraysOES(n, service_ids.get()); |
| 9974 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 9975 | CreateVertexAttribManager(client_ids[ii], service_ids[ii], true); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9976 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9977 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 9978 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9979 | return true; |
| 9980 | } |
| 9981 | |
| 9982 | void GLES2DecoderImpl::DeleteVertexArraysOESHelper( |
| 9983 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9984 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 9985 | VertexAttribManager* vao = |
| 9986 | GetVertexAttribManager(client_ids[ii]); |
| 9987 | if (vao && !vao->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 9988 | if (state_.vertex_attrib_manager.get() == vao) { |
[email protected] | 242c982 | 2014-04-15 21:36:11 | [diff] [blame] | 9989 | DoBindVertexArrayOES(0); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9990 | } |
| 9991 | RemoveVertexAttribManager(client_ids[ii]); |
| 9992 | } |
| 9993 | } |
| 9994 | } |
| 9995 | |
| 9996 | void GLES2DecoderImpl::DoBindVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9997 | VertexAttribManager* vao = NULL; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 9998 | if (client_id != 0) { |
| 9999 | vao = GetVertexAttribManager(client_id); |
| 10000 | if (!vao) { |
| 10001 | // Unlike most Bind* methods, the spec explicitly states that VertexArray |
| 10002 | // only allows names that have been previously generated. As such, we do |
| 10003 | // not generate new names here. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10004 | LOCAL_SET_GL_ERROR( |
| 10005 | GL_INVALID_OPERATION, |
| 10006 | "glBindVertexArrayOES", "bad vertex array id."); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10007 | current_decoder_error_ = error::kNoError; |
| 10008 | return; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10009 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10010 | } else { |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 10011 | vao = state_.default_vertex_attrib_manager.get(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10012 | } |
| 10013 | |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10014 | // Only set the VAO state if it's changed |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 10015 | if (state_.vertex_attrib_manager.get() != vao) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 10016 | state_.vertex_attrib_manager = vao; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 10017 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10018 | EmulateVertexArrayState(); |
| 10019 | } else { |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 10020 | GLuint service_id = vao->service_id(); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10021 | glBindVertexArrayOES(service_id); |
| 10022 | } |
| 10023 | } |
| 10024 | } |
| 10025 | |
| 10026 | // Used when OES_vertex_array_object isn't natively supported |
| 10027 | void GLES2DecoderImpl::EmulateVertexArrayState() { |
| 10028 | // Setup the Vertex attribute state |
| 10029 | for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) { |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 10030 | RestoreStateForAttrib(vv, true); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10031 | } |
| 10032 | |
| 10033 | // Setup the element buffer |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 10034 | Buffer* element_array_buffer = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 10035 | state_.vertex_attrib_manager->element_array_buffer(); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10036 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 10037 | element_array_buffer ? element_array_buffer->service_id() : 0); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10038 | } |
| 10039 | |
| 10040 | bool GLES2DecoderImpl::DoIsVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10041 | const VertexAttribManager* vao = |
| 10042 | GetVertexAttribManager(client_id); |
| 10043 | return vao && vao->IsValid() && !vao->IsDeleted(); |
| 10044 | } |
| 10045 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10046 | #if defined(OS_MACOSX) |
| 10047 | void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { |
| 10048 | TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( |
| 10049 | texture_id); |
| 10050 | if (it != texture_to_io_surface_map_.end()) { |
| 10051 | // Found a previous IOSurface bound to this texture; release it. |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 10052 | IOSurfaceRef surface = it->second; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10053 | CFRelease(surface); |
| 10054 | texture_to_io_surface_map_.erase(it); |
| 10055 | } |
| 10056 | } |
| 10057 | #endif |
| 10058 | |
| 10059 | void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( |
| 10060 | GLenum target, GLsizei width, GLsizei height, |
| 10061 | GLuint io_surface_id, GLuint plane) { |
| 10062 | #if defined(OS_MACOSX) |
| 10063 | if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10064 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10065 | GL_INVALID_OPERATION, |
| 10066 | "glTexImageIOSurface2DCHROMIUM", "only supported on desktop GL."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10067 | return; |
| 10068 | } |
| 10069 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10070 | if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 10071 | // This might be supported in the future, and if we could require |
| 10072 | // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we |
| 10073 | // could delete a lot of code. For now, perform strict validation so we |
| 10074 | // know what's going on. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10075 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10076 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10077 | "glTexImageIOSurface2DCHROMIUM", |
| 10078 | "requires TEXTURE_RECTANGLE_ARB target"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10079 | return; |
| 10080 | } |
| 10081 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10082 | // Default target might be conceptually valid, but disallow it to avoid |
| 10083 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10084 | TextureRef* texture_ref = |
| 10085 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10086 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10087 | LOCAL_SET_GL_ERROR( |
| 10088 | GL_INVALID_OPERATION, |
| 10089 | "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10090 | return; |
| 10091 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10092 | |
| 10093 | // Look up the new IOSurface. Note that because of asynchrony |
| 10094 | // between processes this might fail; during live resizing the |
| 10095 | // plugin process might allocate and release an IOSurface before |
| 10096 | // this process gets a chance to look it up. Hold on to any old |
| 10097 | // IOSurface in this case. |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 10098 | IOSurfaceRef surface = IOSurfaceLookup(io_surface_id); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10099 | if (!surface) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10100 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10101 | GL_INVALID_OPERATION, |
| 10102 | "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10103 | return; |
| 10104 | } |
| 10105 | |
| 10106 | // Release any IOSurface previously bound to this texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10107 | ReleaseIOSurfaceForTexture(texture_ref->service_id()); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10108 | |
| 10109 | // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. |
| 10110 | texture_to_io_surface_map_.insert( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10111 | std::make_pair(texture_ref->service_id(), surface)); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10112 | |
| 10113 | CGLContextObj context = |
| 10114 | static_cast<CGLContextObj>(context_->GetHandle()); |
| 10115 | |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 10116 | CGLError err = CGLTexImageIOSurface2D( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10117 | context, |
| 10118 | target, |
| 10119 | GL_RGBA, |
| 10120 | width, |
| 10121 | height, |
| 10122 | GL_BGRA, |
| 10123 | GL_UNSIGNED_INT_8_8_8_8_REV, |
| 10124 | surface, |
| 10125 | plane); |
| 10126 | |
| 10127 | if (err != kCGLNoError) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10128 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10129 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10130 | "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10131 | return; |
| 10132 | } |
| 10133 | |
| 10134 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10135 | texture_ref, target, 0, GL_RGBA, width, height, 1, 0, |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10136 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); |
| 10137 | |
| 10138 | #else |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10139 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10140 | "glTexImageIOSurface2DCHROMIUM", "not supported."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10141 | #endif |
| 10142 | } |
| 10143 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10144 | static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { |
| 10145 | switch (internalformat) { |
| 10146 | case GL_RGB565: |
| 10147 | return GL_RGB; |
| 10148 | case GL_RGBA4: |
| 10149 | return GL_RGBA; |
| 10150 | case GL_RGB5_A1: |
| 10151 | return GL_RGBA; |
| 10152 | case GL_RGB8_OES: |
| 10153 | return GL_RGB; |
| 10154 | case GL_RGBA8_OES: |
| 10155 | return GL_RGBA; |
| 10156 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 10157 | return GL_LUMINANCE_ALPHA; |
| 10158 | case GL_LUMINANCE8_EXT: |
| 10159 | return GL_LUMINANCE; |
| 10160 | case GL_ALPHA8_EXT: |
| 10161 | return GL_ALPHA; |
| 10162 | case GL_RGBA32F_EXT: |
| 10163 | return GL_RGBA; |
| 10164 | case GL_RGB32F_EXT: |
| 10165 | return GL_RGB; |
| 10166 | case GL_ALPHA32F_EXT: |
| 10167 | return GL_ALPHA; |
| 10168 | case GL_LUMINANCE32F_EXT: |
| 10169 | return GL_LUMINANCE; |
| 10170 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 10171 | return GL_LUMINANCE_ALPHA; |
| 10172 | case GL_RGBA16F_EXT: |
| 10173 | return GL_RGBA; |
| 10174 | case GL_RGB16F_EXT: |
| 10175 | return GL_RGB; |
| 10176 | case GL_ALPHA16F_EXT: |
| 10177 | return GL_ALPHA; |
| 10178 | case GL_LUMINANCE16F_EXT: |
| 10179 | return GL_LUMINANCE; |
| 10180 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 10181 | return GL_LUMINANCE_ALPHA; |
| 10182 | case GL_BGRA8_EXT: |
| 10183 | return GL_BGRA_EXT; |
bajones | 2a2ea23 | 2014-10-13 21:38:59 | [diff] [blame] | 10184 | case GL_SRGB8_ALPHA8_EXT: |
| 10185 | return GL_SRGB_ALPHA_EXT; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10186 | default: |
| 10187 | return GL_NONE; |
| 10188 | } |
| 10189 | } |
| 10190 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10191 | void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10192 | GLenum target, GLuint source_id, GLuint dest_id, GLint level, |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 10193 | GLenum internal_format, GLenum dest_type) { |
[email protected] | 1e24dc7f | 2014-04-14 02:40:08 | [diff] [blame] | 10194 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); |
| 10195 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10196 | TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 10197 | TextureRef* source_texture_ref = GetTexture(source_id); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10198 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10199 | if (!source_texture_ref || !dest_texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10200 | LOCAL_SET_GL_ERROR( |
| 10201 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10202 | return; |
| 10203 | } |
| 10204 | |
| 10205 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10206 | LOCAL_SET_GL_ERROR( |
| 10207 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid texture target"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10208 | return; |
| 10209 | } |
| 10210 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10211 | Texture* source_texture = source_texture_ref->texture(); |
| 10212 | Texture* dest_texture = dest_texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10213 | if (dest_texture->target() != GL_TEXTURE_2D || |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 10214 | (source_texture->target() != GL_TEXTURE_2D && |
[email protected] | 041d463f | 2014-04-30 05:38:34 | [diff] [blame] | 10215 | source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && |
| 10216 | source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 10217 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 10218 | "glCopyTextureCHROMIUM", |
| 10219 | "invalid texture target binding"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10220 | return; |
| 10221 | } |
| 10222 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10223 | int source_width, source_height, dest_width, dest_height; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10224 | |
[email protected] | 3e0dfd7 | 2014-02-21 06:28:41 | [diff] [blame] | 10225 | gfx::GLImage* image = |
| 10226 | source_texture->GetLevelImage(source_texture->target(), 0); |
| 10227 | if (image) { |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 10228 | gfx::Size size = image->GetSize(); |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 10229 | source_width = size.width(); |
| 10230 | source_height = size.height(); |
| 10231 | if (source_width <= 0 || source_height <= 0) { |
| 10232 | LOCAL_SET_GL_ERROR( |
| 10233 | GL_INVALID_VALUE, |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 10234 | "glCopyTextureChromium", "invalid image size"); |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 10235 | return; |
| 10236 | } |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 10237 | } else { |
| 10238 | if (!source_texture->GetLevelSize( |
| 10239 | source_texture->target(), 0, &source_width, &source_height)) { |
| 10240 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 10241 | "glCopyTextureChromium", |
| 10242 | "source texture has no level 0"); |
| 10243 | return; |
| 10244 | } |
| 10245 | |
| 10246 | // Check that this type of texture is allowed. |
| 10247 | if (!texture_manager()->ValidForTarget( |
| 10248 | source_texture->target(), level, source_width, source_height, 1)) { |
| 10249 | LOCAL_SET_GL_ERROR( |
| 10250 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); |
| 10251 | return; |
| 10252 | } |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 10253 | } |
| 10254 | |
[email protected] | 04b5b37d | 2014-02-07 02:11:51 | [diff] [blame] | 10255 | // Clear the source texture if necessary. |
| 10256 | if (!texture_manager()->ClearTextureLevel( |
| 10257 | this, source_texture_ref, source_texture->target(), 0)) { |
| 10258 | LOCAL_SET_GL_ERROR( |
| 10259 | GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", "dimensions too big"); |
| 10260 | return; |
| 10261 | } |
| 10262 | |
[email protected] | a6e3d28 | 2014-08-22 22:20:44 | [diff] [blame] | 10263 | GLenum source_type = 0; |
| 10264 | GLenum source_internal_format = 0; |
| 10265 | source_texture->GetLevelType( |
| 10266 | source_texture->target(), 0, &source_type, &source_internal_format); |
| 10267 | |
| 10268 | // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, |
| 10269 | // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not |
| 10270 | // renderable on some platforms. |
reveman | 6b0fbe4 | 2014-09-04 00:55:03 | [diff] [blame] | 10271 | bool valid_dest_format = internal_format == GL_RGB || |
| 10272 | internal_format == GL_RGBA || |
| 10273 | internal_format == GL_BGRA_EXT; |
[email protected] | a6e3d28 | 2014-08-22 22:20:44 | [diff] [blame] | 10274 | bool valid_source_format = source_internal_format == GL_ALPHA || |
| 10275 | source_internal_format == GL_RGB || |
| 10276 | source_internal_format == GL_RGBA || |
| 10277 | source_internal_format == GL_LUMINANCE || |
| 10278 | source_internal_format == GL_LUMINANCE_ALPHA || |
| 10279 | source_internal_format == GL_BGRA_EXT; |
| 10280 | if (!valid_source_format || !valid_dest_format) { |
| 10281 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10282 | "glCopyTextureCHROMIUM", |
| 10283 | "invalid internal format"); |
| 10284 | return; |
| 10285 | } |
| 10286 | |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 10287 | // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 10288 | // needed because it takes 10s of milliseconds to initialize. |
| 10289 | if (!copy_texture_CHROMIUM_.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10290 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 10291 | copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
[email protected] | 07a0cc3 | 2013-02-28 00:36:27 | [diff] [blame] | 10292 | copy_texture_CHROMIUM_->Initialize(this); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 10293 | RestoreCurrentFramebufferBindings(); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10294 | if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 10295 | return; |
| 10296 | } |
| 10297 | |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 10298 | GLenum dest_type_previous = dest_type; |
| 10299 | GLenum dest_internal_format = internal_format; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10300 | bool dest_level_defined = dest_texture->GetLevelSize( |
| 10301 | GL_TEXTURE_2D, level, &dest_width, &dest_height); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10302 | |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10303 | if (dest_level_defined) { |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 10304 | dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10305 | &dest_internal_format); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10306 | } |
| 10307 | |
| 10308 | // Resize the destination texture to the dimensions of the source texture. |
| 10309 | if (!dest_level_defined || dest_width != source_width || |
| 10310 | dest_height != source_height || |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 10311 | dest_internal_format != internal_format || |
| 10312 | dest_type_previous != dest_type) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10313 | // Ensure that the glTexImage2D succeeds. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10314 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10315 | glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 10316 | glTexImage2D( |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10317 | GL_TEXTURE_2D, level, internal_format, source_width, source_height, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10318 | 0, internal_format, dest_type, NULL); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10319 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10320 | if (error != GL_NO_ERROR) { |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 10321 | RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10322 | return; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10323 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10324 | |
| 10325 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10326 | dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10327 | source_height, 1, 0, internal_format, dest_type, true); |
[email protected] | f702471 | 2012-05-15 21:30:25 | [diff] [blame] | 10328 | } else { |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10329 | texture_manager()->SetLevelCleared( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10330 | dest_texture_ref, GL_TEXTURE_2D, level, true); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10331 | } |
| 10332 | |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 10333 | ScopedModifyPixels modify(dest_texture_ref); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 10334 | |
reveman | ce8fbe8 | 2014-09-05 02:19:52 | [diff] [blame] | 10335 | // Try using GLImage::CopyTexImage when possible. |
| 10336 | bool unpack_premultiply_alpha_change = |
| 10337 | unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; |
| 10338 | if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change && !level) { |
| 10339 | glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| 10340 | if (image->CopyTexImage(GL_TEXTURE_2D)) |
| 10341 | return; |
| 10342 | } |
| 10343 | |
| 10344 | DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 10345 | |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 10346 | // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 10347 | // before presenting. |
| 10348 | if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
| 10349 | // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
| 10350 | // instead of using default matrix crbug.com/226218. |
| 10351 | const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
| 10352 | 0.0f, 1.0f, 0.0f, 0.0f, |
| 10353 | 0.0f, 0.0f, 1.0f, 0.0f, |
| 10354 | 0.0f, 0.0f, 0.0f, 1.0f}; |
| 10355 | copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| 10356 | this, |
| 10357 | source_texture->target(), |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 10358 | source_texture->service_id(), |
[email protected] | 90f7d30d | 2014-08-13 02:51:57 | [diff] [blame] | 10359 | dest_texture->service_id(), |
| 10360 | level, |
| 10361 | source_width, |
| 10362 | source_height, |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 10363 | unpack_flip_y_, |
| 10364 | unpack_premultiply_alpha_, |
| 10365 | unpack_unpremultiply_alpha_, |
| 10366 | default_matrix); |
| 10367 | } else { |
[email protected] | 90f7d30d | 2014-08-13 02:51:57 | [diff] [blame] | 10368 | copy_texture_CHROMIUM_->DoCopyTexture(this, |
| 10369 | source_texture->target(), |
| 10370 | source_texture->service_id(), |
| 10371 | source_internal_format, |
| 10372 | dest_texture->service_id(), |
| 10373 | level, |
| 10374 | internal_format, |
| 10375 | source_width, |
| 10376 | source_height, |
| 10377 | unpack_flip_y_, |
| 10378 | unpack_premultiply_alpha_, |
| 10379 | unpack_unpremultiply_alpha_); |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 10380 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 10381 | |
| 10382 | DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10383 | } |
| 10384 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10385 | static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
| 10386 | switch (internalformat) { |
| 10387 | case GL_RGB565: |
| 10388 | return GL_UNSIGNED_SHORT_5_6_5; |
| 10389 | case GL_RGBA4: |
| 10390 | return GL_UNSIGNED_SHORT_4_4_4_4; |
| 10391 | case GL_RGB5_A1: |
| 10392 | return GL_UNSIGNED_SHORT_5_5_5_1; |
| 10393 | case GL_RGB8_OES: |
| 10394 | return GL_UNSIGNED_BYTE; |
| 10395 | case GL_RGBA8_OES: |
| 10396 | return GL_UNSIGNED_BYTE; |
| 10397 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 10398 | return GL_UNSIGNED_BYTE; |
| 10399 | case GL_LUMINANCE8_EXT: |
| 10400 | return GL_UNSIGNED_BYTE; |
| 10401 | case GL_ALPHA8_EXT: |
| 10402 | return GL_UNSIGNED_BYTE; |
| 10403 | case GL_RGBA32F_EXT: |
| 10404 | return GL_FLOAT; |
| 10405 | case GL_RGB32F_EXT: |
| 10406 | return GL_FLOAT; |
| 10407 | case GL_ALPHA32F_EXT: |
| 10408 | return GL_FLOAT; |
| 10409 | case GL_LUMINANCE32F_EXT: |
| 10410 | return GL_FLOAT; |
| 10411 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 10412 | return GL_FLOAT; |
| 10413 | case GL_RGBA16F_EXT: |
| 10414 | return GL_HALF_FLOAT_OES; |
| 10415 | case GL_RGB16F_EXT: |
| 10416 | return GL_HALF_FLOAT_OES; |
| 10417 | case GL_ALPHA16F_EXT: |
| 10418 | return GL_HALF_FLOAT_OES; |
| 10419 | case GL_LUMINANCE16F_EXT: |
| 10420 | return GL_HALF_FLOAT_OES; |
| 10421 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 10422 | return GL_HALF_FLOAT_OES; |
| 10423 | case GL_BGRA8_EXT: |
| 10424 | return GL_UNSIGNED_BYTE; |
| 10425 | default: |
| 10426 | return GL_NONE; |
| 10427 | } |
| 10428 | } |
| 10429 | |
| 10430 | void GLES2DecoderImpl::DoTexStorage2DEXT( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 10431 | GLenum target, |
| 10432 | GLint levels, |
| 10433 | GLenum internal_format, |
| 10434 | GLsizei width, |
| 10435 | GLsizei height) { |
[email protected] | 67f92942 | 2014-05-17 15:33:13 | [diff] [blame] | 10436 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT", |
| 10437 | "width", width, "height", height); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 10438 | if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 10439 | TextureManager::ComputeMipMapCount(target, width, height, 1) < levels) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10440 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10441 | GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10442 | return; |
| 10443 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10444 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10445 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10446 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10447 | LOCAL_SET_GL_ERROR( |
| 10448 | GL_INVALID_OPERATION, |
| 10449 | "glTexStorage2DEXT", "unknown texture for target"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10450 | return; |
| 10451 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10452 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10453 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10454 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10455 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10456 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10457 | LOCAL_SET_GL_ERROR( |
| 10458 | GL_INVALID_OPERATION, |
| 10459 | "glTexStorage2DEXT", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10460 | return; |
| 10461 | } |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10462 | |
| 10463 | GLenum format = ExtractFormatFromStorageFormat(internal_format); |
| 10464 | GLenum type = ExtractTypeFromStorageFormat(internal_format); |
| 10465 | |
| 10466 | { |
| 10467 | GLsizei level_width = width; |
| 10468 | GLsizei level_height = height; |
| 10469 | uint32 estimated_size = 0; |
| 10470 | for (int ii = 0; ii < levels; ++ii) { |
| 10471 | uint32 level_size = 0; |
| 10472 | if (!GLES2Util::ComputeImageDataSizes( |
| 10473 | level_width, level_height, format, type, state_.unpack_alignment, |
| 10474 | &estimated_size, NULL, NULL) || |
| 10475 | !SafeAddUint32(estimated_size, level_size, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10476 | LOCAL_SET_GL_ERROR( |
| 10477 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10478 | return; |
| 10479 | } |
| 10480 | level_width = std::max(1, level_width >> 1); |
| 10481 | level_height = std::max(1, level_height >> 1); |
| 10482 | } |
| 10483 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10484 | LOCAL_SET_GL_ERROR( |
| 10485 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10486 | return; |
| 10487 | } |
| 10488 | } |
| 10489 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10490 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage2DEXT"); |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 10491 | glTexStorage2DEXT(target, levels, internal_format, width, height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10492 | GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage2DEXT"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10493 | if (error == GL_NO_ERROR) { |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10494 | GLsizei level_width = width; |
| 10495 | GLsizei level_height = height; |
| 10496 | for (int ii = 0; ii < levels; ++ii) { |
| 10497 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10498 | texture_ref, target, ii, format, |
| 10499 | level_width, level_height, 1, 0, format, type, false); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10500 | level_width = std::max(1, level_width >> 1); |
| 10501 | level_height = std::max(1, level_height >> 1); |
| 10502 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10503 | texture->SetImmutable(true); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10504 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10505 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10506 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10507 | error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10508 | uint32 immediate_data_size, |
| 10509 | const void* cmd_data) { |
[email protected] | baed42c | 2013-10-01 05:06:35 | [diff] [blame] | 10510 | return error::kUnknownCommand; |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10511 | } |
| 10512 | |
| 10513 | void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10514 | const GLbyte* data) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10515 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 10516 | "context", logger_.GetLogPrefix(), |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10517 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10518 | |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10519 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10520 | &state_, target); |
| 10521 | ProduceTextureRef("glProduceTextureCHROMIUM", texture_ref, target, data); |
| 10522 | } |
| 10523 | |
| 10524 | void GLES2DecoderImpl::DoProduceTextureDirectCHROMIUM(GLuint client_id, |
| 10525 | GLenum target, const GLbyte* data) { |
| 10526 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureDirectCHROMIUM", |
| 10527 | "context", logger_.GetLogPrefix(), |
| 10528 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10529 | |
| 10530 | ProduceTextureRef("glProduceTextureDirectCHROMIUM", GetTexture(client_id), |
| 10531 | target, data); |
| 10532 | } |
| 10533 | |
| 10534 | void GLES2DecoderImpl::ProduceTextureRef(std::string func_name, |
| 10535 | TextureRef* texture_ref, GLenum target, const GLbyte* data) { |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10536 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10537 | DLOG_IF(ERROR, !mailbox.Verify()) << func_name << " was passed a " |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10538 | "mailbox that was not generated by " |
| 10539 | "GenMailboxCHROMIUM."; |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10540 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10541 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10542 | LOCAL_SET_GL_ERROR( |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10543 | GL_INVALID_OPERATION, func_name.c_str(), "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10544 | return; |
| 10545 | } |
| 10546 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10547 | Texture* produced = texture_manager()->Produce(texture_ref); |
| 10548 | if (!produced) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10549 | LOCAL_SET_GL_ERROR( |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10550 | GL_INVALID_OPERATION, func_name.c_str(), "invalid texture"); |
| 10551 | return; |
| 10552 | } |
| 10553 | |
| 10554 | if (produced->target() != target) { |
| 10555 | LOCAL_SET_GL_ERROR( |
| 10556 | GL_INVALID_OPERATION, func_name.c_str(), "invalid target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10557 | return; |
| 10558 | } |
| 10559 | |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10560 | group_->mailbox_manager()->ProduceTexture(target, mailbox, produced); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10561 | } |
| 10562 | |
| 10563 | void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10564 | const GLbyte* data) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10565 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 10566 | "context", logger_.GetLogPrefix(), |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10567 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10568 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
| 10569 | DLOG_IF(ERROR, !mailbox.Verify()) << "ConsumeTextureCHROMIUM was passed a " |
| 10570 | "mailbox that was not generated by " |
| 10571 | "GenMailboxCHROMIUM."; |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10572 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10573 | scoped_refptr<TextureRef> texture_ref = |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10574 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 10575 | if (!texture_ref.get()) { |
| 10576 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10577 | "glConsumeTextureCHROMIUM", |
| 10578 | "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10579 | return; |
| 10580 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10581 | GLuint client_id = texture_ref->client_id(); |
| 10582 | if (!client_id) { |
| 10583 | LOCAL_SET_GL_ERROR( |
| 10584 | GL_INVALID_OPERATION, |
| 10585 | "glConsumeTextureCHROMIUM", "unknown texture for target"); |
| 10586 | return; |
| 10587 | } |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10588 | Texture* texture = group_->mailbox_manager()->ConsumeTexture(target, mailbox); |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10589 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10590 | LOCAL_SET_GL_ERROR( |
| 10591 | GL_INVALID_OPERATION, |
| 10592 | "glConsumeTextureCHROMIUM", "invalid mailbox name"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10593 | return; |
| 10594 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10595 | if (texture->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10596 | LOCAL_SET_GL_ERROR( |
| 10597 | GL_INVALID_OPERATION, |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10598 | "glConsumeTextureCHROMIUM", "invalid target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10599 | return; |
| 10600 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10601 | |
| 10602 | DeleteTexturesHelper(1, &client_id); |
| 10603 | texture_ref = texture_manager()->Consume(client_id, texture); |
| 10604 | glBindTexture(target, texture_ref->service_id()); |
| 10605 | |
| 10606 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
| 10607 | unit.bind_target = target; |
| 10608 | switch (target) { |
| 10609 | case GL_TEXTURE_2D: |
| 10610 | unit.bound_texture_2d = texture_ref; |
| 10611 | break; |
| 10612 | case GL_TEXTURE_CUBE_MAP: |
| 10613 | unit.bound_texture_cube_map = texture_ref; |
| 10614 | break; |
| 10615 | case GL_TEXTURE_EXTERNAL_OES: |
| 10616 | unit.bound_texture_external_oes = texture_ref; |
| 10617 | break; |
| 10618 | case GL_TEXTURE_RECTANGLE_ARB: |
| 10619 | unit.bound_texture_rectangle_arb = texture_ref; |
| 10620 | break; |
| 10621 | default: |
| 10622 | NOTREACHED(); // Validation should prevent us getting here. |
| 10623 | break; |
| 10624 | } |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10625 | } |
| 10626 | |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10627 | error::Error GLES2DecoderImpl::HandleCreateAndConsumeTextureCHROMIUMImmediate( |
| 10628 | uint32_t immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10629 | const void* cmd_data) { |
| 10630 | const gles2::cmds::CreateAndConsumeTextureCHROMIUMImmediate& c = |
| 10631 | *static_cast< |
| 10632 | const gles2::cmds::CreateAndConsumeTextureCHROMIUMImmediate*>( |
| 10633 | cmd_data); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10634 | GLenum target = static_cast<GLenum>(c.target); |
| 10635 | uint32_t data_size; |
| 10636 | if (!ComputeDataSize(1, sizeof(GLbyte), 64, &data_size)) { |
| 10637 | return error::kOutOfBounds; |
| 10638 | } |
| 10639 | if (data_size > immediate_data_size) { |
| 10640 | return error::kOutOfBounds; |
| 10641 | } |
| 10642 | const GLbyte* mailbox = |
| 10643 | GetImmediateDataAs<const GLbyte*>(c, data_size, immediate_data_size); |
| 10644 | if (!validators_->texture_bind_target.IsValid(target)) { |
| 10645 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 10646 | "glCreateAndConsumeTextureCHROMIUM", target, "target"); |
| 10647 | return error::kNoError; |
| 10648 | } |
| 10649 | if (mailbox == NULL) { |
| 10650 | return error::kOutOfBounds; |
| 10651 | } |
| 10652 | uint32_t client_id = c.client_id; |
| 10653 | DoCreateAndConsumeTextureCHROMIUM(target, mailbox, client_id); |
| 10654 | return error::kNoError; |
| 10655 | } |
| 10656 | |
| 10657 | void GLES2DecoderImpl::DoCreateAndConsumeTextureCHROMIUM(GLenum target, |
| 10658 | const GLbyte* data, GLuint client_id) { |
| 10659 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoCreateAndConsumeTextureCHROMIUM", |
| 10660 | "context", logger_.GetLogPrefix(), |
| 10661 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10662 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
| 10663 | DLOG_IF(ERROR, !mailbox.Verify()) << "CreateAndConsumeTextureCHROMIUM was " |
| 10664 | "passed a mailbox that was not " |
| 10665 | "generated by GenMailboxCHROMIUM."; |
| 10666 | |
| 10667 | TextureRef* texture_ref = GetTexture(client_id); |
| 10668 | if (texture_ref) { |
| 10669 | LOCAL_SET_GL_ERROR( |
| 10670 | GL_INVALID_OPERATION, |
| 10671 | "glCreateAndConsumeTextureCHROMIUM", "client id already in use"); |
| 10672 | return; |
| 10673 | } |
| 10674 | Texture* texture = group_->mailbox_manager()->ConsumeTexture(target, mailbox); |
| 10675 | if (!texture) { |
| 10676 | LOCAL_SET_GL_ERROR( |
| 10677 | GL_INVALID_OPERATION, |
| 10678 | "glCreateAndConsumeTextureCHROMIUM", "invalid mailbox name"); |
| 10679 | return; |
| 10680 | } |
| 10681 | if (texture->target() != target) { |
| 10682 | LOCAL_SET_GL_ERROR( |
| 10683 | GL_INVALID_OPERATION, |
| 10684 | "glCreateAndConsumeTextureCHROMIUM", "invalid target"); |
| 10685 | return; |
| 10686 | } |
| 10687 | |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10688 | texture_ref = texture_manager()->Consume(client_id, texture); |
| 10689 | } |
| 10690 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 10691 | void GLES2DecoderImpl::DoInsertEventMarkerEXT( |
| 10692 | GLsizei length, const GLchar* marker) { |
| 10693 | if (!marker) { |
| 10694 | marker = ""; |
| 10695 | } |
| 10696 | debug_marker_manager_.SetMarker( |
| 10697 | length ? std::string(marker, length) : std::string(marker)); |
| 10698 | } |
| 10699 | |
| 10700 | void GLES2DecoderImpl::DoPushGroupMarkerEXT( |
| 10701 | GLsizei length, const GLchar* marker) { |
| 10702 | if (!marker) { |
| 10703 | marker = ""; |
| 10704 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 10705 | std::string name = length ? std::string(marker, length) : std::string(marker); |
| 10706 | debug_marker_manager_.PushGroup(name); |
| 10707 | gpu_tracer_->Begin(name, kTraceGroupMarker); |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 10708 | } |
| 10709 | |
| 10710 | void GLES2DecoderImpl::DoPopGroupMarkerEXT(void) { |
| 10711 | debug_marker_manager_.PopGroup(); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 10712 | gpu_tracer_->End(kTraceGroupMarker); |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 10713 | } |
| 10714 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10715 | void GLES2DecoderImpl::DoBindTexImage2DCHROMIUM( |
| 10716 | GLenum target, GLint image_id) { |
| 10717 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10718 | |
[email protected] | bc26e8d | 2014-01-29 00:40:30 | [diff] [blame] | 10719 | if (target == GL_TEXTURE_CUBE_MAP) { |
| 10720 | LOCAL_SET_GL_ERROR( |
| 10721 | GL_INVALID_ENUM, |
| 10722 | "glBindTexImage2DCHROMIUM", "invalid target"); |
| 10723 | return; |
| 10724 | } |
| 10725 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10726 | // Default target might be conceptually valid, but disallow it to avoid |
| 10727 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10728 | TextureRef* texture_ref = |
| 10729 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10730 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10731 | LOCAL_SET_GL_ERROR( |
| 10732 | GL_INVALID_OPERATION, |
| 10733 | "glBindTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10734 | return; |
| 10735 | } |
| 10736 | |
| 10737 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 10738 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10739 | LOCAL_SET_GL_ERROR( |
| 10740 | GL_INVALID_OPERATION, |
| 10741 | "glBindTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10742 | return; |
| 10743 | } |
| 10744 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10745 | { |
| 10746 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 10747 | "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | 3c58012 | 2013-11-22 07:52:26 | [diff] [blame] | 10748 | if (!gl_image->BindTexImage(target)) { |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10749 | LOCAL_SET_GL_ERROR( |
| 10750 | GL_INVALID_OPERATION, |
| 10751 | "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID"); |
| 10752 | return; |
| 10753 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10754 | } |
| 10755 | |
| 10756 | gfx::Size size = gl_image->GetSize(); |
| 10757 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10758 | texture_ref, target, 0, GL_RGBA, size.width(), size.height(), 1, 0, |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10759 | GL_RGBA, GL_UNSIGNED_BYTE, true); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10760 | texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10761 | } |
| 10762 | |
| 10763 | void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( |
| 10764 | GLenum target, GLint image_id) { |
| 10765 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10766 | |
| 10767 | // Default target might be conceptually valid, but disallow it to avoid |
| 10768 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10769 | TextureRef* texture_ref = |
| 10770 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10771 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10772 | LOCAL_SET_GL_ERROR( |
| 10773 | GL_INVALID_OPERATION, |
| 10774 | "glReleaseTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10775 | return; |
| 10776 | } |
| 10777 | |
| 10778 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 10779 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10780 | LOCAL_SET_GL_ERROR( |
| 10781 | GL_INVALID_OPERATION, |
| 10782 | "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10783 | return; |
| 10784 | } |
| 10785 | |
| 10786 | // Do nothing when image is not currently bound. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10787 | if (texture_ref->texture()->GetLevelImage(target, 0) != gl_image) |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10788 | return; |
| 10789 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10790 | { |
| 10791 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 10792 | "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | 3c58012 | 2013-11-22 07:52:26 | [diff] [blame] | 10793 | gl_image->ReleaseTexImage(target); |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 10794 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10795 | |
| 10796 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10797 | texture_ref, target, 0, GL_RGBA, 0, 0, 1, 0, |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10798 | GL_RGBA, GL_UNSIGNED_BYTE, false); |
| 10799 | } |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 10800 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10801 | error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10802 | uint32 immediate_data_size, |
| 10803 | const void* cmd_data) { |
| 10804 | const gles2::cmds::TraceBeginCHROMIUM& c = |
| 10805 | *static_cast<const gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10806 | Bucket* bucket = GetBucket(c.bucket_id); |
| 10807 | if (!bucket || bucket->size() == 0) { |
| 10808 | return error::kInvalidArguments; |
| 10809 | } |
| 10810 | std::string command_name; |
| 10811 | if (!bucket->GetAsString(&command_name)) { |
| 10812 | return error::kInvalidArguments; |
| 10813 | } |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10814 | TRACE_EVENT_COPY_ASYNC_BEGIN0("gpu", command_name.c_str(), this); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 10815 | if (!gpu_tracer_->Begin(command_name, kTraceCHROMIUM)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10816 | LOCAL_SET_GL_ERROR( |
| 10817 | GL_INVALID_OPERATION, |
| 10818 | "glTraceBeginCHROMIUM", "unable to create begin trace"); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10819 | return error::kNoError; |
| 10820 | } |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10821 | return error::kNoError; |
| 10822 | } |
| 10823 | |
| 10824 | void GLES2DecoderImpl::DoTraceEndCHROMIUM() { |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10825 | if (gpu_tracer_->CurrentName().empty()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10826 | LOCAL_SET_GL_ERROR( |
| 10827 | GL_INVALID_OPERATION, |
| 10828 | "glTraceEndCHROMIUM", "no trace begin found"); |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10829 | return; |
| 10830 | } |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 10831 | TRACE_EVENT_COPY_ASYNC_END0("gpu", gpu_tracer_->CurrentName().c_str(), this); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 10832 | gpu_tracer_->End(kTraceCHROMIUM); |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 10833 | } |
| 10834 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 10835 | void GLES2DecoderImpl::DoDrawBuffersEXT( |
| 10836 | GLsizei count, const GLenum* bufs) { |
| 10837 | if (count > static_cast<GLsizei>(group_->max_draw_buffers())) { |
| 10838 | LOCAL_SET_GL_ERROR( |
| 10839 | GL_INVALID_VALUE, |
| 10840 | "glDrawBuffersEXT", "greater than GL_MAX_DRAW_BUFFERS_EXT"); |
| 10841 | return; |
| 10842 | } |
| 10843 | |
| 10844 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 10845 | if (framebuffer) { |
| 10846 | for (GLsizei i = 0; i < count; ++i) { |
| 10847 | if (bufs[i] != static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i) && |
| 10848 | bufs[i] != GL_NONE) { |
| 10849 | LOCAL_SET_GL_ERROR( |
| 10850 | GL_INVALID_OPERATION, |
| 10851 | "glDrawBuffersEXT", |
| 10852 | "bufs[i] not GL_NONE or GL_COLOR_ATTACHMENTi_EXT"); |
| 10853 | return; |
| 10854 | } |
| 10855 | } |
| 10856 | glDrawBuffersARB(count, bufs); |
| 10857 | framebuffer->SetDrawBuffers(count, bufs); |
| 10858 | } else { // backbuffer |
| 10859 | if (count > 1 || |
| 10860 | (bufs[0] != GL_BACK && bufs[0] != GL_NONE)) { |
| 10861 | LOCAL_SET_GL_ERROR( |
| 10862 | GL_INVALID_OPERATION, |
| 10863 | "glDrawBuffersEXT", |
| 10864 | "more than one buffer or bufs not GL_NONE or GL_BACK"); |
| 10865 | return; |
| 10866 | } |
| 10867 | GLenum mapped_buf = bufs[0]; |
| 10868 | if (GetBackbufferServiceId() != 0 && // emulated backbuffer |
| 10869 | bufs[0] == GL_BACK) { |
| 10870 | mapped_buf = GL_COLOR_ATTACHMENT0; |
| 10871 | } |
| 10872 | glDrawBuffersARB(count, &mapped_buf); |
| 10873 | group_->set_draw_buffer(bufs[0]); |
| 10874 | } |
| 10875 | } |
| 10876 | |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 10877 | void GLES2DecoderImpl::DoLoseContextCHROMIUM(GLenum current, GLenum other) { |
| 10878 | group_->LoseContexts(other); |
| 10879 | reset_status_ = current; |
| 10880 | current_decoder_error_ = error::kLostContext; |
| 10881 | } |
| 10882 | |
kkinnunen | 337d5963 | 2014-08-26 10:19:57 | [diff] [blame] | 10883 | void GLES2DecoderImpl::DoMatrixLoadfCHROMIUM(GLenum matrix_mode, |
| 10884 | const GLfloat* matrix) { |
| 10885 | DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || |
| 10886 | matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); |
| 10887 | if (!features().chromium_path_rendering) { |
| 10888 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10889 | "glMatrixLoadfCHROMIUM", |
| 10890 | "function not available"); |
| 10891 | return; |
| 10892 | } |
| 10893 | |
| 10894 | GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM |
| 10895 | ? state_.projection_matrix |
| 10896 | : state_.modelview_matrix; |
| 10897 | memcpy(target_matrix, matrix, sizeof(GLfloat) * 16); |
| 10898 | // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV |
| 10899 | // since the values of the _NV and _CHROMIUM tokens match. |
| 10900 | glMatrixLoadfEXT(matrix_mode, matrix); |
| 10901 | } |
| 10902 | |
| 10903 | void GLES2DecoderImpl::DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode) { |
| 10904 | DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || |
| 10905 | matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); |
| 10906 | |
| 10907 | if (!features().chromium_path_rendering) { |
| 10908 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10909 | "glMatrixLoadIdentityCHROMIUM", |
| 10910 | "function not available"); |
| 10911 | return; |
| 10912 | } |
| 10913 | |
| 10914 | static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, |
| 10915 | 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, |
| 10916 | 0.0f, 0.0f, 0.0f, 1.0f}; |
| 10917 | |
| 10918 | GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM |
| 10919 | ? state_.projection_matrix |
| 10920 | : state_.modelview_matrix; |
| 10921 | memcpy(target_matrix, kIdentityMatrix, sizeof(kIdentityMatrix)); |
| 10922 | // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV |
| 10923 | // since the values of the _NV and _CHROMIUM tokens match. |
| 10924 | glMatrixLoadIdentityEXT(matrix_mode); |
| 10925 | } |
| 10926 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10927 | bool GLES2DecoderImpl::ValidateAsyncTransfer( |
| 10928 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10929 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10930 | GLenum target, |
| 10931 | GLint level, |
| 10932 | const void * data) { |
| 10933 | // We only support async uploads to 2D textures for now. |
| 10934 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10935 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10936 | return false; |
| 10937 | } |
| 10938 | // We only support uploads to level zero for now. |
| 10939 | if (level != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10940 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "level != 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10941 | return false; |
| 10942 | } |
| 10943 | // A transfer buffer must be bound, even for asyncTexImage2D. |
| 10944 | if (data == NULL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10945 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, "buffer == 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10946 | return false; |
| 10947 | } |
| 10948 | // We only support one async transfer in progress. |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10949 | if (!texture_ref || |
| 10950 | async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10951 | LOCAL_SET_GL_ERROR( |
| 10952 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10953 | function_name, "transfer already in progress"); |
| 10954 | return false; |
| 10955 | } |
| 10956 | return true; |
| 10957 | } |
| 10958 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 10959 | base::Closure GLES2DecoderImpl::AsyncUploadTokenCompletionClosure( |
| 10960 | uint32 async_upload_token, |
| 10961 | uint32 sync_data_shm_id, |
| 10962 | uint32 sync_data_shm_offset) { |
| 10963 | scoped_refptr<gpu::Buffer> buffer = GetSharedMemoryBuffer(sync_data_shm_id); |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 10964 | if (!buffer.get() || |
| 10965 | !buffer->GetDataAddress(sync_data_shm_offset, sizeof(AsyncUploadSync))) |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 10966 | return base::Closure(); |
| 10967 | |
| 10968 | AsyncMemoryParams mem_params(buffer, |
| 10969 | sync_data_shm_offset, |
| 10970 | sizeof(AsyncUploadSync)); |
| 10971 | |
| 10972 | scoped_refptr<AsyncUploadTokenCompletionObserver> observer( |
| 10973 | new AsyncUploadTokenCompletionObserver(async_upload_token)); |
| 10974 | |
| 10975 | return base::Bind( |
| 10976 | &AsyncPixelTransferManager::AsyncNotifyCompletion, |
| 10977 | base::Unretained(GetAsyncPixelTransferManager()), |
| 10978 | mem_params, |
| 10979 | observer); |
| 10980 | } |
| 10981 | |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10982 | error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10983 | uint32 immediate_data_size, |
| 10984 | const void* cmd_data) { |
| 10985 | const gles2::cmds::AsyncTexImage2DCHROMIUM& c = |
| 10986 | *static_cast<const gles2::cmds::AsyncTexImage2DCHROMIUM*>(cmd_data); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10987 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10988 | GLenum target = static_cast<GLenum>(c.target); |
| 10989 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10990 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 10991 | GLsizei width = static_cast<GLsizei>(c.width); |
| 10992 | GLsizei height = static_cast<GLsizei>(c.height); |
| 10993 | GLint border = static_cast<GLint>(c.border); |
| 10994 | GLenum format = static_cast<GLenum>(c.format); |
| 10995 | GLenum type = static_cast<GLenum>(c.type); |
| 10996 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 10997 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
| 10998 | uint32 pixels_size; |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 10999 | uint32 async_upload_token = static_cast<uint32>(c.async_upload_token); |
| 11000 | uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id); |
| 11001 | uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 11002 | |
| 11003 | base::ScopedClosureRunner scoped_completion_callback; |
| 11004 | if (async_upload_token) { |
| 11005 | base::Closure completion_closure = |
| 11006 | AsyncUploadTokenCompletionClosure(async_upload_token, |
| 11007 | sync_data_shm_id, |
| 11008 | sync_data_shm_offset); |
| 11009 | if (completion_closure.is_null()) |
| 11010 | return error::kInvalidArguments; |
| 11011 | |
| 11012 | scoped_completion_callback.Reset(completion_closure); |
| 11013 | } |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11014 | |
| 11015 | // TODO(epenner): Move this and copies of this memory validation |
| 11016 | // into ValidateTexImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11017 | if (!GLES2Util::ComputeImageDataSizes( |
| 11018 | width, height, format, type, state_.unpack_alignment, &pixels_size, NULL, |
| 11019 | NULL)) { |
| 11020 | return error::kOutOfBounds; |
| 11021 | } |
| 11022 | const void* pixels = NULL; |
| 11023 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 11024 | pixels = GetSharedMemoryAs<const void*>( |
| 11025 | pixels_shm_id, pixels_shm_offset, pixels_size); |
| 11026 | if (!pixels) { |
| 11027 | return error::kOutOfBounds; |
| 11028 | } |
| 11029 | } |
| 11030 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11031 | TextureManager::DoTextImage2DArguments args = { |
| 11032 | target, level, internal_format, width, height, border, format, type, |
| 11033 | pixels, pixels_size}; |
| 11034 | TextureRef* texture_ref; |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11035 | // All the normal glTexSubImage2D validation. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11036 | if (!texture_manager()->ValidateTexImage2D( |
| 11037 | &state_, "glAsyncTexImage2DCHROMIUM", args, &texture_ref)) { |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11038 | return error::kNoError; |
| 11039 | } |
| 11040 | |
| 11041 | // Extra async validation. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11042 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11043 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 11044 | "glAsyncTexImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11045 | return error::kNoError; |
| 11046 | |
| 11047 | // Don't allow async redefinition of a textures. |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 11048 | if (texture->IsDefined()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11049 | LOCAL_SET_GL_ERROR( |
| 11050 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11051 | "glAsyncTexImage2DCHROMIUM", "already defined"); |
| 11052 | return error::kNoError; |
| 11053 | } |
| 11054 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 11055 | if (!EnsureGPUMemoryAvailable(pixels_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11056 | LOCAL_SET_GL_ERROR( |
| 11057 | GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 11058 | return error::kNoError; |
| 11059 | } |
| 11060 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11061 | // Setup the parameters. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 11062 | AsyncTexImage2DParams tex_params = { |
| 11063 | target, level, static_cast<GLenum>(internal_format), |
| 11064 | width, height, border, format, type}; |
[email protected] | c8021e0 | 2014-03-27 06:10:12 | [diff] [blame] | 11065 | AsyncMemoryParams mem_params( |
| 11066 | GetSharedMemoryBuffer(c.pixels_shm_id), c.pixels_shm_offset, pixels_size); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11067 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11068 | // Set up the async state if needed, and make the texture |
| 11069 | // immutable so the async state stays valid. The level info |
| 11070 | // is set up lazily when the transfer completes. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11071 | AsyncPixelTransferDelegate* delegate = |
| 11072 | async_pixel_transfer_manager_->CreatePixelTransferDelegate(texture_ref, |
| 11073 | tex_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11074 | texture->SetImmutable(true); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11075 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11076 | delegate->AsyncTexImage2D( |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11077 | tex_params, |
| 11078 | mem_params, |
| 11079 | base::Bind(&TextureManager::SetLevelInfoFromParams, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11080 | // The callback is only invoked if the transfer delegate still |
| 11081 | // exists, which implies through manager->texture_ref->state |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11082 | // ownership that both of these pointers are valid. |
| 11083 | base::Unretained(texture_manager()), |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11084 | base::Unretained(texture_ref), |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11085 | tex_params)); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 11086 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11087 | } |
| 11088 | |
| 11089 | error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11090 | uint32 immediate_data_size, |
| 11091 | const void* cmd_data) { |
| 11092 | const gles2::cmds::AsyncTexSubImage2DCHROMIUM& c = |
| 11093 | *static_cast<const gles2::cmds::AsyncTexSubImage2DCHROMIUM*>(cmd_data); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11094 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11095 | GLenum target = static_cast<GLenum>(c.target); |
| 11096 | GLint level = static_cast<GLint>(c.level); |
| 11097 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 11098 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 11099 | GLsizei width = static_cast<GLsizei>(c.width); |
| 11100 | GLsizei height = static_cast<GLsizei>(c.height); |
| 11101 | GLenum format = static_cast<GLenum>(c.format); |
| 11102 | GLenum type = static_cast<GLenum>(c.type); |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 11103 | uint32 async_upload_token = static_cast<uint32>(c.async_upload_token); |
| 11104 | uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id); |
| 11105 | uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 11106 | |
| 11107 | base::ScopedClosureRunner scoped_completion_callback; |
| 11108 | if (async_upload_token) { |
| 11109 | base::Closure completion_closure = |
| 11110 | AsyncUploadTokenCompletionClosure(async_upload_token, |
| 11111 | sync_data_shm_id, |
| 11112 | sync_data_shm_offset); |
| 11113 | if (completion_closure.is_null()) |
| 11114 | return error::kInvalidArguments; |
| 11115 | |
| 11116 | scoped_completion_callback.Reset(completion_closure); |
| 11117 | } |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11118 | |
| 11119 | // TODO(epenner): Move this and copies of this memory validation |
| 11120 | // into ValidateTexSubImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11121 | uint32 data_size; |
| 11122 | if (!GLES2Util::ComputeImageDataSizes( |
| 11123 | width, height, format, type, state_.unpack_alignment, &data_size, |
| 11124 | NULL, NULL)) { |
| 11125 | return error::kOutOfBounds; |
| 11126 | } |
| 11127 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 11128 | c.data_shm_id, c.data_shm_offset, data_size); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11129 | |
| 11130 | // All the normal glTexSubImage2D validation. |
| 11131 | error::Error error = error::kNoError; |
| 11132 | if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2DCHROMIUM", |
| 11133 | target, level, xoffset, yoffset, width, height, format, type, pixels)) { |
| 11134 | return error; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11135 | } |
| 11136 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11137 | // Extra async validation. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11138 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 11139 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11140 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11141 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 11142 | "glAsyncTexSubImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11143 | return error::kNoError; |
| 11144 | |
| 11145 | // Guarantee async textures are always 'cleared' as follows: |
| 11146 | // - AsyncTexImage2D can not redefine an existing texture |
| 11147 | // - AsyncTexImage2D must initialize the entire image via non-null buffer. |
| 11148 | // - AsyncTexSubImage2D clears synchronously if not already cleared. |
| 11149 | // - Textures become immutable after an async call. |
| 11150 | // 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] | 11151 | if (!texture->SafeToRenderFrom()) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11152 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, |
| 11153 | target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11154 | LOCAL_SET_GL_ERROR( |
| 11155 | GL_OUT_OF_MEMORY, |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 11156 | "glAsyncTexSubImage2DCHROMIUM", "dimensions too big"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11157 | return error::kNoError; |
| 11158 | } |
| 11159 | } |
| 11160 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11161 | // Setup the parameters. |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 11162 | AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11163 | width, height, format, type}; |
[email protected] | c8021e0 | 2014-03-27 06:10:12 | [diff] [blame] | 11164 | AsyncMemoryParams mem_params( |
| 11165 | GetSharedMemoryBuffer(c.data_shm_id), c.data_shm_offset, data_size); |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11166 | AsyncPixelTransferDelegate* delegate = |
| 11167 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 11168 | if (!delegate) { |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11169 | // TODO(epenner): We may want to enforce exclusive use |
| 11170 | // of async APIs in which case this should become an error, |
| 11171 | // (the texture should have been async defined). |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 11172 | AsyncTexImage2DParams define_params = {target, level, |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11173 | 0, 0, 0, 0, 0, 0}; |
| 11174 | texture->GetLevelSize(target, level, &define_params.width, |
| 11175 | &define_params.height); |
| 11176 | texture->GetLevelType(target, level, &define_params.type, |
| 11177 | &define_params.internal_format); |
| 11178 | // Set up the async state if needed, and make the texture |
| 11179 | // immutable so the async state stays valid. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11180 | delegate = async_pixel_transfer_manager_->CreatePixelTransferDelegate( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 11181 | texture_ref, define_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11182 | texture->SetImmutable(true); |
| 11183 | } |
| 11184 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11185 | delegate->AsyncTexSubImage2D(tex_params, mem_params); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11186 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11187 | } |
| 11188 | |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11189 | error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11190 | uint32 immediate_data_size, |
| 11191 | const void* cmd_data) { |
| 11192 | const gles2::cmds::WaitAsyncTexImage2DCHROMIUM& c = |
| 11193 | *static_cast<const gles2::cmds::WaitAsyncTexImage2DCHROMIUM*>(cmd_data); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11194 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); |
| 11195 | GLenum target = static_cast<GLenum>(c.target); |
| 11196 | |
| 11197 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11198 | LOCAL_SET_GL_ERROR( |
| 11199 | GL_INVALID_ENUM, "glWaitAsyncTexImage2DCHROMIUM", "target"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11200 | return error::kNoError; |
| 11201 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11202 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 11203 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11204 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11205 | LOCAL_SET_GL_ERROR( |
| 11206 | GL_INVALID_OPERATION, |
| 11207 | "glWaitAsyncTexImage2DCHROMIUM", "unknown texture"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11208 | return error::kNoError; |
| 11209 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11210 | AsyncPixelTransferDelegate* delegate = |
| 11211 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 11212 | if (!delegate) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11213 | LOCAL_SET_GL_ERROR( |
| 11214 | GL_INVALID_OPERATION, |
| 11215 | "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); |
| 11216 | return error::kNoError; |
| 11217 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11218 | delegate->WaitForTransferCompletion(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 11219 | ProcessFinishedAsyncTransfers(); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11220 | return error::kNoError; |
| 11221 | } |
| 11222 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 11223 | error::Error GLES2DecoderImpl::HandleWaitAllAsyncTexImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11224 | uint32 immediate_data_size, |
| 11225 | const void* data) { |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 11226 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); |
| 11227 | |
| 11228 | GetAsyncPixelTransferManager()->WaitAllAsyncTexImage2D(); |
| 11229 | ProcessFinishedAsyncTransfers(); |
| 11230 | return error::kNoError; |
| 11231 | } |
| 11232 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 11233 | void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( |
| 11234 | TextureRef* texture_ref) { |
| 11235 | Texture* texture = texture_ref->texture(); |
| 11236 | DoDidUseTexImageIfNeeded(texture, texture->target()); |
| 11237 | } |
| 11238 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 11239 | void GLES2DecoderImpl::OnOutOfMemoryError() { |
| 11240 | if (lose_context_when_out_of_memory_) { |
| 11241 | group_->LoseContexts(GL_UNKNOWN_CONTEXT_RESET_ARB); |
| 11242 | LoseContext(GL_GUILTY_CONTEXT_RESET_ARB); |
| 11243 | } |
| 11244 | } |
| 11245 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 11246 | // Include the auto-generated part of this file. We split this because it means |
| 11247 | // we can easily edit the non-auto generated parts right here in this file |
| 11248 | // instead of having to edit some template or the code generator. |
| 11249 | #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 11250 | |
| 11251 | } // namespace gles2 |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 11252 | } // namespace gpu |