| 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 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
rce, | 272 sk_sp<SkSpecialImage> SkDisplacementMapEffect::onFilterImage(SkSpecialImage* sou
rce, |
| 273 const Context& ctx, | 273 const Context& ctx, |
| 274 SkIPoint* offset) c
onst { | 274 SkIPoint* offset) c
onst { |
| 275 SkIPoint colorOffset = SkIPoint::Make(0, 0); | 275 SkIPoint colorOffset = SkIPoint::Make(0, 0); |
| 276 sk_sp<SkSpecialImage> color(this->filterInput(1, source, ctx, &colorOffset))
; | 276 sk_sp<SkSpecialImage> color(this->filterInput(1, source, ctx, &colorOffset))
; |
| 277 if (!color) { | 277 if (!color) { |
| 278 return nullptr; | 278 return nullptr; |
| 279 } | 279 } |
| 280 | 280 |
| 281 SkIPoint displOffset = SkIPoint::Make(0, 0); | 281 SkIPoint displOffset = SkIPoint::Make(0, 0); |
| 282 sk_sp<SkSpecialImage> displ(this->filterInput(0, source, ctx, &displOffset))
; | 282 // Creation of the displacement map should happen in a non-colorspace aware
context. This |
| 283 // texture is a purely mathematical construct, so we want to just operate on
the stored |
| 284 // values. Consider: |
| 285 // User supplies an sRGB displacement map. If we're rendering to a wider gam
ut, then we could |
| 286 // end up filtering the displacement map into that gamut, which has the effe
ct of reducing |
| 287 // the amount of displacement that it represents (as encoded values move awa
y from the |
| 288 // primaries). |
| 289 // With a more complex DAG attached to this input, it's not clear that worki
ng in ANY specific |
| 290 // color space makes sense, so we ignore color spaces (and gamma) entirely.
This may not be |
| 291 // ideal, but it's at least consistent and predictable. |
| 292 Context displContext(ctx.ctm(), ctx.clipBounds(), ctx.cache(), OutputPropert
ies(nullptr)); |
| 293 sk_sp<SkSpecialImage> displ(this->filterInput(0, source, displContext, &disp
lOffset)); |
| 283 if (!displ) { | 294 if (!displ) { |
| 284 return nullptr; | 295 return nullptr; |
| 285 } | 296 } |
| 286 | 297 |
| 287 const SkIRect srcBounds = SkIRect::MakeXYWH(colorOffset.x(), colorOffset.y()
, | 298 const SkIRect srcBounds = SkIRect::MakeXYWH(colorOffset.x(), colorOffset.y()
, |
| 288 color->width(), color->height())
; | 299 color->width(), color->height())
; |
| 289 | 300 |
| 290 // Both paths do bounds checking on color pixel access, we don't need to | 301 // Both paths do bounds checking on color pixel access, we don't need to |
| 291 // pad the color bitmap to bounds here. | 302 // pad the color bitmap to bounds here. |
| 292 SkIRect bounds; | 303 SkIRect bounds; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 633 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
| 623 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 634 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
| 624 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 635 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 625 | 636 |
| 626 uint32_t xKey = displacementMap.xChannelSelector(); | 637 uint32_t xKey = displacementMap.xChannelSelector(); |
| 627 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 638 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 628 | 639 |
| 629 b->add32(xKey | yKey); | 640 b->add32(xKey | yKey); |
| 630 } | 641 } |
| 631 #endif | 642 #endif |
| OLD | NEW |