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

Side by Side Diff: Source/platform/graphics/Pattern.cpp

Issue 453653003: [SVG] DisplayList-based patterns. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 9 tests marked for rebaseline Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 3 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
4 * Copyright (C) 2013 Google, Inc. All rights reserved. 4 * Copyright (C) 2013 Google, Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 13 matching lines...) Expand all
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "config.h" 28 #include "config.h"
29 #include "platform/graphics/Pattern.h" 29 #include "platform/graphics/Pattern.h"
30 30
31 #include <v8.h> 31 #include <v8.h>
32 #include "SkCanvas.h" 32 #include "SkCanvas.h"
33 #include "SkColorShader.h" 33 #include "SkColorShader.h"
34 #include "SkShader.h"
35 #include "platform/graphics/DisplayList.h"
36 #include "platform/graphics/Image.h"
34 #include "platform/graphics/skia/SkiaUtils.h" 37 #include "platform/graphics/skia/SkiaUtils.h"
35 38
36 39
37 namespace blink { 40 namespace blink {
38 41
39 PassRefPtr<Pattern> Pattern::createBitmapPattern(PassRefPtr<Image> tileImage, Re peatMode repeatMode) 42 PassRefPtr<Pattern> Pattern::createBitmapPattern(PassRefPtr<Image> tileImage, Re peatMode repeatMode)
40 { 43 {
41 return adoptRef(new Pattern(tileImage, repeatMode)); 44 return adoptRef(new Pattern(tileImage, repeatMode));
42 } 45 }
43 46
47 PassRefPtr<Pattern> Pattern::createDisplayListPattern(PassRefPtr<DisplayList> di splayList,
48 RepeatMode repeatMode)
49 {
50 return adoptRef(new Pattern(displayList, repeatMode));
51 }
52
44 Pattern::Pattern(PassRefPtr<Image> image, RepeatMode repeatMode) 53 Pattern::Pattern(PassRefPtr<Image> image, RepeatMode repeatMode)
45 : m_repeatMode(repeatMode) 54 : m_repeatMode(repeatMode)
46 , m_externalMemoryAllocated(0) 55 , m_externalMemoryAllocated(0)
47 { 56 {
48 if (image) { 57 if (image) {
49 m_tileImage = image->nativeImageForCurrentFrame(); 58 m_tileImage = image->nativeImageForCurrentFrame();
50 } 59 }
51 } 60 }
52 61
62 Pattern::Pattern(PassRefPtr<DisplayList> displayList, RepeatMode repeatMode)
63 : m_tileDisplayList(displayList)
64 , m_repeatMode(repeatMode)
65 , m_externalMemoryAllocated(0)
66 {
67 }
68
53 Pattern::~Pattern() 69 Pattern::~Pattern()
54 { 70 {
71 ASSERT(!m_tileImage || !m_tileDisplayList);
72
55 if (m_externalMemoryAllocated) 73 if (m_externalMemoryAllocated)
56 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnalMemoryAllocated); 74 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte rnalMemoryAllocated);
57 } 75 }
58 76
59 SkShader* Pattern::shader() 77 SkShader* Pattern::shader()
60 { 78 {
61 if (m_pattern) 79 if (m_pattern)
62 return m_pattern.get(); 80 return m_pattern.get();
63 81
64 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio n); 82 SkMatrix localMatrix = affineTransformToSkMatrix(m_patternSpaceTransformatio n);
65 83
66 // If we don't have a bitmap, return a transparent shader. 84 // FIXME: convert all clients to DisplayList and drop the Image tile code.
67 if (!m_tileImage) { 85 if (!m_tileImage) {
68 m_pattern = adoptRef(new SkColorShader(SK_ColorTRANSPARENT)); 86 if (m_tileDisplayList) {
87 // All current display list clients use RepeatModeXY, so we only sup port this mode.
88 ASSERT(m_repeatMode == RepeatModeXY);
89
90 SkRect tileBounds = SkRect::MakeWH(m_tileDisplayList->bounds().width (),
91 m_tileDisplayList->bounds().height());
92 m_pattern = adoptRef(SkShader::CreatePictureShader(m_tileDisplayList ->picture(),
93 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMa trix, &tileBounds));
94 } else {
95 m_pattern = adoptRef(new SkColorShader(SK_ColorTRANSPARENT));
96 }
69 } else if (m_repeatMode == RepeatModeXY) { 97 } else if (m_repeatMode == RepeatModeXY) {
70 m_pattern = adoptRef(SkShader::CreateBitmapShader(m_tileImage->bitmap(), 98 m_pattern = adoptRef(SkShader::CreateBitmapShader(m_tileImage->bitmap(), SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix));
71 SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode, &localMatrix ));
72 } else { 99 } else {
73 // Skia does not have a "draw the tile only once" option. Clamp_TileMode 100 // Skia does not have a "draw the tile only once" option. Clamp_TileMode
74 // repeats the last line of the image after drawing one tile. To avoid 101 // repeats the last line of the image after drawing one tile. To avoid
75 // filling the space with arbitrary pixels, this workaround forces the 102 // filling the space with arbitrary pixels, this workaround forces the
76 // image to have a line of transparent pixels on the "repeated" edge(s), 103 // image to have a line of transparent pixels on the "repeated" edge(s),
77 // thus causing extra space to be transparent filled. 104 // thus causing extra space to be transparent filled.
78 SkShader::TileMode tileModeX = (m_repeatMode & RepeatModeX) 105 SkShader::TileMode tileModeX = (m_repeatMode & RepeatModeX)
79 ? SkShader::kRepeat_TileMode 106 ? SkShader::kRepeat_TileMode
80 : SkShader::kClamp_TileMode; 107 : SkShader::kClamp_TileMode;
81 SkShader::TileMode tileModeY = (m_repeatMode & RepeatModeY) 108 SkShader::TileMode tileModeY = (m_repeatMode & RepeatModeY)
(...skipping 29 matching lines...) Expand all
111 void Pattern::setPatternSpaceTransform(const AffineTransform& patternSpaceTransf ormation) 138 void Pattern::setPatternSpaceTransform(const AffineTransform& patternSpaceTransf ormation)
112 { 139 {
113 if (patternSpaceTransformation == m_patternSpaceTransformation) 140 if (patternSpaceTransformation == m_patternSpaceTransformation)
114 return; 141 return;
115 142
116 m_patternSpaceTransformation = patternSpaceTransformation; 143 m_patternSpaceTransformation = patternSpaceTransformation;
117 m_pattern.clear(); 144 m_pattern.clear();
118 } 145 }
119 146
120 } 147 }
OLDNEW
« Source/core/rendering/svg/SVGRenderingContext.cpp ('K') | « Source/platform/graphics/Pattern.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698