| 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 "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/BitmapPattern.h" | 6 #include "platform/graphics/BitmapPattern.h" |
| 7 | 7 |
| 8 #include "platform/graphics/skia/SkiaUtils.h" | 8 #include "platform/graphics/skia/SkiaUtils.h" |
| 9 #include "third_party/skia/include/core/SkCanvas.h" | 9 #include "third_party/skia/include/core/SkCanvas.h" |
| 10 #include "third_party/skia/include/core/SkColorShader.h" | 10 #include "third_party/skia/include/core/SkShader.h" |
| 11 #include <v8.h> | 11 #include <v8.h> |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 BitmapPattern::BitmapPattern(PassRefPtr<Image> image, RepeatMode repeatMode) | 15 BitmapPattern::BitmapPattern(PassRefPtr<Image> image, RepeatMode repeatMode) |
| 16 : BitmapPatternBase(repeatMode, 0 ) | 16 : BitmapPatternBase(repeatMode, 0 ) |
| 17 { | 17 { |
| 18 if (image) { | 18 if (image) { |
| 19 // If image is animated, what about the pattern? | 19 // If image is animated, what about the pattern? |
| 20 m_tileImage = image->nativeImageForCurrentFrame(); | 20 m_tileImage = image->nativeImageForCurrentFrame(); |
| 21 | 21 |
| 22 if (m_tileImage) | 22 if (m_tileImage) |
| 23 adjustExternalMemoryAllocated(m_tileImage->bitmap().getSafeSize()); | 23 adjustExternalMemoryAllocated(m_tileImage->bitmap().getSafeSize()); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 PassRefPtr<SkShader> BitmapPattern::createShader() | 27 PassRefPtr<SkShader> BitmapPattern::createShader() |
| 28 { | 28 { |
| 29 if (!m_tileImage) { | 29 if (!m_tileImage) { |
| 30 return adoptRef(new SkColorShader(SK_ColorTRANSPARENT)); | 30 return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT)); |
| 31 } | 31 } |
| 32 | 32 |
| 33 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio
n); | 33 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio
n); |
| 34 | 34 |
| 35 if (isRepeatXY()) { | 35 if (isRepeatXY()) { |
| 36 return adoptRef(SkShader::CreateBitmapShader(m_tileImage->bitmap(), SkSh
ader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix)); | 36 return adoptRef(SkShader::CreateBitmapShader(m_tileImage->bitmap(), SkSh
ader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix)); |
| 37 } | 37 } |
| 38 | 38 |
| 39 return BitmapPatternBase::createShader(); | 39 return BitmapPatternBase::createShader(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 SkImageInfo BitmapPattern::getBitmapInfo() | 42 SkImageInfo BitmapPattern::getBitmapInfo() |
| 43 { | 43 { |
| 44 return m_tileImage->bitmap().info(); | 44 return m_tileImage->bitmap().info(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void BitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint) | 47 void BitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint) |
| 48 { | 48 { |
| 49 canvas.drawBitmap(m_tileImage->bitmap(), SkIntToScalar(0), SkIntToScalar(0),
&paint); | 49 canvas.drawBitmap(m_tileImage->bitmap(), SkIntToScalar(0), SkIntToScalar(0),
&paint); |
| 50 } | 50 } |
| 51 | 51 |
| 52 } // namespace | 52 } // namespace |
| OLD | NEW |