Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | List of all members
skiagm::ImageLightingGM Class Reference
Inheritance diagram for skiagm::ImageLightingGM:
skiagm::GM

Public Member Functions

 ImageLightingGM ()
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual SkISize getISize ()=0
 
virtual SkString getName () const =0
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual bool isBazelOnly () const
 
virtual std::map< std::string, std::string > getGoldKeys () const
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
void drawClippedBitmap (SkCanvas *canvas, const SkPaint &paint, int x, int y)
 
void onOnceBeforeDraw () override
 
void onDraw (SkCanvas *canvas) override
 
bool onAnimate (double nanos) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 
- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 30 of file lighting.cpp.

Constructor & Destructor Documentation

◆ ImageLightingGM()

skiagm::ImageLightingGM::ImageLightingGM ( )
inline

Definition at line 32 of file lighting.cpp.

33 : fAzimuth(SkIntToScalar(kStartAzimuth)) {
34 this->setBGColor(0xFF000000);
35 }
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void setBGColor(SkColor)
Definition: gm.cpp:159

Member Function Documentation

◆ drawClippedBitmap()

void skiagm::ImageLightingGM::drawClippedBitmap ( SkCanvas canvas,
const SkPaint paint,
int  x,
int  y 
)
inlineprotected

Definition at line 42 of file lighting.cpp.

42 {
43 canvas->save();
45 canvas->clipIRect(fBitmap.bounds());
46 canvas->drawImage(fBitmap.asImage(), 0, 0, SkSamplingOptions(), &paint);
47 canvas->restore();
48 }
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
SkIRect bounds() const
Definition: SkBitmap.h:382
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clipIRect(const SkIRect &irect, SkClipOp op=SkClipOp::kIntersect)
Definition: SkCanvas.h:991
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
const Paint & paint
Definition: color_source.cc:38
double y
double x

◆ getISize()

SkISize skiagm::ImageLightingGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 40 of file lighting.cpp.

40{ return SkISize::Make(WIDTH, HEIGHT); }
#define WIDTH
Definition: lighting.cpp:25
#define HEIGHT
Definition: lighting.cpp:26
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ getName()

SkString skiagm::ImageLightingGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 38 of file lighting.cpp.

38{ return SkString("lighting"); }

◆ onAnimate()

bool skiagm::ImageLightingGM::onAnimate ( double  nanos)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 171 of file lighting.cpp.

171 {
172 constexpr SkScalar kDesiredDurationSecs = 15.0f;
173
174 fAzimuth = kStartAzimuth + TimeUtils::Scaled(1e-9 * nanos, 360.0f/kDesiredDurationSecs, 360.0f);
175 return true;
176 }
float SkScalar
Definition: extension.cpp:12
static float Scaled(float time, float speed, float period=0)
Definition: TimeUtils.h:27

◆ onDraw()

void skiagm::ImageLightingGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 54 of file lighting.cpp.

