| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
| 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 are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 return canvas; | 94 return canvas; |
| 95 } | 95 } |
| 96 | 96 |
| 97 static SkCanvas* createNonPlatformCanvas(const IntSize& size) | 97 static SkCanvas* createNonPlatformCanvas(const IntSize& size) |
| 98 { | 98 { |
| 99 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size
.width(), size.height())); | 99 SkAutoTUnref<SkDevice> device(new SkDevice(SkBitmap::kARGB_8888_Config, size
.width(), size.height())); |
| 100 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); | 100 SkPixelRef* pixelRef = device->accessBitmap(false).pixelRef(); |
| 101 return pixelRef ? new SkCanvas(device) : 0; | 101 return pixelRef ? new SkCanvas(device) : 0; |
| 102 } | 102 } |
| 103 | 103 |
| 104 PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size,
float resolutionScale, ColorSpace colorSpace, const GraphicsContext* context, b
ool hasAlpha) | 104 PassOwnPtr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const IntSize& size,
float resolutionScale, const GraphicsContext* context, bool hasAlpha) |
| 105 { | 105 { |
| 106 bool success = false; | 106 bool success = false; |
| 107 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(size, resolutionScale, co
lorSpace, context, hasAlpha, success)); | 107 OwnPtr<ImageBuffer> buf = adoptPtr(new ImageBuffer(size, resolutionScale, co
ntext, hasAlpha, success)); |
| 108 if (!success) | 108 if (!success) |
| 109 return nullptr; | 109 return nullptr; |
| 110 return buf.release(); | 110 return buf.release(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 ImageBuffer::ImageBuffer(const IntSize& size, float resolutionScale, ColorSpace,
const GraphicsContext* compatibleContext, bool hasAlpha, bool& success) | 113 ImageBuffer::ImageBuffer(const IntSize& size, float resolutionScale, const Graph
icsContext* compatibleContext, bool hasAlpha, bool& success) |
| 114 : m_data(size) | 114 : m_data(size) |
| 115 , m_size(size) | 115 , m_size(size) |
| 116 , m_logicalSize(size) | 116 , m_logicalSize(size) |
| 117 , m_resolutionScale(resolutionScale) | 117 , m_resolutionScale(resolutionScale) |
| 118 { | 118 { |
| 119 if (!compatibleContext) { | 119 if (!compatibleContext) { |
| 120 success = false; | 120 success = false; |
| 121 return; | 121 return; |
| 122 } | 122 } |
| 123 | 123 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 134 } | 134 } |
| 135 | 135 |
| 136 m_data.m_canvas = adoptPtr(new SkCanvas(device)); | 136 m_data.m_canvas = adoptPtr(new SkCanvas(device)); |
| 137 m_context = adoptPtr(new GraphicsContext(m_data.m_canvas.get())); | 137 m_context = adoptPtr(new GraphicsContext(m_data.m_canvas.get())); |
| 138 m_context->setShouldSmoothFonts(false); | 138 m_context->setShouldSmoothFonts(false); |
| 139 m_context->scale(FloatSize(m_resolutionScale, m_resolutionScale)); | 139 m_context->scale(FloatSize(m_resolutionScale, m_resolutionScale)); |
| 140 | 140 |
| 141 success = true; | 141 success = true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 ImageBuffer::ImageBuffer(const IntSize& size, float resolutionScale, ColorSpace,
RenderingMode renderingMode, OpacityMode opacityMode, bool& success) | 144 ImageBuffer::ImageBuffer(const IntSize& size, float resolutionScale, RenderingMo
de renderingMode, OpacityMode opacityMode, bool& success) |
| 145 : m_data(size) | 145 : m_data(size) |
| 146 , m_size(size) | 146 , m_size(size) |
| 147 , m_logicalSize(size) | 147 , m_logicalSize(size) |
| 148 , m_resolutionScale(resolutionScale) | 148 , m_resolutionScale(resolutionScale) |
| 149 { | 149 { |
| 150 OwnPtr<SkCanvas> canvas; | 150 OwnPtr<SkCanvas> canvas; |
| 151 | 151 |
| 152 if (renderingMode == Accelerated) | 152 if (renderingMode == Accelerated) |
| 153 canvas = adoptPtr(createAcceleratedCanvas(size, &m_data, opacityMode)); | 153 canvas = adoptPtr(createAcceleratedCanvas(size, &m_data, opacityMode)); |
| 154 else if (renderingMode == UnacceleratedNonPlatformBuffer) | 154 else if (renderingMode == UnacceleratedNonPlatformBuffer) |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const | 251 void ImageBuffer::clip(GraphicsContext* context, const FloatRect& rect) const |
| 252 { | 252 { |
| 253 context->beginLayerClippedToImage(rect, this); | 253 context->beginLayerClippedToImage(rect, this); |
| 254 } | 254 } |
| 255 | 255 |
| 256 static bool drawNeedsCopy(GraphicsContext* src, GraphicsContext* dst) | 256 static bool drawNeedsCopy(GraphicsContext* src, GraphicsContext* dst) |
| 257 { | 257 { |
| 258 return (src == dst); | 258 return (src == dst); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void ImageBuffer::draw(GraphicsContext* context, ColorSpace styleColorSpace, con
st FloatRect& destRect, const FloatRect& srcRect, | 261 void ImageBuffer::draw(GraphicsContext* context, const FloatRect& destRect, cons
t FloatRect& srcRect, |
| 262 CompositeOperator op, BlendMode blendMode, bool useLowQualityScale) | 262 CompositeOperator op, BlendMode blendMode, bool useLowQualityScale) |
| 263 { | 263 { |
| 264 const SkBitmap& bitmap = *m_context->bitmap(); | 264 const SkBitmap& bitmap = *m_context->bitmap(); |
| 265 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); | 265 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); |
| 266 context->drawImage(image.get(), styleColorSpace, destRect, srcRect, op, blen
dMode, DoNotRespectImageOrientation, useLowQualityScale); | 266 context->drawImage(image.get(), destRect, srcRect, op, blendMode, DoNotRespe
ctImageOrientation, useLowQualityScale); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect
, const AffineTransform& patternTransform, | 269 void ImageBuffer::drawPattern(GraphicsContext* context, const FloatRect& srcRect
, const AffineTransform& patternTransform, |
| 270 const FloatPoint& phase, ColorSpace styleColorSpac
e, CompositeOperator op, const FloatRect& destRect) | 270 const FloatPoint& phase, CompositeOperator op, const FloatRect& destRect) |
| 271 { | 271 { |
| 272 const SkBitmap& bitmap = *m_context->bitmap(); | 272 const SkBitmap& bitmap = *m_context->bitmap(); |
| 273 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); | 273 RefPtr<Image> image = BitmapImage::create(NativeImageSkia::create(drawNeedsC
opy(m_context.get(), context) ? deepSkBitmapCopy(bitmap) : bitmap)); |
| 274 image->drawPattern(context, srcRect, patternTransform, phase, styleColorSpac
e, op, destRect); | 274 image->drawPattern(context, srcRect, patternTransform, phase, op, destRect); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) | 277 void ImageBuffer::platformTransformColorSpace(const Vector<int>& lookUpTable) |
| 278 { | 278 { |
| 279 // FIXME: Disable color space conversions on accelerated canvases (for now). | 279 // FIXME: Disable color space conversions on accelerated canvases (for now). |
| 280 if (context()->isAccelerated()) | 280 if (context()->isAccelerated()) |
| 281 return; | 281 return; |
| 282 | 282 |
| 283 const SkBitmap& bitmap = *context()->bitmap(); | 283 const SkBitmap& bitmap = *context()->bitmap(); |
| 284 if (bitmap.isNull()) | 284 if (bitmap.isNull()) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) | 437 if (!encodeImage(imageData, mimeType, quality, &encodedImage)) |
| 438 return "data:,"; | 438 return "data:,"; |
| 439 | 439 |
| 440 Vector<char> base64Data; | 440 Vector<char> base64Data; |
| 441 base64Encode(encodedImage, base64Data); | 441 base64Encode(encodedImage, base64Data); |
| 442 | 442 |
| 443 return "data:" + mimeType + ";base64," + base64Data; | 443 return "data:" + mimeType + ";base64," + base64Data; |
| 444 } | 444 } |
| 445 | 445 |
| 446 } // namespace WebCore | 446 } // namespace WebCore |
| OLD | NEW |