Flutter Engine
The Flutter Engine
Functions
mipmap.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorSpace.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/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"

Go to the source code of this file.

Functions

static sk_sp< SkImagemake_image ()
 
 DEF_SIMPLE_GM (mipmap, canvas, 400, 200)
 
static sk_sp< SkImagemake (sk_sp< SkColorSpace > cs)
 
static void show_mips (SkCanvas *canvas, SkImage *img)
 
 DEF_SIMPLE_GM (mipmap_srgb, canvas, 260, 230)
 
static sk_sp< SkImagemake_g8_gradient (sk_sp< SkColorSpace > cs)
 
static void show_mips_only (SkCanvas *canvas, SkImage *img)
 
 DEF_SIMPLE_GM (mipmap_gray8_srgb, canvas, 260, 230)
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/3]

DEF_SIMPLE_GM ( mipmap  ,
canvas  ,
400  ,
200   
)

Definition at line 38 of file mipmap.cpp.

38 {
39 sk_sp<SkImage> img(make_image());//SkImage::NewFromEncoded(data));
40
41 const SkRect dst = SkRect::MakeWH(177, 15);
42
43 SkString str;
44 str.printf("scale %g %g", dst.width() / img->width(), dst.height() / img->height());
45// canvas->drawString(str, 300, 100, SkFont(nullptr, 30), paint);
46
47 const SkSamplingOptions samplings[] = {
52 };
53
54 canvas->translate(20, 20);
55 for (size_t i = 0; i < std::size(samplings); ++i) {
56 canvas->drawImageRect(img.get(), dst, samplings[i], nullptr);
57 canvas->translate(0, 20);
58 }
59 canvas->drawImage(img.get(), 20, 20);
60}
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
static sk_sp< SkImage > make_image()
Definition: mipmap.cpp:21
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
dst
Definition: cp.py:12
SkSamplingOptions(SkFilterMode::kLinear))
static constexpr SkCubicResampler Mitchell()
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ DEF_SIMPLE_GM() [2/3]

DEF_SIMPLE_GM ( mipmap_gray8_srgb  ,
canvas  ,
260  ,
230   
)

Definition at line 150 of file mipmap.cpp.

150 {
151 sk_sp<SkImage> limg = make_g8_gradient(nullptr);
153
154 canvas->translate(10, 10);
155 show_mips_only(canvas, limg.get());
156 canvas->translate(0, limg->height() + 10.0f);
157 show_mips_only(canvas, simg.get());
158}
static sk_sp< SkColorSpace > MakeSRGB()
int height() const
Definition: SkImage.h:291
T * get() const
Definition: SkRefCnt.h:303
static sk_sp< SkImage > make_g8_gradient(sk_sp< SkColorSpace > cs)
Definition: mipmap.cpp:114
static void show_mips_only(SkCanvas *canvas, SkImage *img)
Definition: mipmap.cpp:129

◆ DEF_SIMPLE_GM() [3/3]

DEF_SIMPLE_GM ( mipmap_srgb  ,
canvas  ,
260  ,
230   
)

Definition at line 101 of file mipmap.cpp.

101 {
102 sk_sp<SkImage> limg = make(nullptr);
104
105 canvas->translate(10, 10);
106 show_mips(canvas, limg.get());
107 canvas->translate(0, limg->height() + 10.0f);
108 show_mips(canvas, simg.get());
109}
static sk_sp< SkImage > make(sk_sp< SkColorSpace > cs)
Definition: mipmap.cpp:65
static void show_mips(SkCanvas *canvas, SkImage *img)
Definition: mipmap.cpp:80

◆ make()

static sk_sp< SkImage > make ( sk_sp< SkColorSpace cs)
static

Definition at line 65 of file mipmap.cpp.

65 {
66 const int N = 100;
67 SkImageInfo info = SkImageInfo::Make(N, N, kN32_SkColorType, kPremul_SkAlphaType, cs);
68 SkBitmap bm;
69 bm.allocPixels(info);
70
71 for (int y = 0; y < N; ++y) {
72 for (int x = 0; x < N; ++x) {
73 *bm.getAddr32(x, y) = (x ^ y) & 1 ? 0xFFFFFFFF : 0xFF000000;
74 }
75 }
76 bm.setImmutable();
77 return bm.asImage();
78}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define N
Definition: beziers.cpp:19
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void setImmutable()
Definition: SkBitmap.cpp:400
uint32_t * getAddr32(int x, int y) const
Definition: SkBitmap.h:1260
double y
double x
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ make_g8_gradient()

static sk_sp< SkImage > make_g8_gradient ( sk_sp< SkColorSpace cs)
static

Definition at line 114 of file mipmap.cpp.

114 {
115 const int N = 100;
117 SkBitmap bm;
118 bm.allocPixels(info);
119
120 for (int y = 0; y < N; ++y) {
121 for (int x = 0; x < N; ++x) {
122 *bm.getAddr8(x, y) = static_cast<uint8_t>(255.0f * ((x + y) / (2.0f * (N - 1))));
123 }
124 }
125 bm.setImmutable();
126 return bm.asImage();
127}
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:35
uint8_t * getAddr8(int x, int y) const
Definition: SkBitmap.h:1270

◆ make_image()

static sk_sp< SkImage > make_image ( )
static

Definition at line 21 of file mipmap.cpp.

21 {
24 SkCanvas* canvas = surface->getCanvas();
25 canvas->drawColor(0xFFF8F8F8);
26
28 paint.setAntiAlias(true);
29
31 for (int i = 0; i < 20; ++i) {
32 canvas->drawCircle(-4, 25, 20, paint);
33 canvas->translate(25, 0);
34 }
35 return surface->makeImageSnapshot();
36}
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)

◆ show_mips()

static void show_mips ( SkCanvas canvas,
SkImage img 
)
static

Definition at line 80 of file mipmap.cpp.

80 {
83
84 // Want to ensure we never draw fractional pixels, so we use an IRect
85 SkIRect dst = SkIRect::MakeWH(img->width(), img->height());
86 while (dst.width() > 5) {
87 canvas->drawImageRect(img, SkRect::Make(dst), sampling, nullptr);
88 dst.offset(dst.width() + 10, 0);
89 dst.fRight = dst.fLeft + dst.width()/2;
90 dst.fBottom = dst.fTop + dst.height()/2;
91 }
92}
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
int width() const
Definition: SkImage.h:285
SkSamplingOptions sampling
Definition: SkRecords.h:337
Definition: SkRect.h:32
static constexpr SkIRect MakeWH(int32_t w, int32_t h)
Definition: SkRect.h:56
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669

◆ show_mips_only()

static void show_mips_only ( SkCanvas canvas,
SkImage img 
)
static

Definition at line 129 of file mipmap.cpp.

129 {
132
133 // Want to ensure we never draw fractional pixels, so we use an IRect
134 SkIRect dst = SkIRect::MakeWH(img->width() / 2, img->height() / 2);
135 while (dst.width() > 5) {
136 canvas->drawImageRect(img, SkRect::Make(dst), sampling, nullptr);
137 dst.offset(dst.width() + 10, 0);
138 dst.fRight = dst.fLeft + dst.width() / 2;
139 dst.fBottom = dst.fTop + dst.height() / 2;
140 }
141}