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

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

Powered by Google App Engine
This is Rietveld 408576698