Revert "Revert "gms for SkParagraph""
This reverts commit e37d578796
.
Change-Id: I7d979657d34e981998cd7c3ef3e05fd59e2721ab
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/293350
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Julia Lavrova <jlavrova@google.com>
This commit is contained in:
parent
77a233283c
commit
63559a570c
8
BUILD.gn
8
BUILD.gn
@ -1147,11 +1147,9 @@ group("modules") {
|
||||
deps = [
|
||||
"modules/particles",
|
||||
"modules/skottie",
|
||||
"modules/skparagraph",
|
||||
"modules/skshaper",
|
||||
]
|
||||
if (target_cpu == "wasm") {
|
||||
deps += [ "modules/skparagraph" ]
|
||||
}
|
||||
}
|
||||
|
||||
# Targets guarded by skia_enable_tools may use //third_party freely.
|
||||
@ -1534,6 +1532,8 @@ if (skia_enable_tools) {
|
||||
":tool_utils",
|
||||
"modules/skottie",
|
||||
"modules/skottie:gm",
|
||||
"modules/skparagraph",
|
||||
"modules/skparagraph:gm",
|
||||
"modules/skshaper",
|
||||
]
|
||||
if (is_skia_dev_build) {
|
||||
@ -1817,7 +1817,7 @@ if (skia_enable_tools) {
|
||||
":skia",
|
||||
":tool_utils",
|
||||
":trace",
|
||||
"modules/skparagraph:bench",
|
||||
"modules/skparagraph",
|
||||
"modules/skshaper",
|
||||
]
|
||||
}
|
||||
|
@ -11,14 +11,9 @@
|
||||
#include "include/core/SkString.h"
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/private/SkNoncopyable.h"
|
||||
#include "include/private/SkOpts_spi.h"
|
||||
#include "include/private/SkTLogic.h"
|
||||
|
||||
// #include "src/core/SkOpts.h"
|
||||
// It's sort of pesky to be able to include SkOpts.h here, so we'll just re-declare what we need.
|
||||
namespace SkOpts {
|
||||
extern uint32_t (*hash_fn)(const void*, size_t, uint32_t);
|
||||
}
|
||||
|
||||
class SkChecksum : SkNoncopyable {
|
||||
public:
|
||||
/**
|
||||
|
21
include/private/SkOpts_spi.h
Normal file
21
include/private/SkOpts_spi.h
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkOpts_spi_DEFINED
|
||||
#define SkOpts_spi_DEFINED
|
||||
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
// These are exposed as SK_SPI (e.g. SkParagraph), the rest of SkOpts is
|
||||
// declared in src/core
|
||||
|
||||
namespace SkOpts {
|
||||
// The fastest high quality 32-bit hash we can provide on this platform.
|
||||
extern uint32_t SK_SPI (*hash_fn)(const void* data, size_t bytes, uint32_t seed);
|
||||
}
|
||||
|
||||
#endif
|
@ -4,6 +4,7 @@ import("../../gn/skia.gni")
|
||||
|
||||
declare_args() {
|
||||
skia_enable_skparagraph = true
|
||||
paragraph_gms_enabled = true
|
||||
paragraph_tests_enabled = true
|
||||
paragraph_bench_enabled = false
|
||||
}
|
||||
@ -55,6 +56,20 @@ if (skia_enable_skparagraph) {
|
||||
]
|
||||
}
|
||||
|
||||
source_set("gm") {
|
||||
if (skia_use_icu && skia_use_harfbuzz && paragraph_gms_enabled) {
|
||||
testonly = true
|
||||
sources = [ "gm/simple_gm.cpp" ]
|
||||
deps = [
|
||||
":skparagraph",
|
||||
"../..:gpu_tool_utils",
|
||||
"../..:skia",
|
||||
"../skshaper",
|
||||
"//third_party/icu",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
source_set("tests") {
|
||||
if (skia_use_icu && skia_use_harfbuzz && paragraph_tests_enabled) {
|
||||
testonly = true
|
||||
|
120
modules/skparagraph/gm/simple_gm.cpp
Normal file
120
modules/skparagraph/gm/simple_gm.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Copyright 2020 Google Inc.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "gm/gm.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkColor.h"
|
||||
#include "include/core/SkFont.h"
|
||||
#include "include/core/SkFontTypes.h"
|
||||
#include "include/core/SkPaint.h"
|
||||
#include "include/core/SkPoint.h"
|
||||
#include "include/core/SkRect.h"
|
||||
#include "include/core/SkScalar.h"
|
||||
#include "include/core/SkShader.h"
|
||||
#include "include/core/SkSize.h"
|
||||
#include "include/core/SkString.h"
|
||||
#include "include/core/SkTypeface.h"
|
||||
#include "tools/ToolUtils.h"
|
||||
|
||||
#include "modules/skparagraph/include/Paragraph.h"
|
||||
#include "modules/skparagraph/include/ParagraphBuilder.h"
|
||||
|
||||
static const char* gSpeach = "Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of their captivity.";
|
||||
|
||||
namespace {
|
||||
enum ParaFlags {
|
||||
kTimeLayout = 1 << 0,
|
||||
kUseUnderline = 1 << 1,
|
||||
};
|
||||
}
|
||||
|
||||
class ParagraphGM : public skiagm::GM {
|
||||
std::unique_ptr<skia::textlayout::Paragraph> fPara;
|
||||
const unsigned fFlags;
|
||||
|
||||
public:
|
||||
ParagraphGM(unsigned flags) : fFlags(flags) {}
|
||||
|
||||
void buildParagraph() {
|
||||
skia::textlayout::TextStyle style;
|
||||
style.setForegroundColor(SkPaint());
|
||||
style.setFontFamilies({SkString("sans-serif")});
|
||||
style.setFontSize(30);
|
||||
|
||||
if (fFlags & kUseUnderline) {
|
||||
style.setDecoration(skia::textlayout::TextDecoration::kUnderline);
|
||||
style.setDecorationMode(skia::textlayout::TextDecorationMode::kThrough);
|
||||
style.setDecorationColor(SK_ColorBLACK);
|
||||
style.setDecorationThicknessMultiplier(2);
|
||||
}
|
||||
|
||||
skia::textlayout::ParagraphStyle paraStyle;
|
||||
paraStyle.setTextStyle(style);
|
||||
|
||||
auto collection = sk_make_sp<skia::textlayout::FontCollection>();
|
||||
collection->setDefaultFontManager(SkFontMgr::RefDefault());
|
||||
auto builder = skia::textlayout::ParagraphBuilder::make(paraStyle, collection);
|
||||
|
||||
builder->addText(gSpeach, strlen(gSpeach));
|
||||
|
||||
fPara = builder->Build();
|
||||
fPara->layout(400);
|
||||
}
|
||||
|
||||
protected:
|
||||
void onOnceBeforeDraw() override {
|
||||
this->buildParagraph();
|
||||
}
|
||||
|
||||
SkString onShortName() override {
|
||||
SkString name;
|
||||
name.printf("paragraph%s_%s",
|
||||
fFlags & kTimeLayout ? "_layout" : "",
|
||||
fFlags & kUseUnderline ? "_underline" : "");
|
||||
return name;
|
||||
}
|
||||
|
||||
SkISize onISize() override { return SkISize::Make(412, 420); }
|
||||
|
||||
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
|
||||
const int loop = (this->getMode() == kGM_Mode) ? 1 : 50;
|
||||
|
||||
int parity = 0;
|
||||
for (int i = 0; i < loop; ++i) {
|
||||
SkAutoCanvasRestore acr(canvas, true);
|
||||
|
||||
if (fFlags & kTimeLayout) {
|
||||
fPara->layout(400 + parity);
|
||||
parity = (parity + 1) & 1;
|
||||
}
|
||||
fPara->paint(canvas, 10, 10);
|
||||
}
|
||||
// clean up if we've been looping
|
||||
if (loop > 1) {
|
||||
canvas->clear(SK_ColorWHITE);
|
||||
fPara->layout(400);
|
||||
fPara->paint(canvas, 10, 10);
|
||||
}
|
||||
|
||||
if ((this->getMode() == kGM_Mode) && (fFlags & kTimeLayout)) {
|
||||
return DrawResult::kSkip;
|
||||
}
|
||||
return DrawResult::kOk;
|
||||
}
|
||||
|
||||
bool runAsBench() const override { return true; }
|
||||
|
||||
bool onAnimate(double /*nanos*/) override {
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
typedef skiagm::GM INHERITED;
|
||||
};
|
||||
DEF_GM(return new ParagraphGM(0);)
|
||||
DEF_GM(return new ParagraphGM(kTimeLayout);)
|
||||
DEF_GM(return new ParagraphGM(kUseUnderline);)
|
@ -80,16 +80,17 @@ class SkOSFile {
|
||||
public:
|
||||
class Iter {
|
||||
public:
|
||||
Iter();
|
||||
Iter(const char path[], const char suffix[] = nullptr);
|
||||
~Iter();
|
||||
// SPI for module use.
|
||||
SK_SPI Iter();
|
||||
SK_SPI Iter(const char path[], const char suffix[] = nullptr);
|
||||
SK_SPI ~Iter();
|
||||
|
||||
void reset(const char path[], const char suffix[] = nullptr);
|
||||
SK_SPI void reset(const char path[], const char suffix[] = nullptr);
|
||||
/** If getDir is true, only returns directories.
|
||||
Results are undefined if true and false calls are
|
||||
interleaved on a single iterator.
|
||||
*/
|
||||
bool next(SkString* name, bool getDir = false);
|
||||
SK_SPI bool next(SkString* name, bool getDir = false);
|
||||
|
||||
static const size_t kStorageSize = 40;
|
||||
private:
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define SkOpts_DEFINED
|
||||
|
||||
#include "include/core/SkTypes.h"
|
||||
#include "include/private/SkOpts_spi.h"
|
||||
#include "src/core/SkRasterPipeline.h"
|
||||
#include "src/core/SkXfermodePriv.h"
|
||||
|
||||
@ -55,8 +56,6 @@ namespace SkOpts {
|
||||
|
||||
extern float (*cubic_solver)(float, float, float, float);
|
||||
|
||||
// The fastest high quality 32-bit hash we can provide on this platform.
|
||||
extern uint32_t (*hash_fn)(const void*, size_t, uint32_t seed);
|
||||
static inline uint32_t hash(const void* data, size_t bytes, uint32_t seed=0) {
|
||||
return hash_fn(data, bytes, seed);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user