OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTileImageFilter.h" | 8 #include "SkTileImageFilter.h" |
9 | 9 |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 return nullptr; | 48 return nullptr; |
49 } | 49 } |
50 | 50 |
51 SkRect dstRect; | 51 SkRect dstRect; |
52 ctx.ctm().mapRect(&dstRect, fDstRect); | 52 ctx.ctm().mapRect(&dstRect, fDstRect); |
53 if (!dstRect.intersect(SkRect::Make(ctx.clipBounds()))) { | 53 if (!dstRect.intersect(SkRect::Make(ctx.clipBounds()))) { |
54 return nullptr; | 54 return nullptr; |
55 } | 55 } |
56 | 56 |
57 const SkIRect dstIRect = dstRect.roundOut(); | 57 const SkIRect dstIRect = dstRect.roundOut(); |
58 int dstWidth = dstIRect.width(); | 58 if (!fSrcRect.width() || !fSrcRect.height() || !dstIRect.width() || !dstIRec
t.height()) { |
59 int dstHeight = dstIRect.height(); | |
60 if (!fSrcRect.width() || !fSrcRect.height() || !dstWidth || !dstHeight) { | |
61 return nullptr; | 59 return nullptr; |
62 } | 60 } |
63 | 61 |
64 SkRect srcRect; | 62 SkRect srcRect; |
65 ctx.ctm().mapRect(&srcRect, fSrcRect); | 63 ctx.ctm().mapRect(&srcRect, fSrcRect); |
66 SkIRect srcIRect; | 64 SkIRect srcIRect; |
67 srcRect.roundOut(&srcIRect); | 65 srcRect.roundOut(&srcIRect); |
68 srcIRect.offset(-inputOffset); | 66 srcIRect.offset(-inputOffset); |
69 const SkIRect inputBounds = SkIRect::MakeWH(input->width(), input->height())
; | 67 const SkIRect inputBounds = SkIRect::MakeWH(input->width(), input->height())
; |
70 | 68 |
71 if (!SkIRect::Intersects(srcIRect, inputBounds)) { | 69 if (!SkIRect::Intersects(srcIRect, inputBounds)) { |
72 return nullptr; | 70 return nullptr; |
73 } | 71 } |
74 | 72 |
75 // We create an SkImage here b.c. it needs to be a tight fit for the tiling | 73 // We create an SkImage here b.c. it needs to be a tight fit for the tiling |
76 sk_sp<SkImage> subset; | 74 sk_sp<SkImage> subset; |
77 if (inputBounds.contains(srcIRect)) { | 75 if (inputBounds.contains(srcIRect)) { |
78 subset = input->makeTightSubset(srcIRect); | 76 subset = input->makeTightSubset(srcIRect); |
79 if (!subset) { | 77 if (!subset) { |
80 return nullptr; | 78 return nullptr; |
81 } | 79 } |
82 } else { | 80 } else { |
83 const SkImageInfo info = SkImageInfo::MakeN32(srcIRect.width(), srcIRect
.height(), | 81 sk_sp<SkSurface> surf(input->makeTightSurface(ctx.outputProperties(), sr
cIRect.size())); |
84 kPremul_SkAlphaType); | |
85 sk_sp<SkSurface> surf(input->makeTightSurface(info)); | |
86 if (!surf) { | 82 if (!surf) { |
87 return nullptr; | 83 return nullptr; |
88 } | 84 } |
89 | 85 |
90 SkCanvas* canvas = surf->getCanvas(); | 86 SkCanvas* canvas = surf->getCanvas(); |
91 SkASSERT(canvas); | 87 SkASSERT(canvas); |
92 | 88 |
93 SkPaint paint; | 89 SkPaint paint; |
94 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 90 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
95 | 91 |
96 input->draw(canvas, | 92 input->draw(canvas, |
97 SkIntToScalar(inputOffset.x()), SkIntToScalar(inputOffset.y(
)), | 93 SkIntToScalar(inputOffset.x()), SkIntToScalar(inputOffset.y(
)), |
98 &paint); | 94 &paint); |
99 | 95 |
100 subset = surf->makeImageSnapshot(); | 96 subset = surf->makeImageSnapshot(); |
101 } | 97 } |
102 SkASSERT(subset->width() == srcIRect.width()); | 98 SkASSERT(subset->width() == srcIRect.width()); |
103 SkASSERT(subset->height() == srcIRect.height()); | 99 SkASSERT(subset->height() == srcIRect.height()); |
104 | 100 |
105 const SkImageInfo info = SkImageInfo::MakeN32(dstWidth, dstHeight, kPremul_S
kAlphaType); | 101 sk_sp<SkSpecialSurface> surf(source->makeSurface(ctx.outputProperties(), dst
IRect.size())); |
106 | |
107 sk_sp<SkSpecialSurface> surf(source->makeSurface(info)); | |
108 if (!surf) { | 102 if (!surf) { |
109 return nullptr; | 103 return nullptr; |
110 } | 104 } |
111 | 105 |
112 SkCanvas* canvas = surf->getCanvas(); | 106 SkCanvas* canvas = surf->getCanvas(); |
113 SkASSERT(canvas); | 107 SkASSERT(canvas); |
114 | 108 |
115 SkPaint paint; | 109 SkPaint paint; |
116 paint.setXfermodeMode(SkXfermode::kSrc_Mode); | 110 paint.setXfermodeMode(SkXfermode::kSrc_Mode); |
117 paint.setShader(subset->makeShader(SkShader::kRepeat_TileMode, SkShader::kRe
peat_TileMode)); | 111 paint.setShader(subset->makeShader(SkShader::kRepeat_TileMode, SkShader::kRe
peat_TileMode)); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 str->appendf(" dst: %.2f %.2f %.2f %.2f", | 154 str->appendf(" dst: %.2f %.2f %.2f %.2f", |
161 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto
m); | 155 fDstRect.fLeft, fDstRect.fTop, fDstRect.fRight, fDstRect.fBotto
m); |
162 if (this->getInput(0)) { | 156 if (this->getInput(0)) { |
163 str->appendf("input: ("); | 157 str->appendf("input: ("); |
164 this->getInput(0)->toString(str); | 158 this->getInput(0)->toString(str); |
165 str->appendf(")"); | 159 str->appendf(")"); |
166 } | 160 } |
167 str->append(")"); | 161 str->append(")"); |
168 } | 162 } |
169 #endif | 163 #endif |
OLD | NEW |