Commit e3023c76 authored by Eric Karl's avatar Eric Karl Committed by Commit Bot

Simplify ShardImageRepresentationSkiaGL using TextureBase

Previous CL added a SharedImageRepresentationTextureBase for other
reasons, use this to simplify SharedImageRepresentationSkiaGL.

Change-Id: Id0e027afc11c76b89664adc09b6ef3c85ac7a76c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1956255Reviewed-by: default avatarvikas soni <vikassoni@chromium.org>
Commit-Queue: Eric Karl <ericrk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728300}
parent 65f89d72
...@@ -389,7 +389,7 @@ class SharedImageBackingD3D : public SharedImageBacking { ...@@ -389,7 +389,7 @@ class SharedImageBackingD3D : public SharedImageBacking {
SharedImageManager* manager, SharedImageManager* manager,
MemoryTypeTracker* tracker, MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override { scoped_refptr<SharedContextState> context_state) override {
return SharedImageRepresentationSkiaGL::CreateForPassthrough( return SharedImageRepresentationSkiaGL::Create(
ProduceGLTexturePassthrough(manager, tracker), std::move(context_state), ProduceGLTexturePassthrough(manager, tracker), std::move(context_state),
manager, this, tracker); manager, this, tracker);
} }
......
...@@ -48,8 +48,8 @@ bool SharedImageRepresentationGLTextureBase::BeginAccess(GLenum mode) { ...@@ -48,8 +48,8 @@ bool SharedImageRepresentationGLTextureBase::BeginAccess(GLenum mode) {
return true; return true;
} }
bool SharedImageRepresentationSkia::SupportsMultipleConcurrentReadAccess() { gpu::TextureBase* SharedImageRepresentationGLTexture::GetTextureBase() {
return false; return GetTexture();
} }
void SharedImageRepresentationGLTexture::UpdateClearedStateOnEndAccess() { void SharedImageRepresentationGLTexture::UpdateClearedStateOnEndAccess() {
...@@ -61,6 +61,15 @@ void SharedImageRepresentationGLTexture::UpdateClearedStateOnEndAccess() { ...@@ -61,6 +61,15 @@ void SharedImageRepresentationGLTexture::UpdateClearedStateOnEndAccess() {
SetClearedRect(cleared_rect); SetClearedRect(cleared_rect);
} }
gpu::TextureBase*
SharedImageRepresentationGLTexturePassthrough::GetTextureBase() {
return GetTexturePassthrough().get();
}
bool SharedImageRepresentationSkia::SupportsMultipleConcurrentReadAccess() {
return false;
}
SharedImageRepresentationSkia::ScopedWriteAccess::ScopedWriteAccess( SharedImageRepresentationSkia::ScopedWriteAccess::ScopedWriteAccess(
util::PassKey<SharedImageRepresentationSkia> /* pass_key */, util::PassKey<SharedImageRepresentationSkia> /* pass_key */,
SharedImageRepresentationSkia* representation, SharedImageRepresentationSkia* representation,
......
...@@ -29,6 +29,8 @@ class GLImage; ...@@ -29,6 +29,8 @@ class GLImage;
} }
namespace gpu { namespace gpu {
class TextureBase;
namespace gles2 { namespace gles2 {
class Texture; class Texture;
class TexturePassthrough; class TexturePassthrough;
...@@ -129,6 +131,8 @@ class GPU_GLES2_EXPORT SharedImageRepresentationGLTextureBase ...@@ -129,6 +131,8 @@ class GPU_GLES2_EXPORT SharedImageRepresentationGLTextureBase
GLenum mode, GLenum mode,
AllowUnclearedAccess allow_uncleared); AllowUnclearedAccess allow_uncleared);
virtual gpu::TextureBase* GetTextureBase() = 0;
protected: protected:
friend class SharedImageRepresentationSkiaGL; friend class SharedImageRepresentationSkiaGL;
...@@ -152,6 +156,8 @@ class GPU_GLES2_EXPORT SharedImageRepresentationGLTexture ...@@ -152,6 +156,8 @@ class GPU_GLES2_EXPORT SharedImageRepresentationGLTexture
// TODO(ericrk): Move this to the ScopedAccess object. crbug.com/1003686 // TODO(ericrk): Move this to the ScopedAccess object. crbug.com/1003686
virtual gles2::Texture* GetTexture() = 0; virtual gles2::Texture* GetTexture() = 0;
gpu::TextureBase* GetTextureBase() override;
protected: protected:
void UpdateClearedStateOnEndAccess() override; void UpdateClearedStateOnEndAccess() override;
}; };
...@@ -167,6 +173,8 @@ class GPU_GLES2_EXPORT SharedImageRepresentationGLTexturePassthrough ...@@ -167,6 +173,8 @@ class GPU_GLES2_EXPORT SharedImageRepresentationGLTexturePassthrough
// TODO(ericrk): Move this to the ScopedAccess object. crbug.com/1003686 // TODO(ericrk): Move this to the ScopedAccess object. crbug.com/1003686
virtual const scoped_refptr<gles2::TexturePassthrough>& virtual const scoped_refptr<gles2::TexturePassthrough>&
GetTexturePassthrough() = 0; GetTexturePassthrough() = 0;
gpu::TextureBase* GetTextureBase() override;
}; };
class GPU_GLES2_EXPORT SharedImageRepresentationSkia class GPU_GLES2_EXPORT SharedImageRepresentationSkia
......
...@@ -32,16 +32,16 @@ std::ostream& operator<<(std::ostream& os, RepresentationAccessMode mode) { ...@@ -32,16 +32,16 @@ std::ostream& operator<<(std::ostream& os, RepresentationAccessMode mode) {
// static method. // static method.
std::unique_ptr<SharedImageRepresentationSkiaGL> std::unique_ptr<SharedImageRepresentationSkiaGL>
SharedImageRepresentationSkiaGL::Create( SharedImageRepresentationSkiaGL::Create(
std::unique_ptr<SharedImageRepresentationGLTexture> gl_representation, std::unique_ptr<SharedImageRepresentationGLTextureBase> gl_representation,
scoped_refptr<SharedContextState> context_state, scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager, SharedImageManager* manager,
SharedImageBacking* backing, SharedImageBacking* backing,
MemoryTypeTracker* tracker) { MemoryTypeTracker* tracker) {
GrBackendTexture backend_texture; GrBackendTexture backend_texture;
if (!GetGrBackendTexture(context_state->feature_info(), if (!GetGrBackendTexture(context_state->feature_info(),
gl_representation->GetTexture()->target(), gl_representation->GetTextureBase()->target(),
backing->size(), backing->size(),
gl_representation->GetTexture()->service_id(), gl_representation->GetTextureBase()->service_id(),
backing->format(), &backend_texture)) { backing->format(), &backend_texture)) {
return nullptr; return nullptr;
} }
...@@ -53,33 +53,8 @@ SharedImageRepresentationSkiaGL::Create( ...@@ -53,33 +53,8 @@ SharedImageRepresentationSkiaGL::Create(
std::move(context_state), manager, backing, tracker)); std::move(context_state), manager, backing, tracker));
} }
std::unique_ptr<SharedImageRepresentationSkiaGL>
SharedImageRepresentationSkiaGL::CreateForPassthrough(
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
passthrough_representation,
scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker) {
GrBackendTexture backend_texture;
if (!GetGrBackendTexture(
context_state->feature_info(),
passthrough_representation->GetTexturePassthrough()->target(),
backing->size(),
passthrough_representation->GetTexturePassthrough()->service_id(),
backing->format(), &backend_texture)) {
return nullptr;
}
auto promise_texture = SkPromiseImageTexture::Make(backend_texture);
if (!promise_texture)
return nullptr;
return base::WrapUnique(new SharedImageRepresentationSkiaGL(
std::move(passthrough_representation), std::move(promise_texture),
std::move(context_state), manager, backing, tracker));
}
SharedImageRepresentationSkiaGL::SharedImageRepresentationSkiaGL( SharedImageRepresentationSkiaGL::SharedImageRepresentationSkiaGL(
std::unique_ptr<SharedImageRepresentationGLTexture> gl_representation, std::unique_ptr<SharedImageRepresentationGLTextureBase> gl_representation,
sk_sp<SkPromiseImageTexture> promise_texture, sk_sp<SkPromiseImageTexture> promise_texture,
scoped_refptr<SharedContextState> context_state, scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager, SharedImageManager* manager,
...@@ -95,24 +70,6 @@ SharedImageRepresentationSkiaGL::SharedImageRepresentationSkiaGL( ...@@ -95,24 +70,6 @@ SharedImageRepresentationSkiaGL::SharedImageRepresentationSkiaGL(
#endif #endif
} }
SharedImageRepresentationSkiaGL::SharedImageRepresentationSkiaGL(
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
passthrough_representation,
sk_sp<SkPromiseImageTexture> promise_texture,
scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker)
: SharedImageRepresentationSkia(manager, backing, tracker),
passthrough_representation_(std::move(passthrough_representation)),
promise_texture_(std::move(promise_texture)),
context_state_(std::move(context_state)) {
DCHECK(passthrough_representation_);
#if DCHECK_IS_ON()
context_ = gl::GLContext::GetCurrent();
#endif
}
SharedImageRepresentationSkiaGL::~SharedImageRepresentationSkiaGL() { SharedImageRepresentationSkiaGL::~SharedImageRepresentationSkiaGL() {
DCHECK_EQ(RepresentationAccessMode::kNone, mode_); DCHECK_EQ(RepresentationAccessMode::kNone, mode_);
DCHECK(!surface_); DCHECK(!surface_);
...@@ -127,16 +84,10 @@ sk_sp<SkSurface> SharedImageRepresentationSkiaGL::BeginWriteAccess( ...@@ -127,16 +84,10 @@ sk_sp<SkSurface> SharedImageRepresentationSkiaGL::BeginWriteAccess(
DCHECK(!surface_); DCHECK(!surface_);
CheckContext(); CheckContext();
if (gl_representation_ && if (!gl_representation_->BeginAccess(
!gl_representation_->BeginAccess(
GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM)) { GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM)) {
return nullptr; return nullptr;
} else if (passthrough_representation_ &&
!passthrough_representation_->BeginAccess(
GL_SHARED_IMAGE_ACCESS_MODE_READWRITE_CHROMIUM)) {
return nullptr;
} }
SkColorType sk_color_type = viz::ResourceFormatToClosestSkColorType( SkColorType sk_color_type = viz::ResourceFormatToClosestSkColorType(
/*gpu_compositing=*/true, format()); /*gpu_compositing=*/true, format());
auto surface = SkSurface::MakeFromBackendTextureAsRenderTarget( auto surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
...@@ -154,11 +105,7 @@ void SharedImageRepresentationSkiaGL::EndWriteAccess(sk_sp<SkSurface> surface) { ...@@ -154,11 +105,7 @@ void SharedImageRepresentationSkiaGL::EndWriteAccess(sk_sp<SkSurface> surface) {
DCHECK_EQ(surface.get(), surface_); DCHECK_EQ(surface.get(), surface_);
DCHECK(surface->unique()); DCHECK(surface->unique());
if (gl_representation_) { gl_representation_->EndAccess();
gl_representation_->EndAccess();
} else {
passthrough_representation_->EndAccess();
}
mode_ = RepresentationAccessMode::kNone; mode_ = RepresentationAccessMode::kNone;
surface_ = nullptr; surface_ = nullptr;
} }
...@@ -169,12 +116,8 @@ sk_sp<SkPromiseImageTexture> SharedImageRepresentationSkiaGL::BeginReadAccess( ...@@ -169,12 +116,8 @@ sk_sp<SkPromiseImageTexture> SharedImageRepresentationSkiaGL::BeginReadAccess(
DCHECK_EQ(mode_, RepresentationAccessMode::kNone); DCHECK_EQ(mode_, RepresentationAccessMode::kNone);
CheckContext(); CheckContext();
if (gl_representation_ && !gl_representation_->BeginAccess( if (!gl_representation_->BeginAccess(
GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM)) { GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM)) {
return nullptr;
} else if (passthrough_representation_ &&
!passthrough_representation_->BeginAccess(
GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM)) {
return nullptr; return nullptr;
} }
mode_ = RepresentationAccessMode::kRead; mode_ = RepresentationAccessMode::kRead;
...@@ -185,11 +128,7 @@ void SharedImageRepresentationSkiaGL::EndReadAccess() { ...@@ -185,11 +128,7 @@ void SharedImageRepresentationSkiaGL::EndReadAccess() {
DCHECK_EQ(mode_, RepresentationAccessMode::kRead); DCHECK_EQ(mode_, RepresentationAccessMode::kRead);
CheckContext(); CheckContext();
if (gl_representation_) { gl_representation_->EndAccess();
gl_representation_->EndAccess();
} else {
passthrough_representation_->EndAccess();
}
mode_ = RepresentationAccessMode::kNone; mode_ = RepresentationAccessMode::kNone;
surface_ = nullptr; surface_ = nullptr;
} }
...@@ -200,4 +139,4 @@ void SharedImageRepresentationSkiaGL::CheckContext() { ...@@ -200,4 +139,4 @@ void SharedImageRepresentationSkiaGL::CheckContext() {
#endif #endif
} }
} // namespace gpu } // namespace gpu
\ No newline at end of file
...@@ -19,14 +19,7 @@ class GPU_GLES2_EXPORT SharedImageRepresentationSkiaGL ...@@ -19,14 +19,7 @@ class GPU_GLES2_EXPORT SharedImageRepresentationSkiaGL
: public SharedImageRepresentationSkia { : public SharedImageRepresentationSkia {
public: public:
static std::unique_ptr<SharedImageRepresentationSkiaGL> Create( static std::unique_ptr<SharedImageRepresentationSkiaGL> Create(
std::unique_ptr<SharedImageRepresentationGLTexture> gl_representation, std::unique_ptr<SharedImageRepresentationGLTextureBase> gl_representation,
scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker);
static std::unique_ptr<SharedImageRepresentationSkiaGL> CreateForPassthrough(
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
passthrough_representation,
scoped_refptr<SharedContextState> context_state, scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager, SharedImageManager* manager,
SharedImageBacking* backing, SharedImageBacking* backing,
...@@ -47,15 +40,7 @@ class GPU_GLES2_EXPORT SharedImageRepresentationSkiaGL ...@@ -47,15 +40,7 @@ class GPU_GLES2_EXPORT SharedImageRepresentationSkiaGL
private: private:
SharedImageRepresentationSkiaGL( SharedImageRepresentationSkiaGL(
std::unique_ptr<SharedImageRepresentationGLTexture> gl_representation, std::unique_ptr<SharedImageRepresentationGLTextureBase> gl_representation,
sk_sp<SkPromiseImageTexture> promise_texture,
scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker);
SharedImageRepresentationSkiaGL(
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
passthrough_representation,
sk_sp<SkPromiseImageTexture> promise_texture, sk_sp<SkPromiseImageTexture> promise_texture,
scoped_refptr<SharedContextState> context_state, scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager, SharedImageManager* manager,
...@@ -64,9 +49,7 @@ class GPU_GLES2_EXPORT SharedImageRepresentationSkiaGL ...@@ -64,9 +49,7 @@ class GPU_GLES2_EXPORT SharedImageRepresentationSkiaGL
void CheckContext(); void CheckContext();
std::unique_ptr<SharedImageRepresentationGLTexture> gl_representation_; std::unique_ptr<SharedImageRepresentationGLTextureBase> gl_representation_;
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
passthrough_representation_;
sk_sp<SkPromiseImageTexture> promise_texture_; sk_sp<SkPromiseImageTexture> promise_texture_;
scoped_refptr<SharedContextState> context_state_; scoped_refptr<SharedContextState> context_state_;
SkSurface* surface_ = nullptr; SkSurface* surface_ = nullptr;
......
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