Chromium Code Reviews| Index: gpu/command_buffer/service/texture_manager.cc |
| diff --git a/gpu/command_buffer/service/texture_manager.cc b/gpu/command_buffer/service/texture_manager.cc |
| index 104cadd9d0775f13a847f589dfbdc5ee6ba6dc2d..af3c52178eeddbd736bd8e8a263582c84c78654f 100644 |
| --- a/gpu/command_buffer/service/texture_manager.cc |
| +++ b/gpu/command_buffer/service/texture_manager.cc |
| @@ -64,7 +64,7 @@ TextureManager::~TextureManager() { |
| // If this triggers, that means something is keeping a reference to |
| // a Texture belonging to this. |
| - CHECK_EQ(texture_info_count_, 0u); |
| + CHECK_EQ(texture_count_, 0u); |
| DCHECK_EQ(0, num_unrenderable_textures_); |
| DCHECK_EQ(0, num_unsafe_textures_); |
| @@ -86,8 +86,7 @@ void TextureManager::Destroy(bool have_context) { |
| DCHECK_EQ(0u, memory_tracker_unmanaged_->GetMemRepresented()); |
| } |
| -Texture::Texture(TextureManager* manager, |
| - GLuint service_id) |
| +Texture::Texture(TextureManager* manager, GLuint service_id) |
| : manager_(manager), |
| service_id_(service_id), |
| deleted_(false), |
| @@ -159,8 +158,7 @@ Texture::LevelInfo::LevelInfo(const LevelInfo& rhs) |
| Texture::LevelInfo::~LevelInfo() { |
| } |
| -bool Texture::CanRender( |
| - const FeatureInfo* feature_info) const { |
| +bool Texture::CanRender(const FeatureInfo* feature_info) const { |
| if (target_ == 0) { |
| return false; |
| } |
| @@ -717,7 +715,7 @@ TextureManager::TextureManager( |
| num_unrenderable_textures_(0), |
| num_unsafe_textures_(0), |
| num_uncleared_mips_(0), |
| - texture_info_count_(0), |
| + texture_count_(0), |
| have_context_(true) { |
| for (int ii = 0; ii < kNumDefaultTextures; ++ii) { |
| black_texture_ids_[ii] = 0; |
| @@ -781,7 +779,7 @@ scoped_refptr<Texture> |
| // we need to manually manipulate some of the their bookkeeping. |
| ++num_unrenderable_textures_; |
| scoped_refptr<Texture> default_texture(new Texture(this, ids[1])); |
| - SetInfoTarget(default_texture, target); |
| + SetTarget(default_texture, target); |
| if (needs_faces) { |
| for (int ii = 0; ii < GLES2Util::kNumFaces; ++ii) { |
| SetLevelInfo( |
| @@ -823,79 +821,78 @@ bool TextureManager::ValidForTarget( |
| (target != GL_TEXTURE_2D || (depth == 1)); |
| } |
| -void TextureManager::SetInfoTarget( |
| - Texture* info, GLenum target) { |
| - DCHECK(info); |
| - if (!info->CanRender(feature_info_)) { |
| +void TextureManager::SetTarget(Texture* texture, GLenum target) { |
| + DCHECK(texture); |
| + if (!texture->CanRender(feature_info_)) { |
| DCHECK_NE(0, num_unrenderable_textures_); |
| --num_unrenderable_textures_; |
| } |
| - info->SetTarget(target, MaxLevelsForTarget(target)); |
| - if (!info->CanRender(feature_info_)) { |
| + texture->SetTarget(target, MaxLevelsForTarget(target)); |
| + if (!texture->CanRender(feature_info_)) { |
| ++num_unrenderable_textures_; |
| } |
| } |
| -void TextureManager::SetLevelCleared(Texture* info, |
| +void TextureManager::SetLevelCleared(Texture* texture, |
| GLenum target, |
| GLint level, |
| bool cleared) { |
| - DCHECK(info); |
| - if (!info->SafeToRenderFrom()) { |
| + DCHECK(texture); |
| + if (!texture->SafeToRenderFrom()) { |
| DCHECK_NE(0, num_unsafe_textures_); |
| --num_unsafe_textures_; |
| } |
| - num_uncleared_mips_ -= info->num_uncleared_mips(); |
| + num_uncleared_mips_ -= texture->num_uncleared_mips(); |
| DCHECK_GE(num_uncleared_mips_, 0); |
| - info->SetLevelCleared(target, level, cleared); |
| - num_uncleared_mips_ += info->num_uncleared_mips(); |
| - if (!info->SafeToRenderFrom()) { |
| + texture->SetLevelCleared(target, level, cleared); |
| + num_uncleared_mips_ += texture->num_uncleared_mips(); |
| + if (!texture->SafeToRenderFrom()) { |
| ++num_unsafe_textures_; |
| } |
| } |
| bool TextureManager::ClearRenderableLevels( |
| - GLES2Decoder* decoder,Texture* info) { |
| - DCHECK(info); |
| - if (info->SafeToRenderFrom()) { |
| + GLES2Decoder* decoder,Texture* texture) { |
| + DCHECK(texture); |
| + if (texture->SafeToRenderFrom()) { |
| return true; |
| } |
| DCHECK_NE(0, num_unsafe_textures_); |
| --num_unsafe_textures_; |
| - num_uncleared_mips_ -= info->num_uncleared_mips(); |
| + num_uncleared_mips_ -= texture->num_uncleared_mips(); |
| DCHECK_GE(num_uncleared_mips_, 0); |
| - bool result = info->ClearRenderableLevels(decoder); |
| - num_uncleared_mips_ += info->num_uncleared_mips(); |
| - if (!info->SafeToRenderFrom()) { |
| + bool result = texture->ClearRenderableLevels(decoder); |
| + num_uncleared_mips_ += texture->num_uncleared_mips(); |
| + if (!texture->SafeToRenderFrom()) { |
| ++num_unsafe_textures_; |
| } |
| return result; |
| } |
| bool TextureManager::ClearTextureLevel( |
| - GLES2Decoder* decoder,Texture* info, |
| + GLES2Decoder* decoder,Texture* texture, |
| GLenum target, GLint level) { |
| - DCHECK(info); |
| - if (info->num_uncleared_mips() == 0) { |
| + DCHECK(texture); |
| + if (texture->num_uncleared_mips() == 0) { |
| return true; |
| } |
| - num_uncleared_mips_ -= info->num_uncleared_mips(); |
| + num_uncleared_mips_ -= texture->num_uncleared_mips(); |
| DCHECK_GE(num_uncleared_mips_, 0); |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| DCHECK_NE(0, num_unsafe_textures_); |
| --num_unsafe_textures_; |
| } |
| - bool result = info->ClearLevel(decoder, target, level); |
| - info->UpdateCleared(); |
| - num_uncleared_mips_ += info->num_uncleared_mips(); |
| - if (!info->SafeToRenderFrom()) { |
| + bool result = texture->ClearLevel(decoder, target, level); |
| + texture->UpdateCleared(); |
| + num_uncleared_mips_ += texture->num_uncleared_mips(); |
| + if (!texture->SafeToRenderFrom()) { |
| ++num_unsafe_textures_; |
| } |
| return result; |
| } |
| void TextureManager::SetLevelInfo( |
| - Texture* info, |
| + Texture* texture, |
| GLenum target, |
| GLint level, |
| GLenum internal_format, |
| @@ -906,46 +903,47 @@ void TextureManager::SetLevelInfo( |
| GLenum format, |
| GLenum type, |
| bool cleared) { |
| - DCHECK(info); |
| - if (!info->CanRender(feature_info_)) { |
| + DCHECK(texture); |
| + if (!texture->CanRender(feature_info_)) { |
| DCHECK_NE(0, num_unrenderable_textures_); |
| --num_unrenderable_textures_; |
| } |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| DCHECK_NE(0, num_unsafe_textures_); |
| --num_unsafe_textures_; |
| } |
| - num_uncleared_mips_ -= info->num_uncleared_mips(); |
| + num_uncleared_mips_ -= texture->num_uncleared_mips(); |
| DCHECK_GE(num_uncleared_mips_, 0); |
| - GetMemTracker(info->pool_)->TrackMemFree(info->estimated_size()); |
| - info->SetLevelInfo( |
| + GetMemTracker(texture->pool_)->TrackMemFree(texture->estimated_size()); |
| + texture->SetLevelInfo( |
| feature_info_, target, level, internal_format, width, height, depth, |
| border, format, type, cleared); |
| - GetMemTracker(info->pool_)->TrackMemAlloc(info->estimated_size()); |
| + GetMemTracker(texture->pool_)->TrackMemAlloc(texture->estimated_size()); |
| - num_uncleared_mips_ += info->num_uncleared_mips(); |
| - if (!info->CanRender(feature_info_)) { |
| + num_uncleared_mips_ += texture->num_uncleared_mips(); |
| + if (!texture->CanRender(feature_info_)) { |
| ++num_unrenderable_textures_; |
| } |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| ++num_unsafe_textures_; |
| } |
| } |
| -TextureDefinition* TextureManager::Save(Texture* info) { |
| - DCHECK(info->owned_); |
| +TextureDefinition* TextureManager::Save(Texture* texture) { |
| + DCHECK(texture->owned_); |
| - if (info->IsAttachedToFramebuffer()) |
| + if (texture->IsAttachedToFramebuffer()) |
| return NULL; |
| - TextureDefinition::LevelInfos level_infos(info->level_infos_.size()); |
| + TextureDefinition::LevelInfos level_infos(texture->level_infos_.size()); |
| for (size_t face = 0; face < level_infos.size(); ++face) { |
| - GLenum target = info->target() == GL_TEXTURE_2D ? |
| + GLenum target = texture->target() == GL_TEXTURE_2D ? |
| GL_TEXTURE_2D : FaceIndexToGLTarget(face); |
| - for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { |
| + for (size_t level = 0; level < texture->level_infos_[face].size(); |
| + ++level) { |
| const Texture::LevelInfo& level_info = |
| - info->level_infos_[face][level]; |
| + texture->level_infos_[face][level]; |
| level_infos[face].push_back( |
| TextureDefinition::LevelInfo(target, |
| level_info.internal_format, |
| @@ -957,7 +955,7 @@ TextureDefinition* TextureManager::Save(Texture* info) { |
| level_info.type, |
| level_info.cleared)); |
| - SetLevelInfo(info, |
| + SetLevelInfo(texture, |
| target, |
| level, |
| GL_RGBA, |
| @@ -971,50 +969,54 @@ TextureDefinition* TextureManager::Save(Texture* info) { |
| } |
| } |
| - GLuint old_service_id = info->service_id(); |
| - bool immutable = info->IsImmutable(); |
| + GLuint old_service_id = texture->service_id(); |
| + bool immutable = texture->IsImmutable(); |
| GLuint new_service_id = 0; |
| glGenTextures(1, &new_service_id); |
| - info->SetServiceId(new_service_id); |
| - info->SetImmutable(false); |
| + texture->SetServiceId(new_service_id); |
| + texture->SetImmutable(false); |
| - return new TextureDefinition(info->target(), |
| + return new TextureDefinition(texture->target(), |
| old_service_id, |
| - info->min_filter(), |
| - info->mag_filter(), |
| - info->wrap_s(), |
| - info->wrap_t(), |
| - info->usage(), |
| + texture->min_filter(), |
| + texture->mag_filter(), |
| + texture->wrap_s(), |
| + texture->wrap_t(), |
| + texture->usage(), |
| immutable, |
| level_infos); |
| } |
| -bool TextureManager::Restore(Texture* info, |
| - TextureDefinition* definition) { |
| - DCHECK(info->owned_); |
| +bool TextureManager::Restore( |
| + const char* function_name, |
| + GLES2Decoder* decoder, |
| + Texture* texture, |
| + TextureDefinition* definition) { |
| + DCHECK(texture->owned_); |
| scoped_ptr<TextureDefinition> scoped_definition(definition); |
| - if (info->IsAttachedToFramebuffer()) |
| + if (texture->IsAttachedToFramebuffer()) |
| return false; |
| - if (info->target() != definition->target()) |
| + if (texture->target() != definition->target()) |
| return false; |
| - if (info->level_infos_.size() != definition->level_infos().size()) |
| + if (texture->level_infos_.size() != definition->level_infos().size()) |
| return false; |
| - if (info->level_infos_[0].size() != definition->level_infos()[0].size()) |
| + if (texture->level_infos_[0].size() != definition->level_infos()[0].size()) |
| return false; |
| - for (size_t face = 0; face < info->level_infos_.size(); ++face) { |
| - GLenum target = info->target() == GL_TEXTURE_2D ? |
| + for (size_t face = 0; face < texture->level_infos_.size(); ++face) { |
| + GLenum target = texture->target() == GL_TEXTURE_2D ? |
| GL_TEXTURE_2D : FaceIndexToGLTarget(face); |
| - for (size_t level = 0; level < info->level_infos_[face].size(); ++level) { |
| + for (size_t level = 0; level < texture->level_infos_[face].size(); |
| + ++level) { |
| const TextureDefinition::LevelInfo& level_info = |
| definition->level_infos()[face][level]; |
| - SetLevelInfo(info, |
| + SetLevelInfo(texture, |
| target, |
| level, |
| level_info.internal_format, |
| @@ -1028,61 +1030,82 @@ bool TextureManager::Restore(Texture* info, |
| } |
| } |
| - GLuint old_service_id = info->service_id(); |
| + GLuint old_service_id = texture->service_id(); |
| glDeleteTextures(1, &old_service_id); |
| - info->SetServiceId(definition->ReleaseServiceId()); |
| - info->SetImmutable(definition->immutable()); |
| - SetParameter(info, GL_TEXTURE_MIN_FILTER, definition->min_filter()); |
| - SetParameter(info, GL_TEXTURE_MAG_FILTER, definition->mag_filter()); |
| - SetParameter(info, GL_TEXTURE_WRAP_S, definition->wrap_s()); |
| - SetParameter(info, GL_TEXTURE_WRAP_T, definition->wrap_t()); |
| - SetParameter(info, GL_TEXTURE_USAGE_ANGLE, definition->usage()); |
| + texture->SetServiceId(definition->ReleaseServiceId()); |
| + texture->SetImmutable(definition->immutable()); |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_MIN_FILTER, |
| + definition->min_filter()); |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_MAG_FILTER, |
| + definition->mag_filter()); |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_S, |
| + definition->wrap_s()); |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_WRAP_T, |
| + definition->wrap_t()); |
| + SetParameter(function_name, decoder, texture, GL_TEXTURE_USAGE_ANGLE, |
| + definition->usage()); |
| return true; |
| } |
| -GLenum TextureManager::SetParameter( |
| - Texture* info, GLenum pname, GLint param) { |
| - DCHECK(info); |
| - if (!info->CanRender(feature_info_)) { |
| +void TextureManager::SetParameter( |
| + const char* function_name, GLES2Decoder* decoder, |
| + Texture* texture, GLenum pname, GLint param) { |
| + DCHECK(decoder); |
| + DCHECK(texture); |
| + if (!texture->CanRender(feature_info_)) { |
| DCHECK_NE(0, num_unrenderable_textures_); |
| --num_unrenderable_textures_; |
| } |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| DCHECK_NE(0, num_unsafe_textures_); |
| --num_unsafe_textures_; |
| } |
| - GLenum result = info->SetParameter(feature_info_, pname, param); |
| - if (!info->CanRender(feature_info_)) { |
| + GLenum result = texture->SetParameter(feature_info_, pname, param); |
| + if (result != GL_NO_ERROR) { |
| + if (result == GL_INVALID_ENUM) { |
| + decoder->SetGLErrorInvalidEnum(function_name, param, "param"); |
| + } else { |
| + decoder->SetGLErrorInvalidParam( |
| + result, function_name, pname, static_cast<GLint>(param)); |
| + } |
| + } else { |
| + // Texture tracking pools exist only for the command decoder, so |
| + // do not pass them on to the native GL implementation. |
| + if (pname != GL_TEXTURE_POOL_CHROMIUM) { |
| + glTexParameteri(texture->target(), pname, param); |
| + } |
| + } |
| + |
| + if (!texture->CanRender(feature_info_)) { |
| ++num_unrenderable_textures_; |
| } |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| ++num_unsafe_textures_; |
| } |
| - return result; |
| } |
| -bool TextureManager::MarkMipmapsGenerated(Texture* info) { |
| - DCHECK(info); |
| - if (!info->CanRender(feature_info_)) { |
| +bool TextureManager::MarkMipmapsGenerated(Texture* texture) { |
| + DCHECK(texture); |
| + if (!texture->CanRender(feature_info_)) { |
| DCHECK_NE(0, num_unrenderable_textures_); |
| --num_unrenderable_textures_; |
| } |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| DCHECK_NE(0, num_unsafe_textures_); |
| --num_unsafe_textures_; |
| } |
| - num_uncleared_mips_ -= info->num_uncleared_mips(); |
| + num_uncleared_mips_ -= texture->num_uncleared_mips(); |
| DCHECK_GE(num_uncleared_mips_, 0); |
| - GetMemTracker(info->pool_)->TrackMemFree(info->estimated_size()); |
| - bool result = info->MarkMipmapsGenerated(feature_info_); |
| - GetMemTracker(info->pool_)->TrackMemAlloc(info->estimated_size()); |
| + GetMemTracker(texture->pool_)->TrackMemFree(texture->estimated_size()); |
| + bool result = texture->MarkMipmapsGenerated(feature_info_); |
| + GetMemTracker(texture->pool_)->TrackMemAlloc(texture->estimated_size()); |
| - num_uncleared_mips_ += info->num_uncleared_mips(); |
| - if (!info->CanRender(feature_info_)) { |
| + num_uncleared_mips_ += texture->num_uncleared_mips(); |
| + if (!texture->CanRender(feature_info_)) { |
| ++num_unrenderable_textures_; |
| } |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| ++num_unsafe_textures_; |
| } |
| return result; |
| @@ -1091,18 +1114,18 @@ bool TextureManager::MarkMipmapsGenerated(Texture* info) { |
| Texture* TextureManager::CreateTexture( |
| GLuint client_id, GLuint service_id) { |
| DCHECK_NE(0u, service_id); |
| - scoped_refptr<Texture> info(new Texture(this, service_id)); |
| + scoped_refptr<Texture> texture(new Texture(this, service_id)); |
| std::pair<TextureInfoMap::iterator, bool> result = |
| - texture_infos_.insert(std::make_pair(client_id, info)); |
| + texture_infos_.insert(std::make_pair(client_id, texture)); |
| DCHECK(result.second); |
| - if (!info->CanRender(feature_info_)) { |
| + if (!texture->CanRender(feature_info_)) { |
| ++num_unrenderable_textures_; |
| } |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| ++num_unsafe_textures_; |
| } |
| - num_uncleared_mips_ += info->num_uncleared_mips(); |
| - return info.get(); |
| + num_uncleared_mips_ += texture->num_uncleared_mips(); |
| + return texture.get(); |
| } |
| Texture* TextureManager::GetTexture( |
| @@ -1114,18 +1137,18 @@ Texture* TextureManager::GetTexture( |
| void TextureManager::RemoveTexture(GLuint client_id) { |
| TextureInfoMap::iterator it = texture_infos_.find(client_id); |
| if (it != texture_infos_.end()) { |
| - Texture* info = it->second; |
| - info->MarkAsDeleted(); |
| + Texture* texture = it->second; |
| + texture->MarkAsDeleted(); |
| texture_infos_.erase(it); |
| } |
| } |
| void TextureManager::StartTracking(Texture* /* texture */) { |
| - ++texture_info_count_; |
| + ++texture_count_; |
| } |
| void TextureManager::StopTracking(Texture* texture) { |
| - --texture_info_count_; |
| + --texture_count_; |
| if (!texture->CanRender(feature_info_)) { |
| DCHECK_NE(0, num_unrenderable_textures_); |
| --num_unrenderable_textures_; |
| @@ -1172,39 +1195,39 @@ GLsizei TextureManager::ComputeMipMapCount( |
| } |
| void TextureManager::SetLevelImage( |
| - Texture* info, |
| + Texture* texture, |
| GLenum target, |
| GLint level, |
| gfx::GLImage* image) { |
| - DCHECK(info); |
| - if (!info->CanRender(feature_info_)) { |
| + DCHECK(texture); |
| + if (!texture->CanRender(feature_info_)) { |
| DCHECK_NE(0, num_unrenderable_textures_); |
| --num_unrenderable_textures_; |
| } |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| DCHECK_NE(0, num_unsafe_textures_); |
| --num_unsafe_textures_; |
| } |
| - info->SetLevelImage(feature_info_, target, level, image); |
| - if (!info->CanRender(feature_info_)) { |
| + texture->SetLevelImage(feature_info_, target, level, image); |
| + if (!texture->CanRender(feature_info_)) { |
| ++num_unrenderable_textures_; |
| } |
| - if (!info->SafeToRenderFrom()) { |
| + if (!texture->SafeToRenderFrom()) { |
| ++num_unsafe_textures_; |
| } |
| } |
| void TextureManager::AddToSignature( |
| - Texture* info, |
| + Texture* texture, |
| GLenum target, |
| GLint level, |
| std::string* signature) const { |
| - info->AddToSignature(feature_info_.get(), target, level, signature); |
| + texture->AddToSignature(feature_info_.get(), target, level, signature); |
| } |
| void TextureManager::AddPendingAsyncPixelTransfer( |
| - base::WeakPtr<gfx::AsyncPixelTransferState> state, Texture* info) { |
| - pending_async_transfers_.push_back(PendingAsyncTransfer(state,info)); |
| + base::WeakPtr<gfx::AsyncPixelTransferState> state, Texture* texture) { |
| + pending_async_transfers_.push_back(PendingAsyncTransfer(state,texture)); |
|
apatrick_chromium
2013/03/07 23:22:05
space after comma
|
| } |
| void TextureManager::BindFinishedAsyncPixelTransfers( |