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" |
11 #include "third_party/skia/include/core/SkShader.h" | 11 #include "third_party/skia/include/core/SkShader.h" |
12 #include "third_party/skia/include/core/SkSurface.h" | 12 #include "third_party/skia/include/core/SkSurface.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 | 15 |
16 PassRefPtr<ImagePattern> ImagePattern::create(PassRefPtr<Image> image, | 16 PassRefPtr<ImagePattern> ImagePattern::create(PassRefPtr<Image> image, |
17 RepeatMode repeatMode) { | 17 RepeatMode repeatMode) { |
18 return adoptRef(new ImagePattern(std::move(image), repeatMode)); | 18 return adoptRef(new ImagePattern(std::move(image), repeatMode)); |
19 } | 19 } |
20 | 20 |
21 ImagePattern::ImagePattern(PassRefPtr<Image> image, RepeatMode repeatMode) | 21 ImagePattern::ImagePattern(PassRefPtr<Image> image, RepeatMode repeatMode) |
22 : Pattern(repeatMode), m_tileImage(image->imageForCurrentFrame()) { | 22 : Pattern(repeatMode), m_tileImage(image->imageForCurrentFrame()) { |
23 m_previousLocalMatrix.setIdentity(); | 23 m_previousLocalMatrix.setIdentity(); |
24 if (m_tileImage) { | 24 if (m_tileImage) { |
25 // TODO(fmalita): mechanism to extract the actual SkImageInfo from an SkImag
e? | 25 // TODO(fmalita): mechanism to extract the actual SkImageInfo from an |
| 26 // SkImage? |
26 const SkImageInfo info = SkImageInfo::MakeN32Premul( | 27 const SkImageInfo info = SkImageInfo::MakeN32Premul( |
27 m_tileImage->width() + (isRepeatX() ? 0 : 2), | 28 m_tileImage->width() + (isRepeatX() ? 0 : 2), |
28 m_tileImage->height() + (isRepeatY() ? 0 : 2)); | 29 m_tileImage->height() + (isRepeatY() ? 0 : 2)); |
29 adjustExternalMemoryAllocated(info.getSafeSize(info.minRowBytes())); | 30 adjustExternalMemoryAllocated(info.getSafeSize(info.minRowBytes())); |
30 } | 31 } |
31 } | 32 } |
32 | 33 |
33 bool ImagePattern::isLocalMatrixChanged(const SkMatrix& localMatrix) const { | 34 bool ImagePattern::isLocalMatrixChanged(const SkMatrix& localMatrix) const { |
34 if (isRepeatXY()) | 35 if (isRepeatXY()) |
35 return Pattern::isLocalMatrixChanged(localMatrix); | 36 return Pattern::isLocalMatrixChanged(localMatrix); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 | 79 |
79 return surface->makeImageSnapshot()->makeShader(tileModeX, tileModeY, | 80 return surface->makeImageSnapshot()->makeShader(tileModeX, tileModeY, |
80 &adjustedMatrix); | 81 &adjustedMatrix); |
81 } | 82 } |
82 | 83 |
83 bool ImagePattern::isTextureBacked() const { | 84 bool ImagePattern::isTextureBacked() const { |
84 return m_tileImage && m_tileImage->isTextureBacked(); | 85 return m_tileImage && m_tileImage->isTextureBacked(); |
85 } | 86 } |
86 | 87 |
87 } // namespace blink | 88 } // namespace blink |
OLD | NEW |