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

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

Issue 1372463002: Re-land: Make 2D canvas smarter about chosing whether or not to use GPU acceleration (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed assert Created 5 years, 2 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 lowercaseMimeType = "image/png"; 469 lowercaseMimeType = "image/png";
470 470
471 return lowercaseMimeType; 471 return lowercaseMimeType;
472 } 472 }
473 473
474 const AtomicString HTMLCanvasElement::imageSourceURL() const 474 const AtomicString HTMLCanvasElement::imageSourceURL() const
475 { 475 {
476 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer)); 476 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer));
477 } 477 }
478 478
479 void HTMLCanvasElement::prepareSurfaceForPaintingIfNeeded() const
480 {
481 ASSERT(m_context && m_context->is2d()); // This function is called by the 2d context
482 if (buffer())
483 m_imageBuffer->prepareSurfaceForPaintingIfNeeded();
484 }
485
479 ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer) cons t 486 ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer) cons t
480 { 487 {
481 ImageData* imageData; 488 ImageData* imageData;
482 if (is3D()) { 489 if (is3D()) {
483 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL(). 490 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL().
484 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer); 491 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer);
485 if (imageData) 492 if (imageData)
486 return imageData; 493 return imageData;
487 494
488 m_context->paintRenderingResultsToCanvas(sourceBuffer); 495 m_context->paintRenderingResultsToCanvas(sourceBuffer);
489 imageData = ImageData::create(m_size); 496 imageData = ImageData::create(m_size);
490 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(); 497 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAccelera tion);
491 if (snapshot) { 498 if (snapshot) {
492 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8 888_SkColorType, kUnpremul_SkAlphaType); 499 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8 888_SkColorType, kUnpremul_SkAlphaType);
493 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo .minRowBytes(), 0, 0); 500 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo .minRowBytes(), 0, 0);
494 } 501 }
495 return imageData; 502 return imageData;
496 } 503 }
497 504
498 imageData = ImageData::create(m_size); 505 imageData = ImageData::create(m_size);
499 506
500 if (!m_context) 507 if (!m_context)
501 return imageData; 508 return imageData;
502 509
503 ASSERT(m_context->is2d()); 510 ASSERT(m_context->is2d());
504 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(); 511 RefPtr<SkImage> snapshot = buffer()->newSkImageSnapshot(PreferNoAcceleration );
505 if (snapshot) { 512 if (snapshot) {
506 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_ SkColorType, kUnpremul_SkAlphaType); 513 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_ SkColorType, kUnpremul_SkAlphaType);
507 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo.min RowBytes(), 0, 0); 514 snapshot->readPixels(imageInfo, imageData->data()->data(), imageInfo.min RowBytes(), 0, 0);
508 } 515 }
509 516
510 return imageData; 517 return imageData;
511 } 518 }
512 519
513 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, SourceDrawingBuffer sourceBuffer) const 520 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, SourceDrawingBuffer sourceBuffer) const
514 { 521 {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 // FIXME: Actually, avoid setting m_accelerationDisabled at all when 672 // FIXME: Actually, avoid setting m_accelerationDisabled at all when
666 // doing GPU-based rasterization. 673 // doing GPU-based rasterization.
667 if (m_accelerationDisabled) 674 if (m_accelerationDisabled)
668 return adoptPtr(new UnacceleratedImageBufferSurface(deviceSize, opac ityMode)); 675 return adoptPtr(new UnacceleratedImageBufferSurface(deviceSize, opac ityMode));
669 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod e)); 676 return adoptPtr(new AcceleratedImageBufferSurface(deviceSize, opacityMod e));
670 } 677 }
671 678
672 if (shouldAccelerate(deviceSize)) { 679 if (shouldAccelerate(deviceSize)) {
673 if (document().settings()) 680 if (document().settings())
674 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount(); 681 *msaaSampleCount = document().settings()->accelerated2dCanvasMSAASam pleCount();
675 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur face(deviceSize, opacityMode, *msaaSampleCount)); 682 OwnPtr<ImageBufferSurface> surface = adoptPtr(new Canvas2DImageBufferSur face(deviceSize, *msaaSampleCount, opacityMode, Canvas2DLayerBridge::EnableAccel eration));
676 if (surface->isValid()) 683 if (surface->isValid())
677 return surface.release(); 684 return surface.release();
678 } 685 }
679 686
680 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = adoptPtr (new UnacceleratedSurfaceFactory()); 687 OwnPtr<RecordingImageBufferFallbackSurfaceFactory> surfaceFactory = adoptPtr (new UnacceleratedSurfaceFactory());
681 688
682 if (shouldUseDisplayList(deviceSize)) { 689 if (shouldUseDisplayList(deviceSize)) {
683 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu rface(deviceSize, surfaceFactory.release(), opacityMode)); 690 OwnPtr<ImageBufferSurface> surface = adoptPtr(new RecordingImageBufferSu rface(deviceSize, surfaceFactory.release(), opacityMode));
684 if (surface->isValid()) 691 if (surface->isValid())
685 return surface.release(); 692 return surface.release();
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 { 836 {
830 ASSERT(m_context); 837 ASSERT(m_context);
831 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea teImageBuffer) 838 if ((hasImageBuffer() && !m_imageBuffer->isAccelerated()) || m_didFailToCrea teImageBuffer)
832 return; 839 return;
833 discardImageBuffer(); 840 discardImageBuffer();
834 OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque; 841 OpacityMode opacityMode = m_context->hasAlpha() ? NonOpaque : Opaque;
835 m_imageBuffer = ImageBuffer::create(size(), opacityMode); 842 m_imageBuffer = ImageBuffer::create(size(), opacityMode);
836 m_didFailToCreateImageBuffer = !m_imageBuffer; 843 m_didFailToCreateImageBuffer = !m_imageBuffer;
837 } 844 }
838 845
839 PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe r) const 846 PassRefPtr<Image> HTMLCanvasElement::copiedImage(SourceDrawingBuffer sourceBuffe r, AccelerationHint hint) const
840 { 847 {
841 if (!isPaintable()) 848 if (!isPaintable())
842 return nullptr; 849 return nullptr;
843 if (!m_context) 850 if (!m_context)
844 return createTransparentImage(size()); 851 return createTransparentImage(size());
845 852
846 bool needToUpdate = !m_copiedImage; 853 bool needToUpdate = !m_copiedImage;
847 // The concept of SourceDrawingBuffer is valid on only WebGL. 854 // The concept of SourceDrawingBuffer is valid on only WebGL.
848 if (m_context->is3d()) 855 if (m_context->is3d())
849 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer); 856 needToUpdate |= m_context->paintRenderingResultsToCanvas(sourceBuffer);
850 if (needToUpdate && buffer()) { 857 if (needToUpdate && buffer()) {
851 m_copiedImage = buffer()->newImageSnapshot(); 858 m_copiedImage = buffer()->newImageSnapshot(hint);
852 updateExternallyAllocatedMemory(); 859 updateExternallyAllocatedMemory();
853 } 860 }
854 return m_copiedImage; 861 return m_copiedImage;
855 } 862 }
856 863
857 void HTMLCanvasElement::discardImageBuffer() 864 void HTMLCanvasElement::discardImageBuffer()
858 { 865 {
859 m_imageBuffer.clear(); 866 m_imageBuffer.clear();
860 m_dirtyRect = FloatRect(); 867 m_dirtyRect = FloatRect();
861 updateExternallyAllocatedMemory(); 868 updateExternallyAllocatedMemory();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 } 903 }
897 904
898 void HTMLCanvasElement::didMoveToNewDocument(Document& oldDocument) 905 void HTMLCanvasElement::didMoveToNewDocument(Document& oldDocument)
899 { 906 {
900 setObservedDocument(document()); 907 setObservedDocument(document());
901 if (m_context) 908 if (m_context)
902 m_context->didMoveToNewDocument(&document()); 909 m_context->didMoveToNewDocument(&document());
903 HTMLElement::didMoveToNewDocument(oldDocument); 910 HTMLElement::didMoveToNewDocument(oldDocument);
904 } 911 }
905 912
906 PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(SourceImageStatus* status) const 913 PassRefPtr<Image> HTMLCanvasElement::getSourceImageForCanvas(SourceImageStatus* status, AccelerationHint hint) const
907 { 914 {
908 if (!width() || !height()) { 915 if (!width() || !height()) {
909 *status = ZeroSizeCanvasSourceImageStatus; 916 *status = ZeroSizeCanvasSourceImageStatus;
910 return nullptr; 917 return nullptr;
911 } 918 }
912 919
913 if (!isPaintable()) { 920 if (!isPaintable()) {
914 *status = InvalidSourceImageStatus; 921 *status = InvalidSourceImageStatus;
915 return nullptr; 922 return nullptr;
916 } 923 }
917 924
918 if (!m_context) { 925 if (!m_context) {
919 *status = NormalSourceImageStatus; 926 *status = NormalSourceImageStatus;
920 return createTransparentImage(size()); 927 return createTransparentImage(size());
921 } 928 }
922 929
923 if (m_context->is3d()) { 930 if (m_context->is3d()) {
924 m_context->paintRenderingResultsToCanvas(BackBuffer); 931 m_context->paintRenderingResultsToCanvas(BackBuffer);
925 } 932 }
926 933
927 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(); 934 RefPtr<SkImage> image = buffer()->newSkImageSnapshot(hint);
928 if (image) { 935 if (image) {
929 *status = NormalSourceImageStatus; 936 *status = NormalSourceImageStatus;
930 return StaticBitmapImage::create(image.release()); 937 return StaticBitmapImage::create(image.release());
931 } 938 }
932 939
933 *status = InvalidSourceImageStatus; 940 *status = InvalidSourceImageStatus;
934 return nullptr; 941 return nullptr;
935 } 942 }
936 943
937 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const 944 bool HTMLCanvasElement::wouldTaintOrigin(SecurityOrigin*) const
938 { 945 {
939 return !originClean(); 946 return !originClean();
940 } 947 }
941 948
942 FloatSize HTMLCanvasElement::elementSize() const 949 FloatSize HTMLCanvasElement::elementSize() const
943 { 950 {
944 return FloatSize(width(), height()); 951 return FloatSize(width(), height());
945 } 952 }
946 953
947 bool HTMLCanvasElement::isOpaque() const 954 bool HTMLCanvasElement::isOpaque() const
948 { 955 {
949 return m_context && !m_context->hasAlpha(); 956 return m_context && !m_context->hasAlpha();
950 } 957 }
951 958
952 } // blink 959 } // blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLCanvasElement.h ('k') | third_party/WebKit/Source/core/html/HTMLImageElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698