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

Unified Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 2493673002: Synchronize OffscreenCanvas content with the placeholder canvas (Closed)
Patch Set: fix obsolete test 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
index fbae8739478899e73a50fbdd7910a19c98595335..40462b1f4dcb9245140cee6624b0e176f5513db3 100644
--- a/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp
@@ -145,6 +145,8 @@ HTMLCanvasElement::~HTMLCanvasElement() {
}
void HTMLCanvasElement::dispose() {
+ releasePlaceholderFrame();
+
if (m_context) {
m_context->detachCanvas();
m_context = nullptr;
@@ -470,8 +472,9 @@ void HTMLCanvasElement::reset() {
}
bool HTMLCanvasElement::paintsIntoCanvasBuffer() const {
+ if (placeholderFrame())
+ return false;
DCHECK(m_context);
-
if (!m_context->isAccelerated())
return true;
if (layoutBox() && layoutBox()->hasAcceleratedCompositing())
@@ -515,7 +518,7 @@ void HTMLCanvasElement::notifyListenersCanvasChanged() {
void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r) {
// FIXME: crbug.com/438240; there is a bug with the new CSS blending and
// compositing feature.
- if (!m_context)
+ if (!m_context && !placeholderFrame())
return;
const ComputedStyle* style = ensureComputedStyle();
@@ -536,6 +539,12 @@ void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r) {
if (!paintsIntoCanvasBuffer() && !document().printing())
return;
+ if (placeholderFrame()) {
+ DCHECK(document().printing());
+ context.drawImage(placeholderFrame().get(), pixelSnappedIntRect(r));
+ return;
+ }
+
// TODO(junov): Paint is currently only implemented by ImageBitmap contexts.
// We could improve the abstraction by making all context types paint
// themselves (implement paint()).
@@ -619,19 +628,22 @@ ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer,
imageData = ImageData::create(m_size);
- if (!m_context || !imageData)
+ if ((!m_context || !imageData) && !placeholderFrame())
return imageData;
- DCHECK(m_context->is2d());
+ DCHECK((m_context && m_context->is2d()) || placeholderFrame());
+ sk_sp<SkImage> snapshot;
if (hasImageBuffer()) {
- sk_sp<SkImage> snapshot =
- buffer()->newSkImageSnapshot(PreferNoAcceleration, reason);
- if (snapshot) {
- SkImageInfo imageInfo = SkImageInfo::Make(
- width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);
- snapshot->readPixels(imageInfo, imageData->data()->data(),
- imageInfo.minRowBytes(), 0, 0);
- }
+ snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration, reason);
+ } else if (placeholderFrame()) {
+ snapshot = placeholderFrame()->imageForCurrentFrame();
+ }
+
+ if (snapshot) {
+ SkImageInfo imageInfo = SkImageInfo::Make(
+ width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);
+ snapshot->readPixels(imageInfo, imageData->data()->data(),
+ imageInfo.minRowBytes(), 0, 0);
}
return imageData;
@@ -683,13 +695,6 @@ String HTMLCanvasElement::toDataURLInternal(
String HTMLCanvasElement::toDataURL(const String& mimeType,
const ScriptValue& qualityArgument,
ExceptionState& exceptionState) const {
- if (surfaceLayerBridge()) {
- exceptionState.throwDOMException(InvalidStateError,
- "canvas.toDataURL is not allowed for a "
- "canvas that has transferred its control "
- "to offscreen.");
- return String();
- }
if (!originClean()) {
exceptionState.throwSecurityError("Tainted canvases may not be exported.");
return String();
@@ -709,14 +714,6 @@ void HTMLCanvasElement::toBlob(BlobCallback* callback,
const String& mimeType,
const ScriptValue& qualityArgument,
ExceptionState& exceptionState) {
- if (surfaceLayerBridge()) {
- exceptionState.throwDOMException(InvalidStateError,
- "canvas.toBlob is not allowed for a "
- "canvas that has transferred its control "
- "to offscreen.");
- return;
- }
-
if (!originClean()) {
exceptionState.throwSecurityError("Tainted canvases may not be exported.");
return;
@@ -1200,6 +1197,11 @@ PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(
return nullptr;
}
+ if (placeholderFrame()) {
+ *status = NormalSourceImageStatus;
+ return placeholderFrame();
+ }
+
if (!m_context) {
*status = NormalSourceImageStatus;
return createTransparentImage(size());

Powered by Google App Engine
This is Rietveld 408576698