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" |
11 #include "SkReadBuffer.h" | 11 #include "SkReadBuffer.h" |
12 #include "SkWriteBuffer.h" | 12 #include "SkWriteBuffer.h" |
13 #include "SkReadBuffer.h" | 13 #include "SkReadBuffer.h" |
14 #include "SkWriteBuffer.h" | 14 #include "SkWriteBuffer.h" |
15 #include "SkTypes.h" | 15 #include "SkTypes.h" |
16 | 16 |
17 #if SK_SUPPORT_GPU | 17 #if SK_SUPPORT_GPU |
| 18 #include "GrDrawContext.h" |
18 #include "GrFragmentProcessor.h" | 19 #include "GrFragmentProcessor.h" |
19 #include "GrInvariantOutput.h" | 20 #include "GrInvariantOutput.h" |
20 #include "effects/GrSingleTextureEffect.h" | 21 #include "effects/GrSingleTextureEffect.h" |
21 #include "gl/GrGLProcessor.h" | 22 #include "gl/GrGLProcessor.h" |
22 #include "gl/builders/GrGLProgramBuilder.h" | 23 #include "gl/builders/GrGLProgramBuilder.h" |
23 | 24 |
24 class GrGLDiffuseLightingEffect; | 25 class GrGLDiffuseLightingEffect; |
25 class GrGLSpecularLightingEffect; | 26 class GrGLSpecularLightingEffect; |
26 | 27 |
27 // For brevity | 28 // For brevity |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 bool canFilterImageGPU() const override { return true; } | 304 bool canFilterImageGPU() const override { return true; } |
304 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, | 305 bool filterImageGPU(Proxy*, const SkBitmap& src, const Context&, |
305 SkBitmap* result, SkIPoint* offset) const override; | 306 SkBitmap* result, SkIPoint* offset) const override; |
306 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, | 307 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, |
307 const SkMatrix&, | 308 const SkMatrix&, |
308 const SkIRect& bounds, | 309 const SkIRect& bounds, |
309 BoundaryMode boundaryMode)
const = 0; | 310 BoundaryMode boundaryMode)
const = 0; |
310 #endif | 311 #endif |
311 private: | 312 private: |
312 #if SK_SUPPORT_GPU | 313 #if SK_SUPPORT_GPU |
313 void drawRect(GrContext* context, | 314 void drawRect(GrDrawContext* drawContext, |
314 GrTexture* src, | 315 GrTexture* src, |
315 GrTexture* dst, | 316 GrTexture* dst, |
316 const SkMatrix& matrix, | 317 const SkMatrix& matrix, |
317 const GrClip& clip, | 318 const GrClip& clip, |
318 const SkRect& dstRect, | 319 const SkRect& dstRect, |
319 BoundaryMode boundaryMode, | 320 BoundaryMode boundaryMode, |
320 const SkIRect& bounds) const; | 321 const SkIRect& bounds) const; |
321 #endif | 322 #endif |
322 typedef SkLightingImageFilter INHERITED; | 323 typedef SkLightingImageFilter INHERITED; |
323 }; | 324 }; |
324 | 325 |
325 #if SK_SUPPORT_GPU | 326 #if SK_SUPPORT_GPU |
326 void SkLightingImageFilterInternal::drawRect(GrContext* context, | 327 void SkLightingImageFilterInternal::drawRect(GrDrawContext* drawContext, |
327 GrTexture* src, | 328 GrTexture* src, |
328 GrTexture* dst, | 329 GrTexture* dst, |
329 const SkMatrix& matrix, | 330 const SkMatrix& matrix, |
330 const GrClip& clip, | 331 const GrClip& clip, |
331 const SkRect& dstRect, | 332 const SkRect& dstRect, |
332 BoundaryMode boundaryMode, | 333 BoundaryMode boundaryMode, |
333 const SkIRect& bounds) const { | 334 const SkIRect& bounds) const { |
334 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); | 335 SkRect srcRect = dstRect.makeOffset(SkIntToScalar(bounds.x()), SkIntToScalar
(bounds.y())); |
335 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, bo
undaryMode); | 336 GrFragmentProcessor* fp = this->getFragmentProcessor(src, matrix, bounds, bo
undaryMode); |
336 GrPaint paint; | 337 GrPaint paint; |
337 paint.addColorProcessor(fp)->unref(); | 338 paint.addColorProcessor(fp)->unref(); |
338 context->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatrix::I
(), | 339 drawContext->drawNonAARectToRect(dst->asRenderTarget(), clip, paint, SkMatri
x::I(), |
339 dstRect, srcRect); | 340 dstRect, srcRect); |
340 } | 341 } |
341 | 342 |
342 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, | 343 bool SkLightingImageFilterInternal::filterImageGPU(Proxy* proxy, |
343 const SkBitmap& src, | 344 const SkBitmap& src, |
344 const Context& ctx, | 345 const Context& ctx, |
345 SkBitmap* result, | 346 SkBitmap* result, |
346 SkIPoint* offset) const { | 347 SkIPoint* offset) const { |
347 SkBitmap input = src; | 348 SkBitmap input = src; |
348 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 349 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
349 if (this->getInput(0) && | 350 if (this->getInput(0) && |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 bounds.offset(-srcOffset); | 382 bounds.offset(-srcOffset); |
382 SkRect topLeft = SkRect::MakeXYWH(0, 0, 1, 1); | 383 SkRect topLeft = SkRect::MakeXYWH(0, 0, 1, 1); |
383 SkRect top = SkRect::MakeXYWH(1, 0, dstRect.width() - 2, 1); | 384 SkRect top = SkRect::MakeXYWH(1, 0, dstRect.width() - 2, 1); |
384 SkRect topRight = SkRect::MakeXYWH(dstRect.width() - 1, 0, 1, 1); | 385 SkRect topRight = SkRect::MakeXYWH(dstRect.width() - 1, 0, 1, 1); |
385 SkRect left = SkRect::MakeXYWH(0, 1, 1, dstRect.height() - 2); | 386 SkRect left = SkRect::MakeXYWH(0, 1, 1, dstRect.height() - 2); |
386 SkRect interior = dstRect.makeInset(1, 1); | 387 SkRect interior = dstRect.makeInset(1, 1); |
387 SkRect right = SkRect::MakeXYWH(dstRect.width() - 1, 1, 1, dstRect.height()
- 2); | 388 SkRect right = SkRect::MakeXYWH(dstRect.width() - 1, 1, 1, dstRect.height()
- 2); |
388 SkRect bottomLeft = SkRect::MakeXYWH(0, dstRect.height() - 1, 1, 1); | 389 SkRect bottomLeft = SkRect::MakeXYWH(0, dstRect.height() - 1, 1, 1); |
389 SkRect bottom = SkRect::MakeXYWH(1, dstRect.height() - 1, dstRect.width() -
2, 1); | 390 SkRect bottom = SkRect::MakeXYWH(1, dstRect.height() - 1, dstRect.width() -
2, 1); |
390 SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height()
- 1, 1, 1); | 391 SkRect bottomRight = SkRect::MakeXYWH(dstRect.width() - 1, dstRect.height()
- 1, 1, 1); |
391 this->drawRect(context, srcTexture, dst, matrix, clip, topLeft, kTopLeft_Bou
ndaryMode, bounds); | 392 |
392 this->drawRect(context, srcTexture, dst, matrix, clip, top, kTop_BoundaryMod
e, bounds); | 393 GrDrawContext* drawContext = context->drawContext(); |
393 this->drawRect(context, srcTexture, dst, matrix, clip, topRight, kTopRight_B
oundaryMode, | 394 if (!drawContext) { |
| 395 return false; |
| 396 } |
| 397 |
| 398 this->drawRect(drawContext, srcTexture, dst, matrix, clip, topLeft, kTopLeft
_BoundaryMode, |
394 bounds); | 399 bounds); |
395 this->drawRect(context, srcTexture, dst, matrix, clip, left, kLeft_BoundaryM
ode, bounds); | 400 this->drawRect(drawContext, srcTexture, dst, matrix, clip, top, kTop_Boundar
yMode, bounds); |
396 this->drawRect(context, srcTexture, dst, matrix, clip, interior, kInterior_B
oundaryMode, | 401 this->drawRect(drawContext, srcTexture, dst, matrix, clip, topRight, kTopRig
ht_BoundaryMode, |
397 bounds); | 402 bounds); |
398 this->drawRect(context, srcTexture, dst, matrix, clip, right, kRight_Boundar
yMode, bounds); | 403 this->drawRect(drawContext, srcTexture, dst, matrix, clip, left, kLeft_Bound
aryMode, bounds); |
399 this->drawRect(context, srcTexture, dst, matrix, clip, bottomLeft, kBottomLe
ft_BoundaryMode, | 404 this->drawRect(drawContext, srcTexture, dst, matrix, clip, interior, kInteri
or_BoundaryMode, |
400 bounds); | 405 bounds); |
401 this->drawRect(context, srcTexture, dst, matrix, clip, bottom, kBottom_Bound
aryMode, bounds); | 406 this->drawRect(drawContext, srcTexture, dst, matrix, clip, right, kRight_Bou
ndaryMode, bounds); |
402 this->drawRect(context, srcTexture, dst, matrix, clip, bottomRight, kBottomR
ight_BoundaryMode, | 407 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottomLeft, kBott
omLeft_BoundaryMode, |
403 bounds); | 408 bounds); |
| 409 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottom, kBottom_B
oundaryMode, bounds); |
| 410 this->drawRect(drawContext, srcTexture, dst, matrix, clip, bottomRight, |
| 411 kBottomRight_BoundaryMode, bounds); |
404 WrapTexture(dst, bounds.width(), bounds.height(), result); | 412 WrapTexture(dst, bounds.width(), bounds.height(), result); |
405 return true; | 413 return true; |
406 } | 414 } |
407 #endif | 415 #endif |
408 | 416 |
409 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { | 417 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { |
410 public: | 418 public: |
411 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar
kd, SkImageFilter*, | 419 static SkImageFilter* Create(SkLight* light, SkScalar surfaceScale, SkScalar
kd, SkImageFilter*, |
412 const CropRect*); | 420 const CropRect*); |
413 | 421 |
(...skipping 1572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1986 | 1994 |
1987 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1995 fsBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1988 } | 1996 } |
1989 | 1997 |
1990 #endif | 1998 #endif |
1991 | 1999 |
1992 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2000 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1993 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2001 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1994 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2002 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1995 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2003 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |