| 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 "platform/graphics/StaticBitmapPattern.h" | |
| 7 | |
| 8 #include "platform/graphics/skia/SkiaUtils.h" | |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | |
| 10 #include "third_party/skia/include/core/SkImage.h" | |
| 11 #include "third_party/skia/include/core/SkShader.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 PassRefPtr<Pattern> StaticBitmapPattern::create(PassRefPtr<Image> tileImage, Rep
eatMode repeatMode) | |
| 16 { | |
| 17 return adoptRef(new StaticBitmapPattern(tileImage->imageForCurrentFrame(), r
epeatMode)); | |
| 18 } | |
| 19 | |
| 20 StaticBitmapPattern::StaticBitmapPattern(PassRefPtr<SkImage> image, RepeatMode r
epeatMode) | |
| 21 : BitmapPatternBase(repeatMode, 0) | |
| 22 { | |
| 23 if (image) { | |
| 24 m_tileImage = image; | |
| 25 adjustExternalMemoryAllocated(m_tileImage->width() * m_tileImage->height
() * 4); | |
| 26 } | |
| 27 } | |
| 28 | |
| 29 StaticBitmapPattern::~StaticBitmapPattern() { } | |
| 30 | |
| 31 PassRefPtr<SkShader> StaticBitmapPattern::createShader() | |
| 32 { | |
| 33 // If we have no image, return null | |
| 34 if (!m_tileImage) { | |
| 35 return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT)); | |
| 36 } | |
| 37 | |
| 38 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio
n); | |
| 39 | |
| 40 if (isRepeatXY()) { | |
| 41 return adoptRef(m_tileImage->newShader(SkShader::kRepeat_TileMode, SkSha
der::kRepeat_TileMode, &localMatrix)); | |
| 42 } | |
| 43 | |
| 44 return BitmapPatternBase::createShader(); | |
| 45 } | |
| 46 | |
| 47 SkImageInfo StaticBitmapPattern::getBitmapInfo() | |
| 48 { | |
| 49 return SkImageInfo::MakeN32Premul(m_tileImage->width(), m_tileImage->height(
)); | |
| 50 } | |
| 51 | |
| 52 void StaticBitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint) | |
| 53 { | |
| 54 canvas.drawImage(m_tileImage.get(), SkIntToScalar(0), SkIntToScalar(0), &pai
nt); | |
| 55 } | |
| 56 | |
| 57 } // namespace | |
| OLD | NEW |