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

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

Issue 14844004: gpu: Refactor to support cross-channel shared textures (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix accidentally reverted behavior Created 7 years, 7 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 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 return tracker->EnsureGPUMemoryAvailable(estimated_size); 686 return tracker->EnsureGPUMemoryAvailable(estimated_size);
687 } 687 }
688 return true; 688 return true;
689 } 689 }
690 690
691 bool IsOffscreenBufferMultisampled() const { 691 bool IsOffscreenBufferMultisampled() const {
692 return offscreen_target_samples_ > 1; 692 return offscreen_target_samples_ > 1;
693 } 693 }
694 694
695 // Creates a Texture for the given texture. 695 // Creates a Texture for the given texture.
696 Texture* CreateTexture( 696 TextureRef* CreateTexture(
697 GLuint client_id, GLuint service_id) { 697 GLuint client_id, GLuint service_id) {
698 return texture_manager()->CreateTexture(client_id, service_id); 698 return texture_manager()->CreateTexture(client_id, service_id);
699 } 699 }
700 700
701 // Gets the texture info for the given texture. Returns NULL if none exists. 701 // Gets the texture info for the given texture. Returns NULL if none exists.
702 Texture* GetTexture(GLuint client_id) const { 702 TextureRef* GetTexture(GLuint client_id) const {
703 return texture_manager()->GetTexture(client_id); 703 return texture_manager()->GetTexture(client_id);
704 } 704 }
705 705
706 // Deletes the texture info for the given texture. 706 // Deletes the texture info for the given texture.
707 void RemoveTexture(GLuint client_id) { 707 void RemoveTexture(GLuint client_id) {
708 texture_manager()->RemoveTexture(client_id); 708 texture_manager()->RemoveTexture(client_id);
709 } 709 }
710 710
711 // Get the size (in pixels) of the currently bound frame buffer (either FBO 711 // Get the size (in pixels) of the currently bound frame buffer (either FBO
712 // or regular back buffer). 712 // or regular back buffer).
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 Buffer* GetBufferInfoForTarget(GLenum target) { 1369 Buffer* GetBufferInfoForTarget(GLenum target) {
1370 DCHECK(target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER); 1370 DCHECK(target == GL_ARRAY_BUFFER || target == GL_ELEMENT_ARRAY_BUFFER);
1371 if (target == GL_ARRAY_BUFFER) { 1371 if (target == GL_ARRAY_BUFFER) {
1372 return state_.bound_array_buffer; 1372 return state_.bound_array_buffer;
1373 } else { 1373 } else {
1374 return state_.vertex_attrib_manager->element_array_buffer(); 1374 return state_.vertex_attrib_manager->element_array_buffer();
1375 } 1375 }
1376 } 1376 }
1377 1377
1378 // Gets the texture id for a given target. 1378 // Gets the texture id for a given target.
1379 Texture* GetTextureInfoForTarget(GLenum target) { 1379 TextureRef* GetTextureInfoForTarget(GLenum target) {
1380 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; 1380 TextureUnit& unit = state_.texture_units[state_.active_texture_unit];
1381 Texture* texture = NULL; 1381 TextureRef* texture = NULL;
1382 switch (target) { 1382 switch (target) {
1383 case GL_TEXTURE_2D: 1383 case GL_TEXTURE_2D:
1384 texture = unit.bound_texture_2d; 1384 texture = unit.bound_texture_2d;
1385 break; 1385 break;
1386 case GL_TEXTURE_CUBE_MAP: 1386 case GL_TEXTURE_CUBE_MAP:
1387 case GL_TEXTURE_CUBE_MAP_POSITIVE_X: 1387 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1389 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 1389 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1390 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 1390 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1391 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 1391 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1392 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 1392 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1393 texture = unit.bound_texture_cube_map; 1393 texture = unit.bound_texture_cube_map;
1394 break; 1394 break;
1395 case GL_TEXTURE_EXTERNAL_OES: 1395 case GL_TEXTURE_EXTERNAL_OES:
1396 texture = unit.bound_texture_external_oes; 1396 texture = unit.bound_texture_external_oes;
1397 break; 1397 break;
1398 case GL_TEXTURE_RECTANGLE_ARB: 1398 case GL_TEXTURE_RECTANGLE_ARB:
1399 texture = unit.bound_texture_rectangle_arb; 1399 texture = unit.bound_texture_rectangle_arb;
1400 break; 1400 break;
1401 default: 1401 default:
1402 NOTREACHED(); 1402 NOTREACHED();
1403 return NULL; 1403 return NULL;
1404 } 1404 }
1405 return texture; 1405 return texture;
1406 } 1406 }
1407 1407
1408 Texture* GetTextureInfoForTargetUnlessDefault( 1408 TextureRef* GetTextureInfoForTargetUnlessDefault(
1409 GLenum target) { 1409 GLenum target) {
1410 Texture* texture = GetTextureInfoForTarget(target); 1410 TextureRef* texture = GetTextureInfoForTarget(target);
1411 if (!texture) 1411 if (!texture)
1412 return NULL; 1412 return NULL;
1413 if (texture == texture_manager()->GetDefaultTextureInfo(target)) 1413 if (texture == texture_manager()->GetDefaultTextureInfo(target))
1414 return NULL; 1414 return NULL;
1415 return texture; 1415 return texture;
1416 } 1416 }
1417 1417
1418 GLenum GetBindTargetForSamplerType(GLenum type) { 1418 GLenum GetBindTargetForSamplerType(GLenum type) {
1419 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE || 1419 DCHECK(type == GL_SAMPLER_2D || type == GL_SAMPLER_CUBE ||
1420 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB); 1420 type == GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_2D_RECT_ARB);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1607 scoped_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_; 1607 scoped_ptr<BackRenderbuffer> offscreen_target_stencil_render_buffer_;
1608 GLenum offscreen_target_color_format_; 1608 GLenum offscreen_target_color_format_;
1609 GLenum offscreen_target_depth_format_; 1609 GLenum offscreen_target_depth_format_;
1610 GLenum offscreen_target_stencil_format_; 1610 GLenum offscreen_target_stencil_format_;
1611 GLsizei offscreen_target_samples_; 1611 GLsizei offscreen_target_samples_;
1612 GLboolean offscreen_target_buffer_preserved_; 1612 GLboolean offscreen_target_buffer_preserved_;
1613 1613
1614 // The copy that is saved when SwapBuffers is called. 1614 // The copy that is saved when SwapBuffers is called.
1615 scoped_ptr<BackFramebuffer> offscreen_saved_frame_buffer_; 1615 scoped_ptr<BackFramebuffer> offscreen_saved_frame_buffer_;
1616 scoped_ptr<BackTexture> offscreen_saved_color_texture_; 1616 scoped_ptr<BackTexture> offscreen_saved_color_texture_;
1617 scoped_refptr<Texture> 1617 scoped_refptr<TextureRef>
1618 offscreen_saved_color_texture_info_; 1618 offscreen_saved_color_texture_info_;
1619 1619
1620 // The copy that is used as the destination for multi-sample resolves. 1620 // The copy that is used as the destination for multi-sample resolves.
1621 scoped_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_; 1621 scoped_ptr<BackFramebuffer> offscreen_resolved_frame_buffer_;
1622 scoped_ptr<BackTexture> offscreen_resolved_color_texture_; 1622 scoped_ptr<BackTexture> offscreen_resolved_color_texture_;
1623 GLenum offscreen_saved_color_format_; 1623 GLenum offscreen_saved_color_format_;
1624 1624
1625 scoped_ptr<QueryManager> query_manager_; 1625 scoped_ptr<QueryManager> query_manager_;
1626 1626
1627 scoped_ptr<VertexArrayManager> vertex_array_manager_; 1627 scoped_ptr<VertexArrayManager> vertex_array_manager_;
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
2227 glGenBuffersARB(1, &attrib_0_buffer_id_); 2227 glGenBuffersARB(1, &attrib_0_buffer_id_);
2228 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_); 2228 glBindBuffer(GL_ARRAY_BUFFER, attrib_0_buffer_id_);
2229 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL); 2229 glVertexAttribPointer(0, 1, GL_FLOAT, GL_FALSE, 0, NULL);
2230 glBindBuffer(GL_ARRAY_BUFFER, 0); 2230 glBindBuffer(GL_ARRAY_BUFFER, 0);
2231 glGenBuffersARB(1, &fixed_attrib_buffer_id_); 2231 glGenBuffersARB(1, &fixed_attrib_buffer_id_);
2232 2232
2233 state_.texture_units.resize(group_->max_texture_units()); 2233 state_.texture_units.resize(group_->max_texture_units());
2234 for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) { 2234 for (uint32 tt = 0; tt < state_.texture_units.size(); ++tt) {
2235 glActiveTexture(GL_TEXTURE0 + tt); 2235 glActiveTexture(GL_TEXTURE0 + tt);
2236 // We want the last bind to be 2D. 2236 // We want the last bind to be 2D.
2237 Texture* texture; 2237 TextureRef* ref;
2238 if (features().oes_egl_image_external) { 2238 if (features().oes_egl_image_external) {
2239 texture = texture_manager()->GetDefaultTextureInfo( 2239 ref = texture_manager()->GetDefaultTextureInfo(
2240 GL_TEXTURE_EXTERNAL_OES); 2240 GL_TEXTURE_EXTERNAL_OES);
2241 state_.texture_units[tt].bound_texture_external_oes = texture; 2241 state_.texture_units[tt].bound_texture_external_oes = ref;
2242 glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture->service_id()); 2242 glBindTexture(GL_TEXTURE_EXTERNAL_OES, ref->service_id());
2243 } 2243 }
2244 if (features().arb_texture_rectangle) { 2244 if (features().arb_texture_rectangle) {
2245 texture = texture_manager()->GetDefaultTextureInfo( 2245 ref = texture_manager()->GetDefaultTextureInfo(
2246 GL_TEXTURE_RECTANGLE_ARB); 2246 GL_TEXTURE_RECTANGLE_ARB);
2247 state_.texture_units[tt].bound_texture_rectangle_arb = texture; 2247 state_.texture_units[tt].bound_texture_rectangle_arb = ref;
2248 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture->service_id()); 2248 glBindTexture(GL_TEXTURE_RECTANGLE_ARB, ref->service_id());
2249 } 2249 }
2250 texture = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP); 2250 ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_CUBE_MAP);
2251 state_.texture_units[tt].bound_texture_cube_map = texture; 2251 state_.texture_units[tt].bound_texture_cube_map = ref;
2252 glBindTexture(GL_TEXTURE_CUBE_MAP, texture->service_id()); 2252 glBindTexture(GL_TEXTURE_CUBE_MAP, ref->service_id());
2253 texture = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D); 2253 ref = texture_manager()->GetDefaultTextureInfo(GL_TEXTURE_2D);
2254 state_.texture_units[tt].bound_texture_2d = texture; 2254 state_.texture_units[tt].bound_texture_2d = ref;
2255 glBindTexture(GL_TEXTURE_2D, texture->service_id()); 2255 glBindTexture(GL_TEXTURE_2D, ref->service_id());
2256 } 2256 }
2257 glActiveTexture(GL_TEXTURE0); 2257 glActiveTexture(GL_TEXTURE0);
2258 CHECK_GL_ERROR(); 2258 CHECK_GL_ERROR();
2259 2259
2260 ContextCreationAttribParser attrib_parser; 2260 ContextCreationAttribParser attrib_parser;
2261 if (!attrib_parser.Parse(attribs)) 2261 if (!attrib_parser.Parse(attribs))
2262 return false; 2262 return false;
2263 2263
2264 // These are NOT if the back buffer has these proprorties. They are 2264 // These are NOT if the back buffer has these proprorties. They are
2265 // if we want the command buffer to enforce them regardless of what 2265 // if we want the command buffer to enforce them regardless of what
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 RemoveRenderbuffer(client_ids[ii]); 2698 RemoveRenderbuffer(client_ids[ii]);
2699 } 2699 }
2700 } 2700 }
2701 } 2701 }
2702 2702
2703 void GLES2DecoderImpl::DeleteTexturesHelper( 2703 void GLES2DecoderImpl::DeleteTexturesHelper(
2704 GLsizei n, const GLuint* client_ids) { 2704 GLsizei n, const GLuint* client_ids) {
2705 bool supports_separate_framebuffer_binds = 2705 bool supports_separate_framebuffer_binds =
2706 features().chromium_framebuffer_multisample; 2706 features().chromium_framebuffer_multisample;
2707 for (GLsizei ii = 0; ii < n; ++ii) { 2707 for (GLsizei ii = 0; ii < n; ++ii) {
2708 Texture* texture = GetTexture(client_ids[ii]); 2708 TextureRef* texture_ref = GetTexture(client_ids[ii]);
2709 if (texture && !texture->IsDeleted()) { 2709 if (texture_ref) {
2710 Texture* texture = texture_ref->texture();
2710 if (texture->IsAttachedToFramebuffer()) { 2711 if (texture->IsAttachedToFramebuffer()) {
2711 clear_state_dirty_ = true; 2712 clear_state_dirty_ = true;
2712 } 2713 }
2713 // Unbind texture from texture units. 2714 // Unbind texture_ref from texture_ref units.
2714 for (size_t jj = 0; jj < state_.texture_units.size(); ++jj) { 2715 for (size_t jj = 0; jj < state_.texture_units.size(); ++jj) {
2715 state_.texture_units[jj].Unbind(texture); 2716 state_.texture_units[jj].Unbind(texture_ref);
2716 } 2717 }
2717 // Unbind from current framebuffers. 2718 // Unbind from current framebuffers.
2718 if (supports_separate_framebuffer_binds) { 2719 if (supports_separate_framebuffer_binds) {
2719 if (state_.bound_read_framebuffer) { 2720 if (state_.bound_read_framebuffer) {
2720 state_.bound_read_framebuffer->UnbindTexture( 2721 state_.bound_read_framebuffer->UnbindTexture(
2721 GL_READ_FRAMEBUFFER_EXT, texture); 2722 GL_READ_FRAMEBUFFER_EXT, texture_ref);
2722 } 2723 }
2723 if (state_.bound_draw_framebuffer) { 2724 if (state_.bound_draw_framebuffer) {
2724 state_.bound_draw_framebuffer->UnbindTexture( 2725 state_.bound_draw_framebuffer->UnbindTexture(
2725 GL_DRAW_FRAMEBUFFER_EXT, texture); 2726 GL_DRAW_FRAMEBUFFER_EXT, texture_ref);
2726 } 2727 }
2727 } else { 2728 } else {
2728 if (state_.bound_draw_framebuffer) { 2729 if (state_.bound_draw_framebuffer) {
2729 state_.bound_draw_framebuffer->UnbindTexture(GL_FRAMEBUFFER, texture); 2730 state_.bound_draw_framebuffer->UnbindTexture(GL_FRAMEBUFFER,
2731 texture_ref);
2730 } 2732 }
2731 } 2733 }
2732 GLuint service_id = texture->service_id(); 2734 GLuint service_id = texture->service_id();
2733 if (texture->IsStreamTexture() && stream_texture_manager_) { 2735 if (texture->IsStreamTexture() && stream_texture_manager_) {
2734 stream_texture_manager_->DestroyStreamTexture(service_id); 2736 stream_texture_manager_->DestroyStreamTexture(service_id);
2735 } 2737 }
2736 #if defined(OS_MACOSX) 2738 #if defined(OS_MACOSX)
2737 if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) { 2739 if (texture->target() == GL_TEXTURE_RECTANGLE_ARB) {
2738 ReleaseIOSurfaceForTexture(service_id); 2740 ReleaseIOSurfaceForTexture(service_id);
2739 } 2741 }
(...skipping 24 matching lines...) Expand all
2764 } 2766 }
2765 2767
2766 ProcessFinishedAsyncTransfers(); 2768 ProcessFinishedAsyncTransfers();
2767 if (workarounds().flush_on_context_switch) 2769 if (workarounds().flush_on_context_switch)
2768 glFlush(); 2770 glFlush();
2769 2771
2770 // Rebind the FBO if it was unbound by the context. 2772 // Rebind the FBO if it was unbound by the context.
2771 if (workarounds().unbind_fbo_on_context_switch) 2773 if (workarounds().unbind_fbo_on_context_switch)
2772 RestoreFramebufferBindings(); 2774 RestoreFramebufferBindings();
2773 2775
2776 clear_state_dirty_ = true;
2777
2774 return true; 2778 return true;
2775 } 2779 }
2776 2780
2777 void GLES2DecoderImpl::ProcessFinishedAsyncTransfers() { 2781 void GLES2DecoderImpl::ProcessFinishedAsyncTransfers() {
2778 if (engine() && query_manager_.get()) 2782 if (engine() && query_manager_.get())
2779 query_manager_->ProcessPendingTransferQueries(); 2783 query_manager_->ProcessPendingTransferQueries();
2780 2784
2781 // TODO(epenner): Is there a better place to do this? 2785 // TODO(epenner): Is there a better place to do this?
2782 // This needs to occur before we execute any batch of commands 2786 // This needs to occur before we execute any batch of commands
2783 // from the client, as the client may have recieved an async 2787 // from the client, as the client may have recieved an async
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
2965 } else { 2969 } else {
2966 return back_buffer_color_format_; 2970 return back_buffer_color_format_;
2967 } 2971 }
2968 } 2972 }
2969 2973
2970 void GLES2DecoderImpl::UpdateParentTextureInfo() { 2974 void GLES2DecoderImpl::UpdateParentTextureInfo() {
2971 if (parent_) { 2975 if (parent_) {
2972 // Update the info about the offscreen saved color texture in the parent. 2976 // Update the info about the offscreen saved color texture in the parent.
2973 // The reference to the parent is a weak pointer and will become null if the 2977 // The reference to the parent is a weak pointer and will become null if the
2974 // parent is later destroyed. 2978 // parent is later destroyed.
2979 GLenum target = offscreen_saved_color_texture_info_->texture()->target();
2975 TextureManager* parent_texture_manager = parent_->texture_manager(); 2980 TextureManager* parent_texture_manager = parent_->texture_manager();
2976 glBindTexture(offscreen_saved_color_texture_info_->target(), 2981 glBindTexture(target, offscreen_saved_color_texture_info_->service_id());
2977 offscreen_saved_color_texture_info_->service_id());
2978 parent_texture_manager->SetLevelInfo( 2982 parent_texture_manager->SetLevelInfo(
2979 offscreen_saved_color_texture_info_, 2983 offscreen_saved_color_texture_info_,
2980 GL_TEXTURE_2D, 2984 GL_TEXTURE_2D,
2981 0, // level 2985 0, // level
2982 GL_RGBA, 2986 GL_RGBA,
2983 offscreen_size_.width(), 2987 offscreen_size_.width(),
2984 offscreen_size_.height(), 2988 offscreen_size_.height(),
2985 1, // depth 2989 1, // depth
2986 0, // border 2990 0, // border
2987 GL_RGBA, 2991 GL_RGBA,
(...skipping 16 matching lines...) Expand all
3004 GetErrorState(), 3008 GetErrorState(),
3005 offscreen_saved_color_texture_info_, 3009 offscreen_saved_color_texture_info_,
3006 GL_TEXTURE_WRAP_S, 3010 GL_TEXTURE_WRAP_S,
3007 GL_CLAMP_TO_EDGE); 3011 GL_CLAMP_TO_EDGE);
3008 parent_texture_manager->SetParameter( 3012 parent_texture_manager->SetParameter(
3009 "UpdateParentTextureInfo", 3013 "UpdateParentTextureInfo",
3010 GetErrorState(), 3014 GetErrorState(),
3011 offscreen_saved_color_texture_info_, 3015 offscreen_saved_color_texture_info_,
3012 GL_TEXTURE_WRAP_T, 3016 GL_TEXTURE_WRAP_T,
3013 GL_CLAMP_TO_EDGE); 3017 GL_CLAMP_TO_EDGE);
3014 Texture* texture = GetTextureInfoForTarget( 3018 TextureRef* texture_ref = GetTextureInfoForTarget(target);
3015 offscreen_saved_color_texture_info_->target()); 3019 glBindTexture(target, texture_ref ? texture_ref->service_id() : 0);
3016 glBindTexture(offscreen_saved_color_texture_info_->target(),
3017 texture ? texture->service_id() : 0);
3018 } else { 3020 } else {
3019 offscreen_saved_color_texture_info_ = NULL; 3021 offscreen_saved_color_texture_info_ = NULL;
3020 } 3022 }
3021 } 3023 }
3022 3024
3023 void GLES2DecoderImpl::SetResizeCallback( 3025 void GLES2DecoderImpl::SetResizeCallback(
3024 const base::Callback<void(gfx::Size)>& callback) { 3026 const base::Callback<void(gfx::Size)>& callback) {
3025 resize_callback_ = callback; 3027 resize_callback_ = callback;
3026 } 3028 }
3027 3029
(...skipping 24 matching lines...) Expand all
3052 return async_pixel_transfer_delegate_.get(); 3054 return async_pixel_transfer_delegate_.get();
3053 } 3055 }
3054 3056
3055 void GLES2DecoderImpl::SetAsyncPixelTransferDelegate( 3057 void GLES2DecoderImpl::SetAsyncPixelTransferDelegate(
3056 AsyncPixelTransferDelegate* delegate) { 3058 AsyncPixelTransferDelegate* delegate) {
3057 async_pixel_transfer_delegate_ = make_scoped_ptr(delegate); 3059 async_pixel_transfer_delegate_ = make_scoped_ptr(delegate);
3058 } 3060 }
3059 3061
3060 bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id, 3062 bool GLES2DecoderImpl::GetServiceTextureId(uint32 client_texture_id,
3061 uint32* service_texture_id) { 3063 uint32* service_texture_id) {
3062 Texture* texture = texture_manager()->GetTexture(client_texture_id); 3064 TextureRef* texture_ref = texture_manager()->GetTexture(client_texture_id);
3063 if (texture) { 3065 if (texture_ref) {
3064 *service_texture_id = texture->service_id(); 3066 *service_texture_id = texture_ref->service_id();
3065 return true; 3067 return true;
3066 } 3068 }
3067 return false; 3069 return false;
3068 } 3070 }
3069 3071
3070 uint32 GLES2DecoderImpl::GetTextureUploadCount() { 3072 uint32 GLES2DecoderImpl::GetTextureUploadCount() {
3071 return texture_upload_count_ + 3073 return texture_upload_count_ +
3072 async_pixel_transfer_delegate_->GetTextureUploadCount(); 3074 async_pixel_transfer_delegate_->GetTextureUploadCount();
3073 } 3075 }
3074 3076
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
3253 GLuint service_id = offscreen_saved_color_texture_->id(); 3255 GLuint service_id = offscreen_saved_color_texture_->id();
3254 3256
3255 // Replace texture info when ID is already in use by parent. 3257 // Replace texture info when ID is already in use by parent.
3256 if (new_parent_impl->texture_manager()->GetTexture( 3258 if (new_parent_impl->texture_manager()->GetTexture(
3257 new_parent_texture_id)) 3259 new_parent_texture_id))
3258 new_parent_impl->texture_manager()->RemoveTexture( 3260 new_parent_impl->texture_manager()->RemoveTexture(
3259 new_parent_texture_id); 3261 new_parent_texture_id);
3260 3262
3261 offscreen_saved_color_texture_info_ = 3263 offscreen_saved_color_texture_info_ =
3262 new_parent_impl->CreateTexture(new_parent_texture_id, service_id); 3264 new_parent_impl->CreateTexture(new_parent_texture_id, service_id);
3263 offscreen_saved_color_texture_info_->SetNotOwned(); 3265 offscreen_saved_color_texture_info_->texture()->SetNotOwned();
3264 new_parent_impl->texture_manager()-> 3266 new_parent_impl->texture_manager()->
3265 SetTarget(offscreen_saved_color_texture_info_, GL_TEXTURE_2D); 3267 SetTarget(offscreen_saved_color_texture_info_, GL_TEXTURE_2D);
3266 3268
3267 parent_ = base::AsWeakPtr<GLES2DecoderImpl>(new_parent_impl); 3269 parent_ = base::AsWeakPtr<GLES2DecoderImpl>(new_parent_impl);
3268 3270
3269 UpdateParentTextureInfo(); 3271 UpdateParentTextureInfo();
3270 } else { 3272 } else {
3271 parent_.reset(); 3273 parent_.reset();
3272 offscreen_saved_color_texture_info_ = NULL; 3274 offscreen_saved_color_texture_info_ = NULL;
3273 } 3275 }
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
3692 state_.bound_read_framebuffer->service_id() : 3694 state_.bound_read_framebuffer->service_id() :
3693 GetBackbufferServiceId(); 3695 GetBackbufferServiceId();
3694 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, service_id); 3696 glBindFramebufferEXT(GL_READ_FRAMEBUFFER, service_id);
3695 } 3697 }
3696 OnFboChanged(); 3698 OnFboChanged();
3697 } 3699 }
3698 3700
3699 void GLES2DecoderImpl::RestoreTextureState(unsigned service_id) const { 3701 void GLES2DecoderImpl::RestoreTextureState(unsigned service_id) const {
3700 GLuint client_id = 0; 3702 GLuint client_id = 0;
3701 if (texture_manager()->GetClientId(service_id, &client_id)) { 3703 if (texture_manager()->GetClientId(service_id, &client_id)) {
3702 Texture* texture = GetTexture(client_id); 3704 Texture* texture = GetTexture(client_id)->texture();
3703 GLenum target = texture->target(); 3705 GLenum target = texture->target();
3704 glBindTexture(target, service_id); 3706 glBindTexture(target, service_id);
3705 glTexParameteri( 3707 glTexParameteri(
3706 target, GL_TEXTURE_WRAP_S, texture->wrap_s()); 3708 target, GL_TEXTURE_WRAP_S, texture->wrap_s());
3707 glTexParameteri( 3709 glTexParameteri(
3708 target, GL_TEXTURE_WRAP_T, texture->wrap_t()); 3710 target, GL_TEXTURE_WRAP_T, texture->wrap_t());
3709 glTexParameteri( 3711 glTexParameteri(
3710 target, GL_TEXTURE_MIN_FILTER, texture->min_filter()); 3712 target, GL_TEXTURE_MIN_FILTER, texture->min_filter());
3711 glTexParameteri( 3713 glTexParameteri(
3712 target, GL_TEXTURE_MAG_FILTER, texture->mag_filter()); 3714 target, GL_TEXTURE_MAG_FILTER, texture->mag_filter());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
3805 service_id = renderbuffer->service_id(); 3807 service_id = renderbuffer->service_id();
3806 } 3808 }
3807 renderbuffer->MarkAsValid(); 3809 renderbuffer->MarkAsValid();
3808 } 3810 }
3809 LogClientServiceForInfo(renderbuffer, client_id, "glBindRenerbuffer"); 3811 LogClientServiceForInfo(renderbuffer, client_id, "glBindRenerbuffer");
3810 state_.bound_renderbuffer = renderbuffer; 3812 state_.bound_renderbuffer = renderbuffer;
3811 glBindRenderbufferEXT(target, service_id); 3813 glBindRenderbufferEXT(target, service_id);
3812 } 3814 }
3813 3815
3814 void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) { 3816 void GLES2DecoderImpl::DoBindTexture(GLenum target, GLuint client_id) {
3815 Texture* texture = NULL; 3817 TextureRef* texture_ref = NULL;
3816 GLuint service_id = 0; 3818 GLuint service_id = 0;
3817 if (client_id != 0) { 3819 if (client_id != 0) {
3818 texture = GetTexture(client_id); 3820 texture_ref = GetTexture(client_id);
3819 if (!texture) { 3821 if (!texture_ref) {
3820 if (!group_->bind_generates_resource()) { 3822 if (!group_->bind_generates_resource()) {
3821 LOG(ERROR) << "glBindTexture: id not generated by glGenTextures"; 3823 LOG(ERROR) << "glBindTexture: id not generated by glGenTextures";
3822 current_decoder_error_ = error::kGenericError; 3824 current_decoder_error_ = error::kGenericError;
3823 return; 3825 return;
3824 } 3826 }
3825 3827
3826 // It's a new id so make a texture texture for it. 3828 // It's a new id so make a texture texture for it.
3827 glGenTextures(1, &service_id); 3829 glGenTextures(1, &service_id);
3828 DCHECK_NE(0u, service_id); 3830 DCHECK_NE(0u, service_id);
3829 CreateTexture(client_id, service_id); 3831 CreateTexture(client_id, service_id);
3830 texture = GetTexture(client_id); 3832 texture_ref = GetTexture(client_id);
3831 IdAllocatorInterface* id_allocator = 3833 IdAllocatorInterface* id_allocator =
3832 group_->GetIdAllocator(id_namespaces::kTextures); 3834 group_->GetIdAllocator(id_namespaces::kTextures);
3833 id_allocator->MarkAsUsed(client_id); 3835 id_allocator->MarkAsUsed(client_id);
3834 } 3836 }
3835 } else { 3837 } else {
3836 texture = texture_manager()->GetDefaultTextureInfo(target); 3838 texture_ref = texture_manager()->GetDefaultTextureInfo(target);
3837 } 3839 }
3840 Texture* texture = texture_ref->texture();
3838 3841
3839 // Check the texture exists 3842 // Check the texture exists
3840 // Check that we are not trying to bind it to a different target. 3843 // Check that we are not trying to bind it to a different target.
3841 if (texture->target() != 0 && texture->target() != target) { 3844 if (texture->target() != 0 && texture->target() != target) {
3842 LOCAL_SET_GL_ERROR( 3845 LOCAL_SET_GL_ERROR(
3843 GL_INVALID_OPERATION, 3846 GL_INVALID_OPERATION,
3844 "glBindTexture", "texture bound to more than 1 target."); 3847 "glBindTexture", "texture bound to more than 1 target.");
3845 return; 3848 return;
3846 } 3849 }
3847 if (texture->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) { 3850 if (texture->IsStreamTexture() && target != GL_TEXTURE_EXTERNAL_OES) {
3848 LOCAL_SET_GL_ERROR( 3851 LOCAL_SET_GL_ERROR(
3849 GL_INVALID_OPERATION, 3852 GL_INVALID_OPERATION,
3850 "glBindTexture", "illegal target for stream texture."); 3853 "glBindTexture", "illegal target for stream texture.");
3851 return; 3854 return;
3852 } 3855 }
3853 LogClientServiceForInfo(texture, client_id, "glBindTexture"); 3856 LogClientServiceForInfo(texture, client_id, "glBindTexture");
3854 if (texture->target() == 0) { 3857 if (texture->target() == 0) {
3855 texture_manager()->SetTarget(texture, target); 3858 texture_manager()->SetTarget(texture_ref, target);
3856 } 3859 }
3857 glBindTexture(target, texture->service_id()); 3860 glBindTexture(target, texture->service_id());
3858 3861
3859 TextureUnit& unit = state_.texture_units[state_.active_texture_unit]; 3862 TextureUnit& unit = state_.texture_units[state_.active_texture_unit];
3860 unit.bind_target = target; 3863 unit.bind_target = target;
3861 switch (target) { 3864 switch (target) {
3862 case GL_TEXTURE_2D: 3865 case GL_TEXTURE_2D:
3863 unit.bound_texture_2d = texture; 3866 unit.bound_texture_2d = texture_ref;
3864 break; 3867 break;
3865 case GL_TEXTURE_CUBE_MAP: 3868 case GL_TEXTURE_CUBE_MAP:
3866 unit.bound_texture_cube_map = texture; 3869 unit.bound_texture_cube_map = texture_ref;
3867 break; 3870 break;
3868 case GL_TEXTURE_EXTERNAL_OES: 3871 case GL_TEXTURE_EXTERNAL_OES:
3869 unit.bound_texture_external_oes = texture; 3872 unit.bound_texture_external_oes = texture_ref;
3870 if (texture->IsStreamTexture()) { 3873 if (texture->IsStreamTexture()) {
3871 DCHECK(stream_texture_manager_); 3874 DCHECK(stream_texture_manager_);
3872 StreamTexture* stream_tex = 3875 StreamTexture* stream_tex =
3873 stream_texture_manager_->LookupStreamTexture(texture->service_id()); 3876 stream_texture_manager_->LookupStreamTexture(texture->service_id());
3874 if (stream_tex) 3877 if (stream_tex)
3875 stream_tex->Update(); 3878 stream_tex->Update();
3876 } 3879 }
3877 break; 3880 break;
3878 case GL_TEXTURE_RECTANGLE_ARB: 3881 case GL_TEXTURE_RECTANGLE_ARB:
3879 unit.bound_texture_rectangle_arb = texture; 3882 unit.bound_texture_rectangle_arb = texture_ref;
3880 break; 3883 break;
3881 default: 3884 default:
3882 NOTREACHED(); // Validation should prevent us getting here. 3885 NOTREACHED(); // Validation should prevent us getting here.
3883 break; 3886 break;
3884 } 3887 }
3885 } 3888 }
3886 3889
3887 void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) { 3890 void GLES2DecoderImpl::DoDisableVertexAttribArray(GLuint index) {
3888 if (state_.vertex_attrib_manager->Enable(index, false)) { 3891 if (state_.vertex_attrib_manager->Enable(index, false)) {
3889 if (index != 0 || 3892 if (index != 0 ||
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
3946 void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { 3949 void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) {
3947 if (state_.vertex_attrib_manager->Enable(index, true)) { 3950 if (state_.vertex_attrib_manager->Enable(index, true)) {
3948 glEnableVertexAttribArray(index); 3951 glEnableVertexAttribArray(index);
3949 } else { 3952 } else {
3950 LOCAL_SET_GL_ERROR( 3953 LOCAL_SET_GL_ERROR(
3951 GL_INVALID_VALUE, "glEnableVertexAttribArray", "index out of range"); 3954 GL_INVALID_VALUE, "glEnableVertexAttribArray", "index out of range");
3952 } 3955 }
3953 } 3956 }
3954 3957
3955 void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { 3958 void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) {
3956 Texture* texture = GetTextureInfoForTarget(target); 3959 TextureRef* texture_ref = GetTextureInfoForTarget(target);
3957 if (!texture || 3960 if (!texture_ref ||
3958 !texture_manager()->CanGenerateMipmaps(texture)) { 3961 !texture_manager()->CanGenerateMipmaps(texture_ref)) {
3959 LOCAL_SET_GL_ERROR( 3962 LOCAL_SET_GL_ERROR(
3960 GL_INVALID_OPERATION, "glGenerateMipmap", "Can not generate mips"); 3963 GL_INVALID_OPERATION, "glGenerateMipmap", "Can not generate mips");
3961 return; 3964 return;
3962 } 3965 }
3963 3966
3964 if (target == GL_TEXTURE_CUBE_MAP) { 3967 if (target == GL_TEXTURE_CUBE_MAP) {
3965 for (int i = 0; i < 6; ++i) { 3968 for (int i = 0; i < 6; ++i) {
3966 GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i; 3969 GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + i;
3967 if (!texture_manager()->ClearTextureLevel(this, texture, face, 0)) { 3970 if (!texture_manager()->ClearTextureLevel(this, texture_ref, face, 0)) {
3968 LOCAL_SET_GL_ERROR( 3971 LOCAL_SET_GL_ERROR(
3969 GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); 3972 GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big");
3970 return; 3973 return;
3971 } 3974 }
3972 } 3975 }
3973 } else { 3976 } else {
3974 if (!texture_manager()->ClearTextureLevel(this, texture, target, 0)) { 3977 if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, 0)) {
3975 LOCAL_SET_GL_ERROR( 3978 LOCAL_SET_GL_ERROR(
3976 GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big"); 3979 GL_OUT_OF_MEMORY, "glGenerateMipmap", "dimensions too big");
3977 return; 3980 return;
3978 } 3981 }
3979 } 3982 }
3980 3983
3981 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glGenerateMipmap"); 3984 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glGenerateMipmap");
3982 // Workaround for Mac driver bug. In the large scheme of things setting 3985 // Workaround for Mac driver bug. In the large scheme of things setting
3983 // glTexParamter twice for glGenerateMipmap is probably not a lage performance 3986 // glTexParamter twice for glGenerateMipmap is probably not a lage performance
3984 // hit so there's probably no need to make this conditional. The bug appears 3987 // hit so there's probably no need to make this conditional. The bug appears
3985 // to be that if the filtering mode is set to something that doesn't require 3988 // to be that if the filtering mode is set to something that doesn't require
3986 // mipmaps for rendering, or is never set to something other than the default, 3989 // mipmaps for rendering, or is never set to something other than the default,
3987 // then glGenerateMipmap misbehaves. 3990 // then glGenerateMipmap misbehaves.
3988 if (workarounds().set_texture_filter_before_generating_mipmap) { 3991 if (workarounds().set_texture_filter_before_generating_mipmap) {
3989 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); 3992 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
3990 } 3993 }
3991 glGenerateMipmapEXT(target); 3994 glGenerateMipmapEXT(target);
3992 if (workarounds().set_texture_filter_before_generating_mipmap) { 3995 if (workarounds().set_texture_filter_before_generating_mipmap) {
3993 glTexParameteri(target, GL_TEXTURE_MIN_FILTER, texture->min_filter()); 3996 glTexParameteri(target, GL_TEXTURE_MIN_FILTER,
3997 texture_ref->texture()->min_filter());
3994 } 3998 }
3995 GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap"); 3999 GLenum error = LOCAL_PEEK_GL_ERROR("glGenerateMipmap");
3996 if (error == GL_NO_ERROR) { 4000 if (error == GL_NO_ERROR) {
3997 texture_manager()->MarkMipmapsGenerated(texture); 4001 texture_manager()->MarkMipmapsGenerated(texture_ref);
3998 } 4002 }
3999 } 4003 }
4000 4004
4001 bool GLES2DecoderImpl::GetHelper( 4005 bool GLES2DecoderImpl::GetHelper(
4002 GLenum pname, GLint* params, GLsizei* num_written) { 4006 GLenum pname, GLint* params, GLsizei* num_written) {
4003 DCHECK(num_written); 4007 DCHECK(num_written);
4004 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) { 4008 if (gfx::GetGLImplementation() != gfx::kGLImplementationEGLGLES2) {
4005 switch (pname) { 4009 switch (pname) {
4006 case GL_IMPLEMENTATION_COLOR_READ_FORMAT: 4010 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
4007 *num_written = 1; 4011 *num_written = 1;
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
4876 GLenum target, GLenum attachment, GLenum textarget, 4880 GLenum target, GLenum attachment, GLenum textarget,
4877 GLuint client_texture_id, GLint level) { 4881 GLuint client_texture_id, GLint level) {
4878 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); 4882 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target);
4879 if (!framebuffer) { 4883 if (!framebuffer) {
4880 LOCAL_SET_GL_ERROR( 4884 LOCAL_SET_GL_ERROR(
4881 GL_INVALID_OPERATION, 4885 GL_INVALID_OPERATION,
4882 "glFramebufferTexture2D", "no framebuffer bound."); 4886 "glFramebufferTexture2D", "no framebuffer bound.");
4883 return; 4887 return;
4884 } 4888 }
4885 GLuint service_id = 0; 4889 GLuint service_id = 0;
4886 Texture* texture = NULL; 4890 TextureRef* texture_ref = NULL;
4887 if (client_texture_id) { 4891 if (client_texture_id) {
4888 texture = GetTexture(client_texture_id); 4892 texture_ref = GetTexture(client_texture_id);
4889 if (!texture) { 4893 if (!texture_ref) {
4890 LOCAL_SET_GL_ERROR( 4894 LOCAL_SET_GL_ERROR(
4891 GL_INVALID_OPERATION, 4895 GL_INVALID_OPERATION,
4892 "glFramebufferTexture2D", "unknown texture"); 4896 "glFramebufferTexture2D", "unknown texture_ref");
4893 return; 4897 return;
4894 } 4898 }
4895 service_id = texture->service_id(); 4899 service_id = texture_ref->service_id();
4896 } 4900 }
4897 4901
4898 if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) { 4902 if (!texture_manager()->ValidForTarget(textarget, level, 0, 0, 1)) {
4899 LOCAL_SET_GL_ERROR( 4903 LOCAL_SET_GL_ERROR(
4900 GL_INVALID_VALUE, 4904 GL_INVALID_VALUE,
4901 "glFramebufferTexture2D", "level out of range"); 4905 "glFramebufferTexture2D", "level out of range");
4902 return; 4906 return;
4903 } 4907 }
4904 4908
4905 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glFramebufferTexture2D"); 4909 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glFramebufferTexture2D");
4906 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level); 4910 glFramebufferTexture2DEXT(target, attachment, textarget, service_id, level);
4907 GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferTexture2D"); 4911 GLenum error = LOCAL_PEEK_GL_ERROR("glFramebufferTexture2D");
4908 if (error == GL_NO_ERROR) { 4912 if (error == GL_NO_ERROR) {
4909 framebuffer->AttachTexture(attachment, texture, textarget, level); 4913 framebuffer->AttachTexture(attachment, texture_ref, textarget, level);
4910 } 4914 }
4911 if (framebuffer == state_.bound_draw_framebuffer) { 4915 if (framebuffer == state_.bound_draw_framebuffer) {
4912 clear_state_dirty_ = true; 4916 clear_state_dirty_ = true;
4913 } 4917 }
4914 OnFboChanged(); 4918 OnFboChanged();
4915 } 4919 }
4916 4920
4917 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv( 4921 void GLES2DecoderImpl::DoGetFramebufferAttachmentParameteriv(
4918 GLenum target, GLenum attachment, GLenum pname, GLint* params) { 4922 GLenum target, GLenum attachment, GLenum pname, GLint* params) {
4919 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target); 4923 Framebuffer* framebuffer = GetFramebufferInfoForTarget(target);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
5140 if (workarounds().use_current_program_after_successful_link) { 5144 if (workarounds().use_current_program_after_successful_link) {
5141 glUseProgram(program->service_id()); 5145 glUseProgram(program->service_id());
5142 } 5146 }
5143 program_manager()->ClearUniforms(program); 5147 program_manager()->ClearUniforms(program);
5144 } 5148 }
5145 } 5149 }
5146 }; 5150 };
5147 5151
5148 void GLES2DecoderImpl::DoTexParameterf( 5152 void GLES2DecoderImpl::DoTexParameterf(
5149 GLenum target, GLenum pname, GLfloat param) { 5153 GLenum target, GLenum pname, GLfloat param) {
5150 Texture* texture = GetTextureInfoForTarget(target); 5154 TextureRef* texture = GetTextureInfoForTarget(target);
5151 if (!texture) { 5155 if (!texture) {
5152 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterf", "unknown texture"); 5156 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterf", "unknown texture");
5153 return; 5157 return;
5154 } 5158 }
5155 5159
5156 texture_manager()->SetParameter( 5160 texture_manager()->SetParameter(
5157 "glTexParameterf", GetErrorState(), texture, pname, 5161 "glTexParameterf", GetErrorState(), texture, pname,
5158 static_cast<GLint>(param)); 5162 static_cast<GLint>(param));
5159 } 5163 }
5160 5164
5161 void GLES2DecoderImpl::DoTexParameteri( 5165 void GLES2DecoderImpl::DoTexParameteri(
5162 GLenum target, GLenum pname, GLint param) { 5166 GLenum target, GLenum pname, GLint param) {
5163 Texture* texture = GetTextureInfoForTarget(target); 5167 TextureRef* texture = GetTextureInfoForTarget(target);
5164 if (!texture) { 5168 if (!texture) {
5165 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameteri", "unknown texture"); 5169 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameteri", "unknown texture");
5166 return; 5170 return;
5167 } 5171 }
5168 5172
5169 texture_manager()->SetParameter( 5173 texture_manager()->SetParameter(
5170 "glTexParameteri", GetErrorState(), texture, pname, param); 5174 "glTexParameteri", GetErrorState(), texture, pname, param);
5171 } 5175 }
5172 5176
5173 void GLES2DecoderImpl::DoTexParameterfv( 5177 void GLES2DecoderImpl::DoTexParameterfv(
5174 GLenum target, GLenum pname, const GLfloat* params) { 5178 GLenum target, GLenum pname, const GLfloat* params) {
5175 Texture* texture = GetTextureInfoForTarget(target); 5179 TextureRef* texture = GetTextureInfoForTarget(target);
5176 if (!texture) { 5180 if (!texture) {
5177 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture"); 5181 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, "glTexParameterfv", "unknown texture");
5178 return; 5182 return;
5179 } 5183 }
5180 5184
5181 texture_manager()->SetParameter( 5185 texture_manager()->SetParameter(
5182 "glTexParameterfv", GetErrorState(), texture, pname, 5186 "glTexParameterfv", GetErrorState(), texture, pname,
5183 static_cast<GLint>(params[0])); 5187 static_cast<GLint>(params[0]));
5184 } 5188 }
5185 5189
5186 void GLES2DecoderImpl::DoTexParameteriv( 5190 void GLES2DecoderImpl::DoTexParameteriv(
5187 GLenum target, GLenum pname, const GLint* params) { 5191 GLenum target, GLenum pname, const GLint* params) {
5188 Texture* texture = GetTextureInfoForTarget(target); 5192 TextureRef* texture = GetTextureInfoForTarget(target);
5189 if (!texture) { 5193 if (!texture) {
5190 LOCAL_SET_GL_ERROR( 5194 LOCAL_SET_GL_ERROR(
5191 GL_INVALID_VALUE, "glTexParameteriv", "unknown texture"); 5195 GL_INVALID_VALUE, "glTexParameteriv", "unknown texture");
5192 return; 5196 return;
5193 } 5197 }
5194 5198
5195 texture_manager()->SetParameter( 5199 texture_manager()->SetParameter(
5196 "glTexParameteriv", GetErrorState(), texture, pname, *params); 5200 "glTexParameteriv", GetErrorState(), texture, pname, *params);
5197 } 5201 }
5198 5202
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
5643 const Program::SamplerIndices& sampler_indices = 5647 const Program::SamplerIndices& sampler_indices =
5644 state_.current_program->sampler_indices(); 5648 state_.current_program->sampler_indices();
5645 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { 5649 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) {
5646 const Program::UniformInfo* uniform_info = 5650 const Program::UniformInfo* uniform_info =
5647 state_.current_program->GetUniformInfo(sampler_indices[ii]); 5651 state_.current_program->GetUniformInfo(sampler_indices[ii]);
5648 DCHECK(uniform_info); 5652 DCHECK(uniform_info);
5649 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { 5653 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) {
5650 GLuint texture_unit_index = uniform_info->texture_units[jj]; 5654 GLuint texture_unit_index = uniform_info->texture_units[jj];
5651 if (texture_unit_index < state_.texture_units.size()) { 5655 if (texture_unit_index < state_.texture_units.size()) {
5652 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; 5656 TextureUnit& texture_unit = state_.texture_units[texture_unit_index];
5653 Texture* texture = 5657 TextureRef* texture =
5654 texture_unit.GetInfoForSamplerType(uniform_info->type); 5658 texture_unit.GetInfoForSamplerType(uniform_info->type);
5655 if (!texture || !texture_manager()->CanRender(texture)) { 5659 if (!texture || !texture_manager()->CanRender(texture)) {
5656 textures_set = true; 5660 textures_set = true;
5657 glActiveTexture(GL_TEXTURE0 + texture_unit_index); 5661 glActiveTexture(GL_TEXTURE0 + texture_unit_index);
5658 glBindTexture( 5662 glBindTexture(
5659 GetBindTargetForSamplerType(uniform_info->type), 5663 GetBindTargetForSamplerType(uniform_info->type),
5660 texture_manager()->black_texture_id(uniform_info->type)); 5664 texture_manager()->black_texture_id(uniform_info->type));
5661 LOCAL_RENDER_WARNING( 5665 LOCAL_RENDER_WARNING(
5662 std::string("texture bound to texture unit ") + 5666 std::string("texture bound to texture unit ") +
5663 base::IntToString(texture_unit_index) + 5667 base::IntToString(texture_unit_index) +
(...skipping 13 matching lines...) Expand all
5677 const Program::SamplerIndices& sampler_indices = 5681 const Program::SamplerIndices& sampler_indices =
5678 state_.current_program->sampler_indices(); 5682 state_.current_program->sampler_indices();
5679 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { 5683 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) {
5680 const Program::UniformInfo* uniform_info = 5684 const Program::UniformInfo* uniform_info =
5681 state_.current_program->GetUniformInfo(sampler_indices[ii]); 5685 state_.current_program->GetUniformInfo(sampler_indices[ii]);
5682 DCHECK(uniform_info); 5686 DCHECK(uniform_info);
5683 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { 5687 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) {
5684 GLuint texture_unit_index = uniform_info->texture_units[jj]; 5688 GLuint texture_unit_index = uniform_info->texture_units[jj];
5685 if (texture_unit_index < state_.texture_units.size()) { 5689 if (texture_unit_index < state_.texture_units.size()) {
5686 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; 5690 TextureUnit& texture_unit = state_.texture_units[texture_unit_index];
5687 Texture* texture = uniform_info->type == GL_SAMPLER_2D ? 5691 TextureRef* texture_ref = uniform_info->type == GL_SAMPLER_2D ?
5688 texture_unit.bound_texture_2d : 5692 texture_unit.bound_texture_2d :
5689 texture_unit.bound_texture_cube_map; 5693 texture_unit.bound_texture_cube_map;
5690 if (!texture || !texture_manager()->CanRender(texture)) { 5694 if (!texture_ref || !texture_manager()->CanRender(texture_ref)) {
5691 glActiveTexture(GL_TEXTURE0 + texture_unit_index); 5695 glActiveTexture(GL_TEXTURE0 + texture_unit_index);
5692 // Get the texture info that was previously bound here. 5696 // Get the texture_ref info that was previously bound here.
5693 texture = texture_unit.bind_target == GL_TEXTURE_2D ? 5697 texture_ref = texture_unit.bind_target == GL_TEXTURE_2D ?
5694 texture_unit.bound_texture_2d : 5698 texture_unit.bound_texture_2d :
5695 texture_unit.bound_texture_cube_map; 5699 texture_unit.bound_texture_cube_map;
5696 glBindTexture(texture_unit.bind_target, 5700 glBindTexture(texture_unit.bind_target,
5697 texture ? texture->service_id() : 0); 5701 texture_ref ? texture_ref->service_id() : 0);
5698 } 5702 }
5699 } 5703 }
5700 } 5704 }
5701 } 5705 }
5702 // Set the active texture back to whatever the user had it as. 5706 // Set the active texture back to whatever the user had it as.
5703 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit); 5707 glActiveTexture(GL_TEXTURE0 + state_.active_texture_unit);
5704 } 5708 }
5705 5709
5706 bool GLES2DecoderImpl::ClearUnclearedTextures() { 5710 bool GLES2DecoderImpl::ClearUnclearedTextures() {
5707 // Only check if there are some uncleared textures. 5711 // Only check if there are some uncleared textures.
5708 if (!texture_manager()->HaveUnsafeTextures()) { 5712 if (!texture_manager()->HaveUnsafeTextures()) {
5709 return true; 5713 return true;
5710 } 5714 }
5711 5715
5712 // 1: Check all textures we are about to render with. 5716 // 1: Check all textures we are about to render with.
5713 if (state_.current_program) { 5717 if (state_.current_program) {
5714 const Program::SamplerIndices& sampler_indices = 5718 const Program::SamplerIndices& sampler_indices =
5715 state_.current_program->sampler_indices(); 5719 state_.current_program->sampler_indices();
5716 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) { 5720 for (size_t ii = 0; ii < sampler_indices.size(); ++ii) {
5717 const Program::UniformInfo* uniform_info = 5721 const Program::UniformInfo* uniform_info =
5718 state_.current_program->GetUniformInfo(sampler_indices[ii]); 5722 state_.current_program->GetUniformInfo(sampler_indices[ii]);
5719 DCHECK(uniform_info); 5723 DCHECK(uniform_info);
5720 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) { 5724 for (size_t jj = 0; jj < uniform_info->texture_units.size(); ++jj) {
5721 GLuint texture_unit_index = uniform_info->texture_units[jj]; 5725 GLuint texture_unit_index = uniform_info->texture_units[jj];
5722 if (texture_unit_index < state_.texture_units.size()) { 5726 if (texture_unit_index < state_.texture_units.size()) {
5723 TextureUnit& texture_unit = state_.texture_units[texture_unit_index]; 5727 TextureUnit& texture_unit = state_.texture_units[texture_unit_index];
5724 Texture* texture = 5728 TextureRef* texture_ref =
5725 texture_unit.GetInfoForSamplerType(uniform_info->type); 5729 texture_unit.GetInfoForSamplerType(uniform_info->type);
5726 if (texture && !texture->SafeToRenderFrom()) { 5730 if (texture_ref && !texture_ref->texture()->SafeToRenderFrom()) {
5727 if (!texture_manager()->ClearRenderableLevels(this, texture)) { 5731 if (!texture_manager()->ClearRenderableLevels(this, texture_ref)) {
5728 return false; 5732 return false;
5729 } 5733 }
5730 } 5734 }
5731 } 5735 }
5732 } 5736 }
5733 } 5737 }
5734 } 5738 }
5735 return true; 5739 return true;
5736 } 5740 }
5737 5741
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
6413 } 6417 }
6414 6418
6415 bool GLES2DecoderImpl::DoIsShader(GLuint client_id) { 6419 bool GLES2DecoderImpl::DoIsShader(GLuint client_id) {
6416 // IsShader is true for shaders as soon as they are created, until they 6420 // IsShader is true for shaders as soon as they are created, until they
6417 // are deleted and not attached to any programs. 6421 // are deleted and not attached to any programs.
6418 const Shader* shader = GetShader(client_id); 6422 const Shader* shader = GetShader(client_id);
6419 return shader != NULL && !shader->IsDeleted(); 6423 return shader != NULL && !shader->IsDeleted();
6420 } 6424 }
6421 6425
6422 bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) { 6426 bool GLES2DecoderImpl::DoIsTexture(GLuint client_id) {
6423 const Texture* texture = GetTexture(client_id); 6427 const TextureRef* texture_ref = GetTexture(client_id);
6424 return texture && texture->IsValid() && !texture->IsDeleted(); 6428 return texture_ref && texture_ref->texture()->IsValid();
6425 } 6429 }
6426 6430
6427 void GLES2DecoderImpl::DoAttachShader( 6431 void GLES2DecoderImpl::DoAttachShader(
6428 GLuint program_client_id, GLint shader_client_id) { 6432 GLuint program_client_id, GLint shader_client_id) {
6429 Program* program = GetProgramInfoNotShader( 6433 Program* program = GetProgramInfoNotShader(
6430 program_client_id, "glAttachShader"); 6434 program_client_id, "glAttachShader");
6431 if (!program) { 6435 if (!program) {
6432 return; 6436 return;
6433 } 6437 }
6434 Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glAttachShader"); 6438 Shader* shader = GetShaderInfoNotProgram(shader_client_id, "glAttachShader");
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
7331 while (y < height) { 7335 while (y < height) {
7332 GLint h = y + tile_height > height ? height - y : tile_height; 7336 GLint h = y + tile_height > height ? height - y : tile_height;
7333 if (is_texture_immutable || h != height) { 7337 if (is_texture_immutable || h != height) {
7334 glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get()); 7338 glTexSubImage2D(target, level, 0, y, width, h, format, type, zero.get());
7335 } else { 7339 } else {
7336 glTexImage2D( 7340 glTexImage2D(
7337 target, level, format, width, h, 0, format, type, zero.get()); 7341 target, level, format, width, h, 0, format, type, zero.get());
7338 } 7342 }
7339 y += tile_height; 7343 y += tile_height;
7340 } 7344 }
7341 Texture* texture = GetTextureInfoForTarget(bind_target); 7345 TextureRef* texture = GetTextureInfoForTarget(bind_target);
7342 glBindTexture(bind_target, texture ? texture->service_id() : 0); 7346 glBindTexture(bind_target, texture ? texture->service_id() : 0);
7343 return true; 7347 return true;
7344 } 7348 }
7345 7349
7346 namespace { 7350 namespace {
7347 7351
7348 const int kS3TCBlockWidth = 4; 7352 const int kS3TCBlockWidth = 4;
7349 const int kS3TCBlockHeight = 4; 7353 const int kS3TCBlockHeight = 4;
7350 const int kS3TCDXT1BlockSize = 8; 7354 const int kS3TCDXT1BlockSize = 8;
7351 const int kS3TCDXT3AndDXT5BlockSize = 16; 7355 const int kS3TCDXT3AndDXT5BlockSize = 16;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
7506 "glCompressedTexImage2D", internal_format, "internal_format"); 7510 "glCompressedTexImage2D", internal_format, "internal_format");
7507 return error::kNoError; 7511 return error::kNoError;
7508 } 7512 }
7509 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || 7513 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) ||
7510 border != 0) { 7514 border != 0) {
7511 LOCAL_SET_GL_ERROR( 7515 LOCAL_SET_GL_ERROR(
7512 GL_INVALID_VALUE, 7516 GL_INVALID_VALUE,
7513 "glCompressedTexImage2D", "dimensions out of range"); 7517 "glCompressedTexImage2D", "dimensions out of range");
7514 return error::kNoError; 7518 return error::kNoError;
7515 } 7519 }
7516 Texture* texture = GetTextureInfoForTarget(target); 7520 TextureRef* texture_ref = GetTextureInfoForTarget(target);
7517 if (!texture) { 7521 if (!texture_ref) {
7518 LOCAL_SET_GL_ERROR( 7522 LOCAL_SET_GL_ERROR(
7519 GL_INVALID_VALUE, 7523 GL_INVALID_VALUE,
7520 "glCompressedTexImage2D", "unknown texture target"); 7524 "glCompressedTexImage2D", "unknown texture target");
7521 return error::kNoError; 7525 return error::kNoError;
7522 } 7526 }
7527 Texture* texture = texture_ref->texture();
7523 if (texture->IsImmutable()) { 7528 if (texture->IsImmutable()) {
7524 LOCAL_SET_GL_ERROR( 7529 LOCAL_SET_GL_ERROR(
7525 GL_INVALID_OPERATION, 7530 GL_INVALID_OPERATION,
7526 "glCompressedTexImage2D", "texture is immutable"); 7531 "glCompressedTexImage2D", "texture is immutable");
7527 return error::kNoError; 7532 return error::kNoError;
7528 } 7533 }
7529 7534
7530 if (!ValidateCompressedTexDimensions( 7535 if (!ValidateCompressedTexDimensions(
7531 "glCompressedTexImage2D", level, width, height, internal_format) || 7536 "glCompressedTexImage2D", level, width, height, internal_format) ||
7532 !ValidateCompressedTexFuncData( 7537 !ValidateCompressedTexFuncData(
7533 "glCompressedTexImage2D", width, height, internal_format, image_size)) { 7538 "glCompressedTexImage2D", width, height, internal_format, image_size)) {
7534 return error::kNoError; 7539 return error::kNoError;
7535 } 7540 }
7536 7541
7537 if (!EnsureGPUMemoryAvailable(image_size)) { 7542 if (!EnsureGPUMemoryAvailable(image_size)) {
7538 LOCAL_SET_GL_ERROR( 7543 LOCAL_SET_GL_ERROR(
7539 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory"); 7544 GL_OUT_OF_MEMORY, "glCompressedTexImage2D", "out of memory");
7540 return error::kNoError; 7545 return error::kNoError;
7541 } 7546 }
7542 7547
7543 if (texture->IsAttachedToFramebuffer()) { 7548 if (texture->IsAttachedToFramebuffer()) {
7544 clear_state_dirty_ = true; 7549 clear_state_dirty_ = true;
7545 // TODO(gman): If textures tracked which framebuffers they were attached to
7546 // we could just mark those framebuffers as not complete.
7547 framebuffer_manager()->IncFramebufferStateChangeCount();
7548 } 7550 }
7549 7551
7550 scoped_ptr<int8[]> zero; 7552 scoped_ptr<int8[]> zero;
7551 if (!data) { 7553 if (!data) {
7552 zero.reset(new int8[image_size]); 7554 zero.reset(new int8[image_size]);
7553 memset(zero.get(), 0, image_size); 7555 memset(zero.get(), 0, image_size);
7554 data = zero.get(); 7556 data = zero.get();
7555 } 7557 }
7556 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D"); 7558 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCompressedTexImage2D");
7557 glCompressedTexImage2D( 7559 glCompressedTexImage2D(
7558 target, level, internal_format, width, height, border, image_size, data); 7560 target, level, internal_format, width, height, border, image_size, data);
7559 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D"); 7561 GLenum error = LOCAL_PEEK_GL_ERROR("glCompressedTexImage2D");
7560 if (error == GL_NO_ERROR) { 7562 if (error == GL_NO_ERROR) {
7561 texture_manager()->SetLevelInfo( 7563 texture_manager()->SetLevelInfo(
7562 texture, target, level, internal_format, width, height, 1, border, 0, 0, 7564 texture_ref, target, level, internal_format,
7563 true); 7565 width, height, 1, border, 0, 0, true);
7564 } 7566 }
7565 return error::kNoError; 7567 return error::kNoError;
7566 } 7568 }
7567 7569
7568 error::Error GLES2DecoderImpl::HandleCompressedTexImage2D( 7570 error::Error GLES2DecoderImpl::HandleCompressedTexImage2D(
7569 uint32 immediate_data_size, const cmds::CompressedTexImage2D& c) { 7571 uint32 immediate_data_size, const cmds::CompressedTexImage2D& c) {
7570 GLenum target = static_cast<GLenum>(c.target); 7572 GLenum target = static_cast<GLenum>(c.target);
7571 GLint level = static_cast<GLint>(c.level); 7573 GLint level = static_cast<GLint>(c.level);
7572 GLenum internal_format = static_cast<GLenum>(c.internalformat); 7574 GLenum internal_format = static_cast<GLenum>(c.internalformat);
7573 GLsizei width = static_cast<GLsizei>(c.width); 7575 GLsizei width = static_cast<GLsizei>(c.width);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
7746 GL_INVALID_VALUE, function_name, "dimensions out of range"); 7748 GL_INVALID_VALUE, function_name, "dimensions out of range");
7747 return false; 7749 return false;
7748 } 7750 }
7749 if ((GLES2Util::GetChannelsForFormat(format) & 7751 if ((GLES2Util::GetChannelsForFormat(format) &
7750 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && pixels) { 7752 (GLES2Util::kDepth | GLES2Util::kStencil)) != 0 && pixels) {
7751 LOCAL_SET_GL_ERROR( 7753 LOCAL_SET_GL_ERROR(
7752 GL_INVALID_OPERATION, 7754 GL_INVALID_OPERATION,
7753 function_name, "can not supply data for depth or stencil textures"); 7755 function_name, "can not supply data for depth or stencil textures");
7754 return false; 7756 return false;
7755 } 7757 }
7756 Texture* texture = GetTextureInfoForTarget(target); 7758 TextureRef* texture_ref = GetTextureInfoForTarget(target);
7757 if (!texture) { 7759 if (!texture_ref) {
7758 LOCAL_SET_GL_ERROR( 7760 LOCAL_SET_GL_ERROR(
7759 GL_INVALID_OPERATION, function_name, "unknown texture for target"); 7761 GL_INVALID_OPERATION, function_name, "unknown texture for target");
7760 return false; 7762 return false;
7761 } 7763 }
7762 if (texture->IsImmutable()) { 7764 if (texture_ref->texture()->IsImmutable()) {
7763 LOCAL_SET_GL_ERROR( 7765 LOCAL_SET_GL_ERROR(
7764 GL_INVALID_OPERATION, function_name, "texture is immutable"); 7766 GL_INVALID_OPERATION, function_name, "texture is immutable");
7765 return false; 7767 return false;
7766 } 7768 }
7767 return true; 7769 return true;
7768 } 7770 }
7769 7771
7770 void GLES2DecoderImpl::DoTexImage2D( 7772 void GLES2DecoderImpl::DoTexImage2D(
7771 GLenum target, 7773 GLenum target,
7772 GLint level, 7774 GLint level,
7773 GLenum internal_format, 7775 GLenum internal_format,
7774 GLsizei width, 7776 GLsizei width,
7775 GLsizei height, 7777 GLsizei height,
7776 GLint border, 7778 GLint border,
7777 GLenum format, 7779 GLenum format,
7778 GLenum type, 7780 GLenum type,
7779 const void* pixels, 7781 const void* pixels,
7780 uint32 pixels_size) { 7782 uint32 pixels_size) {
7781 if (!ValidateTexImage2D("glTexImage2D", target, level, internal_format, 7783 if (!ValidateTexImage2D("glTexImage2D", target, level, internal_format,
7782 width, height, border, format, type, pixels, pixels_size)) { 7784 width, height, border, format, type, pixels, pixels_size)) {
7783 return; 7785 return;
7784 } 7786 }
7785 7787
7786 if (!EnsureGPUMemoryAvailable(pixels_size)) { 7788 if (!EnsureGPUMemoryAvailable(pixels_size)) {
7787 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glTexImage2D", "out of memory"); 7789 LOCAL_SET_GL_ERROR(GL_OUT_OF_MEMORY, "glTexImage2D", "out of memory");
7788 return; 7790 return;
7789 } 7791 }
7790 7792
7791 Texture* texture = GetTextureInfoForTarget(target); 7793 TextureRef* texture_ref = GetTextureInfoForTarget(target);
7794 Texture* texture = texture_ref->texture();
7792 GLsizei tex_width = 0; 7795 GLsizei tex_width = 0;
7793 GLsizei tex_height = 0; 7796 GLsizei tex_height = 0;
7794 GLenum tex_type = 0; 7797 GLenum tex_type = 0;
7795 GLenum tex_format = 0; 7798 GLenum tex_format = 0;
7796 bool level_is_same = 7799 bool level_is_same =
7797 texture->GetLevelSize(target, level, &tex_width, &tex_height) && 7800 texture->GetLevelSize(target, level, &tex_width, &tex_height) &&
7798 texture->GetLevelType(target, level, &tex_type, &tex_format) && 7801 texture->GetLevelType(target, level, &tex_type, &tex_format) &&
7799 width == tex_width && height == tex_height && 7802 width == tex_width && height == tex_height &&
7800 type == tex_type && format == tex_format; 7803 type == tex_type && format == tex_format;
7801 7804
7802 if (level_is_same && !pixels) { 7805 if (level_is_same && !pixels) {
7803 // Just set the level texture but mark the texture as uncleared. 7806 // Just set the level texture but mark the texture as uncleared.
7804 texture_manager()->SetLevelInfo( 7807 texture_manager()->SetLevelInfo(
7805 texture, 7808 texture_ref,
7806 target, level, internal_format, width, height, 1, border, format, type, 7809 target, level, internal_format, width, height, 1, border, format, type,
7807 false); 7810 false);
7808 tex_image_2d_failed_ = false; 7811 tex_image_2d_failed_ = false;
7809 return; 7812 return;
7810 } 7813 }
7811 7814
7812 if (texture->IsAttachedToFramebuffer()) { 7815 if (texture->IsAttachedToFramebuffer()) {
7813 clear_state_dirty_ = true; 7816 clear_state_dirty_ = true;
7814 // TODO(gman): If textures tracked which framebuffers they were attached to
7815 // we could just mark those framebuffers as not complete.
7816 framebuffer_manager()->IncFramebufferStateChangeCount();
7817 } 7817 }
7818 7818
7819 if (!teximage2d_faster_than_texsubimage2d_ && level_is_same && pixels) { 7819 if (!teximage2d_faster_than_texsubimage2d_ && level_is_same && pixels) {
7820 glTexSubImage2D(target, level, 0, 0, width, height, format, type, pixels); 7820 glTexSubImage2D(target, level, 0, 0, width, height, format, type, pixels);
7821 texture_manager()->SetLevelCleared(texture, target, level, true); 7821 texture_manager()->SetLevelCleared(texture_ref, target, level, true);
7822 tex_image_2d_failed_ = false; 7822 tex_image_2d_failed_ = false;
7823 return; 7823 return;
7824 } 7824 }
7825 7825
7826 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexImage2D"); 7826 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexImage2D");
7827 glTexImage2D( 7827 glTexImage2D(
7828 target, level, internal_format, width, height, border, format, type, 7828 target, level, internal_format, width, height, border, format, type,
7829 pixels); 7829 pixels);
7830 GLenum error = LOCAL_PEEK_GL_ERROR("glTexImage2D"); 7830 GLenum error = LOCAL_PEEK_GL_ERROR("glTexImage2D");
7831 if (error == GL_NO_ERROR) { 7831 if (error == GL_NO_ERROR) {
7832 texture_manager()->SetLevelInfo( 7832 texture_manager()->SetLevelInfo(
7833 texture, 7833 texture_ref,
7834 target, level, internal_format, width, height, 1, border, format, type, 7834 target, level, internal_format, width, height, 1, border, format, type,
7835 pixels != NULL); 7835 pixels != NULL);
7836 tex_image_2d_failed_ = false; 7836 tex_image_2d_failed_ = false;
7837 } 7837 }
7838 return; 7838 return;
7839 } 7839 }
7840 7840
7841 error::Error GLES2DecoderImpl::HandleTexImage2D( 7841 error::Error GLES2DecoderImpl::HandleTexImage2D(
7842 uint32 immediate_data_size, const cmds::TexImage2D& c) { 7842 uint32 immediate_data_size, const cmds::TexImage2D& c) {
7843 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D"); 7843 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexImage2D");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
7903 void GLES2DecoderImpl::DoCompressedTexSubImage2D( 7903 void GLES2DecoderImpl::DoCompressedTexSubImage2D(
7904 GLenum target, 7904 GLenum target,
7905 GLint level, 7905 GLint level,
7906 GLint xoffset, 7906 GLint xoffset,
7907 GLint yoffset, 7907 GLint yoffset,
7908 GLsizei width, 7908 GLsizei width,
7909 GLsizei height, 7909 GLsizei height,
7910 GLenum format, 7910 GLenum format,
7911 GLsizei image_size, 7911 GLsizei image_size,
7912 const void * data) { 7912 const void * data) {
7913 Texture* texture = GetTextureInfoForTarget(target); 7913 TextureRef* texture_ref = GetTextureInfoForTarget(target);
7914 if (!texture) { 7914 if (!texture_ref) {
7915 LOCAL_SET_GL_ERROR( 7915 LOCAL_SET_GL_ERROR(
7916 GL_INVALID_OPERATION, 7916 GL_INVALID_OPERATION,
7917 "glCompressedTexSubImage2D", "unknown texture for target"); 7917 "glCompressedTexSubImage2D", "unknown texture for target");
7918 return; 7918 return;
7919 } 7919 }
7920 Texture* texture = texture_ref->texture();
7920 GLenum type = 0; 7921 GLenum type = 0;
7921 GLenum internal_format = 0; 7922 GLenum internal_format = 0;
7922 if (!texture->GetLevelType(target, level, &type, &internal_format)) { 7923 if (!texture->GetLevelType(target, level, &type, &internal_format)) {
7923 LOCAL_SET_GL_ERROR( 7924 LOCAL_SET_GL_ERROR(
7924 GL_INVALID_OPERATION, 7925 GL_INVALID_OPERATION,
7925 "glCompressedTexSubImage2D", "level does not exist."); 7926 "glCompressedTexSubImage2D", "level does not exist.");
7926 return; 7927 return;
7927 } 7928 }
7928 if (internal_format != format) { 7929 if (internal_format != format) {
7929 LOCAL_SET_GL_ERROR( 7930 LOCAL_SET_GL_ERROR(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
7975 void GLES2DecoderImpl::DoCopyTexImage2D( 7976 void GLES2DecoderImpl::DoCopyTexImage2D(
7976 GLenum target, 7977 GLenum target,
7977 GLint level, 7978 GLint level,
7978 GLenum internal_format, 7979 GLenum internal_format,
7979 GLint x, 7980 GLint x,
7980 GLint y, 7981 GLint y,
7981 GLsizei width, 7982 GLsizei width,
7982 GLsizei height, 7983 GLsizei height,
7983 GLint border) { 7984 GLint border) {
7984 DCHECK(!ShouldDeferReads()); 7985 DCHECK(!ShouldDeferReads());
7985 Texture* texture = GetTextureInfoForTarget(target); 7986 TextureRef* texture_ref = GetTextureInfoForTarget(target);
7986 if (!texture) { 7987 if (!texture_ref) {
7987 LOCAL_SET_GL_ERROR( 7988 LOCAL_SET_GL_ERROR(
7988 GL_INVALID_OPERATION, 7989 GL_INVALID_OPERATION,
7989 "glCopyTexImage2D", "unknown texture for target"); 7990 "glCopyTexImage2D", "unknown texture for target");
7990 return; 7991 return;
7991 } 7992 }
7993 Texture* texture = texture_ref->texture();
7992 if (texture->IsImmutable()) { 7994 if (texture->IsImmutable()) {
7993 LOCAL_SET_GL_ERROR( 7995 LOCAL_SET_GL_ERROR(
7994 GL_INVALID_OPERATION, "glCopyTexImage2D", "texture is immutable"); 7996 GL_INVALID_OPERATION, "glCopyTexImage2D", "texture is immutable");
7995 } 7997 }
7996 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) || 7998 if (!texture_manager()->ValidForTarget(target, level, width, height, 1) ||
7997 border != 0) { 7999 border != 0) {
7998 LOCAL_SET_GL_ERROR( 8000 LOCAL_SET_GL_ERROR(
7999 GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range"); 8001 GL_INVALID_VALUE, "glCopyTexImage2D", "dimensions out of range");
8000 return; 8002 return;
8001 } 8003 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
8039 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) { 8041 if (!CheckBoundFramebuffersValid("glCopyTexImage2D")) {
8040 return; 8042 return;
8041 } 8043 }
8042 8044
8043 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTexImage2D"); 8045 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glCopyTexImage2D");
8044 ScopedResolvedFrameBufferBinder binder(this, false, true); 8046 ScopedResolvedFrameBufferBinder binder(this, false, true);
8045 gfx::Size size = GetBoundReadFrameBufferSize(); 8047 gfx::Size size = GetBoundReadFrameBufferSize();
8046 8048
8047 if (texture->IsAttachedToFramebuffer()) { 8049 if (texture->IsAttachedToFramebuffer()) {
8048 clear_state_dirty_ = true; 8050 clear_state_dirty_ = true;
8049 // TODO(gman): If textures tracked which framebuffers they were attached to
8050 // we could just mark those framebuffers as not complete.
8051 framebuffer_manager()->IncFramebufferStateChangeCount();
8052 } 8051 }
8053 8052
8054 // Clip to size to source dimensions 8053 // Clip to size to source dimensions
8055 GLint copyX = 0; 8054 GLint copyX = 0;
8056 GLint copyY = 0; 8055 GLint copyY = 0;
8057 GLint copyWidth = 0; 8056 GLint copyWidth = 0;
8058 GLint copyHeight = 0; 8057 GLint copyHeight = 0;
8059 Clip(x, width, size.width(), &copyX, &copyWidth); 8058 Clip(x, width, size.width(), &copyX, &copyWidth);
8060 Clip(y, height, size.height(), &copyY, &copyHeight); 8059 Clip(y, height, size.height(), &copyY, &copyHeight);
8061 8060
(...skipping 19 matching lines...) Expand all
8081 destX, destY, copyX, copyY, 8080 destX, destY, copyX, copyY,
8082 copyWidth, copyHeight); 8081 copyWidth, copyHeight);
8083 } 8082 }
8084 } else { 8083 } else {
8085 glCopyTexImage2D(target, level, internal_format, 8084 glCopyTexImage2D(target, level, internal_format,
8086 copyX, copyY, copyWidth, copyHeight, border); 8085 copyX, copyY, copyWidth, copyHeight, border);
8087 } 8086 }
8088 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D"); 8087 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTexImage2D");
8089 if (error == GL_NO_ERROR) { 8088 if (error == GL_NO_ERROR) {
8090 texture_manager()->SetLevelInfo( 8089 texture_manager()->SetLevelInfo(
8091 texture, target, level, internal_format, width, height, 1, 8090 texture_ref, target, level, internal_format, width, height, 1,
8092 border, internal_format, GL_UNSIGNED_BYTE, true); 8091 border, internal_format, GL_UNSIGNED_BYTE, true);
8093 } 8092 }
8094 } 8093 }
8095 8094
8096 void GLES2DecoderImpl::DoCopyTexSubImage2D( 8095 void GLES2DecoderImpl::DoCopyTexSubImage2D(
8097 GLenum target, 8096 GLenum target,
8098 GLint level, 8097 GLint level,
8099 GLint xoffset, 8098 GLint xoffset,
8100 GLint yoffset, 8099 GLint yoffset,
8101 GLint x, 8100 GLint x,
8102 GLint y, 8101 GLint y,
8103 GLsizei width, 8102 GLsizei width,
8104 GLsizei height) { 8103 GLsizei height) {
8105 DCHECK(!ShouldDeferReads()); 8104 DCHECK(!ShouldDeferReads());
8106 Texture* texture = GetTextureInfoForTarget(target); 8105 TextureRef* texture_ref = GetTextureInfoForTarget(target);
8107 if (!texture) { 8106 if (!texture_ref) {
8108 LOCAL_SET_GL_ERROR( 8107 LOCAL_SET_GL_ERROR(
8109 GL_INVALID_OPERATION, 8108 GL_INVALID_OPERATION,
8110 "glCopyTexSubImage2D", "unknown texture for target"); 8109 "glCopyTexSubImage2D", "unknown texture for target");
8111 return; 8110 return;
8112 } 8111 }
8112 Texture* texture = texture_ref->texture();
8113 GLenum type = 0; 8113 GLenum type = 0;
8114 GLenum format = 0; 8114 GLenum format = 0;
8115 if (!texture->GetLevelType(target, level, &type, &format) || 8115 if (!texture->GetLevelType(target, level, &type, &format) ||
8116 !texture->ValidForTexture( 8116 !texture->ValidForTexture(
8117 target, level, xoffset, yoffset, width, height, format, type)) { 8117 target, level, xoffset, yoffset, width, height, format, type)) {
8118 LOCAL_SET_GL_ERROR( 8118 LOCAL_SET_GL_ERROR(
8119 GL_INVALID_VALUE, "glCopyTexSubImage2D", "bad dimensions."); 8119 GL_INVALID_VALUE, "glCopyTexSubImage2D", "bad dimensions.");
8120 return; 8120 return;
8121 } 8121 }
8122 if (texture->AsyncTransferIsInProgress()) { 8122 if (texture->AsyncTransferIsInProgress()) {
(...skipping 28 matching lines...) Expand all
8151 8151
8152 ScopedResolvedFrameBufferBinder binder(this, false, true); 8152 ScopedResolvedFrameBufferBinder binder(this, false, true);
8153 gfx::Size size = GetBoundReadFrameBufferSize(); 8153 gfx::Size size = GetBoundReadFrameBufferSize();
8154 GLint copyX = 0; 8154 GLint copyX = 0;
8155 GLint copyY = 0; 8155 GLint copyY = 0;
8156 GLint copyWidth = 0; 8156 GLint copyWidth = 0;
8157 GLint copyHeight = 0; 8157 GLint copyHeight = 0;
8158 Clip(x, width, size.width(), &copyX, &copyWidth); 8158 Clip(x, width, size.width(), &copyX, &copyWidth);
8159 Clip(y, height, size.height(), &copyY, &copyHeight); 8159 Clip(y, height, size.height(), &copyY, &copyHeight);
8160 8160
8161 if (!texture_manager()->ClearTextureLevel(this, texture, target, level)) { 8161 if (!texture_manager()->ClearTextureLevel(this, texture_ref, target, level)) {
8162 LOCAL_SET_GL_ERROR( 8162 LOCAL_SET_GL_ERROR(
8163 GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", "dimensions too big"); 8163 GL_OUT_OF_MEMORY, "glCopyTexSubImage2D", "dimensions too big");
8164 return; 8164 return;
8165 } 8165 }
8166 8166
8167 if (copyX != x || 8167 if (copyX != x ||
8168 copyY != y || 8168 copyY != y ||
8169 copyWidth != width || 8169 copyWidth != width ||
8170 copyHeight != height) { 8170 copyHeight != height) {
8171 // some part was clipped so clear the sub rect. 8171 // some part was clipped so clear the sub rect.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
8221 return false; 8221 return false;
8222 } 8222 }
8223 if (!validators_->texture_format.IsValid(format)) { 8223 if (!validators_->texture_format.IsValid(format)) {
8224 LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format"); 8224 LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, format, "format");
8225 return false; 8225 return false;
8226 } 8226 }
8227 if (!validators_->pixel_type.IsValid(type)) { 8227 if (!validators_->pixel_type.IsValid(type)) {
8228 LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, type, "type"); 8228 LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, type, "type");
8229 return false; 8229 return false;
8230 } 8230 }
8231 Texture* texture = GetTextureInfoForTarget(target); 8231 TextureRef* texture_ref = GetTextureInfoForTarget(target);
8232 if (!texture) { 8232 if (!texture_ref) {
8233 LOCAL_SET_GL_ERROR( 8233 LOCAL_SET_GL_ERROR(
8234 GL_INVALID_OPERATION, 8234 GL_INVALID_OPERATION,
8235 function_name, "unknown texture for target"); 8235 function_name, "unknown texture for target");
8236 return false; 8236 return false;
8237 } 8237 }
8238 Texture* texture = texture_ref->texture();
8238 GLenum current_type = 0; 8239 GLenum current_type = 0;
8239 GLenum internal_format = 0; 8240 GLenum internal_format = 0;
8240 if (!texture->GetLevelType(target, level, &current_type, &internal_format)) { 8241 if (!texture->GetLevelType(target, level, &current_type, &internal_format)) {
8241 LOCAL_SET_GL_ERROR( 8242 LOCAL_SET_GL_ERROR(
8242 GL_INVALID_OPERATION, function_name, "level does not exist."); 8243 GL_INVALID_OPERATION, function_name, "level does not exist.");
8243 return false; 8244 return false;
8244 } 8245 }
8245 if (format != internal_format) { 8246 if (format != internal_format) {
8246 LOCAL_SET_GL_ERROR( 8247 LOCAL_SET_GL_ERROR(
8247 GL_INVALID_OPERATION, 8248 GL_INVALID_OPERATION,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
8287 GLsizei width, 8288 GLsizei width,
8288 GLsizei height, 8289 GLsizei height,
8289 GLenum format, 8290 GLenum format,
8290 GLenum type, 8291 GLenum type,
8291 const void * data) { 8292 const void * data) {
8292 error::Error error = error::kNoError; 8293 error::Error error = error::kNoError;
8293 if (!ValidateTexSubImage2D(&error, "glTexSubImage2D", target, level, 8294 if (!ValidateTexSubImage2D(&error, "glTexSubImage2D", target, level,
8294 xoffset, yoffset, width, height, format, type, data)) { 8295 xoffset, yoffset, width, height, format, type, data)) {
8295 return error; 8296 return error;
8296 } 8297 }
8297 Texture* texture = GetTextureInfoForTarget(target); 8298 TextureRef* texture_ref = GetTextureInfoForTarget(target);
8299 Texture* texture = texture_ref->texture();
8298 GLsizei tex_width = 0; 8300 GLsizei tex_width = 0;
8299 GLsizei tex_height = 0; 8301 GLsizei tex_height = 0;
8300 bool ok = texture->GetLevelSize(target, level, &tex_width, &tex_height); 8302 bool ok = texture->GetLevelSize(target, level, &tex_width, &tex_height);
8301 DCHECK(ok); 8303 DCHECK(ok);
8302 if (xoffset != 0 || yoffset != 0 || 8304 if (xoffset != 0 || yoffset != 0 ||
8303 width != tex_width || height != tex_height) { 8305 width != tex_width || height != tex_height) {
8304 if (!texture_manager()->ClearTextureLevel(this, texture, target, level)) { 8306 if (!texture_manager()->ClearTextureLevel(this, texture_ref,
8307 target, level)) {
8305 LOCAL_SET_GL_ERROR( 8308 LOCAL_SET_GL_ERROR(
8306 GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big"); 8309 GL_OUT_OF_MEMORY, "glTexSubImage2D", "dimensions too big");
8307 return error::kNoError; 8310 return error::kNoError;
8308 } 8311 }
8309 ScopedTextureUploadTimer timer(this); 8312 ScopedTextureUploadTimer timer(this);
8310 glTexSubImage2D( 8313 glTexSubImage2D(
8311 target, level, xoffset, yoffset, width, height, format, type, data); 8314 target, level, xoffset, yoffset, width, height, format, type, data);
8312 return error::kNoError; 8315 return error::kNoError;
8313 } 8316 }
8314 8317
8315 if (teximage2d_faster_than_texsubimage2d_ && !texture->IsImmutable()) { 8318 if (teximage2d_faster_than_texsubimage2d_ && !texture->IsImmutable()) {
8316 ScopedTextureUploadTimer timer(this); 8319 ScopedTextureUploadTimer timer(this);
8317 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the 8320 // NOTE: In OpenGL ES 2.0 border is always zero and format is always the
8318 // same as internal_foramt. If that changes we'll need to look them up. 8321 // same as internal_foramt. If that changes we'll need to look them up.
8319 glTexImage2D( 8322 glTexImage2D(
8320 target, level, format, width, height, 0, format, type, data); 8323 target, level, format, width, height, 0, format, type, data);
8321 } else { 8324 } else {
8322 ScopedTextureUploadTimer timer(this); 8325 ScopedTextureUploadTimer timer(this);
8323 glTexSubImage2D( 8326 glTexSubImage2D(
8324 target, level, xoffset, yoffset, width, height, format, type, data); 8327 target, level, xoffset, yoffset, width, height, format, type, data);
8325 } 8328 }
8326 texture_manager()->SetLevelCleared(texture, target, level, true); 8329 texture_manager()->SetLevelCleared(texture_ref, target, level, true);
8327 return error::kNoError; 8330 return error::kNoError;
8328 } 8331 }
8329 8332
8330 error::Error GLES2DecoderImpl::HandleTexSubImage2D( 8333 error::Error GLES2DecoderImpl::HandleTexSubImage2D(
8331 uint32 immediate_data_size, const cmds::TexSubImage2D& c) { 8334 uint32 immediate_data_size, const cmds::TexSubImage2D& c) {
8332 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D"); 8335 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleTexSubImage2D");
8333 GLboolean internal = static_cast<GLboolean>(c.internal); 8336 GLboolean internal = static_cast<GLboolean>(c.internal);
8334 if (internal == GL_TRUE && tex_image_2d_failed_) 8337 if (internal == GL_TRUE && tex_image_2d_failed_)
8335 return error::kNoError; 8338 return error::kNoError;
8336 8339
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
8775 offscreen_target_frame_buffer_->id()); 8778 offscreen_target_frame_buffer_->id());
8776 8779
8777 if (offscreen_target_buffer_preserved_) { 8780 if (offscreen_target_buffer_preserved_) {
8778 // Copy the target frame buffer to the saved offscreen texture. 8781 // Copy the target frame buffer to the saved offscreen texture.
8779 offscreen_saved_color_texture_->Copy( 8782 offscreen_saved_color_texture_->Copy(
8780 offscreen_saved_color_texture_->size(), 8783 offscreen_saved_color_texture_->size(),
8781 offscreen_saved_color_format_); 8784 offscreen_saved_color_format_);
8782 } else { 8785 } else {
8783 // Flip the textures in the parent context via the texture manager. 8786 // Flip the textures in the parent context via the texture manager.
8784 if (!!offscreen_saved_color_texture_info_.get()) 8787 if (!!offscreen_saved_color_texture_info_.get())
8785 offscreen_saved_color_texture_info_-> 8788 offscreen_saved_color_texture_info_->texture()->
8786 SetServiceId(offscreen_target_color_texture_->id()); 8789 SetServiceId(offscreen_target_color_texture_->id());
8787 8790
8788 offscreen_saved_color_texture_.swap(offscreen_target_color_texture_); 8791 offscreen_saved_color_texture_.swap(offscreen_target_color_texture_);
8789 offscreen_target_frame_buffer_->AttachRenderTexture( 8792 offscreen_target_frame_buffer_->AttachRenderTexture(
8790 offscreen_target_color_texture_.get()); 8793 offscreen_target_color_texture_.get());
8791 } 8794 }
8792 8795
8793 // Ensure the side effects of the copy are visible to the parent 8796 // Ensure the side effects of the copy are visible to the parent
8794 // context. There is no need to do this for ANGLE because it uses a 8797 // context. There is no need to do this for ANGLE because it uses a
8795 // single D3D device for all contexts. 8798 // single D3D device for all contexts.
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
9332 } 9335 }
9333 9336
9334 uint32 client_id = c.client_id; 9337 uint32 client_id = c.client_id;
9335 typedef cmds::CreateStreamTextureCHROMIUM::Result Result; 9338 typedef cmds::CreateStreamTextureCHROMIUM::Result Result;
9336 Result* result = GetSharedMemoryAs<Result*>( 9339 Result* result = GetSharedMemoryAs<Result*>(
9337 c.result_shm_id, c.result_shm_offset, sizeof(*result)); 9340 c.result_shm_id, c.result_shm_offset, sizeof(*result));
9338 9341
9339 if (!result) 9342 if (!result)
9340 return error::kOutOfBounds; 9343 return error::kOutOfBounds;
9341 *result = GL_ZERO; 9344 *result = GL_ZERO;
9342 Texture* texture = texture_manager()->GetTexture(client_id); 9345 TextureRef* texture_ref = texture_manager()->GetTexture(client_id);
9343 if (!texture) { 9346 if (!texture_ref) {
9344 LOCAL_SET_GL_ERROR( 9347 LOCAL_SET_GL_ERROR(
9345 GL_INVALID_VALUE, 9348 GL_INVALID_VALUE,
9346 "glCreateStreamTextureCHROMIUM", "bad texture id."); 9349 "glCreateStreamTextureCHROMIUM", "bad texture id.");
9347 return error::kNoError; 9350 return error::kNoError;
9348 } 9351 }
9349 9352
9353 Texture* texture = texture_ref->texture();
9350 if (texture->IsStreamTexture()) { 9354 if (texture->IsStreamTexture()) {
9351 LOCAL_SET_GL_ERROR( 9355 LOCAL_SET_GL_ERROR(
9352 GL_INVALID_OPERATION, 9356 GL_INVALID_OPERATION,
9353 "glCreateStreamTextureCHROMIUM", "is already a stream texture."); 9357 "glCreateStreamTextureCHROMIUM", "is already a stream texture.");
9354 return error::kNoError; 9358 return error::kNoError;
9355 } 9359 }
9356 9360
9357 if (texture->target() && texture->target() != GL_TEXTURE_EXTERNAL_OES) { 9361 if (texture->target() && texture->target() != GL_TEXTURE_EXTERNAL_OES) {
9358 LOCAL_SET_GL_ERROR( 9362 LOCAL_SET_GL_ERROR(
9359 GL_INVALID_OPERATION, 9363 GL_INVALID_OPERATION,
9360 "glCreateStreamTextureCHROMIUM", 9364 "glCreateStreamTextureCHROMIUM",
9361 "is already bound to incompatible target."); 9365 "is already bound to incompatible target.");
9362 return error::kNoError; 9366 return error::kNoError;
9363 } 9367 }
9364 9368
9365 if (!stream_texture_manager_) 9369 if (!stream_texture_manager_)
9366 return error::kInvalidArguments; 9370 return error::kInvalidArguments;
9367 9371
9368 GLuint object_id = stream_texture_manager_->CreateStreamTexture( 9372 GLuint object_id = stream_texture_manager_->CreateStreamTexture(
9369 texture->service_id(), client_id); 9373 texture->service_id(), client_id);
9370 9374
9371 if (object_id) { 9375 if (object_id) {
9372 texture_manager()->SetStreamTexture(texture, true); 9376 texture_manager()->SetStreamTexture(texture_ref, true);
9373 } else { 9377 } else {
9374 LOCAL_SET_GL_ERROR( 9378 LOCAL_SET_GL_ERROR(
9375 GL_OUT_OF_MEMORY, 9379 GL_OUT_OF_MEMORY,
9376 "glCreateStreamTextureCHROMIUM", "failed to create platform texture."); 9380 "glCreateStreamTextureCHROMIUM", "failed to create platform texture.");
9377 } 9381 }
9378 9382
9379 *result = object_id; 9383 *result = object_id;
9380 return error::kNoError; 9384 return error::kNoError;
9381 } 9385 }
9382 9386
9383 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM( 9387 error::Error GLES2DecoderImpl::HandleDestroyStreamTextureCHROMIUM(
9384 uint32 immediate_data_size, 9388 uint32 immediate_data_size,
9385 const cmds::DestroyStreamTextureCHROMIUM& c) { 9389 const cmds::DestroyStreamTextureCHROMIUM& c) {
9386 GLuint client_id = c.texture; 9390 GLuint client_id = c.texture;
9387 Texture* texture = texture_manager()->GetTexture(client_id); 9391 TextureRef* texture_ref = texture_manager()->GetTexture(client_id);
9388 if (texture && texture->IsStreamTexture()) { 9392 if (texture_ref && texture_ref->texture()->IsStreamTexture()) {
9389 if (!stream_texture_manager_) 9393 if (!stream_texture_manager_)
9390 return error::kInvalidArguments; 9394 return error::kInvalidArguments;
9391 9395
9392 stream_texture_manager_->DestroyStreamTexture(texture->service_id()); 9396 stream_texture_manager_->DestroyStreamTexture(texture_ref->service_id());
9393 texture_manager()->SetStreamTexture(texture, false); 9397 texture_manager()->SetStreamTexture(texture_ref, false);
9394 } else { 9398 } else {
9395 LOCAL_SET_GL_ERROR( 9399 LOCAL_SET_GL_ERROR(
9396 GL_INVALID_VALUE, 9400 GL_INVALID_VALUE,
9397 "glDestroyStreamTextureCHROMIUM", "bad texture id."); 9401 "glDestroyStreamTextureCHROMIUM", "bad texture id.");
9398 } 9402 }
9399 9403
9400 return error::kNoError; 9404 return error::kNoError;
9401 } 9405 }
9402 9406
9403 #if defined(OS_MACOSX) 9407 #if defined(OS_MACOSX)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
9439 // know what's going on. 9443 // know what's going on.
9440 LOCAL_SET_GL_ERROR( 9444 LOCAL_SET_GL_ERROR(
9441 GL_INVALID_OPERATION, 9445 GL_INVALID_OPERATION,
9442 "glTexImageIOSurface2DCHROMIUM", 9446 "glTexImageIOSurface2DCHROMIUM",
9443 "requires TEXTURE_RECTANGLE_ARB target"); 9447 "requires TEXTURE_RECTANGLE_ARB target");
9444 return; 9448 return;
9445 } 9449 }
9446 9450
9447 // Default target might be conceptually valid, but disallow it to avoid 9451 // Default target might be conceptually valid, but disallow it to avoid
9448 // accidents. 9452 // accidents.
9449 Texture* texture = GetTextureInfoForTargetUnlessDefault(target); 9453 TextureRef* texture_ref = GetTextureInfoForTargetUnlessDefault(target);
9450 if (!texture) { 9454 if (!texture_ref) {
9451 LOCAL_SET_GL_ERROR( 9455 LOCAL_SET_GL_ERROR(
9452 GL_INVALID_OPERATION, 9456 GL_INVALID_OPERATION,
9453 "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound"); 9457 "glTexImageIOSurface2DCHROMIUM", "no rectangle texture bound");
9454 return; 9458 return;
9455 } 9459 }
9456 9460
9457 // Look up the new IOSurface. Note that because of asynchrony 9461 // Look up the new IOSurface. Note that because of asynchrony
9458 // between processes this might fail; during live resizing the 9462 // between processes this might fail; during live resizing the
9459 // plugin process might allocate and release an IOSurface before 9463 // plugin process might allocate and release an IOSurface before
9460 // this process gets a chance to look it up. Hold on to any old 9464 // this process gets a chance to look it up. Hold on to any old
9461 // IOSurface in this case. 9465 // IOSurface in this case.
9462 CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id); 9466 CFTypeRef surface = surface_support->IOSurfaceLookup(io_surface_id);
9463 if (!surface) { 9467 if (!surface) {
9464 LOCAL_SET_GL_ERROR( 9468 LOCAL_SET_GL_ERROR(
9465 GL_INVALID_OPERATION, 9469 GL_INVALID_OPERATION,
9466 "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID"); 9470 "glTexImageIOSurface2DCHROMIUM", "no IOSurface with the given ID");
9467 return; 9471 return;
9468 } 9472 }
9469 9473
9470 // Release any IOSurface previously bound to this texture. 9474 // Release any IOSurface previously bound to this texture.
9471 ReleaseIOSurfaceForTexture(texture->service_id()); 9475 ReleaseIOSurfaceForTexture(texture_ref->service_id());
9472 9476
9473 // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails. 9477 // Make sure we release the IOSurface even if CGLTexImageIOSurface2D fails.
9474 texture_to_io_surface_map_.insert( 9478 texture_to_io_surface_map_.insert(
9475 std::make_pair(texture->service_id(), surface)); 9479 std::make_pair(texture_ref->service_id(), surface));
9476 9480
9477 CGLContextObj context = 9481 CGLContextObj context =
9478 static_cast<CGLContextObj>(context_->GetHandle()); 9482 static_cast<CGLContextObj>(context_->GetHandle());
9479 9483
9480 CGLError err = surface_support->CGLTexImageIOSurface2D( 9484 CGLError err = surface_support->CGLTexImageIOSurface2D(
9481 context, 9485 context,
9482 target, 9486 target,
9483 GL_RGBA, 9487 GL_RGBA,
9484 width, 9488 width,
9485 height, 9489 height,
9486 GL_BGRA, 9490 GL_BGRA,
9487 GL_UNSIGNED_INT_8_8_8_8_REV, 9491 GL_UNSIGNED_INT_8_8_8_8_REV,
9488 surface, 9492 surface,
9489 plane); 9493 plane);
9490 9494
9491 if (err != kCGLNoError) { 9495 if (err != kCGLNoError) {
9492 LOCAL_SET_GL_ERROR( 9496 LOCAL_SET_GL_ERROR(
9493 GL_INVALID_OPERATION, 9497 GL_INVALID_OPERATION,
9494 "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D"); 9498 "glTexImageIOSurface2DCHROMIUM", "error in CGLTexImageIOSurface2D");
9495 return; 9499 return;
9496 } 9500 }
9497 9501
9498 texture_manager()->SetLevelInfo( 9502 texture_manager()->SetLevelInfo(
9499 texture, target, 0, GL_RGBA, width, height, 1, 0, 9503 texture_ref, target, 0, GL_RGBA, width, height, 1, 0,
9500 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true); 9504 GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, true);
9501 9505
9502 #else 9506 #else
9503 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, 9507 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION,
9504 "glTexImageIOSurface2DCHROMIUM", "not supported."); 9508 "glTexImageIOSurface2DCHROMIUM", "not supported.");
9505 #endif 9509 #endif
9506 } 9510 }
9507 9511
9508 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) { 9512 static GLenum ExtractFormatFromStorageFormat(GLenum internalformat) {
9509 switch (internalformat) { 9513 switch (internalformat) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
9546 case GL_BGRA8_EXT: 9550 case GL_BGRA8_EXT:
9547 return GL_BGRA_EXT; 9551 return GL_BGRA_EXT;
9548 default: 9552 default:
9549 return GL_NONE; 9553 return GL_NONE;
9550 } 9554 }
9551 } 9555 }
9552 9556
9553 void GLES2DecoderImpl::DoCopyTextureCHROMIUM( 9557 void GLES2DecoderImpl::DoCopyTextureCHROMIUM(
9554 GLenum target, GLuint source_id, GLuint dest_id, GLint level, 9558 GLenum target, GLuint source_id, GLuint dest_id, GLint level,
9555 GLenum internal_format, GLenum dest_type) { 9559 GLenum internal_format, GLenum dest_type) {
9556 Texture* dest_texture = GetTexture(dest_id); 9560 TextureRef* dest_texture_ref = GetTexture(dest_id);
9557 Texture* source_texture = GetTexture(source_id); 9561 TextureRef* source_texture_ref = GetTexture(source_id);
9558 9562
9559 if (!source_texture || !dest_texture) { 9563 if (!source_texture_ref || !dest_texture_ref) {
9560 LOCAL_SET_GL_ERROR( 9564 LOCAL_SET_GL_ERROR(
9561 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id"); 9565 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "unknown texture id");
9562 return; 9566 return;
9563 } 9567 }
9564 9568
9565 if (GL_TEXTURE_2D != target) { 9569 if (GL_TEXTURE_2D != target) {
9566 LOCAL_SET_GL_ERROR( 9570 LOCAL_SET_GL_ERROR(
9567 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid texture target"); 9571 GL_INVALID_VALUE, "glCopyTextureCHROMIUM", "invalid texture target");
9568 return; 9572 return;
9569 } 9573 }
9570 9574
9575 Texture* source_texture = source_texture_ref->texture();
9576 Texture* dest_texture = dest_texture_ref->texture();
9571 if (dest_texture->target() != GL_TEXTURE_2D || 9577 if (dest_texture->target() != GL_TEXTURE_2D ||
9572 (source_texture->target() != GL_TEXTURE_2D && 9578 (source_texture->target() != GL_TEXTURE_2D &&
9573 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) { 9579 source_texture->target() != GL_TEXTURE_EXTERNAL_OES)) {
9574 LOCAL_SET_GL_ERROR( 9580 LOCAL_SET_GL_ERROR(
9575 GL_INVALID_VALUE, 9581 GL_INVALID_VALUE,
9576 "glCopyTextureCHROMIUM", "invalid texture target binding"); 9582 "glCopyTextureCHROMIUM", "invalid texture target binding");
9577 return; 9583 return;
9578 } 9584 }
9579 9585
9580 int source_width, source_height, dest_width, dest_height; 9586 int source_width, source_height, dest_width, dest_height;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
9652 glTexImage2D( 9658 glTexImage2D(
9653 GL_TEXTURE_2D, level, internal_format, source_width, source_height, 9659 GL_TEXTURE_2D, level, internal_format, source_width, source_height,
9654 0, internal_format, dest_type, NULL); 9660 0, internal_format, dest_type, NULL);
9655 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM"); 9661 GLenum error = LOCAL_PEEK_GL_ERROR("glCopyTextureCHROMIUM");
9656 if (error != GL_NO_ERROR) { 9662 if (error != GL_NO_ERROR) {
9657 RestoreCurrentTexture2DBindings(); 9663 RestoreCurrentTexture2DBindings();
9658 return; 9664 return;
9659 } 9665 }
9660 9666
9661 texture_manager()->SetLevelInfo( 9667 texture_manager()->SetLevelInfo(
9662 dest_texture, GL_TEXTURE_2D, level, internal_format, source_width, 9668 dest_texture_ref, GL_TEXTURE_2D, level, internal_format, source_width,
9663 source_height, 1, 0, internal_format, dest_type, true); 9669 source_height, 1, 0, internal_format, dest_type, true);
9664 } else { 9670 } else {
9665 texture_manager()->SetLevelCleared( 9671 texture_manager()->SetLevelCleared(
9666 dest_texture, GL_TEXTURE_2D, level, true); 9672 dest_texture_ref, GL_TEXTURE_2D, level, true);
9667 } 9673 }
9668 9674
9669 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix 9675 // GL_TEXTURE_EXTERNAL_OES texture requires apply a transform matrix
9670 // before presenting. 9676 // before presenting.
9671 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) { 9677 if (source_texture->target() == GL_TEXTURE_EXTERNAL_OES) {
9672 // TODO(hkuang): get the StreamTexture transform matrix in GPU process 9678 // TODO(hkuang): get the StreamTexture transform matrix in GPU process
9673 // instead of using default matrix crbug.com/226218. 9679 // instead of using default matrix crbug.com/226218.
9674 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f, 9680 const static GLfloat default_matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f,
9675 0.0f, 1.0f, 0.0f, 0.0f, 9681 0.0f, 1.0f, 0.0f, 0.0f,
9676 0.0f, 0.0f, 1.0f, 0.0f, 9682 0.0f, 0.0f, 1.0f, 0.0f,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
9751 GLenum internal_format, 9757 GLenum internal_format,
9752 GLsizei width, 9758 GLsizei width,
9753 GLsizei height) { 9759 GLsizei height) {
9754 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT"); 9760 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoTexStorage2DEXT");
9755 if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) || 9761 if (!texture_manager()->ValidForTarget(target, 0, width, height, 1) ||
9756 TextureManager::ComputeMipMapCount(width, height, 1) < levels) { 9762 TextureManager::ComputeMipMapCount(width, height, 1) < levels) {
9757 LOCAL_SET_GL_ERROR( 9763 LOCAL_SET_GL_ERROR(
9758 GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range"); 9764 GL_INVALID_VALUE, "glTexStorage2DEXT", "dimensions out of range");
9759 return; 9765 return;
9760 } 9766 }
9761 Texture* texture = GetTextureInfoForTarget(target); 9767 TextureRef* texture_ref = GetTextureInfoForTarget(target);
9762 if (!texture) { 9768 if (!texture_ref) {
9763 LOCAL_SET_GL_ERROR( 9769 LOCAL_SET_GL_ERROR(
9764 GL_INVALID_OPERATION, 9770 GL_INVALID_OPERATION,
9765 "glTexStorage2DEXT", "unknown texture for target"); 9771 "glTexStorage2DEXT", "unknown texture for target");
9766 return; 9772 return;
9767 } 9773 }
9774 Texture* texture = texture_ref->texture();
9768 if (texture->IsAttachedToFramebuffer()) { 9775 if (texture->IsAttachedToFramebuffer()) {
9769 clear_state_dirty_ = true; 9776 clear_state_dirty_ = true;
9770 } 9777 }
9771 if (texture->IsImmutable()) { 9778 if (texture->IsImmutable()) {
9772 LOCAL_SET_GL_ERROR( 9779 LOCAL_SET_GL_ERROR(
9773 GL_INVALID_OPERATION, 9780 GL_INVALID_OPERATION,
9774 "glTexStorage2DEXT", "texture is immutable"); 9781 "glTexStorage2DEXT", "texture is immutable");
9775 return; 9782 return;
9776 } 9783 }
9777 9784
(...skipping 25 matching lines...) Expand all
9803 } 9810 }
9804 9811
9805 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage2DEXT"); 9812 LOCAL_COPY_REAL_GL_ERRORS_TO_WRAPPER("glTexStorage2DEXT");
9806 glTexStorage2DEXT(target, levels, internal_format, width, height); 9813 glTexStorage2DEXT(target, levels, internal_format, width, height);
9807 GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage2DEXT"); 9814 GLenum error = LOCAL_PEEK_GL_ERROR("glTexStorage2DEXT");
9808 if (error == GL_NO_ERROR) { 9815 if (error == GL_NO_ERROR) {
9809 GLsizei level_width = width; 9816 GLsizei level_width = width;
9810 GLsizei level_height = height; 9817 GLsizei level_height = height;
9811 for (int ii = 0; ii < levels; ++ii) { 9818 for (int ii = 0; ii < levels; ++ii) {
9812 texture_manager()->SetLevelInfo( 9819 texture_manager()->SetLevelInfo(
9813 texture, target, ii, format, level_width, level_height, 1, 0, format, 9820 texture_ref, target, ii, format,
9814 type, false); 9821 level_width, level_height, 1, 0, format, type, false);
9815 level_width = std::max(1, level_width >> 1); 9822 level_width = std::max(1, level_width >> 1);
9816 level_height = std::max(1, level_height >> 1); 9823 level_height = std::max(1, level_height >> 1);
9817 } 9824 }
9818 texture->SetImmutable(true); 9825 texture->SetImmutable(true);
9819 } 9826 }
9820 } 9827 }
9821 9828
9822 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM( 9829 error::Error GLES2DecoderImpl::HandleGenMailboxCHROMIUM(
9823 uint32 immediate_data_size, const cmds::GenMailboxCHROMIUM& c) { 9830 uint32 immediate_data_size, const cmds::GenMailboxCHROMIUM& c) {
9824 MailboxName name; 9831 MailboxName name;
9825 mailbox_manager()->GenerateMailboxName(&name); 9832 mailbox_manager()->GenerateMailboxName(&name);
9826 uint32 bucket_id = static_cast<uint32>(c.bucket_id); 9833 uint32 bucket_id = static_cast<uint32>(c.bucket_id);
9827 Bucket* bucket = CreateBucket(bucket_id); 9834 Bucket* bucket = CreateBucket(bucket_id);
9828 9835
9829 bucket->SetSize(GL_MAILBOX_SIZE_CHROMIUM); 9836 bucket->SetSize(GL_MAILBOX_SIZE_CHROMIUM);
9830 bucket->SetData(&name, 0, GL_MAILBOX_SIZE_CHROMIUM); 9837 bucket->SetData(&name, 0, GL_MAILBOX_SIZE_CHROMIUM);
9831 9838
9832 return error::kNoError; 9839 return error::kNoError;
9833 } 9840 }
9834 9841
9835 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target, 9842 void GLES2DecoderImpl::DoProduceTextureCHROMIUM(GLenum target,
9836 const GLbyte* mailbox) { 9843 const GLbyte* mailbox) {
9837 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM", 9844 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoProduceTextureCHROMIUM",
9838 "context", logger_.GetLogPrefix(), 9845 "context", logger_.GetLogPrefix(),
9839 "mailbox[0]", static_cast<unsigned char>(mailbox[0])); 9846 "mailbox[0]", static_cast<unsigned char>(mailbox[0]));
9840 9847
9841 Texture* texture = GetTextureInfoForTarget(target); 9848 TextureRef* texture_ref = GetTextureInfoForTarget(target);
9842 if (!texture) { 9849 if (!texture_ref) {
9843 LOCAL_SET_GL_ERROR( 9850 LOCAL_SET_GL_ERROR(
9844 GL_INVALID_OPERATION, 9851 GL_INVALID_OPERATION,
9845 "glProduceTextureCHROMIUM", "unknown texture for target"); 9852 "glProduceTextureCHROMIUM", "unknown texture for target");
9846 return; 9853 return;
9847 } 9854 }
9848 9855
9849 TextureDefinition* definition = texture_manager()->Save(texture); 9856 TextureDefinition* definition = texture_manager()->Save(texture_ref);
9850 if (!definition) { 9857 if (!definition) {
9851 LOCAL_SET_GL_ERROR( 9858 LOCAL_SET_GL_ERROR(
9852 GL_INVALID_OPERATION, 9859 GL_INVALID_OPERATION,
9853 "glProduceTextureCHROMIUM", "invalid texture"); 9860 "glProduceTextureCHROMIUM", "invalid texture");
9854 return; 9861 return;
9855 } 9862 }
9856 9863
9857 if (!group_->mailbox_manager()->ProduceTexture( 9864 if (!group_->mailbox_manager()->ProduceTexture(
9858 target, 9865 target,
9859 *reinterpret_cast<const MailboxName*>(mailbox), 9866 *reinterpret_cast<const MailboxName*>(mailbox),
9860 definition, 9867 definition,
9861 texture_manager())) { 9868 texture_manager())) {
9862 bool success = texture_manager()->Restore( 9869 bool success = texture_manager()->Restore(
9863 "glProductTextureCHROMIUM", this, texture, definition); 9870 "glProductTextureCHROMIUM", this, texture_ref, definition);
9864 DCHECK(success); 9871 DCHECK(success);
9865 LOCAL_SET_GL_ERROR( 9872 LOCAL_SET_GL_ERROR(
9866 GL_INVALID_OPERATION, 9873 GL_INVALID_OPERATION,
9867 "glProduceTextureCHROMIUM", "invalid mailbox name"); 9874 "glProduceTextureCHROMIUM", "invalid mailbox name");
9868 return; 9875 return;
9869 } 9876 }
9870 9877
9871 glBindTexture(texture->target(), texture->service_id()); 9878 glBindTexture(texture_ref->texture()->target(), texture_ref->service_id());
9872 } 9879 }
9873 9880
9874 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target, 9881 void GLES2DecoderImpl::DoConsumeTextureCHROMIUM(GLenum target,
9875 const GLbyte* mailbox) { 9882 const GLbyte* mailbox) {
9876 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM", 9883 TRACE_EVENT2("gpu", "GLES2DecoderImpl::DoConsumeTextureCHROMIUM",
9877 "context", logger_.GetLogPrefix(), 9884 "context", logger_.GetLogPrefix(),
9878 "mailbox[0]", static_cast<unsigned char>(mailbox[0])); 9885 "mailbox[0]", static_cast<unsigned char>(mailbox[0]));
9879 9886
9880 Texture* texture = GetTextureInfoForTarget(target); 9887 TextureRef* texture_ref = GetTextureInfoForTarget(target);
9881 if (!texture) { 9888 if (!texture_ref) {
9882 LOCAL_SET_GL_ERROR( 9889 LOCAL_SET_GL_ERROR(
9883 GL_INVALID_OPERATION, 9890 GL_INVALID_OPERATION,
9884 "glConsumeTextureCHROMIUM", "unknown texture for target"); 9891 "glConsumeTextureCHROMIUM", "unknown texture for target");
9885 return; 9892 return;
9886 } 9893 }
9887 9894
9888 scoped_ptr<TextureDefinition> definition( 9895 scoped_ptr<TextureDefinition> definition(
9889 group_->mailbox_manager()->ConsumeTexture( 9896 group_->mailbox_manager()->ConsumeTexture(
9890 target, 9897 target,
9891 *reinterpret_cast<const MailboxName*>(mailbox))); 9898 *reinterpret_cast<const MailboxName*>(mailbox)));
9892 if (!definition.get()) { 9899 if (!definition.get()) {
9893 LOCAL_SET_GL_ERROR( 9900 LOCAL_SET_GL_ERROR(
9894 GL_INVALID_OPERATION, 9901 GL_INVALID_OPERATION,
9895 "glConsumeTextureCHROMIUM", "invalid mailbox name"); 9902 "glConsumeTextureCHROMIUM", "invalid mailbox name");
9896 return; 9903 return;
9897 } 9904 }
9898 9905
9899 if (!texture_manager()->Restore( 9906 if (!texture_manager()->Restore(
9900 "glConsumeTextureCHROMIUM", this, texture, definition.release())) { 9907 "glConsumeTextureCHROMIUM", this, texture_ref, definition.release())) {
9901 LOCAL_SET_GL_ERROR( 9908 LOCAL_SET_GL_ERROR(
9902 GL_INVALID_OPERATION, 9909 GL_INVALID_OPERATION,
9903 "glConsumeTextureCHROMIUM", "invalid texture"); 9910 "glConsumeTextureCHROMIUM", "invalid texture");
9904 return; 9911 return;
9905 } 9912 }
9906 } 9913 }
9907 9914
9908 void GLES2DecoderImpl::DoInsertEventMarkerEXT( 9915 void GLES2DecoderImpl::DoInsertEventMarkerEXT(
9909 GLsizei length, const GLchar* marker) { 9916 GLsizei length, const GLchar* marker) {
9910 if (!marker) { 9917 if (!marker) {
(...skipping 22 matching lines...) Expand all
9933 if (target != GL_TEXTURE_2D) { 9940 if (target != GL_TEXTURE_2D) {
9934 // This might be supported in the future. 9941 // This might be supported in the future.
9935 LOCAL_SET_GL_ERROR( 9942 LOCAL_SET_GL_ERROR(
9936 GL_INVALID_OPERATION, 9943 GL_INVALID_OPERATION,
9937 "glBindTexImage2DCHROMIUM", "requires TEXTURE_2D target"); 9944 "glBindTexImage2DCHROMIUM", "requires TEXTURE_2D target");
9938 return; 9945 return;
9939 } 9946 }
9940 9947
9941 // Default target might be conceptually valid, but disallow it to avoid 9948 // Default target might be conceptually valid, but disallow it to avoid
9942 // accidents. 9949 // accidents.
9943 Texture* texture = GetTextureInfoForTargetUnlessDefault(target); 9950 TextureRef* texture_ref = GetTextureInfoForTargetUnlessDefault(target);
9944 if (!texture) { 9951 if (!texture_ref) {
9945 LOCAL_SET_GL_ERROR( 9952 LOCAL_SET_GL_ERROR(
9946 GL_INVALID_OPERATION, 9953 GL_INVALID_OPERATION,
9947 "glBindTexImage2DCHROMIUM", "no texture bound"); 9954 "glBindTexImage2DCHROMIUM", "no texture bound");
9948 return; 9955 return;
9949 } 9956 }
9950 9957
9951 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); 9958 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id);
9952 if (!gl_image) { 9959 if (!gl_image) {
9953 LOCAL_SET_GL_ERROR( 9960 LOCAL_SET_GL_ERROR(
9954 GL_INVALID_OPERATION, 9961 GL_INVALID_OPERATION,
9955 "glBindTexImage2DCHROMIUM", "no image found with the given ID"); 9962 "glBindTexImage2DCHROMIUM", "no image found with the given ID");
9956 return; 9963 return;
9957 } 9964 }
9958 9965
9959 { 9966 {
9960 ScopedGLErrorSuppressor suppressor( 9967 ScopedGLErrorSuppressor suppressor(
9961 "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", this); 9968 "GLES2DecoderImpl::DoBindTexImage2DCHROMIUM", this);
9962 if (!gl_image->BindTexImage()) { 9969 if (!gl_image->BindTexImage()) {
9963 LOCAL_SET_GL_ERROR( 9970 LOCAL_SET_GL_ERROR(
9964 GL_INVALID_OPERATION, 9971 GL_INVALID_OPERATION,
9965 "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID"); 9972 "glBindTexImage2DCHROMIUM", "fail to bind image with the given ID");
9966 return; 9973 return;
9967 } 9974 }
9968 } 9975 }
9969 9976
9970 gfx::Size size = gl_image->GetSize(); 9977 gfx::Size size = gl_image->GetSize();
9971 texture_manager()->SetLevelInfo( 9978 texture_manager()->SetLevelInfo(
9972 texture, target, 0, GL_RGBA, size.width(), size.height(), 1, 0, 9979 texture_ref, target, 0, GL_RGBA, size.width(), size.height(), 1, 0,
9973 GL_RGBA, GL_UNSIGNED_BYTE, true); 9980 GL_RGBA, GL_UNSIGNED_BYTE, true);
9974 texture_manager()->SetLevelImage(texture, target, 0, gl_image); 9981 texture_manager()->SetLevelImage(texture_ref, target, 0, gl_image);
9975 } 9982 }
9976 9983
9977 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM( 9984 void GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM(
9978 GLenum target, GLint image_id) { 9985 GLenum target, GLint image_id) {
9979 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM"); 9986 TRACE_EVENT0("gpu", "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM");
9980 if (target != GL_TEXTURE_2D) { 9987 if (target != GL_TEXTURE_2D) {
9981 // This might be supported in the future. 9988 // This might be supported in the future.
9982 LOCAL_SET_GL_ERROR( 9989 LOCAL_SET_GL_ERROR(
9983 GL_INVALID_OPERATION, 9990 GL_INVALID_OPERATION,
9984 "glReleaseTexImage2DCHROMIUM", "requires TEXTURE_2D target"); 9991 "glReleaseTexImage2DCHROMIUM", "requires TEXTURE_2D target");
9985 return; 9992 return;
9986 } 9993 }
9987 9994
9988 // Default target might be conceptually valid, but disallow it to avoid 9995 // Default target might be conceptually valid, but disallow it to avoid
9989 // accidents. 9996 // accidents.
9990 Texture* texture = GetTextureInfoForTargetUnlessDefault(target); 9997 TextureRef* texture_ref = GetTextureInfoForTargetUnlessDefault(target);
9991 if (!texture) { 9998 if (!texture_ref) {
9992 LOCAL_SET_GL_ERROR( 9999 LOCAL_SET_GL_ERROR(
9993 GL_INVALID_OPERATION, 10000 GL_INVALID_OPERATION,
9994 "glReleaseTexImage2DCHROMIUM", "no texture bound"); 10001 "glReleaseTexImage2DCHROMIUM", "no texture bound");
9995 return; 10002 return;
9996 } 10003 }
9997 10004
9998 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id); 10005 gfx::GLImage* gl_image = image_manager()->LookupImage(image_id);
9999 if (!gl_image) { 10006 if (!gl_image) {
10000 LOCAL_SET_GL_ERROR( 10007 LOCAL_SET_GL_ERROR(
10001 GL_INVALID_OPERATION, 10008 GL_INVALID_OPERATION,
10002 "glReleaseTexImage2DCHROMIUM", "no image found with the given ID"); 10009 "glReleaseTexImage2DCHROMIUM", "no image found with the given ID");
10003 return; 10010 return;
10004 } 10011 }
10005 10012
10006 // Do nothing when image is not currently bound. 10013 // Do nothing when image is not currently bound.
10007 if (texture->GetLevelImage(target, 0) != gl_image) 10014 if (texture_ref->texture()->GetLevelImage(target, 0) != gl_image)
10008 return; 10015 return;
10009 10016
10010 { 10017 {
10011 ScopedGLErrorSuppressor suppressor( 10018 ScopedGLErrorSuppressor suppressor(
10012 "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", this); 10019 "GLES2DecoderImpl::DoReleaseTexImage2DCHROMIUM", this);
10013 gl_image->ReleaseTexImage(); 10020 gl_image->ReleaseTexImage();
10014 } 10021 }
10015 10022
10016 texture_manager()->SetLevelInfo( 10023 texture_manager()->SetLevelInfo(
10017 texture, target, 0, GL_RGBA, 0, 0, 1, 0, 10024 texture_ref, target, 0, GL_RGBA, 0, 0, 1, 0,
10018 GL_RGBA, GL_UNSIGNED_BYTE, false); 10025 GL_RGBA, GL_UNSIGNED_BYTE, false);
10019 } 10026 }
10020 10027
10021 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM( 10028 error::Error GLES2DecoderImpl::HandleTraceBeginCHROMIUM(
10022 uint32 immediate_data_size, const cmds::TraceBeginCHROMIUM& c) { 10029 uint32 immediate_data_size, const cmds::TraceBeginCHROMIUM& c) {
10023 Bucket* bucket = GetBucket(c.bucket_id); 10030 Bucket* bucket = GetBucket(c.bucket_id);
10024 if (!bucket || bucket->size() == 0) { 10031 if (!bucket || bucket->size() == 0) {
10025 return error::kInvalidArguments; 10032 return error::kInvalidArguments;
10026 } 10033 }
10027 std::string command_name; 10034 std::string command_name;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
10154 } 10161 }
10155 10162
10156 // All the normal glTexSubImage2D validation. 10163 // All the normal glTexSubImage2D validation.
10157 if (!ValidateTexImage2D( 10164 if (!ValidateTexImage2D(
10158 "glAsyncTexImage2DCHROMIUM", target, level, internal_format, 10165 "glAsyncTexImage2DCHROMIUM", target, level, internal_format,
10159 width, height, border, format, type, pixels, pixels_size)) { 10166 width, height, border, format, type, pixels, pixels_size)) {
10160 return error::kNoError; 10167 return error::kNoError;
10161 } 10168 }
10162 10169
10163 // Extra async validation. 10170 // Extra async validation.
10164 Texture* texture = GetTextureInfoForTarget(target); 10171 TextureRef* texture_ref = GetTextureInfoForTarget(target);
10172 Texture* texture = texture_ref->texture();
10165 if (!ValidateAsyncTransfer( 10173 if (!ValidateAsyncTransfer(
10166 "glAsyncTexImage2DCHROMIUM", texture, target, level, pixels)) 10174 "glAsyncTexImage2DCHROMIUM", texture, target, level, pixels))
10167 return error::kNoError; 10175 return error::kNoError;
10168 10176
10169 // Don't allow async redefinition of a textures. 10177 // Don't allow async redefinition of a textures.
10170 if (texture->IsDefined()) { 10178 if (texture->IsDefined()) {
10171 LOCAL_SET_GL_ERROR( 10179 LOCAL_SET_GL_ERROR(
10172 GL_INVALID_OPERATION, 10180 GL_INVALID_OPERATION,
10173 "glAsyncTexImage2DCHROMIUM", "already defined"); 10181 "glAsyncTexImage2DCHROMIUM", "already defined");
10174 return error::kNoError; 10182 return error::kNoError;
10175 } 10183 }
10176 10184
10177 // Since we don't allow async redefinition, this is the only
10178 // time the size of this texture can change while bound
10179 // as a frame-buffer.
10180 if (texture->IsAttachedToFramebuffer()) {
10181 // TODO(gman): If textures tracked which framebuffers they were attached to
10182 // we could just mark those framebuffers as not complete.
10183 framebuffer_manager()->IncFramebufferStateChangeCount();
10184 }
10185
10186 if (!EnsureGPUMemoryAvailable(pixels_size)) { 10185 if (!EnsureGPUMemoryAvailable(pixels_size)) {
10187 LOCAL_SET_GL_ERROR( 10186 LOCAL_SET_GL_ERROR(
10188 GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory"); 10187 GL_OUT_OF_MEMORY, "glAsyncTexImage2DCHROMIUM", "out of memory");
10189 return error::kNoError; 10188 return error::kNoError;
10190 } 10189 }
10191 10190
10192 // We know the memory/size is safe, so get the real shared memory since 10191 // We know the memory/size is safe, so get the real shared memory since
10193 // it might need to be duped to prevent use-after-free of the memory. 10192 // it might need to be duped to prevent use-after-free of the memory.
10194 gpu::Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id); 10193 gpu::Buffer buffer = GetSharedMemoryBuffer(c.pixels_shm_id);
10195 base::SharedMemory* shared_memory = buffer.shared_memory; 10194 base::SharedMemory* shared_memory = buffer.shared_memory;
10196 uint32 shm_size = buffer.size; 10195 uint32 shm_size = buffer.size;
10197 uint32 shm_data_offset = c.pixels_shm_offset; 10196 uint32 shm_data_offset = c.pixels_shm_offset;
10198 uint32 shm_data_size = pixels_size; 10197 uint32 shm_data_size = pixels_size;
10199 10198
10200 // Setup the parameters. 10199 // Setup the parameters.
10201 AsyncTexImage2DParams tex_params = { 10200 AsyncTexImage2DParams tex_params = {
10202 target, level, static_cast<GLenum>(internal_format), 10201 target, level, static_cast<GLenum>(internal_format),
10203 width, height, border, format, type}; 10202 width, height, border, format, type};
10204 AsyncMemoryParams mem_params = { 10203 AsyncMemoryParams mem_params = {
10205 shared_memory, shm_size, shm_data_offset, shm_data_size}; 10204 shared_memory, shm_size, shm_data_offset, shm_data_size};
10206 10205
10207 // Set up the async state if needed, and make the texture 10206 // Set up the async state if needed, and make the texture
10208 // immutable so the async state stays valid. The level info 10207 // immutable so the async state stays valid. The level info
10209 // is set up lazily when the transfer completes. 10208 // is set up lazily when the transfer completes.
10210 DCHECK(!texture->GetAsyncTransferState()); 10209 DCHECK(!texture->GetAsyncTransferState());
10211 texture->SetAsyncTransferState( 10210 texture_ref->SetAsyncTransferState(
10212 make_scoped_ptr( 10211 make_scoped_ptr(
10213 async_pixel_transfer_delegate_->CreatePixelTransferState( 10212 async_pixel_transfer_delegate_->CreatePixelTransferState(
10214 texture->service_id(), 10213 texture->service_id(),
10215 tex_params))); 10214 tex_params)));
10216 texture->SetImmutable(true); 10215 texture->SetImmutable(true);
10217 10216
10218 async_pixel_transfer_delegate_->AsyncTexImage2D( 10217 async_pixel_transfer_delegate_->AsyncTexImage2D(
10219 texture->GetAsyncTransferState(), 10218 texture->GetAsyncTransferState(),
10220 tex_params, 10219 tex_params,
10221 mem_params, 10220 mem_params,
10222 base::Bind(&TextureManager::SetLevelInfoFromParams, 10221 base::Bind(&TextureManager::SetLevelInfoFromParams,
10223 // The callback is only invoked if the transfer state 10222 // The callback is only invoked if the transfer delegate still
10224 // still exists, which implies through manager->info->state 10223 // exists, which implies through manager->texture_ref->state
10225 // ownership that both of these pointers are valid. 10224 // ownership that both of these pointers are valid.
10226 base::Unretained(texture_manager()), 10225 base::Unretained(texture_manager()),
10227 base::Unretained(texture), 10226 base::Unretained(texture_ref),
10228 tex_params)); 10227 tex_params));
10229 return error::kNoError; 10228 return error::kNoError;
10230 } 10229 }
10231 10230
10232 error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM( 10231 error::Error GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM(
10233 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) { 10232 uint32 immediate_data_size, const cmds::AsyncTexSubImage2DCHROMIUM& c) {
10234 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM"); 10233 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleAsyncTexSubImage2DCHROMIUM");
10235 GLenum target = static_cast<GLenum>(c.target); 10234 GLenum target = static_cast<GLenum>(c.target);
10236 GLint level = static_cast<GLint>(c.level); 10235 GLint level = static_cast<GLint>(c.level);
10237 GLint xoffset = static_cast<GLint>(c.xoffset); 10236 GLint xoffset = static_cast<GLint>(c.xoffset);
(...skipping 15 matching lines...) Expand all
10253 c.data_shm_id, c.data_shm_offset, data_size); 10252 c.data_shm_id, c.data_shm_offset, data_size);
10254 10253
10255 // All the normal glTexSubImage2D validation. 10254 // All the normal glTexSubImage2D validation.
10256 error::Error error = error::kNoError; 10255 error::Error error = error::kNoError;
10257 if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2DCHROMIUM", 10256 if (!ValidateTexSubImage2D(&error, "glAsyncTexSubImage2DCHROMIUM",
10258 target, level, xoffset, yoffset, width, height, format, type, pixels)) { 10257 target, level, xoffset, yoffset, width, height, format, type, pixels)) {
10259 return error; 10258 return error;
10260 } 10259 }
10261 10260
10262 // Extra async validation. 10261 // Extra async validation.
10263 Texture* texture = GetTextureInfoForTarget(target); 10262 TextureRef* texture_ref = GetTextureInfoForTarget(target);
10263 Texture* texture = texture_ref->texture();
10264 if (!ValidateAsyncTransfer( 10264 if (!ValidateAsyncTransfer(
10265 "glAsyncTexSubImage2DCHROMIUM", texture, target, level, pixels)) 10265 "glAsyncTexSubImage2DCHROMIUM", texture, target, level, pixels))
10266 return error::kNoError; 10266 return error::kNoError;
10267 10267
10268 // Guarantee async textures are always 'cleared' as follows: 10268 // Guarantee async textures are always 'cleared' as follows:
10269 // - AsyncTexImage2D can not redefine an existing texture 10269 // - AsyncTexImage2D can not redefine an existing texture
10270 // - AsyncTexImage2D must initialize the entire image via non-null buffer. 10270 // - AsyncTexImage2D must initialize the entire image via non-null buffer.
10271 // - AsyncTexSubImage2D clears synchronously if not already cleared. 10271 // - AsyncTexSubImage2D clears synchronously if not already cleared.
10272 // - Textures become immutable after an async call. 10272 // - Textures become immutable after an async call.
10273 // This way we know in all cases that an async texture is always clear. 10273 // This way we know in all cases that an async texture is always clear.
10274 if (!texture->SafeToRenderFrom()) { 10274 if (!texture->SafeToRenderFrom()) {
10275 if (!texture_manager()->ClearTextureLevel(this, texture, target, level)) { 10275 if (!texture_manager()->ClearTextureLevel(this, texture_ref,
10276 target, level)) {
10276 LOCAL_SET_GL_ERROR( 10277 LOCAL_SET_GL_ERROR(
10277 GL_OUT_OF_MEMORY, 10278 GL_OUT_OF_MEMORY,
10278 "glAsyncTexSubImage2DCHROMIUM", "dimensions too big"); 10279 "glAsyncTexSubImage2DCHROMIUM", "dimensions too big");
10279 return error::kNoError; 10280 return error::kNoError;
10280 } 10281 }
10281 } 10282 }
10282 10283
10283 // We know the memory/size is safe, so get the real shared memory since 10284 // We know the memory/size is safe, so get the real shared memory since
10284 // it might need to be duped to prevent use-after-free of the memory. 10285 // it might need to be duped to prevent use-after-free of the memory.
10285 gpu::Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id); 10286 gpu::Buffer buffer = GetSharedMemoryBuffer(c.data_shm_id);
10286 base::SharedMemory* shared_memory = buffer.shared_memory; 10287 base::SharedMemory* shared_memory = buffer.shared_memory;
10287 uint32 shm_size = buffer.size; 10288 uint32 shm_size = buffer.size;
10288 uint32 shm_data_offset = c.data_shm_offset; 10289 uint32 shm_data_offset = c.data_shm_offset;
10289 uint32 shm_data_size = data_size; 10290 uint32 shm_data_size = data_size;
10290 10291
10291 // Setup the parameters. 10292 // Setup the parameters.
10292 AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset, 10293 AsyncTexSubImage2DParams tex_params = {target, level, xoffset, yoffset,
10293 width, height, format, type}; 10294 width, height, format, type};
10294 AsyncMemoryParams mem_params = {shared_memory, shm_size, 10295 AsyncMemoryParams mem_params = {shared_memory, shm_size,
10295 shm_data_offset, shm_data_size}; 10296 shm_data_offset, shm_data_size};
10296 if (!texture->GetAsyncTransferState()) { 10297 AsyncPixelTransferState* state = texture->GetAsyncTransferState();
10298 if (!state) {
10297 // TODO(epenner): We may want to enforce exclusive use 10299 // TODO(epenner): We may want to enforce exclusive use
10298 // of async APIs in which case this should become an error, 10300 // of async APIs in which case this should become an error,
10299 // (the texture should have been async defined). 10301 // (the texture should have been async defined).
10300 AsyncTexImage2DParams define_params = {target, level, 10302 AsyncTexImage2DParams define_params = {target, level,
10301 0, 0, 0, 0, 0, 0}; 10303 0, 0, 0, 0, 0, 0};
10302 texture->GetLevelSize(target, level, &define_params.width, 10304 texture->GetLevelSize(target, level, &define_params.width,
10303 &define_params.height); 10305 &define_params.height);
10304 texture->GetLevelType(target, level, &define_params.type, 10306 texture->GetLevelType(target, level, &define_params.type,
10305 &define_params.internal_format); 10307 &define_params.internal_format);
10306 // Set up the async state if needed, and make the texture 10308 // Set up the async state if needed, and make the texture
10307 // immutable so the async state stays valid. 10309 // immutable so the async state stays valid.
10308 texture->SetAsyncTransferState( 10310 state = async_pixel_transfer_delegate_->CreatePixelTransferState(
10309 make_scoped_ptr( 10311 texture->service_id(),
10310 async_pixel_transfer_delegate_->CreatePixelTransferState( 10312 define_params);
10311 texture->service_id(), 10313 texture_ref->SetAsyncTransferState(make_scoped_ptr(state));
10312 define_params)));
10313 texture->SetImmutable(true); 10314 texture->SetImmutable(true);
10314 } 10315 }
10315 10316
10316 async_pixel_transfer_delegate_->AsyncTexSubImage2D( 10317 async_pixel_transfer_delegate_->AsyncTexSubImage2D(
10317 texture->GetAsyncTransferState(), tex_params, mem_params); 10318 state, tex_params, mem_params);
10318 return error::kNoError; 10319 return error::kNoError;
10319 } 10320 }
10320 10321
10321 error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM( 10322 error::Error GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM(
10322 uint32 immediate_data_size, const cmds::WaitAsyncTexImage2DCHROMIUM& c) { 10323 uint32 immediate_data_size, const cmds::WaitAsyncTexImage2DCHROMIUM& c) {
10323 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM"); 10324 TRACE_EVENT0("gpu", "GLES2DecoderImpl::HandleWaitAsyncTexImage2DCHROMIUM");
10324 GLenum target = static_cast<GLenum>(c.target); 10325 GLenum target = static_cast<GLenum>(c.target);
10325 10326
10326 if (GL_TEXTURE_2D != target) { 10327 if (GL_TEXTURE_2D != target) {
10327 LOCAL_SET_GL_ERROR( 10328 LOCAL_SET_GL_ERROR(
10328 GL_INVALID_ENUM, "glWaitAsyncTexImage2DCHROMIUM", "target"); 10329 GL_INVALID_ENUM, "glWaitAsyncTexImage2DCHROMIUM", "target");
10329 return error::kNoError; 10330 return error::kNoError;
10330 } 10331 }
10331 Texture* texture = GetTextureInfoForTarget(target); 10332 TextureRef* texture_ref = GetTextureInfoForTarget(target);
10332 if (!texture) { 10333 if (!texture_ref) {
10333 LOCAL_SET_GL_ERROR( 10334 LOCAL_SET_GL_ERROR(
10334 GL_INVALID_OPERATION, 10335 GL_INVALID_OPERATION,
10335 "glWaitAsyncTexImage2DCHROMIUM", "unknown texture"); 10336 "glWaitAsyncTexImage2DCHROMIUM", "unknown texture");
10336 return error::kNoError; 10337 return error::kNoError;
10337 } 10338 }
10338 async_pixel_transfer_delegate_->WaitForTransferCompletion( 10339 AsyncPixelTransferState* state =
10339 texture->GetAsyncTransferState()); 10340 texture_ref->texture()->GetAsyncTransferState();
10341 if (!state) {
10342 LOCAL_SET_GL_ERROR(
10343 GL_INVALID_OPERATION,
10344 "glWaitAsyncTexImage2DCHROMIUM", "No async transfer started");
10345 return error::kNoError;
10346 }
10347 async_pixel_transfer_delegate_->WaitForTransferCompletion(state);
10340 ProcessFinishedAsyncTransfers(); 10348 ProcessFinishedAsyncTransfers();
10341 return error::kNoError; 10349 return error::kNoError;
10342 } 10350 }
10343 10351
10344 // Include the auto-generated part of this file. We split this because it means 10352 // Include the auto-generated part of this file. We split this because it means
10345 // we can easily edit the non-auto generated parts right here in this file 10353 // we can easily edit the non-auto generated parts right here in this file
10346 // instead of having to edit some template or the code generator. 10354 // instead of having to edit some template or the code generator.
10347 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10355 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10348 10356
10349 } // namespace gles2 10357 } // namespace gles2
10350 } // namespace gpu 10358 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/framebuffer_manager_unittest.cc ('k') | gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698