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