Flutter Engine
The Flutter Engine
DDLRecorderBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2019 Google LLC
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 <memory>
9
10#include "bench/Benchmark.h"
11
16
18 size_t maxResourceBytes = direct->getResourceCacheLimit();
19
22 }
23
25 kPremul_SkAlphaType, nullptr);
26
29 if (!backendFormat.isValid()) {
31 }
32
34
36 direct->threadSafeProxy()->createCharacterization(maxResourceBytes,
37 ii,
38 backendFormat,
39 1,
41 props,
43 return c;
44}
45
46// This benchmark tries to simulate how Viz is using SkDDLRecorders.
47// For each config it will create a single DDLRecorder which it reuses for all the runs
48// For each run it creates a DDL and stores it for later deletion.
50public:
52
53protected:
55
56 const char* onGetName() override { return "DDLRecorder"; }
57
58 void onDraw(int loops, SkCanvas* origCanvas) override {
59 if (!fRecorder) {
60 return;
61 }
62
63 SkASSERT(!fDDLs.size());
64 fDDLs.reserve(loops);
65
66 for (int i = 0; i < loops; ++i) {
67 SkCanvas* recordingCanvas = fRecorder->getCanvas();
68
69 recordingCanvas->drawRect(SkRect::MakeWH(32, 32), SkPaint());
70
71 fDDLs.emplace_back(fRecorder->detach());
72 }
73 }
74
75private:
76 // We create one DDLRecorder for all the timing runs and just keep reusing it
77 void onPerCanvasPreDraw(SkCanvas* origCanvas) override {
78 auto context = origCanvas->recordingContext()->asDirectContext();
79 if (!context) {
80 return;
81 }
82
84
85 fRecorder = std::make_unique<GrDeferredDisplayListRecorder>(c);
86 }
87
88 // We defer the clean up of the DDLs so it is done outside of the timing loop
89 void onPostDraw(SkCanvas*) override {
90 fDDLs.clear();
91 }
92
93 std::unique_ptr<GrDeferredDisplayListRecorder> fRecorder = nullptr;
94 std::vector<sk_sp<GrDeferredDisplayList>> fDDLs;
95
96 using INHERITED = Benchmark;
97};
98
99DEF_BENCH(return new DDLRecorderBench();)
#define DEF_BENCH(code)
Definition: Benchmark.h:20
const char * backend
static GrSurfaceCharacterization create_characterization(GrDirectContext *direct)
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#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
@ kUnknown_SkPixelGeometry
bool isSuitableFor(Backend backend) override
const char * onGetName() override
void onDraw(int loops, SkCanvas *origCanvas) override
bool isValid() const
GrSurfaceCharacterization createCharacterization(size_t cacheMaxResourceBytes, const SkImageInfo &ii, const GrBackendFormat &backendFormat, int sampleCount, GrSurfaceOrigin origin, const SkSurfaceProps &surfaceProps, skgpu::Mipmapped isMipmapped, bool willUseGLFBO0=false, bool isTextureable=true, skgpu::Protected isProtected=GrProtected::kNo, bool vkRTSupportsInputAttachment=false, bool forVulkanSecondaryCommandBuffer=false)
virtual GrDirectContext * asDirectContext()
SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const
SK_API bool colorTypeSupportedAsSurface(SkColorType colorType) const
size_t getResourceCacheLimit() const
sk_sp< GrContextThreadSafeProxy > threadSafeProxy()
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609