52337de95c
PS2 adds a rewrite for Skia #include <...> to #include "...", letting them be otherwise rewritten and sorted too. (We do need one exception for the Vulkan headers, which will otherwise be rewritten to always point to our own.) I don't think it's particularly important to favor "" or <>, but picking one keeps things consistent. PS3 adds a missing SkMutex.h include. PS4 fixes a terrible readability problem. Change-Id: Id9fe752727ef30e802b1daf755ee2ed15e267577 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229742 Commit-Queue: Mike Klein <mtklein@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Auto-Submit: Mike Klein <mtklein@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
65 lines
2.3 KiB
C++
65 lines
2.3 KiB
C++
// Copyright 2019 Google LLC.
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)
|
|
|
|
#include "modules/skparagraph/include/FontCollection.h"
|
|
#include "modules/skparagraph/include/Paragraph.h"
|
|
#include "modules/skparagraph/src/ParagraphBuilderImpl.h"
|
|
#include "modules/skparagraph/src/ParagraphImpl.h"
|
|
#include "tools/Resources.h"
|
|
|
|
#include <cfloat>
|
|
#include "include/core/SkPictureRecorder.h"
|
|
#include "modules/skparagraph/utils/TestFontCollection.h"
|
|
|
|
using namespace skia::textlayout;
|
|
namespace {
|
|
struct ParagraphBench : public Benchmark {
|
|
ParagraphBench(SkScalar width, const char* r, const char* n)
|
|
: fResource(r), fName(n), fWidth(width) {}
|
|
sk_sp<SkData> fData;
|
|
const char* fResource;
|
|
const char* fName;
|
|
SkScalar fWidth;
|
|
const char* onGetName() override { return fName; }
|
|
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
|
|
void onDelayedSetup() override { fData = GetResourceAsData(fResource); }
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
if (!fData) {
|
|
return;
|
|
}
|
|
|
|
const char* text = (const char*)fData->data();
|
|
|
|
auto fontCollection = sk_make_sp<FontCollection>();
|
|
fontCollection->setDefaultFontManager(SkFontMgr::RefDefault());
|
|
ParagraphStyle paragraph_style;
|
|
paragraph_style.turnHintingOff();
|
|
ParagraphBuilderImpl builder(paragraph_style, fontCollection);
|
|
builder.addText(text);
|
|
auto paragraph = builder.Build();
|
|
|
|
SkPictureRecorder rec;
|
|
SkCanvas* canvas = rec.beginRecording({0,0, 2000,3000});
|
|
while (loops-- > 0) {
|
|
paragraph->layout(fWidth);
|
|
auto impl = static_cast<ParagraphImpl*>(paragraph.get());
|
|
paragraph->paint(canvas, 0, 0);
|
|
paragraph->markDirty();
|
|
impl->resetCache();
|
|
}
|
|
}
|
|
};
|
|
} // namespace
|
|
|
|
#define PARAGRAPH_BENCH(X) DEF_BENCH(return new ParagraphBench(50000, "text/" #X ".txt", "paragraph_" #X);)
|
|
//PARAGRAPH_BENCH(arabic)
|
|
//PARAGRAPH_BENCH(emoji)
|
|
PARAGRAPH_BENCH(english)
|
|
#undef PARAGRAPH_BENCH
|
|
|
|
#endif // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)
|