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