Commit 780cb154 authored by Yi Xu's avatar Yi Xu Committed by Commit Bot

Update functions names in OffscreenCanvasPlaceHolder

In OffscreenCanvasPlaceHolder, placeholder used to refer
to both Canvas and OffscreenCanvas. This updates all function names
to avoid ambiguity.

Change-Id: Ia272c3b9e6f978c8c4f638cc7a8b1606d4a2b29e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1776405Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Commit-Queue: Yi Xu <yiyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#691877}
parent 1a1ed6e4
...@@ -129,12 +129,12 @@ HTMLCanvasElement::~HTMLCanvasElement() { ...@@ -129,12 +129,12 @@ HTMLCanvasElement::~HTMLCanvasElement() {
} }
void HTMLCanvasElement::Dispose() { void HTMLCanvasElement::Dispose() {
if (PlaceholderFrame()) { if (OffscreenCanvasFrame()) {
ReleasePlaceholderFrame(); ReleaseOffscreenCanvasFrame();
} }
// It's possible that the placeholder frame has been disposed but its ID still // It's possible that the placeholder frame has been disposed but its ID still
// exists. Make sure that it gets unregistered here // exists. Make sure that it gets unregistered here
UnregisterPlaceholder(); UnregisterPlaceholderCanvas();
// We need to drop frame dispatcher, to prevent mojo calls from completing. // We need to drop frame dispatcher, to prevent mojo calls from completing.
frame_dispatcher_ = nullptr; frame_dispatcher_ = nullptr;
...@@ -191,7 +191,7 @@ Node::InsertionNotificationRequest HTMLCanvasElement::InsertedInto( ...@@ -191,7 +191,7 @@ Node::InsertionNotificationRequest HTMLCanvasElement::InsertedInto(
void HTMLCanvasElement::setHeight(unsigned value, void HTMLCanvasElement::setHeight(unsigned value,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (IsPlaceholderRegistered()) { if (IsOffscreenCanvasRegistered()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kInvalidStateError,
"Cannot resize canvas after call to transferControlToOffscreen()."); "Cannot resize canvas after call to transferControlToOffscreen().");
...@@ -202,7 +202,7 @@ void HTMLCanvasElement::setHeight(unsigned value, ...@@ -202,7 +202,7 @@ void HTMLCanvasElement::setHeight(unsigned value,
void HTMLCanvasElement::setWidth(unsigned value, void HTMLCanvasElement::setWidth(unsigned value,
ExceptionState& exception_state) { ExceptionState& exception_state) {
if (IsPlaceholderRegistered()) { if (IsOffscreenCanvasRegistered()) {
exception_state.ThrowDOMException( exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError, DOMExceptionCode::kInvalidStateError,
"Cannot resize canvas after call to transferControlToOffscreen()."); "Cannot resize canvas after call to transferControlToOffscreen().");
...@@ -598,7 +598,7 @@ void HTMLCanvasElement::Reset() { ...@@ -598,7 +598,7 @@ void HTMLCanvasElement::Reset() {
} }
bool HTMLCanvasElement::PaintsIntoCanvasBuffer() const { bool HTMLCanvasElement::PaintsIntoCanvasBuffer() const {
if (PlaceholderFrame()) if (OffscreenCanvasFrame())
return false; return false;
DCHECK(context_); DCHECK(context_);
if (!context_->IsComposited()) if (!context_->IsComposited())
...@@ -695,7 +695,7 @@ void HTMLCanvasElement::Paint(GraphicsContext& context, ...@@ -695,7 +695,7 @@ void HTMLCanvasElement::Paint(GraphicsContext& context,
// FIXME: crbug.com/438240; there is a bug with the new CSS blending and // FIXME: crbug.com/438240; there is a bug with the new CSS blending and
// compositing feature. // compositing feature.
if (!context_ && !PlaceholderFrame()) if (!context_ && !OffscreenCanvasFrame())
return; return;
if (Is3d()) if (Is3d())
...@@ -713,10 +713,10 @@ void HTMLCanvasElement::Paint(GraphicsContext& context, ...@@ -713,10 +713,10 @@ void HTMLCanvasElement::Paint(GraphicsContext& context,
return; return;
} }
if (PlaceholderFrame()) { if (OffscreenCanvasFrame()) {
DCHECK(GetDocument().Printing()); DCHECK(GetDocument().Printing());
scoped_refptr<StaticBitmapImage> image_for_printing = scoped_refptr<StaticBitmapImage> image_for_printing =
PlaceholderFrame()->Bitmap()->MakeUnaccelerated(); OffscreenCanvasFrame()->Bitmap()->MakeUnaccelerated();
context.DrawImage(image_for_printing.get(), Image::kSyncDecode, context.DrawImage(image_for_printing.get(), Image::kSyncDecode,
FloatRect(PixelSnappedIntRect(r))); FloatRect(PixelSnappedIntRect(r)));
return; return;
...@@ -812,9 +812,9 @@ scoped_refptr<StaticBitmapImage> HTMLCanvasElement::Snapshot( ...@@ -812,9 +812,9 @@ scoped_refptr<StaticBitmapImage> HTMLCanvasElement::Snapshot(
return nullptr; return nullptr;
scoped_refptr<StaticBitmapImage> image_bitmap = nullptr; scoped_refptr<StaticBitmapImage> image_bitmap = nullptr;
if (PlaceholderFrame()) { // Offscreen Canvas if (OffscreenCanvasFrame()) { // Offscreen Canvas
DCHECK(PlaceholderFrame()->OriginClean()); DCHECK(OffscreenCanvasFrame()->OriginClean());
image_bitmap = PlaceholderFrame()->Bitmap(); image_bitmap = OffscreenCanvasFrame()->Bitmap();
} else if (Is3d()) { // WebGL or WebGL2 canvas } else if (Is3d()) { // WebGL or WebGL2 canvas
if (context_->CreationAttributes().premultiplied_alpha) { if (context_->CreationAttributes().premultiplied_alpha) {
context_->PaintRenderingResultsToCanvas(source_buffer); context_->PaintRenderingResultsToCanvas(source_buffer);
...@@ -985,8 +985,8 @@ bool HTMLCanvasElement::OriginClean() const { ...@@ -985,8 +985,8 @@ bool HTMLCanvasElement::OriginClean() const {
GetDocument().GetSettings()->GetDisableReadingFromCanvas()) { GetDocument().GetSettings()->GetDisableReadingFromCanvas()) {
return false; return false;
} }
if (PlaceholderFrame()) if (OffscreenCanvasFrame())
return PlaceholderFrame()->OriginClean(); return OffscreenCanvasFrame()->OriginClean();
return origin_clean_; return origin_clean_;
} }
...@@ -1193,9 +1193,9 @@ scoped_refptr<Image> HTMLCanvasElement::GetSourceImageForCanvas( ...@@ -1193,9 +1193,9 @@ scoped_refptr<Image> HTMLCanvasElement::GetSourceImageForCanvas(
return nullptr; return nullptr;
} }
if (PlaceholderFrame()) { if (OffscreenCanvasFrame()) {
*status = kNormalSourceImageStatus; *status = kNormalSourceImageStatus;
return PlaceholderFrame()->Bitmap(); return OffscreenCanvasFrame()->Bitmap();
} }
if (!context_) { if (!context_) {
...@@ -1249,8 +1249,8 @@ FloatSize HTMLCanvasElement::ElementSize(const FloatSize&) const { ...@@ -1249,8 +1249,8 @@ FloatSize HTMLCanvasElement::ElementSize(const FloatSize&) const {
return FloatSize(image->width(), image->height()); return FloatSize(image->width(), image->height());
return FloatSize(0, 0); return FloatSize(0, 0);
} }
if (PlaceholderFrame()) if (OffscreenCanvasFrame())
return FloatSize(PlaceholderFrame()->Size()); return FloatSize(OffscreenCanvasFrame()->Size());
return FloatSize(width(), height()); return FloatSize(width(), height());
} }
...@@ -1269,15 +1269,15 @@ ScriptPromise HTMLCanvasElement::CreateImageBitmap( ...@@ -1269,15 +1269,15 @@ ScriptPromise HTMLCanvasElement::CreateImageBitmap(
script_state, ImageBitmap::Create(this, crop_rect, options)); script_state, ImageBitmap::Create(this, crop_rect, options));
} }
void HTMLCanvasElement::SetPlaceholderFrame( void HTMLCanvasElement::SetOffscreenCanvasFrame(
scoped_refptr<CanvasResource> image, scoped_refptr<CanvasResource> image,
base::WeakPtr<CanvasResourceDispatcher> dispatcher, base::WeakPtr<CanvasResourceDispatcher> dispatcher,
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
unsigned resource_id) { unsigned resource_id) {
OffscreenCanvasPlaceholder::SetPlaceholderFrame( OffscreenCanvasPlaceholder::SetOffscreenCanvasFrame(
std::move(image), std::move(dispatcher), std::move(task_runner), std::move(image), std::move(dispatcher), std::move(task_runner),
resource_id); resource_id);
SetSize(PlaceholderFrame()->Size()); SetSize(OffscreenCanvasFrame()->Size());
NotifyListenersCanvasChanged(); NotifyListenersCanvasChanged();
} }
......
...@@ -236,10 +236,10 @@ class CORE_EXPORT HTMLCanvasElement final ...@@ -236,10 +236,10 @@ class CORE_EXPORT HTMLCanvasElement final
const ImageBitmapOptions*) override; const ImageBitmapOptions*) override;
// OffscreenCanvasPlaceholder implementation. // OffscreenCanvasPlaceholder implementation.
void SetPlaceholderFrame(scoped_refptr<CanvasResource>, void SetOffscreenCanvasFrame(scoped_refptr<CanvasResource>,
base::WeakPtr<CanvasResourceDispatcher>, base::WeakPtr<CanvasResourceDispatcher>,
scoped_refptr<base::SingleThreadTaskRunner>, scoped_refptr<base::SingleThreadTaskRunner>,
unsigned resource_id) override; unsigned resource_id) override;
void Trace(Visitor*) override; void Trace(Visitor*) override;
void SetResourceProviderForTesting(std::unique_ptr<CanvasResourceProvider>, void SetResourceProviderForTesting(std::unique_ptr<CanvasResourceProvider>,
......
...@@ -69,7 +69,7 @@ OffscreenCanvas* HTMLCanvasElementModule::TransferControlToOffscreenInternal( ...@@ -69,7 +69,7 @@ OffscreenCanvas* HTMLCanvasElementModule::TransferControlToOffscreenInternal(
DOMNodeId canvas_id = DOMNodeIds::IdForNode(&canvas); DOMNodeId canvas_id = DOMNodeIds::IdForNode(&canvas);
offscreen_canvas->SetPlaceholderCanvasId(canvas_id); offscreen_canvas->SetPlaceholderCanvasId(canvas_id);
canvas.RegisterPlaceholder(static_cast<int>(canvas_id)); canvas.RegisterPlaceholderCanvas(static_cast<int>(canvas_id));
SurfaceLayerBridge* bridge = canvas.SurfaceLayerBridge(); SurfaceLayerBridge* bridge = canvas.SurfaceLayerBridge();
if (bridge) { if (bridge) {
......
...@@ -91,9 +91,10 @@ void UpdatePlaceholderImage( ...@@ -91,9 +91,10 @@ void UpdatePlaceholderImage(
viz::ResourceId resource_id) { viz::ResourceId resource_id) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
OffscreenCanvasPlaceholder* placeholder_canvas = OffscreenCanvasPlaceholder* placeholder_canvas =
OffscreenCanvasPlaceholder::GetPlaceholderById(placeholder_canvas_id); OffscreenCanvasPlaceholder::GetPlaceholderCanvasById(
placeholder_canvas_id);
if (placeholder_canvas) { if (placeholder_canvas) {
placeholder_canvas->SetPlaceholderFrame( placeholder_canvas->SetOffscreenCanvasFrame(
std::move(canvas_resource), std::move(dispatcher), std::move(canvas_resource), std::move(dispatcher),
std::move(task_runner), resource_id); std::move(task_runner), resource_id);
} }
......
...@@ -45,40 +45,17 @@ void SetSuspendAnimation( ...@@ -45,40 +45,17 @@ void SetSuspendAnimation(
namespace blink { namespace blink {
OffscreenCanvasPlaceholder::~OffscreenCanvasPlaceholder() { OffscreenCanvasPlaceholder::~OffscreenCanvasPlaceholder() {
UnregisterPlaceholder(); UnregisterPlaceholderCanvas();
} }
OffscreenCanvasPlaceholder* OffscreenCanvasPlaceholder::GetPlaceholderById( void OffscreenCanvasPlaceholder::SetOffscreenCanvasFrame(
unsigned placeholder_id) {
PlaceholderIdMap::iterator it = placeholderRegistry().find(placeholder_id);
if (it == placeholderRegistry().end())
return nullptr;
return it->value;
}
void OffscreenCanvasPlaceholder::RegisterPlaceholder(unsigned placeholder_id) {
DCHECK(!placeholderRegistry().Contains(placeholder_id));
DCHECK(!IsPlaceholderRegistered());
placeholderRegistry().insert(placeholder_id, this);
placeholder_id_ = placeholder_id;
}
void OffscreenCanvasPlaceholder::UnregisterPlaceholder() {
if (!IsPlaceholderRegistered())
return;
DCHECK(placeholderRegistry().find(placeholder_id_)->value == this);
placeholderRegistry().erase(placeholder_id_);
placeholder_id_ = kNoPlaceholderId;
}
void OffscreenCanvasPlaceholder::SetPlaceholderFrame(
scoped_refptr<CanvasResource> new_frame, scoped_refptr<CanvasResource> new_frame,
base::WeakPtr<CanvasResourceDispatcher> dispatcher, base::WeakPtr<CanvasResourceDispatcher> dispatcher,
scoped_refptr<base::SingleThreadTaskRunner> task_runner, scoped_refptr<base::SingleThreadTaskRunner> task_runner,
viz::ResourceId resource_id) { viz::ResourceId resource_id) {
DCHECK(IsPlaceholderRegistered()); DCHECK(IsOffscreenCanvasRegistered());
DCHECK(new_frame); DCHECK(new_frame);
ReleasePlaceholderFrame(); ReleaseOffscreenCanvasFrame();
placeholder_frame_ = std::move(new_frame); placeholder_frame_ = std::move(new_frame);
frame_dispatcher_ = std::move(dispatcher); frame_dispatcher_ = std::move(dispatcher);
frame_dispatcher_task_runner_ = std::move(task_runner); frame_dispatcher_task_runner_ = std::move(task_runner);
...@@ -95,8 +72,8 @@ void OffscreenCanvasPlaceholder::SetPlaceholderFrame( ...@@ -95,8 +72,8 @@ void OffscreenCanvasPlaceholder::SetPlaceholderFrame(
} }
} }
void OffscreenCanvasPlaceholder::ReleasePlaceholderFrame() { void OffscreenCanvasPlaceholder::ReleaseOffscreenCanvasFrame() {
DCHECK(IsPlaceholderRegistered()); DCHECK(IsOffscreenCanvasRegistered());
if (placeholder_frame_) { if (placeholder_frame_) {
DCHECK(frame_dispatcher_task_runner_); DCHECK(frame_dispatcher_task_runner_);
placeholder_frame_->Transfer(); placeholder_frame_->Transfer();
...@@ -144,6 +121,30 @@ void OffscreenCanvasPlaceholder::SetSuspendOffscreenCanvasAnimation( ...@@ -144,6 +121,30 @@ void OffscreenCanvasPlaceholder::SetSuspendOffscreenCanvasAnimation(
} }
} }
OffscreenCanvasPlaceholder*
OffscreenCanvasPlaceholder::GetPlaceholderCanvasById(unsigned placeholder_id) {
PlaceholderIdMap::iterator it = placeholderRegistry().find(placeholder_id);
if (it == placeholderRegistry().end())
return nullptr;
return it->value;
}
void OffscreenCanvasPlaceholder::RegisterPlaceholderCanvas(
unsigned placeholder_id) {
DCHECK(!placeholderRegistry().Contains(placeholder_id));
DCHECK(!IsOffscreenCanvasRegistered());
placeholderRegistry().insert(placeholder_id, this);
placeholder_id_ = placeholder_id;
}
void OffscreenCanvasPlaceholder::UnregisterPlaceholderCanvas() {
if (!IsOffscreenCanvasRegistered())
return;
DCHECK(placeholderRegistry().find(placeholder_id_)->value == this);
placeholderRegistry().erase(placeholder_id_);
placeholder_id_ = kNoPlaceholderId;
}
bool OffscreenCanvasPlaceholder::PostSetSuspendAnimationToOffscreenCanvasThread( bool OffscreenCanvasPlaceholder::PostSetSuspendAnimationToOffscreenCanvasThread(
bool suspend) { bool suspend) {
if (!frame_dispatcher_task_runner_) if (!frame_dispatcher_task_runner_)
......
...@@ -24,30 +24,32 @@ class PLATFORM_EXPORT OffscreenCanvasPlaceholder { ...@@ -24,30 +24,32 @@ class PLATFORM_EXPORT OffscreenCanvasPlaceholder {
public: public:
~OffscreenCanvasPlaceholder(); ~OffscreenCanvasPlaceholder();
virtual void SetPlaceholderFrame(scoped_refptr<CanvasResource>, virtual void SetOffscreenCanvasFrame(
base::WeakPtr<CanvasResourceDispatcher>, scoped_refptr<CanvasResource>,
scoped_refptr<base::SingleThreadTaskRunner>, base::WeakPtr<CanvasResourceDispatcher>,
viz::ResourceId resource_id); scoped_refptr<base::SingleThreadTaskRunner>,
void ReleasePlaceholderFrame(); viz::ResourceId resource_id);
void ReleaseOffscreenCanvasFrame();
void SetSuspendOffscreenCanvasAnimation(bool); void SetSuspendOffscreenCanvasAnimation(bool);
static OffscreenCanvasPlaceholder* GetPlaceholderById( static OffscreenCanvasPlaceholder* GetPlaceholderCanvasById(
unsigned placeholder_id); unsigned placeholder_id);
void RegisterPlaceholder(unsigned placeholder_id); void RegisterPlaceholderCanvas(unsigned placeholder_id);
void UnregisterPlaceholder(); void UnregisterPlaceholderCanvas();
const scoped_refptr<CanvasResource>& PlaceholderFrame() const { const scoped_refptr<CanvasResource>& OffscreenCanvasFrame() const {
return placeholder_frame_; return placeholder_frame_;
} }
bool IsPlaceholderRegistered() const { bool IsOffscreenCanvasRegistered() const {
return placeholder_id_ != kNoPlaceholderId; return placeholder_id_ != kNoPlaceholderId;
} }
private: private:
bool PostSetSuspendAnimationToOffscreenCanvasThread(bool suspend); bool PostSetSuspendAnimationToOffscreenCanvasThread(bool suspend);
// Information about the Offscreen Canvas:
scoped_refptr<CanvasResource> placeholder_frame_; scoped_refptr<CanvasResource> placeholder_frame_;
base::WeakPtr<CanvasResourceDispatcher> frame_dispatcher_; base::WeakPtr<CanvasResourceDispatcher> frame_dispatcher_;
scoped_refptr<base::SingleThreadTaskRunner> frame_dispatcher_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> frame_dispatcher_task_runner_;
......
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