Flutter Engine
The Flutter Engine
discard.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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"
15#include "include/core/SkSize.h"
22#include "src/base/SkRandom.h"
23#include "tools/ToolUtils.h"
24
25#if defined(SK_GRAPHITE)
27#endif
28
29namespace skiagm {
30
31/*
32 * This GM exercises SkCanvas::discard() by creating an offscreen SkSurface and repeatedly
33 * discarding it, drawing to it, and then drawing it to the main canvas.
34 */
35class DiscardGM : public GM {
36
37public:
39
40protected:
41 SkString getName() const override { return SkString("discard"); }
42
43 SkISize getISize() override { return SkISize::Make(100, 100); }
44
45 DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
46
47 SkISize size = this->getISize();
48 size.fWidth /= 10;
49 size.fHeight /= 10;
52
53 auto dContext = GrAsDirectContext(canvas->recordingContext());
54 if (dContext && !dContext->abandoned()) {
56 }
57
58#if defined(SK_GRAPHITE)
59 auto recorder = canvas->recorder();
60 if (recorder) {
62 }
63#endif
64
65 if (!surface) {
67 }
68 if (!surface) {
69 *errorMsg = "Could not create surface.";
70 return DrawResult::kFail;
71 }
72
73 canvas->clear(SK_ColorBLACK);
74
75 SkRandom rand;
76 for (int x = 0; x < 10; ++x) {
77 for (int y = 0; y < 10; ++y) {
78 surface->getCanvas()->discard();
79 // Make something that isn't too close to the background color, black.
80 SkColor color = ToolUtils::color_to_565(rand.nextU() | 0xFF404040);
81 switch (rand.nextULessThan(3)) {
82 case 0:
83 surface->getCanvas()->drawColor(color);
84 break;
85 case 1:
86 surface->getCanvas()->clear(color);
87 break;
88 case 2:
90 paint.setShader(SkShaders::Color(color));
91 surface->getCanvas()->drawPaint(paint);
92 break;
93 }
94 surface->draw(canvas, 10.f*x, 10.f*y);
95 }
96 }
97
98 surface->getCanvas()->discard();
99 return DrawResult::kOk;
100 }
101};
102
103//////////////////////////////////////////////////////////////////////////////
104
105DEF_GM(return new DiscardGM;)
106
107} // namespace skiagm
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
void clear(SkColor color)
Definition: SkCanvas.h:1199
uint32_t nextU()
Definition: SkRandom.h:42
uint32_t nextULessThan(uint32_t count)
Definition: SkRandom.h:93
DrawResult onDraw(SkCanvas *canvas, SkString *errorMsg) override
Definition: discard.cpp:45
SkString getName() const override
Definition: discard.cpp:41
SkISize getISize() override
Definition: discard.cpp:43
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
DlColor color
VkSurfaceKHR surface
Definition: main.cc:49
double y
double x
SK_API sk_sp< SkShader > Color(SkColor)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139
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
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
DrawResult
Definition: gm.h:104
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
int32_t fWidth
Definition: SkSize.h:17
static SkImageInfo MakeN32Premul(int width, int height)