Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: third_party/WebKit/Source/modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.cpp

Issue 2411703004: Add usage counter to OffscreenCanvas API calls (Closed)
Patch Set: fix compile error Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h" 5 #include "modules/offscreencanvas2d/OffscreenCanvasRenderingContext2D.h"
6 6
7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC ontextOrWebGL2RenderingContext.h" 7 #include "bindings/modules/v8/OffscreenCanvasRenderingContext2DOrWebGLRenderingC ontextOrWebGL2RenderingContext.h"
8 #include "core/frame/ImageBitmap.h" 8 #include "core/frame/ImageBitmap.h"
9 #include "core/frame/Settings.h" 9 #include "core/frame/Settings.h"
10 #include "core/workers/WorkerGlobalScope.h" 10 #include "core/workers/WorkerGlobalScope.h"
(...skipping 27 matching lines...) Expand all
38 toWorkerGlobalScope(executionContext)->workerSettings(); 38 toWorkerGlobalScope(executionContext)->workerSettings();
39 if (workerSettings && workerSettings->disableReadingFromCanvas()) 39 if (workerSettings && workerSettings->disableReadingFromCanvas())
40 canvas->setDisableReadingFromCanvasTrue(); 40 canvas->setDisableReadingFromCanvasTrue();
41 } 41 }
42 42
43 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) { 43 DEFINE_TRACE(OffscreenCanvasRenderingContext2D) {
44 CanvasRenderingContext::trace(visitor); 44 CanvasRenderingContext::trace(visitor);
45 BaseRenderingContext2D::trace(visitor); 45 BaseRenderingContext2D::trace(visitor);
46 } 46 }
47 47
48 void OffscreenCanvasRenderingContext2D::commit(ExceptionState& exceptionState) { 48 void OffscreenCanvasRenderingContext2D::commit(ScriptState* scriptState,
49 ExceptionState& exceptionState) {
50 UseCounter::Feature feature = UseCounter::OffscreenCanvasCommit2D;
51 UseCounter::count(scriptState->getExecutionContext(), feature);
49 if (getOffscreenCanvas()->getAssociatedCanvasId() < 0) { 52 if (getOffscreenCanvas()->getAssociatedCanvasId() < 0) {
50 // If an OffscreenCanvas has no associated canvas Id, it indicates that 53 // If an OffscreenCanvas has no associated canvas Id, it indicates that
51 // it is not an OffscreenCanvas created by transfering control from html 54 // it is not an OffscreenCanvas created by transfering control from html
52 // canvas. 55 // canvas.
53 exceptionState.throwDOMException(InvalidStateError, 56 exceptionState.throwDOMException(InvalidStateError,
54 "Commit() was called on a context whose " 57 "Commit() was called on a context whose "
55 "OffscreenCanvas is not associated with a " 58 "OffscreenCanvas is not associated with a "
56 "canvas element."); 59 "canvas element.");
57 return; 60 return;
58 } 61 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (!imageBuffer()) 133 if (!imageBuffer())
131 return nullptr; 134 return nullptr;
132 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot( 135 sk_sp<SkImage> skImage = m_imageBuffer->newSkImageSnapshot(
133 PreferAcceleration, SnapshotReasonTransferToImageBitmap); 136 PreferAcceleration, SnapshotReasonTransferToImageBitmap);
134 RefPtr<StaticBitmapImage> image = 137 RefPtr<StaticBitmapImage> image =
135 StaticBitmapImage::create(std::move(skImage)); 138 StaticBitmapImage::create(std::move(skImage));
136 image->setOriginClean(this->originClean()); 139 image->setOriginClean(this->originClean());
137 return image; 140 return image;
138 } 141 }
139 142
140 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap() { 143 ImageBitmap* OffscreenCanvasRenderingContext2D::transferToImageBitmap(
144 ScriptState* scriptState) {
145 UseCounter::Feature feature =
146 UseCounter::OffscreenCanvasTransferToImageBitmap2D;
147 UseCounter::count(scriptState->getExecutionContext(), feature);
141 RefPtr<StaticBitmapImage> image = transferToStaticBitmapImage(); 148 RefPtr<StaticBitmapImage> image = transferToStaticBitmapImage();
142 if (!image) 149 if (!image)
143 return nullptr; 150 return nullptr;
144 m_imageBuffer.reset(); // "Transfer" means no retained buffer 151 m_imageBuffer.reset(); // "Transfer" means no retained buffer
145 m_needsMatrixClipRestore = true; 152 m_needsMatrixClipRestore = true;
146 return ImageBitmap::create(std::move(image)); 153 return ImageBitmap::create(std::move(image));
147 } 154 }
148 155
149 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::getImage( 156 PassRefPtr<Image> OffscreenCanvasRenderingContext2D::getImage(
150 AccelerationHint hint, 157 AccelerationHint hint,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 } 241 }
235 242
236 bool OffscreenCanvasRenderingContext2D::isContextLost() const { 243 bool OffscreenCanvasRenderingContext2D::isContextLost() const {
237 return false; 244 return false;
238 } 245 }
239 246
240 bool OffscreenCanvasRenderingContext2D::isPaintable() const { 247 bool OffscreenCanvasRenderingContext2D::isPaintable() const {
241 return this->imageBuffer(); 248 return this->imageBuffer();
242 } 249 }
243 } 250 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698