| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/graphics/StaticBitmapImage.h" | 5 #include "platform/graphics/StaticBitmapImage.h" |
| 6 | 6 |
| 7 #include "platform/graphics/AcceleratedStaticBitmapImage.h" | 7 #include "platform/graphics/AcceleratedStaticBitmapImage.h" |
| 8 #include "platform/graphics/GraphicsContext.h" | 8 #include "platform/graphics/GraphicsContext.h" |
| 9 #include "platform/graphics/ImageObserver.h" | 9 #include "platform/graphics/ImageObserver.h" |
| 10 #include "platform/graphics/UnacceleratedStaticBitmapImage.h" |
| 10 #include "third_party/skia/include/core/SkCanvas.h" | 11 #include "third_party/skia/include/core/SkCanvas.h" |
| 11 #include "third_party/skia/include/core/SkImage.h" | 12 #include "third_party/skia/include/core/SkImage.h" |
| 12 #include "third_party/skia/include/core/SkPaint.h" | 13 #include "third_party/skia/include/core/SkPaint.h" |
| 13 #include "wtf/PtrUtil.h" | |
| 14 #include <memory> | |
| 15 | 14 |
| 16 namespace blink { | 15 namespace blink { |
| 17 | 16 |
| 18 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(sk_sp<SkImage> image) { | 17 PassRefPtr<StaticBitmapImage> StaticBitmapImage::create(sk_sp<SkImage> image) { |
| 19 if (!image) | 18 if (!image) |
| 20 return nullptr; | 19 return nullptr; |
| 21 if (image->isTextureBacked()) | 20 if (image->isTextureBacked()) |
| 22 return AcceleratedStaticBitmapImage::createFromSharedContextImage( | 21 return AcceleratedStaticBitmapImage::createFromSharedContextImage( |
| 23 std::move(image)); | 22 std::move(image)); |
| 24 return adoptRef(new StaticBitmapImage(std::move(image))); | 23 return UnacceleratedStaticBitmapImage::create(std::move(image)); |
| 25 } | 24 } |
| 26 | 25 |
| 27 StaticBitmapImage::StaticBitmapImage(sk_sp<SkImage> image) | 26 void StaticBitmapImage::drawHelper(SkCanvas* canvas, |
| 28 : m_image(std::move(image)) { | 27 const SkPaint& paint, |
| 29 ASSERT(m_image); | 28 const FloatRect& dstRect, |
| 30 } | 29 const FloatRect& srcRect, |
| 31 | 30 ImageClampingMode clampMode, |
| 32 StaticBitmapImage::StaticBitmapImage() {} | 31 sk_sp<SkImage> image) { |
| 33 | |
| 34 StaticBitmapImage::~StaticBitmapImage() {} | |
| 35 | |
| 36 IntSize StaticBitmapImage::size() const { | |
| 37 return IntSize(m_image->width(), m_image->height()); | |
| 38 } | |
| 39 | |
| 40 bool StaticBitmapImage::isTextureBacked() { | |
| 41 return m_image && m_image->isTextureBacked(); | |
| 42 } | |
| 43 | |
| 44 bool StaticBitmapImage::currentFrameKnownToBeOpaque(MetadataMode) { | |
| 45 return m_image->isOpaque(); | |
| 46 } | |
| 47 | |
| 48 void StaticBitmapImage::draw(SkCanvas* canvas, | |
| 49 const SkPaint& paint, | |
| 50 const FloatRect& dstRect, | |
| 51 const FloatRect& srcRect, | |
| 52 RespectImageOrientationEnum, | |
| 53 ImageClampingMode clampMode) { | |
| 54 FloatRect adjustedSrcRect = srcRect; | 32 FloatRect adjustedSrcRect = srcRect; |
| 55 adjustedSrcRect.intersect(SkRect::Make(m_image->bounds())); | 33 adjustedSrcRect.intersect(SkRect::Make(image->bounds())); |
| 56 | 34 |
| 57 if (dstRect.isEmpty() || adjustedSrcRect.isEmpty()) | 35 if (dstRect.isEmpty() || adjustedSrcRect.isEmpty()) |
| 58 return; // Nothing to draw. | 36 return; // Nothing to draw. |
| 59 | 37 |
| 60 canvas->drawImageRect(m_image.get(), adjustedSrcRect, dstRect, &paint, | 38 canvas->drawImageRect(image.get(), adjustedSrcRect, dstRect, &paint, |
| 61 WebCoreClampingModeToSkiaRectConstraint(clampMode)); | 39 WebCoreClampingModeToSkiaRectConstraint(clampMode)); |
| 62 | 40 |
| 63 if (ImageObserver* observer = getImageObserver()) | 41 if (ImageObserver* observer = getImageObserver()) |
| 64 observer->didDraw(this); | 42 observer->didDraw(this); |
| 65 } | 43 } |
| 66 | 44 |
| 67 sk_sp<SkImage> StaticBitmapImage::imageForCurrentFrame() { | |
| 68 return m_image; | |
| 69 } | |
| 70 | |
| 71 } // namespace blink | 45 } // namespace blink |
| OLD | NEW |