OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "StaticBitmapImage.h" |
| 7 |
| 8 #include "platform/graphics/GraphicsContext.h" |
| 9 #include "platform/graphics/ImageObserver.h" |
| 10 #include "platform/graphics/skia/NativeImageSkia.h" |
| 11 #include "third_party/skia/include/core/SkImage.h" |
| 12 #include "third_party/skia/include/core/SkPaint.h" |
| 13 #include "third_party/skia/include/core/SkShader.h" |
| 14 |
| 15 namespace blink { |
| 16 |
| 17 PassRefPtr<Image> StaticBitmapImage::create(PassRefPtr<SkImage> image) |
| 18 { |
| 19 return adoptRef(new StaticBitmapImage(image)); |
| 20 } |
| 21 |
| 22 StaticBitmapImage::StaticBitmapImage(PassRefPtr<SkImage> image) : m_image(image) |
| 23 { |
| 24 m_image->setGpuToCpuCachingStrategy(SkImage::kWholeBitmap_CachingStrategy); |
| 25 } |
| 26 |
| 27 StaticBitmapImage::~StaticBitmapImage() { } |
| 28 |
| 29 IntSize StaticBitmapImage::size() const |
| 30 { |
| 31 return IntSize(m_image->width(), m_image->height()); |
| 32 } |
| 33 |
| 34 void StaticBitmapImage::draw(GraphicsContext* ctx, const FloatRect& dstRect, con
st FloatRect& srcRect, CompositeOperator compositeOp, blink::WebBlendMode blendM
ode) |
| 35 { |
| 36 FloatRect normDstRect = adjustForNegativeSize(dstRect); |
| 37 FloatRect normSrcRect = adjustForNegativeSize(srcRect); |
| 38 |
| 39 normSrcRect.intersect(FloatRect(0, 0, m_image->width(), m_image->height())); |
| 40 |
| 41 if (normSrcRect.isEmpty() || normDstRect.isEmpty()) |
| 42 return; // Nothing to draw. |
| 43 |
| 44 ASSERT(normSrcRect.width() <= m_image->width() && normSrcRect.height() <= m_
image->height()); |
| 45 |
| 46 SkPaint paint; |
| 47 ctx->preparePaintForDrawRectToRect(&paint, srcRect, dstRect, compositeOp, bl
endMode); |
| 48 |
| 49 SkRect srcSkRect = WebCoreFloatRectToSKRect(normSrcRect); |
| 50 SkRect dstSkRect = WebCoreFloatRectToSKRect(normDstRect); |
| 51 |
| 52 SkCanvas* canvas = ctx->canvas(); |
| 53 |
| 54 m_image->draw(canvas, &srcSkRect, dstSkRect, &paint); |
| 55 |
| 56 if (ImageObserver* observer = imageObserver()) |
| 57 observer->didDraw(this); |
| 58 } |
| 59 |
| 60 } |
OLD | NEW |