| 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 "platform/graphics/ImagePattern.h" | 5 #include "platform/graphics/ImagePattern.h" |
| 6 | 6 |
| 7 #include "platform/graphics/Image.h" | 7 #include "platform/graphics/Image.h" |
| 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/SkImage.h" | 10 #include "third_party/skia/include/core/SkImage.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 , m_tileImage(toSkSp(image->imageForCurrentFrame())) | 23 , m_tileImage(toSkSp(image->imageForCurrentFrame())) |
| 24 { | 24 { |
| 25 if (m_tileImage) { | 25 if (m_tileImage) { |
| 26 // TODO(fmalita): mechanism to extract the actual SkImageInfo from an Sk
Image? | 26 // TODO(fmalita): mechanism to extract the actual SkImageInfo from an Sk
Image? |
| 27 const SkImageInfo info = | 27 const SkImageInfo info = |
| 28 SkImageInfo::MakeN32Premul(m_tileImage->width(), m_tileImage->height
()); | 28 SkImageInfo::MakeN32Premul(m_tileImage->width(), m_tileImage->height
()); |
| 29 adjustExternalMemoryAllocated(info.getSafeSize(info.minRowBytes())); | 29 adjustExternalMemoryAllocated(info.getSafeSize(info.minRowBytes())); |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 sk_sp<SkShader> ImagePattern::createShader() const | 33 sk_sp<SkShader> ImagePattern::createShader(const SkMatrix& localMatrix) const |
| 34 { | 34 { |
| 35 if (!m_tileImage) | 35 if (!m_tileImage) |
| 36 return SkShader::MakeColorShader(SK_ColorTRANSPARENT); | 36 return SkShader::MakeColorShader(SK_ColorTRANSPARENT); |
| 37 | 37 |
| 38 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio
n); | |
| 39 | |
| 40 if (isRepeatXY()) { | 38 if (isRepeatXY()) { |
| 41 // Fast path: for repeatXY we just return a shader from the original ima
ge. | 39 // Fast path: for repeatXY we just return a shader from the original ima
ge. |
| 42 return m_tileImage->makeShader(SkShader::kRepeat_TileMode, SkShader::kRe
peat_TileMode, &localMatrix); | 40 return m_tileImage->makeShader(SkShader::kRepeat_TileMode, SkShader::kRe
peat_TileMode, &localMatrix); |
| 43 } | 41 } |
| 44 | 42 |
| 45 // Skia does not have a "draw the tile only once" option. Clamp_TileMode | 43 // Skia does not have a "draw the tile only once" option. Clamp_TileMode |
| 46 // repeats the last line of the image after drawing one tile. To avoid | 44 // repeats the last line of the image after drawing one tile. To avoid |
| 47 // filling the space with arbitrary pixels, this workaround forces the | 45 // filling the space with arbitrary pixels, this workaround forces the |
| 48 // image to have a line of transparent pixels on the "repeated" edge(s), | 46 // image to have a line of transparent pixels on the "repeated" edge(s), |
| 49 // thus causing extra space to be transparent filled. | 47 // thus causing extra space to be transparent filled. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 69 | 67 |
| 70 return surface->makeImageSnapshot()->makeShader(tileModeX, tileModeY, &local
Matrix); | 68 return surface->makeImageSnapshot()->makeShader(tileModeX, tileModeY, &local
Matrix); |
| 71 } | 69 } |
| 72 | 70 |
| 73 bool ImagePattern::isTextureBacked() const | 71 bool ImagePattern::isTextureBacked() const |
| 74 { | 72 { |
| 75 return m_tileImage && m_tileImage->isTextureBacked(); | 73 return m_tileImage && m_tileImage->isTextureBacked(); |
| 76 } | 74 } |
| 77 | 75 |
| 78 } // namespace blink | 76 } // namespace blink |
| OLD | NEW |