Remove SkCanvas::getGrContext calls from samplecode
More busywork so we can deprecate getGrContext.
Change-Id: I8479985334881251e6ad814d7855681df716b1da
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301542
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/samplecode/Sample.cpp b/samplecode/Sample.cpp
index 10fac82..2a6e6a1 100644
--- a/samplecode/Sample.cpp
+++ b/samplecode/Sample.cpp
@@ -10,7 +10,7 @@
#include "samplecode/Sample.h"
#if SK_SUPPORT_GPU
-# include "include/gpu/GrContext.h"
+# include "include/gpu/GrDirectContext.h"
#else
class GrContext;
#endif
@@ -50,8 +50,8 @@
this->onDrawContent(canvas);
#if SK_SUPPORT_GPU
// Ensure the GrContext doesn't combine GrDrawOps across draw loops.
- if (GrContext* context = canvas->getGrContext()) {
- context->flushAndSubmit();
+ if (auto direct = GrAsDirectContext(canvas->recordingContext())) {
+ direct->flushAndSubmit();
}
#endif
diff --git a/samplecode/Sample3D.cpp b/samplecode/Sample3D.cpp
index 0ee2c4c..3895c20 100644
--- a/samplecode/Sample3D.cpp
+++ b/samplecode/Sample3D.cpp
@@ -261,7 +261,7 @@
virtual void drawContent(SkCanvas* canvas, SkColor, int index, bool drawFront) = 0;
void onDrawContent(SkCanvas* canvas) override {
- if (!canvas->getGrContext() && !(fFlags & kCanRunOnCPU)) {
+ if (!canvas->recordingContext() && !(fFlags & kCanRunOnCPU)) {
return;
}
diff --git a/samplecode/SampleAnimatedText.cpp b/samplecode/SampleAnimatedText.cpp
index d737d03..97fecb7 100644
--- a/samplecode/SampleAnimatedText.cpp
+++ b/samplecode/SampleAnimatedText.cpp
@@ -17,7 +17,7 @@
#include "src/utils/SkUTF.h"
#if SK_SUPPORT_GPU
-#include "include/gpu/GrContext.h"
+#include "include/gpu/GrDirectContext.h"
#include "src/gpu/GrContextPriv.h"
#endif
@@ -68,9 +68,9 @@
canvas->save();
#if SK_SUPPORT_GPU
- GrContext* grContext = canvas->getGrContext();
- if (grContext) {
- sk_sp<SkImage> image = grContext->priv().testingOnly_getFontAtlasImage(
+ auto direct = GrAsDirectContext(canvas->recordingContext());
+ if (direct) {
+ sk_sp<SkImage> image = direct->priv().testingOnly_getFontAtlasImage(
GrMaskFormat::kA8_GrMaskFormat);
canvas->drawImageRect(image,
SkRect::MakeXYWH(512.0f, 10.0f, 512.0f, 512.0f), &paint);
diff --git a/samplecode/SampleCCPRGeometry.cpp b/samplecode/SampleCCPRGeometry.cpp
index 23061f6..9df119e 100644
--- a/samplecode/SampleCCPRGeometry.cpp
+++ b/samplecode/SampleCCPRGeometry.cpp
@@ -12,6 +12,7 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
+#include "include/gpu/GrDirectContext.h"
#include "samplecode/Sample.h"
#include "src/core/SkRectPriv.h"
#include "src/gpu/GrContextPriv.h"
@@ -19,6 +20,7 @@
#include "src/gpu/GrMemoryPool.h"
#include "src/gpu/GrOnFlushResourceProvider.h"
#include "src/gpu/GrOpFlushState.h"
+#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrRenderTargetContextPriv.h"
#include "src/gpu/GrResourceProvider.h"
@@ -187,7 +189,7 @@
SkString caption;
if (GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext()) {
// Render coverage count.
- GrContext* ctx = canvas->getGrContext();
+ auto ctx = canvas->recordingContext();
SkASSERT(ctx);
GrOpMemoryPool* pool = ctx->priv().opMemoryPool();
@@ -332,9 +334,9 @@
void CCPRGeometryView::DrawCoverageCountOp::onExecute(GrOpFlushState* state,
const SkRect& chainBounds) {
GrResourceProvider* rp = state->resourceProvider();
- GrContext* context = state->gpu()->getContext();
+ auto direct = GrAsDirectContext(state->gpu()->getContext());
#ifdef SK_GL
- GrGLGpu* glGpu = GrBackendApi::kOpenGL == context->backend()
+ GrGLGpu* glGpu = GrBackendApi::kOpenGL == direct->backend()
? static_cast<GrGLGpu*>(state->gpu())
: nullptr;
if (glGpu) {
@@ -397,7 +399,7 @@
SkIRect::MakeWH(fView->width(), fView->height()), {0, 0});
GrCCStroker::BatchID batchID = stroker.closeCurrentBatch();
- GrOnFlushResourceProvider onFlushRP(context->priv().drawingManager());
+ GrOnFlushResourceProvider onFlushRP(direct->priv().drawingManager());
stroker.prepareToDraw(&onFlushRP);
SkIRect ibounds;
@@ -407,7 +409,7 @@
#ifdef SK_GL
if (glGpu) {
- context->resetContext(kMisc_GrGLBackendState);
+ direct->resetContext(kMisc_GrGLBackendState);
}
#endif
}
diff --git a/samplecode/SampleChineseFling.cpp b/samplecode/SampleChineseFling.cpp
index d16fa06..a9acef6 100644
--- a/samplecode/SampleChineseFling.cpp
+++ b/samplecode/SampleChineseFling.cpp
@@ -17,7 +17,7 @@
#include "include/utils/SkRandom.h"
#if SK_SUPPORT_GPU
-#include "include/gpu/GrContext.h"
+#include "include/gpu/GrDirectContext.h"
#include "src/gpu/GrContextPriv.h"
#endif
@@ -137,21 +137,21 @@
if (fAfterFirstFrame) {
#if SK_SUPPORT_GPU
- GrContext* grContext = canvas->getGrContext();
- if (grContext) {
- sk_sp<SkImage> image = grContext->priv().testingOnly_getFontAtlasImage(
+ auto direct = GrAsDirectContext(canvas->recordingContext());
+ if (direct) {
+ sk_sp<SkImage> image = direct->priv().testingOnly_getFontAtlasImage(
GrMaskFormat::kA8_GrMaskFormat, 0);
canvas->drawImageRect(image,
SkRect::MakeXYWH(10.0f, 10.0f, 512.0f, 512.0), &paint);
- image = grContext->priv().testingOnly_getFontAtlasImage(
+ image = direct->priv().testingOnly_getFontAtlasImage(
GrMaskFormat::kA8_GrMaskFormat, 1);
canvas->drawImageRect(image,
SkRect::MakeXYWH(522.0f, 10.0f, 512.f, 512.0f), &paint);
- image = grContext->priv().testingOnly_getFontAtlasImage(
+ image = direct->priv().testingOnly_getFontAtlasImage(
GrMaskFormat::kA8_GrMaskFormat, 2);
canvas->drawImageRect(image,
SkRect::MakeXYWH(10.0f, 522.0f, 512.0f, 512.0f), &paint);
- image = grContext->priv().testingOnly_getFontAtlasImage(
+ image = direct->priv().testingOnly_getFontAtlasImage(
GrMaskFormat::kA8_GrMaskFormat, 3);
canvas->drawImageRect(image,
SkRect::MakeXYWH(522.0f, 522.0f, 512.0f, 512.0f), &paint);
diff --git a/samplecode/SampleFlutterAnimate.cpp b/samplecode/SampleFlutterAnimate.cpp
index e3e53e0..67506d2 100644
--- a/samplecode/SampleFlutterAnimate.cpp
+++ b/samplecode/SampleFlutterAnimate.cpp
@@ -16,10 +16,6 @@
#include "samplecode/Sample.h"
#include "tools/timer/Timer.h"
-#if SK_SUPPORT_GPU
-#include "include/gpu/GrContext.h"
-#endif
-
// Create an animation of a bunch of letters that rotate in place. This is intended to stress
// the glyph atlas and test that we don't see corruption or bad slowdowns.
class FlutterAnimateView : public Sample {
diff --git a/samplecode/SampleTessellatedWedge.cpp b/samplecode/SampleTessellatedWedge.cpp
index 0598b1f..eff867d 100644
--- a/samplecode/SampleTessellatedWedge.cpp
+++ b/samplecode/SampleTessellatedWedge.cpp
@@ -12,10 +12,10 @@
#if SK_SUPPORT_GPU
-#include "include/gpu/GrContext.h"
+#include "include/gpu/GrRecordingContext.h"
#include "src/gpu/GrClip.h"
-#include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrMemoryPool.h"
+#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrRenderTargetContextPriv.h"
#include "src/gpu/tessellate/GrTessellatePathOp.h"
@@ -59,7 +59,7 @@
void TessellatedWedge::onDrawContent(SkCanvas* canvas) {
canvas->clear(SK_ColorBLACK);
- GrContext* ctx = canvas->getGrContext();
+ auto ctx = canvas->recordingContext();
GrRenderTargetContext* rtc = canvas->internal_private_accessTopLayerRenderTargetContext();
SkString error;
diff --git a/samplecode/SampleTextureUpload.cpp b/samplecode/SampleTextureUpload.cpp
index 920c672..420388c 100644
--- a/samplecode/SampleTextureUpload.cpp
+++ b/samplecode/SampleTextureUpload.cpp
@@ -9,7 +9,7 @@
#include "include/core/SkPaint.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
-#include "include/gpu/GrContext.h"
+#include "include/gpu/GrDirectContext.h"
#include "samplecode/Sample.h"
#include "tools/timer/TimeUtils.h"
@@ -31,11 +31,11 @@
class RenderTargetTexture : public SkRefCnt {
public:
- RenderTargetTexture(GrContext* context, int size) {
+ RenderTargetTexture(GrDirectContext* direct, int size) {
SkSurfaceProps surfaceProps(SkSurfaceProps::kLegacyFontHost_InitType);
SkImageInfo imageInfo = SkImageInfo::Make(size, size, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
- fSurface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, imageInfo, 0,
+ fSurface = SkSurface::MakeRenderTarget(direct, SkBudgeted::kNo, imageInfo, 0,
&surfaceProps);
}
@@ -55,7 +55,7 @@
};
SkTArray<sk_sp<RenderTargetTexture>> fTextures;
- GrContext* fCachedContext = nullptr;
+ GrDirectContext* fCachedContext = nullptr;
SkScalar fActiveTileIndex = 0;
SkString name() override {
@@ -92,11 +92,11 @@
this->setSize(1024, 1024);
}
- void initializeTextures(GrContext* context) {
+ void initializeTextures(GrDirectContext* direct) {
fTextures.reset();
int textureCount = fTileRows * fTileCols;
for (int i = 0; i < textureCount; i++) {
- fTextures.emplace_back(new RenderTargetTexture(context, fTileSize));
+ fTextures.emplace_back(new RenderTargetTexture(direct, fTileSize));
}
// Construct two simple rasters of differing colors to serve
@@ -109,12 +109,12 @@
#if SK_SUPPORT_GPU
SkPaint paint;
- GrContext* context = canvas->getGrContext();
- if (context) {
+ auto direct = GrAsDirectContext(canvas->recordingContext());
+ if (direct) {
// One-time context-specific setup.
- if (context != fCachedContext) {
- fCachedContext = context;
- this->initializeTextures(context);
+ if (direct != fCachedContext) {
+ fCachedContext = direct;
+ this->initializeTextures(direct);
}
// Upload new texture data for all textures, simulating a full page of tiles