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

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

Issue 1820813004: Add UMA to HTMLCanvasElement to track image formats usage of toDataURL/toBlob (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Matching name of histogram Created 4 years, 9 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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 { 485 {
486 m_size = size; 486 m_size = size;
487 m_didFailToCreateImageBuffer = false; 487 m_didFailToCreateImageBuffer = false;
488 discardImageBuffer(); 488 discardImageBuffer();
489 clearCopiedImage(); 489 clearCopiedImage();
490 if (m_context && m_context->is2d() && m_context->isContextLost()) { 490 if (m_context && m_context->is2d() && m_context->isContextLost()) {
491 m_context->didSetSurfaceSize(); 491 m_context->didSetSurfaceSize();
492 } 492 }
493 } 493 }
494 494
495 String HTMLCanvasElement::toEncodingMimeType(const String& mimeType) 495 String HTMLCanvasElement::toEncodingMimeType(const String& mimeType, const Strin g& callFunctionName)
496 { 496 {
497 String lowercaseMimeType = mimeType.lower(); 497 String lowercaseMimeType = mimeType.lower();
498 if (mimeType.isNull())
499 lowercaseMimeType = DefaultMimeType;
500
501 CanvasReturnImageFormat imageFormat;
502 if (lowercaseMimeType == "image/png") {
503 imageFormat = CanvasReturnImageFormat::Png;
504 } else if (lowercaseMimeType == "image/jpeg") {
505 imageFormat = CanvasReturnImageFormat::Jpeg;
506 } else if (lowercaseMimeType == "image/webp") {
507 imageFormat = CanvasReturnImageFormat::Webp;
508 } else if (lowercaseMimeType == "image/gif") {
509 imageFormat = CanvasReturnImageFormat::Gif;
510 } else if (lowercaseMimeType == "image/bmp") {
Justin Novosad 2016/03/22 15:09:04 There is also an alternate MIME type for bmp: imag
511 imageFormat = CanvasReturnImageFormat::Bmp;
512 } else if (lowercaseMimeType == "image/ico") {
Justin Novosad 2016/03/22 15:09:03 this is not a valid MIME type. should be "image/x-
513 imageFormat = CanvasReturnImageFormat::Ico;
514 } else if (lowercaseMimeType == "image/tiff") {
Justin Novosad 2016/03/22 15:09:03 can also be image/x-tiff
515 imageFormat = CanvasReturnImageFormat::Tiff;
516 } else {
517 imageFormat = CanvasReturnImageFormat::NumberOfImageFormats;
518 }
519
520 if (imageFormat != CanvasReturnImageFormat::NumberOfImageFormats) {
521 if (callFunctionName == "toDataURL") {
522 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toDataURLImage FormatHistogram, new EnumerationHistogram("Canvas.ReturnImageFormats.toDataURL", CanvasReturnImageFormat::NumberOfImageFormats));
523 toDataURLImageFormatHistogram.count(imageFormat);
524 } else if (callFunctionName == "toBlobCallback") {
525 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toBlobCallback ImageFormatHistogram, new EnumerationHistogram("Canvas.ReturnImageFormats.toBlob Callback", CanvasReturnImageFormat::NumberOfImageFormats));
526 toBlobCallbackImageFormatHistogram.count(imageFormat);
527 }
528 }
498 529
499 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread). 530 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread).
500 if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncod ing(lowercaseMimeType)) 531 if (!MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(lowercaseMimeType ))
501 lowercaseMimeType = DefaultMimeType; 532 lowercaseMimeType = DefaultMimeType;
502
503 return lowercaseMimeType; 533 return lowercaseMimeType;
504 } 534 }
505 535
506 const AtomicString HTMLCanvasElement::imageSourceURL() const 536 const AtomicString HTMLCanvasElement::imageSourceURL() const
507 { 537 {
508 return AtomicString(toDataURLInternal(DefaultMimeType, 0, FrontBuffer)); 538 return AtomicString(toDataURLInternal(DefaultMimeType, 0, FrontBuffer));
509 } 539 }
510 540
511 void HTMLCanvasElement::prepareSurfaceForPaintingIfNeeded() const 541 void HTMLCanvasElement::prepareSurfaceForPaintingIfNeeded() const
512 { 542 {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } 577 }
548 578
549 return imageData; 579 return imageData;
550 } 580 }
551 581
552 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double & quality, SourceDrawingBuffer sourceBuffer) const 582 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double & quality, SourceDrawingBuffer sourceBuffer) const
553 { 583 {
554 if (!isPaintable()) 584 if (!isPaintable())
555 return String("data:,"); 585 return String("data:,");
556 586
557 String encodingMimeType = toEncodingMimeType(mimeType); 587 String encodingMimeType = toEncodingMimeType(mimeType, "toDataURL");
558 588
559 ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL); 589 ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL);
560 ScopedDisposal<ImageData> disposer(imageData); 590 ScopedDisposal<ImageData> disposer(imageData);
561 591
562 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU RL(encodingMimeType, quality); 592 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU RL(encodingMimeType, quality);
563 } 593 }
564 594
565 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const 595 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const
566 { 596 {
567 if (!originClean()) { 597 if (!originClean()) {
(...skipping 24 matching lines...) Expand all
592 } 622 }
593 623
594 double quality = UndefinedQualityValue; 624 double quality = UndefinedQualityValue;
595 if (!qualityArgument.isEmpty()) { 625 if (!qualityArgument.isEmpty()) {
596 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); 626 v8::Local<v8::Value> v8Value = qualityArgument.v8Value();
597 if (v8Value->IsNumber()) { 627 if (v8Value->IsNumber()) {
598 quality = v8Value.As<v8::Number>()->Value(); 628 quality = v8Value.As<v8::Number>()->Value();
599 } 629 }
600 } 630 }
601 631
602 String encodingMimeType = toEncodingMimeType(mimeType); 632 String encodingMimeType = toEncodingMimeType(mimeType, "toBlobCallback");
603 633
604 ImageData* imageData = toImageData(BackBuffer, SnapshotReasonToBlob); 634 ImageData* imageData = toImageData(BackBuffer, SnapshotReasonToBlob);
605 // imageData unref its data, which we still keep alive for the async toBlob thread 635 // imageData unref its data, which we still keep alive for the async toBlob thread
606 ScopedDisposal<ImageData> disposer(imageData); 636 ScopedDisposal<ImageData> disposer(imageData);
607 // Add a ref to keep image data alive until completion of encoding 637 // Add a ref to keep image data alive until completion of encoding
608 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); 638 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data());
609 639
610 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback); 640 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback);
611 641
612 if (encodingMimeType == DefaultMimeType) { 642 if (encodingMimeType == DefaultMimeType) {
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 } 1110 }
1081 1111
1082 std::pair<Element*, String> HTMLCanvasElement::getControlAndIdIfHitRegionExists( const LayoutPoint& location) 1112 std::pair<Element*, String> HTMLCanvasElement::getControlAndIdIfHitRegionExists( const LayoutPoint& location)
1083 { 1113 {
1084 if (m_context && m_context->is2d()) 1114 if (m_context && m_context->is2d())
1085 return m_context->getControlAndIdIfHitRegionExists(location); 1115 return m_context->getControlAndIdIfHitRegionExists(location);
1086 return std::make_pair(nullptr, String()); 1116 return std::make_pair(nullptr, String());
1087 } 1117 }
1088 1118
1089 } // namespace blink 1119 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698