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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 kRight_BoundaryMode, | 340 kRight_BoundaryMode, |
341 kBottomLeft_BoundaryMode, | 341 kBottomLeft_BoundaryMode, |
342 kBottom_BoundaryMode, | 342 kBottom_BoundaryMode, |
343 kBottomRight_BoundaryMode, | 343 kBottomRight_BoundaryMode, |
344 | 344 |
345 kBoundaryModeCount, | 345 kBoundaryModeCount, |
346 }; | 346 }; |
347 | 347 |
348 class SkLightingImageFilterInternal : public SkLightingImageFilter { | 348 class SkLightingImageFilterInternal : public SkLightingImageFilter { |
349 protected: | 349 protected: |
350 SkLightingImageFilterInternal(SkImageFilterLight* light, | 350 SkLightingImageFilterInternal(sk_sp<SkImageFilterLight> light, |
351 SkScalar surfaceScale, | 351 SkScalar surfaceScale, |
352 SkImageFilter* input, | 352 sk_sp<SkImageFilter> input, |
353 const CropRect* cropRect) | 353 const CropRect* cropRect) |
354 : INHERITED(light, surfaceScale, input, cropRect) {} | 354 : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect)
{ |
| 355 } |
355 | 356 |
356 #if SK_SUPPORT_GPU | 357 #if SK_SUPPORT_GPU |
357 bool canFilterImageGPU() const override { return true; } | 358 bool canFilterImageGPU() const override { return true; } |
358 bool filterImageGPUDeprecated(Proxy*, const SkBitmap& src, const Context&, | 359 bool filterImageGPUDeprecated(Proxy*, const SkBitmap& src, const Context&, |
359 SkBitmap* result, SkIPoint* offset) const over
ride; | 360 SkBitmap* result, SkIPoint* offset) const over
ride; |
360 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, | 361 virtual GrFragmentProcessor* getFragmentProcessor(GrTexture*, |
361 const SkMatrix&, | 362 const SkMatrix&, |
362 const SkIRect* srcBounds, | 363 const SkIRect* srcBounds, |
363 BoundaryMode boundaryMode)
const = 0; | 364 BoundaryMode boundaryMode)
const = 0; |
364 #endif | 365 #endif |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 pSrcBounds, bounds); | 470 pSrcBounds, bounds); |
470 this->drawRect(drawContext, srcTexture, matrix, clip, bottomRight, | 471 this->drawRect(drawContext, srcTexture, matrix, clip, bottomRight, |
471 kBottomRight_BoundaryMode, pSrcBounds, bounds); | 472 kBottomRight_BoundaryMode, pSrcBounds, bounds); |
472 GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, result); | 473 GrWrapTextureInBitmap(dst, bounds.width(), bounds.height(), false, result); |
473 return true; | 474 return true; |
474 } | 475 } |
475 #endif | 476 #endif |
476 | 477 |
477 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { | 478 class SkDiffuseLightingImageFilter : public SkLightingImageFilterInternal { |
478 public: | 479 public: |
479 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, | 480 static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilterLight> light, |
480 SkScalar kd, SkImageFilter*, | 481 SkScalar surfaceScale, |
481 const CropRect*); | 482 SkScalar kd, |
| 483 sk_sp<SkImageFilter>, |
| 484 const CropRect*); |
482 | 485 |
483 SK_TO_STRING_OVERRIDE() | 486 SK_TO_STRING_OVERRIDE() |
484 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 487 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
485 SkScalar kd() const { return fKD; } | 488 SkScalar kd() const { return fKD; } |
486 | 489 |
487 protected: | 490 protected: |
488 SkDiffuseLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceScal
e, | 491 SkDiffuseLightingImageFilter(sk_sp<SkImageFilterLight> light, SkScalar surfa
ceScale, |
489 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); | 492 SkScalar kd, |
| 493 sk_sp<SkImageFilter> input, const CropRect* cro
pRect); |
490 void flatten(SkWriteBuffer& buffer) const override; | 494 void flatten(SkWriteBuffer& buffer) const override; |
491 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, | 495 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, |
492 SkBitmap* result, SkIPoint* offset) const overr
ide; | 496 SkBitmap* result, SkIPoint* offset) const overr
ide; |
493 #if SK_SUPPORT_GPU | 497 #if SK_SUPPORT_GPU |
494 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, | 498 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, |
495 BoundaryMode) const override; | 499 BoundaryMode) const override; |
496 #endif | 500 #endif |
497 | 501 |
498 private: | 502 private: |
499 friend class SkLightingImageFilter; | 503 friend class SkLightingImageFilter; |
500 typedef SkLightingImageFilterInternal INHERITED; | 504 typedef SkLightingImageFilterInternal INHERITED; |
501 SkScalar fKD; | 505 SkScalar fKD; |
502 }; | 506 }; |
503 | 507 |
504 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { | 508 class SkSpecularLightingImageFilter : public SkLightingImageFilterInternal { |
505 public: | 509 public: |
506 static SkImageFilter* Create(SkImageFilterLight* light, SkScalar surfaceScal
e, | 510 static sk_sp<SkImageFilter> Make(sk_sp<SkImageFilterLight> light, |
507 SkScalar ks, SkScalar shininess, SkImageFilter*
, const CropRect*); | 511 SkScalar surfaceScale, |
| 512 SkScalar ks, SkScalar shininess, |
| 513 sk_sp<SkImageFilter>, const CropRect*); |
508 | 514 |
509 SK_TO_STRING_OVERRIDE() | 515 SK_TO_STRING_OVERRIDE() |
510 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 516 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
511 | 517 |
512 SkScalar ks() const { return fKS; } | 518 SkScalar ks() const { return fKS; } |
513 SkScalar shininess() const { return fShininess; } | 519 SkScalar shininess() const { return fShininess; } |
514 | 520 |
515 protected: | 521 protected: |
516 SkSpecularLightingImageFilter(SkImageFilterLight* light, SkScalar surfaceSca
le, SkScalar ks, | 522 SkSpecularLightingImageFilter(sk_sp<SkImageFilterLight> light, |
517 SkScalar shininess, SkImageFilter* input, cons
t CropRect*); | 523 SkScalar surfaceScale, SkScalar ks, |
| 524 SkScalar shininess, |
| 525 sk_sp<SkImageFilter> input, const CropRect*); |
518 void flatten(SkWriteBuffer& buffer) const override; | 526 void flatten(SkWriteBuffer& buffer) const override; |
519 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, | 527 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, |
520 SkBitmap* result, SkIPoint* offset) const overr
ide; | 528 SkBitmap* result, SkIPoint* offset) const overr
ide; |
521 #if SK_SUPPORT_GPU | 529 #if SK_SUPPORT_GPU |
522 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, | 530 GrFragmentProcessor* getFragmentProcessor(GrTexture*, const SkMatrix&, const
SkIRect* bounds, |
523 BoundaryMode) const override; | 531 BoundaryMode) const override; |
524 #endif | 532 #endif |
525 | 533 |
526 private: | 534 private: |
527 SkScalar fKS; | 535 SkScalar fKS; |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1087 case SkImageFilterLight::kSpot_LightType: | 1095 case SkImageFilterLight::kSpot_LightType: |
1088 return new SkSpotLight(buffer); | 1096 return new SkSpotLight(buffer); |
1089 default: | 1097 default: |
1090 SkDEBUGFAIL("Unknown LightType."); | 1098 SkDEBUGFAIL("Unknown LightType."); |
1091 buffer.validate(false); | 1099 buffer.validate(false); |
1092 return nullptr; | 1100 return nullptr; |
1093 } | 1101 } |
1094 } | 1102 } |
1095 /////////////////////////////////////////////////////////////////////////////// | 1103 /////////////////////////////////////////////////////////////////////////////// |
1096 | 1104 |
1097 SkLightingImageFilter::SkLightingImageFilter(SkImageFilterLight* light, SkScalar
surfaceScale, | 1105 SkLightingImageFilter::SkLightingImageFilter(sk_sp<SkImageFilterLight> light, |
1098 SkImageFilter* input, const CropRec
t* cropRect) | 1106 SkScalar surfaceScale, |
1099 : INHERITED(1, &input, cropRect) | 1107 sk_sp<SkImageFilter> input, const C
ropRect* cropRect) |
1100 , fLight(SkRef(light)) | 1108 : INHERITED(&input, 1, cropRect) |
1101 , fSurfaceScale(surfaceScale / 255) | 1109 , fLight(std::move(light)) |
1102 {} | 1110 , fSurfaceScale(surfaceScale / 255) { |
1103 | |
1104 SkImageFilter* SkLightingImageFilter::CreateDistantLitDiffuse(const SkPoint3& di
rection, | |
1105 SkColor lightColor
, | |
1106 SkScalar surfaceSc
ale, | |
1107 SkScalar kd, | |
1108 SkImageFilter* inp
ut, | |
1109 const CropRect* cr
opRect) { | |
1110 SkAutoTUnref<SkImageFilterLight> light(new SkDistantLight(direction, lightCo
lor)); | |
1111 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); | |
1112 } | 1111 } |
1113 | 1112 |
1114 SkImageFilter* SkLightingImageFilter::CreatePointLitDiffuse(const SkPoint3& loca
tion, | 1113 sk_sp<SkImageFilter> SkLightingImageFilter::MakeDistantLitDiffuse(const SkPoint3
& direction, |
1115 SkColor lightColor, | 1114 SkColor lightC
olor, |
1116 SkScalar surfaceScal
e, | 1115 SkScalar surfa
ceScale, |
1117 SkScalar kd, | 1116 SkScalar kd, |
1118 SkImageFilter* input
, | 1117 sk_sp<SkImageF
ilter> input, |
1119 const CropRect* crop
Rect) { | 1118 const CropRect
* cropRect) { |
1120 SkAutoTUnref<SkImageFilterLight> light(new SkPointLight(location, lightColor
)); | 1119 sk_sp<SkImageFilterLight> light(new SkDistantLight(direction, lightColor)); |
1121 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); | 1120 return SkDiffuseLightingImageFilter::Make(std::move(light), surfaceScale, kd
, |
| 1121 std::move(input), cropRect); |
1122 } | 1122 } |
1123 | 1123 |
1124 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse(const SkPoint3& locat
ion, | 1124 sk_sp<SkImageFilter> SkLightingImageFilter::MakePointLitDiffuse(const SkPoint3&
location, |
1125 const SkPoint3& targe
t, | 1125 SkColor lightCol
or, |
1126 SkScalar specularExpo
nent, | 1126 SkScalar surface
Scale, |
1127 SkScalar cutoffAngle, | 1127 SkScalar kd, |
1128 SkColor lightColor, | 1128 sk_sp<SkImageFil
ter> input, |
1129 SkScalar surfaceScale
, | 1129 const CropRect*
cropRect) { |
1130 SkScalar kd, | 1130 sk_sp<SkImageFilterLight> light(new SkPointLight(location, lightColor)); |
1131 SkImageFilter* input, | 1131 return SkDiffuseLightingImageFilter::Make(std::move(light), surfaceScale, kd
, |
1132 const CropRect* cropR
ect) { | 1132 std::move(input), cropRect); |
1133 SkAutoTUnref<SkImageFilterLight> light( | |
1134 new SkSpotLight(location, target, specularExponent, cutoffAngle, lig
htColor)); | |
1135 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input,
cropRect); | |
1136 } | 1133 } |
1137 | 1134 |
1138 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular(const SkPoint3& d
irection, | 1135 sk_sp<SkImageFilter> SkLightingImageFilter::MakeSpotLitDiffuse(const SkPoint3& l
ocation, |
| 1136 const SkPoint3& t
arget, |
| 1137 SkScalar specular
Exponent, |
| 1138 SkScalar cutoffAn
gle, |
1139 SkColor lightColo
r, | 1139 SkColor lightColo
r, |
1140 SkScalar surfaceS
cale, | 1140 SkScalar surfaceS
cale, |
1141 SkScalar ks, | 1141 SkScalar kd, |
1142 SkScalar shine, | 1142 sk_sp<SkImageFilt
er> input, |
1143 SkImageFilter* in
put, | |
1144 const CropRect* c
ropRect) { | 1143 const CropRect* c
ropRect) { |
1145 SkAutoTUnref<SkImageFilterLight> light(new SkDistantLight(direction, lightCo
lor)); | 1144 sk_sp<SkImageFilterLight> light( |
1146 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); | 1145 new SkSpotLight(location, target, specularExponent, cutoffAngle, lig
htColor)); |
| 1146 return SkDiffuseLightingImageFilter::Make(std::move(light), surfaceScale, kd
, |
| 1147 std::move(input), cropRect); |
1147 } | 1148 } |
1148 | 1149 |
1149 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular(const SkPoint3& loc
ation, | 1150 sk_sp<SkImageFilter> SkLightingImageFilter::MakeDistantLitSpecular(const SkPoint
3& direction, |
1150 SkColor lightColor, | 1151 SkColor light
Color, |
1151 SkScalar surfaceSca
le, | 1152 SkScalar surf
aceScale, |
1152 SkScalar ks, | 1153 SkScalar ks, |
1153 SkScalar shine, | 1154 SkScalar shin
e, |
1154 SkImageFilter* inpu
t, | 1155 sk_sp<SkImage
Filter> input, |
1155 const CropRect* cro
pRect) { | 1156 const CropRec
t* cropRect) { |
1156 SkAutoTUnref<SkImageFilterLight> light(new SkPointLight(location, lightColor
)); | 1157 sk_sp<SkImageFilterLight> light(new SkDistantLight(direction, lightColor)); |
1157 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); | 1158 return SkSpecularLightingImageFilter::Make(std::move(light), surfaceScale, k
s, shine, |
| 1159 std::move(input), cropRect); |
1158 } | 1160 } |
1159 | 1161 |
1160 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular(const SkPoint3& loca
tion, | 1162 sk_sp<SkImageFilter> SkLightingImageFilter::MakePointLitSpecular(const SkPoint3&
location, |
1161 const SkPoint3& targ
et, | 1163 SkColor lightCo
lor, |
1162 SkScalar specularExp
onent, | 1164 SkScalar surfac
eScale, |
1163 SkScalar cutoffAngle
, | 1165 SkScalar ks, |
1164 SkColor lightColor, | 1166 SkScalar shine, |
1165 SkScalar surfaceScal
e, | 1167 sk_sp<SkImageFi
lter> input, |
1166 SkScalar ks, | 1168 const CropRect*
cropRect) { |
1167 SkScalar shine, | 1169 sk_sp<SkImageFilterLight> light(new SkPointLight(location, lightColor)); |
1168 SkImageFilter* input
, | 1170 return SkSpecularLightingImageFilter::Make(std::move(light), surfaceScale, k
s, shine, |
1169 const CropRect* crop
Rect) { | 1171 std::move(input), cropRect); |
1170 SkAutoTUnref<SkImageFilterLight> light( | |
1171 new SkSpotLight(location, target, specularExponent, cutoffAngle, lig
htColor)); | |
1172 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine,
input, cropRect); | |
1173 } | 1172 } |
1174 | 1173 |
1175 SkLightingImageFilter::~SkLightingImageFilter() {} | 1174 sk_sp<SkImageFilter> SkLightingImageFilter::MakeSpotLitSpecular(const SkPoint3&
location, |
| 1175 const SkPoint3&
target, |
| 1176 SkScalar specula
rExponent, |
| 1177 SkScalar cutoffA
ngle, |
| 1178 SkColor lightCol
or, |
| 1179 SkScalar surface
Scale, |
| 1180 SkScalar ks, |
| 1181 SkScalar shine, |
| 1182 sk_sp<SkImageFil
ter> input, |
| 1183 const CropRect*
cropRect) { |
| 1184 sk_sp<SkImageFilterLight> light( |
| 1185 new SkSpotLight(location, target, specularExponent, cutoffAngle, lig
htColor)); |
| 1186 return SkSpecularLightingImageFilter::Make(std::move(light), surfaceScale, k
s, shine, |
| 1187 std::move(input), cropRect); |
| 1188 } |
1176 | 1189 |
1177 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1190 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1178 this->INHERITED::flatten(buffer); | 1191 this->INHERITED::flatten(buffer); |
1179 fLight->flattenLight(buffer); | 1192 fLight->flattenLight(buffer); |
1180 buffer.writeScalar(fSurfaceScale * 255); | 1193 buffer.writeScalar(fSurfaceScale * 255); |
1181 } | 1194 } |
1182 | 1195 |
1183 /////////////////////////////////////////////////////////////////////////////// | 1196 /////////////////////////////////////////////////////////////////////////////// |
1184 | 1197 |
1185 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkImageFilterLight* light, | 1198 sk_sp<SkImageFilter> SkDiffuseLightingImageFilter::Make(sk_sp<SkImageFilterLight
> light, |
1186 SkScalar surfaceScale, | 1199 SkScalar surfaceScale, |
1187 SkScalar kd, | 1200 SkScalar kd, |
1188 SkImageFilter* input, | 1201 sk_sp<SkImageFilter> inp
ut, |
1189 const CropRect* cropRect) { | 1202 const CropRect* cropRect
) { |
1190 if (nullptr == light) { | 1203 if (!light) { |
1191 return nullptr; | 1204 return nullptr; |
1192 } | 1205 } |
1193 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { | 1206 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { |
1194 return nullptr; | 1207 return nullptr; |
1195 } | 1208 } |
1196 // According to the spec, kd can be any non-negative number : | 1209 // According to the spec, kd can be any non-negative number : |
1197 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement | 1210 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement |
1198 if (kd < 0) { | 1211 if (kd < 0) { |
1199 return nullptr; | 1212 return nullptr; |
1200 } | 1213 } |
1201 return new SkDiffuseLightingImageFilter(light, surfaceScale, kd, input, crop
Rect); | 1214 return sk_sp<SkImageFilter>(new SkDiffuseLightingImageFilter(std::move(light
), surfaceScale, |
| 1215 kd, std::move(i
nput), cropRect)); |
1202 } | 1216 } |
1203 | 1217 |
1204 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkImageFilterLight* l
ight, | 1218 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(sk_sp<SkImageFilterLi
ght> light, |
1205 SkScalar surfaceScale
, | 1219 SkScalar surfaceScale
, |
1206 SkScalar kd, | 1220 SkScalar kd, |
1207 SkImageFilter* input, | 1221 sk_sp<SkImageFilter>
input, |
1208 const CropRect* cropR
ect) | 1222 const CropRect* cropR
ect) |
1209 : INHERITED(light, surfaceScale, input, cropRect), | 1223 : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect) |
1210 fKD(kd) | 1224 , fKD(kd) { |
1211 { | |
1212 } | 1225 } |
1213 | 1226 |
1214 sk_sp<SkFlattenable> SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buff
er) { | 1227 sk_sp<SkFlattenable> SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buff
er) { |
1215 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 1228 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
1216 SkAutoTUnref<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(bu
ffer)); | 1229 sk_sp<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(buffer)); |
1217 SkScalar surfaceScale = buffer.readScalar(); | 1230 SkScalar surfaceScale = buffer.readScalar(); |
1218 SkScalar kd = buffer.readScalar(); | 1231 SkScalar kd = buffer.readScalar(); |
1219 return sk_sp<SkFlattenable>(Create(light, surfaceScale, kd, common.getInput(
0).get(), | 1232 return Make(std::move(light), surfaceScale, kd, common.getInput(0), &common.
cropRect()); |
1220 &common.cropRect())); | |
1221 } | 1233 } |
1222 | 1234 |
1223 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1235 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1224 this->INHERITED::flatten(buffer); | 1236 this->INHERITED::flatten(buffer); |
1225 buffer.writeScalar(fKD); | 1237 buffer.writeScalar(fKD); |
1226 } | 1238 } |
1227 | 1239 |
1228 bool SkDiffuseLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, | 1240 bool SkDiffuseLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, |
1229 const SkBitmap& sourc
e, | 1241 const SkBitmap& sourc
e, |
1230 const Context& ctx, | 1242 const Context& ctx, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 const SkIRect* srcBounds, | 1327 const SkIRect* srcBounds, |
1316 BoundaryMode boundaryMode) co
nst { | 1328 BoundaryMode boundaryMode) co
nst { |
1317 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); | 1329 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); |
1318 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix
, this->kd(), | 1330 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix
, this->kd(), |
1319 boundaryMode, srcBounds); | 1331 boundaryMode, srcBounds); |
1320 } | 1332 } |
1321 #endif | 1333 #endif |
1322 | 1334 |
1323 /////////////////////////////////////////////////////////////////////////////// | 1335 /////////////////////////////////////////////////////////////////////////////// |
1324 | 1336 |
1325 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light, | 1337 sk_sp<SkImageFilter> SkSpecularLightingImageFilter::Make(sk_sp<SkImageFilterLigh
t> light, |
1326 SkScalar surfaceScale, | 1338 SkScalar surfaceScale, |
1327 SkScalar ks, | 1339 SkScalar ks, |
1328 SkScalar shininess, | 1340 SkScalar shininess, |
1329 SkImageFilter* input, | 1341 sk_sp<SkImageFilter> in
put, |
1330 const CropRect* cropRect) { | 1342 const CropRect* cropRec
t) { |
1331 if (nullptr == light) { | 1343 if (!light) { |
1332 return nullptr; | 1344 return nullptr; |
1333 } | 1345 } |
1334 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF
inite(shininess)) { | 1346 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF
inite(shininess)) { |
1335 return nullptr; | 1347 return nullptr; |
1336 } | 1348 } |
1337 // According to the spec, ks can be any non-negative number : | 1349 // According to the spec, ks can be any non-negative number : |
1338 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement | 1350 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement |
1339 if (ks < 0) { | 1351 if (ks < 0) { |
1340 return nullptr; | 1352 return nullptr; |
1341 } | 1353 } |
1342 return new SkSpecularLightingImageFilter(light, surfaceScale, ks, shininess,
input, cropRect); | 1354 return sk_sp<SkImageFilter>(new SkSpecularLightingImageFilter(std::move(ligh
t), surfaceScale, |
| 1355 ks, shininess, |
| 1356 std::move(inpu
t), cropRect)); |
1343 } | 1357 } |
1344 | 1358 |
1345 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkImageFilterLight*
light, | 1359 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(sk_sp<SkImageFilter
Light> light, |
1346 SkScalar surfaceSca
le, | 1360 SkScalar surfaceSca
le, |
1347 SkScalar ks, | 1361 SkScalar ks, |
1348 SkScalar shininess, | 1362 SkScalar shininess, |
1349 SkImageFilter* inpu
t, | 1363 sk_sp<SkImageFilter
> input, |
1350 const CropRect* cro
pRect) | 1364 const CropRect* cro
pRect) |
1351 : INHERITED(light, surfaceScale, input, cropRect), | 1365 : INHERITED(std::move(light), surfaceScale, std::move(input), cropRect) |
1352 fKS(ks), | 1366 , fKS(ks) |
1353 fShininess(shininess) | 1367 , fShininess(shininess) { |
1354 { | |
1355 } | 1368 } |
1356 | 1369 |
1357 sk_sp<SkFlattenable> SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buf
fer) { | 1370 sk_sp<SkFlattenable> SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buf
fer) { |
1358 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 1371 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
1359 SkAutoTUnref<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(bu
ffer)); | 1372 sk_sp<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(buffer)); |
1360 SkScalar surfaceScale = buffer.readScalar(); | 1373 SkScalar surfaceScale = buffer.readScalar(); |
1361 SkScalar ks = buffer.readScalar(); | 1374 SkScalar ks = buffer.readScalar(); |
1362 SkScalar shine = buffer.readScalar(); | 1375 SkScalar shine = buffer.readScalar(); |
1363 return sk_sp<SkFlattenable>(Create(light, surfaceScale, ks, shine, common.ge
tInput(0).get(), | 1376 return Make(std::move(light), surfaceScale, ks, shine, common.getInput(0), |
1364 &common.cropRect())); | 1377 &common.cropRect()); |
1365 } | 1378 } |
1366 | 1379 |
1367 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1380 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1368 this->INHERITED::flatten(buffer); | 1381 this->INHERITED::flatten(buffer); |
1369 buffer.writeScalar(fKS); | 1382 buffer.writeScalar(fKS); |
1370 buffer.writeScalar(fShininess); | 1383 buffer.writeScalar(fShininess); |
1371 } | 1384 } |
1372 | 1385 |
1373 bool SkSpecularLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, | 1386 bool SkSpecularLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, |
1374 const SkBitmap& sour
ce, | 1387 const SkBitmap& sour
ce, |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2121 | 2134 |
2122 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2135 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
2123 } | 2136 } |
2124 | 2137 |
2125 #endif | 2138 #endif |
2126 | 2139 |
2127 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2140 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
2128 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2141 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
2129 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2142 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
2130 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2143 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |