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/BitmapPattern.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 <v8.h> |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 BitmapPattern::BitmapPattern(PassRefPtr<Image> image, bool repeatX, bool repeatY
) |
| 16 : BitmapBackedPattern(repeatX, repeatY, image.get() ? image->nativeImageForCurre
ntFrame()->bitmap().getSafeSize() : 0 ) |
| 17 { |
| 18 if (image) { |
| 19 m_tileImage = image->nativeImageForCurrentFrame(); |
| 20 } |
| 21 } |
| 22 |
| 23 PassRefPtr<SkShader> BitmapPattern::createShader(SkShader::ShaderLocation prefer
redLocation) |
| 24 { |
| 25 if (!m_tileImage) { |
| 26 return adoptRef(new SkColorShader(SK_ColorTRANSPARENT)); |
| 27 } |
| 28 |
| 29 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio
n); |
| 30 |
| 31 if (m_repeatX && m_repeatY) { |
| 32 return adoptRef(SkShader::CreateBitmapShader(m_tileImage->bitmap(), SkSh
ader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix)); |
| 33 } |
| 34 |
| 35 return BitmapBackedPattern::createShader(preferredLocation); |
| 36 } |
| 37 |
| 38 SkImageInfo BitmapPattern::getBitmapInfo() |
| 39 { |
| 40 return m_tileImage->bitmap().info(); |
| 41 } |
| 42 |
| 43 void BitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint) |
| 44 { |
| 45 canvas.drawBitmap(m_tileImage->bitmap(), SkIntToScalar(0), SkIntToScalar(0),
&paint); |
| 46 } |
| 47 |
| 48 } // namespace |
OLD | NEW |