4dca83162b
This CL is mostly mechanical. It: replaces "src/gpu/GrSurfaceDrawContext.h" #includes with "src/gpu/v1/SurfaceDrawContext_v1.h" and reorders replaces "class GrSurfaceDrawContext;" with "namespace skgpu { namespace v1 { class SurfaceDrawContext; }}" replaces "GrSurfaceDrawContext*" with "auto" where possible replaces "rtc" with "sdc" replaces "surfaceDrawContext" with "sdc" replaces GrSurfaceDrawContext with skgpu::v1::SurfaceDrawContext reflows parameters as needed This CL does not try to: make skgpu::v1::SurfaceDrawContext V1-only minimize the skgpu and/or skgpu::v1 prefixes Those two tasks will be accomplished in follow up CLs. This CL is just trying to get the bulk of the mechanical changes comprehensibly landed. Bug: skia:11837 Change-Id: I6fe59080249d585df8f5d27c6b67569cdc35842f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/433156 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
99 lines
2.9 KiB
C++
99 lines
2.9 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/SkColor.h"
|
|
#include "include/core/SkImageInfo.h"
|
|
#include "include/core/SkPaint.h"
|
|
#include "include/core/SkRefCnt.h"
|
|
#include "include/core/SkShader.h"
|
|
#include "include/core/SkSize.h"
|
|
#include "include/core/SkString.h"
|
|
#include "include/core/SkSurface.h"
|
|
#include "include/core/SkTypes.h"
|
|
#include "include/gpu/GrDirectContext.h"
|
|
#include "include/gpu/GrRecordingContext.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 GM {
|
|
|
|
public:
|
|
DiscardGM() {}
|
|
|
|
protected:
|
|
SkString onShortName() override {
|
|
return SkString("discard");
|
|
}
|
|
|
|
SkISize onISize() override {
|
|
return SkISize::Make(100, 100);
|
|
}
|
|
|
|
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
|
|
auto dContext = GrAsDirectContext(canvas->recordingContext());
|
|
if (!dContext || dContext->abandoned()) {
|
|
*errorMsg = "GM relies on having access to a live direct context.";
|
|
return DrawResult::kSkip;
|
|
}
|
|
|
|
SkISize size = this->getISize();
|
|
size.fWidth /= 10;
|
|
size.fHeight /= 10;
|
|
SkImageInfo info = SkImageInfo::MakeN32Premul(size);
|
|
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(dContext, 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);
|
|
}
|
|
}
|
|
|
|
surface->getCanvas()->discard();
|
|
return DrawResult::kOk;
|
|
}
|
|
|
|
private:
|
|
using INHERITED = GM;
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
DEF_GM(return new DiscardGM;)
|
|
|
|
} // namespace skiagm
|