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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { | 264 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { |
265 public: | 265 public: |
266 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, | 266 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, |
267 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); | 267 SkScalar kd, SkImageFilter* input, const CropRe
ct* cropRect); |
268 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) | 268 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi
lter) |
269 SkScalar kd() const { return fKD; } | 269 SkScalar kd() const { return fKD; } |
270 | 270 |
271 protected: | 271 protected: |
272 explicit SkDiffuseLightingImageFilter(SkReadBuffer& buffer); | 272 explicit SkDiffuseLightingImageFilter(SkReadBuffer& buffer); |
273 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 273 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
274 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 274 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
275 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 275 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
276 #if SK_SUPPORT_GPU | 276 #if SK_SUPPORT_GPU |
277 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix, const SkIRect& bounds) const SK_OVERRIDE; | 277 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix, const SkIRect& bounds) const SK_OVERRIDE; |
278 #endif | 278 #endif |
279 | 279 |
280 private: | 280 private: |
281 typedef SkLightingImageFilter INHERITED; | 281 typedef SkLightingImageFilter INHERITED; |
282 SkScalar fKD; | 282 SkScalar fKD; |
283 }; | 283 }; |
284 | 284 |
285 class SkSpecularLightingImageFilter : public SkLightingImageFilter { | 285 class SkSpecularLightingImageFilter : public SkLightingImageFilter { |
286 public: | 286 public: |
287 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect); | 287 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala
r ks, SkScalar shininess, SkImageFilter* input, const CropRect* cropRect); |
288 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) | 288 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF
ilter) |
289 | 289 |
290 SkScalar ks() const { return fKS; } | 290 SkScalar ks() const { return fKS; } |
291 SkScalar shininess() const { return fShininess; } | 291 SkScalar shininess() const { return fShininess; } |
292 | 292 |
293 protected: | 293 protected: |
294 explicit SkSpecularLightingImageFilter(SkReadBuffer& buffer); | 294 explicit SkSpecularLightingImageFilter(SkReadBuffer& buffer); |
295 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; | 295 virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE; |
296 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, | 296 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
297 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 297 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
298 #if SK_SUPPORT_GPU | 298 #if SK_SUPPORT_GPU |
299 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix, const SkIRect& bounds) const SK_OVERRIDE; | 299 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix& m
atrix, const SkIRect& bounds) const SK_OVERRIDE; |
300 #endif | 300 #endif |
301 | 301 |
302 private: | 302 private: |
303 typedef SkLightingImageFilter INHERITED; | 303 typedef SkLightingImageFilter INHERITED; |
304 SkScalar fKS; | 304 SkScalar fKS; |
305 SkScalar fShininess; | 305 SkScalar fShininess; |
306 }; | 306 }; |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 buffer.validate(SkScalarIsFinite(fKD) && (fKD >= 0)); | 926 buffer.validate(SkScalarIsFinite(fKD) && (fKD >= 0)); |
927 } | 927 } |
928 | 928 |
929 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 929 void SkDiffuseLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
930 this->INHERITED::flatten(buffer); | 930 this->INHERITED::flatten(buffer); |
931 buffer.writeScalar(fKD); | 931 buffer.writeScalar(fKD); |
932 } | 932 } |
933 | 933 |
934 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, | 934 bool SkDiffuseLightingImageFilter::onFilterImage(Proxy* proxy, |
935 const SkBitmap& source, | 935 const SkBitmap& source, |
936 const SkMatrix& ctm, | 936 const Context& ctx, |
937 SkBitmap* dst, | 937 SkBitmap* dst, |
938 SkIPoint* offset) const { | 938 SkIPoint* offset) const { |
939 SkImageFilter* input = getInput(0); | 939 SkImageFilter* input = getInput(0); |
940 SkBitmap src = source; | 940 SkBitmap src = source; |
941 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 941 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
942 if (input && !input->filterImage(proxy, source, ctm, &src, &srcOffset)) { | 942 if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) { |
943 return false; | 943 return false; |
944 } | 944 } |
945 | 945 |
946 if (src.colorType() != kPMColor_SkColorType) { | 946 if (src.colorType() != kPMColor_SkColorType) { |
947 return false; | 947 return false; |
948 } | 948 } |
949 SkAutoLockPixels alp(src); | 949 SkAutoLockPixels alp(src); |
950 if (!src.getPixels()) { | 950 if (!src.getPixels()) { |
951 return false; | 951 return false; |
952 } | 952 } |
953 | 953 |
954 SkIRect bounds; | 954 SkIRect bounds; |
955 src.getBounds(&bounds); | 955 src.getBounds(&bounds); |
956 bounds.offset(srcOffset); | 956 bounds.offset(srcOffset); |
957 if (!this->applyCropRect(&bounds, ctm)) { | 957 if (!this->applyCropRect(&bounds, ctx.ctm())) { |
958 return false; | 958 return false; |
959 } | 959 } |
960 | 960 |
961 if (bounds.width() < 2 || bounds.height() < 2) { | 961 if (bounds.width() < 2 || bounds.height() < 2) { |
962 return false; | 962 return false; |
963 } | 963 } |
964 | 964 |
965 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 965 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
966 if (!dst->allocPixels()) { | 966 if (!dst->allocPixels()) { |
967 return false; | 967 return false; |
968 } | 968 } |
969 | 969 |
970 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); | 970 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm())); |
971 | 971 |
972 DiffuseLightingType lightingType(fKD); | 972 DiffuseLightingType lightingType(fKD); |
973 offset->fX = bounds.left(); | 973 offset->fX = bounds.left(); |
974 offset->fY = bounds.top(); | 974 offset->fY = bounds.top(); |
975 bounds.offset(-srcOffset); | 975 bounds.offset(-srcOffset); |
976 switch (transformedLight->type()) { | 976 switch (transformedLight->type()) { |
977 case SkLight::kDistant_LightType: | 977 case SkLight::kDistant_LightType: |
978 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, trans
formedLight, src, dst, surfaceScale(), bounds); | 978 lightBitmap<DiffuseLightingType, SkDistantLight>(lightingType, trans
formedLight, src, dst, surfaceScale(), bounds); |
979 break; | 979 break; |
980 case SkLight::kPoint_LightType: | 980 case SkLight::kPoint_LightType: |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 } | 1019 } |
1020 | 1020 |
1021 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { | 1021 void SkSpecularLightingImageFilter::flatten(SkWriteBuffer& buffer) const { |
1022 this->INHERITED::flatten(buffer); | 1022 this->INHERITED::flatten(buffer); |
1023 buffer.writeScalar(fKS); | 1023 buffer.writeScalar(fKS); |
1024 buffer.writeScalar(fShininess); | 1024 buffer.writeScalar(fShininess); |
1025 } | 1025 } |
1026 | 1026 |
1027 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, | 1027 bool SkSpecularLightingImageFilter::onFilterImage(Proxy* proxy, |
1028 const SkBitmap& source, | 1028 const SkBitmap& source, |
1029 const SkMatrix& ctm, | 1029 const Context& ctx, |
1030 SkBitmap* dst, | 1030 SkBitmap* dst, |
1031 SkIPoint* offset) const { | 1031 SkIPoint* offset) const { |
1032 SkImageFilter* input = getInput(0); | 1032 SkImageFilter* input = getInput(0); |
1033 SkBitmap src = source; | 1033 SkBitmap src = source; |
1034 SkIPoint srcOffset = SkIPoint::Make(0, 0); | 1034 SkIPoint srcOffset = SkIPoint::Make(0, 0); |
1035 if (input && !input->filterImage(proxy, source, ctm, &src, &srcOffset)) { | 1035 if (input && !input->filterImage(proxy, source, ctx, &src, &srcOffset)) { |
1036 return false; | 1036 return false; |
1037 } | 1037 } |
1038 | 1038 |
1039 if (src.colorType() != kPMColor_SkColorType) { | 1039 if (src.colorType() != kPMColor_SkColorType) { |
1040 return false; | 1040 return false; |
1041 } | 1041 } |
1042 SkAutoLockPixels alp(src); | 1042 SkAutoLockPixels alp(src); |
1043 if (!src.getPixels()) { | 1043 if (!src.getPixels()) { |
1044 return false; | 1044 return false; |
1045 } | 1045 } |
1046 | 1046 |
1047 SkIRect bounds; | 1047 SkIRect bounds; |
1048 src.getBounds(&bounds); | 1048 src.getBounds(&bounds); |
1049 bounds.offset(srcOffset); | 1049 bounds.offset(srcOffset); |
1050 if (!this->applyCropRect(&bounds, ctm)) { | 1050 if (!this->applyCropRect(&bounds, ctx.ctm())) { |
1051 return false; | 1051 return false; |
1052 } | 1052 } |
1053 | 1053 |
1054 if (bounds.width() < 2 || bounds.height() < 2) { | 1054 if (bounds.width() < 2 || bounds.height() < 2) { |
1055 return false; | 1055 return false; |
1056 } | 1056 } |
1057 | 1057 |
1058 dst->setConfig(src.config(), bounds.width(), bounds.height()); | 1058 dst->setConfig(src.config(), bounds.width(), bounds.height()); |
1059 dst->allocPixels(); | 1059 dst->allocPixels(); |
1060 if (!dst->getPixels()) { | 1060 if (!dst->getPixels()) { |
1061 return false; | 1061 return false; |
1062 } | 1062 } |
1063 | 1063 |
1064 SpecularLightingType lightingType(fKS, fShininess); | 1064 SpecularLightingType lightingType(fKS, fShininess); |
1065 offset->fX = bounds.left(); | 1065 offset->fX = bounds.left(); |
1066 offset->fY = bounds.top(); | 1066 offset->fY = bounds.top(); |
1067 bounds.offset(-srcOffset); | 1067 bounds.offset(-srcOffset); |
1068 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctm)); | 1068 SkAutoTUnref<SkLight> transformedLight(light()->transform(ctx.ctm())); |
1069 switch (transformedLight->type()) { | 1069 switch (transformedLight->type()) { |
1070 case SkLight::kDistant_LightType: | 1070 case SkLight::kDistant_LightType: |
1071 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, tran
sformedLight, src, dst, surfaceScale(), bounds); | 1071 lightBitmap<SpecularLightingType, SkDistantLight>(lightingType, tran
sformedLight, src, dst, surfaceScale(), bounds); |
1072 break; | 1072 break; |
1073 case SkLight::kPoint_LightType: | 1073 case SkLight::kPoint_LightType: |
1074 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); | 1074 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, transf
ormedLight, src, dst, surfaceScale(), bounds); |
1075 break; | 1075 break; |
1076 case SkLight::kSpot_LightType: | 1076 case SkLight::kSpot_LightType: |
1077 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); | 1077 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, transfo
rmedLight, src, dst, surfaceScale(), bounds); |
1078 break; | 1078 break; |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 | 1618 |
1619 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); | 1619 builder->fsCodeAppendf("%s(%s)", fLightColorFunc.c_str(), surfaceToLight); |
1620 } | 1620 } |
1621 | 1621 |
1622 #endif | 1622 #endif |
1623 | 1623 |
1624 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) | 1624 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) |
1625 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) | 1625 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) |
1626 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) | 1626 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) |
1627 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 1627 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |