Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GpuRectanizerTest.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
11#include "src/base/SkRandom.h"
12#include "src/core/SkIPoint16.h"
13#include "src/gpu/Rectanizer.h"
17#include "tests/Test.h"
18
19struct GrContextOptions;
20
21using namespace skgpu;
22
23static const int kWidth = 1024;
24static const int kHeight = 1024;
25
26// Basic test of a Rectanizer-derived class' functionality
28 REPORTER_ASSERT(reporter, kWidth == rectanizer->width());
29 REPORTER_ASSERT(reporter, kHeight == rectanizer->height());
30
31 SkIPoint16 loc;
32
33 REPORTER_ASSERT(reporter, rectanizer->addRect(50, 50, &loc));
34 REPORTER_ASSERT(reporter, rectanizer->percentFull() > 0.0f);
35 rectanizer->reset();
36 REPORTER_ASSERT(reporter, rectanizer->percentFull() == 0.0f);
37}
38
40 Rectanizer* rectanizer,
41 const SkTDArray<SkISize>& rects) {
42 int i;
43 for (i = 0; i < rects.size(); ++i) {
44 SkIPoint16 loc;
45 if (!rectanizer->addRect(rects[i].fWidth, rects[i].fHeight, &loc)) {
46 break;
47 }
48 }
49
50 //SkDebugf("\n***%d %f\n", i, rectanizer->percentFull());
51}
52
54 RectanizerSkyline skylineRectanizer(kWidth, kHeight);
55
56 test_rectanizer_basic(reporter, &skylineRectanizer);
57 test_rectanizer_inserts(reporter, &skylineRectanizer, rects);
58}
59
61 RectanizerPow2 pow2Rectanizer(kWidth, kHeight);
62
63 test_rectanizer_basic(reporter, &pow2Rectanizer);
64 test_rectanizer_inserts(reporter, &pow2Rectanizer, rects);
65}
66
69 SkRandom rand;
70
71 for (int i = 0; i < 50; i++) {
72 rects.push_back(SkISize::Make(rand.nextRangeU(1, kWidth / 2),
73 rand.nextRangeU(1, kHeight / 2)));
74 }
75
76 test_skyline(reporter, rects);
77 test_pow2(reporter, rects);
78}
reporter
static void test_skyline(skiatest::Reporter *reporter, const SkTDArray< SkISize > &rects)
static const int kHeight
static void test_rectanizer_inserts(skiatest::Reporter *, Rectanizer *rectanizer, const SkTDArray< SkISize > &rects)
static const int kWidth
static void test_pow2(skiatest::Reporter *reporter, const SkTDArray< SkISize > &rects)
static void test_rectanizer_basic(skiatest::Reporter *reporter, Rectanizer *rectanizer)
#define DEF_GANESH_TEST(name, reporter, options, ctsEnforcement)
Definition Test.h:393
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
uint32_t nextRangeU(uint32_t min, uint32_t max)
Definition SkRandom.h:80
int size() const
Definition SkTDArray.h:138
void push_back(const T &v)
Definition SkTDArray.h:219
virtual void reset()=0
int width() const
Definition Rectanizer.h:26
int height() const
Definition Rectanizer.h:27
virtual float percentFull() const =0
virtual bool addRect(int width, int height, SkIPoint16 *loc)=0
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20