diff options
author | Ben Murdoch <benm@google.com> | 2010-07-22 15:37:06 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2010-07-27 10:20:25 +0100 |
commit | 967717af5423377c967781471ee106e2bb4e11c8 (patch) | |
tree | 1e701dc0a12f7f07cce1df4a7681717de77a211b /WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp | |
parent | dcc30a9fca45f634b1d3a12b276d3a0ccce99fc3 (diff) | |
download | external_webkit-967717af5423377c967781471ee106e2bb4e11c8.zip external_webkit-967717af5423377c967781471ee106e2bb4e11c8.tar.gz external_webkit-967717af5423377c967781471ee106e2bb4e11c8.tar.bz2 |
Merge WebKit at r63859 : Initial merge by git.
Change-Id: Ie8096c63ec7c991c9a9cba8bdd9c3b74a3b8ed62
Diffstat (limited to 'WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp')
-rw-r--r-- | WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp b/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp index 9f0f353..8af3d0e 100644 --- a/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp +++ b/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp @@ -36,6 +36,8 @@ #include <CoreGraphics/CGContext.h> #include <CoreGraphics/CGImage.h> +#include <wtf/RetainPtr.h> + namespace WebCore { bool GraphicsContext3D::getImageData(Image* image, @@ -104,6 +106,41 @@ bool GraphicsContext3D::getImageData(Image* image, format, type, neededAlphaOp, outputVector.data()); } +void GraphicsContext3D::paintToCanvas(const unsigned char* imagePixels, int imageWidth, int imageHeight, int canvasWidth, int canvasHeight, CGContextRef context) +{ + if (!imagePixels || imageWidth <= 0 || imageHeight <= 0 || canvasWidth <= 0 || canvasHeight <= 0 || !context) + return; + int rowBytes = imageWidth * 4; + RetainPtr<CGDataProviderRef> dataProvider = CGDataProviderCreateWithData(0, imagePixels, rowBytes * imageHeight, 0); + RetainPtr<CGColorSpaceRef> colorSpace = CGColorSpaceCreateDeviceRGB(); + RetainPtr<CGImageRef> cgImage = CGImageCreate(imageWidth, + imageHeight, + 8, + 32, + rowBytes, + colorSpace.get(), + kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host, + dataProvider.get(), + 0, + false, + kCGRenderingIntentDefault); + // CSS styling may cause the canvas's content to be resized on + // the page. Go back to the Canvas to figure out the correct + // width and height to draw. + CGRect rect = CGRectMake(0, 0, + canvasWidth, + canvasHeight); + // We want to completely overwrite the previous frame's + // rendering results. + CGContextSaveGState(context); + CGContextSetBlendMode(context, + kCGBlendModeCopy); + CGContextSetInterpolationQuality(context, + kCGInterpolationNone); + CGContextDrawImage(context, + rect, cgImage.get()); + CGContextRestoreGState(context); +} } // namespace WebCore |