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

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

Issue 2290903002: Change (Pass)RefPtr<SkXxx> into sk_sp<SkXxx>. (Closed)
Patch Set: Self-review. Created 4 years, 3 months 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // misinterpreted as a user-input value 109 // misinterpreted as a user-input value
110 const int UndefinedQualityValue = -1.0; 110 const int UndefinedQualityValue = -1.0;
111 111
112 // Default image mime type for toDataURL and toBlob functions 112 // Default image mime type for toDataURL and toBlob functions
113 const char DefaultMimeType[] = "image/png"; 113 const char DefaultMimeType[] = "image/png";
114 114
115 PassRefPtr<Image> createTransparentImage(const IntSize& size) 115 PassRefPtr<Image> createTransparentImage(const IntSize& size)
116 { 116 {
117 DCHECK(ImageBuffer::canCreateImageBuffer(size)); 117 DCHECK(ImageBuffer::canCreateImageBuffer(size));
118 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(size.width(), size .height()); 118 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul(size.width(), size .height());
119 return StaticBitmapImage::create(fromSkSp(surface->makeImageSnapshot())); 119 return StaticBitmapImage::create(surface->makeImageSnapshot());
120 } 120 }
121 121
122 } // namespace 122 } // namespace
123 123
124 inline HTMLCanvasElement::HTMLCanvasElement(Document& document) 124 inline HTMLCanvasElement::HTMLCanvasElement(Document& document)
125 : HTMLElement(canvasTag, document) 125 : HTMLElement(canvasTag, document)
126 , ContextLifecycleObserver(&document) 126 , ContextLifecycleObserver(&document)
127 , PageVisibilityObserver(document.page()) 127 , PageVisibilityObserver(document.page())
128 , m_size(DefaultWidth, DefaultHeight) 128 , m_size(DefaultWidth, DefaultHeight)
129 , m_ignoreReset(false) 129 , m_ignoreReset(false)
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 if (listener->needsNewFrame()) { 451 if (listener->needsNewFrame()) {
452 listenerNeedsNewFrameCapture = true; 452 listenerNeedsNewFrameCapture = true;
453 } 453 }
454 } 454 }
455 455
456 if (listenerNeedsNewFrameCapture) { 456 if (listenerNeedsNewFrameCapture) {
457 SourceImageStatus status; 457 SourceImageStatus status;
458 RefPtr<Image> sourceImage = getSourceImageForCanvas(&status, PreferNoAcc eleration, SnapshotReasonCanvasListenerCapture, FloatSize()); 458 RefPtr<Image> sourceImage = getSourceImageForCanvas(&status, PreferNoAcc eleration, SnapshotReasonCanvasListenerCapture, FloatSize());
459 if (status != NormalSourceImageStatus) 459 if (status != NormalSourceImageStatus)
460 return; 460 return;
461 RefPtr<SkImage> image = sourceImage->imageForCurrentFrame(); 461 sk_sp<SkImage> image = sourceImage->imageForCurrentFrame();
462 for (CanvasDrawListener* listener : m_listeners) { 462 for (CanvasDrawListener* listener : m_listeners) {
463 if (listener->needsNewFrame()) { 463 if (listener->needsNewFrame()) {
464 listener->sendNewFrame(image); 464 listener->sendNewFrame(image);
f(malita) 2016/09/01 03:55:37 Not new, but it would make sense to std::move(imag
Łukasz Anforowicz 2016/09/01 20:50:57 But this is in a loop, so |image| can be reused, s
f(malita) 2016/09/01 21:03:43 Acknowledged.
465 } 465 }
466 } 466 }
467 } 467 }
468 468
469 } 469 }
470 470
471 void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r) 471 void HTMLCanvasElement::paint(GraphicsContext& context, const LayoutRect& r)
472 { 472 {
473 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and com positing feature. 473 // FIXME: crbug.com/438240; there is a bug with the new CSS blending and com positing feature.
474 if (!m_context) 474 if (!m_context)
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 { 600 {
601 ImageData* imageData; 601 ImageData* imageData;
602 if (is3D()) { 602 if (is3D()) {
603 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL(). 603 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL().
604 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer); 604 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer);
605 if (imageData) 605 if (imageData)
606 return imageData; 606 return imageData;
607 607
608 m_context->paintRenderingResultsToCanvas(sourceBuffer); 608 m_context->paintRenderingResultsToCanvas(sourceBuffer);
609 imageData = ImageData::create(m_size); 609 imageData = ImageData::create(m_size);
610 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAccelera tion, reason); 610 sk_sp<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAccelerat ion, reason);
611 if (snapshot) { 611 if (snapshot) {
612 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8 888_SkColorType, kUnpremul_SkAlphaType); 612 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8 888_SkColorType, kUnpremul_SkAlphaType);
613 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo .minRowBytes(), 0, 0); 613 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo .minRowBytes(), 0, 0);
614 } 614 }
615 return imageData; 615 return imageData;
616 } 616 }
617 617
618 imageData = ImageData::create(m_size); 618 imageData = ImageData::create(m_size);
619 619
620 if (!m_context) 620 if (!m_context)
621 return imageData; 621 return imageData;
622 622
623 DCHECK(m_context->is2d()); 623 DCHECK(m_context->is2d());
624 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration , reason); 624 sk_sp<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration, reason);
625 if (snapshot) { 625 if (snapshot) {
626 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_ SkColorType, kUnpremul_SkAlphaType); 626 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_ SkColorType, kUnpremul_SkAlphaType);
627 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo.min RowBytes(), 0, 0); 627 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo.min RowBytes(), 0, 0);
628 } 628 }
629 629
630 return imageData; 630 return imageData;
631 } 631 }
632 632
633 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double & quality, SourceDrawingBuffer sourceBuffer) const 633 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double & quality, SourceDrawingBuffer sourceBuffer) const
634 { 634 {
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 1116
1117 if (!m_context) { 1117 if (!m_context) {
1118 *status = NormalSourceImageStatus; 1118 *status = NormalSourceImageStatus;
1119 return createTransparentImage(size()); 1119 return createTransparentImage(size());
1120 } 1120 }
1121 1121
1122 if (m_context->is3d()) { 1122 if (m_context->is3d()) {
1123 m_context->paintRenderingResultsToCanvas(BackBuffer); 1123 m_context->paintRenderingResultsToCanvas(BackBuffer);
1124 } 1124 }
1125 1125
1126 RefPtr<SkImage> skImage; 1126 sk_sp<SkImage> skImage;
1127 RefPtr<blink::Image> image = renderingContext()->getImage(); 1127 RefPtr<blink::Image> image = renderingContext()->getImage();
1128 1128
1129 if (image) 1129 if (image)
1130 skImage = image->imageForCurrentFrame(); 1130 skImage = image->imageForCurrentFrame();
1131 else 1131 else
1132 skImage = hasImageBuffer() ? buffer()->newSkImageSnapshot(hint, reason) : createTransparentImage(size())->imageForCurrentFrame(); 1132 skImage = hasImageBuffer() ? buffer()->newSkImageSnapshot(hint, reason) : createTransparentImage(size())->imageForCurrentFrame();
1133 1133
1134 if (skImage) { 1134 if (skImage) {
1135 *status = NormalSourceImageStatus; 1135 *status = NormalSourceImageStatus;
1136 return StaticBitmapImage::create(skImage.release()); 1136 return StaticBitmapImage::create(std::move(skImage));
1137 } 1137 }
1138 1138
1139 *status = InvalidSourceImageStatus; 1139 *status = InvalidSourceImageStatus;
1140 return nullptr; 1140 return nullptr;
1141 } 1141 }
1142 1142
1143 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const 1143 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const
1144 { 1144 {
1145 return !originClean(); 1145 return !originClean();
1146 } 1146 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 1245
1246 bool HTMLCanvasElement::createSurfaceLayer() 1246 bool HTMLCanvasElement::createSurfaceLayer()
1247 { 1247 {
1248 DCHECK(!m_surfaceLayerBridge); 1248 DCHECK(!m_surfaceLayerBridge);
1249 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl()); 1249 std::unique_ptr<CanvasSurfaceLayerBridgeClient> bridgeClient = wrapUnique(ne w CanvasSurfaceLayerBridgeClientImpl());
1250 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient))); 1250 m_surfaceLayerBridge = wrapUnique(new CanvasSurfaceLayerBridge(std::move(bri dgeClient)));
1251 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( )); 1251 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), this->height( ));
1252 } 1252 }
1253 1253
1254 } // namespace blink 1254 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698