Skip to content

Commit 16bf7d3

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Make SkGpuDevice hold a GrRecordingContext (take 2)
This makes the code reflect what is actually going on. During DDL recording the SkGpuDevice only holds a recording context. This can't land until the following Chrome-side CL lands: https://chromium-review.googlesource.com/c/chromium/src/+/2277964 (Add GrContext.h include to skia renderer for upcoming Skia roll) Reviewed-on: https://skia-review.googlesource.com/c/skia/+/299867 Commit-Queue: Robert Phillips <[email protected]> Reviewed-by: Brian Salomon <[email protected]> Reviewed-by: Adlai Holler <[email protected]> Change-Id: I6ef3896f5a270a4fa7af37f9121f68a66653cce2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/300896
1 parent 112a716 commit 16bf7d3

23 files changed

+231
-121
lines changed

bench/GrMipMapBench.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class GrMipMapBench: public Benchmark {
3030

3131
void onDraw(int loops, SkCanvas* canvas) override {
3232
if (!fSurface) {
33-
GrContext* context = canvas->getGrContext();
34-
if (nullptr == context) {
33+
auto context = canvas->recordingContext();
34+
if (!context) {
3535
return;
3636
}
3737
auto srgb = SkColorSpace::MakeSRGB();

gm/dftext.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
#include <string.h>
3434

35-
class GrContext;
36-
3735
class DFTextGM : public skiagm::GM {
3836
public:
3937
DFTextGM() {
@@ -59,7 +57,7 @@ class DFTextGM : public skiagm::GM {
5957
SkScalar scales[] = { 2.0f*5.0f, 5.0f, 2.0f, 1.0f };
6058

6159
// set up offscreen rendering with distance field text
62-
GrContext* ctx = inputCanvas->getGrContext();
60+
auto ctx = inputCanvas->recordingContext();
6361
SkISize size = onISize();
6462
SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(), kPremul_SkAlphaType,
6563
inputCanvas->imageInfo().refColorSpace());

gm/dftext_blob_persp.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727

2828
#include <initializer_list>
2929

30-
class GrContext;
31-
3230
/**
3331
* This GM tests reusing the same text blobs with distance fields rendering using various
3432
* combinations of perspective and non-perspetive matrices, scissor clips, and different x,y params
@@ -60,8 +58,8 @@ class DFTextBlobPerspGM : public skiagm::GM {
6058
}
6159

6260
void onDraw(SkCanvas* inputCanvas) override {
63-
// set up offscreen rendering with distance field text
64-
GrContext* ctx = inputCanvas->getGrContext();
61+
// set up offscreen rendering with distance field text
62+
auto ctx = inputCanvas->recordingContext();
6563
SkISize size = this->onISize();
6664
if (!inputCanvas->getBaseLayerSize().isEmpty()) {
6765
size = inputCanvas->getBaseLayerSize();

gm/image.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#include <functional>
4141
#include <utility>
4242

43-
class GrContext;
4443
class GrRenderTargetContext;
4544

4645
static void drawContents(SkSurface* surface, SkColor fillC) {
@@ -160,7 +159,7 @@ class ImageGM : public skiagm::GM {
160159
SkImageInfo info = SkImageInfo::MakeN32Premul(W, H);
161160
sk_sp<SkSurface> surf0(SkSurface::MakeRasterDirect(info, fBuffer, RB));
162161
sk_sp<SkSurface> surf1(SkSurface::MakeRaster(info));
163-
sk_sp<SkSurface> surf2(SkSurface::MakeRenderTarget(canvas->getGrContext(),
162+
sk_sp<SkSurface> surf2(SkSurface::MakeRenderTarget(canvas->recordingContext(),
164163
SkBudgeted::kNo, info));
165164

166165
test_surface(canvas, surf0.get(), true);
@@ -222,34 +221,50 @@ static void draw_contents(SkCanvas* canvas) {
222221
canvas->drawCircle(50, 50, 35, paint);
223222
}
224223

225-
static sk_sp<SkImage> make_raster(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) {
224+
static sk_sp<SkImage> make_raster(const SkImageInfo& info,
225+
GrRecordingContext*,
226+
void (*draw)(SkCanvas*)) {
226227
auto surface(SkSurface::MakeRaster(info));
227228
draw(surface->getCanvas());
228229
return surface->makeImageSnapshot();
229230
}
230231

231-
static sk_sp<SkImage> make_picture(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) {
232+
static sk_sp<SkImage> make_picture(const SkImageInfo& info,
233+
GrRecordingContext*,
234+
void (*draw)(SkCanvas*)) {
232235
SkPictureRecorder recorder;
233236
draw(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height())));
234237
return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
235238
info.dimensions(), nullptr, nullptr, SkImage::BitDepth::kU8,
236239
SkColorSpace::MakeSRGB());
237240
}
238241

239-
static sk_sp<SkImage> make_codec(const SkImageInfo& info, GrContext*, void (*draw)(SkCanvas*)) {
242+
static sk_sp<SkImage> make_codec(const SkImageInfo& info,
243+
GrRecordingContext*,
244+
void (*draw)(SkCanvas*)) {
240245
sk_sp<SkImage> image(make_raster(info, nullptr, draw));
241246
return SkImage::MakeFromEncoded(image->encodeToData());
242247
}
243248

244-
static sk_sp<SkImage> make_gpu(const SkImageInfo& info, GrContext* ctx, void (*draw)(SkCanvas*)) {
245-
if (!ctx) { return nullptr; }
249+
static sk_sp<SkImage> make_gpu(const SkImageInfo& info,
250+
GrRecordingContext* ctx,
251+
void (*draw)(SkCanvas*)) {
252+
if (!ctx) {
253+
return nullptr;
254+
}
255+
246256
auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
247-
if (!surface) { return nullptr; }
257+
if (!surface) {
258+
return nullptr;
259+
}
260+
248261
draw(surface->getCanvas());
249262
return surface->makeImageSnapshot();
250263
}
251264

252-
typedef sk_sp<SkImage> (*ImageMakerProc)(const SkImageInfo&, GrContext*, void (*)(SkCanvas*));
265+
typedef sk_sp<SkImage> (*ImageMakerProc)(const SkImageInfo&,
266+
GrRecordingContext*,
267+
void (*)(SkCanvas*));
253268

254269
class ScalePixelsGM : public skiagm::GM {
255270
public:
@@ -271,7 +286,7 @@ class ScalePixelsGM : public skiagm::GM {
271286
make_codec, make_raster, make_picture, make_codec, make_gpu,
272287
};
273288
for (auto& proc : procs) {
274-
sk_sp<SkImage> image(proc(info, canvas->getGrContext(), draw_contents));
289+
sk_sp<SkImage> image(proc(info, canvas->recordingContext(), draw_contents));
275290
if (image) {
276291
show_scaled_pixels(canvas, image.get());
277292
}
@@ -337,8 +352,8 @@ DEF_SIMPLE_GPU_GM(new_texture_image, context, rtc, canvas, 280, 60) {
337352
SkImage::BitDepth::kU8, srgbColorSpace);
338353
},
339354
// Create a texture image
340-
[direct, render_image]() -> sk_sp<SkImage> {
341-
auto surface(SkSurface::MakeRenderTarget(direct, SkBudgeted::kYes,
355+
[context, render_image]() -> sk_sp<SkImage> {
356+
auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
342357
SkImageInfo::MakeS32(kSize, kSize,
343358
kPremul_SkAlphaType)));
344359
if (!surface) {

gm/image_shader.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
#include <utility>
3030

31-
class GrContext;
32-
3331
static void draw_something(SkCanvas* canvas, const SkRect& bounds) {
3432
SkPaint paint;
3533
paint.setAntiAlias(true);
@@ -42,16 +40,20 @@ static void draw_something(SkCanvas* canvas, const SkRect& bounds) {
4240
canvas->drawOval(bounds, paint);
4341
}
4442

45-
typedef sk_sp<SkImage> (*ImageMakerProc)(GrContext*, SkPicture*, const SkImageInfo&);
43+
typedef sk_sp<SkImage> (*ImageMakerProc)(GrRecordingContext*, SkPicture*, const SkImageInfo&);
4644

47-
static sk_sp<SkImage> make_raster(GrContext*, SkPicture* pic, const SkImageInfo& info) {
45+
static sk_sp<SkImage> make_raster(GrRecordingContext*,
46+
SkPicture* pic,
47+
const SkImageInfo& info) {
4848
auto surface(SkSurface::MakeRaster(info));
4949
surface->getCanvas()->clear(0);
5050
surface->getCanvas()->drawPicture(pic);
5151
return surface->makeImageSnapshot();
5252
}
5353

54-
static sk_sp<SkImage> make_texture(GrContext* ctx, SkPicture* pic, const SkImageInfo& info) {
54+
static sk_sp<SkImage> make_texture(GrRecordingContext* ctx,
55+
SkPicture* pic,
56+
const SkImageInfo& info) {
5557
if (!ctx) {
5658
return nullptr;
5759
}
@@ -64,13 +66,17 @@ static sk_sp<SkImage> make_texture(GrContext* ctx, SkPicture* pic, const SkImage
6466
return surface->makeImageSnapshot();
6567
}
6668

67-
static sk_sp<SkImage> make_pict_gen(GrContext*, SkPicture* pic, const SkImageInfo& info) {
69+
static sk_sp<SkImage> make_pict_gen(GrRecordingContext*,
70+
SkPicture* pic,
71+
const SkImageInfo& info) {
6872
return SkImage::MakeFromPicture(sk_ref_sp(pic), info.dimensions(), nullptr, nullptr,
6973
SkImage::BitDepth::kU8,
7074
SkColorSpace::MakeSRGB());
7175
}
7276

73-
static sk_sp<SkImage> make_encode_gen(GrContext* ctx, SkPicture* pic, const SkImageInfo& info) {
77+
static sk_sp<SkImage> make_encode_gen(GrRecordingContext* ctx,
78+
SkPicture* pic,
79+
const SkImageInfo& info) {
7480
sk_sp<SkImage> src(make_raster(ctx, pic, info));
7581
if (!src) {
7682
return nullptr;
@@ -135,7 +141,7 @@ class ImageShaderGM : public skiagm::GM {
135141
const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
136142

137143
for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) {
138-
sk_sp<SkImage> image(gProcs[i](canvas->getGrContext(), fPicture.get(), info));
144+
sk_sp<SkImage> image(gProcs[i](canvas->recordingContext(), fPicture.get(), info));
139145
if (image) {
140146
this->testImage(canvas, image.get());
141147
}

gm/imagemasksubset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const MakerT makers[] = {
5959
// SkImage_Gpu
6060
[](SkCanvas* c, const SkImageInfo& info) -> sk_sp<SkImage> {
6161
sk_sp<SkSurface> surface;
62-
surface = SkSurface::MakeRenderTarget(c->getGrContext(), SkBudgeted::kNo, info);
62+
surface = SkSurface::MakeRenderTarget(c->recordingContext(), SkBudgeted::kNo, info);
6363
return make_mask(surface ? surface : SkSurface::MakeRaster(info));
6464
},
6565

gm/simple_magnification.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626

2727
#include <utility>
2828

29-
class GrContext;
30-
31-
static sk_sp<SkImage> make_image(GrContext* context, int size, GrSurfaceOrigin origin) {
29+
static sk_sp<SkImage> make_image(GrRecordingContext* context, int size, GrSurfaceOrigin origin) {
3230
if (context) {
3331
SkImageInfo ii = SkImageInfo::Make(size, size, kN32_SkColorType, kPremul_SkAlphaType);
3432
sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, ii, 0,
@@ -114,7 +112,7 @@ class SimpleMagnificationGM : public skiagm::GM {
114112
}
115113

116114
DrawResult onDraw(SkCanvas* canvas, SkString* errorMsg) override {
117-
GrContext* context = canvas->getGrContext();
115+
auto context = canvas->recordingContext();
118116

119117
sk_sp<SkImage> bottomLImg = make_image(context, kImgSize, kBottomLeft_GrSurfaceOrigin);
120118
sk_sp<SkImage> topLImg = make_image(context, kImgSize, kTopLeft_GrSurfaceOrigin);

gm/surface.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
#include "include/utils/SkTextUtils.h"
3131
#include "tools/ToolUtils.h"
3232

33-
class GrContext;
34-
3533
#define W 200
3634
#define H 100
3735

@@ -43,7 +41,9 @@ static sk_sp<SkShader> make_shader() {
4341
return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
4442
}
4543

46-
static sk_sp<SkSurface> make_surface(GrContext* ctx, const SkImageInfo& info, SkPixelGeometry geo) {
44+
static sk_sp<SkSurface> make_surface(GrRecordingContext* ctx,
45+
const SkImageInfo& info,
46+
SkPixelGeometry geo) {
4747
SkSurfaceProps props(0, geo);
4848
if (ctx) {
4949
return SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, 0, &props);
@@ -83,7 +83,7 @@ class SurfacePropsGM : public skiagm::GM {
8383
}
8484

8585
void onDraw(SkCanvas* canvas) override {
86-
GrContext* ctx = canvas->getGrContext();
86+
auto ctx = canvas->recordingContext();
8787

8888
// must be opaque to have a hope of testing LCD text
8989
const SkImageInfo info = SkImageInfo::MakeN32(W, H, kOpaque_SkAlphaType);

gm/textblobmixedsizes.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
#include <string.h>
3434

35-
class GrContext;
36-
3735
namespace skiagm {
3836
class TextBlobMixedSizes : public GM {
3937
public:
@@ -107,7 +105,7 @@ class TextBlobMixedSizes : public GM {
107105
sk_sp<SkSurface> surface;
108106
if (fUseDFT) {
109107
// Create a new Canvas to enable DFT
110-
GrContext* ctx = inputCanvas->getGrContext();
108+
auto ctx = inputCanvas->recordingContext();
111109
SkISize size = onISize();
112110
sk_sp<SkColorSpace> colorSpace = inputCanvas->imageInfo().refColorSpace();
113111
SkImageInfo info = SkImageInfo::MakeN32(size.width(), size.height(),

include/core/SkSurface.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,14 @@ class SK_API SkSurface : public SkRefCnt {
364364
@param shouldCreateWithMips hint that SkSurface will host mip map images
365365
@return SkSurface if all parameters are valid; otherwise, nullptr
366366
*/
367+
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
368+
const SkImageInfo& imageInfo,
369+
int sampleCount, GrSurfaceOrigin surfaceOrigin,
370+
const SkSurfaceProps* surfaceProps,
371+
bool shouldCreateWithMips = false);
372+
373+
/** Deprecated.
374+
*/
367375
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
368376
const SkImageInfo& imageInfo,
369377
int sampleCount, GrSurfaceOrigin surfaceOrigin,
@@ -391,13 +399,19 @@ class SK_API SkSurface : public SkRefCnt {
391399
fonts; may be nullptr
392400
@return SkSurface if all parameters are valid; otherwise, nullptr
393401
*/
394-
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
402+
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
395403
const SkImageInfo& imageInfo, int sampleCount,
396404
const SkSurfaceProps* surfaceProps) {
397405
return MakeRenderTarget(context, budgeted, imageInfo, sampleCount,
398406
kBottomLeft_GrSurfaceOrigin, surfaceProps);
399407
}
400408

409+
/** Deprecated.
410+
*/
411+
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
412+
const SkImageInfo& imageInfo, int sampleCount,
413+
const SkSurfaceProps* surfaceProps);
414+
401415
/** Returns SkSurface on GPU indicated by context. Allocates memory for
402416
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
403417
selects whether allocation for pixels is tracked by context. imageInfo
@@ -411,7 +425,7 @@ class SK_API SkSurface : public SkRefCnt {
411425
of raster surface; width, or height, or both, may be zero
412426
@return SkSurface if all parameters are valid; otherwise, nullptr
413427
*/
414-
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
428+
static sk_sp<SkSurface> MakeRenderTarget(GrRecordingContext* context, SkBudgeted budgeted,
415429
const SkImageInfo& imageInfo) {
416430
if (!imageInfo.width() || !imageInfo.height()) {
417431
return nullptr;
@@ -420,6 +434,11 @@ class SK_API SkSurface : public SkRefCnt {
420434
nullptr);
421435
}
422436

437+
/** Deprecated.
438+
*/
439+
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
440+
const SkImageInfo& imageInfo);
441+
423442
/** Returns SkSurface on GPU indicated by context that is compatible with the provided
424443
characterization. budgeted selects whether allocation for pixels is tracked by context.
425444

0 commit comments

Comments
 (0)