| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 4 * Copyright (C) 2010 Mozilla Corporation. All rights reserved. | 4 * Copyright (C) 2010 Mozilla Corporation. 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 11 matching lines...) Expand all Loading... |
| 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #include "config.h" | 28 #include "config.h" |
| 29 | 29 |
| 30 #include "core/platform/graphics/GraphicsContext3D.h" | 30 #include "core/platform/graphics/GraphicsContext3D.h" |
| 31 | 31 |
| 32 #include "core/html/ImageData.h" | |
| 33 #include "core/platform/graphics/Extensions3D.h" | 32 #include "core/platform/graphics/Extensions3D.h" |
| 34 #include "core/platform/graphics/GraphicsContext.h" | 33 #include "core/platform/graphics/GraphicsContext.h" |
| 35 #include "core/platform/graphics/Image.h" | 34 #include "core/platform/graphics/Image.h" |
| 36 #include "core/platform/graphics/ImageBuffer.h" | 35 #include "core/platform/graphics/ImageBuffer.h" |
| 37 #include "core/platform/graphics/ImageObserver.h" | 36 #include "core/platform/graphics/ImageObserver.h" |
| 38 #include "core/platform/graphics/gpu/DrawingBuffer.h" | 37 #include "core/platform/graphics/gpu/DrawingBuffer.h" |
| 39 #include "core/platform/image-decoders/ImageDecoder.h" | 38 #include "core/platform/image-decoders/ImageDecoder.h" |
| 40 #include "platform/CheckedInt.h" | 39 #include "platform/CheckedInt.h" |
| 41 #include "third_party/skia/include/gpu/GrContext.h" | 40 #include "third_party/skia/include/gpu/GrContext.h" |
| 42 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" | 41 #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 } | 516 } |
| 518 | 517 |
| 519 void GraphicsContext3D::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer,
DrawingBuffer* drawingBuffer) | 518 void GraphicsContext3D::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer,
DrawingBuffer* drawingBuffer) |
| 520 { | 519 { |
| 521 Platform3DObject framebufferId; | 520 Platform3DObject framebufferId; |
| 522 int width, height; | 521 int width, height; |
| 523 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height)
; | 522 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height)
; |
| 524 paintFramebufferToCanvas(framebufferId, width, height, !getContextAttributes
().premultipliedAlpha, imageBuffer); | 523 paintFramebufferToCanvas(framebufferId, width, height, !getContextAttributes
().premultipliedAlpha, imageBuffer); |
| 525 } | 524 } |
| 526 | 525 |
| 527 PassRefPtr<ImageData> GraphicsContext3D::paintRenderingResultsToImageData(Drawin
gBuffer* drawingBuffer) | 526 PassRefPtr<Uint8ClampedArray> GraphicsContext3D::paintRenderingResultsToImageDat
a(DrawingBuffer* drawingBuffer, int& width, int& height) |
| 528 { | 527 { |
| 529 if (getContextAttributes().premultipliedAlpha) | 528 if (getContextAttributes().premultipliedAlpha) |
| 530 return 0; | 529 return 0; |
| 531 | 530 |
| 532 Platform3DObject framebufferId; | 531 Platform3DObject framebufferId; |
| 533 int width, height; | |
| 534 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height)
; | 532 getDrawingParameters(drawingBuffer, m_impl, &framebufferId, &width, &height)
; |
| 535 | 533 |
| 536 RefPtr<ImageData> imageData = ImageData::create(IntSize(width, height)); | 534 Checked<int, RecordOverflow> dataSize = 4; |
| 537 unsigned char* pixels = imageData->data()->data(); | 535 dataSize *= width; |
| 536 dataSize *= height; |
| 537 if (dataSize.hasOverflowed()) |
| 538 return 0; |
| 539 |
| 540 RefPtr<Uint8ClampedArray> pixels = Uint8ClampedArray::createUninitialized(wi
dth * height * 4); |
| 538 | 541 |
| 539 m_impl->bindFramebuffer(FRAMEBUFFER, framebufferId); | 542 m_impl->bindFramebuffer(FRAMEBUFFER, framebufferId); |
| 540 readBackFramebuffer(pixels, width, height, ReadbackRGBA, AlphaDoNothing); | 543 readBackFramebuffer(pixels->data(), width, height, ReadbackRGBA, AlphaDoNoth
ing); |
| 541 flipVertically(pixels, width, height); | 544 flipVertically(pixels->data(), width, height); |
| 542 | 545 |
| 543 return imageData.release(); | 546 return pixels.release(); |
| 544 } | 547 } |
| 545 | 548 |
| 546 void GraphicsContext3D::readBackFramebuffer(unsigned char* pixels, int width, in
t height, ReadbackOrder readbackOrder, AlphaOp op) | 549 void GraphicsContext3D::readBackFramebuffer(unsigned char* pixels, int width, in
t height, ReadbackOrder readbackOrder, AlphaOp op) |
| 547 { | 550 { |
| 548 if (m_packAlignment > 4) | 551 if (m_packAlignment > 4) |
| 549 m_impl->pixelStorei(PACK_ALIGNMENT, 1); | 552 m_impl->pixelStorei(PACK_ALIGNMENT, 1); |
| 550 m_impl->readPixels(0, 0, width, height, RGBA, UNSIGNED_BYTE, pixels); | 553 m_impl->readPixels(0, 0, width, height, RGBA, UNSIGNED_BYTE, pixels); |
| 551 if (m_packAlignment > 4) | 554 if (m_packAlignment > 4) |
| 552 m_impl->pixelStorei(PACK_ALIGNMENT, m_packAlignment); | 555 m_impl->pixelStorei(PACK_ALIGNMENT, m_packAlignment); |
| 553 | 556 |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 for (unsigned i = 0; i < count; i++) { | 940 for (unsigned i = 0; i < count; i++) { |
| 938 uint8* rowA = framebuffer + i * rowBytes; | 941 uint8* rowA = framebuffer + i * rowBytes; |
| 939 uint8* rowB = framebuffer + (height - i - 1) * rowBytes; | 942 uint8* rowB = framebuffer + (height - i - 1) * rowBytes; |
| 940 memcpy(scanline, rowB, rowBytes); | 943 memcpy(scanline, rowB, rowBytes); |
| 941 memcpy(rowB, rowA, rowBytes); | 944 memcpy(rowB, rowA, rowBytes); |
| 942 memcpy(rowA, scanline, rowBytes); | 945 memcpy(rowA, scanline, rowBytes); |
| 943 } | 946 } |
| 944 } | 947 } |
| 945 | 948 |
| 946 } // namespace WebCore | 949 } // namespace WebCore |
| OLD | NEW |