diff --git a/docs/examples/Canvas_getGrContext.cpp b/docs/examples/Canvas_getGrContext.cpp index f5ce3ceb43e7a..9695ce17bd46f 100644 --- a/docs/examples/Canvas_getGrContext.cpp +++ b/docs/examples/Canvas_getGrContext.cpp @@ -4,8 +4,12 @@ // HASH=c4ea949e5fa5a0630dcb6b0204bd498f REG_FIDDLE(Canvas_getGrContext, 256, 256, false, 0) { void draw(SkCanvas* canvas) { - if (canvas->getGrContext()) { - canvas->clear(SK_ColorRED); + if (auto context = canvas->recordingContext()) { + if (context->asDirectContext()) { + canvas->clear(SK_ColorRED); + } else { + canvas->clear(SK_ColorGREEN); + } } else { canvas->clear(SK_ColorBLUE); } diff --git a/docs/examples/Image_getBackendTexture.cpp b/docs/examples/Image_getBackendTexture.cpp index 0f4705b8d1223..4467d0cccc615 100644 --- a/docs/examples/Image_getBackendTexture.cpp +++ b/docs/examples/Image_getBackendTexture.cpp @@ -1,25 +1,38 @@ -#if 0 // Disabled until updated to use current API. // Copyright 2019 Google LLC. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "tools/fiddle/examples.h" // HASH=d093aad721261f421c4bef4a296aab48 REG_FIDDLE(Image_getBackendTexture, 256, 256, false, 3) { void draw(SkCanvas* canvas) { - GrContext* grContext = canvas->getGrContext(); - if (!grContext) { - canvas->drawString("GPU only!", 20, 40, SkPaint()); + SkFont font; + SkPaint paint; + + GrRecordingContext* context = canvas->recordingContext(); + if (!context) { + canvas->drawString("GPU only!", 20, 40, font, paint); return; } - sk_sp imageFromBackend = SkImage::MakeFromAdoptedTexture(grContext, backEndTexture, - kBottomLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); + GrDirectContext* direct = context->asDirectContext(); + if (!direct) { + canvas->drawString("Direct context only!", 20, 40, font, paint); + return; + } + + sk_sp imageFromBackend = SkImage::MakeFromAdoptedTexture(direct, + backEndTexture, + kBottomLeft_GrSurfaceOrigin, + kRGBA_8888_SkColorType, + kOpaque_SkAlphaType); GrBackendTexture textureFromImage = imageFromBackend->getBackendTexture(false); if (!textureFromImage.isValid()) { return; } - sk_sp imageFromTexture = SkImage::MakeFromAdoptedTexture(grContext, textureFromImage, - kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); + sk_sp imageFromTexture = SkImage::MakeFromAdoptedTexture(direct, + textureFromImage, + kTopLeft_GrSurfaceOrigin, + kRGBA_8888_SkColorType, + kOpaque_SkAlphaType); canvas->drawImage(imageFromTexture, 0, 0); canvas->drawImage(imageFromBackend, 128, 128); } } // END FIDDLE -#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_isValid.cpp b/docs/examples/Image_isValid.cpp index 4d58a4f018255..ae30b2af77286 100644 --- a/docs/examples/Image_isValid.cpp +++ b/docs/examples/Image_isValid.cpp @@ -1,4 +1,3 @@ -#if 0 // Disabled until updated to use current API. // Copyright 2019 Google LLC. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "tools/fiddle/examples.h" @@ -9,16 +8,22 @@ void draw(SkCanvas* canvas) { if (nullptr == image) { return; } + SkFont font; SkPaint paint; paint.setAntiAlias(true); canvas->drawImage(image, 0, 0); - canvas->drawString(label, image->width() / 2, image->height() / 4, paint); - if (canvas->getGrContext()) { - canvas->drawString(image->isValid(canvas->getGrContext()) ? "is valid on GPU" : - "not valid on GPU", 20, image->height() * 5 / 8, paint); + canvas->drawString(label, image->width() / 2, image->height() / 4, font, paint); + if (canvas->recordingContext()) { + const char* msg = image->isValid(canvas->recordingContext()) ? "is valid on GPU" + : "not valid on GPU"; + canvas->drawString(msg, 20, image->height() * 5 / 8, font, paint); } - canvas->drawString(image->isValid(nullptr) ? "is valid on CPU" : - "not valid on CPU", 20, image->height() * 7 / 8, paint); + + // CONTEXT TODO: Once GrContext is gone, remove this cast + const char* msg = image->isValid((GrRecordingContext*) nullptr) ? "is valid on CPU" + : "not valid on CPU"; + + canvas->drawString(msg, 20, image->height() * 7 / 8, font, paint); }; sk_sp bitmapImage(SkImage::MakeFromBitmap(source)); sk_sp textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, @@ -31,4 +36,3 @@ void draw(SkCanvas* canvas) { drawImage(textureImage, "backEndTexture"); } } // END FIDDLE -#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_MakeFromBackendTexture.cpp b/docs/examples/Surface_MakeFromBackendTexture.cpp index 4abf0dfbe6d13..f0b95e6e29032 100644 --- a/docs/examples/Surface_MakeFromBackendTexture.cpp +++ b/docs/examples/Surface_MakeFromBackendTexture.cpp @@ -1,24 +1,34 @@ -#if 0 // Disabled until updated to use current API. // Copyright 2019 Google LLC. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "tools/fiddle/examples.h" // HASH=d3aec071998f871809f515e58abb1b0e REG_FIDDLE(Surface_MakeFromBackendTexture, 256, 256, false, 3) { void draw(SkCanvas* canvas) { + SkFont font(nullptr, 32); SkPaint paint; - paint.setTextSize(32); - GrContext* context = canvas->getGrContext(); + + GrRecordingContext* context = canvas->recordingContext(); if (!context) { - canvas->drawString("GPU only!", 20, 40, paint); + canvas->drawString("GPU only!", 20, 40, font, paint); return; } - sk_sp gpuSurface = SkSurface::MakeFromBackendTexture(context, - backEndTexture, kTopLeft_GrSurfaceOrigin, 0, - kRGBA_8888_SkColorType, nullptr, nullptr); + GrDirectContext* direct = context->asDirectContext(); + if (!direct) { + canvas->drawString("Direct Context only!", 20, 40, font, paint); + return; + } + + sk_sp gpuSurface = SkSurface::MakeFromBackendTexture(direct, + backEndTexture, + kTopLeft_GrSurfaceOrigin, + 0, + kRGBA_8888_SkColorType, + nullptr, + nullptr, + nullptr); auto surfaceCanvas = gpuSurface->getCanvas(); - surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); + surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint); sk_sp image(gpuSurface->makeImageSnapshot()); canvas->drawImage(image, 0, 0); } } // END FIDDLE -#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_MakeRenderTarget.cpp b/docs/examples/Surface_MakeRenderTarget.cpp index 4ee09f9ae659c..0f88cf8929067 100644 --- a/docs/examples/Surface_MakeRenderTarget.cpp +++ b/docs/examples/Surface_MakeRenderTarget.cpp @@ -1,15 +1,15 @@ -#if 0 // Disabled until updated to use current API. // Copyright 2019 Google LLC. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "tools/fiddle/examples.h" // HASH=67b6609471a3f1ed0f4b1657004cdecb REG_FIDDLE(Surface_MakeRenderTarget, 256, 64, false, 0) { void draw(SkCanvas* canvas) { + SkFont font(nullptr, 32); SkPaint paint; - paint.setTextSize(32); - GrContext* context = canvas->getGrContext(); + + auto context = canvas->getGrContext(); if (!context) { - canvas->drawString("GPU only!", 20, 40, paint); + canvas->drawString("GPU only!", 20, 40, font, paint); return; } SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType); @@ -18,11 +18,10 @@ void draw(SkCanvas* canvas) { surfaceOrigin, nullptr)); auto surfaceCanvas = gpuSurface->getCanvas(); surfaceCanvas->clear(SK_ColorWHITE); - surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); + surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint); sk_sp image(gpuSurface->makeImageSnapshot()); canvas->drawImage(image, 0, 0); canvas->translate(0, 128); } } } // END FIDDLE -#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_MakeRenderTarget_2.cpp b/docs/examples/Surface_MakeRenderTarget_2.cpp index b7718ae91ae1d..ff8046d2ccf60 100644 --- a/docs/examples/Surface_MakeRenderTarget_2.cpp +++ b/docs/examples/Surface_MakeRenderTarget_2.cpp @@ -1,4 +1,3 @@ -#if 0 // Disabled until updated to use current API. // Copyright 2019 Google LLC. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "tools/fiddle/examples.h" @@ -6,23 +5,27 @@ REG_FIDDLE(Surface_MakeRenderTarget_2, 256, 256, false, 0) { void draw(SkCanvas* canvas) { auto test_draw = [](SkCanvas* surfaceCanvas) -> void { + SkFont font(nullptr, 32); + SkPaint paint; paint.setAntiAlias(true); - paint.setLCDRenderText(true); + // TODO: where did this setting go? + //paint.setLCDRenderText(true); paint.setColor(0xFFBBBBBB); + surfaceCanvas->drawRect(SkRect::MakeWH(128, 64), paint); paint.setColor(SK_ColorWHITE); - paint.setTextSize(32); - surfaceCanvas->drawString("Pest", 0, 25, paint); + surfaceCanvas->drawString("Text", 0, 25, font, paint); }; - GrContext* context = canvas->getGrContext(); + auto context = canvas->recordingContext(); SkImageInfo info = SkImageInfo::MakeN32(128, 64, kOpaque_SkAlphaType); int y = 0; for (auto geometry : { kRGB_H_SkPixelGeometry, kBGR_H_SkPixelGeometry, kRGB_V_SkPixelGeometry, kBGR_V_SkPixelGeometry } ) { SkSurfaceProps props(0, geometry); - sk_sp surface = context ? SkSurface::MakeRenderTarget( - context, SkBudgeted::kNo, info, 0, &props) : SkSurface::MakeRaster(info, &props); + sk_sp surface = context + ? SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, &props) + : SkSurface::MakeRaster(info, &props); test_draw(surface->getCanvas()); surface->draw(canvas, 0, y, nullptr); sk_sp image(surface->makeImageSnapshot()); @@ -33,4 +36,3 @@ void draw(SkCanvas* canvas) { } } } // END FIDDLE -#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_MakeRenderTarget_3.cpp b/docs/examples/Surface_MakeRenderTarget_3.cpp index 62b94ebc328ee..0c098de9a2828 100644 --- a/docs/examples/Surface_MakeRenderTarget_3.cpp +++ b/docs/examples/Surface_MakeRenderTarget_3.cpp @@ -1,24 +1,22 @@ -#if 0 // Disabled until updated to use current API. // Copyright 2019 Google LLC. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "tools/fiddle/examples.h" // HASH=5c7629c15e9ac93f098335e72560fa2e REG_FIDDLE(Surface_MakeRenderTarget_3, 256, 256, false, 0) { void draw(SkCanvas* canvas) { + SkFont font(nullptr, 32); SkPaint paint; - paint.setTextSize(32); - GrContext* context = canvas->getGrContext(); + auto context = canvas->recordingContext(); if (!context) { - canvas->drawString("GPU only!", 20, 40, paint); + canvas->drawString("GPU only!", 20, 40, font, paint); return; } SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType); auto gpuSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); auto surfaceCanvas = gpuSurface->getCanvas(); surfaceCanvas->clear(SK_ColorWHITE); - surfaceCanvas->drawString("GPU rocks!", 20, 40, paint); + surfaceCanvas->drawString("GPU rocks!", 20, 40, font, paint); sk_sp image(gpuSurface->makeImageSnapshot()); canvas->drawImage(image, 0, 0); } } // END FIDDLE -#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_characterize.cpp b/docs/examples/Surface_characterize.cpp index a83f14f3c380a..008216adbcd30 100644 --- a/docs/examples/Surface_characterize.cpp +++ b/docs/examples/Surface_characterize.cpp @@ -1,22 +1,21 @@ -#if 0 // Disabled until updated to use current API. // Copyright 2019 Google LLC. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. #include "tools/fiddle/examples.h" // HASH=6de6f3ef699a72ff26da1b26b23a3316 REG_FIDDLE(Surface_characterize, 256, 64, false, 0) { void draw(SkCanvas* canvas) { + SkFont font(nullptr, 32); SkPaint paint; - paint.setTextSize(32); - GrContext* context = canvas->getGrContext(); + auto context = canvas->recordingContext(); if (!context) { - canvas->drawString("GPU only!", 20, 40, paint); + canvas->drawString("GPU only!", 20, 40, font, paint); return; } sk_sp gpuSurface = SkSurface::MakeRenderTarget( context, SkBudgeted::kYes, SkImageInfo::MakeN32Premul(64, 64)); SkSurfaceCharacterization characterization; if (!gpuSurface->characterize(&characterization)) { - canvas->drawString("characterization unsupported", 20, 40, paint); + canvas->drawString("characterization unsupported", 20, 40, font, paint); return; } // start of threadable work @@ -30,4 +29,3 @@ void draw(SkCanvas* canvas) { canvas->drawImage(std::move(img), 0, 0); } } // END FIDDLE -#endif // Disabled until updated to use current API. diff --git a/docs/examples/blur4444.cpp b/docs/examples/blur4444.cpp index 932cb689a04c3..873c97ef24cd6 100644 --- a/docs/examples/blur4444.cpp +++ b/docs/examples/blur4444.cpp @@ -21,8 +21,8 @@ void draw(SkCanvas* canvas) { sk_sp surf; auto ii = SkImageInfo::Make(650, 480, kARGB_4444_SkColorType, kPremul_SkAlphaType); - if (canvas->getGrContext() && !forceRaster) { - surf = SkSurface::MakeRenderTarget(canvas->getGrContext(), SkBudgeted::kNo, ii); + if (canvas->recordingContext() && !forceRaster) { + surf = SkSurface::MakeRenderTarget(canvas->recordingContext(), SkBudgeted::kNo, ii); } else { surf = SkSurface::MakeRaster(ii); } diff --git a/docs/examples/pong.cpp b/docs/examples/pong.cpp index ccc02d31013a4..ca297c9f1ae2a 100644 --- a/docs/examples/pong.cpp +++ b/docs/examples/pong.cpp @@ -22,7 +22,7 @@ void draw(SkCanvas* canvas) { float bX = ballX * 472 + 20; float bY = ballY * 200 + 28; - if (canvas->getGrContext()) { + if (canvas->recordingContext()) { canvas->drawRect(SkRect::MakeXYWH(236, bY - 15, 10, 30), p); bX -= 256; } else {