Flutter Engine
The Flutter Engine
Classes | Functions | Variables
flippity.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrTypes.h"
#include "include/private/base/SkTArray.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrPixmap.h"
#include "src/gpu/ganesh/image/SkImage_Ganesh.h"
#include "src/image/SkImage_Base.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/gpu/ProxyUtils.h"
#include <string.h>
#include <utility>

Go to the source code of this file.

Classes

class  FlippityGM
 

Functions

static sk_sp< SkImagemake_text_image (const char *text, SkColor color)
 
static sk_sp< SkImagemake_reference_image (SkCanvas *mainCanvas, const TArray< sk_sp< SkImage > > &labels, bool bottomLeftOrigin)
 
static bool UVMatToGeomMatForImage (SkMatrix *geomMat, const SkMatrix &uvMat)
 

Variables

static const int kNumMatrices = 6
 
static const int kImageSize = 128
 
static const int kLabelSize = 32
 
static const int kNumLabels = 4
 
static const int kInset = 16
 
static const int kCellSize = kImageSize+2*kLabelSize
 
static const int kGMWidth = kNumMatrices*kCellSize
 
static const int kGMHeight = 4*kCellSize
 
static const SkPoint kPoints [kNumLabels]
 
static const SkMatrix kUVMatrices [kNumMatrices]
 

Function Documentation

◆ make_reference_image()

static sk_sp< SkImage > make_reference_image ( SkCanvas mainCanvas,
const TArray< sk_sp< SkImage > > &  labels,
bool  bottomLeftOrigin 
)
static

Definition at line 113 of file flippity.cpp.

115 {
116 SkASSERT(kNumLabels == labels.size());
117
120 SkBitmap bm;
121 bm.allocPixels(ii);
122
123 {
124 SkCanvas canvas(bm);
125
126 canvas.clear(SK_ColorWHITE);
127 for (int i = 0; i < kNumLabels; ++i) {
128 canvas.drawImage(labels[i],
129 0.0 != kPoints[i].fX ? kPoints[i].fX-kLabelSize-kInset : kInset,
130 0.0 != kPoints[i].fY ? kPoints[i].fY-kLabelSize-kInset : kInset);
131 }
132
133 bm.setImmutable();
134 }
135
136 auto dContext = GrAsDirectContext(mainCanvas->recordingContext());
137 if (dContext && !dContext->abandoned()) {
138 auto origin = bottomLeftOrigin ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
139
141 bm.pixmap());
142 if (!view) {
143 return nullptr;
144 }
145
146 return sk_make_sp<SkImage_Ganesh>(
147 sk_ref_sp(dContext), kNeedNewImageUniqueID, std::move(view), ii.colorInfo());
148 }
149
151}
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
@ kNeedNewImageUniqueID
Definition: SkImage_Base.h:33
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
void setImmutable()
Definition: SkBitmap.cpp:400
const SkPixmap & pixmap() const
Definition: SkBitmap.h:133
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
int size() const
Definition: SkTArray.h:421
static const int kLabelSize
Definition: flippity.cpp:45
static const SkPoint kPoints[kNumLabels]
Definition: flippity.cpp:53
static const int kImageSize
Definition: flippity.cpp:44
static const int kInset
Definition: flippity.cpp:47
static const int kNumLabels
Definition: flippity.cpp:46
SK_API sk_sp< SkImage > RasterFromBitmap(const SkBitmap &bitmap)
GrSurfaceProxyView MakeTextureProxyViewFromData(GrDirectContext *dContext, GrRenderable renderable, GrSurfaceOrigin origin, GrCPixmap pixmap)
Definition: ProxyUtils.cpp:56
const SkColorInfo & colorInfo() const
Definition: SkImageInfo.h:404
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ make_text_image()

static sk_sp< SkImage > make_text_image ( const char *  text,
SkColor  color 
)
static

Definition at line 86 of file flippity.cpp.

