| 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 3931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3942 CheckGLError(); | 3942 CheckGLError(); |
| 3943 } | 3943 } |
| 3944 | 3944 |
| 3945 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() { | 3945 GLuint GLES2Implementation::InsertSyncPointCHROMIUM() { |
| 3946 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 3946 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 3947 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM"); | 3947 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glInsertSyncPointCHROMIUM"); |
| 3948 helper_->CommandBufferHelper::Flush(); | 3948 helper_->CommandBufferHelper::Flush(); |
| 3949 return gpu_control_->InsertSyncPoint(); | 3949 return gpu_control_->InsertSyncPoint(); |
| 3950 } | 3950 } |
| 3951 | 3951 |
| 3952 GLuint GLES2Implementation::CreateImageCHROMIUMHelper( | 3952 GLuint GLES2Implementation::CreateImageCHROMIUMHelper(GLsizei width, |
| 3953 GLsizei width, GLsizei height, GLenum internalformat) { | 3953 GLsizei height, |
| 3954 GLenum internalformat, |
| 3955 GLenum usage) { |
| 3954 if (width <= 0) { | 3956 if (width <= 0) { |
| 3955 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "width <= 0"); | 3957 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "width <= 0"); |
| 3956 return 0; | 3958 return 0; |
| 3957 } | 3959 } |
| 3958 | 3960 |
| 3959 if (height <= 0) { | 3961 if (height <= 0) { |
| 3960 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "height <= 0"); | 3962 SetGLError(GL_INVALID_VALUE, "glCreateImageCHROMIUM", "height <= 0"); |
| 3961 return 0; | 3963 return 0; |
| 3962 } | 3964 } |
| 3963 // Flush the command stream to ensure ordering in case the newly | 3965 // Flush the command stream to ensure ordering in case the newly |
| 3964 // returned image_id has recently been in use with a different buffer. | 3966 // returned image_id has recently been in use with a different buffer. |
| 3965 helper_->CommandBufferHelper::Flush(); | 3967 helper_->CommandBufferHelper::Flush(); |
| 3966 | 3968 |
| 3967 // Create new buffer. | 3969 // Create new buffer. |
| 3968 GLuint buffer_id = gpu_memory_buffer_tracker_->CreateBuffer( | 3970 GLuint buffer_id = gpu_memory_buffer_tracker_->CreateBuffer( |
| 3969 width, height, internalformat); | 3971 width, height, internalformat, usage); |
| 3970 if (buffer_id == 0) { | 3972 if (buffer_id == 0) { |
| 3971 SetGLError(GL_OUT_OF_MEMORY, "glCreateImageCHROMIUM", "out of GPU memory."); | 3973 SetGLError(GL_OUT_OF_MEMORY, "glCreateImageCHROMIUM", "out of GPU memory."); |
| 3972 return 0; | 3974 return 0; |
| 3973 } | 3975 } |
| 3974 return buffer_id; | 3976 return buffer_id; |
| 3975 } | 3977 } |
| 3976 | 3978 |
| 3977 GLuint GLES2Implementation::CreateImageCHROMIUM( | 3979 GLuint GLES2Implementation::CreateImageCHROMIUM(GLsizei width, |
| 3978 GLsizei width, GLsizei height, GLenum internalformat) { | 3980 GLsizei height, |
| 3981 GLenum internalformat, |
| 3982 GLenum usage) { |
| 3979 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 3983 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 3980 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glCreateImageCHROMIUM(" | 3984 GPU_CLIENT_LOG( |
| 3981 << width << ", " | 3985 "[" << GetLogPrefix() << "] glCreateImageCHROMIUM(" << width << ", " |
| 3982 << height << ", " | 3986 << height << ", " |
| 3983 << GLES2Util::GetStringTextureInternalFormat(internalformat) << ")"); | 3987 << GLES2Util::GetStringTextureInternalFormat(internalformat) << ", " |
| 3984 GLuint image_id = CreateImageCHROMIUMHelper(width, height, internalformat); | 3988 << GLES2Util::GetStringTextureInternalFormat(usage) << ")"); |
| 3989 GLuint image_id = |
| 3990 CreateImageCHROMIUMHelper(width, height, internalformat, usage); |
| 3985 CheckGLError(); | 3991 CheckGLError(); |
| 3986 return image_id; | 3992 return image_id; |
| 3987 } | 3993 } |
| 3988 | 3994 |
| 3989 void GLES2Implementation::DestroyImageCHROMIUMHelper(GLuint image_id) { | 3995 void GLES2Implementation::DestroyImageCHROMIUMHelper(GLuint image_id) { |
| 3990 gfx::GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer( | 3996 gfx::GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer( |
| 3991 image_id); | 3997 image_id); |
| 3992 if (!gpu_buffer) { | 3998 if (!gpu_buffer) { |
| 3993 SetGLError(GL_INVALID_OPERATION, "glDestroyImageCHROMIUM", "invalid image"); | 3999 SetGLError(GL_INVALID_OPERATION, "glDestroyImageCHROMIUM", "invalid image"); |
| 3994 return; | 4000 return; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 4025 | 4031 |
| 4026 void GLES2Implementation::UnmapImageCHROMIUM(GLuint image_id) { | 4032 void GLES2Implementation::UnmapImageCHROMIUM(GLuint image_id) { |
| 4027 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 4033 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 4028 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glUnmapImageCHROMIUM(" | 4034 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glUnmapImageCHROMIUM(" |
| 4029 << image_id << ")"); | 4035 << image_id << ")"); |
| 4030 | 4036 |
| 4031 UnmapImageCHROMIUMHelper(image_id); | 4037 UnmapImageCHROMIUMHelper(image_id); |
| 4032 CheckGLError(); | 4038 CheckGLError(); |
| 4033 } | 4039 } |
| 4034 | 4040 |
| 4035 void* GLES2Implementation::MapImageCHROMIUMHelper(GLuint image_id, | 4041 void* GLES2Implementation::MapImageCHROMIUMHelper(GLuint image_id) { |
| 4036 GLenum access) { | |
| 4037 gfx::GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer( | 4042 gfx::GpuMemoryBuffer* gpu_buffer = gpu_memory_buffer_tracker_->GetBuffer( |
| 4038 image_id); | 4043 image_id); |
| 4039 if (!gpu_buffer) { | 4044 if (!gpu_buffer) { |
| 4040 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM", "invalid image"); | 4045 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM", "invalid image"); |
| 4041 return NULL; | 4046 return NULL; |
| 4042 } | 4047 } |
| 4043 gfx::GpuMemoryBuffer::AccessMode mode; | |
| 4044 switch(access) { | |
| 4045 case GL_WRITE_ONLY: | |
| 4046 mode = gfx::GpuMemoryBuffer::WRITE_ONLY; | |
| 4047 break; | |
| 4048 case GL_READ_ONLY: | |
| 4049 mode = gfx::GpuMemoryBuffer::READ_ONLY; | |
| 4050 break; | |
| 4051 case GL_READ_WRITE: | |
| 4052 mode = gfx::GpuMemoryBuffer::READ_WRITE; | |
| 4053 break; | |
| 4054 default: | |
| 4055 SetGLError(GL_INVALID_ENUM, "glMapImageCHROMIUM", | |
| 4056 "invalid GPU access mode"); | |
| 4057 return NULL; | |
| 4058 } | |
| 4059 | 4048 |
| 4060 if (gpu_buffer->IsMapped()) { | 4049 if (gpu_buffer->IsMapped()) { |
| 4061 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM", "already mapped"); | 4050 SetGLError(GL_INVALID_OPERATION, "glMapImageCHROMIUM", "already mapped"); |
| 4062 return NULL; | 4051 return NULL; |
| 4063 } | 4052 } |
| 4064 | 4053 |
| 4065 return gpu_buffer->Map(mode); | 4054 return gpu_buffer->Map(); |
| 4066 } | 4055 } |
| 4067 | 4056 |
| 4068 void* GLES2Implementation::MapImageCHROMIUM( | 4057 void* GLES2Implementation::MapImageCHROMIUM(GLuint image_id) { |
| 4069 GLuint image_id, GLenum access) { | |
| 4070 GPU_CLIENT_SINGLE_THREAD_CHECK(); | 4058 GPU_CLIENT_SINGLE_THREAD_CHECK(); |
| 4071 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glMapImageCHROMIUM(" | 4059 GPU_CLIENT_LOG("[" << GetLogPrefix() << "] glMapImageCHROMIUM(" << image_id |
| 4072 << image_id << ", " | 4060 << ")"); |
| 4073 << GLES2Util::GetStringEnum(access) << ")"); | |
| 4074 | 4061 |
| 4075 void* mapped = MapImageCHROMIUMHelper(image_id, access); | 4062 void* mapped = MapImageCHROMIUMHelper(image_id); |
| 4076 CheckGLError(); | 4063 CheckGLError(); |
| 4077 return mapped; | 4064 return mapped; |
| 4078 } | 4065 } |
| 4079 | 4066 |
| 4080 void GLES2Implementation::GetImageParameterivCHROMIUMHelper( | 4067 void GLES2Implementation::GetImageParameterivCHROMIUMHelper( |
| 4081 GLuint image_id, GLenum pname, GLint* params) { | 4068 GLuint image_id, GLenum pname, GLint* params) { |
| 4082 if (pname != GL_IMAGE_ROWBYTES_CHROMIUM) { | 4069 if (pname != GL_IMAGE_ROWBYTES_CHROMIUM) { |
| 4083 SetGLError(GL_INVALID_ENUM, "glGetImageParameterivCHROMIUM", | 4070 SetGLError(GL_INVALID_ENUM, "glGetImageParameterivCHROMIUM", |
| 4084 "invalid parameter"); | 4071 "invalid parameter"); |
| 4085 return; | 4072 return; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4138 return true; | 4125 return true; |
| 4139 } | 4126 } |
| 4140 | 4127 |
| 4141 // Include the auto-generated part of this file. We split this because it means | 4128 // Include the auto-generated part of this file. We split this because it means |
| 4142 // we can easily edit the non-auto generated parts right here in this file | 4129 // we can easily edit the non-auto generated parts right here in this file |
| 4143 // instead of having to edit some template or the code generator. | 4130 // instead of having to edit some template or the code generator. |
| 4144 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" | 4131 #include "gpu/command_buffer/client/gles2_implementation_impl_autogen.h" |
| 4145 | 4132 |
| 4146 } // namespace gles2 | 4133 } // namespace gles2 |
| 4147 } // namespace gpu | 4134 } // namespace gpu |
| OLD | NEW |