Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(782)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 12647003: Refactor a bunch of Texture related GPU code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <list> 10 #include <list>
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 704 }
705 705
706 // Creates a Texture for the given texture. 706 // Creates a Texture for the given texture.
707 Texture* CreateTexture( 707 Texture* CreateTexture(
708 GLuint client_id, GLuint service_id) { 708 GLuint client_id, GLuint service_id) {
709 return texture_manager()->CreateTexture(client_id, service_id); 709 return texture_manager()->CreateTexture(client_id, service_id);
710 } 710 }
711 711
712 // Gets the texture info for the given texture. Returns NULL if none exists. 712 // Gets the texture info for the given texture. Returns NULL if none exists.
713 Texture* GetTexture(GLuint client_id) const { 713 Texture* GetTexture(GLuint client_id) const {
714 Texture* info = 714 return texture_manager()->GetTexture(client_id);
715 texture_manager()->GetTexture(client_id);
716 return info;
717 } 715 }
718 716
719 // Deletes the texture info for the given texture. 717 // Deletes the texture info for the given texture.
720 void RemoveTexture(GLuint client_id) { 718 void RemoveTexture(GLuint client_id) {
721 texture_manager()->RemoveTexture(client_id); 719 texture_manager()->RemoveTexture(client_id);
722 } 720 }
723 721
724 // Get the size (in pixels) of the currently bound frame buffer (either FBO 722 // Get the size (in pixels) of the currently bound frame buffer (either FBO
725 // or regular back buffer). 723 // or regular back buffer).
726 gfx::Size GetBoundReadFrameBufferSize(); 724 gfx::Size GetBoundReadFrameBufferSize();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 GLint yoffset, 822 GLint yoffset,
825 GLsizei width, 823 GLsizei width,
826 GLsizei height, 824 GLsizei height,
827 GLenum format, 825 GLenum format,
828 GLenum type, 826 GLenum type,
829 const void * data); 827 const void * data);
830 828
831 // Extra validation for async tex(Sub)Image2D. 829 // Extra validation for async tex(Sub)Image2D.
832 bool ValidateAsyncTransfer( 830 bool ValidateAsyncTransfer(
833 const char* function_name, 831 const char* function_name,
834 Texture* info, 832 Texture* texture,
835 GLenum target, 833 GLenum target,
836 GLint level, 834 GLint level,
837 const void * data); 835 const void * data);
838 836
839 // Wrapper for TexImageIOSurface2DCHROMIUM. 837 // Wrapper for TexImageIOSurface2DCHROMIUM.
840 void DoTexImageIOSurface2DCHROMIUM( 838 void DoTexImageIOSurface2DCHROMIUM(
841 GLenum target, 839 GLenum target,
842 GLsizei width, 840 GLsizei width,
843 GLsizei height, 841 GLsizei height,
844 GLuint io_surface_id, 842 GLuint io_surface_id,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 1044
1047 // Helper for glShaderSource. 1045 // Helper for glShaderSource.
1048 error::Error ShaderSourceHelper( 1046 error::Error ShaderSourceHelper(
1049 GLuint client_id, const char* data, uint32 data_size); 1047 GLuint client_id, const char* data, uint32 data_size);
1050 1048
1051 // Clear any textures used by the current program. 1049 // Clear any textures used by the current program.
1052 bool ClearUnclearedTextures(); 1050 bool ClearUnclearedTextures();
1053 1051
1054 // Clear any uncleared level in texture. 1052 // Clear any uncleared level in texture.
1055 // Returns false if there was a generated GL error. 1053 // Returns false if there was a generated GL error.
1056 bool ClearTexture(Texture* info); 1054 bool ClearTexture(Texture* texture);
1057 1055
1058 // Clears any uncleared attachments attached to the given frame buffer. 1056 // Clears any uncleared attachments attached to the given frame buffer.
1059 // Returns false if there was a generated GL error. 1057 // Returns false if there was a generated GL error.
1060 void ClearUnclearedAttachments( 1058 void ClearUnclearedAttachments(
1061 GLenum target, Framebuffer* info); 1059 GLenum target, Framebuffer* info);
1062 1060
1063 // overridden from GLES2Decoder 1061 // overridden from GLES2Decoder
1064 virtual bool ClearLevel(unsigned service_id, 1062 virtual bool ClearLevel(unsigned service_id,
1065 unsigned bind_target, 1063 unsigned bind_target,
1066 unsigned target, 1064 unsigned target,
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1399 if (target == GL_ARRAY_BUFFER) { 1397 if (target == GL_ARRAY_BUFFER) {
1400 return state_.bound_array_buffer; 1398 return state_.bound_array_buffer;
1401 } else { 1399 } else {
1402 return state_.vertex_attrib_manager->element_array_buffer(); 1400 return state_.vertex_attrib_manager->element_array_buffer();
1403 } 1401 }
1404 } 1402 }
1405 1403
1406 // Gets the texture id for a given target. 1404 // Gets the texture id for a given target.
1407 Texture* GetTextureInfoForTarget(GLenum target) { 1405 Texture* GetTextureInfoForTarget(GLenum target) {
1408 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; 1406 TextureUnit& unit = state_.texture_units[state_.active_texture_unit];
1409 Texture* info = NULL; 1407 Texture* texture = NULL;
1410 switch (target) { 1408 switch (target) {
1411 case GL_TEXTURE_2D: 1409 case GL_TEXTURE_2D:
1412 info = unit.bound_texture_2d; 1410 texture = unit.bound_texture_2d;
1413 break; 1411 break;
1414 case GL_TEXTURE_CUBE_MAP: 1412 case GL_TEXTURE_CUBE_MAP:
1415 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1413 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1416 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1414 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1417 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1415 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1418 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1416 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1419 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1417 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1420 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1418 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1421 info = unit.bound_texture_cube_map; 1419 texture = unit.bound_texture_cube_map;
1422 break; 1420 break;
1423 case GL_TEXTURE_EXTERNAL_OES: 1421 case GL_TEXTURE_EXTERNAL_OES:
1424 info = unit.bound_texture_external_oes; 1422 texture = unit.bound_texture_external_oes;
1425 break; 1423 break;
1426 case GL_TEXTURE_RECTANGLE_ARB: 1424 case GL_TEXTURE_RECTANGLE_ARB:
1427 info = unit.bound_texture_rectangle_arb; 1425 texture = unit.bound_texture_rectangle_arb;
1428 break; 1426 break;
1429 default: 1427 default:
1430 NOTREACHED(); 1428 NOTREACHED();
1431 return NULL; 1429 return NULL;
1432 } 1430 }
1433 return info; 1431 return texture;
1434 } 1432 }
1435 1433
1436 Texture* GetTextureInfoForTargetUnlessDefault( 1434 Texture* GetTextureInfoForTargetUnlessDefault(
1437 GLenum target) { 1435 GLenum target) {
1438 Texture* info = GetTextureInfoForTarget(target); 1436 Texture* texture = GetTextureInfoForTarget(target);
1439 if (!info) 1437 if (!texture)
1440 return NULL; 1438 return NULL;
1441 if (info == texture_manager()->GetDefaultTextureInfo(target)) 1439 if (texture == texture_manager()->GetDefaultTextureInfo(target))
1442 return NULL; 1440 return NULL;
1443 return info; 1441 return texture;
1444 } 1442 }
1445 1443
1446 GLenum GetBindTargetForSamplerType(GLenum type) { 1444 GLenum GetBindTargetForSamplerType(GLenum type) {
1447 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || 1445 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
1448 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); 1446 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB);
1449 switch (type) { 1447 switch (type) {
1450 case GL_SAMPLER_2D: 1448 case GL_SAMPLER_2D:
1451 return GL_TEXTURE_2D; 1449 return GL_TEXTURE_2D;
1452 case GL_SAMPLER_CUBE: 1450 case GL_SAMPLER_CUBE:
1453 return GL_TEXTURE_CUBE_MAP; 1451 return GL_TEXTURE_CUBE_MAP;
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 glGenBuffersARB(1, &attrib_0_buffer_id_); 2251 glGenBuffersARB(1, &attrib_0_buffer_id_);
2254 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); 2252 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_);
2255 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); 2253 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
2256 glBindBuffer(GL_ARRAY_BUFFER, 0); 2254 glBindBuffer(GL_ARRAY_BUFFER, 0);
2257 glGenBuffersARB(1, &fixed_attrib_buffer_id_); 2255 glGenBuffersARB(1, &fixed_attrib_buffer_id_);
2258 2256
2259 state_.texture_units.resize(group_->max_texture_units()); 2257 state_.texture_units.resize(group_->max_texture_units());
2260 for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) { 2258 for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) {
2261 glActiveTexture(GL_TEXTURE0 + tt); 2259 glActiveTexture(GL_TEXTURE0 + tt);
2262 // We want the last bind to be 2D. 2260 // We want the last bind to be 2D.
2263 Texture* info; 2261 Texture* texture;
2264 if (features().oes_egl_image_external) { 2262 if (features().oes_egl_image_external) {
2265 info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_EXTERNAL_OES); 2263 texture = texture_manager()->GetDefaultTextureInfo(
2266 state_.texture_units[tt].bound_texture_external_oes = info; 2264 GL_TEXTURE_EXTERNAL_OES);
2267 glBindTexture(GL_TEXTURE_EXTERNAL_OES, info->service_id()); 2265 state_.texture_units[tt].bound_texture_external_oes = texture;
2266 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->service_id());
2268 } 2267 }
2269 if (features().arb_texture_rectangle) { 2268 if (features().arb_texture_rectangle) {
2270 info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_RECTANGLE_ARB); 2269 texture = texture_manager()->GetDefaultTextureInfo(
2271 state_.texture_units[tt].bound_texture_rectangle_arb = info; 2270 GL_TEXTURE_RECTANGLE_ARB);
2272 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, info->service_id()); 2271 state_.texture_units[tt].bound_texture_rectangle_arb = texture;
2272 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture->service_id());
2273 } 2273 }
2274 info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); 2274 texture = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP);
2275 state_.texture_units[tt].bound_texture_cube_map = info; 2275 state_.texture_units[tt].bound_texture_cube_map = texture;
2276 glBindTexture(GL_TEXTURE_CUBE_MAP, info->service_id()); 2276 glBindTexture(GL_TEXTURE_CUBE_MAP, texture->service_id());
2277 info = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); 2277 texture = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D);
2278 state_.texture_units[tt].bound_texture_2d = info; 2278 state_.texture_units[tt].bound_texture_2d = texture;
2279 glBindTexture(GL_TEXTURE_2D, info->service_id()); 2279 glBindTexture(GL_TEXTURE_2D, texture->service_id());
2280 } 2280 }
2281 glActiveTexture(GL_TEXTURE0); 2281 glActiveTexture(GL_TEXTURE0);
2282 CHECK_GL_ERROR(); 2282 CHECK_GL_ERROR();
2283 2283
2284 ContextCreationAttribParser attrib_parser; 2284 ContextCreationAttribParser attrib_parser;
2285 if (!attrib_parser.Parse(attribs)) 2285 if (!attrib_parser.Parse(attribs))
2286 return false; 2286 return false;
2287 2287
2288 // These are NOT if the back buffer has these proprorties. They are 2288 // These are NOT if the back buffer has these proprorties. They are
2289 // if we want the command buffer to enforce them regardless of what 2289 // if we want the command buffer to enforce them regardless of what
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after
2980 0, // level 2980 0, // level
2981 GL_RGBA, 2981 GL_RGBA,
2982 offscreen_size_.width(), 2982 offscreen_size_.width(),
2983 offscreen_size_.height(), 2983 offscreen_size_.height(),
2984 1, // depth 2984 1, // depth
2985 0, // border 2985 0, // border
2986 GL_RGBA, 2986 GL_RGBA,
2987 GL_UNSIGNED_BYTE, 2987 GL_UNSIGNED_BYTE,
2988 true); 2988 true);
2989 parent_texture_manager->SetParameter( 2989 parent_texture_manager->SetParameter(
2990 "UpdateParentTextureInfo",
2991 this,
2990 offscreen_saved_color_texture_info_, 2992 offscreen_saved_color_texture_info_,
2991 GL_TEXTURE_MAG_FILTER, 2993 GL_TEXTURE_MAG_FILTER,
2992 GL_NEAREST); 2994 GL_NEAREST);
2993 parent_texture_manager->SetParameter( 2995 parent_texture_manager->SetParameter(
2996 "UpdateParentTextureInfo",
2997 this,
2994 offscreen_saved_color_texture_info_, 2998 offscreen_saved_color_texture_info_,
2995 GL_TEXTURE_MIN_FILTER, 2999 GL_TEXTURE_MIN_FILTER,
2996 GL_NEAREST); 3000 GL_NEAREST);
2997 parent_texture_manager->SetParameter( 3001 parent_texture_manager->SetParameter(
3002 "UpdateParentTextureInfo",
3003 this,
2998 offscreen_saved_color_texture_info_, 3004 offscreen_saved_color_texture_info_,
2999 GL_TEXTURE_WRAP_S, 3005 GL_TEXTURE_WRAP_S,
3000 GL_CLAMP_TO_EDGE); 3006 GL_CLAMP_TO_EDGE);
3001 parent_texture_manager->SetParameter( 3007 parent_texture_manager->SetParameter(
3008 "UpdateParentTextureInfo",
3009 this,
3002 offscreen_saved_color_texture_info_, 3010 offscreen_saved_color_texture_info_,
3003 GL_TEXTURE_WRAP_T, 3011 GL_TEXTURE_WRAP_T,
3004 GL_CLAMP_TO_EDGE); 3012 GL_CLAMP_TO_EDGE);
3005 } else { 3013 } else {
3006 offscreen_saved_color_texture_info_ = NULL; 3014 offscreen_saved_color_texture_info_ = NULL;
3007 } 3015 }
3008 } 3016 }
3009 3017
3010 void GLES2DecoderImpl::SetResizeCallback( 3018 void GLES2DecoderImpl::SetResizeCallback(
3011 const base::Callback<void(gfx::Size)>& callback) { 3019 const base::Callback<void(gfx::Size)>& callback) {
(...skipping 18 matching lines...) Expand all
3030 return async_pixel_transfer_delegate_.get(); 3038 return async_pixel_transfer_delegate_.get();
3031 } 3039 }
3032 3040
3033 void GLES2DecoderImpl::SetAsyncPixelTransferDelegate( 3041 void GLES2DecoderImpl::SetAsyncPixelTransferDelegate(
3034 gfx::AsyncPixelTransferDelegate* delegate) { 3042 gfx::AsyncPixelTransferDelegate* delegate) {
3035 async_pixel_transfer_delegate_ = make_scoped_ptr(delegate); 3043 async_pixel_transfer_delegate_ = make_scoped_ptr(delegate);
3036 } 3044 }
3037 3045
3038 bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, 3046 bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id,
3039 uint32* service_texture_id) { 3047 uint32* service_texture_id) {
3040 Texture* texture = 3048 Texture* texture = texture_manager()->GetTexture(client_texture_id);
3041 texture_manager()->GetTexture(client_texture_id);
3042 if (texture) { 3049 if (texture) {
3043 *service_texture_id = texture->service_id(); 3050 *service_texture_id = texture->service_id();
3044 return true; 3051 return true;
3045 } 3052 }
3046 return false; 3053 return false;
3047 } 3054 }
3048 3055
3049 uint32 GLES2DecoderImpl::GetTextureUploadCount() { 3056 uint32 GLES2DecoderImpl::GetTextureUploadCount() {
3050 return texture_upload_count_ + 3057 return texture_upload_count_ +
3051 async_pixel_transfer_delegate_->GetTextureUploadCount(); 3058 async_pixel_transfer_delegate_->GetTextureUploadCount();
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
3231 // Replace texture info when ID is already in use by parent. 3238 // Replace texture info when ID is already in use by parent.
3232 if (new_parent_impl->texture_manager()->GetTexture( 3239 if (new_parent_impl->texture_manager()->GetTexture(
3233 new_parent_texture_id)) 3240 new_parent_texture_id))
3234 new_parent_impl->texture_manager()->RemoveTexture( 3241 new_parent_impl->texture_manager()->RemoveTexture(
3235 new_parent_texture_id); 3242 new_parent_texture_id);
3236 3243
3237 offscreen_saved_color_texture_info_ = 3244 offscreen_saved_color_texture_info_ =
3238 new_parent_impl->CreateTexture(new_parent_texture_id, service_id); 3245 new_parent_impl->CreateTexture(new_parent_texture_id, service_id);
3239 offscreen_saved_color_texture_info_->SetNotOwned(); 3246 offscreen_saved_color_texture_info_->SetNotOwned();
3240 new_parent_impl->texture_manager()-> 3247 new_parent_impl->texture_manager()->
3241 SetInfoTarget(offscreen_saved_color_texture_info_, GL_TEXTURE_2D); 3248 SetTarget(offscreen_saved_color_texture_info_, GL_TEXTURE_2D);
3242 3249
3243 parent_ = base::AsWeakPtr<GLES2DecoderImpl>(new_parent_impl); 3250 parent_ = base::AsWeakPtr<GLES2DecoderImpl>(new_parent_impl);
3244 3251
3245 UpdateParentTextureInfo(); 3252 UpdateParentTextureInfo();
3246 } else { 3253 } else {
3247 parent_.reset(); 3254 parent_.reset();
3248 offscreen_saved_color_texture_info_ = NULL; 3255 offscreen_saved_color_texture_info_ = NULL;
3249 } 3256 }
3250 3257
3251 return true; 3258 return true;
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
3765 service_id = info->service_id(); 3772 service_id = info->service_id();
3766 } 3773 }
3767 info->MarkAsValid(); 3774 info->MarkAsValid();
3768 } 3775 }
3769 LogClientServiceForInfo(info, client_id, "glBindRenerbuffer"); 3776 LogClientServiceForInfo(info, client_id, "glBindRenerbuffer");
3770 state_.bound_renderbuffer = info; 3777 state_.bound_renderbuffer = info;
3771 glBindRenderbufferEXT(target, service_id); 3778 glBindRenderbufferEXT(target, service_id);
3772 } 3779 }
3773 3780
3774 void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { 3781 void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) {
3775 Texture* info = NULL; 3782 Texture* texture = NULL;
3776 GLuint service_id = 0; 3783 GLuint service_id = 0;
3777 if (client_id != 0) { 3784 if (client_id != 0) {
3778 info = GetTexture(client_id); 3785 texture = GetTexture(client_id);
3779 if (!info) { 3786 if (!texture) {
3780 if (!group_->bind_generates_resource()) { 3787 if (!group_->bind_generates_resource()) {
3781 LOG(ERROR) << "glBindTexture: id not generated by glGenTextures"; 3788 LOG(ERROR) << "glBindTexture: id not generated by glGenTextures";
3782 current_decoder_error_ = error::kGenericError; 3789 current_decoder_error_ = error::kGenericError;
3783 return; 3790 return;
3784 } 3791 }
3785 3792
3786 // It's a new id so make a texture info for it. 3793 // It's a new id so make a texture texture for it.
3787 glGenTextures(1, &service_id); 3794 glGenTextures(1, &service_id);
3788 DCHECK_NE(0u, service_id); 3795 DCHECK_NE(0u, service_id);
3789 CreateTexture(client_id, service_id); 3796 CreateTexture(client_id, service_id);
3790 info = GetTexture(client_id); 3797 texture = GetTexture(client_id);
3791 IdAllocatorInterface* id_allocator = 3798 IdAllocatorInterface* id_allocator =
3792 group_->GetIdAllocator(id_namespaces::kTextures); 3799 group_->GetIdAllocator(id_namespaces::kTextures);
3793 id_allocator->MarkAsUsed(client_id); 3800 id_allocator->MarkAsUsed(client_id);
3794 } 3801 }
3795 } else { 3802 } else {
3796 info = texture_manager()->GetDefaultTextureInfo(target); 3803 texture = texture_manager()->GetDefaultTextureInfo(target);
3797 } 3804 }
3798 3805
3799 // Check the texture exists 3806 // Check the texture exists
3800 // Check that we are not trying to bind it to a different target. 3807 // Check that we are not trying to bind it to a different target.
3801 if (info->target() != 0 && info->target() != target) { 3808 if (texture->target() != 0 && texture->target() != target) {
3802 SetGLError(GL_INVALID_OPERATION, 3809 SetGLError(GL_INVALID_OPERATION,
3803 "glBindTexture", "texture bound to more than 1 target."); 3810 "glBindTexture", "texture bound to more than 1 target.");
3804 return; 3811 return;
3805 } 3812 }
3806 if (info->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) { 3813 if (texture->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) {
3807 SetGLError(GL_INVALID_OPERATION, 3814 SetGLError(GL_INVALID_OPERATION,
3808 "glBindTexture", "illegal target for stream texture."); 3815 "glBindTexture", "illegal target for stream texture.");
3809 return; 3816 return;
3810 } 3817 }
3811 LogClientServiceForInfo(info, client_id, "glBindTexture"); 3818 LogClientServiceForInfo(texture, client_id, "glBindTexture");
3812 if (info->target() == 0) { 3819 if (texture->target() == 0) {
3813 texture_manager()->SetInfoTarget(info, target); 3820 texture_manager()->SetTarget(texture, target);
3814 } 3821 }
3815 glBindTexture(target, info->service_id()); 3822 glBindTexture(target, texture->service_id());
3816 3823
3817 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; 3824 TextureUnit& unit = state_.texture_units[state_.active_texture_unit];
3818 unit.bind_target = target; 3825 unit.bind_target = target;
3819 switch (target) { 3826 switch (target) {
3820 case GL_TEXTURE_2D: 3827 case GL_TEXTURE_2D:
3821 unit.bound_texture_2d = info; 3828 unit.bound_texture_2d = texture;
3822 break; 3829 break;
3823 case GL_TEXTURE_CUBE_MAP: 3830 case GL_TEXTURE_CUBE_MAP:
3824 unit.bound_texture_cube_map = info; 3831 unit.bound_texture_cube_map = texture;
3825 break; 3832 break;
3826 case GL_TEXTURE_EXTERNAL_OES: 3833 case GL_TEXTURE_EXTERNAL_OES:
3827 unit.bound_texture_external_oes = info; 3834 unit.bound_texture_external_oes = texture;
3828 if (info->IsStreamTexture()) { 3835 if (texture->IsStreamTexture()) {
3829 DCHECK(stream_texture_manager_); 3836 DCHECK(stream_texture_manager_);
3830 StreamTexture* stream_tex = 3837 StreamTexture* stream_tex =
3831 stream_texture_manager_->LookupStreamTexture(info->service_id()); 3838 stream_texture_manager_->LookupStreamTexture(texture->service_id());
3832 if (stream_tex) 3839 if (stream_tex)
3833 stream_tex->Update(); 3840 stream_tex->Update();
3834 } 3841 }
3835 break; 3842 break;
3836 case GL_TEXTURE_RECTANGLE_ARB: 3843 case GL_TEXTURE_RECTANGLE_ARB:
3837 unit.bound_texture_rectangle_arb = info; 3844 unit.bound_texture_rectangle_arb = texture;
3838 break; 3845 break;
3839 default: 3846 default:
3840 NOTREACHED(); // Validation should prevent us getting here. 3847 NOTREACHED(); // Validation should prevent us getting here.
3841 break; 3848 break;
3842 } 3849 }
3843 } 3850 }
3844 3851
3845 void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { 3852 void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) {
3846 if (state_.vertex_attrib_manager->Enable(index, false)) { 3853 if (state_.vertex_attrib_manager->Enable(index, false)) {
3847 if (index != 0 || 3854 if (index != 0 ||
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3904 void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { 3911 void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) {
3905 if (state_.vertex_attrib_manager->Enable(index, true)) { 3912 if (state_.vertex_attrib_manager->Enable(index, true)) {
3906 glEnableVertexAttribArray(index); 3913 glEnableVertexAttribArray(index);
3907 } else { 3914 } else {
3908 SetGLError(GL_INVALID_VALUE, 3915 SetGLError(GL_INVALID_VALUE,
3909 "glEnableVertexAttribArray", "index out of range"); 3916 "glEnableVertexAttribArray", "index out of range");
3910 } 3917 }
3911 } 3918 }
3912 3919
3913 void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { 3920 void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) {
3914 Texture* info = GetTextureInfoForTarget(target); 3921 Texture* texture = GetTextureInfoForTarget(target);
3915 if (!info || 3922 if (!texture ||
3916 !texture_manager()->CanGenerateMipmaps(info)) { 3923 !texture_manager()->CanGenerateMipmaps(texture)) {
3917 SetGLError(GL_INVALID_OPERATION, 3924 SetGLError(GL_INVALID_OPERATION,
3918 "glGenerateMipmaps", "Can not generate mips"); 3925 "glGenerateMipmaps", "Can not generate mips");
3919 return; 3926 return;
3920 } 3927 }
3921 3928
3922 if (target == GL_TEXTURE_CUBE_MAP) { 3929 if (target == GL_TEXTURE_CUBE_MAP) {
3923 for (int i = 0; i < 6; ++i) { 3930 for (int i = 0; i < 6; ++i) {
3924 GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; 3931 GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
3925 if (!texture_manager()->ClearTextureLevel(this, info, face, 0)) { 3932 if (!texture_manager()->ClearTextureLevel(this, texture, face, 0)) {
3926 SetGLError(GL_OUT_OF_MEMORY, "glGenerateMipmaps", "dimensions too big"); 3933 SetGLError(GL_OUT_OF_MEMORY, "glGenerateMipmaps", "dimensions too big");
3927 return; 3934 return;
3928 } 3935 }
3929 } 3936 }
3930 } else { 3937 } else {
3931 if (!texture_manager()->ClearTextureLevel(this, info, target, 0)) { 3938 if (!texture_manager()->ClearTextureLevel(this, texture, target, 0)) {
3932 SetGLError(GL_OUT_OF_MEMORY, "glGenerateMipmaps", "dimensions too big"); 3939 SetGLError(GL_OUT_OF_MEMORY, "glGenerateMipmaps", "dimensions too big");
3933 return; 3940 return;
3934 } 3941 }
3935 } 3942 }
3936 3943
3937 CopyRealGLErrorsToWrapper(); 3944 CopyRealGLErrorsToWrapper();
3938 // Workaround for Mac driver bug. In the large scheme of things setting 3945 // Workaround for Mac driver bug. In the large scheme of things setting
3939 // glTexParamter twice for glGenerateMipmap is probably not a lage performance 3946 // glTexParamter twice for glGenerateMipmap is probably not a lage performance
3940 // hit so there's probably no need to make this conditional. The bug appears 3947 // hit so there's probably no need to make this conditional. The bug appears
3941 // to be that if the filtering mode is set to something that doesn't require 3948 // to be that if the filtering mode is set to something that doesn't require
3942 // mipmaps for rendering, or is never set to something other than the default, 3949 // mipmaps for rendering, or is never set to something other than the default,
3943 // then glGenerateMipmap misbehaves. 3950 // then glGenerateMipmap misbehaves.
3944 if (workarounds().set_texture_filter_before_generating_mipmap) { 3951 if (workarounds().set_texture_filter_before_generating_mipmap) {
3945 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); 3952 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3946 } 3953 }
3947 glGenerateMipmapEXT(target); 3954 glGenerateMipmapEXT(target);
3948 if (workarounds().set_texture_filter_before_generating_mipmap) { 3955 if (workarounds().set_texture_filter_before_generating_mipmap) {
3949 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, info->min_filter()); 3956 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, texture->min_filter());
3950 } 3957 }
3951 GLenum error = PeekGLError(); 3958 GLenum error = PeekGLError();
3952 if (error == GL_NO_ERROR) { 3959 if (error == GL_NO_ERROR) {
3953 texture_manager()->MarkMipmapsGenerated(info); 3960 texture_manager()->MarkMipmapsGenerated(texture);
3954 } 3961 }
3955 } 3962 }
3956 3963
3957 bool GLES2DecoderImpl::GetHelper( 3964 bool GLES2DecoderImpl::GetHelper(
3958 GLenum pname, GLint* params, GLsizei* num_written) { 3965 GLenum pname, GLint* params, GLsizei* num_written) {
3959 DCHECK(num_written); 3966 DCHECK(num_written);
3960 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { 3967 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
3961 switch (pname) { 3968 switch (pname) {
3962 case GL_IMPLEMENTATION_COLOR_READ_FORMAT: 3969 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
3963 *num_written = 1; 3970 *num_written = 1;
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
4792 GLenum target, GLenum attachment, GLenum textarget, 4799 GLenum target, GLenum attachment, GLenum textarget,
4793 GLuint client_texture_id, GLint level) { 4800 GLuint client_texture_id, GLint level) {
4794 Framebuffer* framebuffer_info = 4801 Framebuffer* framebuffer_info =
4795 GetFramebufferInfoForTarget(target); 4802 GetFramebufferInfoForTarget(target);
4796 if (!framebuffer_info) { 4803 if (!framebuffer_info) {
4797 SetGLError(GL_INVALID_OPERATION, 4804 SetGLError(GL_INVALID_OPERATION,
4798 "glFramebufferTexture2D", "no framebuffer bound."); 4805 "glFramebufferTexture2D", "no framebuffer bound.");
4799 return; 4806 return;
4800 } 4807 }
4801 GLuint service_id = 0; 4808 GLuint service_id = 0;
4802 Texture* info = NULL; 4809 Texture* texture = NULL;
4803 if (client_texture_id) { 4810 if (client_texture_id) {
4804 info = GetTexture(client_texture_id); 4811 texture = GetTexture(client_texture_id);
4805 if (!info) { 4812 if (!texture) {
4806 SetGLError(GL_INVALID_OPERATION, 4813 SetGLError(GL_INVALID_OPERATION,
4807 "glFramebufferTexture2D", "unknown texture"); 4814 "glFramebufferTexture2D", "unknown texture");
4808 return; 4815 return;
4809 } 4816 }
4810 service_id = info->service_id(); 4817 service_id = texture->service_id();
4811 } 4818 }
4812 4819
4813 if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { 4820 if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) {
4814 SetGLError(GL_INVALID_VALUE, 4821 SetGLError(GL_INVALID_VALUE,
4815 "glFramebufferTexture2D", "level out of range"); 4822 "glFramebufferTexture2D", "level out of range");
4816 return; 4823 return;
4817 } 4824 }
4818 4825
4819 CopyRealGLErrorsToWrapper(); 4826 CopyRealGLErrorsToWrapper();
4820 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); 4827 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level);
4821 GLenum error = PeekGLError(); 4828 GLenum error = PeekGLError();
4822 if (error == GL_NO_ERROR) { 4829 if (error == GL_NO_ERROR) {
4823 framebuffer_info->AttachTexture(attachment, info, textarget, level); 4830 framebuffer_info->AttachTexture(attachment, texture, textarget, level);
4824 } 4831 }
4825 if (framebuffer_info == state_.bound_draw_framebuffer) { 4832 if (framebuffer_info == state_.bound_draw_framebuffer) {
4826 clear_state_dirty_ = true; 4833 clear_state_dirty_ = true;
4827 } 4834 }
4828 } 4835 }
4829 4836
4830 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( 4837 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv(
4831 GLenum target, GLenum attachment, GLenum pname, GLint* params) { 4838 GLenum target, GLenum attachment, GLenum pname, GLint* params) {
4832 Framebuffer* framebuffer_info = 4839 Framebuffer* framebuffer_info =
4833 GetFramebufferInfoForTarget(target); 4840 GetFramebufferInfoForTarget(target);
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
5036 if (workarounds().use_current_program_after_successful_link) { 5043 if (workarounds().use_current_program_after_successful_link) {
5037 glUseProgram(info->service_id()); 5044 glUseProgram(info->service_id());
5038 } 5045 }
5039 program_manager()->ClearUniforms(info); 5046 program_manager()->ClearUniforms(info);
5040 } 5047 }
5041 } 5048 }
5042 }; 5049 };
5043 5050
5044 void GLES2DecoderImpl::DoTexParameterf( 5051 void GLES2DecoderImpl::DoTexParameterf(
5045 GLenum target, GLenum pname, GLfloat param) { 5052 GLenum target, GLenum pname, GLfloat param) {
5046 Texture* info = GetTextureInfoForTarget(target); 5053 Texture* texture = GetTextureInfoForTarget(target);
5047 if (!info) { 5054 if (!texture) {
5048 SetGLError(GL_INVALID_VALUE, "glTexParameterf", "unknown texture"); 5055 SetGLError(GL_INVALID_VALUE, "glTexParameterf", "unknown texture");
5049 return; 5056 return;
5050 } 5057 }
5051 5058
5052 GLenum error = texture_manager()->SetParameter( 5059 texture_manager()->SetParameter(
5053 info, pname, static_cast<GLint>(param)); 5060 "glTexParameterf", this, texture, pname, static_cast<GLint>(param));
5054 if (error != GL_NO_ERROR) {
5055 SetGLErrorInvalidParam(
5056 error, "glTexParameterf", pname, static_cast<GLint>(param));
5057 return;
5058 }
5059 glTexParameterf(target, pname, param);
5060 } 5061 }
5061 5062
5062 void GLES2DecoderImpl::DoTexParameteri( 5063 void GLES2DecoderImpl::DoTexParameteri(
5063 GLenum target, GLenum pname, GLint param) { 5064 GLenum target, GLenum pname, GLint param) {
5064 Texture* info = GetTextureInfoForTarget(target); 5065 Texture* texture = GetTextureInfoForTarget(target);
5065 if (!info) { 5066 if (!texture) {
5066 SetGLError(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); 5067 SetGLError(GL_INVALID_VALUE, "glTexParameteri", "unknown texture");
5067 return; 5068 return;
5068 } 5069 }
5069 5070
5070 GLenum error = texture_manager()->SetParameter(info, pname, param); 5071 texture_manager()->SetParameter(
5071 if (error != GL_NO_ERROR) { 5072 "glTexParameteri", this, texture, pname, param);
5072 SetGLErrorInvalidParam(error, "glTexParameteri", pname, param);
5073 return;
5074 }
5075 // Texture tracking pools exist only for the command decoder, so
5076 // do not pass them on to the native GL implementation.
5077 if (pname == GL_TEXTURE_POOL_CHROMIUM) {
5078 return;
5079 }
5080 glTexParameteri(target, pname, param);
5081 } 5073 }
5082 5074
5083 void GLES2DecoderImpl::DoTexParameterfv( 5075 void GLES2DecoderImpl::DoTexParameterfv(
5084 GLenum target, GLenum pname, const GLfloat* params) { 5076 GLenum target, GLenum pname, const GLfloat* params) {
5085 Texture* info = GetTextureInfoForTarget(target); 5077 Texture* texture = GetTextureInfoForTarget(target);
5086 if (!info) { 5078 if (!texture) {
5087 SetGLError(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture"); 5079 SetGLError(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture");
5088 return; 5080 return;
5089 } 5081 }
5090 5082
5091 GLenum error =texture_manager()->SetParameter( 5083 texture_manager()->SetParameter(
5092 info, pname, static_cast<GLint>(params[0])); 5084 "glTexParameterfv", this, texture, pname, static_cast<GLint>(params[0]));
5093 if (error != GL_NO_ERROR) {
5094 SetGLErrorInvalidParam(
5095 error, "glTexParameterfv", pname, static_cast<GLint>(params[0]));
5096 return;
5097 }
5098 glTexParameterfv(target, pname, params);
5099 } 5085 }
5100 5086
5101 void GLES2DecoderImpl::DoTexParameteriv( 5087 void GLES2DecoderImpl::DoTexParameteriv(
5102 GLenum target, GLenum pname, const GLint* params) { 5088 GLenum target, GLenum pname, const GLint* params) {
5103 Texture* info = GetTextureInfoForTarget(target); 5089 Texture* texture = GetTextureInfoForTarget(target);
5104 if (!info) { 5090 if (!texture) {
5105 SetGLError(GL_INVALID_VALUE, "glTexParameteriv", "unknown texture"); 5091 SetGLError(GL_INVALID_VALUE, "glTexParameteriv", "unknown texture");
5106 return; 5092 return;
5107 } 5093 }
5108 5094
5109 GLenum error = texture_manager()->SetParameter(info, pname, *params); 5095 texture_manager()->SetParameter(
5110 if (error != GL_NO_ERROR) { 5096 "glTexParameteriv", this, texture, pname, *params);
5111 SetGLErrorInvalidParam(error, "glTexParameteriv", pname, *params);
5112 return;
5113 }
5114 glTexParameteriv(target, pname, params);
5115 } 5097 }
5116 5098
5117 bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) { 5099 bool GLES2DecoderImpl::CheckCurrentProgram(const char* function_name) {
5118 if (!state_.current_program) { 5100 if (!state_.current_program) {
5119 // The program does not exist. 5101 // The program does not exist.
5120 SetGLError(GL_INVALID_OPERATION, function_name, "no program in use"); 5102 SetGLError(GL_INVALID_OPERATION, function_name, "no program in use");
5121 return false; 5103 return false;
5122 } 5104 }
5123 if (!state_.current_program->InUse()) { 5105 if (!state_.current_program->InUse()) {
5124 SetGLError(GL_INVALID_OPERATION, function_name, "program not linked"); 5106 SetGLError(GL_INVALID_OPERATION, function_name, "program not linked");
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
5661 const Program::SamplerIndices& sampler_indices = 5643 const Program::SamplerIndices& sampler_indices =
5662 state_.current_program->sampler_indices(); 5644 state_.current_program->sampler_indices();
5663 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { 5645 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) {
5664 const Program::UniformInfo* uniform_info = 5646 const Program::UniformInfo* uniform_info =
5665 state_.current_program->GetUniformInfo(sampler_indices[ii]); 5647 state_.current_program->GetUniformInfo(sampler_indices[ii]);
5666 DCHECK(uniform_info); 5648 DCHECK(uniform_info);
5667 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { 5649 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) {
5668 GLuint texture_unit_index = uniform_info->texture_units[jj]; 5650 GLuint texture_unit_index = uniform_info->texture_units[jj];
5669 if (texture_unit_index < state_.texture_units.size()) { 5651 if (texture_unit_index < state_.texture_units.size()) {
5670 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; 5652 TextureUnit& texture_unit = state_.texture_units[texture_unit_index];
5671 Texture* texture_info = 5653 Texture* texture =
5672 texture_unit.GetInfoForSamplerType(uniform_info->type); 5654 texture_unit.GetInfoForSamplerType(uniform_info->type);
5673 if (!texture_info || !texture_manager()->CanRender(texture_info)) { 5655 if (!texture || !texture_manager()->CanRender(texture)) {
5674 textures_set = true; 5656 textures_set = true;
5675 glActiveTexture(GL_TEXTURE0 + texture_unit_index); 5657 glActiveTexture(GL_TEXTURE0 + texture_unit_index);
5676 glBindTexture( 5658 glBindTexture(
5677 GetBindTargetForSamplerType(uniform_info->type), 5659 GetBindTargetForSamplerType(uniform_info->type),
5678 texture_manager()->black_texture_id(uniform_info->type)); 5660 texture_manager()->black_texture_id(uniform_info->type));
5679 RenderWarning( 5661 RenderWarning(
5680 std::string("texture bound to texture unit ") + 5662 std::string("texture bound to texture unit ") +
5681 base::IntToString(texture_unit_index) + 5663 base::IntToString(texture_unit_index) +
5682 " is not renderable. It maybe non-power-of-2 and have " 5664 " is not renderable. It maybe non-power-of-2 and have "
5683 " incompatible texture filtering or is not " 5665 " incompatible texture filtering or is not "
(...skipping 11 matching lines...) Expand all
5695 const Program::SamplerIndices& sampler_indices = 5677 const Program::SamplerIndices& sampler_indices =
5696 state_.current_program->sampler_indices(); 5678 state_.current_program->sampler_indices();
5697 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { 5679 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) {
5698 const Program::UniformInfo* uniform_info = 5680 const Program::UniformInfo* uniform_info =
5699 state_.current_program->GetUniformInfo(sampler_indices[ii]); 5681 state_.current_program->GetUniformInfo(sampler_indices[ii]);
5700 DCHECK(uniform_info); 5682 DCHECK(uniform_info);
5701 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { 5683 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) {
5702 GLuint texture_unit_index = uniform_info->texture_units[jj]; 5684 GLuint texture_unit_index = uniform_info->texture_units[jj];
5703 if (texture_unit_index < state_.texture_units.size()) { 5685 if (texture_unit_index < state_.texture_units.size()) {
5704 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; 5686 TextureUnit& texture_unit = state_.texture_units[texture_unit_index];
5705 Texture* texture_info = 5687 Texture* texture = uniform_info->type == GL_SAMPLER_2D ?
5706 uniform_info->type == GL_SAMPLER_2D ? 5688 texture_unit.bound_texture_2d :
5707 texture_unit.bound_texture_2d : 5689 texture_unit.bound_texture_cube_map;
5708 texture_unit.bound_texture_cube_map; 5690 if (!texture || !texture_manager()->CanRender(texture)) {
5709 if (!texture_info || !texture_manager()->CanRender(texture_info)) {
5710 glActiveTexture(GL_TEXTURE0 + texture_unit_index); 5691 glActiveTexture(GL_TEXTURE0 + texture_unit_index);
5711 // Get the texture info that was previously bound here. 5692 // Get the texture info that was previously bound here.
5712 texture_info = texture_unit.bind_target == GL_TEXTURE_2D ? 5693 texture = texture_unit.bind_target == GL_TEXTURE_2D ?
5713 texture_unit.bound_texture_2d : 5694 texture_unit.bound_texture_2d :
5714 texture_unit.bound_texture_cube_map; 5695 texture_unit.bound_texture_cube_map;
5715 glBindTexture(texture_unit.bind_target, 5696 glBindTexture(texture_unit.bind_target,
5716 texture_info ? texture_info->service_id() : 0); 5697 texture ? texture->service_id() : 0);
5717 } 5698 }
5718 } 5699 }
5719 } 5700 }
5720 } 5701 }
5721 // Set the active texture back to whatever the user had it as. 5702 // Set the active texture back to whatever the user had it as.
5722 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); 5703 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit);
5723 } 5704 }
5724 5705
5725 bool GLES2DecoderImpl::ClearUnclearedTextures() { 5706 bool GLES2DecoderImpl::ClearUnclearedTextures() {
5726 // Only check if there are some uncleared textures. 5707 // Only check if there are some uncleared textures.
5727 if (!texture_manager()->HaveUnsafeTextures()) { 5708 if (!texture_manager()->HaveUnsafeTextures()) {
5728 return true; 5709 return true;
5729 } 5710 }
5730 5711
5731 // 1: Check all textures we are about to render with. 5712 // 1: Check all textures we are about to render with.
5732 if (state_.current_program) { 5713 if (state_.current_program) {
5733 const Program::SamplerIndices& sampler_indices = 5714 const Program::SamplerIndices& sampler_indices =
5734 state_.current_program->sampler_indices(); 5715 state_.current_program->sampler_indices();
5735 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { 5716 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) {
5736 const Program::UniformInfo* uniform_info = 5717 const Program::UniformInfo* uniform_info =
5737 state_.current_program->GetUniformInfo(sampler_indices[ii]); 5718 state_.current_program->GetUniformInfo(sampler_indices[ii]);
5738 DCHECK(uniform_info); 5719 DCHECK(uniform_info);
5739 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { 5720 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) {
5740 GLuint texture_unit_index = uniform_info->texture_units[jj]; 5721 GLuint texture_unit_index = uniform_info->texture_units[jj];
5741 if (texture_unit_index < state_.texture_units.size()) { 5722 if (texture_unit_index < state_.texture_units.size()) {
5742 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; 5723 TextureUnit& texture_unit = state_.texture_units[texture_unit_index];
5743 Texture* texture_info = 5724 Texture* texture =
5744 texture_unit.GetInfoForSamplerType(uniform_info->type); 5725 texture_unit.GetInfoForSamplerType(uniform_info->type);
5745 if (texture_info && !texture_info->SafeToRenderFrom()) { 5726 if (texture && !texture->SafeToRenderFrom()) {
5746 if (!texture_manager()->ClearRenderableLevels(this, texture_info)) { 5727 if (!texture_manager()->ClearRenderableLevels(this, texture)) {
5747 return false; 5728 return false;
5748 } 5729 }
5749 } 5730 }
5750 } 5731 }
5751 } 5732 }
5752 } 5733 }
5753 } 5734 }
5754 return true; 5735 return true;
5755 } 5736 }
5756 5737
(...skipping 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after
7342 while (y < height) { 7323 while (y < height) {
7343 GLint h = y + tile_height > height ? height - y : tile_height; 7324 GLint h = y + tile_height > height ? height - y : tile_height;
7344 if (is_texture_immutable || h != height) { 7325 if (is_texture_immutable || h != height) {
7345 glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); 7326 glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get());
7346 } else { 7327 } else {
7347 WrappedTexImage2D( 7328 WrappedTexImage2D(
7348 target, level, format, width, h, 0, format, type, zero.get()); 7329 target, level, format, width, h, 0, format, type, zero.get());
7349 } 7330 }
7350 y += tile_height; 7331 y += tile_height;
7351 } 7332 }
7352 Texture* info = GetTextureInfoForTarget(bind_target); 7333 Texture* texture = GetTextureInfoForTarget(bind_target);
7353 glBindTexture(bind_target, info ? info->service_id() : 0); 7334 glBindTexture(bind_target, texture ? texture->service_id() : 0);
7354 return true; 7335 return true;
7355 } 7336 }
7356 7337
7357 namespace { 7338 namespace {
7358 7339
7359 const int kS3TCBlockWidth = 4; 7340 const int kS3TCBlockWidth = 4;
7360 const int kS3TCBlockHeight = 4; 7341 const int kS3TCBlockHeight = 4;
7361 const int kS3TCDXT1BlockSize = 8; 7342 const int kS3TCDXT1BlockSize = 8;
7362 const int kS3TCDXT3AndDXT5BlockSize = 16; 7343 const int kS3TCDXT3AndDXT5BlockSize = 16;
7363 const int kETC1BlockWidth = 4; 7344 const int kETC1BlockWidth = 4;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
7515 SetGLErrorInvalidEnum( 7496 SetGLErrorInvalidEnum(
7516 "glCompressedTexImage2D", internal_format, "internal_format"); 7497 "glCompressedTexImage2D", internal_format, "internal_format");
7517 return error::kNoError; 7498 return error::kNoError;
7518 } 7499 }
7519 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || 7500 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) ||
7520 border != 0) { 7501 border != 0) {
7521 SetGLError(GL_INVALID_VALUE, 7502 SetGLError(GL_INVALID_VALUE,
7522 "glCompressedTexImage2D", "dimensions out of range"); 7503 "glCompressedTexImage2D", "dimensions out of range");
7523 return error::kNoError; 7504 return error::kNoError;
7524 } 7505 }
7525 Texture* info = GetTextureInfoForTarget(target); 7506 Texture* texture = GetTextureInfoForTarget(target);
7526 if (!info) { 7507 if (!texture) {
7527 SetGLError(GL_INVALID_VALUE, 7508 SetGLError(GL_INVALID_VALUE,
7528 "glCompressedTexImage2D", "unknown texture target"); 7509 "glCompressedTexImage2D", "unknown texture target");
7529 return error::kNoError; 7510 return error::kNoError;
7530 } 7511 }
7531 if (info->IsImmutable()) { 7512 if (texture->IsImmutable()) {
7532 SetGLError(GL_INVALID_OPERATION, 7513 SetGLError(GL_INVALID_OPERATION,
7533 "glCompressedTexImage2D", "texture is immutable"); 7514 "glCompressedTexImage2D", "texture is immutable");
7534 return error::kNoError; 7515 return error::kNoError;
7535 } 7516 }
7536 7517
7537 if (!ValidateCompressedTexDimensions( 7518 if (!ValidateCompressedTexDimensions(
7538 "glCompressedTexImage2D", level, width, height, internal_format) || 7519 "glCompressedTexImage2D", level, width, height, internal_format) ||
7539 !ValidateCompressedTexFuncData( 7520 !ValidateCompressedTexFuncData(
7540 "glCompressedTexImage2D", width, height, internal_format, image_size)) { 7521 "glCompressedTexImage2D", width, height, internal_format, image_size)) {
7541 return error::kNoError; 7522 return error::kNoError;
7542 } 7523 }
7543 7524
7544 if (!EnsureGPUMemoryAvailable(image_size)) { 7525 if (!EnsureGPUMemoryAvailable(image_size)) {
7545 SetGLError(GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); 7526 SetGLError(GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory");
7546 return error::kNoError; 7527 return error::kNoError;
7547 } 7528 }
7548 7529
7549 if (info->IsAttachedToFramebuffer()) { 7530 if (texture->IsAttachedToFramebuffer()) {
7550 clear_state_dirty_ = true; 7531 clear_state_dirty_ = true;
7551 // TODO(gman): If textures tracked which framebuffers they were attached to 7532 // TODO(gman): If textures tracked which framebuffers they were attached to
7552 // we could just mark those framebuffers as not complete. 7533 // we could just mark those framebuffers as not complete.
7553 framebuffer_manager()->IncFramebufferStateChangeCount(); 7534 framebuffer_manager()->IncFramebufferStateChangeCount();
7554 } 7535 }
7555 7536
7556 scoped_array<int8> zero; 7537 scoped_array<int8> zero;
7557 if (!data) { 7538 if (!data) {
7558 zero.reset(new int8[image_size]); 7539 zero.reset(new int8[image_size]);
7559 memset(zero.get(), 0, image_size); 7540 memset(zero.get(), 0, image_size);
7560 data = zero.get(); 7541 data = zero.get();
7561 } 7542 }
7562 CopyRealGLErrorsToWrapper(); 7543 CopyRealGLErrorsToWrapper();
7563 glCompressedTexImage2D( 7544 glCompressedTexImage2D(
7564 target, level, internal_format, width, height, border, image_size, data); 7545 target, level, internal_format, width, height, border, image_size, data);
7565 GLenum error = PeekGLError(); 7546 GLenum error = PeekGLError();
7566 if (error == GL_NO_ERROR) { 7547 if (error == GL_NO_ERROR) {
7567 texture_manager()->SetLevelInfo( 7548 texture_manager()->SetLevelInfo(
7568 info, target, level, internal_format, width, height, 1, border, 0, 0, 7549 texture, target, level, internal_format, width, height, 1, border, 0, 0,
7569 true); 7550 true);
7570 } 7551 }
7571 return error::kNoError; 7552 return error::kNoError;
7572 } 7553 }
7573 7554
7574 error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( 7555 error::Error GLES2DecoderImpl::HandleCompressedTexImage2D(
7575 uint32 immediate_data_size, const cmds::CompressedTexImage2D& c) { 7556 uint32 immediate_data_size, const cmds::CompressedTexImage2D& c) {
7576 GLenum target = static_cast<GLenum>(c.target); 7557 GLenum target = static_cast<GLenum>(c.target);
7577 GLint level = static_cast<GLint>(c.level); 7558 GLint level = static_cast<GLint>(c.level);
7578 GLenum internal_format = static_cast<GLenum>(c.internalformat); 7559 GLenum internal_format = static_cast<GLenum>(c.internalformat);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
7744 SetGLError(GL_INVALID_VALUE, function_name, "dimensions out of range"); 7725 SetGLError(GL_INVALID_VALUE, function_name, "dimensions out of range");
7745 return false; 7726 return false;
7746 } 7727 }
7747 if ((GLES2Util::GetChannelsForFormat(format) & 7728 if ((GLES2Util::GetChannelsForFormat(format) &
7748 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && pixels) { 7729 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && pixels) {
7749 SetGLError( 7730 SetGLError(
7750 GL_INVALID_OPERATION, 7731 GL_INVALID_OPERATION,
7751 function_name, "can not supply data for depth or stencil textures"); 7732 function_name, "can not supply data for depth or stencil textures");
7752 return false; 7733 return false;
7753 } 7734 }
7754 Texture* info = GetTextureInfoForTarget(target); 7735 Texture* texture = GetTextureInfoForTarget(target);
7755 if (!info) { 7736 if (!texture) {
7756 SetGLError(GL_INVALID_OPERATION, 7737 SetGLError(GL_INVALID_OPERATION,
7757 function_name, "unknown texture for target"); 7738 function_name, "unknown texture for target");
7758 return false; 7739 return false;
7759 } 7740 }
7760 if (info->IsImmutable()) { 7741 if (texture->IsImmutable()) {
7761 SetGLError(GL_INVALID_OPERATION, 7742 SetGLError(GL_INVALID_OPERATION,
7762 function_name, "texture is immutable"); 7743 function_name, "texture is immutable");
7763 return false; 7744 return false;
7764 } 7745 }
7765 return true; 7746 return true;
7766 } 7747 }
7767 7748
7768 void GLES2DecoderImpl::DoTexImage2D( 7749 void GLES2DecoderImpl::DoTexImage2D(
7769 GLenum target, 7750 GLenum target,
7770 GLint level, 7751 GLint level,
7771 GLenum internal_format, 7752 GLenum internal_format,
7772 GLsizei width, 7753 GLsizei width,
7773 GLsizei height, 7754 GLsizei height,
7774 GLint border, 7755 GLint border,
7775 GLenum format, 7756 GLenum format,
7776 GLenum type, 7757 GLenum type,
7777 const void* pixels, 7758 const void* pixels,
7778 uint32 pixels_size) { 7759 uint32 pixels_size) {
7779 if (!ValidateTexImage2D("glTexImage2D", target, level, internal_format, 7760 if (!ValidateTexImage2D("glTexImage2D", target, level, internal_format,
7780 width, height, border, format, type, pixels, pixels_size)) { 7761 width, height, border, format, type, pixels, pixels_size)) {
7781 return; 7762 return;
7782 } 7763 }
7783 7764
7784 if (!EnsureGPUMemoryAvailable(pixels_size)) { 7765 if (!EnsureGPUMemoryAvailable(pixels_size)) {
7785 SetGLError(GL_OUT_OF_MEMORY, "glTexImage2D", "out of memory"); 7766 SetGLError(GL_OUT_OF_MEMORY, "glTexImage2D", "out of memory");
7786 return; 7767 return;
7787 } 7768 }
7788 7769
7789 Texture* info = GetTextureInfoForTarget(target); 7770 Texture* texture = GetTextureInfoForTarget(target);
7790 GLsizei tex_width = 0; 7771 GLsizei tex_width = 0;
7791 GLsizei tex_height = 0; 7772 GLsizei tex_height = 0;
7792 GLenum tex_type = 0; 7773 GLenum tex_type = 0;
7793 GLenum tex_format = 0; 7774 GLenum tex_format = 0;
7794 bool level_is_same = 7775 bool level_is_same =
7795 info->GetLevelSize(target, level, &tex_width, &tex_height) && 7776 texture->GetLevelSize(target, level, &tex_width, &tex_height) &&
7796 info->GetLevelType(target, level, &tex_type, &tex_format) && 7777 texture->GetLevelType(target, level, &tex_type, &tex_format) &&
7797 width == tex_width && height == tex_height && 7778 width == tex_width && height == tex_height &&
7798 type == tex_type && format == tex_format; 7779 type == tex_type && format == tex_format;
7799 7780
7800 if (level_is_same && !pixels) { 7781 if (level_is_same && !pixels) {
7801 // Just set the level info but mark the texture as uncleared. 7782 // Just set the level texture but mark the texture as uncleared.
7802 texture_manager()->SetLevelInfo( 7783 texture_manager()->SetLevelInfo(
7803 info, 7784 texture,
7804 target, level, internal_format, width, height, 1, border, format, type, 7785 target, level, internal_format, width, height, 1, border, format, type,
7805 false); 7786 false);
7806 tex_image_2d_failed_ = false; 7787 tex_image_2d_failed_ = false;
7807 return; 7788 return;
7808 } 7789 }
7809 7790
7810 if (info->IsAttachedToFramebuffer()) { 7791 if (texture->IsAttachedToFramebuffer()) {
7811 clear_state_dirty_ = true; 7792 clear_state_dirty_ = true;
7812 // TODO(gman): If textures tracked which framebuffers they were attached to 7793 // TODO(gman): If textures tracked which framebuffers they were attached to
7813 // we could just mark those framebuffers as not complete. 7794 // we could just mark those framebuffers as not complete.
7814 framebuffer_manager()->IncFramebufferStateChangeCount(); 7795 framebuffer_manager()->IncFramebufferStateChangeCount();
7815 } 7796 }
7816 7797
7817 if (!teximage2d_faster_than_texsubimage2d_ && level_is_same && pixels) { 7798 if (!teximage2d_faster_than_texsubimage2d_ && level_is_same && pixels) {
7818 glTexSubImage2D(target, level, 0, 0, width, height, format, type, pixels); 7799 glTexSubImage2D(target, level, 0, 0, width, height, format, type, pixels);
7819 texture_manager()->SetLevelCleared(info, target, level, true); 7800 texture_manager()->SetLevelCleared(texture, target, level, true);
7820 tex_image_2d_failed_ = false; 7801 tex_image_2d_failed_ = false;
7821 return; 7802 return;
7822 } 7803 }
7823 7804
7824 CopyRealGLErrorsToWrapper(); 7805 CopyRealGLErrorsToWrapper();
7825 WrappedTexImage2D( 7806 WrappedTexImage2D(
7826 target, level, internal_format, width, height, border, format, type, 7807 target, level, internal_format, width, height, border, format, type,
7827 pixels); 7808 pixels);
7828 GLenum error = PeekGLError(); 7809 GLenum error = PeekGLError();
7829 if (error == GL_NO_ERROR) { 7810 if (error == GL_NO_ERROR) {
7830 texture_manager()->SetLevelInfo( 7811 texture_manager()->SetLevelInfo(
7831 info, 7812 texture,
7832 target, level, internal_format, width, height, 1, border, format, type, 7813 target, level, internal_format, width, height, 1, border, format, type,
7833 pixels != NULL); 7814 pixels != NULL);
7834 tex_image_2d_failed_ = false; 7815 tex_image_2d_failed_ = false;
7835 } 7816 }
7836 return; 7817 return;
7837 } 7818 }
7838 7819
7839 error::Error GLES2DecoderImpl::HandleTexImage2D( 7820 error::Error GLES2DecoderImpl::HandleTexImage2D(
7840 uint32 immediate_data_size, const cmds::TexImage2D& c) { 7821 uint32 immediate_data_size, const cmds::TexImage2D& c) {
7841 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D"); 7822 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
7901 void GLES2DecoderImpl::DoCompressedTexSubImage2D( 7882 void GLES2DecoderImpl::DoCompressedTexSubImage2D(
7902 GLenum target, 7883 GLenum target,
7903 GLint level, 7884 GLint level,
7904 GLint xoffset, 7885 GLint xoffset,
7905 GLint yoffset, 7886 GLint yoffset,
7906 GLsizei width, 7887 GLsizei width,
7907 GLsizei height, 7888 GLsizei height,
7908 GLenum format, 7889 GLenum format,
7909 GLsizei image_size, 7890 GLsizei image_size,
7910 const void * data) { 7891 const void * data) {
7911 Texture* info = GetTextureInfoForTarget(target); 7892 Texture* texture = GetTextureInfoForTarget(target);
7912 if (!info) { 7893 if (!texture) {
7913 SetGLError(GL_INVALID_OPERATION, 7894 SetGLError(GL_INVALID_OPERATION,
7914 "glCompressedTexSubImage2D", "unknown texture for target"); 7895 "glCompressedTexSubImage2D", "unknown texture for target");
7915 return; 7896 return;
7916 } 7897 }
7917 GLenum type = 0; 7898 GLenum type = 0;
7918 GLenum internal_format = 0; 7899 GLenum internal_format = 0;
7919 if (!info->GetLevelType(target, level, &type, &internal_format)) { 7900 if (!texture->GetLevelType(target, level, &type, &internal_format)) {
7920 SetGLError( 7901 SetGLError(
7921 GL_INVALID_OPERATION, 7902 GL_INVALID_OPERATION,
7922 "glCompressedTexSubImage2D", "level does not exist."); 7903 "glCompressedTexSubImage2D", "level does not exist.");
7923 return; 7904 return;
7924 } 7905 }
7925 if (internal_format != format) { 7906 if (internal_format != format) {
7926 SetGLError( 7907 SetGLError(
7927 GL_INVALID_OPERATION, 7908 GL_INVALID_OPERATION,
7928 "glCompressedTexSubImage2D", "format does not match internal format."); 7909 "glCompressedTexSubImage2D", "format does not match internal format.");
7929 return; 7910 return;
7930 } 7911 }
7931 if (!info->ValidForTexture( 7912 if (!texture->ValidForTexture(
7932 target, level, xoffset, yoffset, width, height, format, type)) { 7913 target, level, xoffset, yoffset, width, height, format, type)) {
7933 SetGLError(GL_INVALID_VALUE, 7914 SetGLError(GL_INVALID_VALUE,
7934 "glCompressedTexSubImage2D", "bad dimensions."); 7915 "glCompressedTexSubImage2D", "bad dimensions.");
7935 return; 7916 return;
7936 } 7917 }
7937 7918
7938 if (!ValidateCompressedTexFuncData( 7919 if (!ValidateCompressedTexFuncData(
7939 "glCompressedTexSubImage2D", width, height, format, image_size) || 7920 "glCompressedTexSubImage2D", width, height, format, image_size) ||
7940 !ValidateCompressedTexSubDimensions( 7921 !ValidateCompressedTexSubDimensions(
7941 "glCompressedTexSubImage2D", 7922 "glCompressedTexSubImage2D",
7942 target, level, xoffset, yoffset, width, height, format, info)) { 7923 target, level, xoffset, yoffset, width, height, format, texture)) {
7943 return; 7924 return;
7944 } 7925 }
7945 7926
7946 7927
7947 // Note: There is no need to deal with texture cleared tracking here 7928 // Note: There is no need to deal with texture cleared tracking here
7948 // because the validation above means you can only get here if the level 7929 // because the validation above means you can only get here if the level
7949 // is already a matching compressed format and in that case 7930 // is already a matching compressed format and in that case
7950 // CompressedTexImage2D already cleared the texture. 7931 // CompressedTexImage2D already cleared the texture.
7951 glCompressedTexSubImage2D( 7932 glCompressedTexSubImage2D(
7952 target, level, xoffset, yoffset, width, height, format, image_size, data); 7933 target, level, xoffset, yoffset, width, height, format, image_size, data);
(...skipping 19 matching lines...) Expand all
7972 void GLES2DecoderImpl::DoCopyTexImage2D( 7953 void GLES2DecoderImpl::DoCopyTexImage2D(
7973 GLenum target, 7954 GLenum target,
7974 GLint level, 7955 GLint level,
7975 GLenum internal_format, 7956 GLenum internal_format,
7976 GLint x, 7957 GLint x,
7977 GLint y, 7958 GLint y,
7978 GLsizei width, 7959 GLsizei width,
7979 GLsizei height, 7960 GLsizei height,
7980 GLint border) { 7961 GLint border) {
7981 DCHECK(!ShouldDeferReads()); 7962 DCHECK(!ShouldDeferReads());
7982 Texture* info = GetTextureInfoForTarget(target); 7963 Texture* texture = GetTextureInfoForTarget(target);
7983 if (!info) { 7964 if (!texture) {
7984 SetGLError(GL_INVALID_OPERATION, 7965 SetGLError(GL_INVALID_OPERATION,
7985 "glCopyTexImage2D", "unknown texture for target"); 7966 "glCopyTexImage2D", "unknown texture for target");
7986 return; 7967 return;
7987 } 7968 }
7988 if (info->IsImmutable()) { 7969 if (texture->IsImmutable()) {
7989 SetGLError(GL_INVALID_OPERATION, 7970 SetGLError(GL_INVALID_OPERATION,
7990 "glCopyTexImage2D", "texture is immutable"); 7971 "glCopyTexImage2D", "texture is immutable");
7991 } 7972 }
7992 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || 7973 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) ||
7993 border != 0) { 7974 border != 0) {
7994 SetGLError(GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range"); 7975 SetGLError(GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range");
7995 return; 7976 return;
7996 } 7977 }
7997 if (!ValidateTextureParameters( 7978 if (!ValidateTextureParameters(
7998 "glCopyTexImage2D", target, internal_format, GL_UNSIGNED_BYTE, level)) { 7979 "glCopyTexImage2D", target, internal_format, GL_UNSIGNED_BYTE, level)) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
8030 } 8011 }
8031 8012
8032 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { 8013 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) {
8033 return; 8014 return;
8034 } 8015 }
8035 8016
8036 CopyRealGLErrorsToWrapper(); 8017 CopyRealGLErrorsToWrapper();
8037 ScopedResolvedFrameBufferBinder binder(this, false, true); 8018 ScopedResolvedFrameBufferBinder binder(this, false, true);
8038 gfx::Size size = GetBoundReadFrameBufferSize(); 8019 gfx::Size size = GetBoundReadFrameBufferSize();
8039 8020
8040 if (info->IsAttachedToFramebuffer()) { 8021 if (texture->IsAttachedToFramebuffer()) {
8041 clear_state_dirty_ = true; 8022 clear_state_dirty_ = true;
8042 // TODO(gman): If textures tracked which framebuffers they were attached to 8023 // TODO(gman): If textures tracked which framebuffers they were attached to
8043 // we could just mark those framebuffers as not complete. 8024 // we could just mark those framebuffers as not complete.
8044 framebuffer_manager()->IncFramebufferStateChangeCount(); 8025 framebuffer_manager()->IncFramebufferStateChangeCount();
8045 } 8026 }
8046 8027
8047 // Clip to size to source dimensions 8028 // Clip to size to source dimensions
8048 GLint copyX = 0; 8029 GLint copyX = 0;
8049 GLint copyY = 0; 8030 GLint copyY = 0;
8050 GLint copyWidth = 0; 8031 GLint copyWidth = 0;
8051 GLint copyHeight = 0; 8032 GLint copyHeight = 0;
8052 Clip(x, width, size.width(), &copyX, &copyWidth); 8033 Clip(x, width, size.width(), &copyX, &copyWidth);
8053 Clip(y, height, size.height(), &copyY, &copyHeight); 8034 Clip(y, height, size.height(), &copyY, &copyHeight);
8054 8035
8055 if (copyX != x || 8036 if (copyX != x ||
8056 copyY != y || 8037 copyY != y ||
8057 copyWidth != width || 8038 copyWidth != width ||
8058 copyHeight != height) { 8039 copyHeight != height) {
8059 // some part was clipped so clear the texture. 8040 // some part was clipped so clear the texture.
8060 if (!ClearLevel( 8041 if (!ClearLevel(
8061 info->service_id(), info->target(), 8042 texture->service_id(), texture->target(),
8062 target, level, internal_format, GL_UNSIGNED_BYTE, width, height, 8043 target, level, internal_format, GL_UNSIGNED_BYTE, width, height,
8063 info->IsImmutable())) { 8044 texture->IsImmutable())) {
8064 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big"); 8045 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexImage2D", "dimensions too big");
8065 return; 8046 return;
8066 } 8047 }
8067 if (copyHeight > 0 && copyWidth > 0) { 8048 if (copyHeight > 0 && copyWidth > 0) {
8068 GLint dx = copyX - x; 8049 GLint dx = copyX - x;
8069 GLint dy = copyY - y; 8050 GLint dy = copyY - y;
8070 GLint destX = dx; 8051 GLint destX = dx;
8071 GLint destY = dy; 8052 GLint destY = dy;
8072 glCopyTexSubImage2D(target, level, 8053 glCopyTexSubImage2D(target, level,
8073 destX, destY, copyX, copyY, 8054 destX, destY, copyX, copyY,
8074 copyWidth, copyHeight); 8055 copyWidth, copyHeight);
8075 } 8056 }
8076 } else { 8057 } else {
8077 glCopyTexImage2D(target, level, internal_format, 8058 glCopyTexImage2D(target, level, internal_format,
8078 copyX, copyY, copyWidth, copyHeight, border); 8059 copyX, copyY, copyWidth, copyHeight, border);
8079 } 8060 }
8080 GLenum error = PeekGLError(); 8061 GLenum error = PeekGLError();
8081 if (error == GL_NO_ERROR) { 8062 if (error == GL_NO_ERROR) {
8082 texture_manager()->SetLevelInfo( 8063 texture_manager()->SetLevelInfo(
8083 info, target, level, internal_format, width, height, 1, 8064 texture, target, level, internal_format, width, height, 1,
8084 border, internal_format, GL_UNSIGNED_BYTE, true); 8065 border, internal_format, GL_UNSIGNED_BYTE, true);
8085 } 8066 }
8086 } 8067 }
8087 8068
8088 void GLES2DecoderImpl::DoCopyTexSubImage2D( 8069 void GLES2DecoderImpl::DoCopyTexSubImage2D(
8089 GLenum target, 8070 GLenum target,
8090 GLint level, 8071 GLint level,
8091 GLint xoffset, 8072 GLint xoffset,
8092 GLint yoffset, 8073 GLint yoffset,
8093 GLint x, 8074 GLint x,
8094 GLint y, 8075 GLint y,
8095 GLsizei width, 8076 GLsizei width,
8096 GLsizei height) { 8077 GLsizei height) {
8097 DCHECK(!ShouldDeferReads()); 8078 DCHECK(!ShouldDeferReads());
8098 Texture* info = GetTextureInfoForTarget(target); 8079 Texture* texture = GetTextureInfoForTarget(target);
8099 if (!info) { 8080 if (!texture) {
8100 SetGLError(GL_INVALID_OPERATION, 8081 SetGLError(GL_INVALID_OPERATION,
8101 "glCopyTexSubImage2D", "unknown texture for target"); 8082 "glCopyTexSubImage2D", "unknown texture for target");
8102 return; 8083 return;
8103 } 8084 }
8104 GLenum type = 0; 8085 GLenum type = 0;
8105 GLenum format = 0; 8086 GLenum format = 0;
8106 if (!info->GetLevelType(target, level, &type, &format) || 8087 if (!texture->GetLevelType(target, level, &type, &format) ||
8107 !info->ValidForTexture( 8088 !texture->ValidForTexture(
8108 target, level, xoffset, yoffset, width, height, format, type)) { 8089 target, level, xoffset, yoffset, width, height, format, type)) {
8109 SetGLError(GL_INVALID_VALUE, 8090 SetGLError(GL_INVALID_VALUE,
8110 "glCopyTexSubImage2D", "bad dimensions."); 8091 "glCopyTexSubImage2D", "bad dimensions.");
8111 return; 8092 return;
8112 } 8093 }
8113 if (info->AsyncTransferIsInProgress()) { 8094 if (texture->AsyncTransferIsInProgress()) {
8114 SetGLError(GL_INVALID_OPERATION, 8095 SetGLError(GL_INVALID_OPERATION,
8115 "glCopyTexSubImage2D", "async upload pending for texture"); 8096 "glCopyTexSubImage2D", "async upload pending for texture");
8116 return; 8097 return;
8117 } 8098 }
8118 8099
8119 // Check we have compatible formats. 8100 // Check we have compatible formats.
8120 GLenum read_format = GetBoundReadFrameBufferInternalFormat(); 8101 GLenum read_format = GetBoundReadFrameBufferInternalFormat();
8121 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format); 8102 uint32 channels_exist = GLES2Util::GetChannelsForFormat(read_format);
8122 uint32 channels_needed = GLES2Util::GetChannelsForFormat(format); 8103 uint32 channels_needed = GLES2Util::GetChannelsForFormat(format);
8123 8104
(...skipping 17 matching lines...) Expand all
8141 8122
8142 ScopedResolvedFrameBufferBinder binder(this, false, true); 8123 ScopedResolvedFrameBufferBinder binder(this, false, true);
8143 gfx::Size size = GetBoundReadFrameBufferSize(); 8124 gfx::Size size = GetBoundReadFrameBufferSize();
8144 GLint copyX = 0; 8125 GLint copyX = 0;
8145 GLint copyY = 0; 8126 GLint copyY = 0;
8146 GLint copyWidth = 0; 8127 GLint copyWidth = 0;
8147 GLint copyHeight = 0; 8128 GLint copyHeight = 0;
8148 Clip(x, width, size.width(), &copyX, &copyWidth); 8129 Clip(x, width, size.width(), &copyX, &copyWidth);
8149 Clip(y, height, size.height(), &copyY, &copyHeight); 8130 Clip(y, height, size.height(), &copyY, &copyHeight);
8150 8131
8151 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { 8132 if (!texture_manager()->ClearTextureLevel(this, texture, target, level)) {
8152 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", "dimensions too big"); 8133 SetGLError(GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", "dimensions too big");
8153 return; 8134 return;
8154 } 8135 }
8155 8136
8156 if (copyX != x || 8137 if (copyX != x ||
8157 copyY != y || 8138 copyY != y ||
8158 copyWidth != width || 8139 copyWidth != width ||
8159 copyHeight != height) { 8140 copyHeight != height) {
8160 // some part was clipped so clear the sub rect. 8141 // some part was clipped so clear the sub rect.
8161 uint32 pixels_size = 0; 8142 uint32 pixels_size = 0;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
8210 return false; 8191 return false;
8211 } 8192 }
8212 if (!validators_->texture_format.IsValid(format)) { 8193 if (!validators_->texture_format.IsValid(format)) {
8213 SetGLErrorInvalidEnum(function_name, format, "format"); 8194 SetGLErrorInvalidEnum(function_name, format, "format");
8214 return false; 8195 return false;
8215 } 8196 }
8216 if (!validators_->pixel_type.IsValid(type)) { 8197 if (!validators_->pixel_type.IsValid(type)) {
8217 SetGLErrorInvalidEnum(function_name, type, "type"); 8198 SetGLErrorInvalidEnum(function_name, type, "type");
8218 return false; 8199 return false;
8219 } 8200 }
8220 Texture* info = GetTextureInfoForTarget(target); 8201 Texture* texture = GetTextureInfoForTarget(target);
8221 if (!info) { 8202 if (!texture) {
8222 SetGLError(GL_INVALID_OPERATION, 8203 SetGLError(GL_INVALID_OPERATION,
8223 function_name, "unknown texture for target"); 8204 function_name, "unknown texture for target");
8224 return false; 8205 return false;
8225 } 8206 }
8226 GLenum current_type = 0; 8207 GLenum current_type = 0;
8227 GLenum internal_format = 0; 8208 GLenum internal_format = 0;
8228 if (!info->GetLevelType(target, level, &current_type, &internal_format)) { 8209 if (!texture->GetLevelType(target, level, &current_type, &internal_format)) {
8229 SetGLError( 8210 SetGLError(
8230 GL_INVALID_OPERATION, function_name, "level does not exist."); 8211 GL_INVALID_OPERATION, function_name, "level does not exist.");
8231 return false; 8212 return false;
8232 } 8213 }
8233 if (format != internal_format) { 8214 if (format != internal_format) {
8234 SetGLError(GL_INVALID_OPERATION, 8215 SetGLError(GL_INVALID_OPERATION,
8235 function_name, "format does not match internal format."); 8216 function_name, "format does not match internal format.");
8236 return false; 8217 return false;
8237 } 8218 }
8238 if (type != current_type) { 8219 if (type != current_type) {
8239 SetGLError(GL_INVALID_OPERATION, 8220 SetGLError(GL_INVALID_OPERATION,
8240 function_name, "type does not match type of texture."); 8221 function_name, "type does not match type of texture.");
8241 return false; 8222 return false;
8242 } 8223 }
8243 if (info->AsyncTransferIsInProgress()) { 8224 if (texture->AsyncTransferIsInProgress()) {
8244 SetGLError(GL_INVALID_OPERATION, 8225 SetGLError(GL_INVALID_OPERATION,
8245 function_name, "async upload pending for texture"); 8226 function_name, "async upload pending for texture");
8246 return false; 8227 return false;
8247 } 8228 }
8248 if (!info->ValidForTexture( 8229 if (!texture->ValidForTexture(
8249 target, level, xoffset, yoffset, width, height, format, type)) { 8230 target, level, xoffset, yoffset, width, height, format, type)) {
8250 SetGLError(GL_INVALID_VALUE, function_name, "bad dimensions."); 8231 SetGLError(GL_INVALID_VALUE, function_name, "bad dimensions.");
8251 return false; 8232 return false;
8252 } 8233 }
8253 if ((GLES2Util::GetChannelsForFormat(format) & 8234 if ((GLES2Util::GetChannelsForFormat(format) &
8254 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) { 8235 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0) {
8255 SetGLError( 8236 SetGLError(
8256 GL_INVALID_OPERATION, 8237 GL_INVALID_OPERATION,
8257 function_name, "can not supply data for depth or stencil textures"); 8238 function_name, "can not supply data for depth or stencil textures");
8258 return false; 8239 return false;
(...skipping 13 matching lines...) Expand all
8272 GLsizei width, 8253 GLsizei width,
8273 GLsizei height, 8254 GLsizei height,
8274 GLenum format, 8255 GLenum format,
8275 GLenum type, 8256 GLenum type,
8276 const void * data) { 8257 const void * data) {
8277 error::Error error = error::kNoError; 8258 error::Error error = error::kNoError;
8278 if (!ValidateTexSubImage2D(&error, "glTexSubImage2D", target, level, 8259 if (!ValidateTexSubImage2D(&error, "glTexSubImage2D", target, level,
8279 xoffset, yoffset, width, height, format, type, data)) { 8260 xoffset, yoffset, width, height, format, type, data)) {
8280 return error; 8261 return error;
8281 } 8262 }
8282 Texture* info = GetTextureInfoForTarget(target); 8263 Texture* texture = GetTextureInfoForTarget(target);
8283 GLsizei tex_width = 0; 8264 GLsizei tex_width = 0;
8284 GLsizei tex_height = 0; 8265 GLsizei tex_height = 0;
8285 bool ok = info->GetLevelSize(target, level, &tex_width, &tex_height); 8266 bool ok = texture->GetLevelSize(target, level, &tex_width, &tex_height);
8286 DCHECK(ok); 8267 DCHECK(ok);
8287 if (xoffset != 0 || yoffset != 0 || 8268 if (xoffset != 0 || yoffset != 0 ||
8288 width != tex_width || height != tex_height) { 8269 width != tex_width || height != tex_height) {
8289 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { 8270 if (!texture_manager()->ClearTextureLevel(this, texture, target, level)) {
8290 SetGLError(GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); 8271 SetGLError(GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big");
8291 return error::kNoError; 8272 return error::kNoError;
8292 } 8273 }
8293 ScopedTextureUploadTimer timer(this); 8274 ScopedTextureUploadTimer timer(this);
8294 glTexSubImage2D( 8275 glTexSubImage2D(
8295 target, level, xoffset, yoffset, width, height, format, type, data); 8276 target, level, xoffset, yoffset, width, height, format, type, data);
8296 return error::kNoError; 8277 return error::kNoError;
8297 } 8278 }
8298 8279
8299 if (teximage2d_faster_than_texsubimage2d_ && !info->IsImmutable()) { 8280 if (teximage2d_faster_than_texsubimage2d_ && !texture->IsImmutable()) {
8300 ScopedTextureUploadTimer timer(this); 8281 ScopedTextureUploadTimer timer(this);
8301 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the 8282 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the
8302 // same as internal_foramt. If that changes we'll need to look them up. 8283 // same as internal_foramt. If that changes we'll need to look them up.
8303 WrappedTexImage2D( 8284 WrappedTexImage2D(
8304 target, level, format, width, height, 0, format, type, data); 8285 target, level, format, width, height, 0, format, type, data);
8305 } else { 8286 } else {
8306 ScopedTextureUploadTimer timer(this); 8287 ScopedTextureUploadTimer timer(this);
8307 glTexSubImage2D( 8288 glTexSubImage2D(
8308 target, level, xoffset, yoffset, width, height, format, type, data); 8289 target, level, xoffset, yoffset, width, height, format, type, data);
8309 } 8290 }
8310 texture_manager()->SetLevelCleared(info, target, level, true); 8291 texture_manager()->SetLevelCleared(texture, target, level, true);
8311 return error::kNoError; 8292 return error::kNoError;
8312 } 8293 }
8313 8294
8314 error::Error GLES2DecoderImpl::HandleTexSubImage2D( 8295 error::Error GLES2DecoderImpl::HandleTexSubImage2D(
8315 uint32 immediate_data_size, const cmds::TexSubImage2D& c) { 8296 uint32 immediate_data_size, const cmds::TexSubImage2D& c) {
8316 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); 8297 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D");
8317 GLboolean internal = static_cast<GLboolean>(c.internal); 8298 GLboolean internal = static_cast<GLboolean>(c.internal);
8318 if (internal == GL_TRUE && tex_image_2d_failed_) 8299 if (internal == GL_TRUE && tex_image_2d_failed_)
8319 return error::kNoError; 8300 return error::kNoError;
8320 8301
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after
9318 } 9299 }
9319 9300
9320 uint32 client_id = c.client_id; 9301 uint32 client_id = c.client_id;
9321 typedef cmds::CreateStreamTextureCHROMIUM::Result Result; 9302 typedef cmds::CreateStreamTextureCHROMIUM::Result Result;
9322 Result* result = GetSharedMemoryAs<Result*>( 9303 Result* result = GetSharedMemoryAs<Result*>(
9323 c.result_shm_id, c.result_shm_offset, sizeof(*result)); 9304 c.result_shm_id, c.result_shm_offset, sizeof(*result));
9324 9305
9325 if (!result) 9306 if (!result)
9326 return error::kOutOfBounds; 9307 return error::kOutOfBounds;
9327 *result = GL_ZERO; 9308 *result = GL_ZERO;
9328 Texture* info = 9309 Texture* texture = texture_manager()->GetTexture(client_id);
9329 texture_manager()->GetTexture(client_id); 9310 if (!texture) {
9330 if (!info) {
9331 SetGLError(GL_INVALID_VALUE, 9311 SetGLError(GL_INVALID_VALUE,
9332 "glCreateStreamTextureCHROMIUM", "" 9312 "glCreateStreamTextureCHROMIUM", ""
9333 "bad texture id."); 9313 "bad texture id.");
9334 return error::kNoError; 9314 return error::kNoError;
9335 } 9315 }
9336 9316
9337 if (info->IsStreamTexture()) { 9317 if (texture->IsStreamTexture()) {
9338 SetGLError(GL_INVALID_OPERATION, 9318 SetGLError(GL_INVALID_OPERATION,
9339 "glCreateStreamTextureCHROMIUM", "" 9319 "glCreateStreamTextureCHROMIUM", ""
9340 "is already a stream texture."); 9320 "is already a stream texture.");
9341 return error::kNoError; 9321 return error::kNoError;
9342 } 9322 }
9343 9323
9344 if (info->target() && info->target() != GL_TEXTURE_EXTERNAL_OES) { 9324 if (texture->target() && texture->target() != GL_TEXTURE_EXTERNAL_OES) {
9345 SetGLError(GL_INVALID_OPERATION, 9325 SetGLError(GL_INVALID_OPERATION,
9346 "glCreateStreamTextureCHROMIUM", "" 9326 "glCreateStreamTextureCHROMIUM", ""
9347 "is already bound to incompatible target."); 9327 "is already bound to incompatible target.");
9348 return error::kNoError; 9328 return error::kNoError;
9349 } 9329 }
9350 9330
9351 if (!stream_texture_manager_) 9331 if (!stream_texture_manager_)
9352 return error::kInvalidArguments; 9332 return error::kInvalidArguments;
9353 9333
9354 GLuint object_id = stream_texture_manager_->CreateStreamTexture( 9334 GLuint object_id = stream_texture_manager_->CreateStreamTexture(
9355 info->service_id(), client_id); 9335 texture->service_id(), client_id);
9356 9336
9357 if (object_id) { 9337 if (object_id) {
9358 info->SetStreamTexture(true); 9338 texture->SetStreamTexture(true);
9359 } else { 9339 } else {
9360 SetGLError(GL_OUT_OF_MEMORY, 9340 SetGLError(GL_OUT_OF_MEMORY,
9361 "glCreateStreamTextureCHROMIUM", "" 9341 "glCreateStreamTextureCHROMIUM", ""
9362 "failed to create platform texture."); 9342 "failed to create platform texture.");
9363 } 9343 }
9364 9344
9365 *result = object_id; 9345 *result = object_id;
9366 return error::kNoError; 9346 return error::kNoError;
9367 } 9347 }
9368 9348
9369 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( 9349 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM(
9370 uint32 immediate_data_size, 9350 uint32 immediate_data_size,
9371 const cmds::DestroyStreamTextureCHROMIUM& c) { 9351 const cmds::DestroyStreamTextureCHROMIUM& c) {
9372 GLuint client_id = c.texture; 9352 GLuint client_id = c.texture;
9373 Texture* info = 9353 Texture* texture = texture_manager()->GetTexture(client_id);
9374 texture_manager()->GetTexture(client_id); 9354 if (texture && texture->IsStreamTexture()) {
9375 if (info && info->IsStreamTexture()) {
9376 if (!stream_texture_manager_) 9355 if (!stream_texture_manager_)
9377 return error::kInvalidArguments; 9356 return error::kInvalidArguments;
9378 9357
9379 stream_texture_manager_->DestroyStreamTexture(info->service_id()); 9358 stream_texture_manager_->DestroyStreamTexture(texture->service_id());
9380 info->SetStreamTexture(false); 9359 texture->SetStreamTexture(false);
9381 } else { 9360 } else {
9382 SetGLError(GL_INVALID_VALUE, 9361 SetGLError(GL_INVALID_VALUE,
9383 "glDestroyStreamTextureCHROMIUM", "bad texture id."); 9362 "glDestroyStreamTextureCHROMIUM", "bad texture id.");
9384 } 9363 }
9385 9364
9386 return error::kNoError; 9365 return error::kNoError;
9387 } 9366 }
9388 9367
9389 #if defined(OS_MACOSX) 9368 #if defined(OS_MACOSX)
9390 void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) { 9369 void GLES2DecoderImpl::ReleaseIOSurfaceForTexture(GLuint texture_id) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
9424 // know what's going on. 9403 // know what's going on.
9425 SetGLError( 9404 SetGLError(
9426 GL_INVALID_OPERATION, 9405 GL_INVALID_OPERATION,
9427 "glTexImageIOSurface2DCHROMIUM", 9406 "glTexImageIOSurface2DCHROMIUM",
9428 "requires TEXTURE_RECTANGLE_ARB target"); 9407 "requires TEXTURE_RECTANGLE_ARB target");
9429 return; 9408 return;
9430 } 9409 }
9431 9410
9432 // Default target might be conceptually valid, but disallow it to avoid 9411 // Default target might be conceptually valid, but disallow it to avoid
9433 // accidents. 9412 // accidents.
9434 Texture* info = GetTextureInfoForTargetUnlessDefault( 9413 Texture* texture = GetTextureInfoForTargetUnlessDefault(target);
9435 target); 9414 if (!texture) {
9436 if (!info) {
9437 SetGLError(GL_INVALID_OPERATION, 9415 SetGLError(GL_INVALID_OPERATION,
9438 "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); 9416 "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound");
9439 return; 9417 return;
9440 } 9418 }
9441 9419
9442 // Look up the new IOSurface. Note that because of asynchrony 9420 // Look up the new IOSurface. Note that because of asynchrony
9443 // between processes this might fail; during live resizing the 9421 // between processes this might fail; during live resizing the
9444 // plugin process might allocate and release an IOSurface before 9422 // plugin process might allocate and release an IOSurface before
9445 // this process gets a chance to look it up. Hold on to any old 9423 // this process gets a chance to look it up. Hold on to any old
9446 // IOSurface in this case. 9424 // IOSurface in this case.
9447 CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); 9425 CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id);
9448 if (!surface) { 9426 if (!surface) {
9449 SetGLError( 9427 SetGLError(
9450 GL_INVALID_OPERATION, 9428 GL_INVALID_OPERATION,
9451 "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); 9429 "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID");
9452 return; 9430 return;
9453 } 9431 }
9454 9432
9455 // Release any IOSurface previously bound to this texture. 9433 // Release any IOSurface previously bound to this texture.
9456 ReleaseIOSurfaceForTexture(info->service_id()); 9434 ReleaseIOSurfaceForTexture(texture->service_id());
9457 9435
9458 // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. 9436 // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails.
9459 texture_to_io_surface_map_.insert( 9437 texture_to_io_surface_map_.insert(
9460 std::make_pair(info->service_id(), surface)); 9438 std::make_pair(texture->service_id(), surface));
9461 9439
9462 CGLContextObj context = 9440 CGLContextObj context =
9463 static_cast<CGLContextObj>(context_->GetHandle()); 9441 static_cast<CGLContextObj>(context_->GetHandle());
9464 9442
9465 CGLError err = surface_support->CGLTexImageIOSurface2D( 9443 CGLError err = surface_support->CGLTexImageIOSurface2D(
9466 context, 9444 context,
9467 target, 9445 target,
9468 GL_RGBA, 9446 GL_RGBA,
9469 width, 9447 width,
9470 height, 9448 height,
9471 GL_BGRA, 9449 GL_BGRA,
9472 GL_UNSIGNED_INT_8_8_8_8_REV, 9450 GL_UNSIGNED_INT_8_8_8_8_REV,
9473 surface, 9451 surface,
9474 plane); 9452 plane);
9475 9453
9476 if (err != kCGLNoError) { 9454 if (err != kCGLNoError) {
9477 SetGLError( 9455 SetGLError(
9478 GL_INVALID_OPERATION, 9456 GL_INVALID_OPERATION,
9479 "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D"); 9457 "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D");
9480 return; 9458 return;
9481 } 9459 }
9482 9460
9483 texture_manager()->SetLevelInfo( 9461 texture_manager()->SetLevelInfo(
9484 info, target, 0, GL_RGBA, width, height, 1, 0, 9462 texture, target, 0, GL_RGBA, width, height, 1, 0,
9485 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); 9463 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true);
9486 9464
9487 #else 9465 #else
9488 SetGLError(GL_INVALID_OPERATION, 9466 SetGLError(GL_INVALID_OPERATION,
9489 "glTexImageIOSurface2DCHROMIUM", "not supported."); 9467 "glTexImageIOSurface2DCHROMIUM", "not supported.");
9490 #endif 9468 #endif
9491 } 9469 }
9492 9470
9493 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { 9471 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) {
9494 switch (internalformat) { 9472 switch (internalformat) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
9531 case GL_BGRA8_EXT: 9509 case GL_BGRA8_EXT:
9532 return GL_BGRA_EXT; 9510 return GL_BGRA_EXT;
9533 default: 9511 default:
9534 return GL_NONE; 9512 return GL_NONE;
9535 } 9513 }
9536 } 9514 }
9537 9515
9538 void GLES2DecoderImpl::DoCopyTextureCHROMIUM( 9516 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
9539 GLenum target, GLuint source_id, GLuint dest_id, GLint level, 9517 GLenum target, GLuint source_id, GLuint dest_id, GLint level,
9540 GLenum internal_format) { 9518 GLenum internal_format) {
9541 Texture* dest_info = GetTexture(dest_id); 9519 Texture* dest_texture = GetTexture(dest_id);
9542 Texture* source_info = GetTexture(source_id); 9520 Texture* source_texture = GetTexture(source_id);
9543 9521
9544 if (!source_info || !dest_info) { 9522 if (!source_texture || !dest_texture) {
9545 SetGLError(GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); 9523 SetGLError(GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id");
9546 return; 9524 return;
9547 } 9525 }
9548 9526
9549 if (GL_TEXTURE_2D != target) { 9527 if (GL_TEXTURE_2D != target) {
9550 SetGLError(GL_INVALID_VALUE, 9528 SetGLError(GL_INVALID_VALUE,
9551 "glCopyTextureCHROMIUM", "invalid texture target"); 9529 "glCopyTextureCHROMIUM", "invalid texture target");
9552 return; 9530 return;
9553 } 9531 }
9554 9532
9555 if (dest_info->target() != GL_TEXTURE_2D || 9533 if (dest_texture->target() != GL_TEXTURE_2D ||
9556 source_info->target() != GL_TEXTURE_2D) { 9534 source_texture->target() != GL_TEXTURE_2D) {
9557 SetGLError(GL_INVALID_VALUE, 9535 SetGLError(GL_INVALID_VALUE,
9558 "glCopyTextureCHROMIUM", "invalid texture target binding"); 9536 "glCopyTextureCHROMIUM", "invalid texture target binding");
9559 return; 9537 return;
9560 } 9538 }
9561 9539
9562 int source_width, source_height, dest_width, dest_height; 9540 int source_width, source_height, dest_width, dest_height;
9563 if (!source_info->GetLevelSize(GL_TEXTURE_2D, 0, &source_width, 9541 if (!source_texture->GetLevelSize(GL_TEXTURE_2D, 0, &source_width,
9564 &source_height)) { 9542 &source_height)) {
9565 SetGLError(GL_INVALID_VALUE, 9543 SetGLError(GL_INVALID_VALUE,
9566 "glCopyTextureChromium", "source texture has no level 0"); 9544 "glCopyTextureChromium", "source texture has no level 0");
9567 return; 9545 return;
9568 } 9546 }
9569 9547
9570 // Check that this type of texture is allowed. 9548 // Check that this type of texture is allowed.
9571 if (!texture_manager()->ValidForTarget(GL_TEXTURE_2D, level, source_width, 9549 if (!texture_manager()->ValidForTarget(GL_TEXTURE_2D, level, source_width,
9572 source_height, 1)) { 9550 source_height, 1)) {
9573 SetGLError(GL_INVALID_VALUE, 9551 SetGLError(GL_INVALID_VALUE,
9574 "glCopyTextureCHROMIUM", "Bad dimensions"); 9552 "glCopyTextureCHROMIUM", "Bad dimensions");
9575 return; 9553 return;
9576 } 9554 }
9577 9555
9578 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is 9556 // Defer initializing the CopyTextureCHROMIUMResourceManager until it is
9579 // needed because it takes 10s of milliseconds to initialize. 9557 // needed because it takes 10s of milliseconds to initialize.
9580 if (!copy_texture_CHROMIUM_.get()) { 9558 if (!copy_texture_CHROMIUM_.get()) {
9581 CopyRealGLErrorsToWrapper(); 9559 CopyRealGLErrorsToWrapper();
9582 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager()); 9560 copy_texture_CHROMIUM_.reset(new CopyTextureCHROMIUMResourceManager());
9583 copy_texture_CHROMIUM_->Initialize(this); 9561 copy_texture_CHROMIUM_->Initialize(this);
9584 RestoreCurrentFramebufferBindings(); 9562 RestoreCurrentFramebufferBindings();
9585 if (PeekGLError() != GL_NO_ERROR) 9563 if (PeekGLError() != GL_NO_ERROR)
9586 return; 9564 return;
9587 } 9565 }
9588 9566
9589 GLenum dest_type; 9567 GLenum dest_type;
9590 GLenum dest_internal_format; 9568 GLenum dest_internal_format;
9591 bool dest_level_defined = dest_info->GetLevelSize(GL_TEXTURE_2D, level, 9569 bool dest_level_defined = dest_texture->GetLevelSize(
9592 &dest_width, 9570 GL_TEXTURE_2D, level, &dest_width, &dest_height);
9593 &dest_height);
9594 9571
9595 if (dest_level_defined) { 9572 if (dest_level_defined) {
9596 dest_info->GetLevelType(GL_TEXTURE_2D, level, &dest_type, 9573 dest_texture->GetLevelType(GL_TEXTURE_2D, level, &dest_type,
9597 &dest_internal_format); 9574 &dest_internal_format);
9598 } else { 9575 } else {
9599 GLenum source_internal_format; 9576 GLenum source_internal_format;
9600 source_info->GetLevelType(GL_TEXTURE_2D, 0, &dest_type, 9577 source_texture->GetLevelType(GL_TEXTURE_2D, 0, &dest_type,
9601 &source_internal_format); 9578 &source_internal_format);
9602 } 9579 }
9603 9580
9604 // Resize the destination texture to the dimensions of the source texture. 9581 // Resize the destination texture to the dimensions of the source texture.
9605 if (!dest_level_defined || dest_width != source_width || 9582 if (!dest_level_defined || dest_width != source_width ||
9606 dest_height != source_height || 9583 dest_height != source_height ||
9607 dest_internal_format != internal_format) { 9584 dest_internal_format != internal_format) {
9608 // Ensure that the glTexImage2D succeeds. 9585 // Ensure that the glTexImage2D succeeds.
9609 CopyRealGLErrorsToWrapper(); 9586 CopyRealGLErrorsToWrapper();
9610 glBindTexture(GL_TEXTURE_2D, dest_info->service_id()); 9587 glBindTexture(GL_TEXTURE_2D, dest_texture->service_id());
9611 WrappedTexImage2D( 9588 WrappedTexImage2D(
9612 GL_TEXTURE_2D, level, internal_format, source_width, source_height, 9589 GL_TEXTURE_2D, level, internal_format, source_width, source_height,
9613 0, internal_format, dest_type, NULL); 9590 0, internal_format, dest_type, NULL);
9614 GLenum error = PeekGLError(); 9591 GLenum error = PeekGLError();
9615 if (error != GL_NO_ERROR) { 9592 if (error != GL_NO_ERROR) {
9616 RestoreCurrentTexture2DBindings(); 9593 RestoreCurrentTexture2DBindings();
9617 return; 9594 return;
9618 } 9595 }
9619 9596
9620 texture_manager()->SetLevelInfo( 9597 texture_manager()->SetLevelInfo(
9621 dest_info, GL_TEXTURE_2D, level, internal_format, source_width, 9598 dest_texture, GL_TEXTURE_2D, level, internal_format, source_width,
9622 source_height, 1, 0, internal_format, dest_type, true); 9599 source_height, 1, 0, internal_format, dest_type, true);
9623 } else { 9600 } else {
9624 texture_manager()->SetLevelCleared(dest_info, GL_TEXTURE_2D, level, true); 9601 texture_manager()->SetLevelCleared(
9602 dest_texture, GL_TEXTURE_2D, level, true);
9625 } 9603 }
9626 9604
9627 copy_texture_CHROMIUM_->DoCopyTexture(this, 9605 copy_texture_CHROMIUM_->DoCopyTexture(this,
9628 source_info->target(), 9606 source_texture->target(),
9629 dest_info->target(), 9607 dest_texture->target(),
9630 source_info->service_id(), 9608 source_texture->service_id(),
9631 dest_info->service_id(), level, 9609 dest_texture->service_id(), level,
9632 source_width, source_height, 9610 source_width, source_height,
9633 unpack_flip_y_, 9611 unpack_flip_y_,
9634 unpack_premultiply_alpha_, 9612 unpack_premultiply_alpha_,
9635 unpack_unpremultiply_alpha_); 9613 unpack_unpremultiply_alpha_);
9636 } 9614 }
9637 9615
9638 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) { 9616 static GLenum ExtractTypeFromStorageFormat(GLenum internalformat) {
9639 switch (internalformat) { 9617 switch (internalformat) {
9640 case GL_RGB565: 9618 case GL_RGB565:
9641 return GL_UNSIGNED_SHORT_5_6_5; 9619 return GL_UNSIGNED_SHORT_5_6_5;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
9686 GLenum internal_format, 9664 GLenum internal_format,
9687 GLsizei width, 9665 GLsizei width,
9688 GLsizei height) { 9666 GLsizei height) {
9689 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT"); 9667 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT");
9690 if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || 9668 if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) ||
9691 TextureManager::ComputeMipMapCount(width, height, 1) < levels) { 9669 TextureManager::ComputeMipMapCount(width, height, 1) < levels) {
9692 SetGLError( 9670 SetGLError(
9693 GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range"); 9671 GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range");
9694 return; 9672 return;
9695 } 9673 }
9696 Texture* info = GetTextureInfoForTarget(target); 9674 Texture* texture = GetTextureInfoForTarget(target);
9697 if (!info) { 9675 if (!texture) {
9698 SetGLError(GL_INVALID_OPERATION, 9676 SetGLError(GL_INVALID_OPERATION,
9699 "glTexStorage2DEXT", "unknown texture for target"); 9677 "glTexStorage2DEXT", "unknown texture for target");
9700 return; 9678 return;
9701 } 9679 }
9702 if (info->IsAttachedToFramebuffer()) { 9680 if (texture->IsAttachedToFramebuffer()) {
9703 clear_state_dirty_ = true; 9681 clear_state_dirty_ = true;
9704 } 9682 }
9705 if (info->IsImmutable()) { 9683 if (texture->IsImmutable()) {
9706 SetGLError(GL_INVALID_OPERATION, 9684 SetGLError(GL_INVALID_OPERATION,
9707 "glTexStorage2DEXT", "texture is immutable"); 9685 "glTexStorage2DEXT", "texture is immutable");
9708 return; 9686 return;
9709 } 9687 }
9710 9688
9711 GLenum format = ExtractFormatFromStorageFormat(internal_format); 9689 GLenum format = ExtractFormatFromStorageFormat(internal_format);
9712 GLenum type = ExtractTypeFromStorageFormat(internal_format); 9690 GLenum type = ExtractTypeFromStorageFormat(internal_format);
9713 9691
9714 { 9692 {
9715 GLsizei level_width = width; 9693 GLsizei level_width = width;
(...skipping 20 matching lines...) Expand all
9736 9714
9737 CopyRealGLErrorsToWrapper(); 9715 CopyRealGLErrorsToWrapper();
9738 glTexStorage2DEXT(target, levels, GetTexInternalFormat(internal_format), 9716 glTexStorage2DEXT(target, levels, GetTexInternalFormat(internal_format),
9739 width, height); 9717 width, height);
9740 GLenum error = PeekGLError(); 9718 GLenum error = PeekGLError();
9741 if (error == GL_NO_ERROR) { 9719 if (error == GL_NO_ERROR) {
9742 GLsizei level_width = width; 9720 GLsizei level_width = width;
9743 GLsizei level_height = height; 9721 GLsizei level_height = height;
9744 for (int ii = 0; ii < levels; ++ii) { 9722 for (int ii = 0; ii < levels; ++ii) {
9745 texture_manager()->SetLevelInfo( 9723 texture_manager()->SetLevelInfo(
9746 info, target, ii, format, level_width, level_height, 1, 0, format, 9724 texture, target, ii, format, level_width, level_height, 1, 0, format,
9747 type, false); 9725 type, false);
9748 level_width = std::max(1, level_width >> 1); 9726 level_width = std::max(1, level_width >> 1);
9749 level_height = std::max(1, level_height >> 1); 9727 level_height = std::max(1, level_height >> 1);
9750 } 9728 }
9751 info->SetImmutable(true); 9729 texture->SetImmutable(true);
9752 } 9730 }
9753 } 9731 }
9754 9732
9755 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( 9733 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM(
9756 uint32 immediate_data_size, const cmds::GenMailboxCHROMIUM& c) { 9734 uint32 immediate_data_size, const cmds::GenMailboxCHROMIUM& c) {
9757 MailboxName name; 9735 MailboxName name;
9758 mailbox_manager()->GenerateMailboxName(&name); 9736 mailbox_manager()->GenerateMailboxName(&name);
9759 uint32 bucket_id = static_cast<uint32>(c.bucket_id); 9737 uint32 bucket_id = static_cast<uint32>(c.bucket_id);
9760 Bucket* bucket = CreateBucket(bucket_id); 9738 Bucket* bucket = CreateBucket(bucket_id);
9761 9739
9762 bucket->SetSize(GL_MAILBOX_SIZE_CHROMIUM); 9740 bucket->SetSize(GL_MAILBOX_SIZE_CHROMIUM);
9763 bucket->SetData(&name, 0, GL_MAILBOX_SIZE_CHROMIUM); 9741 bucket->SetData(&name, 0, GL_MAILBOX_SIZE_CHROMIUM);
9764 9742
9765 return error::kNoError; 9743 return error::kNoError;
9766 } 9744 }
9767 9745
9768 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, 9746 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target,
9769 const GLbyte* mailbox) { 9747 const GLbyte* mailbox) {
9770 Texture* info = GetTextureInfoForTarget(target); 9748 Texture* texture = GetTextureInfoForTarget(target);
9771 if (!info) { 9749 if (!texture) {
9772 SetGLError(GL_INVALID_OPERATION, 9750 SetGLError(GL_INVALID_OPERATION,
9773 "glProduceTextureCHROMIUM", "unknown texture for target"); 9751 "glProduceTextureCHROMIUM", "unknown texture for target");
9774 return; 9752 return;
9775 } 9753 }
9776 9754
9777 TextureDefinition* definition = texture_manager()->Save(info); 9755 TextureDefinition* definition = texture_manager()->Save(texture);
9778 if (!definition) { 9756 if (!definition) {
9779 SetGLError(GL_INVALID_OPERATION, 9757 SetGLError(GL_INVALID_OPERATION,
9780 "glProduceTextureCHROMIUM", "invalid texture"); 9758 "glProduceTextureCHROMIUM", "invalid texture");
9781 return; 9759 return;
9782 } 9760 }
9783 9761
9784 if (!group_->mailbox_manager()->ProduceTexture( 9762 if (!group_->mailbox_manager()->ProduceTexture(
9785 target, 9763 target,
9786 *reinterpret_cast<const MailboxName*>(mailbox), 9764 *reinterpret_cast<const MailboxName*>(mailbox),
9787 definition, 9765 definition,
9788 texture_manager())) { 9766 texture_manager())) {
9789 bool success = texture_manager()->Restore(info, definition); 9767 bool success = texture_manager()->Restore(
9768 "glProductTextureCHROMIUM", this, texture, definition);
9790 DCHECK(success); 9769 DCHECK(success);
9791 SetGLError(GL_INVALID_OPERATION, 9770 SetGLError(GL_INVALID_OPERATION,
9792 "glProduceTextureCHROMIUM", "invalid mailbox name"); 9771 "glProduceTextureCHROMIUM", "invalid mailbox name");
9793 return; 9772 return;
9794 } 9773 }
9795 9774
9796 glBindTexture(info->target(), info->service_id()); 9775 glBindTexture(texture->target(), texture->service_id());
9797 } 9776 }
9798 9777
9799 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, 9778 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target,
9800 const GLbyte* mailbox) { 9779 const GLbyte* mailbox) {
9801 Texture* info = GetTextureInfoForTarget(target); 9780 Texture* texture = GetTextureInfoForTarget(target);
9802 if (!info) { 9781 if (!texture) {
9803 SetGLError(GL_INVALID_OPERATION, 9782 SetGLError(GL_INVALID_OPERATION,
9804 "glConsumeTextureCHROMIUM", "unknown texture for target"); 9783 "glConsumeTextureCHROMIUM", "unknown texture for target");
9805 return; 9784 return;
9806 } 9785 }
9807 9786
9808 scoped_ptr<TextureDefinition> definition( 9787 scoped_ptr<TextureDefinition> definition(
9809 group_->mailbox_manager()->ConsumeTexture( 9788 group_->mailbox_manager()->ConsumeTexture(
9810 target, 9789 target,
9811 *reinterpret_cast<const MailboxName*>(mailbox))); 9790 *reinterpret_cast<const MailboxName*>(mailbox)));
9812 if (!definition.get()) { 9791 if (!definition.get()) {
9813 SetGLError(GL_INVALID_OPERATION, 9792 SetGLError(GL_INVALID_OPERATION,
9814 "glConsumeTextureCHROMIUM", "invalid mailbox name"); 9793 "glConsumeTextureCHROMIUM", "invalid mailbox name");
9815 return; 9794 return;
9816 } 9795 }
9817 9796
9818 if (!texture_manager()->Restore(info, definition.release())) { 9797 if (!texture_manager()->Restore(
9798 "glConsumeTextureCHROMIUM", this, texture, definition.release())) {
9819 SetGLError(GL_INVALID_OPERATION, 9799 SetGLError(GL_INVALID_OPERATION,
9820 "glConsumeTextureCHROMIUM", "invalid texture"); 9800 "glConsumeTextureCHROMIUM", "invalid texture");
9821 return; 9801 return;
9822 } 9802 }
9823 9803
9824 glBindTexture(info->target(), info->service_id()); 9804 glBindTexture(texture->target(), texture->service_id());
9825 } 9805 }
9826 9806
9827 void GLES2DecoderImpl::DoInsertEventMarkerEXT( 9807 void GLES2DecoderImpl::DoInsertEventMarkerEXT(
9828 GLsizei length, const GLchar* marker) { 9808 GLsizei length, const GLchar* marker) {
9829 if (!marker) { 9809 if (!marker) {
9830 marker = ""; 9810 marker = "";
9831 } 9811 }
9832 debug_marker_manager_.SetMarker( 9812 debug_marker_manager_.SetMarker(
9833 length ? std::string(marker, length) : std::string(marker)); 9813 length ? std::string(marker, length) : std::string(marker));
9834 } 9814 }
(...skipping 17 matching lines...) Expand all
9852 if (target != GL_TEXTURE_2D) { 9832 if (target != GL_TEXTURE_2D) {
9853 // This might be supported in the future. 9833 // This might be supported in the future.
9854 SetGLError( 9834 SetGLError(
9855 GL_INVALID_OPERATION, 9835 GL_INVALID_OPERATION,
9856 "glBindTexImage2DCHROMIUM", "requires TEXTURE_2D target"); 9836 "glBindTexImage2DCHROMIUM", "requires TEXTURE_2D target");
9857 return; 9837 return;
9858 } 9838 }
9859 9839
9860 // Default target might be conceptually valid, but disallow it to avoid 9840 // Default target might be conceptually valid, but disallow it to avoid
9861 // accidents. 9841 // accidents.
9862 Texture* info = GetTextureInfoForTargetUnlessDefault( 9842 Texture* texture = GetTextureInfoForTargetUnlessDefault(target);
9863 target); 9843 if (!texture) {
9864 if (!info) {
9865 SetGLError(GL_INVALID_OPERATION, 9844 SetGLError(GL_INVALID_OPERATION,
9866 "glBindTexImage2DCHROMIUM", "no texture bound"); 9845 "glBindTexImage2DCHROMIUM", "no texture bound");
9867 return; 9846 return;
9868 } 9847 }
9869 9848
9870 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); 9849 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id);
9871 if (!gl_image) { 9850 if (!gl_image) {
9872 SetGLError(GL_INVALID_OPERATION, 9851 SetGLError(GL_INVALID_OPERATION,
9873 "glBindTexImage2DCHROMIUM", 9852 "glBindTexImage2DCHROMIUM",
9874 "no image found with the given ID"); 9853 "no image found with the given ID");
9875 return; 9854 return;
9876 } 9855 }
9877 9856
9878 if (!gl_image->BindTexImage()) { 9857 if (!gl_image->BindTexImage()) {
9879 SetGLError(GL_INVALID_OPERATION, 9858 SetGLError(GL_INVALID_OPERATION,
9880 "glBindTexImage2DCHROMIUM", 9859 "glBindTexImage2DCHROMIUM",
9881 "fail to bind image with the given ID"); 9860 "fail to bind image with the given ID");
9882 return; 9861 return;
9883 } 9862 }
9884 9863
9885 gfx::Size size = gl_image->GetSize(); 9864 gfx::Size size = gl_image->GetSize();
9886 texture_manager()->SetLevelInfo( 9865 texture_manager()->SetLevelInfo(
9887 info, target, 0, GL_RGBA, size.width(), size.height(), 1, 0, 9866 texture, target, 0, GL_RGBA, size.width(), size.height(), 1, 0,
9888 GL_RGBA, GL_UNSIGNED_BYTE, true); 9867 GL_RGBA, GL_UNSIGNED_BYTE, true);
9889 texture_manager()->SetLevelImage(info, target, 0, gl_image); 9868 texture_manager()->SetLevelImage(texture, target, 0, gl_image);
9890 } 9869 }
9891 9870
9892 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( 9871 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM(
9893 GLenum target, GLint image_id) { 9872 GLenum target, GLint image_id) {
9894 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); 9873 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM");
9895 if (target != GL_TEXTURE_2D) { 9874 if (target != GL_TEXTURE_2D) {
9896 // This might be supported in the future. 9875 // This might be supported in the future.
9897 SetGLError( 9876 SetGLError(
9898 GL_INVALID_OPERATION, 9877 GL_INVALID_OPERATION,
9899 "glReleaseTexImage2DCHROMIUM", "requires TEXTURE_2D target"); 9878 "glReleaseTexImage2DCHROMIUM", "requires TEXTURE_2D target");
9900 return; 9879 return;
9901 } 9880 }
9902 9881
9903 // Default target might be conceptually valid, but disallow it to avoid 9882 // Default target might be conceptually valid, but disallow it to avoid
9904 // accidents. 9883 // accidents.
9905 Texture* info = GetTextureInfoForTargetUnlessDefault( 9884 Texture* texture = GetTextureInfoForTargetUnlessDefault(target);
9906 target); 9885 if (!texture) {
9907 if (!info) {
9908 SetGLError(GL_INVALID_OPERATION, 9886 SetGLError(GL_INVALID_OPERATION,
9909 "glReleaseTexImage2DCHROMIUM", "no texture bound"); 9887 "glReleaseTexImage2DCHROMIUM", "no texture bound");
9910 return; 9888 return;
9911 } 9889 }
9912 9890
9913 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); 9891 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id);
9914 if (!gl_image) { 9892 if (!gl_image) {
9915 SetGLError(GL_INVALID_OPERATION, 9893 SetGLError(GL_INVALID_OPERATION,
9916 "glReleaseTexImage2DCHROMIUM", 9894 "glReleaseTexImage2DCHROMIUM",
9917 "no image found with the given ID"); 9895 "no image found with the given ID");
9918 return; 9896 return;
9919 } 9897 }
9920 9898
9921 // Do nothing when image is not currently bound. 9899 // Do nothing when image is not currently bound.
9922 if (info->GetLevelImage(target, 0) != gl_image) 9900 if (texture->GetLevelImage(target, 0) != gl_image)
9923 return; 9901 return;
9924 9902
9925 gl_image->ReleaseTexImage(); 9903 gl_image->ReleaseTexImage();
9926 9904
9927 texture_manager()->SetLevelInfo( 9905 texture_manager()->SetLevelInfo(
9928 info, target, 0, GL_RGBA, 0, 0, 1, 0, 9906 texture, target, 0, GL_RGBA, 0, 0, 1, 0,
9929 GL_RGBA, GL_UNSIGNED_BYTE, false); 9907 GL_RGBA, GL_UNSIGNED_BYTE, false);
9930 } 9908 }
9931 9909
9932 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( 9910 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM(
9933 uint32 immediate_data_size, const cmds::TraceBeginCHROMIUM& c) { 9911 uint32 immediate_data_size, const cmds::TraceBeginCHROMIUM& c) {
9934 Bucket* bucket = GetBucket(c.bucket_id); 9912 Bucket* bucket = GetBucket(c.bucket_id);
9935 if (!bucket || bucket->size() == 0) { 9913 if (!bucket || bucket->size() == 0) {
9936 return error::kInvalidArguments; 9914 return error::kInvalidArguments;
9937 } 9915 }
9938 std::string command_name; 9916 std::string command_name;
(...skipping 14 matching lines...) Expand all
9953 SetGLError(GL_INVALID_OPERATION, 9931 SetGLError(GL_INVALID_OPERATION,
9954 "glTraceEndCHROMIUM", "no trace begin found"); 9932 "glTraceEndCHROMIUM", "no trace begin found");
9955 return; 9933 return;
9956 } 9934 }
9957 TRACE_EVENT_COPY_ASYNC_END0("gpu", gpu_tracer_->CurrentName().c_str(), this); 9935 TRACE_EVENT_COPY_ASYNC_END0("gpu", gpu_tracer_->CurrentName().c_str(), this);
9958 gpu_tracer_->End(); 9936 gpu_tracer_->End();
9959 } 9937 }
9960 9938
9961 bool GLES2DecoderImpl::ValidateAsyncTransfer( 9939 bool GLES2DecoderImpl::ValidateAsyncTransfer(
9962 const char* function_name, 9940 const char* function_name,
9963 Texture* info, 9941 Texture* texture,
9964 GLenum target, 9942 GLenum target,
9965 GLint level, 9943 GLint level,
9966 const void * data) { 9944 const void * data) {
9967 // We only support async uploads to 2D textures for now. 9945 // We only support async uploads to 2D textures for now.
9968 if (GL_TEXTURE_2D != target) { 9946 if (GL_TEXTURE_2D != target) {
9969 SetGLErrorInvalidEnum(function_name, target, "target"); 9947 SetGLErrorInvalidEnum(function_name, target, "target");
9970 return false; 9948 return false;
9971 } 9949 }
9972 // We only support uploads to level zero for now. 9950 // We only support uploads to level zero for now.
9973 if (level != 0) { 9951 if (level != 0) {
9974 SetGLError(GL_INVALID_VALUE, function_name, "level != 0"); 9952 SetGLError(GL_INVALID_VALUE, function_name, "level != 0");
9975 return false; 9953 return false;
9976 } 9954 }
9977 // A transfer buffer must be bound, even for asyncTexImage2D. 9955 // A transfer buffer must be bound, even for asyncTexImage2D.
9978 if (data == NULL) { 9956 if (data == NULL) {
9979 SetGLError(GL_INVALID_OPERATION, function_name, "buffer == 0"); 9957 SetGLError(GL_INVALID_OPERATION, function_name, "buffer == 0");
9980 return false; 9958 return false;
9981 } 9959 }
9982 // We only support one async transfer in progress. 9960 // We only support one async transfer in progress.
9983 if (!info || info->AsyncTransferIsInProgress()) { 9961 if (!texture || texture->AsyncTransferIsInProgress()) {
9984 SetGLError(GL_INVALID_OPERATION, 9962 SetGLError(GL_INVALID_OPERATION,
9985 function_name, "transfer already in progress"); 9963 function_name, "transfer already in progress");
9986 return false; 9964 return false;
9987 } 9965 }
9988 return true; 9966 return true;
9989 } 9967 }
9990 9968
9991 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM( 9969 error::Error GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM(
9992 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) { 9970 uint32 immediate_data_size, const cmds::AsyncTexImage2DCHROMIUM& c) {
9993 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM"); 9971 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexImage2DCHROMIUM");
(...skipping 26 matching lines...) Expand all
10020 } 9998 }
10021 9999
10022 // All the normal glTexSubImage2D validation. 10000 // All the normal glTexSubImage2D validation.
10023 if (!ValidateTexImage2D( 10001 if (!ValidateTexImage2D(
10024 "glAsyncTexImage2DCHROMIUM", target, level, internal_format, 10002 "glAsyncTexImage2DCHROMIUM", target, level, internal_format,
10025 width, height, border, format, type, pixels, pixels_size)) { 10003 width, height, border, format, type, pixels, pixels_size)) {
10026 return error::kNoError; 10004 return error::kNoError;
10027 } 10005 }
10028 10006
10029 // Extra async validation. 10007 // Extra async validation.
10030 Texture* info = GetTextureInfoForTarget(target); 10008 Texture* texture = GetTextureInfoForTarget(target);
10031 if (!ValidateAsyncTransfer( 10009 if (!ValidateAsyncTransfer(
10032 "glAsyncTexImage2DCHROMIUM", info, target, level, pixels)) 10010 "glAsyncTexImage2DCHROMIUM", texture, target, level, pixels))
10033 return error::kNoError; 10011 return error::kNoError;
10034 10012
10035 // Don't allow async redefinition of a textures. 10013 // Don't allow async redefinition of a textures.
10036 if (info->IsDefined()) { 10014 if (texture->IsDefined()) {
10037 SetGLError(GL_INVALID_OPERATION, 10015 SetGLError(GL_INVALID_OPERATION,
10038 "glAsyncTexImage2DCHROMIUM", "already defined"); 10016 "glAsyncTexImage2DCHROMIUM", "already defined");
10039 return error::kNoError; 10017 return error::kNoError;
10040 } 10018 }
10041 10019
10042 if (!EnsureGPUMemoryAvailable(pixels_size)) { 10020 if (!EnsureGPUMemoryAvailable(pixels_size)) {
10043 SetGLError(GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory"); 10021 SetGLError(GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory");
10044 return error::kNoError; 10022 return error::kNoError;
10045 } 10023 }
10046 10024
10047 // We know the memory/size is safe, so get the real shared memory since 10025 // We know the memory/size is safe, so get the real shared memory since
10048 // it might need to be duped to prevent use-after-free of the memory. 10026 // it might need to be duped to prevent use-after-free of the memory.
10049 gpu::Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id); 10027 gpu::Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id);
10050 base::SharedMemory* shared_memory = buffer.shared_memory; 10028 base::SharedMemory* shared_memory = buffer.shared_memory;
10051 uint32 shm_size = buffer.size; 10029 uint32 shm_size = buffer.size;
10052 uint32 shm_data_offset = c.pixels_shm_offset; 10030 uint32 shm_data_offset = c.pixels_shm_offset;
10053 uint32 shm_data_size = pixels_size; 10031 uint32 shm_data_size = pixels_size;
10054 10032
10055 // Set up the async state if needed, and make the texture 10033 // Set up the async state if needed, and make the texture
10056 // immutable so the async state stays valid. The level info 10034 // immutable so the async state stays valid. The level texture
10057 // is set up lazily when the transfer completes. 10035 // is set up lazily when the transfer completes.
10058 DCHECK(!info->GetAsyncTransferState()); 10036 DCHECK(!texture->GetAsyncTransferState());
10059 info->SetAsyncTransferState( 10037 texture->SetAsyncTransferState(
10060 async_pixel_transfer_delegate_-> 10038 async_pixel_transfer_delegate_->
10061 CreatePixelTransferState(info->service_id())); 10039 CreatePixelTransferState(texture->service_id()));
10062 info->SetImmutable(true); 10040 texture->SetImmutable(true);
10063 10041
10064 // Issue the async call and set up the texture. 10042 // Issue the async call and set up the texture.
10065 GLenum gl_internal_format = 10043 GLenum gl_internal_format =
10066 GetTexInternalFormat(internal_format, format, type); 10044 GetTexInternalFormat(internal_format, format, type);
10067 gfx::AsyncTexImage2DParams tex_params = {target, level, gl_internal_format, 10045 gfx::AsyncTexImage2DParams tex_params = {target, level, gl_internal_format,
10068 width, height, border, format, type}; 10046 width, height, border, format, type};
10069 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size, 10047 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size,
10070 shm_data_offset, shm_data_size}; 10048 shm_data_offset, shm_data_size};
10071 10049
10072 // Add a pending transfer to the texture manager, which will bind the 10050 // Add a pending transfer to the texture manager, which will bind the
10073 // transfer data to the texture and set the level info at the same time, 10051 // transfer data to the texture and set the level texture at the same time,
10074 // after the the transfer is complete. 10052 // after the the transfer is complete.
10075 texture_manager()->AddPendingAsyncPixelTransfer( 10053 texture_manager()->AddPendingAsyncPixelTransfer(
10076 info->GetAsyncTransferState()->AsWeakPtr(), info); 10054 texture->GetAsyncTransferState()->AsWeakPtr(), texture);
10077 10055
10078 async_pixel_transfer_delegate_->AsyncTexImage2D( 10056 async_pixel_transfer_delegate_->AsyncTexImage2D(
10079 info->GetAsyncTransferState(), tex_params, mem_params); 10057 texture->GetAsyncTransferState(), tex_params, mem_params);
10080 return error::kNoError; 10058 return error::kNoError;
10081 } 10059 }
10082 10060
10083 error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM( 10061 error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM(
10084 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) { 10062 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) {
10085 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); 10063 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM");
10086 GLenum target = static_cast<GLenum>(c.target); 10064 GLenum target = static_cast<GLenum>(c.target);
10087 GLint level = static_cast<GLint>(c.level); 10065 GLint level = static_cast<GLint>(c.level);
10088 GLint xoffset = static_cast<GLint>(c.xoffset); 10066 GLint xoffset = static_cast<GLint>(c.xoffset);
10089 GLint yoffset = static_cast<GLint>(c.yoffset); 10067 GLint yoffset = static_cast<GLint>(c.yoffset);
(...skipping 14 matching lines...) Expand all
10104 c.data_shm_id, c.data_shm_offset, data_size); 10082 c.data_shm_id, c.data_shm_offset, data_size);
10105 10083
10106 // All the normal glTexSubImage2D validation. 10084 // All the normal glTexSubImage2D validation.
10107 error::Error error = error::kNoError; 10085 error::Error error = error::kNoError;
10108 if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2DCHROMIUM", 10086 if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2DCHROMIUM",
10109 target, level, xoffset, yoffset, width, height, format, type, pixels)) { 10087 target, level, xoffset, yoffset, width, height, format, type, pixels)) {
10110 return error; 10088 return error;
10111 } 10089 }
10112 10090
10113 // Extra async validation. 10091 // Extra async validation.
10114 Texture* info = GetTextureInfoForTarget(target); 10092 Texture* texture = GetTextureInfoForTarget(target);
10115 if (!ValidateAsyncTransfer( 10093 if (!ValidateAsyncTransfer(
10116 "glAsyncTexSubImage2DCHROMIUM", info, target, level, pixels)) 10094 "glAsyncTexSubImage2DCHROMIUM", texture, target, level, pixels))
10117 return error::kNoError; 10095 return error::kNoError;
10118 10096
10119 // Guarantee async textures are always 'cleared' as follows: 10097 // Guarantee async textures are always 'cleared' as follows:
10120 // - AsyncTexImage2D can not redefine an existing texture 10098 // - AsyncTexImage2D can not redefine an existing texture
10121 // - AsyncTexImage2D must initialize the entire image via non-null buffer. 10099 // - AsyncTexImage2D must initialize the entire image via non-null buffer.
10122 // - AsyncTexSubImage2D clears synchronously if not already cleared. 10100 // - AsyncTexSubImage2D clears synchronously if not already cleared.
10123 // - Textures become immutable after an async call. 10101 // - Textures become immutable after an async call.
10124 // This way we know in all cases that an async texture is always clear. 10102 // This way we know in all cases that an async texture is always clear.
10125 if (!info->SafeToRenderFrom()) { 10103 if (!texture->SafeToRenderFrom()) {
10126 if (!texture_manager()->ClearTextureLevel(this, info, target, level)) { 10104 if (!texture_manager()->ClearTextureLevel(this, texture, target, level)) {
10127 SetGLError(GL_OUT_OF_MEMORY, 10105 SetGLError(GL_OUT_OF_MEMORY,
10128 "glAsyncTexSubImage2DCHROMIUM", "dimensions too big"); 10106 "glAsyncTexSubImage2DCHROMIUM", "dimensions too big");
10129 return error::kNoError; 10107 return error::kNoError;
10130 } 10108 }
10131 } 10109 }
10132 10110
10133 // We know the memory/size is safe, so get the real shared memory since 10111 // We know the memory/size is safe, so get the real shared memory since
10134 // it might need to be duped to prevent use-after-free of the memory. 10112 // it might need to be duped to prevent use-after-free of the memory.
10135 gpu::Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id); 10113 gpu::Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id);
10136 base::SharedMemory* shared_memory = buffer.shared_memory; 10114 base::SharedMemory* shared_memory = buffer.shared_memory;
10137 uint32 shm_size = buffer.size; 10115 uint32 shm_size = buffer.size;
10138 uint32 shm_data_offset = c.data_shm_offset; 10116 uint32 shm_data_offset = c.data_shm_offset;
10139 uint32 shm_data_size = data_size; 10117 uint32 shm_data_size = data_size;
10140 10118
10141 if (!info->GetAsyncTransferState()) { 10119 if (!texture->GetAsyncTransferState()) {
10142 // Set up the async state if needed, and make the texture 10120 // Set up the async state if needed, and make the texture
10143 // immutable so the async state stays valid. 10121 // immutable so the async state stays valid.
10144 info->SetAsyncTransferState( 10122 texture->SetAsyncTransferState(
10145 async_pixel_transfer_delegate_-> 10123 async_pixel_transfer_delegate_->
10146 CreatePixelTransferState(info->service_id())); 10124 CreatePixelTransferState(texture->service_id()));
10147 info->SetImmutable(true); 10125 texture->SetImmutable(true);
10148 } 10126 }
10149 10127
10150 gfx::AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset, 10128 gfx::AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset,
10151 width, height, format, type}; 10129 width, height, format, type};
10152 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size, 10130 gfx::AsyncMemoryParams mem_params = {shared_memory, shm_size,
10153 shm_data_offset, shm_data_size}; 10131 shm_data_offset, shm_data_size};
10154 async_pixel_transfer_delegate_->AsyncTexSubImage2D( 10132 async_pixel_transfer_delegate_->AsyncTexSubImage2D(
10155 info->GetAsyncTransferState(), tex_params, mem_params); 10133 texture->GetAsyncTransferState(), tex_params, mem_params);
10156 return error::kNoError; 10134 return error::kNoError;
10157 } 10135 }
10158 10136
10159 error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM( 10137 error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM(
10160 uint32 immediate_data_size, const cmds::WaitAsyncTexImage2DCHROMIUM& c) { 10138 uint32 immediate_data_size, const cmds::WaitAsyncTexImage2DCHROMIUM& c) {
10161 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); 10139 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM");
10162 GLenum target = static_cast<GLenum>(c.target); 10140 GLenum target = static_cast<GLenum>(c.target);
10163 10141
10164 if (GL_TEXTURE_2D != target) { 10142 if (GL_TEXTURE_2D != target) {
10165 SetGLError(GL_INVALID_ENUM, "glWaitAsyncTexImage2DCHROMIUM", "target"); 10143 SetGLError(GL_INVALID_ENUM, "glWaitAsyncTexImage2DCHROMIUM", "target");
10166 return error::kNoError; 10144 return error::kNoError;
10167 } 10145 }
10168 Texture* info = GetTextureInfoForTarget(target); 10146 Texture* texture = GetTextureInfoForTarget(target);
10169 if (!info) { 10147 if (!texture) {
10170 SetGLError(GL_INVALID_OPERATION, 10148 SetGLError(GL_INVALID_OPERATION,
10171 "glWaitAsyncTexImage2DCHROMIUM", "unknown texture"); 10149 "glWaitAsyncTexImage2DCHROMIUM", "unknown texture");
10172 return error::kNoError; 10150 return error::kNoError;
10173 } 10151 }
10174 async_pixel_transfer_delegate_->WaitForTransferCompletion( 10152 async_pixel_transfer_delegate_->WaitForTransferCompletion(
10175 info->GetAsyncTransferState()); 10153 texture->GetAsyncTransferState());
10176 ProcessFinishedAsyncTransfers(); 10154 ProcessFinishedAsyncTransfers();
10177 return error::kNoError; 10155 return error::kNoError;
10178 } 10156 }
10179 10157
10180 // Include the auto-generated part of this file. We split this because it means 10158 // Include the auto-generated part of this file. We split this because it means
10181 // we can easily edit the non-auto generated parts right here in this file 10159 // we can easily edit the non-auto generated parts right here in this file
10182 // instead of having to edit some template or the code generator. 10160 // instead of having to edit some template or the code generator.
10183 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10161 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10184 10162
10185 } // namespace gles2 10163 } // namespace gles2
10186 } // namespace gpu 10164 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698