Skip to content

Commit

Permalink
Add a complexity scoring class for Metal and OpenGL (flutter#31417)
Browse files Browse the repository at this point in the history
  • Loading branch information
George Wright authored Feb 18, 2022
1 parent 1932fb9 commit d476e7a
Show file tree
Hide file tree
Showing 15 changed files with 2,358 additions and 72 deletions.
8 changes: 8 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,20 @@ FILE: ../../../flutter/display_list/display_list_color_filter.h
FILE: ../../../flutter/display_list/display_list_color_filter_unittests.cc
FILE: ../../../flutter/display_list/display_list_complexity.cc
FILE: ../../../flutter/display_list/display_list_complexity.h
FILE: ../../../flutter/display_list/display_list_complexity_gl.cc
FILE: ../../../flutter/display_list/display_list_complexity_gl.h
FILE: ../../../flutter/display_list/display_list_complexity_helper.h
FILE: ../../../flutter/display_list/display_list_complexity_metal.cc
FILE: ../../../flutter/display_list/display_list_complexity_metal.h
FILE: ../../../flutter/display_list/display_list_complexity_unittests.cc
FILE: ../../../flutter/display_list/display_list_dispatcher.cc
FILE: ../../../flutter/display_list/display_list_dispatcher.h
FILE: ../../../flutter/display_list/display_list_flags.cc
FILE: ../../../flutter/display_list/display_list_flags.h
FILE: ../../../flutter/display_list/display_list_ops.cc
FILE: ../../../flutter/display_list/display_list_ops.h
FILE: ../../../flutter/display_list/display_list_test_utils.cc
FILE: ../../../flutter/display_list/display_list_test_utils.h
FILE: ../../../flutter/display_list/display_list_unittests.cc
FILE: ../../../flutter/display_list/display_list_utils.cc
FILE: ../../../flutter/display_list/display_list_utils.h
Expand Down
7 changes: 7 additions & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ source_set("display_list") {
"display_list_color_filter.h",
"display_list_complexity.cc",
"display_list_complexity.h",
"display_list_complexity_gl.cc",
"display_list_complexity_gl.h",
"display_list_complexity_metal.cc",
"display_list_complexity_metal.h",
"display_list_dispatcher.cc",
"display_list_dispatcher.h",
"display_list_flags.cc",
Expand All @@ -43,6 +47,9 @@ source_set("unittests") {
sources = [
"display_list_canvas_unittests.cc",
"display_list_color_filter_unittests.cc",
"display_list_complexity_unittests.cc",
"display_list_test_utils.cc",
"display_list_test_utils.h",
"display_list_unittests.cc",
]

Expand Down
6 changes: 6 additions & 0 deletions display_list/display_list_complexity.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "flutter/display_list/display_list_complexity.h"
#include "flutter/display_list/display_list.h"
#include "flutter/display_list/display_list_complexity_gl.h"
#include "flutter/display_list/display_list_complexity_metal.h"

namespace flutter {

Expand All @@ -21,6 +23,10 @@ DisplayListNaiveComplexityCalculator::GetInstance() {
DisplayListComplexityCalculator* DisplayListComplexityCalculator::GetForBackend(
GrBackendApi backend) {
switch (backend) {
case GrBackendApi::kMetal:
return DisplayListMetalComplexityCalculator::GetInstance();
case GrBackendApi::kOpenGL:
return DisplayListGLComplexityCalculator::GetInstance();
default:
return DisplayListNaiveComplexityCalculator::GetInstance();
}
Expand Down
17 changes: 13 additions & 4 deletions display_list/display_list_complexity.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,35 @@ class DisplayListComplexityCalculator {
virtual ~DisplayListComplexityCalculator() = default;

// Returns a calculated complexity score for a given DisplayList object
virtual unsigned int compute(DisplayList* display_list) = 0;
virtual unsigned int Compute(DisplayList* display_list) = 0;

// Returns whether a given complexity score meets the threshold for
// cacheability for this particular ComplexityCalculator
virtual bool should_be_cached(unsigned int complexity_score) = 0;
virtual bool ShouldBeCached(unsigned int complexity_score) = 0;

// Sets a ceiling for the complexity score being calculated. By default
// this is the largest number representable by an unsigned int.
//
// This setting has no effect on non-accumulator based scorers such as
// the Naive calculator.
virtual void SetComplexityCeiling(unsigned int ceiling) = 0;
};

class DisplayListNaiveComplexityCalculator
: public DisplayListComplexityCalculator {
public:
static DisplayListComplexityCalculator* GetInstance();

unsigned int compute(DisplayList* display_list) override {
unsigned int Compute(DisplayList* display_list) override {
return display_list->op_count(true);
}

bool should_be_cached(unsigned int complexity_score) override {
bool ShouldBeCached(unsigned int complexity_score) override {
return complexity_score > 5u;
}

void SetComplexityCeiling(unsigned int ceiling) override {}

private:
DisplayListNaiveComplexityCalculator() {}
static DisplayListNaiveComplexityCalculator* instance_;
Expand Down
Loading

0 comments on commit d476e7a

Please sign in to comment.