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