| 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/SkShader.h" | |
| 11 | |
| 12 namespace blink { | |
| 13 | |
| 14 BitmapPattern::BitmapPattern(PassRefPtr<Image> image, RepeatMode repeatMode) | |
| 15 : BitmapPatternBase(repeatMode, 0 ) | |
| 16 { | |
| 17 if (image) { | |
| 18 // If image is animated, what about the pattern? | |
| 19 if (image->deprecatedBitmapForCurrentFrame(&m_tileImage)) | |
| 20 adjustExternalMemoryAllocated(m_tileImage.getSafeSize()); | |
| 21 } | |
| 22 } | |
| 23 | |
| 24 PassRefPtr<SkShader> BitmapPattern::createShader() | |
| 25 { | |
| 26 if (m_tileImage.isNull()) { | |
| 27 return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT)); | |
| 28 } | |
| 29 | |
| 30 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio
n); | |
| 31 | |
| 32 if (isRepeatXY()) { | |
| 33 return adoptRef(SkShader::CreateBitmapShader(m_tileImage, SkShader::kRep
eat_TileMode, SkShader::kRepeat_TileMode, &localMatrix)); | |
| 34 } | |
| 35 | |
| 36 return BitmapPatternBase::createShader(); | |
| 37 } | |
| 38 | |
| 39 SkImageInfo BitmapPattern::getBitmapInfo() | |
| 40 { | |
| 41 return m_tileImage.info(); | |
| 42 } | |
| 43 | |
| 44 void BitmapPattern::drawBitmapToCanvas(SkCanvas& canvas, SkPaint& paint) | |
| 45 { | |
| 46 canvas.drawBitmap(m_tileImage, SkIntToScalar(0), SkIntToScalar(0), &paint); | |
| 47 } | |
| 48 | |
| 49 } // namespace | |
| OLD | NEW |