Remove duplicate simple samples, make one a gm.
SampleBigBlur is super simple and now covered by gms and AnimBlur sample. SampleBigGradient now has a gm shallow_gradient_linear. SampleConcavePaths has a more complete gm concavepaths. SamplePoints now has an almost exact gm. RasterAllocatorSample is made into a gm so that it will be run by d. It appears to be the only test of SkRasterHandleAllocator, so it should probably run. Change-Id: Iad7b99d0f92898fc4b2fdccc5aae35d0277f2fff Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219400 Reviewed-by: Hal Canary <halcanary@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
25132b6841
commit
2b4dcd381c
@ -5,49 +5,12 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "gm/gm.h"
|
||||
#include "include/core/SkBitmap.h"
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/effects/SkGradientShader.h"
|
||||
#include "samplecode/Sample.h"
|
||||
#include "src/core/SkMakeUnique.h"
|
||||
|
||||
static sk_sp<SkShader> make_grad(SkScalar w, SkScalar h) {
|
||||
SkColor colors[] = { 0xFF000000, 0xFF333333 };
|
||||
SkPoint pts[] = { { 0, 0 }, { w, h } };
|
||||
return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
|
||||
}
|
||||
|
||||
class BigGradientView : public Sample {
|
||||
public:
|
||||
BigGradientView() {}
|
||||
|
||||
protected:
|
||||
bool onQuery(Sample::Event* evt) override {
|
||||
if (Sample::TitleQ(*evt)) {
|
||||
Sample::TitleR(evt, "BigGradient");
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onQuery(evt);
|
||||
}
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
SkRect r;
|
||||
r.set(0, 0, this->width(), this->height());
|
||||
SkPaint p;
|
||||
p.setShader(make_grad(this->width(), this->height()));
|
||||
canvas->drawRect(r, p);
|
||||
}
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new BigGradientView(); )
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "include/core/SkPixmap.h"
|
||||
#include "include/core/SkRasterHandleAllocator.h"
|
||||
#include "src/core/SkMakeUnique.h"
|
||||
|
||||
class GraphicsPort {
|
||||
protected:
|
||||
@ -148,7 +111,9 @@ public:
|
||||
#define MyPort CGGraphicsPort
|
||||
#define MyAllocator Allocator_CG
|
||||
|
||||
#elif defined(WIN32)
|
||||
#elif defined(SK_BUILD_FOR_WIN)
|
||||
|
||||
#include "src/core/SkLeanWindows.h"
|
||||
|
||||
static RECT toRECT(const SkIRect& r) {
|
||||
return { r.left(), r.top(), r.right(), r.bottom() };
|
||||
@ -172,13 +137,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
static void DeleteHDCCallback(void*, void* context) {
|
||||
HDC hdc = static_cast<HDC>(context);
|
||||
HBITMAP hbitmap = static_cast<HBITMAP>(SelectObject(hdc, nullptr));
|
||||
DeleteObject(hbitmap);
|
||||
DeleteDC(hdc);
|
||||
}
|
||||
|
||||
// We use this static factory function instead of the regular constructor so
|
||||
// that we can create the pixel data before calling the constructor. This is
|
||||
// required so that we can call the base class' constructor with the pixel
|
||||
@ -210,10 +168,20 @@ static bool Create(int width, int height, bool is_opaque, SkRasterHandleAllocato
|
||||
return false;
|
||||
}
|
||||
SetGraphicsMode(hdc, GM_ADVANCED);
|
||||
SelectObject(hdc, hbitmap);
|
||||
HGDIOBJ origBitmap = SelectObject(hdc, hbitmap);
|
||||
|
||||
rec->fReleaseProc = DeleteHDCCallback;
|
||||
rec->fReleaseCtx = hdc;
|
||||
struct ReleaseContext {
|
||||
HDC hdc;
|
||||
HGDIOBJ hbitmap;
|
||||
};
|
||||
rec->fReleaseProc = [](void*, void* context) {
|
||||
ReleaseContext* ctx = static_cast<ReleaseContext*>(context);
|
||||
HBITMAP hbitmap = static_cast<HBITMAP>(SelectObject(ctx->hdc, ctx->hbitmap));
|
||||
DeleteObject(hbitmap);
|
||||
DeleteDC(ctx->hdc);
|
||||
delete ctx;
|
||||
};
|
||||
rec->fReleaseCtx = new ReleaseContext{hdc, origBitmap};
|
||||
rec->fPixels = pixels;
|
||||
rec->fRowBytes = row_bytes;
|
||||
rec->fHandle = hdc;
|
||||
@ -259,20 +227,8 @@ public:
|
||||
#endif
|
||||
|
||||
#ifdef MyAllocator
|
||||
class RasterAllocatorSample : public Sample {
|
||||
public:
|
||||
RasterAllocatorSample() {}
|
||||
|
||||
protected:
|
||||
bool onQuery(Sample::Event* evt) override {
|
||||
if (Sample::TitleQ(*evt)) {
|
||||
Sample::TitleR(evt, "raster-allocator");
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onQuery(evt);
|
||||
}
|
||||
|
||||
void doDraw(GraphicsPort* port) {
|
||||
DEF_SIMPLE_GM(rasterallocator, canvas, 600, 300) {
|
||||
auto doDraw = [](GraphicsPort* port) {
|
||||
SkAutoCanvasRestore acr(port->peekCanvas(), true);
|
||||
|
||||
port->drawRect({0, 0, 256, 256}, SK_ColorRED);
|
||||
@ -288,27 +244,22 @@ protected:
|
||||
|
||||
port->clip({150, 50, 200, 200});
|
||||
port->drawRect({0, 0, 256, 256}, 0xFFCCCCCC);
|
||||
}
|
||||
};
|
||||
|
||||
void onDrawContent(SkCanvas* canvas) override {
|
||||
GraphicsPort skp(canvas);
|
||||
doDraw(&skp);
|
||||
GraphicsPort skp(canvas);
|
||||
doDraw(&skp);
|
||||
|
||||
const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
|
||||
std::unique_ptr<SkCanvas> c2 =
|
||||
SkRasterHandleAllocator::MakeCanvas(skstd::make_unique<MyAllocator>(), info);
|
||||
MyPort cgp(c2.get());
|
||||
doDraw(&cgp);
|
||||
const SkImageInfo info = SkImageInfo::MakeN32Premul(256, 256);
|
||||
std::unique_ptr<SkCanvas> c2 =
|
||||
SkRasterHandleAllocator::MakeCanvas(skstd::make_unique<MyAllocator>(), info);
|
||||
MyPort cgp(c2.get());
|
||||
doDraw(&cgp);
|
||||
|
||||
SkPixmap pm;
|
||||
c2->peekPixels(&pm);
|
||||
SkBitmap bm;
|
||||
bm.installPixels(pm);
|
||||
canvas->drawBitmap(bm, 280, 0, nullptr);
|
||||
}
|
||||
SkPixmap pm;
|
||||
c2->peekPixels(&pm);
|
||||
SkBitmap bm;
|
||||
bm.installPixels(pm);
|
||||
canvas->drawBitmap(bm, 280, 0, nullptr);
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
DEF_SAMPLE( return new RasterAllocatorSample; )
|
||||
}
|
||||
#endif
|
@ -283,6 +283,7 @@ gm_sources = [
|
||||
"$_gm/postercircle.cpp",
|
||||
"$_gm/quadpaths.cpp",
|
||||
"$_gm/radial_gradient_precision.cpp",
|
||||
"$_gm/rasterhandleallocator.cpp",
|
||||
"$_gm/readpixels.cpp",
|
||||
"$_gm/recordopts.cpp",
|
||||
"$_gm/rectangletexture.cpp",
|
||||
|
@ -21,8 +21,6 @@ samples_sources = [
|
||||
"$_samplecode/SampleAnimBlur.cpp",
|
||||
"$_samplecode/SampleArc.cpp",
|
||||
"$_samplecode/SampleAtlas.cpp",
|
||||
"$_samplecode/SampleBigBlur.cpp",
|
||||
"$_samplecode/SampleBigGradient.cpp",
|
||||
"$_samplecode/SampleBitmapRect.cpp",
|
||||
"$_samplecode/SampleCCPRGeometry.cpp",
|
||||
"$_samplecode/SampleCamera.cpp",
|
||||
@ -34,7 +32,6 @@ samples_sources = [
|
||||
"$_samplecode/SampleClock.cpp",
|
||||
"$_samplecode/SampleColorFilter.cpp",
|
||||
"$_samplecode/SampleComplexClip.cpp",
|
||||
"$_samplecode/SampleConcavePaths.cpp",
|
||||
"$_samplecode/SampleCowboy.cpp",
|
||||
"$_samplecode/SampleCusp.cpp",
|
||||
"$_samplecode/SampleDegenerateQuads.cpp",
|
||||
@ -69,7 +66,6 @@ samples_sources = [
|
||||
"$_samplecode/SamplePathEffects.cpp",
|
||||
"$_samplecode/SamplePathOverstroke.cpp",
|
||||
"$_samplecode/SamplePdfFileViewer.cpp",
|
||||
"$_samplecode/SamplePoints.cpp",
|
||||
"$_samplecode/SamplePolyToPoly.cpp",
|
||||
"$_samplecode/SampleQuadStroker.cpp",
|
||||
"$_samplecode/SampleRectanizer.cpp",
|
||||
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 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/SkMaskFilter.h"
|
||||
#include "samplecode/Sample.h"
|
||||
#include "src/core/SkBlurMask.h"
|
||||
|
||||
class BigBlurView : public Sample {
|
||||
public:
|
||||
BigBlurView() {
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual bool onQuery(Sample::Event* evt) {
|
||||
if (Sample::TitleQ(*evt)) {
|
||||
Sample::TitleR(evt, "BigBlur");
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onQuery(evt);
|
||||
}
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
canvas->save();
|
||||
paint.setColor(SK_ColorBLUE);
|
||||
paint.setMaskFilter(SkMaskFilter::MakeBlur(
|
||||
kNormal_SkBlurStyle,
|
||||
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(128))));
|
||||
canvas->translate(200, 200);
|
||||
canvas->drawCircle(100, 100, 200, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new BigBlurView(); )
|
@ -1,141 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 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/SkColorFilter.h"
|
||||
#include "include/core/SkColorPriv.h"
|
||||
#include "include/core/SkGraphics.h"
|
||||
#include "include/core/SkPath.h"
|
||||
#include "include/core/SkRegion.h"
|
||||
#include "include/core/SkShader.h"
|
||||
#include "include/core/SkTime.h"
|
||||
#include "include/core/SkTypeface.h"
|
||||
#include "include/effects/SkGradientShader.h"
|
||||
#include "include/utils/SkParsePath.h"
|
||||
#include "samplecode/Sample.h"
|
||||
#include "src/utils/SkUTF.h"
|
||||
|
||||
#include "src/core/SkGeometry.h"
|
||||
|
||||
class ConcavePathView : public Sample {
|
||||
public:
|
||||
ConcavePathView() {}
|
||||
|
||||
protected:
|
||||
virtual bool onQuery(Sample::Event* evt) {
|
||||
if (Sample::TitleQ(*evt)) {
|
||||
Sample::TitleR(evt, "ConcavePaths");
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onQuery(evt);
|
||||
}
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
|
||||
paint.setAntiAlias(true);
|
||||
paint.setStyle(SkPaint::kFill_Style);
|
||||
|
||||
// Concave test
|
||||
if (1) {
|
||||
SkPath path;
|
||||
canvas->translate(0, 0);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(30), SkIntToScalar(30));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
}
|
||||
// Reverse concave test
|
||||
if (1) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(100, 0);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(30), SkIntToScalar(30));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// Bowtie (intersection)
|
||||
if (1) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(200, 0);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// "fake" bowtie (concave, but no intersection)
|
||||
if (1) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(300, 0);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(40));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(60));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// Fish test (intersection/concave)
|
||||
if (1) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(0, 100);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(70), SkIntToScalar(50));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(0), SkIntToScalar(50));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// Collinear test
|
||||
if (1) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(100, 100);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(50), SkIntToScalar(80));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
// Hole test
|
||||
if (1) {
|
||||
SkPath path;
|
||||
canvas->save();
|
||||
canvas->translate(200, 100);
|
||||
path.moveTo(SkIntToScalar(20), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(20));
|
||||
path.lineTo(SkIntToScalar(80), SkIntToScalar(80));
|
||||
path.lineTo(SkIntToScalar(20), SkIntToScalar(80));
|
||||
path.moveTo(SkIntToScalar(30), SkIntToScalar(30));
|
||||
path.lineTo(SkIntToScalar(30), SkIntToScalar(70));
|
||||
path.lineTo(SkIntToScalar(70), SkIntToScalar(70));
|
||||
path.lineTo(SkIntToScalar(70), SkIntToScalar(30));
|
||||
canvas->drawPath(path, paint);
|
||||
canvas->restore();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new ConcavePathView(); )
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 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/SkColorFilter.h"
|
||||
#include "include/core/SkColorPriv.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/effects/SkGradientShader.h"
|
||||
#include "include/utils/SkRandom.h"
|
||||
#include "samplecode/Sample.h"
|
||||
#include "src/utils/SkUTF.h"
|
||||
|
||||
class PointsView : public Sample {
|
||||
public:
|
||||
PointsView() {}
|
||||
|
||||
protected:
|
||||
virtual bool onQuery(Sample::Event* evt) {
|
||||
if (Sample::TitleQ(*evt)) {
|
||||
Sample::TitleR(evt, "Points");
|
||||
return true;
|
||||
}
|
||||
return this->INHERITED::onQuery(evt);
|
||||
}
|
||||
|
||||
static void fill_pts(SkPoint pts[], size_t n, SkRandom* rand) {
|
||||
for (size_t i = 0; i < n; i++)
|
||||
pts[i].set(rand->nextUScalar1() * 640, rand->nextUScalar1() * 480);
|
||||
}
|
||||
|
||||
virtual void onDrawContent(SkCanvas* canvas) {
|
||||
canvas->translate(SK_Scalar1, SK_Scalar1);
|
||||
|
||||
SkRandom rand;
|
||||
SkPaint p0, p1, p2, p3;
|
||||
const size_t n = 99;
|
||||
|
||||
p0.setColor(SK_ColorRED);
|
||||
p1.setColor(SK_ColorGREEN);
|
||||
p2.setColor(SK_ColorBLUE);
|
||||
p3.setColor(SK_ColorWHITE);
|
||||
|
||||
p0.setStrokeWidth(SkIntToScalar(4));
|
||||
p2.setStrokeCap(SkPaint::kRound_Cap);
|
||||
p2.setStrokeWidth(SkIntToScalar(6));
|
||||
|
||||
SkPoint* pts = new SkPoint[n];
|
||||
fill_pts(pts, n, &rand);
|
||||
|
||||
canvas->drawPoints(SkCanvas::kPolygon_PointMode, n, pts, p0);
|
||||
canvas->drawPoints(SkCanvas::kLines_PointMode, n, pts, p1);
|
||||
canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p2);
|
||||
canvas->drawPoints(SkCanvas::kPoints_PointMode, n, pts, p3);
|
||||
|
||||
delete[] pts;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
typedef Sample INHERITED;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_SAMPLE( return new PointsView(); )
|
Loading…
Reference in New Issue
Block a user