Sample/Patch: use resources; cleanup code
Change-Id: I8450193a6033e8b4262c1f23929a9b3d964a785a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/225550 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
aee26ea14e
commit
5f4a754ea6
@ -8,31 +8,32 @@
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkColorFilter.h"
|
||||
#include "include/core/SkColorPriv.h"
|
||||
#include "include/core/SkContourMeasure.h"
|
||||
#include "include/core/SkGraphics.h"
|
||||
#include "include/core/SkPath.h"
|
||||
#include "include/core/SkRegion.h"
|
||||
#include "include/core/SkShader.h"
|
||||
#include "include/core/SkStream.h"
|
||||
#include "include/core/SkTime.h"
|
||||
#include "include/core/SkTypeface.h"
|
||||
#include "include/core/SkVertices.h"
|
||||
#include "include/effects/SkGradientShader.h"
|
||||
#include "include/effects/SkOpPathEffect.h"
|
||||
#include "include/private/SkTDArray.h"
|
||||
#include "include/utils/SkRandom.h"
|
||||
#include "samplecode/DecodeFile.h"
|
||||
#include "samplecode/Sample.h"
|
||||
#include "src/core/SkGeometry.h"
|
||||
#include "src/core/SkOSFile.h"
|
||||
#include "src/utils/SkUTF.h"
|
||||
#include "tools/Resources.h"
|
||||
#include "tools/timer/AnimTimer.h"
|
||||
|
||||
#include "include/core/SkStream.h"
|
||||
#include "src/core/SkOSFile.h"
|
||||
|
||||
#include "src/core/SkGeometry.h"
|
||||
|
||||
namespace {
|
||||
static sk_sp<SkShader> make_shader0(SkIPoint* size) {
|
||||
SkBitmap bm;
|
||||
|
||||
// decode_file("/skimages/progressivejpg.jpg", &bm);
|
||||
decode_file("/skimages/logo.png", &bm);
|
||||
size->set(bm.width(), bm.height());
|
||||
SkBitmap bm;
|
||||
decode_file(GetResourceAsData("images/dog.jpg"), &bm);
|
||||
*size = SkIPoint{bm.width(), bm.height()};
|
||||
return bm.makeShader();
|
||||
}
|
||||
|
||||
@ -44,8 +45,6 @@ static sk_sp<SkShader> make_shader1(const SkIPoint& size) {
|
||||
SK_ARRAY_COUNT(colors), SkTileMode::kMirror);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class Patch {
|
||||
public:
|
||||
Patch() { sk_bzero(fPts, sizeof(fPts)); }
|
||||
@ -198,44 +197,42 @@ static void drawpatches(SkCanvas* canvas, const SkPaint& paint, int nu, int nv,
|
||||
patch->draw(canvas, paint, nu, nv, true, true);
|
||||
}
|
||||
|
||||
const SkScalar DX = 20;
|
||||
const SkScalar DY = 0;
|
||||
static constexpr SkScalar DX = 20;
|
||||
static constexpr SkScalar DY = 0;
|
||||
static constexpr SkScalar kS = 50;
|
||||
static constexpr SkScalar kT = 40;
|
||||
|
||||
class PatchView : public Sample {
|
||||
SkScalar fAngle;
|
||||
struct PatchView : public Sample {
|
||||
sk_sp<SkShader> fShader0;
|
||||
sk_sp<SkShader> fShader1;
|
||||
SkIPoint fSize0, fSize1;
|
||||
SkPoint fPts[12];
|
||||
SkScalar fAngle = 0;
|
||||
SkIPoint fSize0 = {0, 0},
|
||||
fSize1 = {0, 0};
|
||||
SkPoint fPts[12] = {
|
||||
{kS * 0, kT * 1},
|
||||
{kS * 1, kT * 1},
|
||||
{kS * 2, kT * 1},
|
||||
{kS * 3, kT * 1},
|
||||
{kS * 3, kT * 2},
|
||||
{kS * 3, kT * 3},
|
||||
{kS * 3, kT * 4},
|
||||
{kS * 2, kT * 4},
|
||||
{kS * 1, kT * 4},
|
||||
{kS * 0, kT * 4},
|
||||
{kS * 0, kT * 3},
|
||||
{kS * 0, kT * 2},
|
||||
};
|
||||
|
||||
public:
|
||||
PatchView() : fAngle(0) {
|
||||
void onOnceBeforeDraw() override {
|
||||
fShader0 = make_shader0(&fSize0);
|
||||
fSize1 = fSize0;
|
||||
if (fSize0.fX == 0 || fSize0.fY == 0) {
|
||||
fSize1.set(2, 2);
|
||||
}
|
||||
fShader1 = make_shader1(fSize1);
|
||||
|
||||
const SkScalar S = SkIntToScalar(50);
|
||||
const SkScalar T = SkIntToScalar(40);
|
||||
fPts[0].set(S*0, T);
|
||||
fPts[1].set(S*1, T);
|
||||
fPts[2].set(S*2, T);
|
||||
fPts[3].set(S*3, T);
|
||||
fPts[4].set(S*3, T*2);
|
||||
fPts[5].set(S*3, T*3);
|
||||
fPts[6].set(S*3, T*4);
|
||||
fPts[7].set(S*2, T*4);
|
||||
fPts[8].set(S*1, T*4);
|
||||
fPts[9].set(S*0, T*4);
|
||||
fPts[10].set(S*0, T*3);
|
||||
fPts[11].set(S*0, T*2);
|
||||
|
||||
this->setBGColor(SK_ColorGRAY);
|
||||
}
|
||||
|
||||
protected:
|
||||
SkString name() override { return SkString("Patch"); }
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
@ -271,12 +268,12 @@ protected:
|
||||
|
||||
paint.setAntiAlias(false);
|
||||
paint.setShader(fShader1);
|
||||
if (true) {
|
||||
{
|
||||
SkMatrix m;
|
||||
m.setSkew(1, 0);
|
||||
paint.setShader(paint.getShader()->makeWithLocalMatrix(m));
|
||||
}
|
||||
if (true) {
|
||||
{
|
||||
SkMatrix m;
|
||||
m.setRotate(fAngle);
|
||||
paint.setShader(paint.getShader()->makeWithLocalMatrix(m));
|
||||
@ -319,13 +316,12 @@ protected:
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
} // namespace
|
||||
DEF_SAMPLE( return new PatchView(); )
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "include/core/SkContourMeasure.h"
|
||||
#include "include/private/SkTDArray.h"
|
||||
|
||||
namespace {
|
||||
static sk_sp<SkVertices> make_verts(const SkPath& path, SkScalar width) {
|
||||
auto meas = SkContourMeasureIter(path, false).next();
|
||||
if (!meas) {
|
||||
@ -422,9 +418,10 @@ protected:
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
} // namespace
|
||||
DEF_SAMPLE( return new PseudoInkView(); )
|
||||
|
||||
#include "include/effects/SkOpPathEffect.h"
|
||||
namespace {
|
||||
// Show stroking options using patheffects (and pathops)
|
||||
// and why strokeandfill is a hacks
|
||||
class ManyStrokesView : public Sample {
|
||||
@ -508,4 +505,5 @@ protected:
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
} // namespace
|
||||
DEF_SAMPLE( return new ManyStrokesView(); )
|
||||
|
Loading…
Reference in New Issue
Block a user