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, ...@@ -625,35 +625,43 @@ class DirectContextProviderDelegateImpl : public DirectContextProviderDelegate,
} // namespace } // namespace
SkiaOutputSurfaceImplOnGpu::OffscreenSurface::OffscreenSurface() = default; // Offscreen surfaces for render passes. It can only be accessed on GPU
// thread.
SkiaOutputSurfaceImplOnGpu::OffscreenSurface::~OffscreenSurface() = default; class SkiaOutputSurfaceImplOnGpu::OffscreenSurface {
public:
SkiaOutputSurfaceImplOnGpu::OffscreenSurface::OffscreenSurface( OffscreenSurface() = default;
OffscreenSurface&& offscreen_surface) = 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& SkSurface* surface() { return surface_.get(); }
SkiaOutputSurfaceImplOnGpu::OffscreenSurface::operator=( void set_surface(sk_sp<SkSurface> surface) {
OffscreenSurface&& offscreen_surface) = default; surface_ = std::move(surface);
promise_texture_ = {};
}
SkSurface* SkiaOutputSurfaceImplOnGpu::OffscreenSurface::surface() const { SkPromiseImageTexture* fulfill() {
return surface_.get(); DCHECK(surface_);
} if (!promise_texture_) {
promise_texture_ =
SkPromiseImageTexture::Make(surface_->getBackendTexture(
SkSurface::kFlushRead_BackendHandleAccess));
}
return promise_texture_.get();
}
SkPromiseImageTexture* SkiaOutputSurfaceImplOnGpu::OffscreenSurface::fulfill() { sk_sp<SkSurface> TakeSurface() {
DCHECK(surface_); promise_texture_ = {};
if (!promise_texture_) { return std::move(surface_);
promise_texture_ = SkPromiseImageTexture::Make(
surface_->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
} }
return promise_texture_.get();
}
void SkiaOutputSurfaceImplOnGpu::OffscreenSurface::set_surface( private:
sk_sp<SkSurface> surface) { sk_sp<SkSurface> surface_;
surface_ = std::move(surface); sk_sp<SkPromiseImageTexture> promise_texture_;
promise_texture_ = {}; };
}
// static // static
std::unique_ptr<SkiaOutputSurfaceImplOnGpu> SkiaOutputSurfaceImplOnGpu::Create( std::unique_ptr<SkiaOutputSurfaceImplOnGpu> SkiaOutputSurfaceImplOnGpu::Create(
...@@ -1027,7 +1035,11 @@ void SkiaOutputSurfaceImplOnGpu::RemoveRenderPassResource( ...@@ -1027,7 +1035,11 @@ void SkiaOutputSurfaceImplOnGpu::RemoveRenderPassResource(
for (auto& image_context : image_contexts) { for (auto& image_context : image_contexts) {
// It's possible that |offscreen_surfaces_| won't contain an entry for the // It's possible that |offscreen_surfaces_| won't contain an entry for the
// render pass if draw failed early. // 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, ...@@ -211,26 +211,7 @@ class SkiaOutputSurfaceImplOnGpu : public gpu::ImageTransportSurfaceDelegate,
private: private:
class ScopedPromiseImageAccess; class ScopedPromiseImageAccess;
class OffscreenSurface;
// 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_;
};
bool Initialize(); bool Initialize();
bool InitializeForGL(); bool InitializeForGL();
......
...@@ -39,6 +39,22 @@ void CleanupAfterSkiaFlush(void* context) { ...@@ -39,6 +39,22 @@ void CleanupAfterSkiaFlush(void* context) {
delete flush_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 } // namespace
GLuint GetGrGLBackendTextureFormat(const gles2::FeatureInfo* feature_info, GLuint GetGrGLBackendTextureFormat(const gles2::FeatureInfo* feature_info,
...@@ -133,18 +149,12 @@ void DeleteGrBackendTexture(SharedContextState* context_state, ...@@ -133,18 +149,12 @@ void DeleteGrBackendTexture(SharedContextState* context_state,
} }
void DeleteSkImage(SharedContextState* context_state, sk_sp<SkImage> sk_image) { void DeleteSkImage(SharedContextState* context_state, sk_sp<SkImage> sk_image) {
DCHECK(sk_image && sk_image->unique()); DeleteSkObject(context_state, std::move(sk_image));
if (!context_state->GrContextIsVulkan()) }
return;
#if BUILDFLAG(ENABLE_VULKAN) void DeleteSkSurface(SharedContextState* context_state,
auto* fence_helper = sk_sp<SkSurface> sk_surface) {
context_state->vk_context_provider()->GetDeviceQueue()->GetFenceHelper(); DeleteSkObject(context_state, std::move(sk_surface));
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
} }
#if BUILDFLAG(ENABLE_VULKAN) #if BUILDFLAG(ENABLE_VULKAN)
......
...@@ -70,6 +70,9 @@ GPU_GLES2_EXPORT void DeleteGrBackendTexture( ...@@ -70,6 +70,9 @@ GPU_GLES2_EXPORT void DeleteGrBackendTexture(
GPU_GLES2_EXPORT void DeleteSkImage(SharedContextState* context_state, GPU_GLES2_EXPORT void DeleteSkImage(SharedContextState* context_state,
sk_sp<SkImage> sk_image); sk_sp<SkImage> sk_image);
GPU_GLES2_EXPORT void DeleteSkSurface(SharedContextState* context_state,
sk_sp<SkSurface> sk_surface);
#if BUILDFLAG(ENABLE_VULKAN) #if BUILDFLAG(ENABLE_VULKAN)
GPU_GLES2_EXPORT GrVkYcbcrConversionInfo CreateGrVkYcbcrConversionInfo( GPU_GLES2_EXPORT GrVkYcbcrConversionInfo CreateGrVkYcbcrConversionInfo(
VkPhysicalDevice physical_device, 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