Skip to content

Commit

Permalink
Move SoftwareCanvasProvider into its own source file (flutter#30856)
Browse files Browse the repository at this point in the history
  • Loading branch information
George Wright authored Jan 13, 2022
1 parent 4499797 commit fcf7458
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ FILE: ../../../flutter/display_list/display_list_benchmarks.cc
FILE: ../../../flutter/display_list/display_list_benchmarks.h
FILE: ../../../flutter/display_list/display_list_benchmarks_gl.cc
FILE: ../../../flutter/display_list/display_list_benchmarks_metal.cc
FILE: ../../../flutter/display_list/display_list_benchmarks_software.cc
FILE: ../../../flutter/display_list/display_list_builder.cc
FILE: ../../../flutter/display_list/display_list_builder.h
FILE: ../../../flutter/display_list/display_list_canvas_dispatcher.cc
Expand Down
1 change: 1 addition & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ if (enable_unittests) {
sources = [
"display_list_benchmarks.cc",
"display_list_benchmarks.h",
"display_list_benchmarks_software.cc",
]

deps = [
Expand Down
25 changes: 0 additions & 25 deletions display_list/display_list_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,6 @@
namespace flutter {
namespace testing {

class SoftwareCanvasProvider : public CanvasProvider {
public:
virtual ~SoftwareCanvasProvider() = default;
void InitializeSurface(const size_t width, const size_t height) override {
surface_ = SkSurface::MakeRasterN32Premul(width, height);
surface_->getCanvas()->clear(SK_ColorTRANSPARENT);
}

sk_sp<SkSurface> GetSurface() override { return surface_; }

sk_sp<SkSurface> MakeOffscreenSurface(const size_t width,
const size_t height) override {
auto surface = SkSurface::MakeRasterN32Premul(width, height);
surface->getCanvas()->clear(SK_ColorTRANSPARENT);
return surface;
}

const std::string BackendName() override { return "Software"; }

private:
sk_sp<SkSurface> surface_;
};

// Constants chosen to produce benchmark results in the region of 1-50ms
constexpr size_t kLinesToDraw = 10000;
constexpr size_t kRectsToDraw = 5000;
Expand Down Expand Up @@ -1054,7 +1031,5 @@ void BM_DrawShadow(benchmark::State& state,
canvas_provider->Snapshot(filename);
}

RUN_DISPLAYLIST_BENCHMARKS(Software)

} // namespace testing
} // namespace flutter
39 changes: 39 additions & 0 deletions display_list/display_list_benchmarks_software.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/display_list/display_list_benchmarks.h"
#include "flutter/display_list/display_list_builder.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "third_party/skia/include/core/SkTextBlob.h"

namespace flutter {
namespace testing {

class SoftwareCanvasProvider : public CanvasProvider {
public:
virtual ~SoftwareCanvasProvider() = default;
void InitializeSurface(const size_t width, const size_t height) override {
surface_ = SkSurface::MakeRasterN32Premul(width, height);
surface_->getCanvas()->clear(SK_ColorTRANSPARENT);
}

sk_sp<SkSurface> GetSurface() override { return surface_; }

sk_sp<SkSurface> MakeOffscreenSurface(const size_t width,
const size_t height) override {
auto surface = SkSurface::MakeRasterN32Premul(width, height);
surface->getCanvas()->clear(SK_ColorTRANSPARENT);
return surface;
}

const std::string BackendName() override { return "Software"; }

private:
sk_sp<SkSurface> surface_;
};

RUN_DISPLAYLIST_BENCHMARKS(Software)

} // namespace testing
} // namespace flutter

0 comments on commit fcf7458

Please sign in to comment.