[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> |
mateuszs | 3371ab0 | 2015-04-24 13:20:23 | [diff] [blame] | 10 | #include <cmath> |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 11 | #include <list> |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 12 | #include <map> |
dcastagna | 504d45c | 2015-04-06 19:30:39 | [diff] [blame] | 13 | #include <queue> |
[email protected] | 5a6db6c | 2010-04-22 18:32:06 | [diff] [blame] | 14 | |
[email protected] | 00eb49a | 2010-08-12 20:46:57 | [diff] [blame] | 15 | #include "base/at_exit.h" |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 16 | #include "base/bind.h" |
martina.kollarova | a34211d | 2015-06-25 11:49:07 | [diff] [blame^] | 17 | #include "base/callback.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] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 20 | #include "base/memory/scoped_ptr.h" |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 21 | #include "base/numerics/safe_math.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 22 | #include "base/strings/string_number_conversions.h" |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 23 | #include "base/strings/string_split.h" |
primiano | 05dadf01 | 2015-01-28 13:10:32 | [diff] [blame] | 24 | #include "base/trace_event/trace_event.h" |
| 25 | #include "base/trace_event/trace_event_synthetic_delay.h" |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 26 | #include "build/build_config.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 27 | #define GLES2_GPU_SERVICE 1 |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 28 | #include "gpu/command_buffer/common/debug_marker_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 29 | #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 30 | #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
[email protected] | 066849e3 | 2010-05-03 19:14:10 | [diff] [blame] | 31 | #include "gpu/command_buffer/common/id_allocator.h" |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 32 | #include "gpu/command_buffer/common/mailbox.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 33 | #include "gpu/command_buffer/service/async_pixel_transfer_delegate.h" |
| 34 | #include "gpu/command_buffer/service/async_pixel_transfer_manager.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 35 | #include "gpu/command_buffer/service/buffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 36 | #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 37 | #include "gpu/command_buffer/service/context_group.h" |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 38 | #include "gpu/command_buffer/service/context_state.h" |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 39 | #include "gpu/command_buffer/service/error_state.h" |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 40 | #include "gpu/command_buffer/service/feature_info.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 41 | #include "gpu/command_buffer/service/framebuffer_manager.h" |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 42 | #include "gpu/command_buffer/service/gl_utils.h" |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 43 | #include "gpu/command_buffer/service/gles2_cmd_clear_framebuffer.h" |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 44 | #include "gpu/command_buffer/service/gles2_cmd_copy_texture_chromium.h" |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 45 | #include "gpu/command_buffer/service/gles2_cmd_validation.h" |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 46 | #include "gpu/command_buffer/service/gpu_state_tracer.h" |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 47 | #include "gpu/command_buffer/service/gpu_switches.h" |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 48 | #include "gpu/command_buffer/service/gpu_tracer.h" |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 49 | #include "gpu/command_buffer/service/image_manager.h" |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 50 | #include "gpu/command_buffer/service/mailbox_manager.h" |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 51 | #include "gpu/command_buffer/service/memory_tracking.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 52 | #include "gpu/command_buffer/service/program_manager.h" |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 53 | #include "gpu/command_buffer/service/query_manager.h" |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 54 | #include "gpu/command_buffer/service/renderbuffer_manager.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 55 | #include "gpu/command_buffer/service/shader_manager.h" |
[email protected] | a550584e | 2010-09-17 18:01:45 | [diff] [blame] | 56 | #include "gpu/command_buffer/service/shader_translator.h" |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 57 | #include "gpu/command_buffer/service/shader_translator_cache.h" |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 58 | #include "gpu/command_buffer/service/texture_manager.h" |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 59 | #include "gpu/command_buffer/service/valuebuffer_manager.h" |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 60 | #include "gpu/command_buffer/service/vertex_array_manager.h" |
[email protected] | f439096 | 2013-06-11 07:29:22 | [diff] [blame] | 61 | #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
[email protected] | 6896d7f | 2014-04-28 20:24:15 | [diff] [blame] | 62 | #include "third_party/smhasher/src/City.h" |
martina.kollarova | a34211d | 2015-06-25 11:49:07 | [diff] [blame^] | 63 | #include "ui/gfx/geometry/size.h" |
| 64 | #include "ui/gl/gl_context.h" |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 65 | #include "ui/gl/gl_fence.h" |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 66 | #include "ui/gl/gl_image.h" |
[email protected] | c9e2cbbb | 2012-05-12 21:17:27 | [diff] [blame] | 67 | #include "ui/gl/gl_implementation.h" |
| 68 | #include "ui/gl/gl_surface.h" |
dyen | 1fa42196 | 2015-06-17 21:25:39 | [diff] [blame] | 69 | #include "ui/gl/gpu_timing.h" |
[email protected] | 423e644f | 2013-06-19 00:48:27 | [diff] [blame] | 70 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 71 | #if defined(OS_MACOSX) |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 72 | #include <IOSurface/IOSurfaceAPI.h> |
| 73 | // Note that this must be included after gl_bindings.h to avoid conflicts. |
| 74 | #include <OpenGL/CGLIOSurface.h> |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 75 | #endif |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 76 | |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 77 | namespace gpu { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 78 | namespace gles2 { |
| 79 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 80 | namespace { |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 81 | |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 82 | const char kOESDerivativeExtension[] = "GL_OES_standard_derivatives"; |
| 83 | const char kEXTFragDepthExtension[] = "GL_EXT_frag_depth"; |
| 84 | const char kEXTDrawBuffersExtension[] = "GL_EXT_draw_buffers"; |
| 85 | const char kEXTShaderTextureLodExtension[] = "GL_EXT_shader_texture_lod"; |
| 86 | |
| 87 | const GLfloat kIdentityMatrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, |
| 88 | 0.0f, 1.0f, 0.0f, 0.0f, |
| 89 | 0.0f, 0.0f, 1.0f, 0.0f, |
| 90 | 0.0f, 0.0f, 0.0f, 1.0f}; |
[email protected] | 693ca51 | 2012-11-13 18:09:13 | [diff] [blame] | 91 | |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 92 | bool PrecisionMeetsSpecForHighpFloat(GLint rangeMin, |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 93 | GLint rangeMax, |
| 94 | GLint precision) { |
| 95 | return (rangeMin >= 62) && (rangeMax >= 62) && (precision >= 16); |
| 96 | } |
| 97 | |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 98 | void GetShaderPrecisionFormatImpl(GLenum shader_type, |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 99 | GLenum precision_type, |
dcastagna | 504d45c | 2015-04-06 19:30:39 | [diff] [blame] | 100 | GLint* range, GLint* precision) { |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 101 | switch (precision_type) { |
| 102 | case GL_LOW_INT: |
| 103 | case GL_MEDIUM_INT: |
| 104 | case GL_HIGH_INT: |
| 105 | // These values are for a 32-bit twos-complement integer format. |
| 106 | range[0] = 31; |
| 107 | range[1] = 30; |
| 108 | *precision = 0; |
| 109 | break; |
| 110 | case GL_LOW_FLOAT: |
| 111 | case GL_MEDIUM_FLOAT: |
| 112 | case GL_HIGH_FLOAT: |
| 113 | // These values are for an IEEE single-precision floating-point format. |
| 114 | range[0] = 127; |
| 115 | range[1] = 127; |
| 116 | *precision = 23; |
| 117 | break; |
| 118 | default: |
| 119 | NOTREACHED(); |
| 120 | break; |
| 121 | } |
| 122 | |
[email protected] | 8af4d5e | 2013-03-15 23:55:33 | [diff] [blame] | 123 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 && |
| 124 | gfx::g_driver_gl.fn.glGetShaderPrecisionFormatFn) { |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 125 | // This function is sometimes defined even though it's really just |
| 126 | // a stub, so we need to set range and precision as if it weren't |
| 127 | // defined before calling it. |
[email protected] | 501b5740 | 2013-03-14 22:21:44 | [diff] [blame] | 128 | // On Mac OS with some GPUs, calling this generates a |
| 129 | // GL_INVALID_OPERATION error. Avoid calling it on non-GLES2 |
| 130 | // platforms. |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 131 | glGetShaderPrecisionFormat(shader_type, precision_type, |
| 132 | range, precision); |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 133 | |
| 134 | // TODO(brianderson): Make the following official workarounds. |
| 135 | |
| 136 | // Some drivers have bugs where they report the ranges as a negative number. |
| 137 | // Taking the absolute value here shouldn't hurt because negative numbers |
| 138 | // aren't expected anyway. |
| 139 | range[0] = abs(range[0]); |
| 140 | range[1] = abs(range[1]); |
| 141 | |
| 142 | // If the driver reports a precision for highp float that isn't actually |
| 143 | // highp, don't pretend like it's supported because shader compilation will |
| 144 | // fail anyway. |
| 145 | if (precision_type == GL_HIGH_FLOAT && |
| 146 | !PrecisionMeetsSpecForHighpFloat(range[0], range[1], *precision)) { |
| 147 | range[0] = 0; |
| 148 | range[1] = 0; |
| 149 | *precision = 0; |
| 150 | } |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 154 | gfx::OverlayTransform GetGFXOverlayTransform(GLenum plane_transform) { |
[email protected] | d286ebbc | 2014-07-03 17:19:10 | [diff] [blame] | 155 | switch (plane_transform) { |
| 156 | case GL_OVERLAY_TRANSFORM_NONE_CHROMIUM: |
| 157 | return gfx::OVERLAY_TRANSFORM_NONE; |
| 158 | case GL_OVERLAY_TRANSFORM_FLIP_HORIZONTAL_CHROMIUM: |
| 159 | return gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL; |
| 160 | case GL_OVERLAY_TRANSFORM_FLIP_VERTICAL_CHROMIUM: |
| 161 | return gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL; |
| 162 | case GL_OVERLAY_TRANSFORM_ROTATE_90_CHROMIUM: |
| 163 | return gfx::OVERLAY_TRANSFORM_ROTATE_90; |
| 164 | case GL_OVERLAY_TRANSFORM_ROTATE_180_CHROMIUM: |
| 165 | return gfx::OVERLAY_TRANSFORM_ROTATE_180; |
| 166 | case GL_OVERLAY_TRANSFORM_ROTATE_270_CHROMIUM: |
| 167 | return gfx::OVERLAY_TRANSFORM_ROTATE_270; |
| 168 | default: |
| 169 | return gfx::OVERLAY_TRANSFORM_INVALID; |
| 170 | } |
| 171 | } |
| 172 | |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 173 | template <typename MANAGER_TYPE, typename OBJECT_TYPE> |
| 174 | GLuint GetClientId(const MANAGER_TYPE* manager, const OBJECT_TYPE* object) { |
| 175 | DCHECK(manager); |
| 176 | GLuint client_id = 0; |
| 177 | if (object) { |
| 178 | manager->GetClientId(object->service_id(), &client_id); |
| 179 | } |
| 180 | return client_id; |
| 181 | } |
| 182 | |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 183 | struct Vec4f { |
| 184 | explicit Vec4f(const Vec4& data) { |
| 185 | data.GetValues(v); |
| 186 | } |
| 187 | |
| 188 | GLfloat v[4]; |
| 189 | }; |
| 190 | |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 191 | // Returns the union of |rect1| and |rect2| if one of the rectangles is empty, |
| 192 | // contains the other rectangle or shares an edge with the other rectangle. |
| 193 | bool CombineAdjacentRects(const gfx::Rect& rect1, |
| 194 | const gfx::Rect& rect2, |
| 195 | gfx::Rect* result) { |
| 196 | // Return |rect2| if |rect1| is empty or |rect2| contains |rect1|. |
| 197 | if (rect1.IsEmpty() || rect2.Contains(rect1)) { |
| 198 | *result = rect2; |
| 199 | return true; |
| 200 | } |
| 201 | |
| 202 | // Return |rect1| if |rect2| is empty or |rect1| contains |rect2|. |
| 203 | if (rect2.IsEmpty() || rect1.Contains(rect2)) { |
| 204 | *result = rect1; |
| 205 | return true; |
| 206 | } |
| 207 | |
| 208 | // Return the union of |rect1| and |rect2| if they share an edge. |
| 209 | if (rect1.SharesEdgeWith(rect2)) { |
| 210 | *result = gfx::UnionRects(rect1, rect2); |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | // Return false if it's not possible to combine |rect1| and |rect2|. |
| 215 | return false; |
| 216 | } |
| 217 | |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 218 | } // namespace |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 219 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 220 | class GLES2DecoderImpl; |
| 221 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 222 | // Local versions of the SET_GL_ERROR macros |
| 223 | #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 224 | ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 225 | #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 226 | ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \ |
| 227 | function_name, value, label) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 228 | #define LOCAL_SET_GL_ERROR_INVALID_PARAM(error, function_name, pname) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 229 | ERRORSTATE_SET_GL_ERROR_INVALID_PARAM(state_.GetErrorState(), error, \ |
| 230 | function_name, pname) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 231 | #define LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 232 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(state_.GetErrorState(), \ |
| 233 | function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 234 | #define LOCAL_PEEK_GL_ERROR(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 235 | ERRORSTATE_PEEK_GL_ERROR(state_.GetErrorState(), function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 236 | #define LOCAL_CLEAR_REAL_GL_ERRORS(function_name) \ |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 237 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(state_.GetErrorState(), function_name) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 238 | #define LOCAL_PERFORMANCE_WARNING(msg) \ |
| 239 | PerformanceWarning(__FILE__, __LINE__, msg) |
| 240 | #define LOCAL_RENDER_WARNING(msg) \ |
| 241 | RenderWarning(__FILE__, __LINE__, msg) |
| 242 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 243 | // Check that certain assumptions the code makes are true. There are places in |
| 244 | // the code where shared memory is passed direclty to GL. Example, glUniformiv, |
| 245 | // glShaderSource. The command buffer code assumes GLint and GLsizei (and maybe |
| 246 | // a few others) are 32bits. If they are not 32bits the code will have to change |
| 247 | // to call those GL functions with service side memory and then copy the results |
| 248 | // to shared memory, converting the sizes. |
mostynb | 7f03209 | 2014-12-20 00:36:44 | [diff] [blame] | 249 | static_assert(sizeof(GLint) == sizeof(uint32), // NOLINT |
| 250 | "GLint should be the same size as uint32"); |
| 251 | static_assert(sizeof(GLsizei) == sizeof(uint32), // NOLINT |
| 252 | "GLsizei should be the same size as uint32"); |
| 253 | static_assert(sizeof(GLfloat) == sizeof(float), // NOLINT |
| 254 | "GLfloat should be the same size as float"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 255 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 256 | // TODO(kbr): the use of this anonymous namespace core dumps the |
| 257 | // linker on Mac OS X 10.6 when the symbol ordering file is used |
| 258 | // namespace { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 259 | |
| 260 | // Returns the address of the first byte after a struct. |
| 261 | template <typename T> |
| 262 | const void* AddressAfterStruct(const T& pod) { |
| 263 | return reinterpret_cast<const uint8*>(&pod) + sizeof(pod); |
| 264 | } |
| 265 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 266 | // Returns the address of the frst byte after the struct or NULL if size > |
| 267 | // immediate_data_size. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 268 | template <typename RETURN_TYPE, typename COMMAND_TYPE> |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 269 | RETURN_TYPE GetImmediateDataAs(const COMMAND_TYPE& pod, |
| 270 | uint32 size, |
| 271 | uint32 immediate_data_size) { |
| 272 | return (size <= immediate_data_size) ? |
| 273 | static_cast<RETURN_TYPE>(const_cast<void*>(AddressAfterStruct(pod))) : |
| 274 | NULL; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 275 | } |
| 276 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 277 | // Computes the data size for certain gl commands like glUniform. |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 278 | bool ComputeDataSize( |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 279 | GLuint count, |
| 280 | size_t size, |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 281 | unsigned int elements_per_unit, |
| 282 | uint32* dst) { |
| 283 | uint32 value; |
| 284 | if (!SafeMultiplyUint32(count, size, &value)) { |
| 285 | return false; |
| 286 | } |
| 287 | if (!SafeMultiplyUint32(value, elements_per_unit, &value)) { |
| 288 | return false; |
| 289 | } |
| 290 | *dst = value; |
| 291 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 292 | } |
| 293 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 294 | // Return true if a character belongs to the ASCII subset as defined in |
| 295 | // GLSL ES 1.0 spec section 3.1. |
| 296 | static bool CharacterIsValidForGLES(unsigned char c) { |
| 297 | // Printing characters are valid except " $ ` @ \ ' DEL. |
| 298 | if (c >= 32 && c <= 126 && |
| 299 | c != '"' && |
| 300 | c != '$' && |
| 301 | c != '`' && |
| 302 | c != '@' && |
| 303 | c != '\\' && |
| 304 | c != '\'') { |
| 305 | return true; |
| 306 | } |
| 307 | // Horizontal tab, line feed, vertical tab, form feed, carriage return |
| 308 | // are also valid. |
| 309 | if (c >= 9 && c <= 13) { |
| 310 | return true; |
| 311 | } |
| 312 | |
| 313 | return false; |
| 314 | } |
| 315 | |
| 316 | static bool StringIsValidForGLES(const char* str) { |
| 317 | for (; *str; ++str) { |
| 318 | if (!CharacterIsValidForGLES(*str)) { |
| 319 | return false; |
| 320 | } |
| 321 | } |
| 322 | return true; |
| 323 | } |
| 324 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 325 | // This class prevents any GL errors that occur when it is in scope from |
| 326 | // being reported to the client. |
| 327 | class ScopedGLErrorSuppressor { |
| 328 | public: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 329 | explicit ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 330 | const char* function_name, ErrorState* error_state); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 331 | ~ScopedGLErrorSuppressor(); |
| 332 | private: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 333 | const char* function_name_; |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 334 | ErrorState* error_state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 335 | DISALLOW_COPY_AND_ASSIGN(ScopedGLErrorSuppressor); |
| 336 | }; |
| 337 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 338 | // Temporarily changes a decoder's bound texture and restore it when this |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 339 | // object goes out of scope. Also temporarily switches to using active texture |
| 340 | // unit zero in case the client has changed that to something invalid. |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 341 | class ScopedTextureBinder { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 342 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 343 | explicit ScopedTextureBinder(ContextState* state, GLuint id, GLenum target); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 344 | ~ScopedTextureBinder(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 345 | |
| 346 | private: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 347 | ContextState* state_; |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 348 | GLenum target_; |
| 349 | DISALLOW_COPY_AND_ASSIGN(ScopedTextureBinder); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | // Temporarily changes a decoder's bound render buffer and restore it when this |
| 353 | // object goes out of scope. |
| 354 | class ScopedRenderBufferBinder { |
| 355 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 356 | explicit ScopedRenderBufferBinder(ContextState* state, GLuint id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 357 | ~ScopedRenderBufferBinder(); |
| 358 | |
| 359 | private: |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 360 | ContextState* state_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 361 | DISALLOW_COPY_AND_ASSIGN(ScopedRenderBufferBinder); |
| 362 | }; |
| 363 | |
| 364 | // Temporarily changes a decoder's bound frame buffer and restore it when this |
| 365 | // object goes out of scope. |
| 366 | class ScopedFrameBufferBinder { |
| 367 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 368 | explicit ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, GLuint id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 369 | ~ScopedFrameBufferBinder(); |
| 370 | |
| 371 | private: |
| 372 | GLES2DecoderImpl* decoder_; |
| 373 | DISALLOW_COPY_AND_ASSIGN(ScopedFrameBufferBinder); |
| 374 | }; |
| 375 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 376 | // Temporarily changes a decoder's bound frame buffer to a resolved version of |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 377 | // the multisampled offscreen render buffer if that buffer is multisampled, and, |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 378 | // if it is bound or enforce_internal_framebuffer is true. If internal is |
| 379 | // true, the resolved framebuffer is not visible to the parent. |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 380 | class ScopedResolvedFrameBufferBinder { |
| 381 | public: |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 382 | explicit ScopedResolvedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 383 | bool enforce_internal_framebuffer, |
| 384 | bool internal); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 385 | ~ScopedResolvedFrameBufferBinder(); |
| 386 | |
| 387 | private: |
| 388 | GLES2DecoderImpl* decoder_; |
| 389 | bool resolve_and_bind_; |
| 390 | DISALLOW_COPY_AND_ASSIGN(ScopedResolvedFrameBufferBinder); |
| 391 | }; |
| 392 | |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 393 | class ScopedModifyPixels { |
| 394 | public: |
| 395 | explicit ScopedModifyPixels(TextureRef* ref); |
| 396 | ~ScopedModifyPixels(); |
| 397 | |
| 398 | private: |
| 399 | TextureRef* ref_; |
| 400 | }; |
| 401 | |
| 402 | ScopedModifyPixels::ScopedModifyPixels(TextureRef* ref) : ref_(ref) { |
| 403 | if (ref_) |
| 404 | ref_->texture()->OnWillModifyPixels(); |
| 405 | } |
| 406 | |
| 407 | ScopedModifyPixels::~ScopedModifyPixels() { |
| 408 | if (ref_) |
| 409 | ref_->texture()->OnDidModifyPixels(); |
| 410 | } |
| 411 | |
| 412 | class ScopedRenderTo { |
| 413 | public: |
| 414 | explicit ScopedRenderTo(Framebuffer* framebuffer); |
| 415 | ~ScopedRenderTo(); |
| 416 | |
| 417 | private: |
| 418 | const Framebuffer* framebuffer_; |
| 419 | }; |
| 420 | |
| 421 | ScopedRenderTo::ScopedRenderTo(Framebuffer* framebuffer) |
| 422 | : framebuffer_(framebuffer) { |
| 423 | if (framebuffer) |
| 424 | framebuffer_->OnWillRenderTo(); |
| 425 | } |
| 426 | |
| 427 | ScopedRenderTo::~ScopedRenderTo() { |
| 428 | if (framebuffer_) |
| 429 | framebuffer_->OnDidRenderTo(); |
| 430 | } |
| 431 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 432 | // Encapsulates an OpenGL texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 433 | class BackTexture { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 434 | public: |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 435 | explicit BackTexture(MemoryTracker* memory_tracker, ContextState* state); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 436 | ~BackTexture(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 437 | |
| 438 | // Create a new render texture. |
| 439 | void Create(); |
| 440 | |
| 441 | // Set the initial size and format of a render texture or resize it. |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 442 | bool AllocateStorage(const gfx::Size& size, GLenum format, bool zero); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 443 | |
| 444 | // Copy the contents of the currently bound frame buffer. |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 445 | void Copy(const gfx::Size& size, GLenum format); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 446 | |
| 447 | // Destroy the render texture. This must be explicitly called before |
| 448 | // destroying this object. |
| 449 | void Destroy(); |
| 450 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 451 | // Invalidate the texture. This can be used when a context is lost and it is |
| 452 | // not possible to make it current in order to free the resource. |
| 453 | void Invalidate(); |
| 454 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 455 | GLuint id() const { |
| 456 | return id_; |
| 457 | } |
| 458 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 459 | gfx::Size size() const { |
| 460 | return size_; |
| 461 | } |
| 462 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 463 | private: |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 464 | MemoryTypeTracker memory_tracker_; |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 465 | ContextState* state_; |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 466 | size_t bytes_allocated_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 467 | GLuint id_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 468 | gfx::Size size_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 469 | DISALLOW_COPY_AND_ASSIGN(BackTexture); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 470 | }; |
| 471 | |
| 472 | // Encapsulates an OpenGL render buffer of any format. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 473 | class BackRenderbuffer { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 474 | public: |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 475 | explicit BackRenderbuffer( |
| 476 | RenderbufferManager* renderbuffer_manager, |
| 477 | MemoryTracker* memory_tracker, |
| 478 | ContextState* state); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 479 | ~BackRenderbuffer(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 480 | |
| 481 | // Create a new render buffer. |
| 482 | void Create(); |
| 483 | |
| 484 | // Set the initial size and format of a render buffer or resize it. |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 485 | bool AllocateStorage(const FeatureInfo* feature_info, |
| 486 | const gfx::Size& size, |
| 487 | GLenum format, |
| 488 | GLsizei samples); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 489 | |
| 490 | // Destroy the render buffer. This must be explicitly called before destroying |
| 491 | // this object. |
| 492 | void Destroy(); |
| 493 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 494 | // Invalidate the render buffer. This can be used when a context is lost and |
| 495 | // it is not possible to make it current in order to free the resource. |
| 496 | void Invalidate(); |
| 497 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 498 | GLuint id() const { |
| 499 | return id_; |
| 500 | } |
| 501 | |
| 502 | private: |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 503 | RenderbufferManager* renderbuffer_manager_; |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 504 | MemoryTypeTracker memory_tracker_; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 505 | ContextState* state_; |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 506 | size_t bytes_allocated_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 507 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 508 | DISALLOW_COPY_AND_ASSIGN(BackRenderbuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 509 | }; |
| 510 | |
| 511 | // Encapsulates an OpenGL frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 512 | class BackFramebuffer { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 513 | public: |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 514 | explicit BackFramebuffer(GLES2DecoderImpl* decoder); |
| 515 | ~BackFramebuffer(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 516 | |
| 517 | // Create a new frame buffer. |
| 518 | void Create(); |
| 519 | |
| 520 | // Attach a color render buffer to a frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 521 | void AttachRenderTexture(BackTexture* texture); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 522 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 523 | // Attach a render buffer to a frame buffer. Note that this unbinds any |
| 524 | // currently bound frame buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 525 | void AttachRenderBuffer(GLenum target, BackRenderbuffer* render_buffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 526 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 527 | // Destroy the frame buffer. This must be explicitly called before destroying |
| 528 | // this object. |
| 529 | void Destroy(); |
| 530 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 531 | // Invalidate the frame buffer. This can be used when a context is lost and it |
| 532 | // is not possible to make it current in order to free the resource. |
| 533 | void Invalidate(); |
| 534 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 535 | // See glCheckFramebufferStatusEXT. |
| 536 | GLenum CheckStatus(); |
| 537 | |
| 538 | GLuint id() const { |
| 539 | return id_; |
| 540 | } |
| 541 | |
| 542 | private: |
| 543 | GLES2DecoderImpl* decoder_; |
| 544 | GLuint id_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 545 | DISALLOW_COPY_AND_ASSIGN(BackFramebuffer); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 546 | }; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 547 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 548 | struct FenceCallback { |
dcastagna | 504d45c | 2015-04-06 19:30:39 | [diff] [blame] | 549 | FenceCallback() |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 550 | : fence(gfx::GLFence::Create()) { |
| 551 | DCHECK(fence); |
| 552 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 553 | std::vector<base::Closure> callbacks; |
| 554 | scoped_ptr<gfx::GLFence> fence; |
| 555 | }; |
| 556 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 557 | class AsyncUploadTokenCompletionObserver |
| 558 | : public AsyncPixelTransferCompletionObserver { |
| 559 | public: |
| 560 | explicit AsyncUploadTokenCompletionObserver(uint32 async_upload_token) |
| 561 | : async_upload_token_(async_upload_token) { |
| 562 | } |
| 563 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 564 | void DidComplete(const AsyncMemoryParams& mem_params) override { |
dcheng | 6ef3c555 | 2014-08-30 05:34:19 | [diff] [blame] | 565 | DCHECK(mem_params.buffer().get()); |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 566 | void* data = mem_params.GetDataAddress(); |
| 567 | AsyncUploadSync* sync = static_cast<AsyncUploadSync*>(data); |
| 568 | sync->SetAsyncUploadToken(async_upload_token_); |
| 569 | } |
| 570 | |
| 571 | private: |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 572 | ~AsyncUploadTokenCompletionObserver() override {} |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 573 | |
| 574 | uint32 async_upload_token_; |
| 575 | |
| 576 | DISALLOW_COPY_AND_ASSIGN(AsyncUploadTokenCompletionObserver); |
| 577 | }; |
| 578 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 579 | // } // anonymous namespace. |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 580 | |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 581 | // static |
| 582 | const unsigned int GLES2Decoder::kDefaultStencilMask = |
| 583 | static_cast<unsigned int>(-1); |
| 584 | |
[email protected] | ddb1e5a | 2010-12-13 20:10:45 | [diff] [blame] | 585 | bool GLES2Decoder::GetServiceTextureId(uint32 client_texture_id, |
| 586 | uint32* service_texture_id) { |
| 587 | return false; |
| 588 | } |
| 589 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 590 | GLES2Decoder::GLES2Decoder() |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 591 | : initialized_(false), |
| 592 | debug_(false), |
zmo | 84c0820 | 2014-11-23 15:28:40 | [diff] [blame] | 593 | log_commands_(false), |
| 594 | unsafe_es3_apis_enabled_(false) { |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 595 | } |
| 596 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 597 | GLES2Decoder::~GLES2Decoder() { |
| 598 | } |
| 599 | |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 600 | void GLES2Decoder::BeginDecoding() {} |
| 601 | |
| 602 | void GLES2Decoder::EndDecoding() {} |
| 603 | |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 604 | // This class implements GLES2Decoder so we don't have to expose all the GLES2 |
| 605 | // cmd stuff to outside this class. |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 606 | class GLES2DecoderImpl : public GLES2Decoder, |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 607 | public FramebufferManager::TextureDetachObserver, |
| 608 | public ErrorStateClient { |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 609 | public: |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 610 | explicit GLES2DecoderImpl(ContextGroup* group); |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 611 | ~GLES2DecoderImpl() override; |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 612 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 613 | // Overridden from AsyncAPIInterface. |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 614 | Error DoCommand(unsigned int command, |
| 615 | unsigned int arg_count, |
| 616 | const void* args) override; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 617 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 618 | error::Error DoCommands(unsigned int num_commands, |
| 619 | const void* buffer, |
| 620 | int num_entries, |
| 621 | int* entries_processed) override; |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 622 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 623 | template <bool DebugImpl> |
| 624 | error::Error DoCommandsImpl(unsigned int num_commands, |
| 625 | const void* buffer, |
| 626 | int num_entries, |
| 627 | int* entries_processed); |
| 628 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 629 | // Overridden from AsyncAPIInterface. |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 630 | const char* GetCommandName(unsigned int command_id) const override; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 631 | |
| 632 | // Overridden from GLES2Decoder. |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 633 | bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, |
| 634 | const scoped_refptr<gfx::GLContext>& context, |
| 635 | bool offscreen, |
dongseong.hwang | 4c04a16 | 2015-03-04 07:27:33 | [diff] [blame] | 636 | const gfx::Size& offscreen_size, |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 637 | const DisallowedFeatures& disallowed_features, |
| 638 | const std::vector<int32>& attribs) override; |
| 639 | void Destroy(bool have_context) override; |
| 640 | void SetSurface(const scoped_refptr<gfx::GLSurface>& surface) override; |
| 641 | void ProduceFrontBuffer(const Mailbox& mailbox) override; |
| 642 | bool ResizeOffscreenFrameBuffer(const gfx::Size& size) override; |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 643 | void UpdateParentTextureInfo(); |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 644 | bool MakeCurrent() override; |
| 645 | GLES2Util* GetGLES2Util() override { return &util_; } |
| 646 | gfx::GLContext* GetGLContext() override { return context_.get(); } |
| 647 | ContextGroup* GetContextGroup() override { return group_.get(); } |
| 648 | Capabilities GetCapabilities() override; |
| 649 | void RestoreState(const ContextState* prev_state) override; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 650 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 651 | void RestoreActiveTexture() const override { state_.RestoreActiveTexture(); } |
| 652 | void RestoreAllTextureUnitBindings( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 653 | const ContextState* prev_state) const override { |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 654 | state_.RestoreAllTextureUnitBindings(prev_state); |
[email protected] | 21700451 | 2013-05-10 21:25:55 | [diff] [blame] | 655 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 656 | void RestoreActiveTextureUnitBinding(unsigned int target) const override { |
[email protected] | 4b2d2b26 | 2014-03-21 22:05:27 | [diff] [blame] | 657 | state_.RestoreActiveTextureUnitBinding(target); |
| 658 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 659 | void RestoreBufferBindings() const override { |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 660 | state_.RestoreBufferBindings(); |
| 661 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 662 | void RestoreGlobalState() const override { state_.RestoreGlobalState(NULL); } |
| 663 | void RestoreProgramBindings() const override { |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 664 | state_.RestoreProgramBindings(); |
| 665 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 666 | void RestoreTextureUnitBindings(unsigned unit) const override { |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 667 | state_.RestoreTextureUnitBindings(unit, NULL); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 668 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 669 | void RestoreFramebufferBindings() const override; |
| 670 | void RestoreRenderbufferBindings() override; |
| 671 | void RestoreTextureState(unsigned service_id) const override; |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 672 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 673 | void ClearAllAttributes() const override; |
| 674 | void RestoreAllAttributes() const override; |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 675 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 676 | QueryManager* GetQueryManager() override { return query_manager_.get(); } |
| 677 | VertexArrayManager* GetVertexArrayManager() override { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 678 | return vertex_array_manager_.get(); |
| 679 | } |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 680 | ImageManager* GetImageManager() override { return image_manager_.get(); } |
orglofch | 33edd84 | 2014-12-03 05:32:15 | [diff] [blame] | 681 | |
| 682 | ValuebufferManager* GetValuebufferManager() override { |
| 683 | return valuebuffer_manager(); |
| 684 | } |
| 685 | |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 686 | bool ProcessPendingQueries(bool did_finish) override; |
orglofch | 33edd84 | 2014-12-03 05:32:15 | [diff] [blame] | 687 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 688 | bool HasMoreIdleWork() override; |
| 689 | void PerformIdleWork() override; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 690 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 691 | void WaitForReadPixels(base::Closure callback) override; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 692 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 693 | void SetResizeCallback( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 694 | const base::Callback<void(gfx::Size, float)>& callback) override; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 695 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 696 | Logger* GetLogger() override; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 697 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 698 | void BeginDecoding() override; |
| 699 | void EndDecoding() override; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 700 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 701 | ErrorState* GetErrorState() override; |
| 702 | const ContextState* GetContextState() override { return &state_; } |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 703 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 704 | void SetShaderCacheCallback(const ShaderCacheCallback& callback) override; |
| 705 | void SetWaitSyncPointCallback(const WaitSyncPointCallback& callback) override; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 706 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 707 | AsyncPixelTransferManager* GetAsyncPixelTransferManager() override; |
| 708 | void ResetAsyncPixelTransferManagerForTest() override; |
| 709 | void SetAsyncPixelTransferManagerForTest( |
mohan.reddy | 5e1b895 | 2014-10-08 01:38:17 | [diff] [blame] | 710 | AsyncPixelTransferManager* manager) override; |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 711 | void SetIgnoreCachedStateForTest(bool ignore) override; |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 712 | void ProcessFinishedAsyncTransfers(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 713 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 714 | bool GetServiceTextureId(uint32 client_texture_id, |
| 715 | uint32* service_texture_id) override; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 716 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 717 | uint32 GetTextureUploadCount() override; |
| 718 | base::TimeDelta GetTotalTextureUploadTime() override; |
| 719 | base::TimeDelta GetTotalProcessingCommandsTime() override; |
| 720 | void AddProcessingCommandsTime(base::TimeDelta) override; |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 721 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 722 | // Restores the current state to the user's settings. |
| 723 | void RestoreCurrentFramebufferBindings(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 724 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 725 | // Sets DEPTH_TEST, STENCIL_TEST and color mask for the current framebuffer. |
| 726 | void ApplyDirtyState(); |
| 727 | |
| 728 | // These check the state of the currently bound framebuffer or the |
| 729 | // backbuffer if no framebuffer is bound. |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 730 | // If all_draw_buffers is false, only check with COLOR_ATTACHMENT0, otherwise |
| 731 | // check with all attached and enabled color attachments. |
| 732 | bool BoundFramebufferHasColorAttachmentWithAlpha(bool all_draw_buffers); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 733 | bool BoundFramebufferHasDepthAttachment(); |
| 734 | bool BoundFramebufferHasStencilAttachment(); |
| 735 | |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 736 | error::ContextLostReason GetContextLostReason() override; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 737 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 738 | // Overridden from FramebufferManager::TextureDetachObserver: |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 739 | void OnTextureRefDetachedFromFramebuffer(TextureRef* texture) override; |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 740 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 741 | // Overriden from ErrorStateClient. |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 742 | void OnContextLostError() override; |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 743 | void OnOutOfMemoryError() override; |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 744 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 745 | // Ensure Renderbuffer corresponding to last DoBindRenderbuffer() is bound. |
| 746 | void EnsureRenderbufferBound(); |
| 747 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 748 | // Helpers to facilitate calling into compatible extensions. |
| 749 | static void RenderbufferStorageMultisampleHelper( |
| 750 | const FeatureInfo* feature_info, |
| 751 | GLenum target, |
| 752 | GLsizei samples, |
| 753 | GLenum internal_format, |
| 754 | GLsizei width, |
| 755 | GLsizei height); |
| 756 | |
| 757 | void BlitFramebufferHelper(GLint srcX0, |
| 758 | GLint srcY0, |
| 759 | GLint srcX1, |
| 760 | GLint srcY1, |
| 761 | GLint dstX0, |
| 762 | GLint dstY0, |
| 763 | GLint dstX1, |
| 764 | GLint dstY1, |
| 765 | GLbitfield mask, |
| 766 | GLenum filter); |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 767 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 768 | private: |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 769 | friend class ScopedFrameBufferBinder; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 770 | friend class ScopedResolvedFrameBufferBinder; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 771 | friend class BackFramebuffer; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 772 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 773 | // Initialize or re-initialize the shader translator. |
| 774 | bool InitializeShaderTranslator(); |
| 775 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 776 | void UpdateCapabilities(); |
| 777 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 778 | // Helpers for the glGen and glDelete functions. |
| 779 | bool GenTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 780 | void DeleteTexturesHelper(GLsizei n, const GLuint* client_ids); |
| 781 | bool GenBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 782 | void DeleteBuffersHelper(GLsizei n, const GLuint* client_ids); |
| 783 | bool GenFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 784 | void DeleteFramebuffersHelper(GLsizei n, const GLuint* client_ids); |
| 785 | bool GenRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
| 786 | void DeleteRenderbuffersHelper(GLsizei n, const GLuint* client_ids); |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 787 | bool GenValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* client_ids); |
| 788 | void DeleteValuebuffersCHROMIUMHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 789 | bool GenQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
| 790 | void DeleteQueriesEXTHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 791 | bool GenVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
| 792 | void DeleteVertexArraysOESHelper(GLsizei n, const GLuint* client_ids); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 793 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 794 | // Helper for async upload token completion notification callback. |
| 795 | base::Closure AsyncUploadTokenCompletionClosure(uint32 async_upload_token, |
| 796 | uint32 sync_data_shm_id, |
| 797 | uint32 sync_data_shm_offset); |
| 798 | |
| 799 | |
| 800 | |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 801 | // Workarounds |
| 802 | void OnFboChanged() const; |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 803 | void OnUseFramebuffer() const; |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 804 | |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 805 | error::ContextLostReason GetContextLostReasonFromResetStatus( |
| 806 | GLenum reset_status) const; |
| 807 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 808 | // TODO(gman): Cache these pointers? |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 809 | BufferManager* buffer_manager() { |
| 810 | return group_->buffer_manager(); |
| 811 | } |
| 812 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 813 | RenderbufferManager* renderbuffer_manager() { |
| 814 | return group_->renderbuffer_manager(); |
| 815 | } |
| 816 | |
| 817 | FramebufferManager* framebuffer_manager() { |
| 818 | return group_->framebuffer_manager(); |
| 819 | } |
| 820 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 821 | ValuebufferManager* valuebuffer_manager() { |
| 822 | return group_->valuebuffer_manager(); |
| 823 | } |
| 824 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 825 | ProgramManager* program_manager() { |
| 826 | return group_->program_manager(); |
| 827 | } |
| 828 | |
| 829 | ShaderManager* shader_manager() { |
| 830 | return group_->shader_manager(); |
| 831 | } |
| 832 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 833 | ShaderTranslatorCache* shader_translator_cache() { |
| 834 | return group_->shader_translator_cache(); |
| 835 | } |
| 836 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 837 | const TextureManager* texture_manager() const { |
| 838 | return group_->texture_manager(); |
| 839 | } |
| 840 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 841 | TextureManager* texture_manager() { |
| 842 | return group_->texture_manager(); |
| 843 | } |
| 844 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 845 | MailboxManager* mailbox_manager() { |
| 846 | return group_->mailbox_manager(); |
| 847 | } |
| 848 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 849 | ImageManager* image_manager() { return image_manager_.get(); } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 850 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 851 | VertexArrayManager* vertex_array_manager() { |
| 852 | return vertex_array_manager_.get(); |
| 853 | } |
| 854 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 855 | MemoryTracker* memory_tracker() { |
| 856 | return group_->memory_tracker(); |
| 857 | } |
| 858 | |
| 859 | bool EnsureGPUMemoryAvailable(size_t estimated_size) { |
| 860 | MemoryTracker* tracker = memory_tracker(); |
| 861 | if (tracker) { |
| 862 | return tracker->EnsureGPUMemoryAvailable(estimated_size); |
| 863 | } |
| 864 | return true; |
| 865 | } |
| 866 | |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 867 | bool IsWebGLContext() const { |
| 868 | return webgl_version_ == 1 || webgl_version_ == 2; |
| 869 | } |
| 870 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 871 | bool IsOffscreenBufferMultisampled() const { |
| 872 | return offscreen_target_samples_ > 1; |
| 873 | } |
| 874 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 875 | // Creates a Texture for the given texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 876 | TextureRef* CreateTexture( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 877 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 878 | return texture_manager()->CreateTexture(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | // Gets the texture info for the given texture. Returns NULL if none exists. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 882 | TextureRef* GetTexture(GLuint client_id) const { |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 883 | return texture_manager()->GetTexture(client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | // Deletes the texture info for the given texture. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 887 | void RemoveTexture(GLuint client_id) { |
| 888 | texture_manager()->RemoveTexture(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 889 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 890 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 891 | // Get the size (in pixels) of the currently bound frame buffer (either FBO |
| 892 | // or regular back buffer). |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 893 | gfx::Size GetBoundReadFrameBufferSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 894 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 895 | // Get the format of the currently bound frame buffer (either FBO or regular |
| 896 | // back buffer) |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 897 | GLenum GetBoundReadFrameBufferTextureType(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 898 | GLenum GetBoundReadFrameBufferInternalFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 899 | GLenum GetBoundDrawFrameBufferInternalFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 900 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 901 | // Wrapper for CompressedTexImage2D commands. |
| 902 | error::Error DoCompressedTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 903 | GLenum target, |
| 904 | GLint level, |
| 905 | GLenum internal_format, |
| 906 | GLsizei width, |
| 907 | GLsizei height, |
| 908 | GLint border, |
| 909 | GLsizei image_size, |
| 910 | const void* data); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 911 | |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 912 | // Wrapper for CompressedTexImage3D commands. |
| 913 | error::Error DoCompressedTexImage3D( |
| 914 | GLenum target, |
| 915 | GLint level, |
| 916 | GLenum internal_format, |
| 917 | GLsizei width, |
| 918 | GLsizei height, |
| 919 | GLsizei depth, |
| 920 | GLint border, |
| 921 | GLsizei image_size, |
| 922 | const void* data); |
| 923 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 924 | // Wrapper for CompressedTexSubImage2D. |
| 925 | void DoCompressedTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 926 | GLenum target, |
| 927 | GLint level, |
| 928 | GLint xoffset, |
| 929 | GLint yoffset, |
| 930 | GLsizei width, |
| 931 | GLsizei height, |
| 932 | GLenum format, |
| 933 | GLsizei imageSize, |
| 934 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 935 | |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 936 | // Wrapper for CompressedTexSubImage3D. |
| 937 | void DoCompressedTexSubImage3D( |
| 938 | GLenum target, |
| 939 | GLint level, |
| 940 | GLint xoffset, |
| 941 | GLint yoffset, |
| 942 | GLint zoffset, |
| 943 | GLsizei width, |
| 944 | GLsizei height, |
| 945 | GLsizei depth, |
| 946 | GLenum format, |
| 947 | GLsizei image_size, |
| 948 | const void* data); |
| 949 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 950 | // Wrapper for CopyTexImage2D. |
| 951 | void DoCopyTexImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 952 | GLenum target, |
| 953 | GLint level, |
| 954 | GLenum internal_format, |
| 955 | GLint x, |
| 956 | GLint y, |
| 957 | GLsizei width, |
| 958 | GLsizei height, |
| 959 | GLint border); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 960 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 961 | // Wrapper for SwapBuffers. |
| 962 | void DoSwapBuffers(); |
| 963 | |
bajones | 2345c1f | 2014-12-09 04:45:51 | [diff] [blame] | 964 | // Wrapper for SwapInterval. |
| 965 | void DoSwapInterval(int interval); |
| 966 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 967 | // Wrapper for CopyTexSubImage2D. |
| 968 | void DoCopyTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 969 | GLenum target, |
| 970 | GLint level, |
| 971 | GLint xoffset, |
| 972 | GLint yoffset, |
| 973 | GLint x, |
| 974 | GLint y, |
| 975 | GLsizei width, |
| 976 | GLsizei height); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 977 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 978 | // Validation for TexSubImage2D. |
| 979 | bool ValidateTexSubImage2D( |
| 980 | error::Error* error, |
| 981 | const char* function_name, |
| 982 | GLenum target, |
| 983 | GLint level, |
| 984 | GLint xoffset, |
| 985 | GLint yoffset, |
| 986 | GLsizei width, |
| 987 | GLsizei height, |
| 988 | GLenum format, |
| 989 | GLenum type, |
| 990 | const void * data); |
| 991 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 992 | // Wrapper for TexSubImage2D. |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 993 | error::Error DoTexSubImage2D( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 994 | GLenum target, |
| 995 | GLint level, |
| 996 | GLint xoffset, |
| 997 | GLint yoffset, |
| 998 | GLsizei width, |
| 999 | GLsizei height, |
| 1000 | GLenum format, |
| 1001 | GLenum type, |
| 1002 | const void * data); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 1003 | |
zmo | de7b438 | 2015-05-21 21:23:00 | [diff] [blame] | 1004 | // Wrapper for TexSubImage3D. |
| 1005 | error::Error DoTexSubImage3D( |
| 1006 | GLenum target, |
| 1007 | GLint level, |
| 1008 | GLint xoffset, |
| 1009 | GLint yoffset, |
| 1010 | GLint zoffset, |
| 1011 | GLsizei width, |
| 1012 | GLsizei height, |
| 1013 | GLsizei depth, |
| 1014 | GLenum format, |
| 1015 | GLenum type, |
| 1016 | const void * data); |
| 1017 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 1018 | // Extra validation for async tex(Sub)Image2D. |
| 1019 | bool ValidateAsyncTransfer( |
| 1020 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 1021 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 1022 | GLenum target, |
| 1023 | GLint level, |
| 1024 | const void * data); |
| 1025 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1026 | // Wrapper for TexImageIOSurface2DCHROMIUM. |
| 1027 | void DoTexImageIOSurface2DCHROMIUM( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 1028 | GLenum target, |
| 1029 | GLsizei width, |
| 1030 | GLsizei height, |
| 1031 | GLuint io_surface_id, |
| 1032 | GLuint plane); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1033 | |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 1034 | void DoCopyTextureCHROMIUM(GLenum target, |
| 1035 | GLuint source_id, |
| 1036 | GLuint dest_id, |
| 1037 | GLenum internal_format, |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 1038 | GLenum dest_type, |
| 1039 | GLboolean unpack_flip_y, |
| 1040 | GLboolean unpack_premultiply_alpha, |
| 1041 | GLboolean unpack_unmultiply_alpha); |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 1042 | |
| 1043 | void DoCopySubTextureCHROMIUM(GLenum target, |
| 1044 | GLuint source_id, |
| 1045 | GLuint dest_id, |
| 1046 | GLint xoffset, |
reveman | b6643fb0 | 2015-05-26 06:05:34 | [diff] [blame] | 1047 | GLint yoffset, |
| 1048 | GLint x, |
| 1049 | GLint y, |
| 1050 | GLsizei width, |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 1051 | GLsizei height, |
| 1052 | GLboolean unpack_flip_y, |
| 1053 | GLboolean unpack_premultiply_alpha, |
| 1054 | GLboolean unpack_unmultiply_alpha); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1055 | |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 1056 | void DoCompressedCopyTextureCHROMIUM(GLenum target, |
| 1057 | GLuint source_id, |
| 1058 | GLuint dest_id); |
| 1059 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 1060 | // Wrapper for TexStorage2DEXT. |
| 1061 | void DoTexStorage2DEXT( |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 1062 | GLenum target, |
| 1063 | GLint levels, |
| 1064 | GLenum internal_format, |
| 1065 | GLsizei width, |
| 1066 | GLsizei height); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 1067 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 1068 | void DoProduceTextureCHROMIUM(GLenum target, const GLbyte* key); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 1069 | void DoProduceTextureDirectCHROMIUM(GLuint texture, GLenum target, |
| 1070 | const GLbyte* key); |
| 1071 | void ProduceTextureRef(std::string func_name, TextureRef* texture_ref, |
| 1072 | GLenum target, const GLbyte* data); |
| 1073 | |
bajones | d8388be0 | 2015-04-04 00:15:43 | [diff] [blame] | 1074 | void EnsureTextureForClientId(GLenum target, GLuint client_id); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 1075 | void DoConsumeTextureCHROMIUM(GLenum target, const GLbyte* key); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 1076 | void DoCreateAndConsumeTextureCHROMIUM(GLenum target, const GLbyte* key, |
| 1077 | GLuint client_id); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 1078 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 1079 | bool DoIsValuebufferCHROMIUM(GLuint client_id); |
| 1080 | void DoBindValueBufferCHROMIUM(GLenum target, GLuint valuebuffer); |
| 1081 | void DoSubscribeValueCHROMIUM(GLenum target, GLenum subscription); |
| 1082 | void DoPopulateSubscribedValuesCHROMIUM(GLenum target); |
| 1083 | void DoUniformValueBufferCHROMIUM(GLint location, |
| 1084 | GLenum target, |
| 1085 | GLenum subscription); |
| 1086 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 1087 | void DoBindTexImage2DCHROMIUM( |
| 1088 | GLenum target, |
| 1089 | GLint image_id); |
| 1090 | void DoReleaseTexImage2DCHROMIUM( |
| 1091 | GLenum target, |
| 1092 | GLint image_id); |
| 1093 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 1094 | void DoTraceEndCHROMIUM(void); |
| 1095 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 1096 | void DoDrawBuffersEXT(GLsizei count, const GLenum* bufs); |
| 1097 | |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 1098 | void DoLoseContextCHROMIUM(GLenum current, GLenum other); |
| 1099 | |
kkinnunen | 337d5963 | 2014-08-26 10:19:57 | [diff] [blame] | 1100 | void DoMatrixLoadfCHROMIUM(GLenum matrix_mode, const GLfloat* matrix); |
| 1101 | void DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode); |
| 1102 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1103 | // Creates a Program for the given program. |
| 1104 | Program* CreateProgram( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 1105 | GLuint client_id, GLuint service_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1106 | return program_manager()->CreateProgram(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1107 | } |
| 1108 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1109 | // Gets the program info for the given program. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1110 | Program* GetProgram(GLuint client_id) { |
| 1111 | return program_manager()->GetProgram(client_id); |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 1112 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1113 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1114 | #if defined(NDEBUG) |
| 1115 | void LogClientServiceMapping( |
| 1116 | const char* /* function_name */, |
| 1117 | GLuint /* client_id */, |
| 1118 | GLuint /* service_id */) { |
| 1119 | } |
| 1120 | template<typename T> |
| 1121 | void LogClientServiceForInfo( |
| 1122 | T* /* info */, GLuint /* client_id */, const char* /* function_name */) { |
| 1123 | } |
| 1124 | #else |
| 1125 | void LogClientServiceMapping( |
| 1126 | const char* function_name, GLuint client_id, GLuint service_id) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 1127 | if (service_logging_) { |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 1128 | VLOG(1) << "[" << logger_.GetLogPrefix() << "] " << function_name |
| 1129 | << ": client_id = " << client_id |
| 1130 | << ", service_id = " << service_id; |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 1131 | } |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1132 | } |
| 1133 | template<typename T> |
| 1134 | void LogClientServiceForInfo( |
| 1135 | T* info, GLuint client_id, const char* function_name) { |
[email protected] | 2a22fe7 | 2012-12-07 04:21:26 | [diff] [blame] | 1136 | if (info) { |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 1137 | LogClientServiceMapping(function_name, client_id, info->service_id()); |
| 1138 | } |
| 1139 | } |
| 1140 | #endif |
| 1141 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1142 | // Gets the program info for the given program. If it's not a program |
| 1143 | // generates a GL error. Returns NULL if not program. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1144 | Program* GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1145 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1146 | Program* program = GetProgram(client_id); |
| 1147 | if (!program) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1148 | if (GetShader(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1149 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1150 | GL_INVALID_OPERATION, function_name, "shader passed for program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1151 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1152 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown program"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1153 | } |
| 1154 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1155 | LogClientServiceForInfo(program, client_id, function_name); |
| 1156 | return program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1160 | // Creates a Shader for the given shader. |
| 1161 | Shader* CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 1162 | GLuint client_id, |
| 1163 | GLuint service_id, |
| 1164 | GLenum shader_type) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1165 | return shader_manager()->CreateShader( |
[email protected] | d685a68 | 2011-04-29 16:19:57 | [diff] [blame] | 1166 | client_id, service_id, shader_type); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | // Gets the shader info for the given shader. Returns NULL if none exists. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1170 | Shader* GetShader(GLuint client_id) { |
| 1171 | return shader_manager()->GetShader(client_id); |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1172 | } |
| 1173 | |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1174 | // Gets the shader info for the given shader. If it's not a shader generates a |
| 1175 | // GL error. Returns NULL if not shader. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1176 | Shader* GetShaderInfoNotProgram( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1177 | GLuint client_id, const char* function_name) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1178 | Shader* shader = GetShader(client_id); |
| 1179 | if (!shader) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1180 | if (GetProgram(client_id)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1181 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1182 | GL_INVALID_OPERATION, function_name, "program passed for shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1183 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1184 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1185 | GL_INVALID_VALUE, function_name, "unknown shader"); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1186 | } |
| 1187 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 1188 | LogClientServiceForInfo(shader, client_id, function_name); |
| 1189 | return shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 1190 | } |
| 1191 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1192 | // Creates a buffer info for the given buffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1193 | void CreateBuffer(GLuint client_id, GLuint service_id) { |
| 1194 | return buffer_manager()->CreateBuffer(client_id, service_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1195 | } |
| 1196 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1197 | // Gets the buffer info for the given buffer. |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 1198 | Buffer* GetBuffer(GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 1199 | Buffer* buffer = buffer_manager()->GetBuffer(client_id); |
| 1200 | return buffer; |
[email protected] | 1d32bc8 | 2010-01-13 22:06:46 | [diff] [blame] | 1201 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1202 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1203 | // Removes any buffers in the VertexAtrribInfos and BufferInfos. This is used |
| 1204 | // on glDeleteBuffers so we can make sure the user does not try to render |
| 1205 | // with deleted buffers. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1206 | void RemoveBuffer(GLuint client_id); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1207 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1208 | // Creates a framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1209 | void CreateFramebuffer(GLuint client_id, GLuint service_id) { |
| 1210 | return framebuffer_manager()->CreateFramebuffer(client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | // Gets the framebuffer info for the given framebuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1214 | Framebuffer* GetFramebuffer(GLuint client_id) { |
| 1215 | return framebuffer_manager()->GetFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | // Removes the framebuffer info for the given framebuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1219 | void RemoveFramebuffer(GLuint client_id) { |
| 1220 | framebuffer_manager()->RemoveFramebuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | // Creates a renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1224 | void CreateRenderbuffer(GLuint client_id, GLuint service_id) { |
| 1225 | return renderbuffer_manager()->CreateRenderbuffer( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1226 | client_id, service_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | // Gets the renderbuffer info for the given renderbuffer. |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1230 | Renderbuffer* GetRenderbuffer(GLuint client_id) { |
| 1231 | return renderbuffer_manager()->GetRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | // Removes the renderbuffer info for the given renderbuffer. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1235 | void RemoveRenderbuffer(GLuint client_id) { |
| 1236 | renderbuffer_manager()->RemoveRenderbuffer(client_id); |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 1237 | } |
| 1238 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 1239 | // Creates a valuebuffer info for the given valuebuffer. |
| 1240 | void CreateValuebuffer(GLuint client_id) { |
| 1241 | return valuebuffer_manager()->CreateValuebuffer(client_id); |
| 1242 | } |
| 1243 | |
| 1244 | // Gets the valuebuffer info for a given valuebuffer. |
| 1245 | Valuebuffer* GetValuebuffer(GLuint client_id) { |
| 1246 | return valuebuffer_manager()->GetValuebuffer(client_id); |
| 1247 | } |
| 1248 | |
| 1249 | // Removes the valuebuffer info for the given valuebuffer. |
| 1250 | void RemoveValuebuffer(GLuint client_id) { |
| 1251 | valuebuffer_manager()->RemoveValuebuffer(client_id); |
| 1252 | } |
| 1253 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1254 | // Gets the vertex attrib manager for the given vertex array. |
| 1255 | VertexAttribManager* GetVertexAttribManager(GLuint client_id) { |
| 1256 | VertexAttribManager* info = |
| 1257 | vertex_array_manager()->GetVertexAttribManager(client_id); |
| 1258 | return info; |
| 1259 | } |
| 1260 | |
| 1261 | // Removes the vertex attrib manager for the given vertex array. |
| 1262 | void RemoveVertexAttribManager(GLuint client_id) { |
| 1263 | vertex_array_manager()->RemoveVertexAttribManager(client_id); |
| 1264 | } |
| 1265 | |
| 1266 | // Creates a vertex attrib manager for the given vertex array. |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 1267 | scoped_refptr<VertexAttribManager> CreateVertexAttribManager( |
| 1268 | GLuint client_id, |
| 1269 | GLuint service_id, |
| 1270 | bool client_visible) { |
| 1271 | return vertex_array_manager()->CreateVertexAttribManager( |
| 1272 | client_id, service_id, group_->max_vertex_attribs(), client_visible); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1273 | } |
| 1274 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1275 | void DoBindAttribLocation(GLuint client_id, GLuint index, const char* name); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 1276 | void DoBindUniformLocationCHROMIUM( |
| 1277 | GLuint client_id, GLint location, const char* name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 1278 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 1279 | error::Error GetAttribLocationHelper( |
zmo | 4a16ff99 | 2015-02-05 22:18:41 | [diff] [blame] | 1280 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1281 | const std::string& name_str); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 1282 | |
| 1283 | error::Error GetUniformLocationHelper( |
zmo | 4a16ff99 | 2015-02-05 22:18:41 | [diff] [blame] | 1284 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1285 | const std::string& name_str); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 1286 | |
zmo | 5393fb5 | 2015-01-27 01:50:48 | [diff] [blame] | 1287 | error::Error GetFragDataLocationHelper( |
zmo | 4a16ff99 | 2015-02-05 22:18:41 | [diff] [blame] | 1288 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 1289 | const std::string& name_str); |
zmo | 5393fb5 | 2015-01-27 01:50:48 | [diff] [blame] | 1290 | |
zmo | 1bb3d1d | 2015-01-21 20:29:43 | [diff] [blame] | 1291 | // Wrapper for glShaderSource. |
| 1292 | void DoShaderSource( |
| 1293 | GLuint client_id, GLsizei count, const char** data, const GLint* length); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1294 | |
zmo | 3892356 | 2015-01-29 20:17:39 | [diff] [blame] | 1295 | // Wrapper for glTransformFeedbackVaryings. |
| 1296 | void DoTransformFeedbackVaryings( |
| 1297 | GLuint client_program_id, GLsizei count, const char* const* varyings, |
| 1298 | GLenum buffer_mode); |
| 1299 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1300 | // Clear any textures used by the current program. |
| 1301 | bool ClearUnclearedTextures(); |
| 1302 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1303 | // Clears any uncleared attachments attached to the given frame buffer. |
| 1304 | // Returns false if there was a generated GL error. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1305 | void ClearUnclearedAttachments(GLenum target, Framebuffer* framebuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1306 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1307 | // overridden from GLES2Decoder |
boliu | 45dc77a | 2015-02-25 23:26:31 | [diff] [blame] | 1308 | bool ClearLevel(Texture* texture, |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 1309 | unsigned target, |
| 1310 | int level, |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 1311 | unsigned format, |
| 1312 | unsigned type, |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 1313 | int xoffset, |
| 1314 | int yoffset, |
dcheng | 1f4d1d7 | 2014-10-21 16:21:58 | [diff] [blame] | 1315 | int width, |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 1316 | int height) override; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1317 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 1318 | // Restore all GL state that affects clearing. |
| 1319 | void RestoreClearState(); |
| 1320 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1321 | // Remembers the state of some capabilities. |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1322 | // Returns: true if glEnable/glDisable should actually be called. |
| 1323 | bool SetCapabilityState(GLenum cap, bool enabled); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1324 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1325 | // Check that the currently bound framebuffers are valid. |
| 1326 | // Generates GL error if not. |
| 1327 | bool CheckBoundFramebuffersValid(const char* func_name); |
| 1328 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 1329 | // Check that the currently bound read framebuffer has a color image |
| 1330 | // attached. Generates GL error if not. |
| 1331 | bool CheckBoundReadFramebufferColorAttachment(const char* func_name); |
| 1332 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 1333 | // Check that the currently bound read framebuffer's color image |
| 1334 | // isn't the target texture of the glCopyTex{Sub}Image2D. |
| 1335 | bool FormsTextureCopyingFeedbackLoop(TextureRef* texture, GLint level); |
| 1336 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1337 | // Check if a framebuffer meets our requirements. |
| 1338 | bool CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1339 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1340 | GLenum target, |
| 1341 | const char* func_name); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1342 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 1343 | // Check if the current valuebuffer exists and is valid. If not generates |
| 1344 | // the appropriate GL error. Returns true if the current valuebuffer is in |
| 1345 | // a usable state. |
| 1346 | bool CheckCurrentValuebuffer(const char* function_name); |
| 1347 | |
| 1348 | // Check if the current valuebuffer exists and is valiud and that the |
| 1349 | // value buffer is actually subscribed to the given subscription |
| 1350 | bool CheckCurrentValuebufferForSubscription(GLenum subscription, |
| 1351 | const char* function_name); |
| 1352 | |
| 1353 | // Check if the location can be used for the given subscription target. If not |
| 1354 | // generates the appropriate GL error. Returns true if the location is usable |
| 1355 | bool CheckSubscriptionTarget(GLint location, |
| 1356 | GLenum subscription, |
| 1357 | const char* function_name); |
| 1358 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1359 | // Checks if the current program exists and is valid. If not generates the |
| 1360 | // appropriate GL error. Returns true if the current program is in a usable |
| 1361 | // state. |
| 1362 | bool CheckCurrentProgram(const char* function_name); |
| 1363 | |
| 1364 | // Checks if the current program exists and is valid and that location is not |
| 1365 | // -1. If the current program is not valid generates the appropriate GL |
| 1366 | // error. Returns true if the current program is in a usable state and |
| 1367 | // location is not -1. |
| 1368 | bool CheckCurrentProgramForUniform(GLint location, const char* function_name); |
| 1369 | |
zmo | f9a81360f | 2014-10-17 00:06:14 | [diff] [blame] | 1370 | // Checks if the current program samples a texture that is also the color |
| 1371 | // image of the current bound framebuffer, i.e., the source and destination |
| 1372 | // of the draw operation are the same. |
| 1373 | bool CheckDrawingFeedbackLoops(); |
| 1374 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 1375 | // Checks if |api_type| is valid for the given uniform |
| 1376 | // If the api type is not valid generates the appropriate GL |
| 1377 | // error. Returns true if |api_type| is valid for the uniform |
| 1378 | bool CheckUniformForApiType(const Program::UniformInfo* info, |
| 1379 | const char* function_name, |
| 1380 | Program::UniformApiType api_type); |
| 1381 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1382 | // Gets the type of a uniform for a location in the current program. Sets GL |
| 1383 | // errors if the current program is not valid. Returns true if the current |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1384 | // program is valid and the location exists. Adjusts count so it |
| 1385 | // does not overflow the uniform. |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 1386 | bool PrepForSetUniformByLocation(GLint fake_location, |
| 1387 | const char* function_name, |
| 1388 | Program::UniformApiType api_type, |
| 1389 | GLint* real_location, |
| 1390 | GLenum* type, |
| 1391 | GLsizei* count); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1392 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1393 | // Gets the service id for any simulated backbuffer fbo. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 1394 | GLuint GetBackbufferServiceId() const; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 1395 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1396 | // Helper for glGetBooleanv, glGetFloatv and glGetIntegerv |
| 1397 | bool GetHelper(GLenum pname, GLint* params, GLsizei* num_written); |
| 1398 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 1399 | // Helper for glGetVertexAttrib |
| 1400 | void GetVertexAttribHelper( |
| 1401 | const VertexAttrib* attrib, GLenum pname, GLint* param); |
| 1402 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1403 | // Wrapper for glActiveTexture |
| 1404 | void DoActiveTexture(GLenum texture_unit); |
| 1405 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1406 | // Wrapper for glAttachShader |
| 1407 | void DoAttachShader(GLuint client_program_id, GLint client_shader_id); |
| 1408 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1409 | // Wrapper for glBindBuffer since we need to track the current targets. |
| 1410 | void DoBindBuffer(GLenum target, GLuint buffer); |
| 1411 | |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 1412 | // Wrapper for glBindFramebuffer since we need to track the current targets. |
| 1413 | void DoBindFramebuffer(GLenum target, GLuint framebuffer); |
| 1414 | |
| 1415 | // Wrapper for glBindRenderbuffer since we need to track the current targets. |
| 1416 | void DoBindRenderbuffer(GLenum target, GLuint renderbuffer); |
| 1417 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1418 | // Wrapper for glBindTexture since we need to track the current targets. |
| 1419 | void DoBindTexture(GLenum target, GLuint texture); |
| 1420 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1421 | // Wrapper for glBindVertexArrayOES |
| 1422 | void DoBindVertexArrayOES(GLuint array); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 1423 | void EmulateVertexArrayState(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1424 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1425 | // Wrapper for glBlitFramebufferCHROMIUM. |
| 1426 | void DoBlitFramebufferCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1427 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 1428 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 1429 | GLbitfield mask, GLenum filter); |
| 1430 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1431 | // Wrapper for glBufferSubData. |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 1432 | void DoBufferSubData( |
| 1433 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data); |
| 1434 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1435 | // Wrapper for glCheckFramebufferStatus |
| 1436 | GLenum DoCheckFramebufferStatus(GLenum target); |
| 1437 | |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1438 | // Wrapper for glClear |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1439 | error::Error DoClear(GLbitfield mask); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 1440 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1441 | // Wrappers for various state. |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 1442 | void DoDepthRangef(GLclampf znear, GLclampf zfar); |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 1443 | void DoSampleCoverage(GLclampf value, GLboolean invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1444 | |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 1445 | // Wrapper for glCompileShader. |
| 1446 | void DoCompileShader(GLuint shader); |
| 1447 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1448 | // Wrapper for glDetachShader |
| 1449 | void DoDetachShader(GLuint client_program_id, GLint client_shader_id); |
| 1450 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1451 | // Wrapper for glDisable |
| 1452 | void DoDisable(GLenum cap); |
| 1453 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1454 | // Wrapper for glDisableVertexAttribArray. |
| 1455 | void DoDisableVertexAttribArray(GLuint index); |
| 1456 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1457 | // Wrapper for glDiscardFramebufferEXT, since we need to track undefined |
| 1458 | // attachments. |
| 1459 | void DoDiscardFramebufferEXT(GLenum target, |
| 1460 | GLsizei numAttachments, |
| 1461 | const GLenum* attachments); |
| 1462 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 1463 | // Wrapper for glEnable |
| 1464 | void DoEnable(GLenum cap); |
| 1465 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1466 | // Wrapper for glEnableVertexAttribArray. |
| 1467 | void DoEnableVertexAttribArray(GLuint index); |
| 1468 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1469 | // Wrapper for glFinish. |
| 1470 | void DoFinish(); |
| 1471 | |
| 1472 | // Wrapper for glFlush. |
| 1473 | void DoFlush(); |
| 1474 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1475 | // Wrapper for glFramebufferRenderbufffer. |
| 1476 | void DoFramebufferRenderbuffer( |
| 1477 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
| 1478 | GLuint renderbuffer); |
| 1479 | |
| 1480 | // Wrapper for glFramebufferTexture2D. |
| 1481 | void DoFramebufferTexture2D( |
| 1482 | GLenum target, GLenum attachment, GLenum textarget, GLuint texture, |
| 1483 | GLint level); |
| 1484 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1485 | // Wrapper for glFramebufferTexture2DMultisampleEXT. |
| 1486 | void DoFramebufferTexture2DMultisample( |
| 1487 | GLenum target, GLenum attachment, GLenum textarget, |
| 1488 | GLuint texture, GLint level, GLsizei samples); |
| 1489 | |
| 1490 | // Common implementation for both DoFramebufferTexture2D wrappers. |
| 1491 | void DoFramebufferTexture2DCommon(const char* name, |
| 1492 | GLenum target, GLenum attachment, GLenum textarget, |
| 1493 | GLuint texture, GLint level, GLsizei samples); |
| 1494 | |
zmo | 84c0820 | 2014-11-23 15:28:40 | [diff] [blame] | 1495 | // Wrapper for glFramebufferTextureLayer. |
| 1496 | void DoFramebufferTextureLayer( |
| 1497 | GLenum target, GLenum attachment, GLuint texture, GLint level, |
| 1498 | GLint layer); |
| 1499 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 1500 | // Wrapper for glGenerateMipmap |
| 1501 | void DoGenerateMipmap(GLenum target); |
| 1502 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 1503 | // Helper for DoGetBooleanv, Floatv, and Intergerv to adjust pname |
| 1504 | // to account for different pname values defined in different extension |
| 1505 | // variants. |
| 1506 | GLenum AdjustGetPname(GLenum pname); |
| 1507 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1508 | // Wrapper for DoGetBooleanv. |
| 1509 | void DoGetBooleanv(GLenum pname, GLboolean* params); |
| 1510 | |
| 1511 | // Wrapper for DoGetFloatv. |
| 1512 | void DoGetFloatv(GLenum pname, GLfloat* params); |
| 1513 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1514 | // Wrapper for glGetFramebufferAttachmentParameteriv. |
| 1515 | void DoGetFramebufferAttachmentParameteriv( |
| 1516 | GLenum target, GLenum attachment, GLenum pname, GLint* params); |
| 1517 | |
zmo | 8ac3bab | 2015-04-18 02:30:58 | [diff] [blame] | 1518 | // Wrapper for glGetInteger64v. |
| 1519 | void DoGetInteger64v(GLenum pname, GLint64* params); |
| 1520 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1521 | // Wrapper for glGetIntegerv. |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1522 | void DoGetIntegerv(GLenum pname, GLint* params); |
| 1523 | |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1524 | // Gets the max value in a range in a buffer. |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 1525 | GLuint DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 1526 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset); |
| 1527 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 1528 | // Wrapper for glGetBufferParameteriv. |
| 1529 | void DoGetBufferParameteriv( |
| 1530 | GLenum target, GLenum pname, GLint* params); |
| 1531 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 1532 | // Wrapper for glGetProgramiv. |
| 1533 | void DoGetProgramiv( |
| 1534 | GLuint program_id, GLenum pname, GLint* params); |
| 1535 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1536 | // Wrapper for glRenderbufferParameteriv. |
| 1537 | void DoGetRenderbufferParameteriv( |
| 1538 | GLenum target, GLenum pname, GLint* params); |
| 1539 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 1540 | // Wrapper for glGetShaderiv |
| 1541 | void DoGetShaderiv(GLuint shader, GLenum pname, GLint* params); |
| 1542 | |
[email protected] | 4c6f546 | 2014-03-05 00:26:56 | [diff] [blame] | 1543 | // Wrappers for glGetTexParameter. |
| 1544 | void DoGetTexParameterfv(GLenum target, GLenum pname, GLfloat* params); |
| 1545 | void DoGetTexParameteriv(GLenum target, GLenum pname, GLint* params); |
| 1546 | void InitTextureMaxAnisotropyIfNeeded(GLenum target, GLenum pname); |
| 1547 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1548 | // Wrappers for glGetVertexAttrib. |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 1549 | template <typename T> |
| 1550 | void DoGetVertexAttribImpl(GLuint index, GLenum pname, T* params); |
| 1551 | void DoGetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params); |
| 1552 | void DoGetVertexAttribiv(GLuint index, GLenum pname, GLint* params); |
| 1553 | void DoGetVertexAttribIiv(GLuint index, GLenum pname, GLint* params); |
| 1554 | void DoGetVertexAttribIuiv(GLuint index, GLenum pname, GLuint* params); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1555 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1556 | // Wrappers for glIsXXX functions. |
[email protected] | 3dc69c4 | 2012-05-12 02:29:24 | [diff] [blame] | 1557 | bool DoIsEnabled(GLenum cap); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1558 | bool DoIsBuffer(GLuint client_id); |
| 1559 | bool DoIsFramebuffer(GLuint client_id); |
| 1560 | bool DoIsProgram(GLuint client_id); |
| 1561 | bool DoIsRenderbuffer(GLuint client_id); |
| 1562 | bool DoIsShader(GLuint client_id); |
| 1563 | bool DoIsTexture(GLuint client_id); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1564 | bool DoIsVertexArrayOES(GLuint client_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 1565 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1566 | // Wrapper for glLinkProgram |
| 1567 | void DoLinkProgram(GLuint program); |
| 1568 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1569 | // Wrapper for glRenderbufferStorage. |
| 1570 | void DoRenderbufferStorage( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1571 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 1572 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1573 | // Handler for glRenderbufferStorageMultisampleCHROMIUM. |
| 1574 | void DoRenderbufferStorageMultisampleCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1575 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1576 | GLsizei width, GLsizei height); |
| 1577 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 1578 | // Handler for glRenderbufferStorageMultisampleEXT |
| 1579 | // (multisampled_render_to_texture). |
| 1580 | void DoRenderbufferStorageMultisampleEXT( |
| 1581 | GLenum target, GLsizei samples, GLenum internalformat, |
| 1582 | GLsizei width, GLsizei height); |
| 1583 | |
| 1584 | // Common validation for multisample extensions. |
| 1585 | bool ValidateRenderbufferStorageMultisample(GLsizei samples, |
| 1586 | GLenum internalformat, |
| 1587 | GLsizei width, |
| 1588 | GLsizei height); |
| 1589 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 1590 | // Verifies that the currently bound multisample renderbuffer is valid |
| 1591 | // Very slow! Only done on platforms with driver bugs that return invalid |
| 1592 | // buffers under memory pressure |
| 1593 | bool VerifyMultisampleRenderbufferIntegrity( |
| 1594 | GLuint renderbuffer, GLenum format); |
| 1595 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 1596 | // Wrapper for glReleaseShaderCompiler. |
| 1597 | void DoReleaseShaderCompiler() { } |
| 1598 | |
zmo | bcb3fdd6 | 2014-12-11 00:49:03 | [diff] [blame] | 1599 | // Wrappers for glSamplerParameter*v functions. |
| 1600 | void DoSamplerParameterfv( |
| 1601 | GLuint sampler, GLenum pname, const GLfloat* params); |
| 1602 | void DoSamplerParameteriv(GLuint sampler, GLenum pname, const GLint* params); |
| 1603 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1604 | // Wrappers for glTexParameter functions. |
| 1605 | void DoTexParameterf(GLenum target, GLenum pname, GLfloat param); |
| 1606 | void DoTexParameteri(GLenum target, GLenum pname, GLint param); |
| 1607 | void DoTexParameterfv(GLenum target, GLenum pname, const GLfloat* params); |
| 1608 | void DoTexParameteriv(GLenum target, GLenum pname, const GLint* params); |
| 1609 | |
| 1610 | // Wrappers for glUniform1i and glUniform1iv as according to the GLES2 |
| 1611 | // spec only these 2 functions can be used to set sampler uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1612 | void DoUniform1i(GLint fake_location, GLint v0); |
| 1613 | void DoUniform1iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1614 | void DoUniform2iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1615 | void DoUniform3iv(GLint fake_location, GLsizei count, const GLint* value); |
| 1616 | void DoUniform4iv(GLint fake_location, GLsizei count, const GLint* value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 1617 | |
| 1618 | // Wrappers for glUniformfv because some drivers don't correctly accept |
| 1619 | // bool uniforms. |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1620 | void DoUniform1fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1621 | void DoUniform2fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1622 | void DoUniform3fv(GLint fake_location, GLsizei count, const GLfloat* value); |
| 1623 | void DoUniform4fv(GLint fake_location, GLsizei count, const GLfloat* value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1624 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1625 | void DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1626 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1627 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1628 | void DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1629 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1630 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1631 | void DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 1632 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 1633 | const GLfloat* value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 1634 | |
zmo | 143c51a | 2015-05-15 03:04:07 | [diff] [blame] | 1635 | template <typename T> |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1636 | bool SetVertexAttribValue( |
zmo | 143c51a | 2015-05-15 03:04:07 | [diff] [blame] | 1637 | const char* function_name, GLuint index, const T* value); |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1638 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1639 | // Wrappers for glVertexAttrib?? |
| 1640 | void DoVertexAttrib1f(GLuint index, GLfloat v0); |
| 1641 | void DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1); |
| 1642 | void DoVertexAttrib3f(GLuint index, GLfloat v0, GLfloat v1, GLfloat v2); |
| 1643 | void DoVertexAttrib4f( |
| 1644 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3); |
zmo | 143c51a | 2015-05-15 03:04:07 | [diff] [blame] | 1645 | void DoVertexAttrib1fv(GLuint index, const GLfloat* v); |
| 1646 | void DoVertexAttrib2fv(GLuint index, const GLfloat* v); |
| 1647 | void DoVertexAttrib3fv(GLuint index, const GLfloat* v); |
| 1648 | void DoVertexAttrib4fv(GLuint index, const GLfloat* v); |
| 1649 | void DoVertexAttribI4i(GLuint index, GLint v0, GLint v1, GLint v2, GLint v3); |
| 1650 | void DoVertexAttribI4iv(GLuint index, const GLint* v); |
| 1651 | void DoVertexAttribI4ui( |
| 1652 | GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3); |
| 1653 | void DoVertexAttribI4uiv(GLuint index, const GLuint* v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1654 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 1655 | // Wrapper for glViewport |
| 1656 | void DoViewport(GLint x, GLint y, GLsizei width, GLsizei height); |
| 1657 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1658 | // Wrapper for glUseProgram |
| 1659 | void DoUseProgram(GLuint program); |
| 1660 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 1661 | // Wrapper for glValidateProgram. |
| 1662 | void DoValidateProgram(GLuint program_client_id); |
| 1663 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 1664 | void DoInsertEventMarkerEXT(GLsizei length, const GLchar* marker); |
| 1665 | void DoPushGroupMarkerEXT(GLsizei length, const GLchar* group); |
| 1666 | void DoPopGroupMarkerEXT(void); |
| 1667 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 1668 | // Gets the number of values that will be returned by glGetXXX. Returns |
| 1669 | // false if pname is unknown. |
| 1670 | bool GetNumValuesReturnedForGLGet(GLenum pname, GLsizei* num_values); |
| 1671 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1672 | // Checks if the current program and vertex attributes are valid for drawing. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1673 | bool IsDrawValid( |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 1674 | const char* function_name, GLuint max_vertex_accessed, bool instanced, |
| 1675 | GLsizei primcount); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 1676 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 1677 | // Returns true if successful, simulated will be true if attrib0 was |
| 1678 | // simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1679 | bool SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1680 | const char* function_name, GLuint max_vertex_accessed, bool* simulated); |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 1681 | void RestoreStateForAttrib(GLuint attrib, bool restore_array_binding); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1682 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1683 | // If an image is bound to texture, this will call Will/DidUseTexImage |
| 1684 | // if needed. |
| 1685 | void DoWillUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1686 | void DoDidUseTexImageIfNeeded(Texture* texture, GLenum textarget); |
| 1687 | |
| 1688 | // Returns false if textures were replaced. |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 1689 | bool PrepareTexturesForRender(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 1690 | void RestoreStateForTextures(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 1691 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1692 | // Returns true if GL_FIXED attribs were simulated. |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1693 | bool SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1694 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1695 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1696 | void RestoreStateForSimulatedFixedAttribs(); |
| 1697 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1698 | // Handle DrawArrays and DrawElements for both instanced and non-instanced |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 1699 | // cases (primcount is always 1 for non-instanced). |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1700 | error::Error DoDrawArrays( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1701 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1702 | bool instanced, GLenum mode, GLint first, GLsizei count, |
| 1703 | GLsizei primcount); |
| 1704 | error::Error DoDrawElements( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1705 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 1706 | bool instanced, GLenum mode, GLsizei count, GLenum type, |
| 1707 | int32 offset, GLsizei primcount); |
| 1708 | |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1709 | GLenum GetBindTargetForSamplerType(GLenum type) { |
| 1710 | DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1711 | type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); |
| 1712 | switch (type) { |
| 1713 | case GL_SAMPLER_2D: |
| 1714 | return GL_TEXTURE_2D; |
| 1715 | case GL_SAMPLER_CUBE: |
| 1716 | return GL_TEXTURE_CUBE_MAP; |
| 1717 | case GL_SAMPLER_EXTERNAL_OES: |
| 1718 | return GL_TEXTURE_EXTERNAL_OES; |
| 1719 | case GL_SAMPLER_2D_RECT_ARB: |
| 1720 | return GL_TEXTURE_RECTANGLE_ARB; |
| 1721 | } |
| 1722 | |
| 1723 | NOTREACHED(); |
| 1724 | return 0; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 1725 | } |
| 1726 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1727 | // Gets the framebuffer info for a particular target. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1728 | Framebuffer* GetFramebufferInfoForTarget(GLenum target) { |
| 1729 | Framebuffer* framebuffer = NULL; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1730 | switch (target) { |
| 1731 | case GL_FRAMEBUFFER: |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1732 | case GL_DRAW_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1733 | framebuffer = framebuffer_state_.bound_draw_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1734 | break; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 1735 | case GL_READ_FRAMEBUFFER_EXT: |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1736 | framebuffer = framebuffer_state_.bound_read_framebuffer.get(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1737 | break; |
| 1738 | default: |
| 1739 | NOTREACHED(); |
| 1740 | break; |
| 1741 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 1742 | return framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 1743 | } |
| 1744 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1745 | Renderbuffer* GetRenderbufferInfoForTarget( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1746 | GLenum target) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1747 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1748 | switch (target) { |
| 1749 | case GL_RENDERBUFFER: |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 1750 | renderbuffer = state_.bound_renderbuffer.get(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1751 | break; |
| 1752 | default: |
| 1753 | NOTREACHED(); |
| 1754 | break; |
| 1755 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 1756 | return renderbuffer; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 1757 | } |
| 1758 | |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1759 | // Validates the program and location for a glGetUniform call and returns |
| 1760 | // a SizeResult setup to receive the result. Returns true if glGetUniform |
| 1761 | // should be called. |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 1762 | template <class T> |
vmiura | 181c7400 | 2015-03-20 01:32:51 | [diff] [blame] | 1763 | bool GetUniformSetup(GLuint program, |
| 1764 | GLint fake_location, |
| 1765 | uint32 shm_id, |
| 1766 | uint32 shm_offset, |
| 1767 | error::Error* error, |
| 1768 | GLint* real_location, |
| 1769 | GLuint* service_id, |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 1770 | SizedResult<T>** result, |
vmiura | 181c7400 | 2015-03-20 01:32:51 | [diff] [blame] | 1771 | GLenum* result_type, |
| 1772 | GLsizei* result_size); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 1773 | |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 1774 | bool WasContextLost() const override; |
| 1775 | bool WasContextLostByRobustnessExtension() const override; |
| 1776 | void MarkContextLost(error::ContextLostReason reason) override; |
| 1777 | bool CheckResetStatus(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1778 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 1779 | #if defined(OS_MACOSX) |
| 1780 | void ReleaseIOSurfaceForTexture(GLuint texture_id); |
| 1781 | #endif |
| 1782 | |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 1783 | bool GetCompressedTexSizeInBytes( |
| 1784 | const char* function_name, GLsizei width, GLsizei height, GLsizei depth, |
| 1785 | GLenum format, GLsizei* size_in_bytes); |
| 1786 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1787 | bool ValidateCompressedTexDimensions( |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 1788 | const char* function_name, GLenum target, GLint level, |
| 1789 | GLsizei width, GLsizei height, GLsizei depth, GLenum format); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1790 | bool ValidateCompressedTexFuncData( |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 1791 | const char* function_name, GLsizei width, GLsizei height, GLsizei depth, |
| 1792 | GLenum format, GLsizei size); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1793 | bool ValidateCompressedTexSubDimensions( |
| 1794 | const char* function_name, |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 1795 | GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, |
| 1796 | GLsizei width, GLsizei height, GLsizei depth, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1797 | Texture* texture); |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 1798 | bool ValidateCopyTextureCHROMIUM(const char* function_name, |
| 1799 | GLenum target, |
| 1800 | TextureRef* source_texture_ref, |
| 1801 | TextureRef* dest_texture_ref, |
| 1802 | GLenum dest_internal_format); |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 1803 | bool ValidateCompressedCopyTextureCHROMIUM(const char* function_name, |
| 1804 | GLenum target, |
| 1805 | TextureRef* source_texture_ref, |
| 1806 | TextureRef* dest_texture_ref); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 1807 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 1808 | void RenderWarning(const char* filename, int line, const std::string& msg); |
| 1809 | void PerformanceWarning( |
| 1810 | const char* filename, int line, const std::string& msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 1811 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 1812 | const FeatureInfo::FeatureFlags& features() const { |
| 1813 | return feature_info_->feature_flags(); |
| 1814 | } |
| 1815 | |
| 1816 | const FeatureInfo::Workarounds& workarounds() const { |
| 1817 | return feature_info_->workarounds(); |
| 1818 | } |
| 1819 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1820 | bool ShouldDeferDraws() { |
| 1821 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1822 | framebuffer_state_.bound_draw_framebuffer.get() == NULL && |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 1823 | surface_->DeferDraws(); |
| 1824 | } |
| 1825 | |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1826 | bool ShouldDeferReads() { |
| 1827 | return !offscreen_target_frame_buffer_.get() && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 1828 | framebuffer_state_.bound_read_framebuffer.get() == NULL && |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 1829 | surface_->DeferDraws(); |
| 1830 | } |
| 1831 | |
dongseong.hwang | e1cb2aa | 2015-02-11 09:33:33 | [diff] [blame] | 1832 | bool IsRobustnessSupported() { |
| 1833 | return has_robustness_extension_ && |
| 1834 | context_->WasAllocatedUsingRobustnessExtension(); |
| 1835 | } |
| 1836 | |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 1837 | error::Error WillAccessBoundFramebufferForDraw() { |
| 1838 | if (ShouldDeferDraws()) |
| 1839 | return error::kDeferCommandUntilLater; |
| 1840 | if (!offscreen_target_frame_buffer_.get() && |
| 1841 | !framebuffer_state_.bound_draw_framebuffer.get() && |
| 1842 | !surface_->SetBackbufferAllocation(true)) |
| 1843 | return error::kLostContext; |
| 1844 | return error::kNoError; |
| 1845 | } |
| 1846 | |
| 1847 | error::Error WillAccessBoundFramebufferForRead() { |
| 1848 | if (ShouldDeferReads()) |
| 1849 | return error::kDeferCommandUntilLater; |
| 1850 | if (!offscreen_target_frame_buffer_.get() && |
| 1851 | !framebuffer_state_.bound_read_framebuffer.get() && |
| 1852 | !surface_->SetBackbufferAllocation(true)) |
| 1853 | return error::kLostContext; |
| 1854 | return error::kNoError; |
| 1855 | } |
| 1856 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 1857 | // Set remaining commands to process to 0 to force DoCommands to return |
| 1858 | // and allow context preemption and GPU watchdog checks in GpuScheduler(). |
| 1859 | void ExitCommandProcessingEarly() { commands_to_process_ = 0; } |
| 1860 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 1861 | void ProcessPendingReadPixels(); |
| 1862 | void FinishReadPixels(const cmds::ReadPixels& c, GLuint buffer); |
| 1863 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1864 | // Generate a member function prototype for each command in an automated and |
| 1865 | // typesafe way. |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 1866 | #define GLES2_CMD_OP(name) \ |
| 1867 | Error Handle##name(uint32 immediate_data_size, const void* data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1868 | |
| 1869 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 1870 | |
| 1871 | #undef GLES2_CMD_OP |
| 1872 | |
[email protected] | 2f2d704 | 2010-04-14 21:45:58 | [diff] [blame] | 1873 | // The GL context this decoder renders to on behalf of the client. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 1874 | scoped_refptr<gfx::GLSurface> surface_; |
| 1875 | scoped_refptr<gfx::GLContext> context_; |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 1876 | |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1877 | // The ContextGroup for this decoder uses to track resources. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1878 | scoped_refptr<ContextGroup> group_; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 1879 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 1880 | DebugMarkerManager debug_marker_manager_; |
| 1881 | Logger logger_; |
| 1882 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 1883 | // All the state for this context. |
| 1884 | ContextState state_; |
| 1885 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1886 | // Current width and height of the offscreen frame buffer. |
| 1887 | gfx::Size offscreen_size_; |
| 1888 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 1889 | // Util to help with GL. |
| 1890 | GLES2Util util_; |
| 1891 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1892 | // The buffer we bind to attrib 0 since OpenGL requires it (ES does not). |
| 1893 | GLuint attrib_0_buffer_id_; |
| 1894 | |
| 1895 | // The value currently in attrib_0. |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 1896 | Vec4 attrib_0_value_; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1897 | |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 1898 | // Whether or not the attrib_0 buffer holds the attrib_0_value. |
| 1899 | bool attrib_0_buffer_matches_value_; |
| 1900 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 1901 | // The size of attrib 0. |
| 1902 | GLsizei attrib_0_size_; |
| 1903 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 1904 | // The buffer used to simulate GL_FIXED attribs. |
| 1905 | GLuint fixed_attrib_buffer_id_; |
| 1906 | |
| 1907 | // The size of fiixed attrib buffer. |
| 1908 | GLsizei fixed_attrib_buffer_size_; |
| 1909 | |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 1910 | // The offscreen frame buffer that the client renders to. With EGL, the |
| 1911 | // depth and stencil buffers are separate. With regular GL there is a single |
| 1912 | // packed depth stencil buffer in offscreen_target_depth_render_buffer_. |
| 1913 | // offscreen_target_stencil_render_buffer_ is unused. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1914 | scoped_ptr<BackFramebuffer> offscreen_target_frame_buffer_; |
| 1915 | scoped_ptr<BackTexture> offscreen_target_color_texture_; |
| 1916 | scoped_ptr<BackRenderbuffer> offscreen_target_color_render_buffer_; |
| 1917 | scoped_ptr<BackRenderbuffer> offscreen_target_depth_render_buffer_; |
| 1918 | scoped_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 1919 | GLenum offscreen_target_color_format_; |
| 1920 | GLenum offscreen_target_depth_format_; |
| 1921 | GLenum offscreen_target_stencil_format_; |
| 1922 | GLsizei offscreen_target_samples_; |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 1923 | GLboolean offscreen_target_buffer_preserved_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1924 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1925 | // The copy that is saved when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1926 | scoped_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; |
| 1927 | scoped_ptr<BackTexture> offscreen_saved_color_texture_; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 1928 | scoped_refptr<TextureRef> |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1929 | offscreen_saved_color_texture_info_; |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 1930 | |
| 1931 | // The copy that is used as the destination for multi-sample resolves. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1932 | scoped_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; |
| 1933 | scoped_ptr<BackTexture> offscreen_resolved_color_texture_; |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 1934 | GLenum offscreen_saved_color_format_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 1935 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1936 | scoped_ptr<QueryManager> query_manager_; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 1937 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 1938 | scoped_ptr<VertexArrayManager> vertex_array_manager_; |
| 1939 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 1940 | scoped_ptr<ImageManager> image_manager_; |
| 1941 | |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 1942 | base::Callback<void(gfx::Size, float)> resize_callback_; |
[email protected] | 22f320a | 2011-08-30 01:17:00 | [diff] [blame] | 1943 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 1944 | WaitSyncPointCallback wait_sync_point_callback_; |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 1945 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 1946 | ShaderCacheCallback shader_cache_callback_; |
| 1947 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 1948 | scoped_ptr<AsyncPixelTransferManager> async_pixel_transfer_manager_; |
[email protected] | b0af4f5 | 2011-09-28 22:04:42 | [diff] [blame] | 1949 | |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1950 | // The format of the back buffer_ |
| 1951 | GLenum back_buffer_color_format_; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 1952 | bool back_buffer_has_depth_; |
| 1953 | bool back_buffer_has_stencil_; |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 1954 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 1955 | bool surfaceless_; |
| 1956 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 1957 | // Backbuffer attachments that are currently undefined. |
| 1958 | uint32 backbuffer_needs_clear_bits_; |
| 1959 | |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 1960 | // The current decoder error communicates the decoder error through command |
| 1961 | // processing functions that do not return the error value. Should be set only |
| 1962 | // if not returning an error. |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 1963 | error::Error current_decoder_error_; |
| 1964 | |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1965 | bool use_shader_translator_; |
dyen | 0ff9e440 | 2015-02-12 22:27:43 | [diff] [blame] | 1966 | scoped_refptr<ShaderTranslatorInterface> vertex_translator_; |
| 1967 | scoped_refptr<ShaderTranslatorInterface> fragment_translator_; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 1968 | |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 1969 | DisallowedFeatures disallowed_features_; |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 1970 | |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 1971 | // Cached from ContextGroup |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1972 | const Validators* validators_; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 1973 | scoped_refptr<FeatureInfo> feature_info_; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 1974 | |
[email protected] | 6522577 | 2011-05-12 21:10:24 | [diff] [blame] | 1975 | int frame_number_; |
| 1976 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 1977 | // Number of commands remaining to be processed in DoCommands(). |
| 1978 | int commands_to_process_; |
| 1979 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 1980 | bool has_robustness_extension_; |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 1981 | error::ContextLostReason context_lost_reason_; |
| 1982 | bool context_was_lost_; |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 1983 | bool reset_by_robustness_extension_; |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 1984 | bool supports_post_sub_buffer_; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 1985 | |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 1986 | // Indicates whether this is a context for WebGL1, WebGL2, or others. |
| 1987 | // 0: other types |
| 1988 | // 1: WebGL 1 |
| 1989 | // 2: WebGL 2 |
| 1990 | unsigned webgl_version_; |
| 1991 | |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1992 | // These flags are used to override the state of the shared feature_info_ |
| 1993 | // member. Because the same FeatureInfo instance may be shared among many |
| 1994 | // contexts, the assumptions on the availablity of extensions in WebGL |
| 1995 | // contexts may be broken. These flags override the shared state to preserve |
| 1996 | // WebGL semantics. |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 1997 | bool derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 1998 | bool frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 1999 | bool draw_buffers_explicitly_enabled_; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 2000 | bool shader_texture_lod_explicitly_enabled_; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 2001 | |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2002 | bool compile_shader_always_succeeds_; |
| 2003 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2004 | // An optional behaviour to lose the context and group when OOM. |
| 2005 | bool lose_context_when_out_of_memory_; |
| 2006 | |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 2007 | // Log extra info. |
| 2008 | bool service_logging_; |
| 2009 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2010 | #if defined(OS_MACOSX) |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 2011 | typedef std::map<GLuint, IOSurfaceRef> TextureToIOSurfaceMap; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2012 | TextureToIOSurfaceMap texture_to_io_surface_map_; |
| 2013 | #endif |
| 2014 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2015 | scoped_ptr<CopyTextureCHROMIUMResourceManager> copy_texture_CHROMIUM_; |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 2016 | scoped_ptr<ClearFramebufferResourceManager> clear_framebuffer_blit_; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2017 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2018 | // Cached values of the currently assigned viewport dimensions. |
| 2019 | GLsizei viewport_max_width_; |
| 2020 | GLsizei viewport_max_height_; |
| 2021 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 2022 | // Command buffer stats. |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 2023 | base::TimeDelta total_processing_commands_time_; |
| 2024 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 2025 | // States related to each manager. |
| 2026 | DecoderTextureState texture_state_; |
| 2027 | DecoderFramebufferState framebuffer_state_; |
| 2028 | |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 2029 | scoped_ptr<GPUTracer> gpu_tracer_; |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 2030 | scoped_ptr<GPUStateTracer> gpu_state_tracer_; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 2031 | const unsigned char* cb_command_trace_category_; |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 2032 | const unsigned char* gpu_decoder_category_; |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 2033 | int gpu_trace_level_; |
| 2034 | bool gpu_trace_commands_; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 2035 | bool gpu_debug_commands_; |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 2036 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 2037 | std::queue<linked_ptr<FenceCallback> > pending_readpixel_fences_; |
| 2038 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2039 | // Used to validate multisample renderbuffers if needed |
| 2040 | GLuint validation_texture_; |
| 2041 | GLuint validation_fbo_multisample_; |
| 2042 | GLuint validation_fbo_; |
| 2043 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 2044 | typedef gpu::gles2::GLES2Decoder::Error (GLES2DecoderImpl::*CmdHandler)( |
| 2045 | uint32 immediate_data_size, |
| 2046 | const void* data); |
| 2047 | |
| 2048 | // A struct to hold info about each command. |
| 2049 | struct CommandInfo { |
| 2050 | CmdHandler cmd_handler; |
| 2051 | uint8 arg_flags; // How to handle the arguments for this command |
| 2052 | uint8 cmd_flags; // How to handle this command |
| 2053 | uint16 arg_count; // How many arguments are expected for this command. |
| 2054 | }; |
| 2055 | |
| 2056 | // A table of CommandInfo for all the commands. |
| 2057 | static const CommandInfo command_info[kNumCommands - kStartPoint]; |
| 2058 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2059 | DISALLOW_COPY_AND_ASSIGN(GLES2DecoderImpl); |
| 2060 | }; |
| 2061 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 2062 | const GLES2DecoderImpl::CommandInfo GLES2DecoderImpl::command_info[] = { |
| 2063 | #define GLES2_CMD_OP(name) \ |
| 2064 | { \ |
| 2065 | &GLES2DecoderImpl::Handle##name, cmds::name::kArgFlags, \ |
| 2066 | cmds::name::cmd_flags, \ |
| 2067 | sizeof(cmds::name) / sizeof(CommandBufferEntry) - 1, \ |
| 2068 | } \ |
| 2069 | , /* NOLINT */ |
| 2070 | GLES2_COMMAND_LIST(GLES2_CMD_OP) |
| 2071 | #undef GLES2_CMD_OP |
| 2072 | }; |
| 2073 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2074 | ScopedGLErrorSuppressor::ScopedGLErrorSuppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2075 | const char* function_name, ErrorState* error_state) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2076 | : function_name_(function_name), |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2077 | error_state_(error_state) { |
| 2078 | ERRORSTATE_COPY_REAL_GL_ERRORS_TO_WRAPPER(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | ScopedGLErrorSuppressor::~ScopedGLErrorSuppressor() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2082 | ERRORSTATE_CLEAR_REAL_GL_ERRORS(error_state_, function_name_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2083 | } |
| 2084 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2085 | static void RestoreCurrentTextureBindings(ContextState* state, GLenum target) { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2086 | TextureUnit& info = state->texture_units[0]; |
| 2087 | GLuint last_id; |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2088 | scoped_refptr<TextureRef> texture_ref; |
| 2089 | switch (target) { |
| 2090 | case GL_TEXTURE_2D: |
| 2091 | texture_ref = info.bound_texture_2d; |
| 2092 | break; |
| 2093 | case GL_TEXTURE_CUBE_MAP: |
| 2094 | texture_ref = info.bound_texture_cube_map; |
| 2095 | break; |
| 2096 | case GL_TEXTURE_EXTERNAL_OES: |
| 2097 | texture_ref = info.bound_texture_external_oes; |
| 2098 | break; |
| 2099 | case GL_TEXTURE_RECTANGLE_ARB: |
| 2100 | texture_ref = info.bound_texture_rectangle_arb; |
| 2101 | break; |
| 2102 | default: |
| 2103 | NOTREACHED(); |
| 2104 | break; |
| 2105 | } |
| 2106 | if (texture_ref.get()) { |
| 2107 | last_id = texture_ref->service_id(); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2108 | } else { |
| 2109 | last_id = 0; |
| 2110 | } |
| 2111 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2112 | glBindTexture(target, last_id); |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2113 | glActiveTexture(GL_TEXTURE0 + state->active_texture_unit); |
| 2114 | } |
| 2115 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2116 | ScopedTextureBinder::ScopedTextureBinder(ContextState* state, |
| 2117 | GLuint id, |
| 2118 | GLenum target) |
| 2119 | : state_(state), |
| 2120 | target_(target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2121 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2122 | "ScopedTextureBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2123 | |
| 2124 | // TODO(apatrick): Check if there are any other states that need to be reset |
| 2125 | // before binding a new texture. |
| 2126 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2127 | glBindTexture(target, id); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2128 | } |
| 2129 | |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2130 | ScopedTextureBinder::~ScopedTextureBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2131 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2132 | "ScopedTextureBinder::dtor", state_->GetErrorState()); |
| 2133 | RestoreCurrentTextureBindings(state_, target_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2134 | } |
| 2135 | |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 2136 | ScopedRenderBufferBinder::ScopedRenderBufferBinder(ContextState* state, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2137 | GLuint id) |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 2138 | : state_(state) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2139 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 2140 | "ScopedRenderBufferBinder::ctor", state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2141 | glBindRenderbufferEXT(GL_RENDERBUFFER, id); |
| 2142 | } |
| 2143 | |
| 2144 | ScopedRenderBufferBinder::~ScopedRenderBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2145 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 18e785a | 2013-10-09 03:29:41 | [diff] [blame] | 2146 | "ScopedRenderBufferBinder::dtor", state_->GetErrorState()); |
| 2147 | state_->RestoreRenderbufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | ScopedFrameBufferBinder::ScopedFrameBufferBinder(GLES2DecoderImpl* decoder, |
| 2151 | GLuint id) |
| 2152 | : decoder_(decoder) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2153 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2154 | "ScopedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2155 | glBindFramebufferEXT(GL_FRAMEBUFFER, id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 2156 | decoder->OnFboChanged(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2157 | } |
| 2158 | |
| 2159 | ScopedFrameBufferBinder::~ScopedFrameBufferBinder() { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2160 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2161 | "ScopedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 2162 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2163 | } |
| 2164 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2165 | ScopedResolvedFrameBufferBinder::ScopedResolvedFrameBufferBinder( |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2166 | GLES2DecoderImpl* decoder, bool enforce_internal_framebuffer, bool internal) |
[email protected] | c070108 | 2011-04-20 00:34:52 | [diff] [blame] | 2167 | : decoder_(decoder) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 2168 | resolve_and_bind_ = ( |
| 2169 | decoder_->offscreen_target_frame_buffer_.get() && |
| 2170 | decoder_->IsOffscreenBufferMultisampled() && |
| 2171 | (!decoder_->framebuffer_state_.bound_read_framebuffer.get() || |
| 2172 | enforce_internal_framebuffer)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2173 | if (!resolve_and_bind_) |
| 2174 | return; |
| 2175 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2176 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2177 | "ScopedResolvedFrameBufferBinder::ctor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2178 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, |
| 2179 | decoder_->offscreen_target_frame_buffer_->id()); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2180 | GLuint targetid; |
| 2181 | if (internal) { |
| 2182 | if (!decoder_->offscreen_resolved_frame_buffer_.get()) { |
| 2183 | decoder_->offscreen_resolved_frame_buffer_.reset( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2184 | new BackFramebuffer(decoder_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2185 | decoder_->offscreen_resolved_frame_buffer_->Create(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2186 | decoder_->offscreen_resolved_color_texture_.reset( |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2187 | new BackTexture(decoder->memory_tracker(), &decoder->state_)); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2188 | decoder_->offscreen_resolved_color_texture_->Create(); |
| 2189 | |
| 2190 | DCHECK(decoder_->offscreen_saved_color_format_); |
| 2191 | decoder_->offscreen_resolved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2192 | decoder_->offscreen_size_, decoder_->offscreen_saved_color_format_, |
| 2193 | false); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2194 | decoder_->offscreen_resolved_frame_buffer_->AttachRenderTexture( |
| 2195 | decoder_->offscreen_resolved_color_texture_.get()); |
| 2196 | if (decoder_->offscreen_resolved_frame_buffer_->CheckStatus() != |
| 2197 | GL_FRAMEBUFFER_COMPLETE) { |
| 2198 | LOG(ERROR) << "ScopedResolvedFrameBufferBinder failed " |
| 2199 | << "because offscreen resolved FBO was incomplete."; |
| 2200 | return; |
| 2201 | } |
| 2202 | } |
| 2203 | targetid = decoder_->offscreen_resolved_frame_buffer_->id(); |
| 2204 | } else { |
| 2205 | targetid = decoder_->offscreen_saved_frame_buffer_->id(); |
| 2206 | } |
| 2207 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2208 | const int width = decoder_->offscreen_size_.width(); |
| 2209 | const int height = decoder_->offscreen_size_.height(); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 2210 | decoder->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2211 | decoder->BlitFramebufferHelper(0, |
| 2212 | 0, |
| 2213 | width, |
| 2214 | height, |
| 2215 | 0, |
| 2216 | 0, |
| 2217 | width, |
| 2218 | height, |
| 2219 | GL_COLOR_BUFFER_BIT, |
| 2220 | GL_NEAREST); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 2221 | glBindFramebufferEXT(GL_FRAMEBUFFER, targetid); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | ScopedResolvedFrameBufferBinder::~ScopedResolvedFrameBufferBinder() { |
| 2225 | if (!resolve_and_bind_) |
| 2226 | return; |
| 2227 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2228 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2229 | "ScopedResolvedFrameBufferBinder::dtor", decoder_->GetErrorState()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2230 | decoder_->RestoreCurrentFramebufferBindings(); |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 2231 | if (decoder_->state_.enable_flags.scissor_test) { |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 2232 | decoder_->state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
[email protected] | 8c3e6878 | 2010-10-27 16:41:18 | [diff] [blame] | 2233 | } |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2234 | } |
| 2235 | |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2236 | BackTexture::BackTexture( |
| 2237 | MemoryTracker* memory_tracker, |
| 2238 | ContextState* state) |
| 2239 | : memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 2240 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2241 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 2242 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2243 | } |
| 2244 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2245 | BackTexture::~BackTexture() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2246 | // This does not destroy the render texture because that would require that |
| 2247 | // the associated GL context was current. Just check that it was explicitly |
| 2248 | // destroyed. |
| 2249 | DCHECK_EQ(id_, 0u); |
| 2250 | } |
| 2251 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2252 | void BackTexture::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2253 | ScopedGLErrorSuppressor suppressor("BackTexture::Create", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2254 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2255 | Destroy(); |
| 2256 | glGenTextures(1, &id_); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2257 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | eeeb07b9 | 2014-08-16 07:46:26 | [diff] [blame] | 2258 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 2259 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 2260 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
| 2261 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
[email protected] | 6278880 | 2011-10-03 17:57:16 | [diff] [blame] | 2262 | |
| 2263 | // TODO(apatrick): Attempt to diagnose crbug.com/97775. If SwapBuffers is |
| 2264 | // never called on an offscreen context, no data will ever be uploaded to the |
| 2265 | // saved offscreen color texture (it is deferred until to when SwapBuffers |
| 2266 | // is called). My idea is that some nvidia drivers might have a bug where |
| 2267 | // deleting a texture that has never been populated might cause a |
| 2268 | // crash. |
| 2269 | glTexImage2D( |
| 2270 | 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] | 2271 | |
| 2272 | bytes_allocated_ = 16u * 16u * 4u; |
| 2273 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2274 | } |
| 2275 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2276 | bool BackTexture::AllocateStorage( |
| 2277 | const gfx::Size& size, GLenum format, bool zero) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2278 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2279 | ScopedGLErrorSuppressor suppressor("BackTexture::AllocateStorage", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2280 | state_->GetErrorState()); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2281 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2282 | uint32 image_size = 0; |
| 2283 | GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 2284 | size.width(), size.height(), 1, format, GL_UNSIGNED_BYTE, 8, &image_size, |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2285 | NULL, NULL); |
| 2286 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2287 | if (!memory_tracker_.EnsureGPUMemoryAvailable(image_size)) { |
| 2288 | return false; |
| 2289 | } |
| 2290 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 2291 | scoped_ptr<char[]> zero_data; |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2292 | if (zero) { |
| 2293 | zero_data.reset(new char[image_size]); |
| 2294 | memset(zero_data.get(), 0, image_size); |
| 2295 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2296 | |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 2297 | glTexImage2D(GL_TEXTURE_2D, |
| 2298 | 0, // mip level |
| 2299 | format, |
| 2300 | size.width(), |
| 2301 | size.height(), |
| 2302 | 0, // border |
| 2303 | format, |
| 2304 | GL_UNSIGNED_BYTE, |
| 2305 | zero_data.get()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2306 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 2307 | size_ = size; |
| 2308 | |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2309 | bool success = glGetError() == GL_NO_ERROR; |
| 2310 | if (success) { |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2311 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2312 | bytes_allocated_ = image_size; |
| 2313 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2314 | } |
| 2315 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2316 | } |
| 2317 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2318 | void BackTexture::Copy(const gfx::Size& size, GLenum format) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2319 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2320 | ScopedGLErrorSuppressor suppressor("BackTexture::Copy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2321 | state_->GetErrorState()); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 2322 | ScopedTextureBinder binder(state_, id_, GL_TEXTURE_2D); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2323 | glCopyTexImage2D(GL_TEXTURE_2D, |
| 2324 | 0, // level |
[email protected] | 3a4d0c5 | 2011-06-29 23:11:58 | [diff] [blame] | 2325 | format, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2326 | 0, 0, |
| 2327 | size.width(), |
| 2328 | size.height(), |
| 2329 | 0); // border |
| 2330 | } |
| 2331 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2332 | void BackTexture::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2333 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2334 | ScopedGLErrorSuppressor suppressor("BackTexture::Destroy", |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2335 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2336 | glDeleteTextures(1, &id_); |
| 2337 | id_ = 0; |
| 2338 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2339 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2340 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2341 | } |
| 2342 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2343 | void BackTexture::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2344 | id_ = 0; |
| 2345 | } |
| 2346 | |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2347 | BackRenderbuffer::BackRenderbuffer( |
| 2348 | RenderbufferManager* renderbuffer_manager, |
| 2349 | MemoryTracker* memory_tracker, |
| 2350 | ContextState* state) |
| 2351 | : renderbuffer_manager_(renderbuffer_manager), |
| 2352 | memory_tracker_(memory_tracker, MemoryTracker::kUnmanaged), |
| 2353 | state_(state), |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2354 | bytes_allocated_(0), |
[email protected] | ff6493f | 2012-07-31 19:52:25 | [diff] [blame] | 2355 | id_(0) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2356 | } |
| 2357 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2358 | BackRenderbuffer::~BackRenderbuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2359 | // This does not destroy the render buffer because that would require that |
| 2360 | // the associated GL context was current. Just check that it was explicitly |
| 2361 | // destroyed. |
| 2362 | DCHECK_EQ(id_, 0u); |
| 2363 | } |
| 2364 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2365 | void BackRenderbuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2366 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Create", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2367 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2368 | Destroy(); |
| 2369 | glGenRenderbuffersEXT(1, &id_); |
| 2370 | } |
| 2371 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2372 | bool BackRenderbuffer::AllocateStorage(const FeatureInfo* feature_info, |
| 2373 | const gfx::Size& size, |
| 2374 | GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2375 | GLsizei samples) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2376 | ScopedGLErrorSuppressor suppressor( |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2377 | "BackRenderbuffer::AllocateStorage", state_->GetErrorState()); |
| 2378 | ScopedRenderBufferBinder binder(state_, id_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2379 | |
| 2380 | uint32 estimated_size = 0; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2381 | if (!renderbuffer_manager_->ComputeEstimatedRenderbufferSize( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 2382 | size.width(), size.height(), samples, format, &estimated_size)) { |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2383 | return false; |
| 2384 | } |
| 2385 | |
| 2386 | if (!memory_tracker_.EnsureGPUMemoryAvailable(estimated_size)) { |
| 2387 | return false; |
| 2388 | } |
| 2389 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2390 | if (samples <= 1) { |
| 2391 | glRenderbufferStorageEXT(GL_RENDERBUFFER, |
| 2392 | format, |
| 2393 | size.width(), |
| 2394 | size.height()); |
| 2395 | } else { |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2396 | GLES2DecoderImpl::RenderbufferStorageMultisampleHelper(feature_info, |
| 2397 | GL_RENDERBUFFER, |
| 2398 | samples, |
| 2399 | format, |
| 2400 | size.width(), |
| 2401 | size.height()); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2402 | } |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2403 | bool success = glGetError() == GL_NO_ERROR; |
| 2404 | if (success) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2405 | // Mark the previously allocated bytes as free. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2406 | memory_tracker_.TrackMemFree(bytes_allocated_); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 2407 | bytes_allocated_ = estimated_size; |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2408 | // Track the newly allocated bytes. |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2409 | memory_tracker_.TrackMemAlloc(bytes_allocated_); |
[email protected] | 1078f91 | 2011-12-23 13:12:14 | [diff] [blame] | 2410 | } |
| 2411 | return success; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2412 | } |
| 2413 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2414 | void BackRenderbuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2415 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2416 | ScopedGLErrorSuppressor suppressor("BackRenderbuffer::Destroy", |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2417 | state_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2418 | glDeleteRenderbuffersEXT(1, &id_); |
| 2419 | id_ = 0; |
| 2420 | } |
[email protected] | 68e81a4a6 | 2012-12-13 01:16:48 | [diff] [blame] | 2421 | memory_tracker_.TrackMemFree(bytes_allocated_); |
| 2422 | bytes_allocated_ = 0; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2423 | } |
| 2424 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2425 | void BackRenderbuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2426 | id_ = 0; |
| 2427 | } |
| 2428 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2429 | BackFramebuffer::BackFramebuffer(GLES2DecoderImpl* decoder) |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2430 | : decoder_(decoder), |
| 2431 | id_(0) { |
| 2432 | } |
| 2433 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2434 | BackFramebuffer::~BackFramebuffer() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2435 | // This does not destroy the frame buffer because that would require that |
| 2436 | // the associated GL context was current. Just check that it was explicitly |
| 2437 | // destroyed. |
| 2438 | DCHECK_EQ(id_, 0u); |
| 2439 | } |
| 2440 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2441 | void BackFramebuffer::Create() { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2442 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Create", |
| 2443 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2444 | Destroy(); |
| 2445 | glGenFramebuffersEXT(1, &id_); |
| 2446 | } |
| 2447 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2448 | void BackFramebuffer::AttachRenderTexture(BackTexture* texture) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2449 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2450 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2451 | "BackFramebuffer::AttachRenderTexture", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2452 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2453 | GLuint attach_id = texture ? texture->id() : 0; |
| 2454 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, |
| 2455 | GL_COLOR_ATTACHMENT0, |
| 2456 | GL_TEXTURE_2D, |
| 2457 | attach_id, |
| 2458 | 0); |
| 2459 | } |
| 2460 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2461 | void BackFramebuffer::AttachRenderBuffer(GLenum target, |
| 2462 | BackRenderbuffer* render_buffer) { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2463 | DCHECK_NE(id_, 0u); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 2464 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2465 | "BackFramebuffer::AttachRenderBuffer", decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2466 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2467 | GLuint attach_id = render_buffer ? render_buffer->id() : 0; |
| 2468 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2469 | target, |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2470 | GL_RENDERBUFFER, |
| 2471 | attach_id); |
| 2472 | } |
| 2473 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2474 | void BackFramebuffer::Destroy() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2475 | if (id_ != 0) { |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2476 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::Destroy", |
| 2477 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2478 | glDeleteFramebuffersEXT(1, &id_); |
| 2479 | id_ = 0; |
| 2480 | } |
| 2481 | } |
| 2482 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2483 | void BackFramebuffer::Invalidate() { |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2484 | id_ = 0; |
| 2485 | } |
| 2486 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2487 | GLenum BackFramebuffer::CheckStatus() { |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2488 | DCHECK_NE(id_, 0u); |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 2489 | ScopedGLErrorSuppressor suppressor("BackFramebuffer::CheckStatus", |
| 2490 | decoder_->GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2491 | ScopedFrameBufferBinder binder(decoder_, id_); |
| 2492 | return glCheckFramebufferStatusEXT(GL_FRAMEBUFFER); |
| 2493 | } |
| 2494 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2495 | GLES2Decoder* GLES2Decoder::Create(ContextGroup* group) { |
| 2496 | return new GLES2DecoderImpl(group); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2497 | } |
| 2498 | |
[email protected] | aa766612 | 2011-09-02 19:45:52 | [diff] [blame] | 2499 | GLES2DecoderImpl::GLES2DecoderImpl(ContextGroup* group) |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2500 | : GLES2Decoder(), |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2501 | group_(group), |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 2502 | logger_(&debug_marker_manager_), |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2503 | state_(group_->feature_info(), this, &logger_), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2504 | attrib_0_buffer_id_(0), |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 2505 | attrib_0_buffer_matches_value_(true), |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2506 | attrib_0_size_(0), |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2507 | fixed_attrib_buffer_id_(0), |
| 2508 | fixed_attrib_buffer_size_(0), |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2509 | offscreen_target_color_format_(0), |
| 2510 | offscreen_target_depth_format_(0), |
| 2511 | offscreen_target_stencil_format_(0), |
| 2512 | offscreen_target_samples_(0), |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 2513 | offscreen_target_buffer_preserved_(true), |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2514 | offscreen_saved_color_format_(0), |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 2515 | back_buffer_color_format_(0), |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 2516 | back_buffer_has_depth_(false), |
| 2517 | back_buffer_has_stencil_(false), |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2518 | surfaceless_(false), |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 2519 | backbuffer_needs_clear_bits_(0), |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 2520 | current_decoder_error_(error::kNoError), |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 2521 | use_shader_translator_(true), |
[email protected] | 915a59a1 | 2010-09-30 21:29:11 | [diff] [blame] | 2522 | validators_(group_->feature_info()->validators()), |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 2523 | feature_info_(group_->feature_info()), |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2524 | frame_number_(0), |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2525 | has_robustness_extension_(false), |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 2526 | context_lost_reason_(error::kUnknown), |
| 2527 | context_was_lost_(false), |
[email protected] | 93a7d98f | 2013-07-11 00:04:22 | [diff] [blame] | 2528 | reset_by_robustness_extension_(false), |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 2529 | supports_post_sub_buffer_(false), |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 2530 | webgl_version_(0), |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2531 | derivatives_explicitly_enabled_(false), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 2532 | frag_depth_explicitly_enabled_(false), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 2533 | draw_buffers_explicitly_enabled_(false), |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 2534 | shader_texture_lod_explicitly_enabled_(false), |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2535 | compile_shader_always_succeeds_(false), |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2536 | lose_context_when_out_of_memory_(false), |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2537 | service_logging_(base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | cae2017 | 2012-12-07 00:06:19 | [diff] [blame] | 2538 | switches::kEnableGPUServiceLoggingGPU)), |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2539 | viewport_max_width_(0), |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2540 | viewport_max_height_(0), |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 2541 | texture_state_(group_->feature_info() |
| 2542 | ->workarounds() |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 2543 | .texsubimage_faster_than_teximage), |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 2544 | cb_command_trace_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 2545 | TRACE_DISABLED_BY_DEFAULT("cb_command"))), |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 2546 | gpu_decoder_category_(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 2547 | TRACE_DISABLED_BY_DEFAULT("gpu_decoder"))), |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 2548 | gpu_trace_level_(2), |
| 2549 | gpu_trace_commands_(false), |
| 2550 | gpu_debug_commands_(false), |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 2551 | validation_texture_(0), |
| 2552 | validation_fbo_multisample_(0), |
sievers | 8694f633 | 2015-06-09 18:58:47 | [diff] [blame] | 2553 | validation_fbo_(0) { |
[email protected] | 3b1ecc26 | 2011-08-03 22:49:57 | [diff] [blame] | 2554 | DCHECK(group); |
| 2555 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2556 | // The shader translator is used for WebGL even when running on EGL |
| 2557 | // because additional restrictions are needed (like only enabling |
| 2558 | // GL_OES_standard_derivatives on demand). It is used for the unit |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 2559 | // tests because GLES2DecoderWithShaderTest.GetShaderInfoLogValidArgs passes |
| 2560 | // the empty string to CompileShader and this is not a valid shader. |
| 2561 | if (gfx::GetGLImplementation() == gfx::kGLImplementationMockGL || |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2562 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2563 | switches::kDisableGLSLTranslator)) { |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2564 | use_shader_translator_ = false; |
| 2565 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 2566 | } |
| 2567 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 2568 | GLES2DecoderImpl::~GLES2DecoderImpl() { |
| 2569 | } |
| 2570 | |
[email protected] | c410da80 | 2011-03-14 19:17:41 | [diff] [blame] | 2571 | bool GLES2DecoderImpl::Initialize( |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2572 | const scoped_refptr<gfx::GLSurface>& surface, |
| 2573 | const scoped_refptr<gfx::GLContext>& context, |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2574 | bool offscreen, |
dongseong.hwang | 4c04a16 | 2015-03-04 07:27:33 | [diff] [blame] | 2575 | const gfx::Size& offscreen_size, |
[email protected] | e82fb79 | 2011-09-22 00:33:29 | [diff] [blame] | 2576 | const DisallowedFeatures& disallowed_features, |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 2577 | const std::vector<int32>& attribs) { |
[email protected] | 3551cb20 | 2012-05-24 10:55:32 | [diff] [blame] | 2578 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2579 | DCHECK(context->IsCurrent(surface.get())); |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 2580 | DCHECK(!context_.get()); |
hendrikw | 2e3b5c8c | 2015-04-27 23:52:25 | [diff] [blame] | 2581 | DCHECK(!offscreen || !offscreen_size.IsEmpty()); |
[email protected] | 66791e38 | 2010-07-14 20:48:30 | [diff] [blame] | 2582 | |
zmo | 0ee1586 | 2015-03-04 03:50:18 | [diff] [blame] | 2583 | ContextCreationAttribHelper attrib_parser; |
| 2584 | if (!attrib_parser.Parse(attribs)) |
| 2585 | return false; |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 2586 | webgl_version_ = attrib_parser.webgl_version; |
zmo | 0ee1586 | 2015-03-04 03:50:18 | [diff] [blame] | 2587 | |
jbauman | a760469 | 2014-10-17 02:00:39 | [diff] [blame] | 2588 | surfaceless_ = surface->IsSurfaceless() && !offscreen; |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2589 | |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 2590 | set_initialized(); |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 2591 | gpu_state_tracer_ = GPUStateTracer::Create(&state_); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 2592 | |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2593 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2594 | switches::kEnableGPUDebugging)) { |
[email protected] | e844ae2 | 2012-01-14 03:36:26 | [diff] [blame] | 2595 | set_debug(true); |
| 2596 | } |
| 2597 | |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2598 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2599 | switches::kEnableGPUCommandLogging)) { |
[email protected] | 39ba4f0 | 2012-03-26 01:16:00 | [diff] [blame] | 2600 | set_log_commands(true); |
| 2601 | } |
| 2602 | |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 2603 | compile_shader_always_succeeds_ = |
| 2604 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 2605 | switches::kCompileShaderAlwaysSucceeds); |
[email protected] | 062c38b | 2012-01-18 03:25:10 | [diff] [blame] | 2606 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2607 | // Take ownership of the context and surface. The surface can be replaced with |
| 2608 | // SetSurface. |
[email protected] | fbe2037 | 2011-06-01 01:46:38 | [diff] [blame] | 2609 | context_ = context; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2610 | surface_ = surface; |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 2611 | |
dyen | 5b1c02ff | 2015-02-26 01:54:00 | [diff] [blame] | 2612 | // Create GPU Tracer for timing values. |
| 2613 | gpu_tracer_.reset(new GPUTracer(this)); |
| 2614 | |
dyen | 1fa42196 | 2015-06-17 21:25:39 | [diff] [blame] | 2615 | if (feature_info_->workarounds().disable_timestamp_queries) { |
| 2616 | // Forcing time elapsed query for any GPU Timing Client forces it for all |
| 2617 | // clients in the context. |
| 2618 | GetGLContext()->CreateGPUTimingClient()->ForceTimeElapsedQuery(); |
| 2619 | } |
| 2620 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2621 | // Save the loseContextWhenOutOfMemory context creation attribute. |
| 2622 | lose_context_when_out_of_memory_ = |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2623 | attrib_parser.lose_context_when_out_of_memory; |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 2624 | |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 2625 | // If the failIfMajorPerformanceCaveat context creation attribute was true |
| 2626 | // and we are using a software renderer, fail. |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2627 | if (attrib_parser.fail_if_major_perf_caveat && |
[email protected] | 65f7efe | 2013-11-28 03:11:47 | [diff] [blame] | 2628 | feature_info_->feature_flags().is_swiftshader) { |
| 2629 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
| 2630 | Destroy(true); |
| 2631 | return false; |
| 2632 | } |
| 2633 | |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 2634 | disallowed_features_ = disallowed_features; |
| 2635 | if (webgl_version_ == 1) { |
| 2636 | disallowed_features_.npot_support = true; |
| 2637 | } |
| 2638 | |
| 2639 | if (!group_->Initialize(this, |
| 2640 | ContextGroup::GetContextType(webgl_version_), |
| 2641 | disallowed_features_)) { |
[email protected] | 1871a09 | 2011-10-10 21:46:42 | [diff] [blame] | 2642 | group_ = NULL; // Must not destroy ContextGroup if it is not initialized. |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2643 | Destroy(true); |
[email protected] | ae174109 | 2010-11-17 19:16:03 | [diff] [blame] | 2644 | return false; |
[email protected] | a3ded6d | 2010-10-19 06:44:39 | [diff] [blame] | 2645 | } |
[email protected] | b64c2495 | 2012-04-19 03:20:27 | [diff] [blame] | 2646 | CHECK_GL_ERROR(); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2647 | |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 2648 | if (webgl_version_ == 2) { |
| 2649 | if (!feature_info_->IsES3Capable()) { |
| 2650 | LOG(ERROR) << "Underlying driver does not support ES3."; |
| 2651 | Destroy(true); |
| 2652 | return false; |
| 2653 | } |
zmo | ac89bdd | 2015-03-10 02:09:05 | [diff] [blame] | 2654 | feature_info_->EnableES3Validators(); |
| 2655 | set_unsafe_es3_apis_enabled(true); |
| 2656 | } |
| 2657 | |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 2658 | state_.attrib_values.resize(group_->max_vertex_attribs()); |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 2659 | vertex_array_manager_.reset(new VertexArrayManager()); |
| 2660 | |
| 2661 | GLuint default_vertex_attrib_service_id = 0; |
| 2662 | if (features().native_vertex_array_object) { |
| 2663 | glGenVertexArraysOES(1, &default_vertex_attrib_service_id); |
| 2664 | glBindVertexArrayOES(default_vertex_attrib_service_id); |
| 2665 | } |
| 2666 | |
| 2667 | state_.default_vertex_attrib_manager = |
| 2668 | CreateVertexAttribManager(0, default_vertex_attrib_service_id, false); |
| 2669 | |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 2670 | state_.default_vertex_attrib_manager->Initialize( |
[email protected] | 94ba2e0 | 2014-03-12 10:32:00 | [diff] [blame] | 2671 | group_->max_vertex_attribs(), |
| 2672 | feature_info_->workarounds().init_vertex_attributes); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 2673 | |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 2674 | // vertex_attrib_manager is set to default_vertex_attrib_manager by this call |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 2675 | DoBindVertexArrayOES(0); |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 2676 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 2677 | query_manager_.reset(new QueryManager(this, feature_info_.get())); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 2678 | |
[email protected] | b63f1d6 | 2014-07-18 15:40:59 | [diff] [blame] | 2679 | image_manager_.reset(new ImageManager); |
| 2680 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 2681 | util_.set_num_compressed_texture_formats( |
| 2682 | validators_->compressed_texture_format.GetValues().size()); |
| 2683 | |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 2684 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 2685 | // We have to enable vertex array 0 on OpenGL or it won't render. Note that |
| 2686 | // OpenGL ES 2.0 does not have this issue. |
| 2687 | glEnableVertexAttribArray(0); |
| 2688 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 2689 | glGenBuffersARB(1, &attrib_0_buffer_id_); |
| 2690 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 2691 | glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); |
| 2692 | glBindBuffer(GL_ARRAY_BUFFER, 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 2693 | glGenBuffersARB(1, &fixed_attrib_buffer_id_); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 2694 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2695 | state_.texture_units.resize(group_->max_texture_units()); |
| 2696 | for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) { |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2697 | glActiveTexture(GL_TEXTURE0 + tt); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2698 | // We want the last bind to be 2D. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2699 | TextureRef* ref; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2700 | if (features().oes_egl_image_external) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2701 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2702 | GL_TEXTURE_EXTERNAL_OES); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2703 | state_.texture_units[tt].bound_texture_external_oes = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2704 | glBindTexture(GL_TEXTURE_EXTERNAL_OES, ref ? ref->service_id() : 0); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 2705 | } |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2706 | if (features().arb_texture_rectangle) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2707 | ref = texture_manager()->GetDefaultTextureInfo( |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 2708 | GL_TEXTURE_RECTANGLE_ARB); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2709 | state_.texture_units[tt].bound_texture_rectangle_arb = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2710 | glBindTexture(GL_TEXTURE_RECTANGLE_ARB, ref ? ref->service_id() : 0); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 2711 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2712 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); |
| 2713 | state_.texture_units[tt].bound_texture_cube_map = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2714 | glBindTexture(GL_TEXTURE_CUBE_MAP, ref ? ref->service_id() : 0); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 2715 | ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); |
| 2716 | state_.texture_units[tt].bound_texture_2d = ref; |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 2717 | glBindTexture(GL_TEXTURE_2D, ref ? ref->service_id() : 0); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 2718 | } |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 2719 | glActiveTexture(GL_TEXTURE0); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 2720 | CHECK_GL_ERROR(); |
| 2721 | |
jmadill | 653daa7 | 2015-05-06 20:29:04 | [diff] [blame] | 2722 | // cache ALPHA_BITS result for re-use with clear behaviour |
| 2723 | GLint alpha_bits = 0; |
| 2724 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 2725 | if (offscreen) { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2726 | if (attrib_parser.samples > 0 && attrib_parser.sample_buffers > 0 && |
[email protected] | b060965 | 2012-12-14 07:24:54 | [diff] [blame] | 2727 | features().chromium_framebuffer_multisample) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2728 | // Per ext_framebuffer_multisample spec, need max bound on sample count. |
[email protected] | 0b1e9d7 | 2010-11-11 16:29:43 | [diff] [blame] | 2729 | // max_sample_count must be initialized to a sane value. If |
| 2730 | // glGetIntegerv() throws a GL error, it leaves its argument unchanged. |
| 2731 | GLint max_sample_count = 1; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2732 | glGetIntegerv(GL_MAX_SAMPLES_EXT, &max_sample_count); |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2733 | offscreen_target_samples_ = std::min(attrib_parser.samples, |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2734 | max_sample_count); |
| 2735 | } else { |
| 2736 | offscreen_target_samples_ = 1; |
| 2737 | } |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2738 | offscreen_target_buffer_preserved_ = attrib_parser.buffer_preserved; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2739 | |
| 2740 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
| 2741 | const bool rgb8_supported = |
| 2742 | context_->HasExtension("GL_OES_rgb8_rgba8"); |
| 2743 | // The only available default render buffer formats in GLES2 have very |
| 2744 | // little precision. Don't enable multisampling unless 8-bit render |
| 2745 | // buffer formats are available--instead fall back to 8-bit textures. |
| 2746 | if (rgb8_supported && offscreen_target_samples_ > 1) { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2747 | offscreen_target_color_format_ = attrib_parser.alpha_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2748 | GL_RGBA8 : GL_RGB8; |
| 2749 | } else { |
| 2750 | offscreen_target_samples_ = 1; |
rahul.g | 0aaf8db1 | 2015-04-29 14:18:04 | [diff] [blame] | 2751 | offscreen_target_color_format_ = |
| 2752 | attrib_parser.alpha_size > 0 || workarounds().disable_gl_rgb_format |
| 2753 | ? GL_RGBA |
| 2754 | : GL_RGB; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | // ANGLE only supports packed depth/stencil formats, so use it if it is |
| 2758 | // available. |
| 2759 | const bool depth24_stencil8_supported = |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2760 | feature_info_->feature_flags().packed_depth24_stencil8; |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2761 | VLOG(1) << "GL_OES_packed_depth_stencil " |
| 2762 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2763 | if ((attrib_parser.depth_size > 0 || attrib_parser.stencil_size > 0) && |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2764 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2765 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2766 | offscreen_target_stencil_format_ = 0; |
| 2767 | } else { |
| 2768 | // It may be the case that this depth/stencil combination is not |
| 2769 | // supported, but this will be checked later by CheckFramebufferStatus. |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2770 | offscreen_target_depth_format_ = attrib_parser.depth_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2771 | GL_DEPTH_COMPONENT16 : 0; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2772 | offscreen_target_stencil_format_ = attrib_parser.stencil_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2773 | GL_STENCIL_INDEX8 : 0; |
| 2774 | } |
| 2775 | } else { |
rahul.g | 0aaf8db1 | 2015-04-29 14:18:04 | [diff] [blame] | 2776 | offscreen_target_color_format_ = |
| 2777 | attrib_parser.alpha_size > 0 || workarounds().disable_gl_rgb_format |
| 2778 | ? GL_RGBA |
| 2779 | : GL_RGB; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2780 | |
| 2781 | // If depth is requested at all, use the packed depth stencil format if |
| 2782 | // it's available, as some desktop GL drivers don't support any non-packed |
| 2783 | // formats for depth attachments. |
| 2784 | const bool depth24_stencil8_supported = |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 2785 | feature_info_->feature_flags().packed_depth24_stencil8; |
[email protected] | d366c48 | 2010-10-20 00:11:27 | [diff] [blame] | 2786 | VLOG(1) << "GL_EXT_packed_depth_stencil " |
| 2787 | << (depth24_stencil8_supported ? "" : "not ") << "supported."; |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2788 | |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2789 | if ((attrib_parser.depth_size > 0 || attrib_parser.stencil_size > 0) && |
[email protected] | 71ee364 | 2010-10-14 18:08:00 | [diff] [blame] | 2790 | depth24_stencil8_supported) { |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2791 | offscreen_target_depth_format_ = GL_DEPTH24_STENCIL8; |
| 2792 | offscreen_target_stencil_format_ = 0; |
| 2793 | } else { |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2794 | offscreen_target_depth_format_ = attrib_parser.depth_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2795 | GL_DEPTH_COMPONENT : 0; |
[email protected] | 845c4e3 | 2014-08-13 11:50:40 | [diff] [blame] | 2796 | offscreen_target_stencil_format_ = attrib_parser.stencil_size > 0 ? |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2797 | GL_STENCIL_INDEX : 0; |
| 2798 | } |
| 2799 | } |
| 2800 | |
rahul.g | 0aaf8db1 | 2015-04-29 14:18:04 | [diff] [blame] | 2801 | offscreen_saved_color_format_ = |
| 2802 | attrib_parser.alpha_size > 0 || workarounds().disable_gl_rgb_format |
| 2803 | ? GL_RGBA |
| 2804 | : GL_RGB; |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 2805 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2806 | // Create the target frame buffer. This is the one that the client renders |
| 2807 | // directly to. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2808 | offscreen_target_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2809 | offscreen_target_frame_buffer_->Create(); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2810 | // Due to GLES2 format limitations, either the color texture (for |
| 2811 | // non-multisampling) or the color render buffer (for multisampling) will be |
| 2812 | // attached to the offscreen frame buffer. The render buffer has more |
| 2813 | // limited formats available to it, but the texture can't do multisampling. |
| 2814 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2815 | offscreen_target_color_render_buffer_.reset(new BackRenderbuffer( |
| 2816 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2817 | offscreen_target_color_render_buffer_->Create(); |
| 2818 | } else { |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2819 | offscreen_target_color_texture_.reset(new BackTexture( |
| 2820 | memory_tracker(), &state_)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2821 | offscreen_target_color_texture_->Create(); |
| 2822 | } |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2823 | offscreen_target_depth_render_buffer_.reset(new BackRenderbuffer( |
| 2824 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2825 | offscreen_target_depth_render_buffer_->Create(); |
[email protected] | d5a28e45 | 2013-10-10 01:01:40 | [diff] [blame] | 2826 | offscreen_target_stencil_render_buffer_.reset(new BackRenderbuffer( |
| 2827 | renderbuffer_manager(), memory_tracker(), &state_)); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2828 | offscreen_target_stencil_render_buffer_->Create(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2829 | |
| 2830 | // Create the saved offscreen texture. The target frame buffer is copied |
| 2831 | // here when SwapBuffers is called. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 2832 | offscreen_saved_frame_buffer_.reset(new BackFramebuffer(this)); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 2833 | offscreen_saved_frame_buffer_->Create(); |
| 2834 | // |
[email protected] | ce29689 | 2013-10-24 22:04:36 | [diff] [blame] | 2835 | offscreen_saved_color_texture_.reset(new BackTexture( |
| 2836 | memory_tracker(), &state_)); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2837 | offscreen_saved_color_texture_->Create(); |
| 2838 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2839 | // Allocate the render buffers at their initial size and check the status |
| 2840 | // of the frame buffers is okay. |
dongseong.hwang | 4c04a16 | 2015-03-04 07:27:33 | [diff] [blame] | 2841 | if (!ResizeOffscreenFrameBuffer(offscreen_size)) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 2842 | LOG(ERROR) << "Could not allocate offscreen buffer storage."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 2843 | Destroy(true); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2844 | return false; |
| 2845 | } |
| 2846 | |
dongseong.hwang | 4c04a16 | 2015-03-04 07:27:33 | [diff] [blame] | 2847 | state_.viewport_width = offscreen_size.width(); |
| 2848 | state_.viewport_height = offscreen_size.height(); |
| 2849 | |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 2850 | // Allocate the offscreen saved color texture. |
| 2851 | DCHECK(offscreen_saved_color_format_); |
| 2852 | offscreen_saved_color_texture_->AllocateStorage( |
| 2853 | gfx::Size(1, 1), offscreen_saved_color_format_, true); |
| 2854 | |
| 2855 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 2856 | offscreen_saved_color_texture_.get()); |
| 2857 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 2858 | GL_FRAMEBUFFER_COMPLETE) { |
| 2859 | LOG(ERROR) << "Offscreen saved FBO was incomplete."; |
| 2860 | Destroy(true); |
| 2861 | return false; |
| 2862 | } |
| 2863 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2864 | // Bind to the new default frame buffer (the offscreen target frame buffer). |
| 2865 | // This should now be associated with ID zero. |
| 2866 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 2867 | } else { |
| 2868 | glBindFramebufferEXT(GL_FRAMEBUFFER, GetBackbufferServiceId()); |
| 2869 | // These are NOT if the back buffer has these proprorties. They are |
| 2870 | // if we want the command buffer to enforce them regardless of what |
| 2871 | // the real backbuffer is assuming the real back buffer gives us more than |
| 2872 | // we ask for. In other words, if we ask for RGB and we get RGBA then we'll |
| 2873 | // make it appear RGB. If on the other hand we ask for RGBA nd get RGB we |
| 2874 | // can't do anything about that. |
| 2875 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2876 | if (!surfaceless_) { |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 2877 | GLint depth_bits = 0; |
| 2878 | GLint stencil_bits = 0; |
| 2879 | |
| 2880 | bool default_fb = (GetBackbufferServiceId() == 0); |
| 2881 | |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 2882 | if (feature_info_->gl_version_info().is_desktop_core_profile) { |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 2883 | glGetFramebufferAttachmentParameterivEXT( |
| 2884 | GL_FRAMEBUFFER, |
| 2885 | default_fb ? GL_BACK_LEFT : GL_COLOR_ATTACHMENT0, |
| 2886 | GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &alpha_bits); |
| 2887 | glGetFramebufferAttachmentParameterivEXT( |
| 2888 | GL_FRAMEBUFFER, |
| 2889 | default_fb ? GL_DEPTH : GL_DEPTH_ATTACHMENT, |
| 2890 | GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE, &depth_bits); |
| 2891 | glGetFramebufferAttachmentParameterivEXT( |
| 2892 | GL_FRAMEBUFFER, |
| 2893 | default_fb ? GL_STENCIL : GL_STENCIL_ATTACHMENT, |
| 2894 | GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &stencil_bits); |
| 2895 | } else { |
| 2896 | glGetIntegerv(GL_ALPHA_BITS, &alpha_bits); |
| 2897 | glGetIntegerv(GL_DEPTH_BITS, &depth_bits); |
| 2898 | glGetIntegerv(GL_STENCIL_BITS, &stencil_bits); |
| 2899 | } |
| 2900 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2901 | // This checks if the user requested RGBA and we have RGBA then RGBA. If |
| 2902 | // the user requested RGB then RGB. If the user did not specify a |
| 2903 | // preference than use whatever we were given. Same for DEPTH and STENCIL. |
| 2904 | back_buffer_color_format_ = |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 2905 | (attrib_parser.alpha_size != 0 && alpha_bits > 0) ? GL_RGBA : GL_RGB; |
| 2906 | back_buffer_has_depth_ = attrib_parser.depth_size != 0 && depth_bits > 0; |
| 2907 | back_buffer_has_stencil_ = |
| 2908 | attrib_parser.stencil_size != 0 && stencil_bits > 0; |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2909 | } |
dongseong.hwang | 4c04a16 | 2015-03-04 07:27:33 | [diff] [blame] | 2910 | |
| 2911 | state_.viewport_width = surface->GetSize().width(); |
| 2912 | state_.viewport_height = surface->GetSize().height(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 2913 | } |
| 2914 | |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2915 | // OpenGL ES 2.0 implicitly enables the desktop GL capability |
| 2916 | // VERTEX_PROGRAM_POINT_SIZE and doesn't expose this enum. This fact |
| 2917 | // isn't well documented; it was discovered in the Khronos OpenGL ES |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2918 | // mailing list archives. It also implicitly enables the desktop GL |
| 2919 | // capability GL_POINT_SPRITE to provide access to the gl_PointCoord |
| 2920 | // variable in fragment shaders. |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 2921 | if (!feature_info_->gl_version_info().BehavesLikeGLES()) { |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2922 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); |
[email protected] | c1d82b6 | 2010-09-20 22:43:37 | [diff] [blame] | 2923 | glEnable(GL_POINT_SPRITE); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 2924 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2925 | |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2926 | has_robustness_extension_ = |
| 2927 | context->HasExtension("GL_ARB_robustness") || |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 2928 | context->HasExtension("GL_KHR_robustness") || |
[email protected] | 706b69f | 2012-07-27 04:59:30 | [diff] [blame] | 2929 | context->HasExtension("GL_EXT_robustness"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 2930 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 2931 | if (!InitializeShaderTranslator()) { |
| 2932 | return false; |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 2933 | } |
[email protected] | 76a0ee10 | 2010-04-07 21:03:04 | [diff] [blame] | 2934 | |
[email protected] | 5904806b | 2012-05-08 18:10:22 | [diff] [blame] | 2935 | GLint viewport_params[4] = { 0 }; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2936 | glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 2937 | viewport_max_width_ = viewport_params[0]; |
| 2938 | viewport_max_height_ = viewport_params[1]; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 2939 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 2940 | state_.scissor_width = state_.viewport_width; |
| 2941 | state_.scissor_height = state_.viewport_height; |
| 2942 | |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2943 | // Set all the default state because some GL drivers get it wrong. |
[email protected] | 88ba52f | 2014-04-09 12:39:34 | [diff] [blame] | 2944 | state_.InitCapabilities(NULL); |
| 2945 | state_.InitState(NULL); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 2946 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2947 | |
| 2948 | DoBindBuffer(GL_ARRAY_BUFFER, 0); |
| 2949 | DoBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 2950 | DoBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 2951 | DoBindRenderbuffer(GL_RENDERBUFFER, 0); |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 2952 | DoBindValueBufferCHROMIUM(GL_SUBSCRIBED_VALUES_BUFFER_CHROMIUM, 0); |
[email protected] | 11f3e70 | 2012-06-19 19:00:01 | [diff] [blame] | 2953 | |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 2954 | bool call_gl_clear = !surfaceless_; |
[email protected] | 88cfd13 | 2013-07-11 00:59:00 | [diff] [blame] | 2955 | #if defined(OS_ANDROID) |
| 2956 | // Temporary workaround for Android WebView because this clear ignores the |
| 2957 | // clip and corrupts that external UI of the App. Not calling glClear is ok |
| 2958 | // because the system already clears the buffer before each draw. Proper |
| 2959 | // fix might be setting the scissor clip properly before initialize. See |
| 2960 | // crbug.com/259023 for details. |
| 2961 | call_gl_clear = surface_->GetHandle(); |
| 2962 | #endif |
| 2963 | if (call_gl_clear) { |
jmadill | 653daa7 | 2015-05-06 20:29:04 | [diff] [blame] | 2964 | // On configs where we report no alpha, if the underlying surface has |
| 2965 | // alpha, clear the surface alpha to 1.0 to be correct on ReadPixels/etc. |
| 2966 | bool clear_alpha = back_buffer_color_format_ == GL_RGB && alpha_bits > 0; |
| 2967 | if (clear_alpha) { |
| 2968 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 2969 | } |
| 2970 | |
[email protected] | 88cfd13 | 2013-07-11 00:59:00 | [diff] [blame] | 2971 | // Clear the backbuffer. |
| 2972 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
jmadill | 653daa7 | 2015-05-06 20:29:04 | [diff] [blame] | 2973 | |
| 2974 | // Restore alpha clear value if we changed it. |
| 2975 | if (clear_alpha) { |
| 2976 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
| 2977 | } |
[email protected] | 88cfd13 | 2013-07-11 00:59:00 | [diff] [blame] | 2978 | } |
[email protected] | 561cc0a6 | 2013-05-07 18:34:45 | [diff] [blame] | 2979 | |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 2980 | supports_post_sub_buffer_ = surface->SupportsPostSubBuffer(); |
| 2981 | if (feature_info_->workarounds() |
| 2982 | .disable_post_sub_buffers_for_onscreen_surfaces && |
| 2983 | !surface->IsOffscreen()) |
| 2984 | supports_post_sub_buffer_ = false; |
| 2985 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 2986 | if (feature_info_->workarounds().reverse_point_sprite_coord_origin) { |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2987 | glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT); |
| 2988 | } |
[email protected] | dd289a5d6 | 2012-06-30 22:05:46 | [diff] [blame] | 2989 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 2990 | if (feature_info_->workarounds().unbind_fbo_on_context_switch) { |
| 2991 | context_->SetUnbindFboOnMakeCurrent(); |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2992 | } |
[email protected] | 85cb468 | 2013-04-20 00:54:24 | [diff] [blame] | 2993 | |
[email protected] | 97419c0 | 2013-04-10 02:52:38 | [diff] [blame] | 2994 | // Only compositor contexts are known to use only the subset of GL |
| 2995 | // that can be safely migrated between the iGPU and the dGPU. Mark |
| 2996 | // those contexts as safe to forcibly transition between the GPUs. |
| 2997 | // http://crbug.com/180876, http://crbug.com/227228 |
| 2998 | if (!offscreen) |
| 2999 | context_->SetSafeToForceGpuSwitch(); |
| 3000 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3001 | async_pixel_transfer_manager_.reset( |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 3002 | AsyncPixelTransferManager::Create(context.get())); |
| 3003 | async_pixel_transfer_manager_->Initialize(texture_manager()); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 3004 | |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 3005 | if (workarounds().gl_clear_broken) { |
| 3006 | DCHECK(!clear_framebuffer_blit_.get()); |
| 3007 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glClearWorkaroundInit"); |
| 3008 | clear_framebuffer_blit_.reset(new ClearFramebufferResourceManager(this)); |
| 3009 | if (LOCAL_PEEK_GL_ERROR("glClearWorkaroundInit") != GL_NO_ERROR) |
| 3010 | return false; |
| 3011 | } |
| 3012 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 3013 | framebuffer_manager()->AddObserver(this); |
| 3014 | |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 3015 | return true; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3016 | } |
| 3017 | |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3018 | Capabilities GLES2DecoderImpl::GetCapabilities() { |
| 3019 | DCHECK(initialized()); |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3020 | Capabilities caps; |
piman | 1c2e0a85 | 2014-11-12 05:17:55 | [diff] [blame] | 3021 | caps.VisitPrecisions([](GLenum shader, GLenum type, |
| 3022 | Capabilities::ShaderPrecision* shader_precision) { |
| 3023 | GLint range[2] = {0, 0}; |
| 3024 | GLint precision = 0; |
| 3025 | GetShaderPrecisionFormatImpl(shader, type, range, &precision); |
| 3026 | shader_precision->min_range = range[0]; |
| 3027 | shader_precision->max_range = range[1]; |
| 3028 | shader_precision->precision = precision; |
| 3029 | }); |
| 3030 | DoGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, |
| 3031 | &caps.max_combined_texture_image_units); |
| 3032 | DoGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &caps.max_cube_map_texture_size); |
| 3033 | DoGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_VECTORS, |
| 3034 | &caps.max_fragment_uniform_vectors); |
| 3035 | DoGetIntegerv(GL_MAX_RENDERBUFFER_SIZE, &caps.max_renderbuffer_size); |
| 3036 | DoGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &caps.max_texture_image_units); |
| 3037 | DoGetIntegerv(GL_MAX_TEXTURE_SIZE, &caps.max_texture_size); |
| 3038 | DoGetIntegerv(GL_MAX_VARYING_VECTORS, &caps.max_varying_vectors); |
| 3039 | DoGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &caps.max_vertex_attribs); |
| 3040 | DoGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, |
| 3041 | &caps.max_vertex_texture_image_units); |
| 3042 | DoGetIntegerv(GL_MAX_VERTEX_UNIFORM_VECTORS, |
| 3043 | &caps.max_vertex_uniform_vectors); |
| 3044 | DoGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, |
| 3045 | &caps.num_compressed_texture_formats); |
| 3046 | DoGetIntegerv(GL_NUM_SHADER_BINARY_FORMATS, &caps.num_shader_binary_formats); |
| 3047 | DoGetIntegerv(GL_BIND_GENERATES_RESOURCE_CHROMIUM, |
| 3048 | &caps.bind_generates_resource_chromium); |
heejin.r.chung | 8f14329 | 2015-02-05 02:44:00 | [diff] [blame] | 3049 | if (unsafe_es3_apis_enabled()) { |
zmo | ba1fe9d2 | 2015-04-15 21:42:51 | [diff] [blame] | 3050 | // TODO(zmo): Note that some parameter values could be more than 32-bit, |
| 3051 | // but for now we clamp them to 32-bit max. |
| 3052 | DoGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &caps.max_3d_texture_size); |
| 3053 | DoGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &caps.max_array_texture_layers); |
| 3054 | DoGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &caps.max_color_attachments); |
zmo | 0e679b2 | 2015-05-19 00:26:33 | [diff] [blame] | 3055 | DoGetInteger64v(GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS, |
| 3056 | &caps.max_combined_fragment_uniform_components); |
zmo | ba1fe9d2 | 2015-04-15 21:42:51 | [diff] [blame] | 3057 | DoGetIntegerv(GL_MAX_COMBINED_UNIFORM_BLOCKS, |
| 3058 | &caps.max_combined_uniform_blocks); |
zmo | 0e679b2 | 2015-05-19 00:26:33 | [diff] [blame] | 3059 | DoGetInteger64v(GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS, |
| 3060 | &caps.max_combined_vertex_uniform_components); |
zmo | ba1fe9d2 | 2015-04-15 21:42:51 | [diff] [blame] | 3061 | DoGetIntegerv(GL_MAX_DRAW_BUFFERS, &caps.max_draw_buffers); |
zmo | 0e679b2 | 2015-05-19 00:26:33 | [diff] [blame] | 3062 | DoGetInteger64v(GL_MAX_ELEMENT_INDEX, &caps.max_element_index); |
zmo | ba1fe9d2 | 2015-04-15 21:42:51 | [diff] [blame] | 3063 | DoGetIntegerv(GL_MAX_ELEMENTS_INDICES, &caps.max_elements_indices); |
| 3064 | DoGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &caps.max_elements_vertices); |
| 3065 | DoGetIntegerv(GL_MAX_FRAGMENT_INPUT_COMPONENTS, |
| 3066 | &caps.max_fragment_input_components); |
| 3067 | DoGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, |
| 3068 | &caps.max_fragment_uniform_blocks); |
| 3069 | DoGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, |
| 3070 | &caps.max_fragment_uniform_components); |
| 3071 | DoGetIntegerv(GL_MAX_PROGRAM_TEXEL_OFFSET, |
| 3072 | &caps.max_program_texel_offset); |
zmo | 0e679b2 | 2015-05-19 00:26:33 | [diff] [blame] | 3073 | DoGetInteger64v(GL_MAX_SERVER_WAIT_TIMEOUT, &caps.max_server_wait_timeout); |
| 3074 | // Work around Linux NVIDIA driver bug where GL_TIMEOUT_IGNORED is |
| 3075 | // returned. |
| 3076 | if (caps.max_server_wait_timeout < 0) |
| 3077 | caps.max_server_wait_timeout = 0; |
| 3078 | DoGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &caps.max_texture_lod_bias); |
zmo | ba1fe9d2 | 2015-04-15 21:42:51 | [diff] [blame] | 3079 | DoGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, |
| 3080 | &caps.max_transform_feedback_interleaved_components); |
heejin.r.chung | 8f14329 | 2015-02-05 02:44:00 | [diff] [blame] | 3081 | DoGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS, |
| 3082 | &caps.max_transform_feedback_separate_attribs); |
zmo | ba1fe9d2 | 2015-04-15 21:42:51 | [diff] [blame] | 3083 | DoGetIntegerv(GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS, |
| 3084 | &caps.max_transform_feedback_separate_components); |
zmo | 0e679b2 | 2015-05-19 00:26:33 | [diff] [blame] | 3085 | DoGetInteger64v(GL_MAX_UNIFORM_BLOCK_SIZE, &caps.max_uniform_block_size); |
heejin.r.chung | 8f14329 | 2015-02-05 02:44:00 | [diff] [blame] | 3086 | DoGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, |
| 3087 | &caps.max_uniform_buffer_bindings); |
zmo | ba1fe9d2 | 2015-04-15 21:42:51 | [diff] [blame] | 3088 | DoGetIntegerv(GL_MAX_VARYING_COMPONENTS, &caps.max_varying_components); |
| 3089 | DoGetIntegerv(GL_MAX_VERTEX_OUTPUT_COMPONENTS, |
| 3090 | &caps.max_vertex_output_components); |
| 3091 | DoGetIntegerv(GL_MAX_VERTEX_UNIFORM_BLOCKS, |
| 3092 | &caps.max_vertex_uniform_blocks); |
| 3093 | DoGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, |
| 3094 | &caps.max_vertex_uniform_components); |
| 3095 | DoGetIntegerv(GL_MIN_PROGRAM_TEXEL_OFFSET, &caps.min_program_texel_offset); |
| 3096 | DoGetIntegerv(GL_NUM_EXTENSIONS, &caps.num_extensions); |
| 3097 | DoGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, |
| 3098 | &caps.num_program_binary_formats); |
heejin.r.chung | 8f14329 | 2015-02-05 02:44:00 | [diff] [blame] | 3099 | DoGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, |
| 3100 | &caps.uniform_buffer_offset_alignment); |
zmo | ba1fe9d2 | 2015-04-15 21:42:51 | [diff] [blame] | 3101 | // TODO(zmo): once we switch to MANGLE, we should query version numbers. |
| 3102 | caps.major_version = 3; |
| 3103 | caps.minor_version = 0; |
heejin.r.chung | 8f14329 | 2015-02-05 02:44:00 | [diff] [blame] | 3104 | } |
senorblanco | 0aecd69f | 2015-05-01 18:24:05 | [diff] [blame] | 3105 | if (feature_info_->feature_flags().multisampled_render_to_texture || |
| 3106 | feature_info_->feature_flags().chromium_framebuffer_multisample || |
| 3107 | unsafe_es3_apis_enabled()) { |
| 3108 | DoGetIntegerv(GL_MAX_SAMPLES, &caps.max_samples); |
| 3109 | } |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3110 | |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3111 | caps.egl_image_external = |
| 3112 | feature_info_->feature_flags().oes_egl_image_external; |
christiank | 07b6d8b | 2015-02-25 09:41:25 | [diff] [blame] | 3113 | caps.texture_format_atc = |
| 3114 | feature_info_->feature_flags().ext_texture_format_atc; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3115 | caps.texture_format_bgra8888 = |
| 3116 | feature_info_->feature_flags().ext_texture_format_bgra8888; |
christiank | 07b6d8b | 2015-02-25 09:41:25 | [diff] [blame] | 3117 | caps.texture_format_dxt1 = |
| 3118 | feature_info_->feature_flags().ext_texture_format_dxt1; |
| 3119 | caps.texture_format_dxt5 = |
| 3120 | feature_info_->feature_flags().ext_texture_format_dxt5; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3121 | caps.texture_format_etc1 = |
| 3122 | feature_info_->feature_flags().oes_compressed_etc1_rgb8_texture; |
aelias | d880a3d | 2014-08-26 00:46:20 | [diff] [blame] | 3123 | caps.texture_format_etc1_npot = |
| 3124 | caps.texture_format_etc1 && !workarounds().etc1_power_of_two_only; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3125 | caps.texture_rectangle = feature_info_->feature_flags().arb_texture_rectangle; |
| 3126 | caps.texture_usage = feature_info_->feature_flags().angle_texture_usage; |
| 3127 | caps.texture_storage = feature_info_->feature_flags().ext_texture_storage; |
| 3128 | caps.discard_framebuffer = |
| 3129 | feature_info_->feature_flags().ext_discard_framebuffer; |
[email protected] | 12c99ab0 | 2014-04-22 10:12:35 | [diff] [blame] | 3130 | caps.sync_query = feature_info_->feature_flags().chromium_sync_query; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3131 | |
| 3132 | #if defined(OS_MACOSX) |
| 3133 | // This is unconditionally true on mac, no need to test for it at runtime. |
| 3134 | caps.iosurface = true; |
| 3135 | #endif |
| 3136 | |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 3137 | caps.post_sub_buffer = supports_post_sub_buffer_; |
reveman | 34010918 | 2014-09-30 15:36:45 | [diff] [blame] | 3138 | caps.image = true; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3139 | |
ed | 9198b42 | 2014-10-23 15:01:37 | [diff] [blame] | 3140 | caps.blend_equation_advanced = |
| 3141 | feature_info_->feature_flags().blend_equation_advanced; |
| 3142 | caps.blend_equation_advanced_coherent = |
| 3143 | feature_info_->feature_flags().blend_equation_advanced_coherent; |
hendrikw | fc25ca619 | 2014-12-02 06:05:13 | [diff] [blame] | 3144 | caps.texture_rg = feature_info_->feature_flags().ext_texture_rg; |
reveman | e92ab03 | 2015-06-10 01:39:26 | [diff] [blame] | 3145 | caps.max_copy_texture_chromium_size = |
| 3146 | feature_info_->workarounds().max_copy_texture_chromium_size; |
hendrikw | 31692185 | 2015-06-19 23:45:43 | [diff] [blame] | 3147 | caps.render_buffer_format_bgra8888 = |
| 3148 | feature_info_->feature_flags().ext_render_buffer_format_bgra8888; |
[email protected] | 6d66889 | 2013-12-04 21:37:12 | [diff] [blame] | 3149 | return caps; |
| 3150 | } |
| 3151 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 3152 | void GLES2DecoderImpl::UpdateCapabilities() { |
| 3153 | util_.set_num_compressed_texture_formats( |
| 3154 | validators_->compressed_texture_format.GetValues().size()); |
| 3155 | util_.set_num_shader_binary_formats( |
| 3156 | validators_->shader_binary_format.GetValues().size()); |
| 3157 | } |
| 3158 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 3159 | bool GLES2DecoderImpl::InitializeShaderTranslator() { |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 3160 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::InitializeShaderTranslator"); |
| 3161 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 3162 | if (!use_shader_translator_) { |
| 3163 | return true; |
| 3164 | } |
| 3165 | ShBuiltInResources resources; |
| 3166 | ShInitBuiltInResources(&resources); |
| 3167 | resources.MaxVertexAttribs = group_->max_vertex_attribs(); |
| 3168 | resources.MaxVertexUniformVectors = |
| 3169 | group_->max_vertex_uniform_vectors(); |
| 3170 | resources.MaxVaryingVectors = group_->max_varying_vectors(); |
| 3171 | resources.MaxVertexTextureImageUnits = |
| 3172 | group_->max_vertex_texture_image_units(); |
| 3173 | resources.MaxCombinedTextureImageUnits = group_->max_texture_units(); |
| 3174 | resources.MaxTextureImageUnits = group_->max_texture_image_units(); |
| 3175 | resources.MaxFragmentUniformVectors = |
| 3176 | group_->max_fragment_uniform_vectors(); |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 3177 | resources.MaxDrawBuffers = group_->max_draw_buffers(); |
[email protected] | a0b7814 | 2013-05-23 00:47:24 | [diff] [blame] | 3178 | resources.MaxExpressionComplexity = 256; |
| 3179 | resources.MaxCallStackDepth = 256; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 3180 | |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 3181 | GLint range[2] = { 0, 0 }; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 3182 | GLint precision = 0; |
| 3183 | GetShaderPrecisionFormatImpl(GL_FRAGMENT_SHADER, GL_HIGH_FLOAT, |
| 3184 | range, &precision); |
[email protected] | 448e459e | 2013-06-12 17:00:41 | [diff] [blame] | 3185 | resources.FragmentPrecisionHigh = |
| 3186 | PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision); |
[email protected] | 9e98f61b | 2013-03-05 02:21:14 | [diff] [blame] | 3187 | |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 3188 | if (IsWebGLContext()) { |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 3189 | resources.OES_standard_derivatives = derivatives_explicitly_enabled_; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 3190 | resources.EXT_frag_depth = frag_depth_explicitly_enabled_; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 3191 | resources.EXT_draw_buffers = draw_buffers_explicitly_enabled_; |
[email protected] | cd8f189 | 2013-09-05 00:14:44 | [diff] [blame] | 3192 | if (!draw_buffers_explicitly_enabled_) |
| 3193 | resources.MaxDrawBuffers = 1; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 3194 | resources.EXT_shader_texture_lod = shader_texture_lod_explicitly_enabled_; |
oetuaho | 0decd44 | 2014-10-13 08:40:46 | [diff] [blame] | 3195 | resources.NV_draw_buffers = |
| 3196 | draw_buffers_explicitly_enabled_ && features().nv_draw_buffers; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 3197 | } else { |
| 3198 | resources.OES_standard_derivatives = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3199 | features().oes_standard_derivatives ? 1 : 0; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3200 | resources.ARB_texture_rectangle = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3201 | features().arb_texture_rectangle ? 1 : 0; |
[email protected] | 70e7bb1 | 2012-09-29 14:01:06 | [diff] [blame] | 3202 | resources.OES_EGL_image_external = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3203 | features().oes_egl_image_external ? 1 : 0; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 3204 | resources.EXT_draw_buffers = |
| 3205 | features().ext_draw_buffers ? 1 : 0; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 3206 | resources.EXT_frag_depth = |
| 3207 | features().ext_frag_depth ? 1 : 0; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 3208 | resources.EXT_shader_texture_lod = |
| 3209 | features().ext_shader_texture_lod ? 1 : 0; |
oetuaho | 0decd44 | 2014-10-13 08:40:46 | [diff] [blame] | 3210 | resources.NV_draw_buffers = |
| 3211 | features().nv_draw_buffers ? 1 : 0; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 3212 | } |
| 3213 | |
zmo | 0ee1586 | 2015-03-04 03:50:18 | [diff] [blame] | 3214 | ShShaderSpec shader_spec; |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 3215 | if (IsWebGLContext()) { |
| 3216 | shader_spec = webgl_version_ == 2 ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC; |
zmo | 0ee1586 | 2015-03-04 03:50:18 | [diff] [blame] | 3217 | } else { |
| 3218 | shader_spec = unsafe_es3_apis_enabled() ? SH_GLES3_SPEC : SH_GLES2_SPEC; |
| 3219 | } |
| 3220 | |
| 3221 | if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) && |
| 3222 | features().enable_shader_name_hashing) |
[email protected] | 3d944a8 | 2013-02-12 19:09:02 | [diff] [blame] | 3223 | resources.HashFunction = &CityHash64; |
[email protected] | 6aedcdc | 2013-01-24 01:25:05 | [diff] [blame] | 3224 | else |
| 3225 | resources.HashFunction = NULL; |
[email protected] | a2a0fe76 | 2011-09-20 00:59:12 | [diff] [blame] | 3226 | ShaderTranslatorInterface::GlslImplementationType implementation_type = |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 3227 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? |
| 3228 | ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 3229 | int driver_bug_workarounds = 0; |
| 3230 | if (workarounds().needs_glsl_built_in_function_emulation) |
| 3231 | driver_bug_workarounds |= SH_EMULATE_BUILT_IN_FUNCTIONS; |
[email protected] | 81187c6 | 2013-09-09 23:54:54 | [diff] [blame] | 3232 | if (workarounds().init_gl_position_in_vertex_shader) |
| 3233 | driver_bug_workarounds |= SH_INIT_GL_POSITION; |
[email protected] | f0c8760 | 2013-10-17 19:34:11 | [diff] [blame] | 3234 | if (workarounds().unfold_short_circuit_as_ternary_operation) |
| 3235 | driver_bug_workarounds |= SH_UNFOLD_SHORT_CIRCUIT; |
[email protected] | b03219d | 2014-02-12 11:17:05 | [diff] [blame] | 3236 | if (workarounds().init_varyings_without_static_use) |
| 3237 | driver_bug_workarounds |= SH_INIT_VARYINGS_WITHOUT_STATIC_USE; |
[email protected] | f4db2b1 | 2014-03-01 03:57:06 | [diff] [blame] | 3238 | if (workarounds().unroll_for_loop_with_sampler_array_index) |
| 3239 | driver_bug_workarounds |= SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX; |
[email protected] | 711e9080 | 2014-07-22 20:40:25 | [diff] [blame] | 3240 | if (workarounds().scalarize_vec_and_mat_constructor_args) |
| 3241 | driver_bug_workarounds |= SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS; |
[email protected] | fa6d398 | 2014-08-18 18:10:27 | [diff] [blame] | 3242 | if (workarounds().regenerate_struct_names) |
| 3243 | driver_bug_workarounds |= SH_REGENERATE_STRUCT_NAMES; |
oetuaho | 6458e05 | 2015-06-04 17:46:27 | [diff] [blame] | 3244 | if (workarounds().remove_pow_with_constant_exponent) |
| 3245 | driver_bug_workarounds |= SH_REMOVE_POW_WITH_CONSTANT_EXPONENT; |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 3246 | |
avi | 9ab03720 | 2014-12-22 23:49:53 | [diff] [blame] | 3247 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 3248 | switches::kEmulateShaderPrecision)) |
oetuaho | affd85abe | 2014-12-11 09:47:09 | [diff] [blame] | 3249 | resources.WEBGL_debug_shader_precision = true; |
| 3250 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 3251 | vertex_translator_ = shader_translator_cache()->GetTranslator( |
[email protected] | aeecc6b | 2014-07-03 17:18:26 | [diff] [blame] | 3252 | GL_VERTEX_SHADER, |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 3253 | shader_spec, |
| 3254 | &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 3255 | implementation_type, |
| 3256 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 3257 | if (!vertex_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 3258 | LOG(ERROR) << "Could not initialize vertex shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3259 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 3260 | return false; |
| 3261 | } |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 3262 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 3263 | fragment_translator_ = shader_translator_cache()->GetTranslator( |
[email protected] | aeecc6b | 2014-07-03 17:18:26 | [diff] [blame] | 3264 | GL_FRAGMENT_SHADER, |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 3265 | shader_spec, |
| 3266 | &resources, |
[email protected] | a6739bc | 2013-09-07 04:45:21 | [diff] [blame] | 3267 | implementation_type, |
| 3268 | static_cast<ShCompileOptions>(driver_bug_workarounds)); |
[email protected] | 87fb6ab | 2012-06-13 22:28:04 | [diff] [blame] | 3269 | if (!fragment_translator_.get()) { |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 3270 | LOG(ERROR) << "Could not initialize fragment shader translator."; |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3271 | Destroy(true); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 3272 | return false; |
| 3273 | } |
| 3274 | return true; |
| 3275 | } |
| 3276 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3277 | bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3278 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3279 | if (GetBuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3280 | return false; |
| 3281 | } |
| 3282 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 3283 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3284 | glGenBuffersARB(n, service_ids.get()); |
| 3285 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3286 | CreateBuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3287 | } |
| 3288 | return true; |
| 3289 | } |
| 3290 | |
| 3291 | bool GLES2DecoderImpl::GenFramebuffersHelper( |
| 3292 | GLsizei n, const GLuint* client_ids) { |
| 3293 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3294 | if (GetFramebuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3295 | return false; |
| 3296 | } |
| 3297 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 3298 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3299 | glGenFramebuffersEXT(n, service_ids.get()); |
| 3300 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3301 | CreateFramebuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3302 | } |
| 3303 | return true; |
| 3304 | } |
| 3305 | |
| 3306 | bool GLES2DecoderImpl::GenRenderbuffersHelper( |
| 3307 | GLsizei n, const GLuint* client_ids) { |
| 3308 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3309 | if (GetRenderbuffer(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3310 | return false; |
| 3311 | } |
| 3312 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 3313 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3314 | glGenRenderbuffersEXT(n, service_ids.get()); |
| 3315 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3316 | CreateRenderbuffer(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3317 | } |
| 3318 | return true; |
| 3319 | } |
| 3320 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 3321 | bool GLES2DecoderImpl::GenValuebuffersCHROMIUMHelper(GLsizei n, |
| 3322 | const GLuint* client_ids) { |
| 3323 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3324 | if (GetValuebuffer(client_ids[ii])) { |
| 3325 | return false; |
| 3326 | } |
| 3327 | } |
| 3328 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3329 | CreateValuebuffer(client_ids[ii]); |
| 3330 | } |
| 3331 | return true; |
| 3332 | } |
| 3333 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3334 | bool GLES2DecoderImpl::GenTexturesHelper(GLsizei n, const GLuint* client_ids) { |
| 3335 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3336 | if (GetTexture(client_ids[ii])) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3337 | return false; |
| 3338 | } |
| 3339 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 3340 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3341 | glGenTextures(n, service_ids.get()); |
| 3342 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3343 | CreateTexture(client_ids[ii], service_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3344 | } |
| 3345 | return true; |
| 3346 | } |
| 3347 | |
| 3348 | void GLES2DecoderImpl::DeleteBuffersHelper( |
| 3349 | GLsizei n, const GLuint* client_ids) { |
| 3350 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 3351 | Buffer* buffer = GetBuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3352 | if (buffer && !buffer->IsDeleted()) { |
zmo | 2a09dc05 | 2015-03-12 00:48:25 | [diff] [blame] | 3353 | buffer->RemoveMappedRange(); |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 3354 | state_.RemoveBoundBuffer(buffer); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3355 | RemoveBuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3356 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3357 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3358 | } |
| 3359 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3360 | void GLES2DecoderImpl::DeleteFramebuffersHelper( |
| 3361 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3362 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3363 | features().chromium_framebuffer_multisample; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3364 | |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 3365 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3366 | Framebuffer* framebuffer = |
| 3367 | GetFramebuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3368 | if (framebuffer && !framebuffer->IsDeleted()) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3369 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3370 | GLenum target = supports_separate_framebuffer_binds ? |
| 3371 | GL_DRAW_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
vmiura | 7d08fee5 | 2015-02-18 18:39:34 | [diff] [blame] | 3372 | |
| 3373 | // Unbind attachments on FBO before deletion. |
| 3374 | if (workarounds().unbind_attachments_on_bound_render_fbo_delete) |
| 3375 | framebuffer->DoUnbindGLAttachmentsForWorkaround(target); |
| 3376 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3377 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
vmiura | 7d08fee5 | 2015-02-18 18:39:34 | [diff] [blame] | 3378 | framebuffer_state_.bound_draw_framebuffer = NULL; |
| 3379 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3380 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3381 | if (framebuffer == framebuffer_state_.bound_read_framebuffer.get()) { |
| 3382 | framebuffer_state_.bound_read_framebuffer = NULL; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3383 | GLenum target = supports_separate_framebuffer_binds ? |
| 3384 | GL_READ_FRAMEBUFFER_EXT : GL_FRAMEBUFFER; |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 3385 | glBindFramebufferEXT(target, GetBackbufferServiceId()); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3386 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3387 | OnFboChanged(); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3388 | RemoveFramebuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3389 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 3390 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3391 | } |
| 3392 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3393 | void GLES2DecoderImpl::DeleteRenderbuffersHelper( |
| 3394 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3395 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3396 | features().chromium_framebuffer_multisample; |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 3397 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3398 | Renderbuffer* renderbuffer = |
| 3399 | GetRenderbuffer(client_ids[ii]); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3400 | if (renderbuffer && !renderbuffer->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3401 | if (state_.bound_renderbuffer.get() == renderbuffer) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3402 | state_.bound_renderbuffer = NULL; |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3403 | } |
| 3404 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3405 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3406 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 3407 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3408 | ->UnbindRenderbuffer(GL_READ_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3409 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3410 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3411 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3412 | ->UnbindRenderbuffer(GL_DRAW_FRAMEBUFFER_EXT, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3413 | } |
| 3414 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3415 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3416 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3417 | ->UnbindRenderbuffer(GL_FRAMEBUFFER, renderbuffer); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3418 | } |
| 3419 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3420 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3421 | RemoveRenderbuffer(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3422 | } |
[email protected] | a25fa87 | 2010-03-25 02:57:58 | [diff] [blame] | 3423 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3424 | } |
| 3425 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 3426 | void GLES2DecoderImpl::DeleteValuebuffersCHROMIUMHelper( |
| 3427 | GLsizei n, |
| 3428 | const GLuint* client_ids) { |
| 3429 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 3430 | Valuebuffer* valuebuffer = GetValuebuffer(client_ids[ii]); |
| 3431 | if (valuebuffer) { |
| 3432 | if (state_.bound_valuebuffer.get() == valuebuffer) { |
| 3433 | state_.bound_valuebuffer = NULL; |
| 3434 | } |
| 3435 | RemoveValuebuffer(client_ids[ii]); |
| 3436 | } |
| 3437 | } |
| 3438 | } |
| 3439 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3440 | void GLES2DecoderImpl::DeleteTexturesHelper( |
| 3441 | GLsizei n, const GLuint* client_ids) { |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3442 | bool supports_separate_framebuffer_binds = |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3443 | features().chromium_framebuffer_multisample; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3444 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3445 | TextureRef* texture_ref = GetTexture(client_ids[ii]); |
| 3446 | if (texture_ref) { |
| 3447 | Texture* texture = texture_ref->texture(); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3448 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3449 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3450 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3451 | // Unbind texture_ref from texture_ref units. |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3452 | for (size_t jj = 0; jj < state_.texture_units.size(); ++jj) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3453 | state_.texture_units[jj].Unbind(texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3454 | } |
| 3455 | // Unbind from current framebuffers. |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3456 | if (supports_separate_framebuffer_binds) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3457 | if (framebuffer_state_.bound_read_framebuffer.get()) { |
| 3458 | framebuffer_state_.bound_read_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3459 | ->UnbindTexture(GL_READ_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3460 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3461 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3462 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3463 | ->UnbindTexture(GL_DRAW_FRAMEBUFFER_EXT, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3464 | } |
| 3465 | } else { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3466 | if (framebuffer_state_.bound_draw_framebuffer.get()) { |
| 3467 | framebuffer_state_.bound_draw_framebuffer |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3468 | ->UnbindTexture(GL_FRAMEBUFFER, texture_ref); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3469 | } |
| 3470 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3471 | #if defined(OS_MACOSX) |
[email protected] | 4f995814 | 2013-07-02 03:58:07 | [diff] [blame] | 3472 | GLuint service_id = texture->service_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3473 | if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { |
| 3474 | ReleaseIOSurfaceForTexture(service_id); |
| 3475 | } |
| 3476 | #endif |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3477 | RemoveTexture(client_ids[ii]); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 3478 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 3479 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 3480 | } |
| 3481 | |
[email protected] | 43f28f83 | 2010-02-03 02:28:48 | [diff] [blame] | 3482 | // } // anonymous namespace |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 3483 | |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 3484 | bool GLES2DecoderImpl::MakeCurrent() { |
[email protected] | 177d134 | 2013-12-07 04:20:34 | [diff] [blame] | 3485 | if (!context_.get()) |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3486 | return false; |
| 3487 | |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 3488 | if (WasContextLost()) { |
| 3489 | LOG(ERROR) << " GLES2DecoderImpl: Trying to make lost context current."; |
| 3490 | return false; |
| 3491 | } |
| 3492 | |
| 3493 | if (!context_->MakeCurrent(surface_.get())) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 3494 | LOG(ERROR) << " GLES2DecoderImpl: Context lost during MakeCurrent."; |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 3495 | MarkContextLost(error::kMakeCurrentFailed); |
| 3496 | group_->LoseContexts(error::kUnknown); |
| 3497 | return false; |
| 3498 | } |
[email protected] | e9f0ca8 | 2013-04-01 23:52:29 | [diff] [blame] | 3499 | |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 3500 | if (CheckResetStatus()) { |
| 3501 | LOG(ERROR) |
| 3502 | << " GLES2DecoderImpl: Context reset detected after MakeCurrent."; |
| 3503 | group_->LoseContexts(error::kUnknown); |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3504 | return false; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 3505 | } |
| 3506 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 3507 | ProcessFinishedAsyncTransfers(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 3508 | |
[email protected] | 9b75399 | 2013-04-27 02:04:41 | [diff] [blame] | 3509 | // Rebind the FBO if it was unbound by the context. |
| 3510 | if (workarounds().unbind_fbo_on_context_switch) |
| 3511 | RestoreFramebufferBindings(); |
| 3512 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3513 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3514 | |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 3515 | return true; |
| 3516 | } |
| 3517 | |
| 3518 | void GLES2DecoderImpl::ProcessFinishedAsyncTransfers() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 3519 | ProcessPendingReadPixels(); |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 3520 | if (engine() && query_manager_.get()) |
| 3521 | query_manager_->ProcessPendingTransferQueries(); |
| 3522 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 3523 | // TODO(epenner): Is there a better place to do this? |
| 3524 | // This needs to occur before we execute any batch of commands |
| 3525 | // from the client, as the client may have recieved an async |
| 3526 | // completion while issuing those commands. |
| 3527 | // "DidFlushStart" would be ideal if we had such a callback. |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3528 | async_pixel_transfer_manager_->BindCompletedAsyncTransfers(); |
[email protected] | eb54a56 | 2010-01-20 21:55:18 | [diff] [blame] | 3529 | } |
| 3530 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3531 | static void RebindCurrentFramebuffer( |
| 3532 | GLenum target, |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3533 | Framebuffer* framebuffer, |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3534 | GLuint back_buffer_service_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 3535 | GLuint framebuffer_id = framebuffer ? framebuffer->service_id() : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3536 | |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3537 | if (framebuffer_id == 0) { |
| 3538 | framebuffer_id = back_buffer_service_id; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3539 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3540 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3541 | glBindFramebufferEXT(target, framebuffer_id); |
| 3542 | } |
| 3543 | |
| 3544 | void GLES2DecoderImpl::RestoreCurrentFramebufferBindings() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3545 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3546 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3547 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3548 | RebindCurrentFramebuffer( |
| 3549 | GL_FRAMEBUFFER, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3550 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3551 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3552 | } else { |
| 3553 | RebindCurrentFramebuffer( |
| 3554 | GL_READ_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3555 | framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3556 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3557 | RebindCurrentFramebuffer( |
| 3558 | GL_DRAW_FRAMEBUFFER_EXT, |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3559 | framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | a378371 | 2012-01-20 22:18:24 | [diff] [blame] | 3560 | GetBackbufferServiceId()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3561 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 3562 | OnFboChanged(); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3563 | } |
| 3564 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3565 | bool GLES2DecoderImpl::CheckFramebufferValid( |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3566 | Framebuffer* framebuffer, |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3567 | GLenum target, const char* func_name) { |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 3568 | if (!framebuffer) { |
achaulk | cf5316f | 2014-09-26 19:28:42 | [diff] [blame] | 3569 | if (surfaceless_) |
| 3570 | return false; |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3571 | if (backbuffer_needs_clear_bits_) { |
| 3572 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
pkasting | 45796dc | 2014-10-17 04:18:32 | [diff] [blame] | 3573 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1.f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3574 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3575 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 3576 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 3577 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3578 | glClearDepth(1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 3579 | state_.SetDeviceDepthMask(GL_TRUE); |
| 3580 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 3581 | bool reset_draw_buffer = false; |
brucedawson | 1824915 | 2014-10-31 23:02:32 | [diff] [blame] | 3582 | if ((backbuffer_needs_clear_bits_ & GL_COLOR_BUFFER_BIT) != 0 && |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 3583 | group_->draw_buffer() == GL_NONE) { |
| 3584 | reset_draw_buffer = true; |
| 3585 | GLenum buf = GL_BACK; |
| 3586 | if (GetBackbufferServiceId() != 0) // emulated backbuffer |
| 3587 | buf = GL_COLOR_ATTACHMENT0; |
| 3588 | glDrawBuffersARB(1, &buf); |
| 3589 | } |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3590 | glClear(backbuffer_needs_clear_bits_); |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 3591 | if (reset_draw_buffer) { |
| 3592 | GLenum buf = GL_NONE; |
| 3593 | glDrawBuffersARB(1, &buf); |
| 3594 | } |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 3595 | backbuffer_needs_clear_bits_ = 0; |
| 3596 | RestoreClearState(); |
| 3597 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3598 | return true; |
| 3599 | } |
| 3600 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 3601 | if (framebuffer_manager()->IsComplete(framebuffer)) { |
| 3602 | return true; |
| 3603 | } |
| 3604 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3605 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 3606 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3607 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3608 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, "framebuffer incomplete"); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 3609 | return false; |
| 3610 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3611 | |
| 3612 | // Are all the attachments cleared? |
| 3613 | if (renderbuffer_manager()->HaveUnclearedRenderbuffers() || |
| 3614 | texture_manager()->HaveUnclearedMips()) { |
| 3615 | if (!framebuffer->IsCleared()) { |
| 3616 | // Can we clear them? |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 3617 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 3618 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3619 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3620 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 3621 | "framebuffer incomplete (clear)"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3622 | return false; |
| 3623 | } |
| 3624 | ClearUnclearedAttachments(target, framebuffer); |
| 3625 | } |
| 3626 | } |
| 3627 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 3628 | if (!framebuffer_manager()->IsComplete(framebuffer)) { |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 3629 | if (framebuffer->GetStatus(texture_manager(), target) != |
| 3630 | GL_FRAMEBUFFER_COMPLETE) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 3631 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 3632 | GL_INVALID_FRAMEBUFFER_OPERATION, func_name, |
| 3633 | "framebuffer incomplete (check)"); |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 3634 | return false; |
| 3635 | } |
| 3636 | framebuffer_manager()->MarkAsComplete(framebuffer); |
| 3637 | } |
| 3638 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3639 | // NOTE: At this point we don't know if the framebuffer is complete but |
| 3640 | // we DO know that everything that needs to be cleared has been cleared. |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 3641 | return true; |
| 3642 | } |
| 3643 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3644 | bool GLES2DecoderImpl::CheckBoundFramebuffersValid(const char* func_name) { |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 3645 | if (!features().chromium_framebuffer_multisample) { |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3646 | bool valid = CheckFramebufferValid( |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3647 | framebuffer_state_.bound_draw_framebuffer.get(), GL_FRAMEBUFFER_EXT, |
| 3648 | func_name); |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 3649 | |
| 3650 | if (valid) |
| 3651 | OnUseFramebuffer(); |
| 3652 | |
| 3653 | return valid; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3654 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3655 | return CheckFramebufferValid(framebuffer_state_.bound_draw_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3656 | GL_DRAW_FRAMEBUFFER_EXT, |
| 3657 | func_name) && |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3658 | CheckFramebufferValid(framebuffer_state_.bound_read_framebuffer.get(), |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3659 | GL_READ_FRAMEBUFFER_EXT, |
| 3660 | func_name); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3661 | } |
| 3662 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 3663 | bool GLES2DecoderImpl::CheckBoundReadFramebufferColorAttachment( |
| 3664 | const char* func_name) { |
| 3665 | Framebuffer* framebuffer = features().chromium_framebuffer_multisample ? |
| 3666 | framebuffer_state_.bound_read_framebuffer.get() : |
| 3667 | framebuffer_state_.bound_draw_framebuffer.get(); |
| 3668 | if (!framebuffer) |
| 3669 | return true; |
| 3670 | if (framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0) == NULL) { |
| 3671 | LOCAL_SET_GL_ERROR( |
| 3672 | GL_INVALID_OPERATION, func_name, "no color image attached"); |
| 3673 | return false; |
| 3674 | } |
| 3675 | return true; |
| 3676 | } |
| 3677 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 3678 | bool GLES2DecoderImpl::FormsTextureCopyingFeedbackLoop( |
| 3679 | TextureRef* texture, GLint level) { |
| 3680 | Framebuffer* framebuffer = features().chromium_framebuffer_multisample ? |
| 3681 | framebuffer_state_.bound_read_framebuffer.get() : |
| 3682 | framebuffer_state_.bound_draw_framebuffer.get(); |
| 3683 | if (!framebuffer) |
| 3684 | return false; |
| 3685 | const Framebuffer::Attachment* attachment = framebuffer->GetAttachment( |
| 3686 | GL_COLOR_ATTACHMENT0); |
| 3687 | if (!attachment) |
| 3688 | return false; |
| 3689 | return attachment->FormsFeedbackLoop(texture, level); |
| 3690 | } |
| 3691 | |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 3692 | gfx::Size GLES2DecoderImpl::GetBoundReadFrameBufferSize() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3693 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3694 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3695 | if (framebuffer != NULL) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3696 | const Framebuffer::Attachment* attachment = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3697 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3698 | if (attachment) { |
| 3699 | return gfx::Size(attachment->width(), attachment->height()); |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 3700 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3701 | return gfx::Size(0, 0); |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3702 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3703 | return offscreen_size_; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3704 | } else { |
[email protected] | f62a5ab | 2011-05-23 20:34:15 | [diff] [blame] | 3705 | return surface_->GetSize(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 3706 | } |
[email protected] | 246a7045 | 2010-03-05 21:53:50 | [diff] [blame] | 3707 | } |
| 3708 | |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 3709 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferTextureType() { |
| 3710 | Framebuffer* framebuffer = |
| 3711 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
| 3712 | if (framebuffer != NULL) { |
| 3713 | return framebuffer->GetColorAttachmentTextureType(); |
| 3714 | } else { |
| 3715 | return GL_UNSIGNED_BYTE; |
| 3716 | } |
| 3717 | } |
| 3718 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3719 | GLenum GLES2DecoderImpl::GetBoundReadFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3720 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3721 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3722 | if (framebuffer != NULL) { |
| 3723 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 3724 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3725 | return offscreen_target_color_format_; |
| 3726 | } else { |
| 3727 | return back_buffer_color_format_; |
| 3728 | } |
| 3729 | } |
| 3730 | |
| 3731 | GLenum GLES2DecoderImpl::GetBoundDrawFrameBufferInternalFormat() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 3732 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 3733 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 3734 | if (framebuffer != NULL) { |
| 3735 | return framebuffer->GetColorAttachmentFormat(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3736 | } else if (offscreen_target_frame_buffer_.get()) { |
| 3737 | return offscreen_target_color_format_; |
| 3738 | } else { |
[email protected] | 32fe9aa | 2011-01-21 23:47:13 | [diff] [blame] | 3739 | return back_buffer_color_format_; |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 3743 | void GLES2DecoderImpl::UpdateParentTextureInfo() { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3744 | if (!offscreen_saved_color_texture_info_.get()) |
| 3745 | return; |
| 3746 | GLenum target = offscreen_saved_color_texture_info_->texture()->target(); |
| 3747 | glBindTexture(target, offscreen_saved_color_texture_info_->service_id()); |
| 3748 | texture_manager()->SetLevelInfo( |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 3749 | offscreen_saved_color_texture_info_.get(), GL_TEXTURE_2D, |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3750 | 0, // level |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 3751 | GL_RGBA, offscreen_size_.width(), offscreen_size_.height(), |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3752 | 1, // depth |
| 3753 | 0, // border |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 3754 | GL_RGBA, GL_UNSIGNED_BYTE, gfx::Rect(offscreen_size_)); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3755 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3756 | "UpdateParentTextureInfo", |
| 3757 | GetErrorState(), |
| 3758 | offscreen_saved_color_texture_info_.get(), |
| 3759 | GL_TEXTURE_MAG_FILTER, |
[email protected] | eeeb07b9 | 2014-08-16 07:46:26 | [diff] [blame] | 3760 | GL_LINEAR); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3761 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3762 | "UpdateParentTextureInfo", |
| 3763 | GetErrorState(), |
| 3764 | offscreen_saved_color_texture_info_.get(), |
| 3765 | GL_TEXTURE_MIN_FILTER, |
[email protected] | eeeb07b9 | 2014-08-16 07:46:26 | [diff] [blame] | 3766 | GL_LINEAR); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3767 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3768 | "UpdateParentTextureInfo", |
| 3769 | GetErrorState(), |
| 3770 | offscreen_saved_color_texture_info_.get(), |
| 3771 | GL_TEXTURE_WRAP_S, |
| 3772 | GL_CLAMP_TO_EDGE); |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 3773 | texture_manager()->SetParameteri( |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3774 | "UpdateParentTextureInfo", |
| 3775 | GetErrorState(), |
| 3776 | offscreen_saved_color_texture_info_.get(), |
| 3777 | GL_TEXTURE_WRAP_T, |
| 3778 | GL_CLAMP_TO_EDGE); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3779 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 3780 | &state_, target); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3781 | glBindTexture(target, texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 3782 | } |
| 3783 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 3784 | void GLES2DecoderImpl::SetResizeCallback( |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 3785 | const base::Callback<void(gfx::Size, float)>& callback) { |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 3786 | resize_callback_ = callback; |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 3787 | } |
| 3788 | |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 3789 | Logger* GLES2DecoderImpl::GetLogger() { |
| 3790 | return &logger_; |
[email protected] | 6b6e7ee | 2011-12-13 08:04:52 | [diff] [blame] | 3791 | } |
| 3792 | |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3793 | void GLES2DecoderImpl::BeginDecoding() { |
| 3794 | gpu_tracer_->BeginDecoding(); |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 3795 | gpu_trace_commands_ = gpu_tracer_->IsTracing() && *gpu_decoder_category_; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 3796 | gpu_debug_commands_ = log_commands() || debug() || gpu_trace_commands_ || |
| 3797 | (*cb_command_trace_category_ != 0); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | void GLES2DecoderImpl::EndDecoding() { |
| 3801 | gpu_tracer_->EndDecoding(); |
| 3802 | } |
| 3803 | |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 3804 | ErrorState* GLES2DecoderImpl::GetErrorState() { |
| 3805 | return state_.GetErrorState(); |
| 3806 | } |
| 3807 | |
[email protected] | e3932abb | 2013-03-13 00:01:37 | [diff] [blame] | 3808 | void GLES2DecoderImpl::SetShaderCacheCallback( |
| 3809 | const ShaderCacheCallback& callback) { |
| 3810 | shader_cache_callback_ = callback; |
| 3811 | } |
| 3812 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 3813 | void GLES2DecoderImpl::SetWaitSyncPointCallback( |
| 3814 | const WaitSyncPointCallback& callback) { |
| 3815 | wait_sync_point_callback_ = callback; |
| 3816 | } |
| 3817 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3818 | AsyncPixelTransferManager* |
| 3819 | GLES2DecoderImpl::GetAsyncPixelTransferManager() { |
| 3820 | return async_pixel_transfer_manager_.get(); |
| 3821 | } |
| 3822 | |
| 3823 | void GLES2DecoderImpl::ResetAsyncPixelTransferManagerForTest() { |
| 3824 | async_pixel_transfer_manager_.reset(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 3825 | } |
| 3826 | |
[email protected] | 498b5c07 | 2013-06-04 19:30:07 | [diff] [blame] | 3827 | void GLES2DecoderImpl::SetAsyncPixelTransferManagerForTest( |
| 3828 | AsyncPixelTransferManager* manager) { |
| 3829 | async_pixel_transfer_manager_ = make_scoped_ptr(manager); |
| 3830 | } |
| 3831 | |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3832 | bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, |
| 3833 | uint32* service_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 3834 | TextureRef* texture_ref = texture_manager()->GetTexture(client_texture_id); |
| 3835 | if (texture_ref) { |
| 3836 | *service_texture_id = texture_ref->service_id(); |
[email protected] | 1318e92 | 2010-09-17 22:03:16 | [diff] [blame] | 3837 | return true; |
| 3838 | } |
| 3839 | return false; |
| 3840 | } |
| 3841 | |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3842 | uint32 GLES2DecoderImpl::GetTextureUploadCount() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3843 | return texture_state_.texture_upload_count + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3844 | async_pixel_transfer_manager_->GetTextureUploadCount(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | base::TimeDelta GLES2DecoderImpl::GetTotalTextureUploadTime() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 3848 | return texture_state_.total_texture_upload_time + |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 3849 | async_pixel_transfer_manager_->GetTotalTextureUploadTime(); |
[email protected] | 63b46592 | 2012-09-06 02:04:52 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | base::TimeDelta GLES2DecoderImpl::GetTotalProcessingCommandsTime() { |
| 3853 | return total_processing_commands_time_; |
| 3854 | } |
| 3855 | |
[email protected] | dc25dda | 2012-09-27 21:36:30 | [diff] [blame] | 3856 | void GLES2DecoderImpl::AddProcessingCommandsTime(base::TimeDelta time) { |
| 3857 | total_processing_commands_time_ += time; |
| 3858 | } |
| 3859 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3860 | void GLES2DecoderImpl::Destroy(bool have_context) { |
[email protected] | 55e136f | 2013-04-03 18:50:06 | [diff] [blame] | 3861 | if (!initialized()) |
| 3862 | return; |
| 3863 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 3864 | DCHECK(!have_context || context_->IsCurrent(NULL)); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3865 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3866 | // Unbind everything. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3867 | state_.vertex_attrib_manager = NULL; |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 3868 | state_.default_vertex_attrib_manager = NULL; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 3869 | state_.texture_units.clear(); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3870 | state_.bound_array_buffer = NULL; |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 3871 | state_.bound_copy_read_buffer = NULL; |
| 3872 | state_.bound_copy_write_buffer = NULL; |
| 3873 | state_.bound_pixel_pack_buffer = NULL; |
| 3874 | state_.bound_pixel_unpack_buffer = NULL; |
| 3875 | state_.bound_transform_feedback_buffer = NULL; |
| 3876 | state_.bound_uniform_buffer = NULL; |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 3877 | state_.current_queries.clear(); |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 3878 | framebuffer_state_.bound_read_framebuffer = NULL; |
| 3879 | framebuffer_state_.bound_draw_framebuffer = NULL; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 3880 | state_.bound_renderbuffer = NULL; |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 3881 | state_.bound_valuebuffer = NULL; |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 3882 | |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 3883 | if (offscreen_saved_color_texture_info_.get()) { |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 3884 | DCHECK(offscreen_target_color_texture_); |
| 3885 | DCHECK_EQ(offscreen_saved_color_texture_info_->service_id(), |
| 3886 | offscreen_saved_color_texture_->id()); |
| 3887 | offscreen_saved_color_texture_->Invalidate(); |
| 3888 | offscreen_saved_color_texture_info_ = NULL; |
| 3889 | } |
[email protected] | eadc9679 | 2010-10-27 19:39:39 | [diff] [blame] | 3890 | if (have_context) { |
[email protected] | c322e88 | 2012-05-23 18:06:18 | [diff] [blame] | 3891 | if (copy_texture_CHROMIUM_.get()) { |
| 3892 | copy_texture_CHROMIUM_->Destroy(); |
| 3893 | copy_texture_CHROMIUM_.reset(); |
| 3894 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3895 | |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 3896 | clear_framebuffer_blit_.reset(); |
| 3897 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 3898 | if (state_.current_program.get()) { |
| 3899 | program_manager()->UnuseProgram(shader_manager(), |
| 3900 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 3901 | } |
| 3902 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3903 | if (attrib_0_buffer_id_) { |
| 3904 | glDeleteBuffersARB(1, &attrib_0_buffer_id_); |
| 3905 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 3906 | if (fixed_attrib_buffer_id_) { |
| 3907 | glDeleteBuffersARB(1, &fixed_attrib_buffer_id_); |
| 3908 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 3909 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 3910 | if (validation_texture_) { |
| 3911 | glDeleteTextures(1, &validation_texture_); |
| 3912 | glDeleteFramebuffersEXT(1, &validation_fbo_multisample_); |
| 3913 | glDeleteFramebuffersEXT(1, &validation_fbo_); |
| 3914 | } |
| 3915 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3916 | if (offscreen_target_frame_buffer_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3917 | offscreen_target_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3918 | if (offscreen_target_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3919 | offscreen_target_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3920 | if (offscreen_target_color_render_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3921 | offscreen_target_color_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3922 | if (offscreen_target_depth_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3923 | offscreen_target_depth_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3924 | if (offscreen_target_stencil_render_buffer_.get()) |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 3925 | offscreen_target_stencil_render_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3926 | if (offscreen_saved_frame_buffer_.get()) |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 3927 | offscreen_saved_frame_buffer_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3928 | if (offscreen_saved_color_texture_.get()) |
[email protected] | 4bedba7 | 2010-04-20 22:08:54 | [diff] [blame] | 3929 | offscreen_saved_color_texture_->Destroy(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3930 | if (offscreen_resolved_frame_buffer_.get()) |
| 3931 | offscreen_resolved_frame_buffer_->Destroy(); |
| 3932 | if (offscreen_resolved_color_texture_.get()) |
| 3933 | offscreen_resolved_color_texture_->Destroy(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3934 | } else { |
| 3935 | if (offscreen_target_frame_buffer_.get()) |
| 3936 | offscreen_target_frame_buffer_->Invalidate(); |
| 3937 | if (offscreen_target_color_texture_.get()) |
| 3938 | offscreen_target_color_texture_->Invalidate(); |
| 3939 | if (offscreen_target_color_render_buffer_.get()) |
| 3940 | offscreen_target_color_render_buffer_->Invalidate(); |
| 3941 | if (offscreen_target_depth_render_buffer_.get()) |
| 3942 | offscreen_target_depth_render_buffer_->Invalidate(); |
| 3943 | if (offscreen_target_stencil_render_buffer_.get()) |
| 3944 | offscreen_target_stencil_render_buffer_->Invalidate(); |
| 3945 | if (offscreen_saved_frame_buffer_.get()) |
| 3946 | offscreen_saved_frame_buffer_->Invalidate(); |
| 3947 | if (offscreen_saved_color_texture_.get()) |
| 3948 | offscreen_saved_color_texture_->Invalidate(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3949 | if (offscreen_resolved_frame_buffer_.get()) |
| 3950 | offscreen_resolved_frame_buffer_->Invalidate(); |
| 3951 | if (offscreen_resolved_color_texture_.get()) |
| 3952 | offscreen_resolved_color_texture_->Invalidate(); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 3953 | } |
[email protected] | 83a52d03 | 2013-07-24 10:30:37 | [diff] [blame] | 3954 | |
| 3955 | // Current program must be cleared after calling ProgramManager::UnuseProgram. |
| 3956 | // Otherwise, we can leak objects. http://crbug.com/258772. |
| 3957 | // state_.current_program must be reset before group_ is reset because |
| 3958 | // the later deletes the ProgramManager object that referred by |
| 3959 | // state_.current_program object. |
| 3960 | state_.current_program = NULL; |
| 3961 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 3962 | copy_texture_CHROMIUM_.reset(); |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 3963 | clear_framebuffer_blit_.reset(); |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3964 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 3965 | if (query_manager_.get()) { |
| 3966 | query_manager_->Destroy(have_context); |
| 3967 | query_manager_.reset(); |
| 3968 | } |
| 3969 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 3970 | if (vertex_array_manager_ .get()) { |
| 3971 | vertex_array_manager_->Destroy(have_context); |
| 3972 | vertex_array_manager_.reset(); |
| 3973 | } |
| 3974 | |
[email protected] | d2eaf52f | 2014-07-31 15:01:24 | [diff] [blame] | 3975 | if (image_manager_.get()) { |
| 3976 | image_manager_->Destroy(have_context); |
| 3977 | image_manager_.reset(); |
| 3978 | } |
| 3979 | |
[email protected] | 9787206 | 2010-11-03 19:07:05 | [diff] [blame] | 3980 | offscreen_target_frame_buffer_.reset(); |
| 3981 | offscreen_target_color_texture_.reset(); |
| 3982 | offscreen_target_color_render_buffer_.reset(); |
| 3983 | offscreen_target_depth_render_buffer_.reset(); |
| 3984 | offscreen_target_stencil_render_buffer_.reset(); |
| 3985 | offscreen_saved_frame_buffer_.reset(); |
| 3986 | offscreen_saved_color_texture_.reset(); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 3987 | offscreen_resolved_frame_buffer_.reset(); |
| 3988 | offscreen_resolved_color_texture_.reset(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 3989 | |
[email protected] | 03cef9b | 2014-04-03 15:58:14 | [diff] [blame] | 3990 | // Need to release these before releasing |group_| which may own the |
| 3991 | // ShaderTranslatorCache. |
| 3992 | fragment_translator_ = NULL; |
| 3993 | vertex_translator_ = NULL; |
| 3994 | |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 3995 | // Should destroy the transfer manager before the texture manager held |
| 3996 | // by the context group. |
| 3997 | async_pixel_transfer_manager_.reset(); |
| 3998 | |
dyen | dbfb90d | 2015-03-26 02:41:46 | [diff] [blame] | 3999 | // Destroy the GPU Tracer which may own some in process GPU Timings. |
dyen | 8ef65988 | 2015-03-26 23:32:51 | [diff] [blame] | 4000 | if (gpu_tracer_) { |
| 4001 | gpu_tracer_->Destroy(have_context); |
| 4002 | gpu_tracer_.reset(); |
| 4003 | } |
dyen | dbfb90d | 2015-03-26 02:41:46 | [diff] [blame] | 4004 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4005 | if (group_.get()) { |
[email protected] | ac5e402 | 2014-01-24 12:44:39 | [diff] [blame] | 4006 | framebuffer_manager()->RemoveObserver(this); |
[email protected] | 2d9d3b9 | 2013-01-18 01:07:23 | [diff] [blame] | 4007 | group_->Destroy(this, have_context); |
| 4008 | group_ = NULL; |
| 4009 | } |
| 4010 | |
| 4011 | if (context_.get()) { |
| 4012 | context_->ReleaseCurrent(NULL); |
| 4013 | context_ = NULL; |
| 4014 | } |
| 4015 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4016 | #if defined(OS_MACOSX) |
| 4017 | for (TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.begin(); |
| 4018 | it != texture_to_io_surface_map_.end(); ++it) { |
| 4019 | CFRelease(it->second); |
| 4020 | } |
| 4021 | texture_to_io_surface_map_.clear(); |
| 4022 | #endif |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4023 | } |
| 4024 | |
[email protected] | 63c9b05 | 2012-05-17 18:27:38 | [diff] [blame] | 4025 | void GLES2DecoderImpl::SetSurface( |
| 4026 | const scoped_refptr<gfx::GLSurface>& surface) { |
| 4027 | DCHECK(context_->IsCurrent(NULL)); |
| 4028 | DCHECK(surface_.get()); |
| 4029 | surface_ = surface; |
| 4030 | RestoreCurrentFramebufferBindings(); |
| 4031 | } |
| 4032 | |
[email protected] | aba551b | 2014-02-08 03:38:32 | [diff] [blame] | 4033 | void GLES2DecoderImpl::ProduceFrontBuffer(const Mailbox& mailbox) { |
| 4034 | if (!offscreen_saved_color_texture_.get()) { |
| 4035 | LOG(ERROR) << "Called ProduceFrontBuffer on a non-offscreen context"; |
| 4036 | return; |
| 4037 | } |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 4038 | if (!offscreen_saved_color_texture_info_.get()) { |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 4039 | GLuint service_id = offscreen_saved_color_texture_->id(); |
[email protected] | f4647693 | 2013-06-08 05:36:07 | [diff] [blame] | 4040 | offscreen_saved_color_texture_info_ = TextureRef::Create( |
| 4041 | texture_manager(), 0, service_id); |
[email protected] | 2ad67413 | 2013-06-05 07:48:51 | [diff] [blame] | 4042 | texture_manager()->SetTarget(offscreen_saved_color_texture_info_.get(), |
| 4043 | GL_TEXTURE_2D); |
[email protected] | 9a5afa43 | 2011-07-22 18:16:39 | [diff] [blame] | 4044 | UpdateParentTextureInfo(); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 4045 | } |
[email protected] | aba551b | 2014-02-08 03:38:32 | [diff] [blame] | 4046 | mailbox_manager()->ProduceTexture( |
sievers | 8b373ec5 | 2014-10-24 23:04:06 | [diff] [blame] | 4047 | mailbox, offscreen_saved_color_texture_info_->texture()); |
[email protected] | 3c644d8 | 2011-06-20 19:58:24 | [diff] [blame] | 4048 | } |
| 4049 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4050 | bool GLES2DecoderImpl::ResizeOffscreenFrameBuffer(const gfx::Size& size) { |
| 4051 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 4052 | if (!is_offscreen) { |
| 4053 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer called " |
| 4054 | << " with an onscreen framebuffer."; |
| 4055 | return false; |
| 4056 | } |
| 4057 | |
| 4058 | if (offscreen_size_ == size) |
| 4059 | return true; |
| 4060 | |
| 4061 | offscreen_size_ = size; |
| 4062 | int w = offscreen_size_.width(); |
| 4063 | int h = offscreen_size_.height(); |
| 4064 | if (w < 0 || h < 0 || h >= (INT_MAX / 4) / (w ? w : 1)) { |
| 4065 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 4066 | << "to allocate storage due to excessive dimensions."; |
| 4067 | return false; |
| 4068 | } |
| 4069 | |
| 4070 | // Reallocate the offscreen target buffers. |
| 4071 | DCHECK(offscreen_target_color_format_); |
| 4072 | if (IsOffscreenBufferMultisampled()) { |
| 4073 | if (!offscreen_target_color_render_buffer_->AllocateStorage( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 4074 | feature_info_.get(), |
| 4075 | offscreen_size_, |
| 4076 | offscreen_target_color_format_, |
| 4077 | offscreen_target_samples_)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4078 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 4079 | << "to allocate storage for offscreen target color buffer."; |
| 4080 | return false; |
| 4081 | } |
| 4082 | } else { |
| 4083 | if (!offscreen_target_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 4084 | offscreen_size_, offscreen_target_color_format_, false)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4085 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 4086 | << "to allocate storage for offscreen target color texture."; |
| 4087 | return false; |
| 4088 | } |
| 4089 | } |
| 4090 | if (offscreen_target_depth_format_ && |
| 4091 | !offscreen_target_depth_render_buffer_->AllocateStorage( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 4092 | feature_info_.get(), |
| 4093 | offscreen_size_, |
| 4094 | offscreen_target_depth_format_, |
| 4095 | offscreen_target_samples_)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4096 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 4097 | << "to allocate storage for offscreen target depth buffer."; |
| 4098 | return false; |
| 4099 | } |
| 4100 | if (offscreen_target_stencil_format_ && |
| 4101 | !offscreen_target_stencil_render_buffer_->AllocateStorage( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 4102 | feature_info_.get(), |
| 4103 | offscreen_size_, |
| 4104 | offscreen_target_stencil_format_, |
| 4105 | offscreen_target_samples_)) { |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4106 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 4107 | << "to allocate storage for offscreen target stencil buffer."; |
| 4108 | return false; |
| 4109 | } |
| 4110 | |
| 4111 | // Attach the offscreen target buffers to the target frame buffer. |
| 4112 | if (IsOffscreenBufferMultisampled()) { |
| 4113 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 4114 | GL_COLOR_ATTACHMENT0, |
| 4115 | offscreen_target_color_render_buffer_.get()); |
| 4116 | } else { |
| 4117 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 4118 | offscreen_target_color_texture_.get()); |
| 4119 | } |
| 4120 | if (offscreen_target_depth_format_) { |
| 4121 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 4122 | GL_DEPTH_ATTACHMENT, |
| 4123 | offscreen_target_depth_render_buffer_.get()); |
| 4124 | } |
| 4125 | const bool packed_depth_stencil = |
| 4126 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 4127 | if (packed_depth_stencil) { |
| 4128 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 4129 | GL_STENCIL_ATTACHMENT, |
| 4130 | offscreen_target_depth_render_buffer_.get()); |
| 4131 | } else if (offscreen_target_stencil_format_) { |
| 4132 | offscreen_target_frame_buffer_->AttachRenderBuffer( |
| 4133 | GL_STENCIL_ATTACHMENT, |
| 4134 | offscreen_target_stencil_render_buffer_.get()); |
| 4135 | } |
| 4136 | |
| 4137 | if (offscreen_target_frame_buffer_->CheckStatus() != |
| 4138 | GL_FRAMEBUFFER_COMPLETE) { |
| 4139 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 4140 | << "because offscreen FBO was incomplete."; |
| 4141 | return false; |
| 4142 | } |
| 4143 | |
| 4144 | // Clear the target frame buffer. |
| 4145 | { |
| 4146 | ScopedFrameBufferBinder binder(this, offscreen_target_frame_buffer_->id()); |
| 4147 | glClearColor(0, 0, 0, (GLES2Util::GetChannelsForFormat( |
pkasting | 45796dc | 2014-10-17 04:18:32 | [diff] [blame] | 4148 | offscreen_target_color_format_) & 0x0008) != 0 ? 0 : 1.f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4149 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4150 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 4151 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 4152 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4153 | glClearDepth(0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4154 | state_.SetDeviceDepthMask(GL_TRUE); |
| 4155 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4156 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
| 4157 | RestoreClearState(); |
| 4158 | } |
[email protected] | d85ef76d | 2011-09-08 22:21:43 | [diff] [blame] | 4159 | |
| 4160 | // Destroy the offscreen resolved framebuffers. |
| 4161 | if (offscreen_resolved_frame_buffer_.get()) |
| 4162 | offscreen_resolved_frame_buffer_->Destroy(); |
| 4163 | if (offscreen_resolved_color_texture_.get()) |
| 4164 | offscreen_resolved_color_texture_->Destroy(); |
| 4165 | offscreen_resolved_color_texture_.reset(); |
| 4166 | offscreen_resolved_frame_buffer_.reset(); |
| 4167 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4168 | return true; |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 4169 | } |
| 4170 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 4171 | error::Error GLES2DecoderImpl::HandleResizeCHROMIUM(uint32 immediate_data_size, |
| 4172 | const void* cmd_data) { |
| 4173 | const gles2::cmds::ResizeCHROMIUM& c = |
| 4174 | *static_cast<const gles2::cmds::ResizeCHROMIUM*>(cmd_data); |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 4175 | if (!offscreen_target_frame_buffer_.get() && surface_->DeferDraws()) |
[email protected] | 45212087 | 2012-09-27 15:21:02 | [diff] [blame] | 4176 | return error::kDeferCommandUntilLater; |
| 4177 | |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4178 | GLuint width = static_cast<GLuint>(c.width); |
| 4179 | GLuint height = static_cast<GLuint>(c.height); |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 4180 | GLfloat scale_factor = c.scale_factor; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4181 | TRACE_EVENT2("gpu", "glResizeChromium", "width", width, "height", height); |
[email protected] | d16aa4b | 2013-02-14 22:35:41 | [diff] [blame] | 4182 | |
| 4183 | width = std::max(1U, width); |
| 4184 | height = std::max(1U, height); |
| 4185 | |
[email protected] | a0d98916 | 2011-11-22 13:15:07 | [diff] [blame] | 4186 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && \ |
| 4187 | !defined(UI_COMPOSITOR_IMAGE_TRANSPORT) |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 4188 | // Make sure that we are done drawing to the back buffer before resizing. |
| 4189 | glFinish(); |
| 4190 | #endif |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4191 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 4192 | if (is_offscreen) { |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 4193 | if (!ResizeOffscreenFrameBuffer(gfx::Size(width, height))) { |
| 4194 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because " |
| 4195 | << "ResizeOffscreenFrameBuffer failed."; |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4196 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 4197 | } |
[email protected] | 7ff86b9 | 2010-11-25 17:50:00 | [diff] [blame] | 4198 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4199 | |
[email protected] | 9d37f06 | 2011-11-22 01:24:52 | [diff] [blame] | 4200 | if (!resize_callback_.is_null()) { |
[email protected] | 729c0b4 | 2013-05-26 02:05:07 | [diff] [blame] | 4201 | resize_callback_.Run(gfx::Size(width, height), scale_factor); |
[email protected] | 0e9346b | 2013-03-16 16:35:44 | [diff] [blame] | 4202 | DCHECK(context_->IsCurrent(surface_.get())); |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 4203 | if (!context_->IsCurrent(surface_.get())) { |
| 4204 | LOG(ERROR) << "GLES2DecoderImpl: Context lost because context no longer " |
| 4205 | << "current after resize callback."; |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 4206 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 4207 | } |
[email protected] | 658f756 | 2011-09-09 05:24:05 | [diff] [blame] | 4208 | } |
[email protected] | 799b4b2 | 2011-08-22 17:09:59 | [diff] [blame] | 4209 | |
| 4210 | return error::kNoError; |
[email protected] | 43ecf37 | 2010-11-16 19:19:39 | [diff] [blame] | 4211 | } |
| 4212 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4213 | const char* GLES2DecoderImpl::GetCommandName(unsigned int command_id) const { |
| 4214 | if (command_id > kStartPoint && command_id < kNumCommands) { |
| 4215 | return gles2::GetCommandName(static_cast<CommandId>(command_id)); |
| 4216 | } |
| 4217 | return GetCommonCommandName(static_cast<cmd::CommandId>(command_id)); |
| 4218 | } |
| 4219 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4220 | // Decode a command, and call the corresponding GL functions. |
| 4221 | // NOTE: DoCommand() is slower than calling DoCommands() on larger batches |
| 4222 | // of commands at once, and is now only used for tests that need to track |
| 4223 | // individual commands. |
| 4224 | error::Error GLES2DecoderImpl::DoCommand(unsigned int command, |
| 4225 | unsigned int arg_count, |
| 4226 | const void* cmd_data) { |
| 4227 | return DoCommands(1, cmd_data, arg_count + 1, 0); |
| 4228 | } |
| 4229 | |
| 4230 | // Decode multiple commands, and call the corresponding GL functions. |
| 4231 | // NOTE: 'buffer' is a pointer to the command buffer. As such, it could be |
| 4232 | // changed by a (malicious) client at any time, so if validation has to happen, |
| 4233 | // it should operate on a copy of them. |
| 4234 | // NOTE: This is duplicating code from AsyncAPIInterface::DoCommands() in the |
| 4235 | // interest of performance in this critical execution loop. |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4236 | template <bool DebugImpl> |
| 4237 | error::Error GLES2DecoderImpl::DoCommandsImpl(unsigned int num_commands, |
| 4238 | const void* buffer, |
| 4239 | int num_entries, |
| 4240 | int* entries_processed) { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4241 | commands_to_process_ = num_commands; |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 4242 | error::Error result = error::kNoError; |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4243 | const CommandBufferEntry* cmd_data = |
| 4244 | static_cast<const CommandBufferEntry*>(buffer); |
| 4245 | int process_pos = 0; |
| 4246 | unsigned int command = 0; |
| 4247 | |
| 4248 | while (process_pos < num_entries && result == error::kNoError && |
| 4249 | commands_to_process_--) { |
| 4250 | const unsigned int size = cmd_data->value_header.size; |
| 4251 | command = cmd_data->value_header.command; |
| 4252 | |
| 4253 | if (size == 0) { |
| 4254 | result = error::kInvalidSize; |
| 4255 | break; |
| 4256 | } |
| 4257 | |
| 4258 | if (static_cast<int>(size) + process_pos > num_entries) { |
| 4259 | result = error::kOutOfBounds; |
| 4260 | break; |
| 4261 | } |
| 4262 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4263 | if (DebugImpl) { |
| 4264 | TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cb_command"), |
| 4265 | GetCommandName(command)); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4266 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4267 | if (log_commands()) { |
| 4268 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "]" |
| 4269 | << "cmd: " << GetCommandName(command); |
| 4270 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4271 | } |
| 4272 | |
| 4273 | const unsigned int arg_count = size - 1; |
| 4274 | unsigned int command_index = command - kStartPoint - 1; |
| 4275 | if (command_index < arraysize(command_info)) { |
| 4276 | const CommandInfo& info = command_info[command_index]; |
| 4277 | unsigned int info_arg_count = static_cast<unsigned int>(info.arg_count); |
| 4278 | if ((info.arg_flags == cmd::kFixed && arg_count == info_arg_count) || |
| 4279 | (info.arg_flags == cmd::kAtLeastN && arg_count >= info_arg_count)) { |
| 4280 | bool doing_gpu_trace = false; |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4281 | if (DebugImpl && gpu_trace_commands_) { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4282 | if (CMD_FLAG_GET_TRACE_LEVEL(info.cmd_flags) <= gpu_trace_level_) { |
| 4283 | doing_gpu_trace = true; |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 4284 | gpu_tracer_->Begin(TRACE_DISABLED_BY_DEFAULT("gpu_decoder"), |
| 4285 | GetCommandName(command), |
| 4286 | kTraceDecoder); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4287 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 4288 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 4289 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4290 | uint32 immediate_data_size = (arg_count - info_arg_count) * |
| 4291 | sizeof(CommandBufferEntry); // NOLINT |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4292 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4293 | result = (this->*info.cmd_handler)(immediate_data_size, cmd_data); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 4294 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4295 | if (DebugImpl && doing_gpu_trace) |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4296 | gpu_tracer_->End(kTraceDecoder); |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 4297 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4298 | if (DebugImpl && debug()) { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4299 | GLenum error; |
| 4300 | while ((error = glGetError()) != GL_NO_ERROR) { |
| 4301 | LOG(ERROR) << "[" << logger_.GetLogPrefix() << "] " |
| 4302 | << "GL ERROR: " << GLES2Util::GetStringEnum(error) |
| 4303 | << " : " << GetCommandName(command); |
| 4304 | LOCAL_SET_GL_ERROR(error, "DoCommand", "GL error from driver"); |
| 4305 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 4306 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4307 | } else { |
| 4308 | result = error::kInvalidArguments; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4309 | } |
| 4310 | } else { |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4311 | result = DoCommonCommand(command, arg_count, cmd_data); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4312 | } |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4313 | |
| 4314 | if (DebugImpl) { |
| 4315 | TRACE_EVENT_END0(TRACE_DISABLED_BY_DEFAULT("cb_command"), |
| 4316 | GetCommandName(command)); |
| 4317 | } |
| 4318 | |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4319 | if (result == error::kNoError && |
| 4320 | current_decoder_error_ != error::kNoError) { |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 4321 | result = current_decoder_error_; |
| 4322 | current_decoder_error_ = error::kNoError; |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | if (result != error::kDeferCommandUntilLater) { |
| 4326 | process_pos += size; |
| 4327 | cmd_data += size; |
| 4328 | } |
[email protected] | a3a93e7b | 2010-08-28 00:48:56 | [diff] [blame] | 4329 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 4330 | |
| 4331 | if (entries_processed) |
| 4332 | *entries_processed = process_pos; |
| 4333 | |
| 4334 | if (error::IsError(result)) { |
| 4335 | LOG(ERROR) << "Error: " << result << " for Command " |
| 4336 | << GetCommandName(command); |
| 4337 | } |
| 4338 | |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 4339 | return result; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4340 | } |
| 4341 | |
vmiura | 1c2b1de | 2014-09-19 19:03:24 | [diff] [blame] | 4342 | error::Error GLES2DecoderImpl::DoCommands(unsigned int num_commands, |
| 4343 | const void* buffer, |
| 4344 | int num_entries, |
| 4345 | int* entries_processed) { |
| 4346 | if (gpu_debug_commands_) { |
| 4347 | return DoCommandsImpl<true>( |
| 4348 | num_commands, buffer, num_entries, entries_processed); |
| 4349 | } else { |
| 4350 | return DoCommandsImpl<false>( |
| 4351 | num_commands, buffer, num_entries, entries_processed); |
| 4352 | } |
| 4353 | } |
| 4354 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4355 | void GLES2DecoderImpl::RemoveBuffer(GLuint client_id) { |
| 4356 | buffer_manager()->RemoveBuffer(client_id); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4357 | } |
| 4358 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 4359 | void GLES2DecoderImpl::DoFinish() { |
| 4360 | glFinish(); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 4361 | ProcessPendingReadPixels(); |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 4362 | ProcessPendingQueries(true); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 4363 | } |
| 4364 | |
| 4365 | void GLES2DecoderImpl::DoFlush() { |
| 4366 | glFlush(); |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 4367 | ProcessPendingQueries(false); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 4368 | } |
| 4369 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4370 | void GLES2DecoderImpl::DoActiveTexture(GLenum texture_unit) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4371 | GLuint texture_index = texture_unit - GL_TEXTURE0; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4372 | if (texture_index >= state_.texture_units.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4373 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 4374 | "glActiveTexture", texture_unit, "texture_unit"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4375 | return; |
| 4376 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4377 | state_.active_texture_unit = texture_index; |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 4378 | glActiveTexture(texture_unit); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4379 | } |
| 4380 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4381 | void GLES2DecoderImpl::DoBindBuffer(GLenum target, GLuint client_id) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4382 | Buffer* buffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4383 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4384 | if (client_id != 0) { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4385 | buffer = GetBuffer(client_id); |
| 4386 | if (!buffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4387 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4388 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4389 | "glBindBuffer", |
| 4390 | "id not generated by glGenBuffers"); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4391 | return; |
| 4392 | } |
| 4393 | |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4394 | // It's a new id so make a buffer buffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4395 | glGenBuffersARB(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4396 | CreateBuffer(client_id, service_id); |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4397 | buffer = GetBuffer(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4398 | } |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4399 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4400 | LogClientServiceForInfo(buffer, client_id, "glBindBuffer"); |
| 4401 | if (buffer) { |
| 4402 | if (!buffer_manager()->SetTarget(buffer, target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4403 | LOCAL_SET_GL_ERROR( |
| 4404 | GL_INVALID_OPERATION, |
| 4405 | "glBindBuffer", "buffer bound to more than 1 target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4406 | return; |
| 4407 | } |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 4408 | service_id = buffer->service_id(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4409 | } |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 4410 | state_.SetBoundBuffer(target, buffer); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4411 | glBindBuffer(target, service_id); |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 4412 | } |
| 4413 | |
[email protected] | f3b191b | 2013-06-19 03:43:54 | [diff] [blame] | 4414 | bool GLES2DecoderImpl::BoundFramebufferHasColorAttachmentWithAlpha( |
| 4415 | bool all_draw_buffers) { |
| 4416 | Framebuffer* framebuffer = |
| 4417 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 4418 | if (!all_draw_buffers || !framebuffer) { |
| 4419 | return (GLES2Util::GetChannelsForFormat( |
| 4420 | GetBoundDrawFrameBufferInternalFormat()) & 0x0008) != 0; |
| 4421 | } |
| 4422 | return framebuffer->HasAlphaMRT(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | bool GLES2DecoderImpl::BoundFramebufferHasDepthAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4426 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4427 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4428 | if (framebuffer) { |
| 4429 | return framebuffer->HasDepthAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4430 | } |
| 4431 | if (offscreen_target_frame_buffer_.get()) { |
| 4432 | return offscreen_target_depth_format_ != 0; |
| 4433 | } |
| 4434 | return back_buffer_has_depth_; |
| 4435 | } |
| 4436 | |
| 4437 | bool GLES2DecoderImpl::BoundFramebufferHasStencilAttachment() { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4438 | Framebuffer* framebuffer = |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 4439 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 4440 | if (framebuffer) { |
| 4441 | return framebuffer->HasStencilAttachment(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4442 | } |
| 4443 | if (offscreen_target_frame_buffer_.get()) { |
| 4444 | return offscreen_target_stencil_format_ != 0 || |
| 4445 | offscreen_target_depth_format_ == GL_DEPTH24_STENCIL8; |
| 4446 | } |
| 4447 | return back_buffer_has_stencil_; |
| 4448 | } |
| 4449 | |
| 4450 | void GLES2DecoderImpl::ApplyDirtyState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4451 | if (framebuffer_state_.clear_state_dirty) { |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4452 | bool have_alpha = BoundFramebufferHasColorAttachmentWithAlpha(true); |
| 4453 | state_.SetDeviceColorMask(state_.color_mask_red, |
| 4454 | state_.color_mask_green, |
| 4455 | state_.color_mask_blue, |
| 4456 | state_.color_mask_alpha && have_alpha); |
| 4457 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4458 | bool have_depth = BoundFramebufferHasDepthAttachment(); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4459 | state_.SetDeviceDepthMask(state_.depth_mask && have_depth); |
| 4460 | |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4461 | bool have_stencil = BoundFramebufferHasStencilAttachment(); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4462 | state_.SetDeviceStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4463 | GL_FRONT, have_stencil ? state_.stencil_front_writemask : 0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4464 | state_.SetDeviceStencilMaskSeparate( |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 4465 | GL_BACK, have_stencil ? state_.stencil_back_writemask : 0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4466 | |
| 4467 | state_.SetDeviceCapabilityState( |
| 4468 | GL_DEPTH_TEST, state_.enable_flags.depth_test && have_depth); |
| 4469 | state_.SetDeviceCapabilityState( |
[email protected] | f731b946 | 2012-10-30 00:35:22 | [diff] [blame] | 4470 | GL_STENCIL_TEST, state_.enable_flags.stencil_test && have_stencil); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4471 | framebuffer_state_.clear_state_dirty = false; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4472 | } |
| 4473 | } |
| 4474 | |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4475 | GLuint GLES2DecoderImpl::GetBackbufferServiceId() const { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4476 | return (offscreen_target_frame_buffer_.get()) |
| 4477 | ? offscreen_target_frame_buffer_->id() |
| 4478 | : (surface_.get() ? surface_->GetBackingFrameBufferObject() : 0); |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 4479 | } |
| 4480 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4481 | void GLES2DecoderImpl::RestoreState(const ContextState* prev_state) { |
[email protected] | 962bfbe7 | 2013-05-24 11:16:14 | [diff] [blame] | 4482 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::RestoreState", |
| 4483 | "context", logger_.GetLogPrefix()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4484 | // Restore the Framebuffer first because of bugs in Intel drivers. |
| 4485 | // Intel drivers incorrectly clip the viewport settings to |
| 4486 | // the size of the current framebuffer object. |
| 4487 | RestoreFramebufferBindings(); |
[email protected] | 5baa86bc | 2014-01-16 04:33:16 | [diff] [blame] | 4488 | state_.RestoreState(prev_state); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | void GLES2DecoderImpl::RestoreFramebufferBindings() const { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4492 | GLuint service_id = |
| 4493 | framebuffer_state_.bound_draw_framebuffer.get() |
| 4494 | ? framebuffer_state_.bound_draw_framebuffer->service_id() |
| 4495 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4496 | if (!features().chromium_framebuffer_multisample) { |
| 4497 | glBindFramebufferEXT(GL_FRAMEBUFFER, service_id); |
| 4498 | } else { |
| 4499 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, service_id); |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4500 | service_id = framebuffer_state_.bound_read_framebuffer.get() |
| 4501 | ? framebuffer_state_.bound_read_framebuffer->service_id() |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 4502 | : GetBackbufferServiceId(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4503 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, service_id); |
| 4504 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4505 | OnFboChanged(); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4506 | } |
| 4507 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4508 | void GLES2DecoderImpl::RestoreRenderbufferBindings() { |
| 4509 | state_.RestoreRenderbufferBindings(); |
| 4510 | } |
| 4511 | |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4512 | void GLES2DecoderImpl::RestoreTextureState(unsigned service_id) const { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 4513 | Texture* texture = texture_manager()->GetTextureForServiceId(service_id); |
| 4514 | if (texture) { |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4515 | GLenum target = texture->target(); |
| 4516 | glBindTexture(target, service_id); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4517 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4518 | target, GL_TEXTURE_WRAP_S, texture->wrap_s()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4519 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4520 | target, GL_TEXTURE_WRAP_T, texture->wrap_t()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4521 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4522 | target, GL_TEXTURE_MIN_FILTER, texture->min_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4523 | glTexParameteri( |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 4524 | target, GL_TEXTURE_MAG_FILTER, texture->mag_filter()); |
[email protected] | 29a4d90 | 2013-02-26 20:18:06 | [diff] [blame] | 4525 | RestoreTextureUnitBindings(state_.active_texture_unit); |
| 4526 | } |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4527 | } |
| 4528 | |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4529 | void GLES2DecoderImpl::ClearAllAttributes() const { |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 4530 | // Must use native VAO 0, as RestoreAllAttributes can't fully restore |
| 4531 | // other VAOs. |
| 4532 | if (feature_info_->feature_flags().native_vertex_array_object) |
| 4533 | glBindVertexArrayOES(0); |
| 4534 | |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4535 | for (uint32 i = 0; i < group_->max_vertex_attribs(); ++i) { |
dcastagna | 504d45c | 2015-04-06 19:30:39 | [diff] [blame] | 4536 | if (i != 0) // Never disable attribute 0 |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4537 | glDisableVertexAttribArray(i); |
dcastagna | 504d45c | 2015-04-06 19:30:39 | [diff] [blame] | 4538 | if (features().angle_instanced_arrays) |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4539 | glVertexAttribDivisorANGLE(i, 0); |
| 4540 | } |
| 4541 | } |
| 4542 | |
| 4543 | void GLES2DecoderImpl::RestoreAllAttributes() const { |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 4544 | state_.RestoreVertexAttribs(); |
[email protected] | cd2ef75 | 2014-02-12 23:16:03 | [diff] [blame] | 4545 | } |
| 4546 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 4547 | void GLES2DecoderImpl::SetIgnoreCachedStateForTest(bool ignore) { |
| 4548 | state_.SetIgnoreCachedStateForTest(ignore); |
| 4549 | } |
| 4550 | |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4551 | void GLES2DecoderImpl::OnFboChanged() const { |
| 4552 | if (workarounds().restore_scissor_on_fbo_change) |
zmo | 8ac3bab | 2015-04-18 02:30:58 | [diff] [blame] | 4553 | state_.fbo_binding_for_scissor_workaround_dirty = true; |
ccameron | 4ff12a73 | 2014-12-12 21:38:19 | [diff] [blame] | 4554 | |
| 4555 | if (workarounds().gl_begin_gl_end_on_fbo_change_to_backbuffer) { |
| 4556 | GLint bound_fbo_unsigned = -1; |
| 4557 | glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &bound_fbo_unsigned); |
| 4558 | GLuint bound_fbo = static_cast<GLuint>(bound_fbo_unsigned); |
| 4559 | if (surface_ && surface_->GetBackingFrameBufferObject() == bound_fbo) |
| 4560 | surface_->NotifyWasBound(); |
| 4561 | } |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | // Called after the FBO is checked for completeness. |
| 4565 | void GLES2DecoderImpl::OnUseFramebuffer() const { |
zmo | 8ac3bab | 2015-04-18 02:30:58 | [diff] [blame] | 4566 | if (state_.fbo_binding_for_scissor_workaround_dirty) { |
| 4567 | state_.fbo_binding_for_scissor_workaround_dirty = false; |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 4568 | // The driver forgets the correct scissor when modifying the FBO binding. |
[email protected] | 28718a9 | 2013-04-04 12:12:51 | [diff] [blame] | 4569 | glScissor(state_.scissor_x, |
| 4570 | state_.scissor_y, |
| 4571 | state_.scissor_width, |
| 4572 | state_.scissor_height); |
| 4573 | |
| 4574 | // crbug.com/222018 - Also on QualComm, the flush here avoids flicker, |
| 4575 | // it's unclear how this bug works. |
| 4576 | glFlush(); |
| 4577 | } |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 4578 | } |
| 4579 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4580 | void GLES2DecoderImpl::DoBindFramebuffer(GLenum target, GLuint client_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4581 | Framebuffer* framebuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4582 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4583 | if (client_id != 0) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4584 | framebuffer = GetFramebuffer(client_id); |
| 4585 | if (!framebuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4586 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4587 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4588 | "glBindFramebuffer", |
| 4589 | "id not generated by glGenFramebuffers"); |
| 4590 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4591 | } |
| 4592 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4593 | // It's a new id so make a framebuffer framebuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4594 | glGenFramebuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4595 | CreateFramebuffer(client_id, service_id); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4596 | framebuffer = GetFramebuffer(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4597 | } else { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4598 | service_id = framebuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4599 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4600 | framebuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4601 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4602 | LogClientServiceForInfo(framebuffer, client_id, "glBindFramebuffer"); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4603 | |
| 4604 | if (target == GL_FRAMEBUFFER || target == GL_DRAW_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4605 | framebuffer_state_.bound_draw_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4606 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 4607 | |
| 4608 | // vmiura: This looks like dup code |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4609 | if (target == GL_FRAMEBUFFER || target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 4610 | framebuffer_state_.bound_read_framebuffer = framebuffer; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 4611 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 4612 | |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4613 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4614 | |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 4615 | // If we are rendering to the backbuffer get the FBO id for any simulated |
| 4616 | // backbuffer. |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 4617 | if (framebuffer == NULL) { |
[email protected] | b177ae2 | 2011-11-01 03:29:11 | [diff] [blame] | 4618 | service_id = GetBackbufferServiceId(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 4619 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 4620 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4621 | glBindFramebufferEXT(target, service_id); |
[email protected] | 70d34263c | 2013-01-09 00:27:45 | [diff] [blame] | 4622 | OnFboChanged(); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 4623 | } |
| 4624 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4625 | void GLES2DecoderImpl::DoBindRenderbuffer(GLenum target, GLuint client_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4626 | Renderbuffer* renderbuffer = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4627 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4628 | if (client_id != 0) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4629 | renderbuffer = GetRenderbuffer(client_id); |
| 4630 | if (!renderbuffer) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4631 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4632 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4633 | "glBindRenderbuffer", |
| 4634 | "id not generated by glGenRenderbuffers"); |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4635 | return; |
| 4636 | } |
| 4637 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4638 | // It's a new id so make a renderbuffer for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4639 | glGenRenderbuffersEXT(1, &service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4640 | CreateRenderbuffer(client_id, service_id); |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4641 | renderbuffer = GetRenderbuffer(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4642 | } else { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4643 | service_id = renderbuffer->service_id(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4644 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4645 | renderbuffer->MarkAsValid(); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4646 | } |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 4647 | LogClientServiceForInfo(renderbuffer, client_id, "glBindRenderbuffer"); |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 4648 | state_.bound_renderbuffer = renderbuffer; |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 4649 | state_.bound_renderbuffer_valid = true; |
| 4650 | glBindRenderbufferEXT(GL_RENDERBUFFER, service_id); |
[email protected] | 8609397 | 2010-03-11 00:13:56 | [diff] [blame] | 4651 | } |
| 4652 | |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4653 | void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4654 | TextureRef* texture_ref = NULL; |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4655 | GLuint service_id = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4656 | if (client_id != 0) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4657 | texture_ref = GetTexture(client_id); |
| 4658 | if (!texture_ref) { |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4659 | if (!group_->bind_generates_resource()) { |
[email protected] | 7ed37cc | 2014-02-12 11:15:22 | [diff] [blame] | 4660 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4661 | "glBindTexture", |
| 4662 | "id not generated by glGenTextures"); |
| 4663 | return; |
[email protected] | bf5a8d13 | 2011-08-16 08:39:35 | [diff] [blame] | 4664 | } |
| 4665 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 4666 | // It's a new id so make a texture texture for it. |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4667 | glGenTextures(1, &service_id); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 4668 | DCHECK_NE(0u, service_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4669 | CreateTexture(client_id, service_id); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4670 | texture_ref = GetTexture(client_id); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4671 | } |
| 4672 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4673 | texture_ref = texture_manager()->GetDefaultTextureInfo(target); |
[email protected] | 051b137 | 2010-04-12 02:42:08 | [diff] [blame] | 4674 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 4675 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 4676 | // Check the texture exists |
[email protected] | 5ebf59f | 2014-04-08 03:51:57 | [diff] [blame] | 4677 | if (texture_ref) { |
| 4678 | Texture* texture = texture_ref->texture(); |
| 4679 | // Check that we are not trying to bind it to a different target. |
| 4680 | if (texture->target() != 0 && texture->target() != target) { |
| 4681 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 4682 | "glBindTexture", |
| 4683 | "texture bound to more than 1 target."); |
| 4684 | return; |
| 4685 | } |
| 4686 | LogClientServiceForInfo(texture, client_id, "glBindTexture"); |
| 4687 | if (texture->target() == 0) { |
| 4688 | texture_manager()->SetTarget(texture_ref, target); |
| 4689 | } |
| 4690 | glBindTexture(target, texture->service_id()); |
| 4691 | } else { |
| 4692 | glBindTexture(target, 0); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 4693 | } |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 4694 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4695 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 4696 | unit.bind_target = target; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4697 | switch (target) { |
| 4698 | case GL_TEXTURE_2D: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4699 | unit.bound_texture_2d = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4700 | break; |
| 4701 | case GL_TEXTURE_CUBE_MAP: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4702 | unit.bound_texture_cube_map = texture_ref; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4703 | break; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4704 | case GL_TEXTURE_EXTERNAL_OES: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4705 | unit.bound_texture_external_oes = texture_ref; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 4706 | break; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4707 | case GL_TEXTURE_RECTANGLE_ARB: |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4708 | unit.bound_texture_rectangle_arb = texture_ref; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 4709 | break; |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 4710 | case GL_TEXTURE_3D: |
| 4711 | unit.bound_texture_3d = texture_ref; |
| 4712 | break; |
| 4713 | case GL_TEXTURE_2D_ARRAY: |
| 4714 | unit.bound_texture_2d_array = texture_ref; |
| 4715 | break; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4716 | default: |
| 4717 | NOTREACHED(); // Validation should prevent us getting here. |
| 4718 | break; |
| 4719 | } |
| 4720 | } |
| 4721 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4722 | void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4723 | if (state_.vertex_attrib_manager->Enable(index, false)) { |
[email protected] | 1071e57 | 2011-02-09 20:00:12 | [diff] [blame] | 4724 | if (index != 0 || |
| 4725 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 4726 | glDisableVertexAttribArray(index); |
| 4727 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4728 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4729 | LOCAL_SET_GL_ERROR( |
| 4730 | GL_INVALID_VALUE, |
| 4731 | "glDisableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4732 | } |
| 4733 | } |
| 4734 | |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4735 | void GLES2DecoderImpl::DoDiscardFramebufferEXT(GLenum target, |
| 4736 | GLsizei numAttachments, |
| 4737 | const GLenum* attachments) { |
aelias | 8ef99b8a | 2015-04-07 23:19:35 | [diff] [blame] | 4738 | if (workarounds().disable_discard_framebuffer) |
dyen | 5f38cadc | 2015-03-26 16:58:42 | [diff] [blame] | 4739 | return; |
| 4740 | |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 4741 | Framebuffer* framebuffer = |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4742 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 4743 | |
| 4744 | // Validates the attachments. If one of them fails |
| 4745 | // the whole command fails. |
| 4746 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4747 | if ((framebuffer && |
| 4748 | !validators_->attachment.IsValid(attachments[i])) || |
| 4749 | (!framebuffer && |
| 4750 | !validators_->backbuffer_attachment.IsValid(attachments[i]))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4751 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 4752 | "glDiscardFramebufferEXT", attachments[i], "attachments"); |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4753 | return; |
| 4754 | } |
| 4755 | } |
| 4756 | |
| 4757 | // Marks each one of them as not cleared |
| 4758 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4759 | if (framebuffer) { |
| 4760 | framebuffer->MarkAttachmentAsCleared(renderbuffer_manager(), |
| 4761 | texture_manager(), |
| 4762 | attachments[i], |
| 4763 | false); |
| 4764 | } else { |
| 4765 | switch (attachments[i]) { |
| 4766 | case GL_COLOR_EXT: |
| 4767 | backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| 4768 | break; |
| 4769 | case GL_DEPTH_EXT: |
| 4770 | backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
| 4771 | case GL_STENCIL_EXT: |
| 4772 | backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
| 4773 | break; |
| 4774 | default: |
| 4775 | NOTREACHED(); |
| 4776 | break; |
| 4777 | } |
| 4778 | } |
| 4779 | } |
| 4780 | |
[email protected] | d49c540 | 2013-09-11 15:39:02 | [diff] [blame] | 4781 | // If the default framebuffer is bound but we are still rendering to an |
| 4782 | // FBO, translate attachment names that refer to default framebuffer |
| 4783 | // channels to corresponding framebuffer attachments. |
| 4784 | scoped_ptr<GLenum[]> translated_attachments(new GLenum[numAttachments]); |
| 4785 | for (GLsizei i = 0; i < numAttachments; ++i) { |
| 4786 | GLenum attachment = attachments[i]; |
| 4787 | if (!framebuffer && GetBackbufferServiceId()) { |
| 4788 | switch (attachment) { |
| 4789 | case GL_COLOR_EXT: |
| 4790 | attachment = GL_COLOR_ATTACHMENT0; |
| 4791 | break; |
| 4792 | case GL_DEPTH_EXT: |
| 4793 | attachment = GL_DEPTH_ATTACHMENT; |
| 4794 | break; |
| 4795 | case GL_STENCIL_EXT: |
| 4796 | attachment = GL_STENCIL_ATTACHMENT; |
| 4797 | break; |
| 4798 | default: |
| 4799 | NOTREACHED(); |
| 4800 | return; |
| 4801 | } |
| 4802 | } |
| 4803 | translated_attachments[i] = attachment; |
| 4804 | } |
| 4805 | |
boliu | 2e7d8a7a | 2014-10-16 20:35:20 | [diff] [blame] | 4806 | ScopedRenderTo do_render(framebuffer); |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 4807 | if (feature_info_->gl_version_info().is_es3) { |
zmo | 68fcdc6 | 2014-12-05 21:51:49 | [diff] [blame] | 4808 | glInvalidateFramebuffer( |
| 4809 | target, numAttachments, translated_attachments.get()); |
| 4810 | } else { |
| 4811 | glDiscardFramebufferEXT( |
| 4812 | target, numAttachments, translated_attachments.get()); |
| 4813 | } |
[email protected] | 60f22d3 | 2012-12-12 00:31:58 | [diff] [blame] | 4814 | } |
| 4815 | |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4816 | void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 4817 | if (state_.vertex_attrib_manager->Enable(index, true)) { |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4818 | glEnableVertexAttribArray(index); |
| 4819 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4820 | LOCAL_SET_GL_ERROR( |
| 4821 | GL_INVALID_VALUE, "glEnableVertexAttribArray", "index out of range"); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 4822 | } |
| 4823 | } |
| 4824 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4825 | void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 4826 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 4827 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4828 | if (!texture_ref || |
| 4829 | !texture_manager()->CanGenerateMipmaps(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4830 | LOCAL_SET_GL_ERROR( |
| 4831 | GL_INVALID_OPERATION, "glGenerateMipmap", "Can not generate mips"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4832 | return; |
| 4833 | } |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4834 | |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4835 | if (target == GL_TEXTURE_CUBE_MAP) { |
| 4836 | for (int i = 0; i < 6; ++i) { |
| 4837 | GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4838 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, face, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4839 | LOCAL_SET_GL_ERROR( |
| 4840 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4841 | return; |
| 4842 | } |
| 4843 | } |
| 4844 | } else { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4845 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, 0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4846 | LOCAL_SET_GL_ERROR( |
| 4847 | GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); |
[email protected] | 12d9535 | 2012-12-14 07:23:54 | [diff] [blame] | 4848 | return; |
| 4849 | } |
[email protected] | 7687479c | 2012-05-14 23:54:04 | [diff] [blame] | 4850 | } |
| 4851 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4852 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glGenerateMipmap"); |
[email protected] | 59f3ca0 | 2011-03-26 22:24:19 | [diff] [blame] | 4853 | // Workaround for Mac driver bug. In the large scheme of things setting |
| 4854 | // glTexParamter twice for glGenerateMipmap is probably not a lage performance |
[email protected] | a8bad26 | 2011-10-21 18:28:56 | [diff] [blame] | 4855 | // hit so there's probably no need to make this conditional. The bug appears |
| 4856 | // to be that if the filtering mode is set to something that doesn't require |
| 4857 | // mipmaps for rendering, or is never set to something other than the default, |
| 4858 | // then glGenerateMipmap misbehaves. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4859 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4860 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); |
| 4861 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4862 | glGenerateMipmapEXT(target); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 4863 | if (workarounds().set_texture_filter_before_generating_mipmap) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4864 | glTexParameteri(target, GL_TEXTURE_MIN_FILTER, |
| 4865 | texture_ref->texture()->min_filter()); |
[email protected] | c892a4e1 | 2012-05-08 18:20:19 | [diff] [blame] | 4866 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 4867 | GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4868 | if (error == GL_NO_ERROR) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 4869 | texture_manager()->MarkMipmapsGenerated(texture_ref); |
[email protected] | 38c0a97 | 2012-05-12 00:48:02 | [diff] [blame] | 4870 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 4871 | } |
| 4872 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4873 | bool GLES2DecoderImpl::GetHelper( |
| 4874 | GLenum pname, GLint* params, GLsizei* num_written) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 4875 | DCHECK(num_written); |
[email protected] | b9363b2 | 2010-06-09 22:06:15 | [diff] [blame] | 4876 | if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { |
| 4877 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4878 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
| 4879 | *num_written = 1; |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 4880 | // Return the GL implementation's preferred format and (see below type) |
| 4881 | // if we have the GL extension that exposes this. This allows the GPU |
| 4882 | // client to use the implementation's preferred format for glReadPixels |
| 4883 | // for optimisation. |
| 4884 | // |
| 4885 | // A conflicting extension (GL_ARB_ES2_compatibility) specifies an error |
| 4886 | // case when requested on integer/floating point buffers but which is |
| 4887 | // acceptable on GLES2 and with the GL_OES_read_format extension. |
| 4888 | // |
| 4889 | // Therefore if an error occurs we swallow the error and use the |
| 4890 | // internal implementation. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4891 | if (params) { |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 4892 | if (context_->HasExtension("GL_OES_read_format")) { |
| 4893 | ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::GetHelper", |
| 4894 | GetErrorState()); |
| 4895 | glGetIntegerv(pname, params); |
| 4896 | if (glGetError() == GL_NO_ERROR) |
| 4897 | return true; |
| 4898 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 4899 | *params = GLES2Util::GetPreferredGLReadPixelsFormat( |
| 4900 | GetBoundReadFrameBufferInternalFormat()); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4901 | } |
| 4902 | return true; |
| 4903 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 4904 | *num_written = 1; |
| 4905 | if (params) { |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 4906 | if (context_->HasExtension("GL_OES_read_format")) { |
| 4907 | ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::GetHelper", |
| 4908 | GetErrorState()); |
| 4909 | glGetIntegerv(pname, params); |
| 4910 | if (glGetError() == GL_NO_ERROR) |
| 4911 | return true; |
| 4912 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 4913 | *params = GLES2Util::GetPreferredGLReadPixelsType( |
| 4914 | GetBoundReadFrameBufferInternalFormat(), |
| 4915 | GetBoundReadFrameBufferTextureType()); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 4916 | } |
| 4917 | return true; |
| 4918 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 4919 | *num_written = 1; |
| 4920 | if (params) { |
| 4921 | *params = group_->max_fragment_uniform_vectors(); |
| 4922 | } |
| 4923 | return true; |
| 4924 | case GL_MAX_VARYING_VECTORS: |
| 4925 | *num_written = 1; |
| 4926 | if (params) { |
| 4927 | *params = group_->max_varying_vectors(); |
| 4928 | } |
| 4929 | return true; |
| 4930 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 4931 | *num_written = 1; |
| 4932 | if (params) { |
| 4933 | *params = group_->max_vertex_uniform_vectors(); |
| 4934 | } |
| 4935 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 4936 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4937 | } |
kbr | 9370c84 | 2015-05-22 02:36:29 | [diff] [blame] | 4938 | if (unsafe_es3_apis_enabled()) { |
| 4939 | switch (pname) { |
| 4940 | case GL_MAX_VARYING_COMPONENTS: { |
| 4941 | if (feature_info_->gl_version_info().is_es) { |
| 4942 | // We can just delegate this query to the driver. |
| 4943 | return false; |
| 4944 | } |
| 4945 | |
| 4946 | // GL_MAX_VARYING_COMPONENTS is deprecated in the desktop |
| 4947 | // OpenGL core profile, so for simplicity, just compute it |
| 4948 | // from GL_MAX_VARYING_VECTORS on non-OpenGL ES |
| 4949 | // configurations. |
| 4950 | GLint max_varying_vectors = 0; |
| 4951 | glGetIntegerv(GL_MAX_VARYING_VECTORS, &max_varying_vectors); |
| 4952 | *num_written = 1; |
| 4953 | if (params) { |
| 4954 | *params = max_varying_vectors * 4; |
| 4955 | } |
| 4956 | return true; |
| 4957 | } |
| 4958 | } |
| 4959 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4960 | switch (pname) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 4961 | case GL_MAX_VIEWPORT_DIMS: |
| 4962 | if (offscreen_target_frame_buffer_.get()) { |
| 4963 | *num_written = 2; |
| 4964 | if (params) { |
| 4965 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4966 | params[1] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4967 | } |
| 4968 | return true; |
| 4969 | } |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4970 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 4971 | case GL_MAX_SAMPLES: |
| 4972 | *num_written = 1; |
| 4973 | if (params) { |
| 4974 | params[0] = renderbuffer_manager()->max_samples(); |
| 4975 | } |
| 4976 | return true; |
| 4977 | case GL_MAX_RENDERBUFFER_SIZE: |
| 4978 | *num_written = 1; |
| 4979 | if (params) { |
| 4980 | params[0] = renderbuffer_manager()->max_renderbuffer_size(); |
| 4981 | } |
| 4982 | return true; |
[email protected] | 5cb735d | 2011-10-13 01:37:23 | [diff] [blame] | 4983 | case GL_MAX_TEXTURE_SIZE: |
| 4984 | *num_written = 1; |
| 4985 | if (params) { |
| 4986 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_2D); |
| 4987 | } |
| 4988 | return true; |
| 4989 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 4990 | *num_written = 1; |
| 4991 | if (params) { |
| 4992 | params[0] = texture_manager()->MaxSizeForTarget(GL_TEXTURE_CUBE_MAP); |
| 4993 | } |
| 4994 | return true; |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 4995 | case GL_MAX_COLOR_ATTACHMENTS_EXT: |
| 4996 | *num_written = 1; |
| 4997 | if (params) { |
| 4998 | params[0] = group_->max_color_attachments(); |
| 4999 | } |
| 5000 | return true; |
| 5001 | case GL_MAX_DRAW_BUFFERS_ARB: |
| 5002 | *num_written = 1; |
| 5003 | if (params) { |
| 5004 | params[0] = group_->max_draw_buffers(); |
| 5005 | } |
| 5006 | return true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5007 | case GL_ALPHA_BITS: |
| 5008 | *num_written = 1; |
| 5009 | if (params) { |
| 5010 | GLint v = 0; |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 5011 | if (feature_info_->gl_version_info().is_desktop_core_profile) { |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 5012 | Framebuffer* framebuffer = |
| 5013 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 5014 | if (framebuffer) { |
| 5015 | glGetFramebufferAttachmentParameterivEXT( |
| 5016 | GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 5017 | GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE, &v); |
| 5018 | } else { |
| 5019 | v = (back_buffer_color_format_ == GL_RGBA ? 8 : 0); |
| 5020 | } |
| 5021 | } else { |
| 5022 | glGetIntegerv(GL_ALPHA_BITS, &v); |
| 5023 | } |
| 5024 | params[0] = |
| 5025 | BoundFramebufferHasColorAttachmentWithAlpha(false) ? v : 0; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5026 | } |
| 5027 | return true; |
| 5028 | case GL_DEPTH_BITS: |
| 5029 | *num_written = 1; |
| 5030 | if (params) { |
| 5031 | GLint v = 0; |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 5032 | if (feature_info_->gl_version_info().is_desktop_core_profile) { |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 5033 | Framebuffer* framebuffer = |
| 5034 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 5035 | if (framebuffer) { |
| 5036 | glGetFramebufferAttachmentParameterivEXT( |
| 5037 | GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, |
| 5038 | GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE, &v); |
| 5039 | } else { |
| 5040 | v = (back_buffer_has_depth_ ? 24 : 0); |
| 5041 | } |
| 5042 | } else { |
| 5043 | glGetIntegerv(GL_DEPTH_BITS, &v); |
| 5044 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5045 | params[0] = BoundFramebufferHasDepthAttachment() ? v : 0; |
| 5046 | } |
| 5047 | return true; |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 5048 | case GL_RED_BITS: |
| 5049 | case GL_GREEN_BITS: |
| 5050 | case GL_BLUE_BITS: |
| 5051 | *num_written = 1; |
| 5052 | if (params) { |
| 5053 | GLint v = 0; |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 5054 | if (feature_info_->gl_version_info().is_desktop_core_profile) { |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 5055 | Framebuffer* framebuffer = |
| 5056 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 5057 | if (framebuffer) { |
| 5058 | GLenum framebuffer_enum = 0; |
| 5059 | switch (pname) { |
| 5060 | case GL_RED_BITS: |
| 5061 | framebuffer_enum = GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE; |
| 5062 | break; |
| 5063 | case GL_GREEN_BITS: |
| 5064 | framebuffer_enum = GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE; |
| 5065 | break; |
| 5066 | case GL_BLUE_BITS: |
| 5067 | framebuffer_enum = GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE; |
| 5068 | break; |
| 5069 | } |
| 5070 | glGetFramebufferAttachmentParameterivEXT( |
| 5071 | GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, framebuffer_enum, &v); |
| 5072 | } else { |
| 5073 | v = 8; |
| 5074 | } |
| 5075 | } else { |
| 5076 | glGetIntegerv(pname, &v); |
| 5077 | } |
| 5078 | params[0] = v; |
| 5079 | } |
| 5080 | return true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5081 | case GL_STENCIL_BITS: |
| 5082 | *num_written = 1; |
| 5083 | if (params) { |
| 5084 | GLint v = 0; |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 5085 | if (feature_info_->gl_version_info().is_desktop_core_profile) { |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 5086 | Framebuffer* framebuffer = |
| 5087 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 5088 | if (framebuffer) { |
| 5089 | glGetFramebufferAttachmentParameterivEXT( |
| 5090 | GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, |
| 5091 | GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE, &v); |
| 5092 | } else { |
| 5093 | v = (back_buffer_has_stencil_ ? 8 : 0); |
| 5094 | } |
| 5095 | } else { |
| 5096 | glGetIntegerv(GL_STENCIL_BITS, &v); |
| 5097 | } |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5098 | params[0] = BoundFramebufferHasStencilAttachment() ? v : 0; |
| 5099 | } |
| 5100 | return true; |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 5101 | case GL_COMPRESSED_TEXTURE_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 5102 | *num_written = validators_->compressed_texture_format.GetValues().size(); |
| 5103 | if (params) { |
| 5104 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 5105 | params[ii] = validators_->compressed_texture_format.GetValues()[ii]; |
| 5106 | } |
| 5107 | } |
[email protected] | 656dcaad | 2010-05-07 17:18:37 | [diff] [blame] | 5108 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5109 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 5110 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5111 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 5112 | *params = validators_->compressed_texture_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5113 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5114 | return true; |
| 5115 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 5116 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5117 | if (params) { |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 5118 | *params = validators_->shader_binary_format.GetValues().size(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5119 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5120 | return true; |
| 5121 | case GL_SHADER_BINARY_FORMATS: |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 5122 | *num_written = validators_->shader_binary_format.GetValues().size(); |
| 5123 | if (params) { |
| 5124 | for (GLint ii = 0; ii < *num_written; ++ii) { |
| 5125 | params[ii] = validators_->shader_binary_format.GetValues()[ii]; |
| 5126 | } |
| 5127 | } |
| 5128 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5129 | case GL_SHADER_COMPILER: |
| 5130 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5131 | if (params) { |
| 5132 | *params = GL_TRUE; |
| 5133 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5134 | return true; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5135 | case GL_ARRAY_BUFFER_BINDING: |
| 5136 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5137 | if (params) { |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 5138 | *params = GetClientId( |
| 5139 | buffer_manager(), state_.bound_array_buffer.get()); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5140 | } |
| 5141 | return true; |
| 5142 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
| 5143 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5144 | if (params) { |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 5145 | *params = GetClientId( |
| 5146 | buffer_manager(), |
| 5147 | state_.vertex_attrib_manager->element_array_buffer()); |
| 5148 | } |
| 5149 | return true; |
| 5150 | case GL_COPY_READ_BUFFER_BINDING: |
| 5151 | *num_written = 1; |
| 5152 | if (params) { |
| 5153 | *params = GetClientId( |
| 5154 | buffer_manager(), state_.bound_copy_read_buffer.get()); |
| 5155 | } |
| 5156 | return true; |
| 5157 | case GL_COPY_WRITE_BUFFER_BINDING: |
| 5158 | *num_written = 1; |
| 5159 | if (params) { |
| 5160 | *params = GetClientId( |
| 5161 | buffer_manager(), state_.bound_copy_write_buffer.get()); |
| 5162 | } |
| 5163 | return true; |
| 5164 | case GL_PIXEL_PACK_BUFFER_BINDING: |
| 5165 | *num_written = 1; |
| 5166 | if (params) { |
| 5167 | *params = GetClientId( |
| 5168 | buffer_manager(), state_.bound_pixel_pack_buffer.get()); |
| 5169 | } |
| 5170 | return true; |
| 5171 | case GL_PIXEL_UNPACK_BUFFER_BINDING: |
| 5172 | *num_written = 1; |
| 5173 | if (params) { |
| 5174 | *params = GetClientId( |
| 5175 | buffer_manager(), state_.bound_pixel_unpack_buffer.get()); |
| 5176 | } |
| 5177 | return true; |
| 5178 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 5179 | *num_written = 1; |
| 5180 | if (params) { |
| 5181 | *params = GetClientId( |
| 5182 | buffer_manager(), state_.bound_transform_feedback_buffer.get()); |
| 5183 | } |
| 5184 | return true; |
| 5185 | case GL_UNIFORM_BUFFER_BINDING: |
| 5186 | *num_written = 1; |
| 5187 | if (params) { |
| 5188 | *params = GetClientId( |
| 5189 | buffer_manager(), state_.bound_uniform_buffer.get()); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5190 | } |
| 5191 | return true; |
| 5192 | case GL_FRAMEBUFFER_BINDING: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5193 | // case GL_DRAW_FRAMEBUFFER_BINDING_EXT: (same as GL_FRAMEBUFFER_BINDING) |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5194 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5195 | if (params) { |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 5196 | *params = GetClientId( |
| 5197 | framebuffer_manager(), |
| 5198 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER)); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5199 | } |
| 5200 | return true; |
[email protected] | ebfb73c | 2012-08-15 02:37:45 | [diff] [blame] | 5201 | case GL_READ_FRAMEBUFFER_BINDING_EXT: |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5202 | *num_written = 1; |
| 5203 | if (params) { |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 5204 | *params = GetClientId( |
| 5205 | framebuffer_manager(), |
| 5206 | GetFramebufferInfoForTarget(GL_READ_FRAMEBUFFER_EXT)); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5207 | } |
| 5208 | return true; |
| 5209 | case GL_RENDERBUFFER_BINDING: |
| 5210 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5211 | if (params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5212 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5213 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5214 | if (renderbuffer) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5215 | *params = renderbuffer->client_id(); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5216 | } else { |
| 5217 | *params = 0; |
| 5218 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5219 | } |
| 5220 | return true; |
| 5221 | case GL_CURRENT_PROGRAM: |
| 5222 | *num_written = 1; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5223 | if (params) { |
zmo | 4c0c353 | 2015-05-22 20:04:48 | [diff] [blame] | 5224 | *params = GetClientId(program_manager(), state_.current_program.get()); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5225 | } |
| 5226 | return true; |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 5227 | case GL_VERTEX_ARRAY_BINDING_OES: |
| 5228 | *num_written = 1; |
| 5229 | if (params) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5230 | if (state_.vertex_attrib_manager.get() != |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 5231 | state_.default_vertex_attrib_manager.get()) { |
[email protected] | bf83584 | 2012-11-19 15:21:51 | [diff] [blame] | 5232 | GLuint client_id = 0; |
| 5233 | vertex_array_manager_->GetClientId( |
| 5234 | state_.vertex_attrib_manager->service_id(), &client_id); |
| 5235 | *params = client_id; |
| 5236 | } else { |
| 5237 | *params = 0; |
| 5238 | } |
| 5239 | } |
| 5240 | return true; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5241 | case GL_TEXTURE_BINDING_2D: |
| 5242 | *num_written = 1; |
| 5243 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5244 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5245 | if (unit.bound_texture_2d.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5246 | *params = unit.bound_texture_2d->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5247 | } else { |
| 5248 | *params = 0; |
| 5249 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5250 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5251 | return true; |
| 5252 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 5253 | *num_written = 1; |
| 5254 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5255 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5256 | if (unit.bound_texture_cube_map.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5257 | *params = unit.bound_texture_cube_map->client_id(); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5258 | } else { |
| 5259 | *params = 0; |
| 5260 | } |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5261 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5262 | return true; |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 5263 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 5264 | *num_written = 1; |
| 5265 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5266 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5267 | if (unit.bound_texture_external_oes.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5268 | *params = unit.bound_texture_external_oes->client_id(); |
[email protected] | 61eeb33f | 2011-07-26 15:30:31 | [diff] [blame] | 5269 | } else { |
| 5270 | *params = 0; |
| 5271 | } |
| 5272 | } |
| 5273 | return true; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 5274 | case GL_TEXTURE_BINDING_RECTANGLE_ARB: |
| 5275 | *num_written = 1; |
| 5276 | if (params) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5277 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 5278 | if (unit.bound_texture_rectangle_arb.get()) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5279 | *params = unit.bound_texture_rectangle_arb->client_id(); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 5280 | } else { |
| 5281 | *params = 0; |
| 5282 | } |
| 5283 | } |
| 5284 | return true; |
[email protected] | 6eda682 | 2014-04-03 23:00:50 | [diff] [blame] | 5285 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 5286 | *num_written = 1; |
| 5287 | if (params) { |
| 5288 | params[0] = group_->bind_generates_resource() ? 1 : 0; |
| 5289 | } |
| 5290 | return true; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5291 | default: |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 5292 | if (pname >= GL_DRAW_BUFFER0_ARB && |
| 5293 | pname < GL_DRAW_BUFFER0_ARB + group_->max_draw_buffers()) { |
| 5294 | *num_written = 1; |
| 5295 | if (params) { |
| 5296 | Framebuffer* framebuffer = |
| 5297 | GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 5298 | if (framebuffer) { |
| 5299 | params[0] = framebuffer->GetDrawBuffer(pname); |
| 5300 | } else { // backbuffer |
| 5301 | if (pname == GL_DRAW_BUFFER0_ARB) |
| 5302 | params[0] = group_->draw_buffer(); |
| 5303 | else |
| 5304 | params[0] = GL_NONE; |
| 5305 | } |
| 5306 | } |
| 5307 | return true; |
| 5308 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5309 | *num_written = util_.GLGetNumValuesReturned(pname); |
[email protected] | c5d79834 | 2010-09-24 20:42:53 | [diff] [blame] | 5310 | return false; |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5311 | } |
| 5312 | } |
| 5313 | |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5314 | bool GLES2DecoderImpl::GetNumValuesReturnedForGLGet( |
| 5315 | GLenum pname, GLsizei* num_values) { |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 5316 | if (state_.GetStateAsGLint(pname, NULL, num_values)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 5317 | return true; |
| 5318 | } |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5319 | return GetHelper(pname, NULL, num_values); |
| 5320 | } |
| 5321 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5322 | GLenum GLES2DecoderImpl::AdjustGetPname(GLenum pname) { |
| 5323 | if (GL_MAX_SAMPLES == pname && |
| 5324 | features().use_img_for_multisampled_render_to_texture) { |
| 5325 | return GL_MAX_SAMPLES_IMG; |
| 5326 | } |
| 5327 | return pname; |
| 5328 | } |
| 5329 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5330 | void GLES2DecoderImpl::DoGetBooleanv(GLenum pname, GLboolean* params) { |
| 5331 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5332 | GLsizei num_written = 0; |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 5333 | if (GetNumValuesReturnedForGLGet(pname, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5334 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 5335 | if (!state_.GetStateAsGLint(pname, values.get(), &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 5336 | GetHelper(pname, values.get(), &num_written); |
| 5337 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5338 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 5339 | params[ii] = static_cast<GLboolean>(values[ii]); |
| 5340 | } |
| 5341 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5342 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5343 | glGetBooleanv(pname, params); |
| 5344 | } |
| 5345 | } |
| 5346 | |
| 5347 | void GLES2DecoderImpl::DoGetFloatv(GLenum pname, GLfloat* params) { |
| 5348 | DCHECK(params); |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 5349 | GLsizei num_written = 0; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 5350 | if (!state_.GetStateAsGLfloat(pname, params, &num_written)) { |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 5351 | if (GetHelper(pname, NULL, &num_written)) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 5352 | scoped_ptr<GLint[]> values(new GLint[num_written]); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 5353 | GetHelper(pname, values.get(), &num_written); |
| 5354 | for (GLsizei ii = 0; ii < num_written; ++ii) { |
| 5355 | params[ii] = static_cast<GLfloat>(values[ii]); |
| 5356 | } |
| 5357 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5358 | pname = AdjustGetPname(pname); |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 5359 | glGetFloatv(pname, params); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5360 | } |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5361 | } |
| 5362 | } |
| 5363 | |
zmo | 8ac3bab | 2015-04-18 02:30:58 | [diff] [blame] | 5364 | void GLES2DecoderImpl::DoGetInteger64v(GLenum pname, GLint64* params) { |
| 5365 | DCHECK(params); |
kbr | 9370c84 | 2015-05-22 02:36:29 | [diff] [blame] | 5366 | if (unsafe_es3_apis_enabled()) { |
| 5367 | switch (pname) { |
| 5368 | case GL_MAX_ELEMENT_INDEX: { |
| 5369 | if (feature_info_->gl_version_info().IsAtLeastGLES(3, 0) || |
| 5370 | feature_info_->gl_version_info().IsAtLeastGL(4, 3)) { |
| 5371 | glGetInteger64v(GL_MAX_ELEMENT_INDEX, params); |
| 5372 | } else { |
| 5373 | // Assume that desktop GL implementations can generally support |
| 5374 | // 32-bit indices. |
| 5375 | if (params) { |
| 5376 | *params = std::numeric_limits<unsigned int>::max(); |
| 5377 | } |
| 5378 | } |
| 5379 | return; |
| 5380 | } |
| 5381 | } |
| 5382 | } |
zmo | 8ac3bab | 2015-04-18 02:30:58 | [diff] [blame] | 5383 | pname = AdjustGetPname(pname); |
| 5384 | glGetInteger64v(pname, params); |
| 5385 | } |
| 5386 | |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5387 | void GLES2DecoderImpl::DoGetIntegerv(GLenum pname, GLint* params) { |
| 5388 | DCHECK(params); |
| 5389 | GLsizei num_written; |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 5390 | if (!state_.GetStateAsGLint(pname, params, &num_written) && |
[email protected] | f63b123 | 2012-10-31 07:03:53 | [diff] [blame] | 5391 | !GetHelper(pname, params, &num_written)) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5392 | pname = AdjustGetPname(pname); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 5393 | glGetIntegerv(pname, params); |
| 5394 | } |
| 5395 | } |
| 5396 | |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 5397 | void GLES2DecoderImpl::DoGetProgramiv( |
| 5398 | GLuint program_id, GLenum pname, GLint* params) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5399 | Program* program = GetProgramInfoNotShader(program_id, "glGetProgramiv"); |
| 5400 | if (!program) { |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 5401 | return; |
| 5402 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5403 | program->GetProgramiv(pname, params); |
[email protected] | a0c3e97 | 2010-04-21 00:49:13 | [diff] [blame] | 5404 | } |
| 5405 | |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 5406 | void GLES2DecoderImpl::DoGetBufferParameteriv( |
| 5407 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 5408 | // Just delegate it. Some validation is actually done before this. |
| 5409 | buffer_manager()->ValidateAndDoGetBufferParameteriv( |
| 5410 | &state_, target, pname, params); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 5411 | } |
| 5412 | |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5413 | void GLES2DecoderImpl::DoBindAttribLocation( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5414 | GLuint program_id, GLuint index, const char* name) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5415 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5416 | LOCAL_SET_GL_ERROR( |
| 5417 | GL_INVALID_VALUE, "glBindAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5418 | return; |
| 5419 | } |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 5420 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5421 | LOCAL_SET_GL_ERROR( |
| 5422 | GL_INVALID_OPERATION, "glBindAttribLocation", "reserved prefix"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 5423 | return; |
| 5424 | } |
| 5425 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5426 | LOCAL_SET_GL_ERROR( |
| 5427 | GL_INVALID_VALUE, "glBindAttribLocation", "index out of range"); |
[email protected] | 68dcb1f | 2012-04-07 00:14:56 | [diff] [blame] | 5428 | return; |
| 5429 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5430 | Program* program = GetProgramInfoNotShader( |
| 5431 | program_id, "glBindAttribLocation"); |
| 5432 | if (!program) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5433 | return; |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5434 | } |
zmo | 460b593e | 2014-10-13 23:07:45 | [diff] [blame] | 5435 | // At this point, the program's shaders may not be translated yet, |
| 5436 | // therefore, we may not find the hashed attribute name. |
| 5437 | // glBindAttribLocation call with original name is useless. |
| 5438 | // So instead, we should simply cache the binding, and then call |
| 5439 | // Program::ExecuteBindAttribLocationCalls() right before link. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5440 | program->SetAttribLocationBinding(name, static_cast<GLint>(index)); |
zmo | 460b593e | 2014-10-13 23:07:45 | [diff] [blame] | 5441 | // TODO(zmo): Get rid of the following glBindAttribLocation call. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5442 | glBindAttribLocation(program->service_id(), index, name); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5443 | } |
| 5444 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5445 | error::Error GLES2DecoderImpl::HandleBindAttribLocationBucket( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 5446 | uint32 immediate_data_size, |
| 5447 | const void* cmd_data) { |
| 5448 | const gles2::cmds::BindAttribLocationBucket& c = |
| 5449 | *static_cast<const gles2::cmds::BindAttribLocationBucket*>(cmd_data); |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 5450 | GLuint program = static_cast<GLuint>(c.program); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5451 | GLuint index = static_cast<GLuint>(c.index); |
| 5452 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 5453 | if (!bucket || bucket->size() == 0) { |
| 5454 | return error::kInvalidArguments; |
| 5455 | } |
| 5456 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 5457 | if (!bucket->GetAsString(&name_str)) { |
| 5458 | return error::kInvalidArguments; |
| 5459 | } |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 5460 | DoBindAttribLocation(program, index, name_str.c_str()); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 5461 | return error::kNoError; |
| 5462 | } |
| 5463 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5464 | void GLES2DecoderImpl::DoBindUniformLocationCHROMIUM( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5465 | GLuint program_id, GLint location, const char* name) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5466 | if (!StringIsValidForGLES(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5467 | LOCAL_SET_GL_ERROR( |
| 5468 | GL_INVALID_VALUE, |
| 5469 | "glBindUniformLocationCHROMIUM", "Invalid character"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5470 | return; |
| 5471 | } |
| 5472 | if (ProgramManager::IsInvalidPrefix(name, strlen(name))) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5473 | LOCAL_SET_GL_ERROR( |
| 5474 | GL_INVALID_OPERATION, |
| 5475 | "glBindUniformLocationCHROMIUM", "reserved prefix"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5476 | return; |
| 5477 | } |
| 5478 | if (location < 0 || static_cast<uint32>(location) >= |
| 5479 | (group_->max_fragment_uniform_vectors() + |
| 5480 | group_->max_vertex_uniform_vectors()) * 4) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5481 | LOCAL_SET_GL_ERROR( |
| 5482 | GL_INVALID_VALUE, |
| 5483 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5484 | return; |
| 5485 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5486 | Program* program = GetProgramInfoNotShader( |
| 5487 | program_id, "glBindUniformLocationCHROMIUM"); |
| 5488 | if (!program) { |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5489 | return; |
| 5490 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5491 | if (!program->SetUniformLocationBinding(name, location)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5492 | LOCAL_SET_GL_ERROR( |
| 5493 | GL_INVALID_VALUE, |
| 5494 | "glBindUniformLocationCHROMIUM", "location out of range"); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5495 | } |
| 5496 | } |
| 5497 | |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5498 | error::Error GLES2DecoderImpl::HandleBindUniformLocationCHROMIUMBucket( |
| 5499 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 5500 | const void* cmd_data) { |
| 5501 | const gles2::cmds::BindUniformLocationCHROMIUMBucket& c = |
| 5502 | *static_cast<const gles2::cmds::BindUniformLocationCHROMIUMBucket*>( |
| 5503 | cmd_data); |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 5504 | GLuint program = static_cast<GLuint>(c.program); |
| 5505 | GLint location = static_cast<GLint>(c.location); |
| 5506 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 5507 | if (!bucket || bucket->size() == 0) { |
| 5508 | return error::kInvalidArguments; |
| 5509 | } |
| 5510 | std::string name_str; |
| 5511 | if (!bucket->GetAsString(&name_str)) { |
| 5512 | return error::kInvalidArguments; |
| 5513 | } |
| 5514 | DoBindUniformLocationCHROMIUM(program, location, name_str.c_str()); |
| 5515 | return error::kNoError; |
| 5516 | } |
| 5517 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 5518 | error::Error GLES2DecoderImpl::HandleDeleteShader(uint32 immediate_data_size, |
| 5519 | const void* cmd_data) { |
| 5520 | const gles2::cmds::DeleteShader& c = |
| 5521 | *static_cast<const gles2::cmds::DeleteShader*>(cmd_data); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5522 | GLuint client_id = c.shader; |
| 5523 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5524 | Shader* shader = GetShader(client_id); |
| 5525 | if (shader) { |
| 5526 | if (!shader->IsDeleted()) { |
dyen | c6a36cdd | 2015-02-25 05:24:31 | [diff] [blame] | 5527 | shader_manager()->Delete(shader); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5528 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5529 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5530 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glDeleteShader", "unknown shader"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5531 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5532 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5533 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5534 | } |
| 5535 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 5536 | error::Error GLES2DecoderImpl::HandleDeleteProgram(uint32 immediate_data_size, |
| 5537 | const void* cmd_data) { |
| 5538 | const gles2::cmds::DeleteProgram& c = |
| 5539 | *static_cast<const gles2::cmds::DeleteProgram*>(cmd_data); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5540 | GLuint client_id = c.program; |
| 5541 | if (client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 5542 | Program* program = GetProgram(client_id); |
| 5543 | if (program) { |
| 5544 | if (!program->IsDeleted()) { |
| 5545 | program_manager()->MarkAsDeleted(shader_manager(), program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 5546 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5547 | } else { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5548 | LOCAL_SET_GL_ERROR( |
| 5549 | GL_INVALID_VALUE, "glDeleteProgram", "unknown program"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5550 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5551 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 5552 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 5553 | } |
| 5554 | |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 5555 | error::Error GLES2DecoderImpl::DoClear(GLbitfield mask) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 5556 | DCHECK(!ShouldDeferDraws()); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5557 | if (CheckBoundFramebuffersValid("glClear")) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5558 | ApplyDirtyState(); |
boliu | 2e7d8a7a | 2014-10-16 20:35:20 | [diff] [blame] | 5559 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
sievers | 2384f2b | 2014-11-18 02:10:35 | [diff] [blame] | 5560 | if (workarounds().gl_clear_broken) { |
| 5561 | ScopedGLErrorSuppressor suppressor("GLES2DecoderImpl::ClearWorkaround", |
| 5562 | GetErrorState()); |
| 5563 | if (!BoundFramebufferHasDepthAttachment()) |
| 5564 | mask &= ~GL_DEPTH_BUFFER_BIT; |
| 5565 | if (!BoundFramebufferHasStencilAttachment()) |
| 5566 | mask &= ~GL_STENCIL_BUFFER_BIT; |
| 5567 | clear_framebuffer_blit_->ClearFramebuffer( |
| 5568 | this, GetBoundReadFrameBufferSize(), mask, state_.color_clear_red, |
| 5569 | state_.color_clear_green, state_.color_clear_blue, |
| 5570 | state_.color_clear_alpha, state_.depth_clear, state_.stencil_clear); |
| 5571 | return error::kNoError; |
| 5572 | } |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 5573 | glClear(mask); |
| 5574 | } |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 5575 | return error::kNoError; |
| 5576 | } |
| 5577 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5578 | void GLES2DecoderImpl::DoFramebufferRenderbuffer( |
| 5579 | GLenum target, GLenum attachment, GLenum renderbuffertarget, |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5580 | GLuint client_renderbuffer_id) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5581 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5582 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5583 | LOCAL_SET_GL_ERROR( |
| 5584 | GL_INVALID_OPERATION, |
| 5585 | "glFramebufferRenderbuffer", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5586 | return; |
| 5587 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5588 | GLuint service_id = 0; |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5589 | Renderbuffer* renderbuffer = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5590 | if (client_renderbuffer_id) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5591 | renderbuffer = GetRenderbuffer(client_renderbuffer_id); |
| 5592 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5593 | LOCAL_SET_GL_ERROR( |
| 5594 | GL_INVALID_OPERATION, |
| 5595 | "glFramebufferRenderbuffer", "unknown renderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5596 | return; |
| 5597 | } |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5598 | service_id = renderbuffer->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5599 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5600 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glFramebufferRenderbuffer"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5601 | glFramebufferRenderbufferEXT( |
| 5602 | target, attachment, renderbuffertarget, service_id); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5603 | GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferRenderbuffer"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5604 | if (error == GL_NO_ERROR) { |
[email protected] | ee2a79c3 | 2013-03-10 03:50:27 | [diff] [blame] | 5605 | framebuffer->AttachRenderbuffer(attachment, renderbuffer); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5606 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 5607 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5608 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5609 | } |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 5610 | OnFboChanged(); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5611 | } |
| 5612 | |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5613 | void GLES2DecoderImpl::DoDisable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5614 | if (SetCapabilityState(cap, false)) { |
| 5615 | glDisable(cap); |
| 5616 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5617 | } |
| 5618 | |
| 5619 | void GLES2DecoderImpl::DoEnable(GLenum cap) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5620 | if (SetCapabilityState(cap, true)) { |
| 5621 | glEnable(cap); |
| 5622 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5623 | } |
| 5624 | |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 5625 | void GLES2DecoderImpl::DoDepthRangef(GLclampf znear, GLclampf zfar) { |
| 5626 | state_.z_near = std::min(1.0f, std::max(0.0f, znear)); |
| 5627 | state_.z_far = std::min(1.0f, std::max(0.0f, zfar)); |
| 5628 | glDepthRange(znear, zfar); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5629 | } |
| 5630 | |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 5631 | void GLES2DecoderImpl::DoSampleCoverage(GLclampf value, GLboolean invert) { |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 5632 | state_.sample_coverage_value = std::min(1.0f, std::max(0.0f, value)); |
| 5633 | state_.sample_coverage_invert = (invert != 0); |
| 5634 | glSampleCoverage(state_.sample_coverage_value, invert); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5635 | } |
| 5636 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5637 | // Assumes framebuffer is complete. |
| 5638 | void GLES2DecoderImpl::ClearUnclearedAttachments( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5639 | GLenum target, Framebuffer* framebuffer) { |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5640 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5641 | // bind this to the DRAW point, clear then bind back to READ |
| 5642 | // TODO(gman): I don't think there is any guarantee that an FBO that |
| 5643 | // is complete on the READ attachment will be complete as a DRAW |
| 5644 | // attachment. |
| 5645 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5646 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, framebuffer->service_id()); |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5647 | } |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5648 | GLbitfield clear_bits = 0; |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 5649 | if (framebuffer->HasUnclearedColorAttachments()) { |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5650 | glClearColor( |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5651 | 0.0f, 0.0f, 0.0f, |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5652 | (GLES2Util::GetChannelsForFormat( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5653 | framebuffer->GetColorAttachmentFormat()) & 0x0008) != 0 ? 0.0f : |
| 5654 | 1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5655 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5656 | clear_bits |= GL_COLOR_BUFFER_BIT; |
[email protected] | 0e58af8 | 2014-08-08 14:02:53 | [diff] [blame] | 5657 | if (feature_info_->feature_flags().ext_draw_buffers) |
| 5658 | framebuffer->PrepareDrawBuffersForClear(); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5659 | } |
| 5660 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5661 | if (framebuffer->HasUnclearedAttachment(GL_STENCIL_ATTACHMENT) || |
| 5662 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5663 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 5664 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 5665 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5666 | clear_bits |= GL_STENCIL_BUFFER_BIT; |
| 5667 | } |
| 5668 | |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5669 | if (framebuffer->HasUnclearedAttachment(GL_DEPTH_ATTACHMENT) || |
| 5670 | framebuffer->HasUnclearedAttachment(GL_DEPTH_STENCIL_ATTACHMENT)) { |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5671 | glClearDepth(1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5672 | state_.SetDeviceDepthMask(GL_TRUE); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5673 | clear_bits |= GL_DEPTH_BUFFER_BIT; |
| 5674 | } |
| 5675 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5676 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5677 | glClear(clear_bits); |
| 5678 | |
brucedawson | 1824915 | 2014-10-31 23:02:32 | [diff] [blame] | 5679 | if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0 && |
[email protected] | 0e58af8 | 2014-08-08 14:02:53 | [diff] [blame] | 5680 | feature_info_->feature_flags().ext_draw_buffers) |
[email protected] | ee75792 | 2014-06-06 05:21:42 | [diff] [blame] | 5681 | framebuffer->RestoreDrawBuffersAfterClear(); |
| 5682 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 5683 | framebuffer_manager()->MarkAttachmentsAsCleared( |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5684 | framebuffer, renderbuffer_manager(), texture_manager()); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5685 | |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 5686 | RestoreClearState(); |
| 5687 | |
| 5688 | if (target == GL_READ_FRAMEBUFFER_EXT) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5689 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, framebuffer->service_id()); |
| 5690 | Framebuffer* draw_framebuffer = |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 5691 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5692 | GLuint service_id = draw_framebuffer ? draw_framebuffer->service_id() : |
| 5693 | GetBackbufferServiceId(); |
[email protected] | 87d1a3fe | 2011-12-01 04:25:48 | [diff] [blame] | 5694 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, service_id); |
[email protected] | c007aa0 | 2010-09-02 22:22:40 | [diff] [blame] | 5695 | } |
| 5696 | } |
| 5697 | |
| 5698 | void GLES2DecoderImpl::RestoreClearState() { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5699 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 5700 | glClearColor( |
| 5701 | state_.color_clear_red, state_.color_clear_green, state_.color_clear_blue, |
| 5702 | state_.color_clear_alpha); |
| 5703 | glClearStencil(state_.stencil_clear); |
| 5704 | glClearDepth(state_.depth_clear); |
reveman | 842a098 | 2015-06-09 05:14:31 | [diff] [blame] | 5705 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, |
| 5706 | state_.enable_flags.scissor_test); |
| 5707 | glScissor(state_.scissor_x, state_.scissor_y, state_.scissor_width, |
| 5708 | state_.scissor_height); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5709 | } |
| 5710 | |
| 5711 | GLenum GLES2DecoderImpl::DoCheckFramebufferStatus(GLenum target) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5712 | Framebuffer* framebuffer = |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5713 | GetFramebufferInfoForTarget(target); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5714 | if (!framebuffer) { |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5715 | return GL_FRAMEBUFFER_COMPLETE; |
| 5716 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5717 | GLenum completeness = framebuffer->IsPossiblyComplete(); |
| 5718 | if (completeness != GL_FRAMEBUFFER_COMPLETE) { |
| 5719 | return completeness; |
| 5720 | } |
[email protected] | 7327652 | 2012-11-09 05:50:20 | [diff] [blame] | 5721 | return framebuffer->GetStatus(texture_manager(), target); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5722 | } |
| 5723 | |
| 5724 | void GLES2DecoderImpl::DoFramebufferTexture2D( |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5725 | GLenum target, GLenum attachment, GLenum textarget, |
| 5726 | GLuint client_texture_id, GLint level) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5727 | DoFramebufferTexture2DCommon( |
| 5728 | "glFramebufferTexture2D", target, attachment, |
| 5729 | textarget, client_texture_id, level, 0); |
| 5730 | } |
| 5731 | |
| 5732 | void GLES2DecoderImpl::DoFramebufferTexture2DMultisample( |
| 5733 | GLenum target, GLenum attachment, GLenum textarget, |
| 5734 | GLuint client_texture_id, GLint level, GLsizei samples) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5735 | DoFramebufferTexture2DCommon( |
| 5736 | "glFramebufferTexture2DMultisample", target, attachment, |
| 5737 | textarget, client_texture_id, level, samples); |
| 5738 | } |
| 5739 | |
| 5740 | void GLES2DecoderImpl::DoFramebufferTexture2DCommon( |
| 5741 | const char* name, GLenum target, GLenum attachment, GLenum textarget, |
| 5742 | GLuint client_texture_id, GLint level, GLsizei samples) { |
| 5743 | if (samples > renderbuffer_manager()->max_samples()) { |
| 5744 | LOCAL_SET_GL_ERROR( |
| 5745 | GL_INVALID_VALUE, |
| 5746 | "glFramebufferTexture2DMultisample", "samples too large"); |
| 5747 | return; |
| 5748 | } |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5749 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5750 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5751 | LOCAL_SET_GL_ERROR( |
| 5752 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5753 | name, "no framebuffer bound."); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5754 | return; |
| 5755 | } |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5756 | GLuint service_id = 0; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5757 | TextureRef* texture_ref = NULL; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5758 | if (client_texture_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5759 | texture_ref = GetTexture(client_texture_id); |
| 5760 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5761 | LOCAL_SET_GL_ERROR( |
| 5762 | GL_INVALID_OPERATION, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5763 | name, "unknown texture_ref"); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5764 | return; |
| 5765 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 5766 | service_id = texture_ref->service_id(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 5767 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5768 | |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 5769 | if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5770 | LOCAL_SET_GL_ERROR( |
| 5771 | GL_INVALID_VALUE, |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5772 | name, "level out of range"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5773 | return; |
| 5774 | } |
| 5775 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5776 | if (texture_ref) |
| 5777 | DoWillUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 5778 | |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5779 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(name); |
| 5780 | if (0 == samples) { |
| 5781 | glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); |
| 5782 | } else { |
| 5783 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5784 | glFramebufferTexture2DMultisampleIMG(target, attachment, textarget, |
| 5785 | service_id, level, samples); |
| 5786 | } else { |
| 5787 | glFramebufferTexture2DMultisampleEXT(target, attachment, textarget, |
| 5788 | service_id, level, samples); |
| 5789 | } |
| 5790 | } |
| 5791 | GLenum error = LOCAL_PEEK_GL_ERROR(name); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 5792 | if (error == GL_NO_ERROR) { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5793 | framebuffer->AttachTexture(attachment, texture_ref, textarget, level, |
| 5794 | samples); |
[email protected] | 3a2e7c7b | 2010-08-06 01:12:28 | [diff] [blame] | 5795 | } |
[email protected] | 9d3b2e1 | 2013-10-02 01:04:34 | [diff] [blame] | 5796 | if (framebuffer == framebuffer_state_.bound_draw_framebuffer.get()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 5797 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 5798 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 5799 | |
| 5800 | if (texture_ref) |
| 5801 | DoDidUseTexImageIfNeeded(texture_ref->texture(), textarget); |
| 5802 | |
[email protected] | 81fc9d0 | 2013-03-14 23:53:32 | [diff] [blame] | 5803 | OnFboChanged(); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5804 | } |
| 5805 | |
zmo | 84c0820 | 2014-11-23 15:28:40 | [diff] [blame] | 5806 | void GLES2DecoderImpl::DoFramebufferTextureLayer( |
| 5807 | GLenum target, GLenum attachment, GLuint client_texture_id, |
| 5808 | GLint level, GLint layer) { |
| 5809 | // TODO(zmo): Unsafe ES3 API, missing states update. |
| 5810 | GLuint service_id = 0; |
| 5811 | TextureRef* texture_ref = NULL; |
| 5812 | if (client_texture_id) { |
| 5813 | texture_ref = GetTexture(client_texture_id); |
| 5814 | if (!texture_ref) { |
| 5815 | LOCAL_SET_GL_ERROR( |
| 5816 | GL_INVALID_OPERATION, |
| 5817 | "glFramebufferTextureLayer", "unknown texture_ref"); |
| 5818 | return; |
| 5819 | } |
| 5820 | service_id = texture_ref->service_id(); |
| 5821 | } |
| 5822 | glFramebufferTextureLayer(target, attachment, service_id, level, layer); |
| 5823 | } |
| 5824 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5825 | void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( |
| 5826 | GLenum target, GLenum attachment, GLenum pname, GLint* params) { |
[email protected] | 4d8f0dd | 2013-03-09 14:37:06 | [diff] [blame] | 5827 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); |
| 5828 | if (!framebuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5829 | LOCAL_SET_GL_ERROR( |
| 5830 | GL_INVALID_OPERATION, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5831 | "glGetFramebufferAttachmentParameteriv", "no framebuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5832 | return; |
| 5833 | } |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 5834 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME) { |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5835 | const Framebuffer::Attachment* attachment_object = |
| 5836 | framebuffer->GetAttachment(attachment); |
| 5837 | *params = attachment_object ? attachment_object->object_name() : 0; |
| 5838 | } else { |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5839 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_SAMPLES_EXT && |
| 5840 | features().use_img_for_multisampled_render_to_texture) { |
| 5841 | pname = GL_TEXTURE_SAMPLES_IMG; |
| 5842 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 5843 | glGetFramebufferAttachmentParameterivEXT(target, attachment, pname, params); |
[email protected] | 74c1ec4 | 2010-08-12 01:55:57 | [diff] [blame] | 5844 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5845 | } |
| 5846 | |
| 5847 | void GLES2DecoderImpl::DoGetRenderbufferParameteriv( |
| 5848 | GLenum target, GLenum pname, GLint* params) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 5849 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 5850 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5851 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5852 | LOCAL_SET_GL_ERROR( |
| 5853 | GL_INVALID_OPERATION, |
| 5854 | "glGetRenderbufferParameteriv", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5855 | return; |
| 5856 | } |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5857 | |
| 5858 | EnsureRenderbufferBound(); |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 5859 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5860 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5861 | *params = renderbuffer->internal_format(); |
| 5862 | break; |
| 5863 | case GL_RENDERBUFFER_WIDTH: |
| 5864 | *params = renderbuffer->width(); |
| 5865 | break; |
| 5866 | case GL_RENDERBUFFER_HEIGHT: |
| 5867 | *params = renderbuffer->height(); |
| 5868 | break; |
[email protected] | 7d3c36e | 2013-07-12 14:13:16 | [diff] [blame] | 5869 | case GL_RENDERBUFFER_SAMPLES_EXT: |
| 5870 | if (features().use_img_for_multisampled_render_to_texture) { |
| 5871 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_IMG, |
| 5872 | params); |
| 5873 | } else { |
| 5874 | glGetRenderbufferParameterivEXT(target, GL_RENDERBUFFER_SAMPLES_EXT, |
| 5875 | params); |
| 5876 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 5877 | default: |
| 5878 | glGetRenderbufferParameterivEXT(target, pname, params); |
| 5879 | break; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 5880 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 5881 | } |
| 5882 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5883 | void GLES2DecoderImpl::DoBlitFramebufferCHROMIUM( |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5884 | GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, |
| 5885 | GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, |
| 5886 | GLbitfield mask, GLenum filter) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 5887 | DCHECK(!ShouldDeferReads() && !ShouldDeferDraws()); |
[email protected] | 0c16343f | 2013-03-08 20:40:16 | [diff] [blame] | 5888 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5889 | if (!CheckBoundFramebuffersValid("glBlitFramebufferCHROMIUM")) { |
[email protected] | 0c16343f | 2013-03-08 20:40:16 | [diff] [blame] | 5890 | return; |
| 5891 | } |
| 5892 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5893 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
boliu | 2e7d8a7a | 2014-10-16 20:35:20 | [diff] [blame] | 5894 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5895 | BlitFramebufferHelper( |
| 5896 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 5897 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, |
| 5898 | state_.enable_flags.scissor_test); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5899 | } |
| 5900 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 5901 | void GLES2DecoderImpl::EnsureRenderbufferBound() { |
| 5902 | if (!state_.bound_renderbuffer_valid) { |
| 5903 | state_.bound_renderbuffer_valid = true; |
| 5904 | glBindRenderbufferEXT(GL_RENDERBUFFER, |
| 5905 | state_.bound_renderbuffer.get() |
| 5906 | ? state_.bound_renderbuffer->service_id() |
| 5907 | : 0); |
| 5908 | } |
| 5909 | } |
| 5910 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5911 | void GLES2DecoderImpl::RenderbufferStorageMultisampleHelper( |
| 5912 | const FeatureInfo* feature_info, |
| 5913 | GLenum target, |
| 5914 | GLsizei samples, |
| 5915 | GLenum internal_format, |
| 5916 | GLsizei width, |
| 5917 | GLsizei height) { |
| 5918 | // TODO(sievers): This could be resolved at the GL binding level, but the |
| 5919 | // binding process is currently a bit too 'brute force'. |
zmo | 68fcdc6 | 2014-12-05 21:51:49 | [diff] [blame] | 5920 | if (feature_info->gl_version_info().is_angle) { |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5921 | glRenderbufferStorageMultisampleANGLE( |
| 5922 | target, samples, internal_format, width, height); |
| 5923 | } else if (feature_info->feature_flags().use_core_framebuffer_multisample) { |
| 5924 | glRenderbufferStorageMultisample( |
| 5925 | target, samples, internal_format, width, height); |
| 5926 | } else { |
| 5927 | glRenderbufferStorageMultisampleEXT( |
| 5928 | target, samples, internal_format, width, height); |
| 5929 | } |
| 5930 | } |
| 5931 | |
| 5932 | void GLES2DecoderImpl::BlitFramebufferHelper(GLint srcX0, |
| 5933 | GLint srcY0, |
| 5934 | GLint srcX1, |
| 5935 | GLint srcY1, |
| 5936 | GLint dstX0, |
| 5937 | GLint dstY0, |
| 5938 | GLint dstX1, |
| 5939 | GLint dstY1, |
| 5940 | GLbitfield mask, |
| 5941 | GLenum filter) { |
| 5942 | // TODO(sievers): This could be resolved at the GL binding level, but the |
| 5943 | // binding process is currently a bit too 'brute force'. |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 5944 | if (feature_info_->gl_version_info().is_angle) { |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 5945 | glBlitFramebufferANGLE( |
| 5946 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 5947 | } else if (feature_info_->feature_flags().use_core_framebuffer_multisample) { |
| 5948 | glBlitFramebuffer( |
| 5949 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
[email protected] | 5094b0f | 2010-11-09 19:45:24 | [diff] [blame] | 5950 | } else { |
| 5951 | glBlitFramebufferEXT( |
| 5952 | srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter); |
| 5953 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5954 | } |
| 5955 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5956 | bool GLES2DecoderImpl::ValidateRenderbufferStorageMultisample( |
| 5957 | GLsizei samples, |
| 5958 | GLenum internalformat, |
| 5959 | GLsizei width, |
| 5960 | GLsizei height) { |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5961 | if (samples > renderbuffer_manager()->max_samples()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5962 | LOCAL_SET_GL_ERROR( |
| 5963 | GL_INVALID_VALUE, |
| 5964 | "glRenderbufferStorageMultisample", "samples too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5965 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 5969 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5970 | LOCAL_SET_GL_ERROR( |
| 5971 | GL_INVALID_VALUE, |
| 5972 | "glRenderbufferStorageMultisample", "dimensions too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5973 | return false; |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 5974 | } |
| 5975 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5976 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 5977 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 5978 | width, height, samples, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5979 | LOCAL_SET_GL_ERROR( |
| 5980 | GL_OUT_OF_MEMORY, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5981 | "glRenderbufferStorageMultisample", "dimensions too large"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5982 | return false; |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 5983 | } |
| 5984 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 5985 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 5986 | LOCAL_SET_GL_ERROR( |
| 5987 | GL_OUT_OF_MEMORY, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 5988 | "glRenderbufferStorageMultisample", "out of memory"); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5989 | return false; |
| 5990 | } |
| 5991 | |
| 5992 | return true; |
| 5993 | } |
| 5994 | |
| 5995 | void GLES2DecoderImpl::DoRenderbufferStorageMultisampleCHROMIUM( |
| 5996 | GLenum target, GLsizei samples, GLenum internalformat, |
| 5997 | GLsizei width, GLsizei height) { |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 5998 | Renderbuffer* renderbuffer = GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 5999 | if (!renderbuffer) { |
| 6000 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 6001 | "glRenderbufferStorageMultisampleCHROMIUM", |
| 6002 | "no renderbuffer bound"); |
| 6003 | return; |
| 6004 | } |
| 6005 | |
| 6006 | if (!ValidateRenderbufferStorageMultisample( |
| 6007 | samples, internalformat, width, height)) { |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 6008 | return; |
| 6009 | } |
| 6010 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 6011 | EnsureRenderbufferBound(); |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 6012 | GLenum impl_format = |
| 6013 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 6014 | internalformat); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 6015 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER( |
| 6016 | "glRenderbufferStorageMultisampleCHROMIUM"); |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 6017 | RenderbufferStorageMultisampleHelper( |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 6018 | feature_info_.get(), target, samples, impl_format, width, height); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 6019 | GLenum error = |
| 6020 | LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleCHROMIUM"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 6021 | if (error == GL_NO_ERROR) { |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6022 | if (workarounds().validate_multisample_buffer_allocation) { |
| 6023 | if (!VerifyMultisampleRenderbufferIntegrity( |
| 6024 | renderbuffer->service_id(), impl_format)) { |
| 6025 | LOCAL_SET_GL_ERROR( |
| 6026 | GL_OUT_OF_MEMORY, |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 6027 | "glRenderbufferStorageMultisampleCHROMIUM", "out of memory"); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6028 | return; |
| 6029 | } |
| 6030 | } |
| 6031 | |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 6032 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 6033 | // attached to we could just mark those framebuffers as not complete. |
| 6034 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6035 | renderbuffer_manager()->SetInfo( |
| 6036 | renderbuffer, samples, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 6037 | } |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 6038 | } |
| 6039 | |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 6040 | // This is the handler for multisampled_render_to_texture extensions. |
| 6041 | void GLES2DecoderImpl::DoRenderbufferStorageMultisampleEXT( |
| 6042 | GLenum target, GLsizei samples, GLenum internalformat, |
| 6043 | GLsizei width, GLsizei height) { |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 6044 | Renderbuffer* renderbuffer = GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 6045 | if (!renderbuffer) { |
| 6046 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 6047 | "glRenderbufferStorageMultisampleEXT", |
| 6048 | "no renderbuffer bound"); |
| 6049 | return; |
| 6050 | } |
| 6051 | |
| 6052 | if (!ValidateRenderbufferStorageMultisample( |
| 6053 | samples, internalformat, width, height)) { |
| 6054 | return; |
| 6055 | } |
| 6056 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 6057 | EnsureRenderbufferBound(); |
[email protected] | 49cabed | 2013-11-13 18:15:18 | [diff] [blame] | 6058 | GLenum impl_format = |
| 6059 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 6060 | internalformat); |
| 6061 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorageMultisampleEXT"); |
| 6062 | if (features().use_img_for_multisampled_render_to_texture) { |
| 6063 | glRenderbufferStorageMultisampleIMG( |
| 6064 | target, samples, impl_format, width, height); |
| 6065 | } else { |
| 6066 | glRenderbufferStorageMultisampleEXT( |
| 6067 | target, samples, impl_format, width, height); |
| 6068 | } |
| 6069 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorageMultisampleEXT"); |
| 6070 | if (error == GL_NO_ERROR) { |
| 6071 | // TODO(gman): If renderbuffers tracked which framebuffers they were |
| 6072 | // attached to we could just mark those framebuffers as not complete. |
| 6073 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
| 6074 | renderbuffer_manager()->SetInfo( |
| 6075 | renderbuffer, samples, internalformat, width, height); |
| 6076 | } |
| 6077 | } |
| 6078 | |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6079 | // This function validates the allocation of a multisampled renderbuffer |
| 6080 | // by clearing it to a key color, blitting the contents to a texture, and |
| 6081 | // reading back the color to ensure it matches the key. |
| 6082 | bool GLES2DecoderImpl::VerifyMultisampleRenderbufferIntegrity( |
| 6083 | GLuint renderbuffer, GLenum format) { |
| 6084 | |
| 6085 | // Only validate color buffers. |
| 6086 | // These formats have been selected because they are very common or are known |
| 6087 | // to be used by the WebGL backbuffer. If problems are observed with other |
| 6088 | // color formats they can be added here. |
dcastagna | 504d45c | 2015-04-06 19:30:39 | [diff] [blame] | 6089 | switch (format) { |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6090 | case GL_RGB: |
| 6091 | case GL_RGB8: |
| 6092 | case GL_RGBA: |
| 6093 | case GL_RGBA8: |
| 6094 | break; |
| 6095 | default: |
| 6096 | return true; |
| 6097 | } |
| 6098 | |
| 6099 | GLint draw_framebuffer, read_framebuffer; |
| 6100 | |
| 6101 | // Cache framebuffer and texture bindings. |
| 6102 | glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &draw_framebuffer); |
| 6103 | glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &read_framebuffer); |
| 6104 | |
| 6105 | if (!validation_texture_) { |
| 6106 | GLint bound_texture; |
| 6107 | glGetIntegerv(GL_TEXTURE_BINDING_2D, &bound_texture); |
| 6108 | |
| 6109 | // Create additional resources needed for the verification. |
| 6110 | glGenTextures(1, &validation_texture_); |
| 6111 | glGenFramebuffersEXT(1, &validation_fbo_multisample_); |
| 6112 | glGenFramebuffersEXT(1, &validation_fbo_); |
| 6113 | |
| 6114 | // Texture only needs to be 1x1. |
| 6115 | glBindTexture(GL_TEXTURE_2D, validation_texture_); |
erikchen | e5cc32e | 2015-05-11 21:51:09 | [diff] [blame] | 6116 | // TODO(erikchen): When Chrome on Mac is linked against an OSX 10.9+ SDK, a |
| 6117 | // multisample will fail if the color format of the source and destination |
| 6118 | // do not match. Here, we assume that the source is GL_RGBA, and make the |
| 6119 | // destination GL_RGBA. http://crbug.com/484203 |
| 6120 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6121 | GL_UNSIGNED_BYTE, NULL); |
| 6122 | |
| 6123 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 6124 | glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 6125 | GL_TEXTURE_2D, validation_texture_, 0); |
| 6126 | |
| 6127 | glBindTexture(GL_TEXTURE_2D, bound_texture); |
| 6128 | } |
| 6129 | |
| 6130 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 6131 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 6132 | GL_RENDERBUFFER, renderbuffer); |
| 6133 | |
| 6134 | // Cache current state and reset it to the values we require. |
| 6135 | GLboolean scissor_enabled = false; |
| 6136 | glGetBooleanv(GL_SCISSOR_TEST, &scissor_enabled); |
| 6137 | if (scissor_enabled) |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 6138 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6139 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 6140 | GLboolean color_mask[4] = {GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE}; |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6141 | glGetBooleanv(GL_COLOR_WRITEMASK, color_mask); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 6142 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6143 | |
| 6144 | GLfloat clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f}; |
| 6145 | glGetFloatv(GL_COLOR_CLEAR_VALUE, clear_color); |
| 6146 | glClearColor(1.0f, 0.0f, 1.0f, 1.0f); |
| 6147 | |
| 6148 | // Clear the buffer to the desired key color. |
| 6149 | glClear(GL_COLOR_BUFFER_BIT); |
| 6150 | |
| 6151 | // Blit from the multisample buffer to a standard texture. |
| 6152 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, validation_fbo_multisample_); |
| 6153 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, validation_fbo_); |
| 6154 | |
[email protected] | f42f05b | 2013-11-15 21:46:18 | [diff] [blame] | 6155 | BlitFramebufferHelper( |
| 6156 | 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] | 6157 | |
| 6158 | // Read a pixel from the buffer. |
| 6159 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_); |
| 6160 | |
| 6161 | unsigned char pixel[3] = {0, 0, 0}; |
| 6162 | glReadPixels(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixel); |
| 6163 | |
| 6164 | // Detach the renderbuffer. |
| 6165 | glBindFramebufferEXT(GL_FRAMEBUFFER, validation_fbo_multisample_); |
| 6166 | glFramebufferRenderbufferEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, |
| 6167 | GL_RENDERBUFFER, 0); |
| 6168 | |
| 6169 | // Restore cached state. |
| 6170 | if (scissor_enabled) |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 6171 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6172 | |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 6173 | state_.SetDeviceColorMask( |
| 6174 | color_mask[0], color_mask[1], color_mask[2], color_mask[3]); |
[email protected] | 4a4c18b | 2013-09-13 22:50:10 | [diff] [blame] | 6175 | glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); |
| 6176 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, draw_framebuffer); |
| 6177 | glBindFramebufferEXT(GL_READ_FRAMEBUFFER, read_framebuffer); |
| 6178 | |
| 6179 | // Return true if the pixel matched the desired key color. |
| 6180 | return (pixel[0] == 0xFF && |
| 6181 | pixel[1] == 0x00 && |
| 6182 | pixel[2] == 0xFF); |
| 6183 | } |
| 6184 | |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 6185 | void GLES2DecoderImpl::DoRenderbufferStorage( |
| 6186 | GLenum target, GLenum internalformat, GLsizei width, GLsizei height) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6187 | Renderbuffer* renderbuffer = |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6188 | GetRenderbufferInfoForTarget(GL_RENDERBUFFER); |
| 6189 | if (!renderbuffer) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6190 | LOCAL_SET_GL_ERROR( |
| 6191 | GL_INVALID_OPERATION, |
| 6192 | "glRenderbufferStorage", "no renderbuffer bound"); |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 6193 | return; |
| 6194 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6195 | |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 6196 | if (width > renderbuffer_manager()->max_renderbuffer_size() || |
| 6197 | height > renderbuffer_manager()->max_renderbuffer_size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6198 | LOCAL_SET_GL_ERROR( |
| 6199 | GL_INVALID_VALUE, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 84afefa | 2011-10-19 21:45:53 | [diff] [blame] | 6200 | return; |
| 6201 | } |
| 6202 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 6203 | uint32 estimated_size = 0; |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 6204 | if (!renderbuffer_manager()->ComputeEstimatedRenderbufferSize( |
| 6205 | width, height, 1, internalformat, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6206 | LOCAL_SET_GL_ERROR( |
| 6207 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 6208 | return; |
| 6209 | } |
| 6210 | |
| 6211 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6212 | LOCAL_SET_GL_ERROR( |
| 6213 | GL_OUT_OF_MEMORY, "glRenderbufferStorage", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 6214 | return; |
[email protected] | b71f52c | 2010-06-18 22:20:20 | [diff] [blame] | 6215 | } |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6216 | |
[email protected] | 8875a5f | 2014-06-27 08:33:47 | [diff] [blame] | 6217 | EnsureRenderbufferBound(); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6218 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glRenderbufferStorage"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 6219 | glRenderbufferStorageEXT( |
[email protected] | 8e102e10 | 2013-09-20 22:50:23 | [diff] [blame] | 6220 | target, |
| 6221 | renderbuffer_manager()->InternalRenderbufferFormatToImplFormat( |
| 6222 | internalformat), |
| 6223 | width, |
| 6224 | height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6225 | GLenum error = LOCAL_PEEK_GL_ERROR("glRenderbufferStorage"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 6226 | if (error == GL_NO_ERROR) { |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 6227 | // TODO(gman): If tetxures tracked which framebuffers they were attached to |
| 6228 | // we could just mark those framebuffers as not complete. |
| 6229 | framebuffer_manager()->IncFramebufferStateChangeCount(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6230 | renderbuffer_manager()->SetInfo( |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 6231 | renderbuffer, 1, internalformat, width, height); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 6232 | } |
[email protected] | 36cef8ce | 2010-03-16 07:34:45 | [diff] [blame] | 6233 | } |
| 6234 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6235 | void GLES2DecoderImpl::DoLinkProgram(GLuint program_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 6236 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoLinkProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6237 | Program* program = GetProgramInfoNotShader( |
| 6238 | program_id, "glLinkProgram"); |
| 6239 | if (!program) { |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 6240 | return; |
| 6241 | } |
[email protected] | 05afda1 | 2011-01-20 00:17:34 | [diff] [blame] | 6242 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6243 | LogClientServiceForInfo(program, program_id, "glLinkProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6244 | if (program->Link(shader_manager(), |
[email protected] | 00840153 | 2014-02-07 00:10:50 | [diff] [blame] | 6245 | workarounds().count_all_in_varyings_packing ? |
| 6246 | Program::kCountAll : Program::kCountOnlyStaticallyUsed, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6247 | shader_cache_callback_)) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6248 | if (program == state_.current_program.get()) { |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 6249 | if (workarounds().use_current_program_after_successful_link) |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6250 | glUseProgram(program->service_id()); |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 6251 | if (workarounds().clear_uniforms_before_first_program_use) |
| 6252 | program_manager()->ClearUniforms(program); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 6253 | } |
| 6254 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 6255 | |
| 6256 | // LinkProgram can be very slow. Exit command processing to allow for |
| 6257 | // context preemption and GPU watchdog checks. |
| 6258 | ExitCommandProcessingEarly(); |
dcastagna | 504d45c | 2015-04-06 19:30:39 | [diff] [blame] | 6259 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6260 | |
zmo | bcb3fdd6 | 2014-12-11 00:49:03 | [diff] [blame] | 6261 | void GLES2DecoderImpl::DoSamplerParameterfv( |
| 6262 | GLuint sampler, GLenum pname, const GLfloat* params) { |
| 6263 | DCHECK(params); |
| 6264 | glSamplerParameterf(sampler, pname, params[0]); |
| 6265 | } |
| 6266 | |
| 6267 | void GLES2DecoderImpl::DoSamplerParameteriv( |
| 6268 | GLuint sampler, GLenum pname, const GLint* params) { |
| 6269 | DCHECK(params); |
| 6270 | glSamplerParameteri(sampler, pname, params[0]); |
| 6271 | } |
| 6272 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6273 | void GLES2DecoderImpl::DoTexParameterf( |
| 6274 | GLenum target, GLenum pname, GLfloat param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 6275 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 6276 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 6277 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6278 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterf", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 6279 | return; |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6280 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 6281 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 6282 | texture_manager()->SetParameterf( |
| 6283 | "glTexParameterf", GetErrorState(), texture, pname, param); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6284 | } |
| 6285 | |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6286 | void GLES2DecoderImpl::DoTexParameteri( |
| 6287 | GLenum target, GLenum pname, GLint param) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 6288 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 6289 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 6290 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6291 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 6292 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6293 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 6294 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 6295 | texture_manager()->SetParameteri( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 6296 | "glTexParameteri", GetErrorState(), texture, pname, param); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6297 | } |
| 6298 | |
| 6299 | void GLES2DecoderImpl::DoTexParameterfv( |
| 6300 | GLenum target, GLenum pname, const GLfloat* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 6301 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 6302 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 6303 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6304 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 6305 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6306 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 6307 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 6308 | texture_manager()->SetParameterf( |
| 6309 | "glTexParameterfv", GetErrorState(), texture, pname, *params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6310 | } |
| 6311 | |
| 6312 | void GLES2DecoderImpl::DoTexParameteriv( |
| 6313 | GLenum target, GLenum pname, const GLint* params) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 6314 | TextureRef* texture = texture_manager()->GetTextureInfoForTarget( |
| 6315 | &state_, target); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 6316 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6317 | LOCAL_SET_GL_ERROR( |
| 6318 | GL_INVALID_VALUE, "glTexParameteriv", "unknown texture"); |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 6319 | return; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6320 | } |
[email protected] | cbb22e4 | 2011-05-12 23:36:24 | [diff] [blame] | 6321 | |
[email protected] | 737191ee7 | 2014-03-09 08:02:42 | [diff] [blame] | 6322 | texture_manager()->SetParameteri( |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 6323 | "glTexParameteriv", GetErrorState(), texture, pname, *params); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6324 | } |
| 6325 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 6326 | bool GLES2DecoderImpl::CheckCurrentValuebuffer(const char* function_name) { |
| 6327 | if (!state_.bound_valuebuffer.get()) { |
| 6328 | // There is no valuebuffer bound |
| 6329 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 6330 | "no valuebuffer in use"); |
| 6331 | return false; |
| 6332 | } |
| 6333 | return true; |
| 6334 | } |
| 6335 | |
| 6336 | bool GLES2DecoderImpl::CheckCurrentValuebufferForSubscription( |
| 6337 | GLenum subscription, |
| 6338 | const char* function_name) { |
| 6339 | if (!CheckCurrentValuebuffer(function_name)) { |
| 6340 | return false; |
| 6341 | } |
| 6342 | if (!state_.bound_valuebuffer.get()->IsSubscribed(subscription)) { |
| 6343 | // The valuebuffer is not subscribed to the target |
| 6344 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 6345 | "valuebuffer is not subscribed"); |
| 6346 | return false; |
| 6347 | } |
| 6348 | return true; |
| 6349 | } |
| 6350 | |
| 6351 | bool GLES2DecoderImpl::CheckSubscriptionTarget(GLint location, |
| 6352 | GLenum subscription, |
| 6353 | const char* function_name) { |
| 6354 | if (!CheckCurrentProgramForUniform(location, function_name)) { |
| 6355 | return false; |
| 6356 | } |
| 6357 | GLint real_location = -1; |
| 6358 | GLint array_index = -1; |
| 6359 | const Program::UniformInfo* info = |
| 6360 | state_.current_program->GetUniformInfoByFakeLocation( |
| 6361 | location, &real_location, &array_index); |
| 6362 | if (!info) { |
| 6363 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, "unknown location"); |
| 6364 | return false; |
| 6365 | } |
| 6366 | if ((ValuebufferManager::ApiTypeForSubscriptionTarget(subscription) & |
| 6367 | info->accepts_api_type) == 0) { |
| 6368 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 6369 | "wrong type for subscription"); |
| 6370 | return false; |
| 6371 | } |
| 6372 | return true; |
| 6373 | } |
| 6374 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6375 | bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6376 | if (!state_.current_program.get()) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6377 | // The program does not exist. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6378 | LOCAL_SET_GL_ERROR( |
| 6379 | GL_INVALID_OPERATION, function_name, "no program in use"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6380 | return false; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6381 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6382 | if (!state_.current_program->InUse()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6383 | LOCAL_SET_GL_ERROR( |
| 6384 | GL_INVALID_OPERATION, function_name, "program not linked"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6385 | return false; |
| 6386 | } |
| 6387 | return true; |
| 6388 | } |
| 6389 | |
| 6390 | bool GLES2DecoderImpl::CheckCurrentProgramForUniform( |
| 6391 | GLint location, const char* function_name) { |
| 6392 | if (!CheckCurrentProgram(function_name)) { |
| 6393 | return false; |
| 6394 | } |
| 6395 | return location != -1; |
| 6396 | } |
| 6397 | |
zmo | f9a81360f | 2014-10-17 00:06:14 | [diff] [blame] | 6398 | bool GLES2DecoderImpl::CheckDrawingFeedbackLoops() { |
| 6399 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 6400 | if (!framebuffer) |
| 6401 | return false; |
| 6402 | const Framebuffer::Attachment* attachment = |
| 6403 | framebuffer->GetAttachment(GL_COLOR_ATTACHMENT0); |
| 6404 | if (!attachment) |
| 6405 | return false; |
| 6406 | |
| 6407 | DCHECK(state_.current_program.get()); |
| 6408 | const Program::SamplerIndices& sampler_indices = |
| 6409 | state_.current_program->sampler_indices(); |
| 6410 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
| 6411 | const Program::UniformInfo* uniform_info = |
| 6412 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
| 6413 | DCHECK(uniform_info); |
| 6414 | if (uniform_info->type != GL_SAMPLER_2D) |
| 6415 | continue; |
| 6416 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6417 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
| 6418 | if (texture_unit_index >= state_.texture_units.size()) |
| 6419 | continue; |
| 6420 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
| 6421 | TextureRef* texture_ref = |
| 6422 | texture_unit.GetInfoForSamplerType(GL_SAMPLER_2D).get(); |
| 6423 | if (attachment->IsTexture(texture_ref)) |
| 6424 | return true; |
| 6425 | } |
| 6426 | } |
| 6427 | return false; |
| 6428 | } |
| 6429 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 6430 | bool GLES2DecoderImpl::CheckUniformForApiType( |
| 6431 | const Program::UniformInfo* info, |
| 6432 | const char* function_name, |
| 6433 | Program::UniformApiType api_type) { |
| 6434 | DCHECK(info); |
| 6435 | if ((api_type & info->accepts_api_type) == 0) { |
| 6436 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 6437 | "wrong uniform function for type"); |
| 6438 | return false; |
| 6439 | } |
| 6440 | return true; |
| 6441 | } |
| 6442 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6443 | bool GLES2DecoderImpl::PrepForSetUniformByLocation( |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6444 | GLint fake_location, |
| 6445 | const char* function_name, |
| 6446 | Program::UniformApiType api_type, |
| 6447 | GLint* real_location, |
| 6448 | GLenum* type, |
| 6449 | GLsizei* count) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6450 | DCHECK(type); |
| 6451 | DCHECK(count); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6452 | DCHECK(real_location); |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 6453 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6454 | if (!CheckCurrentProgramForUniform(fake_location, function_name)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6455 | return false; |
| 6456 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6457 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6458 | const Program::UniformInfo* info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6459 | state_.current_program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6460 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6461 | if (!info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6462 | LOCAL_SET_GL_ERROR( |
| 6463 | GL_INVALID_OPERATION, function_name, "unknown location"); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6464 | return false; |
| 6465 | } |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 6466 | if (!CheckUniformForApiType(info, function_name, api_type)) { |
[email protected] | 476ccb7 | 2012-12-06 15:52:52 | [diff] [blame] | 6467 | return false; |
| 6468 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6469 | if (*count > 1 && !info->is_array) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6470 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6471 | GL_INVALID_OPERATION, function_name, "count > 1 for non-array"); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6472 | return false; |
| 6473 | } |
| 6474 | *count = std::min(info->size - array_index, *count); |
| 6475 | if (*count <= 0) { |
| 6476 | return false; |
| 6477 | } |
| 6478 | *type = info->type; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6479 | return true; |
| 6480 | } |
| 6481 | |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6482 | void GLES2DecoderImpl::DoUniform1i(GLint fake_location, GLint v0) { |
| 6483 | GLenum type = 0; |
| 6484 | GLsizei count = 1; |
| 6485 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6486 | if (!PrepForSetUniformByLocation(fake_location, |
| 6487 | "glUniform1i", |
| 6488 | Program::kUniform1i, |
| 6489 | &real_location, |
| 6490 | &type, |
| 6491 | &count)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6492 | return; |
| 6493 | } |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6494 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6495 | state_.texture_units.size(), fake_location, 1, &v0)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6496 | LOCAL_SET_GL_ERROR( |
| 6497 | GL_INVALID_VALUE, "glUniform1i", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 6498 | return; |
| 6499 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6500 | glUniform1i(real_location, v0); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6501 | } |
| 6502 | |
| 6503 | void GLES2DecoderImpl::DoUniform1iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6504 | GLint fake_location, GLsizei count, const GLint *value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6505 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6506 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6507 | if (!PrepForSetUniformByLocation(fake_location, |
| 6508 | "glUniform1iv", |
| 6509 | Program::kUniform1i, |
| 6510 | &real_location, |
| 6511 | &type, |
| 6512 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6513 | return; |
| 6514 | } |
[email protected] | 7472711 | 2012-06-13 21:18:08 | [diff] [blame] | 6515 | if (type == GL_SAMPLER_2D || type == GL_SAMPLER_2D_RECT_ARB || |
| 6516 | type == GL_SAMPLER_CUBE || type == GL_SAMPLER_EXTERNAL_OES) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6517 | if (!state_.current_program->SetSamplers( |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6518 | state_.texture_units.size(), fake_location, count, value)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6519 | LOCAL_SET_GL_ERROR( |
| 6520 | GL_INVALID_VALUE, "glUniform1iv", "texture unit out of range"); |
[email protected] | d20a651 | 2012-05-02 20:17:46 | [diff] [blame] | 6521 | return; |
| 6522 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6523 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6524 | glUniform1iv(real_location, count, value); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6525 | } |
| 6526 | |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6527 | void GLES2DecoderImpl::DoUniform1fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6528 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6529 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6530 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6531 | if (!PrepForSetUniformByLocation(fake_location, |
| 6532 | "glUniform1fv", |
| 6533 | Program::kUniform1f, |
| 6534 | &real_location, |
| 6535 | &type, |
| 6536 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6537 | return; |
| 6538 | } |
| 6539 | if (type == GL_BOOL) { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6540 | scoped_ptr<GLint[]> temp(new GLint[count]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6541 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 6542 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6543 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6544 | DoUniform1iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6545 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6546 | glUniform1fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6547 | } |
| 6548 | } |
| 6549 | |
| 6550 | void GLES2DecoderImpl::DoUniform2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6551 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6552 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6553 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6554 | if (!PrepForSetUniformByLocation(fake_location, |
| 6555 | "glUniform2fv", |
| 6556 | Program::kUniform2f, |
| 6557 | &real_location, |
| 6558 | &type, |
| 6559 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6560 | return; |
| 6561 | } |
| 6562 | if (type == GL_BOOL_VEC2) { |
| 6563 | GLsizei num_values = count * 2; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6564 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6565 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 6566 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6567 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6568 | glUniform2iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6569 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6570 | glUniform2fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6571 | } |
| 6572 | } |
| 6573 | |
| 6574 | void GLES2DecoderImpl::DoUniform3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6575 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6576 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6577 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6578 | if (!PrepForSetUniformByLocation(fake_location, |
| 6579 | "glUniform3fv", |
| 6580 | Program::kUniform3f, |
| 6581 | &real_location, |
| 6582 | &type, |
| 6583 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6584 | return; |
| 6585 | } |
| 6586 | if (type == GL_BOOL_VEC3) { |
| 6587 | GLsizei num_values = count * 3; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6588 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6589 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 6590 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6591 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6592 | glUniform3iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6593 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6594 | glUniform3fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6595 | } |
| 6596 | } |
| 6597 | |
| 6598 | void GLES2DecoderImpl::DoUniform4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6599 | GLint fake_location, GLsizei count, const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6600 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6601 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6602 | if (!PrepForSetUniformByLocation(fake_location, |
| 6603 | "glUniform4fv", |
| 6604 | Program::kUniform4f, |
| 6605 | &real_location, |
| 6606 | &type, |
| 6607 | &count)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6608 | return; |
| 6609 | } |
| 6610 | if (type == GL_BOOL_VEC4) { |
| 6611 | GLsizei num_values = count * 4; |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 6612 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6613 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
[email protected] | 136a63e | 2010-11-12 22:01:53 | [diff] [blame] | 6614 | temp[ii] = static_cast<GLint>(value[ii] != 0.0f); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6615 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6616 | glUniform4iv(real_location, count, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6617 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6618 | glUniform4fv(real_location, count, value); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 6619 | } |
| 6620 | } |
| 6621 | |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6622 | void GLES2DecoderImpl::DoUniform2iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6623 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6624 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6625 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6626 | if (!PrepForSetUniformByLocation(fake_location, |
| 6627 | "glUniform2iv", |
| 6628 | Program::kUniform2i, |
| 6629 | &real_location, |
| 6630 | &type, |
| 6631 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6632 | return; |
| 6633 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6634 | glUniform2iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6635 | } |
| 6636 | |
| 6637 | void GLES2DecoderImpl::DoUniform3iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6638 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6639 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6640 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6641 | if (!PrepForSetUniformByLocation(fake_location, |
| 6642 | "glUniform3iv", |
| 6643 | Program::kUniform3i, |
| 6644 | &real_location, |
| 6645 | &type, |
| 6646 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6647 | return; |
| 6648 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6649 | glUniform3iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6650 | } |
| 6651 | |
| 6652 | void GLES2DecoderImpl::DoUniform4iv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6653 | GLint fake_location, GLsizei count, const GLint* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6654 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6655 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6656 | if (!PrepForSetUniformByLocation(fake_location, |
| 6657 | "glUniform4iv", |
| 6658 | Program::kUniform4i, |
| 6659 | &real_location, |
| 6660 | &type, |
| 6661 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6662 | return; |
| 6663 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6664 | glUniform4iv(real_location, count, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6665 | } |
| 6666 | |
| 6667 | void GLES2DecoderImpl::DoUniformMatrix2fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6668 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 6669 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6670 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6671 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6672 | if (!PrepForSetUniformByLocation(fake_location, |
| 6673 | "glUniformMatrix2fv", |
| 6674 | Program::kUniformMatrix2f, |
| 6675 | &real_location, |
| 6676 | &type, |
| 6677 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6678 | return; |
| 6679 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6680 | glUniformMatrix2fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6681 | } |
| 6682 | |
| 6683 | void GLES2DecoderImpl::DoUniformMatrix3fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6684 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 6685 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6686 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6687 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6688 | if (!PrepForSetUniformByLocation(fake_location, |
| 6689 | "glUniformMatrix3fv", |
| 6690 | Program::kUniformMatrix3f, |
| 6691 | &real_location, |
| 6692 | &type, |
| 6693 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6694 | return; |
| 6695 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6696 | glUniformMatrix3fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6697 | } |
| 6698 | |
| 6699 | void GLES2DecoderImpl::DoUniformMatrix4fv( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6700 | GLint fake_location, GLsizei count, GLboolean transpose, |
| 6701 | const GLfloat* value) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6702 | GLenum type = 0; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6703 | GLint real_location = -1; |
[email protected] | 9b1f1b5 | 2014-03-12 10:40:13 | [diff] [blame] | 6704 | if (!PrepForSetUniformByLocation(fake_location, |
| 6705 | "glUniformMatrix4fv", |
| 6706 | Program::kUniformMatrix4f, |
| 6707 | &real_location, |
| 6708 | &type, |
| 6709 | &count)) { |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6710 | return; |
| 6711 | } |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 6712 | glUniformMatrix4fv(real_location, count, transpose, value); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 6713 | } |
| 6714 | |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6715 | void GLES2DecoderImpl::DoUseProgram(GLuint program_id) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6716 | GLuint service_id = 0; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6717 | Program* program = NULL; |
| 6718 | if (program_id) { |
| 6719 | program = GetProgramInfoNotShader(program_id, "glUseProgram"); |
| 6720 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 6721 | return; |
| 6722 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6723 | if (!program->IsValid()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6724 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6725 | LOCAL_SET_GL_ERROR( |
| 6726 | GL_INVALID_OPERATION, "glUseProgram", "program not linked"); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6727 | return; |
| 6728 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6729 | service_id = program->service_id(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6730 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6731 | if (state_.current_program.get()) { |
| 6732 | program_manager()->UnuseProgram(shader_manager(), |
| 6733 | state_.current_program.get()); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 6734 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 6735 | state_.current_program = program; |
| 6736 | LogClientServiceMapping("glUseProgram", program_id, service_id); |
[email protected] | 2df7389 | 2012-04-28 01:09:54 | [diff] [blame] | 6737 | glUseProgram(service_id); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6738 | if (state_.current_program.get()) { |
| 6739 | program_manager()->UseProgram(state_.current_program.get()); |
[email protected] | b0595555 | 2014-02-06 18:41:18 | [diff] [blame] | 6740 | if (workarounds().clear_uniforms_before_first_program_use) |
| 6741 | program_manager()->ClearUniforms(program); |
[email protected] | ca488e1 | 2010-12-13 20:06:14 | [diff] [blame] | 6742 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6743 | } |
| 6744 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6745 | void GLES2DecoderImpl::RenderWarning( |
| 6746 | const char* filename, int line, const std::string& msg) { |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 6747 | logger_.LogMessage(filename, line, std::string("RENDER WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6748 | } |
| 6749 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6750 | void GLES2DecoderImpl::PerformanceWarning( |
| 6751 | const char* filename, int line, const std::string& msg) { |
[email protected] | d3eba34 | 2013-04-18 21:11:50 | [diff] [blame] | 6752 | logger_.LogMessage(filename, line, |
| 6753 | std::string("PERFORMANCE WARNING: ") + msg); |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6754 | } |
| 6755 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6756 | void GLES2DecoderImpl::DoWillUseTexImageIfNeeded( |
| 6757 | Texture* texture, GLenum textarget) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6758 | // Image is already in use if texture is attached to a framebuffer. |
| 6759 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 6760 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6761 | if (image) { |
| 6762 | ScopedGLErrorSuppressor suppressor( |
| 6763 | "GLES2DecoderImpl::DoWillUseTexImageIfNeeded", |
| 6764 | GetErrorState()); |
| 6765 | glBindTexture(textarget, texture->service_id()); |
| 6766 | image->WillUseTexImage(); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 6767 | RestoreCurrentTextureBindings(&state_, textarget); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6768 | } |
| 6769 | } |
| 6770 | } |
| 6771 | |
| 6772 | void GLES2DecoderImpl::DoDidUseTexImageIfNeeded( |
| 6773 | Texture* texture, GLenum textarget) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6774 | // Image is still in use if texture is attached to a framebuffer. |
| 6775 | if (texture && !texture->IsAttachedToFramebuffer()) { |
| 6776 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6777 | if (image) { |
| 6778 | ScopedGLErrorSuppressor suppressor( |
| 6779 | "GLES2DecoderImpl::DoDidUseTexImageIfNeeded", |
| 6780 | GetErrorState()); |
| 6781 | glBindTexture(textarget, texture->service_id()); |
| 6782 | image->DidUseTexImage(); |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 6783 | RestoreCurrentTextureBindings(&state_, textarget); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6784 | } |
| 6785 | } |
| 6786 | } |
| 6787 | |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6788 | bool GLES2DecoderImpl::PrepareTexturesForRender() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6789 | DCHECK(state_.current_program.get()); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6790 | if (!texture_manager()->HaveUnrenderableTextures() && |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 6791 | !texture_manager()->HaveImages()) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6792 | return true; |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 6793 | } |
[email protected] | e2367b4 | 2013-05-31 03:37:21 | [diff] [blame] | 6794 | |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 6795 | bool textures_set = false; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6796 | const Program::SamplerIndices& sampler_indices = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6797 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6798 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6799 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6800 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6801 | DCHECK(uniform_info); |
| 6802 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6803 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6804 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6805 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6806 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 6807 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6808 | GLenum textarget = GetBindTargetForSamplerType(uniform_info->type); |
| 6809 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | ef52649 | 2010-06-02 23:12:25 | [diff] [blame] | 6810 | textures_set = true; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6811 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6812 | glBindTexture( |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6813 | textarget, |
[email protected] | 00f893d | 2010-08-24 18:55:49 | [diff] [blame] | 6814 | texture_manager()->black_texture_id(uniform_info->type)); |
dongseong.hwang | 7d87d72 | 2015-01-14 20:02:40 | [diff] [blame] | 6815 | if (!texture_ref) { |
| 6816 | LOCAL_RENDER_WARNING( |
| 6817 | std::string("there is no texture bound to the unit ") + |
| 6818 | base::IntToString(texture_unit_index)); |
| 6819 | } else { |
| 6820 | LOCAL_RENDER_WARNING( |
| 6821 | std::string("texture bound to texture unit ") + |
| 6822 | base::IntToString(texture_unit_index) + |
| 6823 | " is not renderable. It maybe non-power-of-2 and have" |
| 6824 | " incompatible texture filtering."); |
| 6825 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6826 | continue; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6827 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6828 | |
[email protected] | 4e7b8920 | 2014-01-28 01:44:06 | [diff] [blame] | 6829 | if (textarget != GL_TEXTURE_CUBE_MAP) { |
| 6830 | Texture* texture = texture_ref->texture(); |
| 6831 | gfx::GLImage* image = texture->GetLevelImage(textarget, 0); |
| 6832 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 6833 | ScopedGLErrorSuppressor suppressor( |
| 6834 | "GLES2DecoderImpl::PrepareTexturesForRender", GetErrorState()); |
| 6835 | textures_set = true; |
| 6836 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6837 | image->WillUseTexImage(); |
| 6838 | continue; |
| 6839 | } |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6840 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6841 | } |
| 6842 | // else: should this be an error? |
| 6843 | } |
| 6844 | } |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 6845 | return !textures_set; |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6846 | } |
| 6847 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6848 | void GLES2DecoderImpl::RestoreStateForTextures() { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6849 | DCHECK(state_.current_program.get()); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6850 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6851 | state_.current_program->sampler_indices(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6852 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6853 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6854 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6855 | DCHECK(uniform_info); |
| 6856 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6857 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6858 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6859 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6860 | TextureRef* texture_ref = |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6861 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6862 | if (!texture_ref || !texture_manager()->CanRender(texture_ref)) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6863 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6864 | // Get the texture_ref info that was previously bound here. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6865 | texture_ref = texture_unit.bind_target == GL_TEXTURE_2D |
| 6866 | ? texture_unit.bound_texture_2d.get() |
| 6867 | : texture_unit.bound_texture_cube_map.get(); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6868 | glBindTexture(texture_unit.bind_target, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6869 | texture_ref ? texture_ref->service_id() : 0); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 6870 | continue; |
| 6871 | } |
| 6872 | |
[email protected] | 4e7b8920 | 2014-01-28 01:44:06 | [diff] [blame] | 6873 | if (texture_unit.bind_target != GL_TEXTURE_CUBE_MAP) { |
| 6874 | Texture* texture = texture_ref->texture(); |
| 6875 | gfx::GLImage* image = |
| 6876 | texture->GetLevelImage(texture_unit.bind_target, 0); |
| 6877 | if (image && !texture->IsAttachedToFramebuffer()) { |
| 6878 | ScopedGLErrorSuppressor suppressor( |
| 6879 | "GLES2DecoderImpl::RestoreStateForTextures", GetErrorState()); |
| 6880 | glActiveTexture(GL_TEXTURE0 + texture_unit_index); |
| 6881 | image->DidUseTexImage(); |
| 6882 | continue; |
| 6883 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6884 | } |
| 6885 | } |
| 6886 | } |
| 6887 | } |
| 6888 | // Set the active texture back to whatever the user had it as. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6889 | glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 6890 | } |
| 6891 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6892 | bool GLES2DecoderImpl::ClearUnclearedTextures() { |
| 6893 | // Only check if there are some uncleared textures. |
| 6894 | if (!texture_manager()->HaveUnsafeTextures()) { |
| 6895 | return true; |
| 6896 | } |
| 6897 | |
| 6898 | // 1: Check all textures we are about to render with. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6899 | if (state_.current_program.get()) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6900 | const Program::SamplerIndices& sampler_indices = |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6901 | state_.current_program->sampler_indices(); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6902 | for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6903 | const Program::UniformInfo* uniform_info = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6904 | state_.current_program->GetUniformInfo(sampler_indices[ii]); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6905 | DCHECK(uniform_info); |
| 6906 | for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { |
| 6907 | GLuint texture_unit_index = uniform_info->texture_units[jj]; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 6908 | if (texture_unit_index < state_.texture_units.size()) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 6909 | TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6910 | TextureRef* texture_ref = |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 6911 | texture_unit.GetInfoForSamplerType(uniform_info->type).get(); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 6912 | if (texture_ref && !texture_ref->texture()->SafeToRenderFrom()) { |
| 6913 | if (!texture_manager()->ClearRenderableLevels(this, texture_ref)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 6914 | return false; |
| 6915 | } |
| 6916 | } |
| 6917 | } |
| 6918 | } |
| 6919 | } |
| 6920 | } |
| 6921 | return true; |
| 6922 | } |
| 6923 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6924 | bool GLES2DecoderImpl::IsDrawValid( |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6925 | const char* function_name, GLuint max_vertex_accessed, bool instanced, |
| 6926 | GLsizei primcount) { |
| 6927 | DCHECK(instanced || primcount == 1); |
| 6928 | |
[email protected] | 689fa1c5 | 2010-06-09 18:35:03 | [diff] [blame] | 6929 | // NOTE: We specifically do not check current_program->IsValid() because |
| 6930 | // it could never be invalid since glUseProgram would have failed. While |
| 6931 | // glLinkProgram could later mark the program as invalid the previous |
| 6932 | // valid program will still function if it is still the current program. |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6933 | if (!state_.current_program.get()) { |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6934 | // The program does not exist. |
| 6935 | // But GL says no ERROR. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6936 | LOCAL_RENDER_WARNING("Drawing with no current shader program."); |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 6937 | return false; |
| 6938 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 6939 | |
zmo | f9a81360f | 2014-10-17 00:06:14 | [diff] [blame] | 6940 | if (CheckDrawingFeedbackLoops()) { |
| 6941 | LOCAL_SET_GL_ERROR( |
| 6942 | GL_INVALID_OPERATION, function_name, |
| 6943 | "Source and destination textures of the draw are the same."); |
| 6944 | return false; |
| 6945 | } |
| 6946 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6947 | return state_.vertex_attrib_manager |
| 6948 | ->ValidateBindings(function_name, |
| 6949 | this, |
| 6950 | feature_info_.get(), |
| 6951 | state_.current_program.get(), |
| 6952 | max_vertex_accessed, |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 6953 | instanced, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 6954 | primcount); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6955 | } |
| 6956 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6957 | bool GLES2DecoderImpl::SimulateAttrib0( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 6958 | const char* function_name, GLuint max_vertex_accessed, bool* simulated) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6959 | DCHECK(simulated); |
| 6960 | *simulated = false; |
| 6961 | |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 6962 | if (feature_info_->gl_version_info().BehavesLikeGLES()) |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6963 | return true; |
[email protected] | 876f6fee | 2010-08-02 23:10:32 | [diff] [blame] | 6964 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6965 | const VertexAttrib* attrib = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 6966 | state_.vertex_attrib_manager->GetVertexAttrib(0); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6967 | // 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] | 6968 | bool attrib_0_used = |
| 6969 | state_.current_program->GetAttribInfoByLocation(0) != NULL; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 6970 | if (attrib->enabled() && attrib_0_used) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6971 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6972 | } |
| 6973 | |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 6974 | // Make a buffer with a single repeated vec4 value enough to |
| 6975 | // simulate the constant value that is supposed to be here. |
| 6976 | // This is required to emulate GLES2 on GL. |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6977 | GLuint num_vertices = max_vertex_accessed + 1; |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 6978 | uint32 size_needed = 0; |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6979 | |
| 6980 | if (num_vertices == 0 || |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 6981 | !SafeMultiplyUint32(num_vertices, sizeof(Vec4f), &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6982 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6983 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6984 | return false; |
| 6985 | } |
| 6986 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6987 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 6988 | "Attribute 0 is disabled. This has signficant performance penalty"); |
| 6989 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6990 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6991 | glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); |
| 6992 | |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 6993 | bool new_buffer = static_cast<GLsizei>(size_needed) > attrib_0_size_; |
| 6994 | if (new_buffer) { |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 6995 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 6996 | GLenum error = glGetError(); |
| 6997 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 6998 | LOCAL_SET_GL_ERROR( |
| 6999 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7000 | return false; |
| 7001 | } |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 7002 | } |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7003 | |
| 7004 | const Vec4& value = state_.attrib_values[0]; |
[email protected] | 8f0b86c2f | 2012-04-10 05:48:28 | [diff] [blame] | 7005 | if (new_buffer || |
| 7006 | (attrib_0_used && |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7007 | (!attrib_0_buffer_matches_value_ || !value.Equal(attrib_0_value_)))){ |
| 7008 | // TODO(zmo): This is not 100% correct because we might lose data when |
| 7009 | // casting to float type, but it is a corner case and once we migrate to |
| 7010 | // core profiles on desktop GL, it is no longer relevant. |
| 7011 | Vec4f fvalue(value); |
| 7012 | std::vector<Vec4f> temp(num_vertices, fvalue); |
[email protected] | fc75344 | 2011-02-04 19:49:49 | [diff] [blame] | 7013 | glBufferSubData(GL_ARRAY_BUFFER, 0, size_needed, &temp[0].v[0]); |
| 7014 | attrib_0_buffer_matches_value_ = true; |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7015 | attrib_0_value_ = value; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7016 | attrib_0_size_ = size_needed; |
| 7017 | } |
| 7018 | |
| 7019 | glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL); |
| 7020 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7021 | if (attrib->divisor()) |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7022 | glVertexAttribDivisorANGLE(0, 0); |
| 7023 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7024 | *simulated = true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7025 | return true; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7026 | } |
| 7027 | |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 7028 | void GLES2DecoderImpl::RestoreStateForAttrib( |
| 7029 | GLuint attrib_index, bool restore_array_binding) { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7030 | const VertexAttrib* attrib = |
| 7031 | state_.vertex_attrib_manager->GetVertexAttrib(attrib_index); |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 7032 | if (restore_array_binding) { |
| 7033 | const void* ptr = reinterpret_cast<const void*>(attrib->offset()); |
| 7034 | Buffer* buffer = attrib->buffer(); |
| 7035 | glBindBuffer(GL_ARRAY_BUFFER, buffer ? buffer->service_id() : 0); |
| 7036 | glVertexAttribPointer( |
| 7037 | attrib_index, attrib->size(), attrib->type(), attrib->normalized(), |
| 7038 | attrib->gl_stride(), ptr); |
| 7039 | } |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7040 | if (attrib->divisor()) |
| 7041 | glVertexAttribDivisorANGLE(attrib_index, attrib->divisor()); |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7042 | glBindBuffer( |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 7043 | GL_ARRAY_BUFFER, state_.bound_array_buffer.get() ? |
| 7044 | state_.bound_array_buffer->service_id() : 0); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 7045 | |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 7046 | // Never touch vertex attribute 0's state (in particular, never |
| 7047 | // disable it) when running on desktop GL because it will never be |
| 7048 | // re-enabled. |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7049 | if (attrib_index != 0 || |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 7050 | gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7051 | if (attrib->enabled()) { |
| 7052 | glEnableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 7053 | } else { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7054 | glDisableVertexAttribArray(attrib_index); |
[email protected] | 265f899 | 2012-07-20 01:03:14 | [diff] [blame] | 7055 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 7056 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7057 | } |
[email protected] | 07f54fcc | 2009-12-22 02:46:30 | [diff] [blame] | 7058 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7059 | bool GLES2DecoderImpl::SimulateFixedAttribs( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7060 | const char* function_name, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7061 | GLuint max_vertex_accessed, bool* simulated, GLsizei primcount) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7062 | DCHECK(simulated); |
| 7063 | *simulated = false; |
| 7064 | if (gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2) |
| 7065 | return true; |
| 7066 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7067 | if (!state_.vertex_attrib_manager->HaveFixedAttribs()) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7068 | return true; |
| 7069 | } |
| 7070 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7071 | LOCAL_PERFORMANCE_WARNING( |
[email protected] | 0f8afe8 | 2012-05-14 23:43:01 | [diff] [blame] | 7072 | "GL_FIXED attributes have a signficant performance penalty"); |
| 7073 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7074 | // NOTE: we could be smart and try to check if a buffer is used |
| 7075 | // twice in 2 different attribs, find the overlapping parts and therefore |
| 7076 | // duplicate the minimum amount of data but this whole code path is not meant |
| 7077 | // to be used normally. It's just here to pass that OpenGL ES 2.0 conformance |
| 7078 | // tests so we just add to the buffer attrib used. |
| 7079 | |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7080 | GLuint elements_needed = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7081 | const VertexAttribManager::VertexAttribList& enabled_attribs = |
| 7082 | state_.vertex_attrib_manager->GetEnabledVertexAttribs(); |
| 7083 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 7084 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 7085 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7086 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7087 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 7088 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
| 7089 | max_vertex_accessed); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7090 | GLuint num_vertices = max_accessed + 1; |
| 7091 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7092 | LOCAL_SET_GL_ERROR( |
| 7093 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7094 | return false; |
| 7095 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7096 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7097 | attrib->CanAccess(max_accessed) && |
| 7098 | attrib->type() == GL_FIXED) { |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 7099 | uint32 elements_used = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7100 | if (!SafeMultiplyUint32(num_vertices, attrib->size(), &elements_used) || |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 7101 | !SafeAddUint32(elements_needed, elements_used, &elements_needed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7102 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7103 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7104 | return false; |
| 7105 | } |
| 7106 | } |
| 7107 | } |
| 7108 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 7109 | const uint32 kSizeOfFloat = sizeof(float); // NOLINT |
| 7110 | uint32 size_needed = 0; |
| 7111 | if (!SafeMultiplyUint32(elements_needed, kSizeOfFloat, &size_needed) || |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7112 | size_needed > 0x7FFFFFFFU) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7113 | LOCAL_SET_GL_ERROR( |
| 7114 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7115 | return false; |
| 7116 | } |
| 7117 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7118 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER(function_name); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7119 | |
| 7120 | glBindBuffer(GL_ARRAY_BUFFER, fixed_attrib_buffer_id_); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7121 | if (static_cast<GLsizei>(size_needed) > fixed_attrib_buffer_size_) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7122 | glBufferData(GL_ARRAY_BUFFER, size_needed, NULL, GL_DYNAMIC_DRAW); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7123 | GLenum error = glGetError(); |
| 7124 | if (error != GL_NO_ERROR) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7125 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7126 | GL_OUT_OF_MEMORY, function_name, "simulating GL_FIXED attribs"); |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7127 | return false; |
| 7128 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7129 | } |
| 7130 | |
| 7131 | // Copy the elements and convert to float |
| 7132 | GLintptr offset = 0; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7133 | for (VertexAttribManager::VertexAttribList::const_iterator it = |
| 7134 | enabled_attribs.begin(); it != enabled_attribs.end(); ++it) { |
| 7135 | const VertexAttrib* attrib = *it; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7136 | const Program::VertexAttrib* attrib_info = |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7137 | state_.current_program->GetAttribInfoByLocation(attrib->index()); |
| 7138 | GLuint max_accessed = attrib->MaxVertexAccessed(primcount, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7139 | max_vertex_accessed); |
| 7140 | GLuint num_vertices = max_accessed + 1; |
| 7141 | if (num_vertices == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7142 | LOCAL_SET_GL_ERROR( |
| 7143 | GL_OUT_OF_MEMORY, function_name, "Simulating attrib 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7144 | return false; |
| 7145 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7146 | if (attrib_info && |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7147 | attrib->CanAccess(max_accessed) && |
| 7148 | attrib->type() == GL_FIXED) { |
penghuang | 5a3210b | 2014-10-29 18:24:36 | [diff] [blame] | 7149 | int num_elements = attrib->size() * num_vertices; |
| 7150 | const int src_size = num_elements * sizeof(int32); |
| 7151 | const int dst_size = num_elements * sizeof(float); |
| 7152 | scoped_ptr<float[]> data(new float[num_elements]); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7153 | const int32* src = reinterpret_cast<const int32 *>( |
penghuang | 5a3210b | 2014-10-29 18:24:36 | [diff] [blame] | 7154 | attrib->buffer()->GetRange(attrib->offset(), src_size)); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7155 | const int32* end = src + num_elements; |
| 7156 | float* dst = data.get(); |
| 7157 | while (src != end) { |
| 7158 | *dst++ = static_cast<float>(*src++) / 65536.0f; |
| 7159 | } |
penghuang | 5a3210b | 2014-10-29 18:24:36 | [diff] [blame] | 7160 | glBufferSubData(GL_ARRAY_BUFFER, offset, dst_size, data.get()); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7161 | glVertexAttribPointer( |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7162 | attrib->index(), attrib->size(), GL_FLOAT, false, 0, |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7163 | reinterpret_cast<GLvoid*>(offset)); |
penghuang | 5a3210b | 2014-10-29 18:24:36 | [diff] [blame] | 7164 | offset += dst_size; |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7165 | } |
| 7166 | } |
| 7167 | *simulated = true; |
| 7168 | return true; |
| 7169 | } |
| 7170 | |
| 7171 | void GLES2DecoderImpl::RestoreStateForSimulatedFixedAttribs() { |
| 7172 | // There's no need to call glVertexAttribPointer because we shadow all the |
| 7173 | // settings and passing GL_FIXED to it will not work. |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7174 | glBindBuffer( |
| 7175 | GL_ARRAY_BUFFER, |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 7176 | state_.bound_array_buffer.get() ? state_.bound_array_buffer->service_id() |
| 7177 | : 0); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7178 | } |
| 7179 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7180 | error::Error GLES2DecoderImpl::DoDrawArrays( |
| 7181 | const char* function_name, |
| 7182 | bool instanced, |
| 7183 | GLenum mode, |
| 7184 | GLint first, |
| 7185 | GLsizei count, |
| 7186 | GLsizei primcount) { |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 7187 | error::Error error = WillAccessBoundFramebufferForDraw(); |
| 7188 | if (error != error::kNoError) |
| 7189 | return error; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7190 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7191 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7192 | return error::kNoError; |
| 7193 | } |
| 7194 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7195 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7196 | return error::kNoError; |
| 7197 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7198 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7199 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7200 | return error::kNoError; |
| 7201 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7202 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7203 | return error::kNoError; |
| 7204 | } |
| 7205 | // We have to check this here because the prototype for glDrawArrays |
| 7206 | // is GLint not GLsizei. |
| 7207 | if (first < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7208 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "first < 0"); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7209 | return error::kNoError; |
| 7210 | } |
| 7211 | |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 7212 | if (count == 0 || primcount == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7213 | LOCAL_RENDER_WARNING("Render count or primcount is 0."); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7214 | return error::kNoError; |
| 7215 | } |
| 7216 | |
| 7217 | GLuint max_vertex_accessed = first + count - 1; |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 7218 | if (IsDrawValid(function_name, max_vertex_accessed, instanced, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7219 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7220 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7221 | return error::kNoError; |
| 7222 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7223 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7224 | if (!SimulateAttrib0( |
| 7225 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7226 | return error::kNoError; |
| 7227 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7228 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7229 | if (SimulateFixedAttribs( |
| 7230 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 7231 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 7232 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7233 | ApplyDirtyState(); |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 7234 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7235 | if (!instanced) { |
| 7236 | glDrawArrays(mode, first, count); |
| 7237 | } else { |
| 7238 | glDrawArraysInstancedANGLE(mode, first, count, primcount); |
| 7239 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7240 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 7241 | RestoreStateForTextures(); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7242 | } |
| 7243 | if (simulated_fixed_attribs) { |
| 7244 | RestoreStateForSimulatedFixedAttribs(); |
| 7245 | } |
| 7246 | } |
| 7247 | if (simulated_attrib_0) { |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 7248 | // We don't have to restore attrib 0 generic data at the end of this |
| 7249 | // function even if it is simulated. This is because we will simulate |
| 7250 | // it in each draw call, and attrib 0 generic data queries use cached |
| 7251 | // values instead of passing down to the underlying driver. |
| 7252 | RestoreStateForAttrib(0, false); |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7253 | } |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 7254 | } |
| 7255 | return error::kNoError; |
| 7256 | } |
| 7257 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7258 | error::Error GLES2DecoderImpl::HandleDrawArrays(uint32 immediate_data_size, |
| 7259 | const void* cmd_data) { |
zmo | 640dc65 | 2015-04-28 00:53:38 | [diff] [blame] | 7260 | // TODO(zmo): crbug.com/481184 |
| 7261 | // On Desktop GL with versions lower than 4.3, we need to emulate |
| 7262 | // GL_PRIMITIVE_RESTART_FIXED_INDEX using glPrimitiveRestartIndex(). |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7263 | const cmds::DrawArrays& c = *static_cast<const cmds::DrawArrays*>(cmd_data); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7264 | return DoDrawArrays("glDrawArrays", |
| 7265 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7266 | static_cast<GLenum>(c.mode), |
| 7267 | static_cast<GLint>(c.first), |
| 7268 | static_cast<GLsizei>(c.count), |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 7269 | 1); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7270 | } |
| 7271 | |
| 7272 | error::Error GLES2DecoderImpl::HandleDrawArraysInstancedANGLE( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7273 | uint32 immediate_data_size, |
| 7274 | const void* cmd_data) { |
| 7275 | const gles2::cmds::DrawArraysInstancedANGLE& c = |
| 7276 | *static_cast<const gles2::cmds::DrawArraysInstancedANGLE*>(cmd_data); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 7277 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7278 | LOCAL_SET_GL_ERROR( |
| 7279 | GL_INVALID_OPERATION, |
| 7280 | "glDrawArraysInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7281 | return error::kNoError; |
| 7282 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7283 | return DoDrawArrays("glDrawArraysIntancedANGLE", |
| 7284 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7285 | static_cast<GLenum>(c.mode), |
| 7286 | static_cast<GLint>(c.first), |
| 7287 | static_cast<GLsizei>(c.count), |
| 7288 | static_cast<GLsizei>(c.primcount)); |
| 7289 | } |
| 7290 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7291 | error::Error GLES2DecoderImpl::DoDrawElements( |
| 7292 | const char* function_name, |
| 7293 | bool instanced, |
| 7294 | GLenum mode, |
| 7295 | GLsizei count, |
| 7296 | GLenum type, |
| 7297 | int32 offset, |
| 7298 | GLsizei primcount) { |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 7299 | error::Error error = WillAccessBoundFramebufferForDraw(); |
| 7300 | if (error != error::kNoError) |
| 7301 | return error; |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 7302 | if (!state_.vertex_attrib_manager->element_array_buffer()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7303 | LOCAL_SET_GL_ERROR( |
| 7304 | GL_INVALID_OPERATION, function_name, "No element array buffer bound"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7305 | return error::kNoError; |
| 7306 | } |
| 7307 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7308 | if (count < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7309 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "count < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7310 | return error::kNoError; |
| 7311 | } |
| 7312 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7313 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7314 | return error::kNoError; |
| 7315 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7316 | if (!validators_->draw_mode.IsValid(mode)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7317 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, mode, "mode"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7318 | return error::kNoError; |
| 7319 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 7320 | if (!validators_->index_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7321 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7322 | return error::kNoError; |
| 7323 | } |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7324 | if (primcount < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7325 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "primcount < 0"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7326 | return error::kNoError; |
| 7327 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7328 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7329 | if (!CheckBoundFramebuffersValid(function_name)) { |
[email protected] | 3a03a8f | 2011-03-19 00:51:27 | [diff] [blame] | 7330 | return error::kNoError; |
| 7331 | } |
| 7332 | |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 7333 | if (count == 0 || primcount == 0) { |
[email protected] | 6c788fb7 | 2010-08-26 02:16:31 | [diff] [blame] | 7334 | return error::kNoError; |
| 7335 | } |
| 7336 | |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7337 | GLuint max_vertex_accessed; |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 7338 | Buffer* element_array_buffer = |
| 7339 | state_.vertex_attrib_manager->element_array_buffer(); |
| 7340 | |
| 7341 | if (!element_array_buffer->GetMaxValueForRange( |
| 7342 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7343 | LOCAL_SET_GL_ERROR( |
| 7344 | GL_INVALID_OPERATION, function_name, "range out of bounds for buffer"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7345 | return error::kNoError; |
| 7346 | } |
| 7347 | |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 7348 | if (IsDrawValid(function_name, max_vertex_accessed, instanced, primcount)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7349 | if (!ClearUnclearedTextures()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7350 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "out of memory"); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 7351 | return error::kNoError; |
| 7352 | } |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7353 | bool simulated_attrib_0 = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7354 | if (!SimulateAttrib0( |
| 7355 | function_name, max_vertex_accessed, &simulated_attrib_0)) { |
[email protected] | c13e1da6 | 2011-09-09 21:48:30 | [diff] [blame] | 7356 | return error::kNoError; |
| 7357 | } |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7358 | bool simulated_fixed_attribs = false; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7359 | if (SimulateFixedAttribs( |
| 7360 | function_name, max_vertex_accessed, &simulated_fixed_attribs, |
| 7361 | primcount)) { |
[email protected] | e56131d2 | 2013-07-28 16:14:11 | [diff] [blame] | 7362 | bool textures_set = !PrepareTexturesForRender(); |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 7363 | ApplyDirtyState(); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 7364 | // TODO(gman): Refactor to hide these details in BufferManager or |
| 7365 | // VertexAttribManager. |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7366 | const GLvoid* indices = reinterpret_cast<const GLvoid*>(offset); |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 7367 | bool used_client_side_array = false; |
| 7368 | if (element_array_buffer->IsClientSideArray()) { |
| 7369 | used_client_side_array = true; |
| 7370 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 7371 | indices = element_array_buffer->GetRange(offset, 0); |
| 7372 | } |
| 7373 | |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 7374 | ScopedRenderTo do_render(framebuffer_state_.bound_draw_framebuffer.get()); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7375 | if (!instanced) { |
| 7376 | glDrawElements(mode, count, type, indices); |
| 7377 | } else { |
| 7378 | glDrawElementsInstancedANGLE(mode, count, type, indices, primcount); |
| 7379 | } |
[email protected] | 17cfbe0e | 2013-03-07 01:26:08 | [diff] [blame] | 7380 | |
| 7381 | if (used_client_side_array) { |
| 7382 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 7383 | element_array_buffer->service_id()); |
| 7384 | } |
| 7385 | |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7386 | if (textures_set) { |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 7387 | RestoreStateForTextures(); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 7388 | } |
| 7389 | if (simulated_fixed_attribs) { |
| 7390 | RestoreStateForSimulatedFixedAttribs(); |
| 7391 | } |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 7392 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7393 | if (simulated_attrib_0) { |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 7394 | // We don't have to restore attrib 0 generic data at the end of this |
| 7395 | // function even if it is simulated. This is because we will simulate |
| 7396 | // it in each draw call, and attrib 0 generic data queries use cached |
| 7397 | // values instead of passing down to the underlying driver. |
| 7398 | RestoreStateForAttrib(0, false); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7399 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7400 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 7401 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7402 | } |
| 7403 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7404 | error::Error GLES2DecoderImpl::HandleDrawElements(uint32 immediate_data_size, |
| 7405 | const void* cmd_data) { |
zmo | 640dc65 | 2015-04-28 00:53:38 | [diff] [blame] | 7406 | // TODO(zmo): crbug.com/481184 |
| 7407 | // On Desktop GL with versions lower than 4.3, we need to emulate |
| 7408 | // GL_PRIMITIVE_RESTART_FIXED_INDEX using glPrimitiveRestartIndex(). |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7409 | const gles2::cmds::DrawElements& c = |
| 7410 | *static_cast<const gles2::cmds::DrawElements*>(cmd_data); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7411 | return DoDrawElements("glDrawElements", |
| 7412 | false, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7413 | static_cast<GLenum>(c.mode), |
| 7414 | static_cast<GLsizei>(c.count), |
| 7415 | static_cast<GLenum>(c.type), |
| 7416 | static_cast<int32>(c.index_offset), |
[email protected] | ac6904d6 | 2014-07-30 12:00:10 | [diff] [blame] | 7417 | 1); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7418 | } |
| 7419 | |
| 7420 | error::Error GLES2DecoderImpl::HandleDrawElementsInstancedANGLE( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7421 | uint32 immediate_data_size, |
| 7422 | const void* cmd_data) { |
| 7423 | const gles2::cmds::DrawElementsInstancedANGLE& c = |
| 7424 | *static_cast<const gles2::cmds::DrawElementsInstancedANGLE*>(cmd_data); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 7425 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7426 | LOCAL_SET_GL_ERROR( |
| 7427 | GL_INVALID_OPERATION, |
| 7428 | "glDrawElementsInstancedANGLE", "function not available"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7429 | return error::kNoError; |
| 7430 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7431 | return DoDrawElements("glDrawElementsInstancedANGLE", |
| 7432 | true, |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7433 | static_cast<GLenum>(c.mode), |
| 7434 | static_cast<GLsizei>(c.count), |
| 7435 | static_cast<GLenum>(c.type), |
| 7436 | static_cast<int32>(c.index_offset), |
| 7437 | static_cast<GLsizei>(c.primcount)); |
| 7438 | } |
| 7439 | |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 7440 | GLuint GLES2DecoderImpl::DoGetMaxValueInBufferCHROMIUM( |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 7441 | GLuint buffer_id, GLsizei count, GLenum type, GLuint offset) { |
| 7442 | GLuint max_vertex_accessed = 0; |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 7443 | Buffer* buffer = GetBuffer(buffer_id); |
| 7444 | if (!buffer) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7445 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7446 | LOCAL_SET_GL_ERROR( |
| 7447 | GL_INVALID_VALUE, "GetMaxValueInBufferCHROMIUM", "unknown buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 7448 | } else { |
[email protected] | b10492f | 2013-03-08 05:24:07 | [diff] [blame] | 7449 | if (!buffer->GetMaxValueForRange( |
| 7450 | offset, count, type, &max_vertex_accessed)) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7451 | // TODO(gman): Should this be a GL error or a command buffer error? |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7452 | LOCAL_SET_GL_ERROR( |
[email protected] | 269200b1 | 2010-11-18 22:53:06 | [diff] [blame] | 7453 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 7454 | "GetMaxValueInBufferCHROMIUM", "range out of bounds for buffer"); |
[email protected] | 29a9eb5 | 2010-04-13 09:04:23 | [diff] [blame] | 7455 | } |
| 7456 | } |
| 7457 | return max_vertex_accessed; |
| 7458 | } |
| 7459 | |
zmo | 1bb3d1d | 2015-01-21 20:29:43 | [diff] [blame] | 7460 | void GLES2DecoderImpl::DoShaderSource( |
| 7461 | GLuint client_id, GLsizei count, const char** data, const GLint* length) { |
| 7462 | std::string str; |
| 7463 | for (GLsizei ii = 0; ii < count; ++ii) { |
dyen | 7b0b4ba5 | 2015-02-04 21:38:06 | [diff] [blame] | 7464 | if (length && length[ii] > 0) |
| 7465 | str.append(data[ii], length[ii]); |
| 7466 | else |
| 7467 | str.append(data[ii]); |
zmo | 1bb3d1d | 2015-01-21 20:29:43 | [diff] [blame] | 7468 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7469 | Shader* shader = GetShaderInfoNotProgram(client_id, "glShaderSource"); |
| 7470 | if (!shader) { |
zmo | 1bb3d1d | 2015-01-21 20:29:43 | [diff] [blame] | 7471 | return; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7472 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 7473 | // Note: We don't actually call glShaderSource here. We wait until |
dyen | 7b0b4ba5 | 2015-02-04 21:38:06 | [diff] [blame] | 7474 | // we actually compile the shader. |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7475 | shader->set_source(str); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 7476 | } |
| 7477 | |
zmo | 3892356 | 2015-01-29 20:17:39 | [diff] [blame] | 7478 | void GLES2DecoderImpl::DoTransformFeedbackVaryings( |
| 7479 | GLuint client_program_id, GLsizei count, const char* const* varyings, |
| 7480 | GLenum buffer_mode) { |
| 7481 | Program* program = GetProgramInfoNotShader( |
| 7482 | client_program_id, "glTransformFeedbackVaryings"); |
| 7483 | if (!program) { |
| 7484 | return; |
| 7485 | } |
bajones | 63ead73 | 2015-03-14 00:12:46 | [diff] [blame] | 7486 | program->TransformFeedbackVaryings(count, varyings, buffer_mode); |
zmo | 3892356 | 2015-01-29 20:17:39 | [diff] [blame] | 7487 | glTransformFeedbackVaryings( |
| 7488 | program->service_id(), count, varyings, buffer_mode); |
| 7489 | } |
| 7490 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7491 | void GLES2DecoderImpl::DoCompileShader(GLuint client_id) { |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 7492 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompileShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7493 | Shader* shader = GetShaderInfoNotProgram(client_id, "glCompileShader"); |
| 7494 | if (!shader) { |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 7495 | return; |
| 7496 | } |
dyen | 0ff9e440 | 2015-02-12 22:27:43 | [diff] [blame] | 7497 | |
| 7498 | scoped_refptr<ShaderTranslatorInterface> translator; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 7499 | if (use_shader_translator_) { |
dyen | 0ff9e440 | 2015-02-12 22:27:43 | [diff] [blame] | 7500 | translator = shader->shader_type() == GL_VERTEX_SHADER ? |
| 7501 | vertex_translator_ : fragment_translator_; |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 7502 | } |
[email protected] | de17df39 | 2010-04-23 21:09:41 | [diff] [blame] | 7503 | |
dyen | 0ff9e440 | 2015-02-12 22:27:43 | [diff] [blame] | 7504 | const Shader::TranslatedShaderSourceType source_type = |
| 7505 | feature_info_->feature_flags().angle_translated_shader_source ? |
| 7506 | Shader::kANGLE : Shader::kGL; |
| 7507 | shader->RequestCompile(translator, source_type); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 7508 | } |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 7509 | |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7510 | void GLES2DecoderImpl::DoGetShaderiv( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7511 | GLuint shader_id, GLenum pname, GLint* params) { |
| 7512 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderiv"); |
| 7513 | if (!shader) { |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7514 | return; |
| 7515 | } |
dyen | 0ff9e440 | 2015-02-12 22:27:43 | [diff] [blame] | 7516 | |
| 7517 | // Compile now for statuses that require it. |
| 7518 | switch (pname) { |
| 7519 | case GL_COMPILE_STATUS: |
| 7520 | case GL_INFO_LOG_LENGTH: |
| 7521 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 7522 | shader->DoCompile(); |
| 7523 | break; |
| 7524 | |
| 7525 | default: |
| 7526 | break; |
| 7527 | } |
| 7528 | |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 7529 | switch (pname) { |
| 7530 | case GL_SHADER_SOURCE_LENGTH: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7531 | *params = shader->source().size(); |
| 7532 | if (*params) |
| 7533 | ++(*params); |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 7534 | return; |
| 7535 | case GL_COMPILE_STATUS: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7536 | *params = compile_shader_always_succeeds_ ? true : shader->valid(); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 7537 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 7538 | case GL_INFO_LOG_LENGTH: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7539 | *params = shader->log_info().size(); |
| 7540 | if (*params) |
| 7541 | ++(*params); |
[email protected] | e518616 | 2010-06-14 18:54:41 | [diff] [blame] | 7542 | return; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7543 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7544 | *params = shader->translated_source().size(); |
| 7545 | if (*params) |
| 7546 | ++(*params); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7547 | return; |
[email protected] | 8f1ccdac | 2010-05-19 21:01:48 | [diff] [blame] | 7548 | default: |
| 7549 | break; |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7550 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7551 | glGetShaderiv(shader->service_id(), pname, params); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 7552 | } |
| 7553 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7554 | error::Error GLES2DecoderImpl::HandleGetShaderSource(uint32 immediate_data_size, |
| 7555 | const void* cmd_data) { |
| 7556 | const gles2::cmds::GetShaderSource& c = |
| 7557 | *static_cast<const gles2::cmds::GetShaderSource*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7558 | GLuint shader_id = c.shader; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7559 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 7560 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7561 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderSource"); |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7562 | if (!shader || shader->source().empty()) { |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7563 | bucket->SetSize(0); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 7564 | return error::kNoError; |
| 7565 | } |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7566 | bucket->SetFromString(shader->source().c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7567 | return error::kNoError; |
| 7568 | } |
| 7569 | |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7570 | error::Error GLES2DecoderImpl::HandleGetTranslatedShaderSourceANGLE( |
| 7571 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7572 | const void* cmd_data) { |
| 7573 | const gles2::cmds::GetTranslatedShaderSourceANGLE& c = |
| 7574 | *static_cast<const gles2::cmds::GetTranslatedShaderSourceANGLE*>( |
| 7575 | cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7576 | GLuint shader_id = c.shader; |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7577 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 7578 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7579 | Shader* shader = GetShaderInfoNotProgram( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 7580 | shader_id, "glGetTranslatedShaderSourceANGLE"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7581 | if (!shader) { |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7582 | bucket->SetSize(0); |
| 7583 | return error::kNoError; |
| 7584 | } |
| 7585 | |
dyen | 0ff9e440 | 2015-02-12 22:27:43 | [diff] [blame] | 7586 | // Make sure translator has been utilized in compile. |
| 7587 | shader->DoCompile(); |
| 7588 | |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7589 | bucket->SetFromString(shader->translated_source().c_str()); |
[email protected] | d6a53e4 | 2011-10-05 00:09:36 | [diff] [blame] | 7590 | return error::kNoError; |
| 7591 | } |
| 7592 | |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7593 | error::Error GLES2DecoderImpl::HandleGetProgramInfoLog( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7594 | uint32 immediate_data_size, |
| 7595 | const void* cmd_data) { |
| 7596 | const gles2::cmds::GetProgramInfoLog& c = |
| 7597 | *static_cast<const gles2::cmds::GetProgramInfoLog*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7598 | GLuint program_id = c.program; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7599 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 7600 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7601 | Program* program = GetProgramInfoNotShader( |
| 7602 | program_id, "glGetProgramInfoLog"); |
| 7603 | if (!program || !program->log_info()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 7604 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7605 | return error::kNoError; |
[email protected] | 45bf515 | 2010-02-12 00:11:31 | [diff] [blame] | 7606 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7607 | bucket->SetFromString(program->log_info()->c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7608 | return error::kNoError; |
| 7609 | } |
| 7610 | |
| 7611 | error::Error GLES2DecoderImpl::HandleGetShaderInfoLog( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 7612 | uint32 immediate_data_size, |
| 7613 | const void* cmd_data) { |
| 7614 | const gles2::cmds::GetShaderInfoLog& c = |
| 7615 | *static_cast<const gles2::cmds::GetShaderInfoLog*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7616 | GLuint shader_id = c.shader; |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7617 | uint32 bucket_id = static_cast<uint32>(c.bucket_id); |
| 7618 | Bucket* bucket = CreateBucket(bucket_id); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7619 | Shader* shader = GetShaderInfoNotProgram(shader_id, "glGetShaderInfoLog"); |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7620 | if (!shader) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 7621 | bucket->SetFromString(""); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7622 | return error::kNoError; |
| 7623 | } |
dyen | 0ff9e440 | 2015-02-12 22:27:43 | [diff] [blame] | 7624 | |
| 7625 | // Shader must be compiled in order to get the info log. |
| 7626 | shader->DoCompile(); |
| 7627 | |
zmo | 576a049 | 2014-09-13 01:12:32 | [diff] [blame] | 7628 | bucket->SetFromString(shader->log_info().c_str()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7629 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 7630 | } |
| 7631 | |
[email protected] | d058bca | 2012-11-26 10:27:26 | [diff] [blame] | 7632 | bool GLES2DecoderImpl::DoIsEnabled(GLenum cap) { |
| 7633 | return state_.GetEnabled(cap); |
| 7634 | } |
| 7635 | |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7636 | bool GLES2DecoderImpl::DoIsBuffer(GLuint client_id) { |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 7637 | const Buffer* buffer = GetBuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7638 | return buffer && buffer->IsValid() && !buffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7639 | } |
| 7640 | |
| 7641 | bool GLES2DecoderImpl::DoIsFramebuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7642 | const Framebuffer* framebuffer = |
| 7643 | GetFramebuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7644 | return framebuffer && framebuffer->IsValid() && !framebuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7645 | } |
| 7646 | |
| 7647 | bool GLES2DecoderImpl::DoIsProgram(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 7648 | // IsProgram is true for programs as soon as they are created, until they are |
| 7649 | // deleted and no longer in use. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7650 | const Program* program = GetProgram(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7651 | return program != NULL && !program->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7652 | } |
| 7653 | |
| 7654 | bool GLES2DecoderImpl::DoIsRenderbuffer(GLuint client_id) { |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7655 | const Renderbuffer* renderbuffer = |
| 7656 | GetRenderbuffer(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7657 | return renderbuffer && renderbuffer->IsValid() && !renderbuffer->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7658 | } |
| 7659 | |
| 7660 | bool GLES2DecoderImpl::DoIsShader(GLuint client_id) { |
[email protected] | 06c8b08 | 2011-01-05 18:00:36 | [diff] [blame] | 7661 | // IsShader is true for shaders as soon as they are created, until they |
| 7662 | // are deleted and not attached to any programs. |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 7663 | const Shader* shader = GetShader(client_id); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 7664 | return shader != NULL && !shader->IsDeleted(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7665 | } |
| 7666 | |
| 7667 | bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 7668 | const TextureRef* texture_ref = GetTexture(client_id); |
| 7669 | return texture_ref && texture_ref->texture()->IsValid(); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7670 | } |
| 7671 | |
| 7672 | void GLES2DecoderImpl::DoAttachShader( |
| 7673 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7674 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7675 | program_client_id, "glAttachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7676 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7677 | return; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7678 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7679 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glAttachShader"); |
| 7680 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7681 | return; |
| 7682 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7683 | if (!program->AttachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7684 | LOCAL_SET_GL_ERROR( |
| 7685 | GL_INVALID_OPERATION, |
| 7686 | "glAttachShader", |
| 7687 | "can not attach more than one shader of the same type."); |
[email protected] | fb96c8e | 2010-08-12 04:10:31 | [diff] [blame] | 7688 | return; |
| 7689 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7690 | glAttachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7691 | } |
| 7692 | |
| 7693 | void GLES2DecoderImpl::DoDetachShader( |
| 7694 | GLuint program_client_id, GLint shader_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7695 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7696 | program_client_id, "glDetachShader"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7697 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7698 | return; |
| 7699 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7700 | Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glDetachShader"); |
| 7701 | if (!shader) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7702 | return; |
| 7703 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7704 | if (!program->DetachShader(shader_manager(), shader)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7705 | LOCAL_SET_GL_ERROR( |
| 7706 | GL_INVALID_OPERATION, |
| 7707 | "glDetachShader", "shader not attached to program"); |
[email protected] | 9a0ccd4 | 2011-03-16 23:58:22 | [diff] [blame] | 7708 | return; |
| 7709 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7710 | glDetachShader(program->service_id(), shader->service_id()); |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7711 | } |
| 7712 | |
| 7713 | void GLES2DecoderImpl::DoValidateProgram(GLuint program_client_id) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7714 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 7715 | program_client_id, "glValidateProgram"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7716 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 7717 | return; |
| 7718 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 7719 | program->Validate(); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 7720 | } |
| 7721 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7722 | void GLES2DecoderImpl::GetVertexAttribHelper( |
| 7723 | const VertexAttrib* attrib, GLenum pname, GLint* params) { |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7724 | switch (pname) { |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7725 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 7726 | { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7727 | Buffer* buffer = attrib->buffer(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7728 | if (buffer && !buffer->IsDeleted()) { |
| 7729 | GLuint client_id; |
| 7730 | buffer_manager()->GetClientId(buffer->service_id(), &client_id); |
| 7731 | *params = client_id; |
| 7732 | } |
| 7733 | break; |
| 7734 | } |
| 7735 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7736 | *params = attrib->enabled(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7737 | break; |
| 7738 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7739 | *params = attrib->size(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7740 | break; |
| 7741 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7742 | *params = attrib->gl_stride(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7743 | break; |
| 7744 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7745 | *params = attrib->type(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7746 | break; |
| 7747 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7748 | *params = attrib->normalized(); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7749 | break; |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7750 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7751 | *params = attrib->divisor(); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 7752 | break; |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7753 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 7754 | *params = attrib->integer(); |
| 7755 | break; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7756 | default: |
| 7757 | NOTREACHED(); |
| 7758 | break; |
| 7759 | } |
| 7760 | } |
| 7761 | |
[email protected] | 4c6f546 | 2014-03-05 00:26:56 | [diff] [blame] | 7762 | void GLES2DecoderImpl::DoGetTexParameterfv( |
| 7763 | GLenum target, GLenum pname, GLfloat* params) { |
| 7764 | InitTextureMaxAnisotropyIfNeeded(target, pname); |
| 7765 | glGetTexParameterfv(target, pname, params); |
| 7766 | } |
| 7767 | |
| 7768 | void GLES2DecoderImpl::DoGetTexParameteriv( |
| 7769 | GLenum target, GLenum pname, GLint* params) { |
| 7770 | InitTextureMaxAnisotropyIfNeeded(target, pname); |
| 7771 | glGetTexParameteriv(target, pname, params); |
| 7772 | } |
| 7773 | |
| 7774 | void GLES2DecoderImpl::InitTextureMaxAnisotropyIfNeeded( |
| 7775 | GLenum target, GLenum pname) { |
| 7776 | if (!workarounds().init_texture_max_anisotropy) |
| 7777 | return; |
| 7778 | if (pname != GL_TEXTURE_MAX_ANISOTROPY_EXT || |
| 7779 | !validators_->texture_parameter.IsValid(pname)) { |
| 7780 | return; |
| 7781 | } |
| 7782 | |
| 7783 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 7784 | &state_, target); |
| 7785 | if (!texture_ref) { |
| 7786 | LOCAL_SET_GL_ERROR( |
| 7787 | GL_INVALID_OPERATION, |
| 7788 | "glGetTexParamter{fi}v", "unknown texture for target"); |
| 7789 | return; |
| 7790 | } |
| 7791 | Texture* texture = texture_ref->texture(); |
| 7792 | texture->InitTextureMaxAnisotropyIfNeeded(target); |
| 7793 | } |
| 7794 | |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7795 | template <typename T> |
| 7796 | void GLES2DecoderImpl::DoGetVertexAttribImpl( |
| 7797 | GLuint index, GLenum pname, T* params) { |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7798 | VertexAttrib* attrib = state_.vertex_attrib_manager->GetVertexAttrib(index); |
| 7799 | if (!attrib) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7800 | LOCAL_SET_GL_ERROR( |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7801 | GL_INVALID_VALUE, "glGetVertexAttrib", "index out of range"); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7802 | return; |
| 7803 | } |
| 7804 | switch (pname) { |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7805 | case GL_CURRENT_VERTEX_ATTRIB: |
| 7806 | state_.attrib_values[index].GetValues(params); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7807 | break; |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7808 | default: { |
| 7809 | GLint value = 0; |
| 7810 | GetVertexAttribHelper(attrib, pname, &value); |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7811 | *params = static_cast<T>(value); |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7812 | break; |
| 7813 | } |
| 7814 | } |
| 7815 | } |
| 7816 | |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7817 | void GLES2DecoderImpl::DoGetVertexAttribfv( |
| 7818 | GLuint index, GLenum pname, GLfloat* params) { |
| 7819 | DoGetVertexAttribImpl<GLfloat>(index, pname, params); |
| 7820 | } |
| 7821 | |
[email protected] | ac77603c7 | 2013-03-08 13:52:06 | [diff] [blame] | 7822 | void GLES2DecoderImpl::DoGetVertexAttribiv( |
| 7823 | GLuint index, GLenum pname, GLint* params) { |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7824 | DoGetVertexAttribImpl<GLint>(index, pname, params); |
| 7825 | } |
| 7826 | |
| 7827 | void GLES2DecoderImpl::DoGetVertexAttribIiv( |
| 7828 | GLuint index, GLenum pname, GLint* params) { |
| 7829 | DoGetVertexAttribImpl<GLint>(index, pname, params); |
| 7830 | } |
| 7831 | |
| 7832 | void GLES2DecoderImpl::DoGetVertexAttribIuiv( |
| 7833 | GLuint index, GLenum pname, GLuint* params) { |
| 7834 | DoGetVertexAttribImpl<GLuint>(index, pname, params); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7835 | } |
| 7836 | |
zmo | 143c51a | 2015-05-15 03:04:07 | [diff] [blame] | 7837 | template <typename T> |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7838 | bool GLES2DecoderImpl::SetVertexAttribValue( |
zmo | 143c51a | 2015-05-15 03:04:07 | [diff] [blame] | 7839 | const char* function_name, GLuint index, const T* value) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7840 | if (index >= state_.attrib_values.size()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 7841 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "index out of range"); |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7842 | return false; |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7843 | } |
zmo | 5ee097e | 2015-05-14 19:13:52 | [diff] [blame] | 7844 | state_.attrib_values[index].SetValues(value); |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7845 | return true; |
| 7846 | } |
| 7847 | |
| 7848 | void GLES2DecoderImpl::DoVertexAttrib1f(GLuint index, GLfloat v0) { |
| 7849 | GLfloat v[4] = { v0, 0.0f, 0.0f, 1.0f, }; |
| 7850 | if (SetVertexAttribValue("glVertexAttrib1f", index, v)) { |
| 7851 | glVertexAttrib1f(index, v0); |
| 7852 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7853 | } |
| 7854 | |
| 7855 | void GLES2DecoderImpl::DoVertexAttrib2f(GLuint index, GLfloat v0, GLfloat v1) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7856 | GLfloat v[4] = { v0, v1, 0.0f, 1.0f, }; |
| 7857 | if (SetVertexAttribValue("glVertexAttrib2f", index, v)) { |
| 7858 | glVertexAttrib2f(index, v0, v1); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7859 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7860 | } |
| 7861 | |
| 7862 | void GLES2DecoderImpl::DoVertexAttrib3f( |
| 7863 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7864 | GLfloat v[4] = { v0, v1, v2, 1.0f, }; |
| 7865 | if (SetVertexAttribValue("glVertexAttrib3f", index, v)) { |
| 7866 | glVertexAttrib3f(index, v0, v1, v2); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7867 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7868 | } |
| 7869 | |
| 7870 | void GLES2DecoderImpl::DoVertexAttrib4f( |
| 7871 | GLuint index, GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7872 | GLfloat v[4] = { v0, v1, v2, v3, }; |
| 7873 | if (SetVertexAttribValue("glVertexAttrib4f", index, v)) { |
| 7874 | glVertexAttrib4f(index, v0, v1, v2, v3); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7875 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7876 | } |
| 7877 | |
| 7878 | void GLES2DecoderImpl::DoVertexAttrib1fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7879 | GLfloat t[4] = { v[0], 0.0f, 0.0f, 1.0f, }; |
| 7880 | if (SetVertexAttribValue("glVertexAttrib1fv", index, t)) { |
| 7881 | glVertexAttrib1fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7882 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7883 | } |
| 7884 | |
| 7885 | void GLES2DecoderImpl::DoVertexAttrib2fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7886 | GLfloat t[4] = { v[0], v[1], 0.0f, 1.0f, }; |
| 7887 | if (SetVertexAttribValue("glVertexAttrib2fv", index, t)) { |
| 7888 | glVertexAttrib2fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7889 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7890 | } |
| 7891 | |
| 7892 | void GLES2DecoderImpl::DoVertexAttrib3fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7893 | GLfloat t[4] = { v[0], v[1], v[2], 1.0f, }; |
| 7894 | if (SetVertexAttribValue("glVertexAttrib3fv", index, t)) { |
| 7895 | glVertexAttrib3fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7896 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7897 | } |
| 7898 | |
| 7899 | void GLES2DecoderImpl::DoVertexAttrib4fv(GLuint index, const GLfloat* v) { |
[email protected] | af638096 | 2012-11-29 23:24:13 | [diff] [blame] | 7900 | if (SetVertexAttribValue("glVertexAttrib4fv", index, v)) { |
| 7901 | glVertexAttrib4fv(index, v); |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7902 | } |
[email protected] | b112298 | 2010-05-17 23:04:24 | [diff] [blame] | 7903 | } |
| 7904 | |
zmo | 143c51a | 2015-05-15 03:04:07 | [diff] [blame] | 7905 | void GLES2DecoderImpl::DoVertexAttribI4i( |
| 7906 | GLuint index, GLint v0, GLint v1, GLint v2, GLint v3) { |
| 7907 | GLint v[4] = { v0, v1, v2, v3 }; |
| 7908 | if (SetVertexAttribValue("glVertexAttribI4i", index, v)) { |
| 7909 | glVertexAttribI4i(index, v0, v1, v2, v3); |
| 7910 | } |
| 7911 | } |
| 7912 | |
| 7913 | void GLES2DecoderImpl::DoVertexAttribI4iv(GLuint index, const GLint* v) { |
| 7914 | if (SetVertexAttribValue("glVertexAttribI4iv", index, v)) { |
| 7915 | glVertexAttribI4iv(index, v); |
| 7916 | } |
| 7917 | } |
| 7918 | |
| 7919 | void GLES2DecoderImpl::DoVertexAttribI4ui( |
| 7920 | GLuint index, GLuint v0, GLuint v1, GLuint v2, GLuint v3) { |
| 7921 | GLuint v[4] = { v0, v1, v2, v3 }; |
| 7922 | if (SetVertexAttribValue("glVertexAttribI4ui", index, v)) { |
| 7923 | glVertexAttribI4ui(index, v0, v1, v2, v3); |
| 7924 | } |
| 7925 | } |
| 7926 | |
| 7927 | void GLES2DecoderImpl::DoVertexAttribI4uiv(GLuint index, const GLuint* v) { |
| 7928 | if (SetVertexAttribValue("glVertexAttribI4uiv", index, v)) { |
| 7929 | glVertexAttribI4uiv(index, v); |
| 7930 | } |
| 7931 | } |
| 7932 | |
zmo | 0c4b7cf | 2014-11-26 00:52:11 | [diff] [blame] | 7933 | error::Error GLES2DecoderImpl::HandleVertexAttribIPointer( |
| 7934 | uint32 immediate_data_size, |
| 7935 | const void* cmd_data) { |
zmo | 0c4b7cf | 2014-11-26 00:52:11 | [diff] [blame] | 7936 | if (!unsafe_es3_apis_enabled()) |
| 7937 | return error::kUnknownCommand; |
| 7938 | const gles2::cmds::VertexAttribIPointer& c = |
| 7939 | *static_cast<const gles2::cmds::VertexAttribIPointer*>(cmd_data); |
guanxian.li | 87543be3 | 2015-04-28 03:01:04 | [diff] [blame] | 7940 | |
| 7941 | if (!state_.bound_array_buffer.get() || |
| 7942 | state_.bound_array_buffer->IsDeleted()) { |
| 7943 | if (state_.vertex_attrib_manager.get() == |
| 7944 | state_.default_vertex_attrib_manager.get()) { |
| 7945 | LOCAL_SET_GL_ERROR( |
| 7946 | GL_INVALID_VALUE, "glVertexAttribIPointer", "no array buffer bound"); |
| 7947 | return error::kNoError; |
| 7948 | } else if (c.offset != 0) { |
| 7949 | LOCAL_SET_GL_ERROR( |
| 7950 | GL_INVALID_VALUE, |
| 7951 | "glVertexAttribIPointer", "client side arrays are not allowed"); |
| 7952 | return error::kNoError; |
| 7953 | } |
| 7954 | } |
| 7955 | |
zmo | 0c4b7cf | 2014-11-26 00:52:11 | [diff] [blame] | 7956 | GLuint indx = c.indx; |
| 7957 | GLint size = c.size; |
| 7958 | GLenum type = c.type; |
| 7959 | GLsizei stride = c.stride; |
| 7960 | GLsizei offset = c.offset; |
| 7961 | const void* ptr = reinterpret_cast<const void*>(offset); |
guanxian.li | 87543be3 | 2015-04-28 03:01:04 | [diff] [blame] | 7962 | if (!validators_->vertex_attrib_i_type.IsValid(type)) { |
| 7963 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glVertexAttribIPointer", type, "type"); |
| 7964 | return error::kNoError; |
| 7965 | } |
| 7966 | if (!validators_->vertex_attrib_size.IsValid(size)) { |
| 7967 | LOCAL_SET_GL_ERROR( |
| 7968 | GL_INVALID_VALUE, "glVertexAttribIPointer", "size GL_INVALID_VALUE"); |
| 7969 | return error::kNoError; |
| 7970 | } |
| 7971 | if (indx >= group_->max_vertex_attribs()) { |
| 7972 | LOCAL_SET_GL_ERROR( |
| 7973 | GL_INVALID_VALUE, "glVertexAttribIPointer", "index out of range"); |
| 7974 | return error::kNoError; |
| 7975 | } |
| 7976 | if (stride < 0) { |
| 7977 | LOCAL_SET_GL_ERROR( |
| 7978 | GL_INVALID_VALUE, "glVertexAttribIPointer", "stride < 0"); |
| 7979 | return error::kNoError; |
| 7980 | } |
| 7981 | if (stride > 255) { |
| 7982 | LOCAL_SET_GL_ERROR( |
| 7983 | GL_INVALID_VALUE, "glVertexAttribIPointer", "stride > 255"); |
| 7984 | return error::kNoError; |
| 7985 | } |
| 7986 | if (offset < 0) { |
| 7987 | LOCAL_SET_GL_ERROR( |
| 7988 | GL_INVALID_VALUE, "glVertexAttribIPointer", "offset < 0"); |
| 7989 | return error::kNoError; |
| 7990 | } |
| 7991 | GLsizei component_size = |
| 7992 | GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type); |
| 7993 | // component_size must be a power of two to use & as optimized modulo. |
| 7994 | DCHECK(GLES2Util::IsPOT(component_size)); |
| 7995 | if (offset & (component_size - 1)) { |
| 7996 | LOCAL_SET_GL_ERROR( |
| 7997 | GL_INVALID_OPERATION, |
| 7998 | "glVertexAttribIPointer", "offset not valid for type"); |
| 7999 | return error::kNoError; |
| 8000 | } |
| 8001 | if (stride & (component_size - 1)) { |
| 8002 | LOCAL_SET_GL_ERROR( |
| 8003 | GL_INVALID_OPERATION, |
| 8004 | "glVertexAttribIPointer", "stride not valid for type"); |
| 8005 | return error::kNoError; |
| 8006 | } |
| 8007 | state_.vertex_attrib_manager |
| 8008 | ->SetAttribInfo(indx, |
| 8009 | state_.bound_array_buffer.get(), |
| 8010 | size, |
| 8011 | type, |
| 8012 | GL_FALSE, |
| 8013 | stride, |
| 8014 | stride != 0 ? stride : component_size * size, |
zmo | 143c51a | 2015-05-15 03:04:07 | [diff] [blame] | 8015 | offset, |
| 8016 | GL_TRUE); |
zmo | 0c4b7cf | 2014-11-26 00:52:11 | [diff] [blame] | 8017 | glVertexAttribIPointer(indx, size, type, stride, ptr); |
| 8018 | return error::kNoError; |
| 8019 | } |
| 8020 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8021 | error::Error GLES2DecoderImpl::HandleVertexAttribPointer( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8022 | uint32 immediate_data_size, |
| 8023 | const void* cmd_data) { |
| 8024 | const gles2::cmds::VertexAttribPointer& c = |
| 8025 | *static_cast<const gles2::cmds::VertexAttribPointer*>(cmd_data); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8026 | |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 8027 | if (!state_.bound_array_buffer.get() || |
| 8028 | state_.bound_array_buffer->IsDeleted()) { |
| 8029 | if (state_.vertex_attrib_manager.get() == |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 8030 | state_.default_vertex_attrib_manager.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8031 | LOCAL_SET_GL_ERROR( |
| 8032 | GL_INVALID_VALUE, "glVertexAttribPointer", "no array buffer bound"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8033 | return error::kNoError; |
| 8034 | } else if (c.offset != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8035 | LOCAL_SET_GL_ERROR( |
| 8036 | GL_INVALID_VALUE, |
| 8037 | "glVertexAttribPointer", "client side arrays are not allowed"); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 8038 | return error::kNoError; |
| 8039 | } |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8040 | } |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8041 | |
| 8042 | GLuint indx = c.indx; |
| 8043 | GLint size = c.size; |
| 8044 | GLenum type = c.type; |
pkasting | 45796dc | 2014-10-17 04:18:32 | [diff] [blame] | 8045 | GLboolean normalized = static_cast<GLboolean>(c.normalized); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8046 | GLsizei stride = c.stride; |
| 8047 | GLsizei offset = c.offset; |
| 8048 | const void* ptr = reinterpret_cast<const void*>(offset); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8049 | if (!validators_->vertex_attrib_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8050 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glVertexAttribPointer", type, "type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8051 | return error::kNoError; |
| 8052 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8053 | if (!validators_->vertex_attrib_size.IsValid(size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8054 | LOCAL_SET_GL_ERROR( |
| 8055 | GL_INVALID_VALUE, "glVertexAttribPointer", "size GL_INVALID_VALUE"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8056 | return error::kNoError; |
| 8057 | } |
| 8058 | if (indx >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8059 | LOCAL_SET_GL_ERROR( |
| 8060 | GL_INVALID_VALUE, "glVertexAttribPointer", "index out of range"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8061 | return error::kNoError; |
| 8062 | } |
| 8063 | if (stride < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8064 | LOCAL_SET_GL_ERROR( |
| 8065 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8066 | return error::kNoError; |
| 8067 | } |
| 8068 | if (stride > 255) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8069 | LOCAL_SET_GL_ERROR( |
| 8070 | GL_INVALID_VALUE, "glVertexAttribPointer", "stride > 255"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8071 | return error::kNoError; |
| 8072 | } |
| 8073 | if (offset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8074 | LOCAL_SET_GL_ERROR( |
| 8075 | GL_INVALID_VALUE, "glVertexAttribPointer", "offset < 0"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8076 | return error::kNoError; |
| 8077 | } |
| 8078 | GLsizei component_size = |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 8079 | GLES2Util::GetGLTypeSizeForTexturesAndBuffers(type); |
[email protected] | a07a2360 | 2014-08-05 11:36:12 | [diff] [blame] | 8080 | // component_size must be a power of two to use & as optimized modulo. |
| 8081 | DCHECK(GLES2Util::IsPOT(component_size)); |
| 8082 | if (offset & (component_size - 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8083 | LOCAL_SET_GL_ERROR( |
| 8084 | GL_INVALID_OPERATION, |
| 8085 | "glVertexAttribPointer", "offset not valid for type"); |
[email protected] | ff81c19 | 2011-01-07 23:04:31 | [diff] [blame] | 8086 | return error::kNoError; |
| 8087 | } |
[email protected] | a07a2360 | 2014-08-05 11:36:12 | [diff] [blame] | 8088 | if (stride & (component_size - 1)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8089 | LOCAL_SET_GL_ERROR( |
| 8090 | GL_INVALID_OPERATION, |
| 8091 | "glVertexAttribPointer", "stride not valid for type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8092 | return error::kNoError; |
| 8093 | } |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 8094 | state_.vertex_attrib_manager |
| 8095 | ->SetAttribInfo(indx, |
| 8096 | state_.bound_array_buffer.get(), |
| 8097 | size, |
| 8098 | type, |
| 8099 | normalized, |
| 8100 | stride, |
| 8101 | stride != 0 ? stride : component_size * size, |
zmo | 143c51a | 2015-05-15 03:04:07 | [diff] [blame] | 8102 | offset, |
| 8103 | GL_FALSE); |
jmadill | 7cb0b8e7 | 2015-05-06 14:03:14 | [diff] [blame] | 8104 | // We support GL_FIXED natively on EGL/GLES2 implementations |
| 8105 | if (type != GL_FIXED || feature_info_->gl_version_info().is_es) { |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 8106 | glVertexAttribPointer(indx, size, type, normalized, stride, ptr); |
| 8107 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8108 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8109 | } |
| 8110 | |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8111 | void GLES2DecoderImpl::DoViewport(GLint x, GLint y, GLsizei width, |
| 8112 | GLsizei height) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8113 | state_.viewport_x = x; |
| 8114 | state_.viewport_y = y; |
[email protected] | 1868a34 | 2012-11-07 15:56:02 | [diff] [blame] | 8115 | state_.viewport_width = std::min(width, viewport_max_width_); |
| 8116 | state_.viewport_height = std::min(height, viewport_max_height_); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 8117 | glViewport(x, y, width, height); |
| 8118 | } |
| 8119 | |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 8120 | error::Error GLES2DecoderImpl::HandleVertexAttribDivisorANGLE( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8121 | uint32 immediate_data_size, |
| 8122 | const void* cmd_data) { |
| 8123 | const gles2::cmds::VertexAttribDivisorANGLE& c = |
| 8124 | *static_cast<const gles2::cmds::VertexAttribDivisorANGLE*>(cmd_data); |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 8125 | if (!features().angle_instanced_arrays) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8126 | LOCAL_SET_GL_ERROR( |
| 8127 | GL_INVALID_OPERATION, |
| 8128 | "glVertexAttribDivisorANGLE", "function not available"); |
[email protected] | cedee33 | 2014-05-23 07:07:53 | [diff] [blame] | 8129 | return error::kNoError; |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 8130 | } |
| 8131 | GLuint index = c.index; |
| 8132 | GLuint divisor = c.divisor; |
| 8133 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8134 | LOCAL_SET_GL_ERROR( |
| 8135 | GL_INVALID_VALUE, |
| 8136 | "glVertexAttribDivisorANGLE", "index out of range"); |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 8137 | return error::kNoError; |
| 8138 | } |
| 8139 | |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8140 | state_.vertex_attrib_manager->SetDivisor( |
[email protected] | c6aef90 | 2012-02-14 03:31:42 | [diff] [blame] | 8141 | index, |
| 8142 | divisor); |
| 8143 | glVertexAttribDivisorANGLE(index, divisor); |
| 8144 | return error::kNoError; |
| 8145 | } |
| 8146 | |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 8147 | template <typename pixel_data_type> |
| 8148 | static void WriteAlphaData( |
dcastagna | 504d45c | 2015-04-06 19:30:39 | [diff] [blame] | 8149 | void* pixels, uint32 row_count, uint32 channel_count, |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 8150 | uint32 alpha_channel_index, uint32 unpadded_row_size, |
| 8151 | uint32 padded_row_size, pixel_data_type alpha_value) { |
| 8152 | DCHECK_GT(channel_count, 0U); |
| 8153 | DCHECK_EQ(unpadded_row_size % sizeof(pixel_data_type), 0U); |
| 8154 | uint32 unpadded_row_size_in_elements = |
| 8155 | unpadded_row_size / sizeof(pixel_data_type); |
| 8156 | DCHECK_EQ(padded_row_size % sizeof(pixel_data_type), 0U); |
| 8157 | uint32 padded_row_size_in_elements = |
| 8158 | padded_row_size / sizeof(pixel_data_type); |
| 8159 | pixel_data_type* dst = |
| 8160 | static_cast<pixel_data_type*>(pixels) + alpha_channel_index; |
| 8161 | for (uint32 yy = 0; yy < row_count; ++yy) { |
| 8162 | pixel_data_type* end = dst + unpadded_row_size_in_elements; |
| 8163 | for (pixel_data_type* d = dst; d < end; d += channel_count) { |
| 8164 | *d = alpha_value; |
| 8165 | } |
| 8166 | dst += padded_row_size_in_elements; |
| 8167 | } |
| 8168 | } |
| 8169 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8170 | void GLES2DecoderImpl::FinishReadPixels( |
| 8171 | const cmds::ReadPixels& c, |
| 8172 | GLuint buffer) { |
| 8173 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::FinishReadPixels"); |
| 8174 | GLsizei width = c.width; |
| 8175 | GLsizei height = c.height; |
| 8176 | GLenum format = c.format; |
| 8177 | GLenum type = c.type; |
| 8178 | typedef cmds::ReadPixels::Result Result; |
| 8179 | uint32 pixels_size; |
| 8180 | Result* result = NULL; |
| 8181 | if (c.result_shm_id != 0) { |
| 8182 | result = GetSharedMemoryAs<Result*>( |
| 8183 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8184 | if (!result) { |
| 8185 | if (buffer != 0) { |
| 8186 | glDeleteBuffersARB(1, &buffer); |
| 8187 | } |
| 8188 | return; |
| 8189 | } |
| 8190 | } |
| 8191 | GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8192 | width, height, 1, format, type, state_.pack_alignment, &pixels_size, |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8193 | NULL, NULL); |
| 8194 | void* pixels = GetSharedMemoryAs<void*>( |
| 8195 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
| 8196 | if (!pixels) { |
| 8197 | if (buffer != 0) { |
| 8198 | glDeleteBuffersARB(1, &buffer); |
| 8199 | } |
| 8200 | return; |
| 8201 | } |
| 8202 | |
| 8203 | if (buffer != 0) { |
| 8204 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
[email protected] | e585f9e2 | 2013-08-27 02:50:33 | [diff] [blame] | 8205 | void* data; |
| 8206 | if (features().map_buffer_range) { |
| 8207 | data = glMapBufferRange( |
| 8208 | GL_PIXEL_PACK_BUFFER_ARB, 0, pixels_size, GL_MAP_READ_BIT); |
| 8209 | } else { |
| 8210 | data = glMapBuffer(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY); |
| 8211 | } |
miu | b70d7859 | 2014-11-15 03:53:47 | [diff] [blame] | 8212 | if (!data) { |
| 8213 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glMapBuffer", |
| 8214 | "Unable to map memory for readback."); |
| 8215 | return; |
| 8216 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8217 | memcpy(pixels, data, pixels_size); |
| 8218 | // GL_PIXEL_PACK_BUFFER_ARB is currently unused, so we don't |
| 8219 | // have to restore the state. |
| 8220 | glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB); |
| 8221 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 8222 | glDeleteBuffersARB(1, &buffer); |
| 8223 | } |
| 8224 | |
| 8225 | if (result != NULL) { |
| 8226 | *result = true; |
| 8227 | } |
| 8228 | |
| 8229 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 8230 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 8231 | if ((channels_exist & 0x0008) == 0 && |
| 8232 | workarounds().clear_alpha_in_readpixels) { |
| 8233 | // Set the alpha to 255 because some drivers are buggy in this regard. |
| 8234 | uint32 temp_size; |
| 8235 | |
| 8236 | uint32 unpadded_row_size; |
| 8237 | uint32 padded_row_size; |
| 8238 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8239 | width, 2, 1, format, type, state_.pack_alignment, &temp_size, |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8240 | &unpadded_row_size, &padded_row_size)) { |
| 8241 | return; |
| 8242 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 8243 | |
| 8244 | uint32 channel_count = 0; |
| 8245 | uint32 alpha_channel = 0; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8246 | switch (format) { |
| 8247 | case GL_RGBA: |
| 8248 | case GL_BGRA_EXT: |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 8249 | channel_count = 4; |
| 8250 | alpha_channel = 3; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8251 | break; |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 8252 | case GL_ALPHA: |
| 8253 | channel_count = 1; |
| 8254 | alpha_channel = 0; |
| 8255 | break; |
| 8256 | } |
| 8257 | |
| 8258 | if (channel_count > 0) { |
| 8259 | switch (type) { |
| 8260 | case GL_UNSIGNED_BYTE: |
| 8261 | WriteAlphaData<uint8>( |
| 8262 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 8263 | padded_row_size, 0xFF); |
| 8264 | break; |
| 8265 | case GL_FLOAT: |
| 8266 | WriteAlphaData<float>( |
| 8267 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 8268 | padded_row_size, 1.0f); |
| 8269 | break; |
| 8270 | case GL_HALF_FLOAT: |
| 8271 | WriteAlphaData<uint16>( |
| 8272 | pixels, height, channel_count, alpha_channel, unpadded_row_size, |
| 8273 | padded_row_size, 0x3C00); |
| 8274 | break; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8275 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8276 | } |
| 8277 | } |
| 8278 | } |
| 8279 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8280 | error::Error GLES2DecoderImpl::HandleReadPixels(uint32 immediate_data_size, |
| 8281 | const void* cmd_data) { |
| 8282 | const gles2::cmds::ReadPixels& c = |
| 8283 | *static_cast<const gles2::cmds::ReadPixels*>(cmd_data); |
[email protected] | c959a09a | 2014-03-27 11:44:21 | [diff] [blame] | 8284 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleReadPixels"); |
[email protected] | c76fe67 | 2013-12-13 23:30:22 | [diff] [blame] | 8285 | error::Error fbo_error = WillAccessBoundFramebufferForRead(); |
| 8286 | if (fbo_error != error::kNoError) |
| 8287 | return fbo_error; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 8288 | GLint x = c.x; |
| 8289 | GLint y = c.y; |
| 8290 | GLsizei width = c.width; |
| 8291 | GLsizei height = c.height; |
| 8292 | GLenum format = c.format; |
| 8293 | GLenum type = c.type; |
pkasting | 45796dc | 2014-10-17 04:18:32 | [diff] [blame] | 8294 | GLboolean async = static_cast<GLboolean>(c.async); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8295 | if (width < 0 || height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8296 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glReadPixels", "dimensions < 0"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8297 | return error::kNoError; |
| 8298 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8299 | typedef cmds::ReadPixels::Result Result; |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 8300 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8301 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8302 | width, height, 1, format, type, state_.pack_alignment, &pixels_size, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8303 | NULL, NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 8304 | return error::kOutOfBounds; |
| 8305 | } |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 8306 | void* pixels = GetSharedMemoryAs<void*>( |
| 8307 | c.pixels_shm_id, c.pixels_shm_offset, pixels_size); |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 8308 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8309 | return error::kOutOfBounds; |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 8310 | } |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 8311 | Result* result = NULL; |
| 8312 | if (c.result_shm_id != 0) { |
| 8313 | result = GetSharedMemoryAs<Result*>( |
| 8314 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 8315 | if (!result) { |
| 8316 | return error::kOutOfBounds; |
| 8317 | } |
| 8318 | } |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 8319 | |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8320 | if (!validators_->read_pixel_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8321 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", format, "format"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 8322 | return error::kNoError; |
| 8323 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 8324 | if (!validators_->read_pixel_type.IsValid(type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8325 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glReadPixels", type, "type"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 8326 | return error::kNoError; |
| 8327 | } |
[email protected] | 6858637 | 2013-12-11 01:27:59 | [diff] [blame] | 8328 | if ((format != GL_RGBA && format != GL_BGRA_EXT && format != GL_RGB && |
| 8329 | format != GL_ALPHA) || type != GL_UNSIGNED_BYTE) { |
| 8330 | // format and type are acceptable enums but not guaranteed to be supported |
| 8331 | // for this framebuffer. Have to ask gl if they are valid. |
| 8332 | GLint preferred_format = 0; |
| 8333 | DoGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &preferred_format); |
| 8334 | GLint preferred_type = 0; |
| 8335 | DoGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &preferred_type); |
| 8336 | if (format != static_cast<GLenum>(preferred_format) || |
| 8337 | type != static_cast<GLenum>(preferred_type)) { |
| 8338 | LOCAL_SET_GL_ERROR( |
| 8339 | GL_INVALID_OPERATION, "glReadPixels", "format and type incompatible " |
| 8340 | "with the current read framebuffer"); |
| 8341 | return error::kNoError; |
| 8342 | } |
| 8343 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8344 | if (width == 0 || height == 0) { |
| 8345 | return error::kNoError; |
| 8346 | } |
| 8347 | |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8348 | // Get the size of the current fbo or backbuffer. |
[email protected] | 8e3e066 | 2010-08-23 18:46:30 | [diff] [blame] | 8349 | gfx::Size max_size = GetBoundReadFrameBufferSize(); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8350 | |
[email protected] | 3aad1a3 | 2012-09-07 20:54:47 | [diff] [blame] | 8351 | int32 max_x; |
| 8352 | int32 max_y; |
| 8353 | if (!SafeAddInt32(x, width, &max_x) || !SafeAddInt32(y, height, &max_y)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8354 | LOCAL_SET_GL_ERROR( |
| 8355 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8356 | return error::kNoError; |
[email protected] | 612d2f8 | 2009-12-08 20:49:31 | [diff] [blame] | 8357 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8358 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 8359 | if (!CheckBoundReadFramebufferColorAttachment("glReadPixels")) { |
| 8360 | return error::kNoError; |
| 8361 | } |
| 8362 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8363 | if (!CheckBoundFramebuffersValid("glReadPixels")) { |
| 8364 | return error::kNoError; |
| 8365 | } |
| 8366 | |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 8367 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glReadPixels"); |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 8368 | |
| 8369 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
| 8370 | |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 8371 | 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] | 8372 | // The user requested an out of range area. Get the results 1 line |
| 8373 | // at a time. |
| 8374 | uint32 temp_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8375 | uint32 unpadded_row_size; |
| 8376 | uint32 padded_row_size; |
| 8377 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8378 | width, 2, 1, format, type, state_.pack_alignment, &temp_size, |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8379 | &unpadded_row_size, &padded_row_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8380 | LOCAL_SET_GL_ERROR( |
| 8381 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8382 | return error::kNoError; |
| 8383 | } |
| 8384 | |
| 8385 | GLint dest_x_offset = std::max(-x, 0); |
| 8386 | uint32 dest_row_offset; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8387 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8388 | dest_x_offset, 1, 1, format, type, state_.pack_alignment, |
| 8389 | &dest_row_offset, NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8390 | LOCAL_SET_GL_ERROR( |
| 8391 | GL_INVALID_VALUE, "glReadPixels", "dimensions out of range"); |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8392 | return error::kNoError; |
| 8393 | } |
| 8394 | |
| 8395 | // Copy each row into the larger dest rect. |
| 8396 | int8* dst = static_cast<int8*>(pixels); |
| 8397 | GLint read_x = std::max(0, x); |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 8398 | 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] | 8399 | GLint read_width = read_end_x - read_x; |
| 8400 | for (GLint yy = 0; yy < height; ++yy) { |
| 8401 | GLint ry = y + yy; |
| 8402 | |
| 8403 | // Clear the row. |
| 8404 | memset(dst, 0, unpadded_row_size); |
| 8405 | |
| 8406 | // If the row is in range, copy it. |
[email protected] | d37231fa | 2010-04-09 21:16:02 | [diff] [blame] | 8407 | if (ry >= 0 && ry < max_size.height() && read_width > 0) { |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8408 | glReadPixels( |
| 8409 | read_x, ry, read_width, 1, format, type, dst + dest_row_offset); |
| 8410 | } |
| 8411 | dst += padded_row_size; |
| 8412 | } |
| 8413 | } else { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8414 | if (async && features().use_async_readpixels) { |
miu | 50cef60 | 2014-11-11 01:35:41 | [diff] [blame] | 8415 | GLuint buffer = 0; |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8416 | glGenBuffersARB(1, &buffer); |
| 8417 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, buffer); |
miu | b70d7859 | 2014-11-15 03:53:47 | [diff] [blame] | 8418 | // For ANGLE client version 2, GL_STREAM_READ is not available. |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 8419 | const GLenum usage_hint = feature_info_->gl_version_info().is_angle ? |
zmo | 68fcdc6 | 2014-12-05 21:51:49 | [diff] [blame] | 8420 | GL_STATIC_DRAW : GL_STREAM_READ; |
miu | b70d7859 | 2014-11-15 03:53:47 | [diff] [blame] | 8421 | glBufferData(GL_PIXEL_PACK_BUFFER_ARB, pixels_size, NULL, usage_hint); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8422 | GLenum error = glGetError(); |
| 8423 | if (error == GL_NO_ERROR) { |
| 8424 | glReadPixels(x, y, width, height, format, type, 0); |
| 8425 | pending_readpixel_fences_.push(linked_ptr<FenceCallback>( |
| 8426 | new FenceCallback())); |
| 8427 | WaitForReadPixels(base::Bind( |
| 8428 | &GLES2DecoderImpl::FinishReadPixels, |
| 8429 | base::internal::SupportsWeakPtrBase::StaticAsWeakPtr |
| 8430 | <GLES2DecoderImpl>(this), |
| 8431 | c, buffer)); |
| 8432 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
| 8433 | return error::kNoError; |
[email protected] | 77bfe744 | 2014-03-01 02:42:59 | [diff] [blame] | 8434 | } else { |
| 8435 | // On error, unbind pack buffer and fall through to sync readpixels |
| 8436 | glBindBuffer(GL_PIXEL_PACK_BUFFER_ARB, 0); |
miu | 50cef60 | 2014-11-11 01:35:41 | [diff] [blame] | 8437 | glDeleteBuffersARB(1, &buffer); |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8438 | } |
| 8439 | } |
[email protected] | 57f22383 | 2010-03-19 01:57:56 | [diff] [blame] | 8440 | glReadPixels(x, y, width, height, format, type, pixels); |
| 8441 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8442 | GLenum error = LOCAL_PEEK_GL_ERROR("glReadPixels"); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 8443 | if (error == GL_NO_ERROR) { |
[email protected] | de43f08 | 2013-04-02 01:16:10 | [diff] [blame] | 8444 | if (result != NULL) { |
| 8445 | *result = true; |
| 8446 | } |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 8447 | FinishReadPixels(c, 0); |
[email protected] | a51788e | 2010-02-24 21:54:25 | [diff] [blame] | 8448 | } |
[email protected] | 4848b9f8 | 2011-03-10 18:37:56 | [diff] [blame] | 8449 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8450 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 8451 | } |
| 8452 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8453 | error::Error GLES2DecoderImpl::HandlePixelStorei(uint32 immediate_data_size, |
| 8454 | const void* cmd_data) { |
| 8455 | const gles2::cmds::PixelStorei& c = |
| 8456 | *static_cast<const gles2::cmds::PixelStorei*>(cmd_data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8457 | GLenum pname = c.pname; |
| 8458 | GLenum param = c.param; |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8459 | if (!validators_->pixel_store.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8460 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glPixelStorei", pname, "pname"); |
[email protected] | d2cf0a2d | 2010-02-25 21:36:12 | [diff] [blame] | 8461 | return error::kNoError; |
| 8462 | } |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 8463 | switch (pname) { |
| 8464 | case GL_PACK_ALIGNMENT: |
| 8465 | case GL_UNPACK_ALIGNMENT: |
| 8466 | if (!validators_->pixel_store_alignment.IsValid(param)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8467 | LOCAL_SET_GL_ERROR( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 8468 | GL_INVALID_VALUE, "glPixelStorei", "param GL_INVALID_VALUE"); |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 8469 | return error::kNoError; |
| 8470 | } |
[email protected] | 164d6d5 | 2012-05-05 00:55:03 | [diff] [blame] | 8471 | break; |
[email protected] | 222471d | 2011-11-30 18:06:39 | [diff] [blame] | 8472 | default: |
| 8473 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8474 | } |
| 8475 | glPixelStorei(pname, param); |
| 8476 | switch (pname) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8477 | case GL_PACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8478 | state_.pack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8479 | break; |
| 8480 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
[email protected] | 88a61bf | 2012-10-27 13:00:42 | [diff] [blame] | 8481 | state_.pack_reverse_row_order = (param != 0); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8482 | break; |
| 8483 | case GL_UNPACK_ALIGNMENT: |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8484 | state_.unpack_alignment = param; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8485 | break; |
| 8486 | default: |
| 8487 | // Validation should have prevented us from getting here. |
| 8488 | NOTREACHED(); |
| 8489 | break; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8490 | } |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8491 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8492 | } |
| 8493 | |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 8494 | error::Error GLES2DecoderImpl::HandlePostSubBufferCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8495 | uint32 immediate_data_size, |
| 8496 | const void* cmd_data) { |
| 8497 | const gles2::cmds::PostSubBufferCHROMIUM& c = |
| 8498 | *static_cast<const gles2::cmds::PostSubBufferCHROMIUM*>(cmd_data); |
[email protected] | 43ed3a7 | 2012-05-30 22:55:38 | [diff] [blame] | 8499 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandlePostSubBufferCHROMIUM"); |
[email protected] | a36ed483 | 2014-04-24 16:40:27 | [diff] [blame] | 8500 | { |
| 8501 | TRACE_EVENT_SYNTHETIC_DELAY("gpu.PresentingFrame"); |
| 8502 | } |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 8503 | if (!supports_post_sub_buffer_) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8504 | LOCAL_SET_GL_ERROR( |
| 8505 | GL_INVALID_OPERATION, |
| 8506 | "glPostSubBufferCHROMIUM", "command not supported by surface"); |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 8507 | return error::kNoError; |
| 8508 | } |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 8509 | bool is_tracing; |
| 8510 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 8511 | &is_tracing); |
| 8512 | if (is_tracing) { |
| 8513 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
| 8514 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 8515 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 8516 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 8517 | } |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 8518 | if (surface_->PostSubBuffer(c.x, c.y, c.width, c.height) != |
| 8519 | gfx::SwapResult::SWAP_FAILED) { |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 8520 | return error::kNoError; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 8521 | } else { |
| 8522 | LOG(ERROR) << "Context lost because PostSubBuffer failed."; |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 8523 | return error::kLostContext; |
[email protected] | 7794d51 | 2012-04-17 20:36:49 | [diff] [blame] | 8524 | } |
[email protected] | 1c75a370 | 2011-11-11 14:15:28 | [diff] [blame] | 8525 | } |
| 8526 | |
[email protected] | 957f064 | 2014-04-09 16:50:01 | [diff] [blame] | 8527 | error::Error GLES2DecoderImpl::HandleScheduleOverlayPlaneCHROMIUM( |
| 8528 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8529 | const void* cmd_data) { |
| 8530 | const gles2::cmds::ScheduleOverlayPlaneCHROMIUM& c = |
| 8531 | *static_cast<const gles2::cmds::ScheduleOverlayPlaneCHROMIUM*>(cmd_data); |
[email protected] | d286ebbc | 2014-07-03 17:19:10 | [diff] [blame] | 8532 | TextureRef* ref = texture_manager()->GetTexture(c.overlay_texture_id); |
| 8533 | if (!ref) { |
| 8534 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 8535 | "glScheduleOverlayPlaneCHROMIUM", |
| 8536 | "unknown texture"); |
| 8537 | return error::kNoError; |
| 8538 | } |
| 8539 | gfx::GLImage* image = |
| 8540 | ref->texture()->GetLevelImage(ref->texture()->target(), 0); |
| 8541 | if (!image) { |
| 8542 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 8543 | "glScheduleOverlayPlaneCHROMIUM", |
| 8544 | "unsupported texture format"); |
| 8545 | return error::kNoError; |
| 8546 | } |
| 8547 | gfx::OverlayTransform transform = GetGFXOverlayTransform(c.plane_transform); |
| 8548 | if (transform == gfx::OVERLAY_TRANSFORM_INVALID) { |
| 8549 | LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, |
| 8550 | "glScheduleOverlayPlaneCHROMIUM", |
| 8551 | "invalid transform enum"); |
| 8552 | return error::kNoError; |
| 8553 | } |
| 8554 | if (!surface_->ScheduleOverlayPlane( |
| 8555 | c.plane_z_order, |
| 8556 | transform, |
| 8557 | image, |
| 8558 | gfx::Rect(c.bounds_x, c.bounds_y, c.bounds_width, c.bounds_height), |
| 8559 | gfx::RectF(c.uv_x, c.uv_y, c.uv_width, c.uv_height))) { |
| 8560 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 8561 | "glScheduleOverlayPlaneCHROMIUM", |
| 8562 | "failed to schedule overlay"); |
| 8563 | } |
[email protected] | 957f064 | 2014-04-09 16:50:01 | [diff] [blame] | 8564 | return error::kNoError; |
| 8565 | } |
| 8566 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8567 | error::Error GLES2DecoderImpl::GetAttribLocationHelper( |
| 8568 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 8569 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 8570 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8571 | LOCAL_SET_GL_ERROR( |
| 8572 | GL_INVALID_VALUE, "glGetAttribLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 8573 | return error::kNoError; |
| 8574 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8575 | Program* program = GetProgramInfoNotShader( |
[email protected] | 6b8cf1a | 2010-05-06 16:13:58 | [diff] [blame] | 8576 | client_id, "glGetAttribLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8577 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8578 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8579 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8580 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8581 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8582 | GL_INVALID_OPERATION, "glGetAttribLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8583 | return error::kNoError; |
| 8584 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8585 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8586 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 8587 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8588 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8589 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8590 | // Require the client to init this incase the context is lost and we are no |
| 8591 | // longer executing commands. |
| 8592 | if (*location != -1) { |
| 8593 | return error::kGenericError; |
| 8594 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8595 | *location = program->GetAttribLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8596 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8597 | } |
| 8598 | |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8599 | error::Error GLES2DecoderImpl::HandleGetAttribLocation( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8600 | uint32 immediate_data_size, |
| 8601 | const void* cmd_data) { |
| 8602 | const gles2::cmds::GetAttribLocation& c = |
| 8603 | *static_cast<const gles2::cmds::GetAttribLocation*>(cmd_data); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8604 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 8605 | if (!bucket) { |
| 8606 | return error::kInvalidArguments; |
| 8607 | } |
| 8608 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8609 | if (!bucket->GetAsString(&name_str)) { |
| 8610 | return error::kInvalidArguments; |
| 8611 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8612 | return GetAttribLocationHelper( |
| 8613 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 8614 | } |
| 8615 | |
| 8616 | error::Error GLES2DecoderImpl::GetUniformLocationHelper( |
| 8617 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 8618 | const std::string& name_str) { |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 8619 | if (!StringIsValidForGLES(name_str.c_str())) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8620 | LOCAL_SET_GL_ERROR( |
| 8621 | GL_INVALID_VALUE, "glGetUniformLocation", "Invalid character"); |
[email protected] | 258a3313f | 2011-10-18 20:13:57 | [diff] [blame] | 8622 | return error::kNoError; |
| 8623 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8624 | Program* program = GetProgramInfoNotShader( |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 8625 | client_id, "glGetUniformLocation"); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8626 | if (!program) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8627 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8628 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8629 | if (!program->IsValid()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8630 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 8631 | GL_INVALID_OPERATION, "glGetUniformLocation", "program not linked"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 8632 | return error::kNoError; |
| 8633 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8634 | GLint* location = GetSharedMemoryAs<GLint*>( |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8635 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 8636 | if (!location) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8637 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8638 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8639 | // Require the client to init this incase the context is lost an we are no |
| 8640 | // longer executing commands. |
| 8641 | if (*location != -1) { |
| 8642 | return error::kGenericError; |
| 8643 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 8644 | *location = program->GetUniformFakeLocation(name_str); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8645 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8646 | } |
| 8647 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8648 | error::Error GLES2DecoderImpl::HandleGetUniformLocation( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8649 | uint32 immediate_data_size, |
| 8650 | const void* cmd_data) { |
| 8651 | const gles2::cmds::GetUniformLocation& c = |
| 8652 | *static_cast<const gles2::cmds::GetUniformLocation*>(cmd_data); |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8653 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 8654 | if (!bucket) { |
| 8655 | return error::kInvalidArguments; |
| 8656 | } |
| 8657 | std::string name_str; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 8658 | if (!bucket->GetAsString(&name_str)) { |
| 8659 | return error::kInvalidArguments; |
| 8660 | } |
[email protected] | 558847a | 2010-03-24 07:02:54 | [diff] [blame] | 8661 | return GetUniformLocationHelper( |
| 8662 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8663 | } |
| 8664 | |
zmo | 155435a4 | 2015-02-13 05:06:53 | [diff] [blame] | 8665 | error::Error GLES2DecoderImpl::HandleGetUniformIndices( |
| 8666 | uint32 immediate_data_size, |
| 8667 | const void* cmd_data) { |
| 8668 | if (!unsafe_es3_apis_enabled()) |
| 8669 | return error::kUnknownCommand; |
| 8670 | const gles2::cmds::GetUniformIndices& c = |
| 8671 | *static_cast<const gles2::cmds::GetUniformIndices*>(cmd_data); |
| 8672 | Bucket* bucket = GetBucket(c.names_bucket_id); |
| 8673 | if (!bucket) { |
| 8674 | return error::kInvalidArguments; |
| 8675 | } |
| 8676 | GLsizei count = 0; |
| 8677 | std::vector<char*> names; |
| 8678 | std::vector<GLint> len; |
| 8679 | if (!bucket->GetAsStrings(&count, &names, &len) || count <= 0) { |
| 8680 | return error::kInvalidArguments; |
| 8681 | } |
| 8682 | typedef cmds::GetUniformIndices::Result Result; |
| 8683 | Result* result = GetSharedMemoryAs<Result*>( |
| 8684 | c.indices_shm_id, c.indices_shm_offset, |
| 8685 | Result::ComputeSize(static_cast<size_t>(count))); |
| 8686 | GLuint* indices = result ? result->GetData() : NULL; |
| 8687 | if (indices == NULL) { |
| 8688 | return error::kOutOfBounds; |
| 8689 | } |
| 8690 | // Check that the client initialized the result. |
| 8691 | if (result->size != 0) { |
| 8692 | return error::kInvalidArguments; |
| 8693 | } |
| 8694 | Program* program = GetProgramInfoNotShader(c.program, "glGetUniformIndices"); |
| 8695 | if (!program) { |
| 8696 | return error::kNoError; |
| 8697 | } |
| 8698 | GLuint service_id = program->service_id(); |
| 8699 | GLint link_status = GL_FALSE; |
| 8700 | glGetProgramiv(service_id, GL_LINK_STATUS, &link_status); |
| 8701 | if (link_status != GL_TRUE) { |
| 8702 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 8703 | "glGetUniformIndices", "program not linked"); |
| 8704 | return error::kNoError; |
| 8705 | } |
| 8706 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("GetUniformIndices"); |
| 8707 | glGetUniformIndices(service_id, count, &names[0], indices); |
| 8708 | GLenum error = glGetError(); |
| 8709 | if (error == GL_NO_ERROR) { |
| 8710 | result->SetNumResults(count); |
| 8711 | } else { |
| 8712 | LOCAL_SET_GL_ERROR(error, "GetUniformIndices", ""); |
| 8713 | } |
| 8714 | return error::kNoError; |
| 8715 | } |
| 8716 | |
zmo | 5393fb5 | 2015-01-27 01:50:48 | [diff] [blame] | 8717 | error::Error GLES2DecoderImpl::GetFragDataLocationHelper( |
| 8718 | GLuint client_id, uint32 location_shm_id, uint32 location_shm_offset, |
| 8719 | const std::string& name_str) { |
| 8720 | GLint* location = GetSharedMemoryAs<GLint*>( |
| 8721 | location_shm_id, location_shm_offset, sizeof(GLint)); |
| 8722 | if (!location) { |
| 8723 | return error::kOutOfBounds; |
| 8724 | } |
| 8725 | // Require the client to init this incase the context is lost and we are no |
| 8726 | // longer executing commands. |
| 8727 | if (*location != -1) { |
| 8728 | return error::kGenericError; |
| 8729 | } |
| 8730 | Program* program = GetProgramInfoNotShader( |
| 8731 | client_id, "glGetFragDataLocation"); |
| 8732 | if (!program) { |
| 8733 | return error::kNoError; |
| 8734 | } |
| 8735 | *location = glGetFragDataLocation(program->service_id(), name_str.c_str()); |
| 8736 | return error::kNoError; |
| 8737 | } |
| 8738 | |
| 8739 | error::Error GLES2DecoderImpl::HandleGetFragDataLocation( |
| 8740 | uint32 immediate_data_size, |
| 8741 | const void* cmd_data) { |
| 8742 | if (!unsafe_es3_apis_enabled()) |
| 8743 | return error::kUnknownCommand; |
| 8744 | const gles2::cmds::GetFragDataLocation& c = |
| 8745 | *static_cast<const gles2::cmds::GetFragDataLocation*>(cmd_data); |
| 8746 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 8747 | if (!bucket) { |
| 8748 | return error::kInvalidArguments; |
| 8749 | } |
| 8750 | std::string name_str; |
| 8751 | if (!bucket->GetAsString(&name_str)) { |
| 8752 | return error::kInvalidArguments; |
| 8753 | } |
| 8754 | return GetFragDataLocationHelper( |
| 8755 | c.program, c.location_shm_id, c.location_shm_offset, name_str); |
| 8756 | } |
| 8757 | |
zmo | 4a16ff99 | 2015-02-05 22:18:41 | [diff] [blame] | 8758 | error::Error GLES2DecoderImpl::HandleGetUniformBlockIndex( |
| 8759 | uint32 immediate_data_size, const void* cmd_data) { |
| 8760 | if (!unsafe_es3_apis_enabled()) |
| 8761 | return error::kUnknownCommand; |
| 8762 | const gles2::cmds::GetUniformBlockIndex& c = |
| 8763 | *static_cast<const gles2::cmds::GetUniformBlockIndex*>(cmd_data); |
| 8764 | Bucket* bucket = GetBucket(c.name_bucket_id); |
| 8765 | if (!bucket) { |
| 8766 | return error::kInvalidArguments; |
| 8767 | } |
| 8768 | std::string name_str; |
| 8769 | if (!bucket->GetAsString(&name_str)) { |
| 8770 | return error::kInvalidArguments; |
| 8771 | } |
| 8772 | GLuint* index = GetSharedMemoryAs<GLuint*>( |
| 8773 | c.index_shm_id, c.index_shm_offset, sizeof(GLuint)); |
| 8774 | if (!index) { |
| 8775 | return error::kOutOfBounds; |
| 8776 | } |
| 8777 | // Require the client to init this in case the context is lost and we are no |
| 8778 | // longer executing commands. |
| 8779 | if (*index != GL_INVALID_INDEX) { |
| 8780 | return error::kGenericError; |
| 8781 | } |
| 8782 | Program* program = GetProgramInfoNotShader( |
| 8783 | c.program, "glGetUniformBlockIndex"); |
| 8784 | if (!program) { |
| 8785 | return error::kNoError; |
| 8786 | } |
| 8787 | *index = glGetUniformBlockIndex(program->service_id(), name_str.c_str()); |
| 8788 | return error::kNoError; |
| 8789 | } |
| 8790 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8791 | error::Error GLES2DecoderImpl::HandleGetString(uint32 immediate_data_size, |
| 8792 | const void* cmd_data) { |
| 8793 | const gles2::cmds::GetString& c = |
| 8794 | *static_cast<const gles2::cmds::GetString*>(cmd_data); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 8795 | GLenum name = static_cast<GLenum>(c.name); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 8796 | if (!validators_->string_type.IsValid(name)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 8797 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glGetString", name, "name"); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 8798 | return error::kNoError; |
| 8799 | } |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 8800 | |
| 8801 | const char* str = nullptr; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8802 | std::string extensions; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8803 | switch (name) { |
| 8804 | case GL_VERSION: |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 8805 | if (unsafe_es3_apis_enabled()) |
| 8806 | str = "OpenGL ES 3.0 Chromium"; |
| 8807 | else |
| 8808 | str = "OpenGL ES 2.0 Chromium"; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8809 | break; |
| 8810 | case GL_SHADING_LANGUAGE_VERSION: |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 8811 | if (unsafe_es3_apis_enabled()) |
| 8812 | str = "OpenGL ES GLSL ES 3.0 Chromium"; |
| 8813 | else |
| 8814 | str = "OpenGL ES GLSL ES 1.0 Chromium"; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8815 | break; |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 8816 | case GL_RENDERER: |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 8817 | case GL_VENDOR: |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 8818 | // Return the unmasked VENDOR/RENDERER string for WebGL contexts. |
| 8819 | // They are used by WEBGL_debug_renderer_info. |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 8820 | if (!IsWebGLContext()) |
[email protected] | 959e907 | 2013-09-20 16:58:38 | [diff] [blame] | 8821 | str = "Chromium"; |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 8822 | else |
| 8823 | str = reinterpret_cast<const char*>(glGetString(name)); |
[email protected] | 3293960 | 2012-05-09 06:25:16 | [diff] [blame] | 8824 | break; |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8825 | case GL_EXTENSIONS: |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8826 | { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8827 | // For WebGL contexts, strip out the OES derivatives and |
| 8828 | // EXT frag depth extensions if they have not been enabled. |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 8829 | if (IsWebGLContext()) { |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8830 | extensions = feature_info_->extensions(); |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8831 | if (!derivatives_explicitly_enabled_) { |
| 8832 | size_t offset = extensions.find(kOESDerivativeExtension); |
| 8833 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 8834 | extensions.replace(offset, arraysize(kOESDerivativeExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8835 | std::string()); |
| 8836 | } |
| 8837 | } |
| 8838 | if (!frag_depth_explicitly_enabled_) { |
| 8839 | size_t offset = extensions.find(kEXTFragDepthExtension); |
| 8840 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 8841 | extensions.replace(offset, arraysize(kEXTFragDepthExtension), |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 8842 | std::string()); |
| 8843 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8844 | } |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 8845 | if (!draw_buffers_explicitly_enabled_) { |
| 8846 | size_t offset = extensions.find(kEXTDrawBuffersExtension); |
| 8847 | if (std::string::npos != offset) { |
[email protected] | f16cc9f | 2013-06-14 01:04:09 | [diff] [blame] | 8848 | extensions.replace(offset, arraysize(kEXTDrawBuffersExtension), |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 8849 | std::string()); |
| 8850 | } |
| 8851 | } |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 8852 | if (!shader_texture_lod_explicitly_enabled_) { |
| 8853 | size_t offset = extensions.find(kEXTShaderTextureLodExtension); |
| 8854 | if (std::string::npos != offset) { |
| 8855 | extensions.replace(offset, |
| 8856 | arraysize(kEXTShaderTextureLodExtension), |
| 8857 | std::string()); |
| 8858 | } |
| 8859 | } |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8860 | } else { |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 8861 | extensions = feature_info_->extensions().c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8862 | } |
[email protected] | b381ee3 | 2014-03-22 02:43:43 | [diff] [blame] | 8863 | if (supports_post_sub_buffer_) |
| 8864 | extensions += " GL_CHROMIUM_post_sub_buffer"; |
[email protected] | 6f5fac9d1 | 2012-06-26 21:02:45 | [diff] [blame] | 8865 | str = extensions.c_str(); |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 8866 | } |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8867 | break; |
| 8868 | default: |
kbr | c9f0e10c | 2015-03-31 19:49:12 | [diff] [blame] | 8869 | str = reinterpret_cast<const char*>(glGetString(name)); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8870 | break; |
| 8871 | } |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 8872 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | 1958e0e | 2010-04-22 05:17:15 | [diff] [blame] | 8873 | bucket->SetFromString(str); |
[email protected] | ddd968b8 | 2010-03-02 00:44:29 | [diff] [blame] | 8874 | return error::kNoError; |
| 8875 | } |
| 8876 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 8877 | error::Error GLES2DecoderImpl::HandleBufferData(uint32 immediate_data_size, |
| 8878 | const void* cmd_data) { |
| 8879 | const gles2::cmds::BufferData& c = |
| 8880 | *static_cast<const gles2::cmds::BufferData*>(cmd_data); |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 8881 | GLenum target = static_cast<GLenum>(c.target); |
| 8882 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
| 8883 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 8884 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 8885 | GLenum usage = static_cast<GLenum>(c.usage); |
| 8886 | const void* data = NULL; |
| 8887 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 8888 | data = GetSharedMemoryAs<const void*>(data_shm_id, data_shm_offset, size); |
| 8889 | if (!data) { |
| 8890 | return error::kOutOfBounds; |
| 8891 | } |
| 8892 | } |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 8893 | buffer_manager()->ValidateAndDoBufferData(&state_, target, size, data, usage); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 8894 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8895 | } |
| 8896 | |
[email protected] | 0c86dbf | 2010-03-05 08:14:11 | [diff] [blame] | 8897 | void GLES2DecoderImpl::DoBufferSubData( |
| 8898 | GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid * data) { |
[email protected] | 0fbba373 | 2013-07-17 15:40:13 | [diff] [blame] | 8899 | // Just delegate it. Some validation is actually done before this. |
| 8900 | buffer_manager()->ValidateAndDoBufferSubData( |
| 8901 | &state_, target, offset, size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 8902 | } |
| 8903 | |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 8904 | bool GLES2DecoderImpl::ClearLevel(Texture* texture, |
| 8905 | unsigned target, |
| 8906 | int level, |
| 8907 | unsigned format, |
| 8908 | unsigned type, |
| 8909 | int xoffset, |
| 8910 | int yoffset, |
| 8911 | int width, |
| 8912 | int height) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8913 | uint32 channels = GLES2Util::GetChannelsForFormat(format); |
[email protected] | 345ba90 | 2013-11-14 21:39:00 | [diff] [blame] | 8914 | if (feature_info_->feature_flags().angle_depth_texture && |
| 8915 | (channels & GLES2Util::kDepth) != 0) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8916 | // It's a depth format and ANGLE doesn't allow texImage2D or texSubImage2D |
| 8917 | // on depth formats. |
| 8918 | GLuint fb = 0; |
| 8919 | glGenFramebuffersEXT(1, &fb); |
| 8920 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb); |
| 8921 | |
| 8922 | bool have_stencil = (channels & GLES2Util::kStencil) != 0; |
| 8923 | GLenum attachment = have_stencil ? GL_DEPTH_STENCIL_ATTACHMENT : |
| 8924 | GL_DEPTH_ATTACHMENT; |
| 8925 | |
boliu | 45dc77a | 2015-02-25 23:26:31 | [diff] [blame] | 8926 | glFramebufferTexture2DEXT(GL_DRAW_FRAMEBUFFER_EXT, attachment, target, |
| 8927 | texture->service_id(), level); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8928 | // ANGLE promises a depth only attachment ok. |
| 8929 | if (glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT) != |
| 8930 | GL_FRAMEBUFFER_COMPLETE) { |
| 8931 | return false; |
| 8932 | } |
| 8933 | glClearStencil(0); |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 8934 | state_.SetDeviceStencilMaskSeparate(GL_FRONT, kDefaultStencilMask); |
| 8935 | state_.SetDeviceStencilMaskSeparate(GL_BACK, kDefaultStencilMask); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8936 | glClearDepth(1.0f); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 8937 | state_.SetDeviceDepthMask(GL_TRUE); |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 8938 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, true); |
| 8939 | glScissor(xoffset, yoffset, width, height); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8940 | glClear(GL_DEPTH_BUFFER_BIT | (have_stencil ? GL_STENCIL_BUFFER_BIT : 0)); |
| 8941 | |
| 8942 | RestoreClearState(); |
| 8943 | |
| 8944 | glDeleteFramebuffersEXT(1, &fb); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 8945 | Framebuffer* framebuffer = |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 8946 | GetFramebufferInfoForTarget(GL_DRAW_FRAMEBUFFER_EXT); |
| 8947 | GLuint fb_service_id = |
| 8948 | framebuffer ? framebuffer->service_id() : GetBackbufferServiceId(); |
| 8949 | glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fb_service_id); |
| 8950 | return true; |
| 8951 | } |
| 8952 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8953 | static const uint32 kMaxZeroSize = 1024 * 1024 * 4; |
| 8954 | |
| 8955 | uint32 size; |
| 8956 | uint32 padded_row_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 8957 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8958 | width, height, 1, format, type, state_.unpack_alignment, &size, |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8959 | NULL, &padded_row_size)) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 8960 | return false; |
| 8961 | } |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8962 | |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 8963 | TRACE_EVENT1("gpu", "GLES2DecoderImpl::ClearLevel", "size", size); |
| 8964 | |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8965 | int tile_height; |
| 8966 | |
| 8967 | if (size > kMaxZeroSize) { |
| 8968 | if (kMaxZeroSize < padded_row_size) { |
| 8969 | // That'd be an awfully large texture. |
| 8970 | return false; |
| 8971 | } |
| 8972 | // We should never have a large total size with a zero row size. |
| 8973 | DCHECK_GT(padded_row_size, 0U); |
| 8974 | tile_height = kMaxZeroSize / padded_row_size; |
| 8975 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 8976 | width, tile_height, 1, format, type, state_.unpack_alignment, &size, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 8977 | NULL, NULL)) { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8978 | return false; |
| 8979 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8980 | } else { |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8981 | tile_height = height; |
| 8982 | } |
| 8983 | |
| 8984 | // Assumes the size has already been checked. |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 8985 | scoped_ptr<char[]> zero(new char[size]); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8986 | memset(zero.get(), 0, size); |
boliu | 45dc77a | 2015-02-25 23:26:31 | [diff] [blame] | 8987 | glBindTexture(texture->target(), texture->service_id()); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8988 | |
| 8989 | GLint y = 0; |
| 8990 | while (y < height) { |
| 8991 | GLint h = y + tile_height > height ? height - y : tile_height; |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 8992 | glTexSubImage2D(target, level, xoffset, yoffset + y, width, h, format, type, |
| 8993 | zero.get()); |
[email protected] | 45d15a6 | 2012-04-18 14:33:17 | [diff] [blame] | 8994 | y += tile_height; |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 8995 | } |
boliu | 45dc77a | 2015-02-25 23:26:31 | [diff] [blame] | 8996 | TextureRef* bound_texture = |
| 8997 | texture_manager()->GetTextureInfoForTarget(&state_, texture->target()); |
| 8998 | glBindTexture(texture->target(), |
| 8999 | bound_texture ? bound_texture->service_id() : 0); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 9000 | return true; |
| 9001 | } |
| 9002 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9003 | namespace { |
| 9004 | |
| 9005 | const int kS3TCBlockWidth = 4; |
| 9006 | const int kS3TCBlockHeight = 4; |
| 9007 | const int kS3TCDXT1BlockSize = 8; |
| 9008 | const int kS3TCDXT3AndDXT5BlockSize = 16; |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9009 | const int kEACAndETC2BlockSize = 4; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9010 | |
| 9011 | bool IsValidDXTSize(GLint level, GLsizei size) { |
[email protected] | 10b56de | 2012-07-14 02:09:51 | [diff] [blame] | 9012 | return (size == 1) || |
| 9013 | (size == 2) || !(size % kS3TCBlockWidth); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9014 | } |
| 9015 | |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9016 | bool IsValidPVRTCSize(GLint level, GLsizei size) { |
[email protected] | a07a2360 | 2014-08-05 11:36:12 | [diff] [blame] | 9017 | return GLES2Util::IsPOT(size); |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9018 | } |
| 9019 | |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9020 | } // anonymous namespace. |
| 9021 | |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 9022 | bool GLES2DecoderImpl::GetCompressedTexSizeInBytes( |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9023 | const char* function_name, GLsizei width, GLsizei height, GLsizei depth, |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 9024 | GLenum format, GLsizei* size_in_bytes) { |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9025 | base::CheckedNumeric<GLsizei> bytes_required(0); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9026 | |
| 9027 | switch (format) { |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9028 | case GL_ATC_RGB_AMD: |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9029 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9030 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9031 | case GL_ETC1_RGB8_OES: |
| 9032 | bytes_required = |
| 9033 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 9034 | bytes_required *= |
| 9035 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 9036 | bytes_required *= kS3TCDXT1BlockSize; |
| 9037 | break; |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9038 | case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
| 9039 | case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9040 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9041 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
| 9042 | bytes_required = |
| 9043 | (width + kS3TCBlockWidth - 1) / kS3TCBlockWidth; |
| 9044 | bytes_required *= |
| 9045 | (height + kS3TCBlockHeight - 1) / kS3TCBlockHeight; |
| 9046 | bytes_required *= kS3TCDXT3AndDXT5BlockSize; |
| 9047 | break; |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9048 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9049 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
| 9050 | bytes_required = std::max(width, 8); |
| 9051 | bytes_required *= std::max(height, 8); |
| 9052 | bytes_required *= 4; |
| 9053 | bytes_required += 7; |
| 9054 | bytes_required /= 8; |
| 9055 | break; |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9056 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9057 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: |
| 9058 | bytes_required = std::max(width, 16); |
| 9059 | bytes_required *= std::max(height, 8); |
| 9060 | bytes_required *= 2; |
| 9061 | bytes_required += 7; |
| 9062 | bytes_required /= 8; |
| 9063 | break; |
| 9064 | |
| 9065 | // ES3 formats. |
| 9066 | case GL_COMPRESSED_R11_EAC: |
| 9067 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 9068 | case GL_COMPRESSED_RGB8_ETC2: |
| 9069 | case GL_COMPRESSED_SRGB8_ETC2: |
| 9070 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 9071 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 9072 | bytes_required = |
| 9073 | (width + kEACAndETC2BlockSize - 1) / kEACAndETC2BlockSize; |
| 9074 | bytes_required *= |
| 9075 | (height + kEACAndETC2BlockSize - 1) / kEACAndETC2BlockSize; |
| 9076 | bytes_required *= 8; |
| 9077 | bytes_required *= depth; |
| 9078 | break; |
| 9079 | case GL_COMPRESSED_RG11_EAC: |
| 9080 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 9081 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 9082 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 9083 | bytes_required = |
| 9084 | (width + kEACAndETC2BlockSize - 1) / kEACAndETC2BlockSize; |
| 9085 | bytes_required *= |
| 9086 | (height + kEACAndETC2BlockSize - 1) / kEACAndETC2BlockSize; |
| 9087 | bytes_required *= 16; |
| 9088 | bytes_required *= depth; |
| 9089 | break; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9090 | default: |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9091 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9092 | return false; |
| 9093 | } |
| 9094 | |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 9095 | if (!bytes_required.IsValid()) { |
| 9096 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "invalid size"); |
| 9097 | return false; |
| 9098 | } |
| 9099 | |
| 9100 | *size_in_bytes = bytes_required.ValueOrDefault(0); |
| 9101 | return true; |
| 9102 | } |
| 9103 | |
| 9104 | bool GLES2DecoderImpl::ValidateCompressedTexFuncData( |
| 9105 | const char* function_name, GLsizei width, GLsizei height, GLsizei depth, |
| 9106 | GLenum format, GLsizei size) { |
| 9107 | GLsizei bytes_required = 0; |
| 9108 | if (!GetCompressedTexSizeInBytes( |
| 9109 | function_name, width, height, depth, format, &bytes_required)) { |
| 9110 | return false; |
| 9111 | } |
| 9112 | |
| 9113 | if (size != bytes_required) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9114 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9115 | GL_INVALID_VALUE, function_name, "size is not correct for dimensions"); |
| 9116 | return false; |
| 9117 | } |
| 9118 | |
| 9119 | return true; |
| 9120 | } |
| 9121 | |
| 9122 | bool GLES2DecoderImpl::ValidateCompressedTexDimensions( |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9123 | const char* function_name, GLenum target, GLint level, |
| 9124 | GLsizei width, GLsizei height, GLsizei depth, GLenum format) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9125 | switch (format) { |
| 9126 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 9127 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 9128 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9129 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: |
| 9130 | DCHECK_EQ(1, depth); // 2D formats. |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9131 | if (!IsValidDXTSize(level, width) || !IsValidDXTSize(level, height)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9132 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9133 | GL_INVALID_OPERATION, function_name, |
| 9134 | "width or height invalid for level"); |
| 9135 | return false; |
| 9136 | } |
| 9137 | return true; |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9138 | case GL_ATC_RGB_AMD: |
| 9139 | case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
| 9140 | case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9141 | case GL_ETC1_RGB8_OES: |
| 9142 | DCHECK_EQ(1, depth); // 2D formats. |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 9143 | if (width <= 0 || height <= 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9144 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 9145 | GL_INVALID_OPERATION, function_name, |
| 9146 | "width or height invalid for level"); |
| 9147 | return false; |
| 9148 | } |
| 9149 | return true; |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9150 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 9151 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 9152 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9153 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: |
| 9154 | DCHECK_EQ(1, depth); // 2D formats. |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9155 | if (!IsValidPVRTCSize(level, width) || |
| 9156 | !IsValidPVRTCSize(level, height)) { |
| 9157 | LOCAL_SET_GL_ERROR( |
| 9158 | GL_INVALID_OPERATION, function_name, |
| 9159 | "width or height invalid for level"); |
| 9160 | return false; |
| 9161 | } |
| 9162 | return true; |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9163 | |
| 9164 | // ES3 formats. |
| 9165 | case GL_COMPRESSED_R11_EAC: |
| 9166 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 9167 | case GL_COMPRESSED_RG11_EAC: |
| 9168 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 9169 | case GL_COMPRESSED_RGB8_ETC2: |
| 9170 | case GL_COMPRESSED_SRGB8_ETC2: |
| 9171 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 9172 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 9173 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 9174 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 9175 | if (width <= 0 || height <= 0 || depth <= 0) { |
| 9176 | LOCAL_SET_GL_ERROR( |
| 9177 | GL_INVALID_OPERATION, function_name, |
| 9178 | "width, height, or depth invalid"); |
| 9179 | return false; |
| 9180 | } |
bajones | 69efbed | 2015-05-08 19:40:20 | [diff] [blame] | 9181 | if (target == GL_TEXTURE_3D) { |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9182 | LOCAL_SET_GL_ERROR( |
| 9183 | GL_INVALID_OPERATION, function_name, |
| 9184 | "target invalid for format"); |
| 9185 | return false; |
| 9186 | } |
| 9187 | return true; |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9188 | default: |
| 9189 | return false; |
| 9190 | } |
| 9191 | } |
| 9192 | |
| 9193 | bool GLES2DecoderImpl::ValidateCompressedTexSubDimensions( |
| 9194 | const char* function_name, |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9195 | GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, |
| 9196 | GLsizei width, GLsizei height, GLsizei depth, GLenum format, |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 9197 | Texture* texture) { |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9198 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9199 | LOCAL_SET_GL_ERROR( |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9200 | GL_INVALID_VALUE, function_name, "x/y/z offset < 0"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9201 | return false; |
| 9202 | } |
| 9203 | |
| 9204 | switch (format) { |
| 9205 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 9206 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 9207 | case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: |
| 9208 | case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: { |
| 9209 | const int kBlockWidth = 4; |
| 9210 | const int kBlockHeight = 4; |
| 9211 | if ((xoffset % kBlockWidth) || (yoffset % kBlockHeight)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9212 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9213 | GL_INVALID_OPERATION, function_name, |
| 9214 | "xoffset or yoffset not multiple of 4"); |
| 9215 | return false; |
| 9216 | } |
| 9217 | GLsizei tex_width = 0; |
| 9218 | GLsizei tex_height = 0; |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9219 | if (!texture->GetLevelSize(target, level, |
| 9220 | &tex_width, &tex_height, nullptr) || |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9221 | width - xoffset > tex_width || |
| 9222 | height - yoffset > tex_height) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9223 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9224 | GL_INVALID_OPERATION, function_name, "dimensions out of range"); |
| 9225 | return false; |
| 9226 | } |
| 9227 | return ValidateCompressedTexDimensions( |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9228 | function_name, target, level, width, height, 1, format); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9229 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9230 | case GL_ATC_RGB_AMD: |
| 9231 | case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD: |
| 9232 | case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD: { |
| 9233 | LOCAL_SET_GL_ERROR( |
| 9234 | GL_INVALID_OPERATION, function_name, |
| 9235 | "not supported for ATC textures"); |
| 9236 | return false; |
| 9237 | } |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 9238 | case GL_ETC1_RGB8_OES: { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9239 | LOCAL_SET_GL_ERROR( |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 9240 | GL_INVALID_OPERATION, function_name, |
[email protected] | caa13ed | 2014-02-17 11:29:20 | [diff] [blame] | 9241 | "not supported for ECT1_RGB8_OES textures"); |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 9242 | return false; |
| 9243 | } |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9244 | case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG: |
| 9245 | case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG: |
| 9246 | case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: |
| 9247 | case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: { |
| 9248 | if ((xoffset != 0) || (yoffset != 0)) { |
| 9249 | LOCAL_SET_GL_ERROR( |
| 9250 | GL_INVALID_OPERATION, function_name, |
| 9251 | "xoffset and yoffset must be zero"); |
| 9252 | return false; |
| 9253 | } |
| 9254 | GLsizei tex_width = 0; |
| 9255 | GLsizei tex_height = 0; |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9256 | if (!texture->GetLevelSize(target, level, |
| 9257 | &tex_width, &tex_height, nullptr) || |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9258 | width != tex_width || |
| 9259 | height != tex_height) { |
| 9260 | LOCAL_SET_GL_ERROR( |
| 9261 | GL_INVALID_OPERATION, function_name, |
| 9262 | "dimensions must match existing texture level dimensions"); |
| 9263 | return false; |
| 9264 | } |
| 9265 | return ValidateCompressedTexDimensions( |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9266 | function_name, target, level, width, height, 1, format); |
[email protected] | 8aec81ec | 2014-04-29 01:04:51 | [diff] [blame] | 9267 | } |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9268 | |
| 9269 | // ES3 formats |
| 9270 | case GL_COMPRESSED_R11_EAC: |
| 9271 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 9272 | case GL_COMPRESSED_RG11_EAC: |
| 9273 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 9274 | case GL_COMPRESSED_RGB8_ETC2: |
| 9275 | case GL_COMPRESSED_SRGB8_ETC2: |
| 9276 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 9277 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 9278 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 9279 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 9280 | { |
| 9281 | const int kBlockSize = 4; |
| 9282 | GLsizei tex_width, tex_height; |
bajones | 69efbed | 2015-05-08 19:40:20 | [diff] [blame] | 9283 | if (target == GL_TEXTURE_3D || |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9284 | !texture->GetLevelSize(target, level, |
| 9285 | &tex_width, &tex_height, nullptr) || |
| 9286 | (xoffset % kBlockSize) || (yoffset % kBlockSize) || |
| 9287 | ((width % kBlockSize) && xoffset + width != tex_width) || |
| 9288 | ((height % kBlockSize) && yoffset + height != tex_height)) { |
| 9289 | LOCAL_SET_GL_ERROR( |
| 9290 | GL_INVALID_OPERATION, function_name, |
| 9291 | "dimensions must match existing texture level dimensions"); |
| 9292 | return false; |
| 9293 | } |
| 9294 | return true; |
| 9295 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9296 | default: |
| 9297 | return false; |
| 9298 | } |
| 9299 | } |
| 9300 | |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 9301 | error::Error GLES2DecoderImpl::DoCompressedTexImage2D( |
| 9302 | GLenum target, |
| 9303 | GLint level, |
| 9304 | GLenum internal_format, |
| 9305 | GLsizei width, |
| 9306 | GLsizei height, |
| 9307 | GLint border, |
| 9308 | GLsizei image_size, |
| 9309 | const void* data) { |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9310 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9311 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 9312 | "glCompressedTexImage2D", target, "target"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 9313 | return error::kNoError; |
| 9314 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9315 | if (!validators_->compressed_texture_format.IsValid( |
| 9316 | internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9317 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 9318 | "glCompressedTexImage2D", internal_format, "internal_format"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 9319 | return error::kNoError; |
| 9320 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 9321 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 9322 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9323 | LOCAL_SET_GL_ERROR( |
| 9324 | GL_INVALID_VALUE, |
| 9325 | "glCompressedTexImage2D", "dimensions out of range"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 9326 | return error::kNoError; |
| 9327 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9328 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9329 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9330 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9331 | LOCAL_SET_GL_ERROR( |
| 9332 | GL_INVALID_VALUE, |
| 9333 | "glCompressedTexImage2D", "unknown texture target"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 9334 | return error::kNoError; |
| 9335 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9336 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9337 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9338 | LOCAL_SET_GL_ERROR( |
| 9339 | GL_INVALID_OPERATION, |
| 9340 | "glCompressedTexImage2D", "texture is immutable"); |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9341 | return error::kNoError; |
| 9342 | } |
| 9343 | |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9344 | if (!ValidateCompressedTexDimensions("glCompressedTexImage2D", target, level, |
| 9345 | width, height, 1, internal_format) || |
| 9346 | !ValidateCompressedTexFuncData("glCompressedTexImage2D", width, height, |
| 9347 | 1, internal_format, image_size)) { |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9348 | return error::kNoError; |
| 9349 | } |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 9350 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9351 | if (!EnsureGPUMemoryAvailable(image_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9352 | LOCAL_SET_GL_ERROR( |
| 9353 | GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9354 | return error::kNoError; |
| 9355 | } |
| 9356 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9357 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9358 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 968351b | 2011-12-20 08:26:51 | [diff] [blame] | 9359 | } |
| 9360 | |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 9361 | scoped_ptr<int8[]> zero; |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 9362 | if (!data) { |
| 9363 | zero.reset(new int8[image_size]); |
| 9364 | memset(zero.get(), 0, image_size); |
| 9365 | data = zero.get(); |
| 9366 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9367 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D"); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 9368 | glCompressedTexImage2D( |
| 9369 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9370 | GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9371 | if (error == GL_NO_ERROR) { |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 9372 | texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format, |
| 9373 | width, height, 1, border, 0, 0, |
| 9374 | gfx::Rect(width, height)); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9375 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 9376 | |
| 9377 | // This may be a slow command. Exit command processing to allow for |
| 9378 | // context preemption and GPU watchdog checks. |
| 9379 | ExitCommandProcessingEarly(); |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 9380 | return error::kNoError; |
| 9381 | } |
| 9382 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9383 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9384 | uint32 immediate_data_size, |
| 9385 | const void* cmd_data) { |
| 9386 | const gles2::cmds::CompressedTexImage2D& c = |
| 9387 | *static_cast<const gles2::cmds::CompressedTexImage2D*>(cmd_data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 9388 | GLenum target = static_cast<GLenum>(c.target); |
| 9389 | GLint level = static_cast<GLint>(c.level); |
| 9390 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 9391 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9392 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9393 | GLint border = static_cast<GLint>(c.border); |
| 9394 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
| 9395 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 9396 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 9397 | const void* data = NULL; |
| 9398 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 9399 | data = GetSharedMemoryAs<const void*>( |
| 9400 | data_shm_id, data_shm_offset, image_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 9401 | if (!data) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9402 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 9403 | } |
| 9404 | } |
[email protected] | a93bb84 | 2010-02-16 23:03:47 | [diff] [blame] | 9405 | return DoCompressedTexImage2D( |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 9406 | target, level, internal_format, width, height, border, image_size, data); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 9407 | } |
| 9408 | |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9409 | error::Error GLES2DecoderImpl::HandleCompressedTexImage2DBucket( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9410 | uint32 immediate_data_size, |
| 9411 | const void* cmd_data) { |
| 9412 | const gles2::cmds::CompressedTexImage2DBucket& c = |
| 9413 | *static_cast<const gles2::cmds::CompressedTexImage2DBucket*>(cmd_data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9414 | GLenum target = static_cast<GLenum>(c.target); |
| 9415 | GLint level = static_cast<GLint>(c.level); |
| 9416 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 9417 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9418 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9419 | GLint border = static_cast<GLint>(c.border); |
| 9420 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9421 | if (!bucket) { |
| 9422 | return error::kInvalidArguments; |
| 9423 | } |
| 9424 | uint32 data_size = bucket->size(); |
| 9425 | GLsizei imageSize = data_size; |
| 9426 | const void* data = bucket->GetData(0, data_size); |
| 9427 | if (!data) { |
| 9428 | return error::kInvalidArguments; |
| 9429 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9430 | return DoCompressedTexImage2D( |
| 9431 | target, level, internal_format, width, height, border, |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9432 | imageSize, data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9433 | } |
| 9434 | |
| 9435 | error::Error GLES2DecoderImpl::HandleCompressedTexSubImage2DBucket( |
| 9436 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9437 | const void* cmd_data) { |
| 9438 | const gles2::cmds::CompressedTexSubImage2DBucket& c = |
| 9439 | *static_cast<const gles2::cmds::CompressedTexSubImage2DBucket*>(cmd_data); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9440 | GLenum target = static_cast<GLenum>(c.target); |
| 9441 | GLint level = static_cast<GLint>(c.level); |
| 9442 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 9443 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 9444 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9445 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9446 | GLenum format = static_cast<GLenum>(c.format); |
| 9447 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9448 | if (!bucket) { |
| 9449 | return error::kInvalidArguments; |
| 9450 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9451 | uint32 data_size = bucket->size(); |
| 9452 | GLsizei imageSize = data_size; |
| 9453 | const void* data = bucket->GetData(0, data_size); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 9454 | if (!data) { |
| 9455 | return error::kInvalidArguments; |
| 9456 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9457 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9458 | LOCAL_SET_GL_ERROR( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 9459 | GL_INVALID_ENUM, "glCompressedTexSubImage2D", "target"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9460 | return error::kNoError; |
| 9461 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9462 | if (!validators_->compressed_texture_format.IsValid(format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9463 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 9464 | "glCompressedTexSubImage2D", format, "format"); |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 9465 | return error::kNoError; |
| 9466 | } |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9467 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9468 | LOCAL_SET_GL_ERROR( |
| 9469 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "width < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9470 | return error::kNoError; |
| 9471 | } |
| 9472 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9473 | LOCAL_SET_GL_ERROR( |
| 9474 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "height < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9475 | return error::kNoError; |
| 9476 | } |
| 9477 | if (imageSize < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9478 | LOCAL_SET_GL_ERROR( |
| 9479 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "imageSize < 0"); |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9480 | return error::kNoError; |
| 9481 | } |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9482 | DoCompressedTexSubImage2D( |
[email protected] | b6140d0 | 2010-05-17 14:47:16 | [diff] [blame] | 9483 | target, level, xoffset, yoffset, width, height, format, imageSize, data); |
| 9484 | return error::kNoError; |
| 9485 | } |
| 9486 | |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9487 | error::Error GLES2DecoderImpl::DoCompressedTexImage3D( |
| 9488 | GLenum target, |
| 9489 | GLint level, |
| 9490 | GLenum internal_format, |
| 9491 | GLsizei width, |
| 9492 | GLsizei height, |
| 9493 | GLsizei depth, |
| 9494 | GLint border, |
| 9495 | GLsizei image_size, |
| 9496 | const void* data) { |
| 9497 | if (!validators_->texture_3_d_target.IsValid(target)) { |
| 9498 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 9499 | "glCompressedTexImage3D", target, "target"); |
| 9500 | return error::kNoError; |
| 9501 | } |
| 9502 | if (!validators_->compressed_texture_format.IsValid( |
| 9503 | internal_format)) { |
| 9504 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 9505 | "glCompressedTexImage3D", internal_format, "internal_format"); |
| 9506 | return error::kNoError; |
| 9507 | } |
| 9508 | if (!texture_manager()->ValidForTarget(target, level, width, height, depth) || |
| 9509 | border != 0) { |
| 9510 | LOCAL_SET_GL_ERROR( |
| 9511 | GL_INVALID_VALUE, |
| 9512 | "glCompressedTexImage3D", "dimensions out of range"); |
| 9513 | return error::kNoError; |
| 9514 | } |
| 9515 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9516 | &state_, target); |
| 9517 | if (!texture_ref) { |
| 9518 | LOCAL_SET_GL_ERROR( |
| 9519 | GL_INVALID_VALUE, |
| 9520 | "glCompressedTexImage3D", "unknown texture target"); |
| 9521 | return error::kNoError; |
| 9522 | } |
| 9523 | Texture* texture = texture_ref->texture(); |
| 9524 | if (texture->IsImmutable()) { |
| 9525 | LOCAL_SET_GL_ERROR( |
| 9526 | GL_INVALID_OPERATION, |
| 9527 | "glCompressedTexImage3D", "texture is immutable"); |
| 9528 | return error::kNoError; |
| 9529 | } |
| 9530 | |
| 9531 | if (!ValidateCompressedTexDimensions("glCompressedTexImage3D", target, level, |
| 9532 | width, height, depth, internal_format) || |
| 9533 | !ValidateCompressedTexFuncData("glCompressedTexImage3D", width, height, |
| 9534 | depth, internal_format, image_size)) { |
| 9535 | return error::kNoError; |
| 9536 | } |
| 9537 | |
| 9538 | if (!EnsureGPUMemoryAvailable(image_size)) { |
| 9539 | LOCAL_SET_GL_ERROR( |
| 9540 | GL_OUT_OF_MEMORY, "glCompressedTexImage3D", "out of memory"); |
| 9541 | return error::kNoError; |
| 9542 | } |
| 9543 | |
| 9544 | if (texture->IsAttachedToFramebuffer()) { |
| 9545 | framebuffer_state_.clear_state_dirty = true; |
| 9546 | } |
| 9547 | |
| 9548 | scoped_ptr<int8[]> zero; |
| 9549 | if (!data) { |
| 9550 | zero.reset(new int8[image_size]); |
| 9551 | memset(zero.get(), 0, image_size); |
| 9552 | data = zero.get(); |
| 9553 | } |
| 9554 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage3D"); |
| 9555 | glCompressedTexImage3D(target, level, internal_format, width, height, depth, |
| 9556 | border, image_size, data); |
| 9557 | GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage3D"); |
| 9558 | if (error == GL_NO_ERROR) { |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 9559 | texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format, |
| 9560 | width, height, depth, border, 0, 0, |
| 9561 | gfx::Rect(width, height)); |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9562 | } |
| 9563 | |
| 9564 | // This may be a slow command. Exit command processing to allow for |
| 9565 | // context preemption and GPU watchdog checks. |
| 9566 | ExitCommandProcessingEarly(); |
| 9567 | return error::kNoError; |
| 9568 | } |
| 9569 | |
| 9570 | error::Error GLES2DecoderImpl::HandleCompressedTexImage3D( |
| 9571 | uint32 immediate_data_size, const void* cmd_data) { |
| 9572 | if (!unsafe_es3_apis_enabled()) |
| 9573 | return error::kUnknownCommand; |
| 9574 | |
| 9575 | const gles2::cmds::CompressedTexImage3D& c = |
| 9576 | *static_cast<const gles2::cmds::CompressedTexImage3D*>(cmd_data); |
| 9577 | GLenum target = static_cast<GLenum>(c.target); |
| 9578 | GLint level = static_cast<GLint>(c.level); |
| 9579 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 9580 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9581 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9582 | GLsizei depth = static_cast<GLsizei>(c.depth); |
| 9583 | GLint border = static_cast<GLint>(c.border); |
| 9584 | GLsizei image_size = static_cast<GLsizei>(c.imageSize); |
| 9585 | uint32 data_shm_id = static_cast<uint32>(c.data_shm_id); |
| 9586 | uint32 data_shm_offset = static_cast<uint32>(c.data_shm_offset); |
| 9587 | const void* data = NULL; |
| 9588 | if (data_shm_id != 0 || data_shm_offset != 0) { |
| 9589 | data = GetSharedMemoryAs<const void*>( |
| 9590 | data_shm_id, data_shm_offset, image_size); |
| 9591 | if (!data) { |
| 9592 | return error::kOutOfBounds; |
| 9593 | } |
| 9594 | } |
| 9595 | return DoCompressedTexImage3D(target, level, internal_format, width, height, |
| 9596 | depth, border, image_size, data); |
| 9597 | } |
| 9598 | |
| 9599 | error::Error GLES2DecoderImpl::HandleCompressedTexImage3DBucket( |
| 9600 | uint32 immediate_data_size, const void* cmd_data) { |
| 9601 | if (!unsafe_es3_apis_enabled()) |
| 9602 | return error::kUnknownCommand; |
| 9603 | |
| 9604 | const gles2::cmds::CompressedTexImage3DBucket& c = |
| 9605 | *static_cast<const gles2::cmds::CompressedTexImage3DBucket*>(cmd_data); |
| 9606 | GLenum target = static_cast<GLenum>(c.target); |
| 9607 | GLint level = static_cast<GLint>(c.level); |
| 9608 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 9609 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9610 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9611 | GLsizei depth = static_cast<GLsizei>(c.depth); |
| 9612 | GLint border = static_cast<GLint>(c.border); |
| 9613 | Bucket* bucket = GetBucket(c.bucket_id); |
| 9614 | if (!bucket) { |
| 9615 | return error::kInvalidArguments; |
| 9616 | } |
| 9617 | uint32 data_size = bucket->size(); |
| 9618 | GLsizei imageSize = data_size; |
| 9619 | const void* data = bucket->GetData(0, data_size); |
| 9620 | if (!data) { |
| 9621 | return error::kInvalidArguments; |
| 9622 | } |
| 9623 | return DoCompressedTexImage3D(target, level, internal_format, width, height, |
| 9624 | depth, border, imageSize, data); |
| 9625 | } |
| 9626 | |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9627 | void GLES2DecoderImpl::DoCompressedTexSubImage3D( |
| 9628 | GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset, |
| 9629 | GLsizei width, GLsizei height, GLsizei depth, GLenum format, |
| 9630 | GLsizei image_size, const void* data) { |
| 9631 | if (!validators_->texture_3_d_target.IsValid(target)) { |
| 9632 | LOCAL_SET_GL_ERROR( |
| 9633 | GL_INVALID_ENUM, "glCompressedTexSubImage3D", "target"); |
| 9634 | return; |
| 9635 | } |
| 9636 | if (!validators_->compressed_texture_format.IsValid(format)) { |
| 9637 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 9638 | "glCompressedTexSubImage3D", format, "format"); |
| 9639 | return; |
| 9640 | } |
| 9641 | if (width < 0 || height < 0 || depth < 0) { |
| 9642 | LOCAL_SET_GL_ERROR( |
| 9643 | GL_INVALID_VALUE, "glCompressedTexSubImage3D", "size < 0"); |
| 9644 | return; |
| 9645 | } |
| 9646 | if (image_size < 0) { |
| 9647 | LOCAL_SET_GL_ERROR( |
| 9648 | GL_INVALID_VALUE, "glCompressedTexSubImage3D", "imageSize < 0"); |
| 9649 | return; |
| 9650 | } |
| 9651 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9652 | &state_, target); |
| 9653 | if (!texture_ref) { |
| 9654 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCompressedTexSubImage3D", |
| 9655 | "unknown texture for target"); |
| 9656 | return; |
| 9657 | } |
| 9658 | Texture* texture = texture_ref->texture(); |
| 9659 | GLenum type = 0, internal_format = 0; |
| 9660 | if (!texture->GetLevelType(target, level, &type, &internal_format)) { |
| 9661 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCompressedTexSubImage3D", |
| 9662 | "level does not exist"); |
| 9663 | return; |
| 9664 | } |
| 9665 | if (internal_format != format) { |
| 9666 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCompressedTexSubImage3D", |
| 9667 | "format does not match internal format"); |
| 9668 | return; |
| 9669 | } |
| 9670 | if (!texture->ValidForTexture(target, level, xoffset, yoffset, zoffset, |
| 9671 | width, height, depth, type)) { |
| 9672 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCompressedTexSubImage3D", |
| 9673 | "bad dimensions"); |
| 9674 | return; |
| 9675 | } |
| 9676 | if (!ValidateCompressedTexFuncData("glCompressedTexSubImage3D", |
| 9677 | width, height, depth, format, |
| 9678 | image_size) || |
| 9679 | !ValidateCompressedTexSubDimensions("glCompressedTexSubImage3D", |
| 9680 | target, level, xoffset, yoffset, |
| 9681 | zoffset, width, height, depth, |
| 9682 | format, texture)) { |
| 9683 | return; |
| 9684 | } |
| 9685 | |
| 9686 | // Note: There is no need to deal with texture cleared tracking here |
| 9687 | // because the validation above means you can only get here if the level |
| 9688 | // is already a matching compressed format and in that case |
| 9689 | // CompressedTexImage3D already cleared the texture. |
| 9690 | glCompressedTexSubImage3D( |
| 9691 | target, level, xoffset, yoffset, zoffset, width, height, depth, format, |
| 9692 | image_size, data); |
| 9693 | |
| 9694 | // This may be a slow command. Exit command processing to allow for |
| 9695 | // context preemption and GPU watchdog checks. |
| 9696 | ExitCommandProcessingEarly(); |
| 9697 | } |
| 9698 | |
| 9699 | error::Error GLES2DecoderImpl::HandleCompressedTexSubImage3DBucket( |
| 9700 | uint32 immediate_data_size, const void* cmd_data) { |
| 9701 | if (!unsafe_es3_apis_enabled()) |
| 9702 | return error::kUnknownCommand; |
| 9703 | const gles2::cmds::CompressedTexSubImage3DBucket& c = |
| 9704 | *static_cast<const gles2::cmds::CompressedTexSubImage3DBucket*>(cmd_data); |
| 9705 | GLenum target = static_cast<GLenum>(c.target); |
| 9706 | GLint level = static_cast<GLint>(c.level); |
| 9707 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 9708 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 9709 | GLint zoffset = static_cast<GLint>(c.zoffset); |
| 9710 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9711 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9712 | GLsizei depth = static_cast<GLsizei>(c.depth); |
| 9713 | GLenum format = static_cast<GLenum>(c.format); |
| 9714 | Bucket* bucket = GetBucket(c.bucket_id); |
| 9715 | if (!bucket) { |
| 9716 | return error::kInvalidArguments; |
| 9717 | } |
| 9718 | uint32 data_size = bucket->size(); |
| 9719 | GLsizei image_size = data_size; |
| 9720 | const void* data = bucket->GetData(0, data_size); |
| 9721 | if (!data) { |
| 9722 | return error::kInvalidArguments; |
| 9723 | } |
| 9724 | DoCompressedTexSubImage3D( |
| 9725 | target, level, xoffset, yoffset, zoffset, width, height, depth, format, |
| 9726 | image_size, data); |
| 9727 | return error::kNoError; |
| 9728 | } |
| 9729 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 9730 | error::Error GLES2DecoderImpl::HandleTexImage2D(uint32 immediate_data_size, |
| 9731 | const void* cmd_data) { |
| 9732 | const gles2::cmds::TexImage2D& c = |
| 9733 | *static_cast<const gles2::cmds::TexImage2D*>(cmd_data); |
[email protected] | 67f92942 | 2014-05-17 15:33:13 | [diff] [blame] | 9734 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexImage2D", |
| 9735 | "width", c.width, "height", c.height); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9736 | // Set as failed for now, but if it successed, this will be set to not failed. |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 9737 | texture_state_.tex_image_failed = true; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 9738 | GLenum target = static_cast<GLenum>(c.target); |
| 9739 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9740 | // TODO(kloveless): Change TexImage2D command to use unsigned integer |
| 9741 | // for internalformat. |
| 9742 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 9743 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9744 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9745 | GLint border = static_cast<GLint>(c.border); |
| 9746 | GLenum format = static_cast<GLenum>(c.format); |
| 9747 | GLenum type = static_cast<GLenum>(c.type); |
| 9748 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 9749 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 9750 | uint32 pixels_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 9751 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 9752 | width, height, 1, format, type, state_.unpack_alignment, &pixels_size, |
| 9753 | NULL, NULL)) { |
[email protected] | a76b005 | 2010-03-05 00:33:18 | [diff] [blame] | 9754 | return error::kOutOfBounds; |
| 9755 | } |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 9756 | const void* pixels = NULL; |
| 9757 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 9758 | pixels = GetSharedMemoryAs<const void*>( |
| 9759 | pixels_shm_id, pixels_shm_offset, pixels_size); |
[email protected] | ba3176a | 2009-12-16 18:19:46 | [diff] [blame] | 9760 | if (!pixels) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 9761 | return error::kOutOfBounds; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 9762 | } |
| 9763 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9764 | |
bajones | 6b0124f4 | 2015-04-07 23:14:42 | [diff] [blame] | 9765 | // For testing only. Allows us to stress the ability to respond to OOM errors. |
| 9766 | if (workarounds().simulate_out_of_memory_on_large_textures && |
| 9767 | (width * height >= 4096 * 4096)) { |
| 9768 | LOCAL_SET_GL_ERROR( |
| 9769 | GL_OUT_OF_MEMORY, |
| 9770 | "glTexImage2D", "synthetic out of memory"); |
| 9771 | return error::kNoError; |
| 9772 | } |
| 9773 | |
zmo | de7b438 | 2015-05-21 21:23:00 | [diff] [blame] | 9774 | TextureManager::DoTexImageArguments args = { |
| 9775 | target, level, internal_format, width, height, 1, border, format, type, |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 9776 | pixels, pixels_size, TextureManager::DoTexImageArguments::kTexImage2D }; |
| 9777 | texture_manager()->ValidateAndDoTexImage( |
| 9778 | &texture_state_, &state_, &framebuffer_state_, "glTexImage2D", args); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 9779 | |
| 9780 | // This may be a slow command. Exit command processing to allow for |
| 9781 | // context preemption and GPU watchdog checks. |
| 9782 | ExitCommandProcessingEarly(); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 9783 | return error::kNoError; |
[email protected] | b9849abf | 2009-11-25 19:13:19 | [diff] [blame] | 9784 | } |
| 9785 | |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 9786 | error::Error GLES2DecoderImpl::HandleTexImage3D(uint32 immediate_data_size, |
| 9787 | const void* cmd_data) { |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 9788 | if (!unsafe_es3_apis_enabled()) |
| 9789 | return error::kUnknownCommand; |
| 9790 | |
| 9791 | const gles2::cmds::TexImage3D& c = |
| 9792 | *static_cast<const gles2::cmds::TexImage3D*>(cmd_data); |
| 9793 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexImage3D", |
| 9794 | "widthXheight", c.width * c.height, "depth", c.depth); |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 9795 | // Set as failed for now, but if it successed, this will be set to not failed. |
| 9796 | texture_state_.tex_image_failed = true; |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 9797 | GLenum target = static_cast<GLenum>(c.target); |
| 9798 | GLint level = static_cast<GLint>(c.level); |
| 9799 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
| 9800 | GLsizei width = static_cast<GLsizei>(c.width); |
| 9801 | GLsizei height = static_cast<GLsizei>(c.height); |
| 9802 | GLsizei depth = static_cast<GLsizei>(c.depth); |
| 9803 | GLint border = static_cast<GLint>(c.border); |
| 9804 | GLenum format = static_cast<GLenum>(c.format); |
| 9805 | GLenum type = static_cast<GLenum>(c.type); |
| 9806 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 9807 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
| 9808 | uint32 pixels_size; |
| 9809 | if (!GLES2Util::ComputeImageDataSizes( |
| 9810 | width, height, depth, format, type, state_.unpack_alignment, &pixels_size, |
| 9811 | NULL, NULL)) { |
| 9812 | return error::kOutOfBounds; |
| 9813 | } |
| 9814 | const void* pixels = NULL; |
| 9815 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 9816 | pixels = GetSharedMemoryAs<const void*>( |
| 9817 | pixels_shm_id, pixels_shm_offset, pixels_size); |
| 9818 | if (!pixels) { |
| 9819 | return error::kOutOfBounds; |
| 9820 | } |
| 9821 | } |
| 9822 | |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 9823 | // For testing only. Allows us to stress the ability to respond to OOM errors. |
| 9824 | if (workarounds().simulate_out_of_memory_on_large_textures && |
| 9825 | (width * height * depth >= 4096 * 4096)) { |
| 9826 | LOCAL_SET_GL_ERROR( |
| 9827 | GL_OUT_OF_MEMORY, |
| 9828 | "glTexImage3D", "synthetic out of memory"); |
| 9829 | return error::kNoError; |
| 9830 | } |
| 9831 | |
zmo | de7b438 | 2015-05-21 21:23:00 | [diff] [blame] | 9832 | TextureManager::DoTexImageArguments args = { |
| 9833 | target, level, internal_format, width, height, depth, border, format, type, |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 9834 | pixels, pixels_size, TextureManager::DoTexImageArguments::kTexImage3D }; |
| 9835 | texture_manager()->ValidateAndDoTexImage( |
| 9836 | &texture_state_, &state_, &framebuffer_state_, "glTexImage3D", args); |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 9837 | |
| 9838 | // This may be a slow command. Exit command processing to allow for |
| 9839 | // context preemption and GPU watchdog checks. |
| 9840 | ExitCommandProcessingEarly(); |
| 9841 | return error::kNoError; |
| 9842 | } |
| 9843 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9844 | void GLES2DecoderImpl::DoCompressedTexSubImage2D( |
| 9845 | GLenum target, |
| 9846 | GLint level, |
| 9847 | GLint xoffset, |
| 9848 | GLint yoffset, |
| 9849 | GLsizei width, |
| 9850 | GLsizei height, |
| 9851 | GLenum format, |
| 9852 | GLsizei image_size, |
| 9853 | const void * data) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9854 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9855 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9856 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9857 | LOCAL_SET_GL_ERROR( |
| 9858 | GL_INVALID_OPERATION, |
| 9859 | "glCompressedTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9860 | return; |
| 9861 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9862 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9863 | GLenum type = 0; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 9864 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9865 | if (!texture->GetLevelType(target, level, &type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9866 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 9867 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9868 | "glCompressedTexSubImage2D", "level does not exist."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 9869 | return; |
| 9870 | } |
| 9871 | if (internal_format != format) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9872 | LOCAL_SET_GL_ERROR( |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 9873 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9874 | "glCompressedTexSubImage2D", "format does not match internal format."); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 9875 | return; |
| 9876 | } |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9877 | if (!texture->ValidForTexture(target, level, xoffset, yoffset, 0, width, |
| 9878 | height, 1, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9879 | LOCAL_SET_GL_ERROR( |
| 9880 | GL_INVALID_VALUE, "glCompressedTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9881 | return; |
| 9882 | } |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9883 | |
zmo | ea06a6f | 2015-04-30 01:15:46 | [diff] [blame] | 9884 | if (!ValidateCompressedTexFuncData("glCompressedTexSubImage2D", |
| 9885 | width, height, 1, format, image_size) || |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 9886 | !ValidateCompressedTexSubDimensions("glCompressedTexSubImage2D", |
| 9887 | target, level, xoffset, yoffset, 0, |
| 9888 | width, height, 1, format, texture)) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 9889 | return; |
| 9890 | } |
| 9891 | |
| 9892 | |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 9893 | // Note: There is no need to deal with texture cleared tracking here |
| 9894 | // because the validation above means you can only get here if the level |
| 9895 | // is already a matching compressed format and in that case |
| 9896 | // CompressedTexImage2D already cleared the texture. |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9897 | glCompressedTexSubImage2D( |
| 9898 | target, level, xoffset, yoffset, width, height, format, image_size, data); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 9899 | |
| 9900 | // This may be a slow command. Exit command processing to allow for |
| 9901 | // context preemption and GPU watchdog checks. |
| 9902 | ExitCommandProcessingEarly(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9903 | } |
| 9904 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 9905 | static void Clip( |
| 9906 | GLint start, GLint range, GLint sourceRange, |
| 9907 | GLint* out_start, GLint* out_range) { |
| 9908 | DCHECK(out_start); |
| 9909 | DCHECK(out_range); |
| 9910 | if (start < 0) { |
| 9911 | range += start; |
| 9912 | start = 0; |
| 9913 | } |
| 9914 | GLint end = start + range; |
| 9915 | if (end > sourceRange) { |
| 9916 | range -= end - sourceRange; |
| 9917 | } |
| 9918 | *out_start = start; |
| 9919 | *out_range = range; |
| 9920 | } |
| 9921 | |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9922 | void GLES2DecoderImpl::DoCopyTexImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 9923 | GLenum target, |
| 9924 | GLint level, |
| 9925 | GLenum internal_format, |
| 9926 | GLint x, |
| 9927 | GLint y, |
| 9928 | GLsizei width, |
| 9929 | GLsizei height, |
| 9930 | GLint border) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 9931 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 9932 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 9933 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9934 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9935 | LOCAL_SET_GL_ERROR( |
| 9936 | GL_INVALID_OPERATION, |
| 9937 | "glCopyTexImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 9938 | return; |
| 9939 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 9940 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 9941 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9942 | LOCAL_SET_GL_ERROR( |
| 9943 | GL_INVALID_OPERATION, "glCopyTexImage2D", "texture is immutable"); |
[email protected] | cedee33 | 2014-05-23 07:07:53 | [diff] [blame] | 9944 | return; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 9945 | } |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 9946 | if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 9947 | border != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9948 | LOCAL_SET_GL_ERROR( |
| 9949 | GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range"); |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 9950 | return; |
| 9951 | } |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 9952 | if (!texture_manager()->ValidateFormatAndTypeCombination( |
| 9953 | state_.GetErrorState(), "glCopyTexImage2D", internal_format, |
| 9954 | GL_UNSIGNED_BYTE)) { |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9955 | return; |
| 9956 | } |
[email protected] | f5719fb | 2010-08-04 18:27:18 | [diff] [blame] | 9957 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 9958 | // Check we have compatible formats. |
| 9959 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 9960 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 9961 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(internal_format); |
| 9962 | |
| 9963 | if ((channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9964 | LOCAL_SET_GL_ERROR( |
| 9965 | GL_INVALID_OPERATION, "glCopyTexImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 9966 | return; |
| 9967 | } |
| 9968 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9969 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9970 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9971 | GL_INVALID_OPERATION, |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9972 | "glCopyTexImage2D", "can not be used with depth or stencil textures"); |
| 9973 | return; |
| 9974 | } |
| 9975 | |
| 9976 | uint32 estimated_size = 0; |
| 9977 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 9978 | width, height, 1, internal_format, GL_UNSIGNED_BYTE, |
| 9979 | state_.unpack_alignment, &estimated_size, NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9980 | LOCAL_SET_GL_ERROR( |
| 9981 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 9982 | return; |
| 9983 | } |
| 9984 | |
| 9985 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 9986 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "out of memory"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 9987 | return; |
| 9988 | } |
| 9989 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 9990 | if (!CheckBoundReadFramebufferColorAttachment("glCopyTexImage2D")) { |
| 9991 | return; |
| 9992 | } |
| 9993 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 9994 | if (FormsTextureCopyingFeedbackLoop(texture_ref, level)) { |
| 9995 | LOCAL_SET_GL_ERROR( |
| 9996 | GL_INVALID_OPERATION, |
| 9997 | "glCopyTexImage2D", "source and destination textures are the same"); |
| 9998 | return; |
| 9999 | } |
| 10000 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 10001 | if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { |
| 10002 | return; |
| 10003 | } |
| 10004 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10005 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTexImage2D"); |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 10006 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10007 | gfx::Size size = GetBoundReadFrameBufferSize(); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 10008 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10009 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10010 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 297ca1c | 2011-06-20 23:08:46 | [diff] [blame] | 10011 | } |
| 10012 | |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 10013 | // Clip to size to source dimensions |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10014 | GLint copyX = 0; |
| 10015 | GLint copyY = 0; |
| 10016 | GLint copyWidth = 0; |
| 10017 | GLint copyHeight = 0; |
| 10018 | Clip(x, width, size.width(), ©X, ©Width); |
| 10019 | Clip(y, height, size.height(), ©Y, ©Height); |
| 10020 | |
| 10021 | if (copyX != x || |
| 10022 | copyY != y || |
| 10023 | copyWidth != width || |
| 10024 | copyHeight != height) { |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 10025 | // some part was clipped so clear the rect. |
| 10026 | uint32 pixels_size = 0; |
| 10027 | if (!GLES2Util::ComputeImageDataSizes( |
| 10028 | width, height, 1, internal_format, GL_UNSIGNED_BYTE, |
| 10029 | state_.unpack_alignment, &pixels_size, NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10030 | LOCAL_SET_GL_ERROR( |
| 10031 | GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10032 | return; |
| 10033 | } |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 10034 | scoped_ptr<char[]> zero(new char[pixels_size]); |
| 10035 | memset(zero.get(), 0, pixels_size); |
| 10036 | ScopedModifyPixels modify(texture_ref); |
| 10037 | glTexImage2D(target, level, internal_format, width, height, border, |
| 10038 | internal_format, GL_UNSIGNED_BYTE, zero.get()); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10039 | if (copyHeight > 0 && copyWidth > 0) { |
| 10040 | GLint dx = copyX - x; |
| 10041 | GLint dy = copyY - y; |
| 10042 | GLint destX = dx; |
| 10043 | GLint destY = dy; |
| 10044 | glCopyTexSubImage2D(target, level, |
| 10045 | destX, destY, copyX, copyY, |
| 10046 | copyWidth, copyHeight); |
| 10047 | } |
| 10048 | } else { |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 10049 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10050 | glCopyTexImage2D(target, level, internal_format, |
| 10051 | copyX, copyY, copyWidth, copyHeight, border); |
| 10052 | } |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10053 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10054 | if (error == GL_NO_ERROR) { |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 10055 | texture_manager()->SetLevelInfo(texture_ref, target, level, internal_format, |
| 10056 | width, height, 1, border, internal_format, |
| 10057 | GL_UNSIGNED_BYTE, gfx::Rect(width, height)); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10058 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 10059 | |
| 10060 | // This may be a slow command. Exit command processing to allow for |
| 10061 | // context preemption and GPU watchdog checks. |
| 10062 | ExitCommandProcessingEarly(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10063 | } |
| 10064 | |
| 10065 | void GLES2DecoderImpl::DoCopyTexSubImage2D( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 10066 | GLenum target, |
| 10067 | GLint level, |
| 10068 | GLint xoffset, |
| 10069 | GLint yoffset, |
| 10070 | GLint x, |
| 10071 | GLint y, |
| 10072 | GLsizei width, |
| 10073 | GLsizei height) { |
[email protected] | 09e1727 | 2012-11-30 10:30:44 | [diff] [blame] | 10074 | DCHECK(!ShouldDeferReads()); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10075 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10076 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10077 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10078 | LOCAL_SET_GL_ERROR( |
| 10079 | GL_INVALID_OPERATION, |
| 10080 | "glCopyTexSubImage2D", "unknown texture for target"); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10081 | return; |
| 10082 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10083 | Texture* texture = texture_ref->texture(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10084 | GLenum type = 0; |
| 10085 | GLenum format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10086 | if (!texture->GetLevelType(target, level, &type, &format) || |
| 10087 | !texture->ValidForTexture( |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 10088 | target, level, xoffset, yoffset, 0, width, height, 1, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10089 | LOCAL_SET_GL_ERROR( |
| 10090 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "bad dimensions."); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10091 | return; |
| 10092 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10093 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10094 | LOCAL_SET_GL_ERROR( |
| 10095 | GL_INVALID_OPERATION, |
| 10096 | "glCopyTexSubImage2D", "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10097 | return; |
| 10098 | } |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 10099 | |
| 10100 | // Check we have compatible formats. |
| 10101 | GLenum read_format = GetBoundReadFrameBufferInternalFormat(); |
| 10102 | uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); |
| 10103 | uint32 channels_needed = GLES2Util::GetChannelsForFormat(format); |
| 10104 | |
[email protected] | 2d3765b | 2012-10-03 00:31:07 | [diff] [blame] | 10105 | if (!channels_needed || |
| 10106 | (channels_needed & channels_exist) != channels_needed) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10107 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10108 | GL_INVALID_OPERATION, "glCopyTexSubImage2D", "incompatible format"); |
[email protected] | 9edc6b2 | 2010-12-23 02:00:26 | [diff] [blame] | 10109 | return; |
| 10110 | } |
| 10111 | |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 10112 | if ((channels_needed & (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10113 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 10114 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10115 | "glCopySubImage2D", "can not be used with depth or stencil textures"); |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 10116 | return; |
| 10117 | } |
| 10118 | |
[email protected] | 2ea5950d | 2014-07-09 18:20:34 | [diff] [blame] | 10119 | if (!CheckBoundReadFramebufferColorAttachment("glCopyTexSubImage2D")) { |
| 10120 | return; |
| 10121 | } |
| 10122 | |
zmo | 383512cf | 2014-10-14 00:11:00 | [diff] [blame] | 10123 | if (FormsTextureCopyingFeedbackLoop(texture_ref, level)) { |
| 10124 | LOCAL_SET_GL_ERROR( |
| 10125 | GL_INVALID_OPERATION, |
| 10126 | "glCopyTexSubImage2D", "source and destination textures are the same"); |
| 10127 | return; |
| 10128 | } |
| 10129 | |
[email protected] | a0b78dc | 2011-11-11 10:43:10 | [diff] [blame] | 10130 | if (!CheckBoundFramebuffersValid("glCopyTexSubImage2D")) { |
| 10131 | return; |
| 10132 | } |
| 10133 | |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 10134 | ScopedResolvedFrameBufferBinder binder(this, false, true); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10135 | gfx::Size size = GetBoundReadFrameBufferSize(); |
| 10136 | GLint copyX = 0; |
| 10137 | GLint copyY = 0; |
| 10138 | GLint copyWidth = 0; |
| 10139 | GLint copyHeight = 0; |
| 10140 | Clip(x, width, size.width(), ©X, ©Width); |
| 10141 | Clip(y, height, size.height(), ©Y, ©Height); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 10142 | |
dongseong.hwang | 351519f | 2015-01-21 14:33:59 | [diff] [blame] | 10143 | if (xoffset != 0 || yoffset != 0 || width != size.width() || |
| 10144 | height != size.height()) { |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 10145 | gfx::Rect cleared_rect; |
| 10146 | if (CombineAdjacentRects(texture->GetLevelClearedRect(target, level), |
| 10147 | gfx::Rect(xoffset, yoffset, width, height), |
| 10148 | &cleared_rect)) { |
| 10149 | DCHECK_GE(cleared_rect.size().GetArea(), |
| 10150 | texture->GetLevelClearedRect(target, level).size().GetArea()); |
| 10151 | texture_manager()->SetLevelClearedRect(texture_ref, target, level, |
| 10152 | cleared_rect); |
| 10153 | } else { |
| 10154 | // Otherwise clear part of texture level that is not already cleared. |
| 10155 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, |
| 10156 | level)) { |
| 10157 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", |
| 10158 | "dimensions too big"); |
| 10159 | return; |
| 10160 | } |
dongseong.hwang | 351519f | 2015-01-21 14:33:59 | [diff] [blame] | 10161 | } |
| 10162 | } else { |
| 10163 | // Write all pixels in below. |
| 10164 | texture_manager()->SetLevelCleared(texture_ref, target, level, true); |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 10165 | } |
| 10166 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10167 | if (copyX != x || |
| 10168 | copyY != y || |
| 10169 | copyWidth != width || |
| 10170 | copyHeight != height) { |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 10171 | // some part was clipped so clear the sub rect. |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10172 | uint32 pixels_size = 0; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 10173 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 10174 | width, height, 1, format, type, state_.unpack_alignment, &pixels_size, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 10175 | NULL, NULL)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10176 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 10177 | GL_INVALID_VALUE, "glCopyTexSubImage2D", "dimensions too large"); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10178 | return; |
| 10179 | } |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 10180 | scoped_ptr<char[]> zero(new char[pixels_size]); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10181 | memset(zero.get(), 0, pixels_size); |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 10182 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10183 | glTexSubImage2D( |
| 10184 | target, level, xoffset, yoffset, width, height, |
| 10185 | format, type, zero.get()); |
| 10186 | } |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 10187 | |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10188 | if (copyHeight > 0 && copyWidth > 0) { |
| 10189 | GLint dx = copyX - x; |
| 10190 | GLint dy = copyY - y; |
| 10191 | GLint destX = xoffset + dx; |
| 10192 | GLint destY = yoffset + dy; |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 10193 | ScopedModifyPixels modify(texture_ref); |
[email protected] | 6e28861 | 2010-12-21 20:45:03 | [diff] [blame] | 10194 | glCopyTexSubImage2D(target, level, |
| 10195 | destX, destY, copyX, copyY, |
| 10196 | copyWidth, copyHeight); |
| 10197 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 10198 | |
| 10199 | // This may be a slow command. Exit command processing to allow for |
| 10200 | // context preemption and GPU watchdog checks. |
| 10201 | ExitCommandProcessingEarly(); |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10202 | } |
| 10203 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10204 | bool GLES2DecoderImpl::ValidateTexSubImage2D( |
| 10205 | error::Error* error, |
| 10206 | const char* function_name, |
| 10207 | GLenum target, |
| 10208 | GLint level, |
| 10209 | GLint xoffset, |
| 10210 | GLint yoffset, |
| 10211 | GLsizei width, |
| 10212 | GLsizei height, |
| 10213 | GLenum format, |
| 10214 | GLenum type, |
| 10215 | const void * data) { |
| 10216 | (*error) = error::kNoError; |
| 10217 | if (!validators_->texture_target.IsValid(target)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10218 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10219 | return false; |
| 10220 | } |
| 10221 | if (width < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10222 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "width < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10223 | return false; |
| 10224 | } |
| 10225 | if (height < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10226 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "height < 0"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10227 | return false; |
| 10228 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10229 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10230 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10231 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10232 | LOCAL_SET_GL_ERROR( |
| 10233 | GL_INVALID_OPERATION, |
| 10234 | function_name, "unknown texture for target"); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10235 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10236 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10237 | Texture* texture = texture_ref->texture(); |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 10238 | GLenum current_type = 0; |
| 10239 | GLenum internal_format = 0; |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10240 | if (!texture->GetLevelType(target, level, ¤t_type, &internal_format)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10241 | LOCAL_SET_GL_ERROR( |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10242 | GL_INVALID_OPERATION, function_name, "level does not exist."); |
| 10243 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 10244 | } |
[email protected] | 17a96119 | 2014-02-14 15:20:52 | [diff] [blame] | 10245 | if (!texture_manager()->ValidateTextureParameters(state_.GetErrorState(), |
| 10246 | function_name, format, type, internal_format, level)) { |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10247 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 10248 | } |
| 10249 | if (type != current_type) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10250 | LOCAL_SET_GL_ERROR( |
| 10251 | GL_INVALID_OPERATION, |
| 10252 | function_name, "type does not match type of texture."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10253 | return false; |
[email protected] | df6cf1ad | 2011-01-29 01:20:52 | [diff] [blame] | 10254 | } |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 10255 | if (async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10256 | LOCAL_SET_GL_ERROR( |
| 10257 | GL_INVALID_OPERATION, |
| 10258 | function_name, "async upload pending for texture"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 10259 | return false; |
| 10260 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 10261 | if (!texture->ValidForTexture( |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 10262 | target, level, xoffset, yoffset, 0, width, height, 1, type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10263 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "bad dimensions."); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10264 | return false; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10265 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 10266 | if ((GLES2Util::GetChannelsForFormat(format) & |
| 10267 | (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10268 | LOCAL_SET_GL_ERROR( |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 10269 | GL_INVALID_OPERATION, |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10270 | function_name, "can not supply data for depth or stencil textures"); |
| 10271 | return false; |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 10272 | } |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10273 | if (data == NULL) { |
| 10274 | (*error) = error::kOutOfBounds; |
| 10275 | return false; |
| 10276 | } |
| 10277 | return true; |
| 10278 | } |
[email protected] | 8137574 | 2012-06-08 00:04:00 | [diff] [blame] | 10279 | |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10280 | error::Error GLES2DecoderImpl::DoTexSubImage2D( |
| 10281 | GLenum target, |
| 10282 | GLint level, |
| 10283 | GLint xoffset, |
| 10284 | GLint yoffset, |
| 10285 | GLsizei width, |
| 10286 | GLsizei height, |
| 10287 | GLenum format, |
| 10288 | GLenum type, |
| 10289 | const void * data) { |
| 10290 | error::Error error = error::kNoError; |
| 10291 | if (!ValidateTexSubImage2D(&error, "glTexSubImage2D", target, level, |
| 10292 | xoffset, yoffset, width, height, format, type, data)) { |
| 10293 | return error; |
| 10294 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10295 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10296 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10297 | Texture* texture = texture_ref->texture(); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10298 | GLsizei tex_width = 0; |
| 10299 | GLsizei tex_height = 0; |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 10300 | bool ok = texture->GetLevelSize( |
| 10301 | target, level, &tex_width, &tex_height, nullptr); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10302 | DCHECK(ok); |
| 10303 | if (xoffset != 0 || yoffset != 0 || |
| 10304 | width != tex_width || height != tex_height) { |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 10305 | gfx::Rect cleared_rect; |
| 10306 | if (CombineAdjacentRects(texture->GetLevelClearedRect(target, level), |
| 10307 | gfx::Rect(xoffset, yoffset, width, height), |
| 10308 | &cleared_rect)) { |
| 10309 | DCHECK_GE(cleared_rect.size().GetArea(), |
| 10310 | texture->GetLevelClearedRect(target, level).size().GetArea()); |
| 10311 | texture_manager()->SetLevelClearedRect(texture_ref, target, level, |
| 10312 | cleared_rect); |
| 10313 | } else { |
| 10314 | // Otherwise clear part of texture level that is not already cleared. |
| 10315 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, |
| 10316 | level)) { |
| 10317 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glTexSubImage2D", |
| 10318 | "dimensions too big"); |
| 10319 | return error::kNoError; |
| 10320 | } |
[email protected] | 473c01ccb | 2011-06-07 01:33:30 | [diff] [blame] | 10321 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10322 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10323 | glTexSubImage2D( |
| 10324 | target, level, xoffset, yoffset, width, height, format, type, data); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10325 | return error::kNoError; |
[email protected] | 0d6bfdc | 2011-11-02 01:32:20 | [diff] [blame] | 10326 | } |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10327 | |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 10328 | if (!texture_state_.texsubimage_faster_than_teximage && |
boliu | 45dc77a | 2015-02-25 23:26:31 | [diff] [blame] | 10329 | !texture->IsImmutable() && |
| 10330 | !texture->HasImages()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10331 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 10332 | GLenum internal_format; |
| 10333 | GLenum tex_type; |
| 10334 | texture->GetLevelType(target, level, &tex_type, &internal_format); |
| 10335 | // NOTE: In OpenGL ES 2.0 border is always zero. If that changes we'll need |
| 10336 | // to look it up. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 10337 | glTexImage2D( |
[email protected] | d8e6c924 | 2014-02-20 16:56:25 | [diff] [blame] | 10338 | target, level, internal_format, width, height, 0, format, type, data); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10339 | } else { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 10340 | ScopedTextureUploadTimer timer(&texture_state_); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 10341 | glTexSubImage2D( |
| 10342 | target, level, xoffset, yoffset, width, height, format, type, data); |
| 10343 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 10344 | texture_manager()->SetLevelCleared(texture_ref, target, level, true); |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 10345 | |
| 10346 | // This may be a slow command. Exit command processing to allow for |
| 10347 | // context preemption and GPU watchdog checks. |
| 10348 | ExitCommandProcessingEarly(); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10349 | return error::kNoError; |
[email protected] | cadde4a | 2010-07-31 17:10:43 | [diff] [blame] | 10350 | } |
| 10351 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10352 | error::Error GLES2DecoderImpl::HandleTexSubImage2D(uint32 immediate_data_size, |
| 10353 | const void* cmd_data) { |
| 10354 | const gles2::cmds::TexSubImage2D& c = |
| 10355 | *static_cast<const gles2::cmds::TexSubImage2D*>(cmd_data); |
[email protected] | 67f92942 | 2014-05-17 15:33:13 | [diff] [blame] | 10356 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexSubImage2D", |
| 10357 | "width", c.width, "height", c.height); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 10358 | GLboolean internal = static_cast<GLboolean>(c.internal); |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 10359 | if (internal == GL_TRUE && texture_state_.tex_image_failed) |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 10360 | return error::kNoError; |
| 10361 | |
| 10362 | GLenum target = static_cast<GLenum>(c.target); |
| 10363 | GLint level = static_cast<GLint>(c.level); |
| 10364 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 10365 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 10366 | GLsizei width = static_cast<GLsizei>(c.width); |
| 10367 | GLsizei height = static_cast<GLsizei>(c.height); |
| 10368 | GLenum format = static_cast<GLenum>(c.format); |
| 10369 | GLenum type = static_cast<GLenum>(c.type); |
| 10370 | uint32 data_size; |
[email protected] | 3458a64a | 2012-04-10 17:39:34 | [diff] [blame] | 10371 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 10372 | width, height, 1, format, type, state_.unpack_alignment, &data_size, |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 10373 | NULL, NULL)) { |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 10374 | return error::kOutOfBounds; |
| 10375 | } |
| 10376 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 10377 | c.pixels_shm_id, c.pixels_shm_offset, data_size); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 10378 | return DoTexSubImage2D( |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 10379 | target, level, xoffset, yoffset, width, height, format, type, pixels); |
[email protected] | b493ee62 | 2011-04-13 23:52:00 | [diff] [blame] | 10380 | } |
| 10381 | |
zmo | de7b438 | 2015-05-21 21:23:00 | [diff] [blame] | 10382 | error::Error GLES2DecoderImpl::DoTexSubImage3D( |
| 10383 | GLenum target, |
| 10384 | GLint level, |
| 10385 | GLint xoffset, |
| 10386 | GLint yoffset, |
| 10387 | GLint zoffset, |
| 10388 | GLsizei width, |
| 10389 | GLsizei height, |
| 10390 | GLsizei depth, |
| 10391 | GLenum format, |
| 10392 | GLenum type, |
| 10393 | const void * data) { |
| 10394 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 10395 | &state_, target); |
| 10396 | if (!texture_ref) { |
| 10397 | LOCAL_SET_GL_ERROR( |
| 10398 | GL_INVALID_ENUM, "glTexSubImage3D", "invalid target"); |
| 10399 | } |
| 10400 | |
| 10401 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexSubImage3D"); |
| 10402 | ScopedTextureUploadTimer timer(&texture_state_); |
| 10403 | glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, |
| 10404 | depth, format, type, data); |
| 10405 | GLenum error = LOCAL_PEEK_GL_ERROR("glTexSubImage3D"); |
| 10406 | if (error == GL_NO_ERROR) { |
| 10407 | // TODO(zmo): This is not 100% correct because only part of the level |
| 10408 | // image is cleared. |
| 10409 | texture_manager()->SetLevelCleared(texture_ref, target, level, true); |
| 10410 | } |
| 10411 | |
| 10412 | // This may be a slow command. Exit command processing to allow for |
| 10413 | // context preemption and GPU watchdog checks. |
| 10414 | ExitCommandProcessingEarly(); |
| 10415 | return error::kNoError; |
| 10416 | } |
| 10417 | |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 10418 | error::Error GLES2DecoderImpl::HandleTexSubImage3D(uint32 immediate_data_size, |
| 10419 | const void* cmd_data) { |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 10420 | if (!unsafe_es3_apis_enabled()) |
| 10421 | return error::kUnknownCommand; |
| 10422 | |
| 10423 | const gles2::cmds::TexSubImage3D& c = |
| 10424 | *static_cast<const gles2::cmds::TexSubImage3D*>(cmd_data); |
| 10425 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::HandleTexSubImage3D", |
| 10426 | "widthXheight", c.width * c.height, "depth", c.depth); |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 10427 | GLboolean internal = static_cast<GLboolean>(c.internal); |
| 10428 | if (internal == GL_TRUE && texture_state_.tex_image_failed) |
| 10429 | return error::kNoError; |
| 10430 | |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 10431 | GLenum target = static_cast<GLenum>(c.target); |
| 10432 | GLint level = static_cast<GLint>(c.level); |
| 10433 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 10434 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 10435 | GLint zoffset = static_cast<GLint>(c.zoffset); |
| 10436 | GLsizei width = static_cast<GLsizei>(c.width); |
| 10437 | GLsizei height = static_cast<GLsizei>(c.height); |
| 10438 | GLsizei depth = static_cast<GLsizei>(c.depth); |
| 10439 | GLenum format = static_cast<GLenum>(c.format); |
| 10440 | GLenum type = static_cast<GLenum>(c.type); |
| 10441 | uint32 data_size; |
| 10442 | if (!GLES2Util::ComputeImageDataSizes( |
| 10443 | width, height, depth, format, type, state_.unpack_alignment, &data_size, |
| 10444 | NULL, NULL)) { |
| 10445 | return error::kOutOfBounds; |
| 10446 | } |
| 10447 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 10448 | c.pixels_shm_id, c.pixels_shm_offset, data_size); |
zmo | de7b438 | 2015-05-21 21:23:00 | [diff] [blame] | 10449 | return DoTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, |
| 10450 | height, depth, format, type, pixels); |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 10451 | } |
| 10452 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10453 | error::Error GLES2DecoderImpl::HandleGetVertexAttribPointerv( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10454 | uint32 immediate_data_size, |
| 10455 | const void* cmd_data) { |
| 10456 | const gles2::cmds::GetVertexAttribPointerv& c = |
| 10457 | *static_cast<const gles2::cmds::GetVertexAttribPointerv*>(cmd_data); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 10458 | GLuint index = static_cast<GLuint>(c.index); |
| 10459 | GLenum pname = static_cast<GLenum>(c.pname); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10460 | typedef cmds::GetVertexAttribPointerv::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10461 | Result* result = GetSharedMemoryAs<Result*>( |
| 10462 | c.pointer_shm_id, c.pointer_shm_offset, Result::ComputeSize(1)); |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 10463 | if (!result) { |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10464 | return error::kOutOfBounds; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 10465 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 10466 | // Check that the client initialized the result. |
| 10467 | if (result->size != 0) { |
| 10468 | return error::kInvalidArguments; |
| 10469 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 10470 | if (!validators_->vertex_pointer.IsValid(pname)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10471 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 10472 | "glGetVertexAttribPointerv", pname, "pname"); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10473 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 10474 | } |
[email protected] | 3916c97e | 2010-02-25 03:20:50 | [diff] [blame] | 10475 | if (index >= group_->max_vertex_attribs()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10476 | LOCAL_SET_GL_ERROR( |
| 10477 | GL_INVALID_VALUE, "glGetVertexAttribPointerv", "index out of range."); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10478 | return error::kNoError; |
[email protected] | 8bf5a3e | 2010-01-29 04:21:36 | [diff] [blame] | 10479 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10480 | result->SetNumResults(1); |
[email protected] | f39f4b3f | 2010-05-12 17:04:08 | [diff] [blame] | 10481 | *result->GetData() = |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10482 | state_.vertex_attrib_manager->GetVertexAttrib(index)->offset(); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10483 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 10484 | } |
| 10485 | |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10486 | template <class T> |
vmiura | 181c7400 | 2015-03-20 01:32:51 | [diff] [blame] | 10487 | bool GLES2DecoderImpl::GetUniformSetup(GLuint program_id, |
| 10488 | GLint fake_location, |
| 10489 | uint32 shm_id, |
| 10490 | uint32 shm_offset, |
| 10491 | error::Error* error, |
| 10492 | GLint* real_location, |
| 10493 | GLuint* service_id, |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10494 | SizedResult<T>** result_pointer, |
vmiura | 181c7400 | 2015-03-20 01:32:51 | [diff] [blame] | 10495 | GLenum* result_type, |
| 10496 | GLsizei* result_size) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 10497 | DCHECK(error); |
| 10498 | DCHECK(service_id); |
| 10499 | DCHECK(result_pointer); |
| 10500 | DCHECK(result_type); |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10501 | DCHECK(result_size); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 10502 | DCHECK(real_location); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10503 | *error = error::kNoError; |
| 10504 | // Make sure we have enough room for the result on failure. |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10505 | SizedResult<T>* result; |
| 10506 | result = GetSharedMemoryAs<SizedResult<T>*>( |
| 10507 | shm_id, shm_offset, SizedResult<T>::ComputeSize(0)); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10508 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10509 | *error = error::kOutOfBounds; |
| 10510 | return false; |
| 10511 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10512 | *result_pointer = result; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10513 | // 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] | 10514 | result->SetNumResults(0); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10515 | Program* program = GetProgramInfoNotShader(program_id, "glGetUniform"); |
| 10516 | if (!program) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 10517 | return false; |
| 10518 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10519 | if (!program->IsValid()) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10520 | // Program was not linked successfully. (ie, glLinkProgram) |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10521 | LOCAL_SET_GL_ERROR( |
| 10522 | GL_INVALID_OPERATION, "glGetUniform", "program not linked"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10523 | return false; |
| 10524 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10525 | *service_id = program->service_id(); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 10526 | GLint array_index = -1; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10527 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10528 | program->GetUniformInfoByFakeLocation( |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 10529 | fake_location, real_location, &array_index); |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 10530 | if (!uniform_info) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10531 | // No such location. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10532 | LOCAL_SET_GL_ERROR( |
| 10533 | GL_INVALID_OPERATION, "glGetUniform", "unknown location"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10534 | return false; |
| 10535 | } |
[email protected] | 43c2f1f | 2011-03-25 18:35:36 | [diff] [blame] | 10536 | GLenum type = uniform_info->type; |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10537 | uint32 num_elements = GLES2Util::GetElementCountForUniformType(type); |
| 10538 | if (num_elements == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10539 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glGetUniform", "unknown type"); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10540 | return false; |
| 10541 | } |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10542 | result = GetSharedMemoryAs<SizedResult<T>*>( |
| 10543 | shm_id, shm_offset, SizedResult<T>::ComputeSize(num_elements)); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10544 | if (!result) { |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10545 | *error = error::kOutOfBounds; |
| 10546 | return false; |
| 10547 | } |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10548 | result->SetNumResults(num_elements); |
| 10549 | *result_size = num_elements * sizeof(T); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 10550 | *result_type = type; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10551 | return true; |
| 10552 | } |
| 10553 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10554 | error::Error GLES2DecoderImpl::HandleGetUniformiv(uint32 immediate_data_size, |
| 10555 | const void* cmd_data) { |
| 10556 | const gles2::cmds::GetUniformiv& c = |
| 10557 | *static_cast<const gles2::cmds::GetUniformiv*>(cmd_data); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10558 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 10559 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10560 | GLuint service_id; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 10561 | GLenum result_type; |
vmiura | 181c7400 | 2015-03-20 01:32:51 | [diff] [blame] | 10562 | GLsizei result_size; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 10563 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10564 | Error error; |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10565 | cmds::GetUniformiv::Result* result; |
| 10566 | if (GetUniformSetup<GLint>(program, fake_location, c.params_shm_id, |
| 10567 | c.params_shm_offset, &error, &real_location, |
| 10568 | &service_id, &result, &result_type, |
| 10569 | &result_size)) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10570 | glGetUniformiv( |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10571 | service_id, real_location, result->GetData()); |
| 10572 | } |
| 10573 | return error; |
| 10574 | } |
| 10575 | |
| 10576 | error::Error GLES2DecoderImpl::HandleGetUniformuiv(uint32 immediate_data_size, |
| 10577 | const void* cmd_data) { |
| 10578 | if (!unsafe_es3_apis_enabled()) |
| 10579 | return error::kUnknownCommand; |
| 10580 | |
| 10581 | const gles2::cmds::GetUniformuiv& c = |
| 10582 | *static_cast<const gles2::cmds::GetUniformuiv*>(cmd_data); |
| 10583 | GLuint program = c.program; |
| 10584 | GLint fake_location = c.location; |
| 10585 | GLuint service_id; |
| 10586 | GLenum result_type; |
| 10587 | GLsizei result_size; |
| 10588 | GLint real_location = -1; |
| 10589 | Error error; |
| 10590 | cmds::GetUniformuiv::Result* result; |
| 10591 | if (GetUniformSetup<GLuint>(program, fake_location, c.params_shm_id, |
| 10592 | c.params_shm_offset, &error, &real_location, |
| 10593 | &service_id, &result, &result_type, |
| 10594 | &result_size)) { |
| 10595 | glGetUniformuiv( |
| 10596 | service_id, real_location, result->GetData()); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10597 | } |
| 10598 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 10599 | } |
| 10600 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10601 | error::Error GLES2DecoderImpl::HandleGetUniformfv(uint32 immediate_data_size, |
| 10602 | const void* cmd_data) { |
| 10603 | const gles2::cmds::GetUniformfv& c = |
| 10604 | *static_cast<const gles2::cmds::GetUniformfv*>(cmd_data); |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10605 | GLuint program = c.program; |
[email protected] | 2be6abf3 | 2012-06-26 00:28:33 | [diff] [blame] | 10606 | GLint fake_location = c.location; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10607 | GLuint service_id; |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 10608 | GLint real_location = -1; |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10609 | Error error; |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10610 | cmds::GetUniformfv::Result* result; |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 10611 | GLenum result_type; |
vmiura | 181c7400 | 2015-03-20 01:32:51 | [diff] [blame] | 10612 | GLsizei result_size; |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10613 | if (GetUniformSetup<GLfloat>(program, fake_location, c.params_shm_id, |
| 10614 | c.params_shm_offset, &error, &real_location, |
| 10615 | &service_id, &result, &result_type, |
| 10616 | &result_size)) { |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 10617 | if (result_type == GL_BOOL || result_type == GL_BOOL_VEC2 || |
| 10618 | result_type == GL_BOOL_VEC3 || result_type == GL_BOOL_VEC4) { |
zmo | c9ea7b8 | 2015-05-08 03:44:44 | [diff] [blame] | 10619 | GLsizei num_values = result_size / sizeof(GLfloat); |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 10620 | scoped_ptr<GLint[]> temp(new GLint[num_values]); |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 10621 | glGetUniformiv(service_id, real_location, temp.get()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 10622 | GLfloat* dst = result->GetData(); |
| 10623 | for (GLsizei ii = 0; ii < num_values; ++ii) { |
| 10624 | dst[ii] = (temp[ii] != 0); |
| 10625 | } |
| 10626 | } else { |
[email protected] | 1b0a675 | 2012-02-22 03:44:12 | [diff] [blame] | 10627 | glGetUniformfv(service_id, real_location, result->GetData()); |
[email protected] | 939e736 | 2010-05-13 20:49:10 | [diff] [blame] | 10628 | } |
[email protected] | f7b8537 | 2010-02-03 01:11:37 | [diff] [blame] | 10629 | } |
| 10630 | return error; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 10631 | } |
| 10632 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10633 | error::Error GLES2DecoderImpl::HandleGetShaderPrecisionFormat( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10634 | uint32 immediate_data_size, |
| 10635 | const void* cmd_data) { |
| 10636 | const gles2::cmds::GetShaderPrecisionFormat& c = |
| 10637 | *static_cast<const gles2::cmds::GetShaderPrecisionFormat*>(cmd_data); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10638 | GLenum shader_type = static_cast<GLenum>(c.shadertype); |
| 10639 | GLenum precision_type = static_cast<GLenum>(c.precisiontype); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10640 | typedef cmds::GetShaderPrecisionFormat::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10641 | Result* result = GetSharedMemoryAs<Result*>( |
| 10642 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 10643 | if (!result) { |
| 10644 | return error::kOutOfBounds; |
| 10645 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 10646 | // Check that the client initialized the result. |
| 10647 | if (result->success != 0) { |
| 10648 | return error::kInvalidArguments; |
| 10649 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 10650 | if (!validators_->shader_type.IsValid(shader_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10651 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 10652 | "glGetShaderPrecisionFormat", shader_type, "shader_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 10653 | return error::kNoError; |
| 10654 | } |
[email protected] | 9438b01 | 2010-06-15 22:55:05 | [diff] [blame] | 10655 | if (!validators_->shader_precision.IsValid(precision_type)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10656 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
[email protected] | f80e6e1 | 2012-08-31 00:43:53 | [diff] [blame] | 10657 | "glGetShaderPrecisionFormat", precision_type, "precision_type"); |
[email protected] | 8eee29c | 2010-04-29 03:38:29 | [diff] [blame] | 10658 | return error::kNoError; |
| 10659 | } |
| 10660 | |
| 10661 | result->success = 1; // true |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 10662 | |
[email protected] | 46c8675 | 2013-05-21 05:08:39 | [diff] [blame] | 10663 | GLint range[2] = { 0, 0 }; |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 10664 | GLint precision = 0; |
[email protected] | 8dc1bf9 | 2013-03-12 03:58:21 | [diff] [blame] | 10665 | GetShaderPrecisionFormatImpl(shader_type, precision_type, range, &precision); |
[email protected] | d8bc3ec | 2013-03-07 06:28:40 | [diff] [blame] | 10666 | |
| 10667 | result->min_range = range[0]; |
| 10668 | result->max_range = range[1]; |
| 10669 | result->precision = precision; |
| 10670 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10671 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 10672 | } |
| 10673 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10674 | error::Error GLES2DecoderImpl::HandleGetAttachedShaders( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10675 | uint32 immediate_data_size, |
| 10676 | const void* cmd_data) { |
| 10677 | const gles2::cmds::GetAttachedShaders& c = |
| 10678 | *static_cast<const gles2::cmds::GetAttachedShaders*>(cmd_data); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10679 | uint32 result_size = c.result_size; |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10680 | GLuint program_id = static_cast<GLuint>(c.program); |
| 10681 | Program* program = GetProgramInfoNotShader( |
| 10682 | program_id, "glGetAttachedShaders"); |
| 10683 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10684 | return error::kNoError; |
| 10685 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10686 | typedef cmds::GetAttachedShaders::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10687 | uint32 max_count = Result::ComputeMaxResults(result_size); |
| 10688 | Result* result = GetSharedMemoryAs<Result*>( |
| 10689 | c.result_shm_id, c.result_shm_offset, Result::ComputeSize(max_count)); |
| 10690 | if (!result) { |
| 10691 | return error::kOutOfBounds; |
| 10692 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 10693 | // Check that the client initialized the result. |
| 10694 | if (result->size != 0) { |
| 10695 | return error::kInvalidArguments; |
| 10696 | } |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10697 | GLsizei count = 0; |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 10698 | glGetAttachedShaders( |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10699 | program->service_id(), max_count, &count, result->GetData()); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10700 | for (GLsizei ii = 0; ii < count; ++ii) { |
[email protected] | ae51d19 | 2010-04-27 00:48:03 | [diff] [blame] | 10701 | if (!shader_manager()->GetClientId(result->GetData()[ii], |
| 10702 | &result->GetData()[ii])) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10703 | NOTREACHED(); |
| 10704 | return error::kGenericError; |
| 10705 | } |
| 10706 | } |
| 10707 | result->SetNumResults(count); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10708 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 10709 | } |
| 10710 | |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10711 | error::Error GLES2DecoderImpl::HandleGetActiveUniform( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10712 | uint32 immediate_data_size, |
| 10713 | const void* cmd_data) { |
| 10714 | const gles2::cmds::GetActiveUniform& c = |
| 10715 | *static_cast<const gles2::cmds::GetActiveUniform*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10716 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10717 | GLuint index = c.index; |
| 10718 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10719 | typedef cmds::GetActiveUniform::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10720 | Result* result = GetSharedMemoryAs<Result*>( |
| 10721 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 10722 | if (!result) { |
| 10723 | return error::kOutOfBounds; |
| 10724 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 10725 | // Check that the client initialized the result. |
| 10726 | if (result->success != 0) { |
| 10727 | return error::kInvalidArguments; |
| 10728 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10729 | Program* program = GetProgramInfoNotShader( |
| 10730 | program_id, "glGetActiveUniform"); |
| 10731 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10732 | return error::kNoError; |
| 10733 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10734 | const Program::UniformInfo* uniform_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10735 | program->GetUniformInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10736 | if (!uniform_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10737 | LOCAL_SET_GL_ERROR( |
| 10738 | GL_INVALID_VALUE, "glGetActiveUniform", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10739 | return error::kNoError; |
| 10740 | } |
| 10741 | result->success = 1; // true. |
| 10742 | result->size = uniform_info->size; |
| 10743 | result->type = uniform_info->type; |
| 10744 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 10745 | bucket->SetFromString(uniform_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10746 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 10747 | } |
| 10748 | |
zmo | a2b555d | 2015-02-06 23:50:39 | [diff] [blame] | 10749 | error::Error GLES2DecoderImpl::HandleGetActiveUniformBlockiv( |
| 10750 | uint32 immediate_data_size, const void* cmd_data) { |
| 10751 | if (!unsafe_es3_apis_enabled()) |
| 10752 | return error::kUnknownCommand; |
| 10753 | const gles2::cmds::GetActiveUniformBlockiv& c = |
| 10754 | *static_cast<const gles2::cmds::GetActiveUniformBlockiv*>(cmd_data); |
| 10755 | GLuint program_id = c.program; |
| 10756 | GLuint index = static_cast<GLuint>(c.index); |
| 10757 | GLenum pname = static_cast<GLenum>(c.pname); |
| 10758 | Program* program = GetProgramInfoNotShader( |
zmo | 8fab00c | 2015-02-07 02:45:05 | [diff] [blame] | 10759 | program_id, "glGetActiveUniformBlockiv"); |
zmo | a2b555d | 2015-02-06 23:50:39 | [diff] [blame] | 10760 | if (!program) { |
| 10761 | return error::kNoError; |
| 10762 | } |
| 10763 | GLuint service_id = program->service_id(); |
| 10764 | GLint link_status = GL_FALSE; |
| 10765 | glGetProgramiv(service_id, GL_LINK_STATUS, &link_status); |
| 10766 | if (link_status != GL_TRUE) { |
| 10767 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10768 | "glGetActiveActiveUniformBlockiv", "program not linked"); |
| 10769 | return error::kNoError; |
| 10770 | } |
| 10771 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("GetActiveUniformBlockiv"); |
| 10772 | GLsizei num_values = 1; |
| 10773 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) { |
| 10774 | GLint num = 0; |
| 10775 | glGetActiveUniformBlockiv( |
| 10776 | service_id, index, GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS, &num); |
| 10777 | GLenum error = glGetError(); |
| 10778 | if (error != GL_NO_ERROR) { |
| 10779 | // Assume this will the same error if calling with pname. |
| 10780 | LOCAL_SET_GL_ERROR(error, "GetActiveUniformBlockiv", ""); |
| 10781 | return error::kNoError; |
| 10782 | } |
| 10783 | num_values = static_cast<GLsizei>(num); |
| 10784 | } |
| 10785 | typedef cmds::GetActiveUniformBlockiv::Result Result; |
| 10786 | Result* result = GetSharedMemoryAs<Result*>( |
| 10787 | c.params_shm_id, c.params_shm_offset, Result::ComputeSize(num_values)); |
| 10788 | GLint* params = result ? result->GetData() : NULL; |
| 10789 | if (params == NULL) { |
| 10790 | return error::kOutOfBounds; |
| 10791 | } |
| 10792 | // Check that the client initialized the result. |
| 10793 | if (result->size != 0) { |
| 10794 | return error::kInvalidArguments; |
| 10795 | } |
| 10796 | glGetActiveUniformBlockiv(service_id, index, pname, params); |
| 10797 | GLenum error = glGetError(); |
| 10798 | if (error == GL_NO_ERROR) { |
| 10799 | result->SetNumResults(num_values); |
| 10800 | } else { |
| 10801 | LOCAL_SET_GL_ERROR(error, "GetActiveUniformBlockiv", ""); |
| 10802 | } |
| 10803 | return error::kNoError; |
| 10804 | } |
| 10805 | |
zmo | 4a16ff99 | 2015-02-05 22:18:41 | [diff] [blame] | 10806 | error::Error GLES2DecoderImpl::HandleGetActiveUniformBlockName( |
| 10807 | uint32 immediate_data_size, const void* cmd_data) { |
| 10808 | if (!unsafe_es3_apis_enabled()) |
| 10809 | return error::kUnknownCommand; |
| 10810 | const gles2::cmds::GetActiveUniformBlockName& c = |
| 10811 | *static_cast<const gles2::cmds::GetActiveUniformBlockName*>(cmd_data); |
| 10812 | GLuint program_id = c.program; |
| 10813 | GLuint index = c.index; |
| 10814 | uint32 name_bucket_id = c.name_bucket_id; |
| 10815 | typedef cmds::GetActiveUniformBlockName::Result Result; |
| 10816 | Result* result = GetSharedMemoryAs<Result*>( |
| 10817 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 10818 | if (!result) { |
| 10819 | return error::kOutOfBounds; |
| 10820 | } |
| 10821 | // Check that the client initialized the result. |
| 10822 | if (*result != 0) { |
| 10823 | return error::kInvalidArguments; |
| 10824 | } |
| 10825 | Program* program = GetProgramInfoNotShader( |
| 10826 | program_id, "glGetActiveUniformBlockName"); |
| 10827 | if (!program) { |
| 10828 | return error::kNoError; |
| 10829 | } |
| 10830 | GLuint service_id = program->service_id(); |
| 10831 | GLint link_status = GL_FALSE; |
| 10832 | glGetProgramiv(service_id, GL_LINK_STATUS, &link_status); |
| 10833 | if (link_status != GL_TRUE) { |
| 10834 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10835 | "glGetActiveActiveUniformBlockName", "program not linked"); |
| 10836 | return error::kNoError; |
| 10837 | } |
| 10838 | GLint max_length = 0; |
| 10839 | glGetProgramiv( |
| 10840 | service_id, GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, &max_length); |
| 10841 | // Increase one so &buffer[0] is always valid. |
| 10842 | GLsizei buf_size = static_cast<GLsizei>(max_length) + 1; |
| 10843 | std::vector<char> buffer(buf_size); |
| 10844 | GLsizei length = 0; |
| 10845 | glGetActiveUniformBlockName( |
| 10846 | service_id, index, buf_size, &length, &buffer[0]); |
| 10847 | if (length == 0) { |
| 10848 | *result = 0; |
| 10849 | return error::kNoError; |
| 10850 | } |
| 10851 | *result = 1; |
| 10852 | Bucket* bucket = CreateBucket(name_bucket_id); |
| 10853 | DCHECK_GT(buf_size, length); |
| 10854 | DCHECK_EQ(0, buffer[length]); |
| 10855 | bucket->SetFromString(&buffer[0]); |
| 10856 | return error::kNoError; |
| 10857 | } |
| 10858 | |
zmo | c7e7e13f | 2015-02-17 22:07:07 | [diff] [blame] | 10859 | error::Error GLES2DecoderImpl::HandleGetActiveUniformsiv( |
| 10860 | uint32 immediate_data_size, const void* cmd_data) { |
| 10861 | if (!unsafe_es3_apis_enabled()) |
| 10862 | return error::kUnknownCommand; |
| 10863 | const gles2::cmds::GetActiveUniformsiv& c = |
| 10864 | *static_cast<const gles2::cmds::GetActiveUniformsiv*>(cmd_data); |
| 10865 | GLuint program_id = c.program; |
| 10866 | GLenum pname = static_cast<GLenum>(c.pname); |
| 10867 | Bucket* bucket = GetBucket(c.indices_bucket_id); |
| 10868 | if (!bucket) { |
| 10869 | return error::kInvalidArguments; |
| 10870 | } |
| 10871 | GLsizei count = static_cast<GLsizei>(bucket->size() / sizeof(GLuint)); |
| 10872 | const GLuint* indices = bucket->GetDataAs<const GLuint*>(0, bucket->size()); |
| 10873 | typedef cmds::GetActiveUniformsiv::Result Result; |
| 10874 | Result* result = GetSharedMemoryAs<Result*>( |
| 10875 | c.params_shm_id, c.params_shm_offset, Result::ComputeSize(count)); |
| 10876 | GLint* params = result ? result->GetData() : NULL; |
| 10877 | if (params == NULL) { |
| 10878 | return error::kOutOfBounds; |
| 10879 | } |
| 10880 | // Check that the client initialized the result. |
| 10881 | if (result->size != 0) { |
| 10882 | return error::kInvalidArguments; |
| 10883 | } |
| 10884 | Program* program = GetProgramInfoNotShader( |
| 10885 | program_id, "glGetActiveUniformsiv"); |
| 10886 | if (!program) { |
| 10887 | return error::kNoError; |
| 10888 | } |
| 10889 | GLuint service_id = program->service_id(); |
| 10890 | GLint link_status = GL_FALSE; |
| 10891 | glGetProgramiv(service_id, GL_LINK_STATUS, &link_status); |
| 10892 | if (link_status != GL_TRUE) { |
| 10893 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 10894 | "glGetActiveUniformsiv", "program not linked"); |
| 10895 | return error::kNoError; |
| 10896 | } |
| 10897 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("GetActiveUniformsiv"); |
| 10898 | glGetActiveUniformsiv(service_id, count, indices, pname, params); |
| 10899 | GLenum error = glGetError(); |
| 10900 | if (error == GL_NO_ERROR) { |
| 10901 | result->SetNumResults(count); |
| 10902 | } else { |
| 10903 | LOCAL_SET_GL_ERROR(error, "GetActiveUniformsiv", ""); |
| 10904 | } |
| 10905 | return error::kNoError; |
| 10906 | } |
| 10907 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10908 | error::Error GLES2DecoderImpl::HandleGetActiveAttrib(uint32 immediate_data_size, |
| 10909 | const void* cmd_data) { |
| 10910 | const gles2::cmds::GetActiveAttrib& c = |
| 10911 | *static_cast<const gles2::cmds::GetActiveAttrib*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10912 | GLuint program_id = c.program; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10913 | GLuint index = c.index; |
| 10914 | uint32 name_bucket_id = c.name_bucket_id; |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10915 | typedef cmds::GetActiveAttrib::Result Result; |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10916 | Result* result = GetSharedMemoryAs<Result*>( |
| 10917 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 10918 | if (!result) { |
| 10919 | return error::kOutOfBounds; |
| 10920 | } |
[email protected] | 07d0cc8 | 2010-02-17 04:51:40 | [diff] [blame] | 10921 | // Check that the client initialized the result. |
| 10922 | if (result->success != 0) { |
| 10923 | return error::kInvalidArguments; |
| 10924 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10925 | Program* program = GetProgramInfoNotShader( |
| 10926 | program_id, "glGetActiveAttrib"); |
| 10927 | if (!program) { |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10928 | return error::kNoError; |
| 10929 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 10930 | const Program::VertexAttrib* attrib_info = |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10931 | program->GetAttribInfo(index); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10932 | if (!attrib_info) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10933 | LOCAL_SET_GL_ERROR( |
| 10934 | GL_INVALID_VALUE, "glGetActiveAttrib", "index out of range"); |
[email protected] | 0bfd988 | 2010-02-05 23:02:25 | [diff] [blame] | 10935 | return error::kNoError; |
| 10936 | } |
| 10937 | result->success = 1; // true. |
| 10938 | result->size = attrib_info->size; |
| 10939 | result->type = attrib_info->type; |
| 10940 | Bucket* bucket = CreateBucket(name_bucket_id); |
[email protected] | 262d7aa | 2010-12-03 22:07:29 | [diff] [blame] | 10941 | bucket->SetFromString(attrib_info->name.c_str()); |
[email protected] | f7a64ee | 2010-02-01 22:24:14 | [diff] [blame] | 10942 | return error::kNoError; |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 10943 | } |
| 10944 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 10945 | error::Error GLES2DecoderImpl::HandleShaderBinary(uint32 immediate_data_size, |
| 10946 | const void* cmd_data) { |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 10947 | #if 1 // No binary shader support. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10948 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glShaderBinary", "not supported"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 10949 | return error::kNoError; |
| 10950 | #else |
| 10951 | GLsizei n = static_cast<GLsizei>(c.n); |
| 10952 | if (n < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10953 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "n < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 10954 | return error::kNoError; |
| 10955 | } |
| 10956 | GLsizei length = static_cast<GLsizei>(c.length); |
| 10957 | if (length < 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10958 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "length < 0"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 10959 | return error::kNoError; |
| 10960 | } |
| 10961 | uint32 data_size; |
| 10962 | if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { |
| 10963 | return error::kOutOfBounds; |
| 10964 | } |
| 10965 | const GLuint* shaders = GetSharedMemoryAs<const GLuint*>( |
| 10966 | c.shaders_shm_id, c.shaders_shm_offset, data_size); |
| 10967 | GLenum binaryformat = static_cast<GLenum>(c.binaryformat); |
| 10968 | const void* binary = GetSharedMemoryAs<const void*>( |
| 10969 | c.binary_shm_id, c.binary_shm_offset, length); |
| 10970 | if (shaders == NULL || binary == NULL) { |
| 10971 | return error::kOutOfBounds; |
| 10972 | } |
[email protected] | 0782b14b | 2014-05-24 13:04:16 | [diff] [blame] | 10973 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 10974 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10975 | Shader* shader = GetShader(shaders[ii]); |
| 10976 | if (!shader) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 10977 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glShaderBinary", "unknown shader"); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 10978 | return error::kNoError; |
| 10979 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 10980 | service_ids[ii] = shader->service_id(); |
[email protected] | b273e43 | 2010-04-12 17:23:58 | [diff] [blame] | 10981 | } |
| 10982 | // TODO(gman): call glShaderBinary |
| 10983 | return error::kNoError; |
| 10984 | #endif |
| 10985 | } |
| 10986 | |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 10987 | void GLES2DecoderImpl::DoSwapBuffers() { |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 10988 | bool is_offscreen = !!offscreen_target_frame_buffer_.get(); |
[email protected] | a7266a9 | 2012-06-28 02:11:08 | [diff] [blame] | 10989 | |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 10990 | int this_frame_number = frame_number_++; |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 10991 | // TRACE_EVENT for gpu tests: |
| 10992 | TRACE_EVENT_INSTANT2("test_gpu", "SwapBuffersLatency", |
[email protected] | c76faea | 2013-03-26 07:42:42 | [diff] [blame] | 10993 | TRACE_EVENT_SCOPE_THREAD, |
[email protected] | 2ac620e5 | 2012-07-23 20:31:42 | [diff] [blame] | 10994 | "GLImpl", static_cast<int>(gfx::GetGLImplementation()), |
| 10995 | "width", (is_offscreen ? offscreen_size_.width() : |
| 10996 | surface_->GetSize().width())); |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 10997 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoSwapBuffers", |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 10998 | "offscreen", is_offscreen, |
| 10999 | "frame", this_frame_number); |
[email protected] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 11000 | { |
[email protected] | a36ed483 | 2014-04-24 16:40:27 | [diff] [blame] | 11001 | TRACE_EVENT_SYNTHETIC_DELAY("gpu.PresentingFrame"); |
[email protected] | b2e9259 | 2014-01-10 15:47:15 | [diff] [blame] | 11002 | } |
| 11003 | |
dyen | b547eff6 | 2015-01-17 00:14:56 | [diff] [blame] | 11004 | ScopedGPUTrace scoped_gpu_trace(gpu_tracer_.get(), kTraceDecoder, |
| 11005 | "gpu_toplevel", "SwapBuffer"); |
| 11006 | |
[email protected] | 8f9b8dd | 2013-09-12 18:05:13 | [diff] [blame] | 11007 | bool is_tracing; |
| 11008 | TRACE_EVENT_CATEGORY_GROUP_ENABLED(TRACE_DISABLED_BY_DEFAULT("gpu.debug"), |
| 11009 | &is_tracing); |
| 11010 | if (is_tracing) { |
| 11011 | ScopedFrameBufferBinder binder(this, GetBackbufferServiceId()); |
| 11012 | gpu_state_tracer_->TakeSnapshotWithCurrentFramebuffer( |
| 11013 | is_offscreen ? offscreen_size_ : surface_->GetSize()); |
| 11014 | } |
| 11015 | |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 11016 | // If offscreen then don't actually SwapBuffers to the display. Just copy |
| 11017 | // the rendered frame to another frame buffer. |
[email protected] | 64ace85 | 2011-05-19 21:49:49 | [diff] [blame] | 11018 | if (is_offscreen) { |
[email protected] | 111975c6 | 2012-09-06 01:37:31 | [diff] [blame] | 11019 | TRACE_EVENT2("gpu", "Offscreen", |
| 11020 | "width", offscreen_size_.width(), "height", offscreen_size_.height()); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 11021 | if (offscreen_size_ != offscreen_saved_color_texture_->size()) { |
| 11022 | // Workaround for NVIDIA driver bug on OS X; crbug.com/89557, |
| 11023 | // crbug.com/94163. TODO(kbr): figure out reproduction so Apple will |
| 11024 | // fix this. |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 11025 | if (workarounds().needs_offscreen_buffer_workaround) { |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 11026 | offscreen_saved_frame_buffer_->Create(); |
| 11027 | glFinish(); |
| 11028 | } |
| 11029 | |
| 11030 | // Allocate the offscreen saved color texture. |
| 11031 | DCHECK(offscreen_saved_color_format_); |
| 11032 | offscreen_saved_color_texture_->AllocateStorage( |
[email protected] | 678a73f | 2012-12-19 19:22:09 | [diff] [blame] | 11033 | offscreen_size_, offscreen_saved_color_format_, false); |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 11034 | |
| 11035 | offscreen_saved_frame_buffer_->AttachRenderTexture( |
| 11036 | offscreen_saved_color_texture_.get()); |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 11037 | if (offscreen_size_.width() != 0 && offscreen_size_.height() != 0) { |
| 11038 | if (offscreen_saved_frame_buffer_->CheckStatus() != |
| 11039 | GL_FRAMEBUFFER_COMPLETE) { |
| 11040 | LOG(ERROR) << "GLES2DecoderImpl::ResizeOffscreenFrameBuffer failed " |
| 11041 | << "because offscreen saved FBO was incomplete."; |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 11042 | MarkContextLost(error::kUnknown); |
| 11043 | group_->LoseContexts(error::kUnknown); |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 11044 | return; |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 11045 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 11046 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 11047 | // Clear the offscreen color texture. |
| 11048 | // TODO(piman): Is this still necessary? |
| 11049 | { |
| 11050 | ScopedFrameBufferBinder binder(this, |
| 11051 | offscreen_saved_frame_buffer_->id()); |
| 11052 | glClearColor(0, 0, 0, 0); |
[email protected] | 454157e | 2014-05-03 02:49:45 | [diff] [blame] | 11053 | state_.SetDeviceColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); |
| 11054 | state_.SetDeviceCapabilityState(GL_SCISSOR_TEST, false); |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 11055 | glClear(GL_COLOR_BUFFER_BIT); |
| 11056 | RestoreClearState(); |
| 11057 | } |
[email protected] | 1fb8c48 | 2011-08-31 01:01:53 | [diff] [blame] | 11058 | } |
| 11059 | |
| 11060 | UpdateParentTextureInfo(); |
| 11061 | } |
| 11062 | |
[email protected] | f0cfe75 | 2013-01-14 01:09:05 | [diff] [blame] | 11063 | if (offscreen_size_.width() == 0 || offscreen_size_.height() == 0) |
[email protected] | 6d792ee1 | 2013-05-15 00:40:56 | [diff] [blame] | 11064 | return; |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11065 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 11066 | "GLES2DecoderImpl::DoSwapBuffers", GetErrorState()); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 11067 | |
[email protected] | 34ff8b0c | 2010-10-01 20:06:02 | [diff] [blame] | 11068 | if (IsOffscreenBufferMultisampled()) { |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 11069 | // For multisampled buffers, resolve the frame buffer. |
[email protected] | de26b3c | 2011-08-03 21:54:27 | [diff] [blame] | 11070 | ScopedResolvedFrameBufferBinder binder(this, true, false); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 11071 | } else { |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 11072 | ScopedFrameBufferBinder binder(this, |
| 11073 | offscreen_target_frame_buffer_->id()); |
[email protected] | 51411e3 | 2012-01-19 20:21:13 | [diff] [blame] | 11074 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 11075 | if (offscreen_target_buffer_preserved_) { |
| 11076 | // Copy the target frame buffer to the saved offscreen texture. |
| 11077 | offscreen_saved_color_texture_->Copy( |
| 11078 | offscreen_saved_color_texture_->size(), |
| 11079 | offscreen_saved_color_format_); |
| 11080 | } else { |
| 11081 | // Flip the textures in the parent context via the texture manager. |
| 11082 | if (!!offscreen_saved_color_texture_info_.get()) |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11083 | offscreen_saved_color_texture_info_->texture()-> |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 11084 | SetServiceId(offscreen_target_color_texture_->id()); |
[email protected] | 8a61d87 | 2012-01-20 12:43:56 | [diff] [blame] | 11085 | |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 11086 | offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); |
| 11087 | offscreen_target_frame_buffer_->AttachRenderTexture( |
| 11088 | offscreen_target_color_texture_.get()); |
[email protected] | b86b1498 | 2010-10-11 18:45:48 | [diff] [blame] | 11089 | } |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 11090 | |
| 11091 | // Ensure the side effects of the copy are visible to the parent |
| 11092 | // context. There is no need to do this for ANGLE because it uses a |
| 11093 | // single D3D device for all contexts. |
marcheu | 1856f5d5 | 2015-04-04 01:42:53 | [diff] [blame] | 11094 | if (!feature_info_->gl_version_info().is_angle) |
[email protected] | 06994467 | 2012-04-25 20:52:23 | [diff] [blame] | 11095 | glFlush(); |
[email protected] | 0c8c9d2 | 2010-06-25 17:36:39 | [diff] [blame] | 11096 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 11097 | } else { |
achaulk | ec8c2db | 2015-05-29 16:35:03 | [diff] [blame] | 11098 | if (surface_->SwapBuffers() == gfx::SwapResult::SWAP_FAILED) { |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 11099 | LOG(ERROR) << "Context lost because SwapBuffers failed."; |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 11100 | if (!CheckResetStatus()) { |
| 11101 | MarkContextLost(error::kUnknown); |
| 11102 | group_->LoseContexts(error::kUnknown); |
| 11103 | } |
[email protected] | d049874 | 2010-09-20 20:27:01 | [diff] [blame] | 11104 | } |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 11105 | } |
vmiura | 8266ca7 | 2014-09-09 21:37:00 | [diff] [blame] | 11106 | |
| 11107 | // This may be a slow command. Exit command processing to allow for |
| 11108 | // context preemption and GPU watchdog checks. |
| 11109 | ExitCommandProcessingEarly(); |
[email protected] | 6217d39 | 2010-03-25 22:08:35 | [diff] [blame] | 11110 | } |
| 11111 | |
dcastagna | 504d45c | 2015-04-06 19:30:39 | [diff] [blame] | 11112 | void GLES2DecoderImpl::DoSwapInterval(int interval) { |
bajones | 2345c1f | 2014-12-09 04:45:51 | [diff] [blame] | 11113 | context_->SetSwapInterval(interval); |
| 11114 | } |
| 11115 | |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 11116 | error::Error GLES2DecoderImpl::HandleEnableFeatureCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11117 | uint32 immediate_data_size, |
| 11118 | const void* cmd_data) { |
| 11119 | const gles2::cmds::EnableFeatureCHROMIUM& c = |
| 11120 | *static_cast<const gles2::cmds::EnableFeatureCHROMIUM*>(cmd_data); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 11121 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 11122 | if (!bucket || bucket->size() == 0) { |
| 11123 | return error::kInvalidArguments; |
| 11124 | } |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 11125 | typedef cmds::EnableFeatureCHROMIUM::Result Result; |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 11126 | Result* result = GetSharedMemoryAs<Result*>( |
| 11127 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 11128 | if (!result) { |
| 11129 | return error::kOutOfBounds; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 11130 | } |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 11131 | // Check that the client initialized the result. |
| 11132 | if (*result != 0) { |
| 11133 | return error::kInvalidArguments; |
| 11134 | } |
| 11135 | std::string feature_str; |
| 11136 | if (!bucket->GetAsString(&feature_str)) { |
| 11137 | return error::kInvalidArguments; |
| 11138 | } |
| 11139 | |
| 11140 | // TODO(gman): make this some kind of table to function pointer thingy. |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 11141 | if (feature_str.compare("pepper3d_allow_buffers_on_multiple_targets") == 0) { |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 11142 | buffer_manager()->set_allow_buffers_on_multiple_targets(true); |
[email protected] | d423985 | 2011-08-12 04:51:22 | [diff] [blame] | 11143 | } else if (feature_str.compare("pepper3d_support_fixed_attribs") == 0) { |
penghuang | 0140c18 | 2015-01-12 23:20:12 | [diff] [blame] | 11144 | buffer_manager()->set_allow_fixed_attribs(true); |
[email protected] | 8fbedc0 | 2010-11-18 18:43:40 | [diff] [blame] | 11145 | // TODO(gman): decide how to remove the need for this const_cast. |
| 11146 | // I could make validators_ non const but that seems bad as this is the only |
| 11147 | // place it is needed. I could make some special friend class of validators |
| 11148 | // just to allow this to set them. That seems silly. I could refactor this |
| 11149 | // code to use the extension mechanism or the initialization attributes to |
| 11150 | // turn this feature on. Given that the only real point of this is to make |
| 11151 | // the conformance tests pass and given that there is lots of real work that |
| 11152 | // needs to be done it seems like refactoring for one to one of those |
| 11153 | // methods is a very low priority. |
| 11154 | const_cast<Validators*>(validators_)->vertex_attrib_type.AddValue(GL_FIXED); |
[email protected] | b1d2dcb | 2010-05-17 19:24:18 | [diff] [blame] | 11155 | } else { |
| 11156 | return error::kNoError; |
| 11157 | } |
| 11158 | |
| 11159 | *result = 1; // true. |
| 11160 | return error::kNoError; |
[email protected] | 4e8a5b12 | 2010-05-08 22:00:10 | [diff] [blame] | 11161 | } |
| 11162 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 11163 | error::Error GLES2DecoderImpl::HandleGetRequestableExtensionsCHROMIUM( |
| 11164 | uint32 immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11165 | const void* cmd_data) { |
| 11166 | const gles2::cmds::GetRequestableExtensionsCHROMIUM& c = |
| 11167 | *static_cast<const gles2::cmds::GetRequestableExtensionsCHROMIUM*>( |
| 11168 | cmd_data); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 11169 | Bucket* bucket = CreateBucket(c.bucket_id); |
[email protected] | ed9f9cd | 2013-02-27 21:12:35 | [diff] [blame] | 11170 | scoped_refptr<FeatureInfo> info(new FeatureInfo()); |
[email protected] | 956aec5 | 2013-09-05 15:41:19 | [diff] [blame] | 11171 | info->Initialize(disallowed_features_); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 11172 | bucket->SetFromString(info->extensions().c_str()); |
| 11173 | return error::kNoError; |
| 11174 | } |
| 11175 | |
| 11176 | error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11177 | uint32 immediate_data_size, |
| 11178 | const void* cmd_data) { |
| 11179 | const gles2::cmds::RequestExtensionCHROMIUM& c = |
| 11180 | *static_cast<const gles2::cmds::RequestExtensionCHROMIUM*>(cmd_data); |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 11181 | Bucket* bucket = GetBucket(c.bucket_id); |
[email protected] | 12f93d8 | 2011-10-17 21:16:28 | [diff] [blame] | 11182 | if (!bucket || bucket->size() == 0) { |
| 11183 | return error::kInvalidArguments; |
| 11184 | } |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 11185 | std::string feature_str; |
| 11186 | if (!bucket->GetAsString(&feature_str)) { |
| 11187 | return error::kInvalidArguments; |
| 11188 | } |
| 11189 | |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 11190 | bool desire_standard_derivatives = false; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 11191 | bool desire_frag_depth = false; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 11192 | bool desire_draw_buffers = false; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 11193 | bool desire_shader_texture_lod = false; |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 11194 | if (IsWebGLContext()) { |
[email protected] | 4b7eba9 | 2013-01-08 02:23:56 | [diff] [blame] | 11195 | desire_standard_derivatives = |
| 11196 | feature_str.find("GL_OES_standard_derivatives") != std::string::npos; |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 11197 | desire_frag_depth = |
| 11198 | feature_str.find("GL_EXT_frag_depth") != std::string::npos; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 11199 | desire_draw_buffers = |
| 11200 | feature_str.find("GL_EXT_draw_buffers") != std::string::npos; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 11201 | desire_shader_texture_lod = |
| 11202 | feature_str.find("GL_EXT_shader_texture_lod") != std::string::npos; |
[email protected] | f0d7474 | 2011-10-03 16:31:04 | [diff] [blame] | 11203 | } |
| 11204 | |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 11205 | if (desire_standard_derivatives != derivatives_explicitly_enabled_ || |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 11206 | desire_frag_depth != frag_depth_explicitly_enabled_ || |
zmo | 539d22c | 2015-06-09 04:14:19 | [diff] [blame] | 11207 | desire_draw_buffers != draw_buffers_explicitly_enabled_ || |
| 11208 | desire_shader_texture_lod != shader_texture_lod_explicitly_enabled_) { |
[email protected] | 70dc6093 | 2013-06-04 03:33:49 | [diff] [blame] | 11209 | derivatives_explicitly_enabled_ |= desire_standard_derivatives; |
| 11210 | frag_depth_explicitly_enabled_ |= desire_frag_depth; |
[email protected] | aff39ac8 | 2013-06-08 04:53:13 | [diff] [blame] | 11211 | draw_buffers_explicitly_enabled_ |= desire_draw_buffers; |
[email protected] | 93c2fd8 | 2014-04-16 02:46:06 | [diff] [blame] | 11212 | shader_texture_lod_explicitly_enabled_ |= desire_shader_texture_lod; |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 11213 | InitializeShaderTranslator(); |
| 11214 | } |
| 11215 | |
[email protected] | 302ce6d | 2011-07-07 23:28:11 | [diff] [blame] | 11216 | UpdateCapabilities(); |
| 11217 | |
[email protected] | c2f8c840 | 2010-12-06 18:07:24 | [diff] [blame] | 11218 | return error::kNoError; |
| 11219 | } |
| 11220 | |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 11221 | error::Error GLES2DecoderImpl::HandleGetProgramInfoCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11222 | uint32 immediate_data_size, |
| 11223 | const void* cmd_data) { |
| 11224 | const gles2::cmds::GetProgramInfoCHROMIUM& c = |
| 11225 | *static_cast<const gles2::cmds::GetProgramInfoCHROMIUM*>(cmd_data); |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 11226 | GLuint program_id = static_cast<GLuint>(c.program); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 11227 | uint32 bucket_id = c.bucket_id; |
| 11228 | Bucket* bucket = CreateBucket(bucket_id); |
| 11229 | bucket->SetSize(sizeof(ProgramInfoHeader)); // in case we fail. |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 11230 | Program* program = NULL; |
| 11231 | program = GetProgram(program_id); |
| 11232 | if (!program || !program->IsValid()) { |
[email protected] | 9a14ae61 | 2011-08-08 17:51:46 | [diff] [blame] | 11233 | return error::kNoError; |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 11234 | } |
[email protected] | df37b993 | 2013-03-08 05:21:42 | [diff] [blame] | 11235 | program->GetProgramInfo(program_manager(), bucket); |
[email protected] | 2318d34 | 2011-07-11 22:27:42 | [diff] [blame] | 11236 | return error::kNoError; |
| 11237 | } |
| 11238 | |
zmo | 4a16ff99 | 2015-02-05 22:18:41 | [diff] [blame] | 11239 | error::Error GLES2DecoderImpl::HandleGetUniformBlocksCHROMIUM( |
| 11240 | uint32 immediate_data_size, const void* cmd_data) { |
| 11241 | if (!unsafe_es3_apis_enabled()) |
| 11242 | return error::kUnknownCommand; |
| 11243 | const gles2::cmds::GetUniformBlocksCHROMIUM& c = |
| 11244 | *static_cast<const gles2::cmds::GetUniformBlocksCHROMIUM*>(cmd_data); |
| 11245 | GLuint program_id = static_cast<GLuint>(c.program); |
| 11246 | uint32 bucket_id = c.bucket_id; |
| 11247 | Bucket* bucket = CreateBucket(bucket_id); |
| 11248 | bucket->SetSize(sizeof(UniformBlocksHeader)); // in case we fail. |
| 11249 | Program* program = NULL; |
| 11250 | program = GetProgram(program_id); |
| 11251 | if (!program || !program->IsValid()) { |
| 11252 | return error::kNoError; |
| 11253 | } |
| 11254 | program->GetUniformBlocks(bucket); |
| 11255 | return error::kNoError; |
| 11256 | } |
| 11257 | |
zmo | c7e7e13f | 2015-02-17 22:07:07 | [diff] [blame] | 11258 | error::Error GLES2DecoderImpl::HandleGetUniformsES3CHROMIUM( |
| 11259 | uint32 immediate_data_size, const void* cmd_data) { |
| 11260 | if (!unsafe_es3_apis_enabled()) |
| 11261 | return error::kUnknownCommand; |
| 11262 | const gles2::cmds::GetUniformsES3CHROMIUM& c = |
| 11263 | *static_cast<const gles2::cmds::GetUniformsES3CHROMIUM*>(cmd_data); |
| 11264 | GLuint program_id = static_cast<GLuint>(c.program); |
| 11265 | uint32 bucket_id = c.bucket_id; |
| 11266 | Bucket* bucket = CreateBucket(bucket_id); |
| 11267 | bucket->SetSize(sizeof(UniformsES3Header)); // in case we fail. |
| 11268 | Program* program = NULL; |
| 11269 | program = GetProgram(program_id); |
| 11270 | if (!program || !program->IsValid()) { |
| 11271 | return error::kNoError; |
| 11272 | } |
| 11273 | program->GetUniformsES3(bucket); |
| 11274 | return error::kNoError; |
| 11275 | } |
| 11276 | |
zmo | 1084249 | 2015-02-12 00:44:16 | [diff] [blame] | 11277 | error::Error GLES2DecoderImpl::HandleGetTransformFeedbackVarying( |
| 11278 | uint32 immediate_data_size, |
| 11279 | const void* cmd_data) { |
| 11280 | if (!unsafe_es3_apis_enabled()) |
| 11281 | return error::kUnknownCommand; |
| 11282 | const gles2::cmds::GetTransformFeedbackVarying& c = |
| 11283 | *static_cast<const gles2::cmds::GetTransformFeedbackVarying*>(cmd_data); |
| 11284 | GLuint program_id = c.program; |
| 11285 | GLuint index = c.index; |
| 11286 | uint32 name_bucket_id = c.name_bucket_id; |
| 11287 | typedef cmds::GetTransformFeedbackVarying::Result Result; |
| 11288 | Result* result = GetSharedMemoryAs<Result*>( |
| 11289 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 11290 | if (!result) { |
| 11291 | return error::kOutOfBounds; |
| 11292 | } |
| 11293 | // Check that the client initialized the result. |
| 11294 | if (result->success != 0) { |
| 11295 | return error::kInvalidArguments; |
| 11296 | } |
| 11297 | Program* program = GetProgramInfoNotShader( |
| 11298 | program_id, "glGetTransformFeedbackVarying"); |
| 11299 | if (!program) { |
| 11300 | return error::kNoError; |
| 11301 | } |
| 11302 | GLuint service_id = program->service_id(); |
| 11303 | GLint link_status = GL_FALSE; |
| 11304 | glGetProgramiv(service_id, GL_LINK_STATUS, &link_status); |
| 11305 | if (link_status != GL_TRUE) { |
| 11306 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 11307 | "glGetTransformFeedbackVarying", "program not linked"); |
| 11308 | return error::kNoError; |
| 11309 | } |
| 11310 | GLint max_length = 0; |
| 11311 | glGetProgramiv( |
| 11312 | service_id, GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, &max_length); |
| 11313 | max_length = std::max(1, max_length); |
| 11314 | std::vector<char> buffer(max_length); |
| 11315 | GLsizei length = 0; |
| 11316 | GLsizei size = 0; |
| 11317 | GLenum type = 0; |
| 11318 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("GetTransformFeedbackVarying"); |
| 11319 | glGetTransformFeedbackVarying( |
| 11320 | service_id, index, max_length, &length, &size, &type, &buffer[0]); |
| 11321 | GLenum error = glGetError(); |
| 11322 | if (error != GL_NO_ERROR) { |
| 11323 | LOCAL_SET_GL_ERROR(error, "glGetTransformFeedbackVarying", ""); |
| 11324 | return error::kNoError; |
| 11325 | } |
| 11326 | result->success = 1; // true. |
| 11327 | result->size = static_cast<int32_t>(size); |
| 11328 | result->type = static_cast<uint32_t>(type); |
| 11329 | Bucket* bucket = CreateBucket(name_bucket_id); |
| 11330 | DCHECK(length >= 0 && length < max_length); |
| 11331 | buffer[length] = '\0'; // Just to be safe. |
| 11332 | bucket->SetFromString(&buffer[0]); |
| 11333 | return error::kNoError; |
| 11334 | } |
| 11335 | |
| 11336 | error::Error GLES2DecoderImpl::HandleGetTransformFeedbackVaryingsCHROMIUM( |
| 11337 | uint32 immediate_data_size, const void* cmd_data) { |
| 11338 | if (!unsafe_es3_apis_enabled()) |
| 11339 | return error::kUnknownCommand; |
| 11340 | const gles2::cmds::GetTransformFeedbackVaryingsCHROMIUM& c = |
| 11341 | *static_cast<const gles2::cmds::GetTransformFeedbackVaryingsCHROMIUM*>( |
| 11342 | cmd_data); |
| 11343 | GLuint program_id = static_cast<GLuint>(c.program); |
| 11344 | uint32 bucket_id = c.bucket_id; |
| 11345 | Bucket* bucket = CreateBucket(bucket_id); |
| 11346 | bucket->SetSize(sizeof(TransformFeedbackVaryingsHeader)); // in case we fail. |
| 11347 | Program* program = NULL; |
| 11348 | program = GetProgram(program_id); |
| 11349 | if (!program || !program->IsValid()) { |
| 11350 | return error::kNoError; |
| 11351 | } |
| 11352 | program->GetTransformFeedbackVaryings(bucket); |
| 11353 | return error::kNoError; |
| 11354 | } |
| 11355 | |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 11356 | error::ContextLostReason GLES2DecoderImpl::GetContextLostReason() { |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 11357 | return context_lost_reason_; |
| 11358 | } |
| 11359 | |
| 11360 | error::ContextLostReason GLES2DecoderImpl::GetContextLostReasonFromResetStatus( |
| 11361 | GLenum reset_status) const { |
| 11362 | switch (reset_status) { |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 11363 | case GL_NO_ERROR: |
| 11364 | // TODO(kbr): improve the precision of the error code in this case. |
| 11365 | // Consider delegating to context for error code if MakeCurrent fails. |
| 11366 | return error::kUnknown; |
| 11367 | case GL_GUILTY_CONTEXT_RESET_ARB: |
| 11368 | return error::kGuilty; |
| 11369 | case GL_INNOCENT_CONTEXT_RESET_ARB: |
| 11370 | return error::kInnocent; |
| 11371 | case GL_UNKNOWN_CONTEXT_RESET_ARB: |
| 11372 | return error::kUnknown; |
[email protected] | 38d139d | 2011-07-14 00:38:43 | [diff] [blame] | 11373 | } |
| 11374 | |
| 11375 | NOTREACHED(); |
| 11376 | return error::kUnknown; |
| 11377 | } |
| 11378 | |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 11379 | bool GLES2DecoderImpl::WasContextLost() const { |
| 11380 | return context_was_lost_; |
| 11381 | } |
| 11382 | |
| 11383 | bool GLES2DecoderImpl::WasContextLostByRobustnessExtension() const { |
| 11384 | return WasContextLost() && reset_by_robustness_extension_; |
| 11385 | } |
| 11386 | |
| 11387 | void GLES2DecoderImpl::MarkContextLost(error::ContextLostReason reason) { |
| 11388 | // Only lose the context once. |
| 11389 | if (WasContextLost()) |
| 11390 | return; |
| 11391 | |
| 11392 | // Don't make GL calls in here, the context might not be current. |
| 11393 | context_lost_reason_ = reason; |
| 11394 | current_decoder_error_ = error::kLostContext; |
| 11395 | context_was_lost_ = true; |
jbauman | 7a05931 | 2014-10-16 19:30:54 | [diff] [blame] | 11396 | } |
| 11397 | |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 11398 | bool GLES2DecoderImpl::CheckResetStatus() { |
| 11399 | DCHECK(!WasContextLost()); |
| 11400 | DCHECK(context_->IsCurrent(NULL)); |
| 11401 | |
dongseong.hwang | e1cb2aa | 2015-02-11 09:33:33 | [diff] [blame] | 11402 | if (IsRobustnessSupported()) { |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 11403 | // If the reason for the call was a GL error, we can try to determine the |
| 11404 | // reset status more accurately. |
| 11405 | GLenum driver_status = glGetGraphicsResetStatusARB(); |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 11406 | if (driver_status == GL_NO_ERROR) |
| 11407 | return false; |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 11408 | |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 11409 | LOG(ERROR) << (surface_->IsOffscreen() ? "Offscreen" : "Onscreen") |
| 11410 | << " context lost via ARB/EXT_robustness. Reset status = " |
| 11411 | << GLES2Util::GetStringEnum(driver_status); |
| 11412 | |
| 11413 | // Don't pretend we know which client was responsible. |
| 11414 | if (workarounds().use_virtualized_gl_contexts) |
| 11415 | driver_status = GL_UNKNOWN_CONTEXT_RESET_ARB; |
| 11416 | |
| 11417 | switch (driver_status) { |
| 11418 | case GL_GUILTY_CONTEXT_RESET_ARB: |
| 11419 | MarkContextLost(error::kGuilty); |
| 11420 | break; |
| 11421 | case GL_INNOCENT_CONTEXT_RESET_ARB: |
| 11422 | MarkContextLost(error::kInnocent); |
| 11423 | break; |
| 11424 | case GL_UNKNOWN_CONTEXT_RESET_ARB: |
| 11425 | MarkContextLost(error::kUnknown); |
| 11426 | break; |
| 11427 | default: |
| 11428 | NOTREACHED(); |
| 11429 | return false; |
| 11430 | } |
| 11431 | reset_by_robustness_extension_ = true; |
| 11432 | return true; |
| 11433 | } |
| 11434 | return false; |
[email protected] | c4485aad6 | 2012-12-17 10:19:09 | [diff] [blame] | 11435 | } |
| 11436 | |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 11437 | error::Error GLES2DecoderImpl::HandleInsertSyncPointCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11438 | uint32 immediate_data_size, |
| 11439 | const void* cmd_data) { |
[email protected] | b096d03 | 2013-03-08 03:08:01 | [diff] [blame] | 11440 | return error::kUnknownCommand; |
| 11441 | } |
| 11442 | |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 11443 | error::Error GLES2DecoderImpl::HandleWaitSyncPointCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11444 | uint32 immediate_data_size, |
| 11445 | const void* cmd_data) { |
| 11446 | const gles2::cmds::WaitSyncPointCHROMIUM& c = |
| 11447 | *static_cast<const gles2::cmds::WaitSyncPointCHROMIUM*>(cmd_data); |
sievers | 173a20d | 2014-10-22 18:19:32 | [diff] [blame] | 11448 | uint32 sync_point = c.sync_point; |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 11449 | if (wait_sync_point_callback_.is_null()) |
| 11450 | return error::kNoError; |
| 11451 | |
sievers | 173a20d | 2014-10-22 18:19:32 | [diff] [blame] | 11452 | return wait_sync_point_callback_.Run(sync_point) ? |
[email protected] | 840a7e46 | 2013-02-27 01:29:51 | [diff] [blame] | 11453 | error::kNoError : error::kDeferCommandUntilLater; |
| 11454 | } |
| 11455 | |
[email protected] | 5dfc457b | 2013-12-13 11:13:07 | [diff] [blame] | 11456 | error::Error GLES2DecoderImpl::HandleDiscardBackbufferCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11457 | uint32 immediate_data_size, |
| 11458 | const void* cmd_data) { |
[email protected] | 5dfc457b | 2013-12-13 11:13:07 | [diff] [blame] | 11459 | if (surface_->DeferDraws()) |
| 11460 | return error::kDeferCommandUntilLater; |
| 11461 | if (!surface_->SetBackbufferAllocation(false)) |
| 11462 | return error::kLostContext; |
| 11463 | backbuffer_needs_clear_bits_ |= GL_COLOR_BUFFER_BIT; |
| 11464 | backbuffer_needs_clear_bits_ |= GL_DEPTH_BUFFER_BIT; |
| 11465 | backbuffer_needs_clear_bits_ |= GL_STENCIL_BUFFER_BIT; |
| 11466 | return error::kNoError; |
| 11467 | } |
| 11468 | |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11469 | bool GLES2DecoderImpl::GenQueriesEXTHelper( |
| 11470 | GLsizei n, const GLuint* client_ids) { |
| 11471 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 11472 | if (query_manager_->GetQuery(client_ids[ii])) { |
| 11473 | return false; |
| 11474 | } |
| 11475 | } |
[email protected] | 4eea7e6 | 2014-04-22 21:14:43 | [diff] [blame] | 11476 | query_manager_->GenQueries(n, client_ids); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11477 | return true; |
| 11478 | } |
| 11479 | |
| 11480 | void GLES2DecoderImpl::DeleteQueriesEXTHelper( |
| 11481 | GLsizei n, const GLuint* client_ids) { |
| 11482 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 11483 | QueryManager::Query* query = query_manager_->GetQuery(client_ids[ii]); |
| 11484 | if (query && !query->IsDeleted()) { |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 11485 | ContextState::QueryMap::iterator it = |
| 11486 | state_.current_queries.find(query->target()); |
| 11487 | if (it != state_.current_queries.end()) |
| 11488 | state_.current_queries.erase(it); |
| 11489 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 11490 | query->Destroy(true); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11491 | } |
[email protected] | 4eea7e6 | 2014-04-22 21:14:43 | [diff] [blame] | 11492 | query_manager_->RemoveQuery(client_ids[ii]); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11493 | } |
| 11494 | } |
| 11495 | |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 11496 | bool GLES2DecoderImpl::ProcessPendingQueries(bool did_finish) { |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 11497 | if (query_manager_.get() == NULL) { |
| 11498 | return false; |
| 11499 | } |
reveman | cc241eb | 2014-11-11 03:30:37 | [diff] [blame] | 11500 | if (!query_manager_->ProcessPendingQueries(did_finish)) { |
[email protected] | 22e3f55 | 2012-03-13 01:54:19 | [diff] [blame] | 11501 | current_decoder_error_ = error::kOutOfBounds; |
| 11502 | } |
| 11503 | return query_manager_->HavePendingQueries(); |
| 11504 | } |
| 11505 | |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 11506 | // Note that if there are no pending readpixels right now, |
| 11507 | // this function will call the callback immediately. |
| 11508 | void GLES2DecoderImpl::WaitForReadPixels(base::Closure callback) { |
| 11509 | if (features().use_async_readpixels && !pending_readpixel_fences_.empty()) { |
| 11510 | pending_readpixel_fences_.back()->callbacks.push_back(callback); |
| 11511 | } else { |
| 11512 | callback.Run(); |
| 11513 | } |
| 11514 | } |
| 11515 | |
| 11516 | void GLES2DecoderImpl::ProcessPendingReadPixels() { |
| 11517 | while (!pending_readpixel_fences_.empty() && |
| 11518 | pending_readpixel_fences_.front()->fence->HasCompleted()) { |
| 11519 | std::vector<base::Closure> callbacks = |
| 11520 | pending_readpixel_fences_.front()->callbacks; |
| 11521 | pending_readpixel_fences_.pop(); |
| 11522 | for (size_t i = 0; i < callbacks.size(); i++) { |
| 11523 | callbacks[i].Run(); |
| 11524 | } |
| 11525 | } |
| 11526 | } |
| 11527 | |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 11528 | bool GLES2DecoderImpl::HasMoreIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 11529 | return !pending_readpixel_fences_.empty() || |
| 11530 | async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 11531 | } |
| 11532 | |
| 11533 | void GLES2DecoderImpl::PerformIdleWork() { |
[email protected] | 5a36dc13 | 2013-07-23 23:17:55 | [diff] [blame] | 11534 | ProcessPendingReadPixels(); |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 11535 | if (!async_pixel_transfer_manager_->NeedsProcessMorePendingTransfers()) |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 11536 | return; |
[email protected] | b68b10075 | 2013-06-05 08:34:48 | [diff] [blame] | 11537 | async_pixel_transfer_manager_->ProcessMorePendingTransfers(); |
[email protected] | 2b1767cf | 2013-03-16 09:25:05 | [diff] [blame] | 11538 | ProcessFinishedAsyncTransfers(); |
| 11539 | } |
| 11540 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11541 | error::Error GLES2DecoderImpl::HandleBeginQueryEXT(uint32 immediate_data_size, |
| 11542 | const void* cmd_data) { |
| 11543 | const gles2::cmds::BeginQueryEXT& c = |
| 11544 | *static_cast<const gles2::cmds::BeginQueryEXT*>(cmd_data); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11545 | GLenum target = static_cast<GLenum>(c.target); |
| 11546 | GLuint client_id = static_cast<GLuint>(c.id); |
| 11547 | int32 sync_shm_id = static_cast<int32>(c.sync_data_shm_id); |
| 11548 | uint32 sync_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 11549 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 11550 | switch (target) { |
| 11551 | case GL_COMMANDS_ISSUED_CHROMIUM: |
[email protected] | fb4bf582 | 2012-10-23 21:25:55 | [diff] [blame] | 11552 | case GL_LATENCY_QUERY_CHROMIUM: |
[email protected] | 5537605d | 2013-08-27 05:22:31 | [diff] [blame] | 11553 | case GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM: |
| 11554 | case GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM: |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 11555 | case GL_GET_ERROR_QUERY_CHROMIUM: |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 11556 | break; |
[email protected] | 6a25ae42 | 2014-04-17 23:48:27 | [diff] [blame] | 11557 | case GL_COMMANDS_COMPLETED_CHROMIUM: |
| 11558 | if (!features().chromium_sync_query) { |
| 11559 | LOCAL_SET_GL_ERROR( |
| 11560 | GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 11561 | "not enabled for commands completed queries"); |
| 11562 | return error::kNoError; |
| 11563 | } |
| 11564 | break; |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 11565 | default: |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 11566 | if (!features().occlusion_query_boolean) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11567 | LOCAL_SET_GL_ERROR( |
[email protected] | 620b0db0 | 2013-03-20 15:47:00 | [diff] [blame] | 11568 | GL_INVALID_OPERATION, "glBeginQueryEXT", |
| 11569 | "not enabled for occlusion queries"); |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 11570 | return error::kNoError; |
| 11571 | } |
| 11572 | break; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11573 | } |
| 11574 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 11575 | if (state_.current_queries.find(target) != state_.current_queries.end()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11576 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 11577 | GL_INVALID_OPERATION, "glBeginQueryEXT", "query already in progress"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11578 | return error::kNoError; |
| 11579 | } |
| 11580 | |
| 11581 | if (client_id == 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11582 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBeginQueryEXT", "id is 0"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11583 | return error::kNoError; |
| 11584 | } |
| 11585 | |
| 11586 | QueryManager::Query* query = query_manager_->GetQuery(client_id); |
| 11587 | if (!query) { |
[email protected] | 4eea7e6 | 2014-04-22 21:14:43 | [diff] [blame] | 11588 | if (!query_manager_->IsValidQuery(client_id)) { |
| 11589 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 11590 | "glBeginQueryEXT", |
| 11591 | "id not made by glGenQueriesEXT"); |
| 11592 | return error::kNoError; |
| 11593 | } |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 11594 | query = query_manager_->CreateQuery( |
| 11595 | target, client_id, sync_shm_id, sync_shm_offset); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11596 | } |
| 11597 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 11598 | if (query->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11599 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 11600 | GL_INVALID_OPERATION, "glBeginQueryEXT", "target does not match"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11601 | return error::kNoError; |
| 11602 | } else if (query->shm_id() != sync_shm_id || |
| 11603 | query->shm_offset() != sync_shm_offset) { |
| 11604 | DLOG(ERROR) << "Shared memory used by query not the same as before"; |
| 11605 | return error::kInvalidArguments; |
| 11606 | } |
| 11607 | |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 11608 | if (!query_manager_->BeginQuery(query)) { |
| 11609 | return error::kOutOfBounds; |
| 11610 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11611 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 11612 | state_.current_queries[target] = query; |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11613 | return error::kNoError; |
| 11614 | } |
| 11615 | |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 11616 | error::Error GLES2DecoderImpl::HandleEndQueryEXT(uint32 immediate_data_size, |
| 11617 | const void* cmd_data) { |
| 11618 | const gles2::cmds::EndQueryEXT& c = |
| 11619 | *static_cast<const gles2::cmds::EndQueryEXT*>(cmd_data); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11620 | GLenum target = static_cast<GLenum>(c.target); |
| 11621 | uint32 submit_count = static_cast<GLuint>(c.submit_count); |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 11622 | ContextState::QueryMap::iterator it = state_.current_queries.find(target); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11623 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 11624 | if (it == state_.current_queries.end()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11625 | LOCAL_SET_GL_ERROR( |
| 11626 | GL_INVALID_OPERATION, "glEndQueryEXT", "No active query"); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11627 | return error::kNoError; |
| 11628 | } |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11629 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 11630 | QueryManager::Query* query = it->second.get(); |
| 11631 | if (!query_manager_->EndQuery(query, submit_count)) { |
[email protected] | c45f197 | 2012-03-14 07:27:36 | [diff] [blame] | 11632 | return error::kOutOfBounds; |
| 11633 | } |
| 11634 | |
[email protected] | fe8d73c | 2013-02-16 22:37:32 | [diff] [blame] | 11635 | query_manager_->ProcessPendingTransferQueries(); |
| 11636 | |
[email protected] | 8ebd46c | 2014-01-08 12:06:13 | [diff] [blame] | 11637 | state_.current_queries.erase(it); |
[email protected] | 882ba1e2 | 2012-03-08 19:02:53 | [diff] [blame] | 11638 | return error::kNoError; |
| 11639 | } |
| 11640 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11641 | bool GLES2DecoderImpl::GenVertexArraysOESHelper( |
| 11642 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11643 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 11644 | if (GetVertexAttribManager(client_ids[ii])) { |
| 11645 | return false; |
| 11646 | } |
| 11647 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11648 | |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 11649 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11650 | // Emulated VAO |
| 11651 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 11652 | CreateVertexAttribManager(client_ids[ii], 0, true); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11653 | } |
| 11654 | } else { |
[email protected] | 40d90a2 | 2013-04-09 03:39:55 | [diff] [blame] | 11655 | scoped_ptr<GLuint[]> service_ids(new GLuint[n]); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11656 | |
| 11657 | glGenVertexArraysOES(n, service_ids.get()); |
| 11658 | for (GLsizei ii = 0; ii < n; ++ii) { |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 11659 | CreateVertexAttribManager(client_ids[ii], service_ids[ii], true); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11660 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11661 | } |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11662 | |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11663 | return true; |
| 11664 | } |
| 11665 | |
| 11666 | void GLES2DecoderImpl::DeleteVertexArraysOESHelper( |
| 11667 | GLsizei n, const GLuint* client_ids) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11668 | for (GLsizei ii = 0; ii < n; ++ii) { |
| 11669 | VertexAttribManager* vao = |
| 11670 | GetVertexAttribManager(client_ids[ii]); |
| 11671 | if (vao && !vao->IsDeleted()) { |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 11672 | if (state_.vertex_attrib_manager.get() == vao) { |
[email protected] | 242c982 | 2014-04-15 21:36:11 | [diff] [blame] | 11673 | DoBindVertexArrayOES(0); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11674 | } |
| 11675 | RemoveVertexAttribManager(client_ids[ii]); |
| 11676 | } |
| 11677 | } |
| 11678 | } |
| 11679 | |
| 11680 | void GLES2DecoderImpl::DoBindVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11681 | VertexAttribManager* vao = NULL; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11682 | if (client_id != 0) { |
| 11683 | vao = GetVertexAttribManager(client_id); |
| 11684 | if (!vao) { |
| 11685 | // Unlike most Bind* methods, the spec explicitly states that VertexArray |
| 11686 | // only allows names that have been previously generated. As such, we do |
| 11687 | // not generate new names here. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11688 | LOCAL_SET_GL_ERROR( |
| 11689 | GL_INVALID_OPERATION, |
| 11690 | "glBindVertexArrayOES", "bad vertex array id."); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11691 | current_decoder_error_ = error::kNoError; |
| 11692 | return; |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11693 | } |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11694 | } else { |
[email protected] | 81f20a62 | 2014-04-18 01:54:52 | [diff] [blame] | 11695 | vao = state_.default_vertex_attrib_manager.get(); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11696 | } |
| 11697 | |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11698 | // Only set the VAO state if it's changed |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 11699 | if (state_.vertex_attrib_manager.get() != vao) { |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 11700 | state_.vertex_attrib_manager = vao; |
[email protected] | 62e155e | 2012-10-23 22:43:15 | [diff] [blame] | 11701 | if (!features().native_vertex_array_object) { |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11702 | EmulateVertexArrayState(); |
| 11703 | } else { |
[email protected] | da36481 | 2014-05-09 21:39:48 | [diff] [blame] | 11704 | GLuint service_id = vao->service_id(); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11705 | glBindVertexArrayOES(service_id); |
| 11706 | } |
| 11707 | } |
| 11708 | } |
| 11709 | |
| 11710 | // Used when OES_vertex_array_object isn't natively supported |
| 11711 | void GLES2DecoderImpl::EmulateVertexArrayState() { |
| 11712 | // Setup the Vertex attribute state |
| 11713 | for (uint32 vv = 0; vv < group_->max_vertex_attribs(); ++vv) { |
[email protected] | 3fc38e2 | 2014-05-30 00:13:23 | [diff] [blame] | 11714 | RestoreStateForAttrib(vv, true); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11715 | } |
| 11716 | |
| 11717 | // Setup the element buffer |
[email protected] | 16ccec1 | 2013-02-28 03:40:21 | [diff] [blame] | 11718 | Buffer* element_array_buffer = |
[email protected] | e259eb41 | 2012-10-13 05:47:24 | [diff] [blame] | 11719 | state_.vertex_attrib_manager->element_array_buffer(); |
[email protected] | ab4fd728 | 2012-10-12 16:25:57 | [diff] [blame] | 11720 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, |
| 11721 | element_array_buffer ? element_array_buffer->service_id() : 0); |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11722 | } |
| 11723 | |
| 11724 | bool GLES2DecoderImpl::DoIsVertexArrayOES(GLuint client_id) { |
[email protected] | 944b62f3 | 2012-09-27 02:20:46 | [diff] [blame] | 11725 | const VertexAttribManager* vao = |
| 11726 | GetVertexAttribManager(client_id); |
| 11727 | return vao && vao->IsValid() && !vao->IsDeleted(); |
| 11728 | } |
| 11729 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11730 | #if defined(OS_MACOSX) |
| 11731 | void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { |
| 11732 | TextureToIOSurfaceMap::iterator it = texture_to_io_surface_map_.find( |
| 11733 | texture_id); |
| 11734 | if (it != texture_to_io_surface_map_.end()) { |
| 11735 | // Found a previous IOSurface bound to this texture; release it. |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 11736 | IOSurfaceRef surface = it->second; |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11737 | CFRelease(surface); |
| 11738 | texture_to_io_surface_map_.erase(it); |
| 11739 | } |
| 11740 | } |
| 11741 | #endif |
| 11742 | |
| 11743 | void GLES2DecoderImpl::DoTexImageIOSurface2DCHROMIUM( |
| 11744 | GLenum target, GLsizei width, GLsizei height, |
| 11745 | GLuint io_surface_id, GLuint plane) { |
| 11746 | #if defined(OS_MACOSX) |
| 11747 | if (gfx::GetGLImplementation() != gfx::kGLImplementationDesktopGL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11748 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 11749 | GL_INVALID_OPERATION, |
| 11750 | "glTexImageIOSurface2DCHROMIUM", "only supported on desktop GL."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11751 | return; |
| 11752 | } |
| 11753 | |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11754 | if (target != GL_TEXTURE_RECTANGLE_ARB) { |
| 11755 | // This might be supported in the future, and if we could require |
| 11756 | // support for binding an IOSurface to a NPOT TEXTURE_2D texture, we |
| 11757 | // could delete a lot of code. For now, perform strict validation so we |
| 11758 | // know what's going on. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11759 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11760 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 11761 | "glTexImageIOSurface2DCHROMIUM", |
| 11762 | "requires TEXTURE_RECTANGLE_ARB target"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11763 | return; |
| 11764 | } |
| 11765 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 11766 | // Default target might be conceptually valid, but disallow it to avoid |
| 11767 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 11768 | TextureRef* texture_ref = |
| 11769 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11770 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11771 | LOCAL_SET_GL_ERROR( |
| 11772 | GL_INVALID_OPERATION, |
| 11773 | "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11774 | return; |
| 11775 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11776 | |
| 11777 | // Look up the new IOSurface. Note that because of asynchrony |
| 11778 | // between processes this might fail; during live resizing the |
| 11779 | // plugin process might allocate and release an IOSurface before |
| 11780 | // this process gets a chance to look it up. Hold on to any old |
| 11781 | // IOSurface in this case. |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 11782 | IOSurfaceRef surface = IOSurfaceLookup(io_surface_id); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11783 | if (!surface) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11784 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 11785 | GL_INVALID_OPERATION, |
| 11786 | "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11787 | return; |
| 11788 | } |
| 11789 | |
| 11790 | // Release any IOSurface previously bound to this texture. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11791 | ReleaseIOSurfaceForTexture(texture_ref->service_id()); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11792 | |
| 11793 | // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. |
| 11794 | texture_to_io_surface_map_.insert( |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11795 | std::make_pair(texture_ref->service_id(), surface)); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11796 | |
| 11797 | CGLContextObj context = |
| 11798 | static_cast<CGLContextObj>(context_->GetHandle()); |
| 11799 | |
[email protected] | c3a6b4a | 2014-06-04 09:25:53 | [diff] [blame] | 11800 | CGLError err = CGLTexImageIOSurface2D( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11801 | context, |
| 11802 | target, |
| 11803 | GL_RGBA, |
| 11804 | width, |
| 11805 | height, |
| 11806 | GL_BGRA, |
| 11807 | GL_UNSIGNED_INT_8_8_8_8_REV, |
| 11808 | surface, |
| 11809 | plane); |
| 11810 | |
| 11811 | if (err != kCGLNoError) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11812 | LOCAL_SET_GL_ERROR( |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11813 | GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 11814 | "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D"); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11815 | return; |
| 11816 | } |
| 11817 | |
| 11818 | texture_manager()->SetLevelInfo( |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 11819 | texture_ref, target, 0, GL_RGBA, width, height, 1, 0, GL_BGRA, |
| 11820 | GL_UNSIGNED_INT_8_8_8_8_REV, gfx::Rect(width, height)); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11821 | |
| 11822 | #else |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 11823 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 11824 | "glTexImageIOSurface2DCHROMIUM", "not supported."); |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 11825 | #endif |
| 11826 | } |
| 11827 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 11828 | static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { |
| 11829 | switch (internalformat) { |
| 11830 | case GL_RGB565: |
| 11831 | return GL_RGB; |
| 11832 | case GL_RGBA4: |
| 11833 | return GL_RGBA; |
| 11834 | case GL_RGB5_A1: |
| 11835 | return GL_RGBA; |
| 11836 | case GL_RGB8_OES: |
| 11837 | return GL_RGB; |
| 11838 | case GL_RGBA8_OES: |
| 11839 | return GL_RGBA; |
| 11840 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 11841 | return GL_LUMINANCE_ALPHA; |
| 11842 | case GL_LUMINANCE8_EXT: |
| 11843 | return GL_LUMINANCE; |
| 11844 | case GL_ALPHA8_EXT: |
| 11845 | return GL_ALPHA; |
| 11846 | case GL_RGBA32F_EXT: |
| 11847 | return GL_RGBA; |
| 11848 | case GL_RGB32F_EXT: |
| 11849 | return GL_RGB; |
| 11850 | case GL_ALPHA32F_EXT: |
| 11851 | return GL_ALPHA; |
| 11852 | case GL_LUMINANCE32F_EXT: |
| 11853 | return GL_LUMINANCE; |
| 11854 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 11855 | return GL_LUMINANCE_ALPHA; |
| 11856 | case GL_RGBA16F_EXT: |
| 11857 | return GL_RGBA; |
| 11858 | case GL_RGB16F_EXT: |
| 11859 | return GL_RGB; |
| 11860 | case GL_ALPHA16F_EXT: |
| 11861 | return GL_ALPHA; |
| 11862 | case GL_LUMINANCE16F_EXT: |
| 11863 | return GL_LUMINANCE; |
| 11864 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 11865 | return GL_LUMINANCE_ALPHA; |
| 11866 | case GL_BGRA8_EXT: |
| 11867 | return GL_BGRA_EXT; |
bajones | 2a2ea23 | 2014-10-13 21:38:59 | [diff] [blame] | 11868 | case GL_SRGB8_ALPHA8_EXT: |
| 11869 | return GL_SRGB_ALPHA_EXT; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 11870 | default: |
| 11871 | return GL_NONE; |
| 11872 | } |
| 11873 | } |
| 11874 | |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 11875 | bool GLES2DecoderImpl::ValidateCopyTextureCHROMIUM( |
| 11876 | const char* function_name, |
| 11877 | GLenum target, |
| 11878 | TextureRef* source_texture_ref, |
| 11879 | TextureRef* dest_texture_ref, |
| 11880 | GLenum dest_internal_format) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11881 | if (!source_texture_ref || !dest_texture_ref) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 11882 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); |
| 11883 | return false; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 11884 | } |
| 11885 | |
| 11886 | if (GL_TEXTURE_2D != target) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 11887 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
| 11888 | "invalid texture target"); |
| 11889 | return false; |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 11890 | } |
| 11891 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 11892 | Texture* source_texture = source_texture_ref->texture(); |
| 11893 | Texture* dest_texture = dest_texture_ref->texture(); |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 11894 | if (source_texture == dest_texture) { |
| 11895 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 11896 | "source and destination textures are the same"); |
| 11897 | return false; |
| 11898 | } |
| 11899 | |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 11900 | if (dest_texture->target() != GL_TEXTURE_2D || |
[email protected] | 9bc9a2e8 | 2013-04-03 03:56:25 | [diff] [blame] | 11901 | (source_texture->target() != GL_TEXTURE_2D && |
[email protected] | 041d463f | 2014-04-30 05:38:34 | [diff] [blame] | 11902 | source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && |
| 11903 | source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 11904 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 11905 | "invalid texture target binding"); |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 11906 | return false; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 11907 | } |
| 11908 | |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 11909 | GLenum source_type = 0; |
| 11910 | GLenum source_internal_format = 0; |
| 11911 | source_texture->GetLevelType(source_texture->target(), 0, &source_type, |
| 11912 | &source_internal_format); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 11913 | |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 11914 | // The destination format should be GL_RGB, or GL_RGBA. GL_ALPHA, |
| 11915 | // GL_LUMINANCE, and GL_LUMINANCE_ALPHA are not supported because they are not |
| 11916 | // renderable on some platforms. |
| 11917 | bool valid_dest_format = dest_internal_format == GL_RGB || |
| 11918 | dest_internal_format == GL_RGBA || |
| 11919 | dest_internal_format == GL_BGRA_EXT; |
| 11920 | bool valid_source_format = source_internal_format == GL_ALPHA || |
| 11921 | source_internal_format == GL_RGB || |
| 11922 | source_internal_format == GL_RGBA || |
| 11923 | source_internal_format == GL_LUMINANCE || |
| 11924 | source_internal_format == GL_LUMINANCE_ALPHA || |
| 11925 | source_internal_format == GL_BGRA_EXT; |
| 11926 | if (!valid_source_format || !valid_dest_format) { |
| 11927 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 11928 | "invalid internal format"); |
| 11929 | return false; |
| 11930 | } |
| 11931 | return true; |
| 11932 | } |
| 11933 | |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 11934 | bool GLES2DecoderImpl::ValidateCompressedCopyTextureCHROMIUM( |
| 11935 | const char* function_name, |
| 11936 | GLenum target, |
| 11937 | TextureRef* source_texture_ref, |
| 11938 | TextureRef* dest_texture_ref) { |
| 11939 | if (!source_texture_ref || !dest_texture_ref) { |
| 11940 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "unknown texture id"); |
| 11941 | return false; |
| 11942 | } |
| 11943 | |
| 11944 | if (GL_TEXTURE_2D != target) { |
| 11945 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
| 11946 | "invalid texture target"); |
| 11947 | return false; |
| 11948 | } |
| 11949 | |
| 11950 | Texture* source_texture = source_texture_ref->texture(); |
| 11951 | Texture* dest_texture = dest_texture_ref->texture(); |
| 11952 | if (source_texture == dest_texture) { |
| 11953 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 11954 | "source and destination textures are the same"); |
| 11955 | return false; |
| 11956 | } |
| 11957 | |
| 11958 | if (dest_texture->target() != GL_TEXTURE_2D || |
| 11959 | (source_texture->target() != GL_TEXTURE_2D && |
| 11960 | source_texture->target() != GL_TEXTURE_RECTANGLE_ARB && |
| 11961 | source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { |
| 11962 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, |
| 11963 | "invalid texture target binding"); |
| 11964 | return false; |
| 11965 | } |
| 11966 | |
| 11967 | GLenum source_type = 0; |
| 11968 | GLenum source_internal_format = 0; |
| 11969 | source_texture->GetLevelType(source_texture->target(), 0, &source_type, |
| 11970 | &source_internal_format); |
| 11971 | |
| 11972 | bool valid_format = |
| 11973 | source_internal_format == GL_ATC_RGB_AMD || |
| 11974 | source_internal_format == GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD || |
| 11975 | source_internal_format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT || |
| 11976 | source_internal_format == GL_COMPRESSED_RGBA_S3TC_DXT5_EXT || |
| 11977 | source_internal_format == GL_ETC1_RGB8_OES; |
| 11978 | |
| 11979 | if (!valid_format) { |
| 11980 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, |
| 11981 | "invalid internal format"); |
| 11982 | return false; |
| 11983 | } |
| 11984 | |
| 11985 | return true; |
| 11986 | } |
| 11987 | |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 11988 | void GLES2DecoderImpl::DoCopyTextureCHROMIUM( |
| 11989 | GLenum target, |
| 11990 | GLuint source_id, |
| 11991 | GLuint dest_id, |
| 11992 | GLenum internal_format, |
| 11993 | GLenum dest_type, |
| 11994 | GLboolean unpack_flip_y, |
| 11995 | GLboolean unpack_premultiply_alpha, |
| 11996 | GLboolean unpack_unmultiply_alpha) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 11997 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopyTextureCHROMIUM"); |
| 11998 | |
| 11999 | TextureRef* source_texture_ref = GetTexture(source_id); |
| 12000 | TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 12001 | Texture* source_texture = source_texture_ref->texture(); |
| 12002 | Texture* dest_texture = dest_texture_ref->texture(); |
| 12003 | int source_width = 0; |
| 12004 | int source_height = 0; |
[email protected] | 3e0dfd7 | 2014-02-21 06:28:41 | [diff] [blame] | 12005 | gfx::GLImage* image = |
| 12006 | source_texture->GetLevelImage(source_texture->target(), 0); |
| 12007 | if (image) { |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 12008 | gfx::Size size = image->GetSize(); |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 12009 | source_width = size.width(); |
| 12010 | source_height = size.height(); |
| 12011 | if (source_width <= 0 || source_height <= 0) { |
| 12012 | LOCAL_SET_GL_ERROR( |
| 12013 | GL_INVALID_VALUE, |
[email protected] | 7bffe9e1 | 2014-01-27 23:02:55 | [diff] [blame] | 12014 | "glCopyTextureChromium", "invalid image size"); |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 12015 | return; |
| 12016 | } |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 12017 | } else { |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 12018 | if (!source_texture->GetLevelSize(source_texture->target(), 0, |
| 12019 | &source_width, &source_height, nullptr)) { |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 12020 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 12021 | "glCopyTextureChromium", |
| 12022 | "source texture has no level 0"); |
| 12023 | return; |
| 12024 | } |
| 12025 | |
| 12026 | // Check that this type of texture is allowed. |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12027 | if (!texture_manager()->ValidForTarget(source_texture->target(), 0, |
| 12028 | source_width, source_height, 1)) { |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 12029 | LOCAL_SET_GL_ERROR( |
| 12030 | GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "Bad dimensions"); |
| 12031 | return; |
| 12032 | } |
[email protected] | 37797655 | 2013-05-14 23:32:56 | [diff] [blame] | 12033 | } |
| 12034 | |
[email protected] | a6e3d28 | 2014-08-22 22:20:44 | [diff] [blame] | 12035 | GLenum source_type = 0; |
| 12036 | GLenum source_internal_format = 0; |
| 12037 | source_texture->GetLevelType( |
| 12038 | source_texture->target(), 0, &source_type, &source_internal_format); |
| 12039 | |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12040 | if (dest_texture->IsImmutable()) { |
| 12041 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopyTextureCHROMIUM", |
| 12042 | "texture is immutable"); |
| 12043 | return; |
| 12044 | } |
| 12045 | |
| 12046 | if (!ValidateCopyTextureCHROMIUM("glCopyTextureCHROMIUM", target, |
| 12047 | source_texture_ref, dest_texture_ref, |
| 12048 | internal_format)) { |
| 12049 | return; |
| 12050 | } |
| 12051 | |
| 12052 | // Clear the source texture if necessary. |
| 12053 | if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, |
| 12054 | source_texture->target(), 0)) { |
| 12055 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopyTextureCHROMIUM", |
| 12056 | "dimensions too big"); |
[email protected] | a6e3d28 | 2014-08-22 22:20:44 | [diff] [blame] | 12057 | return; |
| 12058 | } |
| 12059 | |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 12060 | // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 12061 | // needed because it takes 10s of milliseconds to initialize. |
| 12062 | if (!copy_texture_CHROMIUM_.get()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12063 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 12064 | copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
[email protected] | 07a0cc3 | 2013-02-28 00:36:27 | [diff] [blame] | 12065 | copy_texture_CHROMIUM_->Initialize(this); |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 12066 | RestoreCurrentFramebufferBindings(); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12067 | if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
[email protected] | cf6b8f6 | 2012-05-25 21:43:37 | [diff] [blame] | 12068 | return; |
| 12069 | } |
| 12070 | |
[email protected] | efc8771 | 2014-07-09 00:22:47 | [diff] [blame] | 12071 | GLenum dest_type_previous = dest_type; |
| 12072 | GLenum dest_internal_format = internal_format; |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12073 | int dest_width = 0; |
| 12074 | int dest_height = 0; |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 12075 | bool dest_level_defined = dest_texture->GetLevelSize( |
| 12076 | GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 12077 | |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 12078 | if (dest_level_defined) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12079 | dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type_previous, |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 12080 | &dest_internal_format); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 12081 | } |
| 12082 | |
| 12083 | // Resize the destination texture to the dimensions of the source texture. |
| 12084 | if (!dest_level_defined || dest_width != source_width || |
| 12085 | dest_height != source_height || |
[email protected] | a4a6bdd1 | 2013-04-19 20:46:54 | [diff] [blame] | 12086 | dest_internal_format != internal_format || |
| 12087 | dest_type_previous != dest_type) { |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 12088 | // Ensure that the glTexImage2D succeeds. |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12089 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 12090 | glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12091 | glTexImage2D(GL_TEXTURE_2D, 0, internal_format, source_width, source_height, |
| 12092 | 0, internal_format, dest_type, NULL); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12093 | GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 12094 | if (error != GL_NO_ERROR) { |
[email protected] | 2b10c02d | 2014-01-29 16:43:02 | [diff] [blame] | 12095 | RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 12096 | return; |
[email protected] | 0a1e9ad | 2012-05-04 21:13:03 | [diff] [blame] | 12097 | } |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 12098 | |
| 12099 | texture_manager()->SetLevelInfo( |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12100 | dest_texture_ref, GL_TEXTURE_2D, 0, internal_format, source_width, |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 12101 | source_height, 1, 0, internal_format, dest_type, |
| 12102 | gfx::Rect(source_width, source_height)); |
[email protected] | f702471 | 2012-05-15 21:30:25 | [diff] [blame] | 12103 | } else { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12104 | texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
| 12105 | true); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 12106 | } |
| 12107 | |
[email protected] | 00c2cf9 | 2014-03-14 00:08:37 | [diff] [blame] | 12108 | ScopedModifyPixels modify(dest_texture_ref); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 12109 | |
reveman | b6643fb0 | 2015-05-26 06:05:34 | [diff] [blame] | 12110 | // Try using GLImage::CopyTexSubImage when possible. |
reveman | ce8fbe8 | 2014-09-05 02:19:52 | [diff] [blame] | 12111 | bool unpack_premultiply_alpha_change = |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 12112 | (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; |
| 12113 | if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { |
reveman | ce8fbe8 | 2014-09-05 02:19:52 | [diff] [blame] | 12114 | glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
reveman | 6b683f2 | 2015-05-22 02:38:32 | [diff] [blame] | 12115 | if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(0, 0), |
| 12116 | gfx::Rect(0, 0, source_width, source_height))) { |
reveman | ce8fbe8 | 2014-09-05 02:19:52 | [diff] [blame] | 12117 | return; |
reveman | 6b683f2 | 2015-05-22 02:38:32 | [diff] [blame] | 12118 | } |
reveman | ce8fbe8 | 2014-09-05 02:19:52 | [diff] [blame] | 12119 | } |
| 12120 | |
| 12121 | DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 12122 | |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 12123 | // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 12124 | // before presenting. |
| 12125 | if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
| 12126 | // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12127 | // instead of using kIdentityMatrix crbug.com/226218. |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 12128 | copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12129 | this, source_texture->target(), source_texture->service_id(), |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 12130 | dest_texture->service_id(), source_width, source_height, |
| 12131 | unpack_flip_y == GL_TRUE, |
| 12132 | unpack_premultiply_alpha == GL_TRUE, |
| 12133 | unpack_unmultiply_alpha == GL_TRUE, |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12134 | kIdentityMatrix); |
[email protected] | 5394a410 | 2013-04-18 05:41:37 | [diff] [blame] | 12135 | } else { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12136 | copy_texture_CHROMIUM_->DoCopyTexture( |
| 12137 | this, source_texture->target(), source_texture->service_id(), |
| 12138 | source_internal_format, dest_texture->service_id(), internal_format, |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 12139 | source_width, source_height, |
| 12140 | unpack_flip_y == GL_TRUE, |
| 12141 | unpack_premultiply_alpha == GL_TRUE, |
| 12142 | unpack_unmultiply_alpha == GL_TRUE); |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12143 | } |
| 12144 | |
| 12145 | DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 12146 | } |
| 12147 | |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 12148 | void GLES2DecoderImpl::DoCopySubTextureCHROMIUM( |
| 12149 | GLenum target, |
| 12150 | GLuint source_id, |
| 12151 | GLuint dest_id, |
| 12152 | GLint xoffset, |
| 12153 | GLint yoffset, |
| 12154 | GLint x, |
| 12155 | GLint y, |
| 12156 | GLsizei width, |
| 12157 | GLsizei height, |
| 12158 | GLboolean unpack_flip_y, |
| 12159 | GLboolean unpack_premultiply_alpha, |
| 12160 | GLboolean unpack_unmultiply_alpha) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12161 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCopySubTextureCHROMIUM"); |
| 12162 | |
| 12163 | TextureRef* source_texture_ref = GetTexture(source_id); |
| 12164 | TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 12165 | Texture* source_texture = source_texture_ref->texture(); |
| 12166 | Texture* dest_texture = dest_texture_ref->texture(); |
| 12167 | int source_width = 0; |
| 12168 | int source_height = 0; |
| 12169 | gfx::GLImage* image = |
| 12170 | source_texture->GetLevelImage(source_texture->target(), 0); |
| 12171 | if (image) { |
| 12172 | gfx::Size size = image->GetSize(); |
| 12173 | source_width = size.width(); |
| 12174 | source_height = size.height(); |
| 12175 | if (source_width <= 0 || source_height <= 0) { |
| 12176 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
| 12177 | "invalid image size"); |
| 12178 | return; |
| 12179 | } |
| 12180 | } else { |
| 12181 | if (!source_texture->GetLevelSize(source_texture->target(), 0, |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 12182 | &source_width, &source_height, nullptr)) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12183 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
| 12184 | "source texture has no level 0"); |
| 12185 | return; |
| 12186 | } |
| 12187 | |
| 12188 | // Check that this type of texture is allowed. |
| 12189 | if (!texture_manager()->ValidForTarget(source_texture->target(), 0, |
| 12190 | source_width, source_height, 1)) { |
| 12191 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
| 12192 | "source texture bad dimensions"); |
| 12193 | return; |
| 12194 | } |
| 12195 | } |
| 12196 | |
| 12197 | GLenum source_type = 0; |
| 12198 | GLenum source_internal_format = 0; |
| 12199 | source_texture->GetLevelType(source_texture->target(), 0, &source_type, |
| 12200 | &source_internal_format); |
reveman | b6643fb0 | 2015-05-26 06:05:34 | [diff] [blame] | 12201 | if (!source_texture->ValidForTexture(source_texture->target(), 0, x, y, 0, |
| 12202 | width, height, 1, source_type)) { |
| 12203 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
| 12204 | "source texture bad dimensions."); |
| 12205 | return; |
| 12206 | } |
| 12207 | |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12208 | GLenum dest_type = 0; |
| 12209 | GLenum dest_internal_format = 0; |
| 12210 | bool dest_level_defined = dest_texture->GetLevelType( |
| 12211 | dest_texture->target(), 0, &dest_type, &dest_internal_format); |
| 12212 | if (!dest_level_defined) { |
| 12213 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glCopySubTextureCHROMIUM", |
| 12214 | "destination texture is not defined"); |
| 12215 | return; |
| 12216 | } |
| 12217 | if (!dest_texture->ValidForTexture(dest_texture->target(), 0, xoffset, |
reveman | b6643fb0 | 2015-05-26 06:05:34 | [diff] [blame] | 12218 | yoffset, 0, width, height, 1, dest_type)) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12219 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glCopySubTextureCHROMIUM", |
| 12220 | "destination texture bad dimensions."); |
| 12221 | return; |
| 12222 | } |
| 12223 | |
| 12224 | if (!ValidateCopyTextureCHROMIUM("glCopySubTextureCHROMIUM", target, |
| 12225 | source_texture_ref, dest_texture_ref, |
| 12226 | dest_internal_format)) { |
| 12227 | return; |
| 12228 | } |
| 12229 | |
| 12230 | // Clear the source texture if necessary. |
| 12231 | if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, |
| 12232 | source_texture->target(), 0)) { |
| 12233 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", |
| 12234 | "source texture dimensions too big"); |
| 12235 | return; |
| 12236 | } |
| 12237 | |
| 12238 | // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 12239 | // needed because it takes 10s of milliseconds to initialize. |
| 12240 | if (!copy_texture_CHROMIUM_.get()) { |
| 12241 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopySubTextureCHROMIUM"); |
| 12242 | copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
| 12243 | copy_texture_CHROMIUM_->Initialize(this); |
| 12244 | RestoreCurrentFramebufferBindings(); |
| 12245 | if (LOCAL_PEEK_GL_ERROR("glCopySubTextureCHROMIUM") != GL_NO_ERROR) |
| 12246 | return; |
| 12247 | } |
| 12248 | |
| 12249 | int dest_width = 0; |
| 12250 | int dest_height = 0; |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 12251 | bool ok = dest_texture->GetLevelSize( |
| 12252 | GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr); |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12253 | DCHECK(ok); |
reveman | b6643fb0 | 2015-05-26 06:05:34 | [diff] [blame] | 12254 | if (xoffset != 0 || yoffset != 0 || width != dest_width || |
| 12255 | height != dest_height) { |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 12256 | gfx::Rect cleared_rect; |
| 12257 | if (CombineAdjacentRects(dest_texture->GetLevelClearedRect(target, 0), |
| 12258 | gfx::Rect(xoffset, yoffset, width, height), |
| 12259 | &cleared_rect)) { |
| 12260 | DCHECK_GE(cleared_rect.size().GetArea(), |
| 12261 | dest_texture->GetLevelClearedRect(target, 0).size().GetArea()); |
| 12262 | texture_manager()->SetLevelClearedRect(dest_texture_ref, target, 0, |
| 12263 | cleared_rect); |
| 12264 | } else { |
| 12265 | // Otherwise clear part of texture level that is not already cleared. |
| 12266 | if (!texture_manager()->ClearTextureLevel(this, dest_texture_ref, target, |
| 12267 | 0)) { |
| 12268 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCopySubTextureCHROMIUM", |
| 12269 | "destination texture dimensions too big"); |
| 12270 | return; |
| 12271 | } |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12272 | } |
| 12273 | } else { |
| 12274 | texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
| 12275 | true); |
| 12276 | } |
| 12277 | |
| 12278 | ScopedModifyPixels modify(dest_texture_ref); |
| 12279 | |
| 12280 | // Try using GLImage::CopyTexSubImage when possible. |
| 12281 | bool unpack_premultiply_alpha_change = |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 12282 | (unpack_premultiply_alpha ^ unpack_unmultiply_alpha) != 0; |
| 12283 | if (image && !unpack_flip_y && !unpack_premultiply_alpha_change) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12284 | glBindTexture(GL_TEXTURE_2D, dest_texture->service_id()); |
reveman | 6b683f2 | 2015-05-22 02:38:32 | [diff] [blame] | 12285 | if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(xoffset, yoffset), |
reveman | d41b0e1f | 2015-05-26 13:05:19 | [diff] [blame] | 12286 | gfx::Rect(x, y, width, height))) { |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12287 | return; |
reveman | 6b683f2 | 2015-05-22 02:38:32 | [diff] [blame] | 12288 | } |
dongseong.hwang | 46305b1 | 2015-03-05 18:28:04 | [diff] [blame] | 12289 | } |
| 12290 | |
| 12291 | DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 12292 | |
reveman | b6643fb0 | 2015-05-26 06:05:34 | [diff] [blame] | 12293 | // TODO(hkuang): get the StreamTexture transform matrix in GPU process. |
| 12294 | // crbug.com/226218. |
| 12295 | copy_texture_CHROMIUM_->DoCopySubTexture( |
| 12296 | this, source_texture->target(), source_texture->service_id(), |
| 12297 | source_internal_format, dest_texture->service_id(), dest_internal_format, |
| 12298 | xoffset, yoffset, x, y, width, height, dest_width, dest_height, |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 12299 | source_width, source_height, |
| 12300 | unpack_flip_y == GL_TRUE, |
| 12301 | unpack_premultiply_alpha == GL_TRUE, |
| 12302 | unpack_unmultiply_alpha == GL_TRUE); |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 12303 | |
| 12304 | DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
[email protected] | 43410e9 | 2012-04-20 17:06:28 | [diff] [blame] | 12305 | } |
| 12306 | |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 12307 | void GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM(GLenum target, |
| 12308 | GLuint source_id, |
| 12309 | GLuint dest_id) { |
| 12310 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM"); |
| 12311 | |
| 12312 | TextureRef* source_texture_ref = GetTexture(source_id); |
| 12313 | TextureRef* dest_texture_ref = GetTexture(dest_id); |
| 12314 | Texture* source_texture = source_texture_ref->texture(); |
| 12315 | Texture* dest_texture = dest_texture_ref->texture(); |
| 12316 | int source_width = 0; |
| 12317 | int source_height = 0; |
| 12318 | gfx::GLImage* image = |
| 12319 | source_texture->GetLevelImage(source_texture->target(), 0); |
| 12320 | if (image) { |
| 12321 | gfx::Size size = image->GetSize(); |
| 12322 | source_width = size.width(); |
| 12323 | source_height = size.height(); |
| 12324 | if (source_width <= 0 || source_height <= 0) { |
| 12325 | LOCAL_SET_GL_ERROR( |
| 12326 | GL_INVALID_VALUE, |
| 12327 | "glCompressedCopyTextureCHROMIUM", "invalid image size"); |
| 12328 | return; |
| 12329 | } |
| 12330 | } else { |
| 12331 | if (!source_texture->GetLevelSize(source_texture->target(), 0, |
| 12332 | &source_width, &source_height, nullptr)) { |
| 12333 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, |
| 12334 | "glCompressedCopyTextureCHROMIUM", |
| 12335 | "source texture has no level 0"); |
| 12336 | return; |
| 12337 | } |
| 12338 | |
| 12339 | // Check that this type of texture is allowed. |
| 12340 | if (!texture_manager()->ValidForTarget(source_texture->target(), 0, |
| 12341 | source_width, source_height, 1)) { |
| 12342 | LOCAL_SET_GL_ERROR( |
| 12343 | GL_INVALID_VALUE, "glCompressedCopyTextureCHROMIUM", |
| 12344 | "Bad dimensions"); |
| 12345 | return; |
| 12346 | } |
| 12347 | } |
| 12348 | |
| 12349 | GLenum source_type = 0; |
| 12350 | GLenum source_internal_format = 0; |
| 12351 | source_texture->GetLevelType( |
| 12352 | source_texture->target(), 0, &source_type, &source_internal_format); |
| 12353 | |
| 12354 | if (dest_texture->IsImmutable()) { |
| 12355 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 12356 | "glCompressedCopyTextureCHROMIUM", |
| 12357 | "texture is immutable"); |
| 12358 | return; |
| 12359 | } |
| 12360 | |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 12361 | if (!ValidateCompressedCopyTextureCHROMIUM( |
| 12362 | "glCompressedCopyTextureCHROMIUM", |
| 12363 | target, |
| 12364 | source_texture_ref, dest_texture_ref)) { |
| 12365 | return; |
| 12366 | } |
| 12367 | |
| 12368 | // Defer initializing the CopyTextureCHROMIUMResourceManager until it is |
| 12369 | // needed because it takes 10s of milliseconds to initialize. |
| 12370 | if (!copy_texture_CHROMIUM_.get()) { |
| 12371 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTextureCHROMIUM"); |
| 12372 | copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); |
| 12373 | copy_texture_CHROMIUM_->Initialize(this); |
| 12374 | RestoreCurrentFramebufferBindings(); |
| 12375 | if (LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM") != GL_NO_ERROR) |
| 12376 | return; |
| 12377 | } |
| 12378 | |
| 12379 | // Clear the source texture if necessary. |
| 12380 | if (!texture_manager()->ClearTextureLevel(this, source_texture_ref, |
| 12381 | source_texture->target(), 0)) { |
| 12382 | LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glCompressedCopyTextureCHROMIUM", |
| 12383 | "dimensions too big"); |
| 12384 | return; |
| 12385 | } |
| 12386 | |
| 12387 | ScopedTextureBinder binder( |
| 12388 | &state_, dest_texture->service_id(), GL_TEXTURE_2D); |
| 12389 | |
| 12390 | ScopedModifyPixels modify(dest_texture_ref); |
| 12391 | |
| 12392 | // Try using GLImage::CopyTexImage when possible. |
| 12393 | if (image) { |
| 12394 | GLenum dest_type = 0; |
| 12395 | GLenum dest_internal_format = 0; |
| 12396 | int dest_width = 0; |
| 12397 | int dest_height = 0; |
| 12398 | bool dest_level_defined = dest_texture->GetLevelSize( |
| 12399 | GL_TEXTURE_2D, 0, &dest_width, &dest_height, nullptr); |
| 12400 | |
| 12401 | if (dest_level_defined) { |
| 12402 | dest_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type, |
| 12403 | &dest_internal_format); |
| 12404 | } |
| 12405 | |
| 12406 | // Resize the destination texture to the dimensions of the source texture. |
| 12407 | if (!dest_level_defined || dest_width != source_width || |
| 12408 | dest_height != source_height || |
| 12409 | dest_internal_format != source_internal_format) { |
| 12410 | GLsizei source_size = 0; |
| 12411 | |
| 12412 | bool did_get_size = GetCompressedTexSizeInBytes( |
| 12413 | "glCompressedCopyTextureCHROMIUM", source_width, source_height, |
| 12414 | 1, source_internal_format, &source_size); |
| 12415 | DCHECK(did_get_size); |
| 12416 | |
| 12417 | // Ensure that the glCompressedTexImage2D succeeds. |
| 12418 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); |
| 12419 | glCompressedTexImage2D(GL_TEXTURE_2D, 0, source_internal_format, |
| 12420 | source_width, source_height, 0, source_size, |
| 12421 | NULL); |
| 12422 | GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM"); |
| 12423 | if (error != GL_NO_ERROR) { |
| 12424 | RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
| 12425 | return; |
| 12426 | } |
| 12427 | |
| 12428 | texture_manager()->SetLevelInfo( |
| 12429 | dest_texture_ref, GL_TEXTURE_2D, 0, source_internal_format, |
| 12430 | source_width, source_height, 1, 0, source_internal_format, |
| 12431 | source_type, gfx::Rect(source_width, source_height)); |
| 12432 | } else { |
| 12433 | texture_manager()->SetLevelCleared(dest_texture_ref, GL_TEXTURE_2D, 0, |
| 12434 | true); |
| 12435 | } |
| 12436 | |
| 12437 | if (image->CopyTexSubImage(GL_TEXTURE_2D, gfx::Point(0, 0), |
| 12438 | gfx::Rect(0, 0, source_width, source_height))) { |
| 12439 | return; |
| 12440 | } |
| 12441 | } |
| 12442 | |
| 12443 | TRACE_EVENT0( |
| 12444 | "gpu", |
| 12445 | "GLES2DecoderImpl::DoCompressedCopyTextureCHROMIUM, fallback"); |
| 12446 | |
| 12447 | DoWillUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 12448 | |
| 12449 | // As a fallback, copy into a non-compressed GL_RGBA texture. |
| 12450 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedCopyTextureCHROMIUM"); |
| 12451 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, source_width, source_height, |
| 12452 | 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); |
| 12453 | GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedCopyTextureCHROMIUM"); |
| 12454 | if (error != GL_NO_ERROR) { |
| 12455 | RestoreCurrentTextureBindings(&state_, GL_TEXTURE_2D); |
| 12456 | return; |
| 12457 | } |
| 12458 | |
| 12459 | texture_manager()->SetLevelInfo( |
| 12460 | dest_texture_ref, GL_TEXTURE_2D, 0, GL_RGBA, source_width, |
| 12461 | source_height, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, |
| 12462 | gfx::Rect(source_width, source_height)); |
| 12463 | |
| 12464 | // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix |
| 12465 | // before presenting. |
| 12466 | if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { |
| 12467 | // TODO(hkuang): get the StreamTexture transform matrix in GPU process |
| 12468 | // instead of using kIdentityMatrix crbug.com/226218. |
| 12469 | copy_texture_CHROMIUM_->DoCopyTextureWithTransform( |
| 12470 | this, source_texture->target(), source_texture->service_id(), |
| 12471 | dest_texture->service_id(), source_width, source_height, |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 12472 | false, false, false, kIdentityMatrix); |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 12473 | } else { |
| 12474 | copy_texture_CHROMIUM_->DoCopyTexture( |
| 12475 | this, source_texture->target(), source_texture->service_id(), |
| 12476 | source_internal_format, dest_texture->service_id(), GL_RGBA, |
zmo | dbea74da | 2015-06-23 20:41:51 | [diff] [blame] | 12477 | source_width, source_height, false, false, false); |
christiank | 8312009 | 2015-06-17 11:40:10 | [diff] [blame] | 12478 | } |
| 12479 | |
| 12480 | DoDidUseTexImageIfNeeded(source_texture, source_texture->target()); |
| 12481 | } |
| 12482 | |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 12483 | static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { |
| 12484 | switch (internalformat) { |
| 12485 | case GL_RGB565: |
| 12486 | return GL_UNSIGNED_SHORT_5_6_5; |
| 12487 | case GL_RGBA4: |
| 12488 | return GL_UNSIGNED_SHORT_4_4_4_4; |
| 12489 | case GL_RGB5_A1: |
| 12490 | return GL_UNSIGNED_SHORT_5_5_5_1; |
| 12491 | case GL_RGB8_OES: |
| 12492 | return GL_UNSIGNED_BYTE; |
| 12493 | case GL_RGBA8_OES: |
| 12494 | return GL_UNSIGNED_BYTE; |
| 12495 | case GL_LUMINANCE8_ALPHA8_EXT: |
| 12496 | return GL_UNSIGNED_BYTE; |
| 12497 | case GL_LUMINANCE8_EXT: |
| 12498 | return GL_UNSIGNED_BYTE; |
| 12499 | case GL_ALPHA8_EXT: |
| 12500 | return GL_UNSIGNED_BYTE; |
| 12501 | case GL_RGBA32F_EXT: |
| 12502 | return GL_FLOAT; |
| 12503 | case GL_RGB32F_EXT: |
| 12504 | return GL_FLOAT; |
| 12505 | case GL_ALPHA32F_EXT: |
| 12506 | return GL_FLOAT; |
| 12507 | case GL_LUMINANCE32F_EXT: |
| 12508 | return GL_FLOAT; |
| 12509 | case GL_LUMINANCE_ALPHA32F_EXT: |
| 12510 | return GL_FLOAT; |
| 12511 | case GL_RGBA16F_EXT: |
| 12512 | return GL_HALF_FLOAT_OES; |
| 12513 | case GL_RGB16F_EXT: |
| 12514 | return GL_HALF_FLOAT_OES; |
| 12515 | case GL_ALPHA16F_EXT: |
| 12516 | return GL_HALF_FLOAT_OES; |
| 12517 | case GL_LUMINANCE16F_EXT: |
| 12518 | return GL_HALF_FLOAT_OES; |
| 12519 | case GL_LUMINANCE_ALPHA16F_EXT: |
| 12520 | return GL_HALF_FLOAT_OES; |
| 12521 | case GL_BGRA8_EXT: |
| 12522 | return GL_UNSIGNED_BYTE; |
| 12523 | default: |
| 12524 | return GL_NONE; |
| 12525 | } |
| 12526 | } |
| 12527 | |
| 12528 | void GLES2DecoderImpl::DoTexStorage2DEXT( |
[email protected] | a5d3dad | 2012-05-26 04:34:44 | [diff] [blame] | 12529 | GLenum target, |
| 12530 | GLint levels, |
| 12531 | GLenum internal_format, |
| 12532 | GLsizei width, |
| 12533 | GLsizei height) { |
[email protected] | 67f92942 | 2014-05-17 15:33:13 | [diff] [blame] | 12534 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT", |
| 12535 | "width", width, "height", height); |
[email protected] | 80eb6b5 | 2012-01-19 00:14:41 | [diff] [blame] | 12536 | if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || |
[email protected] | 3ecc105 | 2013-09-26 08:59:00 | [diff] [blame] | 12537 | TextureManager::ComputeMipMapCount(target, width, height, 1) < levels) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12538 | LOCAL_SET_GL_ERROR( |
[email protected] | ad84a3a | 2012-06-08 21:42:43 | [diff] [blame] | 12539 | GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 12540 | return; |
| 12541 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 12542 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 12543 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 12544 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12545 | LOCAL_SET_GL_ERROR( |
| 12546 | GL_INVALID_OPERATION, |
| 12547 | "glTexStorage2DEXT", "unknown texture for target"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 12548 | return; |
| 12549 | } |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 12550 | Texture* texture = texture_ref->texture(); |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 12551 | if (texture->IsAttachedToFramebuffer()) { |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 12552 | framebuffer_state_.clear_state_dirty = true; |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 12553 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 12554 | if (texture->IsImmutable()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12555 | LOCAL_SET_GL_ERROR( |
| 12556 | GL_INVALID_OPERATION, |
| 12557 | "glTexStorage2DEXT", "texture is immutable"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 12558 | return; |
| 12559 | } |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 12560 | |
| 12561 | GLenum format = ExtractFormatFromStorageFormat(internal_format); |
| 12562 | GLenum type = ExtractTypeFromStorageFormat(internal_format); |
| 12563 | |
| 12564 | { |
| 12565 | GLsizei level_width = width; |
| 12566 | GLsizei level_height = height; |
| 12567 | uint32 estimated_size = 0; |
| 12568 | for (int ii = 0; ii < levels; ++ii) { |
| 12569 | uint32 level_size = 0; |
| 12570 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 12571 | level_width, level_height, 1, format, type, state_.unpack_alignment, |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 12572 | &estimated_size, NULL, NULL) || |
| 12573 | !SafeAddUint32(estimated_size, level_size, &estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12574 | LOCAL_SET_GL_ERROR( |
| 12575 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "dimensions too large"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 12576 | return; |
| 12577 | } |
| 12578 | level_width = std::max(1, level_width >> 1); |
| 12579 | level_height = std::max(1, level_height >> 1); |
| 12580 | } |
| 12581 | if (!EnsureGPUMemoryAvailable(estimated_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12582 | LOCAL_SET_GL_ERROR( |
| 12583 | GL_OUT_OF_MEMORY, "glTexStorage2DEXT", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 12584 | return; |
| 12585 | } |
| 12586 | } |
| 12587 | |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12588 | LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage2DEXT"); |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 12589 | glTexStorage2DEXT(target, levels, internal_format, width, height); |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12590 | GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage2DEXT"); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 12591 | if (error == GL_NO_ERROR) { |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 12592 | GLsizei level_width = width; |
| 12593 | GLsizei level_height = height; |
| 12594 | for (int ii = 0; ii < levels; ++ii) { |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 12595 | texture_manager()->SetLevelInfo(texture_ref, target, ii, format, |
| 12596 | level_width, level_height, 1, 0, format, |
| 12597 | type, gfx::Rect()); |
[email protected] | 4502e649 | 2011-12-14 19:39:15 | [diff] [blame] | 12598 | level_width = std::max(1, level_width >> 1); |
| 12599 | level_height = std::max(1, level_height >> 1); |
| 12600 | } |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 12601 | texture->SetImmutable(true); |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 12602 | } |
[email protected] | 97dc7cbe | 2011-12-06 17:26:17 | [diff] [blame] | 12603 | } |
[email protected] | e51bdf3 | 2011-11-23 22:21:46 | [diff] [blame] | 12604 | |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 12605 | error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 12606 | uint32 immediate_data_size, |
| 12607 | const void* cmd_data) { |
[email protected] | baed42c | 2013-10-01 05:06:35 | [diff] [blame] | 12608 | return error::kUnknownCommand; |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 12609 | } |
| 12610 | |
| 12611 | void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 12612 | const GLbyte* data) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 12613 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 12614 | "context", logger_.GetLogPrefix(), |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 12615 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 12616 | |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12617 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 12618 | &state_, target); |
| 12619 | ProduceTextureRef("glProduceTextureCHROMIUM", texture_ref, target, data); |
| 12620 | } |
| 12621 | |
| 12622 | void GLES2DecoderImpl::DoProduceTextureDirectCHROMIUM(GLuint client_id, |
| 12623 | GLenum target, const GLbyte* data) { |
| 12624 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureDirectCHROMIUM", |
| 12625 | "context", logger_.GetLogPrefix(), |
| 12626 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 12627 | |
| 12628 | ProduceTextureRef("glProduceTextureDirectCHROMIUM", GetTexture(client_id), |
| 12629 | target, data); |
| 12630 | } |
| 12631 | |
| 12632 | void GLES2DecoderImpl::ProduceTextureRef(std::string func_name, |
| 12633 | TextureRef* texture_ref, GLenum target, const GLbyte* data) { |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 12634 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12635 | DLOG_IF(ERROR, !mailbox.Verify()) << func_name << " was passed a " |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 12636 | "mailbox that was not generated by " |
| 12637 | "GenMailboxCHROMIUM."; |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 12638 | |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 12639 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12640 | LOCAL_SET_GL_ERROR( |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12641 | GL_INVALID_OPERATION, func_name.c_str(), "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 12642 | return; |
| 12643 | } |
| 12644 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 12645 | Texture* produced = texture_manager()->Produce(texture_ref); |
| 12646 | if (!produced) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12647 | LOCAL_SET_GL_ERROR( |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12648 | GL_INVALID_OPERATION, func_name.c_str(), "invalid texture"); |
| 12649 | return; |
| 12650 | } |
| 12651 | |
| 12652 | if (produced->target() != target) { |
| 12653 | LOCAL_SET_GL_ERROR( |
| 12654 | GL_INVALID_OPERATION, func_name.c_str(), "invalid target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 12655 | return; |
| 12656 | } |
| 12657 | |
sievers | 8b373ec5 | 2014-10-24 23:04:06 | [diff] [blame] | 12658 | group_->mailbox_manager()->ProduceTexture(mailbox, produced); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 12659 | } |
| 12660 | |
| 12661 | void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 12662 | const GLbyte* data) { |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 12663 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM", |
[email protected] | 1d82e82 | 2013-04-10 21:32:32 | [diff] [blame] | 12664 | "context", logger_.GetLogPrefix(), |
[email protected] | 64ba52f | 2014-02-15 14:22:37 | [diff] [blame] | 12665 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 12666 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
| 12667 | DLOG_IF(ERROR, !mailbox.Verify()) << "ConsumeTextureCHROMIUM was passed a " |
| 12668 | "mailbox that was not generated by " |
| 12669 | "GenMailboxCHROMIUM."; |
[email protected] | 987b9c0 | 2013-03-23 00:58:02 | [diff] [blame] | 12670 | |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 12671 | scoped_refptr<TextureRef> texture_ref = |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 12672 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 7cd76fd | 2013-06-02 21:11:11 | [diff] [blame] | 12673 | if (!texture_ref.get()) { |
| 12674 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 12675 | "glConsumeTextureCHROMIUM", |
| 12676 | "unknown texture for target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 12677 | return; |
| 12678 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 12679 | GLuint client_id = texture_ref->client_id(); |
| 12680 | if (!client_id) { |
| 12681 | LOCAL_SET_GL_ERROR( |
| 12682 | GL_INVALID_OPERATION, |
| 12683 | "glConsumeTextureCHROMIUM", "unknown texture for target"); |
| 12684 | return; |
| 12685 | } |
sievers | 8b373ec5 | 2014-10-24 23:04:06 | [diff] [blame] | 12686 | Texture* texture = group_->mailbox_manager()->ConsumeTexture(mailbox); |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 12687 | if (!texture) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12688 | LOCAL_SET_GL_ERROR( |
| 12689 | GL_INVALID_OPERATION, |
| 12690 | "glConsumeTextureCHROMIUM", "invalid mailbox name"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 12691 | return; |
| 12692 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 12693 | if (texture->target() != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12694 | LOCAL_SET_GL_ERROR( |
| 12695 | GL_INVALID_OPERATION, |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 12696 | "glConsumeTextureCHROMIUM", "invalid target"); |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 12697 | return; |
| 12698 | } |
[email protected] | 62e65f0 | 2013-05-29 22:28:10 | [diff] [blame] | 12699 | |
| 12700 | DeleteTexturesHelper(1, &client_id); |
| 12701 | texture_ref = texture_manager()->Consume(client_id, texture); |
| 12702 | glBindTexture(target, texture_ref->service_id()); |
| 12703 | |
| 12704 | TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; |
| 12705 | unit.bind_target = target; |
| 12706 | switch (target) { |
| 12707 | case GL_TEXTURE_2D: |
| 12708 | unit.bound_texture_2d = texture_ref; |
| 12709 | break; |
| 12710 | case GL_TEXTURE_CUBE_MAP: |
| 12711 | unit.bound_texture_cube_map = texture_ref; |
| 12712 | break; |
| 12713 | case GL_TEXTURE_EXTERNAL_OES: |
| 12714 | unit.bound_texture_external_oes = texture_ref; |
| 12715 | break; |
| 12716 | case GL_TEXTURE_RECTANGLE_ARB: |
| 12717 | unit.bound_texture_rectangle_arb = texture_ref; |
| 12718 | break; |
| 12719 | default: |
| 12720 | NOTREACHED(); // Validation should prevent us getting here. |
| 12721 | break; |
| 12722 | } |
[email protected] | 78b514b | 2012-05-01 21:50:59 | [diff] [blame] | 12723 | } |
| 12724 | |
bajones | d8388be0 | 2015-04-04 00:15:43 | [diff] [blame] | 12725 | void GLES2DecoderImpl::EnsureTextureForClientId( |
| 12726 | GLenum target, |
| 12727 | GLuint client_id) { |
| 12728 | TextureRef* texture_ref = GetTexture(client_id); |
| 12729 | if (!texture_ref) { |
| 12730 | GLuint service_id; |
| 12731 | glGenTextures(1, &service_id); |
| 12732 | DCHECK_NE(0u, service_id); |
| 12733 | texture_ref = CreateTexture(client_id, service_id); |
| 12734 | texture_manager()->SetTarget(texture_ref, target); |
| 12735 | glBindTexture(target, service_id); |
| 12736 | RestoreCurrentTextureBindings(&state_, target); |
| 12737 | } |
| 12738 | } |
| 12739 | |
| 12740 | // If CreateAndConsumeTexture fails we still need to ensure that the client_id |
| 12741 | // provided is associated with a service_id/TextureRef for consistency, even if |
| 12742 | // the resulting texture is incomplete. |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12743 | error::Error GLES2DecoderImpl::HandleCreateAndConsumeTextureCHROMIUMImmediate( |
| 12744 | uint32_t immediate_data_size, |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 12745 | const void* cmd_data) { |
| 12746 | const gles2::cmds::CreateAndConsumeTextureCHROMIUMImmediate& c = |
| 12747 | *static_cast< |
| 12748 | const gles2::cmds::CreateAndConsumeTextureCHROMIUMImmediate*>( |
| 12749 | cmd_data); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12750 | GLenum target = static_cast<GLenum>(c.target); |
| 12751 | uint32_t data_size; |
| 12752 | if (!ComputeDataSize(1, sizeof(GLbyte), 64, &data_size)) { |
| 12753 | return error::kOutOfBounds; |
| 12754 | } |
| 12755 | if (data_size > immediate_data_size) { |
| 12756 | return error::kOutOfBounds; |
| 12757 | } |
| 12758 | const GLbyte* mailbox = |
| 12759 | GetImmediateDataAs<const GLbyte*>(c, data_size, immediate_data_size); |
| 12760 | if (!validators_->texture_bind_target.IsValid(target)) { |
| 12761 | LOCAL_SET_GL_ERROR_INVALID_ENUM( |
| 12762 | "glCreateAndConsumeTextureCHROMIUM", target, "target"); |
| 12763 | return error::kNoError; |
| 12764 | } |
| 12765 | if (mailbox == NULL) { |
| 12766 | return error::kOutOfBounds; |
| 12767 | } |
| 12768 | uint32_t client_id = c.client_id; |
| 12769 | DoCreateAndConsumeTextureCHROMIUM(target, mailbox, client_id); |
| 12770 | return error::kNoError; |
| 12771 | } |
| 12772 | |
| 12773 | void GLES2DecoderImpl::DoCreateAndConsumeTextureCHROMIUM(GLenum target, |
| 12774 | const GLbyte* data, GLuint client_id) { |
| 12775 | TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoCreateAndConsumeTextureCHROMIUM", |
| 12776 | "context", logger_.GetLogPrefix(), |
| 12777 | "mailbox[0]", static_cast<unsigned char>(data[0])); |
| 12778 | const Mailbox& mailbox = *reinterpret_cast<const Mailbox*>(data); |
| 12779 | DLOG_IF(ERROR, !mailbox.Verify()) << "CreateAndConsumeTextureCHROMIUM was " |
| 12780 | "passed a mailbox that was not " |
| 12781 | "generated by GenMailboxCHROMIUM."; |
| 12782 | |
| 12783 | TextureRef* texture_ref = GetTexture(client_id); |
| 12784 | if (texture_ref) { |
bajones | d8388be0 | 2015-04-04 00:15:43 | [diff] [blame] | 12785 | // No need to call EnsureTextureForClientId here, the client_id already has |
| 12786 | // an associated texture. |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12787 | LOCAL_SET_GL_ERROR( |
| 12788 | GL_INVALID_OPERATION, |
| 12789 | "glCreateAndConsumeTextureCHROMIUM", "client id already in use"); |
| 12790 | return; |
| 12791 | } |
sievers | 8b373ec5 | 2014-10-24 23:04:06 | [diff] [blame] | 12792 | Texture* texture = group_->mailbox_manager()->ConsumeTexture(mailbox); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12793 | if (!texture) { |
bajones | d8388be0 | 2015-04-04 00:15:43 | [diff] [blame] | 12794 | EnsureTextureForClientId(target, client_id); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12795 | LOCAL_SET_GL_ERROR( |
| 12796 | GL_INVALID_OPERATION, |
| 12797 | "glCreateAndConsumeTextureCHROMIUM", "invalid mailbox name"); |
| 12798 | return; |
| 12799 | } |
bajones | d8388be0 | 2015-04-04 00:15:43 | [diff] [blame] | 12800 | |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12801 | if (texture->target() != target) { |
bajones | d8388be0 | 2015-04-04 00:15:43 | [diff] [blame] | 12802 | EnsureTextureForClientId(target, client_id); |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12803 | LOCAL_SET_GL_ERROR( |
| 12804 | GL_INVALID_OPERATION, |
| 12805 | "glCreateAndConsumeTextureCHROMIUM", "invalid target"); |
| 12806 | return; |
| 12807 | } |
| 12808 | |
[email protected] | 43f253da | 2014-06-10 17:51:22 | [diff] [blame] | 12809 | texture_ref = texture_manager()->Consume(client_id, texture); |
| 12810 | } |
| 12811 | |
orglofch | cad5a674 | 2014-11-07 19:51:12 | [diff] [blame] | 12812 | bool GLES2DecoderImpl::DoIsValuebufferCHROMIUM(GLuint client_id) { |
| 12813 | const Valuebuffer* valuebuffer = GetValuebuffer(client_id); |
| 12814 | return valuebuffer && valuebuffer->IsValid(); |
| 12815 | } |
| 12816 | |
| 12817 | void GLES2DecoderImpl::DoBindValueBufferCHROMIUM(GLenum target, |
| 12818 | GLuint client_id) { |
| 12819 | Valuebuffer* valuebuffer = NULL; |
| 12820 | if (client_id != 0) { |
| 12821 | valuebuffer = GetValuebuffer(client_id); |
| 12822 | if (!valuebuffer) { |
| 12823 | if (!group_->bind_generates_resource()) { |
| 12824 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "glBindValuebufferCHROMIUM", |
| 12825 | "id not generated by glBindValuebufferCHROMIUM"); |
| 12826 | return; |
| 12827 | } |
| 12828 | |
| 12829 | // It's a new id so make a valuebuffer for it. |
| 12830 | CreateValuebuffer(client_id); |
| 12831 | valuebuffer = GetValuebuffer(client_id); |
| 12832 | } |
| 12833 | valuebuffer->MarkAsValid(); |
| 12834 | } |
| 12835 | state_.bound_valuebuffer = valuebuffer; |
| 12836 | } |
| 12837 | |
| 12838 | void GLES2DecoderImpl::DoSubscribeValueCHROMIUM(GLenum target, |
| 12839 | GLenum subscription) { |
| 12840 | if (!CheckCurrentValuebuffer("glSubscribeValueCHROMIUM")) { |
| 12841 | return; |
| 12842 | } |
| 12843 | state_.bound_valuebuffer.get()->AddSubscription(subscription); |
| 12844 | } |
| 12845 | |
| 12846 | void GLES2DecoderImpl::DoPopulateSubscribedValuesCHROMIUM(GLenum target) { |
| 12847 | if (!CheckCurrentValuebuffer("glPopulateSubscribedValuesCHROMIUM")) { |
| 12848 | return; |
| 12849 | } |
| 12850 | valuebuffer_manager()->UpdateValuebufferState(state_.bound_valuebuffer.get()); |
| 12851 | } |
| 12852 | |
| 12853 | void GLES2DecoderImpl::DoUniformValueBufferCHROMIUM(GLint location, |
| 12854 | GLenum target, |
| 12855 | GLenum subscription) { |
| 12856 | if (!CheckCurrentValuebufferForSubscription( |
| 12857 | subscription, "glPopulateSubscribedValuesCHROMIUM")) { |
| 12858 | return; |
| 12859 | } |
| 12860 | if (!CheckSubscriptionTarget(location, subscription, |
| 12861 | "glPopulateSubscribedValuesCHROMIUM")) { |
| 12862 | return; |
| 12863 | } |
| 12864 | const ValueState* state = |
| 12865 | state_.bound_valuebuffer.get()->GetState(subscription); |
| 12866 | if (state) { |
| 12867 | switch (subscription) { |
| 12868 | case GL_MOUSE_POSITION_CHROMIUM: |
| 12869 | DoUniform2iv(location, 1, state->int_value); |
| 12870 | break; |
| 12871 | default: |
| 12872 | NOTREACHED() << "Unhandled uniform subscription target " |
| 12873 | << subscription; |
| 12874 | break; |
| 12875 | } |
| 12876 | } |
| 12877 | } |
| 12878 | |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 12879 | void GLES2DecoderImpl::DoInsertEventMarkerEXT( |
| 12880 | GLsizei length, const GLchar* marker) { |
| 12881 | if (!marker) { |
| 12882 | marker = ""; |
| 12883 | } |
| 12884 | debug_marker_manager_.SetMarker( |
| 12885 | length ? std::string(marker, length) : std::string(marker)); |
| 12886 | } |
| 12887 | |
| 12888 | void GLES2DecoderImpl::DoPushGroupMarkerEXT( |
| 12889 | GLsizei length, const GLchar* marker) { |
| 12890 | if (!marker) { |
| 12891 | marker = ""; |
| 12892 | } |
[email protected] | cac1654 | 2014-01-15 17:53:51 | [diff] [blame] | 12893 | std::string name = length ? std::string(marker, length) : std::string(marker); |
| 12894 | debug_marker_manager_.PushGroup(name); |
dyen | 4bb4328 | 2015-01-08 01:09:56 | [diff] [blame] | 12895 | gpu_tracer_->Begin(TRACE_DISABLED_BY_DEFAULT("gpu_group_marker"), name, |
| 12896 | kTraceGroupMarker); |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 12897 | } |
| 12898 | |
| 12899 | void GLES2DecoderImpl::DoPopGroupMarkerEXT(void) { |
| 12900 | debug_marker_manager_.PopGroup(); |
dyen | 4bb4328 | 2015-01-08 01:09:56 | [diff] [blame] | 12901 | gpu_tracer_->End(kTraceGroupMarker); |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 12902 | } |
| 12903 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12904 | void GLES2DecoderImpl::DoBindTexImage2DCHROMIUM( |
| 12905 | GLenum target, GLint image_id) { |
| 12906 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12907 | |
[email protected] | bc26e8d | 2014-01-29 00:40:30 | [diff] [blame] | 12908 | if (target == GL_TEXTURE_CUBE_MAP) { |
| 12909 | LOCAL_SET_GL_ERROR( |
| 12910 | GL_INVALID_ENUM, |
| 12911 | "glBindTexImage2DCHROMIUM", "invalid target"); |
| 12912 | return; |
| 12913 | } |
| 12914 | |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12915 | // Default target might be conceptually valid, but disallow it to avoid |
| 12916 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 12917 | TextureRef* texture_ref = |
| 12918 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 12919 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12920 | LOCAL_SET_GL_ERROR( |
| 12921 | GL_INVALID_OPERATION, |
| 12922 | "glBindTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12923 | return; |
| 12924 | } |
| 12925 | |
| 12926 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 12927 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12928 | LOCAL_SET_GL_ERROR( |
| 12929 | GL_INVALID_OPERATION, |
| 12930 | "glBindTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12931 | return; |
| 12932 | } |
| 12933 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 12934 | { |
| 12935 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 12936 | "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | 3c58012 | 2013-11-22 07:52:26 | [diff] [blame] | 12937 | if (!gl_image->BindTexImage(target)) { |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 12938 | LOCAL_SET_GL_ERROR( |
| 12939 | GL_INVALID_OPERATION, |
| 12940 | "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID"); |
| 12941 | return; |
| 12942 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12943 | } |
| 12944 | |
| 12945 | gfx::Size size = gl_image->GetSize(); |
| 12946 | texture_manager()->SetLevelInfo( |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 12947 | texture_ref, target, 0, gl_image->GetInternalFormat(), size.width(), |
| 12948 | size.height(), 1, 0, gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE, |
| 12949 | gfx::Rect(size)); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 12950 | texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12951 | } |
| 12952 | |
| 12953 | void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( |
| 12954 | GLenum target, GLint image_id) { |
| 12955 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12956 | |
| 12957 | // Default target might be conceptually valid, but disallow it to avoid |
| 12958 | // accidents. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 12959 | TextureRef* texture_ref = |
| 12960 | texture_manager()->GetTextureInfoForTargetUnlessDefault(&state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 12961 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12962 | LOCAL_SET_GL_ERROR( |
| 12963 | GL_INVALID_OPERATION, |
| 12964 | "glReleaseTexImage2DCHROMIUM", "no texture bound"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12965 | return; |
| 12966 | } |
| 12967 | |
| 12968 | gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); |
| 12969 | if (!gl_image) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 12970 | LOCAL_SET_GL_ERROR( |
| 12971 | GL_INVALID_OPERATION, |
| 12972 | "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12973 | return; |
| 12974 | } |
| 12975 | |
| 12976 | // Do nothing when image is not currently bound. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 12977 | if (texture_ref->texture()->GetLevelImage(target, 0) != gl_image) |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12978 | return; |
| 12979 | |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 12980 | { |
| 12981 | ScopedGLErrorSuppressor suppressor( |
[email protected] | 40621eb5 | 2013-10-08 15:40:30 | [diff] [blame] | 12982 | "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", GetErrorState()); |
[email protected] | 3c58012 | 2013-11-22 07:52:26 | [diff] [blame] | 12983 | gl_image->ReleaseTexImage(target); |
[email protected] | b816081 | 2013-04-09 00:41:04 | [diff] [blame] | 12984 | } |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12985 | |
| 12986 | texture_manager()->SetLevelInfo( |
christiank | 55ddebb | 2015-05-18 08:56:32 | [diff] [blame] | 12987 | texture_ref, target, 0, gl_image->GetInternalFormat(), 0, 0, 1, 0, |
reveman | 7c4a13b | 2015-06-05 22:28:15 | [diff] [blame] | 12988 | gl_image->GetInternalFormat(), GL_UNSIGNED_BYTE, gfx::Rect()); |
[email protected] | 09d5036 | 2012-10-18 20:54:37 | [diff] [blame] | 12989 | } |
[email protected] | d2a0e1a | 2012-08-12 02:25:01 | [diff] [blame] | 12990 | |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 12991 | error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 12992 | uint32 immediate_data_size, |
| 12993 | const void* cmd_data) { |
| 12994 | const gles2::cmds::TraceBeginCHROMIUM& c = |
| 12995 | *static_cast<const gles2::cmds::TraceBeginCHROMIUM*>(cmd_data); |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 12996 | Bucket* category_bucket = GetBucket(c.category_bucket_id); |
| 12997 | Bucket* name_bucket = GetBucket(c.name_bucket_id); |
| 12998 | if (!category_bucket || category_bucket->size() == 0 || |
| 12999 | !name_bucket || name_bucket->size() == 0) { |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 13000 | return error::kInvalidArguments; |
| 13001 | } |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 13002 | |
| 13003 | std::string category_name; |
| 13004 | std::string trace_name; |
| 13005 | if (!category_bucket->GetAsString(&category_name) || |
| 13006 | !name_bucket->GetAsString(&trace_name)) { |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 13007 | return error::kInvalidArguments; |
| 13008 | } |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 13009 | |
dyen | cb86f2f | 2014-12-09 18:35:41 | [diff] [blame] | 13010 | if (!gpu_tracer_->Begin(category_name, trace_name, kTraceCHROMIUM)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13011 | LOCAL_SET_GL_ERROR( |
| 13012 | GL_INVALID_OPERATION, |
| 13013 | "glTraceBeginCHROMIUM", "unable to create begin trace"); |
[email protected] | fb97b66 | 2013-02-20 23:02:14 | [diff] [blame] | 13014 | return error::kNoError; |
| 13015 | } |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 13016 | return error::kNoError; |
| 13017 | } |
| 13018 | |
| 13019 | void GLES2DecoderImpl::DoTraceEndCHROMIUM() { |
dyen | 4bb4328 | 2015-01-08 01:09:56 | [diff] [blame] | 13020 | if (!gpu_tracer_->End(kTraceCHROMIUM)) { |
| 13021 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 13022 | "glTraceEndCHROMIUM", "no trace begin found"); |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 13023 | return; |
| 13024 | } |
[email protected] | 9430771 | 2012-11-16 23:26:11 | [diff] [blame] | 13025 | } |
| 13026 | |
[email protected] | 2f143d48 | 2013-03-14 18:04:49 | [diff] [blame] | 13027 | void GLES2DecoderImpl::DoDrawBuffersEXT( |
| 13028 | GLsizei count, const GLenum* bufs) { |
| 13029 | if (count > static_cast<GLsizei>(group_->max_draw_buffers())) { |
| 13030 | LOCAL_SET_GL_ERROR( |
| 13031 | GL_INVALID_VALUE, |
| 13032 | "glDrawBuffersEXT", "greater than GL_MAX_DRAW_BUFFERS_EXT"); |
| 13033 | return; |
| 13034 | } |
| 13035 | |
| 13036 | Framebuffer* framebuffer = GetFramebufferInfoForTarget(GL_FRAMEBUFFER); |
| 13037 | if (framebuffer) { |
| 13038 | for (GLsizei i = 0; i < count; ++i) { |
| 13039 | if (bufs[i] != static_cast<GLenum>(GL_COLOR_ATTACHMENT0 + i) && |
| 13040 | bufs[i] != GL_NONE) { |
| 13041 | LOCAL_SET_GL_ERROR( |
| 13042 | GL_INVALID_OPERATION, |
| 13043 | "glDrawBuffersEXT", |
| 13044 | "bufs[i] not GL_NONE or GL_COLOR_ATTACHMENTi_EXT"); |
| 13045 | return; |
| 13046 | } |
| 13047 | } |
| 13048 | glDrawBuffersARB(count, bufs); |
| 13049 | framebuffer->SetDrawBuffers(count, bufs); |
| 13050 | } else { // backbuffer |
| 13051 | if (count > 1 || |
| 13052 | (bufs[0] != GL_BACK && bufs[0] != GL_NONE)) { |
| 13053 | LOCAL_SET_GL_ERROR( |
| 13054 | GL_INVALID_OPERATION, |
| 13055 | "glDrawBuffersEXT", |
| 13056 | "more than one buffer or bufs not GL_NONE or GL_BACK"); |
| 13057 | return; |
| 13058 | } |
| 13059 | GLenum mapped_buf = bufs[0]; |
| 13060 | if (GetBackbufferServiceId() != 0 && // emulated backbuffer |
| 13061 | bufs[0] == GL_BACK) { |
| 13062 | mapped_buf = GL_COLOR_ATTACHMENT0; |
| 13063 | } |
| 13064 | glDrawBuffersARB(count, &mapped_buf); |
| 13065 | group_->set_draw_buffer(bufs[0]); |
| 13066 | } |
| 13067 | } |
| 13068 | |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 13069 | void GLES2DecoderImpl::DoLoseContextCHROMIUM(GLenum current, GLenum other) { |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 13070 | MarkContextLost(GetContextLostReasonFromResetStatus(current)); |
| 13071 | group_->LoseContexts(GetContextLostReasonFromResetStatus(other)); |
| 13072 | reset_by_robustness_extension_ = true; |
[email protected] | a6a09f85 | 2014-05-23 13:05:03 | [diff] [blame] | 13073 | } |
| 13074 | |
kkinnunen | 337d5963 | 2014-08-26 10:19:57 | [diff] [blame] | 13075 | void GLES2DecoderImpl::DoMatrixLoadfCHROMIUM(GLenum matrix_mode, |
| 13076 | const GLfloat* matrix) { |
| 13077 | DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || |
| 13078 | matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); |
| 13079 | if (!features().chromium_path_rendering) { |
| 13080 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 13081 | "glMatrixLoadfCHROMIUM", |
| 13082 | "function not available"); |
| 13083 | return; |
| 13084 | } |
| 13085 | |
| 13086 | GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM |
| 13087 | ? state_.projection_matrix |
| 13088 | : state_.modelview_matrix; |
| 13089 | memcpy(target_matrix, matrix, sizeof(GLfloat) * 16); |
| 13090 | // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV |
| 13091 | // since the values of the _NV and _CHROMIUM tokens match. |
| 13092 | glMatrixLoadfEXT(matrix_mode, matrix); |
| 13093 | } |
| 13094 | |
| 13095 | void GLES2DecoderImpl::DoMatrixLoadIdentityCHROMIUM(GLenum matrix_mode) { |
| 13096 | DCHECK(matrix_mode == GL_PATH_PROJECTION_CHROMIUM || |
| 13097 | matrix_mode == GL_PATH_MODELVIEW_CHROMIUM); |
| 13098 | |
| 13099 | if (!features().chromium_path_rendering) { |
| 13100 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, |
| 13101 | "glMatrixLoadIdentityCHROMIUM", |
| 13102 | "function not available"); |
| 13103 | return; |
| 13104 | } |
| 13105 | |
kkinnunen | 337d5963 | 2014-08-26 10:19:57 | [diff] [blame] | 13106 | GLfloat* target_matrix = matrix_mode == GL_PATH_PROJECTION_CHROMIUM |
| 13107 | ? state_.projection_matrix |
| 13108 | : state_.modelview_matrix; |
| 13109 | memcpy(target_matrix, kIdentityMatrix, sizeof(kIdentityMatrix)); |
| 13110 | // The matrix_mode is either GL_PATH_MODELVIEW_NV or GL_PATH_PROJECTION_NV |
| 13111 | // since the values of the _NV and _CHROMIUM tokens match. |
| 13112 | glMatrixLoadIdentityEXT(matrix_mode); |
| 13113 | } |
| 13114 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13115 | bool GLES2DecoderImpl::ValidateAsyncTransfer( |
| 13116 | const char* function_name, |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 13117 | TextureRef* texture_ref, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13118 | GLenum target, |
| 13119 | GLint level, |
| 13120 | const void * data) { |
| 13121 | // We only support async uploads to 2D textures for now. |
| 13122 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13123 | LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, target, "target"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13124 | return false; |
| 13125 | } |
| 13126 | // We only support uploads to level zero for now. |
| 13127 | if (level != 0) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13128 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name, "level != 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13129 | return false; |
| 13130 | } |
| 13131 | // A transfer buffer must be bound, even for asyncTexImage2D. |
| 13132 | if (data == NULL) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13133 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name, "buffer == 0"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13134 | return false; |
| 13135 | } |
| 13136 | // We only support one async transfer in progress. |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 13137 | if (!texture_ref || |
| 13138 | async_pixel_transfer_manager_->AsyncTransferIsInProgress(texture_ref)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13139 | LOCAL_SET_GL_ERROR( |
| 13140 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13141 | function_name, "transfer already in progress"); |
| 13142 | return false; |
| 13143 | } |
| 13144 | return true; |
| 13145 | } |
| 13146 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 13147 | base::Closure GLES2DecoderImpl::AsyncUploadTokenCompletionClosure( |
| 13148 | uint32 async_upload_token, |
| 13149 | uint32 sync_data_shm_id, |
| 13150 | uint32 sync_data_shm_offset) { |
| 13151 | scoped_refptr<gpu::Buffer> buffer = GetSharedMemoryBuffer(sync_data_shm_id); |
Daniel Cheng | 3d7ce9f | 2014-08-26 00:26:25 | [diff] [blame] | 13152 | if (!buffer.get() || |
| 13153 | !buffer->GetDataAddress(sync_data_shm_offset, sizeof(AsyncUploadSync))) |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 13154 | return base::Closure(); |
| 13155 | |
| 13156 | AsyncMemoryParams mem_params(buffer, |
| 13157 | sync_data_shm_offset, |
| 13158 | sizeof(AsyncUploadSync)); |
| 13159 | |
| 13160 | scoped_refptr<AsyncUploadTokenCompletionObserver> observer( |
| 13161 | new AsyncUploadTokenCompletionObserver(async_upload_token)); |
| 13162 | |
| 13163 | return base::Bind( |
| 13164 | &AsyncPixelTransferManager::AsyncNotifyCompletion, |
| 13165 | base::Unretained(GetAsyncPixelTransferManager()), |
| 13166 | mem_params, |
| 13167 | observer); |
| 13168 | } |
| 13169 | |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13170 | error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 13171 | uint32 immediate_data_size, |
| 13172 | const void* cmd_data) { |
| 13173 | const gles2::cmds::AsyncTexImage2DCHROMIUM& c = |
| 13174 | *static_cast<const gles2::cmds::AsyncTexImage2DCHROMIUM*>(cmd_data); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13175 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13176 | GLenum target = static_cast<GLenum>(c.target); |
| 13177 | GLint level = static_cast<GLint>(c.level); |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 13178 | GLenum internal_format = static_cast<GLenum>(c.internalformat); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13179 | GLsizei width = static_cast<GLsizei>(c.width); |
| 13180 | GLsizei height = static_cast<GLsizei>(c.height); |
| 13181 | GLint border = static_cast<GLint>(c.border); |
| 13182 | GLenum format = static_cast<GLenum>(c.format); |
| 13183 | GLenum type = static_cast<GLenum>(c.type); |
| 13184 | uint32 pixels_shm_id = static_cast<uint32>(c.pixels_shm_id); |
| 13185 | uint32 pixels_shm_offset = static_cast<uint32>(c.pixels_shm_offset); |
| 13186 | uint32 pixels_size; |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 13187 | uint32 async_upload_token = static_cast<uint32>(c.async_upload_token); |
| 13188 | uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id); |
| 13189 | uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 13190 | |
| 13191 | base::ScopedClosureRunner scoped_completion_callback; |
| 13192 | if (async_upload_token) { |
| 13193 | base::Closure completion_closure = |
| 13194 | AsyncUploadTokenCompletionClosure(async_upload_token, |
| 13195 | sync_data_shm_id, |
| 13196 | sync_data_shm_offset); |
| 13197 | if (completion_closure.is_null()) |
| 13198 | return error::kInvalidArguments; |
| 13199 | |
| 13200 | scoped_completion_callback.Reset(completion_closure); |
| 13201 | } |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13202 | |
| 13203 | // TODO(epenner): Move this and copies of this memory validation |
| 13204 | // into ValidateTexImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13205 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 13206 | width, height, 1, format, type, state_.unpack_alignment, &pixels_size, |
| 13207 | NULL, NULL)) { |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13208 | return error::kOutOfBounds; |
| 13209 | } |
| 13210 | const void* pixels = NULL; |
| 13211 | if (pixels_shm_id != 0 || pixels_shm_offset != 0) { |
| 13212 | pixels = GetSharedMemoryAs<const void*>( |
| 13213 | pixels_shm_id, pixels_shm_offset, pixels_size); |
| 13214 | if (!pixels) { |
| 13215 | return error::kOutOfBounds; |
| 13216 | } |
| 13217 | } |
| 13218 | |
zmo | de7b438 | 2015-05-21 21:23:00 | [diff] [blame] | 13219 | TextureManager::DoTexImageArguments args = { |
| 13220 | target, level, internal_format, width, height, 1, border, format, type, |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 13221 | pixels, pixels_size, TextureManager::DoTexImageArguments::kTexImage2D }; |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 13222 | TextureRef* texture_ref; |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13223 | // All the normal glTexSubImage2D validation. |
zmo | 54f2371 | 2015-05-28 19:28:49 | [diff] [blame] | 13224 | if (!texture_manager()->ValidateTexImage( |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 13225 | &state_, "glAsyncTexImage2DCHROMIUM", args, &texture_ref)) { |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13226 | return error::kNoError; |
| 13227 | } |
| 13228 | |
| 13229 | // Extra async validation. |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 13230 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13231 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 13232 | "glAsyncTexImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13233 | return error::kNoError; |
| 13234 | |
| 13235 | // Don't allow async redefinition of a textures. |
[email protected] | 02965c2 | 2013-03-09 02:40:07 | [diff] [blame] | 13236 | if (texture->IsDefined()) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13237 | LOCAL_SET_GL_ERROR( |
| 13238 | GL_INVALID_OPERATION, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13239 | "glAsyncTexImage2DCHROMIUM", "already defined"); |
| 13240 | return error::kNoError; |
| 13241 | } |
| 13242 | |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 13243 | if (!EnsureGPUMemoryAvailable(pixels_size)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13244 | LOCAL_SET_GL_ERROR( |
| 13245 | GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory"); |
[email protected] | 7989c9e | 2013-01-23 06:39:26 | [diff] [blame] | 13246 | return error::kNoError; |
| 13247 | } |
| 13248 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13249 | // Setup the parameters. |
[email protected] | 8f1d2aa | 2013-05-10 23:45:38 | [diff] [blame] | 13250 | AsyncTexImage2DParams tex_params = { |
| 13251 | target, level, static_cast<GLenum>(internal_format), |
| 13252 | width, height, border, format, type}; |
[email protected] | c8021e0 | 2014-03-27 06:10:12 | [diff] [blame] | 13253 | AsyncMemoryParams mem_params( |
| 13254 | GetSharedMemoryBuffer(c.pixels_shm_id), c.pixels_shm_offset, pixels_size); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13255 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13256 | // Set up the async state if needed, and make the texture |
| 13257 | // immutable so the async state stays valid. The level info |
| 13258 | // is set up lazily when the transfer completes. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 13259 | AsyncPixelTransferDelegate* delegate = |
| 13260 | async_pixel_transfer_manager_->CreatePixelTransferDelegate(texture_ref, |
| 13261 | tex_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13262 | texture->SetImmutable(true); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13263 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 13264 | delegate->AsyncTexImage2D( |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13265 | tex_params, |
| 13266 | mem_params, |
| 13267 | base::Bind(&TextureManager::SetLevelInfoFromParams, |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 13268 | // The callback is only invoked if the transfer delegate still |
| 13269 | // exists, which implies through manager->texture_ref->state |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13270 | // ownership that both of these pointers are valid. |
| 13271 | base::Unretained(texture_manager()), |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 13272 | base::Unretained(texture_ref), |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13273 | tex_params)); |
[email protected] | f598f42 | 2012-12-07 08:30:03 | [diff] [blame] | 13274 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13275 | } |
| 13276 | |
| 13277 | error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 13278 | uint32 immediate_data_size, |
| 13279 | const void* cmd_data) { |
| 13280 | const gles2::cmds::AsyncTexSubImage2DCHROMIUM& c = |
| 13281 | *static_cast<const gles2::cmds::AsyncTexSubImage2DCHROMIUM*>(cmd_data); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13282 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13283 | GLenum target = static_cast<GLenum>(c.target); |
| 13284 | GLint level = static_cast<GLint>(c.level); |
| 13285 | GLint xoffset = static_cast<GLint>(c.xoffset); |
| 13286 | GLint yoffset = static_cast<GLint>(c.yoffset); |
| 13287 | GLsizei width = static_cast<GLsizei>(c.width); |
| 13288 | GLsizei height = static_cast<GLsizei>(c.height); |
| 13289 | GLenum format = static_cast<GLenum>(c.format); |
| 13290 | GLenum type = static_cast<GLenum>(c.type); |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 13291 | uint32 async_upload_token = static_cast<uint32>(c.async_upload_token); |
| 13292 | uint32 sync_data_shm_id = static_cast<uint32>(c.sync_data_shm_id); |
| 13293 | uint32 sync_data_shm_offset = static_cast<uint32>(c.sync_data_shm_offset); |
| 13294 | |
| 13295 | base::ScopedClosureRunner scoped_completion_callback; |
| 13296 | if (async_upload_token) { |
| 13297 | base::Closure completion_closure = |
| 13298 | AsyncUploadTokenCompletionClosure(async_upload_token, |
| 13299 | sync_data_shm_id, |
| 13300 | sync_data_shm_offset); |
| 13301 | if (completion_closure.is_null()) |
| 13302 | return error::kInvalidArguments; |
| 13303 | |
| 13304 | scoped_completion_callback.Reset(completion_closure); |
| 13305 | } |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13306 | |
| 13307 | // TODO(epenner): Move this and copies of this memory validation |
| 13308 | // into ValidateTexSubImage2D step. |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13309 | uint32 data_size; |
| 13310 | if (!GLES2Util::ComputeImageDataSizes( |
zmo | bcadd659 | 2015-01-08 20:13:42 | [diff] [blame] | 13311 | width, height, 1, format, type, state_.unpack_alignment, &data_size, |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13312 | NULL, NULL)) { |
| 13313 | return error::kOutOfBounds; |
| 13314 | } |
| 13315 | const void* pixels = GetSharedMemoryAs<const void*>( |
| 13316 | c.data_shm_id, c.data_shm_offset, data_size); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13317 | |
| 13318 | // All the normal glTexSubImage2D validation. |
| 13319 | error::Error error = error::kNoError; |
| 13320 | if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2DCHROMIUM", |
| 13321 | target, level, xoffset, yoffset, width, height, format, type, pixels)) { |
| 13322 | return error; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13323 | } |
| 13324 | |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13325 | // Extra async validation. |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 13326 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 13327 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 13328 | Texture* texture = texture_ref->texture(); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13329 | if (!ValidateAsyncTransfer( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 13330 | "glAsyncTexSubImage2DCHROMIUM", texture_ref, target, level, pixels)) |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13331 | return error::kNoError; |
| 13332 | |
| 13333 | // Guarantee async textures are always 'cleared' as follows: |
| 13334 | // - AsyncTexImage2D can not redefine an existing texture |
| 13335 | // - AsyncTexImage2D must initialize the entire image via non-null buffer. |
| 13336 | // - AsyncTexSubImage2D clears synchronously if not already cleared. |
| 13337 | // - Textures become immutable after an async call. |
| 13338 | // 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] | 13339 | if (!texture->SafeToRenderFrom()) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 13340 | if (!texture_manager()->ClearTextureLevel(this, texture_ref, |
| 13341 | target, level)) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13342 | LOCAL_SET_GL_ERROR( |
| 13343 | GL_OUT_OF_MEMORY, |
[email protected] | b04e24c | 2013-01-08 18:35:25 | [diff] [blame] | 13344 | "glAsyncTexSubImage2DCHROMIUM", "dimensions too big"); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13345 | return error::kNoError; |
| 13346 | } |
| 13347 | } |
| 13348 | |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13349 | // Setup the parameters. |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 13350 | AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset, |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13351 | width, height, format, type}; |
[email protected] | c8021e0 | 2014-03-27 06:10:12 | [diff] [blame] | 13352 | AsyncMemoryParams mem_params( |
| 13353 | GetSharedMemoryBuffer(c.data_shm_id), c.data_shm_offset, data_size); |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 13354 | AsyncPixelTransferDelegate* delegate = |
| 13355 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 13356 | if (!delegate) { |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13357 | // TODO(epenner): We may want to enforce exclusive use |
| 13358 | // of async APIs in which case this should become an error, |
| 13359 | // (the texture should have been async defined). |
[email protected] | 2a7568a | 2013-05-09 23:12:03 | [diff] [blame] | 13360 | AsyncTexImage2DParams define_params = {target, level, |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13361 | 0, 0, 0, 0, 0, 0}; |
zmo | 9a7b17e | 2015-05-06 00:22:33 | [diff] [blame] | 13362 | texture->GetLevelSize( |
| 13363 | target, level, &define_params.width, &define_params.height, nullptr); |
| 13364 | texture->GetLevelType( |
| 13365 | target, level, &define_params.type, &define_params.internal_format); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13366 | // Set up the async state if needed, and make the texture |
| 13367 | // immutable so the async state stays valid. |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 13368 | delegate = async_pixel_transfer_manager_->CreatePixelTransferDelegate( |
[email protected] | 85a4ac2 | 2013-05-31 01:58:47 | [diff] [blame] | 13369 | texture_ref, define_params); |
[email protected] | 5b3a8e0 | 2013-03-13 05:36:44 | [diff] [blame] | 13370 | texture->SetImmutable(true); |
| 13371 | } |
| 13372 | |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 13373 | delegate->AsyncTexSubImage2D(tex_params, mem_params); |
[email protected] | 32145a9 | 2012-12-17 09:01:59 | [diff] [blame] | 13374 | return error::kNoError; |
[email protected] | 6902394 | 2012-11-30 19:57:16 | [diff] [blame] | 13375 | } |
| 13376 | |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 13377 | error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 13378 | uint32 immediate_data_size, |
| 13379 | const void* cmd_data) { |
| 13380 | const gles2::cmds::WaitAsyncTexImage2DCHROMIUM& c = |
| 13381 | *static_cast<const gles2::cmds::WaitAsyncTexImage2DCHROMIUM*>(cmd_data); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 13382 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); |
| 13383 | GLenum target = static_cast<GLenum>(c.target); |
| 13384 | |
| 13385 | if (GL_TEXTURE_2D != target) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13386 | LOCAL_SET_GL_ERROR( |
| 13387 | GL_INVALID_ENUM, "glWaitAsyncTexImage2DCHROMIUM", "target"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 13388 | return error::kNoError; |
| 13389 | } |
[email protected] | c986af50 | 2013-08-14 01:04:44 | [diff] [blame] | 13390 | TextureRef* texture_ref = texture_manager()->GetTextureInfoForTarget( |
| 13391 | &state_, target); |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 13392 | if (!texture_ref) { |
[email protected] | ab09b61 | 2013-03-11 22:11:51 | [diff] [blame] | 13393 | LOCAL_SET_GL_ERROR( |
| 13394 | GL_INVALID_OPERATION, |
| 13395 | "glWaitAsyncTexImage2DCHROMIUM", "unknown texture"); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 13396 | return error::kNoError; |
| 13397 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 13398 | AsyncPixelTransferDelegate* delegate = |
| 13399 | async_pixel_transfer_manager_->GetPixelTransferDelegate(texture_ref); |
| 13400 | if (!delegate) { |
[email protected] | 370eaf1 | 2013-05-18 09:19:49 | [diff] [blame] | 13401 | LOCAL_SET_GL_ERROR( |
| 13402 | GL_INVALID_OPERATION, |
| 13403 | "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started"); |
| 13404 | return error::kNoError; |
| 13405 | } |
[email protected] | 896425e | 2013-06-12 17:27:18 | [diff] [blame] | 13406 | delegate->WaitForTransferCompletion(); |
[email protected] | 69a8701e | 2013-03-07 21:31:09 | [diff] [blame] | 13407 | ProcessFinishedAsyncTransfers(); |
[email protected] | a00c1f74 | 2013-03-05 17:02:16 | [diff] [blame] | 13408 | return error::kNoError; |
| 13409 | } |
| 13410 | |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 13411 | error::Error GLES2DecoderImpl::HandleWaitAllAsyncTexImage2DCHROMIUM( |
vmiura | cd10859 | 2014-09-08 14:36:34 | [diff] [blame] | 13412 | uint32 immediate_data_size, |
| 13413 | const void* data) { |
[email protected] | e3c4a9ab | 2014-03-31 09:07:02 | [diff] [blame] | 13414 | TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); |
| 13415 | |
| 13416 | GetAsyncPixelTransferManager()->WaitAllAsyncTexImage2D(); |
| 13417 | ProcessFinishedAsyncTransfers(); |
| 13418 | return error::kNoError; |
| 13419 | } |
| 13420 | |
zmo | 8fab00c | 2015-02-07 02:45:05 | [diff] [blame] | 13421 | error::Error GLES2DecoderImpl::HandleUniformBlockBinding( |
| 13422 | uint32_t immediate_data_size, const void* cmd_data) { |
| 13423 | if (!unsafe_es3_apis_enabled()) |
| 13424 | return error::kUnknownCommand; |
| 13425 | const gles2::cmds::UniformBlockBinding& c = |
| 13426 | *static_cast<const gles2::cmds::UniformBlockBinding*>(cmd_data); |
| 13427 | GLuint client_id = c.program; |
| 13428 | GLuint index = static_cast<GLuint>(c.index); |
| 13429 | GLuint binding = static_cast<GLuint>(c.binding); |
| 13430 | Program* program = GetProgramInfoNotShader( |
| 13431 | client_id, "glUniformBlockBinding"); |
| 13432 | if (!program) { |
| 13433 | return error::kNoError; |
| 13434 | } |
| 13435 | GLuint service_id = program->service_id(); |
| 13436 | glUniformBlockBinding(service_id, index, binding); |
| 13437 | return error::kNoError; |
| 13438 | } |
| 13439 | |
zmo | 3366957e | 2015-02-18 23:40:07 | [diff] [blame] | 13440 | error::Error GLES2DecoderImpl::HandleClientWaitSync( |
| 13441 | uint32_t immediate_data_size, const void* cmd_data) { |
| 13442 | if (!unsafe_es3_apis_enabled()) |
| 13443 | return error::kUnknownCommand; |
| 13444 | const gles2::cmds::ClientWaitSync& c = |
| 13445 | *static_cast<const gles2::cmds::ClientWaitSync*>(cmd_data); |
| 13446 | GLuint sync = static_cast<GLuint>(c.sync); |
| 13447 | GLbitfield flags = static_cast<GLbitfield>(c.flags); |
| 13448 | GLuint64 timeout = GLES2Util::MapTwoUint32ToUint64(c.timeout_0, c.timeout_1); |
| 13449 | typedef cmds::ClientWaitSync::Result Result; |
| 13450 | Result* result_dst = GetSharedMemoryAs<Result*>( |
| 13451 | c.result_shm_id, c.result_shm_offset, sizeof(*result_dst)); |
| 13452 | if (!result_dst) { |
| 13453 | return error::kOutOfBounds; |
| 13454 | } |
| 13455 | if (*result_dst != GL_WAIT_FAILED) { |
| 13456 | return error::kInvalidArguments; |
| 13457 | } |
| 13458 | GLsync service_sync = 0; |
| 13459 | if (!group_->GetSyncServiceId(sync, &service_sync)) { |
| 13460 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "ClientWaitSync", "invalid sync"); |
| 13461 | return error::kNoError; |
| 13462 | } |
| 13463 | *result_dst = glClientWaitSync(service_sync, flags, timeout); |
| 13464 | return error::kNoError; |
| 13465 | } |
| 13466 | |
zmo | 41e4058 | 2015-02-19 02:13:30 | [diff] [blame] | 13467 | error::Error GLES2DecoderImpl::HandleWaitSync( |
| 13468 | uint32_t immediate_data_size, const void* cmd_data) { |
| 13469 | if (!unsafe_es3_apis_enabled()) |
| 13470 | return error::kUnknownCommand; |
| 13471 | const gles2::cmds::WaitSync& c = |
| 13472 | *static_cast<const gles2::cmds::WaitSync*>(cmd_data); |
| 13473 | GLuint sync = static_cast<GLuint>(c.sync); |
| 13474 | GLbitfield flags = static_cast<GLbitfield>(c.flags); |
| 13475 | GLuint64 timeout = GLES2Util::MapTwoUint32ToUint64(c.timeout_0, c.timeout_1); |
| 13476 | GLsync service_sync = 0; |
| 13477 | if (!group_->GetSyncServiceId(sync, &service_sync)) { |
| 13478 | LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "WaitSync", "invalid sync"); |
| 13479 | return error::kNoError; |
| 13480 | } |
| 13481 | glWaitSync(service_sync, flags, timeout); |
| 13482 | return error::kNoError; |
| 13483 | } |
| 13484 | |
zmo | 335fe541 | 2015-06-05 22:23:43 | [diff] [blame] | 13485 | error::Error GLES2DecoderImpl::HandleGetInternalformativ( |
| 13486 | uint32_t immediate_data_size, const void* cmd_data) { |
| 13487 | if (!unsafe_es3_apis_enabled()) |
| 13488 | return error::kUnknownCommand; |
| 13489 | const gles2::cmds::GetInternalformativ& c = |
| 13490 | *static_cast<const gles2::cmds::GetInternalformativ*>(cmd_data); |
| 13491 | GLenum target = static_cast<GLenum>(c.target); |
| 13492 | GLenum format = static_cast<GLenum>(c.format); |
| 13493 | GLenum pname = static_cast<GLenum>(c.pname); |
| 13494 | if (!validators_->render_buffer_target.IsValid(target)) { |
| 13495 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glGetInternalformativ", target, "target"); |
| 13496 | return error::kNoError; |
| 13497 | } |
| 13498 | if (!validators_->render_buffer_format.IsValid(format)) { |
| 13499 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glGetInternalformativ", format, "format"); |
| 13500 | return error::kNoError; |
| 13501 | } |
| 13502 | if (!validators_->internal_format_parameter.IsValid(pname)) { |
| 13503 | LOCAL_SET_GL_ERROR_INVALID_ENUM("glGetInternalformativ", pname, "pname"); |
| 13504 | return error::kNoError; |
| 13505 | } |
| 13506 | typedef cmds::GetInternalformativ::Result Result; |
| 13507 | GLsizei num_values = 0; |
| 13508 | switch (pname) { |
| 13509 | case GL_NUM_SAMPLE_COUNTS: |
| 13510 | num_values = 1; |
| 13511 | break; |
| 13512 | case GL_SAMPLES: |
| 13513 | { |
| 13514 | GLint value = 0; |
| 13515 | glGetInternalformativ(target, format, GL_NUM_SAMPLE_COUNTS, 1, &value); |
| 13516 | num_values = static_cast<GLsizei>(value); |
| 13517 | } |
| 13518 | break; |
| 13519 | default: |
| 13520 | NOTREACHED(); |
| 13521 | break; |
| 13522 | } |
| 13523 | Result* result = GetSharedMemoryAs<Result*>( |
| 13524 | c.params_shm_id, c.params_shm_offset, Result::ComputeSize(num_values)); |
| 13525 | GLint* params = result ? result->GetData() : NULL; |
| 13526 | if (params == NULL) { |
| 13527 | return error::kOutOfBounds; |
| 13528 | } |
| 13529 | // Check that the client initialized the result. |
| 13530 | if (result->size != 0) { |
| 13531 | return error::kInvalidArguments; |
| 13532 | } |
| 13533 | glGetInternalformativ(target, format, pname, num_values, params); |
| 13534 | result->SetNumResults(num_values); |
| 13535 | return error::kNoError; |
| 13536 | } |
| 13537 | |
zmo | a06b988 | 2015-03-10 20:50:34 | [diff] [blame] | 13538 | error::Error GLES2DecoderImpl::HandleMapBufferRange( |
| 13539 | uint32_t immediate_data_size, const void* cmd_data) { |
| 13540 | if (!unsafe_es3_apis_enabled()) { |
| 13541 | return error::kUnknownCommand; |
| 13542 | } |
| 13543 | const gles2::cmds::MapBufferRange& c = |
| 13544 | *static_cast<const gles2::cmds::MapBufferRange*>(cmd_data); |
| 13545 | GLenum target = static_cast<GLenum>(c.target); |
| 13546 | GLbitfield access = static_cast<GLbitfield>(c.access); |
| 13547 | GLintptr offset = static_cast<GLintptr>(c.offset); |
| 13548 | GLsizeiptr size = static_cast<GLsizeiptr>(c.size); |
| 13549 | |
| 13550 | typedef cmds::MapBufferRange::Result Result; |
| 13551 | Result* result = GetSharedMemoryAs<Result*>( |
| 13552 | c.result_shm_id, c.result_shm_offset, sizeof(*result)); |
| 13553 | if (!result) { |
| 13554 | return error::kOutOfBounds; |
| 13555 | } |
| 13556 | if (*result != 0) { |
| 13557 | *result = 0; |
| 13558 | return error::kInvalidArguments; |
| 13559 | } |
| 13560 | int8_t* mem = |
| 13561 | GetSharedMemoryAs<int8_t*>(c.data_shm_id, c.data_shm_offset, size); |
| 13562 | if (!mem) { |
| 13563 | return error::kOutOfBounds; |
| 13564 | } |
| 13565 | |
| 13566 | GLbitfield mask = GL_MAP_INVALIDATE_BUFFER_BIT; |
| 13567 | if ((access & mask) == mask) { |
| 13568 | // TODO(zmo): To be on the safe side, always map |
| 13569 | // GL_MAP_INVALIDATE_BUFFER_BIT to GL_MAP_INVALIDATE_RANGE_BIT. |
| 13570 | access = (access & ~GL_MAP_INVALIDATE_BUFFER_BIT); |
| 13571 | access = (access | GL_MAP_INVALIDATE_RANGE_BIT); |
| 13572 | } |
| 13573 | // TODO(zmo): Always filter out GL_MAP_UNSYNCHRONIZED_BIT to get rid of |
| 13574 | // undefined behaviors. |
| 13575 | mask = GL_MAP_READ_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 13576 | if ((access & mask) == mask) { |
| 13577 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "MapBufferRange", |
| 13578 | "incompatible access bits"); |
| 13579 | return error::kNoError; |
| 13580 | } |
| 13581 | access = (access & ~GL_MAP_UNSYNCHRONIZED_BIT); |
| 13582 | if ((access & GL_MAP_WRITE_BIT) == GL_MAP_WRITE_BIT && |
| 13583 | (access & GL_MAP_INVALIDATE_RANGE_BIT) == 0) { |
| 13584 | access = (access | GL_MAP_READ_BIT); |
| 13585 | } |
| 13586 | void* ptr = glMapBufferRange(target, offset, size, access); |
| 13587 | if (ptr == nullptr) { |
| 13588 | return error::kNoError; |
| 13589 | } |
| 13590 | Buffer* buffer = buffer_manager()->GetBufferInfoForTarget(&state_, target); |
| 13591 | DCHECK(buffer); |
zmo | 2a09dc05 | 2015-03-12 00:48:25 | [diff] [blame] | 13592 | buffer->SetMappedRange(offset, size, access, ptr, |
| 13593 | GetSharedMemoryBuffer(c.data_shm_id)); |
zmo | a06b988 | 2015-03-10 20:50:34 | [diff] [blame] | 13594 | if ((access & GL_MAP_INVALIDATE_RANGE_BIT) == 0) { |
| 13595 | memcpy(mem, ptr, size); |
| 13596 | } |
| 13597 | *result = 1; |
| 13598 | return error::kNoError; |
| 13599 | } |
| 13600 | |
zmo | 2a09dc05 | 2015-03-12 00:48:25 | [diff] [blame] | 13601 | error::Error GLES2DecoderImpl::HandleUnmapBuffer( |
| 13602 | uint32_t immediate_data_size, const void* cmd_data) { |
| 13603 | if (!unsafe_es3_apis_enabled()) { |
| 13604 | return error::kUnknownCommand; |
| 13605 | } |
| 13606 | const gles2::cmds::UnmapBuffer& c = |
| 13607 | *static_cast<const gles2::cmds::UnmapBuffer*>(cmd_data); |
| 13608 | GLenum target = static_cast<GLenum>(c.target); |
| 13609 | |
| 13610 | Buffer* buffer = buffer_manager()->GetBufferInfoForTarget(&state_, target); |
| 13611 | if (!buffer) { |
| 13612 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "UnmapBuffer", "no buffer bound"); |
| 13613 | return error::kNoError; |
| 13614 | } |
| 13615 | const Buffer::MappedRange* mapped_range = buffer->GetMappedRange(); |
| 13616 | if (!mapped_range) { |
| 13617 | LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, "UnmapBuffer", |
| 13618 | "buffer is unmapped"); |
| 13619 | return error::kNoError; |
| 13620 | } |
| 13621 | if ((mapped_range->access & GL_MAP_WRITE_BIT) == 0 || |
| 13622 | (mapped_range->access & GL_MAP_FLUSH_EXPLICIT_BIT) == |
| 13623 | GL_MAP_FLUSH_EXPLICIT_BIT) { |
| 13624 | // If we don't need to write back, or explict flush is required, no copying |
| 13625 | // back is needed. |
| 13626 | } else { |
| 13627 | void* mem = mapped_range->GetShmPointer(); |
| 13628 | if (!mem) { |
| 13629 | return error::kOutOfBounds; |
| 13630 | } |
| 13631 | DCHECK(mapped_range->pointer); |
| 13632 | memcpy(mapped_range->pointer, mem, mapped_range->size); |
| 13633 | } |
| 13634 | buffer->RemoveMappedRange(); |
| 13635 | GLboolean rt = glUnmapBuffer(target); |
| 13636 | if (rt == GL_FALSE) { |
| 13637 | // At this point, we have already done the necessary validation, so |
| 13638 | // GL_FALSE indicates data corruption. |
| 13639 | // TODO(zmo): We could redo the map / copy data / unmap to recover, but |
| 13640 | // the second unmap could still return GL_FALSE. For now, we simply lose |
| 13641 | // the contexts in the share group. |
| 13642 | LOG(ERROR) << "glUnmapBuffer unexpectedly returned GL_FALSE"; |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 13643 | // Need to lose current context before broadcasting! |
| 13644 | MarkContextLost(error::kGuilty); |
| 13645 | group_->LoseContexts(error::kInnocent); |
zmo | 2a09dc05 | 2015-03-12 00:48:25 | [diff] [blame] | 13646 | return error::kLostContext; |
| 13647 | } |
| 13648 | return error::kNoError; |
| 13649 | } |
| 13650 | |
[email protected] | 91c94eb | 2013-10-22 10:32:54 | [diff] [blame] | 13651 | void GLES2DecoderImpl::OnTextureRefDetachedFromFramebuffer( |
| 13652 | TextureRef* texture_ref) { |
| 13653 | Texture* texture = texture_ref->texture(); |
| 13654 | DoDidUseTexImageIfNeeded(texture, texture->target()); |
| 13655 | } |
| 13656 | |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 13657 | // Note that GL_LOST_CONTEXT is specific to GLES. |
| 13658 | // For desktop GL we have to query the reset status proactively. |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 13659 | void GLES2DecoderImpl::OnContextLostError() { |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 13660 | if (!WasContextLost()) { |
| 13661 | // Need to lose current context before broadcasting! |
| 13662 | CheckResetStatus(); |
| 13663 | group_->LoseContexts(error::kUnknown); |
| 13664 | reset_by_robustness_extension_ = true; |
| 13665 | } |
oetuaho | 37cc50e | 2014-10-31 11:19:20 | [diff] [blame] | 13666 | } |
| 13667 | |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 13668 | void GLES2DecoderImpl::OnOutOfMemoryError() { |
sievers | fbaa5dc | 2015-04-28 00:45:31 | [diff] [blame] | 13669 | if (lose_context_when_out_of_memory_ && !WasContextLost()) { |
| 13670 | error::ContextLostReason other = error::kOutOfMemory; |
| 13671 | if (CheckResetStatus()) { |
| 13672 | other = error::kUnknown; |
| 13673 | } else { |
| 13674 | // Need to lose current context before broadcasting! |
| 13675 | MarkContextLost(error::kOutOfMemory); |
| 13676 | } |
| 13677 | group_->LoseContexts(other); |
[email protected] | 828a393 | 2014-04-02 14:43:13 | [diff] [blame] | 13678 | } |
| 13679 | } |
| 13680 | |
[email protected] | 96449d2c | 2009-11-25 00:01:32 | [diff] [blame] | 13681 | // Include the auto-generated part of this file. We split this because it means |
| 13682 | // we can easily edit the non-auto generated parts right here in this file |
| 13683 | // instead of having to edit some template or the code generator. |
| 13684 | #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" |
| 13685 | |
| 13686 | } // namespace gles2 |
[email protected] | a7a27ace | 2009-12-12 00:11:25 | [diff] [blame] | 13687 | } // namespace gpu |