1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_FLOW_DISPLAY_LIST_BENCHMARKING_DL_COMPLEXITY_H_
6#define FLUTTER_FLOW_DISPLAY_LIST_BENCHMARKING_DL_COMPLEXITY_H_
7
8#include "flutter/display_list/display_list.h"
9
10#include "third_party/skia/include/gpu/GrTypes.h"
11
12namespace flutter {
13
14class DisplayListComplexityCalculator {
15 public:
16 static DisplayListComplexityCalculator* GetForSoftware();
17 static DisplayListComplexityCalculator* GetForBackend(GrBackendApi backend);
18
19 virtual ~DisplayListComplexityCalculator() = default;
20
21 // Returns a calculated complexity score for a given DisplayList object
22 virtual unsigned int Compute(const DisplayList* display_list) = 0;
23
24 // Returns whether a given complexity score meets the threshold for
25 // cacheability for this particular ComplexityCalculator
26 virtual bool ShouldBeCached(unsigned int complexity_score) = 0;
27
28 // Sets a ceiling for the complexity score being calculated. By default
29 // this is the largest number representable by an unsigned int.
30 //
31 // This setting has no effect on non-accumulator based scorers such as
32 // the Naive calculator.
33 virtual void SetComplexityCeiling(unsigned int ceiling) = 0;
34};
35
36class DisplayListNaiveComplexityCalculator
37 : public DisplayListComplexityCalculator {
38 public:
39 static DisplayListComplexityCalculator* GetInstance();
40
41 unsigned int Compute(const DisplayList* display_list) override {
42 return display_list->op_count(nested: true);
43 }
44
45 bool ShouldBeCached(unsigned int complexity_score) override {
46 return complexity_score > 5u;
47 }
48
49 void SetComplexityCeiling(unsigned int ceiling) override {}
50
51 private:
52 DisplayListNaiveComplexityCalculator() {}
53 static DisplayListNaiveComplexityCalculator* instance_;
54};
55
56} // namespace flutter
57
58#endif // FLUTTER_FLOW_DISPLAY_LIST_BENCHMARKING_DL_COMPLEXITY_H_
59

source code of flutter_engine/flutter/display_list/benchmarking/dl_complexity.h