Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
PosterCircleGM Class Reference
Inheritance diagram for PosterCircleGM:
skiagm::GM

Public Member Functions

 PosterCircleGM ()
 
- 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 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
 
bool onAnimate (double nanos) override
 
void onOnceBeforeDraw () override
 
void onDraw (SkCanvas *canvas) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual DrawResult onDraw (SkCanvas *, SkString *errorMsg)
 
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 postercircle.cpp.

Constructor & Destructor Documentation

◆ PosterCircleGM()

PosterCircleGM::PosterCircleGM ( )
inline

Definition at line 32 of file postercircle.cpp.

32: fTime(0.f) {}

Member Function Documentation

◆ getISize()

SkISize PosterCircleGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 37 of file postercircle.cpp.

37{ return SkISize::Make(kStageWidth, kStageHeight + 50); }
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20

◆ getName()

SkString PosterCircleGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 35 of file postercircle.cpp.

35{ return SkString("poster_circle"); }

◆ onAnimate()

bool PosterCircleGM::onAnimate ( double  nanos)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 39 of file postercircle.cpp.

39 {
40 fTime = TimeUtils::Scaled(1e-9 * nanos, 0.5f);
41 return true;
42 }
static float Scaled(float time, float speed, float period=0)
Definition TimeUtils.h:27

◆ onDraw()

void PosterCircleGM::onDraw ( SkCanvas canvas)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 78 of file postercircle.cpp.

78 {
79 // See https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/perspective
80 // for projection matrix when --webkit-perspective: 800px is used.
81 SkM44 proj;
82 proj.setRC(3, 2, -1.f / 800.f);
83
84 for (int pass = 0; pass < 2; ++pass) {
85 // Want to draw 90 to 270 first (the back), then 270 to 90 (the front), but do all 3
86 // rings backsides, then their frontsides since the front projections overlap across
87 // rings. Note: we skip the poster circle's x axis rotation because that complicates the
88 // back-to-front drawing order and it isn't necessary to trigger draws aligned with Z.
89 bool drawFront = pass > 0;
90
91 for (int y = 0; y < 3; ++y) {
92 float ringY = (y - 1) * (kPosterSize + 10.f);
93 for (int i = 0; i < kNumAngles; ++i) {
94 // Add an extra 45 degree rotation, which triggers the bug by aligning some of
95 // the posters with the z axis.
96 SkScalar yDuration = 5.f - y;
97 SkScalar yRotation = SkScalarMod(kAngleStep * i +
98 360.f * SkScalarMod(fTime / yDuration, yDuration), 360.f);
99 // These rotation limits were chosen manually to line up with current projection
100 static constexpr SkScalar kBackMinAngle = 70.f;
101 static constexpr SkScalar kBackMaxAngle = 290.f;
102 if (drawFront) {
103 if (yRotation >= kBackMinAngle && yRotation <= kBackMaxAngle) {
104 // Back portion during a front draw
105 continue;
106 }
107 } else {
108 if (yRotation < kBackMinAngle || yRotation > kBackMaxAngle) {
109 // Front portion during a back draw
110 continue;
111 }
112 }
113
114 canvas->save();
115
116 // Matrix matches transform: rotateY(<angle>deg) translateZ(200px); nested in an
117 // element with the perspective projection matrix above.
118 SkM44 model = SkM44::Translate(kStageWidth/2, kStageHeight/2 + 25, 0)
119 * proj
120 * SkM44::Translate(0, ringY, 0)
121 * SkM44::Rotate({0,1,0}, SkDegreesToRadians(yRotation))
122 * SkM44::Translate(0, 0, kRingRadius);
123 canvas->concat(model);
124
125 SkRect poster = SkRect::MakeLTRB(-0.5f * kPosterSize, -0.5f * kPosterSize,
126 0.5f * kPosterSize, 0.5f * kPosterSize);
127 SkPaint fillPaint;
128 fillPaint.setAntiAlias(true);
129 fillPaint.setAlphaf(0.7f);
130 canvas->drawImageRect(fPosterImages[i], poster,
132
133 canvas->restore();
134 }
135 }
136 }
137 }
#define SkDegreesToRadians(degrees)
Definition SkScalar.h:77
#define SkScalarMod(x, y)
Definition SkScalar.h:41
void restore()
Definition SkCanvas.cpp:465
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
int save()
Definition SkCanvas.cpp:451
void concat(const SkMatrix &matrix)
Definition SkM44.h:150
static SkM44 Rotate(SkV3 axis, SkScalar radians)
Definition SkM44.h:239
static SkM44 Translate(SkScalar x, SkScalar y, SkScalar z=0)
Definition SkM44.h:225
void setRC(int r, int c, SkScalar value)
Definition SkM44.h:266
void setAntiAlias(bool aa)
Definition SkPaint.h:170
void setAlphaf(float a)
Definition SkPaint.cpp:130
float SkScalar
Definition extension.cpp:12
double y
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition SkRect.h:646

◆ onOnceBeforeDraw()

void PosterCircleGM::onOnceBeforeDraw ( )
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 44 of file postercircle.cpp.

44 {
47 font.setEmbolden(true);
48 font.setSize(24.f);
49
51 SkSurfaces::Raster(SkImageInfo::MakeN32Premul(kPosterSize, kPosterSize));
52 for (int i = 0; i < kNumAngles; ++i) {
53 SkCanvas* canvas = surface->getCanvas();
54
55 SkPaint fillPaint;
56 fillPaint.setAntiAlias(true);
57 fillPaint.setColor(i % 2 == 0 ? SkColorSetRGB(0x99, 0x5C, 0x7F)
58 : SkColorSetRGB(0x83, 0x5A, 0x99));
59 canvas->drawRRect(SkRRect::MakeRectXY(SkRect::MakeWH(kPosterSize, kPosterSize),
60 10.f, 10.f), fillPaint);
61
62 SkString label;
63 label.printf("%d", i);
64 SkRect labelBounds;
65 font.measureText(label.c_str(), label.size(), SkTextEncoding::kUTF8, &labelBounds);
66 SkScalar labelX = 0.5f * kPosterSize - 0.5f * labelBounds.width();
67 SkScalar labelY = 0.5f * kPosterSize + 0.5f * labelBounds.height();
68
69
70 SkPaint labelPaint;
71 labelPaint.setAntiAlias(true);
72 canvas->drawString(label, labelX, labelY, font, labelPaint);
73
74 fPosterImages[i] = surface->makeImageSnapshot();
75 }
76 }
#define SkColorSetRGB(r, g, b)
Definition SkColor.h:57
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
@ kAntiAlias
may have transparent pixels on glyph edges
void setColor(SkColor color)
Definition SkPaint.cpp:119
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition SkRRect.h:180
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
size_t size() const
Definition SkString.h:131
const char * c_str() const
Definition SkString.h:133
VkSurfaceKHR surface
Definition main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SkFont DefaultPortableFont()
font
Font Metadata and Metrics.
static SkImageInfo MakeN32Premul(int width, int height)
constexpr float height() const
Definition SkRect.h:769
constexpr float width() const
Definition SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

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