skia2/gm/pathopsinverse.cpp
Mike Klein c0bd9f9fe5 rewrite includes to not need so much -Ifoo
Current strategy: everything from the top

Things to look at first are the manual changes:

   - added tools/rewrite_includes.py
   - removed -Idirectives from BUILD.gn
   - various compile.sh simplifications
   - tweak tools/embed_resources.py
   - update gn/find_headers.py to write paths from the top
   - update gn/gn_to_bp.py SkUserConfig.h layout
     so that #include "include/config/SkUserConfig.h" always
     gets the header we want.

No-Presubmit: true
Change-Id: I73a4b181654e0e38d229bc456c0d0854bae3363e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209706
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Hal Canary <halcanary@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
2019-04-24 16:27:11 +00:00

115 lines
3.8 KiB
C++

/*
* Copyright 2013 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/SkBitmap.h"
#include "include/core/SkPath.h"
#include "include/core/SkRect.h"
#include "include/pathops/SkPathOps.h"
#include "tools/ToolUtils.h"
namespace skiagm {
class PathOpsInverseGM : public GM {
public:
PathOpsInverseGM() {
}
protected:
void onOnceBeforeDraw() override {
const unsigned oneColor = ToolUtils::color_to_565(0xFF8080FF);
const unsigned twoColor = 0x807F1f1f;
SkColor blendColor = blend(oneColor, twoColor);
makePaint(&fOnePaint, oneColor);
makePaint(&fTwoPaint, twoColor);
makePaint(&fOpPaint[kDifference_SkPathOp], oneColor);
makePaint(&fOpPaint[kIntersect_SkPathOp], blendColor);
makePaint(&fOpPaint[kUnion_SkPathOp], ToolUtils::color_to_565(0xFFc0FFc0));
makePaint(&fOpPaint[kReverseDifference_SkPathOp], twoColor);
makePaint(&fOpPaint[kXOR_SkPathOp], ToolUtils::color_to_565(0xFFa0FFe0));
makePaint(&fOutlinePaint, 0xFF000000);
fOutlinePaint.setStyle(SkPaint::kStroke_Style);
}
SkColor blend(SkColor one, SkColor two) {
SkBitmap temp;
temp.allocN32Pixels(1, 1);
SkCanvas canvas(temp);
canvas.drawColor(one);
canvas.drawColor(two);
void* pixels = temp.getPixels();
return *(SkColor*) pixels;
}
void makePaint(SkPaint* paint, SkColor color) {
paint->setAntiAlias(true);
paint->setStyle(SkPaint::kFill_Style);
paint->setColor(color);
}
SkString onShortName() override {
return SkString("pathopsinverse");
}
SkISize onISize() override {
return SkISize::Make(1200, 900);
}
void onDraw(SkCanvas* canvas) override {
SkPath one, two;
int yPos = 0;
for (int oneFill = 0; oneFill <= 1; ++oneFill) {
SkPath::FillType oneF = oneFill ? SkPath::kInverseEvenOdd_FillType
: SkPath::kEvenOdd_FillType;
for (int twoFill = 0; twoFill <= 1; ++twoFill) {
SkPath::FillType twoF = twoFill ? SkPath::kInverseEvenOdd_FillType
: SkPath::kEvenOdd_FillType;
one.reset();
one.setFillType(oneF);
one.addRect(10, 10, 70, 70);
two.reset();
two.setFillType(twoF);
two.addRect(40, 40, 100, 100);
canvas->save();
canvas->translate(0, SkIntToScalar(yPos));
canvas->clipRect(SkRect::MakeWH(110, 110), true);
canvas->drawPath(one, fOnePaint);
canvas->drawPath(one, fOutlinePaint);
canvas->drawPath(two, fTwoPaint);
canvas->drawPath(two, fOutlinePaint);
canvas->restore();
int xPos = 150;
for (int op = kDifference_SkPathOp; op <= kReverseDifference_SkPathOp; ++op) {
SkPath result;
Op(one, two, (SkPathOp) op, &result);
canvas->save();
canvas->translate(SkIntToScalar(xPos), SkIntToScalar(yPos));
canvas->clipRect(SkRect::MakeWH(110, 110), true);
canvas->drawPath(result, fOpPaint[op]);
canvas->drawPath(result, fOutlinePaint);
canvas->restore();
xPos += 150;
}
yPos += 150;
}
}
}
private:
SkPaint fOnePaint;
SkPaint fTwoPaint;
SkPaint fOutlinePaint;
SkPaint fOpPaint[kReverseDifference_SkPathOp - kDifference_SkPathOp + 1];
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM( return new PathOpsInverseGM; )
}