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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp

Issue 2559013002: Add ColorBehavior to blink::Image draw methods (Closed)
Patch Set: Rebase Created 4 years 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 /* 1 /*
2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Alp Toker <alp@atoker.com> 3 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 483 }
484 } 484 }
485 485
486 if (listenerNeedsNewFrameCapture) { 486 if (listenerNeedsNewFrameCapture) {
487 SourceImageStatus status; 487 SourceImageStatus status;
488 RefPtr<Image> sourceImage = getSourceImageForCanvas( 488 RefPtr<Image> sourceImage = getSourceImageForCanvas(
489 &status, PreferNoAcceleration, SnapshotReasonCanvasListenerCapture, 489 &status, PreferNoAcceleration, SnapshotReasonCanvasListenerCapture,
490 FloatSize()); 490 FloatSize());
491 if (status != NormalSourceImageStatus) 491 if (status != NormalSourceImageStatus)
492 return; 492 return;
493 sk_sp<SkImage> image = sourceImage->imageForCurrentFrame(); 493 // TODO(ccameron): Canvas should produce sRGB images.
494 // https://crbug.com/672299
495 sk_sp<SkImage> image = sourceImage->imageForCurrentFrame(
496 ColorBehavior::transformToGlobalTarget());
494 for (CanvasDrawListener* listener : m_listeners) { 497 for (CanvasDrawListener* listener : m_listeners) {
495 if (listener->needsNewFrame()) { 498 if (listener->needsNewFrame()) {
496 listener->sendNewFrame(image); 499 listener->sendNewFrame(image);
497 } 500 }
498 } 501 }
499 } 502 }
500 } 503 }
501 504
502 void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r) { 505 void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r) {
503 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and 506 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 imageData = ImageData::create(m_size); 616 imageData = ImageData::create(m_size);
614 617
615 if ((!m_context || !imageData) && !placeholderFrame()) 618 if ((!m_context || !imageData) && !placeholderFrame())
616 return imageData; 619 return imageData;
617 620
618 DCHECK((m_context && m_context->is2d()) || placeholderFrame()); 621 DCHECK((m_context && m_context->is2d()) || placeholderFrame());
619 sk_sp<SkImage> snapshot; 622 sk_sp<SkImage> snapshot;
620 if (hasImageBuffer()) { 623 if (hasImageBuffer()) {
621 snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration, reason); 624 snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration, reason);
622 } else if (placeholderFrame()) { 625 } else if (placeholderFrame()) {
623 snapshot = placeholderFrame()->imageForCurrentFrame(); 626 // TODO(ccameron): Canvas should produce sRGB images.
627 // https://crbug.com/672299
628 snapshot = placeholderFrame()->imageForCurrentFrame(
629 ColorBehavior::transformToGlobalTarget());
624 } 630 }
625 631
626 if (snapshot) { 632 if (snapshot) {
627 SkImageInfo imageInfo = SkImageInfo::Make( 633 SkImageInfo imageInfo = SkImageInfo::Make(
628 width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType); 634 width(), height(), kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);
629 snapshot->readPixels(imageInfo, imageData->data()->data(), 635 snapshot->readPixels(imageInfo, imageData->data()->data(),
630 imageInfo.minRowBytes(), 0, 0); 636 imageInfo.minRowBytes(), 0, 0);
631 } 637 }
632 638
633 return imageData; 639 return imageData;
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 1206
1201 if (!m_context) { 1207 if (!m_context) {
1202 *status = NormalSourceImageStatus; 1208 *status = NormalSourceImageStatus;
1203 return createTransparentImage(size()); 1209 return createTransparentImage(size());
1204 } 1210 }
1205 1211
1206 if (m_context->getContextType() == CanvasRenderingContext::ContextImageBitmap) 1212 if (m_context->getContextType() == CanvasRenderingContext::ContextImageBitmap)
1207 return m_context->getImage(hint, reason); 1213 return m_context->getImage(hint, reason);
1208 1214
1209 sk_sp<SkImage> skImage; 1215 sk_sp<SkImage> skImage;
1216 // TODO(ccameron): Canvas should produce sRGB images.
1217 // https://crbug.com/672299
1210 if (m_context->is3d()) { 1218 if (m_context->is3d()) {
1211 // Because WebGL sources always require making a copy of the back buffer, we 1219 // Because WebGL sources always require making a copy of the back buffer, we
1212 // use paintRenderingResultsToCanvas instead of getImage in order to keep a 1220 // use paintRenderingResultsToCanvas instead of getImage in order to keep a
1213 // cached copy of the backing in the canvas's ImageBuffer. 1221 // cached copy of the backing in the canvas's ImageBuffer.
1214 renderingContext()->paintRenderingResultsToCanvas(BackBuffer); 1222 renderingContext()->paintRenderingResultsToCanvas(BackBuffer);
1215 skImage = hasImageBuffer() 1223 skImage = hasImageBuffer()
1216 ? buffer()->newSkImageSnapshot(hint, reason) 1224 ? buffer()->newSkImageSnapshot(hint, reason)
1217 : createTransparentImage(size())->imageForCurrentFrame(); 1225 : createTransparentImage(size())->imageForCurrentFrame(
1226 ColorBehavior::transformToGlobalTarget());
1218 } else { 1227 } else {
1219 if (ExpensiveCanvasHeuristicParameters:: 1228 if (ExpensiveCanvasHeuristicParameters::
1220 DisableAccelerationToAvoidReadbacks && 1229 DisableAccelerationToAvoidReadbacks &&
1221 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled() && 1230 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled() &&
1222 hint == PreferNoAcceleration && m_context->isAccelerated() && 1231 hint == PreferNoAcceleration && m_context->isAccelerated() &&
1223 hasImageBuffer()) 1232 hasImageBuffer())
1224 buffer()->disableAcceleration(); 1233 buffer()->disableAcceleration();
1225 RefPtr<blink::Image> image = renderingContext()->getImage(hint, reason); 1234 RefPtr<blink::Image> image = renderingContext()->getImage(hint, reason);
1226 skImage = image ? image->imageForCurrentFrame() 1235 skImage = image
1227 : createTransparentImage(size())->imageForCurrentFrame(); 1236 ? image->imageForCurrentFrame(
1237 ColorBehavior::transformToGlobalTarget())
1238 : createTransparentImage(size())->imageForCurrentFrame(
1239 ColorBehavior::transformToGlobalTarget());
1228 } 1240 }
1229 1241
1230 if (skImage) { 1242 if (skImage) {
1231 *status = NormalSourceImageStatus; 1243 *status = NormalSourceImageStatus;
1232 return StaticBitmapImage::create(std::move(skImage)); 1244 return StaticBitmapImage::create(std::move(skImage));
1233 } 1245 }
1234 1246
1235 *status = InvalidSourceImageStatus; 1247 *status = InvalidSourceImageStatus;
1236 return nullptr; 1248 return nullptr;
1237 } 1249 }
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1369 mojom::blink::OffscreenCanvasSurfacePtr service; 1381 mojom::blink::OffscreenCanvasSurfacePtr service;
1370 Platform::current()->interfaceProvider()->getInterface( 1382 Platform::current()->interfaceProvider()->getInterface(
1371 mojo::GetProxy(&service)); 1383 mojo::GetProxy(&service));
1372 m_surfaceLayerBridge = 1384 m_surfaceLayerBridge =
1373 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); 1385 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service)));
1374 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), 1386 return m_surfaceLayerBridge->createSurfaceLayer(this->width(),
1375 this->height()); 1387 this->height());
1376 } 1388 }
1377 1389
1378 } // namespace blink 1390 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698