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(light, surfaceScale, input, cropRect) { |
f(malita)
2016/04/08 21:12:08
nit: move light, input?
robertphillips
2016/04/08 21:56:53
Done.
| |
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 , input, cropRect); |
f(malita)
2016/04/08 21:12:08
nit: move input
robertphillips
2016/04/08 21:56:53
Done.
| |
1122 } | 1121 } |
1123 | 1122 |
1124 SkImageFilter* SkLightingImageFilter::CreateSpotLitDiffuse(const SkPoint3& locat ion, | 1123 sk_sp<SkImageFilter> SkLightingImageFilter::MakePointLitDiffuse(const SkPoint3& location, |
1125 const SkPoint3& targe t, | 1124 SkColor lightCol or, |
1126 SkScalar specularExpo nent, | 1125 SkScalar surface Scale, |
1127 SkScalar cutoffAngle, | 1126 SkScalar kd, |
1128 SkColor lightColor, | 1127 sk_sp<SkImageFil ter> input, |
1129 SkScalar surfaceScale , | 1128 const CropRect* cropRect) { |
1130 SkScalar kd, | 1129 sk_sp<SkImageFilterLight> light(new SkPointLight(location, lightColor)); |
1131 SkImageFilter* input, | 1130 return SkDiffuseLightingImageFilter::Make(std::move(light), surfaceScale, kd , input, cropRect); |
f(malita)
2016/04/08 21:12:08
ditto
robertphillips
2016/04/08 21:56:53
Done.
| |
1132 const CropRect* cropR ect) { | |
1133 SkAutoTUnref<SkImageFilterLight> light( | |
1134 new SkSpotLight(location, target, specularExponent, cutoffAngle, lig htColor)); | |
1135 return SkDiffuseLightingImageFilter::Create(light, surfaceScale, kd, input, cropRect); | |
1136 } | 1131 } |
1137 | 1132 |
1138 SkImageFilter* SkLightingImageFilter::CreateDistantLitSpecular(const SkPoint3& d irection, | 1133 sk_sp<SkImageFilter> SkLightingImageFilter::MakeSpotLitDiffuse(const SkPoint3& l ocation, |
1134 const SkPoint3& t arget, | |
1135 SkScalar specular Exponent, | |
1136 SkScalar cutoffAn gle, | |
1139 SkColor lightColo r, | 1137 SkColor lightColo r, |
1140 SkScalar surfaceS cale, | 1138 SkScalar surfaceS cale, |
1141 SkScalar ks, | 1139 SkScalar kd, |
1142 SkScalar shine, | 1140 sk_sp<SkImageFilt er> input, |
1143 SkImageFilter* in put, | |
1144 const CropRect* c ropRect) { | 1141 const CropRect* c ropRect) { |
1145 SkAutoTUnref<SkImageFilterLight> light(new SkDistantLight(direction, lightCo lor)); | 1142 sk_sp<SkImageFilterLight> light( |
1146 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect); | 1143 new SkSpotLight(location, target, specularExponent, cutoffAngle, lig htColor)); |
1144 return SkDiffuseLightingImageFilter::Make(std::move(light), surfaceScale, kd , input, cropRect); | |
f(malita)
2016/04/08 21:12:08
ditto
robertphillips
2016/04/08 21:56:53
Done.
| |
1147 } | 1145 } |
1148 | 1146 |
1149 SkImageFilter* SkLightingImageFilter::CreatePointLitSpecular(const SkPoint3& loc ation, | 1147 sk_sp<SkImageFilter> SkLightingImageFilter::MakeDistantLitSpecular(const SkPoint 3& direction, |
1150 SkColor lightColor, | 1148 SkColor light Color, |
1151 SkScalar surfaceSca le, | 1149 SkScalar surf aceScale, |
1152 SkScalar ks, | 1150 SkScalar ks, |
1153 SkScalar shine, | 1151 SkScalar shin e, |
1154 SkImageFilter* inpu t, | 1152 sk_sp<SkImage Filter> input, |
1155 const CropRect* cro pRect) { | 1153 const CropRec t* cropRect) { |
1156 SkAutoTUnref<SkImageFilterLight> light(new SkPointLight(location, lightColor )); | 1154 sk_sp<SkImageFilterLight> light(new SkDistantLight(direction, lightColor)); |
1157 return SkSpecularLightingImageFilter::Create(light, surfaceScale, ks, shine, input, cropRect); | 1155 return SkSpecularLightingImageFilter::Make(std::move(light), surfaceScale, k s, shine, input, |
f(malita)
2016/04/08 21:12:08
ditto
robertphillips
2016/04/08 21:56:53
Done.
| |
1156 cropRect); | |
1158 } | 1157 } |
1159 | 1158 |
1160 SkImageFilter* SkLightingImageFilter::CreateSpotLitSpecular(const SkPoint3& loca tion, | 1159 sk_sp<SkImageFilter> SkLightingImageFilter::MakePointLitSpecular(const SkPoint3& location, |
1161 const SkPoint3& targ et, | 1160 SkColor lightCo lor, |
1162 SkScalar specularExp onent, | 1161 SkScalar surfac eScale, |
1163 SkScalar cutoffAngle , | 1162 SkScalar ks, |
1164 SkColor lightColor, | 1163 SkScalar shine, |
1165 SkScalar surfaceScal e, | 1164 sk_sp<SkImageFi lter> input, |
1166 SkScalar ks, | 1165 const CropRect* cropRect) { |
1167 SkScalar shine, | 1166 sk_sp<SkImageFilterLight> light(new SkPointLight(location, lightColor)); |
1168 SkImageFilter* input , | 1167 return SkSpecularLightingImageFilter::Make(std::move(light), surfaceScale, k s, shine, input, |
f(malita)
2016/04/08 21:12:08
ditto
robertphillips
2016/04/08 21:56:53
Done.
| |
1169 const CropRect* crop Rect) { | 1168 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 } | 1169 } |
1174 | 1170 |
1175 SkLightingImageFilter::~SkLightingImageFilter() {} | 1171 sk_sp<SkImageFilter> SkLightingImageFilter::MakeSpotLitSpecular(const SkPoint3& location, |
1172 const SkPoint3& target, | |
1173 SkScalar specula rExponent, | |
1174 SkScalar cutoffA ngle, | |
1175 SkColor lightCol or, | |
1176 SkScalar surface Scale, | |
1177 SkScalar ks, | |
1178 SkScalar shine, | |
1179 sk_sp<SkImageFil ter> input, | |
1180 const CropRect* cropRect) { | |
1181 sk_sp<SkImageFilterLight> light( | |
1182 new SkSpotLight(location, target, specularExponent, cutoffAngle, lig htColor)); | |
1183 return SkSpecularLightingImageFilter::Make(std::move(light), surfaceScale, k s, shine, input, | |
f(malita)
2016/04/08 21:12:08
ditto
robertphillips
2016/04/08 21:56:53
Done.
| |
1184 cropRect); | |
1185 } | |
1176 | 1186 |
1177 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1187 void SkLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1178 this->INHERITED::flatten(buffer); | 1188 this->INHERITED::flatten(buffer); |
1179 fLight->flattenLight(buffer); | 1189 fLight->flattenLight(buffer); |
1180 buffer.writeScalar(fSurfaceScale * 255); | 1190 buffer.writeScalar(fSurfaceScale * 255); |
1181 } | 1191 } |
1182 | 1192 |
1183 /////////////////////////////////////////////////////////////////////////////// | 1193 /////////////////////////////////////////////////////////////////////////////// |
1184 | 1194 |
1185 SkImageFilter* SkDiffuseLightingImageFilter::Create(SkImageFilterLight* light, | 1195 sk_sp<SkImageFilter> SkDiffuseLightingImageFilter::Make(sk_sp<SkImageFilterLight > light, |
1186 SkScalar surfaceScale, | 1196 SkScalar surfaceScale, |
1187 SkScalar kd, | 1197 SkScalar kd, |
1188 SkImageFilter* input, | 1198 sk_sp<SkImageFilter> inp ut, |
1189 const CropRect* cropRect) { | 1199 const CropRect* cropRect ) { |
1190 if (nullptr == light) { | 1200 if (!light) { |
1191 return nullptr; | 1201 return nullptr; |
1192 } | 1202 } |
1193 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { | 1203 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(kd)) { |
1194 return nullptr; | 1204 return nullptr; |
1195 } | 1205 } |
1196 // According to the spec, kd can be any non-negative number : | 1206 // According to the spec, kd can be any non-negative number : |
1197 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement | 1207 // http://www.w3.org/TR/SVG/filters.html#feDiffuseLightingElement |
1198 if (kd < 0) { | 1208 if (kd < 0) { |
1199 return nullptr; | 1209 return nullptr; |
1200 } | 1210 } |
1201 return new SkDiffuseLightingImageFilter(light, surfaceScale, kd, input, crop Rect); | 1211 return sk_sp<SkImageFilter>(new SkDiffuseLightingImageFilter(std::move(light ), surfaceScale, |
1212 kd, std::move(i nput), cropRect)); | |
1202 } | 1213 } |
1203 | 1214 |
1204 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(SkImageFilterLight* l ight, | 1215 SkDiffuseLightingImageFilter::SkDiffuseLightingImageFilter(sk_sp<SkImageFilterLi ght> light, |
1205 SkScalar surfaceScale , | 1216 SkScalar surfaceScale , |
1206 SkScalar kd, | 1217 SkScalar kd, |
1207 SkImageFilter* input, | 1218 sk_sp<SkImageFilter> input, |
1208 const CropRect* cropR ect) | 1219 const CropRect* cropR ect) |
1209 : INHERITED(light, surfaceScale, input, cropRect), | 1220 : INHERITED(light, surfaceScale, input, cropRect) |
f(malita)
2016/04/08 21:12:08
nit: move light, input
robertphillips
2016/04/08 21:56:53
Done.
| |
1210 fKD(kd) | 1221 , fKD(kd) { |
1211 { | |
1212 } | 1222 } |
1213 | 1223 |
1214 sk_sp<SkFlattenable> SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buff er) { | 1224 sk_sp<SkFlattenable> SkDiffuseLightingImageFilter::CreateProc(SkReadBuffer& buff er) { |
1215 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 1225 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
1216 SkAutoTUnref<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(bu ffer)); | 1226 sk_sp<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(buffer)); |
1217 SkScalar surfaceScale = buffer.readScalar(); | 1227 SkScalar surfaceScale = buffer.readScalar(); |
1218 SkScalar kd = buffer.readScalar(); | 1228 SkScalar kd = buffer.readScalar(); |
1219 return sk_sp<SkFlattenable>(Create(light, surfaceScale, kd, common.getInput( 0).get(), | 1229 return Make(std::move(light), surfaceScale, kd, common.getInput(0), &common. cropRect()); |
1220 &common.cropRect())); | |
1221 } | 1230 } |
1222 | 1231 |
1223 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1232 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1224 this->INHERITED::flatten(buffer); | 1233 this->INHERITED::flatten(buffer); |
1225 buffer.writeScalar(fKD); | 1234 buffer.writeScalar(fKD); |
1226 } | 1235 } |
1227 | 1236 |
1228 bool SkDiffuseLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, | 1237 bool SkDiffuseLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, |
1229 const SkBitmap& sourc e, | 1238 const SkBitmap& sourc e, |
1230 const Context& ctx, | 1239 const Context& ctx, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1315 const SkIRect* srcBounds, | 1324 const SkIRect* srcBounds, |
1316 BoundaryMode boundaryMode) co nst { | 1325 BoundaryMode boundaryMode) co nst { |
1317 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); | 1326 SkScalar scale = SkScalarMul(this->surfaceScale(), SkIntToScalar(255)); |
1318 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix , this->kd(), | 1327 return GrDiffuseLightingEffect::Create(texture, this->light(), scale, matrix , this->kd(), |
1319 boundaryMode, srcBounds); | 1328 boundaryMode, srcBounds); |
1320 } | 1329 } |
1321 #endif | 1330 #endif |
1322 | 1331 |
1323 /////////////////////////////////////////////////////////////////////////////// | 1332 /////////////////////////////////////////////////////////////////////////////// |
1324 | 1333 |
1325 SkImageFilter* SkSpecularLightingImageFilter::Create(SkImageFilterLight* light, | 1334 sk_sp<SkImageFilter> SkSpecularLightingImageFilter::Make(sk_sp<SkImageFilterLigh t> light, |
1326 SkScalar surfaceScale, | 1335 SkScalar surfaceScale, |
1327 SkScalar ks, | 1336 SkScalar ks, |
1328 SkScalar shininess, | 1337 SkScalar shininess, |
1329 SkImageFilter* input, | 1338 sk_sp<SkImageFilter> in put, |
1330 const CropRect* cropRect) { | 1339 const CropRect* cropRec t) { |
1331 if (nullptr == light) { | 1340 if (!light) { |
1332 return nullptr; | 1341 return nullptr; |
1333 } | 1342 } |
1334 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF inite(shininess)) { | 1343 if (!SkScalarIsFinite(surfaceScale) || !SkScalarIsFinite(ks) || !SkScalarIsF inite(shininess)) { |
1335 return nullptr; | 1344 return nullptr; |
1336 } | 1345 } |
1337 // According to the spec, ks can be any non-negative number : | 1346 // According to the spec, ks can be any non-negative number : |
1338 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement | 1347 // http://www.w3.org/TR/SVG/filters.html#feSpecularLightingElement |
1339 if (ks < 0) { | 1348 if (ks < 0) { |
1340 return nullptr; | 1349 return nullptr; |
1341 } | 1350 } |
1342 return new SkSpecularLightingImageFilter(light, surfaceScale, ks, shininess, input, cropRect); | 1351 return sk_sp<SkImageFilter>(new SkSpecularLightingImageFilter(std::move(ligh t), surfaceScale, |
1352 ks, shininess, | |
1353 std::move(inpu t), cropRect)); | |
1343 } | 1354 } |
1344 | 1355 |
1345 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkImageFilterLight* light, | 1356 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(sk_sp<SkImageFilter Light> light, |
1346 SkScalar surfaceSca le, | 1357 SkScalar surfaceSca le, |
1347 SkScalar ks, | 1358 SkScalar ks, |
1348 SkScalar shininess, | 1359 SkScalar shininess, |
1349 SkImageFilter* inpu t, | 1360 sk_sp<SkImageFilter > input, |
1350 const CropRect* cro pRect) | 1361 const CropRect* cro pRect) |
1351 : INHERITED(light, surfaceScale, input, cropRect), | 1362 : INHERITED(light, surfaceScale, input, cropRect) |
f(malita)
2016/04/08 21:12:08
ditto
robertphillips
2016/04/08 21:56:53
Done.
| |
1352 fKS(ks), | 1363 , fKS(ks) |
1353 fShininess(shininess) | 1364 , fShininess(shininess) { |
1354 { | |
1355 } | 1365 } |
1356 | 1366 |
1357 sk_sp<SkFlattenable> SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buf fer) { | 1367 sk_sp<SkFlattenable> SkSpecularLightingImageFilter::CreateProc(SkReadBuffer& buf fer) { |
1358 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); | 1368 SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1); |
1359 SkAutoTUnref<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(bu ffer)); | 1369 sk_sp<SkImageFilterLight> light(SkImageFilterLight::UnflattenLight(buffer)); |
1360 SkScalar surfaceScale = buffer.readScalar(); | 1370 SkScalar surfaceScale = buffer.readScalar(); |
1361 SkScalar ks = buffer.readScalar(); | 1371 SkScalar ks = buffer.readScalar(); |
1362 SkScalar shine = buffer.readScalar(); | 1372 SkScalar shine = buffer.readScalar(); |
1363 return sk_sp<SkFlattenable>(Create(light, surfaceScale, ks, shine, common.ge tInput(0).get(), | 1373 return Make(std::move(light), surfaceScale, ks, shine, common.getInput(0), |
1364 &common.cropRect())); | 1374 &common.cropRect()); |
1365 } | 1375 } |
1366 | 1376 |
1367 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1377 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1368 this->INHERITED::flatten(buffer); | 1378 this->INHERITED::flatten(buffer); |
1369 buffer.writeScalar(fKS); | 1379 buffer.writeScalar(fKS); |
1370 buffer.writeScalar(fShininess); | 1380 buffer.writeScalar(fShininess); |
1371 } | 1381 } |
1372 | 1382 |
1373 bool SkSpecularLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, | 1383 bool SkSpecularLightingImageFilter::onFilterImageDeprecated(Proxy* proxy, |
1374 const SkBitmap& sour ce, | 1384 const SkBitmap& sour ce, |
(...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2121 | 2131 |
2122 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 2132 fragBuilder->codeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
2123 } | 2133 } |
2124 | 2134 |
2125 #endif | 2135 #endif |
2126 | 2136 |
2127 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 2137 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
2128 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 2138 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
2129 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 2139 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
2130 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 2140 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |