Commit 47e01da7 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

SharedImageBackingGLCommon: Move common functions to separate file

Now that most of the functional changes are done, the classes that have
been accumulating together can get separate files.

TBR=geofflang

Bug: 1092155
Change-Id: Ic9f31557cbd2144bf4de643640ae05be3a60ae10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2309130
Commit-Queue: ccameron <ccameron@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790283}
parent 2e74d176
...@@ -227,7 +227,9 @@ target(link_target_type, "gles2_sources") { ...@@ -227,7 +227,9 @@ target(link_target_type, "gles2_sources") {
"shared_image_backing_factory.h", "shared_image_backing_factory.h",
"shared_image_backing_factory_gl_texture.cc", "shared_image_backing_factory_gl_texture.cc",
"shared_image_backing_factory_gl_texture.h", "shared_image_backing_factory_gl_texture.h",
"shared_image_backing_factory_gl_texture_internal.h", "shared_image_backing_gl_common.h",
"shared_image_backing_gl_image.h",
"shared_image_backing_gl_texture.h",
"shared_image_factory.cc", "shared_image_factory.cc",
"shared_image_factory.h", "shared_image_factory.h",
"shared_image_manager.cc", "shared_image_manager.cc",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "components/viz/common/resources/resource_format.h" #include "components/viz/common/resources/resource_format.h"
#include "gpu/command_buffer/service/shared_image_backing_factory.h" #include "gpu/command_buffer/service/shared_image_backing_factory.h"
#include "gpu/command_buffer/service/shared_image_backing_gl_common.h"
#include "gpu/command_buffer/service/texture_manager.h" #include "gpu/command_buffer/service/texture_manager.h"
#include "gpu/gpu_gles2_export.h" #include "gpu/gpu_gles2_export.h"
#include "ui/gfx/buffer_types.h" #include "ui/gfx/buffer_types.h"
...@@ -37,12 +38,6 @@ class ImageFactory; ...@@ -37,12 +38,6 @@ class ImageFactory;
class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture
: public SharedImageBackingFactory { : public SharedImageBackingFactory {
public: public:
struct UnpackStateAttribs {
bool es3_capable = false;
bool desktop_gl = false;
bool supports_unpack_subimage = false;
};
SharedImageBackingFactoryGLTexture( SharedImageBackingFactoryGLTexture(
const GpuPreferences& gpu_preferences, const GpuPreferences& gpu_preferences,
const GpuDriverBugWorkarounds& workarounds, const GpuDriverBugWorkarounds& workarounds,
...@@ -172,7 +167,7 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture ...@@ -172,7 +167,7 @@ class GPU_GLES2_EXPORT SharedImageBackingFactoryGLTexture
GpuMemoryBufferFormatSet gpu_memory_buffer_formats_; GpuMemoryBufferFormatSet gpu_memory_buffer_formats_;
int32_t max_texture_size_ = 0; int32_t max_texture_size_ = 0;
bool texture_usage_angle_ = false; bool texture_usage_angle_ = false;
UnpackStateAttribs attribs; SharedImageBackingGLCommon::UnpackStateAttribs attribs;
GpuDriverBugWorkarounds workarounds_; GpuDriverBugWorkarounds workarounds_;
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
// Copyright 2020 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_BACKING_GL_COMMON_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_GL_COMMON_H_
#include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "ui/gl/gl_bindings.h"
namespace gpu {
// Common helper functions for SharedImageBackingGLTexture and
// SharedImageBackingPassthroughGLImage.
class SharedImageBackingGLCommon {
public:
// These parameters are used to explicitly initialize a GL texture.
struct InitializeGLTextureParams {
GLenum target = 0;
GLenum internal_format = 0;
GLenum format = 0;
GLenum type = 0;
bool is_cleared = false;
bool is_rgb_emulation = false;
bool framebuffer_attachment_angle = false;
bool has_immutable_storage = false;
};
// Attributes needed to know what state to restore for GL upload and copy.
struct UnpackStateAttribs {
bool es3_capable = false;
bool desktop_gl = false;
bool supports_unpack_subimage = false;
};
// Object used to restore state around GL upload and copy.
class ScopedResetAndRestoreUnpackState {
public:
ScopedResetAndRestoreUnpackState(gl::GLApi* api,
const UnpackStateAttribs& attribs,
bool uploading_data);
~ScopedResetAndRestoreUnpackState();
private:
gl::GLApi* const api_;
// Always used if |es3_capable|.
GLint unpack_buffer_ = 0;
// Always used when |uploading_data|.
GLint unpack_alignment_ = 4;
// Used when |uploading_data_| and (|es3_capable| or
// |supports_unpack_subimage|).
GLint unpack_row_length_ = 0;
GLint unpack_skip_pixels_ = 0;
GLint unpack_skip_rows_ = 0;
// Used when |uploading_data| and |es3_capable|.
GLint unpack_skip_images_ = 0;
GLint unpack_image_height_ = 0;
// Used when |desktop_gl|.
GLboolean unpack_swap_bytes_ = GL_FALSE;
GLboolean unpack_lsb_first_ = GL_FALSE;
DISALLOW_COPY_AND_ASSIGN(ScopedResetAndRestoreUnpackState);
};
// Object used to restore texture bindings.
class ScopedRestoreTexture {
public:
ScopedRestoreTexture(gl::GLApi* api, GLenum target);
~ScopedRestoreTexture();
private:
gl::GLApi* api_;
GLenum target_;
GLuint old_binding_ = 0;
DISALLOW_COPY_AND_ASSIGN(ScopedRestoreTexture);
};
// Helper function to create a GL texture.
static void MakeTextureAndSetParameters(
GLenum target,
GLuint service_id,
bool framebuffer_attachment_angle,
scoped_refptr<gles2::TexturePassthrough>* passthrough_texture,
gles2::Texture** texture);
// Create a Dawn backing. This will use |backing|'s ProduceGLTexture or
// ProduceGLTexturePassthrough method, and populate the dawn backing via
// CopyTextureCHROMIUM.
static std::unique_ptr<SharedImageRepresentationDawn> ProduceDawnCommon(
SharedImageFactory* factory,
SharedImageManager* manager,
MemoryTypeTracker* tracker,
WGPUDevice device,
SharedImageBacking* backing,
bool use_passthrough);
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_GL_COMMON_H_
...@@ -2,12 +2,11 @@ ...@@ -2,12 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_FACTORY_GL_TEXTURE_INTERNAL_H_ #ifndef GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_GL_IMAGE_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_FACTORY_GL_TEXTURE_INTERNAL_H_ #define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_GL_IMAGE_H_
#include "gpu/command_buffer/service/shared_image_backing.h" #include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/command_buffer/service/shared_image_backing_factory_gl_texture.h" #include "gpu/command_buffer/service/shared_image_backing_gl_common.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
namespace gpu { namespace gpu {
...@@ -71,36 +70,6 @@ class SharedImageRepresentationGLTexturePassthroughImpl ...@@ -71,36 +70,6 @@ class SharedImageRepresentationGLTexturePassthroughImpl
scoped_refptr<gles2::TexturePassthrough> texture_passthrough_; scoped_refptr<gles2::TexturePassthrough> texture_passthrough_;
}; };
// Common helper functions for SharedImageBackingGLTexture and
// SharedImageBackingPassthroughGLImage.
class SharedImageBackingGLCommon : public SharedImageBacking {
public:
// These parameters are used to explicitly initialize a GL texture.
// TODO(https://crbug.com/1092155): The goal here is to cache these parameters
// (which are specified at initialization), so that the GL texture can be
// allocated and bound lazily. In that world, |service_id| will not be a
// parameter, but will be allocated lazily, and |image| will be handled by the
// relevant sub-class.
struct InitializeGLTextureParams {
GLenum target = 0;
GLenum internal_format = 0;
GLenum format = 0;
GLenum type = 0;
bool is_cleared = false;
bool is_rgb_emulation = false;
bool framebuffer_attachment_angle = false;
bool has_immutable_storage = false;
};
// Helper function to create a GL texture.
static void MakeTextureAndSetParameters(
GLenum target,
GLuint service_id,
bool framebuffer_attachment_angle,
scoped_refptr<gles2::TexturePassthrough>* passthrough_texture,
gles2::Texture** texture);
};
// Skia representation for both SharedImageBackingGLCommon. // Skia representation for both SharedImageBackingGLCommon.
class SharedImageRepresentationSkiaImpl : public SharedImageRepresentationSkia { class SharedImageRepresentationSkiaImpl : public SharedImageRepresentationSkia {
public: public:
...@@ -165,66 +134,6 @@ class SharedImageRepresentationOverlayImpl ...@@ -165,66 +134,6 @@ class SharedImageRepresentationOverlayImpl
scoped_refptr<gl::GLImage> gl_image_; scoped_refptr<gl::GLImage> gl_image_;
}; };
// Implementation of SharedImageBacking that creates a GL Texture that is not
// backed by a GLImage.
class SharedImageBackingGLTexture : public SharedImageBacking {
public:
SharedImageBackingGLTexture(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
GrSurfaceOrigin surface_origin,
SkAlphaType alpha_type,
uint32_t usage,
bool is_passthrough);
SharedImageBackingGLTexture(const SharedImageBackingGLTexture&) = delete;
SharedImageBackingGLTexture& operator=(const SharedImageBackingGLTexture&) =
delete;
~SharedImageBackingGLTexture() override;
void InitializeGLTexture(
GLuint service_id,
const SharedImageBackingGLCommon::InitializeGLTextureParams& params);
void SetCompatibilitySwizzle(
const gles2::Texture::CompatibilitySwizzle* swizzle);
GLenum GetGLTarget() const;
GLuint GetGLServiceId() const;
private:
// SharedImageBacking:
void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override;
gfx::Rect ClearedRect() const final;
void SetClearedRect(const gfx::Rect& cleared_rect) final;
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) final;
std::unique_ptr<SharedImageRepresentationGLTexture> ProduceGLTexture(
SharedImageManager* manager,
MemoryTypeTracker* tracker) final;
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
ProduceGLTexturePassthrough(SharedImageManager* manager,
MemoryTypeTracker* tracker) final;
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
WGPUDevice device) final;
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override;
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override;
bool IsPassthrough() const { return is_passthrough_; }
const bool is_passthrough_;
gles2::Texture* texture_ = nullptr;
scoped_refptr<gles2::TexturePassthrough> passthrough_texture_;
sk_sp<SkPromiseImageTexture> cached_promise_texture_;
};
// Implementation of SharedImageBacking that creates a GL Texture that is backed // Implementation of SharedImageBacking that creates a GL Texture that is backed
// by a GLImage and stores it as a gles2::Texture. Can be used with the legacy // by a GLImage and stores it as a gles2::Texture. Can be used with the legacy
// mailbox implementation. // mailbox implementation.
...@@ -242,7 +151,7 @@ class SharedImageBackingGLImage ...@@ -242,7 +151,7 @@ class SharedImageBackingGLImage
SkAlphaType alpha_type, SkAlphaType alpha_type,
uint32_t usage, uint32_t usage,
const SharedImageBackingGLCommon::InitializeGLTextureParams& params, const SharedImageBackingGLCommon::InitializeGLTextureParams& params,
const SharedImageBackingFactoryGLTexture::UnpackStateAttribs& attribs, const SharedImageBackingGLCommon::UnpackStateAttribs& attribs,
bool is_passthrough); bool is_passthrough);
SharedImageBackingGLImage(const SharedImageBackingGLImage& other) = delete; SharedImageBackingGLImage(const SharedImageBackingGLImage& other) = delete;
SharedImageBackingGLImage& operator=(const SharedImageBackingGLImage& other) = SharedImageBackingGLImage& operator=(const SharedImageBackingGLImage& other) =
...@@ -306,8 +215,7 @@ class SharedImageBackingGLImage ...@@ -306,8 +215,7 @@ class SharedImageBackingGLImage
bool gl_texture_retained_for_legacy_mailbox_ = false; bool gl_texture_retained_for_legacy_mailbox_ = false;
const SharedImageBackingGLCommon::InitializeGLTextureParams gl_params_; const SharedImageBackingGLCommon::InitializeGLTextureParams gl_params_;
const SharedImageBackingFactoryGLTexture::UnpackStateAttribs const SharedImageBackingGLCommon::UnpackStateAttribs gl_unpack_attribs_;
gl_unpack_attribs_;
const bool is_passthrough_; const bool is_passthrough_;
// This is the cleared rect used by ClearedRect and SetClearedRect when // This is the cleared rect used by ClearedRect and SetClearedRect when
...@@ -325,4 +233,4 @@ class SharedImageBackingGLImage ...@@ -325,4 +233,4 @@ class SharedImageBackingGLImage
} // namespace gpu } // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_FACTORY_GL_TEXTURE_INTERNAL_H_ #endif // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_GL_IMAGE_H_
// Copyright 2020 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_BACKING_GL_TEXTURE_H_
#define GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_GL_TEXTURE_H_
#include "gpu/command_buffer/service/shared_image_backing.h"
namespace gpu {
// Implementation of SharedImageBacking that creates a GL Texture that is not
// backed by a GLImage.
class SharedImageBackingGLTexture : public SharedImageBacking {
public:
SharedImageBackingGLTexture(const Mailbox& mailbox,
viz::ResourceFormat format,
const gfx::Size& size,
const gfx::ColorSpace& color_space,
GrSurfaceOrigin surface_origin,
SkAlphaType alpha_type,
uint32_t usage,
bool is_passthrough);
SharedImageBackingGLTexture(const SharedImageBackingGLTexture&) = delete;
SharedImageBackingGLTexture& operator=(const SharedImageBackingGLTexture&) =
delete;
~SharedImageBackingGLTexture() override;
void InitializeGLTexture(
GLuint service_id,
const SharedImageBackingGLCommon::InitializeGLTextureParams& params);
void SetCompatibilitySwizzle(
const gles2::Texture::CompatibilitySwizzle* swizzle);
GLenum GetGLTarget() const;
GLuint GetGLServiceId() const;
private:
// SharedImageBacking:
void OnMemoryDump(const std::string& dump_name,
base::trace_event::MemoryAllocatorDump* dump,
base::trace_event::ProcessMemoryDump* pmd,
uint64_t client_tracing_id) override;
gfx::Rect ClearedRect() const final;
void SetClearedRect(const gfx::Rect& cleared_rect) final;
bool ProduceLegacyMailbox(MailboxManager* mailbox_manager) final;
std::unique_ptr<SharedImageRepresentationGLTexture> ProduceGLTexture(
SharedImageManager* manager,
MemoryTypeTracker* tracker) final;
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
ProduceGLTexturePassthrough(SharedImageManager* manager,
MemoryTypeTracker* tracker) final;
std::unique_ptr<SharedImageRepresentationDawn> ProduceDawn(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
WGPUDevice device) final;
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override;
void Update(std::unique_ptr<gfx::GpuFence> in_fence) override;
bool IsPassthrough() const { return is_passthrough_; }
const bool is_passthrough_;
gles2::Texture* texture_ = nullptr;
scoped_refptr<gles2::TexturePassthrough> passthrough_texture_;
sk_sp<SkPromiseImageTexture> cached_promise_texture_;
};
} // namespace gpu
#endif // GPU_COMMAND_BUFFER_SERVICE_SHARED_IMAGE_BACKING_FACTORY_GL_TEXTURE_INTERNAL_H_
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