86 {
88 paint.setAntiAlias(true);
89 paint.setColor(color);
90
93 font.setSize(32);
94
96 font.measureText(text, strlen(text), SkTextEncoding::kUTF8, &bounds);
98
101
102 SkCanvas* canvas = surf->getCanvas();
103
104 canvas->clear(SK_ColorWHITE);
105 canvas->concat(mat);
106 canvas->drawSimpleText(text, strlen(text), SkTextEncoding::kUTF8, 0, 0, font, paint);
107
108 return surf->makeImageSnapshot();
109}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.cpp:2413
void clear(SkColor color)
Definition: SkCanvas.h:1199
void concat(const SkMatrix &matrix)
Definition: SkCanvas.cpp:1318
Definition: SkFont.h:35
@ kAntiAlias
may have transparent pixels on glyph edges
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition: SkMatrix.h:157
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
sk_sp< SkImage > makeImageSnapshot()
Definition: SkSurface.cpp:90
const Paint & paint
Definition: color_source.cc:38
DlColor color
std::u16string text
Optional< SkRect > bounds
Definition: SkRecords.h:189
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)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ UVMatToGeomMatForImage()

static bool UVMatToGeomMatForImage ( SkMatrix geomMat,
const SkMatrix uvMat 
)
static

Definition at line 157 of file flippity.cpp.

157 {
158
159 const SkMatrix yFlip = SkMatrix::MakeAll(1, 0, 0, 0, -1, 1, 0, 0, 1);
160
161 SkMatrix tmp = uvMat;
162 tmp.preConcat(yFlip);
163 tmp.preScale(1.0f/kImageSize, 1.0f/kImageSize);
164
165 tmp.postConcat(yFlip);
167
168 return tmp.invert(geomMat);
169}
SkMatrix & postConcat(const SkMatrix &other)
Definition: SkMatrix.cpp:683
SkMatrix & postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:360
static SkMatrix MakeAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar pers0, SkScalar pers1, SkScalar pers2)
Definition: SkMatrix.h:179
bool invert(SkMatrix *inverse) const
Definition: SkMatrix.h:1206
SkMatrix & preConcat(const SkMatrix &other)
Definition: SkMatrix.cpp:674
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:315

Variable Documentation

◆ kCellSize

const int kCellSize = kImageSize+2*kLabelSize
static

Definition at line 49 of file flippity.cpp.

◆ kGMHeight

const int kGMHeight = 4*kCellSize
static

Definition at line 51 of file flippity.cpp.

◆ kGMWidth

const int kGMWidth = kNumMatrices*kCellSize
static

Definition at line 50 of file flippity.cpp.

◆ kImageSize

const int kImageSize = 128
static

Definition at line 44 of file flippity.cpp.

◆ kInset

const int kInset = 16
static

Definition at line 47 of file flippity.cpp.

◆ kLabelSize

const int kLabelSize = 32
static

Definition at line 45 of file flippity.cpp.

◆ kNumLabels

const int kNumLabels = 4
static

Definition at line 46 of file flippity.cpp.

◆ kNumMatrices

const int kNumMatrices = 6
static

Definition at line 43 of file flippity.cpp.

◆ kPoints

const SkPoint kPoints[kNumLabels]
static
Initial value:
= {
{ 0, kImageSize },
{ 0, 0 },
{ kImageSize, 0 },
}

Definition at line 53 of file flippity.cpp.

◆ kUVMatrices

const SkMatrix kUVMatrices[kNumMatrices]
static
Initial value:
= {
SkMatrix::MakeAll( 0, -1, 1,
-1, 0, 1,
0, 0, 1),
0, -1, 1,
0, 0, 1),
0, 1, 0,
0, 0, 1),
-1, 0, 1,
0, 0, 1),
0, -1, 1,
0, 0, 1),
0, 1, 0,
0, 0, 1)
}

Definition at line 60 of file flippity.cpp.