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

Move canvas and offscreenCanvas size recorders to their destructors

This prevents us from recording canvas size multiple times for the same
canvas. Also confirmed that we are recording the correct numbers and
move `isOffscreen` to an enum.

Bug: 902000
Change-Id: Ic6e66ec960ae0166699280303a61b574c9320294
Reviewed-on: https://chromium-review.googlesource.com/c/1319180
Commit-Queue: Aaron Krajeski <aaronhk@chromium.org>
Reviewed-by: default avatarFernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606062}
parent 14754da5
......@@ -20,13 +20,15 @@ CanvasRenderingContextHost::CanvasRenderingContextHost() = default;
void CanvasRenderingContextHost::RecordCanvasSizeToUMA(unsigned width,
unsigned height,
bool isOffscreen) {
if (isOffscreen) {
HostType hostType) {
if (hostType == kCanvasHost) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Blink.Canvas.SqrtNumberOfPixels",
std::sqrt(width * height), 1, 5000, 100);
} else if (hostType == kOffscreenCanvasHost) {
UMA_HISTOGRAM_CUSTOM_COUNTS("Blink.OffscreenCanvas.SqrtNumberOfPixels",
std::sqrt(width * height), 1, 5000, 100);
} else {
UMA_HISTOGRAM_CUSTOM_COUNTS("Blink.Canvas.SqrtNumberOfPixels",
std::sqrt(width * height), 1, 5000, 100);
NOTREACHED();
}
}
......
......@@ -34,9 +34,12 @@ class CORE_EXPORT CanvasRenderingContextHost : public CanvasResourceHost,
public:
CanvasRenderingContextHost();
void static RecordCanvasSizeToUMA(unsigned width,
unsigned height,
bool isOffscreen);
enum HostType {
kCanvasHost,
kOffscreenCanvasHost,
};
void static RecordCanvasSizeToUMA(unsigned width, unsigned height, HostType);
virtual void DetachContext() = 0;
virtual void DidDraw(const FloatRect& rect) = 0;
......
......@@ -134,8 +134,6 @@ inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
externally_allocated_memory_(0),
gpu_readback_invoked_in_current_frame_(false),
gpu_readback_successive_frames_(0) {
CanvasRenderingContextHost::RecordCanvasSizeToUMA(
size_.Width(), size_.Height(), false /* Canvas */);
UseCounter::Count(document, WebFeature::kHTMLCanvasElement);
GetDocument().IncrementNumberOfCanvases();
......@@ -147,6 +145,9 @@ intptr_t HTMLCanvasElement::global_gpu_memory_usage_ = 0;
unsigned HTMLCanvasElement::global_accelerated_context_count_ = 0;
HTMLCanvasElement::~HTMLCanvasElement() {
CanvasRenderingContextHost::RecordCanvasSizeToUMA(
size_.Width(), size_.Height(),
CanvasRenderingContextHost::HostType::kCanvasHost);
if (surface_layer_bridge_ && surface_layer_bridge_->GetCcLayer())
GraphicsLayer::UnregisterContentsLayer(surface_layer_bridge_->GetCcLayer());
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
......@@ -571,9 +572,6 @@ void HTMLCanvasElement::Reset() {
IntSize old_size = Size();
IntSize new_size(w, h);
if (old_size != new_size)
CanvasRenderingContextHost::RecordCanvasSizeToUMA(w, h, false /* Canvas */);
// If the size of an existing buffer matches, we can just clear it instead of
// reallocating. This optimization is only done for 2D canvases for now.
if (had_resource_provider && old_size == new_size && Is2d()) {
......
......@@ -46,6 +46,9 @@ OffscreenCanvas* OffscreenCanvas::Create(unsigned width, unsigned height) {
}
OffscreenCanvas::~OffscreenCanvas() {
CanvasRenderingContextHost::RecordCanvasSizeToUMA(
Size().Width(), Size().Height(),
CanvasRenderingContextHost::HostType::kOffscreenCanvasHost);
v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(
-memory_usage_);
}
......@@ -423,9 +426,6 @@ FontSelector* OffscreenCanvas::GetFontSelector() {
}
void OffscreenCanvas::UpdateMemoryUsage() {
CanvasRenderingContextHost::RecordCanvasSizeToUMA(
Size().Width(), Size().Height(), true /* OffscreenCanvas */);
int bytes_per_pixel = ColorParams().BytesPerPixel();
base::CheckedNumeric<int32_t> memory_usage_checked = bytes_per_pixel;
......
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