Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/ImagePattern.cpp

Issue 1789063005: Add sk_sp helpers and switch Blink SkShader clients to the new APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adoptSkSp/toSkSp Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
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 PassRefPtr<SkShader> ImagePattern::createShader() 33 PassRefPtr<SkShader> ImagePattern::createShader()
34 { 34 {
35 if (!m_tileImage) 35 if (!m_tileImage)
36 return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT)); 36 return adoptSkSp(SkShader::MakeColorShader(SK_ColorTRANSPARENT));
Stephen White 2016/03/17 17:50:40 Bikeshed: I'd actually to avoid "adopt" here, ("sk
f(malita) 2016/03/17 18:04:42 Since jbroman also suggested fromSkSp, fromSkSp it
37 37
38 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio n); 38 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio n);
39 39
40 if (isRepeatXY()) { 40 if (isRepeatXY()) {
41 // Fast path: for repeatXY we just return a shader from the original ima ge. 41 // Fast path: for repeatXY we just return a shader from the original ima ge.
42 return adoptRef(m_tileImage->newShader(SkShader::kRepeat_TileMode, 42 return adoptSkSp(m_tileImage->makeShader(SkShader::kRepeat_TileMode,
43 SkShader::kRepeat_TileMode, &localMatrix)); 43 SkShader::kRepeat_TileMode, &localMatrix));
44 } 44 }
45 45
46 // Skia does not have a "draw the tile only once" option. Clamp_TileMode 46 // Skia does not have a "draw the tile only once" option. Clamp_TileMode
47 // repeats the last line of the image after drawing one tile. To avoid 47 // repeats the last line of the image after drawing one tile. To avoid
48 // filling the space with arbitrary pixels, this workaround forces the 48 // filling the space with arbitrary pixels, this workaround forces the
49 // image to have a line of transparent pixels on the "repeated" edge(s), 49 // image to have a line of transparent pixels on the "repeated" edge(s),
50 // thus causing extra space to be transparent filled. 50 // thus causing extra space to be transparent filled.
51 SkShader::TileMode tileModeX = isRepeatX() 51 SkShader::TileMode tileModeX = isRepeatX()
52 ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; 52 ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode;
53 SkShader::TileMode tileModeY = isRepeatY() 53 SkShader::TileMode tileModeY = isRepeatY()
54 ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode; 54 ? SkShader::kRepeat_TileMode : SkShader::kClamp_TileMode;
55 int expandW = isRepeatX() ? 0 : 1; 55 int expandW = isRepeatX() ? 0 : 1;
56 int expandH = isRepeatY() ? 0 : 1; 56 int expandH = isRepeatY() ? 0 : 1;
57 57
58 // Create a transparent image 1 pixel wider and/or taller than the 58 // Create a transparent image 1 pixel wider and/or taller than the
59 // original, then copy the orignal into it. 59 // original, then copy the orignal into it.
60 // FIXME: Is there a better way to pad (not scale) an image in skia? 60 // FIXME: Is there a better way to pad (not scale) an image in skia?
61 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul( 61 RefPtr<SkSurface> surface = adoptRef(SkSurface::NewRasterN32Premul(
62 m_tileImage->width() + expandW, m_tileImage->height() + expandH)); 62 m_tileImage->width() + expandW, m_tileImage->height() + expandH));
63 if (!surface) 63 if (!surface)
64 return adoptRef(SkShader::CreateColorShader(SK_ColorTRANSPARENT)); 64 return adoptSkSp(SkShader::MakeColorShader(SK_ColorTRANSPARENT));
65 65
66 surface->getCanvas()->clear(SK_ColorTRANSPARENT); 66 surface->getCanvas()->clear(SK_ColorTRANSPARENT);
67 SkPaint paint; 67 SkPaint paint;
68 paint.setXfermodeMode(SkXfermode::kSrc_Mode); 68 paint.setXfermodeMode(SkXfermode::kSrc_Mode);
69 surface->getCanvas()->drawImage(m_tileImage.get(), 0, 0, &paint); 69 surface->getCanvas()->drawImage(m_tileImage.get(), 0, 0, &paint);
70 RefPtr<SkImage> expandedImage = adoptRef(surface->newImageSnapshot()); 70 RefPtr<SkImage> expandedImage = adoptRef(surface->newImageSnapshot());
71 71
72 return adoptRef(expandedImage->newShader(tileModeX, tileModeY, &localMatrix) ); 72 return adoptSkSp(expandedImage->makeShader(tileModeX, tileModeY, &localMatri x));
73 } 73 }
74 74
75 bool ImagePattern::isTextureBacked() const 75 bool ImagePattern::isTextureBacked() const
76 { 76 {
77 return m_tileImage && m_tileImage->isTextureBacked(); 77 return m_tileImage && m_tileImage->isTextureBacked();
78 } 78 }
79 79
80 } // namespace blink 80 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698