[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" |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 44 | #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h" |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 45 | #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 46 | #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 47 | #include "gpu/command_buffer/service/gpu_state_tracer.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 48 | #include "gpu/command_buffer/service/gpu_switches.h" |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 49 | #include "gpu/command_buffer/service/gpu_tracer.h" |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 50 | #include "gpu/command_buffer/service/image_manager.h" |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 51 | #include "gpu/command_buffer/service/mailbox_manager.h" |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 52 | #include "gpu/command_buffer/service/memory_tracking.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 53 | #include "gpu/command_buffer/service/program_manager.h" |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 54 | #include "gpu/command_buffer/service/query_manager.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 55 | #include "gpu/command_buffer/service/renderbuffer_manager.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 56 | #include "gpu/command_buffer/service/shader_manager.h" |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 57 | #include "gpu/command_buffer/service/shader_translator.h" |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 58 | #include "gpu/command_buffer/service/shader_translator_cache.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 59 | #include "gpu/command_buffer/service/texture_manager.h" |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 60 | #include "gpu/command_buffer/service/valuebuffer_manager.h" |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 61 | #include "gpu/command_buffer/service/vertex_array_manager.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 62 | #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
[email protected] | 6896d7f | 2014-04-28 20:24:15 | [diff] [blame] | 63 | #include "third_party/smhasher/src/City.h" |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 64 | #include "ui/gl/gl_fence.h" |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 65 | #include "ui/gl/gl_image.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 66 | #include "ui/gl/gl_implementation.h" |
| 67 | #include "ui/gl/gl_surface.h" |
[email protected] | 423e644f | 2013-06-19 00:48:27 | [diff] [blame] | 68 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 69 | #if defined(OS_MACOSX) |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 70 | #include <IOSurface/IOSurfaceAPI.h> |
| 71 | // Note that this must be included after gl_bindings.h to avoid conflicts. |
| 72 | #include <OpenGL/CGLIOSurface.h> |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 73 | #endif |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 74 | |
[email protected] | 6eb77535 | 2013-08-27 05:57:16 | [diff] [blame] | 75 | #if defined(OS_WIN) |
| 76 | #include "base/win/win_util.h" |
| 77 | #endif |
| 78 | |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 79 | namespace gpu { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 80 | namespace gles2 { |
| 81 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 82 | namespace { |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 83 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 84 | static const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 85 | static const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 86 | static const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 87 | static const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 88 | |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 89 | static bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, |
| 90 | GLint rangeMax, |
| 91 | GLint precision) { |
| 92 | return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); |
| 93 | } |
| 94 | |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 95 | static void GetShaderPrecisionFormatImpl(GLenum shader_type, |
| 96 | GLenum precision_type, |
| 97 | GLint *range, GLint *precision) { |
| 98 | switch (precision_type) { |
| 99 | case GL_LOW_INT: |
| 100 | case GL_MEDIUM_INT: |
| 101 | case GL_HIGH_INT: |
| 102 | // These values are for a 32-bit twos-complement integer format. |
| 103 | range[0] = 31; |
| 104 | range[1] = 30; |
| 105 | *precision = 0; |
| 106 | break; |
| 107 | case GL_LOW_FLOAT: |
| 108 | case GL_MEDIUM_FLOAT: |
| 109 | case GL_HIGH_FLOAT: |
| 110 | // These values are for an IEEE single-precision floating-point format. |
| 111 | range[0] = 127; |
| 112 | range[1] = 127; |
| 113 | *precision = 23; |
| 114 | break; |
| 115 | default: |
| 116 | NOTREACHED(); |
| 117 | break; |
| 118 | } |
| 119 | |
[email protected] | 8af4d5e | 2013-03-15 23:55:33 | [diff] [blame] | 120 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
| 121 | gfx::g_driver_gl.fn.glGetShaderPrecisionFormatFn) { |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 122 | // This function is sometimes defined even though it's really just |
| 123 | // a stub, so we need to set range and precision as if it weren't |
| 124 | // defined before calling it. |
[email protected] | 501b5740 | 2013-03-14 22:21:44 | [diff] [blame] | 125 | // On Mac OS with some GPUs, calling this generates a |
| 126 | // GL_INVALID_OPERATION error. Avoid calling it on non-GLES2 |
| 127 | // platforms. |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 128 | glGetShaderPrecisionFormat(shader_type, precision_type, |
| 129 | range, precision); |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 130 | |
| 131 | // TODO(brianderson): Make the following official workarounds. |
| 132 | |
| 133 | // Some drivers have bugs where they report the ranges as a negative number. |
| 134 | // Taking the absolute value here shouldn't hurt because negative numbers |
| 135 | // aren't expected anyway. |
| 136 | range[0] = abs(range[0]); |
| 137 | range[1] = abs(range[1]); |
| 138 | |
| 139 | // If the driver reports a precision for highp float that isn't actually |
| 140 | // highp, don't pretend like it's supported because shader compilation will |
| 141 | // fail anyway. |
| 142 | if (precision_type == GL_HIGH_FLOAT && |
| 143 | !PrecisionMeetsSpecForHighpFloat(range[0], range[1], *precision)) { |
| 144 | range[0] = 0; |
| 145 | range[1] = 0; |
| 146 | *precision = 0; |
| 147 | } |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
[email protected] | d286ebbc | 2014-07-03 17:19:10 | [diff] [blame] | 151 | static gfx::OverlayTransform GetGFXOverlayTransform(GLenum plane_transform) { |
| 152 | switch (plane_transform) { |
| 153 | case GL_OVERLAY_TRANSFORM_NONE_CHROMIUM: |
| 154 | return gfx::OVERLAY_TRANSFORM_NONE; |
| 155 | case GL_OVERLAY_TRANSFORM_FLIP_HORIZONTAL_CHROMIUM: |
| 156 | return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; |
| 157 | case GL_OVERLAY_TRANSFORM_FLIP_VERTICAL_CHROMIUM: |
| 158 | return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL; |
| 159 | case GL_OVERLAY_TRANSFORM_ROTATE_90_CHROMIUM: |
| 160 | return gfx::OVERLAY_TRANSFORM_ROTATE_90; |
| 161 | case GL_OVERLAY_TRANSFORM_ROTATE_180_CHROMIUM: |
| 162 | return gfx::OVERLAY_TRANSFORM_ROTATE_180; |
| 163 | case GL_OVERLAY_TRANSFORM_ROTATE_270_CHROMIUM: |
| 164 | return gfx::OVERLAY_TRANSFORM_ROTATE_270; |
| 165 | default: |
| 166 | return gfx::OVERLAY_TRANSFORM_INVALID; |
| 167 | } |
| 168 | } |
| 169 | |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 170 | } // namespace |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 171 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 172 | class GLES2DecoderImpl; |
| 173 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 174 | // Local versions of the SET_GL_ERROR macros |
| 175 | #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 176 | ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 177 | #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 178 | ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \ |
| 179 | function_name, value, label) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 180 | #define LOCAL_SET_GL_ERROR_INVALID_PARAM(error, function_name, pname) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 181 | ERRORSTATE_SET_GL_ERROR_INVALID_PARAM(state_.GetErrorState(), error, \ |
| 182 | function_name, pname) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 183 | #define LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 184 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(state_.GetErrorState(), \ |
| 185 | function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 186 | #define LOCAL_PEEK_GL_ERROR(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 187 | ERRORSTATE_PEEK_GL_ERROR(state_.GetErrorState(), function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 188 | #define LOCAL_CLEAR_REAL_GL_ERRORS(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 189 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(state_.GetErrorState(), function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 190 | #define LOCAL_PERFORMANCE_WARNING(msg) \ |
| 191 | PerformanceWarning(__FILE__, __LINE__, msg) |
| 192 | #define LOCAL_RENDER_WARNING(msg) \ |
| 193 | RenderWarning(__FILE__, __LINE__, msg) |
| 194 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 195 | // Check that certain assumptions the code makes are true. There are places in |
| 196 | // the code where shared memory is passed direclty to GL. Example, glUniformiv, |
| 197 | // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe |
| 198 | // a few others) are 32bits. If they are not 32bits the code will have to change |
| 199 | // to call those GL functions with service side memory and then copy the results |
| 200 | // to shared memory, converting the sizes. |
mostynb | 7f03209 | 2014-12-20 00:36:44 | [diff] [blame] | 201 | static_assert(sizeof(GLint) == sizeof(uint32), // NOLINT |
| 202 | "GLint should be the same size as uint32"); |
| 203 | static_assert(sizeof(GLsizei) == sizeof(uint32), // NOLINT |
| 204 | "GLsizei should be the same size as uint32"); |
| 205 | static_assert(sizeof(GLfloat) == sizeof(float), // NOLINT |
| 206 | "GLfloat should be the same size as float"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 207 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 208 | // TODO(kbr): the use of this anonymous namespace core dumps the |
| 209 | // linker on Mac OS X 10.6 when the symbol ordering file is used |
| 210 | // namespace { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 211 | |
| 212 | // Returns the address of the first byte after a struct. |
| 213 | template <typename T> |
| 214 | const void* AddressAfterStruct(const T& pod) { |
| 215 | return reinterpret_cast<const uint8*>(&pod) + sizeof(pod); |
| 216 | } |
| 217 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 218 | // Returns the address of the frst byte after the struct or NULL if size > |
| 219 | // immediate_data_size. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 220 | template <typename RETURN_TYPE, typename COMMAND_TYPE> |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 221 | RETURN_TYPE GetImmediateDataAs(const COMMAND_TYPE& pod, |
| 222 | uint32 size, |
| 223 | uint32 immediate_data_size) { |
| 224 | return (size <= immediate_data_size) ? |
| 225 | static_cast<RETURN_TYPE>(const_cast<void*>(AddressAfterStruct(pod))) : |
| 226 | NULL; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 227 | } |
| 228 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 229 | // Computes the data size for certain gl commands like glUniform. |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 230 | bool ComputeDataSize( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 231 | GLuint count, |
| 232 | size_t size, |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 233 | unsigned int elements_per_unit, |
| 234 | uint32* dst) { |
| 235 | uint32 value; |
| 236 | if (!SafeMultiplyUint32(count, size, &value)) { |
| 237 | return false; |
| 238 | } |
| 239 | if (!SafeMultiplyUint32(value, elements_per_unit, &value)) { |
| 240 | return false; |
| 241 | } |
| 242 | *dst = value; |
| 243 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 246 | // Return true if a character belongs to the ASCII subset as defined in |
| 247 | // GLSL ES 1.0 spec section 3.1. |
| 248 | static bool CharacterIsValidForGLES(unsigned char c) { |
| 249 | // Printing characters are valid except " $ ` @ \ ' DEL. |
| 250 | if (c >= 32 && c <= 126 && |
| 251 | c != '"' && |
| 252 | c != '$' && |
| 253 | c != '`' && |
| 254 | c != '@' && |
| 255 | c != '\\' && |
| 256 | c != '\'') { |
| 257 | return true; |
| 258 | } |
| 259 | // Horizontal tab, line feed, vertical tab, form feed, carriage return |
| 260 | // are also valid. |
| 261 | if (c >= 9 && c <= 13) { |
| 262 | return true; |
| 263 | } |
| 264 | |
| 265 | return false; |
| 266 | } |
| 267 | |
| 268 | static bool StringIsValidForGLES(const char* str) { |
| 269 | for (; *str; ++str) { |
| 270 | if (!CharacterIsValidForGLES(*str)) { |
| 271 | return false; |
| 272 | } |
| 273 | } |
| 274 | return true; |
| 275 | } |
| 276 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 277 | // This class prevents any GL errors that occur when it is in scope from |
| 278 | // being reported to the client. |
| 279 | class ScopedGLErrorSuppressor { |
| 280 | public: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 281 | explicit ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 282 | const char* function_name, ErrorState* error_state); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 283 | ~ScopedGLErrorSuppressor(); |
| 284 | private: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 285 | const char* function_name_; |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 286 | ErrorState* error_state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 287 | DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); |
| 288 | }; |
| 289 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 290 | // Temporarily changes a decoder's bound texture and restore it when this |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 291 | // object goes out of scope. Also temporarily switches to using active texture |
| 292 | // unit zero in case the client has changed that to something invalid. |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 293 | class ScopedTextureBinder { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 294 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 295 | explicit ScopedTextureBinder(ContextState* state, GLuint id, GLenum target); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 296 | ~ScopedTextureBinder(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 297 | |
| 298 | private: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 299 | ContextState* state_; |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 300 | GLenum target_; |
| 301 | DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | // Temporarily changes a decoder's bound render buffer and restore it when this |
| 305 | // object goes out of scope. |
| 306 | class ScopedRenderBufferBinder { |
| 307 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 308 | explicit ScopedRenderBufferBinder(ContextState* state, GLuint id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 309 | ~ScopedRenderBufferBinder(); |
| 310 | |
| 311 | private: |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 312 | ContextState* state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 313 | DISALLOW_COPY_AND_ASSIGN(ScopedRenderBufferBinder); |
| 314 | }; |
| 315 | |
| 316 | // Temporarily changes a decoder's bound frame buffer and restore it when this |
| 317 | // object goes out of scope. |
| 318 | class ScopedFrameBufferBinder { |
| 319 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 320 | explicit ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 321 | ~ScopedFrameBufferBinder(); |
| 322 | |
| 323 | private: |
| 324 | GLES2DecoderImpl* decoder_; |
| 325 | DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); |
| 326 | }; |
| 327 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 328 | // Temporarily changes a decoder's bound frame buffer to a resolved version of |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 329 | // the multisampled offscreen render buffer if that buffer is multisampled, and, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 330 | // if it is bound or enforce_internal_framebuffer is true. If internal is |
| 331 | // true, the resolved framebuffer is not visible to the parent. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 332 | class ScopedResolvedFrameBufferBinder { |
| 333 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 334 | explicit ScopedResolvedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 335 | bool enforce_internal_framebuffer, |
| 336 | bool internal); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 337 | ~ScopedResolvedFrameBufferBinder(); |
| 338 | |
| 339 | private: |
| 340 | GLES2DecoderImpl* decoder_; |
| 341 | bool resolve_and_bind_; |
| 342 | DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); |
| 343 | }; |
| 344 | |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 345 | class ScopedModifyPixels { |
| 346 | public: |
| 347 | explicit ScopedModifyPixels(TextureRef* ref); |
| 348 | ~ScopedModifyPixels(); |
| 349 | |
| 350 | private: |
| 351 | TextureRef* ref_; |
| 352 | }; |
| 353 | |
| 354 | ScopedModifyPixels::ScopedModifyPixels(TextureRef* ref) : ref_(ref) { |
| 355 | if (ref_) |
| 356 | ref_->texture()->OnWillModifyPixels(); |
| 357 | } |
| 358 | |
| 359 | ScopedModifyPixels::~ScopedModifyPixels() { |
| 360 | if (ref_) |
| 361 | ref_->texture()->OnDidModifyPixels(); |
| 362 | } |
| 363 | |
| 364 | class ScopedRenderTo { |
| 365 | public: |
| 366 | explicit ScopedRenderTo(Framebuffer* framebuffer); |
| 367 | ~ScopedRenderTo(); |
| 368 | |
| 369 | private: |
| 370 | const Framebuffer* framebuffer_; |
| 371 | }; |
| 372 | |
| 373 | ScopedRenderTo::ScopedRenderTo(Framebuffer* framebuffer) |
| 374 | : framebuffer_(framebuffer) { |
| 375 | if (framebuffer) |
| 376 | framebuffer_->OnWillRenderTo(); |
| 377 | } |
| 378 | |
| 379 | ScopedRenderTo::~ScopedRenderTo() { |
| 380 | if (framebuffer_) |
| 381 | framebuffer_->OnDidRenderTo(); |
| 382 | } |
| 383 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 384 | // Encapsulates an OpenGL texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 385 | class BackTexture { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 386 | public: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 387 | explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 388 | ~BackTexture(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 389 | |
| 390 | // Create a new render texture. |
| 391 | void Create(); |
| 392 | |
| 393 | // Set the initial size and format of a render texture or resize it. |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 394 | bool AllocateStorage(const gfx::Size& size, GLenum format, bool zero); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 395 | |
| 396 | // Copy the contents of the currently bound frame buffer. |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 397 | void Copy(const gfx::Size& size, GLenum format); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 398 | |
| 399 | // Destroy the render texture. This must be explicitly called before |
| 400 | // destroying this object. |
| 401 | void Destroy(); |
| 402 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 403 | // Invalidate the texture. This can be used when a context is lost and it is |
| 404 | // not possible to make it current in order to free the resource. |
| 405 | void Invalidate(); |
| 406 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 407 | GLuint id() const { |
| 408 | return id_; |
| 409 | } |
| 410 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 411 | gfx::Size size() const { |
| 412 | return size_; |
| 413 | } |
| 414 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 415 | private: |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 416 | MemoryTypeTracker memory_tracker_; |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 417 | ContextState* state_; |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 418 | size_t bytes_allocated_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 419 | GLuint id_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 420 | gfx::Size size_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 421 | DISALLOW_COPY_AND_ASSIGN(BackTexture); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 422 | }; |
| 423 | |
| 424 | // Encapsulates an OpenGL render buffer of any format. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 425 | class BackRenderbuffer { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 426 | public: |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 427 | explicit BackRenderbuffer( |
| 428 | RenderbufferManager* renderbuffer_manager, |
| 429 | MemoryTracker* memory_tracker, |
| 430 | ContextState* state); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 431 | ~BackRenderbuffer(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 432 | |
| 433 | // Create a new render buffer. |
| 434 | void Create(); |
| 435 | |
| 436 | // Set the initial size and format of a render buffer or resize it. |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 437 | bool AllocateStorage(const FeatureInfo* feature_info, |
| 438 | const gfx::Size& size, |
| 439 | GLenum format, |
| 440 | GLsizei samples); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 441 | |
| 442 | // Destroy the render buffer. This must be explicitly called before destroying |
| 443 | // this object. |
| 444 | void Destroy(); |
| 445 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 446 | // Invalidate the render buffer. This can be used when a context is lost and |
| 447 | // it is not possible to make it current in order to free the resource. |
| 448 | void Invalidate(); |
| 449 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 450 | GLuint id() const { |
| 451 | return id_; |
| 452 | } |
| 453 | |
| 454 | private: |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 455 | RenderbufferManager* renderbuffer_manager_; |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 456 | MemoryTypeTracker memory_tracker_; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 457 | ContextState* state_; |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 458 | size_t bytes_allocated_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 459 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 460 | DISALLOW_COPY_AND_ASSIGN(BackRenderbuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 461 | }; |
| 462 | |
| 463 | // Encapsulates an OpenGL frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 464 | class BackFramebuffer { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 465 | public: |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 466 | explicit BackFramebuffer(GLES2DecoderImpl* decoder); |
| 467 | ~BackFramebuffer(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 468 | |
| 469 | // Create a new frame buffer. |
| 470 | void Create(); |
| 471 | |
| 472 | // Attach a color render buffer to a frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 473 | void AttachRenderTexture(BackTexture* texture); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 474 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 475 | // Attach a render buffer to a frame buffer. Note that this unbinds any |
| 476 | // currently bound frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 477 | void AttachRenderBuffer(GLenum target, BackRenderbuffer* render_buffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 478 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 479 | // Destroy the frame buffer. This must be explicitly called before destroying |
| 480 | // this object. |
| 481 | void Destroy(); |
| 482 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 483 | // Invalidate the frame buffer. This can be used when a context is lost and it |
| 484 | // is not possible to make it current in order to free the resource. |
| 485 | void Invalidate(); |
| 486 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 487 | // See glCheckFramebufferStatusEXT. |
| 488 | GLenum CheckStatus(); |
| 489 | |
| 490 | GLuint id() const { |
| 491 | return id_; |
| 492 | } |
| 493 | |
| 494 | private: |
| 495 | GLES2DecoderImpl* decoder_; |
| 496 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 497 | DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 498 | }; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 499 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 500 | struct FenceCallback { |
| 501 | explicit FenceCallback() |
| 502 | : fence(gfx::GLFence::Create()) { |
| 503 | DCHECK(fence); |
| 504 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 505 | std::vector<base::Closure> callbacks; |
| 506 | scoped_ptr<gfx::GLFence> fence; |
| 507 | }; |
| 508 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 509 | class AsyncUploadTokenCompletionObserver |
| 510 | : public AsyncPixelTransferCompletionObserver { |
| 511 | public: |
| 512 | explicit AsyncUploadTokenCompletionObserver(uint32 async_upload_token) |
| 513 | : async_upload_token_(async_upload_token) { |
| 514 | } |
| 515 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 516 | void DidComplete(const AsyncMemoryParams& mem_params) override { |
dcheng | 6ef3c555 | 2014-08-30 05:34:19 | [diff] [blame] | 517 | DCHECK(mem_params.buffer().get()); |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 518 | void* data = mem_params.GetDataAddress(); |
| 519 | AsyncUploadSync* sync = static_cast<AsyncUploadSync*>(data); |
| 520 | sync->SetAsyncUploadToken(async_upload_token_); |
| 521 | } |
| 522 | |
| 523 | private: |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 524 | ~AsyncUploadTokenCompletionObserver() override {} |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 525 | |
| 526 | uint32 async_upload_token_; |
| 527 | |
| 528 | DISALLOW_COPY_AND_ASSIGN(AsyncUploadTokenCompletionObserver); |
| 529 | }; |
| 530 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 531 | // } // anonymous namespace. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 532 | |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 533 | // static |
| 534 | const unsigned int GLES2Decoder::kDefaultStencilMask = |
| 535 | static_cast<unsigned int>(-1); |
| 536 | |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 537 | bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, |
| 538 | uint32* service_texture_id) { |
| 539 | return false; |
| 540 | } |
| 541 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 542 | GLES2Decoder::GLES2Decoder() |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 543 | : initialized_(false), |
| 544 | debug_(false), |
zmo | 84c0820 | 2014-11-23 15:28:40 | [diff] [blame] | 545 | log_commands_(false), |
| 546 | unsafe_es3_apis_enabled_(false) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 547 | } |
| 548 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 549 | GLES2Decoder::~GLES2Decoder() { |
| 550 | } |
| 551 | |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 552 | void GLES2Decoder::BeginDecoding() {} |
| 553 | |
| 554 | void GLES2Decoder::EndDecoding() {} |
| 555 | |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 556 | // This class implements GLES2Decoder so we don't have to expose all the GLES2 |
| 557 | // cmd stuff to outside this class. |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 558 | class GLES2DecoderImpl : public GLES2Decoder, |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 559 | public FramebufferManager::TextureDetachObserver, |
| 560 | public ErrorStateClient { |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 561 | public: |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 562 | explicit GLES2DecoderImpl(ContextGroup* group); |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 563 | ~GLES2DecoderImpl() override; |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 564 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 565 | // Overridden from AsyncAPIInterface. |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 566 | Error DoCommand(unsigned int command, |
| 567 | unsigned int arg_count, |
| 568 | const void* args) override; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 569 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 570 | error::Error DoCommands(unsigned int num_commands, |
| 571 | const void* buffer, |
| 572 | int num_entries, |
| 573 | int* entries_processed) override; |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 574 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 575 | template <bool DebugImpl> |
| 576 | error::Error DoCommandsImpl(unsigned int num_commands, |
| 577 | const void* buffer, |
| 578 | int num_entries, |
| 579 | int* entries_processed); |
| 580 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 581 | // Overridden from AsyncAPIInterface. |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 582 | const char* GetCommandName(unsigned int command_id) const override; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 583 | |
| 584 | // Overridden from GLES2Decoder. |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 585 | bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
| 586 | const scoped_refptr<gfx::GLContext>& context, |
| 587 | bool offscreen, |
| 588 | const gfx::Size& size, |
| 589 | const DisallowedFeatures& disallowed_features, |
| 590 | const std::vector<int32>& attribs) override; |
| 591 | void Destroy(bool have_context) override; |
| 592 | void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override; |
| 593 | void ProduceFrontBuffer(const Mailbox& mailbox) override; |
| 594 | bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 595 | void UpdateParentTextureInfo(); |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 596 | bool MakeCurrent() override; |
| 597 | GLES2Util* GetGLES2Util() override { return &util_; } |
| 598 | gfx::GLContext* GetGLContext() override { return context_.get(); } |
| 599 | ContextGroup* GetContextGroup() override { return group_.get(); } |
| 600 | Capabilities GetCapabilities() override; |
| 601 | void RestoreState(const ContextState* prev_state) override; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 602 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 603 | void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); } |
| 604 | void RestoreAllTextureUnitBindings( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 605 | const ContextState* prev_state) const override { |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 606 | state_.RestoreAllTextureUnitBindings(prev_state); |
[email protected] | 21700451 | 2013-05-10 21:25:55 | [diff] [blame] | 607 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 608 | void RestoreActiveTextureUnitBinding(unsigned int target) const override { |
[email protected] | 4b2d2b26 | 2014-03-21 22:05:27 | [diff] [blame] | 609 | state_.RestoreActiveTextureUnitBinding(target); |
| 610 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 611 | void RestoreBufferBindings() const override { |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 612 | state_.RestoreBufferBindings(); |
| 613 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 614 | void RestoreGlobalState() const override { state_.RestoreGlobalState(NULL); } |
| 615 | void RestoreProgramBindings() const override { |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 616 | state_.RestoreProgramBindings(); |
| 617 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 618 | void RestoreTextureUnitBindings(unsigned unit) const override { |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 619 | state_.RestoreTextureUnitBindings(unit, NULL); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 620 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 621 | void RestoreFramebufferBindings() const override; |
| 622 | void RestoreRenderbufferBindings() override; |
| 623 | void RestoreTextureState(unsigned service_id) const override; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 624 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 625 | void ClearAllAttributes() const override; |
| 626 | void RestoreAllAttributes() const override; |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 627 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 628 | QueryManager* GetQueryManager() override { return query_manager_.get(); } |
| 629 | VertexArrayManager* GetVertexArrayManager() override { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 630 | return vertex_array_manager_.get(); |
| 631 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 632 | ImageManager* GetImageManager() override { return image_manager_.get(); } |
orglofch | 33edd84 | 2014-12-03 05:32:15 | [diff] [blame] | 633 | |
| 634 | ValuebufferManager* GetValuebufferManager() override { |
| 635 | return valuebuffer_manager(); |
| 636 | } |
| 637 | |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 638 | bool ProcessPendingQueries(bool did_finish) override; |
orglofch | 33edd84 | 2014-12-03 05:32:15 | [diff] [blame] | 639 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 640 | bool HasMoreIdleWork() override; |
| 641 | void PerformIdleWork() override; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 642 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 643 | void WaitForReadPixels(base::Closure callback) override; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 644 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 645 | void SetResizeCallback( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 646 | const base::Callback<void(gfx::Size, float)>& callback) override; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 647 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 648 | Logger* GetLogger() override; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 649 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 650 | void BeginDecoding() override; |
| 651 | void EndDecoding() override; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 652 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 653 | ErrorState* GetErrorState() override; |
| 654 | const ContextState* GetContextState() override { return &state_; } |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 655 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 656 | void SetShaderCacheCallback(const ShaderCacheCallback& callback) override; |
| 657 | void SetWaitSyncPointCallback(const WaitSyncPointCallback& callback) override; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 658 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 659 | AsyncPixelTransferManager* GetAsyncPixelTransferManager() override; |
| 660 | void ResetAsyncPixelTransferManagerForTest() override; |
| 661 | void SetAsyncPixelTransferManagerForTest( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 662 | AsyncPixelTransferManager* manager) override; |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 663 | void SetIgnoreCachedStateForTest(bool ignore) override; |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 664 | void ProcessFinishedAsyncTransfers(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 665 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 666 | bool GetServiceTextureId(uint32 client_texture_id, |
| 667 | uint32* service_texture_id) override; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 668 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 669 | uint32 GetTextureUploadCount() override; |
| 670 | base::TimeDelta GetTotalTextureUploadTime() override; |
| 671 | base::TimeDelta GetTotalProcessingCommandsTime() override; |
| 672 | void AddProcessingCommandsTime(base::TimeDelta) override; |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 673 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 674 | // Restores the current state to the user's settings. |
| 675 | void RestoreCurrentFramebufferBindings(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 676 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 677 | // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
| 678 | void ApplyDirtyState(); |
| 679 | |
| 680 | // These check the state of the currently bound framebuffer or the |
| 681 | // backbuffer if no framebuffer is bound. |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 682 | // If all_draw_buffers is false, only check with COLOR_ATTACHMENT0, otherwise |
| 683 | // check with all attached and enabled color attachments. |
| 684 | bool BoundFramebufferHasColorAttachmentWithAlpha(bool all_draw_buffers); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 685 | bool BoundFramebufferHasDepthAttachment(); |
| 686 | bool BoundFramebufferHasStencilAttachment(); |
| 687 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 688 | error::ContextLostReason GetContextLostReason() override; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 689 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 690 | // Overridden from FramebufferManager::TextureDetachObserver: |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 691 | void OnTextureRefDetachedFromFramebuffer(TextureRef* texture) override; |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 692 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 693 | // Overriden from ErrorStateClient. |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 694 | void OnContextLostError() override; |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 695 | void OnOutOfMemoryError() override; |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 696 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 697 | // Ensure Renderbuffer corresponding to last DoBindRenderbuffer() is bound. |
| 698 | void EnsureRenderbufferBound(); |
| 699 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 700 | // Helpers to facilitate calling into compatible extensions. |
| 701 | static void RenderbufferStorageMultisampleHelper( |
| 702 | const FeatureInfo* feature_info, |
| 703 | GLenum target, |
| 704 | GLsizei samples, |
| 705 | GLenum internal_format, |
| 706 | GLsizei width, |
| 707 | GLsizei height); |
| 708 | |
| 709 | void BlitFramebufferHelper(GLint srcX0, |
| 710 | GLint srcY0, |
| 711 | GLint srcX1, |
| 712 | GLint srcY1, |
| 713 | GLint dstX0, |
| 714 | GLint dstY0, |
| 715 | GLint dstX1, |
| 716 | GLint dstY1, |
| 717 | GLbitfield mask, |
| 718 | GLenum filter); |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 719 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 720 | private: |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 721 | friend class ScopedFrameBufferBinder; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 722 | friend class ScopedResolvedFrameBufferBinder; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 723 | friend class BackFramebuffer; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 724 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 725 | // Initialize or re-initialize the shader translator. |
| 726 | bool InitializeShaderTranslator(); |
| 727 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 728 | void UpdateCapabilities(); |
| 729 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 730 | // Helpers for the glGen and glDelete functions. |
| 731 | bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 732 | void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 733 | bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 734 | void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 735 | bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 736 | void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 737 | bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
| 738 | void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 739 | bool GenValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* client_ids); |
| 740 | void DeleteValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 741 | bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
| 742 | void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 743 | bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
| 744 | void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 745 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 746 | // Helper for async upload token completion notification callback. |
| 747 | base::Closure AsyncUploadTokenCompletionClosure(uint32 async_upload_token, |
| 748 | uint32 sync_data_shm_id, |
| 749 | uint32 sync_data_shm_offset); |
| 750 | |
| 751 | |
| 752 | |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 753 | // Workarounds |
| 754 | void OnFboChanged() const; |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 755 | void OnUseFramebuffer() const; |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 756 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 757 | // TODO(gman): Cache these pointers? |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 758 | BufferManager* buffer_manager() { |
| 759 | return group_->buffer_manager(); |
| 760 | } |
| 761 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 762 | RenderbufferManager* renderbuffer_manager() { |
| 763 | return group_->renderbuffer_manager(); |
| 764 | } |
| 765 | |
| 766 | FramebufferManager* framebuffer_manager() { |
| 767 | return group_->framebuffer_manager(); |
| 768 | } |
| 769 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 770 | ValuebufferManager* valuebuffer_manager() { |
| 771 | return group_->valuebuffer_manager(); |
| 772 | } |
| 773 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 774 | ProgramManager* program_manager() { |
| 775 | return group_->program_manager(); |
| 776 | } |
| 777 | |
| 778 | ShaderManager* shader_manager() { |
| 779 | return group_->shader_manager(); |
| 780 | } |
| 781 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 782 | ShaderTranslatorCache* shader_translator_cache() { |
| 783 | return group_->shader_translator_cache(); |
| 784 | } |
| 785 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 786 | const TextureManager* texture_manager() const { |
| 787 | return group_->texture_manager(); |
| 788 | } |
| 789 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 790 | TextureManager* texture_manager() { |
| 791 | return group_->texture_manager(); |
| 792 | } |
| 793 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 794 | MailboxManager* mailbox_manager() { |
| 795 | return group_->mailbox_manager(); |
| 796 | } |
| 797 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 798 | ImageManager* image_manager() { return image_manager_.get(); } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 799 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 800 | VertexArrayManager* vertex_array_manager() { |
| 801 | return vertex_array_manager_.get(); |
| 802 | } |
| 803 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 804 | MemoryTracker* memory_tracker() { |
| 805 | return group_->memory_tracker(); |
| 806 | } |
| 807 | |
| 808 | bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
| 809 | MemoryTracker* tracker = memory_tracker(); |
| 810 | if (tracker) { |
| 811 | return tracker->EnsureGPUMemoryAvailable(estimated_size); |
| 812 | } |
| 813 | return true; |
| 814 | } |
| 815 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 816 | bool IsOffscreenBufferMultisampled() const { |
| 817 | return offscreen_target_samples_ > 1; |
| 818 | } |
| 819 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 820 | // Creates a Texture for the given texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 821 | TextureRef* CreateTexture( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 822 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 823 | return texture_manager()->CreateTexture(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 824 | } |
| 825 | |
| 826 | // Gets the texture info for the given texture. Returns NULL if none exists. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 827 | TextureRef* GetTexture(GLuint client_id) const { |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 828 | return texture_manager()->GetTexture(client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | // Deletes the texture info for the given texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 832 | void RemoveTexture(GLuint client_id) { |
| 833 | texture_manager()->RemoveTexture(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 834 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 835 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 836 | // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| 837 | // or regular back buffer). |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 838 | gfx::Size GetBoundReadFrameBufferSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 839 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 840 | // Get the format of the currently bound frame buffer (either FBO or regular |
| 841 | // back buffer) |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 842 | GLenum GetBoundReadFrameBufferTextureType(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 843 | GLenum GetBoundReadFrameBufferInternalFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 844 | GLenum GetBoundDrawFrameBufferInternalFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 845 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 846 | // Wrapper for CompressedTexImage2D commands. |
| 847 | error::Error DoCompressedTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 848 | GLenum target, |
| 849 | GLint level, |
| 850 | GLenum internal_format, |
| 851 | GLsizei width, |
| 852 | GLsizei height, |
| 853 | GLint border, |
| 854 | GLsizei image_size, |
| 855 | const void* data); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 856 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 857 | // Wrapper for CompressedTexSubImage2D. |
| 858 | void DoCompressedTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 859 | GLenum target, |
| 860 | GLint level, |
| 861 | GLint xoffset, |
| 862 | GLint yoffset, |
| 863 | GLsizei width, |
| 864 | GLsizei height, |
| 865 | GLenum format, |
| 866 | GLsizei imageSize, |
| 867 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 868 | |
| 869 | // Wrapper for CopyTexImage2D. |
| 870 | void DoCopyTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 871 | GLenum target, |
| 872 | GLint level, |
| 873 | GLenum internal_format, |
| 874 | GLint x, |
| 875 | GLint y, |
| 876 | GLsizei width, |
| 877 | GLsizei height, |
| 878 | GLint border); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 879 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 880 | // Wrapper for SwapBuffers. |
| 881 | void DoSwapBuffers(); |
| 882 | |
bajones | 2345c1f | 2014-12-09 04:45:51 | [diff] [blame] | 883 | // Wrapper for SwapInterval. |
| 884 | void DoSwapInterval(int interval); |
| 885 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 886 | // Wrapper for CopyTexSubImage2D. |
| 887 | void DoCopyTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 888 | GLenum target, |
| 889 | GLint level, |
| 890 | GLint xoffset, |
| 891 | GLint yoffset, |
| 892 | GLint x, |
| 893 | GLint y, |
| 894 | GLsizei width, |
| 895 | GLsizei height); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 896 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 897 | // Validation for TexSubImage2D. |
| 898 | bool ValidateTexSubImage2D( |
| 899 | error::Error* error, |
| 900 | const char* function_name, |
| 901 | GLenum target, |
| 902 | GLint level, |
| 903 | GLint xoffset, |
| 904 | GLint yoffset, |
| 905 | GLsizei width, |
| 906 | GLsizei height, |
| 907 | GLenum format, |
| 908 | GLenum type, |
| 909 | const void * data); |
| 910 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 911 | // Wrapper for TexSubImage2D. |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 912 | error::Error DoTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 913 | GLenum target, |
| 914 | GLint level, |
| 915 | GLint xoffset, |
| 916 | GLint yoffset, |
| 917 | GLsizei width, |
| 918 | GLsizei height, |
| 919 | GLenum format, |
| 920 | GLenum type, |
| 921 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 922 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 923 | // Extra validation for async tex(Sub)Image2D. |
| 924 | bool ValidateAsyncTransfer( |
| 925 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 926 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 927 | GLenum target, |
| 928 | GLint level, |
| 929 | const void * data); |
| 930 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 931 | // Wrapper for TexImageIOSurface2DCHROMIUM. |
| 932 | void DoTexImageIOSurface2DCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 933 | GLenum target, |
| 934 | GLsizei width, |
| 935 | GLsizei height, |
| 936 | GLuint io_surface_id, |
| 937 | GLuint plane); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 938 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 939 | void DoCopyTextureCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 940 | GLenum target, |
| 941 | GLuint source_id, |
| 942 | GLuint target_id, |
| 943 | GLint level, |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 944 | GLenum internal_format, |
| 945 | GLenum dest_type); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 946 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 947 | // Wrapper for TexStorage2DEXT. |
| 948 | void DoTexStorage2DEXT( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 949 | GLenum target, |
| 950 | GLint levels, |
| 951 | GLenum internal_format, |
| 952 | GLsizei width, |
| 953 | GLsizei height); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 954 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 955 | void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 956 | void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, |
| 957 | const GLbyte* key); |
| 958 | void ProduceTextureRef(std::string func_name, TextureRef* texture_ref, |
| 959 | GLenum target, const GLbyte* data); |
| 960 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 961 | void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 962 | void DoCreateAndConsumeTextureCHROMIUM(GLenum target, const GLbyte* key, |
| 963 | GLuint client_id); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 964 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 965 | bool DoIsValuebufferCHROMIUM(GLuint client_id); |
| 966 | void DoBindValueBufferCHROMIUM(GLenum target, GLuint valuebuffer); |
| 967 | void DoSubscribeValueCHROMIUM(GLenum target, GLenum subscription); |
| 968 | void DoPopulateSubscribedValuesCHROMIUM(GLenum target); |
| 969 | void DoUniformValueBufferCHROMIUM(GLint location, |
| 970 | GLenum target, |
| 971 | GLenum subscription); |
| 972 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 973 | void DoBindTexImage2DCHROMIUM( |
| 974 | GLenum target, |
| 975 | GLint image_id); |
| 976 | void DoReleaseTexImage2DCHROMIUM( |
| 977 | GLenum target, |
| 978 | GLint image_id); |
| 979 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 980 | void DoTraceEndCHROMIUM(void); |
| 981 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 982 | void DoDrawBuffersEXT(GLsizei count, const GLenum* bufs); |
| 983 | |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 984 | void DoLoseContextCHROMIUM(GLenum current, GLenum other); |
| 985 | |
kkinnunen | 337d5963 | 2014-08-26 10:19:57 | [diff] [blame] | 986 | void DoMatrixLoadfCHROMIUM(GLenum matrix_mode, const GLfloat* matrix); |
| 987 | void DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode); |
| 988 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 989 | // Creates a Program for the given program. |
| 990 | Program* CreateProgram( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 991 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 992 | return program_manager()->CreateProgram(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 993 | } |
| 994 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 995 | // Gets the program info for the given program. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 996 | Program* GetProgram(GLuint client_id) { |
| 997 | return program_manager()->GetProgram(client_id); |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 998 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 999 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1000 | #if defined(NDEBUG) |
| 1001 | void LogClientServiceMapping( |
| 1002 | const char* /* function_name */, |
| 1003 | GLuint /* client_id */, |
| 1004 | GLuint /* service_id */) { |
| 1005 | } |
| 1006 | template<typename T> |
| 1007 | void LogClientServiceForInfo( |
| 1008 | T* /* info */, GLuint /* client_id */, const char* /* function_name */) { |
| 1009 | } |
| 1010 | #else |
| 1011 | void LogClientServiceMapping( |
| 1012 | const char* function_name, GLuint client_id, GLuint service_id) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 1013 | if (service_logging_) { |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 1014 | VLOG(1) << "[" << logger_.GetLogPrefix() << "] " << function_name |
| 1015 | << ": client_id = " << client_id |
| 1016 | << ", service_id = " << service_id; |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 1017 | } |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1018 | } |
| 1019 | template<typename T> |
| 1020 | void LogClientServiceForInfo( |
| 1021 | T* info, GLuint client_id, const char* function_name) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 1022 | if (info) { |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1023 | LogClientServiceMapping(function_name, client_id, info->service_id()); |
| 1024 | } |
| 1025 | } |
| 1026 | #endif |
| 1027 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1028 | // Gets the program info for the given program. If it's not a program |
| 1029 | // generates a GL error. Returns NULL if not program. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1030 | Program* GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1031 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1032 | Program* program = GetProgram(client_id); |
| 1033 | if (!program) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1034 | if (GetShader(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1035 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1036 | GL_INVALID_OPERATION, function_name, "shader passed for program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1037 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1038 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1039 | } |
| 1040 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1041 | LogClientServiceForInfo(program, client_id, function_name); |
| 1042 | return program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1046 | // Creates a Shader for the given shader. |
| 1047 | Shader* CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 1048 | GLuint client_id, |
| 1049 | GLuint service_id, |
| 1050 | GLenum shader_type) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1051 | return shader_manager()->CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 1052 | client_id, service_id, shader_type); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | // Gets the shader info for the given shader. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1056 | Shader* GetShader(GLuint client_id) { |
| 1057 | return shader_manager()->GetShader(client_id); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1058 | } |
| 1059 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1060 | // Gets the shader info for the given shader. If it's not a shader generates a |
| 1061 | // GL error. Returns NULL if not shader. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1062 | Shader* GetShaderInfoNotProgram( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1063 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1064 | Shader* shader = GetShader(client_id); |
| 1065 | if (!shader) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1066 | if (GetProgram(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1067 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1068 | GL_INVALID_OPERATION, function_name, "program passed for shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1069 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1070 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1071 | GL_INVALID_VALUE, function_name, "unknown shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1072 | } |
| 1073 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1074 | LogClientServiceForInfo(shader, client_id, function_name); |
| 1075 | return shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1076 | } |
| 1077 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1078 | // Creates a buffer info for the given buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1079 | void CreateBuffer(GLuint client_id, GLuint service_id) { |
| 1080 | return buffer_manager()->CreateBuffer(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1081 | } |
| 1082 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1083 | // Gets the buffer info for the given buffer. |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 1084 | Buffer* GetBuffer(GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 1085 | Buffer* buffer = buffer_manager()->GetBuffer(client_id); |
| 1086 | return buffer; |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 1087 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1088 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1089 | // Removes any buffers in the VertexAtrribInfos and BufferInfos. This is used |
| 1090 | // on glDeleteBuffers so we can make sure the user does not try to render |
| 1091 | // with deleted buffers. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1092 | void RemoveBuffer(GLuint client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1093 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1094 | // Creates a framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1095 | void CreateFramebuffer(GLuint client_id, GLuint service_id) { |
| 1096 | return framebuffer_manager()->CreateFramebuffer(client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | // Gets the framebuffer info for the given framebuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1100 | Framebuffer* GetFramebuffer(GLuint client_id) { |
| 1101 | return framebuffer_manager()->GetFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | // Removes the framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1105 | void RemoveFramebuffer(GLuint client_id) { |
| 1106 | framebuffer_manager()->RemoveFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | // Creates a renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1110 | void CreateRenderbuffer(GLuint client_id, GLuint service_id) { |
| 1111 | return renderbuffer_manager()->CreateRenderbuffer( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1112 | client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | // Gets the renderbuffer info for the given renderbuffer. |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1116 | Renderbuffer* GetRenderbuffer(GLuint client_id) { |
| 1117 | return renderbuffer_manager()->GetRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | // Removes the renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1121 | void RemoveRenderbuffer(GLuint client_id) { |
| 1122 | renderbuffer_manager()->RemoveRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1123 | } |
| 1124 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 1125 | // Creates a valuebuffer info for the given valuebuffer. |
| 1126 | void CreateValuebuffer(GLuint client_id) { |
| 1127 | return valuebuffer_manager()->CreateValuebuffer(client_id); |
| 1128 | } |
| 1129 | |
| 1130 | // Gets the valuebuffer info for a given valuebuffer. |
| 1131 | Valuebuffer* GetValuebuffer(GLuint client_id) { |
| 1132 | return valuebuffer_manager()->GetValuebuffer(client_id); |
| 1133 | } |
| 1134 | |
| 1135 | // Removes the valuebuffer info for the given valuebuffer. |
| 1136 | void RemoveValuebuffer(GLuint client_id) { |
| 1137 | valuebuffer_manager()->RemoveValuebuffer(client_id); |
| 1138 | } |
| 1139 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1140 | // Gets the vertex attrib manager for the given vertex array. |
| 1141 | VertexAttribManager* GetVertexAttribManager(GLuint client_id) { |
| 1142 | VertexAttribManager* info = |
| 1143 | vertex_array_manager()->GetVertexAttribManager(client_id); |
| 1144 | return info; |
| 1145 | } |
| 1146 | |
| 1147 | // Removes the vertex attrib manager for the given vertex array. |
| 1148 | void RemoveVertexAttribManager(GLuint client_id) { |
| 1149 | vertex_array_manager()->RemoveVertexAttribManager(client_id); |
| 1150 | } |
| 1151 | |
| 1152 | // Creates a vertex attrib manager for the given vertex array. |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 1153 | scoped_refptr<VertexAttribManager> CreateVertexAttribManager( |
| 1154 | GLuint client_id, |
| 1155 | GLuint service_id, |
| 1156 | bool client_visible) { |
| 1157 | return vertex_array_manager()->CreateVertexAttribManager( |
| 1158 | client_id, service_id, group_->max_vertex_attribs(), client_visible); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1159 | } |
| 1160 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1161 | void DoBindAttribLocation(GLuint client_id, GLuint index, const char* name); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 1162 | void DoBindUniformLocationCHROMIUM( |
| 1163 | GLuint client_id, GLint location, const char* name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1164 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 1165 | error::Error GetAttribLocationHelper( |
| 1166 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1167 | const std::string& name_str); |
| 1168 | |
| 1169 | error::Error GetUniformLocationHelper( |
| 1170 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1171 | const std::string& name_str); |
| 1172 | |
zmo | 1bb3d1d | 2015-01-21 20:29:43 | [diff] [blame^] | 1173 | // Wrapper for glShaderSource. |
| 1174 | void DoShaderSource( |
| 1175 | GLuint client_id, GLsizei count, const char** data, const GLint* length); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1176 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1177 | // Clear any textures used by the current program. |
| 1178 | bool ClearUnclearedTextures(); |
| 1179 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1180 | // Clears any uncleared attachments attached to the given frame buffer. |
| 1181 | // Returns false if there was a generated GL error. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1182 | void ClearUnclearedAttachments(GLenum target, Framebuffer* framebuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1183 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1184 | // overridden from GLES2Decoder |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 1185 | bool ClearLevel(unsigned service_id, |
| 1186 | unsigned bind_target, |
| 1187 | unsigned target, |
| 1188 | int level, |
| 1189 | unsigned internal_format, |
| 1190 | unsigned format, |
| 1191 | unsigned type, |
| 1192 | int width, |
| 1193 | int height, |
| 1194 | bool is_texture_immutable) override; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1195 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 1196 | // Restore all GL state that affects clearing. |
| 1197 | void RestoreClearState(); |
| 1198 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1199 | // Remembers the state of some capabilities. |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1200 | // Returns: true if glEnable/glDisable should actually be called. |
| 1201 | bool SetCapabilityState(GLenum cap, bool enabled); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1202 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1203 | // Check that the currently bound framebuffers are valid. |
| 1204 | // Generates GL error if not. |
| 1205 | bool CheckBoundFramebuffersValid(const char* func_name); |
| 1206 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 1207 | // Check that the currently bound read framebuffer has a color image |
| 1208 | // attached. Generates GL error if not. |
| 1209 | bool CheckBoundReadFramebufferColorAttachment(const char* func_name); |
| 1210 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 1211 | // Check that the currently bound read framebuffer's color image |
| 1212 | // isn't the target texture of the glCopyTex{Sub}Image2D. |
| 1213 | bool FormsTextureCopyingFeedbackLoop(TextureRef* texture, GLint level); |
| 1214 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1215 | // Check if a framebuffer meets our requirements. |
| 1216 | bool CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1217 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1218 | GLenum target, |
| 1219 | const char* func_name); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1220 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 1221 | // Check if the current valuebuffer exists and is valid. If not generates |
| 1222 | // the appropriate GL error. Returns true if the current valuebuffer is in |
| 1223 | // a usable state. |
| 1224 | bool CheckCurrentValuebuffer(const char* function_name); |
| 1225 | |
| 1226 | // Check if the current valuebuffer exists and is valiud and that the |
| 1227 | // value buffer is actually subscribed to the given subscription |
| 1228 | bool CheckCurrentValuebufferForSubscription(GLenum subscription, |
| 1229 | const char* function_name); |
| 1230 | |
| 1231 | // Check if the location can be used for the given subscription target. If not |
| 1232 | // generates the appropriate GL error. Returns true if the location is usable |
| 1233 | bool CheckSubscriptionTarget(GLint location, |
| 1234 | GLenum subscription, |
| 1235 | const char* function_name); |
| 1236 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1237 | // Checks if the current program exists and is valid. If not generates the |
| 1238 | // appropriate GL error. Returns true if the current program is in a usable |
| 1239 | // state. |
| 1240 | bool CheckCurrentProgram(const char* function_name); |
| 1241 | |
| 1242 | // Checks if the current program exists and is valid and that location is not |
| 1243 | // -1. If the current program is not valid generates the appropriate GL |
| 1244 | // error. Returns true if the current program is in a usable state and |
| 1245 | // location is not -1. |
| 1246 | bool CheckCurrentProgramForUniform(GLint location, const char* function_name); |
| 1247 | |
zmo | f9a81360f | 2014-10-17 00:06:14 | [diff] [blame] | 1248 | // Checks if the current program samples a texture that is also the color |
| 1249 | // image of the current bound framebuffer, i.e., the source and destination |
| 1250 | // of the draw operation are the same. |
| 1251 | bool CheckDrawingFeedbackLoops(); |
| 1252 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 1253 | // Checks if |api_type| is valid for the given uniform |
| 1254 | // If the api type is not valid generates the appropriate GL |
| 1255 | // error. Returns true if |api_type| is valid for the uniform |
| 1256 | bool CheckUniformForApiType(const Program::UniformInfo* info, |
| 1257 | const char* function_name, |
| 1258 | Program::UniformApiType api_type); |
| 1259 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1260 | // Gets the type of a uniform for a location in the current program. Sets GL |
| 1261 | // errors if the current program is not valid. Returns true if the current |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1262 | // program is valid and the location exists. Adjusts count so it |
| 1263 | // does not overflow the uniform. |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 1264 | bool PrepForSetUniformByLocation(GLint fake_location, |
| 1265 | const char* function_name, |
| 1266 | Program::UniformApiType api_type, |
| 1267 | GLint* real_location, |
| 1268 | GLenum* type, |
| 1269 | GLsizei* count); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1270 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1271 | // Gets the service id for any simulated backbuffer fbo. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1272 | GLuint GetBackbufferServiceId() const; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1273 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1274 | // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv |
| 1275 | bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); |
| 1276 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 1277 | // Helper for glGetVertexAttrib |
| 1278 | void GetVertexAttribHelper( |
| 1279 | const VertexAttrib* attrib, GLenum pname, GLint* param); |
| 1280 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1281 | // Wrapper for glCreateProgram |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1282 | bool CreateProgramHelper(GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1283 | |
| 1284 | // Wrapper for glCreateShader |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1285 | bool CreateShaderHelper(GLenum type, GLuint client_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1286 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1287 | // Wrapper for glActiveTexture |
| 1288 | void DoActiveTexture(GLenum texture_unit); |
| 1289 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1290 | // Wrapper for glAttachShader |
| 1291 | void DoAttachShader(GLuint client_program_id, GLint client_shader_id); |
| 1292 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1293 | // Wrapper for glBindBuffer since we need to track the current targets. |
| 1294 | void DoBindBuffer(GLenum target, GLuint buffer); |
| 1295 | |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 1296 | // Wrapper for glBindFramebuffer since we need to track the current targets. |
| 1297 | void DoBindFramebuffer(GLenum target, GLuint framebuffer); |
| 1298 | |
| 1299 | // Wrapper for glBindRenderbuffer since we need to track the current targets. |
| 1300 | void DoBindRenderbuffer(GLenum target, GLuint renderbuffer); |
| 1301 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1302 | // Wrapper for glBindTexture since we need to track the current targets. |
| 1303 | void DoBindTexture(GLenum target, GLuint texture); |
| 1304 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1305 | // Wrapper for glBindVertexArrayOES |
| 1306 | void DoBindVertexArrayOES(GLuint array); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 1307 | void EmulateVertexArrayState(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1308 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1309 | // Wrapper for glBlitFramebufferCHROMIUM. |
| 1310 | void DoBlitFramebufferCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1311 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 1312 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 1313 | GLbitfield mask, GLenum filter); |
| 1314 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1315 | // Wrapper for glBufferSubData. |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 1316 | void DoBufferSubData( |
| 1317 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); |
| 1318 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1319 | // Wrapper for glCheckFramebufferStatus |
| 1320 | GLenum DoCheckFramebufferStatus(GLenum target); |
| 1321 | |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1322 | // Wrapper for glClear |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1323 | error::Error DoClear(GLbitfield mask); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1324 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1325 | // Wrappers for various state. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1326 | void DoDepthRangef(GLclampf znear, GLclampf zfar); |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 1327 | void DoSampleCoverage(GLclampf value, GLboolean invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1328 | |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1329 | // Wrapper for glCompileShader. |
| 1330 | void DoCompileShader(GLuint shader); |
| 1331 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1332 | // Wrapper for glDetachShader |
| 1333 | void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
| 1334 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1335 | // Wrapper for glDisable |
| 1336 | void DoDisable(GLenum cap); |
| 1337 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1338 | // Wrapper for glDisableVertexAttribArray. |
| 1339 | void DoDisableVertexAttribArray(GLuint index); |
| 1340 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1341 | // Wrapper for glDiscardFramebufferEXT, since we need to track undefined |
| 1342 | // attachments. |
| 1343 | void DoDiscardFramebufferEXT(GLenum target, |
| 1344 | GLsizei numAttachments, |
| 1345 | const GLenum* attachments); |
| 1346 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1347 | // Wrapper for glEnable |
| 1348 | void DoEnable(GLenum cap); |
| 1349 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1350 | // Wrapper for glEnableVertexAttribArray. |
| 1351 | void DoEnableVertexAttribArray(GLuint index); |
| 1352 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1353 | // Wrapper for glFinish. |
| 1354 | void DoFinish(); |
| 1355 | |
| 1356 | // Wrapper for glFlush. |
| 1357 | void DoFlush(); |
| 1358 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1359 | // Wrapper for glFramebufferRenderbufffer. |
| 1360 | void DoFramebufferRenderbuffer( |
| 1361 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
| 1362 | GLuint renderbuffer); |
| 1363 | |
| 1364 | // Wrapper for glFramebufferTexture2D. |
| 1365 | void DoFramebufferTexture2D( |
| 1366 | GLenum target, GLenum attachment, GLenum textarget, GLuint texture, |
| 1367 | GLint level); |
| 1368 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1369 | // Wrapper for glFramebufferTexture2DMultisampleEXT. |
| 1370 | void DoFramebufferTexture2DMultisample( |
| 1371 | GLenum target, GLenum attachment, GLenum textarget, |
| 1372 | GLuint texture, GLint level, GLsizei samples); |
| 1373 | |
| 1374 | // Common implementation for both DoFramebufferTexture2D wrappers. |
| 1375 | void DoFramebufferTexture2DCommon(const char* name, |
| 1376 | GLenum target, GLenum attachment, GLenum textarget, |
| 1377 | GLuint texture, GLint level, GLsizei samples); |
| 1378 | |
zmo | 84c0820 | 2014-11-23 15:28:40 | [diff] [blame] | 1379 | // Wrapper for glFramebufferTextureLayer. |
| 1380 | void DoFramebufferTextureLayer( |
| 1381 | GLenum target, GLenum attachment, GLuint texture, GLint level, |
| 1382 | GLint layer); |
| 1383 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1384 | // Wrapper for glGenerateMipmap |
| 1385 | void DoGenerateMipmap(GLenum target); |
| 1386 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1387 | // Helper for DoGetBooleanv, Floatv, and Intergerv to adjust pname |
| 1388 | // to account for different pname values defined in different extension |
| 1389 | // variants. |
| 1390 | GLenum AdjustGetPname(GLenum pname); |
| 1391 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1392 | // Wrapper for DoGetBooleanv. |
| 1393 | void DoGetBooleanv(GLenum pname, GLboolean* params); |
| 1394 | |
| 1395 | // Wrapper for DoGetFloatv. |
| 1396 | void DoGetFloatv(GLenum pname, GLfloat* params); |
| 1397 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1398 | // Wrapper for glGetFramebufferAttachmentParameteriv. |
| 1399 | void DoGetFramebufferAttachmentParameteriv( |
| 1400 | GLenum target, GLenum attachment, GLenum pname, GLint* params); |
| 1401 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1402 | // Wrapper for glGetIntegerv. |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1403 | void DoGetIntegerv(GLenum pname, GLint* params); |
| 1404 | |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1405 | // Gets the max value in a range in a buffer. |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1406 | GLuint DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1407 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); |
| 1408 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 1409 | // Wrapper for glGetBufferParameteriv. |
| 1410 | void DoGetBufferParameteriv( |
| 1411 | GLenum target, GLenum pname, GLint* params); |
| 1412 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1413 | // Wrapper for glGetProgramiv. |
| 1414 | void DoGetProgramiv( |
| 1415 | GLuint program_id, GLenum pname, GLint* params); |
| 1416 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1417 | // Wrapper for glRenderbufferParameteriv. |
| 1418 | void DoGetRenderbufferParameteriv( |
| 1419 | GLenum target, GLenum pname, GLint* params); |
| 1420 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 1421 | // Wrapper for glGetShaderiv |
| 1422 | void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); |
| 1423 | |
[email protected] | 4c6f546 | 2014-03-05 00:26:56 | [diff] [blame] | 1424 | // Wrappers for glGetTexParameter. |
| 1425 | void DoGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params); |
| 1426 | void DoGetTexParameteriv(GLenum target, GLenum pname, GLint* params); |
| 1427 | void InitTextureMaxAnisotropyIfNeeded(GLenum target, GLenum pname); |
| 1428 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1429 | // Wrappers for glGetVertexAttrib. |
| 1430 | void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat *params); |
| 1431 | void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint *params); |
| 1432 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1433 | // Wrappers for glIsXXX functions. |
[email protected] | 3dc69c4 | 2012-05-12 02:29:24 | [diff] [blame] | 1434 | bool DoIsEnabled(GLenum cap); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1435 | bool DoIsBuffer(GLuint client_id); |
| 1436 | bool DoIsFramebuffer(GLuint client_id); |
| 1437 | bool DoIsProgram(GLuint client_id); |
| 1438 | bool DoIsRenderbuffer(GLuint client_id); |
| 1439 | bool DoIsShader(GLuint client_id); |
| 1440 | bool DoIsTexture(GLuint client_id); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1441 | bool DoIsVertexArrayOES(GLuint client_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1442 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1443 | // Wrapper for glLinkProgram |
| 1444 | void DoLinkProgram(GLuint program); |
| 1445 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1446 | // Wrapper for glRenderbufferStorage. |
| 1447 | void DoRenderbufferStorage( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1448 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1449 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1450 | // Handler for glRenderbufferStorageMultisampleCHROMIUM. |
| 1451 | void DoRenderbufferStorageMultisampleCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1452 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1453 | GLsizei width, GLsizei height); |
| 1454 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1455 | // Handler for glRenderbufferStorageMultisampleEXT |
| 1456 | // (multisampled_render_to_texture). |
| 1457 | void DoRenderbufferStorageMultisampleEXT( |
| 1458 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1459 | GLsizei width, GLsizei height); |
| 1460 | |
| 1461 | // Common validation for multisample extensions. |
| 1462 | bool ValidateRenderbufferStorageMultisample(GLsizei samples, |
| 1463 | GLenum internalformat, |
| 1464 | GLsizei width, |
| 1465 | GLsizei height); |
| 1466 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 1467 | // Verifies that the currently bound multisample renderbuffer is valid |
| 1468 | // Very slow! Only done on platforms with driver bugs that return invalid |
| 1469 | // buffers under memory pressure |
| 1470 | bool VerifyMultisampleRenderbufferIntegrity( |
| 1471 | GLuint renderbuffer, GLenum format); |
| 1472 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1473 | // Wrapper for glReleaseShaderCompiler. |
| 1474 | void DoReleaseShaderCompiler() { } |
| 1475 | |
zmo | bcb3fdd6 | 2014-12-11 00:49:03 | [diff] [blame] | 1476 | // Wrappers for glSamplerParameter*v functions. |
| 1477 | void DoSamplerParameterfv( |
| 1478 | GLuint sampler, GLenum pname, const GLfloat* params); |
| 1479 | void DoSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* params); |
| 1480 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1481 | // Wrappers for glTexParameter functions. |
| 1482 | void DoTexParameterf(GLenum target, GLenum pname, GLfloat param); |
| 1483 | void DoTexParameteri(GLenum target, GLenum pname, GLint param); |
| 1484 | void DoTexParameterfv(GLenum target, GLenum pname, const GLfloat* params); |
| 1485 | void DoTexParameteriv(GLenum target, GLenum pname, const GLint* params); |
| 1486 | |
| 1487 | // Wrappers for glUniform1i and glUniform1iv as according to the GLES2 |
| 1488 | // spec only these 2 functions can be used to set sampler uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1489 | void DoUniform1i(GLint fake_location, GLint v0); |
| 1490 | void DoUniform1iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1491 | void DoUniform2iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1492 | void DoUniform3iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1493 | void DoUniform4iv(GLint fake_location, GLsizei count, const GLint* value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1494 | |
| 1495 | // Wrappers for glUniformfv because some drivers don't correctly accept |
| 1496 | // bool uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1497 | void DoUniform1fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1498 | void DoUniform2fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1499 | void DoUniform3fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1500 | void DoUniform4fv(GLint fake_location, GLsizei count, const GLfloat* value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1501 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1502 | void DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1503 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1504 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1505 | void DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1506 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1507 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1508 | void DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1509 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1510 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1511 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1512 | bool SetVertexAttribValue( |
| 1513 | const char* function_name, GLuint index, const GLfloat* value); |
| 1514 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1515 | // Wrappers for glVertexAttrib?? |
| 1516 | void DoVertexAttrib1f(GLuint index, GLfloat v0); |
| 1517 | void DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1); |
| 1518 | void DoVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2); |
| 1519 | void DoVertexAttrib4f( |
| 1520 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); |
| 1521 | void DoVertexAttrib1fv(GLuint index, const GLfloat *v); |
| 1522 | void DoVertexAttrib2fv(GLuint index, const GLfloat *v); |
| 1523 | void DoVertexAttrib3fv(GLuint index, const GLfloat *v); |
| 1524 | void DoVertexAttrib4fv(GLuint index, const GLfloat *v); |
| 1525 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1526 | // Wrapper for glViewport |
| 1527 | void DoViewport(GLint x, GLint y, GLsizei width, GLsizei height); |
| 1528 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1529 | // Wrapper for glUseProgram |
| 1530 | void DoUseProgram(GLuint program); |
| 1531 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1532 | // Wrapper for glValidateProgram. |
| 1533 | void DoValidateProgram(GLuint program_client_id); |
| 1534 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 1535 | void DoInsertEventMarkerEXT(GLsizei length, const GLchar* marker); |
| 1536 | void DoPushGroupMarkerEXT(GLsizei length, const GLchar* group); |
| 1537 | void DoPopGroupMarkerEXT(void); |
| 1538 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 1539 | // Gets the number of values that will be returned by glGetXXX. Returns |
| 1540 | // false if pname is unknown. |
| 1541 | bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values); |
| 1542 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1543 | // Checks if the current program and vertex attributes are valid for drawing. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1544 | bool IsDrawValid( |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 1545 | const char* function_name, GLuint max_vertex_accessed, bool instanced, |
| 1546 | GLsizei primcount); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1547 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 1548 | // Returns true if successful, simulated will be true if attrib0 was |
| 1549 | // simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1550 | bool SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1551 | const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 1552 | void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1553 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1554 | // If an image is bound to texture, this will call Will/DidUseTexImage |
| 1555 | // if needed. |
| 1556 | void DoWillUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1557 | void DoDidUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1558 | |
| 1559 | // Returns false if textures were replaced. |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 1560 | bool PrepareTexturesForRender(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1561 | void RestoreStateForTextures(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1562 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1563 | // Returns true if GL_FIXED attribs were simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1564 | bool SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1565 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1566 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1567 | void RestoreStateForSimulatedFixedAttribs(); |
| 1568 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1569 | // Handle DrawArrays and DrawElements for both instanced and non-instanced |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 1570 | // cases (primcount is always 1 for non-instanced). |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1571 | error::Error DoDrawArrays( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1572 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1573 | bool instanced, GLenum mode, GLint first, GLsizei count, |
| 1574 | GLsizei primcount); |
| 1575 | error::Error DoDrawElements( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1576 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1577 | bool instanced, GLenum mode, GLsizei count, GLenum type, |
| 1578 | int32 offset, GLsizei primcount); |
| 1579 | |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1580 | GLenum GetBindTargetForSamplerType(GLenum type) { |
| 1581 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1582 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 1583 | switch (type) { |
| 1584 | case GL_SAMPLER_2D: |
| 1585 | return GL_TEXTURE_2D; |
| 1586 | case GL_SAMPLER_CUBE: |
| 1587 | return GL_TEXTURE_CUBE_MAP; |
| 1588 | case GL_SAMPLER_EXTERNAL_OES: |
| 1589 | return GL_TEXTURE_EXTERNAL_OES; |
| 1590 | case GL_SAMPLER_2D_RECT_ARB: |
| 1591 | return GL_TEXTURE_RECTANGLE_ARB; |
| 1592 | } |
| 1593 | |
| 1594 | NOTREACHED(); |
| 1595 | return 0; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1596 | } |
| 1597 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1598 | // Gets the framebuffer info for a particular target. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1599 | Framebuffer* GetFramebufferInfoForTarget(GLenum target) { |
| 1600 | Framebuffer* framebuffer = NULL; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1601 | switch (target) { |
| 1602 | case GL_FRAMEBUFFER: |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1603 | case GL_DRAW_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1604 | framebuffer = framebuffer_state_.bound_draw_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1605 | break; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1606 | case GL_READ_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1607 | framebuffer = framebuffer_state_.bound_read_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1608 | break; |
| 1609 | default: |
| 1610 | NOTREACHED(); |
| 1611 | break; |
| 1612 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1613 | return framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1614 | } |
| 1615 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1616 | Renderbuffer* GetRenderbufferInfoForTarget( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1617 | GLenum target) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1618 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1619 | switch (target) { |
| 1620 | case GL_RENDERBUFFER: |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 1621 | renderbuffer = state_.bound_renderbuffer.get(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1622 | break; |
| 1623 | default: |
| 1624 | NOTREACHED(); |
| 1625 | break; |
| 1626 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1627 | return renderbuffer; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1628 | } |
| 1629 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1630 | // Validates the program and location for a glGetUniform call and returns |
| 1631 | // a SizeResult setup to receive the result. Returns true if glGetUniform |
| 1632 | // should be called. |
| 1633 | bool GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1634 | GLuint program, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1635 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1636 | error::Error* error, GLint* real_location, GLuint* service_id, |
| 1637 | void** result, GLenum* result_type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1638 | |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 1639 | void MaybeExitOnContextLost(); |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 1640 | bool WasContextLost() override; |
| 1641 | bool WasContextLostByRobustnessExtension() override; |
| 1642 | void LoseContext(uint32 reset_status) override; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1643 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1644 | #if defined(OS_MACOSX) |
| 1645 | void ReleaseIOSurfaceForTexture(GLuint texture_id); |
| 1646 | #endif |
| 1647 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1648 | bool ValidateCompressedTexDimensions( |
| 1649 | const char* function_name, |
| 1650 | GLint level, GLsizei width, GLsizei height, GLenum format); |
| 1651 | bool ValidateCompressedTexFuncData( |
| 1652 | const char* function_name, |
| 1653 | GLsizei width, GLsizei height, GLenum format, size_t size); |
| 1654 | bool ValidateCompressedTexSubDimensions( |
| 1655 | const char* function_name, |
| 1656 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 1657 | GLsizei width, GLsizei height, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1658 | Texture* texture); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1659 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1660 | void RenderWarning(const char* filename, int line, const std::string& msg); |
| 1661 | void PerformanceWarning( |
| 1662 | const char* filename, int line, const std::string& msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 1663 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 1664 | const FeatureInfo::FeatureFlags& features() const { |
| 1665 | return feature_info_->feature_flags(); |
| 1666 | } |
| 1667 | |
| 1668 | const FeatureInfo::Workarounds& workarounds() const { |
| 1669 | return feature_info_->workarounds(); |
| 1670 | } |
| 1671 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1672 | bool ShouldDeferDraws() { |
| 1673 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1674 | framebuffer_state_.bound_draw_framebuffer.get() == NULL && |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1675 | surface_->DeferDraws(); |
| 1676 | } |
| 1677 | |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1678 | bool ShouldDeferReads() { |
| 1679 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1680 | framebuffer_state_.bound_read_framebuffer.get() == NULL && |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1681 | surface_->DeferDraws(); |
| 1682 | } |
| 1683 | |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 1684 | error::Error WillAccessBoundFramebufferForDraw() { |
| 1685 | if (ShouldDeferDraws()) |
| 1686 | return error::kDeferCommandUntilLater; |
| 1687 | if (!offscreen_target_frame_buffer_.get() && |
| 1688 | !framebuffer_state_.bound_draw_framebuffer.get() && |
| 1689 | !surface_->SetBackbufferAllocation(true)) |
| 1690 | return error::kLostContext; |
| 1691 | return error::kNoError; |
| 1692 | } |
| 1693 | |
| 1694 | error::Error WillAccessBoundFramebufferForRead() { |
| 1695 | if (ShouldDeferReads()) |
| 1696 | return error::kDeferCommandUntilLater; |
| 1697 | if (!offscreen_target_frame_buffer_.get() && |
| 1698 | !framebuffer_state_.bound_read_framebuffer.get() && |
| 1699 | !surface_->SetBackbufferAllocation(true)) |
| 1700 | return error::kLostContext; |
| 1701 | return error::kNoError; |
| 1702 | } |
| 1703 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 1704 | // Set remaining commands to process to 0 to force DoCommands to return |
| 1705 | // and allow context preemption and GPU watchdog checks in GpuScheduler(). |
| 1706 | void ExitCommandProcessingEarly() { commands_to_process_ = 0; } |
| 1707 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 1708 | void ProcessPendingReadPixels(); |
| 1709 | void FinishReadPixels(const cmds::ReadPixels& c, GLuint buffer); |
| 1710 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1711 | // Generate a member function prototype for each command in an automated and |
| 1712 | // typesafe way. |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 1713 | #define GLES2_CMD_OP(name) \ |
| 1714 | Error Handle##name(uint32 immediate_data_size, const void* data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1715 | |
| 1716 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 1717 | |
| 1718 | #undef GLES2_CMD_OP |
| 1719 | |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 1720 | // The GL context this decoder renders to on behalf of the client. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1721 | scoped_refptr<gfx::GLSurface> surface_; |
| 1722 | scoped_refptr<gfx::GLContext> context_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1723 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1724 | // The ContextGroup for this decoder uses to track resources. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1725 | scoped_refptr<ContextGroup> group_; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1726 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 1727 | DebugMarkerManager debug_marker_manager_; |
| 1728 | Logger logger_; |
| 1729 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1730 | // All the state for this context. |
| 1731 | ContextState state_; |
| 1732 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1733 | // Current width and height of the offscreen frame buffer. |
| 1734 | gfx::Size offscreen_size_; |
| 1735 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1736 | // Util to help with GL. |
| 1737 | GLES2Util util_; |
| 1738 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1739 | // unpack flip y as last set by glPixelStorei |
| 1740 | bool unpack_flip_y_; |
| 1741 | |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1742 | // unpack (un)premultiply alpha as last set by glPixelStorei |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1743 | bool unpack_premultiply_alpha_; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 1744 | bool unpack_unpremultiply_alpha_; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1745 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1746 | // The buffer we bind to attrib 0 since OpenGL requires it (ES does not). |
| 1747 | GLuint attrib_0_buffer_id_; |
| 1748 | |
| 1749 | // The value currently in attrib_0. |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1750 | Vec4 attrib_0_value_; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1751 | |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 1752 | // Whether or not the attrib_0 buffer holds the attrib_0_value. |
| 1753 | bool attrib_0_buffer_matches_value_; |
| 1754 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1755 | // The size of attrib 0. |
| 1756 | GLsizei attrib_0_size_; |
| 1757 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1758 | // The buffer used to simulate GL_FIXED attribs. |
| 1759 | GLuint fixed_attrib_buffer_id_; |
| 1760 | |
| 1761 | // The size of fiixed attrib buffer. |
| 1762 | GLsizei fixed_attrib_buffer_size_; |
| 1763 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1764 | // The offscreen frame buffer that the client renders to. With EGL, the |
| 1765 | // depth and stencil buffers are separate. With regular GL there is a single |
| 1766 | // packed depth stencil buffer in offscreen_target_depth_render_buffer_. |
| 1767 | // offscreen_target_stencil_render_buffer_ is unused. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1768 | scoped_ptr<BackFramebuffer> offscreen_target_frame_buffer_; |
| 1769 | scoped_ptr<BackTexture> offscreen_target_color_texture_; |
| 1770 | scoped_ptr<BackRenderbuffer> offscreen_target_color_render_buffer_; |
| 1771 | scoped_ptr<BackRenderbuffer> offscreen_target_depth_render_buffer_; |
| 1772 | scoped_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1773 | GLenum offscreen_target_color_format_; |
| 1774 | GLenum offscreen_target_depth_format_; |
| 1775 | GLenum offscreen_target_stencil_format_; |
| 1776 | GLsizei offscreen_target_samples_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1777 | GLboolean offscreen_target_buffer_preserved_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1778 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1779 | // The copy that is saved when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1780 | scoped_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; |
| 1781 | scoped_ptr<BackTexture> offscreen_saved_color_texture_; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 1782 | scoped_refptr<TextureRef> |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1783 | offscreen_saved_color_texture_info_; |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1784 | |
| 1785 | // The copy that is used as the destination for multi-sample resolves. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1786 | scoped_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; |
| 1787 | scoped_ptr<BackTexture> offscreen_resolved_color_texture_; |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1788 | GLenum offscreen_saved_color_format_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1789 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1790 | scoped_ptr<QueryManager> query_manager_; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1791 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1792 | scoped_ptr<VertexArrayManager> vertex_array_manager_; |
| 1793 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 1794 | scoped_ptr<ImageManager> image_manager_; |
| 1795 | |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 1796 | base::Callback<void(gfx::Size, float)> resize_callback_; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 1797 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 1798 | WaitSyncPointCallback wait_sync_point_callback_; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 1799 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 1800 | ShaderCacheCallback shader_cache_callback_; |
| 1801 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 1802 | scoped_ptr<AsyncPixelTransferManager> async_pixel_transfer_manager_; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 1803 | |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1804 | // The format of the back buffer_ |
| 1805 | GLenum back_buffer_color_format_; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1806 | bool back_buffer_has_depth_; |
| 1807 | bool back_buffer_has_stencil_; |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1808 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 1809 | bool surfaceless_; |
| 1810 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1811 | // Backbuffer attachments that are currently undefined. |
| 1812 | uint32 backbuffer_needs_clear_bits_; |
| 1813 | |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 1814 | // The current decoder error communicates the decoder error through command |
| 1815 | // processing functions that do not return the error value. Should be set only |
| 1816 | // if not returning an error. |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 1817 | error::Error current_decoder_error_; |
| 1818 | |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1819 | bool use_shader_translator_; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 1820 | scoped_refptr<ShaderTranslator> vertex_translator_; |
| 1821 | scoped_refptr<ShaderTranslator> fragment_translator_; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1822 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1823 | DisallowedFeatures disallowed_features_; |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1824 | |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 1825 | // Cached from ContextGroup |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1826 | const Validators* validators_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1827 | scoped_refptr<FeatureInfo> feature_info_; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1828 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1829 | int frame_number_; |
| 1830 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 1831 | // Number of commands remaining to be processed in DoCommands(). |
| 1832 | int commands_to_process_; |
| 1833 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 1834 | bool has_robustness_extension_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1835 | GLenum reset_status_; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 1836 | bool reset_by_robustness_extension_; |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 1837 | bool supports_post_sub_buffer_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1838 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1839 | // These flags are used to override the state of the shared feature_info_ |
| 1840 | // member. Because the same FeatureInfo instance may be shared among many |
| 1841 | // contexts, the assumptions on the availablity of extensions in WebGL |
| 1842 | // contexts may be broken. These flags override the shared state to preserve |
| 1843 | // WebGL semantics. |
| 1844 | bool force_webgl_glsl_validation_; |
| 1845 | bool derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 1846 | bool frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 1847 | bool draw_buffers_explicitly_enabled_; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 1848 | bool shader_texture_lod_explicitly_enabled_; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1849 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 1850 | bool compile_shader_always_succeeds_; |
| 1851 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 1852 | // An optional behaviour to lose the context and group when OOM. |
| 1853 | bool lose_context_when_out_of_memory_; |
| 1854 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1855 | // Log extra info. |
| 1856 | bool service_logging_; |
| 1857 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1858 | #if defined(OS_MACOSX) |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 1859 | typedef std::map<GLuint, IOSurfaceRef> TextureToIOSurfaceMap; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1860 | TextureToIOSurfaceMap texture_to_io_surface_map_; |
| 1861 | #endif |
| 1862 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1863 | scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 1864 | scoped_ptr<ClearFramebufferResourceManager> clear_framebuffer_blit_; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1865 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1866 | // Cached values of the currently assigned viewport dimensions. |
| 1867 | GLsizei viewport_max_width_; |
| 1868 | GLsizei viewport_max_height_; |
| 1869 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1870 | // Command buffer stats. |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 1871 | base::TimeDelta total_processing_commands_time_; |
| 1872 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 1873 | // States related to each manager. |
| 1874 | DecoderTextureState texture_state_; |
| 1875 | DecoderFramebufferState framebuffer_state_; |
| 1876 | |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 1877 | scoped_ptr<GPUTracer> gpu_tracer_; |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 1878 | scoped_ptr<GPUStateTracer> gpu_state_tracer_; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 1879 | const unsigned char* cb_command_trace_category_; |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 1880 | const unsigned char* gpu_decoder_category_; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 1881 | int gpu_trace_level_; |
| 1882 | bool gpu_trace_commands_; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 1883 | bool gpu_debug_commands_; |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 1884 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 1885 | std::queue<linked_ptr<FenceCallback> > pending_readpixel_fences_; |
| 1886 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 1887 | // Used to validate multisample renderbuffers if needed |
| 1888 | GLuint validation_texture_; |
| 1889 | GLuint validation_fbo_multisample_; |
| 1890 | GLuint validation_fbo_; |
| 1891 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 1892 | typedef gpu::gles2::GLES2Decoder::Error (GLES2DecoderImpl::*CmdHandler)( |
| 1893 | uint32 immediate_data_size, |
| 1894 | const void* data); |
| 1895 | |
| 1896 | // A struct to hold info about each command. |
| 1897 | struct CommandInfo { |
| 1898 | CmdHandler cmd_handler; |
| 1899 | uint8 arg_flags; // How to handle the arguments for this command |
| 1900 | uint8 cmd_flags; // How to handle this command |
| 1901 | uint16 arg_count; // How many arguments are expected for this command. |
| 1902 | }; |
| 1903 | |
| 1904 | // A table of CommandInfo for all the commands. |
| 1905 | static const CommandInfo command_info[kNumCommands - kStartPoint]; |
| 1906 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1907 | DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
| 1908 | }; |
| 1909 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 1910 | const GLES2DecoderImpl::CommandInfo GLES2DecoderImpl::command_info[] = { |
| 1911 | #define GLES2_CMD_OP(name) \ |
| 1912 | { \ |
| 1913 | &GLES2DecoderImpl::Handle##name, cmds::name::kArgFlags, \ |
| 1914 | cmds::name::cmd_flags, \ |
| 1915 | sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ |
| 1916 | } \ |
| 1917 | , /* NOLINT */ |
| 1918 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 1919 | #undef GLES2_CMD_OP |
| 1920 | }; |
| 1921 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1922 | ScopedGLErrorSuppressor::ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1923 | const char* function_name, ErrorState* error_state) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1924 | : function_name_(function_name), |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1925 | error_state_(error_state) { |
| 1926 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1927 | } |
| 1928 | |
| 1929 | ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 1930 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1931 | } |
| 1932 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1933 | static void RestoreCurrentTextureBindings(ContextState* state, GLenum target) { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1934 | TextureUnit& info = state->texture_units[0]; |
| 1935 | GLuint last_id; |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1936 | scoped_refptr<TextureRef> texture_ref; |
| 1937 | switch (target) { |
| 1938 | case GL_TEXTURE_2D: |
| 1939 | texture_ref = info.bound_texture_2d; |
| 1940 | break; |
| 1941 | case GL_TEXTURE_CUBE_MAP: |
| 1942 | texture_ref = info.bound_texture_cube_map; |
| 1943 | break; |
| 1944 | case GL_TEXTURE_EXTERNAL_OES: |
| 1945 | texture_ref = info.bound_texture_external_oes; |
| 1946 | break; |
| 1947 | case GL_TEXTURE_RECTANGLE_ARB: |
| 1948 | texture_ref = info.bound_texture_rectangle_arb; |
| 1949 | break; |
| 1950 | default: |
| 1951 | NOTREACHED(); |
| 1952 | break; |
| 1953 | } |
| 1954 | if (texture_ref.get()) { |
| 1955 | last_id = texture_ref->service_id(); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1956 | } else { |
| 1957 | last_id = 0; |
| 1958 | } |
| 1959 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1960 | glBindTexture(target, last_id); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 1961 | glActiveTexture(GL_TEXTURE0 + state->active_texture_unit); |
| 1962 | } |
| 1963 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1964 | ScopedTextureBinder::ScopedTextureBinder(ContextState* state, |
| 1965 | GLuint id, |
| 1966 | GLenum target) |
| 1967 | : state_(state), |
| 1968 | target_(target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1969 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1970 | "ScopedTextureBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1971 | |
| 1972 | // TODO(apatrick): Check if there are any other states that need to be reset |
| 1973 | // before binding a new texture. |
| 1974 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1975 | glBindTexture(target, id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1976 | } |
| 1977 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1978 | ScopedTextureBinder::~ScopedTextureBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1979 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 1980 | "ScopedTextureBinder::dtor", state_->GetErrorState()); |
| 1981 | RestoreCurrentTextureBindings(state_, target_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1982 | } |
| 1983 | |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1984 | ScopedRenderBufferBinder::ScopedRenderBufferBinder(ContextState* state, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1985 | GLuint id) |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1986 | : state_(state) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1987 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1988 | "ScopedRenderBufferBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1989 | glBindRenderbufferEXT(GL_RENDERBUFFER, id); |
| 1990 | } |
| 1991 | |
| 1992 | ScopedRenderBufferBinder::~ScopedRenderBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1993 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 1994 | "ScopedRenderBufferBinder::dtor", state_->GetErrorState()); |
| 1995 | state_->RestoreRenderbufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | ScopedFrameBufferBinder::ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 1999 | GLuint id) |
| 2000 | : decoder_(decoder) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2001 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2002 | "ScopedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2003 | glBindFramebufferEXT(GL_FRAMEBUFFER, id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 2004 | decoder->OnFboChanged(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | ScopedFrameBufferBinder::~ScopedFrameBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2008 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2009 | "ScopedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2010 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2011 | } |
| 2012 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2013 | ScopedResolvedFrameBufferBinder::ScopedResolvedFrameBufferBinder( |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2014 | GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 2015 | : decoder_(decoder) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2016 | resolve_and_bind_ = ( |
| 2017 | decoder_->offscreen_target_frame_buffer_.get() && |
| 2018 | decoder_->IsOffscreenBufferMultisampled() && |
| 2019 | (!decoder_->framebuffer_state_.bound_read_framebuffer.get() || |
| 2020 | enforce_internal_framebuffer)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2021 | if (!resolve_and_bind_) |
| 2022 | return; |
| 2023 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2024 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2025 | "ScopedResolvedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2026 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, |
| 2027 | decoder_->offscreen_target_frame_buffer_->id()); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2028 | GLuint targetid; |
| 2029 | if (internal) { |
| 2030 | if (!decoder_->offscreen_resolved_frame_buffer_.get()) { |
| 2031 | decoder_->offscreen_resolved_frame_buffer_.reset( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2032 | new BackFramebuffer(decoder_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2033 | decoder_->offscreen_resolved_frame_buffer_->Create(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2034 | decoder_->offscreen_resolved_color_texture_.reset( |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2035 | new BackTexture(decoder->memory_tracker(), &decoder->state_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2036 | decoder_->offscreen_resolved_color_texture_->Create(); |
| 2037 | |
| 2038 | DCHECK(decoder_->offscreen_saved_color_format_); |
| 2039 | decoder_->offscreen_resolved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2040 | decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_, |
| 2041 | false); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2042 | decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( |
| 2043 | decoder_->offscreen_resolved_color_texture_.get()); |
| 2044 | if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != |
| 2045 | GL_FRAMEBUFFER_COMPLETE) { |
| 2046 | LOG(ERROR) << "ScopedResolvedFrameBufferBinder failed " |
| 2047 | << "because offscreen resolved FBO was incomplete."; |
| 2048 | return; |
| 2049 | } |
| 2050 | } |
| 2051 | targetid = decoder_->offscreen_resolved_frame_buffer_->id(); |
| 2052 | } else { |
| 2053 | targetid = decoder_->offscreen_saved_frame_buffer_->id(); |
| 2054 | } |
| 2055 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2056 | const int width = decoder_->offscreen_size_.width(); |
| 2057 | const int height = decoder_->offscreen_size_.height(); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 2058 | decoder->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2059 | decoder->BlitFramebufferHelper(0, |
| 2060 | 0, |
| 2061 | width, |
| 2062 | height, |
| 2063 | 0, |
| 2064 | 0, |
| 2065 | width, |
| 2066 | height, |
| 2067 | GL_COLOR_BUFFER_BIT, |
| 2068 | GL_NEAREST); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2069 | glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { |
| 2073 | if (!resolve_and_bind_) |
| 2074 | return; |
| 2075 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2076 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2077 | "ScopedResolvedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2078 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 2079 | if (decoder_->state_.enable_flags.scissor_test) { |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 2080 | decoder_->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 2081 | } |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2082 | } |
| 2083 | |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2084 | BackTexture::BackTexture( |
| 2085 | MemoryTracker* memory_tracker, |
| 2086 | ContextState* state) |
| 2087 | : memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 2088 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2089 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 2090 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2091 | } |
| 2092 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2093 | BackTexture::~BackTexture() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2094 | // This does not destroy the render texture because that would require that |
| 2095 | // the associated GL context was current. Just check that it was explicitly |
| 2096 | // destroyed. |
| 2097 | DCHECK_EQ(id_, 0u); |
| 2098 | } |
| 2099 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2100 | void BackTexture::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2101 | ScopedGLErrorSuppressor suppressor("BackTexture::Create", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2102 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2103 | Destroy(); |
| 2104 | glGenTextures(1, &id_); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2105 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | eeeb07b9 | 2014-08-16 07:46:26 | [diff] [blame] | 2106 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 2107 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 2108 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 2109 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
[email protected] | 6278880 | 2011-10-03 17:57:16 | [diff] [blame] | 2110 | |
| 2111 | // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 2112 | // never called on an offscreen context, no data will ever be uploaded to the |
| 2113 | // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 2114 | // is called). My idea is that some nvidia drivers might have a bug where |
| 2115 | // deleting a texture that has never been populated might cause a |
| 2116 | // crash. |
| 2117 | glTexImage2D( |
| 2118 | 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] | 2119 | |
| 2120 | bytes_allocated_ = 16u * 16u * 4u; |
| 2121 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2122 | } |
| 2123 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2124 | bool BackTexture::AllocateStorage( |
| 2125 | const gfx::Size& size, GLenum format, bool zero) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2126 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2127 | ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2128 | state_->GetErrorState()); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2129 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2130 | uint32 image_size = 0; |
| 2131 | GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 2132 | size.width(), size.height(), 1, format, GL_UNSIGNED_BYTE, 8, &image_size, |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2133 | NULL, NULL); |
| 2134 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2135 | if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { |
| 2136 | return false; |
| 2137 | } |
| 2138 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2139 | scoped_ptr<char[]> zero_data; |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2140 | if (zero) { |
| 2141 | zero_data.reset(new char[image_size]); |
| 2142 | memset(zero_data.get(), 0, image_size); |
| 2143 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2144 | |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 2145 | glTexImage2D(GL_TEXTURE_2D, |
| 2146 | 0, // mip level |
| 2147 | format, |
| 2148 | size.width(), |
| 2149 | size.height(), |
| 2150 | 0, // border |
| 2151 | format, |
| 2152 | GL_UNSIGNED_BYTE, |
| 2153 | zero_data.get()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2154 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2155 | size_ = size; |
| 2156 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2157 | bool success = glGetError() == GL_NO_ERROR; |
| 2158 | if (success) { |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2159 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2160 | bytes_allocated_ = image_size; |
| 2161 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2162 | } |
| 2163 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2164 | } |
| 2165 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2166 | void BackTexture::Copy(const gfx::Size& size, GLenum format) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2167 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2168 | ScopedGLErrorSuppressor suppressor("BackTexture::Copy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2169 | state_->GetErrorState()); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2170 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2171 | glCopyTexImage2D(GL_TEXTURE_2D, |
| 2172 | 0, // level |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 2173 | format, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2174 | 0, 0, |
| 2175 | size.width(), |
| 2176 | size.height(), |
| 2177 | 0); // border |
| 2178 | } |
| 2179 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2180 | void BackTexture::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2181 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2182 | ScopedGLErrorSuppressor suppressor("BackTexture::Destroy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2183 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2184 | glDeleteTextures(1, &id_); |
| 2185 | id_ = 0; |
| 2186 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2187 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2188 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2189 | } |
| 2190 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2191 | void BackTexture::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2192 | id_ = 0; |
| 2193 | } |
| 2194 | |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2195 | BackRenderbuffer::BackRenderbuffer( |
| 2196 | RenderbufferManager* renderbuffer_manager, |
| 2197 | MemoryTracker* memory_tracker, |
| 2198 | ContextState* state) |
| 2199 | : renderbuffer_manager_(renderbuffer_manager), |
| 2200 | memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 2201 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2202 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 2203 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2204 | } |
| 2205 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2206 | BackRenderbuffer::~BackRenderbuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2207 | // This does not destroy the render buffer because that would require that |
| 2208 | // the associated GL context was current. Just check that it was explicitly |
| 2209 | // destroyed. |
| 2210 | DCHECK_EQ(id_, 0u); |
| 2211 | } |
| 2212 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2213 | void BackRenderbuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2214 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Create", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2215 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2216 | Destroy(); |
| 2217 | glGenRenderbuffersEXT(1, &id_); |
| 2218 | } |
| 2219 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2220 | bool BackRenderbuffer::AllocateStorage(const FeatureInfo* feature_info, |
| 2221 | const gfx::Size& size, |
| 2222 | GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2223 | GLsizei samples) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2224 | ScopedGLErrorSuppressor suppressor( |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2225 | "BackRenderbuffer::AllocateStorage", state_->GetErrorState()); |
| 2226 | ScopedRenderBufferBinder binder(state_, id_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2227 | |
| 2228 | uint32 estimated_size = 0; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2229 | if (!renderbuffer_manager_->ComputeEstimatedRenderbufferSize( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 2230 | size.width(), size.height(), samples, format, &estimated_size)) { |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2231 | return false; |
| 2232 | } |
| 2233 | |
| 2234 | if (!memory_tracker_.EnsureGPUMemoryAvailable(estimated_size)) { |
| 2235 | return false; |
| 2236 | } |
| 2237 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2238 | if (samples <= 1) { |
| 2239 | glRenderbufferStorageEXT(GL_RENDERBUFFER, |
| 2240 | format, |
| 2241 | size.width(), |
| 2242 | size.height()); |
| 2243 | } else { |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2244 | GLES2DecoderImpl::RenderbufferStorageMultisampleHelper(feature_info, |
| 2245 | GL_RENDERBUFFER, |
| 2246 | samples, |
| 2247 | format, |
| 2248 | size.width(), |
| 2249 | size.height()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2250 | } |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2251 | bool success = glGetError() == GL_NO_ERROR; |
| 2252 | if (success) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2253 | // Mark the previously allocated bytes as free. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2254 | memory_tracker_.TrackMemFree(bytes_allocated_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2255 | bytes_allocated_ = estimated_size; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2256 | // Track the newly allocated bytes. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2257 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2258 | } |
| 2259 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2260 | } |
| 2261 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2262 | void BackRenderbuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2263 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2264 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Destroy", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2265 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2266 | glDeleteRenderbuffersEXT(1, &id_); |
| 2267 | id_ = 0; |
| 2268 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2269 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2270 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2271 | } |
| 2272 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2273 | void BackRenderbuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2274 | id_ = 0; |
| 2275 | } |
| 2276 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2277 | BackFramebuffer::BackFramebuffer(GLES2DecoderImpl* decoder) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2278 | : decoder_(decoder), |
| 2279 | id_(0) { |
| 2280 | } |
| 2281 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2282 | BackFramebuffer::~BackFramebuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2283 | // This does not destroy the frame buffer because that would require that |
| 2284 | // the associated GL context was current. Just check that it was explicitly |
| 2285 | // destroyed. |
| 2286 | DCHECK_EQ(id_, 0u); |
| 2287 | } |
| 2288 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2289 | void BackFramebuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2290 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Create", |
| 2291 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2292 | Destroy(); |
| 2293 | glGenFramebuffersEXT(1, &id_); |
| 2294 | } |
| 2295 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2296 | void BackFramebuffer::AttachRenderTexture(BackTexture* texture) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2297 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2298 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2299 | "BackFramebuffer::AttachRenderTexture", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2300 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2301 | GLuint attach_id = texture ? texture->id() : 0; |
| 2302 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 2303 | GL_COLOR_ATTACHMENT0, |
| 2304 | GL_TEXTURE_2D, |
| 2305 | attach_id, |
| 2306 | 0); |
| 2307 | } |
| 2308 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2309 | void BackFramebuffer::AttachRenderBuffer(GLenum target, |
| 2310 | BackRenderbuffer* render_buffer) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2311 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2312 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2313 | "BackFramebuffer::AttachRenderBuffer", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2314 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2315 | GLuint attach_id = render_buffer ? render_buffer->id() : 0; |
| 2316 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2317 | target, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2318 | GL_RENDERBUFFER, |
| 2319 | attach_id); |
| 2320 | } |
| 2321 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2322 | void BackFramebuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2323 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2324 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Destroy", |
| 2325 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2326 | glDeleteFramebuffersEXT(1, &id_); |
| 2327 | id_ = 0; |
| 2328 | } |
| 2329 | } |
| 2330 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2331 | void BackFramebuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2332 | id_ = 0; |
| 2333 | } |
| 2334 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2335 | GLenum BackFramebuffer::CheckStatus() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2336 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2337 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::CheckStatus", |
| 2338 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2339 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2340 | return glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 2341 | } |
| 2342 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2343 | GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) { |
| 2344 | return new GLES2DecoderImpl(group); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2345 | } |
| 2346 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2347 | GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2348 | : GLES2Decoder(), |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2349 | group_(group), |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 2350 | logger_(&debug_marker_manager_), |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2351 | state_(group_->feature_info(), this, &logger_), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2352 | unpack_flip_y_(false), |
| 2353 | unpack_premultiply_alpha_(false), |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 2354 | unpack_unpremultiply_alpha_(false), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2355 | attrib_0_buffer_id_(0), |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 2356 | attrib_0_buffer_matches_value_(true), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2357 | attrib_0_size_(0), |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2358 | fixed_attrib_buffer_id_(0), |
| 2359 | fixed_attrib_buffer_size_(0), |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2360 | offscreen_target_color_format_(0), |
| 2361 | offscreen_target_depth_format_(0), |
| 2362 | offscreen_target_stencil_format_(0), |
| 2363 | offscreen_target_samples_(0), |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2364 | offscreen_target_buffer_preserved_(true), |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2365 | offscreen_saved_color_format_(0), |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 2366 | back_buffer_color_format_(0), |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2367 | back_buffer_has_depth_(false), |
| 2368 | back_buffer_has_stencil_(false), |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2369 | surfaceless_(false), |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 2370 | backbuffer_needs_clear_bits_(0), |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 2371 | current_decoder_error_(error::kNoError), |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 2372 | use_shader_translator_(true), |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 2373 | validators_(group_->feature_info()->validators()), |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 2374 | feature_info_(group_->feature_info()), |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2375 | frame_number_(0), |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2376 | has_robustness_extension_(false), |
[email protected] | 75c023c | 2011-08-22 23:54:51 | [diff] [blame] | 2377 | reset_status_(GL_NO_ERROR), |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 2378 | reset_by_robustness_extension_(false), |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 2379 | supports_post_sub_buffer_(false), |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2380 | force_webgl_glsl_validation_(false), |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2381 | derivatives_explicitly_enabled_(false), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2382 | frag_depth_explicitly_enabled_(false), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 2383 | draw_buffers_explicitly_enabled_(false), |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 2384 | shader_texture_lod_explicitly_enabled_(false), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2385 | compile_shader_always_succeeds_(false), |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2386 | lose_context_when_out_of_memory_(false), |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2387 | service_logging_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 2388 | switches::kEnableGPUServiceLoggingGPU)), |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2389 | viewport_max_width_(0), |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2390 | viewport_max_height_(0), |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 2391 | texture_state_(group_->feature_info() |
| 2392 | ->workarounds() |
| 2393 | .texsubimage2d_faster_than_teximage2d), |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 2394 | cb_command_trace_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 2395 | TRACE_DISABLED_BY_DEFAULT("cb_command"))), |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 2396 | gpu_decoder_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 2397 | TRACE_DISABLED_BY_DEFAULT("gpu_decoder"))), |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 2398 | gpu_trace_level_(2), |
| 2399 | gpu_trace_commands_(false), |
| 2400 | gpu_debug_commands_(false), |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2401 | validation_texture_(0), |
| 2402 | validation_fbo_multisample_(0), |
| 2403 | validation_fbo_(0) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2404 | DCHECK(group); |
| 2405 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2406 | attrib_0_value_.v[0] = 0.0f; |
| 2407 | attrib_0_value_.v[1] = 0.0f; |
| 2408 | attrib_0_value_.v[2] = 0.0f; |
| 2409 | attrib_0_value_.v[3] = 1.0f; |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2410 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2411 | // The shader translator is used for WebGL even when running on EGL |
| 2412 | // because additional restrictions are needed (like only enabling |
| 2413 | // GL_OES_standard_derivatives on demand). It is used for the unit |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 2414 | // tests because GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes |
| 2415 | // the empty string to CompileShader and this is not a valid shader. |
| 2416 | if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL || |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2417 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2418 | switches::kDisableGLSLTranslator)) { |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2419 | use_shader_translator_ = false; |
| 2420 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2421 | } |
| 2422 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2423 | GLES2DecoderImpl::~GLES2DecoderImpl() { |
| 2424 | } |
| 2425 | |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2426 | bool GLES2DecoderImpl::Initialize( |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2427 | const scoped_refptr<gfx::GLSurface>& surface, |
| 2428 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2429 | bool offscreen, |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2430 | const gfx::Size& size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2431 | const DisallowedFeatures& disallowed_features, |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2432 | const std::vector<int32>& attribs) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 2433 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2434 | DCHECK(context->IsCurrent(surface.get())); |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 2435 | DCHECK(!context_.get()); |
| 2436 | |
jbauman | a760469 | 2014-10-17 02:00:39 | [diff] [blame] | 2437 | surfaceless_ = surface->IsSurfaceless() && !offscreen; |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2438 | |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 2439 | set_initialized(); |
[email protected] | b4af07d | 2014-08-20 00:11:57 | [diff] [blame] | 2440 | gpu_tracer_.reset(new GPUTracer(this)); |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 2441 | gpu_state_tracer_ = GPUStateTracer::Create(&state_); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 2442 | |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2443 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2444 | switches::kEnableGPUDebugging)) { |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 2445 | set_debug(true); |
| 2446 | } |
| 2447 | |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2448 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2449 | switches::kEnableGPUCommandLogging)) { |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2450 | set_log_commands(true); |
| 2451 | } |
| 2452 | |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2453 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2454 | switches::kEnableUnsafeES3APIs)) { |
zmo | 84c0820 | 2014-11-23 15:28:40 | [diff] [blame] | 2455 | set_unsafe_es3_apis_enabled(true); |
| 2456 | } |
| 2457 | |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2458 | compile_shader_always_succeeds_ = |
| 2459 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2460 | switches::kCompileShaderAlwaysSucceeds); |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2461 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2462 | // Take ownership of the context and surface. The surface can be replaced with |
| 2463 | // SetSurface. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2464 | context_ = context; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2465 | surface_ = surface; |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2466 | |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 2467 | ContextCreationAttribHelper attrib_parser; |
| 2468 | if (!attrib_parser.Parse(attribs)) |
| 2469 | return false; |
| 2470 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2471 | // Save the loseContextWhenOutOfMemory context creation attribute. |
| 2472 | lose_context_when_out_of_memory_ = |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2473 | attrib_parser.lose_context_when_out_of_memory; |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2474 | |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 2475 | // If the failIfMajorPerformanceCaveat context creation attribute was true |
| 2476 | // and we are using a software renderer, fail. |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2477 | if (attrib_parser.fail_if_major_perf_caveat && |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 2478 | feature_info_->feature_flags().is_swiftshader) { |
| 2479 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
| 2480 | Destroy(true); |
| 2481 | return false; |
| 2482 | } |
| 2483 | |
[email protected] | 956aec5 | 2013-09-05 15:41:19 | [diff] [blame] | 2484 | if (!group_->Initialize(this, disallowed_features)) { |
[email protected] | 09ddb91f | 2011-04-14 23:16:22 | [diff] [blame] | 2485 | LOG(ERROR) << "GpuScheduler::InitializeCommon failed because group " |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2486 | << "failed to initialize."; |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 2487 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2488 | Destroy(true); |
[email protected] | ae174109 | 2010-11-17 19:16:03 | [diff] [blame] | 2489 | return false; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2490 | } |
[email protected] | b64c2495 | 2012-04-19 03:20:27 | [diff] [blame] | 2491 | CHECK_GL_ERROR(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2492 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2493 | disallowed_features_ = disallowed_features; |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2494 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 2495 | state_.attrib_values.resize(group_->max_vertex_attribs()); |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 2496 | vertex_array_manager_.reset(new VertexArrayManager()); |
| 2497 | |
| 2498 | GLuint default_vertex_attrib_service_id = 0; |
| 2499 | if (features().native_vertex_array_object) { |
| 2500 | glGenVertexArraysOES(1, &default_vertex_attrib_service_id); |
| 2501 | glBindVertexArrayOES(default_vertex_attrib_service_id); |
| 2502 | } |
| 2503 | |
| 2504 | state_.default_vertex_attrib_manager = |
| 2505 | CreateVertexAttribManager(0, default_vertex_attrib_service_id, false); |
| 2506 | |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 2507 | state_.default_vertex_attrib_manager->Initialize( |
[email protected] | 94ba2e0 | 2014-03-12 10:32:00 | [diff] [blame] | 2508 | group_->max_vertex_attribs(), |
| 2509 | feature_info_->workarounds().init_vertex_attributes); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2510 | |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 2511 | // vertex_attrib_manager is set to default_vertex_attrib_manager by this call |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 2512 | DoBindVertexArrayOES(0); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 2513 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2514 | query_manager_.reset(new QueryManager(this, feature_info_.get())); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 2515 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 2516 | image_manager_.reset(new ImageManager); |
| 2517 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2518 | util_.set_num_compressed_texture_formats( |
| 2519 | validators_->compressed_texture_format.GetValues().size()); |
| 2520 | |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 2521 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2522 | // We have to enable vertex array 0 on OpenGL or it won't render. Note that |
| 2523 | // OpenGL ES 2.0 does not have this issue. |
| 2524 | glEnableVertexAttribArray(0); |
| 2525 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2526 | glGenBuffersARB(1, &attrib_0_buffer_id_); |
| 2527 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 2528 | glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); |
| 2529 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2530 | glGenBuffersARB(1, &fixed_attrib_buffer_id_); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 2531 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2532 | state_.texture_units.resize(group_->max_texture_units()); |
| 2533 | for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) { |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2534 | glActiveTexture(GL_TEXTURE0 + tt); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2535 | // We want the last bind to be 2D. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2536 | TextureRef* ref; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2537 | if (features().oes_egl_image_external) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2538 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2539 | GL_TEXTURE_EXTERNAL_OES); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2540 | state_.texture_units[tt].bound_texture_external_oes = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2541 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, ref ? ref->service_id() : 0); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2542 | } |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2543 | if (features().arb_texture_rectangle) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2544 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2545 | GL_TEXTURE_RECTANGLE_ARB); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2546 | state_.texture_units[tt].bound_texture_rectangle_arb = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2547 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, ref ? ref->service_id() : 0); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2548 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2549 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
| 2550 | state_.texture_units[tt].bound_texture_cube_map = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2551 | glBindTexture(GL_TEXTURE_CUBE_MAP, ref ? ref->service_id() : 0); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2552 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
| 2553 | state_.texture_units[tt].bound_texture_2d = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2554 | glBindTexture(GL_TEXTURE_2D, ref ? ref->service_id() : 0); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 2555 | } |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2556 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2557 | CHECK_GL_ERROR(); |
| 2558 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2559 | if (offscreen) { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2560 | if (attrib_parser.samples > 0 && attrib_parser.sample_buffers > 0 && |
[email protected] | b060965 | 2012-12-14 07:24:54 | [diff] [blame] | 2561 | features().chromium_framebuffer_multisample) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2562 | // Per ext_framebuffer_multisample spec, need max bound on sample count. |
[email protected] | 0b1e9d7 | 2010-11-11 16:29:43 | [diff] [blame] | 2563 | // max_sample_count must be initialized to a sane value. If |
| 2564 | // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
| 2565 | GLint max_sample_count = 1; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2566 | glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2567 | offscreen_target_samples_ = std::min(attrib_parser.samples, |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2568 | max_sample_count); |
| 2569 | } else { |
| 2570 | offscreen_target_samples_ = 1; |
| 2571 | } |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2572 | offscreen_target_buffer_preserved_ = attrib_parser.buffer_preserved; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2573 | |
| 2574 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 2575 | const bool rgb8_supported = |
| 2576 | context_->HasExtension("GL_OES_rgb8_rgba8"); |
| 2577 | // The only available default render buffer formats in GLES2 have very |
| 2578 | // little precision. Don't enable multisampling unless 8-bit render |
| 2579 | // buffer formats are available--instead fall back to 8-bit textures. |
| 2580 | if (rgb8_supported && offscreen_target_samples_ > 1) { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2581 | offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2582 | GL_RGBA8 : GL_RGB8; |
| 2583 | } else { |
| 2584 | offscreen_target_samples_ = 1; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2585 | offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2586 | GL_RGBA : GL_RGB; |
| 2587 | } |
| 2588 | |
| 2589 | // ANGLE only supports packed depth/stencil formats, so use it if it is |
| 2590 | // available. |
| 2591 | const bool depth24_stencil8_supported = |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2592 | feature_info_->feature_flags().packed_depth24_stencil8; |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2593 | VLOG(1) << "GL_OES_packed_depth_stencil " |
| 2594 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2595 | if ((attrib_parser.depth_size > 0 || attrib_parser.stencil_size > 0) && |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2596 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2597 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2598 | offscreen_target_stencil_format_ = 0; |
| 2599 | } else { |
| 2600 | // It may be the case that this depth/stencil combination is not |
| 2601 | // supported, but this will be checked later by CheckFramebufferStatus. |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2602 | offscreen_target_depth_format_ = attrib_parser.depth_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2603 | GL_DEPTH_COMPONENT16 : 0; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2604 | offscreen_target_stencil_format_ = attrib_parser.stencil_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2605 | GL_STENCIL_INDEX8 : 0; |
| 2606 | } |
| 2607 | } else { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2608 | offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2609 | GL_RGBA : GL_RGB; |
| 2610 | |
| 2611 | // If depth is requested at all, use the packed depth stencil format if |
| 2612 | // it's available, as some desktop GL drivers don't support any non-packed |
| 2613 | // formats for depth attachments. |
| 2614 | const bool depth24_stencil8_supported = |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2615 | feature_info_->feature_flags().packed_depth24_stencil8; |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2616 | VLOG(1) << "GL_EXT_packed_depth_stencil " |
| 2617 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2618 | |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2619 | if ((attrib_parser.depth_size > 0 || attrib_parser.stencil_size > 0) && |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2620 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2621 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2622 | offscreen_target_stencil_format_ = 0; |
| 2623 | } else { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2624 | offscreen_target_depth_format_ = attrib_parser.depth_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2625 | GL_DEPTH_COMPONENT : 0; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2626 | offscreen_target_stencil_format_ = attrib_parser.stencil_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2627 | GL_STENCIL_INDEX : 0; |
| 2628 | } |
| 2629 | } |
| 2630 | |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2631 | offscreen_saved_color_format_ = attrib_parser.alpha_size > 0 ? |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2632 | GL_RGBA : GL_RGB; |
| 2633 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2634 | // Create the target frame buffer. This is the one that the client renders |
| 2635 | // directly to. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2636 | offscreen_target_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2637 | offscreen_target_frame_buffer_->Create(); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2638 | // Due to GLES2 format limitations, either the color texture (for |
| 2639 | // non-multisampling) or the color render buffer (for multisampling) will be |
| 2640 | // attached to the offscreen frame buffer. The render buffer has more |
| 2641 | // limited formats available to it, but the texture can't do multisampling. |
| 2642 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2643 | offscreen_target_color_render_buffer_.reset(new BackRenderbuffer( |
| 2644 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2645 | offscreen_target_color_render_buffer_->Create(); |
| 2646 | } else { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2647 | offscreen_target_color_texture_.reset(new BackTexture( |
| 2648 | memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2649 | offscreen_target_color_texture_->Create(); |
| 2650 | } |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2651 | offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer( |
| 2652 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2653 | offscreen_target_depth_render_buffer_->Create(); |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2654 | offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer( |
| 2655 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2656 | offscreen_target_stencil_render_buffer_->Create(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2657 | |
| 2658 | // Create the saved offscreen texture. The target frame buffer is copied |
| 2659 | // here when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2660 | offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2661 | offscreen_saved_frame_buffer_->Create(); |
| 2662 | // |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2663 | offscreen_saved_color_texture_.reset(new BackTexture( |
| 2664 | memory_tracker(), &state_)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2665 | offscreen_saved_color_texture_->Create(); |
| 2666 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2667 | // Allocate the render buffers at their initial size and check the status |
| 2668 | // of the frame buffers is okay. |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 2669 | if (!ResizeOffscreenFrameBuffer(size)) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 2670 | LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2671 | Destroy(true); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2672 | return false; |
| 2673 | } |
| 2674 | |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2675 | // Allocate the offscreen saved color texture. |
| 2676 | DCHECK(offscreen_saved_color_format_); |
| 2677 | offscreen_saved_color_texture_->AllocateStorage( |
| 2678 | gfx::Size(1, 1), offscreen_saved_color_format_, true); |
| 2679 | |
| 2680 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 2681 | offscreen_saved_color_texture_.get()); |
| 2682 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 2683 | GL_FRAMEBUFFER_COMPLETE) { |
| 2684 | LOG(ERROR) << "Offscreen saved FBO was incomplete."; |
| 2685 | Destroy(true); |
| 2686 | return false; |
| 2687 | } |
| 2688 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2689 | // Bind to the new default frame buffer (the offscreen target frame buffer). |
| 2690 | // This should now be associated with ID zero. |
| 2691 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 2692 | } else { |
| 2693 | glBindFramebufferEXT(GL_FRAMEBUFFER, GetBackbufferServiceId()); |
| 2694 | // These are NOT if the back buffer has these proprorties. They are |
| 2695 | // if we want the command buffer to enforce them regardless of what |
| 2696 | // the real backbuffer is assuming the real back buffer gives us more than |
| 2697 | // we ask for. In other words, if we ask for RGB and we get RGBA then we'll |
| 2698 | // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we |
| 2699 | // can't do anything about that. |
| 2700 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2701 | if (!surfaceless_) { |
| 2702 | GLint v = 0; |
| 2703 | glGetIntegerv(GL_ALPHA_BITS, &v); |
| 2704 | // This checks if the user requested RGBA and we have RGBA then RGBA. If |
| 2705 | // the user requested RGB then RGB. If the user did not specify a |
| 2706 | // preference than use whatever we were given. Same for DEPTH and STENCIL. |
| 2707 | back_buffer_color_format_ = |
| 2708 | (attrib_parser.alpha_size != 0 && v > 0) ? GL_RGBA : GL_RGB; |
| 2709 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 2710 | back_buffer_has_depth_ = attrib_parser.depth_size != 0 && v > 0; |
| 2711 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 2712 | back_buffer_has_stencil_ = attrib_parser.stencil_size != 0 && v > 0; |
| 2713 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2714 | } |
| 2715 | |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2716 | // OpenGL ES 2.0 implicitly enables the desktop GL capability |
| 2717 | // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact |
| 2718 | // isn't well documented; it was discovered in the Khronos OpenGL ES |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2719 | // mailing list archives. It also implicitly enables the desktop GL |
| 2720 | // capability GL_POINT_SPRITE to provide access to the gl_PointCoord |
| 2721 | // variable in fragment shaders. |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2722 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2723 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2724 | glEnable(GL_POINT_SPRITE); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2725 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2726 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2727 | has_robustness_extension_ = |
| 2728 | context->HasExtension("GL_ARB_robustness") || |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 2729 | context->HasExtension("GL_KHR_robustness") || |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2730 | context->HasExtension("GL_EXT_robustness"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2731 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2732 | if (!InitializeShaderTranslator()) { |
| 2733 | return false; |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2734 | } |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2735 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2736 | state_.viewport_width = size.width(); |
| 2737 | state_.viewport_height = size.height(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2738 | |
[email protected] | 5904806b | 2012-05-08 18:10:22 | [diff] [blame] | 2739 | GLint viewport_params[4] = { 0 }; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2740 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2741 | viewport_max_width_ = viewport_params[0]; |
| 2742 | viewport_max_height_ = viewport_params[1]; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2743 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2744 | state_.scissor_width = state_.viewport_width; |
| 2745 | state_.scissor_height = state_.viewport_height; |
| 2746 | |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2747 | // Set all the default state because some GL drivers get it wrong. |
[email protected] | 88ba52f | 2014-04-09 12:39:34 | [diff] [blame] | 2748 | state_.InitCapabilities(NULL); |
| 2749 | state_.InitState(NULL); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2750 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2751 | |
| 2752 | DoBindBuffer(GL_ARRAY_BUFFER, 0); |
| 2753 | DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 2754 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2755 | DoBindRenderbuffer(GL_RENDERBUFFER, 0); |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 2756 | DoBindValueBufferCHROMIUM(GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM, 0); |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2757 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2758 | bool call_gl_clear = !surfaceless_; |
[email protected] | 88cfd13 | 2013-07-11 00:59:00 | [diff] [blame] | 2759 | #if defined(OS_ANDROID) |
| 2760 | // Temporary workaround for Android WebView because this clear ignores the |
| 2761 | // clip and corrupts that external UI of the App. Not calling glClear is ok |
| 2762 | // because the system already clears the buffer before each draw. Proper |
| 2763 | // fix might be setting the scissor clip properly before initialize. See |
| 2764 | // crbug.com/259023 for details. |
| 2765 | call_gl_clear = surface_->GetHandle(); |
| 2766 | #endif |
| 2767 | if (call_gl_clear) { |
| 2768 | // Clear the backbuffer. |
| 2769 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 2770 | } |
[email protected] | 561cc0a6 | 2013-05-07 18:34:45 | [diff] [blame] | 2771 | |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 2772 | supports_post_sub_buffer_ = surface->SupportsPostSubBuffer(); |
| 2773 | if (feature_info_->workarounds() |
| 2774 | .disable_post_sub_buffers_for_onscreen_surfaces && |
| 2775 | !surface->IsOffscreen()) |
| 2776 | supports_post_sub_buffer_ = false; |
| 2777 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2778 | if (feature_info_->workarounds().reverse_point_sprite_coord_origin) { |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2779 | glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); |
| 2780 | } |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2781 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 2782 | if (feature_info_->workarounds().unbind_fbo_on_context_switch) { |
| 2783 | context_->SetUnbindFboOnMakeCurrent(); |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2784 | } |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2785 | |
[email protected] | 97419c0 | 2013-04-10 02:52:38 | [diff] [blame] | 2786 | // Only compositor contexts are known to use only the subset of GL |
| 2787 | // that can be safely migrated between the iGPU and the dGPU. Mark |
| 2788 | // those contexts as safe to forcibly transition between the GPUs. |
| 2789 | // http://crbug.com/180876, http://crbug.com/227228 |
| 2790 | if (!offscreen) |
| 2791 | context_->SetSafeToForceGpuSwitch(); |
| 2792 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 2793 | async_pixel_transfer_manager_.reset( |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 2794 | AsyncPixelTransferManager::Create(context.get())); |
| 2795 | async_pixel_transfer_manager_->Initialize(texture_manager()); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 2796 | |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 2797 | if (workarounds().gl_clear_broken) { |
| 2798 | DCHECK(!clear_framebuffer_blit_.get()); |
| 2799 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glClearWorkaroundInit"); |
| 2800 | clear_framebuffer_blit_.reset(new ClearFramebufferResourceManager(this)); |
| 2801 | if (LOCAL_PEEK_GL_ERROR("glClearWorkaroundInit") != GL_NO_ERROR) |
| 2802 | return false; |
| 2803 | } |
| 2804 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 2805 | framebuffer_manager()->AddObserver(this); |
| 2806 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2807 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2808 | } |
| 2809 | |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2810 | Capabilities GLES2DecoderImpl::GetCapabilities() { |
| 2811 | DCHECK(initialized()); |
| 2812 | |
| 2813 | Capabilities caps; |
piman | 1c2e0a85 | 2014-11-12 05:17:55 | [diff] [blame] | 2814 | caps.VisitPrecisions([](GLenum shader, GLenum type, |
| 2815 | Capabilities::ShaderPrecision* shader_precision) { |
| 2816 | GLint range[2] = {0, 0}; |
| 2817 | GLint precision = 0; |
| 2818 | GetShaderPrecisionFormatImpl(shader, type, range, &precision); |
| 2819 | shader_precision->min_range = range[0]; |
| 2820 | shader_precision->max_range = range[1]; |
| 2821 | shader_precision->precision = precision; |
| 2822 | }); |
| 2823 | DoGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, |
| 2824 | &caps.max_combined_texture_image_units); |
| 2825 | DoGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &caps.max_cube_map_texture_size); |
| 2826 | DoGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 2827 | &caps.max_fragment_uniform_vectors); |
| 2828 | DoGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &caps.max_renderbuffer_size); |
| 2829 | DoGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &caps.max_texture_image_units); |
| 2830 | DoGetIntegerv(GL_MAX_TEXTURE_SIZE, &caps.max_texture_size); |
| 2831 | DoGetIntegerv(GL_MAX_VARYING_VECTORS, &caps.max_varying_vectors); |
| 2832 | DoGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &caps.max_vertex_attribs); |
| 2833 | DoGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, |
| 2834 | &caps.max_vertex_texture_image_units); |
| 2835 | DoGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, |
| 2836 | &caps.max_vertex_uniform_vectors); |
| 2837 | DoGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, |
| 2838 | &caps.num_compressed_texture_formats); |
| 2839 | DoGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &caps.num_shader_binary_formats); |
| 2840 | DoGetIntegerv(GL_BIND_GENERATES_RESOURCE_CHROMIUM, |
| 2841 | &caps.bind_generates_resource_chromium); |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2842 | |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2843 | caps.egl_image_external = |
| 2844 | feature_info_->feature_flags().oes_egl_image_external; |
| 2845 | caps.texture_format_bgra8888 = |
| 2846 | feature_info_->feature_flags().ext_texture_format_bgra8888; |
| 2847 | caps.texture_format_etc1 = |
| 2848 | feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; |
aelias | d880a3d | 2014-08-26 00:46:20 | [diff] [blame] | 2849 | caps.texture_format_etc1_npot = |
| 2850 | caps.texture_format_etc1 && !workarounds().etc1_power_of_two_only; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2851 | caps.texture_rectangle = feature_info_->feature_flags().arb_texture_rectangle; |
| 2852 | caps.texture_usage = feature_info_->feature_flags().angle_texture_usage; |
| 2853 | caps.texture_storage = feature_info_->feature_flags().ext_texture_storage; |
| 2854 | caps.discard_framebuffer = |
| 2855 | feature_info_->feature_flags().ext_discard_framebuffer; |
[email protected] | 12c99ab0 | 2014-04-22 10:12:35 | [diff] [blame] | 2856 | caps.sync_query = feature_info_->feature_flags().chromium_sync_query; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2857 | |
| 2858 | #if defined(OS_MACOSX) |
| 2859 | // This is unconditionally true on mac, no need to test for it at runtime. |
| 2860 | caps.iosurface = true; |
| 2861 | #endif |
| 2862 | |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 2863 | caps.post_sub_buffer = supports_post_sub_buffer_; |
reveman | 34010918 | 2014-09-30 15:36:45 | [diff] [blame] | 2864 | caps.image = true; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2865 | |
ed | 9198b42 | 2014-10-23 15:01:37 | [diff] [blame] | 2866 | caps.blend_equation_advanced = |
| 2867 | feature_info_->feature_flags().blend_equation_advanced; |
| 2868 | caps.blend_equation_advanced_coherent = |
| 2869 | feature_info_->feature_flags().blend_equation_advanced_coherent; |
hendrikw | fc25ca619 | 2014-12-02 06:05:13 | [diff] [blame] | 2870 | caps.texture_rg = feature_info_->feature_flags().ext_texture_rg; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 2871 | return caps; |
| 2872 | } |
| 2873 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2874 | void GLES2DecoderImpl::UpdateCapabilities() { |
| 2875 | util_.set_num_compressed_texture_formats( |
| 2876 | validators_->compressed_texture_format.GetValues().size()); |
| 2877 | util_.set_num_shader_binary_formats( |
| 2878 | validators_->shader_binary_format.GetValues().size()); |
| 2879 | } |
| 2880 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2881 | bool GLES2DecoderImpl::InitializeShaderTranslator() { |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 2882 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::InitializeShaderTranslator"); |
| 2883 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2884 | if (!use_shader_translator_) { |
| 2885 | return true; |
| 2886 | } |
| 2887 | ShBuiltInResources resources; |
| 2888 | ShInitBuiltInResources(&resources); |
| 2889 | resources.MaxVertexAttribs = group_->max_vertex_attribs(); |
| 2890 | resources.MaxVertexUniformVectors = |
| 2891 | group_->max_vertex_uniform_vectors(); |
| 2892 | resources.MaxVaryingVectors = group_->max_varying_vectors(); |
| 2893 | resources.MaxVertexTextureImageUnits = |
| 2894 | group_->max_vertex_texture_image_units(); |
| 2895 | resources.MaxCombinedTextureImageUnits = group_->max_texture_units(); |
| 2896 | resources.MaxTextureImageUnits = group_->max_texture_image_units(); |
| 2897 | resources.MaxFragmentUniformVectors = |
| 2898 | group_->max_fragment_uniform_vectors(); |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 2899 | resources.MaxDrawBuffers = group_->max_draw_buffers(); |
[email protected] | a0b7814 | 2013-05-23 00:47:24 | [diff] [blame] | 2900 | resources.MaxExpressionComplexity = 256; |
| 2901 | resources.MaxCallStackDepth = 256; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2902 | |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 2903 | GLint range[2] = { 0, 0 }; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 2904 | GLint precision = 0; |
| 2905 | GetShaderPrecisionFormatImpl(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, |
| 2906 | range, &precision); |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 2907 | resources.FragmentPrecisionHigh = |
| 2908 | PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision); |
[email protected] | 9e98f61b | 2013-03-05 02:21:14 | [diff] [blame] | 2909 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2910 | if (force_webgl_glsl_validation_) { |
| 2911 | resources.OES_standard_derivatives = derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2912 | resources.EXT_frag_depth = frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 2913 | resources.EXT_draw_buffers = draw_buffers_explicitly_enabled_; |
[email protected] | cd8f189 | 2013-09-05 00:14:44 | [diff] [blame] | 2914 | if (!draw_buffers_explicitly_enabled_) |
| 2915 | resources.MaxDrawBuffers = 1; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 2916 | resources.EXT_shader_texture_lod = shader_texture_lod_explicitly_enabled_; |
oetuaho | 0decd44 | 2014-10-13 08:40:46 | [diff] [blame] | 2917 | resources.NV_draw_buffers = |
| 2918 | draw_buffers_explicitly_enabled_ && features().nv_draw_buffers; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2919 | } else { |
| 2920 | resources.OES_standard_derivatives = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2921 | features().oes_standard_derivatives ? 1 : 0; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2922 | resources.ARB_texture_rectangle = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2923 | features().arb_texture_rectangle ? 1 : 0; |
[email protected] | 70e7bb1 | 2012-09-29 14:01:06 | [diff] [blame] | 2924 | resources.OES_EGL_image_external = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2925 | features().oes_egl_image_external ? 1 : 0; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 2926 | resources.EXT_draw_buffers = |
| 2927 | features().ext_draw_buffers ? 1 : 0; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2928 | resources.EXT_frag_depth = |
| 2929 | features().ext_frag_depth ? 1 : 0; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 2930 | resources.EXT_shader_texture_lod = |
| 2931 | features().ext_shader_texture_lod ? 1 : 0; |
oetuaho | 0decd44 | 2014-10-13 08:40:46 | [diff] [blame] | 2932 | resources.NV_draw_buffers = |
| 2933 | features().nv_draw_buffers ? 1 : 0; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2934 | } |
| 2935 | |
[email protected] | 26b6144 | 2013-03-17 16:12:01 | [diff] [blame] | 2936 | ShShaderSpec shader_spec = force_webgl_glsl_validation_ ? SH_WEBGL_SPEC |
| 2937 | : SH_GLES2_SPEC; |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2938 | if (shader_spec == SH_WEBGL_SPEC && features().enable_shader_name_hashing) |
[email protected] | 3d944a8 | 2013-02-12 19:09:02 | [diff] [blame] | 2939 | resources.HashFunction = &CityHash64; |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 2940 | else |
| 2941 | resources.HashFunction = NULL; |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 2942 | ShaderTranslatorInterface::GlslImplementationType implementation_type = |
| 2943 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? |
| 2944 | ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2945 | int driver_bug_workarounds = 0; |
| 2946 | if (workarounds().needs_glsl_built_in_function_emulation) |
| 2947 | driver_bug_workarounds |= SH_EMULATE_BUILT_IN_FUNCTIONS; |
[email protected] | 81187c6 | 2013-09-09 23:54:54 | [diff] [blame] | 2948 | if (workarounds().init_gl_position_in_vertex_shader) |
| 2949 | driver_bug_workarounds |= SH_INIT_GL_POSITION; |
[email protected] | f0c8760 | 2013-10-17 19:34:11 | [diff] [blame] | 2950 | if (workarounds().unfold_short_circuit_as_ternary_operation) |
| 2951 | driver_bug_workarounds |= SH_UNFOLD_SHORT_CIRCUIT; |
[email protected] | b03219d | 2014-02-12 11:17:05 | [diff] [blame] | 2952 | if (workarounds().init_varyings_without_static_use) |
| 2953 | driver_bug_workarounds |= SH_INIT_VARYINGS_WITHOUT_STATIC_USE; |
[email protected] | f4db2b1 | 2014-03-01 03:57:06 | [diff] [blame] | 2954 | if (workarounds().unroll_for_loop_with_sampler_array_index) |
| 2955 | driver_bug_workarounds |= SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX; |
[email protected] | 711e9080 | 2014-07-22 20:40:25 | [diff] [blame] | 2956 | if (workarounds().scalarize_vec_and_mat_constructor_args) |
| 2957 | driver_bug_workarounds |= SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS; |
[email protected] | fa6d398 | 2014-08-18 18:10:27 | [diff] [blame] | 2958 | if (workarounds().regenerate_struct_names) |
| 2959 | driver_bug_workarounds |= SH_REGENERATE_STRUCT_NAMES; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2960 | |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2961 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2962 | switches::kEmulateShaderPrecision)) |
oetuaho | affd85abe | 2014-12-11 09:47:09 | [diff] [blame] | 2963 | resources.WEBGL_debug_shader_precision = true; |
| 2964 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 2965 | vertex_translator_ = shader_translator_cache()->GetTranslator( |
[email protected] | aeecc6b | 2014-07-03 17:18:26 | [diff] [blame] | 2966 | GL_VERTEX_SHADER, |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 2967 | shader_spec, |
| 2968 | &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2969 | implementation_type, |
| 2970 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2971 | if (!vertex_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2972 | LOG(ERROR) << "Could not initialize vertex shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2973 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2974 | return false; |
| 2975 | } |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2976 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 2977 | fragment_translator_ = shader_translator_cache()->GetTranslator( |
[email protected] | aeecc6b | 2014-07-03 17:18:26 | [diff] [blame] | 2978 | GL_FRAGMENT_SHADER, |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 2979 | shader_spec, |
| 2980 | &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 2981 | implementation_type, |
| 2982 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 2983 | if (!fragment_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2984 | LOG(ERROR) << "Could not initialize fragment shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2985 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2986 | return false; |
| 2987 | } |
| 2988 | return true; |
| 2989 | } |
| 2990 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2991 | bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 2992 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2993 | if (GetBuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2994 | return false; |
| 2995 | } |
| 2996 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2997 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 2998 | glGenBuffersARB(n, service_ids.get()); |
| 2999 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3000 | CreateBuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3001 | } |
| 3002 | return true; |
| 3003 | } |
| 3004 | |
| 3005 | bool GLES2DecoderImpl::GenFramebuffersHelper( |
| 3006 | GLsizei n, const GLuint* client_ids) { |
| 3007 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3008 | if (GetFramebuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3009 | return false; |
| 3010 | } |
| 3011 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 3012 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3013 | glGenFramebuffersEXT(n, service_ids.get()); |
| 3014 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3015 | CreateFramebuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3016 | } |
| 3017 | return true; |
| 3018 | } |
| 3019 | |
| 3020 | bool GLES2DecoderImpl::GenRenderbuffersHelper( |
| 3021 | GLsizei n, const GLuint* client_ids) { |
| 3022 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3023 | if (GetRenderbuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3024 | return false; |
| 3025 | } |
| 3026 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 3027 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3028 | glGenRenderbuffersEXT(n, service_ids.get()); |
| 3029 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3030 | CreateRenderbuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3031 | } |
| 3032 | return true; |
| 3033 | } |
| 3034 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 3035 | bool GLES2DecoderImpl::GenValuebuffersCHROMIUMHelper(GLsizei n, |
| 3036 | const GLuint* client_ids) { |
| 3037 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3038 | if (GetValuebuffer(client_ids[ii])) { |
| 3039 | return false; |
| 3040 | } |
| 3041 | } |
| 3042 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3043 | CreateValuebuffer(client_ids[ii]); |
| 3044 | } |
| 3045 | return true; |
| 3046 | } |
| 3047 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3048 | bool GLES2DecoderImpl::GenTexturesHelper(GLsizei n, const GLuint* client_ids) { |
| 3049 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3050 | if (GetTexture(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3051 | return false; |
| 3052 | } |
| 3053 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 3054 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3055 | glGenTextures(n, service_ids.get()); |
| 3056 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3057 | CreateTexture(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3058 | } |
| 3059 | return true; |
| 3060 | } |
| 3061 | |
| 3062 | void GLES2DecoderImpl::DeleteBuffersHelper( |
| 3063 | GLsizei n, const GLuint* client_ids) { |
| 3064 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 3065 | Buffer* buffer = GetBuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3066 | if (buffer && !buffer->IsDeleted()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3067 | state_.vertex_attrib_manager->Unbind(buffer); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3068 | if (state_.bound_array_buffer.get() == buffer) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3069 | state_.bound_array_buffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3070 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3071 | RemoveBuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3072 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3073 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3074 | } |
| 3075 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3076 | void GLES2DecoderImpl::DeleteFramebuffersHelper( |
| 3077 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3078 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3079 | features().chromium_framebuffer_multisample; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3080 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 3081 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3082 | Framebuffer* framebuffer = |
| 3083 | GetFramebuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3084 | if (framebuffer && !framebuffer->IsDeleted()) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3085 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3086 | framebuffer_state_.bound_draw_framebuffer = NULL; |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3087 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3088 | GLenum target = supports_separate_framebuffer_binds ? |
| 3089 | GL_DRAW_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3090 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
| 3091 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3092 | if (framebuffer == framebuffer_state_.bound_read_framebuffer.get()) { |
| 3093 | framebuffer_state_.bound_read_framebuffer = NULL; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3094 | GLenum target = supports_separate_framebuffer_binds ? |
| 3095 | GL_READ_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3096 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3097 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3098 | OnFboChanged(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3099 | RemoveFramebuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3100 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 3101 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3102 | } |
| 3103 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3104 | void GLES2DecoderImpl::DeleteRenderbuffersHelper( |
| 3105 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3106 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3107 | features().chromium_framebuffer_multisample; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 3108 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3109 | Renderbuffer* renderbuffer = |
| 3110 | GetRenderbuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3111 | if (renderbuffer && !renderbuffer->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3112 | if (state_.bound_renderbuffer.get() == renderbuffer) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3113 | state_.bound_renderbuffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3114 | } |
| 3115 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3116 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3117 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 3118 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3119 | ->UnbindRenderbuffer(GL_READ_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3120 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3121 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3122 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3123 | ->UnbindRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3124 | } |
| 3125 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3126 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3127 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3128 | ->UnbindRenderbuffer(GL_FRAMEBUFFER, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3129 | } |
| 3130 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3131 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3132 | RemoveRenderbuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3133 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 3134 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3135 | } |
| 3136 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 3137 | void GLES2DecoderImpl::DeleteValuebuffersCHROMIUMHelper( |
| 3138 | GLsizei n, |
| 3139 | const GLuint* client_ids) { |
| 3140 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3141 | Valuebuffer* valuebuffer = GetValuebuffer(client_ids[ii]); |
| 3142 | if (valuebuffer) { |
| 3143 | if (state_.bound_valuebuffer.get() == valuebuffer) { |
| 3144 | state_.bound_valuebuffer = NULL; |
| 3145 | } |
| 3146 | RemoveValuebuffer(client_ids[ii]); |
| 3147 | } |
| 3148 | } |
| 3149 | } |
| 3150 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3151 | void GLES2DecoderImpl::DeleteTexturesHelper( |
| 3152 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3153 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3154 | features().chromium_framebuffer_multisample; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3155 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3156 | TextureRef* texture_ref = GetTexture(client_ids[ii]); |
| 3157 | if (texture_ref) { |
| 3158 | Texture* texture = texture_ref->texture(); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3159 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3160 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3161 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3162 | // Unbind texture_ref from texture_ref units. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3163 | for (size_t jj = 0; jj < state_.texture_units.size(); ++jj) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3164 | state_.texture_units[jj].Unbind(texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3165 | } |
| 3166 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3167 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3168 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 3169 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3170 | ->UnbindTexture(GL_READ_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3171 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3172 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3173 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3174 | ->UnbindTexture(GL_DRAW_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3175 | } |
| 3176 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3177 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3178 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3179 | ->UnbindTexture(GL_FRAMEBUFFER, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3180 | } |
| 3181 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3182 | #if defined(OS_MACOSX) |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 3183 | GLuint service_id = texture->service_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3184 | if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { |
| 3185 | ReleaseIOSurfaceForTexture(service_id); |
| 3186 | } |
| 3187 | #endif |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3188 | RemoveTexture(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3189 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3190 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3191 | } |
| 3192 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 3193 | // } // anonymous namespace |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3194 | |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 3195 | bool GLES2DecoderImpl::MakeCurrent() { |
[email protected] | 177d134 | 2013-12-07 04:20:34 | [diff] [blame] | 3196 | if (!context_.get()) |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3197 | return false; |
| 3198 | |
[email protected] | 177d134 | 2013-12-07 04:20:34 | [diff] [blame] | 3199 | if (!context_->MakeCurrent(surface_.get()) || WasContextLost()) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 3200 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during MakeCurrent."; |
[email protected] | e9f0ca8 | 2013-04-01 23:52:29 | [diff] [blame] | 3201 | |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 3202 | MaybeExitOnContextLost(); |
[email protected] | e9f0ca8 | 2013-04-01 23:52:29 | [diff] [blame] | 3203 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3204 | return false; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 3205 | } |
| 3206 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 3207 | ProcessFinishedAsyncTransfers(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 3208 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 3209 | // Rebind the FBO if it was unbound by the context. |
| 3210 | if (workarounds().unbind_fbo_on_context_switch) |
| 3211 | RestoreFramebufferBindings(); |
| 3212 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3213 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3214 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 3215 | return true; |
| 3216 | } |
| 3217 | |
| 3218 | void GLES2DecoderImpl::ProcessFinishedAsyncTransfers() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 3219 | ProcessPendingReadPixels(); |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 3220 | if (engine() && query_manager_.get()) |
| 3221 | query_manager_->ProcessPendingTransferQueries(); |
| 3222 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 3223 | // TODO(epenner): Is there a better place to do this? |
| 3224 | // This needs to occur before we execute any batch of commands |
| 3225 | // from the client, as the client may have recieved an async |
| 3226 | // completion while issuing those commands. |
| 3227 | // "DidFlushStart" would be ideal if we had such a callback. |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3228 | async_pixel_transfer_manager_->BindCompletedAsyncTransfers(); |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 3229 | } |
| 3230 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3231 | static void RebindCurrentFramebuffer( |
| 3232 | GLenum target, |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3233 | Framebuffer* framebuffer, |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3234 | GLuint back_buffer_service_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3235 | GLuint framebuffer_id = framebuffer ? framebuffer->service_id() : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3236 | |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3237 | if (framebuffer_id == 0) { |
| 3238 | framebuffer_id = back_buffer_service_id; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3239 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3240 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3241 | glBindFramebufferEXT(target, framebuffer_id); |
| 3242 | } |
| 3243 | |
| 3244 | void GLES2DecoderImpl::RestoreCurrentFramebufferBindings() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3245 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3246 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3247 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3248 | RebindCurrentFramebuffer( |
| 3249 | GL_FRAMEBUFFER, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3250 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3251 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3252 | } else { |
| 3253 | RebindCurrentFramebuffer( |
| 3254 | GL_READ_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3255 | framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3256 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3257 | RebindCurrentFramebuffer( |
| 3258 | GL_DRAW_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3259 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3260 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3261 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3262 | OnFboChanged(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3263 | } |
| 3264 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3265 | bool GLES2DecoderImpl::CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3266 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3267 | GLenum target, const char* func_name) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3268 | if (!framebuffer) { |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 3269 | if (surfaceless_) |
| 3270 | return false; |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3271 | if (backbuffer_needs_clear_bits_) { |
| 3272 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
pkasting | 45796dc | 2014-10-17 04:18:32 | [diff] [blame] | 3273 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1.f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3274 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3275 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 3276 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 3277 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3278 | glClearDepth(1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3279 | state_.SetDeviceDepthMask(GL_TRUE); |
| 3280 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 3281 | bool reset_draw_buffer = false; |
brucedawson | 1824915 | 2014-10-31 23:02:32 | [diff] [blame] | 3282 | if ((backbuffer_needs_clear_bits_ & GL_COLOR_BUFFER_BIT) != 0 && |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 3283 | group_->draw_buffer() == GL_NONE) { |
| 3284 | reset_draw_buffer = true; |
| 3285 | GLenum buf = GL_BACK; |
| 3286 | if (GetBackbufferServiceId() != 0) // emulated backbuffer |
| 3287 | buf = GL_COLOR_ATTACHMENT0; |
| 3288 | glDrawBuffersARB(1, &buf); |
| 3289 | } |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3290 | glClear(backbuffer_needs_clear_bits_); |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 3291 | if (reset_draw_buffer) { |
| 3292 | GLenum buf = GL_NONE; |
| 3293 | glDrawBuffersARB(1, &buf); |
| 3294 | } |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3295 | backbuffer_needs_clear_bits_ = 0; |
| 3296 | RestoreClearState(); |
| 3297 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3298 | return true; |
| 3299 | } |
| 3300 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 3301 | if (framebuffer_manager()->IsComplete(framebuffer)) { |
| 3302 | return true; |
| 3303 | } |
| 3304 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3305 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 3306 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3307 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3308 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, "framebuffer incomplete"); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 3309 | return false; |
| 3310 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3311 | |
| 3312 | // Are all the attachments cleared? |
| 3313 | if (renderbuffer_manager()->HaveUnclearedRenderbuffers() || |
| 3314 | texture_manager()->HaveUnclearedMips()) { |
| 3315 | if (!framebuffer->IsCleared()) { |
| 3316 | // Can we clear them? |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 3317 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 3318 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3319 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3320 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 3321 | "framebuffer incomplete (clear)"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3322 | return false; |
| 3323 | } |
| 3324 | ClearUnclearedAttachments(target, framebuffer); |
| 3325 | } |
| 3326 | } |
| 3327 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 3328 | if (!framebuffer_manager()->IsComplete(framebuffer)) { |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 3329 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 3330 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3331 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3332 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 3333 | "framebuffer incomplete (check)"); |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 3334 | return false; |
| 3335 | } |
| 3336 | framebuffer_manager()->MarkAsComplete(framebuffer); |
| 3337 | } |
| 3338 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3339 | // NOTE: At this point we don't know if the framebuffer is complete but |
| 3340 | // we DO know that everything that needs to be cleared has been cleared. |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 3341 | return true; |
| 3342 | } |
| 3343 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3344 | bool GLES2DecoderImpl::CheckBoundFramebuffersValid(const char* func_name) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3345 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3346 | bool valid = CheckFramebufferValid( |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3347 | framebuffer_state_.bound_draw_framebuffer.get(), GL_FRAMEBUFFER_EXT, |
| 3348 | func_name); |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3349 | |
| 3350 | if (valid) |
| 3351 | OnUseFramebuffer(); |
| 3352 | |
| 3353 | return valid; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3354 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3355 | return CheckFramebufferValid(framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3356 | GL_DRAW_FRAMEBUFFER_EXT, |
| 3357 | func_name) && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3358 | CheckFramebufferValid(framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3359 | GL_READ_FRAMEBUFFER_EXT, |
| 3360 | func_name); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3361 | } |
| 3362 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 3363 | bool GLES2DecoderImpl::CheckBoundReadFramebufferColorAttachment( |
| 3364 | const char* func_name) { |
| 3365 | Framebuffer* framebuffer = features().chromium_framebuffer_multisample ? |
| 3366 | framebuffer_state_.bound_read_framebuffer.get() : |
| 3367 | framebuffer_state_.bound_draw_framebuffer.get(); |
| 3368 | if (!framebuffer) |
| 3369 | return true; |
| 3370 | if (framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL) { |
| 3371 | LOCAL_SET_GL_ERROR( |
| 3372 | GL_INVALID_OPERATION, func_name, "no color image attached"); |
| 3373 | return false; |
| 3374 | } |
| 3375 | return true; |
| 3376 | } |
| 3377 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 3378 | bool GLES2DecoderImpl::FormsTextureCopyingFeedbackLoop( |
| 3379 | TextureRef* texture, GLint level) { |
| 3380 | Framebuffer* framebuffer = features().chromium_framebuffer_multisample ? |
| 3381 | framebuffer_state_.bound_read_framebuffer.get() : |
| 3382 | framebuffer_state_.bound_draw_framebuffer.get(); |
| 3383 | if (!framebuffer) |
| 3384 | return false; |
| 3385 | const Framebuffer::Attachment* attachment = framebuffer->GetAttachment( |
| 3386 | GL_COLOR_ATTACHMENT0); |
| 3387 | if (!attachment) |
| 3388 | return false; |
| 3389 | return attachment->FormsFeedbackLoop(texture, level); |
| 3390 | } |
| 3391 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3392 | gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3393 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3394 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3395 | if (framebuffer != NULL) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3396 | const Framebuffer::Attachment* attachment = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3397 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3398 | if (attachment) { |
| 3399 | return gfx::Size(attachment->width(), attachment->height()); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 3400 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3401 | return gfx::Size(0, 0); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3402 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3403 | return offscreen_size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3404 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 3405 | return surface_->GetSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 3406 | } |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 3407 | } |
| 3408 | |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 3409 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferTextureType() { |
| 3410 | Framebuffer* framebuffer = |
| 3411 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
| 3412 | if (framebuffer != NULL) { |
| 3413 | return framebuffer->GetColorAttachmentTextureType(); |
| 3414 | } else { |
| 3415 | return GL_UNSIGNED_BYTE; |
| 3416 | } |
| 3417 | } |
| 3418 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3419 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3420 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3421 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3422 | if (framebuffer != NULL) { |
| 3423 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3424 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3425 | return offscreen_target_color_format_; |
| 3426 | } else { |
| 3427 | return back_buffer_color_format_; |
| 3428 | } |
| 3429 | } |
| 3430 | |
| 3431 | GLenum GLES2DecoderImpl::GetBoundDrawFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3432 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3433 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3434 | if (framebuffer != NULL) { |
| 3435 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3436 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3437 | return offscreen_target_color_format_; |
| 3438 | } else { |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 3439 | return back_buffer_color_format_; |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3440 | } |
| 3441 | } |
| 3442 | |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 3443 | void GLES2DecoderImpl::UpdateParentTextureInfo() { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3444 | if (!offscreen_saved_color_texture_info_.get()) |
| 3445 | return; |
| 3446 | GLenum target = offscreen_saved_color_texture_info_->texture()->target(); |
| 3447 | glBindTexture(target, offscreen_saved_color_texture_info_->service_id()); |
| 3448 | texture_manager()->SetLevelInfo( |
| 3449 | offscreen_saved_color_texture_info_.get(), |
| 3450 | GL_TEXTURE_2D, |
| 3451 | 0, // level |
| 3452 | GL_RGBA, |
| 3453 | offscreen_size_.width(), |
| 3454 | offscreen_size_.height(), |
| 3455 | 1, // depth |
| 3456 | 0, // border |
| 3457 | GL_RGBA, |
| 3458 | GL_UNSIGNED_BYTE, |
| 3459 | true); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3460 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3461 | "UpdateParentTextureInfo", |
| 3462 | GetErrorState(), |
| 3463 | offscreen_saved_color_texture_info_.get(), |
| 3464 | GL_TEXTURE_MAG_FILTER, |
[email protected] | eeeb07b9 | 2014-08-16 07:46:26 | [diff] [blame] | 3465 | GL_LINEAR); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3466 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3467 | "UpdateParentTextureInfo", |
| 3468 | GetErrorState(), |
| 3469 | offscreen_saved_color_texture_info_.get(), |
| 3470 | GL_TEXTURE_MIN_FILTER, |
[email protected] | eeeb07b9 | 2014-08-16 07:46:26 | [diff] [blame] | 3471 | GL_LINEAR); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3472 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3473 | "UpdateParentTextureInfo", |
| 3474 | GetErrorState(), |
| 3475 | offscreen_saved_color_texture_info_.get(), |
| 3476 | GL_TEXTURE_WRAP_S, |
| 3477 | GL_CLAMP_TO_EDGE); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3478 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3479 | "UpdateParentTextureInfo", |
| 3480 | GetErrorState(), |
| 3481 | offscreen_saved_color_texture_info_.get(), |
| 3482 | GL_TEXTURE_WRAP_T, |
| 3483 | GL_CLAMP_TO_EDGE); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3484 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 3485 | &state_, target); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3486 | glBindTexture(target, texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3487 | } |
| 3488 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3489 | void GLES2DecoderImpl::SetResizeCallback( |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3490 | const base::Callback<void(gfx::Size, float)>& callback) { |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3491 | resize_callback_ = callback; |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3492 | } |
| 3493 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 3494 | Logger* GLES2DecoderImpl::GetLogger() { |
| 3495 | return &logger_; |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 3496 | } |
| 3497 | |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3498 | void GLES2DecoderImpl::BeginDecoding() { |
| 3499 | gpu_tracer_->BeginDecoding(); |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 3500 | gpu_trace_commands_ = gpu_tracer_->IsTracing() && *gpu_decoder_category_; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3501 | gpu_debug_commands_ = log_commands() || debug() || gpu_trace_commands_ || |
| 3502 | (*cb_command_trace_category_ != 0); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | void GLES2DecoderImpl::EndDecoding() { |
| 3506 | gpu_tracer_->EndDecoding(); |
| 3507 | } |
| 3508 | |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 3509 | ErrorState* GLES2DecoderImpl::GetErrorState() { |
| 3510 | return state_.GetErrorState(); |
| 3511 | } |
| 3512 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 3513 | void GLES2DecoderImpl::SetShaderCacheCallback( |
| 3514 | const ShaderCacheCallback& callback) { |
| 3515 | shader_cache_callback_ = callback; |
| 3516 | } |
| 3517 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 3518 | void GLES2DecoderImpl::SetWaitSyncPointCallback( |
| 3519 | const WaitSyncPointCallback& callback) { |
| 3520 | wait_sync_point_callback_ = callback; |
| 3521 | } |
| 3522 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3523 | AsyncPixelTransferManager* |
| 3524 | GLES2DecoderImpl::GetAsyncPixelTransferManager() { |
| 3525 | return async_pixel_transfer_manager_.get(); |
| 3526 | } |
| 3527 | |
| 3528 | void GLES2DecoderImpl::ResetAsyncPixelTransferManagerForTest() { |
| 3529 | async_pixel_transfer_manager_.reset(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 3530 | } |
| 3531 | |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 3532 | void GLES2DecoderImpl::SetAsyncPixelTransferManagerForTest( |
| 3533 | AsyncPixelTransferManager* manager) { |
| 3534 | async_pixel_transfer_manager_ = make_scoped_ptr(manager); |
| 3535 | } |
| 3536 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3537 | bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, |
| 3538 | uint32* service_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3539 | TextureRef* texture_ref = texture_manager()->GetTexture(client_texture_id); |
| 3540 | if (texture_ref) { |
| 3541 | *service_texture_id = texture_ref->service_id(); |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3542 | return true; |
| 3543 | } |
| 3544 | return false; |
| 3545 | } |
| 3546 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3547 | uint32 GLES2DecoderImpl::GetTextureUploadCount() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3548 | return texture_state_.texture_upload_count + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3549 | async_pixel_transfer_manager_->GetTextureUploadCount(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | base::TimeDelta GLES2DecoderImpl::GetTotalTextureUploadTime() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3553 | return texture_state_.total_texture_upload_time + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3554 | async_pixel_transfer_manager_->GetTotalTextureUploadTime(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3555 | } |
| 3556 | |
| 3557 | base::TimeDelta GLES2DecoderImpl::GetTotalProcessingCommandsTime() { |
| 3558 | return total_processing_commands_time_; |
| 3559 | } |
| 3560 | |
[email protected] | dc25dda | 2012-09-27 21:36:30 | [diff] [blame] | 3561 | void GLES2DecoderImpl::AddProcessingCommandsTime(base::TimeDelta time) { |
| 3562 | total_processing_commands_time_ += time; |
| 3563 | } |
| 3564 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3565 | void GLES2DecoderImpl::Destroy(bool have_context) { |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 3566 | if (!initialized()) |
| 3567 | return; |
| 3568 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3569 | DCHECK(!have_context || context_->IsCurrent(NULL)); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3570 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3571 | // Unbind everything. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3572 | state_.vertex_attrib_manager = NULL; |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 3573 | state_.default_vertex_attrib_manager = NULL; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3574 | state_.texture_units.clear(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3575 | state_.bound_array_buffer = NULL; |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 3576 | state_.current_queries.clear(); |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3577 | framebuffer_state_.bound_read_framebuffer = NULL; |
| 3578 | framebuffer_state_.bound_draw_framebuffer = NULL; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3579 | state_.bound_renderbuffer = NULL; |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 3580 | state_.bound_valuebuffer = NULL; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3581 | |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 3582 | if (offscreen_saved_color_texture_info_.get()) { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3583 | DCHECK(offscreen_target_color_texture_); |
| 3584 | DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), |
| 3585 | offscreen_saved_color_texture_->id()); |
| 3586 | offscreen_saved_color_texture_->Invalidate(); |
| 3587 | offscreen_saved_color_texture_info_ = NULL; |
| 3588 | } |
[email protected] | eadc9679 | 2010-10-27 19:39:39 | [diff] [blame] | 3589 | if (have_context) { |
[email protected] | c322e88 | 2012-05-23 18:06:18 | [diff] [blame] | 3590 | if (copy_texture_CHROMIUM_.get()) { |
| 3591 | copy_texture_CHROMIUM_->Destroy(); |
| 3592 | copy_texture_CHROMIUM_.reset(); |
| 3593 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3594 | |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 3595 | clear_framebuffer_blit_.reset(); |
| 3596 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3597 | if (state_.current_program.get()) { |
| 3598 | program_manager()->UnuseProgram(shader_manager(), |
| 3599 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 3600 | } |
| 3601 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3602 | if (attrib_0_buffer_id_) { |
| 3603 | glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
| 3604 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 3605 | if (fixed_attrib_buffer_id_) { |
| 3606 | glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); |
| 3607 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3608 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 3609 | if (validation_texture_) { |
| 3610 | glDeleteTextures(1, &validation_texture_); |
| 3611 | glDeleteFramebuffersEXT(1, &validation_fbo_multisample_); |
| 3612 | glDeleteFramebuffersEXT(1, &validation_fbo_); |
| 3613 | } |
| 3614 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3615 | if (offscreen_target_frame_buffer_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3616 | offscreen_target_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3617 | if (offscreen_target_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3618 | offscreen_target_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3619 | if (offscreen_target_color_render_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3620 | offscreen_target_color_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3621 | if (offscreen_target_depth_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3622 | offscreen_target_depth_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3623 | if (offscreen_target_stencil_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3624 | offscreen_target_stencil_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3625 | if (offscreen_saved_frame_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3626 | offscreen_saved_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3627 | if (offscreen_saved_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3628 | offscreen_saved_color_texture_->Destroy(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3629 | if (offscreen_resolved_frame_buffer_.get()) |
| 3630 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3631 | if (offscreen_resolved_color_texture_.get()) |
| 3632 | offscreen_resolved_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3633 | } else { |
| 3634 | if (offscreen_target_frame_buffer_.get()) |
| 3635 | offscreen_target_frame_buffer_->Invalidate(); |
| 3636 | if (offscreen_target_color_texture_.get()) |
| 3637 | offscreen_target_color_texture_->Invalidate(); |
| 3638 | if (offscreen_target_color_render_buffer_.get()) |
| 3639 | offscreen_target_color_render_buffer_->Invalidate(); |
| 3640 | if (offscreen_target_depth_render_buffer_.get()) |
| 3641 | offscreen_target_depth_render_buffer_->Invalidate(); |
| 3642 | if (offscreen_target_stencil_render_buffer_.get()) |
| 3643 | offscreen_target_stencil_render_buffer_->Invalidate(); |
| 3644 | if (offscreen_saved_frame_buffer_.get()) |
| 3645 | offscreen_saved_frame_buffer_->Invalidate(); |
| 3646 | if (offscreen_saved_color_texture_.get()) |
| 3647 | offscreen_saved_color_texture_->Invalidate(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3648 | if (offscreen_resolved_frame_buffer_.get()) |
| 3649 | offscreen_resolved_frame_buffer_->Invalidate(); |
| 3650 | if (offscreen_resolved_color_texture_.get()) |
| 3651 | offscreen_resolved_color_texture_->Invalidate(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 3652 | } |
[email protected] | 83a52d03 | 2013-07-24 10:30:37 | [diff] [blame] | 3653 | |
| 3654 | // Current program must be cleared after calling ProgramManager::UnuseProgram. |
| 3655 | // Otherwise, we can leak objects. http://crbug.com/258772. |
| 3656 | // state_.current_program must be reset before group_ is reset because |
| 3657 | // the later deletes the ProgramManager object that referred by |
| 3658 | // state_.current_program object. |
| 3659 | state_.current_program = NULL; |
| 3660 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3661 | copy_texture_CHROMIUM_.reset(); |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 3662 | clear_framebuffer_blit_.reset(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3663 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3664 | if (query_manager_.get()) { |
| 3665 | query_manager_->Destroy(have_context); |
| 3666 | query_manager_.reset(); |
| 3667 | } |
| 3668 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 3669 | if (vertex_array_manager_ .get()) { |
| 3670 | vertex_array_manager_->Destroy(have_context); |
| 3671 | vertex_array_manager_.reset(); |
| 3672 | } |
| 3673 | |
[email protected] | d2eaf52f | 2014-07-31 15:01:24 | [diff] [blame] | 3674 | if (image_manager_.get()) { |
| 3675 | image_manager_->Destroy(have_context); |
| 3676 | image_manager_.reset(); |
| 3677 | } |
| 3678 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3679 | offscreen_target_frame_buffer_.reset(); |
| 3680 | offscreen_target_color_texture_.reset(); |
| 3681 | offscreen_target_color_render_buffer_.reset(); |
| 3682 | offscreen_target_depth_render_buffer_.reset(); |
| 3683 | offscreen_target_stencil_render_buffer_.reset(); |
| 3684 | offscreen_saved_frame_buffer_.reset(); |
| 3685 | offscreen_saved_color_texture_.reset(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3686 | offscreen_resolved_frame_buffer_.reset(); |
| 3687 | offscreen_resolved_color_texture_.reset(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3688 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 3689 | // Need to release these before releasing |group_| which may own the |
| 3690 | // ShaderTranslatorCache. |
| 3691 | fragment_translator_ = NULL; |
| 3692 | vertex_translator_ = NULL; |
| 3693 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3694 | // Should destroy the transfer manager before the texture manager held |
| 3695 | // by the context group. |
| 3696 | async_pixel_transfer_manager_.reset(); |
| 3697 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3698 | if (group_.get()) { |
[email protected] | ac5e402 | 2014-01-24 12:44:39 | [diff] [blame] | 3699 | framebuffer_manager()->RemoveObserver(this); |
[email protected] | 2d9d3b9 | 2013-01-18 01:07:23 | [diff] [blame] | 3700 | group_->Destroy(this, have_context); |
| 3701 | group_ = NULL; |
| 3702 | } |
| 3703 | |
| 3704 | if (context_.get()) { |
| 3705 | context_->ReleaseCurrent(NULL); |
| 3706 | context_ = NULL; |
| 3707 | } |
| 3708 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3709 | #if defined(OS_MACOSX) |
| 3710 | for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); |
| 3711 | it != texture_to_io_surface_map_.end(); ++it) { |
| 3712 | CFRelease(it->second); |
| 3713 | } |
| 3714 | texture_to_io_surface_map_.clear(); |
| 3715 | #endif |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3716 | } |
| 3717 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3718 | void GLES2DecoderImpl::SetSurface( |
| 3719 | const scoped_refptr<gfx::GLSurface>& surface) { |
| 3720 | DCHECK(context_->IsCurrent(NULL)); |
| 3721 | DCHECK(surface_.get()); |
| 3722 | surface_ = surface; |
| 3723 | RestoreCurrentFramebufferBindings(); |
| 3724 | } |
| 3725 | |
[email protected] | aba551b | 2014-02-08 03:38:32 | [diff] [blame] | 3726 | void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) { |
| 3727 | if (!offscreen_saved_color_texture_.get()) { |
| 3728 | LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context"; |
| 3729 | return; |
| 3730 | } |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3731 | if (!offscreen_saved_color_texture_info_.get()) { |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3732 | GLuint service_id = offscreen_saved_color_texture_->id(); |
[email protected] | f4647693 | 2013-06-08 05:36:07 | [diff] [blame] | 3733 | offscreen_saved_color_texture_info_ = TextureRef::Create( |
| 3734 | texture_manager(), 0, service_id); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3735 | texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), |
| 3736 | GL_TEXTURE_2D); |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 3737 | UpdateParentTextureInfo(); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3738 | } |
[email protected] | aba551b | 2014-02-08 03:38:32 | [diff] [blame] | 3739 | mailbox_manager()->ProduceTexture( |
sievers | 8b373ec5 | 2014-10-24 23:04:06 | [diff] [blame] | 3740 | mailbox, offscreen_saved_color_texture_info_->texture()); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 3741 | } |
| 3742 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3743 | bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 3744 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3745 | if (!is_offscreen) { |
| 3746 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " |
| 3747 | << " with an onscreen framebuffer."; |
| 3748 | return false; |
| 3749 | } |
| 3750 | |
| 3751 | if (offscreen_size_ == size) |
| 3752 | return true; |
| 3753 | |
| 3754 | offscreen_size_ = size; |
| 3755 | int w = offscreen_size_.width(); |
| 3756 | int h = offscreen_size_.height(); |
| 3757 | if (w < 0 || h < 0 || h >= (INT_MAX / 4) / (w ? w : 1)) { |
| 3758 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3759 | << "to allocate storage due to excessive dimensions."; |
| 3760 | return false; |
| 3761 | } |
| 3762 | |
| 3763 | // Reallocate the offscreen target buffers. |
| 3764 | DCHECK(offscreen_target_color_format_); |
| 3765 | if (IsOffscreenBufferMultisampled()) { |
| 3766 | if (!offscreen_target_color_render_buffer_->AllocateStorage( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 3767 | feature_info_.get(), |
| 3768 | offscreen_size_, |
| 3769 | offscreen_target_color_format_, |
| 3770 | offscreen_target_samples_)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3771 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3772 | << "to allocate storage for offscreen target color buffer."; |
| 3773 | return false; |
| 3774 | } |
| 3775 | } else { |
| 3776 | if (!offscreen_target_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 3777 | offscreen_size_, offscreen_target_color_format_, false)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3778 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3779 | << "to allocate storage for offscreen target color texture."; |
| 3780 | return false; |
| 3781 | } |
| 3782 | } |
| 3783 | if (offscreen_target_depth_format_ && |
| 3784 | !offscreen_target_depth_render_buffer_->AllocateStorage( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 3785 | feature_info_.get(), |
| 3786 | offscreen_size_, |
| 3787 | offscreen_target_depth_format_, |
| 3788 | offscreen_target_samples_)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3789 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3790 | << "to allocate storage for offscreen target depth buffer."; |
| 3791 | return false; |
| 3792 | } |
| 3793 | if (offscreen_target_stencil_format_ && |
| 3794 | !offscreen_target_stencil_render_buffer_->AllocateStorage( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 3795 | feature_info_.get(), |
| 3796 | offscreen_size_, |
| 3797 | offscreen_target_stencil_format_, |
| 3798 | offscreen_target_samples_)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3799 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3800 | << "to allocate storage for offscreen target stencil buffer."; |
| 3801 | return false; |
| 3802 | } |
| 3803 | |
| 3804 | // Attach the offscreen target buffers to the target frame buffer. |
| 3805 | if (IsOffscreenBufferMultisampled()) { |
| 3806 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3807 | GL_COLOR_ATTACHMENT0, |
| 3808 | offscreen_target_color_render_buffer_.get()); |
| 3809 | } else { |
| 3810 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 3811 | offscreen_target_color_texture_.get()); |
| 3812 | } |
| 3813 | if (offscreen_target_depth_format_) { |
| 3814 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3815 | GL_DEPTH_ATTACHMENT, |
| 3816 | offscreen_target_depth_render_buffer_.get()); |
| 3817 | } |
| 3818 | const bool packed_depth_stencil = |
| 3819 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 3820 | if (packed_depth_stencil) { |
| 3821 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3822 | GL_STENCIL_ATTACHMENT, |
| 3823 | offscreen_target_depth_render_buffer_.get()); |
| 3824 | } else if (offscreen_target_stencil_format_) { |
| 3825 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 3826 | GL_STENCIL_ATTACHMENT, |
| 3827 | offscreen_target_stencil_render_buffer_.get()); |
| 3828 | } |
| 3829 | |
| 3830 | if (offscreen_target_frame_buffer_->CheckStatus() != |
| 3831 | GL_FRAMEBUFFER_COMPLETE) { |
| 3832 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 3833 | << "because offscreen FBO was incomplete."; |
| 3834 | return false; |
| 3835 | } |
| 3836 | |
| 3837 | // Clear the target frame buffer. |
| 3838 | { |
| 3839 | ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); |
| 3840 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
pkasting | 45796dc | 2014-10-17 04:18:32 | [diff] [blame] | 3841 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1.f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3842 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3843 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 3844 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 3845 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3846 | glClearDepth(0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3847 | state_.SetDeviceDepthMask(GL_TRUE); |
| 3848 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3849 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 3850 | RestoreClearState(); |
| 3851 | } |
[email protected] | d85ef76d | 2011-09-08 22:21:43 | [diff] [blame] | 3852 | |
| 3853 | // Destroy the offscreen resolved framebuffers. |
| 3854 | if (offscreen_resolved_frame_buffer_.get()) |
| 3855 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3856 | if (offscreen_resolved_color_texture_.get()) |
| 3857 | offscreen_resolved_color_texture_->Destroy(); |
| 3858 | offscreen_resolved_color_texture_.reset(); |
| 3859 | offscreen_resolved_frame_buffer_.reset(); |
| 3860 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3861 | return true; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3862 | } |
| 3863 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 3864 | error::Error GLES2DecoderImpl::HandleResizeCHROMIUM(uint32 immediate_data_size, |
| 3865 | const void* cmd_data) { |
| 3866 | const gles2::cmds::ResizeCHROMIUM& c = |
| 3867 | *static_cast<const gles2::cmds::ResizeCHROMIUM*>(cmd_data); |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 3868 | if (!offscreen_target_frame_buffer_.get() && surface_->DeferDraws()) |
[email protected] | 45212087 | 2012-09-27 15:21:02 | [diff] [blame] | 3869 | return error::kDeferCommandUntilLater; |
| 3870 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3871 | GLuint width = static_cast<GLuint>(c.width); |
| 3872 | GLuint height = static_cast<GLuint>(c.height); |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3873 | GLfloat scale_factor = c.scale_factor; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3874 | TRACE_EVENT2("gpu", "glResizeChromium", "width", width, "height", height); |
[email protected] | d16aa4b | 2013-02-14 22:35:41 | [diff] [blame] | 3875 | |
| 3876 | width = std::max(1U, width); |
| 3877 | height = std::max(1U, height); |
| 3878 | |
[email protected] | a0d98916 | 2011-11-22 13:15:07 | [diff] [blame] | 3879 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && \ |
| 3880 | !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3881 | // Make sure that we are done drawing to the back buffer before resizing. |
| 3882 | glFinish(); |
| 3883 | #endif |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3884 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 3885 | if (is_offscreen) { |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3886 | if (!ResizeOffscreenFrameBuffer(gfx::Size(width, height))) { |
| 3887 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because " |
| 3888 | << "ResizeOffscreenFrameBuffer failed."; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3889 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3890 | } |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3891 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3892 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3893 | if (!resize_callback_.is_null()) { |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3894 | resize_callback_.Run(gfx::Size(width, height), scale_factor); |
[email protected] | 0e9346b | 2013-03-16 16:35:44 | [diff] [blame] | 3895 | DCHECK(context_->IsCurrent(surface_.get())); |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3896 | if (!context_->IsCurrent(surface_.get())) { |
| 3897 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because context no longer " |
| 3898 | << "current after resize callback."; |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3899 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 3900 | } |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 3901 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3902 | |
| 3903 | return error::kNoError; |
[email protected] | 43ecf37 | 2010-11-16 19:19:39 | [diff] [blame] | 3904 | } |
| 3905 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3906 | const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { |
| 3907 | if (command_id > kStartPoint && command_id < kNumCommands) { |
| 3908 | return gles2::GetCommandName(static_cast<CommandId>(command_id)); |
| 3909 | } |
| 3910 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 3911 | } |
| 3912 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3913 | // Decode a command, and call the corresponding GL functions. |
| 3914 | // NOTE: DoCommand() is slower than calling DoCommands() on larger batches |
| 3915 | // of commands at once, and is now only used for tests that need to track |
| 3916 | // individual commands. |
| 3917 | error::Error GLES2DecoderImpl::DoCommand(unsigned int command, |
| 3918 | unsigned int arg_count, |
| 3919 | const void* cmd_data) { |
| 3920 | return DoCommands(1, cmd_data, arg_count + 1, 0); |
| 3921 | } |
| 3922 | |
| 3923 | // Decode multiple commands, and call the corresponding GL functions. |
| 3924 | // NOTE: 'buffer' is a pointer to the command buffer. As such, it could be |
| 3925 | // changed by a (malicious) client at any time, so if validation has to happen, |
| 3926 | // it should operate on a copy of them. |
| 3927 | // NOTE: This is duplicating code from AsyncAPIInterface::DoCommands() in the |
| 3928 | // interest of performance in this critical execution loop. |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3929 | template <bool DebugImpl> |
| 3930 | error::Error GLES2DecoderImpl::DoCommandsImpl(unsigned int num_commands, |
| 3931 | const void* buffer, |
| 3932 | int num_entries, |
| 3933 | int* entries_processed) { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3934 | commands_to_process_ = num_commands; |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 3935 | error::Error result = error::kNoError; |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3936 | const CommandBufferEntry* cmd_data = |
| 3937 | static_cast<const CommandBufferEntry*>(buffer); |
| 3938 | int process_pos = 0; |
| 3939 | unsigned int command = 0; |
| 3940 | |
| 3941 | while (process_pos < num_entries && result == error::kNoError && |
| 3942 | commands_to_process_--) { |
| 3943 | const unsigned int size = cmd_data->value_header.size; |
| 3944 | command = cmd_data->value_header.command; |
| 3945 | |
| 3946 | if (size == 0) { |
| 3947 | result = error::kInvalidSize; |
| 3948 | break; |
| 3949 | } |
| 3950 | |
| 3951 | if (static_cast<int>(size) + process_pos > num_entries) { |
| 3952 | result = error::kOutOfBounds; |
| 3953 | break; |
| 3954 | } |
| 3955 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3956 | if (DebugImpl) { |
| 3957 | TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cb_command"), |
| 3958 | GetCommandName(command)); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3959 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3960 | if (log_commands()) { |
| 3961 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "]" |
| 3962 | << "cmd: " << GetCommandName(command); |
| 3963 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | const unsigned int arg_count = size - 1; |
| 3967 | unsigned int command_index = command - kStartPoint - 1; |
| 3968 | if (command_index < arraysize(command_info)) { |
| 3969 | const CommandInfo& info = command_info[command_index]; |
| 3970 | unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
| 3971 | if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
| 3972 | (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
| 3973 | bool doing_gpu_trace = false; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3974 | if (DebugImpl && gpu_trace_commands_) { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3975 | if (CMD_FLAG_GET_TRACE_LEVEL(info.cmd_flags) <= gpu_trace_level_) { |
| 3976 | doing_gpu_trace = true; |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 3977 | gpu_tracer_->Begin(TRACE_DISABLED_BY_DEFAULT("gpu_decoder"), |
| 3978 | GetCommandName(command), |
| 3979 | kTraceDecoder); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3980 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3981 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3982 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3983 | uint32 immediate_data_size = (arg_count - info_arg_count) * |
| 3984 | sizeof(CommandBufferEntry); // NOLINT |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3985 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3986 | result = (this->*info.cmd_handler)(immediate_data_size, cmd_data); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3987 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3988 | if (DebugImpl && doing_gpu_trace) |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3989 | gpu_tracer_->End(kTraceDecoder); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3990 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3991 | if (DebugImpl && debug()) { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 3992 | GLenum error; |
| 3993 | while ((error = glGetError()) != GL_NO_ERROR) { |
| 3994 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "] " |
| 3995 | << "GL ERROR: " << GLES2Util::GetStringEnum(error) |
| 3996 | << " : " << GetCommandName(command); |
| 3997 | LOCAL_SET_GL_ERROR(error, "DoCommand", "GL error from driver"); |
| 3998 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 3999 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4000 | } else { |
| 4001 | result = error::kInvalidArguments; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4002 | } |
| 4003 | } else { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4004 | result = DoCommonCommand(command, arg_count, cmd_data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4005 | } |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4006 | |
| 4007 | if (DebugImpl) { |
| 4008 | TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("cb_command"), |
| 4009 | GetCommandName(command)); |
| 4010 | } |
| 4011 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4012 | if (result == error::kNoError && |
| 4013 | current_decoder_error_ != error::kNoError) { |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 4014 | result = current_decoder_error_; |
| 4015 | current_decoder_error_ = error::kNoError; |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4016 | } |
| 4017 | |
| 4018 | if (result != error::kDeferCommandUntilLater) { |
| 4019 | process_pos += size; |
| 4020 | cmd_data += size; |
| 4021 | } |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 4022 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4023 | |
| 4024 | if (entries_processed) |
| 4025 | *entries_processed = process_pos; |
| 4026 | |
| 4027 | if (error::IsError(result)) { |
| 4028 | LOG(ERROR) << "Error: " << result << " for Command " |
| 4029 | << GetCommandName(command); |
| 4030 | } |
| 4031 | |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 4032 | return result; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4033 | } |
| 4034 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4035 | error::Error GLES2DecoderImpl::DoCommands(unsigned int num_commands, |
| 4036 | const void* buffer, |
| 4037 | int num_entries, |
| 4038 | int* entries_processed) { |
| 4039 | if (gpu_debug_commands_) { |
| 4040 | return DoCommandsImpl<true>( |
| 4041 | num_commands, buffer, num_entries, entries_processed); |
| 4042 | } else { |
| 4043 | return DoCommandsImpl<false>( |
| 4044 | num_commands, buffer, num_entries, entries_processed); |
| 4045 | } |
| 4046 | } |
| 4047 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4048 | void GLES2DecoderImpl::RemoveBuffer(GLuint client_id) { |
| 4049 | buffer_manager()->RemoveBuffer(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4050 | } |
| 4051 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4052 | bool GLES2DecoderImpl::CreateProgramHelper(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4053 | if (GetProgram(client_id)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4054 | return false; |
| 4055 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4056 | GLuint service_id = glCreateProgram(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4057 | if (service_id != 0) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4058 | CreateProgram(client_id, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4059 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4060 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4061 | } |
| 4062 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4063 | bool GLES2DecoderImpl::CreateShaderHelper(GLenum type, GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4064 | if (GetShader(client_id)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4065 | return false; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4066 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4067 | GLuint service_id = glCreateShader(type); |
| 4068 | if (service_id != 0) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4069 | CreateShader(client_id, service_id, type); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4070 | } |
| 4071 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4072 | } |
| 4073 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 4074 | void GLES2DecoderImpl::DoFinish() { |
| 4075 | glFinish(); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 4076 | ProcessPendingReadPixels(); |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 4077 | ProcessPendingQueries(true); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | void GLES2DecoderImpl::DoFlush() { |
| 4081 | glFlush(); |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 4082 | ProcessPendingQueries(false); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 4083 | } |
| 4084 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4085 | void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4086 | GLuint texture_index = texture_unit - GL_TEXTURE0; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4087 | if (texture_index >= state_.texture_units.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4088 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 4089 | "glActiveTexture", texture_unit, "texture_unit"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4090 | return; |
| 4091 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4092 | state_.active_texture_unit = texture_index; |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4093 | glActiveTexture(texture_unit); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4094 | } |
| 4095 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4096 | void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4097 | Buffer* buffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4098 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4099 | if (client_id != 0) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4100 | buffer = GetBuffer(client_id); |
| 4101 | if (!buffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4102 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4103 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4104 | "glBindBuffer", |
| 4105 | "id not generated by glGenBuffers"); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4106 | return; |
| 4107 | } |
| 4108 | |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4109 | // It's a new id so make a buffer buffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4110 | glGenBuffersARB(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4111 | CreateBuffer(client_id, service_id); |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4112 | buffer = GetBuffer(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4113 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4114 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4115 | LogClientServiceForInfo(buffer, client_id, "glBindBuffer"); |
| 4116 | if (buffer) { |
| 4117 | if (!buffer_manager()->SetTarget(buffer, target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4118 | LOCAL_SET_GL_ERROR( |
| 4119 | GL_INVALID_OPERATION, |
| 4120 | "glBindBuffer", "buffer bound to more than 1 target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4121 | return; |
| 4122 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4123 | service_id = buffer->service_id(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4124 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4125 | switch (target) { |
| 4126 | case GL_ARRAY_BUFFER: |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4127 | state_.bound_array_buffer = buffer; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4128 | break; |
| 4129 | case GL_ELEMENT_ARRAY_BUFFER: |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4130 | state_.vertex_attrib_manager->SetElementArrayBuffer(buffer); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4131 | break; |
| 4132 | default: |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4133 | NOTREACHED(); // Validation should prevent us getting here. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4134 | break; |
| 4135 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4136 | glBindBuffer(target, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4137 | } |
| 4138 | |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 4139 | bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha( |
| 4140 | bool all_draw_buffers) { |
| 4141 | Framebuffer* framebuffer = |
| 4142 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 4143 | if (!all_draw_buffers || !framebuffer) { |
| 4144 | return (GLES2Util::GetChannelsForFormat( |
| 4145 | GetBoundDrawFrameBufferInternalFormat()) & 0x0008) != 0; |
| 4146 | } |
| 4147 | return framebuffer->HasAlphaMRT(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4148 | } |
| 4149 | |
| 4150 | bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4151 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4152 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4153 | if (framebuffer) { |
| 4154 | return framebuffer->HasDepthAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4155 | } |
| 4156 | if (offscreen_target_frame_buffer_.get()) { |
| 4157 | return offscreen_target_depth_format_ != 0; |
| 4158 | } |
| 4159 | return back_buffer_has_depth_; |
| 4160 | } |
| 4161 | |
| 4162 | bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4163 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4164 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4165 | if (framebuffer) { |
| 4166 | return framebuffer->HasStencilAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4167 | } |
| 4168 | if (offscreen_target_frame_buffer_.get()) { |
| 4169 | return offscreen_target_stencil_format_ != 0 || |
| 4170 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 4171 | } |
| 4172 | return back_buffer_has_stencil_; |
| 4173 | } |
| 4174 | |
| 4175 | void GLES2DecoderImpl::ApplyDirtyState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4176 | if (framebuffer_state_.clear_state_dirty) { |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4177 | bool have_alpha = BoundFramebufferHasColorAttachmentWithAlpha(true); |
| 4178 | state_.SetDeviceColorMask(state_.color_mask_red, |
| 4179 | state_.color_mask_green, |
| 4180 | state_.color_mask_blue, |
| 4181 | state_.color_mask_alpha && have_alpha); |
| 4182 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4183 | bool have_depth = BoundFramebufferHasDepthAttachment(); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4184 | state_.SetDeviceDepthMask(state_.depth_mask && have_depth); |
| 4185 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4186 | bool have_stencil = BoundFramebufferHasStencilAttachment(); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4187 | state_.SetDeviceStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4188 | GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4189 | state_.SetDeviceStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4190 | GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4191 | |
| 4192 | state_.SetDeviceCapabilityState( |
| 4193 | GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth); |
| 4194 | state_.SetDeviceCapabilityState( |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 4195 | GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4196 | framebuffer_state_.clear_state_dirty = false; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4197 | } |
| 4198 | } |
| 4199 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4200 | GLuint GLES2DecoderImpl::GetBackbufferServiceId() const { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4201 | return (offscreen_target_frame_buffer_.get()) |
| 4202 | ? offscreen_target_frame_buffer_->id() |
| 4203 | : (surface_.get() ? surface_->GetBackingFrameBufferObject() : 0); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4204 | } |
| 4205 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4206 | void GLES2DecoderImpl::RestoreState(const ContextState* prev_state) { |
[email protected] | 962bfbe7 | 2013-05-24 11:16:14 | [diff] [blame] | 4207 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::RestoreState", |
| 4208 | "context", logger_.GetLogPrefix()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4209 | // Restore the Framebuffer first because of bugs in Intel drivers. |
| 4210 | // Intel drivers incorrectly clip the viewport settings to |
| 4211 | // the size of the current framebuffer object. |
| 4212 | RestoreFramebufferBindings(); |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 4213 | state_.RestoreState(prev_state); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | void GLES2DecoderImpl::RestoreFramebufferBindings() const { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4217 | GLuint service_id = |
| 4218 | framebuffer_state_.bound_draw_framebuffer.get() |
| 4219 | ? framebuffer_state_.bound_draw_framebuffer->service_id() |
| 4220 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4221 | if (!features().chromium_framebuffer_multisample) { |
| 4222 | glBindFramebufferEXT(GL_FRAMEBUFFER, service_id); |
| 4223 | } else { |
| 4224 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, service_id); |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4225 | service_id = framebuffer_state_.bound_read_framebuffer.get() |
| 4226 | ? framebuffer_state_.bound_read_framebuffer->service_id() |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4227 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4228 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, service_id); |
| 4229 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4230 | OnFboChanged(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4231 | } |
| 4232 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4233 | void GLES2DecoderImpl::RestoreRenderbufferBindings() { |
| 4234 | state_.RestoreRenderbufferBindings(); |
| 4235 | } |
| 4236 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4237 | void GLES2DecoderImpl::RestoreTextureState(unsigned service_id) const { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4238 | Texture* texture = texture_manager()->GetTextureForServiceId(service_id); |
| 4239 | if (texture) { |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4240 | GLenum target = texture->target(); |
| 4241 | glBindTexture(target, service_id); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4242 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4243 | target, GL_TEXTURE_WRAP_S, texture->wrap_s()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4244 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4245 | target, GL_TEXTURE_WRAP_T, texture->wrap_t()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4246 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4247 | target, GL_TEXTURE_MIN_FILTER, texture->min_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4248 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4249 | target, GL_TEXTURE_MAG_FILTER, texture->mag_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4250 | RestoreTextureUnitBindings(state_.active_texture_unit); |
| 4251 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4252 | } |
| 4253 | |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4254 | void GLES2DecoderImpl::ClearAllAttributes() const { |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 4255 | // Must use native VAO 0, as RestoreAllAttributes can't fully restore |
| 4256 | // other VAOs. |
| 4257 | if (feature_info_->feature_flags().native_vertex_array_object) |
| 4258 | glBindVertexArrayOES(0); |
| 4259 | |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4260 | for (uint32 i = 0; i < group_->max_vertex_attribs(); ++i) { |
| 4261 | if (i != 0) // Never disable attribute 0 |
| 4262 | glDisableVertexAttribArray(i); |
| 4263 | if(features().angle_instanced_arrays) |
| 4264 | glVertexAttribDivisorANGLE(i, 0); |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | void GLES2DecoderImpl::RestoreAllAttributes() const { |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 4269 | state_.RestoreVertexAttribs(); |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4270 | } |
| 4271 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4272 | void GLES2DecoderImpl::SetIgnoreCachedStateForTest(bool ignore) { |
| 4273 | state_.SetIgnoreCachedStateForTest(ignore); |
| 4274 | } |
| 4275 | |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4276 | void GLES2DecoderImpl::OnFboChanged() const { |
| 4277 | if (workarounds().restore_scissor_on_fbo_change) |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 4278 | state_.fbo_binding_for_scissor_workaround_dirty_ = true; |
ccameron | 4ff12a73 | 2014-12-12 21:38:19 | [diff] [blame] | 4279 | |
| 4280 | if (workarounds().gl_begin_gl_end_on_fbo_change_to_backbuffer) { |
| 4281 | GLint bound_fbo_unsigned = -1; |
| 4282 | glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &bound_fbo_unsigned); |
| 4283 | GLuint bound_fbo = static_cast<GLuint>(bound_fbo_unsigned); |
| 4284 | if (surface_ && surface_->GetBackingFrameBufferObject() == bound_fbo) |
| 4285 | surface_->NotifyWasBound(); |
| 4286 | } |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 4287 | } |
| 4288 | |
| 4289 | // Called after the FBO is checked for completeness. |
| 4290 | void GLES2DecoderImpl::OnUseFramebuffer() const { |
| 4291 | if (state_.fbo_binding_for_scissor_workaround_dirty_) { |
| 4292 | state_.fbo_binding_for_scissor_workaround_dirty_ = false; |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 4293 | // The driver forgets the correct scissor when modifying the FBO binding. |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 4294 | glScissor(state_.scissor_x, |
| 4295 | state_.scissor_y, |
| 4296 | state_.scissor_width, |
| 4297 | state_.scissor_height); |
| 4298 | |
| 4299 | // crbug.com/222018 - Also on QualComm, the flush here avoids flicker, |
| 4300 | // it's unclear how this bug works. |
| 4301 | glFlush(); |
| 4302 | } |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 4303 | } |
| 4304 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4305 | void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4306 | Framebuffer* framebuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4307 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4308 | if (client_id != 0) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4309 | framebuffer = GetFramebuffer(client_id); |
| 4310 | if (!framebuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4311 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4312 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4313 | "glBindFramebuffer", |
| 4314 | "id not generated by glGenFramebuffers"); |
| 4315 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4316 | } |
| 4317 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4318 | // It's a new id so make a framebuffer framebuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4319 | glGenFramebuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4320 | CreateFramebuffer(client_id, service_id); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4321 | framebuffer = GetFramebuffer(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4322 | } else { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4323 | service_id = framebuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4324 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4325 | framebuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4326 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4327 | LogClientServiceForInfo(framebuffer, client_id, "glBindFramebuffer"); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4328 | |
| 4329 | if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4330 | framebuffer_state_.bound_draw_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4331 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 4332 | |
| 4333 | // vmiura: This looks like dup code |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4334 | if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4335 | framebuffer_state_.bound_read_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4336 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 4337 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4338 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4339 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 4340 | // If we are rendering to the backbuffer get the FBO id for any simulated |
| 4341 | // backbuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4342 | if (framebuffer == NULL) { |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 4343 | service_id = GetBackbufferServiceId(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4344 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 4345 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4346 | glBindFramebufferEXT(target, service_id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4347 | OnFboChanged(); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 4348 | } |
| 4349 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4350 | void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4351 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4352 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4353 | if (client_id != 0) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4354 | renderbuffer = GetRenderbuffer(client_id); |
| 4355 | if (!renderbuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4356 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4357 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4358 | "glBindRenderbuffer", |
| 4359 | "id not generated by glGenRenderbuffers"); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4360 | return; |
| 4361 | } |
| 4362 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4363 | // It's a new id so make a renderbuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4364 | glGenRenderbuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4365 | CreateRenderbuffer(client_id, service_id); |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4366 | renderbuffer = GetRenderbuffer(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4367 | } else { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4368 | service_id = renderbuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4369 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4370 | renderbuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4371 | } |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 4372 | LogClientServiceForInfo(renderbuffer, client_id, "glBindRenderbuffer"); |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4373 | state_.bound_renderbuffer = renderbuffer; |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4374 | state_.bound_renderbuffer_valid = true; |
| 4375 | glBindRenderbufferEXT(GL_RENDERBUFFER, service_id); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 4376 | } |
| 4377 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4378 | void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4379 | TextureRef* texture_ref = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4380 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4381 | if (client_id != 0) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4382 | texture_ref = GetTexture(client_id); |
| 4383 | if (!texture_ref) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4384 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4385 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4386 | "glBindTexture", |
| 4387 | "id not generated by glGenTextures"); |
| 4388 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4389 | } |
| 4390 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 4391 | // It's a new id so make a texture texture for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4392 | glGenTextures(1, &service_id); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4393 | DCHECK_NE(0u, service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4394 | CreateTexture(client_id, service_id); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4395 | texture_ref = GetTexture(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4396 | } |
| 4397 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4398 | texture_ref = texture_manager()->GetDefaultTextureInfo(target); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4399 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4400 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 4401 | // Check the texture exists |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 4402 | if (texture_ref) { |
| 4403 | Texture* texture = texture_ref->texture(); |
| 4404 | // Check that we are not trying to bind it to a different target. |
| 4405 | if (texture->target() != 0 && texture->target() != target) { |
| 4406 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4407 | "glBindTexture", |
| 4408 | "texture bound to more than 1 target."); |
| 4409 | return; |
| 4410 | } |
| 4411 | LogClientServiceForInfo(texture, client_id, "glBindTexture"); |
| 4412 | if (texture->target() == 0) { |
| 4413 | texture_manager()->SetTarget(texture_ref, target); |
| 4414 | } |
| 4415 | glBindTexture(target, texture->service_id()); |
| 4416 | } else { |
| 4417 | glBindTexture(target, 0); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 4418 | } |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 4419 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4420 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4421 | unit.bind_target = target; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4422 | switch (target) { |
| 4423 | case GL_TEXTURE_2D: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4424 | unit.bound_texture_2d = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4425 | break; |
| 4426 | case GL_TEXTURE_CUBE_MAP: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4427 | unit.bound_texture_cube_map = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4428 | break; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4429 | case GL_TEXTURE_EXTERNAL_OES: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4430 | unit.bound_texture_external_oes = texture_ref; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4431 | break; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4432 | case GL_TEXTURE_RECTANGLE_ARB: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4433 | unit.bound_texture_rectangle_arb = texture_ref; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4434 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4435 | default: |
| 4436 | NOTREACHED(); // Validation should prevent us getting here. |
| 4437 | break; |
| 4438 | } |
| 4439 | } |
| 4440 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4441 | void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4442 | if (state_.vertex_attrib_manager->Enable(index, false)) { |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 4443 | if (index != 0 || |
| 4444 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4445 | glDisableVertexAttribArray(index); |
| 4446 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4447 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4448 | LOCAL_SET_GL_ERROR( |
| 4449 | GL_INVALID_VALUE, |
| 4450 | "glDisableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4451 | } |
| 4452 | } |
| 4453 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4454 | void GLES2DecoderImpl::DoDiscardFramebufferEXT(GLenum target, |
| 4455 | GLsizei numAttachments, |
| 4456 | const GLenum* attachments) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4457 | Framebuffer* framebuffer = |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4458 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 4459 | |
| 4460 | // Validates the attachments. If one of them fails |
| 4461 | // the whole command fails. |
| 4462 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4463 | if ((framebuffer && |
| 4464 | !validators_->attachment.IsValid(attachments[i])) || |
| 4465 | (!framebuffer && |
| 4466 | !validators_->backbuffer_attachment.IsValid(attachments[i]))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4467 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 4468 | "glDiscardFramebufferEXT", attachments[i], "attachments"); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4469 | return; |
| 4470 | } |
| 4471 | } |
| 4472 | |
| 4473 | // Marks each one of them as not cleared |
| 4474 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4475 | if (framebuffer) { |
| 4476 | framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), |
| 4477 | texture_manager(), |
| 4478 | attachments[i], |
| 4479 | false); |
| 4480 | } else { |
| 4481 | switch (attachments[i]) { |
| 4482 | case GL_COLOR_EXT: |
| 4483 | backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| 4484 | break; |
| 4485 | case GL_DEPTH_EXT: |
| 4486 | backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
| 4487 | case GL_STENCIL_EXT: |
| 4488 | backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
| 4489 | break; |
| 4490 | default: |
| 4491 | NOTREACHED(); |
| 4492 | break; |
| 4493 | } |
| 4494 | } |
| 4495 | } |
| 4496 | |
[email protected] | d49c540 | 2013-09-11 15:39:02 | [diff] [blame] | 4497 | // If the default framebuffer is bound but we are still rendering to an |
| 4498 | // FBO, translate attachment names that refer to default framebuffer |
| 4499 | // channels to corresponding framebuffer attachments. |
| 4500 | scoped_ptr<GLenum[]> translated_attachments(new GLenum[numAttachments]); |
| 4501 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4502 | GLenum attachment = attachments[i]; |
| 4503 | if (!framebuffer && GetBackbufferServiceId()) { |
| 4504 | switch (attachment) { |
| 4505 | case GL_COLOR_EXT: |
| 4506 | attachment = GL_COLOR_ATTACHMENT0; |
| 4507 | break; |
| 4508 | case GL_DEPTH_EXT: |
| 4509 | attachment = GL_DEPTH_ATTACHMENT; |
| 4510 | break; |
| 4511 | case GL_STENCIL_EXT: |
| 4512 | attachment = GL_STENCIL_ATTACHMENT; |
| 4513 | break; |
| 4514 | default: |
| 4515 | NOTREACHED(); |
| 4516 | return; |
| 4517 | } |
| 4518 | } |
| 4519 | translated_attachments[i] = attachment; |
| 4520 | } |
| 4521 | |
boliu | 2e7d8a7a | 2014-10-16 20:35:20 | [diff] [blame] | 4522 | ScopedRenderTo do_render(framebuffer); |
zmo | 68fcdc6 | 2014-12-05 21:51:49 | [diff] [blame] | 4523 | if (feature_info_->gl_version_info().is_es3) { |
| 4524 | glInvalidateFramebuffer( |
| 4525 | target, numAttachments, translated_attachments.get()); |
| 4526 | } else { |
| 4527 | glDiscardFramebufferEXT( |
| 4528 | target, numAttachments, translated_attachments.get()); |
| 4529 | } |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4530 | } |
| 4531 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4532 | void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4533 | if (state_.vertex_attrib_manager->Enable(index, true)) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4534 | glEnableVertexAttribArray(index); |
| 4535 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4536 | LOCAL_SET_GL_ERROR( |
| 4537 | GL_INVALID_VALUE, "glEnableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4538 | } |
| 4539 | } |
| 4540 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4541 | void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4542 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 4543 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4544 | if (!texture_ref || |
| 4545 | !texture_manager()->CanGenerateMipmaps(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4546 | LOCAL_SET_GL_ERROR( |
| 4547 | GL_INVALID_OPERATION, "glGenerateMipmap", "Can not generate mips"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4548 | return; |
| 4549 | } |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4550 | |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4551 | if (target == GL_TEXTURE_CUBE_MAP) { |
| 4552 | for (int i = 0; i < 6; ++i) { |
| 4553 | GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4554 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, face, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4555 | LOCAL_SET_GL_ERROR( |
| 4556 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4557 | return; |
| 4558 | } |
| 4559 | } |
| 4560 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4561 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4562 | LOCAL_SET_GL_ERROR( |
| 4563 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4564 | return; |
| 4565 | } |
[email protected] | 7687479c | 2012-05-14 23:54:04 | [diff] [blame] | 4566 | } |
| 4567 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4568 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glGenerateMipmap"); |
[email protected] | 59f3ca0 | 2011-03-26 22:24:19 | [diff] [blame] | 4569 | // Workaround for Mac driver bug. In the large scheme of things setting |
| 4570 | // glTexParamter twice for glGenerateMipmap is probably not a lage performance |
[email protected] | a8bad26 | 2011-10-21 18:28:56 | [diff] [blame] | 4571 | // hit so there's probably no need to make this conditional. The bug appears |
| 4572 | // to be that if the filtering mode is set to something that doesn't require |
| 4573 | // mipmaps for rendering, or is never set to something other than the default, |
| 4574 | // then glGenerateMipmap misbehaves. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4575 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4576 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 4577 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4578 | glGenerateMipmapEXT(target); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4579 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4580 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, |
| 4581 | texture_ref->texture()->min_filter()); |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4582 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4583 | GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4584 | if (error == GL_NO_ERROR) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4585 | texture_manager()->MarkMipmapsGenerated(texture_ref); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4586 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4587 | } |
| 4588 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4589 | bool GLES2DecoderImpl::GetHelper( |
| 4590 | GLenum pname, GLint* params, GLsizei* num_written) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4591 | DCHECK(num_written); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 4592 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 4593 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4594 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 4595 | *num_written = 1; |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 4596 | // Return the GL implementation's preferred format and (see below type) |
| 4597 | // if we have the GL extension that exposes this. This allows the GPU |
| 4598 | // client to use the implementation's preferred format for glReadPixels |
| 4599 | // for optimisation. |
| 4600 | // |
| 4601 | // A conflicting extension (GL_ARB_ES2_compatibility) specifies an error |
| 4602 | // case when requested on integer/floating point buffers but which is |
| 4603 | // acceptable on GLES2 and with the GL_OES_read_format extension. |
| 4604 | // |
| 4605 | // Therefore if an error occurs we swallow the error and use the |
| 4606 | // internal implementation. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4607 | if (params) { |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 4608 | if (context_->HasExtension("GL_OES_read_format")) { |
| 4609 | ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::GetHelper", |
| 4610 | GetErrorState()); |
| 4611 | glGetIntegerv(pname, params); |
| 4612 | if (glGetError() == GL_NO_ERROR) |
| 4613 | return true; |
| 4614 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 4615 | *params = GLES2Util::GetPreferredGLReadPixelsFormat( |
| 4616 | GetBoundReadFrameBufferInternalFormat()); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4617 | } |
| 4618 | return true; |
| 4619 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 4620 | *num_written = 1; |
| 4621 | if (params) { |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 4622 | if (context_->HasExtension("GL_OES_read_format")) { |
| 4623 | ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::GetHelper", |
| 4624 | GetErrorState()); |
| 4625 | glGetIntegerv(pname, params); |
| 4626 | if (glGetError() == GL_NO_ERROR) |
| 4627 | return true; |
| 4628 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 4629 | *params = GLES2Util::GetPreferredGLReadPixelsType( |
| 4630 | GetBoundReadFrameBufferInternalFormat(), |
| 4631 | GetBoundReadFrameBufferTextureType()); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4632 | } |
| 4633 | return true; |
| 4634 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 4635 | *num_written = 1; |
| 4636 | if (params) { |
| 4637 | *params = group_->max_fragment_uniform_vectors(); |
| 4638 | } |
| 4639 | return true; |
| 4640 | case GL_MAX_VARYING_VECTORS: |
| 4641 | *num_written = 1; |
| 4642 | if (params) { |
| 4643 | *params = group_->max_varying_vectors(); |
| 4644 | } |
| 4645 | return true; |
| 4646 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 4647 | *num_written = 1; |
| 4648 | if (params) { |
| 4649 | *params = group_->max_vertex_uniform_vectors(); |
| 4650 | } |
| 4651 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4652 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4653 | } |
| 4654 | switch (pname) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 4655 | case GL_MAX_VIEWPORT_DIMS: |
| 4656 | if (offscreen_target_frame_buffer_.get()) { |
| 4657 | *num_written = 2; |
| 4658 | if (params) { |
| 4659 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4660 | params[1] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4661 | } |
| 4662 | return true; |
| 4663 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4664 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4665 | case GL_MAX_SAMPLES: |
| 4666 | *num_written = 1; |
| 4667 | if (params) { |
| 4668 | params[0] = renderbuffer_manager()->max_samples(); |
| 4669 | } |
| 4670 | return true; |
| 4671 | case GL_MAX_RENDERBUFFER_SIZE: |
| 4672 | *num_written = 1; |
| 4673 | if (params) { |
| 4674 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4675 | } |
| 4676 | return true; |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4677 | case GL_MAX_TEXTURE_SIZE: |
| 4678 | *num_written = 1; |
| 4679 | if (params) { |
| 4680 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_2D); |
| 4681 | } |
| 4682 | return true; |
| 4683 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 4684 | *num_written = 1; |
| 4685 | if (params) { |
| 4686 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP); |
| 4687 | } |
| 4688 | return true; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 4689 | case GL_MAX_COLOR_ATTACHMENTS_EXT: |
| 4690 | *num_written = 1; |
| 4691 | if (params) { |
| 4692 | params[0] = group_->max_color_attachments(); |
| 4693 | } |
| 4694 | return true; |
| 4695 | case GL_MAX_DRAW_BUFFERS_ARB: |
| 4696 | *num_written = 1; |
| 4697 | if (params) { |
| 4698 | params[0] = group_->max_draw_buffers(); |
| 4699 | } |
| 4700 | return true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4701 | case GL_ALPHA_BITS: |
| 4702 | *num_written = 1; |
| 4703 | if (params) { |
| 4704 | GLint v = 0; |
| 4705 | glGetIntegerv(GL_ALPHA_BITS, &v); |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 4706 | params[0] = BoundFramebufferHasColorAttachmentWithAlpha(false) ? v : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4707 | } |
| 4708 | return true; |
| 4709 | case GL_DEPTH_BITS: |
| 4710 | *num_written = 1; |
| 4711 | if (params) { |
| 4712 | GLint v = 0; |
| 4713 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 4714 | params[0] = BoundFramebufferHasDepthAttachment() ? v : 0; |
| 4715 | } |
| 4716 | return true; |
| 4717 | case GL_STENCIL_BITS: |
| 4718 | *num_written = 1; |
| 4719 | if (params) { |
| 4720 | GLint v = 0; |
| 4721 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 4722 | params[0] = BoundFramebufferHasStencilAttachment() ? v : 0; |
| 4723 | } |
| 4724 | return true; |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 4725 | case GL_COMPRESSED_TEXTURE_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4726 | *num_written = validators_->compressed_texture_format.GetValues().size(); |
| 4727 | if (params) { |
| 4728 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 4729 | params[ii] = validators_->compressed_texture_format.GetValues()[ii]; |
| 4730 | } |
| 4731 | } |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 4732 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4733 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 4734 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4735 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4736 | *params = validators_->compressed_texture_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4737 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4738 | return true; |
| 4739 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 4740 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4741 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4742 | *params = validators_->shader_binary_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4743 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4744 | return true; |
| 4745 | case GL_SHADER_BINARY_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 4746 | *num_written = validators_->shader_binary_format.GetValues().size(); |
| 4747 | if (params) { |
| 4748 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 4749 | params[ii] = validators_->shader_binary_format.GetValues()[ii]; |
| 4750 | } |
| 4751 | } |
| 4752 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4753 | case GL_SHADER_COMPILER: |
| 4754 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4755 | if (params) { |
| 4756 | *params = GL_TRUE; |
| 4757 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4758 | return true; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4759 | case GL_ARRAY_BUFFER_BINDING: |
| 4760 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4761 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4762 | if (state_.bound_array_buffer.get()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4763 | GLuint client_id = 0; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4764 | buffer_manager()->GetClientId(state_.bound_array_buffer->service_id(), |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4765 | &client_id); |
| 4766 | *params = client_id; |
| 4767 | } else { |
| 4768 | *params = 0; |
| 4769 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4770 | } |
| 4771 | return true; |
| 4772 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 4773 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4774 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4775 | if (state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4776 | GLuint client_id = 0; |
| 4777 | buffer_manager()->GetClientId( |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 4778 | state_.vertex_attrib_manager->element_array_buffer()-> |
| 4779 | service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4780 | *params = client_id; |
| 4781 | } else { |
| 4782 | *params = 0; |
| 4783 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4784 | } |
| 4785 | return true; |
| 4786 | case GL_FRAMEBUFFER_BINDING: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4787 | // case GL_DRAW_FRAMEBUFFER_BINDING_EXT: (same as GL_FRAMEBUFFER_BINDING) |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4788 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4789 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4790 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4791 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4792 | if (framebuffer) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4793 | GLuint client_id = 0; |
| 4794 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4795 | framebuffer->service_id(), &client_id); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4796 | *params = client_id; |
| 4797 | } else { |
| 4798 | *params = 0; |
| 4799 | } |
| 4800 | } |
| 4801 | return true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4802 | case GL_READ_FRAMEBUFFER_BINDING_EXT: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4803 | *num_written = 1; |
| 4804 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4805 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4806 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4807 | if (framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4808 | GLuint client_id = 0; |
| 4809 | framebuffer_manager()->GetClientId( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4810 | framebuffer->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4811 | *params = client_id; |
| 4812 | } else { |
| 4813 | *params = 0; |
| 4814 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4815 | } |
| 4816 | return true; |
| 4817 | case GL_RENDERBUFFER_BINDING: |
| 4818 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4819 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4820 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4821 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 4822 | if (renderbuffer) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4823 | *params = renderbuffer->client_id(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4824 | } else { |
| 4825 | *params = 0; |
| 4826 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4827 | } |
| 4828 | return true; |
| 4829 | case GL_CURRENT_PROGRAM: |
| 4830 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4831 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4832 | if (state_.current_program.get()) { |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4833 | GLuint client_id = 0; |
| 4834 | program_manager()->GetClientId( |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4835 | state_.current_program->service_id(), &client_id); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4836 | *params = client_id; |
| 4837 | } else { |
| 4838 | *params = 0; |
| 4839 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4840 | } |
| 4841 | return true; |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 4842 | case GL_VERTEX_ARRAY_BINDING_OES: |
| 4843 | *num_written = 1; |
| 4844 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4845 | if (state_.vertex_attrib_manager.get() != |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 4846 | state_.default_vertex_attrib_manager.get()) { |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 4847 | GLuint client_id = 0; |
| 4848 | vertex_array_manager_->GetClientId( |
| 4849 | state_.vertex_attrib_manager->service_id(), &client_id); |
| 4850 | *params = client_id; |
| 4851 | } else { |
| 4852 | *params = 0; |
| 4853 | } |
| 4854 | } |
| 4855 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4856 | case GL_TEXTURE_BINDING_2D: |
| 4857 | *num_written = 1; |
| 4858 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4859 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4860 | if (unit.bound_texture_2d.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4861 | *params = unit.bound_texture_2d->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4862 | } else { |
| 4863 | *params = 0; |
| 4864 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4865 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4866 | return true; |
| 4867 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 4868 | *num_written = 1; |
| 4869 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4870 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4871 | if (unit.bound_texture_cube_map.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4872 | *params = unit.bound_texture_cube_map->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4873 | } else { |
| 4874 | *params = 0; |
| 4875 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 4876 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4877 | return true; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4878 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 4879 | *num_written = 1; |
| 4880 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4881 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4882 | if (unit.bound_texture_external_oes.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4883 | *params = unit.bound_texture_external_oes->client_id(); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4884 | } else { |
| 4885 | *params = 0; |
| 4886 | } |
| 4887 | } |
| 4888 | return true; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4889 | case GL_TEXTURE_BINDING_RECTANGLE_ARB: |
| 4890 | *num_written = 1; |
| 4891 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4892 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4893 | if (unit.bound_texture_rectangle_arb.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4894 | *params = unit.bound_texture_rectangle_arb->client_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4895 | } else { |
| 4896 | *params = 0; |
| 4897 | } |
| 4898 | } |
| 4899 | return true; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 4900 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 4901 | *num_written = 1; |
| 4902 | if (params) { |
| 4903 | params[0] = unpack_flip_y_; |
| 4904 | } |
| 4905 | return true; |
| 4906 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 4907 | *num_written = 1; |
| 4908 | if (params) { |
| 4909 | params[0] = unpack_premultiply_alpha_; |
| 4910 | } |
| 4911 | return true; |
| 4912 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 4913 | *num_written = 1; |
| 4914 | if (params) { |
| 4915 | params[0] = unpack_unpremultiply_alpha_; |
| 4916 | } |
| 4917 | return true; |
[email protected] | 6eda682 | 2014-04-03 23:00:50 | [diff] [blame] | 4918 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 4919 | *num_written = 1; |
| 4920 | if (params) { |
| 4921 | params[0] = group_->bind_generates_resource() ? 1 : 0; |
| 4922 | } |
| 4923 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4924 | default: |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 4925 | if (pname >= GL_DRAW_BUFFER0_ARB && |
| 4926 | pname < GL_DRAW_BUFFER0_ARB + group_->max_draw_buffers()) { |
| 4927 | *num_written = 1; |
| 4928 | if (params) { |
| 4929 | Framebuffer* framebuffer = |
| 4930 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 4931 | if (framebuffer) { |
| 4932 | params[0] = framebuffer->GetDrawBuffer(pname); |
| 4933 | } else { // backbuffer |
| 4934 | if (pname == GL_DRAW_BUFFER0_ARB) |
| 4935 | params[0] = group_->draw_buffer(); |
| 4936 | else |
| 4937 | params[0] = GL_NONE; |
| 4938 | } |
| 4939 | } |
| 4940 | return true; |
| 4941 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4942 | *num_written = util_.GLGetNumValuesReturned(pname); |
[email protected] | c5d79834 | 2010-09-24 20:42:53 | [diff] [blame] | 4943 | return false; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4944 | } |
| 4945 | } |
| 4946 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4947 | bool GLES2DecoderImpl::GetNumValuesReturnedForGLGet( |
| 4948 | GLenum pname, GLsizei* num_values) { |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4949 | if (state_.GetStateAsGLint(pname, NULL, num_values)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4950 | return true; |
| 4951 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4952 | return GetHelper(pname, NULL, num_values); |
| 4953 | } |
| 4954 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4955 | GLenum GLES2DecoderImpl::AdjustGetPname(GLenum pname) { |
| 4956 | if (GL_MAX_SAMPLES == pname && |
| 4957 | features().use_img_for_multisampled_render_to_texture) { |
| 4958 | return GL_MAX_SAMPLES_IMG; |
| 4959 | } |
| 4960 | return pname; |
| 4961 | } |
| 4962 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4963 | void GLES2DecoderImpl::DoGetBooleanv(GLenum pname, GLboolean* params) { |
| 4964 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4965 | GLsizei num_written = 0; |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4966 | if (GetNumValuesReturnedForGLGet(pname, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 4967 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4968 | if (!state_.GetStateAsGLint(pname, values.get(), &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4969 | GetHelper(pname, values.get(), &num_written); |
| 4970 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4971 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 4972 | params[ii] = static_cast<GLboolean>(values[ii]); |
| 4973 | } |
| 4974 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4975 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4976 | glGetBooleanv(pname, params); |
| 4977 | } |
| 4978 | } |
| 4979 | |
| 4980 | void GLES2DecoderImpl::DoGetFloatv(GLenum pname, GLfloat* params) { |
| 4981 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4982 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 4983 | if (!state_.GetStateAsGLfloat(pname, params, &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4984 | if (GetHelper(pname, NULL, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 4985 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4986 | GetHelper(pname, values.get(), &num_written); |
| 4987 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 4988 | params[ii] = static_cast<GLfloat>(values[ii]); |
| 4989 | } |
| 4990 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 4991 | pname = AdjustGetPname(pname); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 4992 | glGetFloatv(pname, params); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4993 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | void GLES2DecoderImpl::DoGetIntegerv(GLenum pname, GLint* params) { |
| 4998 | DCHECK(params); |
| 4999 | GLsizei num_written; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 5000 | if (!state_.GetStateAsGLint(pname, params, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 5001 | !GetHelper(pname, params, &num_written)) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5002 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5003 | glGetIntegerv(pname, params); |
| 5004 | } |
| 5005 | } |
| 5006 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 5007 | void GLES2DecoderImpl::DoGetProgramiv( |
| 5008 | GLuint program_id, GLenum pname, GLint* params) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5009 | Program* program = GetProgramInfoNotShader(program_id, "glGetProgramiv"); |
| 5010 | if (!program) { |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 5011 | return; |
| 5012 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5013 | program->GetProgramiv(pname, params); |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 5014 | } |
| 5015 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 5016 | void GLES2DecoderImpl::DoGetBufferParameteriv( |
| 5017 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 5018 | // Just delegate it. Some validation is actually done before this. |
| 5019 | buffer_manager()->ValidateAndDoGetBufferParameteriv( |
| 5020 | &state_, target, pname, params); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 5021 | } |
| 5022 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5023 | void GLES2DecoderImpl::DoBindAttribLocation( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5024 | GLuint program_id, GLuint index, const char* name) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5025 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5026 | LOCAL_SET_GL_ERROR( |
| 5027 | GL_INVALID_VALUE, "glBindAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5028 | return; |
| 5029 | } |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 5030 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5031 | LOCAL_SET_GL_ERROR( |
| 5032 | GL_INVALID_OPERATION, "glBindAttribLocation", "reserved prefix"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 5033 | return; |
| 5034 | } |
| 5035 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5036 | LOCAL_SET_GL_ERROR( |
| 5037 | GL_INVALID_VALUE, "glBindAttribLocation", "index out of range"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 5038 | return; |
| 5039 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5040 | Program* program = GetProgramInfoNotShader( |
| 5041 | program_id, "glBindAttribLocation"); |
| 5042 | if (!program) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5043 | return; |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5044 | } |
zmo | 460b593e | 2014-10-13 23:07:45 | [diff] [blame] | 5045 | // At this point, the program's shaders may not be translated yet, |
| 5046 | // therefore, we may not find the hashed attribute name. |
| 5047 | // glBindAttribLocation call with original name is useless. |
| 5048 | // So instead, we should simply cache the binding, and then call |
| 5049 | // Program::ExecuteBindAttribLocationCalls() right before link. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5050 | program->SetAttribLocationBinding(name, static_cast<GLint>(index)); |
zmo | 460b593e | 2014-10-13 23:07:45 | [diff] [blame] | 5051 | // TODO(zmo): Get rid of the following glBindAttribLocation call. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5052 | glBindAttribLocation(program->service_id(), index, name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5053 | } |
| 5054 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5055 | error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 5056 | uint32 immediate_data_size, |
| 5057 | const void* cmd_data) { |
| 5058 | const gles2::cmds::BindAttribLocationBucket& c = |
| 5059 | *static_cast<const gles2::cmds::BindAttribLocationBucket*>(cmd_data); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5060 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5061 | GLuint index = static_cast<GLuint>(c.index); |
| 5062 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 5063 | if (!bucket || bucket->size() == 0) { |
| 5064 | return error::kInvalidArguments; |
| 5065 | } |
| 5066 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 5067 | if (!bucket->GetAsString(&name_str)) { |
| 5068 | return error::kInvalidArguments; |
| 5069 | } |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5070 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5071 | return error::kNoError; |
| 5072 | } |
| 5073 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5074 | void GLES2DecoderImpl::DoBindUniformLocationCHROMIUM( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5075 | GLuint program_id, GLint location, const char* name) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5076 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5077 | LOCAL_SET_GL_ERROR( |
| 5078 | GL_INVALID_VALUE, |
| 5079 | "glBindUniformLocationCHROMIUM", "Invalid character"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5080 | return; |
| 5081 | } |
| 5082 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5083 | LOCAL_SET_GL_ERROR( |
| 5084 | GL_INVALID_OPERATION, |
| 5085 | "glBindUniformLocationCHROMIUM", "reserved prefix"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5086 | return; |
| 5087 | } |
| 5088 | if (location < 0 || static_cast<uint32>(location) >= |
| 5089 | (group_->max_fragment_uniform_vectors() + |
| 5090 | group_->max_vertex_uniform_vectors()) * 4) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5091 | LOCAL_SET_GL_ERROR( |
| 5092 | GL_INVALID_VALUE, |
| 5093 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5094 | return; |
| 5095 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5096 | Program* program = GetProgramInfoNotShader( |
| 5097 | program_id, "glBindUniformLocationCHROMIUM"); |
| 5098 | if (!program) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5099 | return; |
| 5100 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5101 | if (!program->SetUniformLocationBinding(name, location)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5102 | LOCAL_SET_GL_ERROR( |
| 5103 | GL_INVALID_VALUE, |
| 5104 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5105 | } |
| 5106 | } |
| 5107 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5108 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUMBucket( |
| 5109 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 5110 | const void* cmd_data) { |
| 5111 | const gles2::cmds::BindUniformLocationCHROMIUMBucket& c = |
| 5112 | *static_cast<const gles2::cmds::BindUniformLocationCHROMIUMBucket*>( |
| 5113 | cmd_data); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5114 | GLuint program = static_cast<GLuint>(c.program); |
| 5115 | GLint location = static_cast<GLint>(c.location); |
| 5116 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 5117 | if (!bucket || bucket->size() == 0) { |
| 5118 | return error::kInvalidArguments; |
| 5119 | } |
| 5120 | std::string name_str; |
| 5121 | if (!bucket->GetAsString(&name_str)) { |
| 5122 | return error::kInvalidArguments; |
| 5123 | } |
| 5124 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 5125 | return error::kNoError; |
| 5126 | } |
| 5127 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 5128 | error::Error GLES2DecoderImpl::HandleDeleteShader(uint32 immediate_data_size, |
| 5129 | const void* cmd_data) { |
| 5130 | const gles2::cmds::DeleteShader& c = |
| 5131 | *static_cast<const gles2::cmds::DeleteShader*>(cmd_data); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5132 | GLuint client_id = c.shader; |
| 5133 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5134 | Shader* shader = GetShader(client_id); |
| 5135 | if (shader) { |
| 5136 | if (!shader->IsDeleted()) { |
| 5137 | glDeleteShader(shader->service_id()); |
| 5138 | shader_manager()->MarkAsDeleted(shader); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5139 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5140 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5141 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteShader", "unknown shader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5142 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5143 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5144 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5145 | } |
| 5146 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 5147 | error::Error GLES2DecoderImpl::HandleDeleteProgram(uint32 immediate_data_size, |
| 5148 | const void* cmd_data) { |
| 5149 | const gles2::cmds::DeleteProgram& c = |
| 5150 | *static_cast<const gles2::cmds::DeleteProgram*>(cmd_data); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5151 | GLuint client_id = c.program; |
| 5152 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5153 | Program* program = GetProgram(client_id); |
| 5154 | if (program) { |
| 5155 | if (!program->IsDeleted()) { |
| 5156 | program_manager()->MarkAsDeleted(shader_manager(), program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5157 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5158 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5159 | LOCAL_SET_GL_ERROR( |
| 5160 | GL_INVALID_VALUE, "glDeleteProgram", "unknown program"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5161 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5162 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5163 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5164 | } |
| 5165 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 5166 | error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 5167 | DCHECK(!ShouldDeferDraws()); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5168 | if (CheckBoundFramebuffersValid("glClear")) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5169 | ApplyDirtyState(); |
boliu | 2e7d8a7a | 2014-10-16 20:35:20 | [diff] [blame] | 5170 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 5171 | if (workarounds().gl_clear_broken) { |
| 5172 | ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::ClearWorkaround", |
| 5173 | GetErrorState()); |
| 5174 | if (!BoundFramebufferHasDepthAttachment()) |
| 5175 | mask &= ~GL_DEPTH_BUFFER_BIT; |
| 5176 | if (!BoundFramebufferHasStencilAttachment()) |
| 5177 | mask &= ~GL_STENCIL_BUFFER_BIT; |
| 5178 | clear_framebuffer_blit_->ClearFramebuffer( |
| 5179 | this, GetBoundReadFrameBufferSize(), mask, state_.color_clear_red, |
| 5180 | state_.color_clear_green, state_.color_clear_blue, |
| 5181 | state_.color_clear_alpha, state_.depth_clear, state_.stencil_clear); |
| 5182 | return error::kNoError; |
| 5183 | } |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 5184 | glClear(mask); |
| 5185 | } |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 5186 | return error::kNoError; |
| 5187 | } |
| 5188 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5189 | void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
| 5190 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5191 | GLuint client_renderbuffer_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5192 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5193 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5194 | LOCAL_SET_GL_ERROR( |
| 5195 | GL_INVALID_OPERATION, |
| 5196 | "glFramebufferRenderbuffer", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5197 | return; |
| 5198 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5199 | GLuint service_id = 0; |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5200 | Renderbuffer* renderbuffer = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5201 | if (client_renderbuffer_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5202 | renderbuffer = GetRenderbuffer(client_renderbuffer_id); |
| 5203 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5204 | LOCAL_SET_GL_ERROR( |
| 5205 | GL_INVALID_OPERATION, |
| 5206 | "glFramebufferRenderbuffer", "unknown renderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5207 | return; |
| 5208 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5209 | service_id = renderbuffer->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5210 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5211 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glFramebufferRenderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5212 | glFramebufferRenderbufferEXT( |
| 5213 | target, attachment, renderbuffertarget, service_id); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5214 | GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferRenderbuffer"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5215 | if (error == GL_NO_ERROR) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5216 | framebuffer->AttachRenderbuffer(attachment, renderbuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5217 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 5218 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5219 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5220 | } |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 5221 | OnFboChanged(); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5222 | } |
| 5223 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5224 | void GLES2DecoderImpl::DoDisable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5225 | if (SetCapabilityState(cap, false)) { |
| 5226 | glDisable(cap); |
| 5227 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5228 | } |
| 5229 | |
| 5230 | void GLES2DecoderImpl::DoEnable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5231 | if (SetCapabilityState(cap, true)) { |
| 5232 | glEnable(cap); |
| 5233 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5234 | } |
| 5235 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 5236 | void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { |
| 5237 | state_.z_near = std::min(1.0f, std::max(0.0f, znear)); |
| 5238 | state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); |
| 5239 | glDepthRange(znear, zfar); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5240 | } |
| 5241 | |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 5242 | void GLES2DecoderImpl::DoSampleCoverage(GLclampf value, GLboolean invert) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 5243 | state_.sample_coverage_value = std::min(1.0f, std::max(0.0f, value)); |
| 5244 | state_.sample_coverage_invert = (invert != 0); |
| 5245 | glSampleCoverage(state_.sample_coverage_value, invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5246 | } |
| 5247 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5248 | // Assumes framebuffer is complete. |
| 5249 | void GLES2DecoderImpl::ClearUnclearedAttachments( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5250 | GLenum target, Framebuffer* framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5251 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5252 | // bind this to the DRAW point, clear then bind back to READ |
| 5253 | // TODO(gman): I don't think there is any guarantee that an FBO that |
| 5254 | // is complete on the READ attachment will be complete as a DRAW |
| 5255 | // attachment. |
| 5256 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5257 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffer->service_id()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5258 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5259 | GLbitfield clear_bits = 0; |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 5260 | if (framebuffer->HasUnclearedColorAttachments()) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5261 | glClearColor( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5262 | 0.0f, 0.0f, 0.0f, |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5263 | (GLES2Util::GetChannelsForFormat( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5264 | framebuffer->GetColorAttachmentFormat()) & 0x0008) != 0 ? 0.0f : |
| 5265 | 1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5266 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5267 | clear_bits |= GL_COLOR_BUFFER_BIT; |
[email protected] | 0e58af8 | 2014-08-08 14:02:53 | [diff] [blame] | 5268 | if (feature_info_->feature_flags().ext_draw_buffers) |
| 5269 | framebuffer->PrepareDrawBuffersForClear(); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5270 | } |
| 5271 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5272 | if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
| 5273 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5274 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 5275 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 5276 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5277 | clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 5278 | } |
| 5279 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5280 | if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
| 5281 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5282 | glClearDepth(1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5283 | state_.SetDeviceDepthMask(GL_TRUE); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5284 | clear_bits |= GL_DEPTH_BUFFER_BIT; |
| 5285 | } |
| 5286 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5287 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5288 | glClear(clear_bits); |
| 5289 | |
brucedawson | 1824915 | 2014-10-31 23:02:32 | [diff] [blame] | 5290 | if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0 && |
[email protected] | 0e58af8 | 2014-08-08 14:02:53 | [diff] [blame] | 5291 | feature_info_->feature_flags().ext_draw_buffers) |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 5292 | framebuffer->RestoreDrawBuffersAfterClear(); |
| 5293 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5294 | framebuffer_manager()->MarkAttachmentsAsCleared( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5295 | framebuffer, renderbuffer_manager(), texture_manager()); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5296 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 5297 | RestoreClearState(); |
| 5298 | |
| 5299 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5300 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, framebuffer->service_id()); |
| 5301 | Framebuffer* draw_framebuffer = |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 5302 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5303 | GLuint service_id = draw_framebuffer ? draw_framebuffer->service_id() : |
| 5304 | GetBackbufferServiceId(); |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 5305 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, service_id); |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 5306 | } |
| 5307 | } |
| 5308 | |
| 5309 | void GLES2DecoderImpl::RestoreClearState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5310 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5311 | glClearColor( |
| 5312 | state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, |
| 5313 | state_.color_clear_alpha); |
| 5314 | glClearStencil(state_.stencil_clear); |
| 5315 | glClearDepth(state_.depth_clear); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 5316 | if (state_.enable_flags.scissor_test) { |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5317 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5318 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5322 | Framebuffer* framebuffer = |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5323 | GetFramebufferInfoForTarget(target); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5324 | if (!framebuffer) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5325 | return GL_FRAMEBUFFER_COMPLETE; |
| 5326 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5327 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 5328 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
| 5329 | return completeness; |
| 5330 | } |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 5331 | return framebuffer->GetStatus(texture_manager(), target); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | void GLES2DecoderImpl::DoFramebufferTexture2D( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5335 | GLenum target, GLenum attachment, GLenum textarget, |
| 5336 | GLuint client_texture_id, GLint level) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5337 | DoFramebufferTexture2DCommon( |
| 5338 | "glFramebufferTexture2D", target, attachment, |
| 5339 | textarget, client_texture_id, level, 0); |
| 5340 | } |
| 5341 | |
| 5342 | void GLES2DecoderImpl::DoFramebufferTexture2DMultisample( |
| 5343 | GLenum target, GLenum attachment, GLenum textarget, |
| 5344 | GLuint client_texture_id, GLint level, GLsizei samples) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5345 | DoFramebufferTexture2DCommon( |
| 5346 | "glFramebufferTexture2DMultisample", target, attachment, |
| 5347 | textarget, client_texture_id, level, samples); |
| 5348 | } |
| 5349 | |
| 5350 | void GLES2DecoderImpl::DoFramebufferTexture2DCommon( |
| 5351 | const char* name, GLenum target, GLenum attachment, GLenum textarget, |
| 5352 | GLuint client_texture_id, GLint level, GLsizei samples) { |
| 5353 | if (samples > renderbuffer_manager()->max_samples()) { |
| 5354 | LOCAL_SET_GL_ERROR( |
| 5355 | GL_INVALID_VALUE, |
| 5356 | "glFramebufferTexture2DMultisample", "samples too large"); |
| 5357 | return; |
| 5358 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5359 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5360 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5361 | LOCAL_SET_GL_ERROR( |
| 5362 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5363 | name, "no framebuffer bound."); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5364 | return; |
| 5365 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5366 | GLuint service_id = 0; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5367 | TextureRef* texture_ref = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5368 | if (client_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5369 | texture_ref = GetTexture(client_texture_id); |
| 5370 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5371 | LOCAL_SET_GL_ERROR( |
| 5372 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5373 | name, "unknown texture_ref"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5374 | return; |
| 5375 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5376 | service_id = texture_ref->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5377 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5378 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 5379 | if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5380 | LOCAL_SET_GL_ERROR( |
| 5381 | GL_INVALID_VALUE, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5382 | name, "level out of range"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5383 | return; |
| 5384 | } |
| 5385 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5386 | if (texture_ref) |
| 5387 | DoWillUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 5388 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5389 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); |
| 5390 | if (0 == samples) { |
| 5391 | glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
| 5392 | } else { |
| 5393 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5394 | glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, |
| 5395 | service_id, level, samples); |
| 5396 | } else { |
| 5397 | glFramebufferTexture2DMultisampleEXT(target, attachment, textarget, |
| 5398 | service_id, level, samples); |
| 5399 | } |
| 5400 | } |
| 5401 | GLenum error = LOCAL_PEEK_GL_ERROR(name); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5402 | if (error == GL_NO_ERROR) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5403 | framebuffer->AttachTexture(attachment, texture_ref, textarget, level, |
| 5404 | samples); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5405 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 5406 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5407 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5408 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5409 | |
| 5410 | if (texture_ref) |
| 5411 | DoDidUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 5412 | |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 5413 | OnFboChanged(); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5414 | } |
| 5415 | |
zmo | 84c0820 | 2014-11-23 15:28:40 | [diff] [blame] | 5416 | void GLES2DecoderImpl::DoFramebufferTextureLayer( |
| 5417 | GLenum target, GLenum attachment, GLuint client_texture_id, |
| 5418 | GLint level, GLint layer) { |
| 5419 | // TODO(zmo): Unsafe ES3 API, missing states update. |
| 5420 | GLuint service_id = 0; |
| 5421 | TextureRef* texture_ref = NULL; |
| 5422 | if (client_texture_id) { |
| 5423 | texture_ref = GetTexture(client_texture_id); |
| 5424 | if (!texture_ref) { |
| 5425 | LOCAL_SET_GL_ERROR( |
| 5426 | GL_INVALID_OPERATION, |
| 5427 | "glFramebufferTextureLayer", "unknown texture_ref"); |
| 5428 | return; |
| 5429 | } |
| 5430 | service_id = texture_ref->service_id(); |
| 5431 | } |
| 5432 | glFramebufferTextureLayer(target, attachment, service_id, level, layer); |
| 5433 | } |
| 5434 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5435 | void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( |
| 5436 | GLenum target, GLenum attachment, GLenum pname, GLint* params) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5437 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5438 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5439 | LOCAL_SET_GL_ERROR( |
| 5440 | GL_INVALID_OPERATION, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5441 | "glGetFramebufferAttachmentParameteriv", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5442 | return; |
| 5443 | } |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 5444 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5445 | const Framebuffer::Attachment* attachment_object = |
| 5446 | framebuffer->GetAttachment(attachment); |
| 5447 | *params = attachment_object ? attachment_object->object_name() : 0; |
| 5448 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5449 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT && |
| 5450 | features().use_img_for_multisampled_render_to_texture) { |
| 5451 | pname = GL_TEXTURE_SAMPLES_IMG; |
| 5452 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5453 | glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 5454 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5455 | } |
| 5456 | |
| 5457 | void GLES2DecoderImpl::DoGetRenderbufferParameteriv( |
| 5458 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5459 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5460 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5461 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5462 | LOCAL_SET_GL_ERROR( |
| 5463 | GL_INVALID_OPERATION, |
| 5464 | "glGetRenderbufferParameteriv", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5465 | return; |
| 5466 | } |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5467 | |
| 5468 | EnsureRenderbufferBound(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 5469 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5470 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5471 | *params = renderbuffer->internal_format(); |
| 5472 | break; |
| 5473 | case GL_RENDERBUFFER_WIDTH: |
| 5474 | *params = renderbuffer->width(); |
| 5475 | break; |
| 5476 | case GL_RENDERBUFFER_HEIGHT: |
| 5477 | *params = renderbuffer->height(); |
| 5478 | break; |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5479 | case GL_RENDERBUFFER_SAMPLES_EXT: |
| 5480 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5481 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_IMG, |
| 5482 | params); |
| 5483 | } else { |
| 5484 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_EXT, |
| 5485 | params); |
| 5486 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5487 | default: |
| 5488 | glGetRenderbufferParameterivEXT(target, pname, params); |
| 5489 | break; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 5490 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5491 | } |
| 5492 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5493 | void GLES2DecoderImpl::DoBlitFramebufferCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5494 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 5495 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 5496 | GLbitfield mask, GLenum filter) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 5497 | DCHECK(!ShouldDeferReads() && !ShouldDeferDraws()); |
[email protected] | 0c16343f | 2013-03-08 20:40:16 | [diff] [blame] | 5498 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5499 | if (!CheckBoundFramebuffersValid("glBlitFramebufferCHROMIUM")) { |
[email protected] | 0c16343f | 2013-03-08 20:40:16 | [diff] [blame] | 5500 | return; |
| 5501 | } |
| 5502 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5503 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
boliu | 2e7d8a7a | 2014-10-16 20:35:20 | [diff] [blame] | 5504 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5505 | BlitFramebufferHelper( |
| 5506 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5507 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, |
| 5508 | state_.enable_flags.scissor_test); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5509 | } |
| 5510 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5511 | void GLES2DecoderImpl::EnsureRenderbufferBound() { |
| 5512 | if (!state_.bound_renderbuffer_valid) { |
| 5513 | state_.bound_renderbuffer_valid = true; |
| 5514 | glBindRenderbufferEXT(GL_RENDERBUFFER, |
| 5515 | state_.bound_renderbuffer.get() |
| 5516 | ? state_.bound_renderbuffer->service_id() |
| 5517 | : 0); |
| 5518 | } |
| 5519 | } |
| 5520 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5521 | void GLES2DecoderImpl::RenderbufferStorageMultisampleHelper( |
| 5522 | const FeatureInfo* feature_info, |
| 5523 | GLenum target, |
| 5524 | GLsizei samples, |
| 5525 | GLenum internal_format, |
| 5526 | GLsizei width, |
| 5527 | GLsizei height) { |
| 5528 | // TODO(sievers): This could be resolved at the GL binding level, but the |
| 5529 | // binding process is currently a bit too 'brute force'. |
zmo | 68fcdc6 | 2014-12-05 21:51:49 | [diff] [blame] | 5530 | if (feature_info->gl_version_info().is_angle) { |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5531 | glRenderbufferStorageMultisampleANGLE( |
| 5532 | target, samples, internal_format, width, height); |
| 5533 | } else if (feature_info->feature_flags().use_core_framebuffer_multisample) { |
| 5534 | glRenderbufferStorageMultisample( |
| 5535 | target, samples, internal_format, width, height); |
| 5536 | } else { |
| 5537 | glRenderbufferStorageMultisampleEXT( |
| 5538 | target, samples, internal_format, width, height); |
| 5539 | } |
| 5540 | } |
| 5541 | |
| 5542 | void GLES2DecoderImpl::BlitFramebufferHelper(GLint srcX0, |
| 5543 | GLint srcY0, |
| 5544 | GLint srcX1, |
| 5545 | GLint srcY1, |
| 5546 | GLint dstX0, |
| 5547 | GLint dstY0, |
| 5548 | GLint dstX1, |
| 5549 | GLint dstY1, |
| 5550 | GLbitfield mask, |
| 5551 | GLenum filter) { |
| 5552 | // TODO(sievers): This could be resolved at the GL binding level, but the |
| 5553 | // binding process is currently a bit too 'brute force'. |
zmo | 68fcdc6 | 2014-12-05 21:51:49 | [diff] [blame] | 5554 | if (feature_info_->gl_version_info().is_angle) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 5555 | glBlitFramebufferANGLE( |
| 5556 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5557 | } else if (feature_info_->feature_flags().use_core_framebuffer_multisample) { |
| 5558 | glBlitFramebuffer( |
| 5559 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 5560 | } else { |
| 5561 | glBlitFramebufferEXT( |
| 5562 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 5563 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5564 | } |
| 5565 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5566 | bool GLES2DecoderImpl::ValidateRenderbufferStorageMultisample( |
| 5567 | GLsizei samples, |
| 5568 | GLenum internalformat, |
| 5569 | GLsizei width, |
| 5570 | GLsizei height) { |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5571 | if (samples > renderbuffer_manager()->max_samples()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5572 | LOCAL_SET_GL_ERROR( |
| 5573 | GL_INVALID_VALUE, |
| 5574 | "glRenderbufferStorageMultisample", "samples too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5575 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5576 | } |
| 5577 | |
| 5578 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 5579 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5580 | LOCAL_SET_GL_ERROR( |
| 5581 | GL_INVALID_VALUE, |
| 5582 | "glRenderbufferStorageMultisample", "dimensions too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5583 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5584 | } |
| 5585 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5586 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5587 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 5588 | width, height, samples, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5589 | LOCAL_SET_GL_ERROR( |
| 5590 | GL_OUT_OF_MEMORY, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5591 | "glRenderbufferStorageMultisample", "dimensions too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5592 | return false; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5593 | } |
| 5594 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5595 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5596 | LOCAL_SET_GL_ERROR( |
| 5597 | GL_OUT_OF_MEMORY, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5598 | "glRenderbufferStorageMultisample", "out of memory"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5599 | return false; |
| 5600 | } |
| 5601 | |
| 5602 | return true; |
| 5603 | } |
| 5604 | |
| 5605 | void GLES2DecoderImpl::DoRenderbufferStorageMultisampleCHROMIUM( |
| 5606 | GLenum target, GLsizei samples, GLenum internalformat, |
| 5607 | GLsizei width, GLsizei height) { |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5608 | Renderbuffer* renderbuffer = GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5609 | if (!renderbuffer) { |
| 5610 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 5611 | "glRenderbufferStorageMultisampleCHROMIUM", |
| 5612 | "no renderbuffer bound"); |
| 5613 | return; |
| 5614 | } |
| 5615 | |
| 5616 | if (!ValidateRenderbufferStorageMultisample( |
| 5617 | samples, internalformat, width, height)) { |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5618 | return; |
| 5619 | } |
| 5620 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5621 | EnsureRenderbufferBound(); |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5622 | GLenum impl_format = |
| 5623 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5624 | internalformat); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5625 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER( |
| 5626 | "glRenderbufferStorageMultisampleCHROMIUM"); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5627 | RenderbufferStorageMultisampleHelper( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 5628 | feature_info_.get(), target, samples, impl_format, width, height); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5629 | GLenum error = |
| 5630 | LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleCHROMIUM"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5631 | if (error == GL_NO_ERROR) { |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5632 | |
| 5633 | if (workarounds().validate_multisample_buffer_allocation) { |
| 5634 | if (!VerifyMultisampleRenderbufferIntegrity( |
| 5635 | renderbuffer->service_id(), impl_format)) { |
| 5636 | LOCAL_SET_GL_ERROR( |
| 5637 | GL_OUT_OF_MEMORY, |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5638 | "glRenderbufferStorageMultisampleCHROMIUM", "out of memory"); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5639 | return; |
| 5640 | } |
| 5641 | } |
| 5642 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5643 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 5644 | // attached to we could just mark those framebuffers as not complete. |
| 5645 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5646 | renderbuffer_manager()->SetInfo( |
| 5647 | renderbuffer, samples, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5648 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5649 | } |
| 5650 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5651 | // This is the handler for multisampled_render_to_texture extensions. |
| 5652 | void GLES2DecoderImpl::DoRenderbufferStorageMultisampleEXT( |
| 5653 | GLenum target, GLsizei samples, GLenum internalformat, |
| 5654 | GLsizei width, GLsizei height) { |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5655 | Renderbuffer* renderbuffer = GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5656 | if (!renderbuffer) { |
| 5657 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 5658 | "glRenderbufferStorageMultisampleEXT", |
| 5659 | "no renderbuffer bound"); |
| 5660 | return; |
| 5661 | } |
| 5662 | |
| 5663 | if (!ValidateRenderbufferStorageMultisample( |
| 5664 | samples, internalformat, width, height)) { |
| 5665 | return; |
| 5666 | } |
| 5667 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5668 | EnsureRenderbufferBound(); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5669 | GLenum impl_format = |
| 5670 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5671 | internalformat); |
| 5672 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorageMultisampleEXT"); |
| 5673 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5674 | glRenderbufferStorageMultisampleIMG( |
| 5675 | target, samples, impl_format, width, height); |
| 5676 | } else { |
| 5677 | glRenderbufferStorageMultisampleEXT( |
| 5678 | target, samples, impl_format, width, height); |
| 5679 | } |
| 5680 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleEXT"); |
| 5681 | if (error == GL_NO_ERROR) { |
| 5682 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 5683 | // attached to we could just mark those framebuffers as not complete. |
| 5684 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
| 5685 | renderbuffer_manager()->SetInfo( |
| 5686 | renderbuffer, samples, internalformat, width, height); |
| 5687 | } |
| 5688 | } |
| 5689 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5690 | // This function validates the allocation of a multisampled renderbuffer |
| 5691 | // by clearing it to a key color, blitting the contents to a texture, and |
| 5692 | // reading back the color to ensure it matches the key. |
| 5693 | bool GLES2DecoderImpl::VerifyMultisampleRenderbufferIntegrity( |
| 5694 | GLuint renderbuffer, GLenum format) { |
| 5695 | |
| 5696 | // Only validate color buffers. |
| 5697 | // These formats have been selected because they are very common or are known |
| 5698 | // to be used by the WebGL backbuffer. If problems are observed with other |
| 5699 | // color formats they can be added here. |
| 5700 | switch(format) { |
| 5701 | case GL_RGB: |
| 5702 | case GL_RGB8: |
| 5703 | case GL_RGBA: |
| 5704 | case GL_RGBA8: |
| 5705 | break; |
| 5706 | default: |
| 5707 | return true; |
| 5708 | } |
| 5709 | |
| 5710 | GLint draw_framebuffer, read_framebuffer; |
| 5711 | |
| 5712 | // Cache framebuffer and texture bindings. |
| 5713 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_framebuffer); |
| 5714 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_framebuffer); |
| 5715 | |
| 5716 | if (!validation_texture_) { |
| 5717 | GLint bound_texture; |
| 5718 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
| 5719 | |
| 5720 | // Create additional resources needed for the verification. |
| 5721 | glGenTextures(1, &validation_texture_); |
| 5722 | glGenFramebuffersEXT(1, &validation_fbo_multisample_); |
| 5723 | glGenFramebuffersEXT(1, &validation_fbo_); |
| 5724 | |
| 5725 | // Texture only needs to be 1x1. |
| 5726 | glBindTexture(GL_TEXTURE_2D, validation_texture_); |
| 5727 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, |
| 5728 | GL_UNSIGNED_BYTE, NULL); |
| 5729 | |
| 5730 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 5731 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5732 | GL_TEXTURE_2D, validation_texture_, 0); |
| 5733 | |
| 5734 | glBindTexture(GL_TEXTURE_2D, bound_texture); |
| 5735 | } |
| 5736 | |
| 5737 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 5738 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5739 | GL_RENDERBUFFER, renderbuffer); |
| 5740 | |
| 5741 | // Cache current state and reset it to the values we require. |
| 5742 | GLboolean scissor_enabled = false; |
| 5743 | glGetBooleanv(GL_SCISSOR_TEST, &scissor_enabled); |
| 5744 | if (scissor_enabled) |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5745 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5746 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5747 | GLboolean color_mask[4] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE}; |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5748 | glGetBooleanv(GL_COLOR_WRITEMASK, color_mask); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5749 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5750 | |
| 5751 | GLfloat clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 5752 | glGetFloatv(GL_COLOR_CLEAR_VALUE, clear_color); |
| 5753 | glClearColor(1.0f, 0.0f, 1.0f, 1.0f); |
| 5754 | |
| 5755 | // Clear the buffer to the desired key color. |
| 5756 | glClear(GL_COLOR_BUFFER_BIT); |
| 5757 | |
| 5758 | // Blit from the multisample buffer to a standard texture. |
| 5759 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, validation_fbo_multisample_); |
| 5760 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, validation_fbo_); |
| 5761 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5762 | BlitFramebufferHelper( |
| 5763 | 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] | 5764 | |
| 5765 | // Read a pixel from the buffer. |
| 5766 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 5767 | |
| 5768 | unsigned char pixel[3] = {0, 0, 0}; |
| 5769 | glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixel); |
| 5770 | |
| 5771 | // Detach the renderbuffer. |
| 5772 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 5773 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5774 | GL_RENDERBUFFER, 0); |
| 5775 | |
| 5776 | // Restore cached state. |
| 5777 | if (scissor_enabled) |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5778 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5779 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5780 | state_.SetDeviceColorMask( |
| 5781 | color_mask[0], color_mask[1], color_mask[2], color_mask[3]); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 5782 | glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); |
| 5783 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, draw_framebuffer); |
| 5784 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, read_framebuffer); |
| 5785 | |
| 5786 | // Return true if the pixel matched the desired key color. |
| 5787 | return (pixel[0] == 0xFF && |
| 5788 | pixel[1] == 0x00 && |
| 5789 | pixel[2] == 0xFF); |
| 5790 | } |
| 5791 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5792 | void GLES2DecoderImpl::DoRenderbufferStorage( |
| 5793 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5794 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5795 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5796 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5797 | LOCAL_SET_GL_ERROR( |
| 5798 | GL_INVALID_OPERATION, |
| 5799 | "glRenderbufferStorage", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5800 | return; |
| 5801 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5802 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5803 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 5804 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5805 | LOCAL_SET_GL_ERROR( |
| 5806 | GL_INVALID_VALUE, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5807 | return; |
| 5808 | } |
| 5809 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5810 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5811 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 5812 | width, height, 1, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5813 | LOCAL_SET_GL_ERROR( |
| 5814 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5815 | return; |
| 5816 | } |
| 5817 | |
| 5818 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5819 | LOCAL_SET_GL_ERROR( |
| 5820 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5821 | return; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 5822 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 5823 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5824 | EnsureRenderbufferBound(); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5825 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorage"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5826 | glRenderbufferStorageEXT( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5827 | target, |
| 5828 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 5829 | internalformat), |
| 5830 | width, |
| 5831 | height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5832 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorage"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5833 | if (error == GL_NO_ERROR) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5834 | // TODO(gman): If tetxures tracked which framebuffers they were attached to |
| 5835 | // we could just mark those framebuffers as not complete. |
| 5836 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5837 | renderbuffer_manager()->SetInfo( |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5838 | renderbuffer, 1, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5839 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5840 | } |
| 5841 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5842 | void GLES2DecoderImpl::DoLinkProgram(GLuint program_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 5843 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoLinkProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5844 | Program* program = GetProgramInfoNotShader( |
| 5845 | program_id, "glLinkProgram"); |
| 5846 | if (!program) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 5847 | return; |
| 5848 | } |
[email protected] | 05afda1 | 2011-01-20 00:17:34 | [diff] [blame] | 5849 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5850 | LogClientServiceForInfo(program, program_id, "glLinkProgram"); |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 5851 | ShaderTranslator* vertex_translator = NULL; |
| 5852 | ShaderTranslator* fragment_translator = NULL; |
| 5853 | if (use_shader_translator_) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5854 | vertex_translator = vertex_translator_.get(); |
| 5855 | fragment_translator = fragment_translator_.get(); |
[email protected] | 65dfc60 | 2012-07-23 20:39:39 | [diff] [blame] | 5856 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5857 | if (program->Link(shader_manager(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5858 | vertex_translator, |
| 5859 | fragment_translator, |
[email protected] | 00840153 | 2014-02-07 00:10:50 | [diff] [blame] | 5860 | workarounds().count_all_in_varyings_packing ? |
| 5861 | Program::kCountAll : Program::kCountOnlyStaticallyUsed, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5862 | shader_cache_callback_)) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5863 | if (program == state_.current_program.get()) { |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 5864 | if (workarounds().use_current_program_after_successful_link) |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5865 | glUseProgram(program->service_id()); |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 5866 | if (workarounds().clear_uniforms_before_first_program_use) |
| 5867 | program_manager()->ClearUniforms(program); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 5868 | } |
| 5869 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 5870 | |
| 5871 | // LinkProgram can be very slow. Exit command processing to allow for |
| 5872 | // context preemption and GPU watchdog checks. |
| 5873 | ExitCommandProcessingEarly(); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5874 | }; |
| 5875 | |
zmo | bcb3fdd6 | 2014-12-11 00:49:03 | [diff] [blame] | 5876 | void GLES2DecoderImpl::DoSamplerParameterfv( |
| 5877 | GLuint sampler, GLenum pname, const GLfloat* params) { |
| 5878 | DCHECK(params); |
| 5879 | glSamplerParameterf(sampler, pname, params[0]); |
| 5880 | } |
| 5881 | |
| 5882 | void GLES2DecoderImpl::DoSamplerParameteriv( |
| 5883 | GLuint sampler, GLenum pname, const GLint* params) { |
| 5884 | DCHECK(params); |
| 5885 | glSamplerParameteri(sampler, pname, params[0]); |
| 5886 | } |
| 5887 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5888 | void GLES2DecoderImpl::DoTexParameterf( |
| 5889 | GLenum target, GLenum pname, GLfloat param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5890 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5891 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5892 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5893 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterf", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5894 | return; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5895 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5896 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 5897 | texture_manager()->SetParameterf( |
| 5898 | "glTexParameterf", GetErrorState(), texture, pname, param); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 5899 | } |
| 5900 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5901 | void GLES2DecoderImpl::DoTexParameteri( |
| 5902 | GLenum target, GLenum pname, GLint param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5903 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5904 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5905 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5906 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5907 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5908 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5909 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 5910 | texture_manager()->SetParameteri( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5911 | "glTexParameteri", GetErrorState(), texture, pname, param); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5912 | } |
| 5913 | |
| 5914 | void GLES2DecoderImpl::DoTexParameterfv( |
| 5915 | GLenum target, GLenum pname, const GLfloat* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5916 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5917 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5918 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5919 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5920 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5921 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5922 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 5923 | texture_manager()->SetParameterf( |
| 5924 | "glTexParameterfv", GetErrorState(), texture, pname, *params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | void GLES2DecoderImpl::DoTexParameteriv( |
| 5928 | GLenum target, GLenum pname, const GLint* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5929 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 5930 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 5931 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5932 | LOCAL_SET_GL_ERROR( |
| 5933 | GL_INVALID_VALUE, "glTexParameteriv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5934 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5935 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 5936 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 5937 | texture_manager()->SetParameteri( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 5938 | "glTexParameteriv", GetErrorState(), texture, pname, *params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 5939 | } |
| 5940 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 5941 | bool GLES2DecoderImpl::CheckCurrentValuebuffer(const char* function_name) { |
| 5942 | if (!state_.bound_valuebuffer.get()) { |
| 5943 | // There is no valuebuffer bound |
| 5944 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 5945 | "no valuebuffer in use"); |
| 5946 | return false; |
| 5947 | } |
| 5948 | return true; |
| 5949 | } |
| 5950 | |
| 5951 | bool GLES2DecoderImpl::CheckCurrentValuebufferForSubscription( |
| 5952 | GLenum subscription, |
| 5953 | const char* function_name) { |
| 5954 | if (!CheckCurrentValuebuffer(function_name)) { |
| 5955 | return false; |
| 5956 | } |
| 5957 | if (!state_.bound_valuebuffer.get()->IsSubscribed(subscription)) { |
| 5958 | // The valuebuffer is not subscribed to the target |
| 5959 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 5960 | "valuebuffer is not subscribed"); |
| 5961 | return false; |
| 5962 | } |
| 5963 | return true; |
| 5964 | } |
| 5965 | |
| 5966 | bool GLES2DecoderImpl::CheckSubscriptionTarget(GLint location, |
| 5967 | GLenum subscription, |
| 5968 | const char* function_name) { |
| 5969 | if (!CheckCurrentProgramForUniform(location, function_name)) { |
| 5970 | return false; |
| 5971 | } |
| 5972 | GLint real_location = -1; |
| 5973 | GLint array_index = -1; |
| 5974 | const Program::UniformInfo* info = |
| 5975 | state_.current_program->GetUniformInfoByFakeLocation( |
| 5976 | location, &real_location, &array_index); |
| 5977 | if (!info) { |
| 5978 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, "unknown location"); |
| 5979 | return false; |
| 5980 | } |
| 5981 | if ((ValuebufferManager::ApiTypeForSubscriptionTarget(subscription) & |
| 5982 | info->accepts_api_type) == 0) { |
| 5983 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 5984 | "wrong type for subscription"); |
| 5985 | return false; |
| 5986 | } |
| 5987 | return true; |
| 5988 | } |
| 5989 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5990 | bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5991 | if (!state_.current_program.get()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5992 | // The program does not exist. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5993 | LOCAL_SET_GL_ERROR( |
| 5994 | GL_INVALID_OPERATION, function_name, "no program in use"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5995 | return false; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 5996 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5997 | if (!state_.current_program->InUse()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5998 | LOCAL_SET_GL_ERROR( |
| 5999 | GL_INVALID_OPERATION, function_name, "program not linked"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6000 | return false; |
| 6001 | } |
| 6002 | return true; |
| 6003 | } |
| 6004 | |
| 6005 | bool GLES2DecoderImpl::CheckCurrentProgramForUniform( |
| 6006 | GLint location, const char* function_name) { |
| 6007 | if (!CheckCurrentProgram(function_name)) { |
| 6008 | return false; |
| 6009 | } |
| 6010 | return location != -1; |
| 6011 | } |
| 6012 | |
zmo | f9a81360f | 2014-10-17 00:06:14 | [diff] [blame] | 6013 | bool GLES2DecoderImpl::CheckDrawingFeedbackLoops() { |
| 6014 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 6015 | if (!framebuffer) |
| 6016 | return false; |
| 6017 | const Framebuffer::Attachment* attachment = |
| 6018 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
| 6019 | if (!attachment) |
| 6020 | return false; |
| 6021 | |
| 6022 | DCHECK(state_.current_program.get()); |
| 6023 | const Program::SamplerIndices& sampler_indices = |
| 6024 | state_.current_program->sampler_indices(); |
| 6025 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 6026 | const Program::UniformInfo* uniform_info = |
| 6027 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
| 6028 | DCHECK(uniform_info); |
| 6029 | if (uniform_info->type != GL_SAMPLER_2D) |
| 6030 | continue; |
| 6031 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6032 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
| 6033 | if (texture_unit_index >= state_.texture_units.size()) |
| 6034 | continue; |
| 6035 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
| 6036 | TextureRef* texture_ref = |
| 6037 | texture_unit.GetInfoForSamplerType(GL_SAMPLER_2D).get(); |
| 6038 | if (attachment->IsTexture(texture_ref)) |
| 6039 | return true; |
| 6040 | } |
| 6041 | } |
| 6042 | return false; |
| 6043 | } |
| 6044 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 6045 | bool GLES2DecoderImpl::CheckUniformForApiType( |
| 6046 | const Program::UniformInfo* info, |
| 6047 | const char* function_name, |
| 6048 | Program::UniformApiType api_type) { |
| 6049 | DCHECK(info); |
| 6050 | if ((api_type & info->accepts_api_type) == 0) { |
| 6051 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 6052 | "wrong uniform function for type"); |
| 6053 | return false; |
| 6054 | } |
| 6055 | return true; |
| 6056 | } |
| 6057 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6058 | bool GLES2DecoderImpl::PrepForSetUniformByLocation( |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6059 | GLint fake_location, |
| 6060 | const char* function_name, |
| 6061 | Program::UniformApiType api_type, |
| 6062 | GLint* real_location, |
| 6063 | GLenum* type, |
| 6064 | GLsizei* count) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6065 | DCHECK(type); |
| 6066 | DCHECK(count); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6067 | DCHECK(real_location); |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 6068 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6069 | if (!CheckCurrentProgramForUniform(fake_location, function_name)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6070 | return false; |
| 6071 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6072 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6073 | const Program::UniformInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6074 | state_.current_program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6075 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6076 | if (!info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6077 | LOCAL_SET_GL_ERROR( |
| 6078 | GL_INVALID_OPERATION, function_name, "unknown location"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6079 | return false; |
| 6080 | } |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 6081 | if (!CheckUniformForApiType(info, function_name, api_type)) { |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 6082 | return false; |
| 6083 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6084 | if (*count > 1 && !info->is_array) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6085 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6086 | GL_INVALID_OPERATION, function_name, "count > 1 for non-array"); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6087 | return false; |
| 6088 | } |
| 6089 | *count = std::min(info->size - array_index, *count); |
| 6090 | if (*count <= 0) { |
| 6091 | return false; |
| 6092 | } |
| 6093 | *type = info->type; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6094 | return true; |
| 6095 | } |
| 6096 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6097 | void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) { |
| 6098 | GLenum type = 0; |
| 6099 | GLsizei count = 1; |
| 6100 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6101 | if (!PrepForSetUniformByLocation(fake_location, |
| 6102 | "glUniform1i", |
| 6103 | Program::kUniform1i, |
| 6104 | &real_location, |
| 6105 | &type, |
| 6106 | &count)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6107 | return; |
| 6108 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6109 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6110 | state_.texture_units.size(), fake_location, 1, &v0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6111 | LOCAL_SET_GL_ERROR( |
| 6112 | GL_INVALID_VALUE, "glUniform1i", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 6113 | return; |
| 6114 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6115 | glUniform1i(real_location, v0); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6116 | } |
| 6117 | |
| 6118 | void GLES2DecoderImpl::DoUniform1iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6119 | GLint fake_location, GLsizei count, const GLint *value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6120 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6121 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6122 | if (!PrepForSetUniformByLocation(fake_location, |
| 6123 | "glUniform1iv", |
| 6124 | Program::kUniform1i, |
| 6125 | &real_location, |
| 6126 | &type, |
| 6127 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6128 | return; |
| 6129 | } |
[email protected] | 7472711 | 2012-06-13 21:18:08 | [diff] [blame] | 6130 | if (type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || |
| 6131 | type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6132 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6133 | state_.texture_units.size(), fake_location, count, value)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6134 | LOCAL_SET_GL_ERROR( |
| 6135 | GL_INVALID_VALUE, "glUniform1iv", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 6136 | return; |
| 6137 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6138 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6139 | glUniform1iv(real_location, count, value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6140 | } |
| 6141 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6142 | void GLES2DecoderImpl::DoUniform1fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6143 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6144 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6145 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6146 | if (!PrepForSetUniformByLocation(fake_location, |
| 6147 | "glUniform1fv", |
| 6148 | Program::kUniform1f, |
| 6149 | &real_location, |
| 6150 | &type, |
| 6151 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6152 | return; |
| 6153 | } |
| 6154 | if (type == GL_BOOL) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6155 | scoped_ptr<GLint[]> temp(new GLint[count]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6156 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 6157 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6158 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6159 | DoUniform1iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6160 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6161 | glUniform1fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6162 | } |
| 6163 | } |
| 6164 | |
| 6165 | void GLES2DecoderImpl::DoUniform2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6166 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6167 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6168 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6169 | if (!PrepForSetUniformByLocation(fake_location, |
| 6170 | "glUniform2fv", |
| 6171 | Program::kUniform2f, |
| 6172 | &real_location, |
| 6173 | &type, |
| 6174 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6175 | return; |
| 6176 | } |
| 6177 | if (type == GL_BOOL_VEC2) { |
| 6178 | GLsizei num_values = count * 2; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6179 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6180 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 6181 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6182 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6183 | glUniform2iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6184 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6185 | glUniform2fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6186 | } |
| 6187 | } |
| 6188 | |
| 6189 | void GLES2DecoderImpl::DoUniform3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6190 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6191 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6192 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6193 | if (!PrepForSetUniformByLocation(fake_location, |
| 6194 | "glUniform3fv", |
| 6195 | Program::kUniform3f, |
| 6196 | &real_location, |
| 6197 | &type, |
| 6198 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6199 | return; |
| 6200 | } |
| 6201 | if (type == GL_BOOL_VEC3) { |
| 6202 | GLsizei num_values = count * 3; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6203 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6204 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 6205 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6206 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6207 | glUniform3iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6208 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6209 | glUniform3fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | void GLES2DecoderImpl::DoUniform4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6214 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6215 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6216 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6217 | if (!PrepForSetUniformByLocation(fake_location, |
| 6218 | "glUniform4fv", |
| 6219 | Program::kUniform4f, |
| 6220 | &real_location, |
| 6221 | &type, |
| 6222 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6223 | return; |
| 6224 | } |
| 6225 | if (type == GL_BOOL_VEC4) { |
| 6226 | GLsizei num_values = count * 4; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6227 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6228 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 6229 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6230 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6231 | glUniform4iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6232 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6233 | glUniform4fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6234 | } |
| 6235 | } |
| 6236 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6237 | void GLES2DecoderImpl::DoUniform2iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6238 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6239 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6240 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6241 | if (!PrepForSetUniformByLocation(fake_location, |
| 6242 | "glUniform2iv", |
| 6243 | Program::kUniform2i, |
| 6244 | &real_location, |
| 6245 | &type, |
| 6246 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6247 | return; |
| 6248 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6249 | glUniform2iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6250 | } |
| 6251 | |
| 6252 | void GLES2DecoderImpl::DoUniform3iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6253 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6254 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6255 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6256 | if (!PrepForSetUniformByLocation(fake_location, |
| 6257 | "glUniform3iv", |
| 6258 | Program::kUniform3i, |
| 6259 | &real_location, |
| 6260 | &type, |
| 6261 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6262 | return; |
| 6263 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6264 | glUniform3iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | void GLES2DecoderImpl::DoUniform4iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6268 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6269 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6270 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6271 | if (!PrepForSetUniformByLocation(fake_location, |
| 6272 | "glUniform4iv", |
| 6273 | Program::kUniform4i, |
| 6274 | &real_location, |
| 6275 | &type, |
| 6276 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6277 | return; |
| 6278 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6279 | glUniform4iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6280 | } |
| 6281 | |
| 6282 | void GLES2DecoderImpl::DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6283 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 6284 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6285 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6286 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6287 | if (!PrepForSetUniformByLocation(fake_location, |
| 6288 | "glUniformMatrix2fv", |
| 6289 | Program::kUniformMatrix2f, |
| 6290 | &real_location, |
| 6291 | &type, |
| 6292 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6293 | return; |
| 6294 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6295 | glUniformMatrix2fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6296 | } |
| 6297 | |
| 6298 | void GLES2DecoderImpl::DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6299 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 6300 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6301 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6302 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6303 | if (!PrepForSetUniformByLocation(fake_location, |
| 6304 | "glUniformMatrix3fv", |
| 6305 | Program::kUniformMatrix3f, |
| 6306 | &real_location, |
| 6307 | &type, |
| 6308 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6309 | return; |
| 6310 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6311 | glUniformMatrix3fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6312 | } |
| 6313 | |
| 6314 | void GLES2DecoderImpl::DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6315 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 6316 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6317 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6318 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6319 | if (!PrepForSetUniformByLocation(fake_location, |
| 6320 | "glUniformMatrix4fv", |
| 6321 | Program::kUniformMatrix4f, |
| 6322 | &real_location, |
| 6323 | &type, |
| 6324 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6325 | return; |
| 6326 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6327 | glUniformMatrix4fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6328 | } |
| 6329 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6330 | void GLES2DecoderImpl::DoUseProgram(GLuint program_id) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6331 | GLuint service_id = 0; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6332 | Program* program = NULL; |
| 6333 | if (program_id) { |
| 6334 | program = GetProgramInfoNotShader(program_id, "glUseProgram"); |
| 6335 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6336 | return; |
| 6337 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6338 | if (!program->IsValid()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6339 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6340 | LOCAL_SET_GL_ERROR( |
| 6341 | GL_INVALID_OPERATION, "glUseProgram", "program not linked"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6342 | return; |
| 6343 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6344 | service_id = program->service_id(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6345 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6346 | if (state_.current_program.get()) { |
| 6347 | program_manager()->UnuseProgram(shader_manager(), |
| 6348 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 6349 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6350 | state_.current_program = program; |
| 6351 | LogClientServiceMapping("glUseProgram", program_id, service_id); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 6352 | glUseProgram(service_id); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6353 | if (state_.current_program.get()) { |
| 6354 | program_manager()->UseProgram(state_.current_program.get()); |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 6355 | if (workarounds().clear_uniforms_before_first_program_use) |
| 6356 | program_manager()->ClearUniforms(program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 6357 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6358 | } |
| 6359 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6360 | void GLES2DecoderImpl::RenderWarning( |
| 6361 | const char* filename, int line, const std::string& msg) { |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 6362 | logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6363 | } |
| 6364 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6365 | void GLES2DecoderImpl::PerformanceWarning( |
| 6366 | const char* filename, int line, const std::string& msg) { |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 6367 | logger_.LogMessage(filename, line, |
| 6368 | std::string("PERFORMANCE WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6369 | } |
| 6370 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6371 | void GLES2DecoderImpl::DoWillUseTexImageIfNeeded( |
| 6372 | Texture* texture, GLenum textarget) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6373 | // Image is already in use if texture is attached to a framebuffer. |
| 6374 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 6375 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6376 | if (image) { |
| 6377 | ScopedGLErrorSuppressor suppressor( |
| 6378 | "GLES2DecoderImpl::DoWillUseTexImageIfNeeded", |
| 6379 | GetErrorState()); |
| 6380 | glBindTexture(textarget, texture->service_id()); |
| 6381 | image->WillUseTexImage(); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 6382 | RestoreCurrentTextureBindings(&state_, textarget); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6383 | } |
| 6384 | } |
| 6385 | } |
| 6386 | |
| 6387 | void GLES2DecoderImpl::DoDidUseTexImageIfNeeded( |
| 6388 | Texture* texture, GLenum textarget) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6389 | // Image is still in use if texture is attached to a framebuffer. |
| 6390 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 6391 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6392 | if (image) { |
| 6393 | ScopedGLErrorSuppressor suppressor( |
| 6394 | "GLES2DecoderImpl::DoDidUseTexImageIfNeeded", |
| 6395 | GetErrorState()); |
| 6396 | glBindTexture(textarget, texture->service_id()); |
| 6397 | image->DidUseTexImage(); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 6398 | RestoreCurrentTextureBindings(&state_, textarget); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6399 | } |
| 6400 | } |
| 6401 | } |
| 6402 | |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6403 | bool GLES2DecoderImpl::PrepareTexturesForRender() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6404 | DCHECK(state_.current_program.get()); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6405 | if (!texture_manager()->HaveUnrenderableTextures() && |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 6406 | !texture_manager()->HaveImages()) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6407 | return true; |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 6408 | } |
[email protected] | e2367b4 | 2013-05-31 03:37:21 | [diff] [blame] | 6409 | |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 6410 | bool textures_set = false; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6411 | const Program::SamplerIndices& sampler_indices = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6412 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6413 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6414 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6415 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6416 | DCHECK(uniform_info); |
| 6417 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6418 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6419 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6420 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6421 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 6422 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6423 | GLenum textarget = GetBindTargetForSamplerType(uniform_info->type); |
| 6424 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 6425 | textures_set = true; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6426 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6427 | glBindTexture( |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6428 | textarget, |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 6429 | texture_manager()->black_texture_id(uniform_info->type)); |
dongseong.hwang | 7d87d72 | 2015-01-14 20:02:40 | [diff] [blame] | 6430 | if (!texture_ref) { |
| 6431 | LOCAL_RENDER_WARNING( |
| 6432 | std::string("there is no texture bound to the unit ") + |
| 6433 | base::IntToString(texture_unit_index)); |
| 6434 | } else { |
| 6435 | LOCAL_RENDER_WARNING( |
| 6436 | std::string("texture bound to texture unit ") + |
| 6437 | base::IntToString(texture_unit_index) + |
| 6438 | " is not renderable. It maybe non-power-of-2 and have" |
| 6439 | " incompatible texture filtering."); |
| 6440 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6441 | continue; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6442 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6443 | |
[email protected] | 4e7b8920 | 2014-01-28 01:44:06 | [diff] [blame] | 6444 | if (textarget != GL_TEXTURE_CUBE_MAP) { |
| 6445 | Texture* texture = texture_ref->texture(); |
| 6446 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6447 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 6448 | ScopedGLErrorSuppressor suppressor( |
| 6449 | "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); |
| 6450 | textures_set = true; |
| 6451 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6452 | image->WillUseTexImage(); |
| 6453 | continue; |
| 6454 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6455 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6456 | } |
| 6457 | // else: should this be an error? |
| 6458 | } |
| 6459 | } |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6460 | return !textures_set; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6461 | } |
| 6462 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6463 | void GLES2DecoderImpl::RestoreStateForTextures() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6464 | DCHECK(state_.current_program.get()); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6465 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6466 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6467 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6468 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6469 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6470 | DCHECK(uniform_info); |
| 6471 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6472 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6473 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6474 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6475 | TextureRef* texture_ref = |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6476 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6477 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6478 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6479 | // Get the texture_ref info that was previously bound here. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6480 | texture_ref = texture_unit.bind_target == GL_TEXTURE_2D |
| 6481 | ? texture_unit.bound_texture_2d.get() |
| 6482 | : texture_unit.bound_texture_cube_map.get(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6483 | glBindTexture(texture_unit.bind_target, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6484 | texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6485 | continue; |
| 6486 | } |
| 6487 | |
[email protected] | 4e7b8920 | 2014-01-28 01:44:06 | [diff] [blame] | 6488 | if (texture_unit.bind_target != GL_TEXTURE_CUBE_MAP) { |
| 6489 | Texture* texture = texture_ref->texture(); |
| 6490 | gfx::GLImage* image = |
| 6491 | texture->GetLevelImage(texture_unit.bind_target, 0); |
| 6492 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 6493 | ScopedGLErrorSuppressor suppressor( |
| 6494 | "GLES2DecoderImpl::RestoreStateForTextures", GetErrorState()); |
| 6495 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6496 | image->DidUseTexImage(); |
| 6497 | continue; |
| 6498 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6499 | } |
| 6500 | } |
| 6501 | } |
| 6502 | } |
| 6503 | // Set the active texture back to whatever the user had it as. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6504 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6505 | } |
| 6506 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6507 | bool GLES2DecoderImpl::ClearUnclearedTextures() { |
| 6508 | // Only check if there are some uncleared textures. |
| 6509 | if (!texture_manager()->HaveUnsafeTextures()) { |
| 6510 | return true; |
| 6511 | } |
| 6512 | |
| 6513 | // 1: Check all textures we are about to render with. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6514 | if (state_.current_program.get()) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6515 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6516 | state_.current_program->sampler_indices(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6517 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6518 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6519 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6520 | DCHECK(uniform_info); |
| 6521 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6522 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6523 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6524 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6525 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 6526 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6527 | if (texture_ref && !texture_ref->texture()->SafeToRenderFrom()) { |
| 6528 | if (!texture_manager()->ClearRenderableLevels(this, texture_ref)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6529 | return false; |
| 6530 | } |
| 6531 | } |
| 6532 | } |
| 6533 | } |
| 6534 | } |
| 6535 | } |
| 6536 | return true; |
| 6537 | } |
| 6538 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6539 | bool GLES2DecoderImpl::IsDrawValid( |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6540 | const char* function_name, GLuint max_vertex_accessed, bool instanced, |
| 6541 | GLsizei primcount) { |
| 6542 | DCHECK(instanced || primcount == 1); |
| 6543 | |
[email protected] | 689fa1c5 | 2010-06-09 18:35:03 | [diff] [blame] | 6544 | // NOTE: We specifically do not check current_program->IsValid() because |
| 6545 | // it could never be invalid since glUseProgram would have failed. While |
| 6546 | // glLinkProgram could later mark the program as invalid the previous |
| 6547 | // valid program will still function if it is still the current program. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6548 | if (!state_.current_program.get()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6549 | // The program does not exist. |
| 6550 | // But GL says no ERROR. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6551 | LOCAL_RENDER_WARNING("Drawing with no current shader program."); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6552 | return false; |
| 6553 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6554 | |
zmo | f9a81360f | 2014-10-17 00:06:14 | [diff] [blame] | 6555 | if (CheckDrawingFeedbackLoops()) { |
| 6556 | LOCAL_SET_GL_ERROR( |
| 6557 | GL_INVALID_OPERATION, function_name, |
| 6558 | "Source and destination textures of the draw are the same."); |
| 6559 | return false; |
| 6560 | } |
| 6561 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6562 | return state_.vertex_attrib_manager |
| 6563 | ->ValidateBindings(function_name, |
| 6564 | this, |
| 6565 | feature_info_.get(), |
| 6566 | state_.current_program.get(), |
| 6567 | max_vertex_accessed, |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6568 | instanced, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6569 | primcount); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6570 | } |
| 6571 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6572 | bool GLES2DecoderImpl::SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6573 | const char* function_name, GLuint max_vertex_accessed, bool* simulated) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6574 | DCHECK(simulated); |
| 6575 | *simulated = false; |
| 6576 | |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6577 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6578 | return true; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6579 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6580 | const VertexAttrib* attrib = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6581 | state_.vertex_attrib_manager->GetVertexAttrib(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6582 | // 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] | 6583 | bool attrib_0_used = |
| 6584 | state_.current_program->GetAttribInfoByLocation(0) != NULL; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6585 | if (attrib->enabled() && attrib_0_used) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6586 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6587 | } |
| 6588 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6589 | // Make a buffer with a single repeated vec4 value enough to |
| 6590 | // simulate the constant value that is supposed to be here. |
| 6591 | // This is required to emulate GLES2 on GL. |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6592 | GLuint num_vertices = max_vertex_accessed + 1; |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6593 | uint32 size_needed = 0; |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6594 | |
| 6595 | if (num_vertices == 0 || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6596 | !SafeMultiplyUint32(num_vertices, sizeof(Vec4), &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6597 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6598 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6599 | return false; |
| 6600 | } |
| 6601 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6602 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6603 | "Attribute 0 is disabled. This has signficant performance penalty"); |
| 6604 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6605 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6606 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 6607 | |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 6608 | bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; |
| 6609 | if (new_buffer) { |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6610 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6611 | GLenum error = glGetError(); |
| 6612 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6613 | LOCAL_SET_GL_ERROR( |
| 6614 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6615 | return false; |
| 6616 | } |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6617 | } |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6618 | |
| 6619 | const Vec4& value = state_.attrib_values[0]; |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 6620 | if (new_buffer || |
| 6621 | (attrib_0_used && |
| 6622 | (!attrib_0_buffer_matches_value_ || |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6623 | (value.v[0] != attrib_0_value_.v[0] || |
| 6624 | value.v[1] != attrib_0_value_.v[1] || |
| 6625 | value.v[2] != attrib_0_value_.v[2] || |
| 6626 | value.v[3] != attrib_0_value_.v[3])))) { |
| 6627 | std::vector<Vec4> temp(num_vertices, value); |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6628 | glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); |
| 6629 | attrib_0_buffer_matches_value_ = true; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 6630 | attrib_0_value_ = value; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6631 | attrib_0_size_ = size_needed; |
| 6632 | } |
| 6633 | |
| 6634 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 6635 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6636 | if (attrib->divisor()) |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6637 | glVertexAttribDivisorANGLE(0, 0); |
| 6638 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6639 | *simulated = true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6640 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6641 | } |
| 6642 | |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 6643 | void GLES2DecoderImpl::RestoreStateForAttrib( |
| 6644 | GLuint attrib_index, bool restore_array_binding) { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6645 | const VertexAttrib* attrib = |
| 6646 | state_.vertex_attrib_manager->GetVertexAttrib(attrib_index); |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 6647 | if (restore_array_binding) { |
| 6648 | const void* ptr = reinterpret_cast<const void*>(attrib->offset()); |
| 6649 | Buffer* buffer = attrib->buffer(); |
| 6650 | glBindBuffer(GL_ARRAY_BUFFER, buffer ? buffer->service_id() : 0); |
| 6651 | glVertexAttribPointer( |
| 6652 | attrib_index, attrib->size(), attrib->type(), attrib->normalized(), |
| 6653 | attrib->gl_stride(), ptr); |
| 6654 | } |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6655 | if (attrib->divisor()) |
| 6656 | glVertexAttribDivisorANGLE(attrib_index, attrib->divisor()); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6657 | glBindBuffer( |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 6658 | GL_ARRAY_BUFFER, state_.bound_array_buffer.get() ? |
| 6659 | state_.bound_array_buffer->service_id() : 0); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6660 | |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6661 | // Never touch vertex attribute 0's state (in particular, never |
| 6662 | // disable it) when running on desktop GL because it will never be |
| 6663 | // re-enabled. |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6664 | if (attrib_index != 0 || |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6665 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6666 | if (attrib->enabled()) { |
| 6667 | glEnableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6668 | } else { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6669 | glDisableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 6670 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 6671 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6672 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6673 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6674 | bool GLES2DecoderImpl::SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6675 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6676 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6677 | DCHECK(simulated); |
| 6678 | *simulated = false; |
| 6679 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
| 6680 | return true; |
| 6681 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6682 | if (!state_.vertex_attrib_manager->HaveFixedAttribs()) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6683 | return true; |
| 6684 | } |
| 6685 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6686 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6687 | "GL_FIXED attributes have a signficant performance penalty"); |
| 6688 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6689 | // NOTE: we could be smart and try to check if a buffer is used |
| 6690 | // twice in 2 different attribs, find the overlapping parts and therefore |
| 6691 | // duplicate the minimum amount of data but this whole code path is not meant |
| 6692 | // to be used normally. It's just here to pass that OpenGL ES 2.0 conformance |
| 6693 | // tests so we just add to the buffer attrib used. |
| 6694 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6695 | GLuint elements_needed = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6696 | const VertexAttribManager::VertexAttribList& enabled_attribs = |
| 6697 | state_.vertex_attrib_manager->GetEnabledVertexAttribs(); |
| 6698 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 6699 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 6700 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6701 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6702 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 6703 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
| 6704 | max_vertex_accessed); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6705 | GLuint num_vertices = max_accessed + 1; |
| 6706 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6707 | LOCAL_SET_GL_ERROR( |
| 6708 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6709 | return false; |
| 6710 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6711 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6712 | attrib->CanAccess(max_accessed) && |
| 6713 | attrib->type() == GL_FIXED) { |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6714 | uint32 elements_used = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6715 | if (!SafeMultiplyUint32(num_vertices, attrib->size(), &elements_used) || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6716 | !SafeAddUint32(elements_needed, elements_used, &elements_needed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6717 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6718 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6719 | return false; |
| 6720 | } |
| 6721 | } |
| 6722 | } |
| 6723 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6724 | const uint32 kSizeOfFloat = sizeof(float); // NOLINT |
| 6725 | uint32 size_needed = 0; |
| 6726 | if (!SafeMultiplyUint32(elements_needed, kSizeOfFloat, &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6727 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6728 | LOCAL_SET_GL_ERROR( |
| 6729 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6730 | return false; |
| 6731 | } |
| 6732 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6733 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6734 | |
| 6735 | glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6736 | if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6737 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6738 | GLenum error = glGetError(); |
| 6739 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6740 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6741 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6742 | return false; |
| 6743 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6744 | } |
| 6745 | |
| 6746 | // Copy the elements and convert to float |
| 6747 | GLintptr offset = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6748 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 6749 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 6750 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6751 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6752 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 6753 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6754 | max_vertex_accessed); |
| 6755 | GLuint num_vertices = max_accessed + 1; |
| 6756 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6757 | LOCAL_SET_GL_ERROR( |
| 6758 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6759 | return false; |
| 6760 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6761 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6762 | attrib->CanAccess(max_accessed) && |
| 6763 | attrib->type() == GL_FIXED) { |
penghuang | 5a3210b | 2014-10-29 18:24:36 | [diff] [blame] | 6764 | int num_elements = attrib->size() * num_vertices; |
| 6765 | const int src_size = num_elements * sizeof(int32); |
| 6766 | const int dst_size = num_elements * sizeof(float); |
| 6767 | scoped_ptr<float[]> data(new float[num_elements]); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6768 | const int32* src = reinterpret_cast<const int32 *>( |
penghuang | 5a3210b | 2014-10-29 18:24:36 | [diff] [blame] | 6769 | attrib->buffer()->GetRange(attrib->offset(), src_size)); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6770 | const int32* end = src + num_elements; |
| 6771 | float* dst = data.get(); |
| 6772 | while (src != end) { |
| 6773 | *dst++ = static_cast<float>(*src++) / 65536.0f; |
| 6774 | } |
penghuang | 5a3210b | 2014-10-29 18:24:36 | [diff] [blame] | 6775 | glBufferSubData(GL_ARRAY_BUFFER, offset, dst_size, data.get()); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6776 | glVertexAttribPointer( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6777 | attrib->index(), attrib->size(), GL_FLOAT, false, 0, |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6778 | reinterpret_cast<GLvoid*>(offset)); |
penghuang | 5a3210b | 2014-10-29 18:24:36 | [diff] [blame] | 6779 | offset += dst_size; |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6780 | } |
| 6781 | } |
| 6782 | *simulated = true; |
| 6783 | return true; |
| 6784 | } |
| 6785 | |
| 6786 | void GLES2DecoderImpl::RestoreStateForSimulatedFixedAttribs() { |
| 6787 | // There's no need to call glVertexAttribPointer because we shadow all the |
| 6788 | // settings and passing GL_FIXED to it will not work. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6789 | glBindBuffer( |
| 6790 | GL_ARRAY_BUFFER, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6791 | state_.bound_array_buffer.get() ? state_.bound_array_buffer->service_id() |
| 6792 | : 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6793 | } |
| 6794 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6795 | error::Error GLES2DecoderImpl::DoDrawArrays( |
| 6796 | const char* function_name, |
| 6797 | bool instanced, |
| 6798 | GLenum mode, |
| 6799 | GLint first, |
| 6800 | GLsizei count, |
| 6801 | GLsizei primcount) { |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 6802 | error::Error error = WillAccessBoundFramebufferForDraw(); |
| 6803 | if (error != error::kNoError) |
| 6804 | return error; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6805 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6806 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6807 | return error::kNoError; |
| 6808 | } |
| 6809 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6810 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6811 | return error::kNoError; |
| 6812 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6813 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6814 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6815 | return error::kNoError; |
| 6816 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6817 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6818 | return error::kNoError; |
| 6819 | } |
| 6820 | // We have to check this here because the prototype for glDrawArrays |
| 6821 | // is GLint not GLsizei. |
| 6822 | if (first < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6823 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "first < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6824 | return error::kNoError; |
| 6825 | } |
| 6826 | |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6827 | if (count == 0 || primcount == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6828 | LOCAL_RENDER_WARNING("Render count or primcount is 0."); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6829 | return error::kNoError; |
| 6830 | } |
| 6831 | |
| 6832 | GLuint max_vertex_accessed = first + count - 1; |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6833 | if (IsDrawValid(function_name, max_vertex_accessed, instanced, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6834 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6835 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6836 | return error::kNoError; |
| 6837 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6838 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6839 | if (!SimulateAttrib0( |
| 6840 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6841 | return error::kNoError; |
| 6842 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6843 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6844 | if (SimulateFixedAttribs( |
| 6845 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 6846 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6847 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6848 | ApplyDirtyState(); |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 6849 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6850 | if (!instanced) { |
| 6851 | glDrawArrays(mode, first, count); |
| 6852 | } else { |
| 6853 | glDrawArraysInstancedANGLE(mode, first, count, primcount); |
| 6854 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6855 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6856 | RestoreStateForTextures(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6857 | } |
| 6858 | if (simulated_fixed_attribs) { |
| 6859 | RestoreStateForSimulatedFixedAttribs(); |
| 6860 | } |
| 6861 | } |
| 6862 | if (simulated_attrib_0) { |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 6863 | // We don't have to restore attrib 0 generic data at the end of this |
| 6864 | // function even if it is simulated. This is because we will simulate |
| 6865 | // it in each draw call, and attrib 0 generic data queries use cached |
| 6866 | // values instead of passing down to the underlying driver. |
| 6867 | RestoreStateForAttrib(0, false); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6868 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 6869 | } |
| 6870 | return error::kNoError; |
| 6871 | } |
| 6872 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6873 | error::Error GLES2DecoderImpl::HandleDrawArrays(uint32 immediate_data_size, |
| 6874 | const void* cmd_data) { |
| 6875 | const cmds::DrawArrays& c = *static_cast<const cmds::DrawArrays*>(cmd_data); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6876 | return DoDrawArrays("glDrawArrays", |
| 6877 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6878 | static_cast<GLenum>(c.mode), |
| 6879 | static_cast<GLint>(c.first), |
| 6880 | static_cast<GLsizei>(c.count), |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6881 | 1); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6882 | } |
| 6883 | |
| 6884 | error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 6885 | uint32 immediate_data_size, |
| 6886 | const void* cmd_data) { |
| 6887 | const gles2::cmds::DrawArraysInstancedANGLE& c = |
| 6888 | *static_cast<const gles2::cmds::DrawArraysInstancedANGLE*>(cmd_data); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 6889 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6890 | LOCAL_SET_GL_ERROR( |
| 6891 | GL_INVALID_OPERATION, |
| 6892 | "glDrawArraysInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6893 | return error::kNoError; |
| 6894 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6895 | return DoDrawArrays("glDrawArraysIntancedANGLE", |
| 6896 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6897 | static_cast<GLenum>(c.mode), |
| 6898 | static_cast<GLint>(c.first), |
| 6899 | static_cast<GLsizei>(c.count), |
| 6900 | static_cast<GLsizei>(c.primcount)); |
| 6901 | } |
| 6902 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6903 | error::Error GLES2DecoderImpl::DoDrawElements( |
| 6904 | const char* function_name, |
| 6905 | bool instanced, |
| 6906 | GLenum mode, |
| 6907 | GLsizei count, |
| 6908 | GLenum type, |
| 6909 | int32 offset, |
| 6910 | GLsizei primcount) { |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 6911 | error::Error error = WillAccessBoundFramebufferForDraw(); |
| 6912 | if (error != error::kNoError) |
| 6913 | return error; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6914 | if (!state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6915 | LOCAL_SET_GL_ERROR( |
| 6916 | GL_INVALID_OPERATION, function_name, "No element array buffer bound"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6917 | return error::kNoError; |
| 6918 | } |
| 6919 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6920 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6921 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6922 | return error::kNoError; |
| 6923 | } |
| 6924 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6925 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6926 | return error::kNoError; |
| 6927 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6928 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6929 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6930 | return error::kNoError; |
| 6931 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 6932 | if (!validators_->index_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6933 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6934 | return error::kNoError; |
| 6935 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6936 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6937 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6938 | return error::kNoError; |
| 6939 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6940 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6941 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 6942 | return error::kNoError; |
| 6943 | } |
| 6944 | |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6945 | if (count == 0 || primcount == 0) { |
[email protected] | 6c788fb7 | 2010-08-26 02:16:31 | [diff] [blame] | 6946 | return error::kNoError; |
| 6947 | } |
| 6948 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6949 | GLuint max_vertex_accessed; |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6950 | Buffer* element_array_buffer = |
| 6951 | state_.vertex_attrib_manager->element_array_buffer(); |
| 6952 | |
| 6953 | if (!element_array_buffer->GetMaxValueForRange( |
| 6954 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6955 | LOCAL_SET_GL_ERROR( |
| 6956 | GL_INVALID_OPERATION, function_name, "range out of bounds for buffer"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 6957 | return error::kNoError; |
| 6958 | } |
| 6959 | |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6960 | if (IsDrawValid(function_name, max_vertex_accessed, instanced, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6961 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6962 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6963 | return error::kNoError; |
| 6964 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6965 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6966 | if (!SimulateAttrib0( |
| 6967 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6968 | return error::kNoError; |
| 6969 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6970 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6971 | if (SimulateFixedAttribs( |
| 6972 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 6973 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6974 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 6975 | ApplyDirtyState(); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6976 | // TODO(gman): Refactor to hide these details in BufferManager or |
| 6977 | // VertexAttribManager. |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6978 | const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6979 | bool used_client_side_array = false; |
| 6980 | if (element_array_buffer->IsClientSideArray()) { |
| 6981 | used_client_side_array = true; |
| 6982 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 6983 | indices = element_array_buffer->GetRange(offset, 0); |
| 6984 | } |
| 6985 | |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 6986 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6987 | if (!instanced) { |
| 6988 | glDrawElements(mode, count, type, indices); |
| 6989 | } else { |
| 6990 | glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); |
| 6991 | } |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 6992 | |
| 6993 | if (used_client_side_array) { |
| 6994 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 6995 | element_array_buffer->service_id()); |
| 6996 | } |
| 6997 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 6998 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6999 | RestoreStateForTextures(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7000 | } |
| 7001 | if (simulated_fixed_attribs) { |
| 7002 | RestoreStateForSimulatedFixedAttribs(); |
| 7003 | } |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7004 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7005 | if (simulated_attrib_0) { |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 7006 | // We don't have to restore attrib 0 generic data at the end of this |
| 7007 | // function even if it is simulated. This is because we will simulate |
| 7008 | // it in each draw call, and attrib 0 generic data queries use cached |
| 7009 | // values instead of passing down to the underlying driver. |
| 7010 | RestoreStateForAttrib(0, false); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7011 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7012 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7013 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7014 | } |
| 7015 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7016 | error::Error GLES2DecoderImpl::HandleDrawElements(uint32 immediate_data_size, |
| 7017 | const void* cmd_data) { |
| 7018 | const gles2::cmds::DrawElements& c = |
| 7019 | *static_cast<const gles2::cmds::DrawElements*>(cmd_data); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7020 | return DoDrawElements("glDrawElements", |
| 7021 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7022 | static_cast<GLenum>(c.mode), |
| 7023 | static_cast<GLsizei>(c.count), |
| 7024 | static_cast<GLenum>(c.type), |
| 7025 | static_cast<int32>(c.index_offset), |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 7026 | 1); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7027 | } |
| 7028 | |
| 7029 | error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7030 | uint32 immediate_data_size, |
| 7031 | const void* cmd_data) { |
| 7032 | const gles2::cmds::DrawElementsInstancedANGLE& c = |
| 7033 | *static_cast<const gles2::cmds::DrawElementsInstancedANGLE*>(cmd_data); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 7034 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7035 | LOCAL_SET_GL_ERROR( |
| 7036 | GL_INVALID_OPERATION, |
| 7037 | "glDrawElementsInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7038 | return error::kNoError; |
| 7039 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7040 | return DoDrawElements("glDrawElementsInstancedANGLE", |
| 7041 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7042 | static_cast<GLenum>(c.mode), |
| 7043 | static_cast<GLsizei>(c.count), |
| 7044 | static_cast<GLenum>(c.type), |
| 7045 | static_cast<int32>(c.index_offset), |
| 7046 | static_cast<GLsizei>(c.primcount)); |
| 7047 | } |
| 7048 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 7049 | GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 7050 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { |
| 7051 | GLuint max_vertex_accessed = 0; |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 7052 | Buffer* buffer = GetBuffer(buffer_id); |
| 7053 | if (!buffer) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7054 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7055 | LOCAL_SET_GL_ERROR( |
| 7056 | GL_INVALID_VALUE, "GetMaxValueInBufferCHROMIUM", "unknown buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 7057 | } else { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 7058 | if (!buffer->GetMaxValueForRange( |
| 7059 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7060 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7061 | LOCAL_SET_GL_ERROR( |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 7062 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7063 | "GetMaxValueInBufferCHROMIUM", "range out of bounds for buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 7064 | } |
| 7065 | } |
| 7066 | return max_vertex_accessed; |
| 7067 | } |
| 7068 | |
zmo | 1bb3d1d | 2015-01-21 20:29:43 | [diff] [blame^] | 7069 | void GLES2DecoderImpl::DoShaderSource( |
| 7070 | GLuint client_id, GLsizei count, const char** data, const GLint* length) { |
| 7071 | std::string str; |
| 7072 | for (GLsizei ii = 0; ii < count; ++ii) { |
| 7073 | str.append(data[ii]); |
| 7074 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7075 | Shader* shader = GetShaderInfoNotProgram(client_id, "glShaderSource"); |
| 7076 | if (!shader) { |
zmo | 1bb3d1d | 2015-01-21 20:29:43 | [diff] [blame^] | 7077 | return; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7078 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 7079 | // Note: We don't actually call glShaderSource here. We wait until |
| 7080 | // the call to glCompileShader. |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7081 | shader->set_source(str); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7082 | } |
| 7083 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7084 | void GLES2DecoderImpl::DoCompileShader(GLuint client_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 7085 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompileShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7086 | Shader* shader = GetShaderInfoNotProgram(client_id, "glCompileShader"); |
| 7087 | if (!shader) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 7088 | return; |
| 7089 | } |
[email protected] | f57bb28 | 2010-11-12 00:51:34 | [diff] [blame] | 7090 | ShaderTranslator* translator = NULL; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7091 | if (use_shader_translator_) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7092 | translator = shader->shader_type() == GL_VERTEX_SHADER ? |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 7093 | vertex_translator_.get() : fragment_translator_.get(); |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 7094 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 7095 | |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7096 | shader->DoCompile( |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 7097 | translator, |
| 7098 | feature_info_->feature_flags().angle_translated_shader_source ? |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7099 | Shader::kANGLE : Shader::kGL); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 7100 | |
| 7101 | // CompileShader can be very slow. Exit command processing to allow for |
| 7102 | // context preemption and GPU watchdog checks. |
| 7103 | ExitCommandProcessingEarly(); |
| 7104 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 7105 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7106 | void GLES2DecoderImpl::DoGetShaderiv( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7107 | GLuint shader_id, GLenum pname, GLint* params) { |
| 7108 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderiv"); |
| 7109 | if (!shader) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7110 | return; |
| 7111 | } |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 7112 | switch (pname) { |
| 7113 | case GL_SHADER_SOURCE_LENGTH: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7114 | *params = shader->source().size(); |
| 7115 | if (*params) |
| 7116 | ++(*params); |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 7117 | return; |
| 7118 | case GL_COMPILE_STATUS: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7119 | *params = compile_shader_always_succeeds_ ? true : shader->valid(); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 7120 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 7121 | case GL_INFO_LOG_LENGTH: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7122 | *params = shader->log_info().size(); |
| 7123 | if (*params) |
| 7124 | ++(*params); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 7125 | return; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7126 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7127 | *params = shader->translated_source().size(); |
| 7128 | if (*params) |
| 7129 | ++(*params); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7130 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 7131 | default: |
| 7132 | break; |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7133 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7134 | glGetShaderiv(shader->service_id(), pname, params); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7135 | } |
| 7136 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7137 | error::Error GLES2DecoderImpl::HandleGetShaderSource(uint32 immediate_data_size, |
| 7138 | const void* cmd_data) { |
| 7139 | const gles2::cmds::GetShaderSource& c = |
| 7140 | *static_cast<const gles2::cmds::GetShaderSource*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7141 | GLuint shader_id = c.shader; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7142 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 7143 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7144 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderSource"); |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7145 | if (!shader || shader->source().empty()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7146 | bucket->SetSize(0); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7147 | return error::kNoError; |
| 7148 | } |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7149 | bucket->SetFromString(shader->source().c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7150 | return error::kNoError; |
| 7151 | } |
| 7152 | |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7153 | error::Error GLES2DecoderImpl::HandleGetTranslatedShaderSourceANGLE( |
| 7154 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7155 | const void* cmd_data) { |
| 7156 | const gles2::cmds::GetTranslatedShaderSourceANGLE& c = |
| 7157 | *static_cast<const gles2::cmds::GetTranslatedShaderSourceANGLE*>( |
| 7158 | cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7159 | GLuint shader_id = c.shader; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7160 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 7161 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7162 | Shader* shader = GetShaderInfoNotProgram( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7163 | shader_id, "glGetTranslatedShaderSourceANGLE"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7164 | if (!shader) { |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7165 | bucket->SetSize(0); |
| 7166 | return error::kNoError; |
| 7167 | } |
| 7168 | |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7169 | bucket->SetFromString(shader->translated_source().c_str()); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7170 | return error::kNoError; |
| 7171 | } |
| 7172 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7173 | error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7174 | uint32 immediate_data_size, |
| 7175 | const void* cmd_data) { |
| 7176 | const gles2::cmds::GetProgramInfoLog& c = |
| 7177 | *static_cast<const gles2::cmds::GetProgramInfoLog*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7178 | GLuint program_id = c.program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7179 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 7180 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7181 | Program* program = GetProgramInfoNotShader( |
| 7182 | program_id, "glGetProgramInfoLog"); |
| 7183 | if (!program || !program->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 7184 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7185 | return error::kNoError; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 7186 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7187 | bucket->SetFromString(program->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7188 | return error::kNoError; |
| 7189 | } |
| 7190 | |
| 7191 | error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7192 | uint32 immediate_data_size, |
| 7193 | const void* cmd_data) { |
| 7194 | const gles2::cmds::GetShaderInfoLog& c = |
| 7195 | *static_cast<const gles2::cmds::GetShaderInfoLog*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7196 | GLuint shader_id = c.shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7197 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 7198 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7199 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderInfoLog"); |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7200 | if (!shader) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 7201 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7202 | return error::kNoError; |
| 7203 | } |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7204 | bucket->SetFromString(shader->log_info().c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7205 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7206 | } |
| 7207 | |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 7208 | bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) { |
| 7209 | return state_.GetEnabled(cap); |
| 7210 | } |
| 7211 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7212 | bool GLES2DecoderImpl::DoIsBuffer(GLuint client_id) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 7213 | const Buffer* buffer = GetBuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7214 | return buffer && buffer->IsValid() && !buffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7215 | } |
| 7216 | |
| 7217 | bool GLES2DecoderImpl::DoIsFramebuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7218 | const Framebuffer* framebuffer = |
| 7219 | GetFramebuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7220 | return framebuffer && framebuffer->IsValid() && !framebuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7221 | } |
| 7222 | |
| 7223 | bool GLES2DecoderImpl::DoIsProgram(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 7224 | // IsProgram is true for programs as soon as they are created, until they are |
| 7225 | // deleted and no longer in use. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7226 | const Program* program = GetProgram(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7227 | return program != NULL && !program->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7228 | } |
| 7229 | |
| 7230 | bool GLES2DecoderImpl::DoIsRenderbuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7231 | const Renderbuffer* renderbuffer = |
| 7232 | GetRenderbuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7233 | return renderbuffer && renderbuffer->IsValid() && !renderbuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7234 | } |
| 7235 | |
| 7236 | bool GLES2DecoderImpl::DoIsShader(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 7237 | // IsShader is true for shaders as soon as they are created, until they |
| 7238 | // are deleted and not attached to any programs. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7239 | const Shader* shader = GetShader(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7240 | return shader != NULL && !shader->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7241 | } |
| 7242 | |
| 7243 | bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7244 | const TextureRef* texture_ref = GetTexture(client_id); |
| 7245 | return texture_ref && texture_ref->texture()->IsValid(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7246 | } |
| 7247 | |
| 7248 | void GLES2DecoderImpl::DoAttachShader( |
| 7249 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7250 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7251 | program_client_id, "glAttachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7252 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7253 | return; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7254 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7255 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glAttachShader"); |
| 7256 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7257 | return; |
| 7258 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7259 | if (!program->AttachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7260 | LOCAL_SET_GL_ERROR( |
| 7261 | GL_INVALID_OPERATION, |
| 7262 | "glAttachShader", |
| 7263 | "can not attach more than one shader of the same type."); |
[email protected] | fb96c8e | 2010-08-12 04:10:31 | [diff] [blame] | 7264 | return; |
| 7265 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7266 | glAttachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7267 | } |
| 7268 | |
| 7269 | void GLES2DecoderImpl::DoDetachShader( |
| 7270 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7271 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7272 | program_client_id, "glDetachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7273 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7274 | return; |
| 7275 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7276 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glDetachShader"); |
| 7277 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7278 | return; |
| 7279 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7280 | if (!program->DetachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7281 | LOCAL_SET_GL_ERROR( |
| 7282 | GL_INVALID_OPERATION, |
| 7283 | "glDetachShader", "shader not attached to program"); |
[email protected] | 9a0ccd4 | 2011-03-16 23:58:22 | [diff] [blame] | 7284 | return; |
| 7285 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7286 | glDetachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7287 | } |
| 7288 | |
| 7289 | void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7290 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7291 | program_client_id, "glValidateProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7292 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7293 | return; |
| 7294 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7295 | program->Validate(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7296 | } |
| 7297 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7298 | void GLES2DecoderImpl::GetVertexAttribHelper( |
| 7299 | const VertexAttrib* attrib, GLenum pname, GLint* params) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7300 | switch (pname) { |
| 7301 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7302 | Buffer* buffer = attrib->buffer(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7303 | if (buffer && !buffer->IsDeleted()) { |
| 7304 | GLuint client_id; |
| 7305 | buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
| 7306 | *params = client_id; |
| 7307 | } |
| 7308 | break; |
| 7309 | } |
| 7310 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7311 | *params = attrib->enabled(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7312 | break; |
| 7313 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7314 | *params = attrib->size(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7315 | break; |
| 7316 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7317 | *params = attrib->gl_stride(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7318 | break; |
| 7319 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7320 | *params = attrib->type(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7321 | break; |
| 7322 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7323 | *params = attrib->normalized(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7324 | break; |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7325 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7326 | *params = attrib->divisor(); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7327 | break; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7328 | default: |
| 7329 | NOTREACHED(); |
| 7330 | break; |
| 7331 | } |
| 7332 | } |
| 7333 | |
[email protected] | 4c6f546 | 2014-03-05 00:26:56 | [diff] [blame] | 7334 | void GLES2DecoderImpl::DoGetTexParameterfv( |
| 7335 | GLenum target, GLenum pname, GLfloat* params) { |
| 7336 | InitTextureMaxAnisotropyIfNeeded(target, pname); |
| 7337 | glGetTexParameterfv(target, pname, params); |
| 7338 | } |
| 7339 | |
| 7340 | void GLES2DecoderImpl::DoGetTexParameteriv( |
| 7341 | GLenum target, GLenum pname, GLint* params) { |
| 7342 | InitTextureMaxAnisotropyIfNeeded(target, pname); |
| 7343 | glGetTexParameteriv(target, pname, params); |
| 7344 | } |
| 7345 | |
| 7346 | void GLES2DecoderImpl::InitTextureMaxAnisotropyIfNeeded( |
| 7347 | GLenum target, GLenum pname) { |
| 7348 | if (!workarounds().init_texture_max_anisotropy) |
| 7349 | return; |
| 7350 | if (pname != GL_TEXTURE_MAX_ANISOTROPY_EXT || |
| 7351 | !validators_->texture_parameter.IsValid(pname)) { |
| 7352 | return; |
| 7353 | } |
| 7354 | |
| 7355 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 7356 | &state_, target); |
| 7357 | if (!texture_ref) { |
| 7358 | LOCAL_SET_GL_ERROR( |
| 7359 | GL_INVALID_OPERATION, |
| 7360 | "glGetTexParamter{fi}v", "unknown texture for target"); |
| 7361 | return; |
| 7362 | } |
| 7363 | Texture* texture = texture_ref->texture(); |
| 7364 | texture->InitTextureMaxAnisotropyIfNeeded(target); |
| 7365 | } |
| 7366 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7367 | void GLES2DecoderImpl::DoGetVertexAttribfv( |
| 7368 | GLuint index, GLenum pname, GLfloat* params) { |
| 7369 | VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| 7370 | if (!attrib) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7371 | LOCAL_SET_GL_ERROR( |
| 7372 | GL_INVALID_VALUE, "glGetVertexAttribfv", "index out of range"); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7373 | return; |
| 7374 | } |
| 7375 | switch (pname) { |
| 7376 | case GL_CURRENT_VERTEX_ATTRIB: { |
| 7377 | const Vec4& value = state_.attrib_values[index]; |
| 7378 | params[0] = value.v[0]; |
| 7379 | params[1] = value.v[1]; |
| 7380 | params[2] = value.v[2]; |
| 7381 | params[3] = value.v[3]; |
| 7382 | break; |
| 7383 | } |
| 7384 | default: { |
| 7385 | GLint value = 0; |
| 7386 | GetVertexAttribHelper(attrib, pname, &value); |
| 7387 | *params = static_cast<GLfloat>(value); |
| 7388 | break; |
| 7389 | } |
| 7390 | } |
| 7391 | } |
| 7392 | |
| 7393 | void GLES2DecoderImpl::DoGetVertexAttribiv( |
| 7394 | GLuint index, GLenum pname, GLint* params) { |
| 7395 | VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| 7396 | if (!attrib) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7397 | LOCAL_SET_GL_ERROR( |
| 7398 | GL_INVALID_VALUE, "glGetVertexAttribiv", "index out of range"); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7399 | return; |
| 7400 | } |
| 7401 | switch (pname) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7402 | case GL_CURRENT_VERTEX_ATTRIB: { |
| 7403 | const Vec4& value = state_.attrib_values[index]; |
| 7404 | params[0] = static_cast<GLint>(value.v[0]); |
| 7405 | params[1] = static_cast<GLint>(value.v[1]); |
| 7406 | params[2] = static_cast<GLint>(value.v[2]); |
| 7407 | params[3] = static_cast<GLint>(value.v[3]); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7408 | break; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7409 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7410 | default: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7411 | GetVertexAttribHelper(attrib, pname, params); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7412 | break; |
| 7413 | } |
| 7414 | } |
| 7415 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7416 | bool GLES2DecoderImpl::SetVertexAttribValue( |
| 7417 | const char* function_name, GLuint index, const GLfloat* value) { |
| 7418 | if (index >= state_.attrib_values.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7419 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "index out of range"); |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7420 | return false; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7421 | } |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7422 | Vec4& v = state_.attrib_values[index]; |
| 7423 | v.v[0] = value[0]; |
| 7424 | v.v[1] = value[1]; |
| 7425 | v.v[2] = value[2]; |
| 7426 | v.v[3] = value[3]; |
| 7427 | return true; |
| 7428 | } |
| 7429 | |
| 7430 | void GLES2DecoderImpl::DoVertexAttrib1f(GLuint index, GLfloat v0) { |
| 7431 | GLfloat v[4] = { v0, 0.0f, 0.0f, 1.0f, }; |
| 7432 | if (SetVertexAttribValue("glVertexAttrib1f", index, v)) { |
| 7433 | glVertexAttrib1f(index, v0); |
| 7434 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7435 | } |
| 7436 | |
| 7437 | void GLES2DecoderImpl::DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7438 | GLfloat v[4] = { v0, v1, 0.0f, 1.0f, }; |
| 7439 | if (SetVertexAttribValue("glVertexAttrib2f", index, v)) { |
| 7440 | glVertexAttrib2f(index, v0, v1); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7441 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7442 | } |
| 7443 | |
| 7444 | void GLES2DecoderImpl::DoVertexAttrib3f( |
| 7445 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7446 | GLfloat v[4] = { v0, v1, v2, 1.0f, }; |
| 7447 | if (SetVertexAttribValue("glVertexAttrib3f", index, v)) { |
| 7448 | glVertexAttrib3f(index, v0, v1, v2); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7449 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7450 | } |
| 7451 | |
| 7452 | void GLES2DecoderImpl::DoVertexAttrib4f( |
| 7453 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7454 | GLfloat v[4] = { v0, v1, v2, v3, }; |
| 7455 | if (SetVertexAttribValue("glVertexAttrib4f", index, v)) { |
| 7456 | glVertexAttrib4f(index, v0, v1, v2, v3); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7457 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7458 | } |
| 7459 | |
| 7460 | void GLES2DecoderImpl::DoVertexAttrib1fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7461 | GLfloat t[4] = { v[0], 0.0f, 0.0f, 1.0f, }; |
| 7462 | if (SetVertexAttribValue("glVertexAttrib1fv", index, t)) { |
| 7463 | glVertexAttrib1fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7464 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7465 | } |
| 7466 | |
| 7467 | void GLES2DecoderImpl::DoVertexAttrib2fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7468 | GLfloat t[4] = { v[0], v[1], 0.0f, 1.0f, }; |
| 7469 | if (SetVertexAttribValue("glVertexAttrib2fv", index, t)) { |
| 7470 | glVertexAttrib2fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7471 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7472 | } |
| 7473 | |
| 7474 | void GLES2DecoderImpl::DoVertexAttrib3fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7475 | GLfloat t[4] = { v[0], v[1], v[2], 1.0f, }; |
| 7476 | if (SetVertexAttribValue("glVertexAttrib3fv", index, t)) { |
| 7477 | glVertexAttrib3fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7478 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7479 | } |
| 7480 | |
| 7481 | void GLES2DecoderImpl::DoVertexAttrib4fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7482 | if (SetVertexAttribValue("glVertexAttrib4fv", index, v)) { |
| 7483 | glVertexAttrib4fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7484 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7485 | } |
| 7486 | |
zmo | 0c4b7cf | 2014-11-26 00:52:11 | [diff] [blame] | 7487 | error::Error GLES2DecoderImpl::HandleVertexAttribIPointer( |
| 7488 | uint32 immediate_data_size, |
| 7489 | const void* cmd_data) { |
| 7490 | // TODO(zmo): Unsafe ES3 API, missing states update. |
| 7491 | if (!unsafe_es3_apis_enabled()) |
| 7492 | return error::kUnknownCommand; |
| 7493 | const gles2::cmds::VertexAttribIPointer& c = |
| 7494 | *static_cast<const gles2::cmds::VertexAttribIPointer*>(cmd_data); |
| 7495 | GLuint indx = c.indx; |
| 7496 | GLint size = c.size; |
| 7497 | GLenum type = c.type; |
| 7498 | GLsizei stride = c.stride; |
| 7499 | GLsizei offset = c.offset; |
| 7500 | const void* ptr = reinterpret_cast<const void*>(offset); |
| 7501 | glVertexAttribIPointer(indx, size, type, stride, ptr); |
| 7502 | return error::kNoError; |
| 7503 | } |
| 7504 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7505 | error::Error GLES2DecoderImpl::HandleVertexAttribPointer( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7506 | uint32 immediate_data_size, |
| 7507 | const void* cmd_data) { |
| 7508 | const gles2::cmds::VertexAttribPointer& c = |
| 7509 | *static_cast<const gles2::cmds::VertexAttribPointer*>(cmd_data); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 7510 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 7511 | if (!state_.bound_array_buffer.get() || |
| 7512 | state_.bound_array_buffer->IsDeleted()) { |
| 7513 | if (state_.vertex_attrib_manager.get() == |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 7514 | state_.default_vertex_attrib_manager.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7515 | LOCAL_SET_GL_ERROR( |
| 7516 | GL_INVALID_VALUE, "glVertexAttribPointer", "no array buffer bound"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 7517 | return error::kNoError; |
| 7518 | } else if (c.offset != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7519 | LOCAL_SET_GL_ERROR( |
| 7520 | GL_INVALID_VALUE, |
| 7521 | "glVertexAttribPointer", "client side arrays are not allowed"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 7522 | return error::kNoError; |
| 7523 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7524 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7525 | |
| 7526 | GLuint indx = c.indx; |
| 7527 | GLint size = c.size; |
| 7528 | GLenum type = c.type; |
pkasting | 45796dc | 2014-10-17 04:18:32 | [diff] [blame] | 7529 | GLboolean normalized = static_cast<GLboolean>(c.normalized); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7530 | GLsizei stride = c.stride; |
| 7531 | GLsizei offset = c.offset; |
| 7532 | const void* ptr = reinterpret_cast<const void*>(offset); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7533 | if (!validators_->vertex_attrib_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7534 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glVertexAttribPointer", type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7535 | return error::kNoError; |
| 7536 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7537 | if (!validators_->vertex_attrib_size.IsValid(size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7538 | LOCAL_SET_GL_ERROR( |
| 7539 | GL_INVALID_VALUE, "glVertexAttribPointer", "size GL_INVALID_VALUE"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7540 | return error::kNoError; |
| 7541 | } |
| 7542 | if (indx >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7543 | LOCAL_SET_GL_ERROR( |
| 7544 | GL_INVALID_VALUE, "glVertexAttribPointer", "index out of range"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7545 | return error::kNoError; |
| 7546 | } |
| 7547 | if (stride < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7548 | LOCAL_SET_GL_ERROR( |
| 7549 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7550 | return error::kNoError; |
| 7551 | } |
| 7552 | if (stride > 255) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7553 | LOCAL_SET_GL_ERROR( |
| 7554 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride > 255"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7555 | return error::kNoError; |
| 7556 | } |
| 7557 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7558 | LOCAL_SET_GL_ERROR( |
| 7559 | GL_INVALID_VALUE, "glVertexAttribPointer", "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7560 | return error::kNoError; |
| 7561 | } |
| 7562 | GLsizei component_size = |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 7563 | GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type); |
[email protected] | a07a2360 | 2014-08-05 11:36:12 | [diff] [blame] | 7564 | // component_size must be a power of two to use & as optimized modulo. |
| 7565 | DCHECK(GLES2Util::IsPOT(component_size)); |
| 7566 | if (offset & (component_size - 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7567 | LOCAL_SET_GL_ERROR( |
| 7568 | GL_INVALID_OPERATION, |
| 7569 | "glVertexAttribPointer", "offset not valid for type"); |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 7570 | return error::kNoError; |
| 7571 | } |
[email protected] | a07a2360 | 2014-08-05 11:36:12 | [diff] [blame] | 7572 | if (stride & (component_size - 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7573 | LOCAL_SET_GL_ERROR( |
| 7574 | GL_INVALID_OPERATION, |
| 7575 | "glVertexAttribPointer", "stride not valid for type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7576 | return error::kNoError; |
| 7577 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 7578 | state_.vertex_attrib_manager |
| 7579 | ->SetAttribInfo(indx, |
| 7580 | state_.bound_array_buffer.get(), |
| 7581 | size, |
| 7582 | type, |
| 7583 | normalized, |
| 7584 | stride, |
| 7585 | stride != 0 ? stride : component_size * size, |
| 7586 | offset); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7587 | if (type != GL_FIXED) { |
| 7588 | glVertexAttribPointer(indx, size, type, normalized, stride, ptr); |
| 7589 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7590 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7591 | } |
| 7592 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 7593 | void GLES2DecoderImpl::DoViewport(GLint x, GLint y, GLsizei width, |
| 7594 | GLsizei height) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7595 | state_.viewport_x = x; |
| 7596 | state_.viewport_y = y; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 7597 | state_.viewport_width = std::min(width, viewport_max_width_); |
| 7598 | state_.viewport_height = std::min(height, viewport_max_height_); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 7599 | glViewport(x, y, width, height); |
| 7600 | } |
| 7601 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7602 | error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7603 | uint32 immediate_data_size, |
| 7604 | const void* cmd_data) { |
| 7605 | const gles2::cmds::VertexAttribDivisorANGLE& c = |
| 7606 | *static_cast<const gles2::cmds::VertexAttribDivisorANGLE*>(cmd_data); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 7607 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7608 | LOCAL_SET_GL_ERROR( |
| 7609 | GL_INVALID_OPERATION, |
| 7610 | "glVertexAttribDivisorANGLE", "function not available"); |
[email protected] | cedee33 | 2014-05-23 07:07:53 | [diff] [blame] | 7611 | return error::kNoError; |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7612 | } |
| 7613 | GLuint index = c.index; |
| 7614 | GLuint divisor = c.divisor; |
| 7615 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7616 | LOCAL_SET_GL_ERROR( |
| 7617 | GL_INVALID_VALUE, |
| 7618 | "glVertexAttribDivisorANGLE", "index out of range"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7619 | return error::kNoError; |
| 7620 | } |
| 7621 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7622 | state_.vertex_attrib_manager->SetDivisor( |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7623 | index, |
| 7624 | divisor); |
| 7625 | glVertexAttribDivisorANGLE(index, divisor); |
| 7626 | return error::kNoError; |
| 7627 | } |
| 7628 | |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7629 | template <typename pixel_data_type> |
| 7630 | static void WriteAlphaData( |
| 7631 | void *pixels, uint32 row_count, uint32 channel_count, |
| 7632 | uint32 alpha_channel_index, uint32 unpadded_row_size, |
| 7633 | uint32 padded_row_size, pixel_data_type alpha_value) { |
| 7634 | DCHECK_GT(channel_count, 0U); |
| 7635 | DCHECK_EQ(unpadded_row_size % sizeof(pixel_data_type), 0U); |
| 7636 | uint32 unpadded_row_size_in_elements = |
| 7637 | unpadded_row_size / sizeof(pixel_data_type); |
| 7638 | DCHECK_EQ(padded_row_size % sizeof(pixel_data_type), 0U); |
| 7639 | uint32 padded_row_size_in_elements = |
| 7640 | padded_row_size / sizeof(pixel_data_type); |
| 7641 | pixel_data_type* dst = |
| 7642 | static_cast<pixel_data_type*>(pixels) + alpha_channel_index; |
| 7643 | for (uint32 yy = 0; yy < row_count; ++yy) { |
| 7644 | pixel_data_type* end = dst + unpadded_row_size_in_elements; |
| 7645 | for (pixel_data_type* d = dst; d < end; d += channel_count) { |
| 7646 | *d = alpha_value; |
| 7647 | } |
| 7648 | dst += padded_row_size_in_elements; |
| 7649 | } |
| 7650 | } |
| 7651 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7652 | void GLES2DecoderImpl::FinishReadPixels( |
| 7653 | const cmds::ReadPixels& c, |
| 7654 | GLuint buffer) { |
| 7655 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::FinishReadPixels"); |
| 7656 | GLsizei width = c.width; |
| 7657 | GLsizei height = c.height; |
| 7658 | GLenum format = c.format; |
| 7659 | GLenum type = c.type; |
| 7660 | typedef cmds::ReadPixels::Result Result; |
| 7661 | uint32 pixels_size; |
| 7662 | Result* result = NULL; |
| 7663 | if (c.result_shm_id != 0) { |
| 7664 | result = GetSharedMemoryAs<Result*>( |
| 7665 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7666 | if (!result) { |
| 7667 | if (buffer != 0) { |
| 7668 | glDeleteBuffersARB(1, &buffer); |
| 7669 | } |
| 7670 | return; |
| 7671 | } |
| 7672 | } |
| 7673 | GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 7674 | width, height, 1, format, type, state_.pack_alignment, &pixels_size, |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7675 | NULL, NULL); |
| 7676 | void* pixels = GetSharedMemoryAs<void*>( |
| 7677 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| 7678 | if (!pixels) { |
| 7679 | if (buffer != 0) { |
| 7680 | glDeleteBuffersARB(1, &buffer); |
| 7681 | } |
| 7682 | return; |
| 7683 | } |
| 7684 | |
| 7685 | if (buffer != 0) { |
| 7686 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
[email protected] | e585f9e2 | 2013-08-27 02:50:33 | [diff] [blame] | 7687 | void* data; |
| 7688 | if (features().map_buffer_range) { |
| 7689 | data = glMapBufferRange( |
| 7690 | GL_PIXEL_PACK_BUFFER_ARB, 0, pixels_size, GL_MAP_READ_BIT); |
| 7691 | } else { |
| 7692 | data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); |
| 7693 | } |
miu | b70d7859 | 2014-11-15 03:53:47 | [diff] [blame] | 7694 | if (!data) { |
| 7695 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glMapBuffer", |
| 7696 | "Unable to map memory for readback."); |
| 7697 | return; |
| 7698 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7699 | memcpy(pixels, data, pixels_size); |
| 7700 | // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't |
| 7701 | // have to restore the state. |
| 7702 | glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); |
| 7703 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7704 | glDeleteBuffersARB(1, &buffer); |
| 7705 | } |
| 7706 | |
| 7707 | if (result != NULL) { |
| 7708 | *result = true; |
| 7709 | } |
| 7710 | |
| 7711 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 7712 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 7713 | if ((channels_exist & 0x0008) == 0 && |
| 7714 | workarounds().clear_alpha_in_readpixels) { |
| 7715 | // Set the alpha to 255 because some drivers are buggy in this regard. |
| 7716 | uint32 temp_size; |
| 7717 | |
| 7718 | uint32 unpadded_row_size; |
| 7719 | uint32 padded_row_size; |
| 7720 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 7721 | width, 2, 1, format, type, state_.pack_alignment, &temp_size, |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7722 | &unpadded_row_size, &padded_row_size)) { |
| 7723 | return; |
| 7724 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7725 | |
| 7726 | uint32 channel_count = 0; |
| 7727 | uint32 alpha_channel = 0; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7728 | switch (format) { |
| 7729 | case GL_RGBA: |
| 7730 | case GL_BGRA_EXT: |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7731 | channel_count = 4; |
| 7732 | alpha_channel = 3; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7733 | break; |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7734 | case GL_ALPHA: |
| 7735 | channel_count = 1; |
| 7736 | alpha_channel = 0; |
| 7737 | break; |
| 7738 | } |
| 7739 | |
| 7740 | if (channel_count > 0) { |
| 7741 | switch (type) { |
| 7742 | case GL_UNSIGNED_BYTE: |
| 7743 | WriteAlphaData<uint8>( |
| 7744 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 7745 | padded_row_size, 0xFF); |
| 7746 | break; |
| 7747 | case GL_FLOAT: |
| 7748 | WriteAlphaData<float>( |
| 7749 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 7750 | padded_row_size, 1.0f); |
| 7751 | break; |
| 7752 | case GL_HALF_FLOAT: |
| 7753 | WriteAlphaData<uint16>( |
| 7754 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 7755 | padded_row_size, 0x3C00); |
| 7756 | break; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7757 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7758 | } |
| 7759 | } |
| 7760 | } |
| 7761 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7762 | error::Error GLES2DecoderImpl::HandleReadPixels(uint32 immediate_data_size, |
| 7763 | const void* cmd_data) { |
| 7764 | const gles2::cmds::ReadPixels& c = |
| 7765 | *static_cast<const gles2::cmds::ReadPixels*>(cmd_data); |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 7766 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleReadPixels"); |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 7767 | error::Error fbo_error = WillAccessBoundFramebufferForRead(); |
| 7768 | if (fbo_error != error::kNoError) |
| 7769 | return fbo_error; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7770 | GLint x = c.x; |
| 7771 | GLint y = c.y; |
| 7772 | GLsizei width = c.width; |
| 7773 | GLsizei height = c.height; |
| 7774 | GLenum format = c.format; |
| 7775 | GLenum type = c.type; |
pkasting | 45796dc | 2014-10-17 04:18:32 | [diff] [blame] | 7776 | GLboolean async = static_cast<GLboolean>(c.async); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7777 | if (width < 0 || height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7778 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7779 | return error::kNoError; |
| 7780 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7781 | typedef cmds::ReadPixels::Result Result; |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7782 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7783 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 7784 | width, height, 1, format, type, state_.pack_alignment, &pixels_size, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7785 | NULL, NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 7786 | return error::kOutOfBounds; |
| 7787 | } |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7788 | void* pixels = GetSharedMemoryAs<void*>( |
| 7789 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7790 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7791 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7792 | } |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7793 | Result* result = NULL; |
| 7794 | if (c.result_shm_id != 0) { |
| 7795 | result = GetSharedMemoryAs<Result*>( |
| 7796 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 7797 | if (!result) { |
| 7798 | return error::kOutOfBounds; |
| 7799 | } |
| 7800 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7801 | |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7802 | if (!validators_->read_pixel_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7803 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", format, "format"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7804 | return error::kNoError; |
| 7805 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7806 | if (!validators_->read_pixel_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7807 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", type, "type"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 7808 | return error::kNoError; |
| 7809 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 7810 | if ((format != GL_RGBA && format != GL_BGRA_EXT && format != GL_RGB && |
| 7811 | format != GL_ALPHA) || type != GL_UNSIGNED_BYTE) { |
| 7812 | // format and type are acceptable enums but not guaranteed to be supported |
| 7813 | // for this framebuffer. Have to ask gl if they are valid. |
| 7814 | GLint preferred_format = 0; |
| 7815 | DoGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &preferred_format); |
| 7816 | GLint preferred_type = 0; |
| 7817 | DoGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &preferred_type); |
| 7818 | if (format != static_cast<GLenum>(preferred_format) || |
| 7819 | type != static_cast<GLenum>(preferred_type)) { |
| 7820 | LOCAL_SET_GL_ERROR( |
| 7821 | GL_INVALID_OPERATION, "glReadPixels", "format and type incompatible " |
| 7822 | "with the current read framebuffer"); |
| 7823 | return error::kNoError; |
| 7824 | } |
| 7825 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7826 | if (width == 0 || height == 0) { |
| 7827 | return error::kNoError; |
| 7828 | } |
| 7829 | |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7830 | // Get the size of the current fbo or backbuffer. |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 7831 | gfx::Size max_size = GetBoundReadFrameBufferSize(); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7832 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 7833 | int32 max_x; |
| 7834 | int32 max_y; |
| 7835 | if (!SafeAddInt32(x, width, &max_x) || !SafeAddInt32(y, height, &max_y)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7836 | LOCAL_SET_GL_ERROR( |
| 7837 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7838 | return error::kNoError; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 7839 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7840 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 7841 | if (!CheckBoundReadFramebufferColorAttachment("glReadPixels")) { |
| 7842 | return error::kNoError; |
| 7843 | } |
| 7844 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7845 | if (!CheckBoundFramebuffersValid("glReadPixels")) { |
| 7846 | return error::kNoError; |
| 7847 | } |
| 7848 | |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7849 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7850 | |
| 7851 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 7852 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7853 | 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] | 7854 | // The user requested an out of range area. Get the results 1 line |
| 7855 | // at a time. |
| 7856 | uint32 temp_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7857 | uint32 unpadded_row_size; |
| 7858 | uint32 padded_row_size; |
| 7859 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 7860 | width, 2, 1, format, type, state_.pack_alignment, &temp_size, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7861 | &unpadded_row_size, &padded_row_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7862 | LOCAL_SET_GL_ERROR( |
| 7863 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7864 | return error::kNoError; |
| 7865 | } |
| 7866 | |
| 7867 | GLint dest_x_offset = std::max(-x, 0); |
| 7868 | uint32 dest_row_offset; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 7869 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 7870 | dest_x_offset, 1, 1, format, type, state_.pack_alignment, |
| 7871 | &dest_row_offset, NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7872 | LOCAL_SET_GL_ERROR( |
| 7873 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7874 | return error::kNoError; |
| 7875 | } |
| 7876 | |
| 7877 | // Copy each row into the larger dest rect. |
| 7878 | int8* dst = static_cast<int8*>(pixels); |
| 7879 | GLint read_x = std::max(0, x); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7880 | 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] | 7881 | GLint read_width = read_end_x - read_x; |
| 7882 | for (GLint yy = 0; yy < height; ++yy) { |
| 7883 | GLint ry = y + yy; |
| 7884 | |
| 7885 | // Clear the row. |
| 7886 | memset(dst, 0, unpadded_row_size); |
| 7887 | |
| 7888 | // If the row is in range, copy it. |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 7889 | if (ry >= 0 && ry < max_size.height() && read_width > 0) { |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7890 | glReadPixels( |
| 7891 | read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
| 7892 | } |
| 7893 | dst += padded_row_size; |
| 7894 | } |
| 7895 | } else { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7896 | if (async && features().use_async_readpixels) { |
miu | 50cef60 | 2014-11-11 01:35:41 | [diff] [blame] | 7897 | GLuint buffer = 0; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7898 | glGenBuffersARB(1, &buffer); |
| 7899 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
miu | b70d7859 | 2014-11-15 03:53:47 | [diff] [blame] | 7900 | // For ANGLE client version 2, GL_STREAM_READ is not available. |
zmo | 68fcdc6 | 2014-12-05 21:51:49 | [diff] [blame] | 7901 | const GLenum usage_hint = feature_info_->gl_version_info().is_angle ? |
| 7902 | GL_STATIC_DRAW : GL_STREAM_READ; |
miu | b70d7859 | 2014-11-15 03:53:47 | [diff] [blame] | 7903 | glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, usage_hint); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7904 | GLenum error = glGetError(); |
| 7905 | if (error == GL_NO_ERROR) { |
| 7906 | glReadPixels(x, y, width, height, format, type, 0); |
| 7907 | pending_readpixel_fences_.push(linked_ptr<FenceCallback>( |
| 7908 | new FenceCallback())); |
| 7909 | WaitForReadPixels(base::Bind( |
| 7910 | &GLES2DecoderImpl::FinishReadPixels, |
| 7911 | base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 7912 | <GLES2DecoderImpl>(this), |
| 7913 | c, buffer)); |
| 7914 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 7915 | return error::kNoError; |
[email protected] | 77bfe744 | 2014-03-01 02:42:59 | [diff] [blame] | 7916 | } else { |
| 7917 | // On error, unbind pack buffer and fall through to sync readpixels |
| 7918 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
miu | 50cef60 | 2014-11-11 01:35:41 | [diff] [blame] | 7919 | glDeleteBuffersARB(1, &buffer); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7920 | } |
| 7921 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 7922 | glReadPixels(x, y, width, height, format, type, pixels); |
| 7923 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7924 | GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7925 | if (error == GL_NO_ERROR) { |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 7926 | if (result != NULL) { |
| 7927 | *result = true; |
| 7928 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 7929 | FinishReadPixels(c, 0); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 7930 | } |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 7931 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7932 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7933 | } |
| 7934 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7935 | error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, |
| 7936 | const void* cmd_data) { |
| 7937 | const gles2::cmds::PixelStorei& c = |
| 7938 | *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7939 | GLenum pname = c.pname; |
| 7940 | GLenum param = c.param; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7941 | if (!validators_->pixel_store.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7942 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glPixelStorei", pname, "pname"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 7943 | return error::kNoError; |
| 7944 | } |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7945 | switch (pname) { |
| 7946 | case GL_PACK_ALIGNMENT: |
| 7947 | case GL_UNPACK_ALIGNMENT: |
| 7948 | if (!validators_->pixel_store_alignment.IsValid(param)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7949 | LOCAL_SET_GL_ERROR( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7950 | GL_INVALID_VALUE, "glPixelStorei", "param GL_INVALID_VALUE"); |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7951 | return error::kNoError; |
| 7952 | } |
[email protected] | 164d6d5 | 2012-05-05 00:55:03 | [diff] [blame] | 7953 | break; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 7954 | case GL_UNPACK_FLIP_Y_CHROMIUM: |
| 7955 | unpack_flip_y_ = (param != 0); |
| 7956 | return error::kNoError; |
| 7957 | case GL_UNPACK_PREMULTIPLY_ALPHA_CHROMIUM: |
| 7958 | unpack_premultiply_alpha_ = (param != 0); |
| 7959 | return error::kNoError; |
[email protected] | 6c75c71 | 2012-06-19 15:43:17 | [diff] [blame] | 7960 | case GL_UNPACK_UNPREMULTIPLY_ALPHA_CHROMIUM: |
| 7961 | unpack_unpremultiply_alpha_ = (param != 0); |
| 7962 | return error::kNoError; |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 7963 | default: |
| 7964 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7965 | } |
| 7966 | glPixelStorei(pname, param); |
| 7967 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7968 | case GL_PACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7969 | state_.pack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7970 | break; |
| 7971 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 7972 | state_.pack_reverse_row_order = (param != 0); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7973 | break; |
| 7974 | case GL_UNPACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7975 | state_.unpack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7976 | break; |
| 7977 | default: |
| 7978 | // Validation should have prevented us from getting here. |
| 7979 | NOTREACHED(); |
| 7980 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7981 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7982 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 7983 | } |
| 7984 | |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7985 | error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7986 | uint32 immediate_data_size, |
| 7987 | const void* cmd_data) { |
| 7988 | const gles2::cmds::PostSubBufferCHROMIUM& c = |
| 7989 | *static_cast<const gles2::cmds::PostSubBufferCHROMIUM*>(cmd_data); |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 7990 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandlePostSubBufferCHROMIUM"); |
[email protected] | a36ed483 | 2014-04-24 16:40:27 | [diff] [blame] | 7991 | { |
| 7992 | TRACE_EVENT_SYNTHETIC_DELAY("gpu.PresentingFrame"); |
| 7993 | } |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 7994 | if (!supports_post_sub_buffer_) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7995 | LOCAL_SET_GL_ERROR( |
| 7996 | GL_INVALID_OPERATION, |
| 7997 | "glPostSubBufferCHROMIUM", "command not supported by surface"); |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 7998 | return error::kNoError; |
| 7999 | } |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 8000 | bool is_tracing; |
| 8001 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 8002 | &is_tracing); |
| 8003 | if (is_tracing) { |
| 8004 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 8005 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 8006 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 8007 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 8008 | } |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 8009 | if (surface_->PostSubBuffer(c.x, c.y, c.width, c.height)) { |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 8010 | return error::kNoError; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 8011 | } else { |
| 8012 | LOG(ERROR) << "Context lost because PostSubBuffer failed."; |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 8013 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 8014 | } |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 8015 | } |
| 8016 | |
[email protected] | 957f064 | 2014-04-09 16:50:01 | [diff] [blame] | 8017 | error::Error GLES2DecoderImpl::HandleScheduleOverlayPlaneCHROMIUM( |
| 8018 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8019 | const void* cmd_data) { |
| 8020 | const gles2::cmds::ScheduleOverlayPlaneCHROMIUM& c = |
| 8021 | *static_cast<const gles2::cmds::ScheduleOverlayPlaneCHROMIUM*>(cmd_data); |
[email protected] | d286ebbc | 2014-07-03 17:19:10 | [diff] [blame] | 8022 | TextureRef* ref = texture_manager()->GetTexture(c.overlay_texture_id); |
| 8023 | if (!ref) { |
| 8024 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 8025 | "glScheduleOverlayPlaneCHROMIUM", |
| 8026 | "unknown texture"); |
| 8027 | return error::kNoError; |
| 8028 | } |
| 8029 | gfx::GLImage* image = |
| 8030 | ref->texture()->GetLevelImage(ref->texture()->target(), 0); |
| 8031 | if (!image) { |
| 8032 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 8033 | "glScheduleOverlayPlaneCHROMIUM", |
| 8034 | "unsupported texture format"); |
| 8035 | return error::kNoError; |
| 8036 | } |
| 8037 | gfx::OverlayTransform transform = GetGFXOverlayTransform(c.plane_transform); |
| 8038 | if (transform == gfx::OVERLAY_TRANSFORM_INVALID) { |
| 8039 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, |
| 8040 | "glScheduleOverlayPlaneCHROMIUM", |
| 8041 | "invalid transform enum"); |
| 8042 | return error::kNoError; |
| 8043 | } |
| 8044 | if (!surface_->ScheduleOverlayPlane( |
| 8045 | c.plane_z_order, |
| 8046 | transform, |
| 8047 | image, |
| 8048 | gfx::Rect(c.bounds_x, c.bounds_y, c.bounds_width, c.bounds_height), |
| 8049 | gfx::RectF(c.uv_x, c.uv_y, c.uv_width, c.uv_height))) { |
| 8050 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 8051 | "glScheduleOverlayPlaneCHROMIUM", |
| 8052 | "failed to schedule overlay"); |
| 8053 | } |
[email protected] | 957f064 | 2014-04-09 16:50:01 | [diff] [blame] | 8054 | return error::kNoError; |
| 8055 | } |
| 8056 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8057 | error::Error GLES2DecoderImpl::GetAttribLocationHelper( |
| 8058 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 8059 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 8060 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8061 | LOCAL_SET_GL_ERROR( |
| 8062 | GL_INVALID_VALUE, "glGetAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 8063 | return error::kNoError; |
| 8064 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8065 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 8066 | client_id, "glGetAttribLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8067 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8068 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8069 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8070 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8071 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8072 | GL_INVALID_OPERATION, "glGetAttribLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8073 | return error::kNoError; |
| 8074 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8075 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8076 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 8077 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8078 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8079 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8080 | // Require the client to init this incase the context is lost and we are no |
| 8081 | // longer executing commands. |
| 8082 | if (*location != -1) { |
| 8083 | return error::kGenericError; |
| 8084 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8085 | *location = program->GetAttribLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8086 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8087 | } |
| 8088 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8089 | error::Error GLES2DecoderImpl::HandleGetAttribLocation( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8090 | uint32 immediate_data_size, |
| 8091 | const void* cmd_data) { |
| 8092 | const gles2::cmds::GetAttribLocation& c = |
| 8093 | *static_cast<const gles2::cmds::GetAttribLocation*>(cmd_data); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8094 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 8095 | if (!bucket) { |
| 8096 | return error::kInvalidArguments; |
| 8097 | } |
| 8098 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8099 | if (!bucket->GetAsString(&name_str)) { |
| 8100 | return error::kInvalidArguments; |
| 8101 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8102 | return GetAttribLocationHelper( |
| 8103 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 8104 | } |
| 8105 | |
| 8106 | error::Error GLES2DecoderImpl::GetUniformLocationHelper( |
| 8107 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 8108 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 8109 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8110 | LOCAL_SET_GL_ERROR( |
| 8111 | GL_INVALID_VALUE, "glGetUniformLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 8112 | return error::kNoError; |
| 8113 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8114 | Program* program = GetProgramInfoNotShader( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 8115 | client_id, "glGetUniformLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8116 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8117 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8118 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8119 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8120 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8121 | GL_INVALID_OPERATION, "glGetUniformLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8122 | return error::kNoError; |
| 8123 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8124 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8125 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 8126 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8127 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8128 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8129 | // Require the client to init this incase the context is lost an we are no |
| 8130 | // longer executing commands. |
| 8131 | if (*location != -1) { |
| 8132 | return error::kGenericError; |
| 8133 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8134 | *location = program->GetUniformFakeLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8135 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8136 | } |
| 8137 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8138 | error::Error GLES2DecoderImpl::HandleGetUniformLocation( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8139 | uint32 immediate_data_size, |
| 8140 | const void* cmd_data) { |
| 8141 | const gles2::cmds::GetUniformLocation& c = |
| 8142 | *static_cast<const gles2::cmds::GetUniformLocation*>(cmd_data); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8143 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 8144 | if (!bucket) { |
| 8145 | return error::kInvalidArguments; |
| 8146 | } |
| 8147 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8148 | if (!bucket->GetAsString(&name_str)) { |
| 8149 | return error::kInvalidArguments; |
| 8150 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8151 | return GetUniformLocationHelper( |
| 8152 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8153 | } |
| 8154 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8155 | error::Error GLES2DecoderImpl::HandleGetString(uint32 immediate_data_size, |
| 8156 | const void* cmd_data) { |
| 8157 | const gles2::cmds::GetString& c = |
| 8158 | *static_cast<const gles2::cmds::GetString*>(cmd_data); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 8159 | GLenum name = static_cast<GLenum>(c.name); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8160 | if (!validators_->string_type.IsValid(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8161 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glGetString", name, "name"); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 8162 | return error::kNoError; |
| 8163 | } |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 8164 | const char* str = reinterpret_cast<const char*>(glGetString(name)); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8165 | std::string extensions; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8166 | switch (name) { |
| 8167 | case GL_VERSION: |
| 8168 | str = "OpenGL ES 2.0 Chromium"; |
| 8169 | break; |
| 8170 | case GL_SHADING_LANGUAGE_VERSION: |
| 8171 | str = "OpenGL ES GLSL ES 1.0 Chromium"; |
| 8172 | break; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 8173 | case GL_RENDERER: |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 8174 | case GL_VENDOR: |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 8175 | // Return the unmasked VENDOR/RENDERER string for WebGL contexts. |
| 8176 | // They are used by WEBGL_debug_renderer_info. |
| 8177 | if (!force_webgl_glsl_validation_) |
| 8178 | str = "Chromium"; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 8179 | break; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8180 | case GL_EXTENSIONS: |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8181 | { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8182 | // For WebGL contexts, strip out the OES derivatives and |
| 8183 | // EXT frag depth extensions if they have not been enabled. |
| 8184 | if (force_webgl_glsl_validation_) { |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8185 | extensions = feature_info_->extensions(); |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8186 | if (!derivatives_explicitly_enabled_) { |
| 8187 | size_t offset = extensions.find(kOESDerivativeExtension); |
| 8188 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 8189 | extensions.replace(offset, arraysize(kOESDerivativeExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8190 | std::string()); |
| 8191 | } |
| 8192 | } |
| 8193 | if (!frag_depth_explicitly_enabled_) { |
| 8194 | size_t offset = extensions.find(kEXTFragDepthExtension); |
| 8195 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 8196 | extensions.replace(offset, arraysize(kEXTFragDepthExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8197 | std::string()); |
| 8198 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8199 | } |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 8200 | if (!draw_buffers_explicitly_enabled_) { |
| 8201 | size_t offset = extensions.find(kEXTDrawBuffersExtension); |
| 8202 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 8203 | extensions.replace(offset, arraysize(kEXTDrawBuffersExtension), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 8204 | std::string()); |
| 8205 | } |
| 8206 | } |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 8207 | if (!shader_texture_lod_explicitly_enabled_) { |
| 8208 | size_t offset = extensions.find(kEXTShaderTextureLodExtension); |
| 8209 | if (std::string::npos != offset) { |
| 8210 | extensions.replace(offset, |
| 8211 | arraysize(kEXTShaderTextureLodExtension), |
| 8212 | std::string()); |
| 8213 | } |
| 8214 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8215 | } else { |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 8216 | extensions = feature_info_->extensions().c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8217 | } |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 8218 | if (supports_post_sub_buffer_) |
| 8219 | extensions += " GL_CHROMIUM_post_sub_buffer"; |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 8220 | str = extensions.c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8221 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8222 | break; |
| 8223 | default: |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8224 | break; |
| 8225 | } |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 8226 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8227 | bucket->SetFromString(str); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 8228 | return error::kNoError; |
| 8229 | } |
| 8230 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8231 | error::Error GLES2DecoderImpl::HandleBufferData(uint32 immediate_data_size, |
| 8232 | const void* cmd_data) { |
| 8233 | const gles2::cmds::BufferData& c = |
| 8234 | *static_cast<const gles2::cmds::BufferData*>(cmd_data); |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 8235 | GLenum target = static_cast<GLenum>(c.target); |
| 8236 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
| 8237 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 8238 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 8239 | GLenum usage = static_cast<GLenum>(c.usage); |
| 8240 | const void* data = NULL; |
| 8241 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 8242 | data = GetSharedMemoryAs<const void*>(data_shm_id, data_shm_offset, size); |
| 8243 | if (!data) { |
| 8244 | return error::kOutOfBounds; |
| 8245 | } |
| 8246 | } |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 8247 | buffer_manager()->ValidateAndDoBufferData(&state_, target, size, data, usage); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8248 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8249 | } |
| 8250 | |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 8251 | void GLES2DecoderImpl::DoBufferSubData( |
| 8252 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 8253 | // Just delegate it. Some validation is actually done before this. |
| 8254 | buffer_manager()->ValidateAndDoBufferSubData( |
| 8255 | &state_, target, offset, size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8256 | } |
| 8257 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8258 | bool GLES2DecoderImpl::ClearLevel( |
| 8259 | unsigned service_id, |
| 8260 | unsigned bind_target, |
| 8261 | unsigned target, |
| 8262 | int level, |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 8263 | unsigned internal_format, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8264 | unsigned format, |
| 8265 | unsigned type, |
| 8266 | int width, |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8267 | int height, |
| 8268 | bool is_texture_immutable) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8269 | uint32 channels = GLES2Util::GetChannelsForFormat(format); |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 8270 | if (feature_info_->feature_flags().angle_depth_texture && |
| 8271 | (channels & GLES2Util::kDepth) != 0) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8272 | // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D |
| 8273 | // on depth formats. |
| 8274 | GLuint fb = 0; |
| 8275 | glGenFramebuffersEXT(1, &fb); |
| 8276 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); |
| 8277 | |
| 8278 | bool have_stencil = (channels & GLES2Util::kStencil) != 0; |
| 8279 | GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : |
| 8280 | GL_DEPTH_ATTACHMENT; |
| 8281 | |
| 8282 | glFramebufferTexture2DEXT( |
| 8283 | GL_DRAW_FRAMEBUFFER_EXT, attachment, target, service_id, level); |
| 8284 | // ANGLE promises a depth only attachment ok. |
| 8285 | if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != |
| 8286 | GL_FRAMEBUFFER_COMPLETE) { |
| 8287 | return false; |
| 8288 | } |
| 8289 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 8290 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 8291 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8292 | glClearDepth(1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 8293 | state_.SetDeviceDepthMask(GL_TRUE); |
| 8294 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8295 | glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); |
| 8296 | |
| 8297 | RestoreClearState(); |
| 8298 | |
| 8299 | glDeleteFramebuffersEXT(1, &fb); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8300 | Framebuffer* framebuffer = |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8301 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 8302 | GLuint fb_service_id = |
| 8303 | framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); |
| 8304 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); |
| 8305 | return true; |
| 8306 | } |
| 8307 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8308 | static const uint32 kMaxZeroSize = 1024 * 1024 * 4; |
| 8309 | |
| 8310 | uint32 size; |
| 8311 | uint32 padded_row_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8312 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8313 | width, height, 1, format, type, state_.unpack_alignment, &size, |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8314 | NULL, &padded_row_size)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8315 | return false; |
| 8316 | } |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8317 | |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 8318 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearLevel", "size", size); |
| 8319 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8320 | int tile_height; |
| 8321 | |
| 8322 | if (size > kMaxZeroSize) { |
| 8323 | if (kMaxZeroSize < padded_row_size) { |
| 8324 | // That'd be an awfully large texture. |
| 8325 | return false; |
| 8326 | } |
| 8327 | // We should never have a large total size with a zero row size. |
| 8328 | DCHECK_GT(padded_row_size, 0U); |
| 8329 | tile_height = kMaxZeroSize / padded_row_size; |
| 8330 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8331 | width, tile_height, 1, format, type, state_.unpack_alignment, &size, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8332 | NULL, NULL)) { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8333 | return false; |
| 8334 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8335 | } else { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8336 | tile_height = height; |
| 8337 | } |
| 8338 | |
| 8339 | // Assumes the size has already been checked. |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8340 | scoped_ptr<char[]> zero(new char[size]); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8341 | memset(zero.get(), 0, size); |
| 8342 | glBindTexture(bind_target, service_id); |
| 8343 | |
| 8344 | GLint y = 0; |
| 8345 | while (y < height) { |
| 8346 | GLint h = y + tile_height > height ? height - y : tile_height; |
| 8347 | if (is_texture_immutable || h != height) { |
| 8348 | glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); |
| 8349 | } else { |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 8350 | glTexImage2D( |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 8351 | target, level, internal_format, width, h, 0, format, type, |
| 8352 | zero.get()); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8353 | } |
| 8354 | y += tile_height; |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8355 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8356 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 8357 | &state_, bind_target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8358 | glBindTexture(bind_target, texture ? texture->service_id() : 0); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8359 | return true; |
| 8360 | } |
| 8361 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8362 | namespace { |
| 8363 | |
| 8364 | const int kS3TCBlockWidth = 4; |
| 8365 | const int kS3TCBlockHeight = 4; |
| 8366 | const int kS3TCDXT1BlockSize = 8; |
| 8367 | const int kS3TCDXT3AndDXT5BlockSize = 16; |
| 8368 | |
| 8369 | bool IsValidDXTSize(GLint level, GLsizei size) { |
[email protected] | 10b56de | 2012-07-14 02:09:51 | [diff] [blame] | 8370 | return (size == 1) || |
| 8371 | (size == 2) || !(size % kS3TCBlockWidth); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8372 | } |
| 8373 | |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8374 | bool IsValidPVRTCSize(GLint level, GLsizei size) { |
[email protected] | a07a2360 | 2014-08-05 11:36:12 | [diff] [blame] | 8375 | return GLES2Util::IsPOT(size); |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8376 | } |
| 8377 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8378 | } // anonymous namespace. |
| 8379 | |
| 8380 | bool GLES2DecoderImpl::ValidateCompressedTexFuncData( |
| 8381 | const char* function_name, |
| 8382 | GLsizei width, GLsizei height, GLenum format, size_t size) { |
| 8383 | unsigned int bytes_required = 0; |
| 8384 | |
| 8385 | switch (format) { |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8386 | case GL_ATC_RGB_AMD: |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8387 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8388 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 8389 | case GL_ETC1_RGB8_OES: { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8390 | int num_blocks_across = |
| 8391 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 8392 | int num_blocks_down = |
| 8393 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 8394 | int num_blocks = num_blocks_across * num_blocks_down; |
| 8395 | bytes_required = num_blocks * kS3TCDXT1BlockSize; |
| 8396 | break; |
| 8397 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8398 | case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
| 8399 | case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8400 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 8401 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 8402 | int num_blocks_across = |
| 8403 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 8404 | int num_blocks_down = |
| 8405 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 8406 | int num_blocks = num_blocks_across * num_blocks_down; |
| 8407 | bytes_required = num_blocks * kS3TCDXT3AndDXT5BlockSize; |
| 8408 | break; |
| 8409 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8410 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 8411 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: { |
| 8412 | bytes_required = (std::max(width, 8) * std::max(height, 8) * 4 + 7)/8; |
| 8413 | break; |
| 8414 | } |
| 8415 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 8416 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: { |
| 8417 | bytes_required = (std::max(width, 16) * std::max(height, 8) * 2 + 7)/8; |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8418 | break; |
| 8419 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8420 | default: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8421 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8422 | return false; |
| 8423 | } |
| 8424 | |
| 8425 | if (size != bytes_required) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8426 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8427 | GL_INVALID_VALUE, function_name, "size is not correct for dimensions"); |
| 8428 | return false; |
| 8429 | } |
| 8430 | |
| 8431 | return true; |
| 8432 | } |
| 8433 | |
| 8434 | bool GLES2DecoderImpl::ValidateCompressedTexDimensions( |
| 8435 | const char* function_name, |
| 8436 | GLint level, GLsizei width, GLsizei height, GLenum format) { |
| 8437 | switch (format) { |
| 8438 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 8439 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 8440 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 8441 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 8442 | if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8443 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8444 | GL_INVALID_OPERATION, function_name, |
| 8445 | "width or height invalid for level"); |
| 8446 | return false; |
| 8447 | } |
| 8448 | return true; |
| 8449 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8450 | case GL_ATC_RGB_AMD: |
| 8451 | case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
| 8452 | case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
| 8453 | case GL_ETC1_RGB8_OES: { |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8454 | if (width <= 0 || height <= 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8455 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8456 | GL_INVALID_OPERATION, function_name, |
| 8457 | "width or height invalid for level"); |
| 8458 | return false; |
| 8459 | } |
| 8460 | return true; |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8461 | } |
| 8462 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 8463 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 8464 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
| 8465 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: { |
| 8466 | if (!IsValidPVRTCSize(level, width) || |
| 8467 | !IsValidPVRTCSize(level, height)) { |
| 8468 | LOCAL_SET_GL_ERROR( |
| 8469 | GL_INVALID_OPERATION, function_name, |
| 8470 | "width or height invalid for level"); |
| 8471 | return false; |
| 8472 | } |
| 8473 | return true; |
| 8474 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8475 | default: |
| 8476 | return false; |
| 8477 | } |
| 8478 | } |
| 8479 | |
| 8480 | bool GLES2DecoderImpl::ValidateCompressedTexSubDimensions( |
| 8481 | const char* function_name, |
| 8482 | GLenum target, GLint level, GLint xoffset, GLint yoffset, |
| 8483 | GLsizei width, GLsizei height, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8484 | Texture* texture) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8485 | if (xoffset < 0 || yoffset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8486 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8487 | GL_INVALID_VALUE, function_name, "xoffset or yoffset < 0"); |
| 8488 | return false; |
| 8489 | } |
| 8490 | |
| 8491 | switch (format) { |
| 8492 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 8493 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 8494 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 8495 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 8496 | const int kBlockWidth = 4; |
| 8497 | const int kBlockHeight = 4; |
| 8498 | if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8499 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8500 | GL_INVALID_OPERATION, function_name, |
| 8501 | "xoffset or yoffset not multiple of 4"); |
| 8502 | return false; |
| 8503 | } |
| 8504 | GLsizei tex_width = 0; |
| 8505 | GLsizei tex_height = 0; |
| 8506 | if (!texture->GetLevelSize(target, level, &tex_width, &tex_height) || |
| 8507 | width - xoffset > tex_width || |
| 8508 | height - yoffset > tex_height) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8509 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8510 | GL_INVALID_OPERATION, function_name, "dimensions out of range"); |
| 8511 | return false; |
| 8512 | } |
| 8513 | return ValidateCompressedTexDimensions( |
| 8514 | function_name, level, width, height, format); |
| 8515 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8516 | case GL_ATC_RGB_AMD: |
| 8517 | case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
| 8518 | case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: { |
| 8519 | LOCAL_SET_GL_ERROR( |
| 8520 | GL_INVALID_OPERATION, function_name, |
| 8521 | "not supported for ATC textures"); |
| 8522 | return false; |
| 8523 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8524 | case GL_ETC1_RGB8_OES: { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8525 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8526 | GL_INVALID_OPERATION, function_name, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 8527 | "not supported for ECT1_RGB8_OES textures"); |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 8528 | return false; |
| 8529 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 8530 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 8531 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 8532 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
| 8533 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: { |
| 8534 | if ((xoffset != 0) || (yoffset != 0)) { |
| 8535 | LOCAL_SET_GL_ERROR( |
| 8536 | GL_INVALID_OPERATION, function_name, |
| 8537 | "xoffset and yoffset must be zero"); |
| 8538 | return false; |
| 8539 | } |
| 8540 | GLsizei tex_width = 0; |
| 8541 | GLsizei tex_height = 0; |
| 8542 | if (!texture->GetLevelSize(target, level, &tex_width, &tex_height) || |
| 8543 | width != tex_width || |
| 8544 | height != tex_height) { |
| 8545 | LOCAL_SET_GL_ERROR( |
| 8546 | GL_INVALID_OPERATION, function_name, |
| 8547 | "dimensions must match existing texture level dimensions"); |
| 8548 | return false; |
| 8549 | } |
| 8550 | return ValidateCompressedTexDimensions( |
| 8551 | function_name, level, width, height, format); |
| 8552 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8553 | default: |
| 8554 | return false; |
| 8555 | } |
| 8556 | } |
| 8557 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8558 | error::Error GLES2DecoderImpl::DoCompressedTexImage2D( |
| 8559 | GLenum target, |
| 8560 | GLint level, |
| 8561 | GLenum internal_format, |
| 8562 | GLsizei width, |
| 8563 | GLsizei height, |
| 8564 | GLint border, |
| 8565 | GLsizei image_size, |
| 8566 | const void* data) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8567 | // TODO(gman): Validate image_size is correct for width, height and format. |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8568 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8569 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 8570 | "glCompressedTexImage2D", target, "target"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8571 | return error::kNoError; |
| 8572 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8573 | if (!validators_->compressed_texture_format.IsValid( |
| 8574 | internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8575 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8576 | "glCompressedTexImage2D", internal_format, "internal_format"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8577 | return error::kNoError; |
| 8578 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8579 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8580 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8581 | LOCAL_SET_GL_ERROR( |
| 8582 | GL_INVALID_VALUE, |
| 8583 | "glCompressedTexImage2D", "dimensions out of range"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8584 | return error::kNoError; |
| 8585 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8586 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8587 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8588 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8589 | LOCAL_SET_GL_ERROR( |
| 8590 | GL_INVALID_VALUE, |
| 8591 | "glCompressedTexImage2D", "unknown texture target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8592 | return error::kNoError; |
| 8593 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8594 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8595 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8596 | LOCAL_SET_GL_ERROR( |
| 8597 | GL_INVALID_OPERATION, |
| 8598 | "glCompressedTexImage2D", "texture is immutable"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8599 | return error::kNoError; |
| 8600 | } |
| 8601 | |
| 8602 | if (!ValidateCompressedTexDimensions( |
| 8603 | "glCompressedTexImage2D", level, width, height, internal_format) || |
| 8604 | !ValidateCompressedTexFuncData( |
| 8605 | "glCompressedTexImage2D", width, height, internal_format, image_size)) { |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8606 | return error::kNoError; |
| 8607 | } |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 8608 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8609 | if (!EnsureGPUMemoryAvailable(image_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8610 | LOCAL_SET_GL_ERROR( |
| 8611 | GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8612 | return error::kNoError; |
| 8613 | } |
| 8614 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8615 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8616 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 8617 | } |
| 8618 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8619 | scoped_ptr<int8[]> zero; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8620 | if (!data) { |
| 8621 | zero.reset(new int8[image_size]); |
| 8622 | memset(zero.get(), 0, image_size); |
| 8623 | data = zero.get(); |
| 8624 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8625 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8626 | glCompressedTexImage2D( |
| 8627 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8628 | GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8629 | if (error == GL_NO_ERROR) { |
| 8630 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8631 | texture_ref, target, level, internal_format, |
| 8632 | width, height, 1, border, 0, 0, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8633 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 8634 | |
| 8635 | // This may be a slow command. Exit command processing to allow for |
| 8636 | // context preemption and GPU watchdog checks. |
| 8637 | ExitCommandProcessingEarly(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8638 | return error::kNoError; |
| 8639 | } |
| 8640 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8641 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8642 | uint32 immediate_data_size, |
| 8643 | const void* cmd_data) { |
| 8644 | const gles2::cmds::CompressedTexImage2D& c = |
| 8645 | *static_cast<const gles2::cmds::CompressedTexImage2D*>(cmd_data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8646 | GLenum target = static_cast<GLenum>(c.target); |
| 8647 | GLint level = static_cast<GLint>(c.level); |
| 8648 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 8649 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8650 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8651 | GLint border = static_cast<GLint>(c.border); |
| 8652 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
| 8653 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 8654 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 8655 | const void* data = NULL; |
| 8656 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 8657 | data = GetSharedMemoryAs<const void*>( |
| 8658 | data_shm_id, data_shm_offset, image_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 8659 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8660 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8661 | } |
| 8662 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 8663 | return DoCompressedTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8664 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8665 | } |
| 8666 | |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8667 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2DBucket( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8668 | uint32 immediate_data_size, |
| 8669 | const void* cmd_data) { |
| 8670 | const gles2::cmds::CompressedTexImage2DBucket& c = |
| 8671 | *static_cast<const gles2::cmds::CompressedTexImage2DBucket*>(cmd_data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8672 | GLenum target = static_cast<GLenum>(c.target); |
| 8673 | GLint level = static_cast<GLint>(c.level); |
| 8674 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 8675 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8676 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8677 | GLint border = static_cast<GLint>(c.border); |
| 8678 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8679 | if (!bucket) { |
| 8680 | return error::kInvalidArguments; |
| 8681 | } |
| 8682 | uint32 data_size = bucket->size(); |
| 8683 | GLsizei imageSize = data_size; |
| 8684 | const void* data = bucket->GetData(0, data_size); |
| 8685 | if (!data) { |
| 8686 | return error::kInvalidArguments; |
| 8687 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8688 | return DoCompressedTexImage2D( |
| 8689 | target, level, internal_format, width, height, border, |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8690 | imageSize, data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8691 | } |
| 8692 | |
| 8693 | error::Error GLES2DecoderImpl::HandleCompressedTexSubImage2DBucket( |
| 8694 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8695 | const void* cmd_data) { |
| 8696 | const gles2::cmds::CompressedTexSubImage2DBucket& c = |
| 8697 | *static_cast<const gles2::cmds::CompressedTexSubImage2DBucket*>(cmd_data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8698 | GLenum target = static_cast<GLenum>(c.target); |
| 8699 | GLint level = static_cast<GLint>(c.level); |
| 8700 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 8701 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 8702 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8703 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8704 | GLenum format = static_cast<GLenum>(c.format); |
| 8705 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8706 | if (!bucket) { |
| 8707 | return error::kInvalidArguments; |
| 8708 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8709 | uint32 data_size = bucket->size(); |
| 8710 | GLsizei imageSize = data_size; |
| 8711 | const void* data = bucket->GetData(0, data_size); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 8712 | if (!data) { |
| 8713 | return error::kInvalidArguments; |
| 8714 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8715 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8716 | LOCAL_SET_GL_ERROR( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 8717 | GL_INVALID_ENUM, "glCompressedTexSubImage2D", "target"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8718 | return error::kNoError; |
| 8719 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8720 | if (!validators_->compressed_texture_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8721 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 8722 | "glCompressedTexSubImage2D", format, "format"); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8723 | return error::kNoError; |
| 8724 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8725 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8726 | LOCAL_SET_GL_ERROR( |
| 8727 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "width < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8728 | return error::kNoError; |
| 8729 | } |
| 8730 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8731 | LOCAL_SET_GL_ERROR( |
| 8732 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "height < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8733 | return error::kNoError; |
| 8734 | } |
| 8735 | if (imageSize < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8736 | LOCAL_SET_GL_ERROR( |
| 8737 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "imageSize < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8738 | return error::kNoError; |
| 8739 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8740 | DoCompressedTexSubImage2D( |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 8741 | target, level, xoffset, yoffset, width, height, format, imageSize, data); |
| 8742 | return error::kNoError; |
| 8743 | } |
| 8744 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8745 | error::Error GLES2DecoderImpl::HandleTexImage2D(uint32 immediate_data_size, |
| 8746 | const void* cmd_data) { |
| 8747 | const gles2::cmds::TexImage2D& c = |
| 8748 | *static_cast<const gles2::cmds::TexImage2D*>(cmd_data); |
[email protected] | 67f92942 | 2014-05-17 15:33:13 | [diff] [blame] | 8749 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexImage2D", |
| 8750 | "width", c.width, "height", c.height); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8751 | // Set as failed for now, but if it successed, this will be set to not failed. |
| 8752 | texture_state_.tex_image_2d_failed = true; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8753 | GLenum target = static_cast<GLenum>(c.target); |
| 8754 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8755 | // TODO(kloveless): Change TexImage2D command to use unsigned integer |
| 8756 | // for internalformat. |
| 8757 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8758 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8759 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8760 | GLint border = static_cast<GLint>(c.border); |
| 8761 | GLenum format = static_cast<GLenum>(c.format); |
| 8762 | GLenum type = static_cast<GLenum>(c.type); |
| 8763 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 8764 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 8765 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8766 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8767 | width, height, 1, format, type, state_.unpack_alignment, &pixels_size, |
| 8768 | NULL, NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 8769 | return error::kOutOfBounds; |
| 8770 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8771 | const void* pixels = NULL; |
| 8772 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 8773 | pixels = GetSharedMemoryAs<const void*>( |
| 8774 | pixels_shm_id, pixels_shm_offset, pixels_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 8775 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8776 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8777 | } |
| 8778 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8779 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8780 | TextureManager::DoTextImage2DArguments args = { |
| 8781 | target, level, internal_format, width, height, border, format, type, |
| 8782 | pixels, pixels_size}; |
| 8783 | texture_manager()->ValidateAndDoTexImage2D( |
| 8784 | &texture_state_, &state_, &framebuffer_state_, args); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 8785 | |
| 8786 | // This may be a slow command. Exit command processing to allow for |
| 8787 | // context preemption and GPU watchdog checks. |
| 8788 | ExitCommandProcessingEarly(); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 8789 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8790 | } |
| 8791 | |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8792 | error::Error GLES2DecoderImpl::HandleTexImage3D(uint32 immediate_data_size, |
| 8793 | const void* cmd_data) { |
| 8794 | // TODO(zmo): Unsafe ES3 API. |
| 8795 | if (!unsafe_es3_apis_enabled()) |
| 8796 | return error::kUnknownCommand; |
| 8797 | |
| 8798 | const gles2::cmds::TexImage3D& c = |
| 8799 | *static_cast<const gles2::cmds::TexImage3D*>(cmd_data); |
| 8800 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexImage3D", |
| 8801 | "widthXheight", c.width * c.height, "depth", c.depth); |
| 8802 | GLenum target = static_cast<GLenum>(c.target); |
| 8803 | GLint level = static_cast<GLint>(c.level); |
| 8804 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 8805 | GLsizei width = static_cast<GLsizei>(c.width); |
| 8806 | GLsizei height = static_cast<GLsizei>(c.height); |
| 8807 | GLsizei depth = static_cast<GLsizei>(c.depth); |
| 8808 | GLint border = static_cast<GLint>(c.border); |
| 8809 | GLenum format = static_cast<GLenum>(c.format); |
| 8810 | GLenum type = static_cast<GLenum>(c.type); |
| 8811 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 8812 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
| 8813 | uint32 pixels_size; |
| 8814 | if (!GLES2Util::ComputeImageDataSizes( |
| 8815 | width, height, depth, format, type, state_.unpack_alignment, &pixels_size, |
| 8816 | NULL, NULL)) { |
| 8817 | return error::kOutOfBounds; |
| 8818 | } |
| 8819 | const void* pixels = NULL; |
| 8820 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 8821 | pixels = GetSharedMemoryAs<const void*>( |
| 8822 | pixels_shm_id, pixels_shm_offset, pixels_size); |
| 8823 | if (!pixels) { |
| 8824 | return error::kOutOfBounds; |
| 8825 | } |
| 8826 | } |
| 8827 | |
| 8828 | glTexImage3D(target, level, internal_format, width, height, depth, border, |
| 8829 | format, type, pixels); |
| 8830 | |
| 8831 | // This may be a slow command. Exit command processing to allow for |
| 8832 | // context preemption and GPU watchdog checks. |
| 8833 | ExitCommandProcessingEarly(); |
| 8834 | return error::kNoError; |
| 8835 | } |
| 8836 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8837 | void GLES2DecoderImpl::DoCompressedTexSubImage2D( |
| 8838 | GLenum target, |
| 8839 | GLint level, |
| 8840 | GLint xoffset, |
| 8841 | GLint yoffset, |
| 8842 | GLsizei width, |
| 8843 | GLsizei height, |
| 8844 | GLenum format, |
| 8845 | GLsizei image_size, |
| 8846 | const void * data) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8847 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8848 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8849 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8850 | LOCAL_SET_GL_ERROR( |
| 8851 | GL_INVALID_OPERATION, |
| 8852 | "glCompressedTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8853 | return; |
| 8854 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8855 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8856 | GLenum type = 0; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8857 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8858 | if (!texture->GetLevelType(target, level, &type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8859 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8860 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8861 | "glCompressedTexSubImage2D", "level does not exist."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8862 | return; |
| 8863 | } |
| 8864 | if (internal_format != format) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8865 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8866 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8867 | "glCompressedTexSubImage2D", "format does not match internal format."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 8868 | return; |
| 8869 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8870 | if (!texture->ValidForTexture( |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8871 | target, level, xoffset, yoffset, width, height, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8872 | LOCAL_SET_GL_ERROR( |
| 8873 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8874 | return; |
| 8875 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8876 | |
| 8877 | if (!ValidateCompressedTexFuncData( |
| 8878 | "glCompressedTexSubImage2D", width, height, format, image_size) || |
| 8879 | !ValidateCompressedTexSubDimensions( |
| 8880 | "glCompressedTexSubImage2D", |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8881 | target, level, xoffset, yoffset, width, height, format, texture)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8882 | return; |
| 8883 | } |
| 8884 | |
| 8885 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8886 | // Note: There is no need to deal with texture cleared tracking here |
| 8887 | // because the validation above means you can only get here if the level |
| 8888 | // is already a matching compressed format and in that case |
| 8889 | // CompressedTexImage2D already cleared the texture. |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8890 | glCompressedTexSubImage2D( |
| 8891 | target, level, xoffset, yoffset, width, height, format, image_size, data); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 8892 | |
| 8893 | // This may be a slow command. Exit command processing to allow for |
| 8894 | // context preemption and GPU watchdog checks. |
| 8895 | ExitCommandProcessingEarly(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8896 | } |
| 8897 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 8898 | static void Clip( |
| 8899 | GLint start, GLint range, GLint sourceRange, |
| 8900 | GLint* out_start, GLint* out_range) { |
| 8901 | DCHECK(out_start); |
| 8902 | DCHECK(out_range); |
| 8903 | if (start < 0) { |
| 8904 | range += start; |
| 8905 | start = 0; |
| 8906 | } |
| 8907 | GLint end = start + range; |
| 8908 | if (end > sourceRange) { |
| 8909 | range -= end - sourceRange; |
| 8910 | } |
| 8911 | *out_start = start; |
| 8912 | *out_range = range; |
| 8913 | } |
| 8914 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8915 | void GLES2DecoderImpl::DoCopyTexImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 8916 | GLenum target, |
| 8917 | GLint level, |
| 8918 | GLenum internal_format, |
| 8919 | GLint x, |
| 8920 | GLint y, |
| 8921 | GLsizei width, |
| 8922 | GLsizei height, |
| 8923 | GLint border) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 8924 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 8925 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 8926 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8927 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8928 | LOCAL_SET_GL_ERROR( |
| 8929 | GL_INVALID_OPERATION, |
| 8930 | "glCopyTexImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 8931 | return; |
| 8932 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 8933 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 8934 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8935 | LOCAL_SET_GL_ERROR( |
| 8936 | GL_INVALID_OPERATION, "glCopyTexImage2D", "texture is immutable"); |
[email protected] | cedee33 | 2014-05-23 07:07:53 | [diff] [blame] | 8937 | return; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 8938 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 8939 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8940 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8941 | LOCAL_SET_GL_ERROR( |
| 8942 | GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range"); |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8943 | return; |
| 8944 | } |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 8945 | if (!texture_manager()->ValidateFormatAndTypeCombination( |
| 8946 | state_.GetErrorState(), "glCopyTexImage2D", internal_format, |
| 8947 | GL_UNSIGNED_BYTE)) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8948 | return; |
| 8949 | } |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 8950 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8951 | // Check we have compatible formats. |
| 8952 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 8953 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 8954 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); |
| 8955 | |
| 8956 | if ((channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8957 | LOCAL_SET_GL_ERROR( |
| 8958 | GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 8959 | return; |
| 8960 | } |
| 8961 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8962 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8963 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8964 | GL_INVALID_OPERATION, |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8965 | "glCopyTexImage2D", "can not be used with depth or stencil textures"); |
| 8966 | return; |
| 8967 | } |
| 8968 | |
| 8969 | uint32 estimated_size = 0; |
| 8970 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8971 | width, height, 1, internal_format, GL_UNSIGNED_BYTE, |
| 8972 | state_.unpack_alignment, &estimated_size, NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8973 | LOCAL_SET_GL_ERROR( |
| 8974 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 8975 | return; |
| 8976 | } |
| 8977 | |
| 8978 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8979 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "out of memory"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8980 | return; |
| 8981 | } |
| 8982 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 8983 | if (!CheckBoundReadFramebufferColorAttachment("glCopyTexImage2D")) { |
| 8984 | return; |
| 8985 | } |
| 8986 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 8987 | if (FormsTextureCopyingFeedbackLoop(texture_ref, level)) { |
| 8988 | LOCAL_SET_GL_ERROR( |
| 8989 | GL_INVALID_OPERATION, |
| 8990 | "glCopyTexImage2D", "source and destination textures are the same"); |
| 8991 | return; |
| 8992 | } |
| 8993 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 8994 | if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { |
| 8995 | return; |
| 8996 | } |
| 8997 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8998 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTexImage2D"); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 8999 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9000 | gfx::Size size = GetBoundReadFrameBufferSize(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 9001 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9002 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9003 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 9004 | } |
| 9005 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 9006 | // Clip to size to source dimensions |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9007 | GLint copyX = 0; |
| 9008 | GLint copyY = 0; |
| 9009 | GLint copyWidth = 0; |
| 9010 | GLint copyHeight = 0; |
| 9011 | Clip(x, width, size.width(), ©X, ©Width); |
| 9012 | Clip(y, height, size.height(), ©Y, ©Height); |
| 9013 | |
| 9014 | if (copyX != x || |
| 9015 | copyY != y || |
| 9016 | copyWidth != width || |
| 9017 | copyHeight != height) { |
| 9018 | // some part was clipped so clear the texture. |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 9019 | if (!ClearLevel( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9020 | texture->service_id(), texture->target(), |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 9021 | target, level, internal_format, internal_format, GL_UNSIGNED_BYTE, |
| 9022 | width, height, texture->IsImmutable())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9023 | LOCAL_SET_GL_ERROR( |
| 9024 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9025 | return; |
| 9026 | } |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9027 | if (copyHeight > 0 && copyWidth > 0) { |
| 9028 | GLint dx = copyX - x; |
| 9029 | GLint dy = copyY - y; |
| 9030 | GLint destX = dx; |
| 9031 | GLint destY = dy; |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 9032 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9033 | glCopyTexSubImage2D(target, level, |
| 9034 | destX, destY, copyX, copyY, |
| 9035 | copyWidth, copyHeight); |
| 9036 | } |
| 9037 | } else { |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 9038 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9039 | glCopyTexImage2D(target, level, internal_format, |
| 9040 | copyX, copyY, copyWidth, copyHeight, border); |
| 9041 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9042 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9043 | if (error == GL_NO_ERROR) { |
| 9044 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9045 | texture_ref, target, level, internal_format, width, height, 1, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 9046 | border, internal_format, GL_UNSIGNED_BYTE, true); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9047 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 9048 | |
| 9049 | // This may be a slow command. Exit command processing to allow for |
| 9050 | // context preemption and GPU watchdog checks. |
| 9051 | ExitCommandProcessingEarly(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9052 | } |
| 9053 | |
| 9054 | void GLES2DecoderImpl::DoCopyTexSubImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 9055 | GLenum target, |
| 9056 | GLint level, |
| 9057 | GLint xoffset, |
| 9058 | GLint yoffset, |
| 9059 | GLint x, |
| 9060 | GLint y, |
| 9061 | GLsizei width, |
| 9062 | GLsizei height) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 9063 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9064 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9065 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9066 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9067 | LOCAL_SET_GL_ERROR( |
| 9068 | GL_INVALID_OPERATION, |
| 9069 | "glCopyTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9070 | return; |
| 9071 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9072 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9073 | GLenum type = 0; |
| 9074 | GLenum format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9075 | if (!texture->GetLevelType(target, level, &type, &format) || |
| 9076 | !texture->ValidForTexture( |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 9077 | target, level, xoffset, yoffset, width, height, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9078 | LOCAL_SET_GL_ERROR( |
| 9079 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9080 | return; |
| 9081 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 9082 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9083 | LOCAL_SET_GL_ERROR( |
| 9084 | GL_INVALID_OPERATION, |
| 9085 | "glCopyTexSubImage2D", "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 9086 | return; |
| 9087 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 9088 | |
| 9089 | // Check we have compatible formats. |
| 9090 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 9091 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 9092 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(format); |
| 9093 | |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 9094 | if (!channels_needed || |
| 9095 | (channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9096 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9097 | GL_INVALID_OPERATION, "glCopyTexSubImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 9098 | return; |
| 9099 | } |
| 9100 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9101 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9102 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9103 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9104 | "glCopySubImage2D", "can not be used with depth or stencil textures"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9105 | return; |
| 9106 | } |
| 9107 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 9108 | if (!CheckBoundReadFramebufferColorAttachment("glCopyTexSubImage2D")) { |
| 9109 | return; |
| 9110 | } |
| 9111 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 9112 | if (FormsTextureCopyingFeedbackLoop(texture_ref, level)) { |
| 9113 | LOCAL_SET_GL_ERROR( |
| 9114 | GL_INVALID_OPERATION, |
| 9115 | "glCopyTexSubImage2D", "source and destination textures are the same"); |
| 9116 | return; |
| 9117 | } |
| 9118 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 9119 | if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) { |
| 9120 | return; |
| 9121 | } |
| 9122 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 9123 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9124 | gfx::Size size = GetBoundReadFrameBufferSize(); |
| 9125 | GLint copyX = 0; |
| 9126 | GLint copyY = 0; |
| 9127 | GLint copyWidth = 0; |
| 9128 | GLint copyHeight = 0; |
| 9129 | Clip(x, width, size.width(), ©X, ©Width); |
| 9130 | Clip(y, height, size.height(), ©Y, ©Height); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 9131 | |
dongseong.hwang | 351519f | 2015-01-21 14:33:59 | [diff] [blame] | 9132 | if (xoffset != 0 || yoffset != 0 || width != size.width() || |
| 9133 | height != size.height()) { |
| 9134 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, |
| 9135 | level)) { |
| 9136 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", |
| 9137 | "dimensions too big"); |
| 9138 | return; |
| 9139 | } |
| 9140 | } else { |
| 9141 | // Write all pixels in below. |
| 9142 | texture_manager()->SetLevelCleared(texture_ref, target, level, true); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 9143 | } |
| 9144 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9145 | if (copyX != x || |
| 9146 | copyY != y || |
| 9147 | copyWidth != width || |
| 9148 | copyHeight != height) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 9149 | // some part was clipped so clear the sub rect. |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9150 | uint32 pixels_size = 0; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 9151 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 9152 | width, height, 1, format, type, state_.unpack_alignment, &pixels_size, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9153 | NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9154 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9155 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9156 | return; |
| 9157 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 9158 | scoped_ptr<char[]> zero(new char[pixels_size]); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9159 | memset(zero.get(), 0, pixels_size); |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 9160 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9161 | glTexSubImage2D( |
| 9162 | target, level, xoffset, yoffset, width, height, |
| 9163 | format, type, zero.get()); |
| 9164 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 9165 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9166 | if (copyHeight > 0 && copyWidth > 0) { |
| 9167 | GLint dx = copyX - x; |
| 9168 | GLint dy = copyY - y; |
| 9169 | GLint destX = xoffset + dx; |
| 9170 | GLint destY = yoffset + dy; |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 9171 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9172 | glCopyTexSubImage2D(target, level, |
| 9173 | destX, destY, copyX, copyY, |
| 9174 | copyWidth, copyHeight); |
| 9175 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 9176 | |
| 9177 | // This may be a slow command. Exit command processing to allow for |
| 9178 | // context preemption and GPU watchdog checks. |
| 9179 | ExitCommandProcessingEarly(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9180 | } |
| 9181 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9182 | bool GLES2DecoderImpl::ValidateTexSubImage2D( |
| 9183 | error::Error* error, |
| 9184 | const char* function_name, |
| 9185 | GLenum target, |
| 9186 | GLint level, |
| 9187 | GLint xoffset, |
| 9188 | GLint yoffset, |
| 9189 | GLsizei width, |
| 9190 | GLsizei height, |
| 9191 | GLenum format, |
| 9192 | GLenum type, |
| 9193 | const void * data) { |
| 9194 | (*error) = error::kNoError; |
| 9195 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9196 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9197 | return false; |
| 9198 | } |
| 9199 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9200 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "width < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9201 | return false; |
| 9202 | } |
| 9203 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9204 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "height < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9205 | return false; |
| 9206 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9207 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9208 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9209 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9210 | LOCAL_SET_GL_ERROR( |
| 9211 | GL_INVALID_OPERATION, |
| 9212 | function_name, "unknown texture for target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9213 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9214 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9215 | Texture* texture = texture_ref->texture(); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 9216 | GLenum current_type = 0; |
| 9217 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9218 | if (!texture->GetLevelType(target, level, ¤t_type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9219 | LOCAL_SET_GL_ERROR( |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9220 | GL_INVALID_OPERATION, function_name, "level does not exist."); |
| 9221 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 9222 | } |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 9223 | if (!texture_manager()->ValidateTextureParameters(state_.GetErrorState(), |
| 9224 | function_name, format, type, internal_format, level)) { |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9225 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 9226 | } |
| 9227 | if (type != current_type) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9228 | LOCAL_SET_GL_ERROR( |
| 9229 | GL_INVALID_OPERATION, |
| 9230 | function_name, "type does not match type of texture."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9231 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 9232 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 9233 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9234 | LOCAL_SET_GL_ERROR( |
| 9235 | GL_INVALID_OPERATION, |
| 9236 | function_name, "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 9237 | return false; |
| 9238 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9239 | if (!texture->ValidForTexture( |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 9240 | target, level, xoffset, yoffset, width, height, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9241 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "bad dimensions."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9242 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9243 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9244 | if ((GLES2Util::GetChannelsForFormat(format) & |
| 9245 | (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9246 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9247 | GL_INVALID_OPERATION, |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9248 | function_name, "can not supply data for depth or stencil textures"); |
| 9249 | return false; |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9250 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9251 | if (data == NULL) { |
| 9252 | (*error) = error::kOutOfBounds; |
| 9253 | return false; |
| 9254 | } |
| 9255 | return true; |
| 9256 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9257 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9258 | error::Error GLES2DecoderImpl::DoTexSubImage2D( |
| 9259 | GLenum target, |
| 9260 | GLint level, |
| 9261 | GLint xoffset, |
| 9262 | GLint yoffset, |
| 9263 | GLsizei width, |
| 9264 | GLsizei height, |
| 9265 | GLenum format, |
| 9266 | GLenum type, |
| 9267 | const void * data) { |
| 9268 | error::Error error = error::kNoError; |
| 9269 | if (!ValidateTexSubImage2D(&error, "glTexSubImage2D", target, level, |
| 9270 | xoffset, yoffset, width, height, format, type, data)) { |
| 9271 | return error; |
| 9272 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9273 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9274 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9275 | Texture* texture = texture_ref->texture(); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9276 | GLsizei tex_width = 0; |
| 9277 | GLsizei tex_height = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9278 | bool ok = texture->GetLevelSize(target, level, &tex_width, &tex_height); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9279 | DCHECK(ok); |
| 9280 | if (xoffset != 0 || yoffset != 0 || |
| 9281 | width != tex_width || height != tex_height) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9282 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, |
| 9283 | target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9284 | LOCAL_SET_GL_ERROR( |
| 9285 | GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9286 | return error::kNoError; |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 9287 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9288 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9289 | glTexSubImage2D( |
| 9290 | target, level, xoffset, yoffset, width, height, format, type, data); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9291 | return error::kNoError; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 9292 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9293 | |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 9294 | if (!texture_state_.texsubimage2d_faster_than_teximage2d && |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9295 | !texture->IsImmutable()) { |
| 9296 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 9297 | GLenum internal_format; |
| 9298 | GLenum tex_type; |
| 9299 | texture->GetLevelType(target, level, &tex_type, &internal_format); |
| 9300 | // NOTE: In OpenGL ES 2.0 border is always zero. If that changes we'll need |
| 9301 | // to look it up. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 9302 | glTexImage2D( |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 9303 | target, level, internal_format, width, height, 0, format, type, data); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9304 | } else { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9305 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 9306 | glTexSubImage2D( |
| 9307 | target, level, xoffset, yoffset, width, height, format, type, data); |
| 9308 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9309 | texture_manager()->SetLevelCleared(texture_ref, target, level, true); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 9310 | |
| 9311 | // This may be a slow command. Exit command processing to allow for |
| 9312 | // context preemption and GPU watchdog checks. |
| 9313 | ExitCommandProcessingEarly(); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9314 | return error::kNoError; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9315 | } |
| 9316 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9317 | error::Error GLES2DecoderImpl::HandleTexSubImage2D(uint32 immediate_data_size, |
| 9318 | const void* cmd_data) { |
| 9319 | const gles2::cmds::TexSubImage2D& c = |
| 9320 | *static_cast<const gles2::cmds::TexSubImage2D*>(cmd_data); |
[email protected] | 67f92942 | 2014-05-17 15:33:13 | [diff] [blame] | 9321 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexSubImage2D", |
| 9322 | "width", c.width, "height", c.height); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 9323 | GLboolean internal = static_cast<GLboolean>(c.internal); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9324 | if (internal == GL_TRUE && texture_state_.tex_image_2d_failed) |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 9325 | return error::kNoError; |
| 9326 | |
| 9327 | GLenum target = static_cast<GLenum>(c.target); |
| 9328 | GLint level = static_cast<GLint>(c.level); |
| 9329 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 9330 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 9331 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9332 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9333 | GLenum format = static_cast<GLenum>(c.format); |
| 9334 | GLenum type = static_cast<GLenum>(c.type); |
| 9335 | uint32 data_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 9336 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 9337 | width, height, 1, format, type, state_.unpack_alignment, &data_size, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 9338 | NULL, NULL)) { |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 9339 | return error::kOutOfBounds; |
| 9340 | } |
| 9341 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 9342 | c.pixels_shm_id, c.pixels_shm_offset, data_size); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9343 | return DoTexSubImage2D( |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 9344 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 9345 | } |
| 9346 | |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 9347 | // TODO(zmo): Remove the below stub once we add the real function binding. |
| 9348 | // Currently it's missing due to a gmock limitation. |
| 9349 | static void glTexSubImage3D( |
| 9350 | GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, |
| 9351 | GLsizei height, GLsizei width, GLsizei depth, GLenum format, GLenum type, |
| 9352 | const void* pixels) { |
| 9353 | NOTIMPLEMENTED(); |
| 9354 | } |
| 9355 | |
| 9356 | error::Error GLES2DecoderImpl::HandleTexSubImage3D(uint32 immediate_data_size, |
| 9357 | const void* cmd_data) { |
| 9358 | // TODO(zmo): Unsafe ES3 API. |
| 9359 | if (!unsafe_es3_apis_enabled()) |
| 9360 | return error::kUnknownCommand; |
| 9361 | |
| 9362 | const gles2::cmds::TexSubImage3D& c = |
| 9363 | *static_cast<const gles2::cmds::TexSubImage3D*>(cmd_data); |
| 9364 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexSubImage3D", |
| 9365 | "widthXheight", c.width * c.height, "depth", c.depth); |
| 9366 | GLenum target = static_cast<GLenum>(c.target); |
| 9367 | GLint level = static_cast<GLint>(c.level); |
| 9368 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 9369 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 9370 | GLint zoffset = static_cast<GLint>(c.zoffset); |
| 9371 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9372 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9373 | GLsizei depth = static_cast<GLsizei>(c.depth); |
| 9374 | GLenum format = static_cast<GLenum>(c.format); |
| 9375 | GLenum type = static_cast<GLenum>(c.type); |
| 9376 | uint32 data_size; |
| 9377 | if (!GLES2Util::ComputeImageDataSizes( |
| 9378 | width, height, depth, format, type, state_.unpack_alignment, &data_size, |
| 9379 | NULL, NULL)) { |
| 9380 | return error::kOutOfBounds; |
| 9381 | } |
| 9382 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 9383 | c.pixels_shm_id, c.pixels_shm_offset, data_size); |
| 9384 | glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, |
| 9385 | depth, format, type, pixels); |
| 9386 | return error::kNoError; |
| 9387 | } |
| 9388 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9389 | error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9390 | uint32 immediate_data_size, |
| 9391 | const void* cmd_data) { |
| 9392 | const gles2::cmds::GetVertexAttribPointerv& c = |
| 9393 | *static_cast<const gles2::cmds::GetVertexAttribPointerv*>(cmd_data); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9394 | GLuint index = static_cast<GLuint>(c.index); |
| 9395 | GLenum pname = static_cast<GLenum>(c.pname); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9396 | typedef cmds::GetVertexAttribPointerv::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9397 | Result* result = GetSharedMemoryAs<Result*>( |
| 9398 | c.pointer_shm_id, c.pointer_shm_offset, Result::ComputeSize(1)); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9399 | if (!result) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9400 | return error::kOutOfBounds; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9401 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9402 | // Check that the client initialized the result. |
| 9403 | if (result->size != 0) { |
| 9404 | return error::kInvalidArguments; |
| 9405 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9406 | if (!validators_->vertex_pointer.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9407 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 9408 | "glGetVertexAttribPointerv", pname, "pname"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9409 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9410 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 9411 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9412 | LOCAL_SET_GL_ERROR( |
| 9413 | GL_INVALID_VALUE, "glGetVertexAttribPointerv", "index out of range."); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9414 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 9415 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9416 | result->SetNumResults(1); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 9417 | *result->GetData() = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9418 | state_.vertex_attrib_manager->GetVertexAttrib(index)->offset(); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9419 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9420 | } |
| 9421 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9422 | bool GLES2DecoderImpl::GetUniformSetup( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9423 | GLuint program_id, GLint fake_location, |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9424 | uint32 shm_id, uint32 shm_offset, |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9425 | error::Error* error, GLint* real_location, |
| 9426 | GLuint* service_id, void** result_pointer, GLenum* result_type) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9427 | DCHECK(error); |
| 9428 | DCHECK(service_id); |
| 9429 | DCHECK(result_pointer); |
| 9430 | DCHECK(result_type); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9431 | DCHECK(real_location); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9432 | *error = error::kNoError; |
| 9433 | // Make sure we have enough room for the result on failure. |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9434 | SizedResult<GLint>* result; |
| 9435 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 9436 | shm_id, shm_offset, SizedResult<GLint>::ComputeSize(0)); |
| 9437 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9438 | *error = error::kOutOfBounds; |
| 9439 | return false; |
| 9440 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9441 | *result_pointer = result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9442 | // 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] | 9443 | result->SetNumResults(0); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9444 | Program* program = GetProgramInfoNotShader(program_id, "glGetUniform"); |
| 9445 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 9446 | return false; |
| 9447 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9448 | if (!program->IsValid()) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9449 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9450 | LOCAL_SET_GL_ERROR( |
| 9451 | GL_INVALID_OPERATION, "glGetUniform", "program not linked"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9452 | return false; |
| 9453 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9454 | *service_id = program->service_id(); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 9455 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9456 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9457 | program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9458 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 9459 | if (!uniform_info) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9460 | // No such location. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9461 | LOCAL_SET_GL_ERROR( |
| 9462 | GL_INVALID_OPERATION, "glGetUniform", "unknown location"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9463 | return false; |
| 9464 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 9465 | GLenum type = uniform_info->type; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 9466 | GLsizei size = GLES2Util::GetGLDataTypeSizeForUniforms(type); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9467 | if (size == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9468 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glGetUniform", "unknown type"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9469 | return false; |
| 9470 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9471 | result = GetSharedMemoryAs<SizedResult<GLint>*>( |
| 9472 | shm_id, shm_offset, SizedResult<GLint>::ComputeSizeFromBytes(size)); |
| 9473 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9474 | *error = error::kOutOfBounds; |
| 9475 | return false; |
| 9476 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9477 | result->size = size; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9478 | *result_type = type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9479 | return true; |
| 9480 | } |
| 9481 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9482 | error::Error GLES2DecoderImpl::HandleGetUniformiv(uint32 immediate_data_size, |
| 9483 | const void* cmd_data) { |
| 9484 | const gles2::cmds::GetUniformiv& c = |
| 9485 | *static_cast<const gles2::cmds::GetUniformiv*>(cmd_data); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9486 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 9487 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9488 | GLuint service_id; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9489 | GLenum result_type; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9490 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9491 | Error error; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9492 | void* result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9493 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9494 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 9495 | &error, &real_location, &service_id, &result, &result_type)) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9496 | glGetUniformiv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9497 | service_id, real_location, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9498 | static_cast<cmds::GetUniformiv::Result*>(result)->GetData()); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9499 | } |
| 9500 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9501 | } |
| 9502 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9503 | error::Error GLES2DecoderImpl::HandleGetUniformfv(uint32 immediate_data_size, |
| 9504 | const void* cmd_data) { |
| 9505 | const gles2::cmds::GetUniformfv& c = |
| 9506 | *static_cast<const gles2::cmds::GetUniformfv*>(cmd_data); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9507 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 9508 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9509 | GLuint service_id; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9510 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9511 | Error error; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9512 | typedef cmds::GetUniformfv::Result Result; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9513 | Result* result; |
| 9514 | GLenum result_type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9515 | if (GetUniformSetup( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9516 | program, fake_location, c.params_shm_id, c.params_shm_offset, |
| 9517 | &error, &real_location, &service_id, |
| 9518 | reinterpret_cast<void**>(&result), &result_type)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9519 | if (result_type == GL_BOOL || result_type == GL_BOOL_VEC2 || |
| 9520 | result_type == GL_BOOL_VEC3 || result_type == GL_BOOL_VEC4) { |
| 9521 | GLsizei num_values = result->GetNumResults(); |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 9522 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9523 | glGetUniformiv(service_id, real_location, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9524 | GLfloat* dst = result->GetData(); |
| 9525 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
| 9526 | dst[ii] = (temp[ii] != 0); |
| 9527 | } |
| 9528 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 9529 | glGetUniformfv(service_id, real_location, result->GetData()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 9530 | } |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 9531 | } |
| 9532 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9533 | } |
| 9534 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9535 | error::Error GLES2DecoderImpl::HandleGetShaderPrecisionFormat( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9536 | uint32 immediate_data_size, |
| 9537 | const void* cmd_data) { |
| 9538 | const gles2::cmds::GetShaderPrecisionFormat& c = |
| 9539 | *static_cast<const gles2::cmds::GetShaderPrecisionFormat*>(cmd_data); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9540 | GLenum shader_type = static_cast<GLenum>(c.shadertype); |
| 9541 | GLenum precision_type = static_cast<GLenum>(c.precisiontype); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9542 | typedef cmds::GetShaderPrecisionFormat::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9543 | Result* result = GetSharedMemoryAs<Result*>( |
| 9544 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9545 | if (!result) { |
| 9546 | return error::kOutOfBounds; |
| 9547 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9548 | // Check that the client initialized the result. |
| 9549 | if (result->success != 0) { |
| 9550 | return error::kInvalidArguments; |
| 9551 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9552 | if (!validators_->shader_type.IsValid(shader_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9553 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 9554 | "glGetShaderPrecisionFormat", shader_type, "shader_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 9555 | return error::kNoError; |
| 9556 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9557 | if (!validators_->shader_precision.IsValid(precision_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9558 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 9559 | "glGetShaderPrecisionFormat", precision_type, "precision_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 9560 | return error::kNoError; |
| 9561 | } |
| 9562 | |
| 9563 | result->success = 1; // true |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 9564 | |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 9565 | GLint range[2] = { 0, 0 }; |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 9566 | GLint precision = 0; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 9567 | GetShaderPrecisionFormatImpl(shader_type, precision_type, range, &precision); |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 9568 | |
| 9569 | result->min_range = range[0]; |
| 9570 | result->max_range = range[1]; |
| 9571 | result->precision = precision; |
| 9572 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9573 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9574 | } |
| 9575 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9576 | error::Error GLES2DecoderImpl::HandleGetAttachedShaders( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9577 | uint32 immediate_data_size, |
| 9578 | const void* cmd_data) { |
| 9579 | const gles2::cmds::GetAttachedShaders& c = |
| 9580 | *static_cast<const gles2::cmds::GetAttachedShaders*>(cmd_data); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9581 | uint32 result_size = c.result_size; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9582 | GLuint program_id = static_cast<GLuint>(c.program); |
| 9583 | Program* program = GetProgramInfoNotShader( |
| 9584 | program_id, "glGetAttachedShaders"); |
| 9585 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9586 | return error::kNoError; |
| 9587 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9588 | typedef cmds::GetAttachedShaders::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9589 | uint32 max_count = Result::ComputeMaxResults(result_size); |
| 9590 | Result* result = GetSharedMemoryAs<Result*>( |
| 9591 | c.result_shm_id, c.result_shm_offset, Result::ComputeSize(max_count)); |
| 9592 | if (!result) { |
| 9593 | return error::kOutOfBounds; |
| 9594 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9595 | // Check that the client initialized the result. |
| 9596 | if (result->size != 0) { |
| 9597 | return error::kInvalidArguments; |
| 9598 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9599 | GLsizei count = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 9600 | glGetAttachedShaders( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9601 | program->service_id(), max_count, &count, result->GetData()); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9602 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 9603 | if (!shader_manager()->GetClientId(result->GetData()[ii], |
| 9604 | &result->GetData()[ii])) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9605 | NOTREACHED(); |
| 9606 | return error::kGenericError; |
| 9607 | } |
| 9608 | } |
| 9609 | result->SetNumResults(count); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9610 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9611 | } |
| 9612 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9613 | error::Error GLES2DecoderImpl::HandleGetActiveUniform( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9614 | uint32 immediate_data_size, |
| 9615 | const void* cmd_data) { |
| 9616 | const gles2::cmds::GetActiveUniform& c = |
| 9617 | *static_cast<const gles2::cmds::GetActiveUniform*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9618 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9619 | GLuint index = c.index; |
| 9620 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9621 | typedef cmds::GetActiveUniform::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9622 | Result* result = GetSharedMemoryAs<Result*>( |
| 9623 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9624 | if (!result) { |
| 9625 | return error::kOutOfBounds; |
| 9626 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9627 | // Check that the client initialized the result. |
| 9628 | if (result->success != 0) { |
| 9629 | return error::kInvalidArguments; |
| 9630 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9631 | Program* program = GetProgramInfoNotShader( |
| 9632 | program_id, "glGetActiveUniform"); |
| 9633 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9634 | return error::kNoError; |
| 9635 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9636 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9637 | program->GetUniformInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9638 | if (!uniform_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9639 | LOCAL_SET_GL_ERROR( |
| 9640 | GL_INVALID_VALUE, "glGetActiveUniform", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9641 | return error::kNoError; |
| 9642 | } |
| 9643 | result->success = 1; // true. |
| 9644 | result->size = uniform_info->size; |
| 9645 | result->type = uniform_info->type; |
| 9646 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 9647 | bucket->SetFromString(uniform_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9648 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9649 | } |
| 9650 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9651 | error::Error GLES2DecoderImpl::HandleGetActiveAttrib(uint32 immediate_data_size, |
| 9652 | const void* cmd_data) { |
| 9653 | const gles2::cmds::GetActiveAttrib& c = |
| 9654 | *static_cast<const gles2::cmds::GetActiveAttrib*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9655 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9656 | GLuint index = c.index; |
| 9657 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9658 | typedef cmds::GetActiveAttrib::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9659 | Result* result = GetSharedMemoryAs<Result*>( |
| 9660 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9661 | if (!result) { |
| 9662 | return error::kOutOfBounds; |
| 9663 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 9664 | // Check that the client initialized the result. |
| 9665 | if (result->success != 0) { |
| 9666 | return error::kInvalidArguments; |
| 9667 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9668 | Program* program = GetProgramInfoNotShader( |
| 9669 | program_id, "glGetActiveAttrib"); |
| 9670 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9671 | return error::kNoError; |
| 9672 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9673 | const Program::VertexAttrib* attrib_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9674 | program->GetAttribInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9675 | if (!attrib_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9676 | LOCAL_SET_GL_ERROR( |
| 9677 | GL_INVALID_VALUE, "glGetActiveAttrib", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 9678 | return error::kNoError; |
| 9679 | } |
| 9680 | result->success = 1; // true. |
| 9681 | result->size = attrib_info->size; |
| 9682 | result->type = attrib_info->type; |
| 9683 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 9684 | bucket->SetFromString(attrib_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9685 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 9686 | } |
| 9687 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9688 | error::Error GLES2DecoderImpl::HandleShaderBinary(uint32 immediate_data_size, |
| 9689 | const void* cmd_data) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9690 | #if 1 // No binary shader support. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9691 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glShaderBinary", "not supported"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9692 | return error::kNoError; |
| 9693 | #else |
| 9694 | GLsizei n = static_cast<GLsizei>(c.n); |
| 9695 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9696 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "n < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9697 | return error::kNoError; |
| 9698 | } |
| 9699 | GLsizei length = static_cast<GLsizei>(c.length); |
| 9700 | if (length < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9701 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "length < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9702 | return error::kNoError; |
| 9703 | } |
| 9704 | uint32 data_size; |
| 9705 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 9706 | return error::kOutOfBounds; |
| 9707 | } |
| 9708 | const GLuint* shaders = GetSharedMemoryAs<const GLuint*>( |
| 9709 | c.shaders_shm_id, c.shaders_shm_offset, data_size); |
| 9710 | GLenum binaryformat = static_cast<GLenum>(c.binaryformat); |
| 9711 | const void* binary = GetSharedMemoryAs<const void*>( |
| 9712 | c.binary_shm_id, c.binary_shm_offset, length); |
| 9713 | if (shaders == NULL || binary == NULL) { |
| 9714 | return error::kOutOfBounds; |
| 9715 | } |
[email protected] | 0782b14b | 2014-05-24 13:04:16 | [diff] [blame] | 9716 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9717 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9718 | Shader* shader = GetShader(shaders[ii]); |
| 9719 | if (!shader) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9720 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "unknown shader"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9721 | return error::kNoError; |
| 9722 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9723 | service_ids[ii] = shader->service_id(); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 9724 | } |
| 9725 | // TODO(gman): call glShaderBinary |
| 9726 | return error::kNoError; |
| 9727 | #endif |
| 9728 | } |
| 9729 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9730 | void GLES2DecoderImpl::DoSwapBuffers() { |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 9731 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 9732 | |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 9733 | int this_frame_number = frame_number_++; |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 9734 | // TRACE_EVENT for gpu tests: |
| 9735 | TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffersLatency", |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 9736 | TRACE_EVENT_SCOPE_THREAD, |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 9737 | "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
| 9738 | "width", (is_offscreen ? offscreen_size_.width() : |
| 9739 | surface_->GetSize().width())); |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9740 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoSwapBuffers", |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 9741 | "offscreen", is_offscreen, |
| 9742 | "frame", this_frame_number); |
[email protected] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 9743 | { |
[email protected] | a36ed483 | 2014-04-24 16:40:27 | [diff] [blame] | 9744 | TRACE_EVENT_SYNTHETIC_DELAY("gpu.PresentingFrame"); |
[email protected] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 9745 | } |
| 9746 | |
dyen | b547eff6 | 2015-01-17 00:14:56 | [diff] [blame] | 9747 | ScopedGPUTrace scoped_gpu_trace(gpu_tracer_.get(), kTraceDecoder, |
| 9748 | "gpu_toplevel", "SwapBuffer"); |
| 9749 | |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 9750 | bool is_tracing; |
| 9751 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 9752 | &is_tracing); |
| 9753 | if (is_tracing) { |
| 9754 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 9755 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 9756 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 9757 | } |
| 9758 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9759 | // If offscreen then don't actually SwapBuffers to the display. Just copy |
| 9760 | // the rendered frame to another frame buffer. |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 9761 | if (is_offscreen) { |
[email protected] | 111975c6 | 2012-09-06 01:37:31 | [diff] [blame] | 9762 | TRACE_EVENT2("gpu", "Offscreen", |
| 9763 | "width", offscreen_size_.width(), "height", offscreen_size_.height()); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9764 | if (offscreen_size_ != offscreen_saved_color_texture_->size()) { |
| 9765 | // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, |
| 9766 | // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will |
| 9767 | // fix this. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 9768 | if (workarounds().needs_offscreen_buffer_workaround) { |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9769 | offscreen_saved_frame_buffer_->Create(); |
| 9770 | glFinish(); |
| 9771 | } |
| 9772 | |
| 9773 | // Allocate the offscreen saved color texture. |
| 9774 | DCHECK(offscreen_saved_color_format_); |
| 9775 | offscreen_saved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 9776 | offscreen_size_, offscreen_saved_color_format_, false); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9777 | |
| 9778 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 9779 | offscreen_saved_color_texture_.get()); |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9780 | if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { |
| 9781 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 9782 | GL_FRAMEBUFFER_COMPLETE) { |
| 9783 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 9784 | << "because offscreen saved FBO was incomplete."; |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9785 | LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
| 9786 | return; |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9787 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9788 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9789 | // Clear the offscreen color texture. |
| 9790 | // TODO(piman): Is this still necessary? |
| 9791 | { |
| 9792 | ScopedFrameBufferBinder binder(this, |
| 9793 | offscreen_saved_frame_buffer_->id()); |
| 9794 | glClearColor(0, 0, 0, 0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 9795 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 9796 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9797 | glClear(GL_COLOR_BUFFER_BIT); |
| 9798 | RestoreClearState(); |
| 9799 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 9800 | } |
| 9801 | |
| 9802 | UpdateParentTextureInfo(); |
| 9803 | } |
| 9804 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 9805 | if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9806 | return; |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9807 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 9808 | "GLES2DecoderImpl::DoSwapBuffers", GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9809 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 9810 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 9811 | // For multisampled buffers, resolve the frame buffer. |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 9812 | ScopedResolvedFrameBufferBinder binder(this, true, false); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 9813 | } else { |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9814 | ScopedFrameBufferBinder binder(this, |
| 9815 | offscreen_target_frame_buffer_->id()); |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 9816 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9817 | if (offscreen_target_buffer_preserved_) { |
| 9818 | // Copy the target frame buffer to the saved offscreen texture. |
| 9819 | offscreen_saved_color_texture_->Copy( |
| 9820 | offscreen_saved_color_texture_->size(), |
| 9821 | offscreen_saved_color_format_); |
| 9822 | } else { |
| 9823 | // Flip the textures in the parent context via the texture manager. |
| 9824 | if (!!offscreen_saved_color_texture_info_.get()) |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9825 | offscreen_saved_color_texture_info_->texture()-> |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9826 | SetServiceId(offscreen_target_color_texture_->id()); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 9827 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9828 | offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); |
| 9829 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 9830 | offscreen_target_color_texture_.get()); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 9831 | } |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9832 | |
| 9833 | // Ensure the side effects of the copy are visible to the parent |
| 9834 | // context. There is no need to do this for ANGLE because it uses a |
| 9835 | // single D3D device for all contexts. |
zmo | 68fcdc6 | 2014-12-05 21:51:49 | [diff] [blame] | 9836 | if (!feature_info_->gl_version_info().is_angle) |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 9837 | glFlush(); |
[email protected] | 0c8c9d2 | 2010-06-25 17:36:39 | [diff] [blame] | 9838 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9839 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 9840 | if (!surface_->SwapBuffers()) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 9841 | LOG(ERROR) << "Context lost because SwapBuffers failed."; |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 9842 | LoseContext(GL_UNKNOWN_CONTEXT_RESET_ARB); |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 9843 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9844 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 9845 | |
| 9846 | // This may be a slow command. Exit command processing to allow for |
| 9847 | // context preemption and GPU watchdog checks. |
| 9848 | ExitCommandProcessingEarly(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 9849 | } |
| 9850 | |
bajones | 2345c1f | 2014-12-09 04:45:51 | [diff] [blame] | 9851 | void GLES2DecoderImpl::DoSwapInterval(int interval) |
| 9852 | { |
| 9853 | context_->SetSwapInterval(interval); |
| 9854 | } |
| 9855 | |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 9856 | error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9857 | uint32 immediate_data_size, |
| 9858 | const void* cmd_data) { |
| 9859 | const gles2::cmds::EnableFeatureCHROMIUM& c = |
| 9860 | *static_cast<const gles2::cmds::EnableFeatureCHROMIUM*>(cmd_data); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9861 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9862 | if (!bucket || bucket->size() == 0) { |
| 9863 | return error::kInvalidArguments; |
| 9864 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9865 | typedef cmds::EnableFeatureCHROMIUM::Result Result; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9866 | Result* result = GetSharedMemoryAs<Result*>( |
| 9867 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 9868 | if (!result) { |
| 9869 | return error::kOutOfBounds; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 9870 | } |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9871 | // Check that the client initialized the result. |
| 9872 | if (*result != 0) { |
| 9873 | return error::kInvalidArguments; |
| 9874 | } |
| 9875 | std::string feature_str; |
| 9876 | if (!bucket->GetAsString(&feature_str)) { |
| 9877 | return error::kInvalidArguments; |
| 9878 | } |
| 9879 | |
| 9880 | // TODO(gman): make this some kind of table to function pointer thingy. |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 9881 | if (feature_str.compare("pepper3d_allow_buffers_on_multiple_targets") == 0) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9882 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 9883 | } else if (feature_str.compare("pepper3d_support_fixed_attribs") == 0) { |
penghuang | 0140c18 | 2015-01-12 23:20:12 | [diff] [blame] | 9884 | buffer_manager()->set_allow_fixed_attribs(true); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 9885 | // TODO(gman): decide how to remove the need for this const_cast. |
| 9886 | // I could make validators_ non const but that seems bad as this is the only |
| 9887 | // place it is needed. I could make some special friend class of validators |
| 9888 | // just to allow this to set them. That seems silly. I could refactor this |
| 9889 | // code to use the extension mechanism or the initialization attributes to |
| 9890 | // turn this feature on. Given that the only real point of this is to make |
| 9891 | // the conformance tests pass and given that there is lots of real work that |
| 9892 | // needs to be done it seems like refactoring for one to one of those |
| 9893 | // methods is a very low priority. |
| 9894 | const_cast<Validators*>(validators_)->vertex_attrib_type.AddValue(GL_FIXED); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 9895 | } else if (feature_str.compare("webgl_enable_glsl_webgl_validation") == 0) { |
| 9896 | force_webgl_glsl_validation_ = true; |
| 9897 | InitializeShaderTranslator(); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 9898 | } else { |
| 9899 | return error::kNoError; |
| 9900 | } |
| 9901 | |
| 9902 | *result = 1; // true. |
| 9903 | return error::kNoError; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 9904 | } |
| 9905 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9906 | error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( |
| 9907 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9908 | const void* cmd_data) { |
| 9909 | const gles2::cmds::GetRequestableExtensionsCHROMIUM& c = |
| 9910 | *static_cast<const gles2::cmds::GetRequestableExtensionsCHROMIUM*>( |
| 9911 | cmd_data); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9912 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9913 | scoped_refptr<FeatureInfo> info(new FeatureInfo()); |
[email protected] | 956aec5 | 2013-09-05 15:41:19 | [diff] [blame] | 9914 | info->Initialize(disallowed_features_); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9915 | bucket->SetFromString(info->extensions().c_str()); |
| 9916 | return error::kNoError; |
| 9917 | } |
| 9918 | |
| 9919 | error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9920 | uint32 immediate_data_size, |
| 9921 | const void* cmd_data) { |
| 9922 | const gles2::cmds::RequestExtensionCHROMIUM& c = |
| 9923 | *static_cast<const gles2::cmds::RequestExtensionCHROMIUM*>(cmd_data); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9924 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9925 | if (!bucket || bucket->size() == 0) { |
| 9926 | return error::kInvalidArguments; |
| 9927 | } |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9928 | std::string feature_str; |
| 9929 | if (!bucket->GetAsString(&feature_str)) { |
| 9930 | return error::kInvalidArguments; |
| 9931 | } |
| 9932 | |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 9933 | bool desire_webgl_glsl_validation = |
| 9934 | feature_str.find("GL_CHROMIUM_webglsl") != std::string::npos; |
| 9935 | bool desire_standard_derivatives = false; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9936 | bool desire_frag_depth = false; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9937 | bool desire_draw_buffers = false; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 9938 | bool desire_shader_texture_lod = false; |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 9939 | if (force_webgl_glsl_validation_) { |
| 9940 | desire_standard_derivatives = |
| 9941 | feature_str.find("GL_OES_standard_derivatives") != std::string::npos; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9942 | desire_frag_depth = |
| 9943 | feature_str.find("GL_EXT_frag_depth") != std::string::npos; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9944 | desire_draw_buffers = |
| 9945 | feature_str.find("GL_EXT_draw_buffers") != std::string::npos; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 9946 | desire_shader_texture_lod = |
| 9947 | feature_str.find("GL_EXT_shader_texture_lod") != std::string::npos; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 9948 | } |
| 9949 | |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 9950 | if (desire_webgl_glsl_validation != force_webgl_glsl_validation_ || |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9951 | desire_standard_derivatives != derivatives_explicitly_enabled_ || |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9952 | desire_frag_depth != frag_depth_explicitly_enabled_ || |
| 9953 | desire_draw_buffers != draw_buffers_explicitly_enabled_) { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 9954 | force_webgl_glsl_validation_ |= desire_webgl_glsl_validation; |
| 9955 | derivatives_explicitly_enabled_ |= desire_standard_derivatives; |
| 9956 | frag_depth_explicitly_enabled_ |= desire_frag_depth; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 9957 | draw_buffers_explicitly_enabled_ |= desire_draw_buffers; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 9958 | shader_texture_lod_explicitly_enabled_ |= desire_shader_texture_lod; |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9959 | InitializeShaderTranslator(); |
| 9960 | } |
| 9961 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 9962 | UpdateCapabilities(); |
| 9963 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 9964 | return error::kNoError; |
| 9965 | } |
| 9966 | |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9967 | error::Error GLES2DecoderImpl::HandleGetProgramInfoCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9968 | uint32 immediate_data_size, |
| 9969 | const void* cmd_data) { |
| 9970 | const gles2::cmds::GetProgramInfoCHROMIUM& c = |
| 9971 | *static_cast<const gles2::cmds::GetProgramInfoCHROMIUM*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9972 | GLuint program_id = static_cast<GLuint>(c.program); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9973 | uint32 bucket_id = c.bucket_id; |
| 9974 | Bucket* bucket = CreateBucket(bucket_id); |
| 9975 | bucket->SetSize(sizeof(ProgramInfoHeader)); // in case we fail. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9976 | Program* program = NULL; |
| 9977 | program = GetProgram(program_id); |
| 9978 | if (!program || !program->IsValid()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 9979 | return error::kNoError; |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9980 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 9981 | program->GetProgramInfo(program_manager(), bucket); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 9982 | return error::kNoError; |
| 9983 | } |
| 9984 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9985 | error::ContextLostReason GLES2DecoderImpl::GetContextLostReason() { |
| 9986 | switch (reset_status_) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9987 | case GL_NO_ERROR: |
| 9988 | // TODO(kbr): improve the precision of the error code in this case. |
| 9989 | // Consider delegating to context for error code if MakeCurrent fails. |
| 9990 | return error::kUnknown; |
| 9991 | case GL_GUILTY_CONTEXT_RESET_ARB: |
| 9992 | return error::kGuilty; |
| 9993 | case GL_INNOCENT_CONTEXT_RESET_ARB: |
| 9994 | return error::kInnocent; |
| 9995 | case GL_UNKNOWN_CONTEXT_RESET_ARB: |
| 9996 | return error::kUnknown; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 9997 | } |
| 9998 | |
| 9999 | NOTREACHED(); |
| 10000 | return error::kUnknown; |
| 10001 | } |
| 10002 | |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 10003 | void GLES2DecoderImpl::MaybeExitOnContextLost() { |
| 10004 | // Some D3D drivers cannot recover from device lost in the GPU process |
| 10005 | // sandbox. Allow a new GPU process to launch. |
| 10006 | if (workarounds().exit_on_context_lost) { |
| 10007 | LOG(ERROR) << "Exiting GPU process because some drivers cannot reset" |
| 10008 | << " a D3D device in the Chrome GPU process sandbox."; |
| 10009 | #if defined(OS_WIN) |
| 10010 | base::win::SetShouldCrashOnProcessDetach(false); |
| 10011 | #endif |
| 10012 | exit(0); |
| 10013 | } |
| 10014 | } |
| 10015 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 10016 | bool GLES2DecoderImpl::WasContextLost() { |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 10017 | if (reset_status_ != GL_NO_ERROR) { |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 10018 | MaybeExitOnContextLost(); |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 10019 | return true; |
| 10020 | } |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 10021 | if (context_->WasAllocatedUsingRobustnessExtension()) { |
| 10022 | GLenum status = GL_NO_ERROR; |
| 10023 | if (has_robustness_extension_) |
| 10024 | status = glGetGraphicsResetStatusARB(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 10025 | if (status != GL_NO_ERROR) { |
| 10026 | // The graphics card was reset. Signal a lost context to the application. |
| 10027 | reset_status_ = status; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 10028 | reset_by_robustness_extension_ = true; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 10029 | LOG(ERROR) << (surface_->IsOffscreen() ? "Offscreen" : "Onscreen") |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 10030 | << " context lost via ARB/EXT_robustness. Reset status = " |
| 10031 | << GLES2Util::GetStringEnum(status); |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 10032 | MaybeExitOnContextLost(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 10033 | return true; |
| 10034 | } |
| 10035 | } |
| 10036 | return false; |
| 10037 | } |
| 10038 | |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 10039 | bool GLES2DecoderImpl::WasContextLostByRobustnessExtension() { |
| 10040 | return WasContextLost() && reset_by_robustness_extension_; |
| 10041 | } |
| 10042 | |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 10043 | void GLES2DecoderImpl::LoseContext(uint32 reset_status) { |
| 10044 | // Only loses the context once. |
| 10045 | if (reset_status_ != GL_NO_ERROR) { |
| 10046 | return; |
| 10047 | } |
| 10048 | |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 10049 | if (workarounds().use_virtualized_gl_contexts) { |
| 10050 | // If the context is virtual, the real context being guilty does not ensure |
| 10051 | // that the virtual context is guilty. |
| 10052 | if (reset_status == GL_GUILTY_CONTEXT_RESET_ARB) { |
| 10053 | reset_status = GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 10054 | } |
| 10055 | } else if (reset_status == GL_UNKNOWN_CONTEXT_RESET_ARB && |
| 10056 | has_robustness_extension_) { |
| 10057 | // If the reason for the call was a GL error, we can try to determine the |
| 10058 | // reset status more accurately. |
| 10059 | GLenum driver_status = glGetGraphicsResetStatusARB(); |
| 10060 | if (driver_status == GL_GUILTY_CONTEXT_RESET_ARB || |
| 10061 | driver_status == GL_INNOCENT_CONTEXT_RESET_ARB) { |
| 10062 | reset_status = driver_status; |
| 10063 | } |
| 10064 | } |
| 10065 | |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 10066 | // Marks this context as lost. |
| 10067 | reset_status_ = reset_status; |
| 10068 | current_decoder_error_ = error::kLostContext; |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 10069 | } |
| 10070 | |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 10071 | error::Error GLES2DecoderImpl::HandleInsertSyncPointCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10072 | uint32 immediate_data_size, |
| 10073 | const void* cmd_data) { |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 10074 | return error::kUnknownCommand; |
| 10075 | } |
| 10076 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 10077 | error::Error GLES2DecoderImpl::HandleWaitSyncPointCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10078 | uint32 immediate_data_size, |
| 10079 | const void* cmd_data) { |
| 10080 | const gles2::cmds::WaitSyncPointCHROMIUM& c = |
| 10081 | *static_cast<const gles2::cmds::WaitSyncPointCHROMIUM*>(cmd_data); |
sievers | 173a20d | 2014-10-22 18:19:32 | [diff] [blame] | 10082 | uint32 sync_point = c.sync_point; |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 10083 | if (wait_sync_point_callback_.is_null()) |
| 10084 | return error::kNoError; |
| 10085 | |
sievers | 173a20d | 2014-10-22 18:19:32 | [diff] [blame] | 10086 | return wait_sync_point_callback_.Run(sync_point) ? |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 10087 | error::kNoError : error::kDeferCommandUntilLater; |
| 10088 | } |
| 10089 | |
[email protected] | 5dfc457b | 2013-12-13 11:13:07 | [diff] [blame] | 10090 | error::Error GLES2DecoderImpl::HandleDiscardBackbufferCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10091 | uint32 immediate_data_size, |
| 10092 | const void* cmd_data) { |
[email protected] | 5dfc457b | 2013-12-13 11:13:07 | [diff] [blame] | 10093 | if (surface_->DeferDraws()) |
| 10094 | return error::kDeferCommandUntilLater; |
| 10095 | if (!surface_->SetBackbufferAllocation(false)) |
| 10096 | return error::kLostContext; |
| 10097 | backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| 10098 | backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
| 10099 | backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
| 10100 | return error::kNoError; |
| 10101 | } |
| 10102 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10103 | bool GLES2DecoderImpl::GenQueriesEXTHelper( |
| 10104 | GLsizei n, const GLuint* client_ids) { |
| 10105 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 10106 | if (query_manager_->GetQuery(client_ids[ii])) { |
| 10107 | return false; |
| 10108 | } |
| 10109 | } |
[email protected] | 4eea7e6 | 2014-04-22 21:14:43 | [diff] [blame] | 10110 | query_manager_->GenQueries(n, client_ids); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10111 | return true; |
| 10112 | } |
| 10113 | |
| 10114 | void GLES2DecoderImpl::DeleteQueriesEXTHelper( |
| 10115 | GLsizei n, const GLuint* client_ids) { |
| 10116 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 10117 | QueryManager::Query* query = query_manager_->GetQuery(client_ids[ii]); |
| 10118 | if (query && !query->IsDeleted()) { |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 10119 | ContextState::QueryMap::iterator it = |
| 10120 | state_.current_queries.find(query->target()); |
| 10121 | if (it != state_.current_queries.end()) |
| 10122 | state_.current_queries.erase(it); |
| 10123 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 10124 | query->Destroy(true); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10125 | } |
[email protected] | 4eea7e6 | 2014-04-22 21:14:43 | [diff] [blame] | 10126 | query_manager_->RemoveQuery(client_ids[ii]); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10127 | } |
| 10128 | } |
| 10129 | |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 10130 | bool GLES2DecoderImpl::ProcessPendingQueries(bool did_finish) { |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 10131 | if (query_manager_.get() == NULL) { |
| 10132 | return false; |
| 10133 | } |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 10134 | if (!query_manager_->ProcessPendingQueries(did_finish)) { |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 10135 | current_decoder_error_ = error::kOutOfBounds; |
| 10136 | } |
| 10137 | return query_manager_->HavePendingQueries(); |
| 10138 | } |
| 10139 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 10140 | // Note that if there are no pending readpixels right now, |
| 10141 | // this function will call the callback immediately. |
| 10142 | void GLES2DecoderImpl::WaitForReadPixels(base::Closure callback) { |
| 10143 | if (features().use_async_readpixels && !pending_readpixel_fences_.empty()) { |
| 10144 | pending_readpixel_fences_.back()->callbacks.push_back(callback); |
| 10145 | } else { |
| 10146 | callback.Run(); |
| 10147 | } |
| 10148 | } |
| 10149 | |
| 10150 | void GLES2DecoderImpl::ProcessPendingReadPixels() { |
| 10151 | while (!pending_readpixel_fences_.empty() && |
| 10152 | pending_readpixel_fences_.front()->fence->HasCompleted()) { |
| 10153 | std::vector<base::Closure> callbacks = |
| 10154 | pending_readpixel_fences_.front()->callbacks; |
| 10155 | pending_readpixel_fences_.pop(); |
| 10156 | for (size_t i = 0; i < callbacks.size(); i++) { |
| 10157 | callbacks[i].Run(); |
| 10158 | } |
| 10159 | } |
| 10160 | } |
| 10161 | |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 10162 | bool GLES2DecoderImpl::HasMoreIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 10163 | return !pending_readpixel_fences_.empty() || |
| 10164 | async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 10165 | } |
| 10166 | |
| 10167 | void GLES2DecoderImpl::PerformIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 10168 | ProcessPendingReadPixels(); |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 10169 | if (!async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers()) |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 10170 | return; |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 10171 | async_pixel_transfer_manager_->ProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 10172 | ProcessFinishedAsyncTransfers(); |
| 10173 | } |
| 10174 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10175 | error::Error GLES2DecoderImpl::HandleBeginQueryEXT(uint32 immediate_data_size, |
| 10176 | const void* cmd_data) { |
| 10177 | const gles2::cmds::BeginQueryEXT& c = |
| 10178 | *static_cast<const gles2::cmds::BeginQueryEXT*>(cmd_data); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10179 | GLenum target = static_cast<GLenum>(c.target); |
| 10180 | GLuint client_id = static_cast<GLuint>(c.id); |
| 10181 | int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id); |
| 10182 | uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 10183 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 10184 | switch (target) { |
| 10185 | case GL_COMMANDS_ISSUED_CHROMIUM: |
[email protected] | fb4bf582 | 2012-10-23 21:25:55 | [diff] [blame] | 10186 | case GL_LATENCY_QUERY_CHROMIUM: |
[email protected] | 5537605d | 2013-08-27 05:22:31 | [diff] [blame] | 10187 | case GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM: |
| 10188 | case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM: |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 10189 | case GL_GET_ERROR_QUERY_CHROMIUM: |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 10190 | break; |
[email protected] | 6a25ae42 | 2014-04-17 23:48:27 | [diff] [blame] | 10191 | case GL_COMMANDS_COMPLETED_CHROMIUM: |
| 10192 | if (!features().chromium_sync_query) { |
| 10193 | LOCAL_SET_GL_ERROR( |
| 10194 | GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 10195 | "not enabled for commands completed queries"); |
| 10196 | return error::kNoError; |
| 10197 | } |
| 10198 | break; |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 10199 | default: |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 10200 | if (!features().occlusion_query_boolean) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10201 | LOCAL_SET_GL_ERROR( |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 10202 | GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 10203 | "not enabled for occlusion queries"); |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 10204 | return error::kNoError; |
| 10205 | } |
| 10206 | break; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10207 | } |
| 10208 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 10209 | if (state_.current_queries.find(target) != state_.current_queries.end()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10210 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10211 | GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10212 | return error::kNoError; |
| 10213 | } |
| 10214 | |
| 10215 | if (client_id == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10216 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10217 | return error::kNoError; |
| 10218 | } |
| 10219 | |
| 10220 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 10221 | if (!query) { |
[email protected] | 4eea7e6 | 2014-04-22 21:14:43 | [diff] [blame] | 10222 | if (!query_manager_->IsValidQuery(client_id)) { |
| 10223 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10224 | "glBeginQueryEXT", |
| 10225 | "id not made by glGenQueriesEXT"); |
| 10226 | return error::kNoError; |
| 10227 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 10228 | query = query_manager_->CreateQuery( |
| 10229 | target, client_id, sync_shm_id, sync_shm_offset); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10230 | } |
| 10231 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 10232 | if (query->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10233 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10234 | GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10235 | return error::kNoError; |
| 10236 | } else if (query->shm_id() != sync_shm_id || |
| 10237 | query->shm_offset() != sync_shm_offset) { |
| 10238 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 10239 | return error::kInvalidArguments; |
| 10240 | } |
| 10241 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 10242 | if (!query_manager_->BeginQuery(query)) { |
| 10243 | return error::kOutOfBounds; |
| 10244 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10245 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 10246 | state_.current_queries[target] = query; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10247 | return error::kNoError; |
| 10248 | } |
| 10249 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10250 | error::Error GLES2DecoderImpl::HandleEndQueryEXT(uint32 immediate_data_size, |
| 10251 | const void* cmd_data) { |
| 10252 | const gles2::cmds::EndQueryEXT& c = |
| 10253 | *static_cast<const gles2::cmds::EndQueryEXT*>(cmd_data); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10254 | GLenum target = static_cast<GLenum>(c.target); |
| 10255 | uint32 submit_count = static_cast<GLuint>(c.submit_count); |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 10256 | ContextState::QueryMap::iterator it = state_.current_queries.find(target); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10257 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 10258 | if (it == state_.current_queries.end()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10259 | LOCAL_SET_GL_ERROR( |
| 10260 | GL_INVALID_OPERATION, "glEndQueryEXT", "No active query"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10261 | return error::kNoError; |
| 10262 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10263 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 10264 | QueryManager::Query* query = it->second.get(); |
| 10265 | if (!query_manager_->EndQuery(query, submit_count)) { |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 10266 | return error::kOutOfBounds; |
| 10267 | } |
| 10268 | |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 10269 | query_manager_->ProcessPendingTransferQueries(); |
| 10270 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 10271 | state_.current_queries.erase(it); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 10272 | return error::kNoError; |
| 10273 | } |
| 10274 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10275 | bool GLES2DecoderImpl::GenVertexArraysOESHelper( |
| 10276 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10277 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 10278 | if (GetVertexAttribManager(client_ids[ii])) { |
| 10279 | return false; |
| 10280 | } |
| 10281 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10282 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 10283 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10284 | // Emulated VAO |
| 10285 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 10286 | CreateVertexAttribManager(client_ids[ii], 0, true); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10287 | } |
| 10288 | } else { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 10289 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10290 | |
| 10291 | glGenVertexArraysOES(n, service_ids.get()); |
| 10292 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 10293 | CreateVertexAttribManager(client_ids[ii], service_ids[ii], true); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10294 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10295 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10296 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10297 | return true; |
| 10298 | } |
| 10299 | |
| 10300 | void GLES2DecoderImpl::DeleteVertexArraysOESHelper( |
| 10301 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10302 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 10303 | VertexAttribManager* vao = |
| 10304 | GetVertexAttribManager(client_ids[ii]); |
| 10305 | if (vao && !vao->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 10306 | if (state_.vertex_attrib_manager.get() == vao) { |
[email protected] | 242c982 | 2014-04-15 21:36:11 | [diff] [blame] | 10307 | DoBindVertexArrayOES(0); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10308 | } |
| 10309 | RemoveVertexAttribManager(client_ids[ii]); |
| 10310 | } |
| 10311 | } |
| 10312 | } |
| 10313 | |
| 10314 | void GLES2DecoderImpl::DoBindVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10315 | VertexAttribManager* vao = NULL; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10316 | if (client_id != 0) { |
| 10317 | vao = GetVertexAttribManager(client_id); |
| 10318 | if (!vao) { |
| 10319 | // Unlike most Bind* methods, the spec explicitly states that VertexArray |
| 10320 | // only allows names that have been previously generated. As such, we do |
| 10321 | // not generate new names here. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10322 | LOCAL_SET_GL_ERROR( |
| 10323 | GL_INVALID_OPERATION, |
| 10324 | "glBindVertexArrayOES", "bad vertex array id."); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10325 | current_decoder_error_ = error::kNoError; |
| 10326 | return; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10327 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10328 | } else { |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 10329 | vao = state_.default_vertex_attrib_manager.get(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10330 | } |
| 10331 | |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10332 | // Only set the VAO state if it's changed |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 10333 | if (state_.vertex_attrib_manager.get() != vao) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 10334 | state_.vertex_attrib_manager = vao; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 10335 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10336 | EmulateVertexArrayState(); |
| 10337 | } else { |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 10338 | GLuint service_id = vao->service_id(); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10339 | glBindVertexArrayOES(service_id); |
| 10340 | } |
| 10341 | } |
| 10342 | } |
| 10343 | |
| 10344 | // Used when OES_vertex_array_object isn't natively supported |
| 10345 | void GLES2DecoderImpl::EmulateVertexArrayState() { |
| 10346 | // Setup the Vertex attribute state |
| 10347 | for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) { |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 10348 | RestoreStateForAttrib(vv, true); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10349 | } |
| 10350 | |
| 10351 | // Setup the element buffer |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 10352 | Buffer* element_array_buffer = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 10353 | state_.vertex_attrib_manager->element_array_buffer(); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 10354 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 10355 | element_array_buffer ? element_array_buffer->service_id() : 0); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10356 | } |
| 10357 | |
| 10358 | bool GLES2DecoderImpl::DoIsVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 10359 | const VertexAttribManager* vao = |
| 10360 | GetVertexAttribManager(client_id); |
| 10361 | return vao && vao->IsValid() && !vao->IsDeleted(); |
| 10362 | } |
| 10363 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10364 | #if defined(OS_MACOSX) |
| 10365 | void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { |
| 10366 | TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( |
| 10367 | texture_id); |
| 10368 | if (it != texture_to_io_surface_map_.end()) { |
| 10369 | // Found a previous IOSurface bound to this texture; release it. |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 10370 | IOSurfaceRef surface = it->second; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10371 | CFRelease(surface); |
| 10372 | texture_to_io_surface_map_.erase(it); |
| 10373 | } |
| 10374 | } |
| 10375 | #endif |
| 10376 | |
| 10377 | void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( |
| 10378 | GLenum target, GLsizei width, GLsizei height, |
| 10379 | GLuint io_surface_id, GLuint plane) { |
| 10380 | #if defined(OS_MACOSX) |
| 10381 | if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10382 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10383 | GL_INVALID_OPERATION, |
| 10384 | "glTexImageIOSurface2DCHROMIUM", "only supported on desktop GL."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10385 | return; |
| 10386 | } |
| 10387 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10388 | if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 10389 | // This might be supported in the future, and if we could require |
| 10390 | // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we |
| 10391 | // could delete a lot of code. For now, perform strict validation so we |
| 10392 | // know what's going on. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10393 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10394 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10395 | "glTexImageIOSurface2DCHROMIUM", |
| 10396 | "requires TEXTURE_RECTANGLE_ARB target"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10397 | return; |
| 10398 | } |
| 10399 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 10400 | // Default target might be conceptually valid, but disallow it to avoid |
| 10401 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10402 | TextureRef* texture_ref = |
| 10403 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10404 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10405 | LOCAL_SET_GL_ERROR( |
| 10406 | GL_INVALID_OPERATION, |
| 10407 | "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10408 | return; |
| 10409 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10410 | |
| 10411 | // Look up the new IOSurface. Note that because of asynchrony |
| 10412 | // between processes this might fail; during live resizing the |
| 10413 | // plugin process might allocate and release an IOSurface before |
| 10414 | // this process gets a chance to look it up. Hold on to any old |
| 10415 | // IOSurface in this case. |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 10416 | IOSurfaceRef surface = IOSurfaceLookup(io_surface_id); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10417 | if (!surface) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10418 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10419 | GL_INVALID_OPERATION, |
| 10420 | "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10421 | return; |
| 10422 | } |
| 10423 | |
| 10424 | // Release any IOSurface previously bound to this texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10425 | ReleaseIOSurfaceForTexture(texture_ref->service_id()); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10426 | |
| 10427 | // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. |
| 10428 | texture_to_io_surface_map_.insert( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10429 | std::make_pair(texture_ref->service_id(), surface)); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10430 | |
| 10431 | CGLContextObj context = |
| 10432 | static_cast<CGLContextObj>(context_->GetHandle()); |
| 10433 | |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 10434 | CGLError err = CGLTexImageIOSurface2D( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10435 | context, |
| 10436 | target, |
| 10437 | GL_RGBA, |
| 10438 | width, |
| 10439 | height, |
| 10440 | GL_BGRA, |
| 10441 | GL_UNSIGNED_INT_8_8_8_8_REV, |
| 10442 | surface, |
| 10443 | plane); |
| 10444 | |
| 10445 | if (err != kCGLNoError) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10446 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10447 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10448 | "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10449 | return; |
| 10450 | } |
| 10451 | |
| 10452 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10453 | texture_ref, target, 0, GL_RGBA, width, height, 1, 0, |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10454 | GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); |
| 10455 | |
| 10456 | #else |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10457 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10458 | "glTexImageIOSurface2DCHROMIUM", "not supported."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10459 | #endif |
| 10460 | } |
| 10461 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10462 | static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { |
| 10463 | switch (internalformat) { |
| 10464 | case GL_RGB565: |
| 10465 | return GL_RGB; |
| 10466 | case GL_RGBA4: |
| 10467 | return GL_RGBA; |
| 10468 | case GL_RGB5_A1: |
| 10469 | return GL_RGBA; |
| 10470 | case GL_RGB8_OES: |
| 10471 | return GL_RGB; |
| 10472 | case GL_RGBA8_OES: |
| 10473 | return GL_RGBA; |
| 10474 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 10475 | return GL_LUMINANCE_ALPHA; |
| 10476 | case GL_LUMINANCE8_EXT: |
| 10477 | return GL_LUMINANCE; |
| 10478 | case GL_ALPHA8_EXT: |
| 10479 | return GL_ALPHA; |
| 10480 | case GL_RGBA32F_EXT: |
| 10481 | return GL_RGBA; |
| 10482 | case GL_RGB32F_EXT: |
| 10483 | return GL_RGB; |
| 10484 | case GL_ALPHA32F_EXT: |
| 10485 | return GL_ALPHA; |
| 10486 | case GL_LUMINANCE32F_EXT: |
| 10487 | return GL_LUMINANCE; |
| 10488 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 10489 | return GL_LUMINANCE_ALPHA; |
| 10490 | case GL_RGBA16F_EXT: |
| 10491 | return GL_RGBA; |
| 10492 | case GL_RGB16F_EXT: |
| 10493 | return GL_RGB; |
| 10494 | case GL_ALPHA16F_EXT: |
| 10495 | return GL_ALPHA; |
| 10496 | case GL_LUMINANCE16F_EXT: |
| 10497 | return GL_LUMINANCE; |
| 10498 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 10499 | return GL_LUMINANCE_ALPHA; |
| 10500 | case GL_BGRA8_EXT: |
| 10501 | return GL_BGRA_EXT; |
bajones | 2a2ea23 | 2014-10-13 21:38:59 | [diff] [blame] | 10502 | case GL_SRGB8_ALPHA8_EXT: |
| 10503 | return GL_SRGB_ALPHA_EXT; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10504 | default: |
| 10505 | return GL_NONE; |
| 10506 | } |
| 10507 | } |
| 10508 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10509 | void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10510 | GLenum target, GLuint source_id, GLuint dest_id, GLint level, |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 10511 | GLenum internal_format, GLenum dest_type) { |
[email protected] | 1e24dc7f | 2014-04-14 02:40:08 | [diff] [blame] | 10512 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); |
| 10513 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10514 | TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 10515 | TextureRef* source_texture_ref = GetTexture(source_id); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10516 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10517 | if (!source_texture_ref || !dest_texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10518 | LOCAL_SET_GL_ERROR( |
| 10519 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10520 | return; |
| 10521 | } |
| 10522 | |
| 10523 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10524 | LOCAL_SET_GL_ERROR( |
| 10525 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid texture target"); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10526 | return; |
| 10527 | } |
| 10528 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10529 | Texture* source_texture = source_texture_ref->texture(); |
| 10530 | Texture* dest_texture = dest_texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10531 | if (dest_texture->target() != GL_TEXTURE_2D || |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 10532 | (source_texture->target() != GL_TEXTURE_2D && |
[email protected] | 041d463f | 2014-04-30 05:38:34 | [diff] [blame] | 10533 | source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && |
| 10534 | source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 10535 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 10536 | "glCopyTextureCHROMIUM", |
| 10537 | "invalid texture target binding"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10538 | return; |
| 10539 | } |
| 10540 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10541 | int source_width, source_height, dest_width, dest_height; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10542 | |
[email protected] | 3e0dfd7 | 2014-02-21 06:28:41 | [diff] [blame] | 10543 | gfx::GLImage* image = |
| 10544 | source_texture->GetLevelImage(source_texture->target(), 0); |
| 10545 | if (image) { |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 10546 | gfx::Size size = image->GetSize(); |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 10547 | source_width = size.width(); |
| 10548 | source_height = size.height(); |
| 10549 | if (source_width <= 0 || source_height <= 0) { |
| 10550 | LOCAL_SET_GL_ERROR( |
| 10551 | GL_INVALID_VALUE, |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 10552 | "glCopyTextureChromium", "invalid image size"); |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 10553 | return; |
| 10554 | } |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 10555 | } else { |
| 10556 | if (!source_texture->GetLevelSize( |
| 10557 | source_texture->target(), 0, &source_width, &source_height)) { |
| 10558 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 10559 | "glCopyTextureChromium", |
| 10560 | "source texture has no level 0"); |
| 10561 | return; |
| 10562 | } |
| 10563 | |
| 10564 | // Check that this type of texture is allowed. |
| 10565 | if (!texture_manager()->ValidForTarget( |
| 10566 | source_texture->target(), level, source_width, source_height, 1)) { |
| 10567 | LOCAL_SET_GL_ERROR( |
| 10568 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); |
| 10569 | return; |
| 10570 | } |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 10571 | } |
| 10572 | |
[email protected] | 04b5b37d | 2014-02-07 02:11:51 | [diff] [blame] | 10573 | // Clear the source texture if necessary. |
| 10574 | if (!texture_manager()->ClearTextureLevel( |
| 10575 | this, source_texture_ref, source_texture->target(), 0)) { |
| 10576 | LOCAL_SET_GL_ERROR( |
| 10577 | GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", "dimensions too big"); |
| 10578 | return; |
| 10579 | } |
| 10580 | |
[email protected] | a6e3d28 | 2014-08-22 22:20:44 | [diff] [blame] | 10581 | GLenum source_type = 0; |
| 10582 | GLenum source_internal_format = 0; |
| 10583 | source_texture->GetLevelType( |
| 10584 | source_texture->target(), 0, &source_type, &source_internal_format); |
| 10585 | |
| 10586 | // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, |
| 10587 | // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not |
| 10588 | // renderable on some platforms. |
reveman | 6b0fbe4 | 2014-09-04 00:55:03 | [diff] [blame] | 10589 | bool valid_dest_format = internal_format == GL_RGB || |
| 10590 | internal_format == GL_RGBA || |
| 10591 | internal_format == GL_BGRA_EXT; |
[email protected] | a6e3d28 | 2014-08-22 22:20:44 | [diff] [blame] | 10592 | bool valid_source_format = source_internal_format == GL_ALPHA || |
| 10593 | source_internal_format == GL_RGB || |
| 10594 | source_internal_format == GL_RGBA || |
| 10595 | source_internal_format == GL_LUMINANCE || |
| 10596 | source_internal_format == GL_LUMINANCE_ALPHA || |
| 10597 | source_internal_format == GL_BGRA_EXT; |
| 10598 | if (!valid_source_format || !valid_dest_format) { |
| 10599 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10600 | "glCopyTextureCHROMIUM", |
| 10601 | "invalid internal format"); |
| 10602 | return; |
| 10603 | } |
| 10604 | |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 10605 | // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 10606 | // needed because it takes 10s of milliseconds to initialize. |
| 10607 | if (!copy_texture_CHROMIUM_.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10608 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 10609 | copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
[email protected] | 07a0cc3 | 2013-02-28 00:36:27 | [diff] [blame] | 10610 | copy_texture_CHROMIUM_->Initialize(this); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 10611 | RestoreCurrentFramebufferBindings(); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10612 | if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 10613 | return; |
| 10614 | } |
| 10615 | |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 10616 | GLenum dest_type_previous = dest_type; |
| 10617 | GLenum dest_internal_format = internal_format; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10618 | bool dest_level_defined = dest_texture->GetLevelSize( |
| 10619 | GL_TEXTURE_2D, level, &dest_width, &dest_height); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10620 | |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10621 | if (dest_level_defined) { |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 10622 | dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type_previous, |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10623 | &dest_internal_format); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10624 | } |
| 10625 | |
| 10626 | // Resize the destination texture to the dimensions of the source texture. |
| 10627 | if (!dest_level_defined || dest_width != source_width || |
| 10628 | dest_height != source_height || |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 10629 | dest_internal_format != internal_format || |
| 10630 | dest_type_previous != dest_type) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10631 | // Ensure that the glTexImage2D succeeds. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10632 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10633 | glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 10634 | glTexImage2D( |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10635 | GL_TEXTURE_2D, level, internal_format, source_width, source_height, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10636 | 0, internal_format, dest_type, NULL); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10637 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10638 | if (error != GL_NO_ERROR) { |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 10639 | RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10640 | return; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10641 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10642 | |
| 10643 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10644 | dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width, |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 10645 | source_height, 1, 0, internal_format, dest_type, true); |
[email protected] | f702471 | 2012-05-15 21:30:25 | [diff] [blame] | 10646 | } else { |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10647 | texture_manager()->SetLevelCleared( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10648 | dest_texture_ref, GL_TEXTURE_2D, level, true); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10649 | } |
| 10650 | |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 10651 | ScopedModifyPixels modify(dest_texture_ref); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 10652 | |
reveman | ce8fbe8 | 2014-09-05 02:19:52 | [diff] [blame] | 10653 | // Try using GLImage::CopyTexImage when possible. |
| 10654 | bool unpack_premultiply_alpha_change = |
| 10655 | unpack_premultiply_alpha_ ^ unpack_unpremultiply_alpha_; |
| 10656 | if (image && !unpack_flip_y_ && !unpack_premultiply_alpha_change && !level) { |
| 10657 | glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
| 10658 | if (image->CopyTexImage(GL_TEXTURE_2D)) |
| 10659 | return; |
| 10660 | } |
| 10661 | |
| 10662 | DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 10663 | |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 10664 | // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 10665 | // before presenting. |
| 10666 | if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
| 10667 | // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
| 10668 | // instead of using default matrix crbug.com/226218. |
| 10669 | const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
| 10670 | 0.0f, 1.0f, 0.0f, 0.0f, |
| 10671 | 0.0f, 0.0f, 1.0f, 0.0f, |
| 10672 | 0.0f, 0.0f, 0.0f, 1.0f}; |
| 10673 | copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| 10674 | this, |
| 10675 | source_texture->target(), |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 10676 | source_texture->service_id(), |
[email protected] | 90f7d30d | 2014-08-13 02:51:57 | [diff] [blame] | 10677 | dest_texture->service_id(), |
| 10678 | level, |
| 10679 | source_width, |
| 10680 | source_height, |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 10681 | unpack_flip_y_, |
| 10682 | unpack_premultiply_alpha_, |
| 10683 | unpack_unpremultiply_alpha_, |
| 10684 | default_matrix); |
| 10685 | } else { |
[email protected] | 90f7d30d | 2014-08-13 02:51:57 | [diff] [blame] | 10686 | copy_texture_CHROMIUM_->DoCopyTexture(this, |
| 10687 | source_texture->target(), |
| 10688 | source_texture->service_id(), |
| 10689 | source_internal_format, |
| 10690 | dest_texture->service_id(), |
| 10691 | level, |
| 10692 | internal_format, |
| 10693 | source_width, |
| 10694 | source_height, |
| 10695 | unpack_flip_y_, |
| 10696 | unpack_premultiply_alpha_, |
| 10697 | unpack_unpremultiply_alpha_); |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 10698 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 10699 | |
| 10700 | DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 10701 | } |
| 10702 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10703 | static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
| 10704 | switch (internalformat) { |
| 10705 | case GL_RGB565: |
| 10706 | return GL_UNSIGNED_SHORT_5_6_5; |
| 10707 | case GL_RGBA4: |
| 10708 | return GL_UNSIGNED_SHORT_4_4_4_4; |
| 10709 | case GL_RGB5_A1: |
| 10710 | return GL_UNSIGNED_SHORT_5_5_5_1; |
| 10711 | case GL_RGB8_OES: |
| 10712 | return GL_UNSIGNED_BYTE; |
| 10713 | case GL_RGBA8_OES: |
| 10714 | return GL_UNSIGNED_BYTE; |
| 10715 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 10716 | return GL_UNSIGNED_BYTE; |
| 10717 | case GL_LUMINANCE8_EXT: |
| 10718 | return GL_UNSIGNED_BYTE; |
| 10719 | case GL_ALPHA8_EXT: |
| 10720 | return GL_UNSIGNED_BYTE; |
| 10721 | case GL_RGBA32F_EXT: |
| 10722 | return GL_FLOAT; |
| 10723 | case GL_RGB32F_EXT: |
| 10724 | return GL_FLOAT; |
| 10725 | case GL_ALPHA32F_EXT: |
| 10726 | return GL_FLOAT; |
| 10727 | case GL_LUMINANCE32F_EXT: |
| 10728 | return GL_FLOAT; |
| 10729 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 10730 | return GL_FLOAT; |
| 10731 | case GL_RGBA16F_EXT: |
| 10732 | return GL_HALF_FLOAT_OES; |
| 10733 | case GL_RGB16F_EXT: |
| 10734 | return GL_HALF_FLOAT_OES; |
| 10735 | case GL_ALPHA16F_EXT: |
| 10736 | return GL_HALF_FLOAT_OES; |
| 10737 | case GL_LUMINANCE16F_EXT: |
| 10738 | return GL_HALF_FLOAT_OES; |
| 10739 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 10740 | return GL_HALF_FLOAT_OES; |
| 10741 | case GL_BGRA8_EXT: |
| 10742 | return GL_UNSIGNED_BYTE; |
| 10743 | default: |
| 10744 | return GL_NONE; |
| 10745 | } |
| 10746 | } |
| 10747 | |
| 10748 | void GLES2DecoderImpl::DoTexStorage2DEXT( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 10749 | GLenum target, |
| 10750 | GLint levels, |
| 10751 | GLenum internal_format, |
| 10752 | GLsizei width, |
| 10753 | GLsizei height) { |
[email protected] | 67f92942 | 2014-05-17 15:33:13 | [diff] [blame] | 10754 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT", |
| 10755 | "width", width, "height", height); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 10756 | if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 10757 | TextureManager::ComputeMipMapCount(target, width, height, 1) < levels) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10758 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10759 | GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10760 | return; |
| 10761 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10762 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10763 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10764 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10765 | LOCAL_SET_GL_ERROR( |
| 10766 | GL_INVALID_OPERATION, |
| 10767 | "glTexStorage2DEXT", "unknown texture for target"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10768 | return; |
| 10769 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10770 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10771 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10772 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10773 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10774 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10775 | LOCAL_SET_GL_ERROR( |
| 10776 | GL_INVALID_OPERATION, |
| 10777 | "glTexStorage2DEXT", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10778 | return; |
| 10779 | } |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10780 | |
| 10781 | GLenum format = ExtractFormatFromStorageFormat(internal_format); |
| 10782 | GLenum type = ExtractTypeFromStorageFormat(internal_format); |
| 10783 | |
| 10784 | { |
| 10785 | GLsizei level_width = width; |
| 10786 | GLsizei level_height = height; |
| 10787 | uint32 estimated_size = 0; |
| 10788 | for (int ii = 0; ii < levels; ++ii) { |
| 10789 | uint32 level_size = 0; |
| 10790 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 10791 | level_width, level_height, 1, format, type, state_.unpack_alignment, |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10792 | &estimated_size, NULL, NULL) || |
| 10793 | !SafeAddUint32(estimated_size, level_size, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10794 | LOCAL_SET_GL_ERROR( |
| 10795 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10796 | return; |
| 10797 | } |
| 10798 | level_width = std::max(1, level_width >> 1); |
| 10799 | level_height = std::max(1, level_height >> 1); |
| 10800 | } |
| 10801 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10802 | LOCAL_SET_GL_ERROR( |
| 10803 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 10804 | return; |
| 10805 | } |
| 10806 | } |
| 10807 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10808 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage2DEXT"); |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 10809 | glTexStorage2DEXT(target, levels, internal_format, width, height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10810 | GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage2DEXT"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10811 | if (error == GL_NO_ERROR) { |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10812 | GLsizei level_width = width; |
| 10813 | GLsizei level_height = height; |
| 10814 | for (int ii = 0; ii < levels; ++ii) { |
| 10815 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10816 | texture_ref, target, ii, format, |
| 10817 | level_width, level_height, 1, 0, format, type, false); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10818 | level_width = std::max(1, level_width >> 1); |
| 10819 | level_height = std::max(1, level_height >> 1); |
| 10820 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10821 | texture->SetImmutable(true); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10822 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 10823 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 10824 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10825 | error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10826 | uint32 immediate_data_size, |
| 10827 | const void* cmd_data) { |
[email protected] | baed42c | 2013-10-01 05:06:35 | [diff] [blame] | 10828 | return error::kUnknownCommand; |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10829 | } |
| 10830 | |
| 10831 | void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10832 | const GLbyte* data) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10833 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 10834 | "context", logger_.GetLogPrefix(), |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10835 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10836 | |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10837 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10838 | &state_, target); |
| 10839 | ProduceTextureRef("glProduceTextureCHROMIUM", texture_ref, target, data); |
| 10840 | } |
| 10841 | |
| 10842 | void GLES2DecoderImpl::DoProduceTextureDirectCHROMIUM(GLuint client_id, |
| 10843 | GLenum target, const GLbyte* data) { |
| 10844 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureDirectCHROMIUM", |
| 10845 | "context", logger_.GetLogPrefix(), |
| 10846 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10847 | |
| 10848 | ProduceTextureRef("glProduceTextureDirectCHROMIUM", GetTexture(client_id), |
| 10849 | target, data); |
| 10850 | } |
| 10851 | |
| 10852 | void GLES2DecoderImpl::ProduceTextureRef(std::string func_name, |
| 10853 | TextureRef* texture_ref, GLenum target, const GLbyte* data) { |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10854 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10855 | DLOG_IF(ERROR, !mailbox.Verify()) << func_name << " was passed a " |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10856 | "mailbox that was not generated by " |
| 10857 | "GenMailboxCHROMIUM."; |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10858 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10859 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10860 | LOCAL_SET_GL_ERROR( |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10861 | GL_INVALID_OPERATION, func_name.c_str(), "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10862 | return; |
| 10863 | } |
| 10864 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10865 | Texture* produced = texture_manager()->Produce(texture_ref); |
| 10866 | if (!produced) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10867 | LOCAL_SET_GL_ERROR( |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10868 | GL_INVALID_OPERATION, func_name.c_str(), "invalid texture"); |
| 10869 | return; |
| 10870 | } |
| 10871 | |
| 10872 | if (produced->target() != target) { |
| 10873 | LOCAL_SET_GL_ERROR( |
| 10874 | GL_INVALID_OPERATION, func_name.c_str(), "invalid target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10875 | return; |
| 10876 | } |
| 10877 | |
sievers | 8b373ec5 | 2014-10-24 23:04:06 | [diff] [blame] | 10878 | group_->mailbox_manager()->ProduceTexture(mailbox, produced); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10879 | } |
| 10880 | |
| 10881 | void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10882 | const GLbyte* data) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10883 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 10884 | "context", logger_.GetLogPrefix(), |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 10885 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10886 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
| 10887 | DLOG_IF(ERROR, !mailbox.Verify()) << "ConsumeTextureCHROMIUM was passed a " |
| 10888 | "mailbox that was not generated by " |
| 10889 | "GenMailboxCHROMIUM."; |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 10890 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10891 | scoped_refptr<TextureRef> texture_ref = |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10892 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 10893 | if (!texture_ref.get()) { |
| 10894 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10895 | "glConsumeTextureCHROMIUM", |
| 10896 | "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10897 | return; |
| 10898 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10899 | GLuint client_id = texture_ref->client_id(); |
| 10900 | if (!client_id) { |
| 10901 | LOCAL_SET_GL_ERROR( |
| 10902 | GL_INVALID_OPERATION, |
| 10903 | "glConsumeTextureCHROMIUM", "unknown texture for target"); |
| 10904 | return; |
| 10905 | } |
sievers | 8b373ec5 | 2014-10-24 23:04:06 | [diff] [blame] | 10906 | Texture* texture = group_->mailbox_manager()->ConsumeTexture(mailbox); |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10907 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10908 | LOCAL_SET_GL_ERROR( |
| 10909 | GL_INVALID_OPERATION, |
| 10910 | "glConsumeTextureCHROMIUM", "invalid mailbox name"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10911 | return; |
| 10912 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10913 | if (texture->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10914 | LOCAL_SET_GL_ERROR( |
| 10915 | GL_INVALID_OPERATION, |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10916 | "glConsumeTextureCHROMIUM", "invalid target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10917 | return; |
| 10918 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 10919 | |
| 10920 | DeleteTexturesHelper(1, &client_id); |
| 10921 | texture_ref = texture_manager()->Consume(client_id, texture); |
| 10922 | glBindTexture(target, texture_ref->service_id()); |
| 10923 | |
| 10924 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
| 10925 | unit.bind_target = target; |
| 10926 | switch (target) { |
| 10927 | case GL_TEXTURE_2D: |
| 10928 | unit.bound_texture_2d = texture_ref; |
| 10929 | break; |
| 10930 | case GL_TEXTURE_CUBE_MAP: |
| 10931 | unit.bound_texture_cube_map = texture_ref; |
| 10932 | break; |
| 10933 | case GL_TEXTURE_EXTERNAL_OES: |
| 10934 | unit.bound_texture_external_oes = texture_ref; |
| 10935 | break; |
| 10936 | case GL_TEXTURE_RECTANGLE_ARB: |
| 10937 | unit.bound_texture_rectangle_arb = texture_ref; |
| 10938 | break; |
| 10939 | default: |
| 10940 | NOTREACHED(); // Validation should prevent us getting here. |
| 10941 | break; |
| 10942 | } |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 10943 | } |
| 10944 | |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10945 | error::Error GLES2DecoderImpl::HandleCreateAndConsumeTextureCHROMIUMImmediate( |
| 10946 | uint32_t immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10947 | const void* cmd_data) { |
| 10948 | const gles2::cmds::CreateAndConsumeTextureCHROMIUMImmediate& c = |
| 10949 | *static_cast< |
| 10950 | const gles2::cmds::CreateAndConsumeTextureCHROMIUMImmediate*>( |
| 10951 | cmd_data); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10952 | GLenum target = static_cast<GLenum>(c.target); |
| 10953 | uint32_t data_size; |
| 10954 | if (!ComputeDataSize(1, sizeof(GLbyte), 64, &data_size)) { |
| 10955 | return error::kOutOfBounds; |
| 10956 | } |
| 10957 | if (data_size > immediate_data_size) { |
| 10958 | return error::kOutOfBounds; |
| 10959 | } |
| 10960 | const GLbyte* mailbox = |
| 10961 | GetImmediateDataAs<const GLbyte*>(c, data_size, immediate_data_size); |
| 10962 | if (!validators_->texture_bind_target.IsValid(target)) { |
| 10963 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 10964 | "glCreateAndConsumeTextureCHROMIUM", target, "target"); |
| 10965 | return error::kNoError; |
| 10966 | } |
| 10967 | if (mailbox == NULL) { |
| 10968 | return error::kOutOfBounds; |
| 10969 | } |
| 10970 | uint32_t client_id = c.client_id; |
| 10971 | DoCreateAndConsumeTextureCHROMIUM(target, mailbox, client_id); |
| 10972 | return error::kNoError; |
| 10973 | } |
| 10974 | |
| 10975 | void GLES2DecoderImpl::DoCreateAndConsumeTextureCHROMIUM(GLenum target, |
| 10976 | const GLbyte* data, GLuint client_id) { |
| 10977 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoCreateAndConsumeTextureCHROMIUM", |
| 10978 | "context", logger_.GetLogPrefix(), |
| 10979 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 10980 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
| 10981 | DLOG_IF(ERROR, !mailbox.Verify()) << "CreateAndConsumeTextureCHROMIUM was " |
| 10982 | "passed a mailbox that was not " |
| 10983 | "generated by GenMailboxCHROMIUM."; |
| 10984 | |
| 10985 | TextureRef* texture_ref = GetTexture(client_id); |
| 10986 | if (texture_ref) { |
| 10987 | LOCAL_SET_GL_ERROR( |
| 10988 | GL_INVALID_OPERATION, |
| 10989 | "glCreateAndConsumeTextureCHROMIUM", "client id already in use"); |
| 10990 | return; |
| 10991 | } |
sievers | 8b373ec5 | 2014-10-24 23:04:06 | [diff] [blame] | 10992 | Texture* texture = group_->mailbox_manager()->ConsumeTexture(mailbox); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 10993 | if (!texture) { |
| 10994 | LOCAL_SET_GL_ERROR( |
| 10995 | GL_INVALID_OPERATION, |
| 10996 | "glCreateAndConsumeTextureCHROMIUM", "invalid mailbox name"); |
| 10997 | return; |
| 10998 | } |
| 10999 | if (texture->target() != target) { |
| 11000 | LOCAL_SET_GL_ERROR( |
| 11001 | GL_INVALID_OPERATION, |
| 11002 | "glCreateAndConsumeTextureCHROMIUM", "invalid target"); |
| 11003 | return; |
| 11004 | } |
| 11005 | |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 11006 | texture_ref = texture_manager()->Consume(client_id, texture); |
| 11007 | } |
| 11008 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 11009 | bool GLES2DecoderImpl::DoIsValuebufferCHROMIUM(GLuint client_id) { |
| 11010 | const Valuebuffer* valuebuffer = GetValuebuffer(client_id); |
| 11011 | return valuebuffer && valuebuffer->IsValid(); |
| 11012 | } |
| 11013 | |
| 11014 | void GLES2DecoderImpl::DoBindValueBufferCHROMIUM(GLenum target, |
| 11015 | GLuint client_id) { |
| 11016 | Valuebuffer* valuebuffer = NULL; |
| 11017 | if (client_id != 0) { |
| 11018 | valuebuffer = GetValuebuffer(client_id); |
| 11019 | if (!valuebuffer) { |
| 11020 | if (!group_->bind_generates_resource()) { |
| 11021 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBindValuebufferCHROMIUM", |
| 11022 | "id not generated by glBindValuebufferCHROMIUM"); |
| 11023 | return; |
| 11024 | } |
| 11025 | |
| 11026 | // It's a new id so make a valuebuffer for it. |
| 11027 | CreateValuebuffer(client_id); |
| 11028 | valuebuffer = GetValuebuffer(client_id); |
| 11029 | } |
| 11030 | valuebuffer->MarkAsValid(); |
| 11031 | } |
| 11032 | state_.bound_valuebuffer = valuebuffer; |
| 11033 | } |
| 11034 | |
| 11035 | void GLES2DecoderImpl::DoSubscribeValueCHROMIUM(GLenum target, |
| 11036 | GLenum subscription) { |
| 11037 | if (!CheckCurrentValuebuffer("glSubscribeValueCHROMIUM")) { |
| 11038 | return; |
| 11039 | } |
| 11040 | state_.bound_valuebuffer.get()->AddSubscription(subscription); |
| 11041 | } |
| 11042 | |
| 11043 | void GLES2DecoderImpl::DoPopulateSubscribedValuesCHROMIUM(GLenum target) { |
| 11044 | if (!CheckCurrentValuebuffer("glPopulateSubscribedValuesCHROMIUM")) { |
| 11045 | return; |
| 11046 | } |
| 11047 | valuebuffer_manager()->UpdateValuebufferState(state_.bound_valuebuffer.get()); |
| 11048 | } |
| 11049 | |
| 11050 | void GLES2DecoderImpl::DoUniformValueBufferCHROMIUM(GLint location, |
| 11051 | GLenum target, |
| 11052 | GLenum subscription) { |
| 11053 | if (!CheckCurrentValuebufferForSubscription( |
| 11054 | subscription, "glPopulateSubscribedValuesCHROMIUM")) { |
| 11055 | return; |
| 11056 | } |
| 11057 | if (!CheckSubscriptionTarget(location, subscription, |
| 11058 | "glPopulateSubscribedValuesCHROMIUM")) { |
| 11059 | return; |
| 11060 | } |
| 11061 | const ValueState* state = |
| 11062 | state_.bound_valuebuffer.get()->GetState(subscription); |
| 11063 | if (state) { |
| 11064 | switch (subscription) { |
| 11065 | case GL_MOUSE_POSITION_CHROMIUM: |
| 11066 | DoUniform2iv(location, 1, state->int_value); |
| 11067 | break; |
| 11068 | default: |
| 11069 | NOTREACHED() << "Unhandled uniform subscription target " |
| 11070 | << subscription; |
| 11071 | break; |
| 11072 | } |
| 11073 | } |
| 11074 | } |
| 11075 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 11076 | void GLES2DecoderImpl::DoInsertEventMarkerEXT( |
| 11077 | GLsizei length, const GLchar* marker) { |
| 11078 | if (!marker) { |
| 11079 | marker = ""; |
| 11080 | } |
| 11081 | debug_marker_manager_.SetMarker( |
| 11082 | length ? std::string(marker, length) : std::string(marker)); |
| 11083 | } |
| 11084 | |
| 11085 | void GLES2DecoderImpl::DoPushGroupMarkerEXT( |
| 11086 | GLsizei length, const GLchar* marker) { |
| 11087 | if (!marker) { |
| 11088 | marker = ""; |
| 11089 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 11090 | std::string name = length ? std::string(marker, length) : std::string(marker); |
| 11091 | debug_marker_manager_.PushGroup(name); |
dyen | 4bb4328 | 2015-01-08 01:09:56 | [diff] [blame] | 11092 | gpu_tracer_->Begin(TRACE_DISABLED_BY_DEFAULT("gpu_group_marker"), name, |
| 11093 | kTraceGroupMarker); |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 11094 | } |
| 11095 | |
| 11096 | void GLES2DecoderImpl::DoPopGroupMarkerEXT(void) { |
| 11097 | debug_marker_manager_.PopGroup(); |
dyen | 4bb4328 | 2015-01-08 01:09:56 | [diff] [blame] | 11098 | gpu_tracer_->End(kTraceGroupMarker); |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 11099 | } |
| 11100 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11101 | void GLES2DecoderImpl::DoBindTexImage2DCHROMIUM( |
| 11102 | GLenum target, GLint image_id) { |
| 11103 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11104 | |
[email protected] | bc26e8d | 2014-01-29 00:40:30 | [diff] [blame] | 11105 | if (target == GL_TEXTURE_CUBE_MAP) { |
| 11106 | LOCAL_SET_GL_ERROR( |
| 11107 | GL_INVALID_ENUM, |
| 11108 | "glBindTexImage2DCHROMIUM", "invalid target"); |
| 11109 | return; |
| 11110 | } |
| 11111 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11112 | // Default target might be conceptually valid, but disallow it to avoid |
| 11113 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11114 | TextureRef* texture_ref = |
| 11115 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11116 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11117 | LOCAL_SET_GL_ERROR( |
| 11118 | GL_INVALID_OPERATION, |
| 11119 | "glBindTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11120 | return; |
| 11121 | } |
| 11122 | |
| 11123 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 11124 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11125 | LOCAL_SET_GL_ERROR( |
| 11126 | GL_INVALID_OPERATION, |
| 11127 | "glBindTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11128 | return; |
| 11129 | } |
| 11130 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 11131 | { |
| 11132 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 11133 | "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | 3c58012 | 2013-11-22 07:52:26 | [diff] [blame] | 11134 | if (!gl_image->BindTexImage(target)) { |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 11135 | LOCAL_SET_GL_ERROR( |
| 11136 | GL_INVALID_OPERATION, |
| 11137 | "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID"); |
| 11138 | return; |
| 11139 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11140 | } |
| 11141 | |
| 11142 | gfx::Size size = gl_image->GetSize(); |
| 11143 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11144 | texture_ref, target, 0, GL_RGBA, size.width(), size.height(), 1, 0, |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11145 | GL_RGBA, GL_UNSIGNED_BYTE, true); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11146 | texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11147 | } |
| 11148 | |
| 11149 | void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( |
| 11150 | GLenum target, GLint image_id) { |
| 11151 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11152 | |
| 11153 | // Default target might be conceptually valid, but disallow it to avoid |
| 11154 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11155 | TextureRef* texture_ref = |
| 11156 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11157 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11158 | LOCAL_SET_GL_ERROR( |
| 11159 | GL_INVALID_OPERATION, |
| 11160 | "glReleaseTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11161 | return; |
| 11162 | } |
| 11163 | |
| 11164 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 11165 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11166 | LOCAL_SET_GL_ERROR( |
| 11167 | GL_INVALID_OPERATION, |
| 11168 | "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11169 | return; |
| 11170 | } |
| 11171 | |
| 11172 | // Do nothing when image is not currently bound. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11173 | if (texture_ref->texture()->GetLevelImage(target, 0) != gl_image) |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11174 | return; |
| 11175 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 11176 | { |
| 11177 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 11178 | "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | 3c58012 | 2013-11-22 07:52:26 | [diff] [blame] | 11179 | gl_image->ReleaseTexImage(target); |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 11180 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11181 | |
| 11182 | texture_manager()->SetLevelInfo( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11183 | texture_ref, target, 0, GL_RGBA, 0, 0, 1, 0, |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11184 | GL_RGBA, GL_UNSIGNED_BYTE, false); |
| 11185 | } |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 11186 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 11187 | error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11188 | uint32 immediate_data_size, |
| 11189 | const void* cmd_data) { |
| 11190 | const gles2::cmds::TraceBeginCHROMIUM& c = |
| 11191 | *static_cast<const gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 11192 | Bucket* category_bucket = GetBucket(c.category_bucket_id); |
| 11193 | Bucket* name_bucket = GetBucket(c.name_bucket_id); |
| 11194 | if (!category_bucket || category_bucket->size() == 0 || |
| 11195 | !name_bucket || name_bucket->size() == 0) { |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 11196 | return error::kInvalidArguments; |
| 11197 | } |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 11198 | |
| 11199 | std::string category_name; |
| 11200 | std::string trace_name; |
| 11201 | if (!category_bucket->GetAsString(&category_name) || |
| 11202 | !name_bucket->GetAsString(&trace_name)) { |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 11203 | return error::kInvalidArguments; |
| 11204 | } |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 11205 | |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 11206 | if (!gpu_tracer_->Begin(category_name, trace_name, kTraceCHROMIUM)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11207 | LOCAL_SET_GL_ERROR( |
| 11208 | GL_INVALID_OPERATION, |
| 11209 | "glTraceBeginCHROMIUM", "unable to create begin trace"); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 11210 | return error::kNoError; |
| 11211 | } |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 11212 | return error::kNoError; |
| 11213 | } |
| 11214 | |
| 11215 | void GLES2DecoderImpl::DoTraceEndCHROMIUM() { |
dyen | 4bb4328 | 2015-01-08 01:09:56 | [diff] [blame] | 11216 | if (!gpu_tracer_->End(kTraceCHROMIUM)) { |
| 11217 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 11218 | "glTraceEndCHROMIUM", "no trace begin found"); |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 11219 | return; |
| 11220 | } |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 11221 | } |
| 11222 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 11223 | void GLES2DecoderImpl::DoDrawBuffersEXT( |
| 11224 | GLsizei count, const GLenum* bufs) { |
| 11225 | if (count > static_cast<GLsizei>(group_->max_draw_buffers())) { |
| 11226 | LOCAL_SET_GL_ERROR( |
| 11227 | GL_INVALID_VALUE, |
| 11228 | "glDrawBuffersEXT", "greater than GL_MAX_DRAW_BUFFERS_EXT"); |
| 11229 | return; |
| 11230 | } |
| 11231 | |
| 11232 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 11233 | if (framebuffer) { |
| 11234 | for (GLsizei i = 0; i < count; ++i) { |
| 11235 | if (bufs[i] != static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i) && |
| 11236 | bufs[i] != GL_NONE) { |
| 11237 | LOCAL_SET_GL_ERROR( |
| 11238 | GL_INVALID_OPERATION, |
| 11239 | "glDrawBuffersEXT", |
| 11240 | "bufs[i] not GL_NONE or GL_COLOR_ATTACHMENTi_EXT"); |
| 11241 | return; |
| 11242 | } |
| 11243 | } |
| 11244 | glDrawBuffersARB(count, bufs); |
| 11245 | framebuffer->SetDrawBuffers(count, bufs); |
| 11246 | } else { // backbuffer |
| 11247 | if (count > 1 || |
| 11248 | (bufs[0] != GL_BACK && bufs[0] != GL_NONE)) { |
| 11249 | LOCAL_SET_GL_ERROR( |
| 11250 | GL_INVALID_OPERATION, |
| 11251 | "glDrawBuffersEXT", |
| 11252 | "more than one buffer or bufs not GL_NONE or GL_BACK"); |
| 11253 | return; |
| 11254 | } |
| 11255 | GLenum mapped_buf = bufs[0]; |
| 11256 | if (GetBackbufferServiceId() != 0 && // emulated backbuffer |
| 11257 | bufs[0] == GL_BACK) { |
| 11258 | mapped_buf = GL_COLOR_ATTACHMENT0; |
| 11259 | } |
| 11260 | glDrawBuffersARB(count, &mapped_buf); |
| 11261 | group_->set_draw_buffer(bufs[0]); |
| 11262 | } |
| 11263 | } |
| 11264 | |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 11265 | void GLES2DecoderImpl::DoLoseContextCHROMIUM(GLenum current, GLenum other) { |
| 11266 | group_->LoseContexts(other); |
| 11267 | reset_status_ = current; |
| 11268 | current_decoder_error_ = error::kLostContext; |
| 11269 | } |
| 11270 | |
kkinnunen | 337d5963 | 2014-08-26 10:19:57 | [diff] [blame] | 11271 | void GLES2DecoderImpl::DoMatrixLoadfCHROMIUM(GLenum matrix_mode, |
| 11272 | const GLfloat* matrix) { |
| 11273 | DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || |
| 11274 | matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); |
| 11275 | if (!features().chromium_path_rendering) { |
| 11276 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 11277 | "glMatrixLoadfCHROMIUM", |
| 11278 | "function not available"); |
| 11279 | return; |
| 11280 | } |
| 11281 | |
| 11282 | GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM |
| 11283 | ? state_.projection_matrix |
| 11284 | : state_.modelview_matrix; |
| 11285 | memcpy(target_matrix, matrix, sizeof(GLfloat) * 16); |
| 11286 | // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV |
| 11287 | // since the values of the _NV and _CHROMIUM tokens match. |
| 11288 | glMatrixLoadfEXT(matrix_mode, matrix); |
| 11289 | } |
| 11290 | |
| 11291 | void GLES2DecoderImpl::DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode) { |
| 11292 | DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || |
| 11293 | matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); |
| 11294 | |
| 11295 | if (!features().chromium_path_rendering) { |
| 11296 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 11297 | "glMatrixLoadIdentityCHROMIUM", |
| 11298 | "function not available"); |
| 11299 | return; |
| 11300 | } |
| 11301 | |
| 11302 | static GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, |
| 11303 | 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, |
| 11304 | 0.0f, 0.0f, 0.0f, 1.0f}; |
| 11305 | |
| 11306 | GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM |
| 11307 | ? state_.projection_matrix |
| 11308 | : state_.modelview_matrix; |
| 11309 | memcpy(target_matrix, kIdentityMatrix, sizeof(kIdentityMatrix)); |
| 11310 | // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV |
| 11311 | // since the values of the _NV and _CHROMIUM tokens match. |
| 11312 | glMatrixLoadIdentityEXT(matrix_mode); |
| 11313 | } |
| 11314 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11315 | bool GLES2DecoderImpl::ValidateAsyncTransfer( |
| 11316 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 11317 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11318 | GLenum target, |
| 11319 | GLint level, |
| 11320 | const void * data) { |
| 11321 | // We only support async uploads to 2D textures for now. |
| 11322 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11323 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11324 | return false; |
| 11325 | } |
| 11326 | // We only support uploads to level zero for now. |
| 11327 | if (level != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11328 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "level != 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11329 | return false; |
| 11330 | } |
| 11331 | // A transfer buffer must be bound, even for asyncTexImage2D. |
| 11332 | if (data == NULL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11333 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, "buffer == 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11334 | return false; |
| 11335 | } |
| 11336 | // We only support one async transfer in progress. |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 11337 | if (!texture_ref || |
| 11338 | async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11339 | LOCAL_SET_GL_ERROR( |
| 11340 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11341 | function_name, "transfer already in progress"); |
| 11342 | return false; |
| 11343 | } |
| 11344 | return true; |
| 11345 | } |
| 11346 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 11347 | base::Closure GLES2DecoderImpl::AsyncUploadTokenCompletionClosure( |
| 11348 | uint32 async_upload_token, |
| 11349 | uint32 sync_data_shm_id, |
| 11350 | uint32 sync_data_shm_offset) { |
| 11351 | scoped_refptr<gpu::Buffer> buffer = GetSharedMemoryBuffer(sync_data_shm_id); |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 11352 | if (!buffer.get() || |
| 11353 | !buffer->GetDataAddress(sync_data_shm_offset, sizeof(AsyncUploadSync))) |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 11354 | return base::Closure(); |
| 11355 | |
| 11356 | AsyncMemoryParams mem_params(buffer, |
| 11357 | sync_data_shm_offset, |
| 11358 | sizeof(AsyncUploadSync)); |
| 11359 | |
| 11360 | scoped_refptr<AsyncUploadTokenCompletionObserver> observer( |
| 11361 | new AsyncUploadTokenCompletionObserver(async_upload_token)); |
| 11362 | |
| 11363 | return base::Bind( |
| 11364 | &AsyncPixelTransferManager::AsyncNotifyCompletion, |
| 11365 | base::Unretained(GetAsyncPixelTransferManager()), |
| 11366 | mem_params, |
| 11367 | observer); |
| 11368 | } |
| 11369 | |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11370 | error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11371 | uint32 immediate_data_size, |
| 11372 | const void* cmd_data) { |
| 11373 | const gles2::cmds::AsyncTexImage2DCHROMIUM& c = |
| 11374 | *static_cast<const gles2::cmds::AsyncTexImage2DCHROMIUM*>(cmd_data); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11375 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11376 | GLenum target = static_cast<GLenum>(c.target); |
| 11377 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11378 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11379 | GLsizei width = static_cast<GLsizei>(c.width); |
| 11380 | GLsizei height = static_cast<GLsizei>(c.height); |
| 11381 | GLint border = static_cast<GLint>(c.border); |
| 11382 | GLenum format = static_cast<GLenum>(c.format); |
| 11383 | GLenum type = static_cast<GLenum>(c.type); |
| 11384 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 11385 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
| 11386 | uint32 pixels_size; |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 11387 | uint32 async_upload_token = static_cast<uint32>(c.async_upload_token); |
| 11388 | uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id); |
| 11389 | uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 11390 | |
| 11391 | base::ScopedClosureRunner scoped_completion_callback; |
| 11392 | if (async_upload_token) { |
| 11393 | base::Closure completion_closure = |
| 11394 | AsyncUploadTokenCompletionClosure(async_upload_token, |
| 11395 | sync_data_shm_id, |
| 11396 | sync_data_shm_offset); |
| 11397 | if (completion_closure.is_null()) |
| 11398 | return error::kInvalidArguments; |
| 11399 | |
| 11400 | scoped_completion_callback.Reset(completion_closure); |
| 11401 | } |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11402 | |
| 11403 | // TODO(epenner): Move this and copies of this memory validation |
| 11404 | // into ValidateTexImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11405 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 11406 | width, height, 1, format, type, state_.unpack_alignment, &pixels_size, |
| 11407 | NULL, NULL)) { |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11408 | return error::kOutOfBounds; |
| 11409 | } |
| 11410 | const void* pixels = NULL; |
| 11411 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 11412 | pixels = GetSharedMemoryAs<const void*>( |
| 11413 | pixels_shm_id, pixels_shm_offset, pixels_size); |
| 11414 | if (!pixels) { |
| 11415 | return error::kOutOfBounds; |
| 11416 | } |
| 11417 | } |
| 11418 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11419 | TextureManager::DoTextImage2DArguments args = { |
| 11420 | target, level, internal_format, width, height, border, format, type, |
| 11421 | pixels, pixels_size}; |
| 11422 | TextureRef* texture_ref; |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11423 | // All the normal glTexSubImage2D validation. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11424 | if (!texture_manager()->ValidateTexImage2D( |
| 11425 | &state_, "glAsyncTexImage2DCHROMIUM", args, &texture_ref)) { |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11426 | return error::kNoError; |
| 11427 | } |
| 11428 | |
| 11429 | // Extra async validation. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11430 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11431 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 11432 | "glAsyncTexImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11433 | return error::kNoError; |
| 11434 | |
| 11435 | // Don't allow async redefinition of a textures. |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 11436 | if (texture->IsDefined()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11437 | LOCAL_SET_GL_ERROR( |
| 11438 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11439 | "glAsyncTexImage2DCHROMIUM", "already defined"); |
| 11440 | return error::kNoError; |
| 11441 | } |
| 11442 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 11443 | if (!EnsureGPUMemoryAvailable(pixels_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11444 | LOCAL_SET_GL_ERROR( |
| 11445 | GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 11446 | return error::kNoError; |
| 11447 | } |
| 11448 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11449 | // Setup the parameters. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 11450 | AsyncTexImage2DParams tex_params = { |
| 11451 | target, level, static_cast<GLenum>(internal_format), |
| 11452 | width, height, border, format, type}; |
[email protected] | c8021e0 | 2014-03-27 06:10:12 | [diff] [blame] | 11453 | AsyncMemoryParams mem_params( |
| 11454 | GetSharedMemoryBuffer(c.pixels_shm_id), c.pixels_shm_offset, pixels_size); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11455 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11456 | // Set up the async state if needed, and make the texture |
| 11457 | // immutable so the async state stays valid. The level info |
| 11458 | // is set up lazily when the transfer completes. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11459 | AsyncPixelTransferDelegate* delegate = |
| 11460 | async_pixel_transfer_manager_->CreatePixelTransferDelegate(texture_ref, |
| 11461 | tex_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11462 | texture->SetImmutable(true); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11463 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11464 | delegate->AsyncTexImage2D( |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11465 | tex_params, |
| 11466 | mem_params, |
| 11467 | base::Bind(&TextureManager::SetLevelInfoFromParams, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11468 | // The callback is only invoked if the transfer delegate still |
| 11469 | // exists, which implies through manager->texture_ref->state |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11470 | // ownership that both of these pointers are valid. |
| 11471 | base::Unretained(texture_manager()), |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11472 | base::Unretained(texture_ref), |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11473 | tex_params)); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 11474 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11475 | } |
| 11476 | |
| 11477 | error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11478 | uint32 immediate_data_size, |
| 11479 | const void* cmd_data) { |
| 11480 | const gles2::cmds::AsyncTexSubImage2DCHROMIUM& c = |
| 11481 | *static_cast<const gles2::cmds::AsyncTexSubImage2DCHROMIUM*>(cmd_data); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11482 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11483 | GLenum target = static_cast<GLenum>(c.target); |
| 11484 | GLint level = static_cast<GLint>(c.level); |
| 11485 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 11486 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 11487 | GLsizei width = static_cast<GLsizei>(c.width); |
| 11488 | GLsizei height = static_cast<GLsizei>(c.height); |
| 11489 | GLenum format = static_cast<GLenum>(c.format); |
| 11490 | GLenum type = static_cast<GLenum>(c.type); |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 11491 | uint32 async_upload_token = static_cast<uint32>(c.async_upload_token); |
| 11492 | uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id); |
| 11493 | uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 11494 | |
| 11495 | base::ScopedClosureRunner scoped_completion_callback; |
| 11496 | if (async_upload_token) { |
| 11497 | base::Closure completion_closure = |
| 11498 | AsyncUploadTokenCompletionClosure(async_upload_token, |
| 11499 | sync_data_shm_id, |
| 11500 | sync_data_shm_offset); |
| 11501 | if (completion_closure.is_null()) |
| 11502 | return error::kInvalidArguments; |
| 11503 | |
| 11504 | scoped_completion_callback.Reset(completion_closure); |
| 11505 | } |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11506 | |
| 11507 | // TODO(epenner): Move this and copies of this memory validation |
| 11508 | // into ValidateTexSubImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11509 | uint32 data_size; |
| 11510 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 11511 | width, height, 1, format, type, state_.unpack_alignment, &data_size, |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11512 | NULL, NULL)) { |
| 11513 | return error::kOutOfBounds; |
| 11514 | } |
| 11515 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 11516 | c.data_shm_id, c.data_shm_offset, data_size); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11517 | |
| 11518 | // All the normal glTexSubImage2D validation. |
| 11519 | error::Error error = error::kNoError; |
| 11520 | if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2DCHROMIUM", |
| 11521 | target, level, xoffset, yoffset, width, height, format, type, pixels)) { |
| 11522 | return error; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11523 | } |
| 11524 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11525 | // Extra async validation. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11526 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 11527 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11528 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11529 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 11530 | "glAsyncTexSubImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11531 | return error::kNoError; |
| 11532 | |
| 11533 | // Guarantee async textures are always 'cleared' as follows: |
| 11534 | // - AsyncTexImage2D can not redefine an existing texture |
| 11535 | // - AsyncTexImage2D must initialize the entire image via non-null buffer. |
| 11536 | // - AsyncTexSubImage2D clears synchronously if not already cleared. |
| 11537 | // - Textures become immutable after an async call. |
| 11538 | // 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] | 11539 | if (!texture->SafeToRenderFrom()) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11540 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, |
| 11541 | target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11542 | LOCAL_SET_GL_ERROR( |
| 11543 | GL_OUT_OF_MEMORY, |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 11544 | "glAsyncTexSubImage2DCHROMIUM", "dimensions too big"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11545 | return error::kNoError; |
| 11546 | } |
| 11547 | } |
| 11548 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11549 | // Setup the parameters. |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 11550 | AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11551 | width, height, format, type}; |
[email protected] | c8021e0 | 2014-03-27 06:10:12 | [diff] [blame] | 11552 | AsyncMemoryParams mem_params( |
| 11553 | GetSharedMemoryBuffer(c.data_shm_id), c.data_shm_offset, data_size); |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11554 | AsyncPixelTransferDelegate* delegate = |
| 11555 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 11556 | if (!delegate) { |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11557 | // TODO(epenner): We may want to enforce exclusive use |
| 11558 | // of async APIs in which case this should become an error, |
| 11559 | // (the texture should have been async defined). |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 11560 | AsyncTexImage2DParams define_params = {target, level, |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11561 | 0, 0, 0, 0, 0, 0}; |
| 11562 | texture->GetLevelSize(target, level, &define_params.width, |
| 11563 | &define_params.height); |
| 11564 | texture->GetLevelType(target, level, &define_params.type, |
| 11565 | &define_params.internal_format); |
| 11566 | // Set up the async state if needed, and make the texture |
| 11567 | // immutable so the async state stays valid. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11568 | delegate = async_pixel_transfer_manager_->CreatePixelTransferDelegate( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 11569 | texture_ref, define_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 11570 | texture->SetImmutable(true); |
| 11571 | } |
| 11572 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11573 | delegate->AsyncTexSubImage2D(tex_params, mem_params); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 11574 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 11575 | } |
| 11576 | |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11577 | error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11578 | uint32 immediate_data_size, |
| 11579 | const void* cmd_data) { |
| 11580 | const gles2::cmds::WaitAsyncTexImage2DCHROMIUM& c = |
| 11581 | *static_cast<const gles2::cmds::WaitAsyncTexImage2DCHROMIUM*>(cmd_data); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11582 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); |
| 11583 | GLenum target = static_cast<GLenum>(c.target); |
| 11584 | |
| 11585 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11586 | LOCAL_SET_GL_ERROR( |
| 11587 | GL_INVALID_ENUM, "glWaitAsyncTexImage2DCHROMIUM", "target"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11588 | return error::kNoError; |
| 11589 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11590 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 11591 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11592 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11593 | LOCAL_SET_GL_ERROR( |
| 11594 | GL_INVALID_OPERATION, |
| 11595 | "glWaitAsyncTexImage2DCHROMIUM", "unknown texture"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11596 | return error::kNoError; |
| 11597 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11598 | AsyncPixelTransferDelegate* delegate = |
| 11599 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 11600 | if (!delegate) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11601 | LOCAL_SET_GL_ERROR( |
| 11602 | GL_INVALID_OPERATION, |
| 11603 | "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); |
| 11604 | return error::kNoError; |
| 11605 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 11606 | delegate->WaitForTransferCompletion(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 11607 | ProcessFinishedAsyncTransfers(); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 11608 | return error::kNoError; |
| 11609 | } |
| 11610 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 11611 | error::Error GLES2DecoderImpl::HandleWaitAllAsyncTexImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11612 | uint32 immediate_data_size, |
| 11613 | const void* data) { |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 11614 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); |
| 11615 | |
| 11616 | GetAsyncPixelTransferManager()->WaitAllAsyncTexImage2D(); |
| 11617 | ProcessFinishedAsyncTransfers(); |
| 11618 | return error::kNoError; |
| 11619 | } |
| 11620 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 11621 | void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( |
| 11622 | TextureRef* texture_ref) { |
| 11623 | Texture* texture = texture_ref->texture(); |
| 11624 | DoDidUseTexImageIfNeeded(texture, texture->target()); |
| 11625 | } |
| 11626 | |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 11627 | void GLES2DecoderImpl::OnContextLostError() { |
| 11628 | group_->LoseContexts(GL_UNKNOWN_CONTEXT_RESET_ARB); |
| 11629 | } |
| 11630 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 11631 | void GLES2DecoderImpl::OnOutOfMemoryError() { |
| 11632 | if (lose_context_when_out_of_memory_) { |
| 11633 | group_->LoseContexts(GL_UNKNOWN_CONTEXT_RESET_ARB); |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 11634 | } |
| 11635 | } |
| 11636 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 11637 | // Include the auto-generated part of this file. We split this because it means |
| 11638 | // we can easily edit the non-auto generated parts right here in this file |
| 11639 | // instead of having to edit some template or the code generator. |
| 11640 | #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 11641 | |
| 11642 | } // namespace gles2 |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 11643 | } // namespace gpu |