Skip to content

Commit

Permalink
Add DlSamplingOptions & DlFilterMode (flutter#34024)
Browse files Browse the repository at this point in the history
  • Loading branch information
JsouLiang authored Jun 17, 2022
1 parent 5540f88 commit e25d1ce
Show file tree
Hide file tree
Showing 49 changed files with 448 additions and 337 deletions.
1 change: 1 addition & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ FILE: ../../../flutter/display_list/display_list_paint_unittests.cc
FILE: ../../../flutter/display_list/display_list_path_effect.cc
FILE: ../../../flutter/display_list/display_list_path_effect.h
FILE: ../../../flutter/display_list/display_list_path_effect_unittests.cc
FILE: ../../../flutter/display_list/display_list_sampling_options.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_tile_mode.h
Expand Down
1 change: 1 addition & 0 deletions display_list/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ source_set("display_list") {
"display_list_paint.h",
"display_list_path_effect.cc",
"display_list_path_effect.h",
"display_list_sampling_options.h",
"display_list_tile_mode.h",
"display_list_utils.cc",
"display_list_utils.h",
Expand Down
9 changes: 0 additions & 9 deletions display_list/display_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@ const SaveLayerOptions SaveLayerOptions::kNoAttributes = SaveLayerOptions();
const SaveLayerOptions SaveLayerOptions::kWithAttributes =
kNoAttributes.with_renders_with_attributes();

const SkSamplingOptions DisplayList::NearestSampling =
SkSamplingOptions(SkFilterMode::kNearest, SkMipmapMode::kNone);
const SkSamplingOptions DisplayList::LinearSampling =
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kNone);
const SkSamplingOptions DisplayList::MipmapSampling =
SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear);
const SkSamplingOptions DisplayList::CubicSampling =
SkSamplingOptions(SkCubicResampler{1 / 3.0f, 1 / 3.0f});

DisplayList::DisplayList()
: byte_count_(0),
op_count_(0),
Expand Down
6 changes: 1 addition & 5 deletions display_list/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <optional>

#include "flutter/display_list/display_list_sampling_options.h"
#include "flutter/display_list/types.h"
#include "flutter/fml/logging.h"

