Flutter Engine
The Flutter Engine
verylargebitmap.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
18#include "include/core/SkRect.h"
22#include "include/core/SkSize.h"
28#include "tools/ToolUtils.h"
29
30static void draw(SkCanvas* canvas, int width, int height, SkColor colors[2]) {
32 const SkScalar radius = 40;
34 paint.setShader(SkGradientShader::MakeRadial(center, radius, colors, nullptr, 2,
36 paint.setBlendMode(SkBlendMode::kSrc);
37 canvas->drawPaint(paint);
38}
39
42 draw(surface->getCanvas(), width, height, colors);
43 return surface->makeImageSnapshot();
44}
45
47 SkPictureRecorder recorder;
50 {width, height},
51 nullptr,
52 nullptr,
55}
56
58
59static void show_image(SkCanvas* canvas, int width, int height, SkColor colors[2],
60 ImageMakerProc proc, bool manuallyTile) {
62 if (!image) {
63 return;
64 }
65
66 SkPaint borderPaint;
67
69
70 SkRect dstRect = SkRect::MakeWH(128.f, 128.f);
71
72 canvas->save();
73 canvas->clipRect(dstRect);
74 if (manuallyTile) {
76 } else {
77 canvas->drawImage(image, 0, 0);
78 }
79 canvas->restore();
80 canvas->drawRect(dstRect, borderPaint);
81
82 dstRect.offset(SkIntToScalar(150), 0);
83 int hw = width / 2;
84 int hh = height / 2;
85 SkRect subset = SkRect::MakeLTRB(hw - 64, hh - 32, hw + 64, hh + 32);
86 if (manuallyTile) {
87 SkTiledImageUtils::DrawImageRect(canvas, image, subset, dstRect, {}, nullptr,
89 } else {
90 canvas->drawImageRect(image, subset, dstRect, {}, nullptr,
92 }
93 canvas->drawRect(dstRect, borderPaint);
94
95 dstRect.offset(SkIntToScalar(150), 0);
96 if (manuallyTile) {
98 } else {
99 canvas->drawImageRect(image, dstRect, {});
100 }
101 canvas->drawRect(dstRect, borderPaint);
102}
103
105 ImageMakerProc fProc;
106 const char* fBaseName;
107 bool fManuallyTile;
108
109public:
110 VeryLargeBitmapGM(ImageMakerProc proc, const char baseName[], bool manuallyTile)
111 : fProc(proc)
112 , fBaseName(baseName)
113 , fManuallyTile(manuallyTile) {}
114
115private:
116 SkString getName() const override {
117 SkString name(fBaseName);
118
119 if (fManuallyTile) {
120 name.append("_manual");
121 }
122
123 return name;
124 }
125
126 SkISize getISize() override { return {500, 600}; }
127
128 void onDraw(SkCanvas* canvas) override {
129 int veryBig = 65*1024; // 64K < size
130 int big = 33*1024; // 32K < size < 64K
131 // smaller than many max texture sizes, but large enough to gpu-tile for memory reasons.
132 int medium = 5*1024;
133 int small = 150;
134
135 SkColor colors[2];
136
137 canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
138 colors[0] = SK_ColorRED;
140 show_image(canvas, small, small, colors, fProc, fManuallyTile);
141 canvas->translate(0, SkIntToScalar(150));
142
143 colors[0] = SK_ColorBLUE;
145 show_image(canvas, big, small, colors, fProc, fManuallyTile);
146 canvas->translate(0, SkIntToScalar(150));
147
150 show_image(canvas, medium, medium, colors, fProc, fManuallyTile);
151 canvas->translate(0, SkIntToScalar(150));
152
155 // This used to be big enough that we didn't draw on CPU, but now we do.
156 show_image(canvas, veryBig, small, colors, fProc, fManuallyTile);
157 }
158};
159
160DEF_GM( return new VeryLargeBitmapGM(make_raster_image, "verylargebitmap",
161 /* manuallyTile= */ false); )
162DEF_GM( return new VeryLargeBitmapGM(make_raster_image, "verylargebitmap",
163 /* manuallyTile= */ true); )
164DEF_GM( return new VeryLargeBitmapGM(make_picture_image, "verylarge_picture_image",
165 /* manuallyTile= */ false); )
166DEF_GM( return new VeryLargeBitmapGM(make_picture_image, "verylarge_picture_image",
167 /* manuallyTile= */ true); )
IsFiniteProc fProc
Definition: MathBench.cpp:219
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static SkScalar center(float pos0, float pos1)
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
@ kStrict_SrcRectConstraint
sample only inside bounds; slower
Definition: SkCanvas.h:1542
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
void setStyle(Style style)
Definition: SkPaint.cpp:105
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
VeryLargeBitmapGM(ImageMakerProc proc, const char baseName[], bool manuallyTile)
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
float SkScalar
Definition: extension.cpp:12
SK_API sk_sp< SkImage > DeferredFromPicture(sk_sp< SkPicture > picture, const SkISize &dimensions, const SkMatrix *matrix, const SkPaint *paint, BitDepth bitDepth, sk_sp< SkColorSpace > colorSpace, SkSurfaceProps props)
@ kU8
uses 8-bit unsigned int per color component
sk_sp< const SkImage > image
Definition: SkRecords.h:269
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
void DrawImage(SkCanvas *canvas, const SkImage *image, SkScalar x, SkScalar y, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
SK_API void DrawImageRect(SkCanvas *canvas, const SkImage *image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
int32_t height
int32_t width
Definition: SkSize.h:16
static SkImageInfo MakeN32Premul(int width, int height)
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
void offset(float dx, float dy)
Definition: SkRect.h:1016
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
static void show_image(SkCanvas *canvas, int width, int height, SkColor colors[2], ImageMakerProc proc, bool manuallyTile)
static void draw(SkCanvas *canvas, int width, int height, SkColor colors[2])
sk_sp< SkImage >(* ImageMakerProc)(int width, int height, SkColor colors[2])
static sk_sp< SkImage > make_raster_image(int width, int height, SkColor colors[2])
static sk_sp< SkImage > make_picture_image(int width, int height, SkColor colors[2])
DEF_GM(return new VeryLargeBitmapGM(make_raster_image, "verylargebitmap", false);) DEF_GM(return new VeryLargeBitmapGM(make_raster_image