| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
| 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 "SkLightingImageFilter.h" | 8 #include "SkLightingImageFilter.h" |
| 9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 sobel(m[0], m[3], m[1], m[4], m[2], m[5], gOneHalf), | 155 sobel(m[0], m[3], m[1], m[4], m[2], m[5], gOneHalf), |
| 156 surfaceScale); | 156 surfaceScale); |
| 157 } | 157 } |
| 158 | 158 |
| 159 inline SkPoint3 bottomRightNormal(int m[9], SkScalar surfaceScale) { | 159 inline SkPoint3 bottomRightNormal(int m[9], SkScalar surfaceScale) { |
| 160 return pointToNormal(sobel(m[0], m[1], m[3], m[4], 0, 0, gTwoThirds), | 160 return pointToNormal(sobel(m[0], m[1], m[3], m[4], 0, 0, gTwoThirds), |
| 161 sobel(m[0], m[3], m[1], m[4], 0, 0, gTwoThirds), | 161 sobel(m[0], m[3], m[1], m[4], 0, 0, gTwoThirds), |
| 162 surfaceScale); | 162 surfaceScale); |
| 163 } | 163 } |
| 164 | 164 |
| 165 template <class LightingType, class LightType> void lightBitmap(const LightingTy
pe& lightingType, const SkLight* light, const SkBitmap& src, SkBitmap* dst, SkSc
alar surfaceScale) { | 165 template <class LightingType, class LightType> void lightBitmap(const LightingTy
pe& lightingType, const SkLight* light, const SkBitmap& src, SkBitmap* dst, SkSc
alar surfaceScale, const SkIRect& bounds) { |
| 166 SkASSERT(dst->width() == bounds.width() && dst->height() == bounds.height())
; |
| 166 const LightType* l = static_cast<const LightType*>(light); | 167 const LightType* l = static_cast<const LightType*>(light); |
| 167 int y = 0; | 168 int left = bounds.left(), right = bounds.right(); |
| 169 int bottom = bounds.bottom(); |
| 170 int y = bounds.top(); |
| 171 SkPMColor* dptr = dst->getAddr32(0, 0); |
| 168 { | 172 { |
| 169 const SkPMColor* row1 = src.getAddr32(0, 0); | 173 int x = left; |
| 170 const SkPMColor* row2 = src.getAddr32(0, 1); | 174 const SkPMColor* row1 = src.getAddr32(x, y); |
| 171 SkPMColor* dptr = dst->getAddr32(0, 0); | 175 const SkPMColor* row2 = src.getAddr32(x, y + 1); |
| 172 int m[9]; | 176 int m[9]; |
| 173 int x = 0; | |
| 174 m[4] = SkGetPackedA32(*row1++); | 177 m[4] = SkGetPackedA32(*row1++); |
| 175 m[5] = SkGetPackedA32(*row1++); | 178 m[5] = SkGetPackedA32(*row1++); |
| 176 m[7] = SkGetPackedA32(*row2++); | 179 m[7] = SkGetPackedA32(*row2++); |
| 177 m[8] = SkGetPackedA32(*row2++); | 180 m[8] = SkGetPackedA32(*row2++); |
| 178 SkPoint3 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); | 181 SkPoint3 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
| 179 *dptr++ = lightingType.light(topLeftNormal(m, surfaceScale), surfaceToLi
ght, l->lightColor(surfaceToLight)); | 182 *dptr++ = lightingType.light(topLeftNormal(m, surfaceScale), surfaceToLi
ght, l->lightColor(surfaceToLight)); |
| 180 for (x = 1; x < src.width() - 1; ++x) | 183 for (++x; x < right - 1; ++x) |
| 181 { | 184 { |
| 182 shiftMatrixLeft(m); | 185 shiftMatrixLeft(m); |
| 183 m[5] = SkGetPackedA32(*row1++); | 186 m[5] = SkGetPackedA32(*row1++); |
| 184 m[8] = SkGetPackedA32(*row2++); | 187 m[8] = SkGetPackedA32(*row2++); |
| 185 surfaceToLight = l->surfaceToLight(x, 0, m[4], surfaceScale); | 188 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
| 186 *dptr++ = lightingType.light(topNormal(m, surfaceScale), surfaceToLi
ght, l->lightColor(surfaceToLight)); | 189 *dptr++ = lightingType.light(topNormal(m, surfaceScale), surfaceToLi
ght, l->lightColor(surfaceToLight)); |
| 187 } | 190 } |
| 188 shiftMatrixLeft(m); | 191 shiftMatrixLeft(m); |
| 189 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); | 192 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
| 190 *dptr++ = lightingType.light(topRightNormal(m, surfaceScale), surfaceToL
ight, l->lightColor(surfaceToLight)); | 193 *dptr++ = lightingType.light(topRightNormal(m, surfaceScale), surfaceToL
ight, l->lightColor(surfaceToLight)); |
| 191 } | 194 } |
| 192 | 195 |
| 193 for (++y; y < src.height() - 1; ++y) { | 196 for (++y; y < bottom - 1; ++y) { |
| 194 const SkPMColor* row0 = src.getAddr32(0, y - 1); | 197 int x = left; |
| 195 const SkPMColor* row1 = src.getAddr32(0, y); | 198 const SkPMColor* row0 = src.getAddr32(x, y - 1); |
| 196 const SkPMColor* row2 = src.getAddr32(0, y + 1); | 199 const SkPMColor* row1 = src.getAddr32(x, y); |
| 197 SkPMColor* dptr = dst->getAddr32(0, y); | 200 const SkPMColor* row2 = src.getAddr32(x, y + 1); |
| 198 int m[9]; | 201 int m[9]; |
| 199 int x = 0; | |
| 200 m[1] = SkGetPackedA32(*row0++); | 202 m[1] = SkGetPackedA32(*row0++); |
| 201 m[2] = SkGetPackedA32(*row0++); | 203 m[2] = SkGetPackedA32(*row0++); |
| 202 m[4] = SkGetPackedA32(*row1++); | 204 m[4] = SkGetPackedA32(*row1++); |
| 203 m[5] = SkGetPackedA32(*row1++); | 205 m[5] = SkGetPackedA32(*row1++); |
| 204 m[7] = SkGetPackedA32(*row2++); | 206 m[7] = SkGetPackedA32(*row2++); |
| 205 m[8] = SkGetPackedA32(*row2++); | 207 m[8] = SkGetPackedA32(*row2++); |
| 206 SkPoint3 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); | 208 SkPoint3 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
| 207 *dptr++ = lightingType.light(leftNormal(m, surfaceScale), surfaceToLight
, l->lightColor(surfaceToLight)); | 209 *dptr++ = lightingType.light(leftNormal(m, surfaceScale), surfaceToLight
, l->lightColor(surfaceToLight)); |
| 208 for (x = 1; x < src.width() - 1; ++x) { | 210 for (++x; x < right - 1; ++x) { |
| 209 shiftMatrixLeft(m); | 211 shiftMatrixLeft(m); |
| 210 m[2] = SkGetPackedA32(*row0++); | 212 m[2] = SkGetPackedA32(*row0++); |
| 211 m[5] = SkGetPackedA32(*row1++); | 213 m[5] = SkGetPackedA32(*row1++); |
| 212 m[8] = SkGetPackedA32(*row2++); | 214 m[8] = SkGetPackedA32(*row2++); |
| 213 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); | 215 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
| 214 *dptr++ = lightingType.light(interiorNormal(m, surfaceScale), surfac
eToLight, l->lightColor(surfaceToLight)); | 216 *dptr++ = lightingType.light(interiorNormal(m, surfaceScale), surfac
eToLight, l->lightColor(surfaceToLight)); |
| 215 } | 217 } |
| 216 shiftMatrixLeft(m); | 218 shiftMatrixLeft(m); |
| 217 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); | 219 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
| 218 *dptr++ = lightingType.light(rightNormal(m, surfaceScale), surfaceToLigh
t, l->lightColor(surfaceToLight)); | 220 *dptr++ = lightingType.light(rightNormal(m, surfaceScale), surfaceToLigh
t, l->lightColor(surfaceToLight)); |
| 219 } | 221 } |
| 220 | 222 |
| 221 { | 223 { |
| 222 const SkPMColor* row0 = src.getAddr32(0, src.height() - 2); | 224 int x = left; |
| 223 const SkPMColor* row1 = src.getAddr32(0, src.height() - 1); | 225 const SkPMColor* row0 = src.getAddr32(x, bottom - 2); |
| 224 int x = 0; | 226 const SkPMColor* row1 = src.getAddr32(x, bottom - 1); |
| 225 SkPMColor* dptr = dst->getAddr32(0, src.height() - 1); | |
| 226 int m[9]; | 227 int m[9]; |
| 227 m[1] = SkGetPackedA32(*row0++); | 228 m[1] = SkGetPackedA32(*row0++); |
| 228 m[2] = SkGetPackedA32(*row0++); | 229 m[2] = SkGetPackedA32(*row0++); |
| 229 m[4] = SkGetPackedA32(*row1++); | 230 m[4] = SkGetPackedA32(*row1++); |
| 230 m[5] = SkGetPackedA32(*row1++); | 231 m[5] = SkGetPackedA32(*row1++); |
| 231 SkPoint3 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); | 232 SkPoint3 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
| 232 *dptr++ = lightingType.light(bottomLeftNormal(m, surfaceScale), surfaceT
oLight, l->lightColor(surfaceToLight)); | 233 *dptr++ = lightingType.light(bottomLeftNormal(m, surfaceScale), surfaceT
oLight, l->lightColor(surfaceToLight)); |
| 233 for (x = 1; x < src.width() - 1; ++x) | 234 for (++x; x < right - 1; ++x) |
| 234 { | 235 { |
| 235 shiftMatrixLeft(m); | 236 shiftMatrixLeft(m); |
| 236 m[2] = SkGetPackedA32(*row0++); | 237 m[2] = SkGetPackedA32(*row0++); |
| 237 m[5] = SkGetPackedA32(*row1++); | 238 m[5] = SkGetPackedA32(*row1++); |
| 238 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); | 239 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
| 239 *dptr++ = lightingType.light(bottomNormal(m, surfaceScale), surfaceT
oLight, l->lightColor(surfaceToLight)); | 240 *dptr++ = lightingType.light(bottomNormal(m, surfaceScale), surfaceT
oLight, l->lightColor(surfaceToLight)); |
| 240 } | 241 } |
| 241 shiftMatrixLeft(m); | 242 shiftMatrixLeft(m); |
| 242 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); | 243 surfaceToLight = l->surfaceToLight(x, y, m[4], surfaceScale); |
| 243 *dptr++ = lightingType.light(bottomRightNormal(m, surfaceScale), surface
ToLight, l->lightColor(surfaceToLight)); | 244 *dptr++ = lightingType.light(bottomRightNormal(m, surfaceScale), surface
ToLight, l->lightColor(surfaceToLight)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 254 | 255 |
| 255 void writePoint3(const SkPoint3& point, SkFlattenableWriteBuffer& buffer) { | 256 void writePoint3(const SkPoint3& point, SkFlattenableWriteBuffer& buffer) { |
| 256 buffer.writeScalar(point.fX); | 257 buffer.writeScalar(point.fX); |
| 257 buffer.writeScalar(point.fY); | 258 buffer.writeScalar(point.fY); |
| 258 buffer.writeScalar(point.fZ); | 259 buffer.writeScalar(point.fZ); |
| 259 }; | 260 }; |
| 260 | 261 |
| 261 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { | 262 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { |
| 262 public: | 263 public: |
| 263 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 264 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
| 264 SkScalar kd, SkImageFilter* input); | 265 SkScalar kd, SkImageFilter* input, const SkIRec
t* cropRect); |
| 265 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 266 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
| 266 | 267 |
| 267 #if SK_SUPPORT_GPU | 268 #if SK_SUPPORT_GPU |
| 268 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const SK_OVERRIDE
; | 269 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkIPoint& o
ffset) const SK_OVERRIDE; |
| 269 #endif | 270 #endif |
| 270 SkScalar kd() const { return fKD; } | 271 SkScalar kd() const { return fKD; } |
| 271 | 272 |
| 272 protected: | 273 protected: |
| 273 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer); | 274 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer); |
| 274 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; | 275 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; |
| 275 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 276 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, |
| 276 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; | 277 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; |
| 277 | 278 |
| 278 | 279 |
| 279 private: | 280 private: |
| 280 typedef SkLightingImageFilter INHERITED; | 281 typedef SkLightingImageFilter INHERITED; |
| 281 SkScalar fKD; | 282 SkScalar fKD; |
| 282 }; | 283 }; |
| 283 | 284 |
| 284 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 285 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
| 285 public: | 286 public: |
| 286 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input); | 287 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRect); |
| 287 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 288 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
| 288 | 289 |
| 289 #if SK_SUPPORT_GPU | 290 #if SK_SUPPORT_GPU |
| 290 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const SK_OVERRIDE
; | 291 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkIPoint& o
ffset) const SK_OVERRIDE; |
| 291 #endif | 292 #endif |
| 292 | 293 |
| 293 SkScalar ks() const { return fKS; } | 294 SkScalar ks() const { return fKS; } |
| 294 SkScalar shininess() const { return fShininess; } | 295 SkScalar shininess() const { return fShininess; } |
| 295 | 296 |
| 296 protected: | 297 protected: |
| 297 explicit SkSpecularLightingImageFilter(SkFlattenableReadBuffer& buffer); | 298 explicit SkSpecularLightingImageFilter(SkFlattenableReadBuffer& buffer); |
| 298 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; | 299 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; |
| 299 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 300 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, |
| 300 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; | 301 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; |
| 301 | 302 |
| 302 private: | 303 private: |
| 303 typedef SkLightingImageFilter INHERITED; | 304 typedef SkLightingImageFilter INHERITED; |
| 304 SkScalar fKS; | 305 SkScalar fKS; |
| 305 SkScalar fShininess; | 306 SkScalar fShininess; |
| 306 }; | 307 }; |
| 307 | 308 |
| 308 #if SK_SUPPORT_GPU | 309 #if SK_SUPPORT_GPU |
| 309 | 310 |
| 310 class GrLightingEffect : public GrSingleTextureEffect { | 311 class GrLightingEffect : public GrSingleTextureEffect { |
| 311 public: | 312 public: |
| 312 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale); | 313 GrLightingEffect(GrTexture* texture, const SkLight* light, SkScalar surfaceS
cale, const SkIPoint& offset); |
| 313 virtual ~GrLightingEffect(); | 314 virtual ~GrLightingEffect(); |
| 314 | 315 |
| 315 const SkLight* light() const { return fLight; } | 316 const SkLight* light() const { return fLight; } |
| 316 SkScalar surfaceScale() const { return fSurfaceScale; } | 317 SkScalar surfaceScale() const { return fSurfaceScale; } |
| 318 const SkIPoint& offset() const { return fOffset; } |
| 317 | 319 |
| 318 virtual void getConstantColorComponents(GrColor* color, | 320 virtual void getConstantColorComponents(GrColor* color, |
| 319 uint32_t* validFlags) const SK_OVERR
IDE { | 321 uint32_t* validFlags) const SK_OVERR
IDE { |
| 320 // lighting shaders are complicated. We just throw up our hands. | 322 // lighting shaders are complicated. We just throw up our hands. |
| 321 *validFlags = 0; | 323 *validFlags = 0; |
| 322 } | 324 } |
| 323 | 325 |
| 324 protected: | 326 protected: |
| 325 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 327 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
| 326 | 328 |
| 327 private: | 329 private: |
| 328 typedef GrSingleTextureEffect INHERITED; | 330 typedef GrSingleTextureEffect INHERITED; |
| 329 const SkLight* fLight; | 331 const SkLight* fLight; |
| 330 SkScalar fSurfaceScale; | 332 SkScalar fSurfaceScale; |
| 333 SkIPoint fOffset; |
| 331 }; | 334 }; |
| 332 | 335 |
| 333 class GrDiffuseLightingEffect : public GrLightingEffect { | 336 class GrDiffuseLightingEffect : public GrLightingEffect { |
| 334 public: | 337 public: |
| 335 static GrEffectRef* Create(GrTexture* texture, | 338 static GrEffectRef* Create(GrTexture* texture, |
| 336 const SkLight* light, | 339 const SkLight* light, |
| 337 SkScalar surfaceScale, | 340 SkScalar surfaceScale, |
| 341 const SkIPoint& offset, |
| 338 SkScalar kd) { | 342 SkScalar kd) { |
| 339 AutoEffectUnref effect(SkNEW_ARGS(GrDiffuseLightingEffect, (texture, | 343 AutoEffectUnref effect(SkNEW_ARGS(GrDiffuseLightingEffect, (texture, |
| 340 light, | 344 light, |
| 341 surfaceScale
, | 345 surfaceScale
, |
| 346 offset, |
| 342 kd))); | 347 kd))); |
| 343 return CreateEffectRef(effect); | 348 return CreateEffectRef(effect); |
| 344 } | 349 } |
| 345 | 350 |
| 346 static const char* Name() { return "DiffuseLighting"; } | 351 static const char* Name() { return "DiffuseLighting"; } |
| 347 | 352 |
| 348 typedef GrGLDiffuseLightingEffect GLEffect; | 353 typedef GrGLDiffuseLightingEffect GLEffect; |
| 349 | 354 |
| 350 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 355 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 351 SkScalar kd() const { return fKD; } | 356 SkScalar kd() const { return fKD; } |
| 352 | 357 |
| 353 private: | 358 private: |
| 354 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 359 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
| 355 | 360 |
| 356 GrDiffuseLightingEffect(GrTexture* texture, | 361 GrDiffuseLightingEffect(GrTexture* texture, |
| 357 const SkLight* light, | 362 const SkLight* light, |
| 358 SkScalar surfaceScale, | 363 SkScalar surfaceScale, |
| 364 const SkIPoint& offset, |
| 359 SkScalar kd); | 365 SkScalar kd); |
| 360 | 366 |
| 361 GR_DECLARE_EFFECT_TEST; | 367 GR_DECLARE_EFFECT_TEST; |
| 362 typedef GrLightingEffect INHERITED; | 368 typedef GrLightingEffect INHERITED; |
| 363 SkScalar fKD; | 369 SkScalar fKD; |
| 364 }; | 370 }; |
| 365 | 371 |
| 366 class GrSpecularLightingEffect : public GrLightingEffect { | 372 class GrSpecularLightingEffect : public GrLightingEffect { |
| 367 public: | 373 public: |
| 368 static GrEffectRef* Create(GrTexture* texture, | 374 static GrEffectRef* Create(GrTexture* texture, |
| 369 const SkLight* light, | 375 const SkLight* light, |
| 370 SkScalar surfaceScale, | 376 SkScalar surfaceScale, |
| 377 const SkIPoint& offset, |
| 371 SkScalar ks, | 378 SkScalar ks, |
| 372 SkScalar shininess) { | 379 SkScalar shininess) { |
| 373 AutoEffectUnref effect(SkNEW_ARGS(GrSpecularLightingEffect, (texture, | 380 AutoEffectUnref effect(SkNEW_ARGS(GrSpecularLightingEffect, (texture, |
| 374 light, | 381 light, |
| 375 surfaceScal
e, | 382 surfaceScal
e, |
| 383 offset, |
| 376 ks, | 384 ks, |
| 377 shininess))
); | 385 shininess))
); |
| 378 return CreateEffectRef(effect); | 386 return CreateEffectRef(effect); |
| 379 } | 387 } |
| 380 static const char* Name() { return "SpecularLighting"; } | 388 static const char* Name() { return "SpecularLighting"; } |
| 381 | 389 |
| 382 typedef GrGLSpecularLightingEffect GLEffect; | 390 typedef GrGLSpecularLightingEffect GLEffect; |
| 383 | 391 |
| 384 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 392 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 385 SkScalar ks() const { return fKS; } | 393 SkScalar ks() const { return fKS; } |
| 386 SkScalar shininess() const { return fShininess; } | 394 SkScalar shininess() const { return fShininess; } |
| 387 | 395 |
| 388 private: | 396 private: |
| 389 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 397 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
| 390 | 398 |
| 391 GrSpecularLightingEffect(GrTexture* texture, | 399 GrSpecularLightingEffect(GrTexture* texture, |
| 392 const SkLight* light, | 400 const SkLight* light, |
| 393 SkScalar surfaceScale, | 401 SkScalar surfaceScale, |
| 402 const SkIPoint& offset, |
| 394 SkScalar ks, | 403 SkScalar ks, |
| 395 SkScalar shininess); | 404 SkScalar shininess); |
| 396 | 405 |
| 397 GR_DECLARE_EFFECT_TEST; | 406 GR_DECLARE_EFFECT_TEST; |
| 398 typedef GrLightingEffect INHERITED; | 407 typedef GrLightingEffect INHERITED; |
| 399 SkScalar fKS; | 408 SkScalar fKS; |
| 400 SkScalar fShininess; | 409 SkScalar fShininess; |
| 401 }; | 410 }; |
| 402 | 411 |
| 403 /////////////////////////////////////////////////////////////////////////////// | 412 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 14 matching lines...) Expand all Loading... |
| 418 * the light. The expression will be used in the FS. emitLightColor writes a
n expression into | 427 * the light. The expression will be used in the FS. emitLightColor writes a
n expression into |
| 419 * the FS that is the color of the light. Either function may add functions
and/or uniforms to | 428 * the FS that is the color of the light. Either function may add functions
and/or uniforms to |
| 420 * the FS. The default of emitLightColor appends the name of the constant li
ght color uniform | 429 * the FS. The default of emitLightColor appends the name of the constant li
ght color uniform |
| 421 * and so this function only needs to be overridden if the light color varie
s spatially. | 430 * and so this function only needs to be overridden if the light color varie
s spatially. |
| 422 */ | 431 */ |
| 423 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) = 0; | 432 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) = 0; |
| 424 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight); | 433 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight); |
| 425 | 434 |
| 426 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
ht must call | 435 // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLig
ht must call |
| 427 // INHERITED::setData(). | 436 // INHERITED::setData(). |
| 428 virtual void setData(const GrGLUniformManager&, const SkLight* light) const; | 437 virtual void setData(const GrGLUniformManager&, |
| 438 const SkLight* light, |
| 439 const SkIPoint& offset) const; |
| 429 | 440 |
| 430 protected: | 441 protected: |
| 431 /** | 442 /** |
| 432 * Gets the constant light color uniform. Subclasses can use this in their e
mitLightColor | 443 * Gets the constant light color uniform. Subclasses can use this in their e
mitLightColor |
| 433 * function. | 444 * function. |
| 434 */ | 445 */ |
| 435 UniformHandle lightColorUni() const { return fColorUni; } | 446 UniformHandle lightColorUni() const { return fColorUni; } |
| 436 | 447 |
| 437 private: | 448 private: |
| 438 UniformHandle fColorUni; | 449 UniformHandle fColorUni; |
| 439 | 450 |
| 440 typedef SkRefCnt INHERITED; | 451 typedef SkRefCnt INHERITED; |
| 441 }; | 452 }; |
| 442 | 453 |
| 443 /////////////////////////////////////////////////////////////////////////////// | 454 /////////////////////////////////////////////////////////////////////////////// |
| 444 | 455 |
| 445 class GrGLDistantLight : public GrGLLight { | 456 class GrGLDistantLight : public GrGLLight { |
| 446 public: | 457 public: |
| 447 virtual ~GrGLDistantLight() {} | 458 virtual ~GrGLDistantLight() {} |
| 448 virtual void setData(const GrGLUniformManager&, const SkLight* light) const
SK_OVERRIDE; | 459 virtual void setData(const GrGLUniformManager&, |
| 460 const SkLight* light, |
| 461 const SkIPoint& offset) const SK_OVERRIDE; |
| 449 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; | 462 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; |
| 450 | 463 |
| 451 private: | 464 private: |
| 452 typedef GrGLLight INHERITED; | 465 typedef GrGLLight INHERITED; |
| 453 UniformHandle fDirectionUni; | 466 UniformHandle fDirectionUni; |
| 454 }; | 467 }; |
| 455 | 468 |
| 456 /////////////////////////////////////////////////////////////////////////////// | 469 /////////////////////////////////////////////////////////////////////////////// |
| 457 | 470 |
| 458 class GrGLPointLight : public GrGLLight { | 471 class GrGLPointLight : public GrGLLight { |
| 459 public: | 472 public: |
| 460 virtual ~GrGLPointLight() {} | 473 virtual ~GrGLPointLight() {} |
| 461 virtual void setData(const GrGLUniformManager&, const SkLight* light) const
SK_OVERRIDE; | 474 virtual void setData(const GrGLUniformManager&, |
| 475 const SkLight* light, |
| 476 const SkIPoint& offset) const SK_OVERRIDE; |
| 462 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; | 477 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; |
| 463 | 478 |
| 464 private: | 479 private: |
| 465 typedef GrGLLight INHERITED; | 480 typedef GrGLLight INHERITED; |
| 466 SkPoint3 fLocation; | |
| 467 UniformHandle fLocationUni; | 481 UniformHandle fLocationUni; |
| 468 }; | 482 }; |
| 469 | 483 |
| 470 /////////////////////////////////////////////////////////////////////////////// | 484 /////////////////////////////////////////////////////////////////////////////// |
| 471 | 485 |
| 472 class GrGLSpotLight : public GrGLLight { | 486 class GrGLSpotLight : public GrGLLight { |
| 473 public: | 487 public: |
| 474 virtual ~GrGLSpotLight() {} | 488 virtual ~GrGLSpotLight() {} |
| 475 virtual void setData(const GrGLUniformManager&, const SkLight* light) const
SK_OVERRIDE; | 489 virtual void setData(const GrGLUniformManager&, |
| 490 const SkLight* light, |
| 491 const SkIPoint& offset) const SK_OVERRIDE; |
| 476 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; | 492 virtual void emitSurfaceToLight(GrGLShaderBuilder*, const char* z) SK_OVERRI
DE; |
| 477 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight)
SK_OVERRIDE; | 493 virtual void emitLightColor(GrGLShaderBuilder*, const char *surfaceToLight)
SK_OVERRIDE; |
| 478 | 494 |
| 479 private: | 495 private: |
| 480 typedef GrGLLight INHERITED; | 496 typedef GrGLLight INHERITED; |
| 481 | 497 |
| 482 SkString fLightColorFunc; | 498 SkString fLightColorFunc; |
| 483 UniformHandle fLocationUni; | 499 UniformHandle fLocationUni; |
| 484 UniformHandle fExponentUni; | 500 UniformHandle fExponentUni; |
| 485 UniformHandle fCosOuterConeAngleUni; | 501 UniformHandle fCosOuterConeAngleUni; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 SkPoint3 fTarget; | 750 SkPoint3 fTarget; |
| 735 SkScalar fSpecularExponent; | 751 SkScalar fSpecularExponent; |
| 736 SkScalar fCosOuterConeAngle; | 752 SkScalar fCosOuterConeAngle; |
| 737 SkScalar fCosInnerConeAngle; | 753 SkScalar fCosInnerConeAngle; |
| 738 SkScalar fConeScale; | 754 SkScalar fConeScale; |
| 739 SkPoint3 fS; | 755 SkPoint3 fS; |
| 740 }; | 756 }; |
| 741 | 757 |
| 742 /////////////////////////////////////////////////////////////////////////////// | 758 /////////////////////////////////////////////////////////////////////////////// |
| 743 | 759 |
| 744 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca
le, SkImageFilter* input) | 760 SkLightingImageFilter::SkLightingImageFilter(SkLight* light, SkScalar surfaceSca
le, SkImageFilter* input, const SkIRect* cropRect) |
| 745 : INHERITED(input), | 761 : INHERITED(input, cropRect), |
| 746 fLight(light), | 762 fLight(light), |
| 747 fSurfaceScale(SkScalarDiv(surfaceScale, SkIntToScalar(255))) | 763 fSurfaceScale(SkScalarDiv(surfaceScale, SkIntToScalar(255))) |
| 748 { | 764 { |
| 749 SkASSERT(fLight); | 765 SkASSERT(fLight); |
| 750 // our caller knows that we take ownership of the light, so we don't | 766 // our caller knows that we take ownership of the light, so we don't |
| 751 // need to call ref() here. | 767 // need to call ref() here. |
| 752 } | 768 } |
| 753 | 769 |
| 754 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse( | 770 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse( |
| 755 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, | 771 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, |
| 756 SkScalar kd, SkImageFilter* input) { | 772 SkScalar kd, SkImageFilter* input, const SkIRect* cropRect) { |
| 757 return SkNEW_ARGS(SkDiffuseLightingImageFilter, | 773 return SkNEW_ARGS(SkDiffuseLightingImageFilter, |
| 758 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), surfaceScale, kd, | 774 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), surfaceScale, kd, |
| 759 input)); | 775 input, cropRect)); |
| 760 } | 776 } |
| 761 | 777 |
| 762 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse( | 778 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse( |
| 763 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, | 779 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, |
| 764 SkScalar kd, SkImageFilter* input) { | 780 SkScalar kd, SkImageFilter* input, const SkIRect* cropRect) { |
| 765 return SkNEW_ARGS(SkDiffuseLightingImageFilter, | 781 return SkNEW_ARGS(SkDiffuseLightingImageFilter, |
| 766 (SkNEW_ARGS(SkPointLight, (location, lightColor)), surfaceScale, kd, | 782 (SkNEW_ARGS(SkPointLight, (location, lightColor)), surfaceScale, kd, |
| 767 input)); | 783 input, cropRect)); |
| 768 } | 784 } |
| 769 | 785 |
| 770 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse( | 786 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse( |
| 771 const SkPoint3& location, const SkPoint3& target, | 787 const SkPoint3& location, const SkPoint3& target, |
| 772 SkScalar specularExponent, SkScalar cutoffAngle, | 788 SkScalar specularExponent, SkScalar cutoffAngle, |
| 773 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, | 789 SkColor lightColor, SkScalar surfaceScale, SkScalar kd, |
| 774 SkImageFilter* input) { | 790 SkImageFilter* input, const SkIRect* cropRect) { |
| 775 return SkNEW_ARGS(SkDiffuseLightingImageFilter, | 791 return SkNEW_ARGS(SkDiffuseLightingImageFilter, |
| 776 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, | 792 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, |
| 777 cutoffAngle, lightColor)), | 793 cutoffAngle, lightColor)), |
| 778 surfaceScale, kd, input)); | 794 surfaceScale, kd, input, cropRect)); |
| 779 } | 795 } |
| 780 | 796 |
| 781 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular( | 797 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular( |
| 782 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, | 798 const SkPoint3& direction, SkColor lightColor, SkScalar surfaceScale, |
| 783 SkScalar ks, SkScalar shininess, SkImageFilter* input) { | 799 SkScalar ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRe
ct) { |
| 784 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 800 return SkNEW_ARGS(SkSpecularLightingImageFilter, |
| 785 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), | 801 (SkNEW_ARGS(SkDistantLight, (direction, lightColor)), |
| 786 surfaceScale, ks, shininess, input)); | 802 surfaceScale, ks, shininess, input, cropRect)); |
| 787 } | 803 } |
| 788 | 804 |
| 789 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular( | 805 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular( |
| 790 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, | 806 const SkPoint3& location, SkColor lightColor, SkScalar surfaceScale, |
| 791 SkScalar ks, SkScalar shininess, SkImageFilter* input) { | 807 SkScalar ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRe
ct) { |
| 792 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 808 return SkNEW_ARGS(SkSpecularLightingImageFilter, |
| 793 (SkNEW_ARGS(SkPointLight, (location, lightColor)), | 809 (SkNEW_ARGS(SkPointLight, (location, lightColor)), |
| 794 surfaceScale, ks, shininess, input)); | 810 surfaceScale, ks, shininess, input, cropRect)); |
| 795 } | 811 } |
| 796 | 812 |
| 797 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular( | 813 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular( |
| 798 const SkPoint3& location, const SkPoint3& target, | 814 const SkPoint3& location, const SkPoint3& target, |
| 799 SkScalar specularExponent, SkScalar cutoffAngle, | 815 SkScalar specularExponent, SkScalar cutoffAngle, |
| 800 SkColor lightColor, SkScalar surfaceScale, | 816 SkColor lightColor, SkScalar surfaceScale, |
| 801 SkScalar ks, SkScalar shininess, SkImageFilter* input) { | 817 SkScalar ks, SkScalar shininess, SkImageFilter* input, const SkIRect* cropRe
ct) { |
| 802 return SkNEW_ARGS(SkSpecularLightingImageFilter, | 818 return SkNEW_ARGS(SkSpecularLightingImageFilter, |
| 803 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, cutoffAngl
e, lightColor)), | 819 (SkNEW_ARGS(SkSpotLight, (location, target, specularExponent, cutoffAngl
e, lightColor)), |
| 804 surfaceScale, ks, shininess, input)); | 820 surfaceScale, ks, shininess, input, cropRect)); |
| 805 } | 821 } |
| 806 | 822 |
| 807 SkLightingImageFilter::~SkLightingImageFilter() { | 823 SkLightingImageFilter::~SkLightingImageFilter() { |
| 808 fLight->unref(); | 824 fLight->unref(); |
| 809 } | 825 } |
| 810 | 826 |
| 811 SkLightingImageFilter::SkLightingImageFilter(SkFlattenableReadBuffer& buffer) | 827 SkLightingImageFilter::SkLightingImageFilter(SkFlattenableReadBuffer& buffer) |
| 812 : INHERITED(buffer) | 828 : INHERITED(buffer) |
| 813 { | 829 { |
| 814 fLight = buffer.readFlattenableT<SkLight>(); | 830 fLight = buffer.readFlattenableT<SkLight>(); |
| 815 fSurfaceScale = buffer.readScalar(); | 831 fSurfaceScale = buffer.readScalar(); |
| 816 } | 832 } |
| 817 | 833 |
| 818 void SkLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { | 834 void SkLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) const { |
| 819 this->INHERITED::flatten(buffer); | 835 this->INHERITED::flatten(buffer); |
| 820 buffer.writeFlattenable(fLight); | 836 buffer.writeFlattenable(fLight); |
| 821 buffer.writeScalar(fSurfaceScale); | 837 buffer.writeScalar(fSurfaceScale); |
| 822 } | 838 } |
| 823 | 839 |
| 824 /////////////////////////////////////////////////////////////////////////////// | 840 /////////////////////////////////////////////////////////////////////////////// |
| 825 | 841 |
| 826 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca
lar surfaceScale, SkScalar kd, SkImageFilter* input) | 842 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkLight* light, SkSca
lar surfaceScale, SkScalar kd, SkImageFilter* input, const SkIRect* cropRect = N
ULL) |
| 827 : SkLightingImageFilter(light, surfaceScale, input), | 843 : SkLightingImageFilter(light, surfaceScale, input, cropRect), |
| 828 fKD(kd) | 844 fKD(kd) |
| 829 { | 845 { |
| 830 } | 846 } |
| 831 | 847 |
| 832 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkFlattenableReadBuff
er& buffer) | 848 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkFlattenableReadBuff
er& buffer) |
| 833 : INHERITED(buffer) | 849 : INHERITED(buffer) |
| 834 { | 850 { |
| 835 fKD = buffer.readScalar(); | 851 fKD = buffer.readScalar(); |
| 836 } | 852 } |
| 837 | 853 |
| 838 void SkDiffuseLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) con
st { | 854 void SkDiffuseLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) con
st { |
| 839 this->INHERITED::flatten(buffer); | 855 this->INHERITED::flatten(buffer); |
| 840 buffer.writeScalar(fKD); | 856 buffer.writeScalar(fKD); |
| 841 } | 857 } |
| 842 | 858 |
| 843 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy*, | 859 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy*, |
| 844 const SkBitmap& src, | 860 const SkBitmap& src, |
| 845 const SkMatrix&, | 861 const SkMatrix&, |
| 846 SkBitmap* dst, | 862 SkBitmap* dst, |
| 847 SkIPoint*) { | 863 SkIPoint* offset) { |
| 848 if (src.config() != SkBitmap::kARGB_8888_Config) { | 864 if (src.config() != SkBitmap::kARGB_8888_Config) { |
| 849 return false; | 865 return false; |
| 850 } | 866 } |
| 851 SkAutoLockPixels alp(src); | 867 SkAutoLockPixels alp(src); |
| 852 if (!src.getPixels()) { | 868 if (!src.getPixels()) { |
| 853 return false; | 869 return false; |
| 854 } | 870 } |
| 855 if (src.width() < 2 || src.height() < 2) { | 871 |
| 872 SkIRect bounds; |
| 873 src.getBounds(&bounds); |
| 874 if (!this->applyCropRect(&bounds)) { |
| 856 return false; | 875 return false; |
| 857 } | 876 } |
| 858 dst->setConfig(src.config(), src.width(), src.height()); | 877 |
| 878 if (bounds.width() < 2 || bounds.height() < 2) { |
| 879 return false; |
| 880 } |
| 881 |
| 882 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
| 859 dst->allocPixels(); | 883 dst->allocPixels(); |
| 860 | 884 |
| 861 DiffuseLightingType lightingType(fKD); | 885 DiffuseLightingType lightingType(fKD); |
| 862 switch (light()->type()) { | 886 switch (light()->type()) { |
| 863 case SkLight::kDistant_LightType: | 887 case SkLight::kDistant_LightType: |
| 864 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, light
(), src, dst, surfaceScale()); | 888 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, light
(), src, dst, surfaceScale(), bounds); |
| 865 break; | 889 break; |
| 866 case SkLight::kPoint_LightType: | 890 case SkLight::kPoint_LightType: |
| 867 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, light()
, src, dst, surfaceScale()); | 891 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, light()
, src, dst, surfaceScale(), bounds); |
| 868 break; | 892 break; |
| 869 case SkLight::kSpot_LightType: | 893 case SkLight::kSpot_LightType: |
| 870 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, light(),
src, dst, surfaceScale()); | 894 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, light(),
src, dst, surfaceScale(), bounds); |
| 871 break; | 895 break; |
| 872 } | 896 } |
| 897 |
| 898 offset->fX += bounds.left(); |
| 899 offset->fY += bounds.top(); |
| 873 return true; | 900 return true; |
| 874 } | 901 } |
| 875 | 902 |
| 876 #if SK_SUPPORT_GPU | 903 #if SK_SUPPORT_GPU |
| 877 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture) const { | 904 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkIPoint& offset) const { |
| 878 if (effect) { | 905 if (effect) { |
| 879 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 906 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
| 880 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, kd())
; | 907 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, offse
t, kd()); |
| 881 } | 908 } |
| 882 return true; | 909 return true; |
| 883 } | 910 } |
| 884 #endif | 911 #endif |
| 885 | 912 |
| 886 /////////////////////////////////////////////////////////////////////////////// | 913 /////////////////////////////////////////////////////////////////////////////// |
| 887 | 914 |
| 888 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS
calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input) | 915 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS
calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input, const
SkIRect* cropRect) |
| 889 : SkLightingImageFilter(light, surfaceScale, input), | 916 : SkLightingImageFilter(light, surfaceScale, input, cropRect), |
| 890 fKS(ks), | 917 fKS(ks), |
| 891 fShininess(shininess) | 918 fShininess(shininess) |
| 892 { | 919 { |
| 893 } | 920 } |
| 894 | 921 |
| 895 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkFlattenableReadBu
ffer& buffer) | 922 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkFlattenableReadBu
ffer& buffer) |
| 896 : INHERITED(buffer) | 923 : INHERITED(buffer) |
| 897 { | 924 { |
| 898 fKS = buffer.readScalar(); | 925 fKS = buffer.readScalar(); |
| 899 fShininess = buffer.readScalar(); | 926 fShininess = buffer.readScalar(); |
| 900 } | 927 } |
| 901 | 928 |
| 902 void SkSpecularLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) co
nst { | 929 void SkSpecularLightingImageFilter::flatten(SkFlattenableWriteBuffer& buffer) co
nst { |
| 903 this->INHERITED::flatten(buffer); | 930 this->INHERITED::flatten(buffer); |
| 904 buffer.writeScalar(fKS); | 931 buffer.writeScalar(fKS); |
| 905 buffer.writeScalar(fShininess); | 932 buffer.writeScalar(fShininess); |
| 906 } | 933 } |
| 907 | 934 |
| 908 bool SkSpecularLightingImageFilter::onFilterImage(Proxy*, | 935 bool SkSpecularLightingImageFilter::onFilterImage(Proxy*, |
| 909 const SkBitmap& src, | 936 const SkBitmap& src, |
| 910 const SkMatrix&, | 937 const SkMatrix&, |
| 911 SkBitmap* dst, | 938 SkBitmap* dst, |
| 912 SkIPoint*) { | 939 SkIPoint* offset) { |
| 913 if (src.config() != SkBitmap::kARGB_8888_Config) { | 940 if (src.config() != SkBitmap::kARGB_8888_Config) { |
| 914 return false; | 941 return false; |
| 915 } | 942 } |
| 916 SkAutoLockPixels alp(src); | 943 SkAutoLockPixels alp(src); |
| 917 if (!src.getPixels()) { | 944 if (!src.getPixels()) { |
| 918 return false; | 945 return false; |
| 919 } | 946 } |
| 920 if (src.width() < 2 || src.height() < 2) { | 947 |
| 948 SkIRect bounds; |
| 949 src.getBounds(&bounds); |
| 950 if (!this->applyCropRect(&bounds)) { |
| 921 return false; | 951 return false; |
| 922 } | 952 } |
| 923 dst->setConfig(src.config(), src.width(), src.height()); | 953 |
| 954 if (bounds.width() < 2 || bounds.height() < 2) { |
| 955 return false; |
| 956 } |
| 957 |
| 958 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
| 924 dst->allocPixels(); | 959 dst->allocPixels(); |
| 925 | 960 |
| 926 SpecularLightingType lightingType(fKS, fShininess); | 961 SpecularLightingType lightingType(fKS, fShininess); |
| 927 switch (light()->type()) { | 962 switch (light()->type()) { |
| 928 case SkLight::kDistant_LightType: | 963 case SkLight::kDistant_LightType: |
| 929 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, ligh
t(), src, dst, surfaceScale()); | 964 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, ligh
t(), src, dst, surfaceScale(), bounds); |
| 930 break; | 965 break; |
| 931 case SkLight::kPoint_LightType: | 966 case SkLight::kPoint_LightType: |
| 932 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, light(
), src, dst, surfaceScale()); | 967 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, light(
), src, dst, surfaceScale(), bounds); |
| 933 break; | 968 break; |
| 934 case SkLight::kSpot_LightType: | 969 case SkLight::kSpot_LightType: |
| 935 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, light()
, src, dst, surfaceScale()); | 970 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, light()
, src, dst, surfaceScale(), bounds); |
| 936 break; | 971 break; |
| 937 } | 972 } |
| 973 offset->fX += bounds.left(); |
| 974 offset->fY += bounds.top(); |
| 938 return true; | 975 return true; |
| 939 } | 976 } |
| 940 | 977 |
| 941 #if SK_SUPPORT_GPU | 978 #if SK_SUPPORT_GPU |
| 942 bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture) const { | 979 bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture*
texture, const SkIPoint& offset) const { |
| 943 if (effect) { | 980 if (effect) { |
| 944 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); | 981 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); |
| 945 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, ks()
, shininess()); | 982 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, offs
et, ks(), shininess()); |
| 946 } | 983 } |
| 947 return true; | 984 return true; |
| 948 } | 985 } |
| 949 #endif | 986 #endif |
| 950 | 987 |
| 951 /////////////////////////////////////////////////////////////////////////////// | 988 /////////////////////////////////////////////////////////////////////////////// |
| 952 | 989 |
| 953 #if SK_SUPPORT_GPU | 990 #if SK_SUPPORT_GPU |
| 954 | 991 |
| 955 namespace { | 992 namespace { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 | 1078 |
| 1042 private: | 1079 private: |
| 1043 typedef GrGLLightingEffect INHERITED; | 1080 typedef GrGLLightingEffect INHERITED; |
| 1044 | 1081 |
| 1045 UniformHandle fKSUni; | 1082 UniformHandle fKSUni; |
| 1046 UniformHandle fShininessUni; | 1083 UniformHandle fShininessUni; |
| 1047 }; | 1084 }; |
| 1048 | 1085 |
| 1049 /////////////////////////////////////////////////////////////////////////////// | 1086 /////////////////////////////////////////////////////////////////////////////// |
| 1050 | 1087 |
| 1051 GrLightingEffect::GrLightingEffect(GrTexture* texture, const SkLight* light, SkS
calar surfaceScale) | 1088 GrLightingEffect::GrLightingEffect(GrTexture* texture, |
| 1089 const SkLight* light, |
| 1090 SkScalar surfaceScale, |
| 1091 const SkIPoint& offset) |
| 1052 : INHERITED(texture, MakeDivByTextureWHMatrix(texture)) | 1092 : INHERITED(texture, MakeDivByTextureWHMatrix(texture)) |
| 1053 , fLight(light) | 1093 , fLight(light) |
| 1054 , fSurfaceScale(surfaceScale) { | 1094 , fSurfaceScale(surfaceScale) |
| 1095 , fOffset(offset) { |
| 1055 fLight->ref(); | 1096 fLight->ref(); |
| 1056 if (light->requiresFragmentPosition()) { | 1097 if (light->requiresFragmentPosition()) { |
| 1057 this->setWillReadFragmentPosition(); | 1098 this->setWillReadFragmentPosition(); |
| 1058 } | 1099 } |
| 1059 } | 1100 } |
| 1060 | 1101 |
| 1061 GrLightingEffect::~GrLightingEffect() { | 1102 GrLightingEffect::~GrLightingEffect() { |
| 1062 fLight->unref(); | 1103 fLight->unref(); |
| 1063 } | 1104 } |
| 1064 | 1105 |
| 1065 bool GrLightingEffect::onIsEqual(const GrEffect& sBase) const { | 1106 bool GrLightingEffect::onIsEqual(const GrEffect& sBase) const { |
| 1066 const GrLightingEffect& s = CastEffect<GrLightingEffect>(sBase); | 1107 const GrLightingEffect& s = CastEffect<GrLightingEffect>(sBase); |
| 1067 return this->texture(0) == s.texture(0) && | 1108 return this->texture(0) == s.texture(0) && |
| 1068 fLight->isEqual(*s.fLight) && | 1109 fLight->isEqual(*s.fLight) && |
| 1069 fSurfaceScale == s.fSurfaceScale; | 1110 fSurfaceScale == s.fSurfaceScale; |
| 1070 } | 1111 } |
| 1071 | 1112 |
| 1072 /////////////////////////////////////////////////////////////////////////////// | 1113 /////////////////////////////////////////////////////////////////////////////// |
| 1073 | 1114 |
| 1074 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, const SkLig
ht* light, SkScalar surfaceScale, SkScalar kd) | 1115 GrDiffuseLightingEffect::GrDiffuseLightingEffect(GrTexture* texture, |
| 1075 : INHERITED(texture, light, surfaceScale), fKD(kd) { | 1116 const SkLight* light, |
| 1117 SkScalar surfaceScale, |
| 1118 const SkIPoint& offset, |
| 1119 SkScalar kd) |
| 1120 : INHERITED(texture, light, surfaceScale, offset), fKD(kd) { |
| 1076 } | 1121 } |
| 1077 | 1122 |
| 1078 const GrBackendEffectFactory& GrDiffuseLightingEffect::getFactory() const { | 1123 const GrBackendEffectFactory& GrDiffuseLightingEffect::getFactory() const { |
| 1079 return GrTBackendEffectFactory<GrDiffuseLightingEffect>::getInstance(); | 1124 return GrTBackendEffectFactory<GrDiffuseLightingEffect>::getInstance(); |
| 1080 } | 1125 } |
| 1081 | 1126 |
| 1082 bool GrDiffuseLightingEffect::onIsEqual(const GrEffect& sBase) const { | 1127 bool GrDiffuseLightingEffect::onIsEqual(const GrEffect& sBase) const { |
| 1083 const GrDiffuseLightingEffect& s = CastEffect<GrDiffuseLightingEffect>(sBase
); | 1128 const GrDiffuseLightingEffect& s = CastEffect<GrDiffuseLightingEffect>(sBase
); |
| 1084 return INHERITED::onIsEqual(sBase) && | 1129 return INHERITED::onIsEqual(sBase) && |
| 1085 this->kd() == s.kd(); | 1130 this->kd() == s.kd(); |
| 1086 } | 1131 } |
| 1087 | 1132 |
| 1088 GR_DEFINE_EFFECT_TEST(GrDiffuseLightingEffect); | 1133 GR_DEFINE_EFFECT_TEST(GrDiffuseLightingEffect); |
| 1089 | 1134 |
| 1090 GrEffectRef* GrDiffuseLightingEffect::TestCreate(SkMWCRandom* random, | 1135 GrEffectRef* GrDiffuseLightingEffect::TestCreate(SkMWCRandom* random, |
| 1091 GrContext* context, | 1136 GrContext* context, |
| 1092 const GrDrawTargetCaps&, | 1137 const GrDrawTargetCaps&, |
| 1093 GrTexture* textures[]) { | 1138 GrTexture* textures[]) { |
| 1094 SkScalar surfaceScale = random->nextSScalar1(); | 1139 SkScalar surfaceScale = random->nextSScalar1(); |
| 1095 SkScalar kd = random->nextUScalar1(); | 1140 SkScalar kd = random->nextUScalar1(); |
| 1096 SkAutoTUnref<SkLight> light(create_random_light(random)); | 1141 SkAutoTUnref<SkLight> light(create_random_light(random)); |
| 1142 SkIPoint offset = SkIPoint::Make(random->nextS(), random->nextS()); |
| 1097 return GrDiffuseLightingEffect::Create(textures[GrEffectUnitTest::kAlphaText
ureIdx], | 1143 return GrDiffuseLightingEffect::Create(textures[GrEffectUnitTest::kAlphaText
ureIdx], |
| 1098 light, surfaceScale, kd); | 1144 light, surfaceScale, offset, kd); |
| 1099 } | 1145 } |
| 1100 | 1146 |
| 1101 | 1147 |
| 1102 /////////////////////////////////////////////////////////////////////////////// | 1148 /////////////////////////////////////////////////////////////////////////////// |
| 1103 | 1149 |
| 1104 GrGLLightingEffect::GrGLLightingEffect(const GrBackendEffectFactory& factory, | 1150 GrGLLightingEffect::GrGLLightingEffect(const GrBackendEffectFactory& factory, |
| 1105 const GrDrawEffect& drawEffect) | 1151 const GrDrawEffect& drawEffect) |
| 1106 : INHERITED(factory) | 1152 : INHERITED(factory) |
| 1107 , fImageIncrementUni(kInvalidUniformHandle) | 1153 , fImageIncrementUni(kInvalidUniformHandle) |
| 1108 , fSurfaceScaleUni(kInvalidUniformHandle) | 1154 , fSurfaceScaleUni(kInvalidUniformHandle) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 return key | matrixKey; | 1274 return key | matrixKey; |
| 1229 } | 1275 } |
| 1230 | 1276 |
| 1231 void GrGLLightingEffect::setData(const GrGLUniformManager& uman, | 1277 void GrGLLightingEffect::setData(const GrGLUniformManager& uman, |
| 1232 const GrDrawEffect& drawEffect) { | 1278 const GrDrawEffect& drawEffect) { |
| 1233 const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>()
; | 1279 const GrLightingEffect& lighting = drawEffect.castEffect<GrLightingEffect>()
; |
| 1234 GrTexture* texture = lighting.texture(0); | 1280 GrTexture* texture = lighting.texture(0); |
| 1235 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; | 1281 float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; |
| 1236 uman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->hei
ght()); | 1282 uman.set2f(fImageIncrementUni, 1.0f / texture->width(), ySign / texture->hei
ght()); |
| 1237 uman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); | 1283 uman.set1f(fSurfaceScaleUni, lighting.surfaceScale()); |
| 1238 fLight->setData(uman, lighting.light()); | 1284 fLight->setData(uman, lighting.light(), lighting.offset()); |
| 1239 fEffectMatrix.setData(uman, | 1285 fEffectMatrix.setData(uman, |
| 1240 lighting.getMatrix(), | 1286 lighting.getMatrix(), |
| 1241 drawEffect, | 1287 drawEffect, |
| 1242 lighting.texture(0)); | 1288 lighting.texture(0)); |
| 1243 } | 1289 } |
| 1244 | 1290 |
| 1245 /////////////////////////////////////////////////////////////////////////////// | 1291 /////////////////////////////////////////////////////////////////////////////// |
| 1246 | 1292 |
| 1247 /////////////////////////////////////////////////////////////////////////////// | 1293 /////////////////////////////////////////////////////////////////////////////// |
| 1248 | 1294 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1278 | 1324 |
| 1279 void GrGLDiffuseLightingEffect::setData(const GrGLUniformManager& uman, | 1325 void GrGLDiffuseLightingEffect::setData(const GrGLUniformManager& uman, |
| 1280 const GrDrawEffect& drawEffect) { | 1326 const GrDrawEffect& drawEffect) { |
| 1281 INHERITED::setData(uman, drawEffect); | 1327 INHERITED::setData(uman, drawEffect); |
| 1282 const GrDiffuseLightingEffect& diffuse = drawEffect.castEffect<GrDiffuseLigh
tingEffect>(); | 1328 const GrDiffuseLightingEffect& diffuse = drawEffect.castEffect<GrDiffuseLigh
tingEffect>(); |
| 1283 uman.set1f(fKDUni, diffuse.kd()); | 1329 uman.set1f(fKDUni, diffuse.kd()); |
| 1284 } | 1330 } |
| 1285 | 1331 |
| 1286 /////////////////////////////////////////////////////////////////////////////// | 1332 /////////////////////////////////////////////////////////////////////////////// |
| 1287 | 1333 |
| 1288 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, const SkL
ight* light, SkScalar surfaceScale, SkScalar ks, SkScalar shininess) | 1334 GrSpecularLightingEffect::GrSpecularLightingEffect(GrTexture* texture, |
| 1289 : INHERITED(texture, light, surfaceScale), | 1335 const SkLight* light, |
| 1336 SkScalar surfaceScale, |
| 1337 const SkIPoint& offset, |
| 1338 SkScalar ks, |
| 1339 SkScalar shininess) |
| 1340 : INHERITED(texture, light, surfaceScale, offset), |
| 1290 fKS(ks), | 1341 fKS(ks), |
| 1291 fShininess(shininess) { | 1342 fShininess(shininess) { |
| 1292 } | 1343 } |
| 1293 | 1344 |
| 1294 const GrBackendEffectFactory& GrSpecularLightingEffect::getFactory() const { | 1345 const GrBackendEffectFactory& GrSpecularLightingEffect::getFactory() const { |
| 1295 return GrTBackendEffectFactory<GrSpecularLightingEffect>::getInstance(); | 1346 return GrTBackendEffectFactory<GrSpecularLightingEffect>::getInstance(); |
| 1296 } | 1347 } |
| 1297 | 1348 |
| 1298 bool GrSpecularLightingEffect::onIsEqual(const GrEffect& sBase) const { | 1349 bool GrSpecularLightingEffect::onIsEqual(const GrEffect& sBase) const { |
| 1299 const GrSpecularLightingEffect& s = CastEffect<GrSpecularLightingEffect>(sBa
se); | 1350 const GrSpecularLightingEffect& s = CastEffect<GrSpecularLightingEffect>(sBa
se); |
| 1300 return INHERITED::onIsEqual(sBase) && | 1351 return INHERITED::onIsEqual(sBase) && |
| 1301 this->ks() == s.ks() && | 1352 this->ks() == s.ks() && |
| 1302 this->shininess() == s.shininess(); | 1353 this->shininess() == s.shininess(); |
| 1303 } | 1354 } |
| 1304 | 1355 |
| 1305 GR_DEFINE_EFFECT_TEST(GrSpecularLightingEffect); | 1356 GR_DEFINE_EFFECT_TEST(GrSpecularLightingEffect); |
| 1306 | 1357 |
| 1307 GrEffectRef* GrSpecularLightingEffect::TestCreate(SkMWCRandom* random, | 1358 GrEffectRef* GrSpecularLightingEffect::TestCreate(SkMWCRandom* random, |
| 1308 GrContext* context, | 1359 GrContext* context, |
| 1309 const GrDrawTargetCaps&, | 1360 const GrDrawTargetCaps&, |
| 1310 GrTexture* textures[]) { | 1361 GrTexture* textures[]) { |
| 1311 SkScalar surfaceScale = random->nextSScalar1(); | 1362 SkScalar surfaceScale = random->nextSScalar1(); |
| 1312 SkScalar ks = random->nextUScalar1(); | 1363 SkScalar ks = random->nextUScalar1(); |
| 1313 SkScalar shininess = random->nextUScalar1(); | 1364 SkScalar shininess = random->nextUScalar1(); |
| 1314 SkAutoTUnref<SkLight> light(create_random_light(random)); | 1365 SkAutoTUnref<SkLight> light(create_random_light(random)); |
| 1366 SkIPoint offset = SkIPoint::Make(random->nextS(), random->nextS()); |
| 1315 return GrSpecularLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTex
tureIdx], | 1367 return GrSpecularLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTex
tureIdx], |
| 1316 light, surfaceScale, ks, shininess); | 1368 light, surfaceScale, offset, ks, shi
niness); |
| 1317 } | 1369 } |
| 1318 | 1370 |
| 1319 /////////////////////////////////////////////////////////////////////////////// | 1371 /////////////////////////////////////////////////////////////////////////////// |
| 1320 | 1372 |
| 1321 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendEffectFact
ory& factory, | 1373 GrGLSpecularLightingEffect::GrGLSpecularLightingEffect(const GrBackendEffectFact
ory& factory, |
| 1322 const GrDrawEffect& drawE
ffect) | 1374 const GrDrawEffect& drawE
ffect) |
| 1323 : GrGLLightingEffect(factory, drawEffect) | 1375 : GrGLLightingEffect(factory, drawEffect) |
| 1324 , fKSUni(kInvalidUniformHandle) | 1376 , fKSUni(kInvalidUniformHandle) |
| 1325 , fShininessUni(kInvalidUniformHandle) { | 1377 , fShininessUni(kInvalidUniformHandle) { |
| 1326 } | 1378 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 void GrGLLight::emitLightColorUniform(GrGLShaderBuilder* builder) { | 1417 void GrGLLight::emitLightColorUniform(GrGLShaderBuilder* builder) { |
| 1366 fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 1418 fColorUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
| 1367 kVec3f_GrSLType, "LightColor"); | 1419 kVec3f_GrSLType, "LightColor"); |
| 1368 } | 1420 } |
| 1369 | 1421 |
| 1370 void GrGLLight::emitLightColor(GrGLShaderBuilder* builder, | 1422 void GrGLLight::emitLightColor(GrGLShaderBuilder* builder, |
| 1371 const char *surfaceToLight) { | 1423 const char *surfaceToLight) { |
| 1372 builder->fsCodeAppend(builder->getUniformCStr(this->lightColorUni())); | 1424 builder->fsCodeAppend(builder->getUniformCStr(this->lightColorUni())); |
| 1373 } | 1425 } |
| 1374 | 1426 |
| 1375 void GrGLLight::setData(const GrGLUniformManager& uman, const SkLight* light) co
nst { | 1427 void GrGLLight::setData(const GrGLUniformManager& uman, |
| 1428 const SkLight* light, |
| 1429 const SkIPoint&) const { |
| 1376 setUniformPoint3(uman, fColorUni, light->color() * SkScalarInvert(SkIntToSca
lar(255))); | 1430 setUniformPoint3(uman, fColorUni, light->color() * SkScalarInvert(SkIntToSca
lar(255))); |
| 1377 } | 1431 } |
| 1378 | 1432 |
| 1379 /////////////////////////////////////////////////////////////////////////////// | 1433 /////////////////////////////////////////////////////////////////////////////// |
| 1380 | 1434 |
| 1381 void GrGLDistantLight::setData(const GrGLUniformManager& uman, const SkLight* li
ght) const { | 1435 void GrGLDistantLight::setData(const GrGLUniformManager& uman, |
| 1382 INHERITED::setData(uman, light); | 1436 const SkLight* light, |
| 1437 const SkIPoint& offset) const { |
| 1438 INHERITED::setData(uman, light, offset); |
| 1383 SkASSERT(light->type() == SkLight::kDistant_LightType); | 1439 SkASSERT(light->type() == SkLight::kDistant_LightType); |
| 1384 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); | 1440 const SkDistantLight* distantLight = static_cast<const SkDistantLight*>(ligh
t); |
| 1385 setUniformNormal3(uman, fDirectionUni, distantLight->direction()); | 1441 setUniformNormal3(uman, fDirectionUni, distantLight->direction()); |
| 1386 } | 1442 } |
| 1387 | 1443 |
| 1388 void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char
* z) { | 1444 void GrGLDistantLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char
* z) { |
| 1389 const char* dir; | 1445 const char* dir; |
| 1390 fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType, | 1446 fDirectionUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType, |
| 1391 "LightDirection", &dir); | 1447 "LightDirection", &dir); |
| 1392 builder->fsCodeAppend(dir); | 1448 builder->fsCodeAppend(dir); |
| 1393 } | 1449 } |
| 1394 | 1450 |
| 1395 /////////////////////////////////////////////////////////////////////////////// | 1451 /////////////////////////////////////////////////////////////////////////////// |
| 1396 | 1452 |
| 1397 void GrGLPointLight::setData(const GrGLUniformManager& uman, const SkLight* ligh
t) const { | 1453 void GrGLPointLight::setData(const GrGLUniformManager& uman, |
| 1398 INHERITED::setData(uman, light); | 1454 const SkLight* light, |
| 1455 const SkIPoint& offset) const { |
| 1456 INHERITED::setData(uman, light, offset); |
| 1399 SkASSERT(light->type() == SkLight::kPoint_LightType); | 1457 SkASSERT(light->type() == SkLight::kPoint_LightType); |
| 1400 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); | 1458 const SkPointLight* pointLight = static_cast<const SkPointLight*>(light); |
| 1401 setUniformPoint3(uman, fLocationUni, pointLight->location()); | 1459 SkPoint3 location = pointLight->location(); |
| 1460 location.fX -= offset.fX; |
| 1461 location.fY -= offset.fY; |
| 1462 setUniformPoint3(uman, fLocationUni, location); |
| 1402 } | 1463 } |
| 1403 | 1464 |
| 1404 void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char*
z) { | 1465 void GrGLPointLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char*
z) { |
| 1405 const char* loc; | 1466 const char* loc; |
| 1406 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType, | 1467 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType,
kVec3f_GrSLType, |
| 1407 "LightLocation", &loc); | 1468 "LightLocation", &loc); |
| 1408 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->frag
mentPosition(), z); | 1469 builder->fsCodeAppendf("normalize(%s - vec3(%s.xy, %s))", loc, builder->frag
mentPosition(), z); |
| 1409 } | 1470 } |
| 1410 | 1471 |
| 1411 /////////////////////////////////////////////////////////////////////////////// | 1472 /////////////////////////////////////////////////////////////////////////////// |
| 1412 | 1473 |
| 1413 void GrGLSpotLight::setData(const GrGLUniformManager& uman, const SkLight* light
) const { | 1474 void GrGLSpotLight::setData(const GrGLUniformManager& uman, |
| 1414 INHERITED::setData(uman, light); | 1475 const SkLight* light, |
| 1476 const SkIPoint& offset) const { |
| 1477 INHERITED::setData(uman, light, offset); |
| 1415 SkASSERT(light->type() == SkLight::kSpot_LightType); | 1478 SkASSERT(light->type() == SkLight::kSpot_LightType); |
| 1416 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); | 1479 const SkSpotLight* spotLight = static_cast<const SkSpotLight *>(light); |
| 1417 setUniformPoint3(uman, fLocationUni, spotLight->location()); | 1480 SkPoint3 location = spotLight->location(); |
| 1481 location.fX -= offset.fX; |
| 1482 location.fY -= offset.fY; |
| 1483 setUniformPoint3(uman, fLocationUni, location); |
| 1418 uman.set1f(fExponentUni, spotLight->specularExponent()); | 1484 uman.set1f(fExponentUni, spotLight->specularExponent()); |
| 1419 uman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); | 1485 uman.set1f(fCosInnerConeAngleUni, spotLight->cosInnerConeAngle()); |
| 1420 uman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); | 1486 uman.set1f(fCosOuterConeAngleUni, spotLight->cosOuterConeAngle()); |
| 1421 uman.set1f(fConeScaleUni, spotLight->coneScale()); | 1487 uman.set1f(fConeScaleUni, spotLight->coneScale()); |
| 1422 setUniformNormal3(uman, fSUni, spotLight->s()); | 1488 setUniformNormal3(uman, fSUni, spotLight->s()); |
| 1423 } | 1489 } |
| 1424 | 1490 |
| 1425 void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z
) { | 1491 void GrGLSpotLight::emitSurfaceToLight(GrGLShaderBuilder* builder, const char* z
) { |
| 1426 const char* location; | 1492 const char* location; |
| 1427 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 1493 fLocationUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 | 1544 |
| 1479 #endif | 1545 #endif |
| 1480 | 1546 |
| 1481 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1547 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
| 1482 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1548 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
| 1483 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1549 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
| 1484 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) | 1550 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) |
| 1485 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) | 1551 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) |
| 1486 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) | 1552 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) |
| 1487 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1553 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
| OLD | NEW |