Commit b5baae12 authored by Justin Novosad's avatar Justin Novosad Committed by Commit Bot

Use CanvasResource more in OffscreenCanvasFrameDispatcher

Use CanvasResource instead of StaticBitmapImage in more places
in OffscreenCanvasFrameDispatcher. This change brings us closer to
unifying <canvas> and OffscreenCanvas resource management.

BUG=788439

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2
Change-Id: I2595acf5733015d1c892995181897be90d6619c5
Reviewed-on: https://chromium-review.googlesource.com/1076309Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Justin Novosad <junov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562478}
parent 407d2e27
...@@ -71,8 +71,8 @@ void CanvasResource::WaitSyncTokenBeforeRelease() { ...@@ -71,8 +71,8 @@ void CanvasResource::WaitSyncTokenBeforeRelease() {
auto* gl = ContextGL(); auto* gl = ContextGL();
if (gl) if (gl)
gl->WaitSyncTokenCHROMIUM(sync_token_for_release_.GetData()); gl->WaitSyncTokenCHROMIUM(sync_token_for_release_.GetData());
sync_token_for_release_.Clear();
} }
sync_token_for_release_.Clear();
} }
static void ReleaseFrameResources( static void ReleaseFrameResources(
......
...@@ -129,8 +129,14 @@ void OffscreenCanvasFrameDispatcher::DispatchFrameSync( ...@@ -129,8 +129,14 @@ void OffscreenCanvasFrameDispatcher::DispatchFrameSync(
scoped_refptr<StaticBitmapImage> image, scoped_refptr<StaticBitmapImage> image,
double commit_start_time, double commit_start_time,
const SkIRect& damage_rect) { const SkIRect& damage_rect) {
scoped_refptr<CanvasResource> canvas_resource = CanvasResourceBitmap::Create(
std::move(image),
nullptr, // Resource provider not specified -> recycling will not work
kLow_SkFilterQuality, CanvasColorParams());
viz::CompositorFrame frame; viz::CompositorFrame frame;
if (!PrepareFrame(std::move(image), commit_start_time, damage_rect, &frame)) if (!PrepareFrame(std::move(canvas_resource), commit_start_time, damage_rect,
&frame))
return; return;
pending_compositor_frames_++; pending_compositor_frames_++;
...@@ -145,8 +151,14 @@ void OffscreenCanvasFrameDispatcher::DispatchFrame( ...@@ -145,8 +151,14 @@ void OffscreenCanvasFrameDispatcher::DispatchFrame(
scoped_refptr<StaticBitmapImage> image, scoped_refptr<StaticBitmapImage> image,
double commit_start_time, double commit_start_time,
const SkIRect& damage_rect) { const SkIRect& damage_rect) {
scoped_refptr<CanvasResource> canvas_resource = CanvasResourceBitmap::Create(
std::move(image),
nullptr, // Resource provider not specified -> recycling will not work
kLow_SkFilterQuality, CanvasColorParams());
viz::CompositorFrame frame; viz::CompositorFrame frame;
if (!PrepareFrame(std::move(image), commit_start_time, damage_rect, &frame)) if (!PrepareFrame(std::move(canvas_resource), commit_start_time, damage_rect,
&frame))
return; return;
pending_compositor_frames_++; pending_compositor_frames_++;
...@@ -156,10 +168,11 @@ void OffscreenCanvasFrameDispatcher::DispatchFrame( ...@@ -156,10 +168,11 @@ void OffscreenCanvasFrameDispatcher::DispatchFrame(
} }
bool OffscreenCanvasFrameDispatcher::PrepareFrame( bool OffscreenCanvasFrameDispatcher::PrepareFrame(
scoped_refptr<StaticBitmapImage> image, scoped_refptr<CanvasResource> image,
double commit_start_time, double commit_start_time,
const SkIRect& damage_rect, const SkIRect& damage_rect,
viz::CompositorFrame* frame) { viz::CompositorFrame* frame) {
DCHECK(image->IsBitmap());
if (!image || !VerifyImageSize(image->Size())) if (!image || !VerifyImageSize(image->Size()))
return false; return false;
...@@ -167,14 +180,8 @@ bool OffscreenCanvasFrameDispatcher::PrepareFrame( ...@@ -167,14 +180,8 @@ bool OffscreenCanvasFrameDispatcher::PrepareFrame(
// For frameless canvas, we don't get a valid frame_sink_id and should drop. // For frameless canvas, we don't get a valid frame_sink_id and should drop.
if (!frame_sink_id_.is_valid()) { if (!frame_sink_id_.is_valid()) {
scoped_refptr<CanvasResource> canvas_resource =
CanvasResourceBitmap::Create(std::move(image),
nullptr, // Resource provider not
// specified -> recycling will
// not work
kLow_SkFilterQuality, CanvasColorParams());
PostImageToPlaceholderIfNotBlocked( PostImageToPlaceholderIfNotBlocked(
std::move(canvas_resource), std::move(image),
offscreen_canvas_resource_provider_->GetNextResourceId()); offscreen_canvas_resource_provider_->GetNextResourceId());
return false; return false;
} }
...@@ -214,7 +221,7 @@ bool OffscreenCanvasFrameDispatcher::PrepareFrame( ...@@ -214,7 +221,7 @@ bool OffscreenCanvasFrameDispatcher::PrepareFrame(
DEFINE_THREAD_SAFE_STATIC_LOCAL( DEFINE_THREAD_SAFE_STATIC_LOCAL(
EnumerationHistogram, commit_type_histogram, EnumerationHistogram, commit_type_histogram,
("OffscreenCanvas.CommitType", kOffscreenCanvasCommitTypeCount)); ("OffscreenCanvas.CommitType", kOffscreenCanvasCommitTypeCount));
if (image->IsTextureBacked()) { if (image->IsAccelerated()) {
// While |image| is texture backed, it could be generated with "software // While |image| is texture backed, it could be generated with "software
// rendering" aka swiftshader. If the compositor is not also using // rendering" aka swiftshader. If the compositor is not also using
// swiftshader, then we could not give a swiftshader based texture // swiftshader, then we could not give a swiftshader based texture
...@@ -224,20 +231,22 @@ bool OffscreenCanvasFrameDispatcher::PrepareFrame( ...@@ -224,20 +231,22 @@ bool OffscreenCanvasFrameDispatcher::PrepareFrame(
// Case 1: both canvas and compositor are gpu accelerated. // Case 1: both canvas and compositor are gpu accelerated.
commit_type = kCommitGPUCanvasGPUCompositing; commit_type = kCommitGPUCanvasGPUCompositing;
offscreen_canvas_resource_provider_ offscreen_canvas_resource_provider_
->SetTransferableResourceToStaticBitmapImage(resource, image); ->SetTransferableResourceToStaticBitmapImage(resource,
image->Bitmap());
yflipped = true; yflipped = true;
} else { } else {
// Case 2: canvas is accelerated but gpu compositing is disabled. // Case 2: canvas is accelerated but gpu compositing is disabled.
commit_type = kCommitGPUCanvasSoftwareCompositing; commit_type = kCommitGPUCanvasSoftwareCompositing;
offscreen_canvas_resource_provider_ offscreen_canvas_resource_provider_
->SetTransferableResourceToSharedBitmap(resource, image); ->SetTransferableResourceToSharedBitmap(resource, image->Bitmap());
} }
} else { } else {
if (SharedGpuContext::IsGpuCompositingEnabled()) { if (SharedGpuContext::IsGpuCompositingEnabled()) {
// Case 3: canvas is not gpu-accelerated, but compositor is. // Case 3: canvas is not gpu-accelerated, but compositor is.
commit_type = kCommitSoftwareCanvasGPUCompositing; commit_type = kCommitSoftwareCanvasGPUCompositing;
scoped_refptr<StaticBitmapImage> accelerated_image = scoped_refptr<StaticBitmapImage> accelerated_image =
image->MakeAccelerated(SharedGpuContext::ContextProviderWrapper()); image->Bitmap()->MakeAccelerated(
SharedGpuContext::ContextProviderWrapper());
if (!accelerated_image) if (!accelerated_image)
return false; return false;
offscreen_canvas_resource_provider_ offscreen_canvas_resource_provider_
...@@ -247,19 +256,14 @@ bool OffscreenCanvasFrameDispatcher::PrepareFrame( ...@@ -247,19 +256,14 @@ bool OffscreenCanvasFrameDispatcher::PrepareFrame(
// Case 4: both canvas and compositor are not gpu accelerated. // Case 4: both canvas and compositor are not gpu accelerated.
commit_type = kCommitSoftwareCanvasSoftwareCompositing; commit_type = kCommitSoftwareCanvasSoftwareCompositing;
offscreen_canvas_resource_provider_ offscreen_canvas_resource_provider_
->SetTransferableResourceToSharedBitmap(resource, image); ->SetTransferableResourceToSharedBitmap(resource, image->Bitmap());
} }
} }
commit_type_histogram.Count(commit_type); commit_type_histogram.Count(commit_type);
scoped_refptr<CanvasResource> canvas_resource = CanvasResourceBitmap::Create(
std::move(image),
nullptr, // Resource provider not specified -> recycling will not work
kLow_SkFilterQuality, CanvasColorParams());
PostImageToPlaceholderIfNotBlocked( PostImageToPlaceholderIfNotBlocked(
std::move(canvas_resource), std::move(image),
offscreen_canvas_resource_provider_->GetNextResourceId()); offscreen_canvas_resource_provider_->GetNextResourceId());
frame->resource_list.push_back(std::move(resource)); frame->resource_list.push_back(std::move(resource));
......
...@@ -87,7 +87,7 @@ class PLATFORM_EXPORT OffscreenCanvasFrameDispatcher ...@@ -87,7 +87,7 @@ class PLATFORM_EXPORT OffscreenCanvasFrameDispatcher
private: private:
friend class OffscreenCanvasFrameDispatcherTest; friend class OffscreenCanvasFrameDispatcherTest;
bool PrepareFrame(scoped_refptr<StaticBitmapImage>, bool PrepareFrame(scoped_refptr<CanvasResource>,
double commit_start_time, double commit_start_time,
const SkIRect& damage_rect, const SkIRect& damage_rect,
viz::CompositorFrame* frame); viz::CompositorFrame* frame);
......
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