OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // A class to emulate GLES2 over command buffers. | 5 // A class to emulate GLES2 over command buffers. |
6 | 6 |
7 #include "gpu/command_buffer/client/gles2_implementation.h" | 7 #include "gpu/command_buffer/client/gles2_implementation.h" |
8 | 8 |
9 #include <GLES2/gl2ext.h> | 9 #include <GLES2/gl2ext.h> |
10 #include <GLES2/gl2extchromium.h> | 10 #include <GLES2/gl2extchromium.h> |
(...skipping 2192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2203 helper_->GetString(name, kResultBucketId); | 2203 helper_->GetString(name, kResultBucketId); |
2204 std::string str; | 2204 std::string str; |
2205 if (GetBucketAsString(kResultBucketId, &str)) { | 2205 if (GetBucketAsString(kResultBucketId, &str)) { |
2206 // Adds extensions implemented on client side only. | 2206 // Adds extensions implemented on client side only. |
2207 switch (name) { | 2207 switch (name) { |
2208 case GL_EXTENSIONS: | 2208 case GL_EXTENSIONS: |
2209 str += std::string(str.empty() ? "" : " ") + | 2209 str += std::string(str.empty() ? "" : " ") + |
2210 "GL_CHROMIUM_flipy " | 2210 "GL_CHROMIUM_flipy " |
2211 "GL_EXT_unpack_subimage " | 2211 "GL_EXT_unpack_subimage " |
2212 "GL_CHROMIUM_map_sub"; | 2212 "GL_CHROMIUM_map_sub"; |
2213 if (capabilities_.image) { | 2213 if (capabilities_.image) |
2214 // The first space character is intentional. | 2214 str += " GL_CHROMIUM_image GL_CHROMIUM_gpu_memory_buffer_image"; |
2215 str += " GL_CHROMIUM_image"; | |
2216 } | |
2217 if (capabilities_.future_sync_points) | 2215 if (capabilities_.future_sync_points) |
2218 str += " GL_CHROMIUM_future_sync_point"; | 2216 str += " GL_CHROMIUM_future_sync_point"; |
2219 break; | 2217 break; |
2220 default: | 2218 default: |
2221 break; | 2219 break; |
2222 } | 2220 } |
2223 | 2221 |
2224 // Because of WebGL the extensions can change. We have to cache each unique | 2222 // Because of WebGL the extensions can change. We have to cache each unique |
2225 // result since we don't know when the client will stop referring to a | 2223 // result since we don't know when the client will stop referring to a |
2226 // previous one it queries. | 2224 // previous one it queries. |
(...skipping 1780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4007 | 4005 |
4008 void GLES2Implementation::RetireSyncPointCHROMIUM(GLuint sync_point) { | 4006 void GLES2Implementation::RetireSyncPointCHROMIUM(GLuint sync_point) { |
4009 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 4007 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
4010 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glRetireSyncPointCHROMIUM(" | 4008 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glRetireSyncPointCHROMIUM(" |
4011 << sync_point << ")"); | 4009 << sync_point << ")"); |
4012 DCHECK(capabilities_.future_sync_points); | 4010 DCHECK(capabilities_.future_sync_points); |
4013 helper_->CommandBufferHelper::Flush(); | 4011 helper_->CommandBufferHelper::Flush(); |
4014 gpu_control_->RetireSyncPoint(sync_point); | 4012 gpu_control_->RetireSyncPoint(sync_point); |
4015 } | 4013 } |
4016 | 4014 |
| 4015 namespace { |
| 4016 |
| 4017 bool ValidImageFormat(GLenum internalformat) { |
| 4018 switch (internalformat) { |
| 4019 case GL_RGB: |
| 4020 case GL_RGBA: |
| 4021 return true; |
| 4022 default: |
| 4023 return false; |
| 4024 } |
| 4025 } |
| 4026 |
| 4027 bool ValidImageUsage(GLenum usage) { |
| 4028 switch (usage) { |
| 4029 case GL_MAP_CHROMIUM: |
| 4030 case GL_SCANOUT_CHROMIUM: |
| 4031 return true; |
| 4032 default: |
| 4033 return false; |
| 4034 } |
| 4035 } |
| 4036 |
| 4037 } // namespace |
| 4038 |
4017 GLuint GLES2Implementation::CreateImageCHROMIUMHelper(GLsizei width, | 4039 GLuint GLES2Implementation::CreateImageCHROMIUMHelper(GLsizei width, |
4018 GLsizei height, | 4040 GLsizei height, |
4019 GLenum internalformat, | 4041 GLenum internalformat, |
4020 GLenum usage) { | 4042 GLenum usage) { |
4021 if (width <= 0) { | 4043 if (width <= 0) { |
4022 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "width <= 0"); | 4044 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "width <= 0"); |
4023 return 0; | 4045 return 0; |
4024 } | 4046 } |
4025 | 4047 |
4026 if (height <= 0) { | 4048 if (height <= 0) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4159 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 4181 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
4160 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); | 4182 GPU_CLIENT_VALIDATE_DESTINATION_INITALIZATION(GLint, params); |
4161 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glImageParameterivCHROMIUM(" | 4183 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glImageParameterivCHROMIUM(" |
4162 << image_id << ", " | 4184 << image_id << ", " |
4163 << GLES2Util::GetStringBufferParameter(pname) << ", " | 4185 << GLES2Util::GetStringBufferParameter(pname) << ", " |
4164 << static_cast<const void*>(params) << ")"); | 4186 << static_cast<const void*>(params) << ")"); |
4165 GetImageParameterivCHROMIUMHelper(image_id, pname, params); | 4187 GetImageParameterivCHROMIUMHelper(image_id, pname, params); |
4166 CheckGLError(); | 4188 CheckGLError(); |
4167 } | 4189 } |
4168 | 4190 |
| 4191 GLuint GLES2Implementation::CreateGpuMemoryBufferImageCHROMIUMHelper( |
| 4192 GLsizei width, |
| 4193 GLsizei height, |
| 4194 GLenum internalformat, |
| 4195 GLenum usage) { |
| 4196 if (width <= 0) { |
| 4197 SetGLError( |
| 4198 GL_INVALID_VALUE, "glCreateGpuMemoryBufferImageCHROMIUM", "width <= 0"); |
| 4199 return 0; |
| 4200 } |
| 4201 |
| 4202 if (height <= 0) { |
| 4203 SetGLError(GL_INVALID_VALUE, |
| 4204 "glCreateGpuMemoryBufferImageCHROMIUM", |
| 4205 "height <= 0"); |
| 4206 return 0; |
| 4207 } |
| 4208 |
| 4209 if (!ValidImageFormat(internalformat)) { |
| 4210 SetGLError(GL_INVALID_VALUE, |
| 4211 "glCreateGpuMemoryBufferImageCHROMIUM", |
| 4212 "invalid format"); |
| 4213 return 0; |
| 4214 } |
| 4215 |
| 4216 if (!ValidImageUsage(usage)) { |
| 4217 SetGLError(GL_INVALID_VALUE, |
| 4218 "glCreateGpuMemoryBufferImageCHROMIUM", |
| 4219 "invalid usage"); |
| 4220 return 0; |
| 4221 } |
| 4222 |
| 4223 // Flush the command stream to ensure ordering in case the newly |
| 4224 // returned image_id has recently been in use with a different buffer. |
| 4225 helper_->CommandBufferHelper::Flush(); |
| 4226 |
| 4227 // Create new buffer. |
| 4228 GLuint buffer_id = gpu_memory_buffer_tracker_->CreateBuffer( |
| 4229 width, |
| 4230 height, |
| 4231 internalformat == GL_RGBA ? GL_RGBA8_OES : GL_RGB8_OES, |
| 4232 usage); |
| 4233 if (buffer_id == 0) { |
| 4234 SetGLError(GL_OUT_OF_MEMORY, |
| 4235 "glCreateGpuMemoryBufferImageCHROMIUM", |
| 4236 "out of GPU memory"); |
| 4237 return 0; |
| 4238 } |
| 4239 return buffer_id; |
| 4240 } |
| 4241 |
| 4242 GLuint GLES2Implementation::CreateGpuMemoryBufferImageCHROMIUM( |
| 4243 GLsizei width, |
| 4244 GLsizei height, |
| 4245 GLenum internalformat, |
| 4246 GLenum usage) { |
| 4247 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 4248 GPU_CLIENT_LOG("[" << GetLogPrefix() |
| 4249 << "] glCreateGpuMemoryBufferImageCHROMIUM(" << width |
| 4250 << ", " << height << ", " |
| 4251 << GLES2Util::GetStringImageInternalFormat(internalformat) |
| 4252 << ", " << GLES2Util::GetStringImageUsage(usage) << ")"); |
| 4253 GLuint image_id = CreateGpuMemoryBufferImageCHROMIUMHelper( |
| 4254 width, height, internalformat, usage); |
| 4255 CheckGLError(); |
| 4256 return image_id; |
| 4257 } |
| 4258 |
4169 bool GLES2Implementation::ValidateSize(const char* func, GLsizeiptr size) { | 4259 bool GLES2Implementation::ValidateSize(const char* func, GLsizeiptr size) { |
4170 if (size < 0) { | 4260 if (size < 0) { |
4171 SetGLError(GL_INVALID_VALUE, func, "size < 0"); | 4261 SetGLError(GL_INVALID_VALUE, func, "size < 0"); |
4172 return false; | 4262 return false; |
4173 } | 4263 } |
4174 if (!FitInt32NonNegative<GLsizeiptr>(size)) { | 4264 if (!FitInt32NonNegative<GLsizeiptr>(size)) { |
4175 SetGLError(GL_INVALID_OPERATION, func, "size more than 32-bit"); | 4265 SetGLError(GL_INVALID_OPERATION, func, "size more than 32-bit"); |
4176 return false; | 4266 return false; |
4177 } | 4267 } |
4178 return true; | 4268 return true; |
(...skipping 11 matching lines...) Expand all Loading... |
4190 return true; | 4280 return true; |
4191 } | 4281 } |
4192 | 4282 |
4193 // Include the auto-generated part of this file. We split this because it means | 4283 // Include the auto-generated part of this file. We split this because it means |
4194 // we can easily edit the non-auto generated parts right here in this file | 4284 // we can easily edit the non-auto generated parts right here in this file |
4195 // instead of having to edit some template or the code generator. | 4285 // instead of having to edit some template or the code generator. |
4196 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 4286 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
4197 | 4287 |
4198 } // namespace gles2 | 4288 } // namespace gles2 |
4199 } // namespace gpu | 4289 } // namespace gpu |
OLD | NEW |