Commit 94189587 authored by Peng Huang's avatar Peng Huang Committed by Commit Bot

SkiaOutputSurfaceImplOnGpu: use fence helper to release offscreen.surface

Bug: 1029066
Change-Id: I2b9f1e45dfbdabe2dfe01834d76dd9e225546865
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1954176Reviewed-by: default avatarVasiliy Telezhnikov <vasilyt@chromium.org>
Commit-Queue: Peng Huang <penghuang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722535}
parent 789450b2
......@@ -625,35 +625,43 @@ class DirectContextProviderDelegateImpl : public DirectContextProviderDelegate,
} // namespace
SkiaOutputSurfaceImplOnGpu::OffscreenSurface::OffscreenSurface() = default;
SkiaOutputSurfaceImplOnGpu::OffscreenSurface::~OffscreenSurface() = default;
SkiaOutputSurfaceImplOnGpu::OffscreenSurface::OffscreenSurface(
OffscreenSurface&& offscreen_surface) = default;
// Offscreen surfaces for render passes. It can only be accessed on GPU
// thread.
class SkiaOutputSurfaceImplOnGpu::OffscreenSurface {
public:
OffscreenSurface() = default;
OffscreenSurface(const OffscreenSurface& offscreen_surface) = delete;
OffscreenSurface(OffscreenSurface&& offscreen_surface) = default;
OffscreenSurface& operator=(const OffscreenSurface& offscreen_surface) =
delete;
OffscreenSurface& operator=(OffscreenSurface&& offscreen_surface) = default;
~OffscreenSurface() = default;
SkiaOutputSurfaceImplOnGpu::OffscreenSurface&
SkiaOutputSurfaceImplOnGpu::OffscreenSurface::operator=(
OffscreenSurface&& offscreen_surface) = default;
SkSurface* surface() { return surface_.get(); }
void set_surface(sk_sp<SkSurface> surface) {
surface_ = std::move(surface);
promise_texture_ = {};
}
SkSurface* SkiaOutputSurfaceImplOnGpu::OffscreenSurface::surface() const {
return surface_.get();
}
SkPromiseImageTexture* fulfill() {
DCHECK(surface_);
if (!promise_texture_) {
promise_texture_ =
SkPromiseImageTexture::Make(surface_->getBackendTexture(
SkSurface::kFlushRead_BackendHandleAccess));
}
return promise_texture_.get();
}
SkPromiseImageTexture* SkiaOutputSurfaceImplOnGpu::OffscreenSurface::fulfill() {
DCHECK(surface_);
if (!promise_texture_) {
promise_texture_ = SkPromiseImageTexture::Make(
surface_->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
sk_sp<SkSurface> TakeSurface() {
promise_texture_ = {};
return std::move(surface_);
}
return promise_texture_.get();
}
void SkiaOutputSurfaceImplOnGpu::OffscreenSurface::set_surface(
sk_sp<SkSurface> surface) {
surface_ = std::move(surface);
promise_texture_ = {};
}
private:
sk_sp<SkSurface> surface_;
sk_sp<SkPromiseImageTexture> promise_texture_;
};
// static
std::unique_ptr<SkiaOutputSurfaceImplOnGpu> SkiaOutputSurfaceImplOnGpu::Create(
......@@ -1027,7 +1035,11 @@ void SkiaOutputSurfaceImplOnGpu::RemoveRenderPassResource(
for (auto& image_context : image_contexts) {
// It's possible that |offscreen_surfaces_| won't contain an entry for the
// render pass if draw failed early.
offscreen_surfaces_.erase(image_context->render_pass_id());
auto it = offscreen_surfaces_.find(image_context->render_pass_id());
if (it == offscreen_surfaces_.end())
continue;
DeleteSkSurface(context_state_.get(), it->second.TakeSurface());
offscreen_surfaces_.erase(it);
}
}
......
......@@ -211,26 +211,7 @@ class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate,
private:
class ScopedPromiseImageAccess;
// Offscreen surfaces for render passes. It can only be accessed on GPU
// thread.
class OffscreenSurface {
public:
OffscreenSurface();
OffscreenSurface(const OffscreenSurface& offscreen_surface) = delete;
OffscreenSurface(OffscreenSurface&& offscreen_surface);
OffscreenSurface& operator=(const OffscreenSurface& offscreen_surface) =
delete;
OffscreenSurface& operator=(OffscreenSurface&& offscreen_surface);
~OffscreenSurface();
SkSurface* surface() const;
SkPromiseImageTexture* fulfill();
void set_surface(sk_sp<SkSurface> surface);
private:
sk_sp<SkSurface> surface_;
sk_sp<SkPromiseImageTexture> promise_texture_;
};
class OffscreenSurface;
bool Initialize();
bool InitializeForGL();
......
......@@ -39,6 +39,22 @@ void CleanupAfterSkiaFlush(void* context) {
delete flush_context;
}
template <class T>
void DeleteSkObject(SharedContextState* context_state, sk_sp<T> sk_object) {
DCHECK(sk_object && sk_object->unique());
if (!context_state->GrContextIsVulkan())
return;
#if BUILDFLAG(ENABLE_VULKAN)
auto* fence_helper =
context_state->vk_context_provider()->GetDeviceQueue()->GetFenceHelper();
fence_helper->EnqueueCleanupTaskForSubmittedWork(base::BindOnce(
[](const sk_sp<GrContext>& gr_context, sk_sp<T> sk_object,
gpu::VulkanDeviceQueue* device_queue, bool is_lost) {},
sk_ref_sp(context_state->gr_context()), std::move(sk_object)));
#endif
}
} // namespace
GLuint GetGrGLBackendTextureFormat(const gles2::FeatureInfo* feature_info,
......@@ -133,18 +149,12 @@ void DeleteGrBackendTexture(SharedContextState* context_state,
}
void DeleteSkImage(SharedContextState* context_state, sk_sp<SkImage> sk_image) {
DCHECK(sk_image && sk_image->unique());
if (!context_state->GrContextIsVulkan())
return;
DeleteSkObject(context_state, std::move(sk_image));
}
#if BUILDFLAG(ENABLE_VULKAN)
auto* fence_helper =
context_state->vk_context_provider()->GetDeviceQueue()->GetFenceHelper();
fence_helper->EnqueueCleanupTaskForSubmittedWork(base::BindOnce(
[](const sk_sp<GrContext>& gr_context, sk_sp<SkImage> sk_image,
gpu::VulkanDeviceQueue* device_queue, bool is_lost) {},
sk_ref_sp(context_state->gr_context()), std::move(sk_image)));
#endif
void DeleteSkSurface(SharedContextState* context_state,
sk_sp<SkSurface> sk_surface) {
DeleteSkObject(context_state, std::move(sk_surface));
}
#if BUILDFLAG(ENABLE_VULKAN)
......
......@@ -70,6 +70,9 @@ GPU_GLES2_EXPORT void DeleteGrBackendTexture(
GPU_GLES2_EXPORT void DeleteSkImage(SharedContextState* context_state,
sk_sp<SkImage> sk_image);
GPU_GLES2_EXPORT void DeleteSkSurface(SharedContextState* context_state,
sk_sp<SkSurface> sk_surface);
#if BUILDFLAG(ENABLE_VULKAN)
GPU_GLES2_EXPORT GrVkYcbcrConversionInfo CreateGrVkYcbcrConversionInfo(
VkPhysicalDevice physical_device,
......
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