Skip to content

Commit d1ce4cb

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Update some of the dox code to GrDirectContext
If we're to remove GrContext all uses must go! Change-Id: I487a973004c4f080fc5802128770b417d54628e2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301981 Reviewed-by: Adlai Holler <[email protected]> Commit-Queue: Robert Phillips <[email protected]>
1 parent 31890e2 commit d1ce4cb

10 files changed

+85
-57
lines changed

docs/examples/Canvas_getGrContext.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
// HASH=c4ea949e5fa5a0630dcb6b0204bd498f
55
REG_FIDDLE(Canvas_getGrContext, 256, 256, false, 0) {
66
void draw(SkCanvas* canvas) {
7-
if (canvas->getGrContext()) {
8-
canvas->clear(SK_ColorRED);
7+
if (auto context = canvas->recordingContext()) {
8+
if (context->asDirectContext()) {
9+
canvas->clear(SK_ColorRED);
10+
} else {
11+
canvas->clear(SK_ColorGREEN);
12+
}
913
} else {
1014
canvas->clear(SK_ColorBLUE);
1115
}

docs/examples/Image_getBackendTexture.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
1-
#if 0 // Disabled until updated to use current API.
21
// Copyright 2019 Google LLC.
32
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
43
#include "tools/fiddle/examples.h"
54
// HASH=d093aad721261f421c4bef4a296aab48
65
REG_FIDDLE(Image_getBackendTexture, 256, 256, false, 3) {
76
void draw(SkCanvas* canvas) {
8-
GrContext* grContext = canvas->getGrContext();
9-
if (!grContext) {
10-
canvas->drawString("GPU only!", 20, 40, SkPaint());
7+
SkFont font;
8+
SkPaint paint;
9+
10+
GrRecordingContext* context = canvas->recordingContext();
11+
if (!context) {
12+
canvas->drawString("GPU only!", 20, 40, font, paint);
1113
return;
1214
}
13-
sk_sp<SkImage> imageFromBackend = SkImage::MakeFromAdoptedTexture(grContext, backEndTexture,
14-
kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
15+
GrDirectContext* direct = context->asDirectContext();
16+
if (!direct) {
17+
canvas->drawString("Direct context only!", 20, 40, font, paint);
18+
return;
19+
}
20+
21+
sk_sp<SkImage> imageFromBackend = SkImage::MakeFromAdoptedTexture(direct,
22+
backEndTexture,
23+
kBottomLeft_GrSurfaceOrigin,
24+
kRGBA_8888_SkColorType,
25+
kOpaque_SkAlphaType);
1526
GrBackendTexture textureFromImage = imageFromBackend->getBackendTexture(false);
1627
if (!textureFromImage.isValid()) {
1728
return;
1829
}
19-
sk_sp<SkImage> imageFromTexture = SkImage::MakeFromAdoptedTexture(grContext, textureFromImage,
20-
kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
30+
sk_sp<SkImage> imageFromTexture = SkImage::MakeFromAdoptedTexture(direct,
31+
textureFromImage,
32+
kTopLeft_GrSurfaceOrigin,
33+
kRGBA_8888_SkColorType,
34+
kOpaque_SkAlphaType);
2135
canvas->drawImage(imageFromTexture, 0, 0);
2236
canvas->drawImage(imageFromBackend, 128, 128);
2337
}
2438
} // END FIDDLE
25-
#endif // Disabled until updated to use current API.

docs/examples/Image_isValid.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#if 0 // Disabled until updated to use current API.
21
// Copyright 2019 Google LLC.
32
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
43
#include "tools/fiddle/examples.h"
@@ -9,16 +8,22 @@ void draw(SkCanvas* canvas) {
98
if (nullptr == image) {
109
return;
1110
}
11+
SkFont font;
1212
SkPaint paint;
1313
paint.setAntiAlias(true);
1414
canvas->drawImage(image, 0, 0);
15-
canvas->drawString(label, image->width() / 2, image->height() / 4, paint);
16-
if (canvas->getGrContext()) {
17-
canvas->drawString(image->isValid(canvas->getGrContext()) ? "is valid on GPU" :
18-
"not valid on GPU", 20, image->height() * 5 / 8, paint);
15+
canvas->drawString(label, image->width() / 2, image->height() / 4, font, paint);
16+
if (canvas->recordingContext()) {
17+
const char* msg = image->isValid(canvas->recordingContext()) ? "is valid on GPU"
18+
: "not valid on GPU";
19+
canvas->drawString(msg, 20, image->height() * 5 / 8, font, paint);
1920
}
20-
canvas->drawString(image->isValid(nullptr) ? "is valid on CPU" :
21-
"not valid on CPU", 20, image->height() * 7 / 8, paint);
21+
22+
// CONTEXT TODO: Once GrContext is gone, remove this cast
23+
const char* msg = image->isValid((GrRecordingContext*) nullptr) ? "is valid on CPU"
24+
: "not valid on CPU";
25+
26+
canvas->drawString(msg, 20, image->height() * 7 / 8, font, paint);
2227
};
2328
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
2429
sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
@@ -31,4 +36,3 @@ void draw(SkCanvas* canvas) {
3136
drawImage(textureImage, "backEndTexture");
3237
}
3338
} // END FIDDLE
34-
#endif // Disabled until updated to use current API.

docs/examples/Surface_MakeFromBackendTexture.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
1-
#if 0 // Disabled until updated to use current API.
21
// Copyright 2019 Google LLC.
32
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
43
#include "tools/fiddle/examples.h"
54
// HASH=d3aec071998f871809f515e58abb1b0e
65
REG_FIDDLE(Surface_MakeFromBackendTexture, 256, 256, false, 3) {
76
void draw(SkCanvas* canvas) {
7+
SkFont font(nullptr, 32);
88
SkPaint paint;
9-
paint.setTextSize(32);
10-
GrContext* context = canvas->getGrContext();
9+
10+
GrRecordingContext* context = canvas->recordingContext();
1111
if (!context) {
12-
canvas->drawString("GPU only!", 20, 40, paint);
12+
canvas->drawString("GPU only!", 20, 40, font, paint);
1313
return;
1414
}
15-
sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTexture(context,
16-
backEndTexture, kTopLeft_GrSurfaceOrigin, 0,
17-
kRGBA_8888_SkColorType, nullptr, nullptr);
15+
GrDirectContext* direct = context->asDirectContext();
16+
if (!direct) {
17+
canvas->drawString("Direct Context only!", 20, 40, font, paint);
18+
return;
19+
}
20+
21+
sk_sp<SkSurface> gpuSurface = SkSurface::MakeFromBackendTexture(direct,
22+
backEndTexture,
23+
kTopLeft_GrSurfaceOrigin,
24+
0,
25+
kRGBA_8888_SkColorType,
26+
nullptr,
27+
nullptr,
28+
nullptr);
1829
auto surfaceCanvas = gpuSurface->getCanvas();
19-
surfaceCanvas->drawString("GPU rocks!", 20, 40, paint);
30+
surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint);
2031
sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
2132
canvas->drawImage(image, 0, 0);
2233
}
2334
} // END FIDDLE
24-
#endif // Disabled until updated to use current API.
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
#if 0 // Disabled until updated to use current API.
21
// Copyright 2019 Google LLC.
32
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
43
#include "tools/fiddle/examples.h"
54
// HASH=67b6609471a3f1ed0f4b1657004cdecb
65
REG_FIDDLE(Surface_MakeRenderTarget, 256, 64, false, 0) {
76
void draw(SkCanvas* canvas) {
7+
SkFont font(nullptr, 32);
88
SkPaint paint;
9-
paint.setTextSize(32);
10-
GrContext* context = canvas->getGrContext();
9+
10+
auto context = canvas->getGrContext();
1111
if (!context) {
12-
canvas->drawString("GPU only!", 20, 40, paint);
12+
canvas->drawString("GPU only!", 20, 40, font, paint);
1313
return;
1414
}
1515
SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType);
@@ -18,11 +18,10 @@ void draw(SkCanvas* canvas) {
1818
surfaceOrigin, nullptr));
1919
auto surfaceCanvas = gpuSurface->getCanvas();
2020
surfaceCanvas->clear(SK_ColorWHITE);
21-
surfaceCanvas->drawString("GPU rocks!", 20, 40, paint);
21+
surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint);
2222
sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
2323
canvas->drawImage(image, 0, 0);
2424
canvas->translate(0, 128);
2525
}
2626
}
2727
} // END FIDDLE
28-
#endif // Disabled until updated to use current API.

docs/examples/Surface_MakeRenderTarget_2.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
1-
#if 0 // Disabled until updated to use current API.
21
// Copyright 2019 Google LLC.
32
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
43
#include "tools/fiddle/examples.h"
54
// HASH=640321e8ecfb3f9329f3bc6e1f02485f
65
REG_FIDDLE(Surface_MakeRenderTarget_2, 256, 256, false, 0) {
76
void draw(SkCanvas* canvas) {
87
auto test_draw = [](SkCanvas* surfaceCanvas) -> void {
8+
SkFont font(nullptr, 32);
9+
910
SkPaint paint;
1011
paint.setAntiAlias(true);
11-
paint.setLCDRenderText(true);
12+
// TODO: where did this setting go?
13+
//paint.setLCDRenderText(true);
1214
paint.setColor(0xFFBBBBBB);
15+
1316
surfaceCanvas->drawRect(SkRect::MakeWH(128, 64), paint);
1417
paint.setColor(SK_ColorWHITE);
15-
paint.setTextSize(32);
16-
surfaceCanvas->drawString("Pest", 0, 25, paint);
18+
surfaceCanvas->drawString("Text", 0, 25, font, paint);
1719
};
18-
GrContext* context = canvas->getGrContext();
20+
auto context = canvas->recordingContext();
1921
SkImageInfo info = SkImageInfo::MakeN32(128, 64, kOpaque_SkAlphaType);
2022
int y = 0;
2123
for (auto geometry : { kRGB_H_SkPixelGeometry, kBGR_H_SkPixelGeometry,
2224
kRGB_V_SkPixelGeometry, kBGR_V_SkPixelGeometry } ) {
2325
SkSurfaceProps props(0, geometry);
24-
sk_sp<SkSurface> surface = context ? SkSurface::MakeRenderTarget(
25-
context, SkBudgeted::kNo, info, 0, &props) : SkSurface::MakeRaster(info, &props);
26+
sk_sp<SkSurface> surface = context
27+
? SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &props)
28+
: SkSurface::MakeRaster(info, &props);
2629
test_draw(surface->getCanvas());
2730
surface->draw(canvas, 0, y, nullptr);
2831
sk_sp<SkImage> image(surface->makeImageSnapshot());
@@ -33,4 +36,3 @@ void draw(SkCanvas* canvas) {
3336
}
3437
}
3538
} // END FIDDLE
36-
#endif // Disabled until updated to use current API.
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
#if 0 // Disabled until updated to use current API.
21
// Copyright 2019 Google LLC.
32
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
43
#include "tools/fiddle/examples.h"
54
// HASH=5c7629c15e9ac93f098335e72560fa2e
65
REG_FIDDLE(Surface_MakeRenderTarget_3, 256, 256, false, 0) {
76
void draw(SkCanvas* canvas) {
7+
SkFont font(nullptr, 32);
88
SkPaint paint;
9-
paint.setTextSize(32);
10-
GrContext* context = canvas->getGrContext();
9+
auto context = canvas->recordingContext();
1110
if (!context) {
12-
canvas->drawString("GPU only!", 20, 40, paint);
11+
canvas->drawString("GPU only!", 20, 40, font, paint);
1312
return;
1413
}
1514
SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType);
1615
auto gpuSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info));
1716
auto surfaceCanvas = gpuSurface->getCanvas();
1817
surfaceCanvas->clear(SK_ColorWHITE);
19-
surfaceCanvas->drawString("GPU rocks!", 20, 40, paint);
18+
surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint);
2019
sk_sp<SkImage> image(gpuSurface->makeImageSnapshot());
2120
canvas->drawImage(image, 0, 0);
2221
}
2322
} // END FIDDLE
24-
#endif // Disabled until updated to use current API.
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
#if 0 // Disabled until updated to use current API.
21
// Copyright 2019 Google LLC.
32
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
43
#include "tools/fiddle/examples.h"
54
// HASH=6de6f3ef699a72ff26da1b26b23a3316
65
REG_FIDDLE(Surface_characterize, 256, 64, false, 0) {
76
void draw(SkCanvas* canvas) {
7+
SkFont font(nullptr, 32);
88
SkPaint paint;
9-
paint.setTextSize(32);
10-
GrContext* context = canvas->getGrContext();
9+
auto context = canvas->recordingContext();
1110
if (!context) {
12-
canvas->drawString("GPU only!", 20, 40, paint);
11+
canvas->drawString("GPU only!", 20, 40, font, paint);
1312
return;
1413
}
1514
sk_sp<SkSurface> gpuSurface = SkSurface::MakeRenderTarget(
1615
context, SkBudgeted::kYes, SkImageInfo::MakeN32Premul(64, 64));
1716
SkSurfaceCharacterization characterization;
1817
if (!gpuSurface->characterize(&characterization)) {
19-
canvas->drawString("characterization unsupported", 20, 40, paint);
18+
canvas->drawString("characterization unsupported", 20, 40, font, paint);
2019
return;
2120
}
2221
// start of threadable work
@@ -30,4 +29,3 @@ void draw(SkCanvas* canvas) {
3029
canvas->drawImage(std::move(img), 0, 0);
3130
}
3231
} // END FIDDLE
33-
#endif // Disabled until updated to use current API.

docs/examples/blur4444.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ void draw(SkCanvas* canvas) {
2121

2222
sk_sp<SkSurface> surf;
2323
auto ii = SkImageInfo::Make(650, 480, kARGB_4444_SkColorType, kPremul_SkAlphaType);
24-
if (canvas->getGrContext() && !forceRaster) {
25-
surf = SkSurface::MakeRenderTarget(canvas->getGrContext(), SkBudgeted::kNo, ii);
24+
if (canvas->recordingContext() && !forceRaster) {
25+
surf = SkSurface::MakeRenderTarget(canvas->recordingContext(), SkBudgeted::kNo, ii);
2626
} else {
2727
surf = SkSurface::MakeRaster(ii);
2828
}

docs/examples/pong.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void draw(SkCanvas* canvas) {
2222
float bX = ballX * 472 + 20;
2323
float bY = ballY * 200 + 28;
2424

25-
if (canvas->getGrContext()) {
25+
if (canvas->recordingContext()) {
2626
canvas->drawRect(SkRect::MakeXYWH(236, bY - 15, 10, 30), p);
2727
bX -= 256;
2828
} else {

0 commit comments

Comments
 (0)