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