Expand Down Expand Up @@ -216,11 +217,6 @@ class SaveLayerOptions {
// through an instance of DisplayListBuilder::build().
class DisplayList : public SkRefCnt {
public:
static const SkSamplingOptions NearestSampling;
static const SkSamplingOptions LinearSampling;
static const SkSamplingOptions MipmapSampling;
static const SkSamplingOptions CubicSampling;

DisplayList();

~DisplayList();
Expand Down
12 changes: 6 additions & 6 deletions display_list/display_list_benchmarks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ sk_sp<SkImage> ImageFromBitmapWithNewID(const SkBitmap& bitmap) {
void BM_DrawImage(benchmark::State& state,
BackendType backend_type,
unsigned attributes,
const SkSamplingOptions& options,
DlImageSampling options,
bool upload_bitmap) {
auto canvas_provider = CreateCanvasProvider(backend_type);
DisplayListBuilder builder;
Expand Down Expand Up @@ -1017,7 +1017,7 @@ std::string ConstraintToString(SkCanvas::SrcRectConstraint constraint) {
void BM_DrawImageRect(benchmark::State& state,
BackendType backend_type,
unsigned attributes,
const SkSamplingOptions& options,
DlImageSampling options,
SkCanvas::SrcRectConstraint constraint,
bool upload_bitmap) {
auto canvas_provider = CreateCanvasProvider(backend_type);
Expand Down Expand Up @@ -1083,11 +1083,11 @@ void BM_DrawImageRect(benchmark::State& state,
canvas_provider->Snapshot(filename);
}

std::string FilterModeToString(const SkFilterMode mode) {
std::string FilterModeToString(const DlFilterMode mode) {
switch (mode) {
case SkFilterMode::kNearest:
case DlFilterMode::kNearest:
return "Nearest";
case SkFilterMode::kLinear:
case DlFilterMode::kLinear:
return "Linear";
default:
return "Unknown";
Expand All @@ -1102,7 +1102,7 @@ std::string FilterModeToString(const SkFilterMode mode) {
void BM_DrawImageNine(benchmark::State& state,
BackendType backend_type,
unsigned attributes,
const SkFilterMode filter,
const DlFilterMode filter,
bool upload_bitmap) {
auto canvas_provider = CreateCanvasProvider(backend_type);
DisplayListBuilder builder;
Expand Down
27 changes: 14 additions & 13 deletions display_list/display_list_benchmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define FLUTTER_FLOW_DISPLAY_LIST_BENCHMARKS_H_

#include "flutter/display_list/display_list_benchmarks_canvas_provider.h"
#include "flutter/display_list/display_list_sampling_options.h"
#include "flutter/display_list/display_list_vertices.h"

#include "third_party/benchmark/include/benchmark/benchmark.h"
Expand Down Expand Up @@ -81,18 +82,18 @@ void BM_DrawVertices(benchmark::State& state,
void BM_DrawImage(benchmark::State& state,
BackendType backend_type,
unsigned attributes,
const SkSamplingOptions& options,
DlImageSampling options,
bool upload_bitmap);
void BM_DrawImageRect(benchmark::State& state,
BackendType backend_type,
unsigned attributes,
const SkSamplingOptions& options,
DlImageSampling options,
SkCanvas::SrcRectConstraint constraint,
bool upload_bitmap);
void BM_DrawImageNine(benchmark::State& state,
BackendType backend_type,
unsigned attributes,
const SkFilterMode filter,
const DlFilterMode filter,
bool upload_bitmap);
void BM_DrawTextBlob(benchmark::State& state,
BackendType backend_type,
Expand Down Expand Up @@ -331,7 +332,7 @@ void BM_SaveLayer(benchmark::State& state,
BENCHMARK_CAPTURE(BM_DrawImage, Texture/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkSamplingOptions(), false) \
DlImageSampling::kNearestNeighbor, false) \
->RangeMultiplier(2) \
->Range(128, 512) \
->UseRealTime() \
Expand All @@ -340,7 +341,7 @@ void BM_SaveLayer(benchmark::State& state,
BENCHMARK_CAPTURE(BM_DrawImage, Upload/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkSamplingOptions(), true) \
DlImageSampling::kNearestNeighbor, true) \
->RangeMultiplier(2) \
->Range(128, 512) \
->UseRealTime() \
Expand All @@ -352,7 +353,7 @@ void BM_SaveLayer(benchmark::State& state,
BM_DrawImageRect, Texture/Strict/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkSamplingOptions(), \
DlImageSampling::kNearestNeighbor, \
SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint, false) \
->RangeMultiplier(2) \
->Range(32, 256) \
Expand All @@ -363,7 +364,7 @@ void BM_SaveLayer(benchmark::State& state,
BM_DrawImageRect, Texture/Fast/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkSamplingOptions(), \
DlImageSampling::kNearestNeighbor, \
SkCanvas::SrcRectConstraint::kFast_SrcRectConstraint, false) \
->RangeMultiplier(2) \
->Range(32, 256) \
Expand All @@ -374,7 +375,7 @@ void BM_SaveLayer(benchmark::State& state,
BM_DrawImageRect, Upload/Strict/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkSamplingOptions(), \
DlImageSampling::kNearestNeighbor, \
SkCanvas::SrcRectConstraint::kStrict_SrcRectConstraint, true) \
->RangeMultiplier(2) \
->Range(32, 256) \
Expand All @@ -385,7 +386,7 @@ void BM_SaveLayer(benchmark::State& state,
BM_DrawImageRect, Upload/Fast/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkSamplingOptions(), \
DlImageSampling::kNearestNeighbor, \
SkCanvas::SrcRectConstraint::kFast_SrcRectConstraint, true) \
->RangeMultiplier(2) \
->Range(32, 256) \
Expand All @@ -397,7 +398,7 @@ void BM_SaveLayer(benchmark::State& state,
BENCHMARK_CAPTURE(BM_DrawImageNine, Texture/Nearest/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkFilterMode::kNearest, false) \
DlFilterMode::kNearest, false) \
->RangeMultiplier(2) \
->Range(32, 256) \
->UseRealTime() \
Expand All @@ -406,7 +407,7 @@ void BM_SaveLayer(benchmark::State& state,
BENCHMARK_CAPTURE(BM_DrawImageNine, Upload/Nearest/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkFilterMode::kNearest, true) \
DlFilterMode::kNearest, true) \
->RangeMultiplier(2) \
->Range(32, 256) \
->UseRealTime() \
Expand All @@ -415,7 +416,7 @@ void BM_SaveLayer(benchmark::State& state,
BENCHMARK_CAPTURE(BM_DrawImageNine, Texture/Linear/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkFilterMode::kLinear, false) \
DlFilterMode::kLinear, false) \
->RangeMultiplier(2) \
->Range(32, 256) \
->UseRealTime() \
Expand All @@ -424,7 +425,7 @@ void BM_SaveLayer(benchmark::State& state,
BENCHMARK_CAPTURE(BM_DrawImageNine, Upload/Linear/BACKEND, \
BackendType::k##BACKEND##_Backend, \
ATTRIBUTES, \
SkFilterMode::kLinear, true) \
DlFilterMode::kLinear, true) \
->RangeMultiplier(2) \
->Range(32, 256) \
->UseRealTime() \
Expand Down
18 changes: 9 additions & 9 deletions display_list/display_list_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ void DisplayListBuilder::drawVertices(const DlVertices* vertices,

void DisplayListBuilder::drawImage(const sk_sp<DlImage> image,
const SkPoint point,
const SkSamplingOptions& sampling,
DlImageSampling sampling,
bool render_with_attributes) {
render_with_attributes
? Push<DrawImageWithAttrOp>(0, 1, std::move(image), point, sampling)
Expand All @@ -861,7 +861,7 @@ void DisplayListBuilder::drawImage(const sk_sp<DlImage> image,
}
void DisplayListBuilder::drawImage(const sk_sp<DlImage> image,
const SkPoint point,
const SkSamplingOptions& sampling,
DlImageSampling sampling,
const DlPaint* paint) {
if (paint != nullptr) {
setAttributesFromDlPaint(*paint,
Expand All @@ -874,7 +874,7 @@ void DisplayListBuilder::drawImage(const sk_sp<DlImage> image,
void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
const SkRect& src,
const SkRect& dst,
const SkSamplingOptions& sampling,
DlImageSampling sampling,
bool render_with_attributes,
SkCanvas::SrcRectConstraint constraint) {
Push<DrawImageRectOp>(0, 1, std::move(image), src, dst, sampling,
Expand All @@ -884,7 +884,7 @@ void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
const SkRect& src,
const SkRect& dst,
const SkSamplingOptions& sampling,
DlImageSampling sampling,
const DlPaint* paint,
SkCanvas::SrcRectConstraint constraint) {
if (paint != nullptr) {
Expand All @@ -898,7 +898,7 @@ void DisplayListBuilder::drawImageRect(const sk_sp<DlImage> image,
void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
const SkIRect& center,
const SkRect& dst,
SkFilterMode filter,
DlFilterMode filter,
bool render_with_attributes) {
render_with_attributes
? Push<DrawImageNineWithAttrOp>(0, 1, std::move(image), center, dst,
Expand All @@ -909,7 +909,7 @@ void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
const SkIRect& center,
const SkRect& dst,
SkFilterMode filter,
DlFilterMode filter,
const DlPaint* paint) {
if (paint != nullptr) {
setAttributesFromDlPaint(*paint,
Expand All @@ -922,7 +922,7 @@ void DisplayListBuilder::drawImageNine(const sk_sp<DlImage> image,
void DisplayListBuilder::drawImageLattice(const sk_sp<DlImage> image,
const SkCanvas::Lattice& lattice,
const SkRect& dst,
SkFilterMode filter,
DlFilterMode filter,
bool render_with_attributes) {
int xDivCount = lattice.fXCount;
int yDivCount = lattice.fYCount;
Expand All @@ -947,7 +947,7 @@ void DisplayListBuilder::drawAtlas(const sk_sp<DlImage> atlas,
const DlColor colors[],
int count,
DlBlendMode mode,
const SkSamplingOptions& sampling,
DlImageSampling sampling,
const SkRect* cull_rect,
bool render_with_attributes) {
int bytes = count * (sizeof(SkRSXform) + sizeof(SkRect));
Expand Down Expand Up @@ -985,7 +985,7 @@ void DisplayListBuilder::drawAtlas(const sk_sp<DlImage> atlas,
const DlColor colors[],
int count,
DlBlendMode mode,
const SkSamplingOptions& sampling,
DlImageSampling sampling,
const SkRect* cull_rect,
const DlPaint* paint) {
if (paint != nullptr) {
Expand Down
Loading

0 comments on commit e25d1ce

Please sign in to comment.