2021-06-04 16:09:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Google LLC.
|
|
|
|
*
|
|
|
|
* 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/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/effects/SkImageFilters.h"
|
2021-07-21 19:39:51 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2021-06-04 16:09:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
|
|
|
#include "src/gpu/GrFragmentProcessor.h"
|
|
|
|
#include "src/gpu/GrStyle.h"
|
|
|
|
#include "src/gpu/SkGr.h"
|
2021-07-06 20:28:52 +00:00
|
|
|
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
2021-07-28 19:13:20 +00:00
|
|
|
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
2021-06-04 16:09:11 +00:00
|
|
|
#include "tools/Resources.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class DestColorTestFP : public GrFragmentProcessor {
|
|
|
|
public:
|
|
|
|
static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> child) {
|
|
|
|
return std::unique_ptr<GrFragmentProcessor>(new DestColorTestFP(std::move(child)));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<GrFragmentProcessor> clone() const override {
|
|
|
|
return std::unique_ptr<GrFragmentProcessor>(new DestColorTestFP(*this));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DestColorTestFP(std::unique_ptr<GrFragmentProcessor> child)
|
|
|
|
: INHERITED(kTestFP_ClassID, kNone_OptimizationFlags) {
|
|
|
|
this->registerChild(std::move(child));
|
|
|
|
}
|
|
|
|
|
|
|
|
explicit DestColorTestFP(const DestColorTestFP& that)
|
2021-08-09 19:36:59 +00:00
|
|
|
: INHERITED(that) {}
|
2021-06-04 16:09:11 +00:00
|
|
|
|
|
|
|
const char* name() const override { return "DestColorTestFP"; }
|
2021-08-06 19:33:58 +00:00
|
|
|
void onAddToKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
|
2021-06-04 16:09:11 +00:00
|
|
|
bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
|
|
|
|
|
2021-08-09 15:23:04 +00:00
|
|
|
std::unique_ptr<ProgramImpl> onMakeProgramImpl() const override {
|
2021-08-10 17:56:13 +00:00
|
|
|
class Impl : public ProgramImpl {
|
|
|
|
public:
|
|
|
|
void emitCode(EmitArgs& args) override {
|
|
|
|
SkString result = this->invokeChild(0, args);
|
|
|
|
args.fFragBuilder->codeAppendf("return (half4(1) - (%s)).rgb1;", result.c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-04 16:09:11 +00:00
|
|
|
return std::make_unique<Impl>();
|
|
|
|
}
|
|
|
|
|
|
|
|
using INHERITED = GrFragmentProcessor;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
DEF_SIMPLE_GPU_GM_CAN_FAIL(destcolor, rContext, canvas, errorMsg, 640, 640) {
|
2021-06-04 16:09:11 +00:00
|
|
|
SkRect bounds = SkRect::MakeIWH(512, 512);
|
|
|
|
|
2021-07-21 19:39:51 +00:00
|
|
|
auto sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(canvas);
|
|
|
|
if (!sdc) {
|
|
|
|
*errorMsg = GM::kErrorMsg_DrawSkippedGpuOnly;
|
|
|
|
return DrawResult::kSkip;
|
|
|
|
}
|
|
|
|
|
2021-06-04 16:09:11 +00:00
|
|
|
// Draw the mandrill.
|
|
|
|
SkPaint p;
|
|
|
|
p.setImageFilter(SkImageFilters::Image(GetResourceAsImage("images/mandrill_512.png"),
|
|
|
|
bounds, bounds, SkSamplingOptions()));
|
|
|
|
canvas->drawPaint(p);
|
|
|
|
|
|
|
|
// Now let's add our test FP on top. It reads back the original image and inverts it.
|
|
|
|
GrPaint invertPaint;
|
|
|
|
invertPaint.setColor4f(SK_PMColor4fWHITE);
|
|
|
|
invertPaint.setPorterDuffXPFactory(SkBlendMode::kSrcOver);
|
2021-07-29 21:20:22 +00:00
|
|
|
invertPaint.setColorFragmentProcessor(
|
|
|
|
DestColorTestFP::Make(GrFragmentProcessor::SurfaceColor()));
|
2021-07-07 18:15:12 +00:00
|
|
|
sdc->drawOval(/*clip*/ nullptr, std::move(invertPaint), GrAA::kYes, SkMatrix::I(),
|
|
|
|
SkRect::MakeLTRB(128, 128, 640, 640), GrStyle::SimpleFill());
|
2021-07-21 19:39:51 +00:00
|
|
|
|
|
|
|
return DrawResult::kOk;
|
2021-06-04 16:09:11 +00:00
|
|
|
}
|
2021-07-21 19:39:51 +00:00
|
|
|
|
|
|
|
} // namespace skiagm
|