Commit b65449a2 authored by Aaron Krajeski's avatar Aaron Krajeski Committed by Commit Bot

Add metrics for offscreen canvas

Bug: 894043
Change-Id: Idcfd3f4d430c7bce4c13448c80996128ca831f72
Reviewed-on: https://chromium-review.googlesource.com/c/1265815
Commit-Queue: Aaron Krajeski <aaronhk@chromium.org>
Reviewed-by: default avatarJeremy Roman <jbroman@chromium.org>
Reviewed-by: default avatarRobert Kaplow (sloooow) <rkaplow@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#599659}
parent 62d2bd99
......@@ -369,6 +369,7 @@ void SerializedScriptValue::TransferOffscreenCanvas(
}
visited.insert(offscreen_canvases[i].Get());
offscreen_canvases[i].Get()->SetNeutered();
offscreen_canvases[i].Get()->RecordTransfer();
}
}
......
......@@ -75,6 +75,7 @@ class CORE_EXPORT CanvasRenderingContext : public ScriptWrappable,
kContextXRPresent = 6,
kContextWebgl2Compute = 7,
kContextTypeCount,
kMaxValue = kContextWebgl2Compute,
};
static ContextType ContextTypeFromId(const String& id);
......
......@@ -27,6 +27,7 @@
#include "third_party/blink/renderer/platform/graphics/image.h"
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"
#include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h"
#include "third_party/blink/renderer/platform/histogram.h"
#include "third_party/blink/renderer/platform/image-encoders/image_encoder_utils.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/trace_event.h"
#include "third_party/blink/renderer/platform/wtf/math_extras.h"
......@@ -36,7 +37,14 @@ namespace blink {
OffscreenCanvas::OffscreenCanvas(const IntSize& size) : size_(size) {}
void OffscreenCanvas::RecordCanvasSizeToUMA(unsigned width, unsigned height) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Blink.OffscreenCanvas.SqrtNumberOfPixels",
std::sqrt(width * height), 0, 5000, 100);
}
OffscreenCanvas* OffscreenCanvas::Create(unsigned width, unsigned height) {
UMA_HISTOGRAM_BOOLEAN("Blink.OffscreenCanvas.NewOffscreenCanvas", true);
RecordCanvasSizeToUMA(width, height);
return new OffscreenCanvas(
IntSize(clampTo<int>(width), clampTo<int>(height)));
}
......@@ -107,6 +115,9 @@ void OffscreenCanvas::SetSize(const IntSize& size) {
origin_clean_ = true;
}
}
if (size != size_) {
RecordCanvasSizeToUMA(size.Width(), size.Height());
}
size_ = size;
if (frame_dispatcher_)
frame_dispatcher_->Reshape(size_);
......@@ -116,6 +127,10 @@ void OffscreenCanvas::SetSize(const IntSize& size) {
context_->DidDraw();
}
void OffscreenCanvas::RecordTransfer() {
UMA_HISTOGRAM_BOOLEAN("Blink.OffscreenCanvas.Transferred", true);
}
void OffscreenCanvas::SetNeutered() {
DCHECK(!context_);
is_neutered_ = true;
......@@ -203,6 +218,12 @@ CanvasRenderingContext* OffscreenCanvas::GetCanvasRenderingContext(
return nullptr;
}
// Log the aliased context type used.
if (!context_) {
UMA_HISTOGRAM_ENUMERATION("Blink.OffscreenCanvas.ContextType",
context_type);
}
CanvasRenderingContextFactory* factory =
GetRenderingContextFactory(context_type);
if (!factory)
......
......@@ -45,6 +45,9 @@ class CORE_EXPORT OffscreenCanvas final
USING_GARBAGE_COLLECTED_MIXIN(OffscreenCanvas);
USING_PRE_FINALIZER(OffscreenCanvas, Dispose);
private:
void static RecordCanvasSizeToUMA(unsigned width, unsigned height);
public:
static OffscreenCanvas* Create(unsigned width, unsigned height);
~OffscreenCanvas() override;
......@@ -65,6 +68,7 @@ class CORE_EXPORT OffscreenCanvas final
const IntSize& Size() const override { return size_; }
void SetSize(const IntSize&);
void RecordTransfer();
void SetPlaceholderCanvasId(DOMNodeId canvas_id);
DOMNodeId PlaceholderCanvasId() const { return placeholder_canvas_id_; }
......
......@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h"
#include "third_party/blink/renderer/modules/canvas/htmlcanvas/canvas_context_creation_attributes_helpers.h"
#include "third_party/blink/renderer/modules/canvas/htmlcanvas/canvas_context_creation_attributes_module.h"
#include "third_party/blink/renderer/platform/histogram.h"
namespace blink {
......@@ -38,16 +39,20 @@ void HTMLCanvasElementModule::getContext(
OffscreenCanvas* HTMLCanvasElementModule::transferControlToOffscreen(
HTMLCanvasElement& canvas,
ExceptionState& exception_state) {
OffscreenCanvas* offscreen_canvas = nullptr;
if (canvas.SurfaceLayerBridge()) {
exception_state.ThrowDOMException(
DOMExceptionCode::kInvalidStateError,
"Cannot transfer control from a canvas for more than one time.");
return nullptr;
} else {
canvas.CreateLayer();
offscreen_canvas =
TransferControlToOffscreenInternal(canvas, exception_state);
}
canvas.CreateLayer();
return TransferControlToOffscreenInternal(canvas, exception_state);
UMA_HISTOGRAM_BOOLEAN("Blink.OffscreenCanvas.TransferControlToOffscreen",
bool(offscreen_canvas));
return offscreen_canvas;
}
OffscreenCanvas* HTMLCanvasElementModule::TransferControlToOffscreenInternal(
......
......@@ -9436,6 +9436,51 @@ uploading your change for review.
</summary>
</histogram>
<histogram name="Blink.OffscreenCanvas.ContextType" enum="CanvasContextType">
<owner>aaronhk@chromium.org</owner>
<owner>fserb@chromium.org</owner>
<summary>
Records the context type names used to create offscreen canvas rendering
contexts. Recorded in OffscreenCanvas::GetCanvasRenderingContext
</summary>
</histogram>
<histogram name="Blink.OffscreenCanvas.NewOffscreenCanvas" enum="Boolean">
<owner>aaronhk@chromium.org</owner>
<owner>fserb@chromium.org</owner>
<summary>
Records the creation of a new offscreen canvas in OffscreenCanvas::Create.
</summary>
</histogram>
<histogram name="Blink.OffscreenCanvas.SqrtNumberOfPixels" units="sqrt(pixels)">
<owner>aaronhk@chromium.org</owner>
<owner>fserb@chromium.org</owner>
<summary>
Stores the square root of the number of pixels in a new or resized offscreen
canvas.
</summary>
</histogram>
<histogram name="Blink.OffscreenCanvas.TransferControlToOffscreen"
enum="Boolean">
<owner>aaronhk@chromium.org</owner>
<owner>fserb@chromium.org</owner>
<summary>
Records a call to transfer a canvas offscreen. True indicates a successful
transfer, false for a failure.
</summary>
</histogram>
<histogram name="Blink.OffscreenCanvas.Transferred" enum="Boolean">
<owner>aaronhk@chromium.org</owner>
<owner>fserb@chromium.org</owner>
<summary>
Records when an offscreen canvas has been transferred from the main thread
to a worker.
</summary>
</histogram>
<histogram name="Blink.Paint.UpdateTime" units="microseconds">
<owner>paint-dev@chromium.org</owner>
<summary>
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