Flutter Engine
The Flutter Engine
showmiplevels.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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"
16#include "include/core/SkRect.h"
20#include "include/core/SkSize.h"
23#include "src/core/SkMipmap.h"
25#include "tools/DecodeUtils.h"
26#include "tools/Resources.h"
27#include "tools/ToolUtils.h"
28
29#include <math.h>
30
31class ShowMipLevels3 : public skiagm::GM {
32 sk_sp<SkImage> fImg;
33
34 SkString getName() const override { return SkString("showmiplevels_explicit"); }
35
36 SkISize getISize() override { return {1130, 970}; }
37
38 void onOnceBeforeDraw() override {
39 fImg = ToolUtils::GetResourceAsImage("images/ship.png");
40 fImg = fImg->makeRasterImage(); // makeWithMips only works on raster for now
41
43
45 for (int i = 0; i < builder.countLevels(); ++i) {
46 auto surf = SkSurfaces::WrapPixels(builder.level(i));
47 surf->getCanvas()->drawColor(colors[i % std::size(colors)]);
48 }
49 fImg = builder.attachTo(fImg);
50 }
51
52 DrawResult onDraw(SkCanvas* canvas, SkString*) override {
53 canvas->drawColor(0xFFDDDDDD);
54
55 canvas->translate(10, 10);
58 canvas->translate(0, draw_downscaling(canvas, {fm, mm}));
59 }
60 }
61 return DrawResult::kOk;
62 }
63
64private:
65 SkScalar draw_downscaling(SkCanvas* canvas, SkSamplingOptions sampling) {
66 SkAutoCanvasRestore acr(canvas, true);
67
69 SkRect r = {0, 0, 150, 150};
70 for (float scale = 1; scale >= 0.1f; scale *= 0.7f) {
73 sampling, &matrix));
74 canvas->drawRect(r, paint);
75 canvas->translate(r.width() + 10, 0);
76 }
77 return r.height() + 10;
78 }
79
80 using INHERITED = skiagm::GM;
81};
82DEF_GM( return new ShowMipLevels3; )
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
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition: SkImage.cpp:267
const SkImageInfo & imageInfo() const
Definition: SkImage.h:279
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
PODArray< SkColor > colors
Definition: SkRecords.h:276
SkSamplingOptions sampling
Definition: SkRecords.h:337
SK_API sk_sp< SkSurface > WrapPixels(const SkImageInfo &imageInfo, void *pixels, size_t rowBytes, const SkSurfaceProps *surfaceProps=nullptr)
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
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
DrawResult
Definition: gm.h:104
const Scalar scale
Definition: SkSize.h:16
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762