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 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 lowercaseMimeType = "image/png"; | 456 lowercaseMimeType = "image/png"; |
457 | 457 |
458 return lowercaseMimeType; | 458 return lowercaseMimeType; |
459 } | 459 } |
460 | 460 |
461 const AtomicString HTMLCanvasElement::imageSourceURL() const | 461 const AtomicString HTMLCanvasElement::imageSourceURL() const |
462 { | 462 { |
463 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer)); | 463 return AtomicString(toDataURLInternal("image/png", 0, FrontBuffer)); |
464 } | 464 } |
465 | 465 |
| 466 ImageData* HTMLCanvasElement::toImageData(SourceDrawingBuffer sourceBuffer) cons
t |
| 467 { |
| 468 ImageData* imageData; |
| 469 if (is3D()) { |
| 470 // Get non-premultiplied data because of inaccurate premultiplied alpha
conversion of buffer()->toDataURL(). |
| 471 imageData = m_context->paintRenderingResultsToImageData(sourceBuffer); |
| 472 if (imageData) |
| 473 return imageData; |
| 474 |
| 475 m_context->paintRenderingResultsToCanvas(sourceBuffer); |
| 476 imageData = ImageData::create(m_size); |
| 477 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_
SkColorType, kUnpremul_SkAlphaType); |
| 478 buffer()->bitmap().readPixels(imageInfo, imageData->data()->data(), imag
eInfo.minRowBytes(), 0, 0); |
| 479 return imageData; |
| 480 } |
| 481 |
| 482 imageData = ImageData::create(m_size); |
| 483 |
| 484 if (m_context) { |
| 485 ASSERT(m_context->is2d()); |
| 486 SkImageInfo imageInfo = SkImageInfo::Make(width(), height(), kRGBA_8888_
SkColorType, kUnpremul_SkAlphaType); |
| 487 buffer()->bitmap().readPixels(imageInfo, imageData->data()->data(), imag
eInfo.minRowBytes(), 0, 0); |
| 488 } |
| 489 return imageData; |
| 490 } |
| 491 |
466 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double
* quality, SourceDrawingBuffer sourceBuffer) const | 492 String HTMLCanvasElement::toDataURLInternal(const String& mimeType, const double
* quality, SourceDrawingBuffer sourceBuffer) const |
467 { | 493 { |
468 if (!isPaintable()) | 494 if (!isPaintable()) |
469 return String("data:,"); | 495 return String("data:,"); |
470 | 496 |
471 String encodingMimeType = toEncodingMimeType(mimeType); | 497 String encodingMimeType = toEncodingMimeType(mimeType); |
472 if (!m_context) { | |
473 ImageData* imageData = ImageData::create(m_size); | |
474 ScopedDisposal<ImageData> disposer(imageData); | |
475 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toD
ataURL(encodingMimeType, quality); | |
476 } | |
477 | 498 |
478 if (m_context->is3d()) { | 499 ImageData* imageData = toImageData(sourceBuffer); |
479 // Get non-premultiplied data because of inaccurate premultiplied alpha
conversion of buffer()->toDataURL(). | 500 ScopedDisposal<ImageData> disposer(imageData); |
480 ImageData* imageData = m_context->paintRenderingResultsToImageData(sourc
eBuffer); | |
481 ScopedDisposal<ImageData> disposer(imageData); | |
482 if (imageData) | |
483 return ImageDataBuffer(imageData->size(), imageData->data()->data())
.toDataURL(encodingMimeType, quality); | |
484 m_context->paintRenderingResultsToCanvas(sourceBuffer); | |
485 } | |
486 | 501 |
487 return buffer()->toDataURL(encodingMimeType, quality); | 502 return ImageDataBuffer(imageData->size(), imageData->data()->data()).toDataU
RL(encodingMimeType, quality); |
488 } | 503 } |
489 | 504 |
490 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q
ualityArgument, ExceptionState& exceptionState) const | 505 String HTMLCanvasElement::toDataURL(const String& mimeType, const ScriptValue& q
ualityArgument, ExceptionState& exceptionState) const |
491 { | 506 { |
492 if (!originClean()) { | 507 if (!originClean()) { |
493 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); | 508 exceptionState.throwSecurityError("Tainted canvases may not be exported.
"); |
494 return String(); | 509 return String(); |
495 } | 510 } |
496 double quality; | 511 double quality; |
497 double* qualityPtr = nullptr; | 512 double* qualityPtr = nullptr; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 { | 876 { |
862 return FloatSize(width(), height()); | 877 return FloatSize(width(), height()); |
863 } | 878 } |
864 | 879 |
865 bool HTMLCanvasElement::isOpaque() const | 880 bool HTMLCanvasElement::isOpaque() const |
866 { | 881 { |
867 return m_context && !m_context->hasAlpha(); | 882 return m_context && !m_context->hasAlpha(); |
868 } | 883 } |
869 | 884 |
870 } // blink | 885 } // blink |
OLD | NEW |