blob: ca11c38cace3f9e0b2ff177da6c36b7365c75b9e [file] [log] [blame]
sugoi@google.com781cc762013-01-15 15:40:19 +00001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "SkDisplacementMapEffect.h"
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +00009#include "SkReadBuffer.h"
10#include "SkWriteBuffer.h"
sugoi@google.com781cc762013-01-15 15:40:19 +000011#include "SkUnPreMultiply.h"
sugoi@google.com8cec63e2013-01-15 15:59:45 +000012#include "SkColorPriv.h"
sugoi@google.com781cc762013-01-15 15:40:19 +000013#if SK_SUPPORT_GPU
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +000014#include "GrContext.h"
robertphillipsea461502015-05-26 11:38:03 -070015#include "GrDrawContext.h"
bsalomon@google.com77af6802013-10-02 13:04:56 +000016#include "GrCoordTransform.h"
egdaniel605dd0f2014-11-12 08:35:25 -080017#include "GrInvariantOutput.h"
senorblancod762ca22015-04-07 12:16:55 -070018#include "effects/GrTextureDomain.h"
wangyix6af0c932015-07-22 10:21:17 -070019#include "gl/GrGLFragmentProcessor.h"
joshualitt30ba4362014-08-21 20:18:45 -070020#include "gl/builders/GrGLProgramBuilder.h"
sugoi@google.com781cc762013-01-15 15:40:19 +000021#endif
22
23namespace {
24
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000025#define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at most
26
sugoi@google.com781cc762013-01-15 15:40:19 +000027template<SkDisplacementMapEffect::ChannelSelectorType type>
28uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) {
mtklein@google.com330313a2013-08-22 15:37:26 +000029 SkDEBUGFAIL("Unknown channel selector");
sugoi@google.com781cc762013-01-15 15:40:19 +000030 return 0;
31}
32
33template<> uint32_t getValue<SkDisplacementMapEffect::kR_ChannelSelectorType>(
34 SkColor l, const SkUnPreMultiply::Scale* table) {
35 return SkUnPreMultiply::ApplyScale(table[SkGetPackedA32(l)], SkGetPackedR32(l));
36}
37
38template<> uint32_t getValue<SkDisplacementMapEffect::kG_ChannelSelectorType>(
39 SkColor l, const SkUnPreMultiply::Scale* table) {
40 return SkUnPreMultiply::ApplyScale(table[SkGetPackedA32(l)], SkGetPackedG32(l));
41}
42
43template<> uint32_t getValue<SkDisplacementMapEffect::kB_ChannelSelectorType>(
44 SkColor l, const SkUnPreMultiply::Scale* table) {
45 return SkUnPreMultiply::ApplyScale(table[SkGetPackedA32(l)], SkGetPackedB32(l));
46}
47
48template<> uint32_t getValue<SkDisplacementMapEffect::kA_ChannelSelectorType>(
49 SkColor l, const SkUnPreMultiply::Scale*) {
50 return SkGetPackedA32(l);
51}
52
53template<SkDisplacementMapEffect::ChannelSelectorType typeX,
54 SkDisplacementMapEffect::ChannelSelectorType typeY>
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +000055void computeDisplacement(const SkVector& scale, SkBitmap* dst,
56 SkBitmap* displ, const SkIPoint& offset,
57 SkBitmap* src,
58 const SkIRect& bounds)
sugoi@google.com781cc762013-01-15 15:40:19 +000059{
reed80ea19c2015-05-12 10:37:34 -070060 static const SkScalar Inv8bit = SkScalarInvert(255);
sugoi@google.com781cc762013-01-15 15:40:19 +000061 const int srcW = src->width();
62 const int srcH = src->height();
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +000063 const SkVector scaleForColor = SkVector::Make(SkScalarMul(scale.fX, Inv8bit),
64 SkScalarMul(scale.fY, Inv8bit));
65 const SkVector scaleAdj = SkVector::Make(SK_ScalarHalf - SkScalarMul(scale.fX, SK_ScalarHalf),
66 SK_ScalarHalf - SkScalarMul(scale.fY, SK_ScalarHalf));
sugoi@google.com781cc762013-01-15 15:40:19 +000067 const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable();
senorblanco@chromium.org01bdf3c2013-10-15 19:02:43 +000068 SkPMColor* dstPtr = dst->getAddr32(0, 0);
69 for (int y = bounds.top(); y < bounds.bottom(); ++y) {
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +000070 const SkPMColor* displPtr = displ->getAddr32(bounds.left() + offset.fX,
71 y + offset.fY);
senorblanco@chromium.org01bdf3c2013-10-15 19:02:43 +000072 for (int x = bounds.left(); x < bounds.right(); ++x, ++displPtr) {
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +000073 const SkScalar displX = SkScalarMul(scaleForColor.fX,
74 SkIntToScalar(getValue<typeX>(*displPtr, table))) + scaleAdj.fX;
75 const SkScalar displY = SkScalarMul(scaleForColor.fY,
76 SkIntToScalar(getValue<typeY>(*displPtr, table))) + scaleAdj.fY;
sugoi@google.com4ecd42e2013-03-19 15:07:30 +000077 // Truncate the displacement values
78 const int srcX = x + SkScalarTruncToInt(displX);
79 const int srcY = y + SkScalarTruncToInt(displY);
senorblanco@chromium.org01bdf3c2013-10-15 19:02:43 +000080 *dstPtr++ = ((srcX < 0) || (srcX >= srcW) || (srcY < 0) || (srcY >= srcH)) ?
sugoi@google.com4ecd42e2013-03-19 15:07:30 +000081 0 : *(src->getAddr32(srcX, srcY));
sugoi@google.com781cc762013-01-15 15:40:19 +000082 }
83 }
84}
85
86template<SkDisplacementMapEffect::ChannelSelectorType typeX>
87void computeDisplacement(SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +000088 const SkVector& scale, SkBitmap* dst,
89 SkBitmap* displ, const SkIPoint& offset,
90 SkBitmap* src,
91 const SkIRect& bounds)
sugoi@google.com781cc762013-01-15 15:40:19 +000092{
93 switch (yChannelSelector) {
94 case SkDisplacementMapEffect::kR_ChannelSelectorType:
95 computeDisplacement<typeX, SkDisplacementMapEffect::kR_ChannelSelectorType>(
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +000096 scale, dst, displ, offset, src, bounds);
sugoi@google.com781cc762013-01-15 15:40:19 +000097 break;
98 case SkDisplacementMapEffect::kG_ChannelSelectorType:
99 computeDisplacement<typeX, SkDisplacementMapEffect::kG_ChannelSelectorType>(
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000100 scale, dst, displ, offset, src, bounds);
sugoi@google.com781cc762013-01-15 15:40:19 +0000101 break;
102 case SkDisplacementMapEffect::kB_ChannelSelectorType:
103 computeDisplacement<typeX, SkDisplacementMapEffect::kB_ChannelSelectorType>(
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000104 scale, dst, displ, offset, src, bounds);
sugoi@google.com781cc762013-01-15 15:40:19 +0000105 break;
106 case SkDisplacementMapEffect::kA_ChannelSelectorType:
107 computeDisplacement<typeX, SkDisplacementMapEffect::kA_ChannelSelectorType>(
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000108 scale, dst, displ, offset, src, bounds);
sugoi@google.com781cc762013-01-15 15:40:19 +0000109 break;
110 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
111 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000112 SkDEBUGFAIL("Unknown Y channel selector");
sugoi@google.com781cc762013-01-15 15:40:19 +0000113 }
114}
115
116void computeDisplacement(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
117 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000118 const SkVector& scale, SkBitmap* dst,
119 SkBitmap* displ, const SkIPoint& offset,
120 SkBitmap* src,
121 const SkIRect& bounds)
sugoi@google.com781cc762013-01-15 15:40:19 +0000122{
123 switch (xChannelSelector) {
124 case SkDisplacementMapEffect::kR_ChannelSelectorType:
125 computeDisplacement<SkDisplacementMapEffect::kR_ChannelSelectorType>(
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000126 yChannelSelector, scale, dst, displ, offset, src, bounds);
sugoi@google.com781cc762013-01-15 15:40:19 +0000127 break;
128 case SkDisplacementMapEffect::kG_ChannelSelectorType:
129 computeDisplacement<SkDisplacementMapEffect::kG_ChannelSelectorType>(
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000130 yChannelSelector, scale, dst, displ, offset, src, bounds);
sugoi@google.com781cc762013-01-15 15:40:19 +0000131 break;
132 case SkDisplacementMapEffect::kB_ChannelSelectorType:
133 computeDisplacement<SkDisplacementMapEffect::kB_ChannelSelectorType>(
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000134 yChannelSelector, scale, dst, displ, offset, src, bounds);
sugoi@google.com781cc762013-01-15 15:40:19 +0000135 break;
136 case SkDisplacementMapEffect::kA_ChannelSelectorType:
137 computeDisplacement<SkDisplacementMapEffect::kA_ChannelSelectorType>(
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000138 yChannelSelector, scale, dst, displ, offset, src, bounds);
sugoi@google.com781cc762013-01-15 15:40:19 +0000139 break;
140 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
141 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000142 SkDEBUGFAIL("Unknown X channel selector");
sugoi@google.com781cc762013-01-15 15:40:19 +0000143 }
144}
145
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +0000146bool channel_selector_type_is_valid(SkDisplacementMapEffect::ChannelSelectorType cst) {
147 switch (cst) {
148 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
149 case SkDisplacementMapEffect::kR_ChannelSelectorType:
150 case SkDisplacementMapEffect::kG_ChannelSelectorType:
151 case SkDisplacementMapEffect::kB_ChannelSelectorType:
152 case SkDisplacementMapEffect::kA_ChannelSelectorType:
153 return true;
154 default:
155 break;
156 }
157 return false;
158}
159
sugoi@google.com781cc762013-01-15 15:40:19 +0000160} // end namespace
161
162///////////////////////////////////////////////////////////////////////////////
163
reed9fa60da2014-08-21 07:59:51 -0700164SkDisplacementMapEffect* SkDisplacementMapEffect::Create(ChannelSelectorType xChannelSelector,
165 ChannelSelectorType yChannelSelector,
166 SkScalar scale,
167 SkImageFilter* displacement,
168 SkImageFilter* color,
senorblanco24e06d52015-03-18 12:11:33 -0700169 const CropRect* cropRect) {
reed9fa60da2014-08-21 07:59:51 -0700170 if (!channel_selector_type_is_valid(xChannelSelector) ||
171 !channel_selector_type_is_valid(yChannelSelector)) {
halcanary96fcdcc2015-08-27 07:41:13 -0700172 return nullptr;
reed9fa60da2014-08-21 07:59:51 -0700173 }
174
175 SkImageFilter* inputs[2] = { displacement, color };
halcanary385fe4d2015-08-26 13:07:48 -0700176 return new SkDisplacementMapEffect(xChannelSelector, yChannelSelector, scale, inputs, cropRect);
reed9fa60da2014-08-21 07:59:51 -0700177}
178
sugoi@google.com781cc762013-01-15 15:40:19 +0000179SkDisplacementMapEffect::SkDisplacementMapEffect(ChannelSelectorType xChannelSelector,
180 ChannelSelectorType yChannelSelector,
181 SkScalar scale,
senorblanco9ea3d572014-07-08 09:16:22 -0700182 SkImageFilter* inputs[2],
senorblanco24e06d52015-03-18 12:11:33 -0700183 const CropRect* cropRect)
184 : INHERITED(2, inputs, cropRect)
sugoi@google.com781cc762013-01-15 15:40:19 +0000185 , fXChannelSelector(xChannelSelector)
186 , fYChannelSelector(yChannelSelector)
187 , fScale(scale)
188{
189}
190
191SkDisplacementMapEffect::~SkDisplacementMapEffect() {
192}
193
reed9fa60da2014-08-21 07:59:51 -0700194SkFlattenable* SkDisplacementMapEffect::CreateProc(SkReadBuffer& buffer) {
195 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 2);
196 ChannelSelectorType xsel = (ChannelSelectorType)buffer.readInt();
197 ChannelSelectorType ysel = (ChannelSelectorType)buffer.readInt();
198 SkScalar scale = buffer.readScalar();
senorblanco24e06d52015-03-18 12:11:33 -0700199 return Create(xsel, ysel, scale, common.getInput(0), common.getInput(1), &common.cropRect());
reed9fa60da2014-08-21 07:59:51 -0700200}
sugoi@google.com781cc762013-01-15 15:40:19 +0000201
commit-bot@chromium.org8b0e8ac2014-01-30 18:58:24 +0000202void SkDisplacementMapEffect::flatten(SkWriteBuffer& buffer) const {
sugoi@google.com781cc762013-01-15 15:40:19 +0000203 this->INHERITED::flatten(buffer);
204 buffer.writeInt((int) fXChannelSelector);
205 buffer.writeInt((int) fYChannelSelector);
206 buffer.writeScalar(fScale);
207}
208
209bool SkDisplacementMapEffect::onFilterImage(Proxy* proxy,
210 const SkBitmap& src,
senorblanco@chromium.org4cb543d2014-03-14 15:44:01 +0000211 const Context& ctx,
sugoi@google.com781cc762013-01-15 15:40:19 +0000212 SkBitmap* dst,
commit-bot@chromium.orgae761f72014-02-05 22:32:02 +0000213 SkIPoint* offset) const {
commit-bot@chromium.org6d7296a2013-12-19 17:00:46 +0000214 SkBitmap displ = src, color = src;
robertphillipsff0ca5e2015-07-22 11:54:44 -0700215 const SkImageFilter* colorInput = this->getColorInput();
216 const SkImageFilter* displInput = this->getDisplacementInput();
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000217 SkIPoint colorOffset = SkIPoint::Make(0, 0), displOffset = SkIPoint::Make(0, 0);
senorblanco@chromium.org4cb543d2014-03-14 15:44:01 +0000218 if ((colorInput && !colorInput->filterImage(proxy, src, ctx, &color, &colorOffset)) ||
219 (displInput && !displInput->filterImage(proxy, src, ctx, &displ, &displOffset))) {
sugoi@google.com781cc762013-01-15 15:40:19 +0000220 return false;
221 }
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000222 if ((displ.colorType() != kN32_SkColorType) ||
223 (color.colorType() != kN32_SkColorType)) {
sugoi@google.com781cc762013-01-15 15:40:19 +0000224 return false;
225 }
senorblanco@chromium.org01bdf3c2013-10-15 19:02:43 +0000226 SkIRect bounds;
senorblanco@chromium.org11825292014-03-14 17:44:41 +0000227 // Since computeDisplacement does bounds checking on color pixel access, we don't need to pad
228 // the color bitmap to bounds here.
229 if (!this->applyCropRect(ctx, color, colorOffset, &bounds)) {
senorblanco@chromium.org01bdf3c2013-10-15 19:02:43 +0000230 return false;
231 }
commit-bot@chromium.org5e79c2b2013-12-12 21:48:32 +0000232 SkIRect displBounds;
senorblanco@chromium.org11825292014-03-14 17:44:41 +0000233 if (!this->applyCropRect(ctx, proxy, displ, &displOffset, &displBounds, &displ)) {
commit-bot@chromium.org5e79c2b2013-12-12 21:48:32 +0000234 return false;
235 }
236 if (!bounds.intersect(displBounds)) {
237 return false;
238 }
senorblanco@chromium.org11825292014-03-14 17:44:41 +0000239 SkAutoLockPixels alp_displacement(displ), alp_color(color);
240 if (!displ.getPixels() || !color.getPixels()) {
241 return false;
242 }
senorblanco@chromium.org01bdf3c2013-10-15 19:02:43 +0000243
reed84825042014-09-02 12:50:45 -0700244 if (!dst->tryAllocPixels(color.info().makeWH(bounds.width(), bounds.height()))) {
sugoi@google.com781cc762013-01-15 15:40:19 +0000245 return false;
246 }
247
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000248 SkVector scale = SkVector::Make(fScale, fScale);
senorblanco@chromium.org4cb543d2014-03-14 15:44:01 +0000249 ctx.ctm().mapVectors(&scale, 1);
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000250 SkIRect colorBounds = bounds;
251 colorBounds.offset(-colorOffset);
252
253 computeDisplacement(fXChannelSelector, fYChannelSelector, scale, dst,
254 &displ, colorOffset - displOffset, &color, colorBounds);
sugoi@google.com781cc762013-01-15 15:40:19 +0000255
senorblanco@chromium.org6776b822014-01-03 21:48:22 +0000256 offset->fX = bounds.left();
257 offset->fY = bounds.top();
sugoi@google.com781cc762013-01-15 15:40:19 +0000258 return true;
259}
260
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +0000261void SkDisplacementMapEffect::computeFastBounds(const SkRect& src, SkRect* dst) const {
robertphillipsff0ca5e2015-07-22 11:54:44 -0700262 if (this->getColorInput()) {
263 this->getColorInput()->computeFastBounds(src, dst);
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +0000264 } else {
265 *dst = src;
266 }
senorblanco@chromium.org11825292014-03-14 17:44:41 +0000267 dst->outset(fScale * SK_ScalarHalf, fScale * SK_ScalarHalf);
senorblanco@chromium.org336d1d72014-01-27 21:03:17 +0000268}
269
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +0000270bool SkDisplacementMapEffect::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
robertphillipsd312dca2015-07-06 07:59:09 -0700271 SkIRect* dst) const {
senorblanco@chromium.org11825292014-03-14 17:44:41 +0000272 SkIRect bounds = src;
senorblanco@chromium.orgd4db6572014-05-07 20:00:04 +0000273 SkVector scale = SkVector::Make(fScale, fScale);
274 ctm.mapVectors(&scale, 1);
275 bounds.outset(SkScalarCeilToInt(scale.fX * SK_ScalarHalf),
276 SkScalarCeilToInt(scale.fY * SK_ScalarHalf));
robertphillipsff0ca5e2015-07-22 11:54:44 -0700277 if (this->getColorInput()) {
278 return this->getColorInput()->filterBounds(bounds, ctm, dst);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +0000279 }
senorblanco@chromium.org11825292014-03-14 17:44:41 +0000280 *dst = bounds;
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +0000281 return true;
282}
283
robertphillipsf3f5bad2014-12-19 13:49:15 -0800284#ifndef SK_IGNORE_TO_STRING
285void SkDisplacementMapEffect::toString(SkString* str) const {
286 str->appendf("SkDisplacementMapEffect: (");
287 str->appendf("scale: %f ", fScale);
288 str->appendf("displacement: (");
289 if (this->getDisplacementInput()) {
290 this->getDisplacementInput()->toString(str);
291 }
292 str->appendf(") color: (");
293 if (this->getColorInput()) {
294 this->getColorInput()->toString(str);
295 }
296 str->appendf("))");
297}
298#endif
299
sugoi@google.com781cc762013-01-15 15:40:19 +0000300///////////////////////////////////////////////////////////////////////////////
301
302#if SK_SUPPORT_GPU
joshualittb0a8a372014-09-23 09:50:21 -0700303class GrGLDisplacementMapEffect : public GrGLFragmentProcessor {
sugoi@google.com781cc762013-01-15 15:40:19 +0000304public:
joshualitteb2a6762014-12-04 11:35:33 -0800305 GrGLDisplacementMapEffect(const GrProcessor&);
sugoi@google.com781cc762013-01-15 15:40:19 +0000306 virtual ~GrGLDisplacementMapEffect();
307
wangyix7c157a92015-07-22 15:08:53 -0700308 virtual void emitCode(EmitArgs&) override;
sugoi@google.com781cc762013-01-15 15:40:19 +0000309
jvanverthcfc18862015-04-28 08:48:20 -0700310 static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*);
sugoi@google.com781cc762013-01-15 15:40:19 +0000311
senorblancod762ca22015-04-07 12:16:55 -0700312 const GrTextureDomain::GLDomain& glDomain() const { return fGLDomain; }
sugoi@google.com781cc762013-01-15 15:40:19 +0000313
wangyixb1daa862015-08-18 11:29:31 -0700314protected:
315 void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override;
316
sugoi@google.com781cc762013-01-15 15:40:19 +0000317private:
318 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector;
319 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector;
kkinnunen7510b222014-07-30 00:04:16 -0700320 GrGLProgramDataManager::UniformHandle fScaleUni;
senorblancod762ca22015-04-07 12:16:55 -0700321 GrTextureDomain::GLDomain fGLDomain;
sugoi@google.com781cc762013-01-15 15:40:19 +0000322
joshualittb0a8a372014-09-23 09:50:21 -0700323 typedef GrGLFragmentProcessor INHERITED;
sugoi@google.com781cc762013-01-15 15:40:19 +0000324};
325
326///////////////////////////////////////////////////////////////////////////////
327
joshualittb0a8a372014-09-23 09:50:21 -0700328class GrDisplacementMapEffect : public GrFragmentProcessor {
sugoi@google.com781cc762013-01-15 15:40:19 +0000329public:
joshualittb0a8a372014-09-23 09:50:21 -0700330 static GrFragmentProcessor* Create(
331 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
332 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, SkVector scale,
senorblancod762ca22015-04-07 12:16:55 -0700333 GrTexture* displacement, const SkMatrix& offsetMatrix, GrTexture* color,
334 const SkISize& colorDimensions) {
bsalomon4a339522015-10-06 08:40:50 -0700335 return new GrDisplacementMapEffect(xChannelSelector, yChannelSelector, scale, displacement,
336 offsetMatrix, color, colorDimensions);
bsalomon@google.com0ac6af42013-01-16 15:16:18 +0000337 }
338
sugoi@google.com781cc762013-01-15 15:40:19 +0000339 virtual ~GrDisplacementMapEffect();
340
sugoi@google.com781cc762013-01-15 15:40:19 +0000341 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector() const
342 { return fXChannelSelector; }
343 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const
344 { return fYChannelSelector; }
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000345 const SkVector& scale() const { return fScale; }
sugoi@google.com781cc762013-01-15 15:40:19 +0000346
mtklein36352bf2015-03-25 18:17:31 -0700347 const char* name() const override { return "DisplacementMap"; }
senorblancod762ca22015-04-07 12:16:55 -0700348 const GrTextureDomain& domain() const { return fDomain; }
sugoi@google.com781cc762013-01-15 15:40:19 +0000349
sugoi@google.com781cc762013-01-15 15:40:19 +0000350private:
wangyixb1daa862015-08-18 11:29:31 -0700351 GrGLFragmentProcessor* onCreateGLInstance() const override {
halcanary385fe4d2015-08-26 13:07:48 -0700352 return new GrGLDisplacementMapEffect(*this);
wangyixb1daa862015-08-18 11:29:31 -0700353 }
354
wangyix4b3050b2015-08-04 07:59:37 -0700355 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps,
356 GrProcessorKeyBuilder* b) const override {
357 GrGLDisplacementMapEffect::GenKey(*this, caps, b);
358 }
359
mtklein36352bf2015-03-25 18:17:31 -0700360 bool onIsEqual(const GrFragmentProcessor&) const override;
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000361
mtklein36352bf2015-03-25 18:17:31 -0700362 void onComputeInvariantOutput(GrInvariantOutput* inout) const override;
egdaniel1a8ecdf2014-10-03 06:24:12 -0700363
bsalomon4a339522015-10-06 08:40:50 -0700364 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
bsalomon@google.com0ac6af42013-01-16 15:16:18 +0000365 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000366 const SkVector& scale,
367 GrTexture* displacement, const SkMatrix& offsetMatrix,
senorblancod762ca22015-04-07 12:16:55 -0700368 GrTexture* color,
369 const SkISize& colorDimensions);
bsalomon@google.com0ac6af42013-01-16 15:16:18 +0000370
joshualittb0a8a372014-09-23 09:50:21 -0700371 GR_DECLARE_FRAGMENT_PROCESSOR_TEST;
sugoi@google.com781cc762013-01-15 15:40:19 +0000372
bsalomon@google.com77af6802013-10-02 13:04:56 +0000373 GrCoordTransform fDisplacementTransform;
sugoi@google.com781cc762013-01-15 15:40:19 +0000374 GrTextureAccess fDisplacementAccess;
bsalomon@google.com77af6802013-10-02 13:04:56 +0000375 GrCoordTransform fColorTransform;
senorblancod762ca22015-04-07 12:16:55 -0700376 GrTextureDomain fDomain;
sugoi@google.com781cc762013-01-15 15:40:19 +0000377 GrTextureAccess fColorAccess;
378 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector;
379 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector;
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000380 SkVector fScale;
sugoi@google.com781cc762013-01-15 15:40:19 +0000381
joshualittb0a8a372014-09-23 09:50:21 -0700382 typedef GrFragmentProcessor INHERITED;
sugoi@google.com781cc762013-01-15 15:40:19 +0000383};
384
senorblanco@chromium.org4cb543d2014-03-14 15:44:01 +0000385bool SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
commit-bot@chromium.orgae761f72014-02-05 22:32:02 +0000386 SkBitmap* result, SkIPoint* offset) const {
senorblanco@chromium.org6aa6fec2014-03-03 22:13:56 +0000387 SkBitmap colorBM = src;
commit-bot@chromium.org7b320702013-07-10 21:22:18 +0000388 SkIPoint colorOffset = SkIPoint::Make(0, 0);
robertphillipsff0ca5e2015-07-22 11:54:44 -0700389 if (this->getColorInput() &&
390 !this->getColorInput()->getInputResultGPU(proxy, src, ctx, &colorBM, &colorOffset)) {
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +0000391 return false;
sugoi@google.com781cc762013-01-15 15:40:19 +0000392 }
senorblanco@chromium.org6aa6fec2014-03-03 22:13:56 +0000393 SkBitmap displacementBM = src;
commit-bot@chromium.org7b320702013-07-10 21:22:18 +0000394 SkIPoint displacementOffset = SkIPoint::Make(0, 0);
robertphillipsff0ca5e2015-07-22 11:54:44 -0700395 if (this->getDisplacementInput() &&
396 !this->getDisplacementInput()->getInputResultGPU(proxy, src, ctx, &displacementBM,
397 &displacementOffset)) {
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +0000398 return false;
399 }
senorblanco@chromium.org11825292014-03-14 17:44:41 +0000400 SkIRect bounds;
401 // Since GrDisplacementMapEffect does bounds checking on color pixel access, we don't need to
402 // pad the color bitmap to bounds here.
403 if (!this->applyCropRect(ctx, colorBM, colorOffset, &bounds)) {
404 return false;
405 }
406 SkIRect displBounds;
407 if (!this->applyCropRect(ctx, proxy, displacementBM,
408 &displacementOffset, &displBounds, &displacementBM)) {
409 return false;
410 }
411 if (!bounds.intersect(displBounds)) {
412 return false;
413 }
414 GrTexture* color = colorBM.getTexture();
commit-bot@chromium.orgb8d00db2013-06-26 19:18:23 +0000415 GrTexture* displacement = displacementBM.getTexture();
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +0000416 GrContext* context = color->getContext();
sugoi@google.com781cc762013-01-15 15:40:19 +0000417
bsalomonf2703d82014-10-28 14:33:06 -0700418 GrSurfaceDesc desc;
bsalomon6bc1b5f2015-02-23 09:06:38 -0800419 desc.fFlags = kRenderTarget_GrSurfaceFlag;
senorblanco@chromium.orgd9cdff62014-03-17 23:41:40 +0000420 desc.fWidth = bounds.width();
421 desc.fHeight = bounds.height();
senorblanco@chromium.orgc2594f42013-01-30 19:08:47 +0000422 desc.fConfig = kSkia8888_GrPixelConfig;
sugoi@google.com781cc762013-01-15 15:40:19 +0000423
bsalomoneae62002015-07-31 13:59:30 -0700424 SkAutoTUnref<GrTexture> dst(context->textureProvider()->createApproxTexture(desc));
bsalomone3059732014-10-14 11:47:22 -0700425
426 if (!dst) {
senorblanco673d9732014-08-15 10:48:43 -0700427 return false;
428 }
sugoi@google.com781cc762013-01-15 15:40:19 +0000429
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000430 SkVector scale = SkVector::Make(fScale, fScale);
senorblanco@chromium.org4cb543d2014-03-14 15:44:01 +0000431 ctx.ctm().mapVectors(&scale, 1);
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000432
433 GrPaint paint;
bsalomon6267f812014-08-29 15:05:53 -0700434 SkMatrix offsetMatrix = GrCoordTransform::MakeDivByTextureWHMatrix(displacement);
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000435 offsetMatrix.preTranslate(SkIntToScalar(colorOffset.fX - displacementOffset.fX),
436 SkIntToScalar(colorOffset.fY - displacementOffset.fY));
437
bsalomonac856c92015-08-27 06:30:17 -0700438 paint.addColorFragmentProcessor(
bsalomon4a339522015-10-06 08:40:50 -0700439 GrDisplacementMapEffect::Create(fXChannelSelector,
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000440 fYChannelSelector,
441 scale,
442 displacement,
443 offsetMatrix,
senorblancod762ca22015-04-07 12:16:55 -0700444 color,
445 colorBM.dimensions()))->unref();
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000446 SkIRect colorBounds = bounds;
447 colorBounds.offset(-colorOffset);
448 SkMatrix matrix;
449 matrix.setTranslate(-SkIntToScalar(colorBounds.x()),
450 -SkIntToScalar(colorBounds.y()));
robertphillipsea461502015-05-26 11:38:03 -0700451
robertphillips2e1e51f2015-10-15 08:01:48 -0700452 SkAutoTUnref<GrDrawContext> drawContext(context->drawContext(dst->asRenderTarget()));
robertphillipsea461502015-05-26 11:38:03 -0700453 if (!drawContext) {
454 return false;
455 }
456
robertphillips2e1e51f2015-10-15 08:01:48 -0700457 drawContext->drawRect(GrClip::WideOpen(), paint, matrix, SkRect::Make(colorBounds));
senorblanco@chromium.org6776b822014-01-03 21:48:22 +0000458 offset->fX = bounds.left();
459 offset->fY = bounds.top();
senorblanco@chromium.org6aa6fec2014-03-03 22:13:56 +0000460 WrapTexture(dst, bounds.width(), bounds.height(), result);
461 return true;
sugoi@google.com781cc762013-01-15 15:40:19 +0000462}
463
464///////////////////////////////////////////////////////////////////////////////
465
466GrDisplacementMapEffect::GrDisplacementMapEffect(
467 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
468 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000469 const SkVector& scale,
sugoi@google.com781cc762013-01-15 15:40:19 +0000470 GrTexture* displacement,
senorblanco@chromium.org2bfe36b2014-01-20 19:58:28 +0000471 const SkMatrix& offsetMatrix,
senorblancod762ca22015-04-07 12:16:55 -0700472 GrTexture* color,
473 const SkISize& colorDimensions)
bsalomon9f876a32014-12-09 10:51:07 -0800474 : fDisplacementTransform(kLocal_GrCoordSet, offsetMatrix, displacement,
475 GrTextureParams::kNone_FilterMode)
bsalomon@google.com77af6802013-10-02 13:04:56 +0000476 , fDisplacementAccess(displacement)
bsalomon9f876a32014-12-09 10:51:07 -0800477 , fColorTransform(kLocal_GrCoordSet, color, GrTextureParams::kNone_FilterMode)
senorblancod762ca22015-04-07 12:16:55 -0700478 , fDomain(GrTextureDomain::MakeTexelDomain(color, SkIRect::MakeSize(colorDimensions)),
479 GrTextureDomain::kDecal_Mode)
sugoi@google.com781cc762013-01-15 15:40:19 +0000480 , fColorAccess(color)
481 , fXChannelSelector(xChannelSelector)
482 , fYChannelSelector(yChannelSelector)
483 , fScale(scale) {
joshualitteb2a6762014-12-04 11:35:33 -0800484 this->initClassID<GrDisplacementMapEffect>();
bsalomon@google.com77af6802013-10-02 13:04:56 +0000485 this->addCoordTransform(&fDisplacementTransform);
sugoi@google.com781cc762013-01-15 15:40:19 +0000486 this->addTextureAccess(&fDisplacementAccess);
bsalomon@google.com77af6802013-10-02 13:04:56 +0000487 this->addCoordTransform(&fColorTransform);
sugoi@google.com781cc762013-01-15 15:40:19 +0000488 this->addTextureAccess(&fColorAccess);
489}
490
491GrDisplacementMapEffect::~GrDisplacementMapEffect() {
492}
493
bsalomon0e08fc12014-10-15 08:19:04 -0700494bool GrDisplacementMapEffect::onIsEqual(const GrFragmentProcessor& sBase) const {
joshualitt49586be2014-09-16 08:21:41 -0700495 const GrDisplacementMapEffect& s = sBase.cast<GrDisplacementMapEffect>();
bsalomon420d7e92014-10-16 09:18:09 -0700496 return fXChannelSelector == s.fXChannelSelector &&
bsalomon@google.com68b58c92013-01-17 16:50:08 +0000497 fYChannelSelector == s.fYChannelSelector &&
498 fScale == s.fScale;
sugoi@google.com781cc762013-01-15 15:40:19 +0000499}
500
egdaniel605dd0f2014-11-12 08:35:25 -0800501void GrDisplacementMapEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const {
sugoi@google.com781cc762013-01-15 15:40:19 +0000502 // Any displacement offset bringing a pixel out of bounds will output a color of (0,0,0,0),
503 // so the only way we'd get a constant alpha is if the input color image has a constant alpha
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +0000504 // and no displacement offset push any texture coordinates out of bounds OR if the constant
sugoi@google.com781cc762013-01-15 15:40:19 +0000505 // alpha is 0. Since this isn't trivial to compute at this point, let's assume the output is
506 // not of constant color when a displacement effect is applied.
egdaniel605dd0f2014-11-12 08:35:25 -0800507 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput);
sugoi@google.com781cc762013-01-15 15:40:19 +0000508}
509
510///////////////////////////////////////////////////////////////////////////////
511
joshualittb0a8a372014-09-23 09:50:21 -0700512GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDisplacementMapEffect);
sugoi@google.com781cc762013-01-15 15:40:19 +0000513
bsalomonc21b09e2015-08-28 18:46:56 -0700514const GrFragmentProcessor* GrDisplacementMapEffect::TestCreate(GrProcessorTestData* d) {
joshualitt0067ff52015-07-08 14:26:19 -0700515 int texIdxDispl = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
516 GrProcessorUnitTest::kAlphaTextureIdx;
517 int texIdxColor = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx :
518 GrProcessorUnitTest::kAlphaTextureIdx;
sugoi@google.com781cc762013-01-15 15:40:19 +0000519 static const int kMaxComponent = 4;
520 SkDisplacementMapEffect::ChannelSelectorType xChannelSelector =
521 static_cast<SkDisplacementMapEffect::ChannelSelectorType>(
joshualitt0067ff52015-07-08 14:26:19 -0700522 d->fRandom->nextRangeU(1, kMaxComponent));
sugoi@google.com781cc762013-01-15 15:40:19 +0000523 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector =
524 static_cast<SkDisplacementMapEffect::ChannelSelectorType>(
joshualitt0067ff52015-07-08 14:26:19 -0700525 d->fRandom->nextRangeU(1, kMaxComponent));
526 SkVector scale = SkVector::Make(d->fRandom->nextRangeScalar(0, 100.0f),
527 d->fRandom->nextRangeScalar(0, 100.0f));
senorblancod762ca22015-04-07 12:16:55 -0700528 SkISize colorDimensions;
joshualitt0067ff52015-07-08 14:26:19 -0700529 colorDimensions.fWidth = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor]->width());
530 colorDimensions.fHeight = d->fRandom->nextRangeU(0, d->fTextures[texIdxColor]->height());
bsalomon4a339522015-10-06 08:40:50 -0700531 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, scale,
joshualitt0067ff52015-07-08 14:26:19 -0700532 d->fTextures[texIdxDispl], SkMatrix::I(),
533 d->fTextures[texIdxColor], colorDimensions);
sugoi@google.com781cc762013-01-15 15:40:19 +0000534}
535
536///////////////////////////////////////////////////////////////////////////////
537
joshualitteb2a6762014-12-04 11:35:33 -0800538GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrProcessor& proc)
539 : fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector())
joshualittb0a8a372014-09-23 09:50:21 -0700540 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector()) {
sugoi@google.com781cc762013-01-15 15:40:19 +0000541}
542
543GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() {
544}
545
wangyix7c157a92015-07-22 15:08:53 -0700546void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
547 const GrTextureDomain& domain = args.fFp.cast<GrDisplacementMapEffect>().domain();
sugoi@google.com4d94e1b2013-03-21 18:38:03 +0000548
wangyix7c157a92015-07-22 15:08:53 -0700549 fScaleUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibility,
bsalomon422f56f2014-12-09 10:18:12 -0800550 kVec2f_GrSLType, kDefault_GrSLPrecision, "Scale");
wangyix7c157a92015-07-22 15:08:53 -0700551 const char* scaleUni = args.fBuilder->getUniformCStr(fScaleUni);
sugoi@google.com781cc762013-01-15 15:40:19 +0000552 const char* dColor = "dColor";
sugoi@google.com781cc762013-01-15 15:40:19 +0000553 const char* cCoords = "cCoords";
554 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half float, use
555 // a number smaller than that to approximate 0, but
556 // leave room for 32-bit float GPU rounding errors.
557
wangyix7c157a92015-07-22 15:08:53 -0700558 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder();
joshualitt30ba4362014-08-21 20:18:45 -0700559 fsBuilder->codeAppendf("\t\tvec4 %s = ", dColor);
wangyix7c157a92015-07-22 15:08:53 -0700560 fsBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(),
561 args.fCoords[0].getType());
joshualitt30ba4362014-08-21 20:18:45 -0700562 fsBuilder->codeAppend(";\n");
sugoi@google.com781cc762013-01-15 15:40:19 +0000563
564 // Unpremultiply the displacement
joshualitt30ba4362014-08-21 20:18:45 -0700565 fsBuilder->codeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
bsalomon@google.comf910d3b2013-03-07 17:06:57 +0000566 dColor, dColor, nearZero, dColor, dColor);
wangyix7c157a92015-07-22 15:08:53 -0700567 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 1);
joshualitt30ba4362014-08-21 20:18:45 -0700568 fsBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.",
joshualitt8fc6c2d2014-12-22 15:27:05 -0800569 cCoords, coords2D.c_str(), scaleUni, dColor);
sugoi@google.com781cc762013-01-15 15:40:19 +0000570
571 switch (fXChannelSelector) {
572 case SkDisplacementMapEffect::kR_ChannelSelectorType:
joshualitt30ba4362014-08-21 20:18:45 -0700573 fsBuilder->codeAppend("r");
sugoi@google.com781cc762013-01-15 15:40:19 +0000574 break;
575 case SkDisplacementMapEffect::kG_ChannelSelectorType:
joshualitt30ba4362014-08-21 20:18:45 -0700576 fsBuilder->codeAppend("g");
sugoi@google.com781cc762013-01-15 15:40:19 +0000577 break;
578 case SkDisplacementMapEffect::kB_ChannelSelectorType:
joshualitt30ba4362014-08-21 20:18:45 -0700579 fsBuilder->codeAppend("b");
sugoi@google.com781cc762013-01-15 15:40:19 +0000580 break;
581 case SkDisplacementMapEffect::kA_ChannelSelectorType:
joshualitt30ba4362014-08-21 20:18:45 -0700582 fsBuilder->codeAppend("a");
sugoi@google.com781cc762013-01-15 15:40:19 +0000583 break;
584 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
585 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000586 SkDEBUGFAIL("Unknown X channel selector");
sugoi@google.com781cc762013-01-15 15:40:19 +0000587 }
588
589 switch (fYChannelSelector) {
590 case SkDisplacementMapEffect::kR_ChannelSelectorType:
joshualitt30ba4362014-08-21 20:18:45 -0700591 fsBuilder->codeAppend("r");
sugoi@google.com781cc762013-01-15 15:40:19 +0000592 break;
593 case SkDisplacementMapEffect::kG_ChannelSelectorType:
joshualitt30ba4362014-08-21 20:18:45 -0700594 fsBuilder->codeAppend("g");
sugoi@google.com781cc762013-01-15 15:40:19 +0000595 break;
596 case SkDisplacementMapEffect::kB_ChannelSelectorType:
joshualitt30ba4362014-08-21 20:18:45 -0700597 fsBuilder->codeAppend("b");
sugoi@google.com781cc762013-01-15 15:40:19 +0000598 break;
599 case SkDisplacementMapEffect::kA_ChannelSelectorType:
joshualitt30ba4362014-08-21 20:18:45 -0700600 fsBuilder->codeAppend("a");
sugoi@google.com781cc762013-01-15 15:40:19 +0000601 break;
602 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
603 default:
mtklein@google.com330313a2013-08-22 15:37:26 +0000604 SkDEBUGFAIL("Unknown Y channel selector");
sugoi@google.com781cc762013-01-15 15:40:19 +0000605 }
joshualitt30ba4362014-08-21 20:18:45 -0700606 fsBuilder->codeAppend("-vec2(0.5));\t\t");
sugoi@google.com781cc762013-01-15 15:40:19 +0000607
wangyix7c157a92015-07-22 15:08:53 -0700608 fGLDomain.sampleTexture(fsBuilder, domain, args.fOutputColor, SkString(cCoords),
609 args.fSamplers[1]);
joshualitt30ba4362014-08-21 20:18:45 -0700610 fsBuilder->codeAppend(";\n");
sugoi@google.com781cc762013-01-15 15:40:19 +0000611}
612
wangyixb1daa862015-08-18 11:29:31 -0700613void GrGLDisplacementMapEffect::onSetData(const GrGLProgramDataManager& pdman,
joshualittb0a8a372014-09-23 09:50:21 -0700614 const GrProcessor& proc) {
615 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMapEffect>();
sugoi@google.com781cc762013-01-15 15:40:19 +0000616 GrTexture* colorTex = displacementMap.texture(1);
reed80ea19c2015-05-12 10:37:34 -0700617 SkScalar scaleX = displacementMap.scale().fX / colorTex->width();
618 SkScalar scaleY = displacementMap.scale().fY / colorTex->height();
kkinnunen7510b222014-07-30 00:04:16 -0700619 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX),
620 colorTex->origin() == kTopLeft_GrSurfaceOrigin ?
621 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY));
senorblancod762ca22015-04-07 12:16:55 -0700622 fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin());
sugoi@google.com781cc762013-01-15 15:40:19 +0000623}
624
joshualittb0a8a372014-09-23 09:50:21 -0700625void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc,
jvanverthcfc18862015-04-28 08:48:20 -0700626 const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
joshualittb0a8a372014-09-23 09:50:21 -0700627 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMapEffect>();
sugoi@google.com781cc762013-01-15 15:40:19 +0000628
bsalomon63e99f72014-07-21 08:03:14 -0700629 uint32_t xKey = displacementMap.xChannelSelector();
630 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBits;
sugoi@google.com781cc762013-01-15 15:40:19 +0000631
bsalomon63e99f72014-07-21 08:03:14 -0700632 b->add32(xKey | yKey);
sugoi@google.com781cc762013-01-15 15:40:19 +0000633}
634#endif
robertphillipsf3f5bad2014-12-19 13:49:15 -0800635