Flutter Engine
The Flutter Engine
Classes | Functions
lattice.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/private/base/SkMalloc.h"
#include "tools/ToolUtils.h"

Go to the source code of this file.

Classes

class  LatticeGM
 
class  LatticeGM2
 

Functions

static sk_sp< SkSurfacemake_surface (SkCanvas *root, int N, int padLeft, int padTop, int padRight, int padBottom)
 
static sk_sp< SkImagemake_image (SkCanvas *root, int *xDivs, int *yDivs, int padLeft, int padTop, int padRight, int padBottom)
 
static void image_to_bitmap (GrDirectContext *dContext, const SkImage *image, SkBitmap *bm)
 
 DEF_SIMPLE_GM_BG (lattice_alpha, canvas, 120, 120, SK_ColorWHITE)
 

Function Documentation

◆ DEF_SIMPLE_GM_BG()

DEF_SIMPLE_GM_BG ( lattice_alpha  ,
canvas  ,
120  ,
120  ,
SK_ColorWHITE   
)

Definition at line 357 of file lattice.cpp.

357 {
358 auto surface = ToolUtils::makeSurface(canvas, SkImageInfo::MakeA8(100, 100));
359 surface->getCanvas()->clear(0);
360 surface->getCanvas()->drawCircle(50, 50, 50, SkPaint());
361 auto image = surface->makeImageSnapshot();
362
363 int divs[] = { 20, 40, 60, 80 };
364
365 SkCanvas::Lattice lattice;
366 lattice.fXCount = 4;
367 lattice.fXDivs = divs;
368 lattice.fYCount = 4;
369 lattice.fYDivs = divs;
370 lattice.fRectTypes = nullptr;
371 lattice.fColors = nullptr;
372 lattice.fBounds = nullptr;
373
375 paint.setColor(SK_ColorMAGENTA);
376 canvas->drawImageLattice(image.get(), lattice, SkRect::MakeWH(120, 120),
378}
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
T * get() const
Definition: SkRefCnt.h:303
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
Definition: ToolUtils.cpp:512
int fYCount
number of y-coordinates
Definition: SkCanvas.h:1617
const SkIRect * fBounds
source bounds to draw from
Definition: SkCanvas.h:1618
const int * fYDivs
y-axis values dividing bitmap
Definition: SkCanvas.h:1614
int fXCount
number of x-coordinates
Definition: SkCanvas.h:1616
const RectType * fRectTypes
array of fill types
Definition: SkCanvas.h:1615
const SkColor * fColors
array of colors
Definition: SkCanvas.h:1619
const int * fXDivs
x-axis values dividing bitmap
Definition: SkCanvas.h:1613
static SkImageInfo MakeA8(int width, int height)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ image_to_bitmap()

static void image_to_bitmap ( GrDirectContext dContext,
const SkImage image,
SkBitmap bm 
)
static

Definition at line 84 of file lattice.cpp.

84 {
86 bm->allocPixels(info);
87 image->readPixels(dContext, info, bm->getPixels(), bm->rowBytes(), 0, 0);
88}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
size_t rowBytes() const
Definition: SkBitmap.h:238
void * getPixels() const
Definition: SkBitmap.h:283
bool readPixels(GrDirectContext *context, const SkImageInfo &dstInfo, void *dstPixels, size_t dstRowBytes, int srcX, int srcY, CachingHint cachingHint=kAllow_CachingHint) const
Definition: SkImage.cpp:42
int width() const
Definition: SkImage.h:285
int height() const
Definition: SkImage.h:291
static SkImageInfo MakeN32Premul(int width, int height)

◆ make_image()

static sk_sp< SkImage > make_image ( SkCanvas root,
int xDivs,
int yDivs,
int  padLeft,
int  padTop,
int  padRight,
int  padBottom 
)
static

Definition at line 32 of file lattice.cpp.

33 {
34 const int kCap = 28;
35 const int kMid = 8;
36 const int kSize = 2*kCap + 3*kMid;
37
38 auto surface(make_surface(root, kSize, padLeft, padTop, padRight, padBottom));
39 SkCanvas* canvas = surface->getCanvas();
40 canvas->translate((float) padLeft, (float) padTop);
41
44 const SkScalar radius = SkIntToScalar(kCap) - strokeWidth/2;
45
46 xDivs[0] = kCap + padLeft;
47 yDivs[0] = kCap + padTop;
48 xDivs[1] = kCap + kMid + padLeft;
49 yDivs[1] = kCap + kMid + padTop;
50 xDivs[2] = kCap + 2 * kMid + padLeft;
51 yDivs[2] = kCap + 2 * kMid + padTop;
52 xDivs[3] = kCap + 3 * kMid + padLeft;
53 yDivs[3] = kCap + 3 * kMid + padTop;
54
56 paint.setAntiAlias(true);
57
58 paint.setColor(0xFFFFFF00);
59 canvas->drawRoundRect(r, radius, radius, paint);
60
62 paint.setColor(0x8800FF00);
63 canvas->drawRect(r, paint);
64 r.setXYWH(SkIntToScalar(kCap + kMid), 0, SkIntToScalar(kMid), SkIntToScalar(kSize));
65 paint.setColor(0x880000FF);
66 canvas->drawRect(r, paint);
67 r.setXYWH(SkIntToScalar(kCap + 2*kMid), 0, SkIntToScalar(kMid), SkIntToScalar(kSize));
68 paint.setColor(0x88FF00FF);
69 canvas->drawRect(r, paint);
70
72 paint.setColor(0x8800FF00);
73 canvas->drawRect(r, paint);
74 r.setXYWH(0, SkIntToScalar(kCap + kMid), SkIntToScalar(kSize), SkIntToScalar(kMid));
75 paint.setColor(0x880000FF);
76 canvas->drawRect(r, paint);
77 r.setXYWH(0, SkIntToScalar(kCap + 2*kMid), SkIntToScalar(kSize), SkIntToScalar(kMid));
78 paint.setColor(0x88FF00FF);
79 canvas->drawRect(r, paint);
80
81 return surface->makeImageSnapshot();
82}
static const int strokeWidth
Definition: BlurTest.cpp:60
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, const SkPaint &paint)
Definition: SkCanvas.cpp:2717
float SkScalar
Definition: extension.cpp:12
constexpr int kSize
static sk_sp< SkSurface > make_surface(SkCanvas *root, int N, int padLeft, int padTop, int padRight, int padBottom)
Definition: lattice.cpp:26
PODArray< int > xDivs
Definition: SkRecords.h:271
PODArray< int > yDivs
Definition: SkRecords.h:273
string root
Definition: scale_cpu.py:20
void setXYWH(float x, float y, float width, float height)
Definition: SkRect.h:931

◆ make_surface()

static sk_sp< SkSurface > make_surface ( SkCanvas root,
int  N,
int  padLeft,
int  padTop,
int  padRight,
int  padBottom 
)
static

Definition at line 26 of file lattice.cpp.

27 {
28 SkImageInfo info = SkImageInfo::MakeN32Premul(N + padLeft + padRight, N + padTop + padBottom);
30}
#define N
Definition: beziers.cpp:19