54 {
55 canvas->clear(0xFF101010);
56 SkPaint checkPaint;
57 checkPaint.setColor(0xFF202020);
58 for (int y = 0; y < HEIGHT; y += 16) {
59 for (int x = 0; x < WIDTH; x += 16) {
60 canvas->save();
62 canvas->drawRect(SkRect::MakeXYWH(8, 0, 8, 8), checkPaint);
63 canvas->drawRect(SkRect::MakeXYWH(0, 8, 8, 8), checkPaint);
64 canvas->restore();
65 }
66 }
67 SkScalar sinAzimuth = SkScalarSin(SkDegreesToRadians(fAzimuth)),
68 cosAzimuth = SkScalarCos(SkDegreesToRadians(fAzimuth));
69
70 SkPoint3 spotTarget = SkPoint3::Make(SkIntToScalar(40), SkIntToScalar(40), 0);
71 SkPoint3 spotLocation = SkPoint3::Make(spotTarget.fX + 70.7214f * cosAzimuth,
72 spotTarget.fY + 70.7214f * sinAzimuth,
73 spotTarget.fZ + SkIntToScalar(20));
74 SkScalar spotExponent1 = SK_Scalar1;
75 SkScalar spotExponent10 = SkIntToScalar(10);
76 SkScalar cutoffAngleSmall = SkIntToScalar(15);
77 SkScalar cutoffAngleNone = SkIntToScalar(180);
78
79 SkPoint3 pointLocation = SkPoint3::Make(spotTarget.fX + 50 * cosAzimuth,
80 spotTarget.fY + 50 * sinAzimuth,
81 SkIntToScalar(10));
82 SkScalar elevationRad = SkDegreesToRadians(SkIntToScalar(5));
83
84 SkPoint3 distantDirection = SkPoint3::Make(cosAzimuth * SkScalarCos(elevationRad),
85 sinAzimuth * SkScalarCos(elevationRad),
86 SkScalarSin(elevationRad));
87 SkScalar kd = SkIntToScalar(2);
88 SkScalar ks = SkIntToScalar(1);
89 SkScalar shininess = SkIntToScalar(8);
90 SkScalar surfaceScale = SkIntToScalar(1);
91 SkScalar surfaceScaleSmall = 0.1f;
92 SkColor greenYellow = SkColorSetARGB(255, 173, 255, 47);
94
95 SkIRect cropRect = SkIRect::MakeXYWH(20, 10, 60, 65);
96 SkIRect fullSizeCropRect = SkIRect::MakeXYWH(0, 0, 100, 100);
97 sk_sp<SkImageFilter> noopCropped(SkImageFilters::Offset(0, 0, nullptr, &cropRect));
98
99 int y = 0;
100 for (int i = 0; i < 3; i++) {
101 const SkIRect* cr = (i == 1) ? &cropRect : (i == 2) ? &fullSizeCropRect : nullptr;
102 sk_sp<SkImageFilter> input = (i == 2) ? noopCropped : nullptr;
103 // Basic point, distant and spot lights with diffuse lighting
105 pointLocation, SK_ColorWHITE, surfaceScale, kd, input, cr));
106 drawClippedBitmap(canvas, paint, 0, y);
107
109 distantDirection, SK_ColorWHITE, surfaceScale, kd, input, cr));
110 drawClippedBitmap(canvas, paint, 110, y);
111
113 spotLocation, spotTarget, spotExponent1, cutoffAngleSmall, SK_ColorWHITE,
114 surfaceScale, kd, input, cr));
115 drawClippedBitmap(canvas, paint, 220, y);
116
117 // Spot light with no angle cutoff
119 spotLocation, spotTarget, spotExponent10, cutoffAngleNone, SK_ColorWHITE,
120 surfaceScale, kd, input, cr));
121 drawClippedBitmap(canvas, paint, 330, y);
122
123 // Spot light with falloff exponent
125 spotLocation, spotTarget, spotExponent1, cutoffAngleNone, SK_ColorWHITE,
126 surfaceScaleSmall, kd, input, cr));
127 drawClippedBitmap(canvas, paint, 440, y);
128
129 // Large constant to show oversaturation
131 distantDirection, greenYellow, surfaceScale, 4.f * kd, input, cr));
132 drawClippedBitmap(canvas, paint, 550, y);
133
134 y += 110;
135
136 // Basic point, distant and spot lights with specular lighting
138 pointLocation, SK_ColorWHITE, surfaceScale, ks, shininess, input, cr));
139 drawClippedBitmap(canvas, paint, 0, y);
140
142 distantDirection, SK_ColorWHITE, surfaceScale, ks, shininess, input, cr));
143 drawClippedBitmap(canvas, paint, 110, y);
144
146 spotLocation, spotTarget, spotExponent1, cutoffAngleSmall, SK_ColorWHITE,
147 surfaceScale, ks, shininess, input, cr));
148 drawClippedBitmap(canvas, paint, 220, y);
149
150 // Spot light with no angle cutoff
152 spotLocation, spotTarget, spotExponent10, cutoffAngleNone, SK_ColorWHITE,
153 surfaceScale, ks, shininess, input, cr));
154 drawClippedBitmap(canvas, paint, 330, y);
155
156 // Spot light with falloff exponent
158 spotLocation, spotTarget, spotExponent1, cutoffAngleNone, SK_ColorWHITE,
159 surfaceScaleSmall, ks, shininess, input, cr));
160 drawClippedBitmap(canvas, paint, 440, y);
161
162 // Large constant to show oversaturation
164 distantDirection, greenYellow, surfaceScale, 4.f * ks, shininess, input, cr));
165 drawClippedBitmap(canvas, paint, 550, y);
166
167 y += 110;
168 }
169 }
uint32_t SkColor
Definition: SkColor.h:37
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
#define SkDegreesToRadians(degrees)
Definition: SkScalar.h:77
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkScalarCos(radians)
Definition: SkScalar.h:46
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clear(SkColor color)
Definition: SkCanvas.h:1199
static sk_sp< SkImageFilter > PointLitDiffuse(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > DistantLitSpecular(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > DistantLitDiffuse(const SkPoint3 &direction, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Offset(SkScalar dx, SkScalar dy, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > PointLitSpecular(const SkPoint3 &location, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > SpotLitDiffuse(const SkPoint3 &location, const SkPoint3 &target, SkScalar falloffExponent, SkScalar cutoffAngle, SkColor lightColor, SkScalar surfaceScale, SkScalar kd, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > SpotLitSpecular(const SkPoint3 &location, const SkPoint3 &target, SkScalar falloffExponent, SkScalar cutoffAngle, SkColor lightColor, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void drawClippedBitmap(SkCanvas *canvas, const SkPaint &paint, int x, int y)
Definition: lighting.cpp:42
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
SkScalar fX
Definition: SkPoint3.h:16
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition: SkPoint3.h:18
SkScalar fZ
Definition: SkPoint3.h:16
SkScalar fY
Definition: SkPoint3.h:16
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ onOnceBeforeDraw()

void skiagm::ImageLightingGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 50 of file lighting.cpp.

50 {
51 fBitmap = ToolUtils::CreateStringBitmap(100, 100, 0xFFFFFFFF, 20, 70, 96, "e");
52 }
SkBitmap CreateStringBitmap(int w, int h, SkColor c, int x, int y, int textSize, const char *str)

The documentation for this class was generated from the following file: