Flutter Engine
The Flutter Engine
Classes | Functions
tallstretchedbitmaps.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkRandom.h"
#include "tools/GpuToolUtils.h"
#include "tools/ToolUtils.h"

Go to the source code of this file.

Classes

class  TallStretchedBitmapsGM
 

Functions

int make_bm (SkBitmap *bm, int height)
 

Function Documentation

◆ make_bm()

int make_bm ( SkBitmap bm,
int  height 
)

Definition at line 23 of file tallstretchedbitmaps.cpp.

23 {
24 constexpr int kRadius = 22;
25 constexpr int kMargin = 8;
26 constexpr SkScalar kStartAngle = 0;
27 constexpr SkScalar kDAngle = 25;
28 constexpr SkScalar kSweep = 320;
29 constexpr SkScalar kThickness = 8;
30
31 int count = (height / (2 * kRadius + kMargin));
32 height = count * (2 * kRadius + kMargin);
33
35 SkRandom random;
36
37 SkCanvas wholeCanvas(*bm);
38 wholeCanvas.clear(0x00000000);
39
40 SkScalar angle = kStartAngle;
41 for (int i = 0; i < count; ++i) {
43 // The sw rasterizer disables AA for large canvii. So we make a small canvas for each draw.
44 SkBitmap smallBM;
45 SkIRect subRect = SkIRect::MakeXYWH(0, i * (kMargin + 2 * kRadius),
46 2 * kRadius + kMargin, 2 * kRadius + kMargin);
47 bm->extractSubset(&smallBM, subRect);
48 SkCanvas canvas(smallBM);
49 canvas.translate(kMargin + kRadius, kMargin + kRadius);
50
51 paint.setAntiAlias(true);
52 paint.setColor(random.nextU() | 0xFF000000);
54 paint.setStrokeWidth(kThickness);
55 paint.setStrokeCap(SkPaint::kRound_Cap);
56 SkScalar radius = kRadius - kThickness / 2;
57 SkRect bounds = SkRect::MakeLTRB(-radius, -radius, radius, radius);
58
59 canvas.drawArc(bounds, angle, kSweep, false, paint);
60 angle += kDAngle;
61 }
62 bm->setImmutable();
63 return count;
64}
int count
Definition: FontMgrTest.cpp:50
constexpr int kMargin
Definition: aaxfermodes.cpp:31
void setImmutable()
Definition: SkBitmap.cpp:400
bool extractSubset(SkBitmap *dst, const SkIRect &subset) const
Definition: SkBitmap.cpp:453
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
@ kRound_Cap
adds circle
Definition: SkPaint.h:335
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
uint32_t nextU()
Definition: SkRandom.h:42
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
Optional< SkRect > bounds
Definition: SkRecords.h:189
int32_t height
constexpr int kRadius
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646