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 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 { | 462 { |
463 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer)); | 463 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer)); |
464 } | 464 } |
465 | 465 |
466 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, SourceDrawingBuffer sourceBuffer) const | 466 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double * quality, SourceDrawingBuffer sourceBuffer) const |
467 { | 467 { |
468 if (!isPaintable()) | 468 if (!isPaintable()) |
469 return String("data:,"); | 469 return String("data:,"); |
470 | 470 |
471 String encodingMimeType = toEncodingMimeType(mimeType); | 471 String encodingMimeType = toEncodingMimeType(mimeType); |
472 if (!m_context) { | 472 |
473 ImageData* imageData = ImageData::create(m_size); | 473 if (is3D()) { |
474 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL(). | |
475 ImageData* imageData = m_context->paintRenderingResultsToImageData(sourc eBuffer); | |
474 ScopedDisposal<ImageData> disposer(imageData); | 476 ScopedDisposal<ImageData> disposer(imageData); |
477 if (imageData) { | |
Stephen White
2015/07/16 19:13:01
I think this would be clearer and have less code d
| |
478 return ImageDataBuffer(imageData->size(), imageData->data()->data()) .toDataURL(encodingMimeType, quality); | |
479 } | |
480 m_context->paintRenderingResultsToCanvas(sourceBuffer); | |
481 imageData = ImageData::create(m_size); | |
482 ScopedDisposal<ImageData> disposer2(imageData); | |
475 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toD ataURL(encodingMimeType, quality); | 483 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toD ataURL(encodingMimeType, quality); |
476 } | 484 } |
477 | 485 |
478 if (m_context->is3d()) { | 486 ImageData* imageData = ImageData::create(m_size); |
479 // Get non-premultiplied data because of inaccurate premultiplied alpha conversion of buffer()->toDataURL(). | 487 ScopedDisposal<ImageData> disposer(imageData); |
480 ImageData* imageData = m_context->paintRenderingResultsToImageData(sourc eBuffer); | 488 |
481 ScopedDisposal<ImageData> disposer(imageData); | 489 if (m_context) { |
482 if (imageData) | 490 ASSERT(m_context->is2d()); |
483 return ImageDataBuffer(imageData->size(), imageData->data()->data()) .toDataURL(encodingMimeType, quality); | 491 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_ SkColorType, kUnpremul_SkAlphaType); |
484 m_context->paintRenderingResultsToCanvas(sourceBuffer); | 492 buffer()->bitmap().readPixels(imageInfo, imageData->data()->data(), imag eInfo.minRowBytes(), 0, 0); |
485 } | 493 } |
486 | 494 |
487 return buffer()->toDataURL(encodingMimeType, quality); | 495 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU RL(encodingMimeType, quality); |
488 } | 496 } |
489 | 497 |
490 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const | 498 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q ualityArgument, ExceptionState& exceptionState) const |
491 { | 499 { |
492 if (!originClean()) { | 500 if (!originClean()) { |
493 exceptionState.throwSecurityError("Tainted canvases may not be exported. "); | 501 exceptionState.throwSecurityError("Tainted canvases may not be exported. "); |
494 return String(); | 502 return String(); |
495 } | 503 } |
496 double quality; | 504 double quality; |
497 double* qualityPtr = nullptr; | 505 double* qualityPtr = nullptr; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 { | 869 { |
862 return FloatSize(width(), height()); | 870 return FloatSize(width(), height()); |
863 } | 871 } |
864 | 872 |
865 bool HTMLCanvasElement::isOpaque() const | 873 bool HTMLCanvasElement::isOpaque() const |
866 { | 874 { |
867 return m_context && !m_context->hasAlpha(); | 875 return m_context && !m_context->hasAlpha(); |
868 } | 876 } |
869 | 877 |
870 } // blink | 878 } // blink |
OLD | NEW |