OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 m_context->bindFramebuffer(target, m_multisampleFBO ? m_multisampleFBO :
m_fbo); | 869 m_context->bindFramebuffer(target, m_multisampleFBO ? m_multisampleFBO :
m_fbo); |
870 else | 870 else |
871 m_context->bindFramebuffer(target, m_fbo); | 871 m_context->bindFramebuffer(target, m_fbo); |
872 } | 872 } |
873 | 873 |
874 void DrawingBuffer::setPackAlignment(GLint param) | 874 void DrawingBuffer::setPackAlignment(GLint param) |
875 { | 875 { |
876 m_packAlignment = param; | 876 m_packAlignment = param; |
877 } | 877 } |
878 | 878 |
879 void DrawingBuffer::paintRenderingResultsToCanvas(ImageBuffer* imageBuffer) | |
880 { | |
881 paintFramebufferToCanvas(framebuffer(), size().width(), size().height(), !m_
actualAttributes.premultipliedAlpha, imageBuffer); | |
882 } | |
883 | |
884 bool DrawingBuffer::paintRenderingResultsToImageData(int& width, int& height, So
urceDrawingBuffer sourceBuffer, WTF::ArrayBufferContents& contents) | 879 bool DrawingBuffer::paintRenderingResultsToImageData(int& width, int& height, So
urceDrawingBuffer sourceBuffer, WTF::ArrayBufferContents& contents) |
885 { | 880 { |
886 ASSERT(!m_actualAttributes.premultipliedAlpha); | 881 ASSERT(!m_actualAttributes.premultipliedAlpha); |
887 width = size().width(); | 882 width = size().width(); |
888 height = size().height(); | 883 height = size().height(); |
889 | 884 |
890 Checked<int, RecordOverflow> dataSize = 4; | 885 Checked<int, RecordOverflow> dataSize = 4; |
891 dataSize *= width; | 886 dataSize *= width; |
892 dataSize *= height; | 887 dataSize *= height; |
893 if (dataSize.hasOverflowed()) | 888 if (dataSize.hasOverflowed()) |
(...skipping 17 matching lines...) Expand all Loading... |
911 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, 0, 0); | 906 m_context->framebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL
_TEXTURE_2D, 0, 0); |
912 m_context->deleteFramebuffer(fbo); | 907 m_context->deleteFramebuffer(fbo); |
913 } | 908 } |
914 | 909 |
915 restoreFramebufferBindings(); | 910 restoreFramebufferBindings(); |
916 | 911 |
917 pixels.transfer(contents); | 912 pixels.transfer(contents); |
918 return true; | 913 return true; |
919 } | 914 } |
920 | 915 |
921 void DrawingBuffer::paintFramebufferToCanvas(int framebuffer, int width, int hei
ght, bool premultiplyAlpha, ImageBuffer* imageBuffer) | |
922 { | |
923 unsigned char* pixels = 0; | |
924 | |
925 const SkBitmap& canvasBitmap = imageBuffer->deprecatedBitmapForOverwrite(); | |
926 const SkBitmap* readbackBitmap = 0; | |
927 ASSERT(canvasBitmap.colorType() == kN32_SkColorType); | |
928 if (canvasBitmap.width() == width && canvasBitmap.height() == height) { | |
929 // This is the fastest and most common case. We read back | |
930 // directly into the canvas's backing store. | |
931 readbackBitmap = &canvasBitmap; | |
932 m_resizingBitmap.reset(); | |
933 } else { | |
934 // We need to allocate a temporary bitmap for reading back the | |
935 // pixel data. We will then use Skia to rescale this bitmap to | |
936 // the size of the canvas's backing store. | |
937 if (m_resizingBitmap.width() != width || m_resizingBitmap.height() != he
ight) { | |
938 if (!m_resizingBitmap.tryAllocN32Pixels(width, height)) | |
939 return; | |
940 } | |
941 readbackBitmap = &m_resizingBitmap; | |
942 } | |
943 | |
944 // Read back the frame buffer. | |
945 SkAutoLockPixels bitmapLock(*readbackBitmap); | |
946 pixels = static_cast<unsigned char*>(readbackBitmap->getPixels()); | |
947 | |
948 m_context->bindFramebuffer(GL_FRAMEBUFFER, framebuffer); | |
949 readBackFramebuffer(pixels, width, height, ReadbackSkia, premultiplyAlpha ?
WebGLImageConversion::AlphaDoPremultiply : WebGLImageConversion::AlphaDoNothing)
; | |
950 flipVertically(pixels, width, height); | |
951 | |
952 readbackBitmap->notifyPixelsChanged(); | |
953 if (m_resizingBitmap.readyToDraw()) { | |
954 // We need to draw the resizing bitmap into the canvas's backing store. | |
955 SkCanvas canvas(canvasBitmap); | |
956 canvas.drawBitmapRect(m_resizingBitmap, SkRect::MakeIWH(canvasBitmap.wid
th(), canvasBitmap.height()), nullptr); | |
957 } | |
958 } | |
959 | |
960 void DrawingBuffer::readBackFramebuffer(unsigned char* pixels, int width, int he
ight, ReadbackOrder readbackOrder, WebGLImageConversion::AlphaOp op) | 916 void DrawingBuffer::readBackFramebuffer(unsigned char* pixels, int width, int he
ight, ReadbackOrder readbackOrder, WebGLImageConversion::AlphaOp op) |
961 { | 917 { |
962 if (m_packAlignment > 4) | 918 if (m_packAlignment > 4) |
963 m_context->pixelStorei(GL_PACK_ALIGNMENT, 1); | 919 m_context->pixelStorei(GL_PACK_ALIGNMENT, 1); |
964 m_context->readPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels
); | 920 m_context->readPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels
); |
965 if (m_packAlignment > 4) | 921 if (m_packAlignment > 4) |
966 m_context->pixelStorei(GL_PACK_ALIGNMENT, m_packAlignment); | 922 m_context->pixelStorei(GL_PACK_ALIGNMENT, m_packAlignment); |
967 | 923 |
968 size_t bufferSize = 4 * width * height; | 924 size_t bufferSize = 4 * width * height; |
969 | 925 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) | 983 void DrawingBuffer::deleteChromiumImageForTexture(TextureInfo* info) |
1028 { | 984 { |
1029 if (info->imageId) { | 985 if (info->imageId) { |
1030 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); | 986 m_context->releaseTexImage2DCHROMIUM(GL_TEXTURE_2D, info->imageId); |
1031 m_context->destroyImageCHROMIUM(info->imageId); | 987 m_context->destroyImageCHROMIUM(info->imageId); |
1032 info->imageId = 0; | 988 info->imageId = 0; |
1033 } | 989 } |
1034 } | 990 } |
1035 | 991 |
1036 } // namespace blink | 992 } // namespace blink |
OLD | NEW |