OLD | NEW |
---|---|
(Empty) | |
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 "Benchmark.h" | |
9 #include "SkCanvas.h" | |
10 #include "SkImage.h" | |
11 #include "SkPaint.h" | |
12 #include "SkSurface.h" | |
13 | |
14 #if SK_SUPPORT_GPU | |
15 | |
16 class GrMipMapBench: public Benchmark { | |
17 sk_sp<SkSurface> fSurface; | |
18 SkString fName; | |
19 const int fW, fH; | |
20 | |
21 public: | |
22 GrMipMapBench(int w, int h) : fW(w), fH(h) { | |
23 fName.printf("gr_mipmap_build_%dx%d", w, h); | |
24 } | |
25 | |
26 protected: | |
27 bool isSuitableFor(Backend backend) override { | |
28 return kGPU_Backend == backend; | |
29 } | |
30 | |
31 const char* onGetName() override { return fName.c_str(); } | |
32 | |
33 void onDraw(int loops, SkCanvas* canvas) override { | |
34 if (!fSurface) { | |
35 GrContext* context = canvas->getGrContext(); | |
36 if (nullptr == context) { | |
bsalomon
2016/06/01 19:37:29
you can just say !context if you prefer, but it do
| |
37 return; | |
38 } | |
39 SkImageInfo info = SkImageInfo::Make(fW, fH, kN32_SkColorType, kPrem ul_SkAlphaType, | |
40 kSRGB_SkColorProfileType); | |
41 fSurface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, inf o); | |
42 } | |
43 | |
44 // Clear surface once: | |
45 fSurface->getCanvas()->clear(SK_ColorBLACK); | |
46 | |
47 SkPaint paint; | |
48 paint.setFilterQuality(kMedium_SkFilterQuality); | |
49 | |
50 for (int i = 0; i < loops; i++) { | |
51 // Touch surface so mips are dirtied | |
52 fSurface->getCanvas()->drawPoint(0, 0, SK_ColorWHITE); | |
53 | |
54 // Draw reduced version of surface to original canvas, to trigger mi p generation | |
55 canvas->save(); | |
56 canvas->scale(0.1f, 0.1f); | |
57 canvas->drawImage(fSurface->makeImageSnapshot(SkBudgeted::kNo), 0, 0 , &paint); | |
58 canvas->restore(); | |
59 } | |
60 } | |
61 | |
62 private: | |
63 typedef Benchmark INHERITED; | |
64 }; | |
65 | |
66 // Build variants that exercise the width and heights being even or odd at each level, as the | |
67 // impl specializes on each of these. | |
68 // | |
69 DEF_BENCH( return new GrMipMapBench(511, 1023); ) | |
70 DEF_BENCH( return new GrMipMapBench(512, 511); ) | |
71 DEF_BENCH( return new GrMipMapBench(511, 512); ) | |
72 DEF_BENCH( return new GrMipMapBench(512, 512); ) | |
73 | |
74 #endif | |
OLD | NEW |