Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: src/effects/SkLightingImageFilter.cpp

Issue 13602013: Allow single-pass filters (which use asNewEffect()) to participate in the image filter DAG. This w… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fix return value of SkImageFilter::asNewEffect(). Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 buffer.writeScalar(point.fY); 257 buffer.writeScalar(point.fY);
258 buffer.writeScalar(point.fZ); 258 buffer.writeScalar(point.fZ);
259 }; 259 };
260 260
261 class SkDiffuseLightingImageFilter : public SkLightingImageFilter { 261 class SkDiffuseLightingImageFilter : public SkLightingImageFilter {
262 public: 262 public:
263 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale, 263 SkDiffuseLightingImageFilter(SkLight* light, SkScalar surfaceScale,
264 SkScalar kd, SkImageFilter* input); 264 SkScalar kd, SkImageFilter* input);
265 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter) 265 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFi lter)
266 266
267 #if SK_SUPPORT_GPU
267 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const SK_OVERRIDE ; 268 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const SK_OVERRIDE ;
269 #endif
268 SkScalar kd() const { return fKD; } 270 SkScalar kd() const { return fKD; }
269 271
270 protected: 272 protected:
271 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer); 273 explicit SkDiffuseLightingImageFilter(SkFlattenableReadBuffer& buffer);
272 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; 274 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE;
273 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, 275 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
274 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; 276 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
275 277
276 278
277 private: 279 private:
278 typedef SkLightingImageFilter INHERITED; 280 typedef SkLightingImageFilter INHERITED;
279 SkScalar fKD; 281 SkScalar fKD;
280 }; 282 };
281 283
282 class SkSpecularLightingImageFilter : public SkLightingImageFilter { 284 class SkSpecularLightingImageFilter : public SkLightingImageFilter {
283 public: 285 public:
284 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala r ks, SkScalar shininess, SkImageFilter* input); 286 SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScala r ks, SkScalar shininess, SkImageFilter* input);
285 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter) 287 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageF ilter)
286 288
289 #if SK_SUPPORT_GPU
287 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const SK_OVERRIDE ; 290 virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const SK_OVERRIDE ;
291 #endif
292
288 SkScalar ks() const { return fKS; } 293 SkScalar ks() const { return fKS; }
289 SkScalar shininess() const { return fShininess; } 294 SkScalar shininess() const { return fShininess; }
290 295
291 protected: 296 protected:
292 explicit SkSpecularLightingImageFilter(SkFlattenableReadBuffer& buffer); 297 explicit SkSpecularLightingImageFilter(SkFlattenableReadBuffer& buffer);
293 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE; 298 virtual void flatten(SkFlattenableWriteBuffer& buffer) const SK_OVERRIDE;
294 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, 299 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&,
295 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE; 300 SkBitmap* result, SkIPoint* offset) SK_OVERRIDE;
296 301
297 private: 302 private:
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 case SkLight::kPoint_LightType: 857 case SkLight::kPoint_LightType:
853 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, light() , src, dst, surfaceScale()); 858 lightBitmap<DiffuseLightingType, SkPointLight>(lightingType, light() , src, dst, surfaceScale());
854 break; 859 break;
855 case SkLight::kSpot_LightType: 860 case SkLight::kSpot_LightType:
856 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, light(), src, dst, surfaceScale()); 861 lightBitmap<DiffuseLightingType, SkSpotLight>(lightingType, light(), src, dst, surfaceScale());
857 break; 862 break;
858 } 863 }
859 return true; 864 return true;
860 } 865 }
861 866
862 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect,
863 GrTexture* texture) const {
864 #if SK_SUPPORT_GPU 867 #if SK_SUPPORT_GPU
868 bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture* texture) const {
865 if (effect) { 869 if (effect) {
866 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); 870 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
867 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, kd()) ; 871 *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, kd()) ;
868 } 872 }
869 return true; 873 return true;
870 #else 874 }
871 SkDEBUGFAIL("Should not call in GPU-less build");
872 return false;
873 #endif 875 #endif
874 }
875 876
876 /////////////////////////////////////////////////////////////////////////////// 877 ///////////////////////////////////////////////////////////////////////////////
877 878
878 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input) 879 SkSpecularLightingImageFilter::SkSpecularLightingImageFilter(SkLight* light, SkS calar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input)
879 : SkLightingImageFilter(light, surfaceScale, input), 880 : SkLightingImageFilter(light, surfaceScale, input),
880 fKS(ks), 881 fKS(ks),
881 fShininess(shininess) 882 fShininess(shininess)
882 { 883 {
883 } 884 }
884 885
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 case SkLight::kPoint_LightType: 922 case SkLight::kPoint_LightType:
922 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, light( ), src, dst, surfaceScale()); 923 lightBitmap<SpecularLightingType, SkPointLight>(lightingType, light( ), src, dst, surfaceScale());
923 break; 924 break;
924 case SkLight::kSpot_LightType: 925 case SkLight::kSpot_LightType:
925 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, light() , src, dst, surfaceScale()); 926 lightBitmap<SpecularLightingType, SkSpotLight>(lightingType, light() , src, dst, surfaceScale());
926 break; 927 break;
927 } 928 }
928 return true; 929 return true;
929 } 930 }
930 931
931 bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect,
932 GrTexture* texture) const {
933 #if SK_SUPPORT_GPU 932 #if SK_SUPPORT_GPU
933 bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect, GrTexture* texture) const {
934 if (effect) { 934 if (effect) {
935 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); 935 SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
936 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, ks() , shininess()); 936 *effect = GrSpecularLightingEffect::Create(texture, light(), scale, ks() , shininess());
937 } 937 }
938 return true; 938 return true;
939 #else 939 }
940 SkDEBUGFAIL("Should not call in GPU-less build");
941 return false;
942 #endif 940 #endif
943 }
944 941
945 /////////////////////////////////////////////////////////////////////////////// 942 ///////////////////////////////////////////////////////////////////////////////
946 943
947 #if SK_SUPPORT_GPU 944 #if SK_SUPPORT_GPU
948 945
949 namespace { 946 namespace {
950 SkPoint3 random_point3(SkMWCRandom* random) { 947 SkPoint3 random_point3(SkMWCRandom* random) {
951 return SkPoint3(SkScalarToFloat(random->nextSScalar1()), 948 return SkPoint3(SkScalarToFloat(random->nextSScalar1()),
952 SkScalarToFloat(random->nextSScalar1()), 949 SkScalarToFloat(random->nextSScalar1()),
953 SkScalarToFloat(random->nextSScalar1())); 950 SkScalarToFloat(random->nextSScalar1()));
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1469 1466
1470 #endif 1467 #endif
1471 1468
1472 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter) 1469 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkLightingImageFilter)
1473 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter) 1470 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDiffuseLightingImageFilter)
1474 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter) 1471 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpecularLightingImageFilter)
1475 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight) 1472 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkDistantLight)
1476 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight) 1473 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkPointLight)
1477 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight) 1474 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSpotLight)
1478 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1475 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698