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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 | 42 |
43 // 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 |
44 // 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 |
45 // filling the space with arbitrary pixels, this workaround forces the | 45 // filling the space with arbitrary pixels, this workaround forces the |
46 // 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), |
47 // thus causing extra space to be transparent filled. | 47 // thus causing extra space to be transparent filled. |
48 SkShader::TileMode tileModeX = isRepeatX() | 48 SkShader::TileMode tileModeX = isRepeatX() |
49 ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; | 49 ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; |
50 SkShader::TileMode tileModeY = isRepeatY() | 50 SkShader::TileMode tileModeY = isRepeatY() |
51 ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; | 51 ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; |
52 int expandW = isRepeatX() ? 0 : 1; | 52 int expandW = isRepeatX() ? 0 : 1; |
Justin Novosad
2016/07/08 19:17:01
put 2 here to avoid multiplication later
| |
53 int expandH = isRepeatY() ? 0 : 1; | 53 int expandH = isRepeatY() ? 0 : 1; |
54 | 54 |
55 // Create a transparent image 1 pixel wider and/or taller than the | 55 // Create a transparent image 1 pixel wider and/or taller than the |
56 // original, then copy the orignal into it. | 56 // original, then copy the orignal into it. |
57 // FIXME: Is there a better way to pad (not scale) an image in skia? | 57 // FIXME: Is there a better way to pad (not scale) an image in skia? |
58 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( | 58 sk_sp<SkSurface> surface = SkSurface::MakeRasterN32Premul( |
59 m_tileImage->width() + expandW, m_tileImage->height() + expandH); | 59 m_tileImage->width() + expandW * 2, m_tileImage->height() + expandH * 2) ; |
60 if (!surface) | 60 if (!surface) |
61 return SkShader::MakeColorShader(SK_ColorTRANSPARENT); | 61 return SkShader::MakeColorShader(SK_ColorTRANSPARENT); |
62 | 62 |
63 SkPaint paint; | 63 SkPaint paint; |
64 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 64 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
65 surface->getCanvas()->drawImage(m_tileImage, 0, 0, &paint); | 65 surface->getCanvas()->drawImage(m_tileImage, 0, 0, &paint); |
66 | 66 |
67 return surface->makeImageSnapshot()->makeShader(tileModeX, tileModeY, &local Matrix); | 67 SkMatrix newLocalMatrix(localMatrix); |
68 newLocalMatrix.setTranslate((isRepeatX() ? 0 : -1), (isRepeatY() ? 0 : -1)); | |
69 | |
70 return surface->makeImageSnapshot()->makeShader(tileModeX, tileModeY, &newLo calMatrix); | |
68 } | 71 } |
69 | 72 |
70 bool ImagePattern::isTextureBacked() const | 73 bool ImagePattern::isTextureBacked() const |
71 { | 74 { |
72 return m_tileImage && m_tileImage->isTextureBacked(); | 75 return m_tileImage && m_tileImage->isTextureBacked(); |
73 } | 76 } |
74 | 77 |
75 } // namespace blink | 78 } // namespace blink |
OLD | NEW |