cbc954bf57
According to go/chrome-includes [1], this will save about 185MB (0.08%) off the Chrome build (some of which is handled by https://skia-review.googlesource.com/c/skia/+/512776). http://screen/3foDapQ5BN7srcG This adds several forward declares and moves several implementations from SkPath.h to SkPath.cpp. This also removes privateSetConvexity from SkPathBuilder because the SkPathConvexity being set to a non-zero default value would have required moving the enum out of SkPathRef or adding an include link. This private API was only used in one location, so I just opted to remove it. [1] https://commondatastorage.googleapis.com/chromium-browser-clang/include-analysis.html#view=edges&filter=%5Ethird_party%2Fskia%2Finclude%2Fcore%2FSkPath%5C.h%24&sort=asize&reverse=&includer=%5Ethird_party%2Fskia%2Finclude%2Fcore%2FSkPath%5C.h%24&included=&limit=1000 Change-Id: Ie1f83ac3eee6eb19d7ded18a41a7532f445c13ee Bug: 242216 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/512357 Reviewed-by: Robert Phillips <robertphillips@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
112 lines
3.1 KiB
C++
112 lines
3.1 KiB
C++
/*
|
|
* Copyright 2019 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkFont.h"
|
|
#include "include/core/SkFontMetrics.h"
|
|
#include "include/core/SkPath.h"
|
|
#include "include/private/SkTDArray.h"
|
|
#include "samplecode/Sample.h"
|
|
|
|
#include "modules/sksg/include/SkSGDraw.h"
|
|
#include "modules/sksg/include/SkSGGroup.h"
|
|
#include "modules/sksg/include/SkSGPaint.h"
|
|
#include "modules/sksg/include/SkSGRect.h"
|
|
#include "modules/sksg/include/SkSGScene.h"
|
|
|
|
struct PerNodeInfo {
|
|
// key
|
|
sksg::Draw* fDraw;
|
|
|
|
// value(s)
|
|
sksg::GeometryNode* fGeo;
|
|
sksg::PaintNode* fPaint;
|
|
};
|
|
|
|
class SampleSG : public Sample {
|
|
// TODO(kjlubick) use a vector instead of our private SkTDArray
|
|
SkTDArray<PerNodeInfo> fSideCar;
|
|
sk_sp<sksg::Group> fGroup;
|
|
std::unique_ptr<sksg::Scene> fScene;
|
|
|
|
PerNodeInfo* findInfo(sksg::Draw* key) {
|
|
for (int i = 0; i < fSideCar.count(); ++i) {
|
|
if (fSideCar[i].fDraw == key) {
|
|
return &fSideCar[i];
|
|
}
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void appendNode(sk_sp<sksg::Draw> d, sk_sp<sksg::GeometryNode> g, sk_sp<sksg::PaintNode> p) {
|
|
fGroup->addChild(d);
|
|
auto sc = fSideCar.append();
|
|
sc->fDraw = d.get();
|
|
sc->fGeo = g.get();
|
|
sc->fPaint = p.get();
|
|
}
|
|
|
|
public:
|
|
SampleSG() {
|
|
fGroup = sksg::Group::Make();
|
|
|
|
fScene = sksg::Scene::Make(fGroup);
|
|
|
|
auto r = sksg::Rect::Make({20, 20, 400, 300});
|
|
auto p = sksg::Color::Make(SK_ColorRED);
|
|
auto d = sksg::Draw::Make(r, p);
|
|
this->appendNode(d, r, p);
|
|
|
|
r = sksg::Rect::Make({60, 70, 300, 400});
|
|
p = sksg::Color::Make(SK_ColorBLUE);
|
|
d = sksg::Draw::Make(r, p);
|
|
this->appendNode(d, r, p);
|
|
}
|
|
|
|
protected:
|
|
SkString name() override { return SkString("SceneGraph"); }
|
|
|
|
void onDrawContent(SkCanvas* canvas) override {
|
|
fScene->render(canvas);
|
|
}
|
|
|
|
Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey modi) override {
|
|
if (auto node = fScene->nodeAt({x, y})) {
|
|
Click* click = new Click();
|
|
click->fMeta.setPtr("node", (void*)node);
|
|
return click;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
bool onClick(Click* click) override {
|
|
sksg::Draw* node = nullptr;
|
|
if (click->fMeta.findPtr("node", (void**)&node)) {
|
|
if (auto info = this->findInfo(node)) {
|
|
auto geo = info->fGeo;
|
|
sksg::Rect* r = (sksg::Rect*)geo;
|
|
SkScalar dx = click->fCurr.fX - click->fPrev.fX;
|
|
SkScalar dy = click->fCurr.fY - click->fPrev.fY;
|
|
r->setL(r->getL() + dx);
|
|
r->setR(r->getR() + dx);
|
|
r->setT(r->getT() + dy);
|
|
r->setB(r->getB() + dy);
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private:
|
|
|
|
using INHERITED = Sample;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_SAMPLE( return new SampleSG(); )
|