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 "SkDisplacementMapEffect.h" | 8 #include "SkDisplacementMapEffect.h" |
9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 virtual void emitCode(GrGLShaderBuilder*, | 279 virtual void emitCode(GrGLShaderBuilder*, |
280 const GrDrawEffect&, | 280 const GrDrawEffect&, |
281 const GrEffectKey&, | 281 const GrEffectKey&, |
282 const char* outputColor, | 282 const char* outputColor, |
283 const char* inputColor, | 283 const char* inputColor, |
284 const TransformedCoordsArray&, | 284 const TransformedCoordsArray&, |
285 const TextureSamplerArray&) SK_OVERRIDE; | 285 const TextureSamplerArray&) SK_OVERRIDE; |
286 | 286 |
287 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); | 287 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); |
288 | 288 |
289 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 289 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; |
290 | 290 |
291 private: | 291 private: |
292 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; | 292 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; |
293 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 293 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
294 GrGLUniformManager::UniformHandle fScaleUni; | 294 GrGLProgramDataManager::UniformHandle fScaleUni; |
295 | 295 |
296 typedef GrGLEffect INHERITED; | 296 typedef GrGLEffect INHERITED; |
297 }; | 297 }; |
298 | 298 |
299 /////////////////////////////////////////////////////////////////////////////// | 299 /////////////////////////////////////////////////////////////////////////////// |
300 | 300 |
301 class GrDisplacementMapEffect : public GrEffect { | 301 class GrDisplacementMapEffect : public GrEffect { |
302 public: | 302 public: |
303 static GrEffect* Create(SkDisplacementMapEffect::ChannelSelectorType xChanne
lSelector, | 303 static GrEffect* Create(SkDisplacementMapEffect::ChannelSelectorType xChanne
lSelector, |
304 SkDisplacementMapEffect::ChannelSelectorType yChanne
lSelector, | 304 SkDisplacementMapEffect::ChannelSelectorType yChanne
lSelector, |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 // FIXME : This can be achieved with a "clamp to border" texture repeat mode
and | 581 // FIXME : This can be achieved with a "clamp to border" texture repeat mode
and |
582 // a 0 border color instead of computing if cCoords is out of bounds
here. | 582 // a 0 border color instead of computing if cCoords is out of bounds
here. |
583 builder->fsCodeAppendf( | 583 builder->fsCodeAppendf( |
584 "bool %s = (%s.x < 0.0) || (%s.y < 0.0) || (%s.x > 1.0) || (%s.y > 1.0);
\t\t", | 584 "bool %s = (%s.x < 0.0) || (%s.y < 0.0) || (%s.x > 1.0) || (%s.y > 1.0);
\t\t", |
585 outOfBounds, cCoords, cCoords, cCoords, cCoords); | 585 outOfBounds, cCoords, cCoords, cCoords, cCoords); |
586 builder->fsCodeAppendf("%s = %s ? vec4(0.0) : ", outputColor, outOfBounds); | 586 builder->fsCodeAppendf("%s = %s ? vec4(0.0) : ", outputColor, outOfBounds); |
587 builder->fsAppendTextureLookup(samplers[1], cCoords, coords[1].type()); | 587 builder->fsAppendTextureLookup(samplers[1], cCoords, coords[1].type()); |
588 builder->fsCodeAppend(";\n"); | 588 builder->fsCodeAppend(";\n"); |
589 } | 589 } |
590 | 590 |
591 void GrGLDisplacementMapEffect::setData(const GrGLUniformManager& uman, | 591 void GrGLDisplacementMapEffect::setData(const GrGLProgramDataManager& pdman, |
592 const GrDrawEffect& drawEffect) { | 592 const GrDrawEffect& drawEffect) { |
593 const GrDisplacementMapEffect& displacementMap = | 593 const GrDisplacementMapEffect& displacementMap = |
594 drawEffect.castEffect<GrDisplacementMapEffect>(); | 594 drawEffect.castEffect<GrDisplacementMapEffect>(); |
595 GrTexture* colorTex = displacementMap.texture(1); | 595 GrTexture* colorTex = displacementMap.texture(1); |
596 SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colo
rTex->width())); | 596 SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colo
rTex->width())); |
597 SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colo
rTex->height())); | 597 SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colo
rTex->height())); |
598 uman.set2f(fScaleUni, SkScalarToFloat(scaleX), | 598 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), |
599 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? | 599 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? |
600 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); | 600 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); |
601 } | 601 } |
602 | 602 |
603 void GrGLDisplacementMapEffect::GenKey(const GrDrawEffect& drawEffect, | 603 void GrGLDisplacementMapEffect::GenKey(const GrDrawEffect& drawEffect, |
604 const GrGLCaps&, GrEffectKeyBuilder* b) { | 604 const GrGLCaps&, GrEffectKeyBuilder* b) { |
605 const GrDisplacementMapEffect& displacementMap = | 605 const GrDisplacementMapEffect& displacementMap = |
606 drawEffect.castEffect<GrDisplacementMapEffect>(); | 606 drawEffect.castEffect<GrDisplacementMapEffect>(); |
607 | 607 |
608 uint32_t xKey = displacementMap.xChannelSelector(); | 608 uint32_t xKey = displacementMap.xChannelSelector(); |
609 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 609 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
610 | 610 |
611 b->add32(xKey | yKey); | 611 b->add32(xKey | yKey); |
612 } | 612 } |
613 #endif | 613 #endif |
OLD | NEW |