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

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

Issue 2945673002: Allow creating GLImage-backed textures with glTexStorage2D. (Closed)
Patch Set: add test Created 3 years, 6 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 2821 matching lines...) Expand 10 before | Expand all | Expand 10 after
2832 2832
2833 bool BackTexture::AllocateNativeGpuMemoryBuffer(const gfx::Size& size, 2833 bool BackTexture::AllocateNativeGpuMemoryBuffer(const gfx::Size& size,
2834 GLenum format, 2834 GLenum format,
2835 bool zero) { 2835 bool zero) {
2836 DCHECK(format == GL_RGB || format == GL_RGBA); 2836 DCHECK(format == GL_RGB || format == GL_RGBA);
2837 scoped_refptr<gl::GLImage> image = 2837 scoped_refptr<gl::GLImage> image =
2838 decoder_->GetContextGroup()->image_factory()->CreateAnonymousImage( 2838 decoder_->GetContextGroup()->image_factory()->CreateAnonymousImage(
2839 size, 2839 size,
2840 format == GL_RGB ? gfx::BufferFormat::RGBX_8888 2840 format == GL_RGB ? gfx::BufferFormat::RGBX_8888
2841 : gfx::BufferFormat::RGBA_8888, 2841 : gfx::BufferFormat::RGBA_8888,
2842 format); 2842 gfx::BufferUsage::SCANOUT, format);
2843 if (!image || !image->BindTexImage(Target())) 2843 if (!image || !image->BindTexImage(Target()))
2844 return false; 2844 return false;
2845 2845
2846 image_ = image; 2846 image_ = image;
2847 decoder_->texture_manager()->SetLevelInfo( 2847 decoder_->texture_manager()->SetLevelInfo(
2848 texture_ref_.get(), Target(), 0, image_->GetInternalFormat(), 2848 texture_ref_.get(), Target(), 0, image_->GetInternalFormat(),
2849 size.width(), size.height(), 1, 0, image_->GetInternalFormat(), 2849 size.width(), size.height(), 1, 0, image_->GetInternalFormat(),
2850 GL_UNSIGNED_BYTE, gfx::Rect(size)); 2850 GL_UNSIGNED_BYTE, gfx::Rect(size));
2851 decoder_->texture_manager()->SetLevelImage(texture_ref_.get(), Target(), 0, 2851 decoder_->texture_manager()->SetLevelImage(texture_ref_.get(), Target(), 0,
2852 image_.get(), Texture::BOUND); 2852 image_.get(), Texture::BOUND);
(...skipping 14532 matching lines...) Expand 10 before | Expand all | Expand 10 after
17385 Texture* texture = texture_ref->texture(); 17385 Texture* texture = texture_ref->texture();
17386 if (texture->IsAttachedToFramebuffer()) { 17386 if (texture->IsAttachedToFramebuffer()) {
17387 framebuffer_state_.clear_state_dirty = true; 17387 framebuffer_state_.clear_state_dirty = true;
17388 } 17388 }
17389 if (texture->IsImmutable()) { 17389 if (texture->IsImmutable()) {
17390 LOCAL_SET_GL_ERROR( 17390 LOCAL_SET_GL_ERROR(
17391 GL_INVALID_OPERATION, function_name, "texture is immutable"); 17391 GL_INVALID_OPERATION, function_name, "texture is immutable");
17392 return; 17392 return;
17393 } 17393 }
17394 17394
17395 if (texture->buffer_usage() != GL_NONE) {
17396 ScopedGLErrorSuppressor suppressor("GLES2CmdDecoder::TexStorageImpl",
17397 state_.GetErrorState());
17398 gfx::Size size(width, height);
17399 gfx::BufferFormat buffer_format;
17400 GLint real_internal_format;
17401 switch (internal_format) {
17402 case GL_RGBA8_OES:
17403 buffer_format = gfx::BufferFormat::RGBA_8888;
17404 real_internal_format = GL_RGBA;
17405 break;
17406 case GL_BGRA8_EXT:
17407 buffer_format = gfx::BufferFormat::BGRA_8888;
17408 real_internal_format = GL_BGRA_EXT;
17409 break;
17410 case GL_RGBA16F_EXT:
17411 buffer_format = gfx::BufferFormat::RGBA_F16;
17412 real_internal_format = GL_RGBA;
17413 break;
17414 default:
17415 LOCAL_SET_GL_ERROR(GL_INVALID_ENUM, function_name,
17416 "Invalid buffer format");
17417 return;
17418 }
17419
17420 if (levels != 1) {
17421 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
17422 "Levels != 1 for buffer");
17423 return;
17424 }
17425 if (depth > 1) {
17426 LOCAL_SET_GL_ERROR(GL_INVALID_VALUE, function_name,
17427 "depth > 1 for buffer");
17428 return;
17429 }
17430 DCHECK_EQ(GL_TEXTURE_BUFFER_SCANOUT_CHROMIUM, texture->buffer_usage());
17431
17432 gfx::BufferUsage buffer_usage = gfx::BufferUsage::SCANOUT;
17433 scoped_refptr<gl::GLImage> image =
17434 GetContextGroup()->image_factory()->CreateAnonymousImage(
17435 gfx::Size(width, height), buffer_format, buffer_usage,
17436 real_internal_format);
17437 if (!image || !image->BindTexImage(target)) {
17438 LOCAL_SET_GL_ERROR(GL_INVALID_OPERATION, function_name,
17439 "Cannot create GL Image");
17440 return;
17441 }
17442
17443 texture_manager()->SetLevelInfo(
17444 texture_ref, target, 0, image->GetInternalFormat(), width, height, 1, 0,
17445 image->GetInternalFormat(), GL_UNSIGNED_BYTE, gfx::Rect(size));
17446 texture_manager()->SetLevelImage(texture_ref, target, 0, image.get(),
17447 Texture::BOUND);
17448 return;
17449 }
17450
17395 GLenum format = TextureManager::ExtractFormatFromStorageFormat( 17451 GLenum format = TextureManager::ExtractFormatFromStorageFormat(
17396 internal_format); 17452 internal_format);
17397 GLenum type = TextureManager::ExtractTypeFromStorageFormat(internal_format); 17453 GLenum type = TextureManager::ExtractTypeFromStorageFormat(internal_format);
17398 17454
17399 std::vector<int32_t> level_size(levels); 17455 std::vector<int32_t> level_size(levels);
17400 { 17456 {
17401 GLsizei level_width = width; 17457 GLsizei level_width = width;
17402 GLsizei level_height = height; 17458 GLsizei level_height = height;
17403 GLsizei level_depth = depth; 17459 GLsizei level_depth = depth;
17404 base::CheckedNumeric<uint32_t> estimated_size(0); 17460 base::CheckedNumeric<uint32_t> estimated_size(0);
(...skipping 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after
19704 } 19760 }
19705 19761
19706 // Include the auto-generated part of this file. We split this because it means 19762 // Include the auto-generated part of this file. We split this because it means
19707 // we can easily edit the non-auto generated parts right here in this file 19763 // we can easily edit the non-auto generated parts right here in this file
19708 // instead of having to edit some template or the code generator. 19764 // instead of having to edit some template or the code generator.
19709 #include "base/macros.h" 19765 #include "base/macros.h"
19710 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 19766 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
19711 19767
19712 } // namespace gles2 19768 } // namespace gles2
19713 } // namespace gpu 19769 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698