Commit 5c675fd9 authored by Rafael Cintron's avatar Rafael Cintron Committed by Commit Bot

Enable WebGPU on Skia Renderer

Implement SharedImageBackingD3D::ProduceSkia and supporting methods.

Bug: 1021118,1002316
Change-Id: Ia699bddfa08469b9e151018eca6c5206620cb731
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1938707
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/master@{#720722}
parent fde41d98
......@@ -8,9 +8,11 @@
#include "components/viz/common/resources/resource_format_utils.h"
#include "gpu/command_buffer/common/shared_image_trace_utils.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/shared_context_state.h"
#include "gpu/command_buffer/service/shared_image_backing.h"
#include "gpu/command_buffer/service/shared_image_manager.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/shared_image_representation_skia_gl.h"
#include "gpu/command_buffer/service/texture_manager.h"
#include "ui/gfx/buffer_format_util.h"
#include "ui/gl/buildflags.h"
......@@ -405,6 +407,15 @@ class SharedImageBackingD3D : public SharedImageBacking {
manager, this, tracker, texture_passthrough_);
}
std::unique_ptr<SharedImageRepresentationSkia> ProduceSkia(
SharedImageManager* manager,
MemoryTypeTracker* tracker,
scoped_refptr<SharedContextState> context_state) override {
return SharedImageRepresentationSkiaGL::CreateForPassthrough(
ProduceGLTexturePassthrough(manager, tracker), std::move(context_state),
manager, this, tracker);
}
private:
Microsoft::WRL::ComPtr<IDXGISwapChain1> swap_chain_;
gles2::Texture* texture_ = nullptr;
......
......@@ -212,6 +212,8 @@ class GPU_GLES2_EXPORT SharedImageRepresentationGLTexturePassthrough
GetTexturePassthrough() = 0;
protected:
friend class SharedImageRepresentationSkiaGL;
// TODO(ericrk): Make these pure virtual and ensure real implementations
// exist.
virtual bool BeginAccess(GLenum mode);
......
......@@ -53,6 +53,31 @@ 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,
sk_sp<SkPromiseImageTexture> promise_texture,
......@@ -64,6 +89,25 @@ SharedImageRepresentationSkiaGL::SharedImageRepresentationSkiaGL(
gl_representation_(std::move(gl_representation)),
promise_texture_(std::move(promise_texture)),
context_state_(std::move(context_state)) {
DCHECK(gl_representation_);
#if DCHECK_IS_ON()
context_ = gl::GLContext::GetCurrent();
#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
......@@ -83,9 +127,14 @@ sk_sp<SkSurface> SharedImageRepresentationSkiaGL::BeginWriteAccess(
DCHECK(!surface_);
CheckContext();
if (!gl_representation_->BeginAccess(
if (gl_representation_ &&
!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(
......@@ -105,7 +154,11 @@ void SharedImageRepresentationSkiaGL::EndWriteAccess(sk_sp<SkSurface> surface) {
DCHECK_EQ(surface.get(), surface_);
DCHECK(surface->unique());
gl_representation_->EndAccess();
if (gl_representation_) {
gl_representation_->EndAccess();
} else {
passthrough_representation_->EndAccess();
}
mode_ = RepresentationAccessMode::kNone;
surface_ = nullptr;
}
......@@ -116,9 +169,14 @@ sk_sp<SkPromiseImageTexture> SharedImageRepresentationSkiaGL::BeginReadAccess(
DCHECK_EQ(mode_, RepresentationAccessMode::kNone);
CheckContext();
if (!gl_representation_->BeginAccess(
GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM))
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)) {
return nullptr;
}
mode_ = RepresentationAccessMode::kRead;
return promise_texture_;
}
......@@ -127,7 +185,11 @@ void SharedImageRepresentationSkiaGL::EndReadAccess() {
DCHECK_EQ(mode_, RepresentationAccessMode::kRead);
CheckContext();
gl_representation_->EndAccess();
if (gl_representation_) {
gl_representation_->EndAccess();
} else {
passthrough_representation_->EndAccess();
}
mode_ = RepresentationAccessMode::kNone;
surface_ = nullptr;
}
......@@ -138,4 +200,4 @@ void SharedImageRepresentationSkiaGL::CheckContext() {
#endif
}
} // namespace gpu
} // namespace gpu
\ No newline at end of file
......@@ -24,6 +24,13 @@ class GPU_GLES2_EXPORT SharedImageRepresentationSkiaGL
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker);
static std::unique_ptr<SharedImageRepresentationSkiaGL> CreateForPassthrough(
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
passthrough_representation,
scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker);
~SharedImageRepresentationSkiaGL() override;
......@@ -46,9 +53,20 @@ class GPU_GLES2_EXPORT SharedImageRepresentationSkiaGL
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker);
SharedImageRepresentationSkiaGL(
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
passthrough_representation,
sk_sp<SkPromiseImageTexture> promise_texture,
scoped_refptr<SharedContextState> context_state,
SharedImageManager* manager,
SharedImageBacking* backing,
MemoryTypeTracker* tracker);
void CheckContext();
std::unique_ptr<SharedImageRepresentationGLTexture> gl_representation_;
std::unique_ptr<SharedImageRepresentationGLTexturePassthrough>
passthrough_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