Chromium Code Reviews| 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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 enum RequestedImageMimeType { |
|
jwd
2016/03/23 19:05:12
Can you add a comment that this enum is used for a
| |
| 496 RequestedImageMimeTypePng = 0, | |
| 497 RequestedImageMimeTypeJpeg = 1, | |
| 498 RequestedImageMimeTypeWebp = 2, | |
| 499 RequestedImageMimeTypeGif = 3, | |
| 500 RequestedImageMimeTypeBmp = 4, | |
| 501 RequestedImageMimeTypeIco = 5, | |
| 502 RequestedImageMimeTypeTiff = 6, | |
| 503 RequestedImageMimeTypeUnknown = 7, | |
| 504 NumberOfRequestedImageMimeTypes | |
| 505 }; | |
| 506 | |
| 507 String HTMLCanvasElement::toEncodingMimeType(const String& mimeType, const Encod eReason encodeReason) | |
| 496 { | 508 { |
| 497 String lowercaseMimeType = mimeType.lower(); | 509 String lowercaseMimeType = mimeType.lower(); |
| 510 if (mimeType.isNull()) | |
| 511 lowercaseMimeType = DefaultMimeType; | |
| 512 | |
| 513 RequestedImageMimeType imageFormat; | |
| 514 if (lowercaseMimeType == "image/png") { | |
| 515 imageFormat = RequestedImageMimeTypePng; | |
| 516 } else if (lowercaseMimeType == "image/jpeg") { | |
| 517 imageFormat = RequestedImageMimeTypeJpeg; | |
| 518 } else if (lowercaseMimeType == "image/webp") { | |
| 519 imageFormat = RequestedImageMimeTypeWebp; | |
| 520 } else if (lowercaseMimeType == "image/gif") { | |
| 521 imageFormat = RequestedImageMimeTypeGif; | |
| 522 } else if (lowercaseMimeType == "image/bmp" || lowercaseMimeType == "image/x -windows-bmp") { | |
| 523 imageFormat = RequestedImageMimeTypeBmp; | |
| 524 } else if (lowercaseMimeType == "image/x-icon") { | |
| 525 imageFormat = RequestedImageMimeTypeIco; | |
| 526 } else if (lowercaseMimeType == "image/tiff" || lowercaseMimeType == "image/ x-tiff") { | |
| 527 imageFormat = RequestedImageMimeTypeTiff; | |
| 528 } else { | |
| 529 imageFormat = RequestedImageMimeTypeUnknown; | |
| 530 } | |
| 531 | |
| 532 if (encodeReason == EncodeReasonToDataURL) { | |
| 533 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toDataURLImageForm atHistogram, new EnumerationHistogram("Canvas.RequestedImageMimeTypes_toDataURL" , NumberOfRequestedImageMimeTypes)); | |
|
Justin Novosad
2016/03/23 19:35:48
Are you sure it is correct to use "_" as the suffi
| |
| 534 toDataURLImageFormatHistogram.count(imageFormat); | |
| 535 } else if (encodeReason == EncodeReasonToBlobCallback) { | |
| 536 DEFINE_THREAD_SAFE_STATIC_LOCAL(EnumerationHistogram, toBlobCallbackImag eFormatHistogram, new EnumerationHistogram("Canvas.RequestedImageMimeTypes_toBlo bCallback", NumberOfRequestedImageMimeTypes)); | |
| 537 toBlobCallbackImageFormatHistogram.count(imageFormat); | |
| 538 } | |
| 498 | 539 |
| 499 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread). | 540 // FIXME: Make isSupportedImageMIMETypeForEncoding threadsafe (to allow this method to be used on a worker thread). |
| 500 if (mimeType.isNull() || !MIMETypeRegistry::isSupportedImageMIMETypeForEncod ing(lowercaseMimeType)) | 541 if (!MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(lowercaseMimeType )) |
| 501 lowercaseMimeType = DefaultMimeType; | 542 lowercaseMimeType = DefaultMimeType; |
| 502 | |
| 503 return lowercaseMimeType; | 543 return lowercaseMimeType; |
| 504 } | 544 } |
| 505 | 545 |
| 506 const AtomicString HTMLCanvasElement::imageSourceURL() const | 546 const AtomicString HTMLCanvasElement::imageSourceURL() const |
| 507 { | 547 { |
| 508 return AtomicString(toDataURLInternal(DefaultMimeType, 0, FrontBuffer)); | 548 return AtomicString(toDataURLInternal(DefaultMimeType, 0, FrontBuffer)); |
| 509 } | 549 } |
| 510 | 550 |
| 511 void HTMLCanvasElement::prepareSurfaceForPaintingIfNeeded() const | 551 void HTMLCanvasElement::prepareSurfaceForPaintingIfNeeded() const |
| 512 { | 552 { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 } | 587 } |
| 548 | 588 |
| 549 return imageData; | 589 return imageData; |
| 550 } | 590 } |
| 551 | 591 |
| 552 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double & quality, SourceDrawingBuffer sourceBuffer) const | 592 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double & quality, SourceDrawingBuffer sourceBuffer) const |
| 553 { | 593 { |
| 554 if (!isPaintable()) | 594 if (!isPaintable()) |
| 555 return String("data:,"); | 595 return String("data:,"); |
| 556 | 596 |
| 557 String encodingMimeType = toEncodingMimeType(mimeType); | 597 String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToDataURL ); |
| 558 | 598 |
| 559 ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL); | 599 ImageData* imageData = toImageData(sourceBuffer, SnapshotReasonToDataURL); |
| 560 ScopedDisposal<ImageData> disposer(imageData); | 600 ScopedDisposal<ImageData> disposer(imageData); |
| 561 | 601 |
| 562 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU RL(encodingMimeType, quality); | 602 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU RL(encodingMimeType, quality); |
| 563 } | 603 } |
| 564 | 604 |
| 565 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const | 605 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const |
| 566 { | 606 { |
| 567 if (!originClean()) { | 607 if (!originClean()) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 592 } | 632 } |
| 593 | 633 |
| 594 double quality = UndefinedQualityValue; | 634 double quality = UndefinedQualityValue; |
| 595 if (!qualityArgument.isEmpty()) { | 635 if (!qualityArgument.isEmpty()) { |
| 596 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); | 636 v8::Local<v8::Value> v8Value = qualityArgument.v8Value(); |
| 597 if (v8Value->IsNumber()) { | 637 if (v8Value->IsNumber()) { |
| 598 quality = v8Value.As<v8::Number>()->Value(); | 638 quality = v8Value.As<v8::Number>()->Value(); |
| 599 } | 639 } |
| 600 } | 640 } |
| 601 | 641 |
| 602 String encodingMimeType = toEncodingMimeType(mimeType); | 642 String encodingMimeType = toEncodingMimeType(mimeType, EncodeReasonToBlobCal lback); |
| 603 | 643 |
| 604 ImageData* imageData = toImageData(BackBuffer, SnapshotReasonToBlob); | 644 ImageData* imageData = toImageData(BackBuffer, SnapshotReasonToBlob); |
| 605 // imageData unref its data, which we still keep alive for the async toBlob thread | 645 // imageData unref its data, which we still keep alive for the async toBlob thread |
| 606 ScopedDisposal<ImageData> disposer(imageData); | 646 ScopedDisposal<ImageData> disposer(imageData); |
| 607 // Add a ref to keep image data alive until completion of encoding | 647 // Add a ref to keep image data alive until completion of encoding |
| 608 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); | 648 RefPtr<DOMUint8ClampedArray> imageDataRef(imageData->data()); |
| 609 | 649 |
| 610 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback); | 650 RefPtr<CanvasAsyncBlobCreator> asyncCreatorRef = CanvasAsyncBlobCreator::cre ate(imageDataRef.release(), encodingMimeType, imageData->size(), callback); |
| 611 | 651 |
| 612 if (encodingMimeType == DefaultMimeType) { | 652 if (encodingMimeType == DefaultMimeType) { |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1080 } | 1120 } |
| 1081 | 1121 |
| 1082 std::pair<Element*, String> HTMLCanvasElement::getControlAndIdIfHitRegionExists( const LayoutPoint& location) | 1122 std::pair<Element*, String> HTMLCanvasElement::getControlAndIdIfHitRegionExists( const LayoutPoint& location) |
| 1083 { | 1123 { |
| 1084 if (m_context && m_context->is2d()) | 1124 if (m_context && m_context->is2d()) |
| 1085 return m_context->getControlAndIdIfHitRegionExists(location); | 1125 return m_context->getControlAndIdIfHitRegionExists(location); |
| 1086 return std::make_pair(nullptr, String()); | 1126 return std::make_pair(nullptr, String()); |
| 1087 } | 1127 } |
| 1088 | 1128 |
| 1089 } // namespace blink | 1129 } // namespace blink |
| OLD | NEW |