OLD | NEW |
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 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 | 692 |
693 String HTMLCanvasElement::toDataURLInternal( | 693 String HTMLCanvasElement::toDataURLInternal( |
694 const String& mimeType, | 694 const String& mimeType, |
695 const double& quality, | 695 const double& quality, |
696 SourceDrawingBuffer sourceBuffer) const { | 696 SourceDrawingBuffer sourceBuffer) const { |
697 if (!isPaintable()) | 697 if (!isPaintable()) |
698 return String("data:,"); | 698 return String("data:,"); |
699 | 699 |
700 String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToDataURL); | 700 String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToDataURL); |
701 | 701 |
| 702 Optional<ScopedUsHistogramTimer> timer; |
| 703 if (encodingMimeType == "image/png") { |
| 704 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 705 CustomCountHistogram, scopedUsCounterPNG, |
| 706 new CustomCountHistogram("Blink.Canvas.ToDataURL.PNG", 0, 10000000, |
| 707 50)); |
| 708 timer.emplace(scopedUsCounterPNG); |
| 709 } else if (encodingMimeType == "image/jpeg") { |
| 710 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 711 CustomCountHistogram, scopedUsCounterJPEG, |
| 712 new CustomCountHistogram("Blink.Canvas.ToDataURL.JPEG", 0, 10000000, |
| 713 50)); |
| 714 timer.emplace(scopedUsCounterJPEG); |
| 715 } else if (encodingMimeType == "image/webp") { |
| 716 DEFINE_THREAD_SAFE_STATIC_LOCAL( |
| 717 CustomCountHistogram, scopedUsCounterWEBP, |
| 718 new CustomCountHistogram("Blink.Canvas.ToDataURL.WEBP", 0, 10000000, |
| 719 50)); |
| 720 timer.emplace(scopedUsCounterWEBP); |
| 721 } else { |
| 722 // Currently we only support three encoding types. |
| 723 NOTREACHED(); |
| 724 } |
| 725 |
702 ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL); | 726 ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL); |
703 | 727 |
704 if (!imageData) // allocation failure | 728 if (!imageData) // allocation failure |
705 return String("data:,"); | 729 return String("data:,"); |
706 | 730 |
707 return ImageDataBuffer(imageData->size(), imageData->data()->data()) | 731 return ImageDataBuffer(imageData->size(), imageData->data()->data()) |
708 .toDataURL(encodingMimeType, quality); | 732 .toDataURL(encodingMimeType, quality); |
709 } | 733 } |
710 | 734 |
711 String HTMLCanvasElement::toDataURL(const String& mimeType, | 735 String HTMLCanvasElement::toDataURL(const String& mimeType, |
712 const ScriptValue& qualityArgument, | 736 const ScriptValue& qualityArgument, |
713 ExceptionState& exceptionState) const { | 737 ExceptionState& exceptionState) const { |
714 if (surfaceLayerBridge()) { | 738 if (surfaceLayerBridge()) { |
715 exceptionState.throwDOMException(InvalidStateError, | 739 exceptionState.throwDOMException(InvalidStateError, |
716 "canvas.toDataURL is not allowed for a " | 740 "canvas.toDataURL is not allowed for a " |
717 "canvas that has transferred its control " | 741 "canvas that has transferred its control " |
718 "to offscreen."); | 742 "to offscreen."); |
719 return String(); | 743 return String(); |
720 } | 744 } |
721 if (!originClean()) { | 745 if (!originClean()) { |
722 exceptionState.throwSecurityError("Tainted canvases may not be exported."); | 746 exceptionState.throwSecurityError("Tainted canvases may not be exported."); |
723 return String(); | 747 return String(); |
724 } | 748 } |
725 Optional<ScopedUsHistogramTimer> timer; | |
726 String lowercaseMimeType = mimeType.lower(); | |
727 if (mimeType.isNull()) | |
728 lowercaseMimeType = DefaultMimeType; | |
729 if (lowercaseMimeType == "image/png") { | |
730 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
731 CustomCountHistogram, scopedUsCounterPNG, | |
732 new CustomCountHistogram("Blink.Canvas.ToDataURL.PNG", 0, 10000000, | |
733 50)); | |
734 timer.emplace(scopedUsCounterPNG); | |
735 } else if (lowercaseMimeType == "image/jpeg") { | |
736 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
737 CustomCountHistogram, scopedUsCounterJPEG, | |
738 new CustomCountHistogram("Blink.Canvas.ToDataURL.JPEG", 0, 10000000, | |
739 50)); | |
740 timer.emplace(scopedUsCounterJPEG); | |
741 } else if (lowercaseMimeType == "image/webp") { | |
742 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
743 CustomCountHistogram, scopedUsCounterWEBP, | |
744 new CustomCountHistogram("Blink.Canvas.ToDataURL.WEBP", 0, 10000000, | |
745 50)); | |
746 timer.emplace(scopedUsCounterWEBP); | |
747 } else if (lowercaseMimeType == "image/gif") { | |
748 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
749 CustomCountHistogram, scopedUsCounterGIF, | |
750 new CustomCountHistogram("Blink.Canvas.ToDataURL.GIF", 0, 10000000, | |
751 50)); | |
752 timer.emplace(scopedUsCounterGIF); | |
753 } else if (lowercaseMimeType == "image/bmp" || | |
754 lowercaseMimeType == "image/x-windows-bmp") { | |
755 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
756 CustomCountHistogram, scopedUsCounterBMP, | |
757 new CustomCountHistogram("Blink.Canvas.ToDataURL.BMP", 0, 10000000, | |
758 50)); | |
759 timer.emplace(scopedUsCounterBMP); | |
760 } else if (lowercaseMimeType == "image/x-icon") { | |
761 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
762 CustomCountHistogram, scopedUsCounterICON, | |
763 new CustomCountHistogram("Blink.Canvas.ToDataURL.ICON", 0, 10000000, | |
764 50)); | |
765 timer.emplace(scopedUsCounterICON); | |
766 } else if (lowercaseMimeType == "image/tiff" || | |
767 lowercaseMimeType == "image/x-tiff") { | |
768 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
769 CustomCountHistogram, scopedUsCounterTIFF, | |
770 new CustomCountHistogram("Blink.Canvas.ToDataURL.TIFF", 0, 10000000, | |
771 50)); | |
772 timer.emplace(scopedUsCounterTIFF); | |
773 } else { | |
774 DEFINE_THREAD_SAFE_STATIC_LOCAL( | |
775 CustomCountHistogram, scopedUsCounterUnknown, | |
776 new CustomCountHistogram("Blink.Canvas.ToDataURL.Unknown", 0, 10000000, | |
777 50)); | |
778 timer.emplace(scopedUsCounterUnknown); | |
779 } | |
780 | 749 |
781 double quality = UndefinedQualityValue; | 750 double quality = UndefinedQualityValue; |
782 if (!qualityArgument.isEmpty()) { | 751 if (!qualityArgument.isEmpty()) { |
783 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); | 752 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); |
784 if (v8Value->IsNumber()) { | 753 if (v8Value->IsNumber()) { |
785 quality = v8Value.As<v8::Number>()->Value(); | 754 quality = v8Value.As<v8::Number>()->Value(); |
786 } | 755 } |
787 } | 756 } |
788 return toDataURLInternal(mimeType, quality, BackBuffer); | 757 return toDataURLInternal(mimeType, quality, BackBuffer); |
789 } | 758 } |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 mojom::blink::OffscreenCanvasSurfacePtr service; | 1408 mojom::blink::OffscreenCanvasSurfacePtr service; |
1440 Platform::current()->interfaceProvider()->getInterface( | 1409 Platform::current()->interfaceProvider()->getInterface( |
1441 mojo::GetProxy(&service)); | 1410 mojo::GetProxy(&service)); |
1442 m_surfaceLayerBridge = | 1411 m_surfaceLayerBridge = |
1443 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); | 1412 wrapUnique(new CanvasSurfaceLayerBridge(std::move(service))); |
1444 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), | 1413 return m_surfaceLayerBridge->createSurfaceLayer(this->width(), |
1445 this->height()); | 1414 this->height()); |
1446 } | 1415 } |
1447 | 1416 |
1448 } // namespace blink | 1417 } // namespace blink |
OLD | NEW |