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

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

Issue 2945673002: Allow creating GLImage-backed textures with glTexStorage2D. (Closed)
Patch Set: fix unittests Created 3 years, 4 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
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 <limits.h> 7 #include <limits.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 2816 matching lines...) Expand 10 before | Expand all | Expand 10 after
2827 2827
2828 bool BackTexture::AllocateNativeGpuMemoryBuffer(const gfx::Size& size, 2828 bool BackTexture::AllocateNativeGpuMemoryBuffer(const gfx::Size& size,
2829 GLenum format, 2829 GLenum format,
2830 bool zero) { 2830 bool zero) {
2831 DCHECK(format == GL_RGB || format == GL_RGBA); 2831 DCHECK(format == GL_RGB || format == GL_RGBA);
2832 scoped_refptr<gl::GLImage> image = 2832 scoped_refptr<gl::GLImage> image =
2833 decoder_->GetContextGroup()->image_factory()->CreateAnonymousImage( 2833 decoder_->GetContextGroup()->image_factory()->CreateAnonymousImage(
2834 size, 2834 size,
2835 format == GL_RGB ? gfx::BufferFormat::RGBX_8888 2835 format == GL_RGB ? gfx::BufferFormat::RGBX_8888
2836 : gfx::BufferFormat::RGBA_8888, 2836 : gfx::BufferFormat::RGBA_8888,
2837 format); 2837 gfx::BufferUsage::SCANOUT, format);
2838 if (!image || !image->BindTexImage(Target())) 2838 if (!image || !image->BindTexImage(Target()))
2839 return false; 2839 return false;
2840 2840
2841 image_ = image; 2841 image_ = image;
2842 decoder_->texture_manager()->SetLevelInfo( 2842 decoder_->texture_manager()->SetLevelInfo(
2843 texture_ref_.get(), Target(), 0, image_->GetInternalFormat(), 2843 texture_ref_.get(), Target(), 0, image_->GetInternalFormat(),
2844 size.width(), size.height(), 1, 0, image_->GetInternalFormat(), 2844 size.width(), size.height(), 1, 0, image_->GetInternalFormat(),
2845 GL_UNSIGNED_BYTE, gfx::Rect(size)); 2845 GL_UNSIGNED_BYTE, gfx::Rect(size));
2846 decoder_->texture_manager()->SetLevelImage(texture_ref_.get(), Target(), 0, 2846 decoder_->texture_manager()->SetLevelImage(texture_ref_.get(), Target(), 0,
2847 image_.get(), Texture::BOUND); 2847 image_.get(), Texture::BOUND);
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
3862 caps.disable_webgl_rgb_multisampling_usage = 3862 caps.disable_webgl_rgb_multisampling_usage =
3863 workarounds().disable_webgl_rgb_multisampling_usage; 3863 workarounds().disable_webgl_rgb_multisampling_usage;
3864 caps.software_to_accelerated_canvas_upgrade = 3864 caps.software_to_accelerated_canvas_upgrade =
3865 !workarounds().disable_software_to_accelerated_canvas_upgrade; 3865 !workarounds().disable_software_to_accelerated_canvas_upgrade;
3866 caps.emulate_rgb_buffer_with_rgba = 3866 caps.emulate_rgb_buffer_with_rgba =
3867 workarounds().disable_gl_rgb_format; 3867 workarounds().disable_gl_rgb_format;
3868 if (workarounds().disable_non_empty_post_sub_buffers_for_onscreen_surfaces && 3868 if (workarounds().disable_non_empty_post_sub_buffers_for_onscreen_surfaces &&
3869 !surface_->IsOffscreen()) { 3869 !surface_->IsOffscreen()) {
3870 caps.disable_non_empty_post_sub_buffers = true; 3870 caps.disable_non_empty_post_sub_buffers = true;
3871 } 3871 }
3872 caps.texture_buffer_chromium =
3873 feature_info_->feature_flags().chromium_texture_buffer;
3872 3874
3873 return caps; 3875 return caps;
3874 } 3876 }
3875 3877
3876 void GLES2DecoderImpl::UpdateCapabilities() { 3878 void GLES2DecoderImpl::UpdateCapabilities() {
3877 util_.set_num_compressed_texture_formats( 3879 util_.set_num_compressed_texture_formats(
3878 validators_->compressed_texture_format.GetValues().size()); 3880 validators_->compressed_texture_format.GetValues().size());
3879 util_.set_num_shader_binary_formats( 3881 util_.set_num_shader_binary_formats(
3880 validators_->shader_binary_format.GetValues().size()); 3882 validators_->shader_binary_format.GetValues().size());
3881 } 3883 }
(...skipping 7067 matching lines...) Expand 10 before | Expand all | Expand 10 after
10949 iparams[0] = texture->swizzle_b(); 10951 iparams[0] = texture->swizzle_b();
10950 } 10952 }
10951 return; 10953 return;
10952 case GL_TEXTURE_SWIZZLE_A: 10954 case GL_TEXTURE_SWIZZLE_A:
10953 if (fparams) { 10955 if (fparams) {
10954 fparams[0] = static_cast<GLfloat>(texture->swizzle_a()); 10956 fparams[0] = static_cast<GLfloat>(texture->swizzle_a());
10955 } else { 10957 } else {
10956 iparams[0] = texture->swizzle_a(); 10958 iparams[0] = texture->swizzle_a();
10957 } 10959 }
10958 return; 10960 return;
10961 case GL_TEXTURE_BUFFER_USAGE_CHROMIUM:
10962 if (fparams) {
10963 fparams[0] = static_cast<GLfloat>(texture->buffer_usage());
10964 } else {
10965 iparams[0] = texture->buffer_usage();
10966 }
10967 return;
10959 default: 10968 default:
10960 break; 10969 break;
10961 } 10970 }
10962 if (fparams) { 10971 if (fparams) {
10963 glGetTexParameterfv(target, pname, fparams); 10972 glGetTexParameterfv(target, pname, fparams);
10964 } else { 10973 } else {
10965 glGetTexParameteriv(target, pname, iparams); 10974 glGetTexParameteriv(target, pname, iparams);
10966 } 10975 }
10967 } 10976 }
10968 10977
(...skipping 6559 matching lines...) Expand 10 before | Expand all | Expand 10 after
17528 Texture* texture = texture_ref->texture(); 17537 Texture* texture = texture_ref->texture();
17529 if (texture->IsAttachedToFramebuffer()) { 17538 if (texture->IsAttachedToFramebuffer()) {
17530 framebuffer_state_.clear_state_dirty = true; 17539 framebuffer_state_.clear_state_dirty = true;
17531 } 17540 }
17532 if (texture->IsImmutable()) { 17541 if (texture->IsImmutable()) {
17533 LOCAL_SET_GL_ERROR( 17542 LOCAL_SET_GL_ERROR(
17534 GL_INVALID_OPERATION, function_name, "texture is immutable"); 17543 GL_INVALID_OPERATION, function_name, "texture is immutable");
17535 return; 17544 return;
17536 } 17545 }
17537 17546
17547 if (texture->buffer_usage() != GL_NONE) {
17548 ScopedGLErrorSuppressor suppressor("GLES2CmdDecoder::TexStorageImpl",
17549 state_.GetErrorState());
17550 gfx::Size size(width, height);
17551 gfx::BufferFormat buffer_format;
17552 GLint real_internal_format;
17553 switch (internal_format) {
17554 case GL_RGBA8_OES:
17555 buffer_format = gfx::BufferFormat::RGBA_8888;
17556 real_internal_format = GL_RGBA;
17557 break;
17558 case GL_BGRA8_EXT:
17559 buffer_format = gfx::BufferFormat::BGRA_8888;
17560 real_internal_format = GL_BGRA_EXT;
17561 break;
17562 case GL_RGBA16F_EXT:
17563 buffer_format = gfx::BufferFormat::RGBA_F16;
17564 real_internal_format = GL_RGBA;
17565 break;
17566 default:
17567 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, function_name,
17568 "Invalid buffer format");
17569 return;
17570 }
17571
17572 if (levels != 1) {
17573 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
17574 "Levels != 1 for buffer");
17575 return;
17576 }
17577 if (depth > 1) {
17578 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
17579 "depth > 1 for buffer");
17580 return;
17581 }
17582 DCHECK_EQ(GL_TEXTURE_BUFFER_SCANOUT_CHROMIUM, texture->buffer_usage());
17583
17584 gfx::BufferUsage buffer_usage = gfx::BufferUsage::SCANOUT;
17585 scoped_refptr<gl::GLImage> image =
17586 GetContextGroup()->image_factory()->CreateAnonymousImage(
17587 gfx::Size(width, height), buffer_format, buffer_usage,
17588 real_internal_format);
17589 if (!image || !image->BindTexImage(target)) {
17590 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
17591 "Cannot create GL Image");
17592 return;
17593 }
17594
17595 texture_manager()->SetLevelInfo(
17596 texture_ref, target, 0, image->GetInternalFormat(), width, height, 1, 0,
17597 image->GetInternalFormat(), GL_UNSIGNED_BYTE, gfx::Rect(size));
17598 texture_manager()->SetLevelImage(texture_ref, target, 0, image.get(),
17599 Texture::BOUND);
17600 return;
17601 }
17602
17538 GLenum format = TextureManager::ExtractFormatFromStorageFormat( 17603 GLenum format = TextureManager::ExtractFormatFromStorageFormat(
17539 internal_format); 17604 internal_format);
17540 GLenum type = TextureManager::ExtractTypeFromStorageFormat(internal_format); 17605 GLenum type = TextureManager::ExtractTypeFromStorageFormat(internal_format);
17541 17606
17542 std::vector<int32_t> level_size(levels); 17607 std::vector<int32_t> level_size(levels);
17543 { 17608 {
17544 GLsizei level_width = width; 17609 GLsizei level_width = width;
17545 GLsizei level_height = height; 17610 GLsizei level_height = height;
17546 GLsizei level_depth = depth; 17611 GLsizei level_depth = depth;
17547 base::CheckedNumeric<uint32_t> estimated_size(0); 17612 base::CheckedNumeric<uint32_t> estimated_size(0);
(...skipping 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after
19847 } 19912 }
19848 19913
19849 // Include the auto-generated part of this file. We split this because it means 19914 // Include the auto-generated part of this file. We split this because it means
19850 // we can easily edit the non-auto generated parts right here in this file 19915 // we can easily edit the non-auto generated parts right here in this file
19851 // instead of having to edit some template or the code generator. 19916 // instead of having to edit some template or the code generator.
19852 #include "base/macros.h" 19917 #include "base/macros.h"
19853 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 19918 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
19854 19919
19855 } // namespace gles2 19920 } // namespace gles2
19856 } // namespace gpu 19921 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698