skia2/gm/discard.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

86 lines
2.4 KiB
C++

/*
* Copyright 2014 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/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkSurface.h"
#include "include/utils/SkRandom.h"
#include "tools/ToolUtils.h"
namespace skiagm {
/*
* This GM exercises SkCanvas::discard() by creating an offscreen SkSurface and repeatedly
* discarding it, drawing to it, and then drawing it to the main canvas.
*/
class DiscardGM : public GpuGM {
public:
DiscardGM() {
}
protected:
SkString onShortName() override {
return SkString("discard");
}
SkISize onISize() override {
return SkISize::Make(100, 100);
}
DrawResult onDraw(GrContext* context, GrRenderTargetContext*, SkCanvas* canvas,
SkString* errorMsg) override {
SkISize size = this->getISize();
size.fWidth /= 10;
size.fHeight /= 10;
SkImageInfo info = SkImageInfo::MakeN32Premul(size);
auto surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
if (nullptr == surface) {
*errorMsg = "Could not create render target.";
return DrawResult::kFail;
}
canvas->clear(SK_ColorBLACK);
SkRandom rand;
for (int x = 0; x < 10; ++x) {
for (int y = 0; y < 10; ++y) {
surface->getCanvas()->discard();
// Make something that isn't too close to the background color, black.
SkColor color = ToolUtils::color_to_565(rand.nextU() | 0xFF404040);
switch (rand.nextULessThan(3)) {
case 0:
surface->getCanvas()->drawColor(color);
break;
case 1:
surface->getCanvas()->clear(color);
break;
case 2:
SkPaint paint;
paint.setShader(SkShaders::Color(color));
surface->getCanvas()->drawPaint(paint);
break;
}
surface->draw(canvas, 10.f*x, 10.f*y, nullptr);
}
}
surface->getCanvas()->discard();
return DrawResult::kOk;
}
private:
typedef GM INHERITED;
};
//////////////////////////////////////////////////////////////////////////////
DEF_GM(return new DiscardGM;)
} // end namespace