Skip to content

Commit

Permalink
viz: Move TextureToStorageFormat into util
Browse files Browse the repository at this point in the history
This will be used by local resources.

BUG=738190

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I7e63f0d893b6ef23d38ca8b839c0caecd8295c59
Reviewed-on: https://chromium-review.googlesource.com/753002
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Xing Xu <xing.xu@intel.com>
Cr-Commit-Position: refs/heads/master@{#514353}
  • Loading branch information
axinging authored and Commit Bot committed Nov 7, 2017
1 parent c6c63ff commit dfc8eee
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
33 changes: 2 additions & 31 deletions cc/resources/resource_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,35 +89,6 @@ class TextureIdAllocator {

namespace {

GLenum TextureStorageFormat(viz::ResourceFormat format) {
switch (format) {
case viz::RGBA_8888:
return GL_RGBA8_OES;
case viz::BGRA_8888:
return GL_BGRA8_EXT;
case viz::RGBA_F16:
return GL_RGBA16F_EXT;
case viz::RGBA_4444:
return GL_RGBA4;
case viz::ALPHA_8:
return GL_ALPHA8_EXT;
case viz::LUMINANCE_8:
return GL_LUMINANCE8_EXT;
case viz::RGB_565:
return GL_RGB565;
case viz::RED_8:
return GL_R8_EXT;
case viz::LUMINANCE_F16:
return GL_LUMINANCE16F_EXT;
case viz::R16_EXT:
return GL_R16_EXT;
case viz::ETC1:
break;
}
NOTREACHED();
return GL_RGBA8_OES;
}

class ScopedSetActiveTexture {
public:
ScopedSetActiveTexture(GLES2Interface* gl, GLenum unit)
Expand Down Expand Up @@ -864,7 +835,7 @@ void ResourceProvider::ScopedWriteLockGL::LazyAllocate(

if (is_overlay_) {
DCHECK(settings.use_texture_storage_image);
gl->TexStorage2DImageCHROMIUM(target_, TextureStorageFormat(format_),
gl->TexStorage2DImageCHROMIUM(target_, viz::TextureStorageFormat(format_),
GL_SCANOUT_CHROMIUM, size_.width(),
size_.height());
if (color_space_.IsValid()) {
Expand All @@ -877,7 +848,7 @@ void ResourceProvider::ScopedWriteLockGL::LazyAllocate(
(hint_ & ResourceProvider::TEXTURE_HINT_MIPMAP)) {
levels += base::bits::Log2Floor(std::max(size_.width(), size_.height()));
}
gl->TexStorage2DEXT(target_, levels, TextureStorageFormat(format_),
gl->TexStorage2DEXT(target_, levels, viz::TextureStorageFormat(format_),
size_.width(), size_.height());
} else {
gl->TexImage2D(target_, 0, GLInternalFormat(format_), size_.width(),
Expand Down
29 changes: 29 additions & 0 deletions components/viz/common/resources/resource_format_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,33 @@ bool DoesResourceFormatSupportAlpha(ResourceFormat format) {
return false;
}

unsigned int TextureStorageFormat(ResourceFormat format) {
switch (format) {
case RGBA_8888:
return GL_RGBA8_OES;
case BGRA_8888:
return GL_BGRA8_EXT;
case RGBA_F16:
return GL_RGBA16F_EXT;
case RGBA_4444:
return GL_RGBA4;
case ALPHA_8:
return GL_ALPHA8_EXT;
case LUMINANCE_8:
return GL_LUMINANCE8_EXT;
case RGB_565:
return GL_RGB565;
case RED_8:
return GL_R8_EXT;
case LUMINANCE_F16:
return GL_LUMINANCE16F_EXT;
case R16_EXT:
return GL_R16_EXT;
case ETC1:
break;
}
NOTREACHED();
return GL_RGBA8_OES;
}

} // namespace viz
2 changes: 2 additions & 0 deletions components/viz/common/resources/resource_format_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ VIZ_RESOURCE_FORMAT_EXPORT bool IsResourceFormatCompressed(
ResourceFormat format);
VIZ_RESOURCE_FORMAT_EXPORT bool DoesResourceFormatSupportAlpha(
ResourceFormat format);
VIZ_RESOURCE_FORMAT_EXPORT unsigned int TextureStorageFormat(
ResourceFormat format);
VIZ_RESOURCE_FORMAT_EXPORT GrPixelConfig ToGrPixelConfig(ResourceFormat format);

} // namespace viz
Expand Down

0 comments on commit dfc8eee

Please sign in to comment.