Commit a36c7238 authored by Antoine Labour's avatar Antoine Labour Committed by Commit Bot

gpu: Introduce SharedImageFactory

This is a servce-side class that can create shared images in the form of
mailboxes. This is the service-side implementation of the upcoming
SharedImageInterface, which is a stateless and thread-safe API to create
such shared images from the client side (introduced in a follow-up).

Bug: 870116

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Id0db4300a57e02ccbd46b5b328b534d8cd3f2dc8
Reviewed-on: https://chromium-review.googlesource.com/1159384Reviewed-by: default avatarVictor Miura <vmiura@chromium.org>
Commit-Queue: Antoine Labour <piman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580065}
parent f4a65172
......@@ -173,6 +173,7 @@ static_library("test_support") {
test("gl_tests") {
sources = [
"command_buffer/service/shared_image_factory_unittest.cc",
"command_buffer/tests/compressed_texture_test.cc",
"command_buffer/tests/es3_misc_functions_unittest.cc",
"command_buffer/tests/gl_apply_screen_space_antialiasing_CHROMIUM_unittest.cc",
......
......@@ -79,6 +79,7 @@ source_set("common_sources") {
"mailbox_holder.h",
"scheduling_priority.cc",
"scheduling_priority.h",
"shared_image_usage.h",
"swap_buffers_complete_params.cc",
"swap_buffers_complete_params.h",
"swap_buffers_flags.h",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GPU_COMMAND_BUFFER_COMMON_SHARED_IMAGE_USAGE_H_
#define GPU_COMMAND_BUFFER_COMMON_SHARED_IMAGE_USAGE_H_
#include <stdint.h>
namespace gpu {
enum SharedImageUsage : uint32_t {
// Image will be used in GLES2Interface
SHARED_IMAGE_USAGE_GLES2 = 1 << 0,
// Image will be used as a framebuffer (hint)
SHARED_IMAGE_USAGE_GLES2_FRAMEBUFFER_HINT = 1 << 1,
// Image will be used in RasterInterface
SHARED_IMAGE_USAGE_RASTER = 1 << 2,
// Image will be used in Display
SHARED_IMAGE_USAGE_DISPLAY = 1 << 3,
// Image will be used as a scanout buffer (overlay)
SHARED_IMAGE_USAGE_SCANOUT = 1 << 4,
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_COMMON_SHARED_IMAGE_USAGE_H_
......@@ -216,6 +216,8 @@ target(link_target_type, "gles2_sources") {
"shader_translator.h",
"shader_translator_cache.cc",
"shader_translator_cache.h",
"shared_image_factory.cc",
"shared_image_factory.h",
"texture_definition.cc",
"texture_definition.h",
"texture_manager.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/command_buffer/service/shared_image_factory.h"
#include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include "gpu/command_buffer/service/image_factory.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/memory_tracking.h"
#include "gpu/command_buffer/service/service_utils.h"
#include "gpu/config/gpu_preferences.h"
#include "ui/gfx/color_space.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gl/gl_bindings.h"
namespace gpu {
SharedImageFactory::SharedImageFactory(
const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
MailboxManager* mailbox_manager,
ImageFactory* image_factory,
gles2::MemoryTracker* tracker)
: use_passthrough_(gpu_preferences.use_passthrough_cmd_decoder &&
gles2::PassthroughCommandDecoderSupported()),
mailbox_manager_(mailbox_manager),
image_factory_(image_factory),
memory_tracker_(std::make_unique<gles2::MemoryTypeTracker>(tracker)) {
gl::GLApi* api = gl::g_current_gl_context;
api->glGetIntegervFn(GL_MAX_TEXTURE_SIZE, &max_texture_size_);
if (workarounds.max_texture_size) {
max_texture_size_ =
std::min(max_texture_size_, workarounds.max_texture_size);
}
// TODO(piman): Can we extract the logic out of FeatureInfo?
scoped_refptr<gles2::FeatureInfo> feature_info =
new gles2::FeatureInfo(workarounds, gpu_feature_info);
feature_info->Initialize(ContextType::CONTEXT_TYPE_OPENGLES2,
use_passthrough_, gles2::DisallowedFeatures());
texture_usage_angle_ = feature_info->feature_flags().angle_texture_usage;
es3_capable_ = feature_info->IsES3Capable();
bool enable_texture_storage =
feature_info->feature_flags().ext_texture_storage;
bool enable_scanout_images =
(image_factory_ && image_factory_->SupportsCreateAnonymousImage());
const gles2::Validators* validators = feature_info->validators();
for (int i = 0; i <= viz::RESOURCE_FORMAT_MAX; ++i) {
auto format = static_cast<viz::ResourceFormat>(i);
FormatInfo& info = format_info_[i];
// TODO(piman): do we need to support ETC1?
if (!viz::GLSupportsFormat(format) ||
viz::IsResourceFormatCompressed(format))
continue;
if (enable_texture_storage) {
GLuint internal_format = viz::TextureStorageFormat(format);
if (validators->texture_internal_format_storage.IsValid(
internal_format)) {
info.enabled = true;
info.use_storage = true;
info.internal_format = internal_format;
info.gl_format = gles2::TextureManager::ExtractFormatFromStorageFormat(
info.internal_format);
info.gl_type = gles2::TextureManager::ExtractTypeFromStorageFormat(
internal_format);
info.swizzle = gles2::TextureManager::GetCompatibilitySwizzle(
feature_info.get(), info.gl_format);
info.adjusted_internal_format =
gles2::TextureManager::AdjustTexStorageFormat(feature_info.get(),
internal_format);
}
}
if (!info.enabled) {
GLuint internal_format = viz::GLInternalFormat(format);
GLenum gl_format = viz::GLDataFormat(format);
GLenum gl_type = viz::GLDataType(format);
if (validators->texture_internal_format.IsValid(internal_format) &&
validators->texture_format.IsValid(gl_format) &&
validators->pixel_type.IsValid(gl_type)) {
info.enabled = true;
info.use_storage = false;
info.internal_format = internal_format;
info.gl_format = gl_format;
info.gl_type = gl_type;
info.swizzle = gles2::TextureManager::GetCompatibilitySwizzle(
feature_info.get(), gl_format);
info.adjusted_internal_format =
gles2::TextureManager::AdjustTexInternalFormat(
feature_info.get(), internal_format);
info.adjusted_format = gles2::TextureManager::AdjustTexFormat(
feature_info.get(), gl_format);
}
}
if (!info.enabled || !enable_scanout_images)
continue;
gfx::BufferFormat buffer_format = viz::BufferFormat(format);
switch (buffer_format) {
case gfx::BufferFormat::RGBA_8888:
case gfx::BufferFormat::BGRA_8888:
case gfx::BufferFormat::RGBA_F16:
case gfx::BufferFormat::R_8:
break;
default:
continue;
}
info.allow_scanout = true;
info.buffer_format = buffer_format;
if (base::ContainsValue(
gpu_preferences.texture_target_exception_list,
gfx::BufferUsageAndFormat(gfx::BufferUsage::SCANOUT, buffer_format)))
info.target_for_scanout = gpu::GetPlatformSpecificTextureTarget();
}
}
SharedImageFactory::~SharedImageFactory() {
DCHECK(mailboxes_.empty());
DCHECK(passthrough_textures_.empty());
}
bool SharedImageFactory::CreateSharedImage(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage) {
if (mailboxes_.find(mailbox) != mailboxes_.end()) {
LOG(ERROR) << "CreateSharedImage: mailbox already exists";
return false;
}
const FormatInfo& format_info = format_info_[format];
if (!format_info.enabled) {
LOG(ERROR) << "CreateSharedImage: invalid format";
return false;
}
const bool use_buffer = usage & SHARED_IMAGE_USAGE_SCANOUT;
if (use_buffer && !format_info.allow_scanout) {
LOG(ERROR) << "CreateSharedImage: SCANOUT shared images unavailable";
return false;
}
if (size.width() < 1 || size.height() < 1 ||
size.width() > max_texture_size_ || size.height() > max_texture_size_) {
LOG(ERROR) << "CreateSharedImage: invalid size";
return false;
}
GLenum target = use_buffer ? GL_TEXTURE_2D : format_info.target_for_scanout;
GLenum get_target = GL_TEXTURE_BINDING_2D;
switch (target) {
case GL_TEXTURE_2D:
get_target = GL_TEXTURE_BINDING_2D;
break;
case GL_TEXTURE_RECTANGLE_ARB:
get_target = GL_TEXTURE_BINDING_RECTANGLE_ARB;
break;
case GL_TEXTURE_EXTERNAL_OES:
get_target = GL_TEXTURE_BINDING_EXTERNAL_OES;
break;
default:
NOTREACHED();
break;
}
gl::GLApi* api = gl::g_current_gl_context;
GLuint service_id = 0;
api->glGenTexturesFn(1, &service_id);
GLint old_texture_binding = 0;
api->glGetIntegervFn(get_target, &old_texture_binding);
api->glBindTextureFn(target, service_id);
api->glTexParameteriFn(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
api->glTexParameteriFn(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
const bool for_framebuffer_attachment =
(usage & (SHARED_IMAGE_USAGE_RASTER |
SHARED_IMAGE_USAGE_GLES2_FRAMEBUFFER_HINT)) != 0;
if (for_framebuffer_attachment && texture_usage_angle_) {
api->glTexParameteriFn(target, GL_TEXTURE_USAGE_ANGLE,
GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
}
gfx::Rect cleared_rect;
scoped_refptr<gl::GLImage> image;
GLuint internal_format = format_info.internal_format;
if (use_buffer) {
bool is_cleared = false;
image = image_factory_->CreateAnonymousImage(
size, format_info.buffer_format, gfx::BufferUsage::SCANOUT,
format_info.gl_format, &is_cleared);
if (!image || !image->BindTexImage(target)) {
LOG(ERROR) << "CreateSharedImage: Failed to create image";
api->glBindTextureFn(target, old_texture_binding);
api->glDeleteTexturesFn(1, &service_id);
return false;
}
if (is_cleared)
cleared_rect = gfx::Rect(size);
internal_format = image->GetInternalFormat();
if (color_space.IsValid())
image->SetColorSpace(color_space);
} else if (format_info.use_storage) {
api->glTexStorage2DEXTFn(target, 1, format_info.adjusted_internal_format,
size.width(), size.height());
} else {
// Need to unbind any GL_PIXEL_UNPACK_BUFFER for the nullptr in glTexImage2D
// to mean "no pixels" (as opposed to offset 0 in the buffer).
GLint bound_pixel_unpack_buffer = 0;
if (es3_capable_) {
api->glGetIntegervFn(GL_PIXEL_UNPACK_BUFFER_BINDING,
&bound_pixel_unpack_buffer);
if (bound_pixel_unpack_buffer)
api->glBindBufferFn(GL_PIXEL_UNPACK_BUFFER, 0);
}
api->glTexImage2DFn(target, 0, format_info.adjusted_internal_format,
size.width(), size.height(), 0,
format_info.adjusted_format, format_info.gl_type,
nullptr);
if (bound_pixel_unpack_buffer)
api->glBindBufferFn(GL_PIXEL_UNPACK_BUFFER, bound_pixel_unpack_buffer);
}
if (use_passthrough_) {
auto texture =
base::MakeRefCounted<gles2::TexturePassthrough>(service_id, target);
if (image)
texture->SetLevelImage(target, 0, image.get());
mailbox_manager_->ProduceTexture(mailbox, texture.get());
passthrough_textures_.insert(std::move(texture));
} else {
gles2::Texture* texture = new gles2::Texture(service_id);
texture->SetLightweightRef(memory_tracker_.get());
texture->SetTarget(target, 1);
texture->SetLevelInfo(target, 0, internal_format, size.width(),
size.height(), 1, 0, format_info.gl_format,
format_info.gl_type, cleared_rect);
if (format_info.swizzle)
texture->SetCompatibilitySwizzle(format_info.swizzle);
if (image)
texture->SetLevelImage(target, 0, image.get(), gles2::Texture::BOUND);
texture->SetImmutable(true);
mailbox_manager_->ProduceTexture(mailbox, texture);
}
api->glBindTextureFn(target, old_texture_binding);
mailboxes_.insert(mailbox);
return true;
}
bool SharedImageFactory::DestroySharedImage(const Mailbox& mailbox) {
auto it = mailboxes_.find(mailbox);
if (it == mailboxes_.end()) {
LOG(ERROR) << "Could not find shared image mailbox";
return false;
}
TextureBase* texture_base = mailbox_manager_->ConsumeTexture(mailbox);
DCHECK(texture_base);
if (use_passthrough_) {
scoped_refptr<gles2::TexturePassthrough> texture(
static_cast<gles2::TexturePassthrough*>(texture_base));
size_t count = passthrough_textures_.erase(texture);
DCHECK_EQ(count, 1u);
} else {
auto* texture = static_cast<gles2::Texture*>(texture_base);
texture->RemoveLightweightRef(true);
// Texture may have been deleted at this point.
}
mailboxes_.erase(it);
return true;
}
void SharedImageFactory::DestroyAllSharedImages(bool have_context) {
if (use_passthrough_) {
if (!have_context) {
for (auto& texture : passthrough_textures_)
texture->MarkContextLost();
}
passthrough_textures_.clear();
} else {
for (const auto& mailbox : mailboxes_) {
auto* texture = static_cast<gles2::Texture*>(
mailbox_manager_->ConsumeTexture(mailbox));
DCHECK(texture);
texture->RemoveLightweightRef(have_context);
}
}
mailboxes_.clear();
}
SharedImageFactory::FormatInfo::FormatInfo() = default;
SharedImageFactory::FormatInfo::~FormatInfo() = default;
} // namespace gpu
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_FACTORY_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_FACTORY_H_
#include <memory>
#include "base/containers/flat_set.h"
#include "base/memory/scoped_refptr.h"
#include "components/viz/common/resources/resource_format.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/gpu_gles2_export.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gl/gl_bindings.h"
namespace gfx {
class Size;
class ColorSpace;
} // namespace gfx
namespace gpu {
class GpuDriverBugWorkarounds;
struct GpuFeatureInfo;
struct GpuPreferences;
class ImageFactory;
class MailboxManager;
namespace gles2 {
class MemoryTracker;
class MemoryTypeTracker;
class TexturePassthrough;
}; // namespace gles2
class GPU_GLES2_EXPORT SharedImageFactory {
public:
SharedImageFactory(const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds,
const GpuFeatureInfo& gpu_feature_info,
MailboxManager* mailbox_manager,
ImageFactory* image_factory,
gles2::MemoryTracker* tracker);
~SharedImageFactory();
bool CreateSharedImage(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
uint32_t usage);
bool DestroySharedImage(const Mailbox& mailbox);
bool HasImages() const { return !mailboxes_.empty(); }
void DestroyAllSharedImages(bool have_context);
private:
struct FormatInfo {
FormatInfo();
~FormatInfo();
// Whether this format is supported.
bool enabled = false;
// Whether to use glTexStorage2D or glTexImage2D.
bool use_storage = false;
// Whether to allow SHARED_IMAGE_USAGE_SCANOUT.
bool allow_scanout = false;
// GL internal_format/format/type triplet.
GLuint internal_format = 0;
GLenum gl_format = 0;
GLenum gl_type = 0;
const gles2::Texture::CompatibilitySwizzle* swizzle = nullptr;
GLuint adjusted_internal_format = 0;
GLenum adjusted_format = 0;
// GL target to use for scanout images.
GLenum target_for_scanout = GL_TEXTURE_2D;
// BufferFormat for scanout images.
gfx::BufferFormat buffer_format = gfx::BufferFormat::RGBA_8888;
};
bool use_passthrough_;
MailboxManager* mailbox_manager_;
ImageFactory* image_factory_;
std::unique_ptr<gles2::MemoryTypeTracker> memory_tracker_;
FormatInfo format_info_[viz::RESOURCE_FORMAT_MAX + 1];
int32_t max_texture_size_ = 0;
bool texture_usage_angle_ = false;
bool es3_capable_ = false;
// Mailboxes that have been created by the SharedImageFactory. If not using
// passthrough, the textures pointed to by these mailboxes are kept alive with
// a lightweight ref.
base::flat_set<Mailbox> mailboxes_;
// Textures created by the SharedImageFactory, if using passthrough, to keep
// them alive.
base::flat_set<scoped_refptr<gles2::TexturePassthrough>>
passthrough_textures_;
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_FACTORY_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/command_buffer/service/shared_image_factory.h"
#include "gpu/command_buffer/common/gpu_memory_buffer_support.h"
#include "gpu/command_buffer/common/mailbox.h"
#include "gpu/command_buffer/common/shared_image_usage.h"
#include "gpu/command_buffer/service/mailbox_manager_impl.h"
#include "gpu/command_buffer/service/service_utils.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/command_buffer/tests/texture_image_factory.h"
#include "gpu/config/gpu_driver_bug_workarounds.h"
#include "gpu/config/gpu_feature_info.h"
#include "gpu/config/gpu_preferences.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/color_space.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_surface.h"
#include "ui/gl/init/gl_factory.h"
namespace gpu {
namespace {
class SharedImageFactoryTest : public testing::TestWithParam<bool> {
public:
void SetUp() override {
surface_ = gl::init::CreateOffscreenGLSurface(gfx::Size());
ASSERT_TRUE(surface_);
context_ = gl::init::CreateGLContext(nullptr, surface_.get(),
gl::GLContextAttribs());
ASSERT_TRUE(context_);
bool result = context_->MakeCurrent(surface_.get());
ASSERT_TRUE(result);
GpuPreferences preferences;
preferences.use_passthrough_cmd_decoder = use_passthrough();
GpuDriverBugWorkarounds workarounds;
workarounds.max_texture_size = INT_MAX - 1;
factory_ = std::make_unique<SharedImageFactory>(
preferences, workarounds, GpuFeatureInfo(), &mailbox_manager_,
&image_factory_, nullptr);
}
void TearDown() override {
factory_->DestroyAllSharedImages(true);
factory_.reset();
}
bool use_passthrough() {
return GetParam() && gles2::PassthroughCommandDecoderSupported();
}
protected:
scoped_refptr<gl::GLSurface> surface_;
scoped_refptr<gl::GLContext> context_;
gles2::MailboxManagerImpl mailbox_manager_;
TextureImageFactory image_factory_;
std::unique_ptr<SharedImageFactory> factory_;
};
TEST_P(SharedImageFactoryTest, Basic) {
auto mailbox = Mailbox::Generate();
auto format = viz::ResourceFormat::RGBA_8888;
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
EXPECT_TRUE(
factory_->CreateSharedImage(mailbox, format, size, color_space, usage));
TextureBase* texture_base = mailbox_manager_.ConsumeTexture(mailbox);
ASSERT_TRUE(texture_base);
GLenum expected_target = GL_TEXTURE_2D;
EXPECT_EQ(texture_base->target(), expected_target);
if (!use_passthrough()) {
auto* texture = static_cast<gles2::Texture*>(texture_base);
EXPECT_TRUE(texture->IsImmutable());
int width, height, depth;
bool has_level =
texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, &depth);
EXPECT_TRUE(has_level);
EXPECT_EQ(width, size.width());
EXPECT_EQ(height, size.height());
}
EXPECT_TRUE(factory_->DestroySharedImage(mailbox));
EXPECT_FALSE(mailbox_manager_.ConsumeTexture(mailbox));
}
TEST_P(SharedImageFactoryTest, Image) {
auto mailbox = Mailbox::Generate();
auto format = viz::ResourceFormat::RGBA_8888;
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_SCANOUT;
EXPECT_TRUE(
factory_->CreateSharedImage(mailbox, format, size, color_space, usage));
TextureBase* texture_base = mailbox_manager_.ConsumeTexture(mailbox);
ASSERT_TRUE(texture_base);
GLenum target = texture_base->target();
scoped_refptr<gl::GLImage> image;
if (use_passthrough()) {
auto* texture = static_cast<gles2::TexturePassthrough*>(texture_base);
image = texture->GetLevelImage(target, 0);
} else {
auto* texture = static_cast<gles2::Texture*>(texture_base);
image = texture->GetLevelImage(target, 0);
}
ASSERT_TRUE(image);
EXPECT_EQ(size, image->GetSize());
}
TEST_P(SharedImageFactoryTest, DuplicateMailbox) {
auto mailbox = Mailbox::Generate();
auto format = viz::ResourceFormat::RGBA_8888;
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
EXPECT_TRUE(
factory_->CreateSharedImage(mailbox, format, size, color_space, usage));
EXPECT_FALSE(
factory_->CreateSharedImage(mailbox, format, size, color_space, usage));
}
TEST_P(SharedImageFactoryTest, DestroyInexistentMailbox) {
auto mailbox = Mailbox::Generate();
EXPECT_FALSE(factory_->DestroySharedImage(mailbox));
}
TEST_P(SharedImageFactoryTest, InvalidFormat) {
auto mailbox = Mailbox::Generate();
auto format = viz::ResourceFormat::UYVY_422;
gfx::Size size(256, 256);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
EXPECT_FALSE(
factory_->CreateSharedImage(mailbox, format, size, color_space, usage));
}
TEST_P(SharedImageFactoryTest, InvalidSize) {
auto mailbox = Mailbox::Generate();
auto format = viz::ResourceFormat::RGBA_8888;
gfx::Size size(0, 0);
auto color_space = gfx::ColorSpace::CreateSRGB();
uint32_t usage = SHARED_IMAGE_USAGE_GLES2;
EXPECT_FALSE(
factory_->CreateSharedImage(mailbox, format, size, color_space, usage));
size = gfx::Size(INT_MAX, INT_MAX);
EXPECT_FALSE(
factory_->CreateSharedImage(mailbox, format, size, color_space, usage));
}
INSTANTIATE_TEST_CASE_P(Service, SharedImageFactoryTest, ::testing::Bool());
} // anonymous namespace
} // namespace gpu
......@@ -309,8 +309,8 @@ static const Texture::CompatibilitySwizzle kSwizzledFormats[] = {
{GL_LUMINANCE_ALPHA, GL_RG, GL_RED, GL_RED, GL_RED, GL_GREEN},
};
// static
const Texture::CompatibilitySwizzle* GetCompatibilitySwizzle(GLenum format) {
const Texture::CompatibilitySwizzle* GetCompatibilitySwizzleInternal(
GLenum format) {
size_t count = arraysize(kSwizzledFormats);
for (size_t i = 0; i < count; ++i) {
if (kSwizzledFormats[i].format == format)
......@@ -1922,7 +1922,7 @@ void Texture::ApplyFormatWorkarounds(FeatureInfo* feature_info) {
if (static_cast<size_t>(base_level_) >= face_infos_[0].level_infos.size())
return;
const Texture::LevelInfo& info = face_infos_[0].level_infos[base_level_];
SetCompatibilitySwizzle(GetCompatibilitySwizzle(info.format));
SetCompatibilitySwizzle(GetCompatibilitySwizzleInternal(info.format));
}
}
......@@ -3302,13 +3302,24 @@ void TextureManager::DoTexSubImageLayerByLayerWorkaround(
glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, unpack_params.image_height);
}
// static
const Texture::CompatibilitySwizzle* TextureManager::GetCompatibilitySwizzle(
const gles2::FeatureInfo* feature_info,
GLenum format) {
if (feature_info->gl_version_info().is_desktop_core_profile) {
return GetCompatibilitySwizzleInternal(format);
} else {
return nullptr;
}
}
// static
GLenum TextureManager::AdjustTexInternalFormat(
const gles2::FeatureInfo* feature_info,
GLenum format) {
if (feature_info->gl_version_info().is_desktop_core_profile) {
const Texture::CompatibilitySwizzle* swizzle =
GetCompatibilitySwizzle(format);
GetCompatibilitySwizzleInternal(format);
if (swizzle)
return swizzle->dest_format;
}
......@@ -3328,7 +3339,7 @@ GLenum TextureManager::AdjustTexFormat(const gles2::FeatureInfo* feature_info,
}
if (feature_info->gl_version_info().is_desktop_core_profile) {
const Texture::CompatibilitySwizzle* swizzle =
GetCompatibilitySwizzle(format);
GetCompatibilitySwizzleInternal(format);
if (swizzle)
return swizzle->dest_format;
}
......
......@@ -31,6 +31,7 @@
namespace gpu {
class DecoderContext;
class ServiceDiscardableManager;
class SharedImageFactory;
namespace gles2 {
class GLStreamTextureImage;
......@@ -46,7 +47,7 @@ class TextureRef;
// A ref-counted version of the TextureBase class that deletes the texture after
// all references have been released.
class TexturePassthrough final
class GPU_GLES2_EXPORT TexturePassthrough final
: public TextureBase,
public base::RefCounted<TexturePassthrough>,
public base::SupportsWeakPtr<TexturePassthrough> {
......@@ -327,6 +328,7 @@ class GPU_GLES2_EXPORT Texture final : public TextureBase {
private:
friend class MailboxManagerSync;
friend class MailboxManagerTest;
friend class gpu::SharedImageFactory;
friend class TextureDefinition;
friend class TextureManager;
friend class TextureRef;
......@@ -1104,6 +1106,9 @@ class GPU_GLES2_EXPORT TextureManager
uint32_t GetServiceIdGeneration() const;
void IncrementServiceIdGeneration();
static const Texture::CompatibilitySwizzle* GetCompatibilitySwizzle(
const gles2::FeatureInfo* feature_info,
GLenum format);
static GLenum AdjustTexInternalFormat(const gles2::FeatureInfo* feature_info,
GLenum format);
static GLenum AdjustTexFormat(const gles2::FeatureInfo* feature_info,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment