diff --git a/BUILD.gn b/BUILD.gn index 352acee9a6..be230ba764 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2245,6 +2245,22 @@ if (skia_enable_tools) { } } + import("gn/examples.gni") + if (!skia_use_vulkan && (is_mac || is_linux || is_win)) { + test_app("fiddle_examples") { + sources = [ + "tools/fiddle/examples.cpp", + "tools/fiddle/examples.h" + ] + sources += examples_sources + include_dirs = [ "tools" ] + deps = [ + ":skia", + ":skia.h", + "modules/skottie", + ] + } + } test_app("viewer") { is_shared_library = is_android if (is_ios) { diff --git a/docs/examples/AutoCanvasRestore_000.cpp b/docs/examples/AutoCanvasRestore_000.cpp new file mode 100644 index 0000000000..d7f2de32ee --- /dev/null +++ b/docs/examples/AutoCanvasRestore_000.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=466ef576b88e29d7252422db7adeed1c +REG_FIDDLE(AutoCanvasRestore_000, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkFont font(nullptr, 64); + for (SkScalar sx : { -1, 1 } ) { + for (SkScalar sy : { -1, 1 } ) { + SkAutoCanvasRestore autoRestore(canvas, true); + SkMatrix m = SkMatrix::MakeAll(sx, 1, 96, 0, sy, 64, 0, 0, 1); + canvas->concat(m); + canvas->drawString("R", 0, 0, font, paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/AutoCanvasRestore_001.cpp b/docs/examples/AutoCanvasRestore_001.cpp new file mode 100644 index 0000000000..6176b86f7f --- /dev/null +++ b/docs/examples/AutoCanvasRestore_001.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=9f459b218ec079c1ada23f4412968f9a +REG_FIDDLE(AutoCanvasRestore_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + for (bool callRestore : { false, true } ) { + for (bool saveCanvas : {false, true} ) { + SkAutoCanvasRestore autoRestore(canvas, saveCanvas); + if (!saveCanvas) { + canvas->save(); + } + SkDebugf("saveCanvas: %s before restore: %d\n", + saveCanvas ? "true" : "false", canvas->getSaveCount()); + if (callRestore) autoRestore.restore(); + SkDebugf("saveCanvas: %s after restore: %d\n", + saveCanvas ? "true" : "false", canvas->getSaveCount()); + } + } + SkDebugf("final count: %d\n", canvas->getSaveCount()); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_000.cpp b/docs/examples/Bitmap_000.cpp new file mode 100644 index 0000000000..0bfebc915c --- /dev/null +++ b/docs/examples/Bitmap_000.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=fe79a9c1ec350264eb9c7b2509dd3638 +REG_FIDDLE(Bitmap_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType)); + SkDebugf("pixel address = %p\n", bitmap.getPixels()); + SkBitmap::HeapAllocator stdalloc; + if (!stdalloc.allocPixelRef(&bitmap)) { + SkDebugf("pixel allocation failed\n"); + } else { + SkDebugf("pixel address = %p\n", bitmap.getPixels()); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_001.cpp b/docs/examples/Bitmap_001.cpp new file mode 100644 index 0000000000..39613b1fd9 --- /dev/null +++ b/docs/examples/Bitmap_001.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=6739d14ec0d6a373f2fcadc6b3077fd4 +REG_FIDDLE(Bitmap_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkBitmap bitmap; + for (int i = 0; i < 2; ++i) { + SkDebugf("width: %2d height: %2d", bitmap.width(), bitmap.height()); + SkDebugf(" color: k%s_SkColorType", colors[bitmap.colorType()]); + SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[bitmap.alphaType()]); + bitmap.setInfo(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType), + 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_002.cpp b/docs/examples/Bitmap_002.cpp new file mode 100644 index 0000000000..6e2ca88e2d --- /dev/null +++ b/docs/examples/Bitmap_002.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=bbbae7a181bfd128a4484e8e9f454db1 +REG_FIDDLE(Bitmap_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap original; + if (original.tryAllocPixels( + SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) { + SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false"); + SkBitmap copy(original); + SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false"); + SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_003.cpp b/docs/examples/Bitmap_003.cpp new file mode 100644 index 0000000000..6c307af810 --- /dev/null +++ b/docs/examples/Bitmap_003.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=40afd4f1fa69e02d69d92b38252088ef +REG_FIDDLE(Bitmap_003, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap original; + if (original.tryAllocPixels( + SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) { + SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false"); + SkBitmap copy(std::move(original)); + // NOLINTNEXTLINE(bugprone-use-after-move) + SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false"); + SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_004.cpp b/docs/examples/Bitmap_004.cpp new file mode 100644 index 0000000000..f0e7bfe1da --- /dev/null +++ b/docs/examples/Bitmap_004.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=45279c519ae808f78bd30e9d84bdfdde +REG_FIDDLE(Bitmap_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap original; + if (original.tryAllocPixels( + SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) { + SkDebugf("original has pixels before copy: %s\n", original.getPixels() ? "true" : "false"); + SkBitmap copy = original; + SkDebugf("original has pixels after copy: %s\n", original.getPixels() ? "true" : "false"); + SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_005.cpp b/docs/examples/Bitmap_005.cpp new file mode 100644 index 0000000000..c4bb112794 --- /dev/null +++ b/docs/examples/Bitmap_005.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=35ea3fed27d8db22dc00f48670de64de +REG_FIDDLE(Bitmap_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap original; + if (original.tryAllocPixels( + SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) { + SkDebugf("original has pixels before move: %s\n", original.getPixels() ? "true" : "false"); + SkBitmap copy = std::move(original); + // NOLINTNEXTLINE(bugprone-use-after-move) + SkDebugf("original has pixels after move: %s\n", original.getPixels() ? "true" : "false"); + SkDebugf("copy has pixels: %s\n", copy.getPixels() ? "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_006.cpp b/docs/examples/Bitmap_006.cpp new file mode 100644 index 0000000000..9de6348134 --- /dev/null +++ b/docs/examples/Bitmap_006.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=de9be45255e48fae445c916a41063abc +REG_FIDDLE(Bitmap_006, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkBitmap& b) -> void { + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkDebugf("%s width:%d height:%d colorType:k%s_SkColorType alphaType:k%s_SkAlphaType\n", + prefix, b.width(), b.height(), colors[b.colorType()], alphas[b.alphaType()]); + }; + SkBitmap one, two; + if (!one.tryAllocPixels( + SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType))) { + return; + } + if (!two.tryAllocPixels( + SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType))) { + return; + } + for (int index = 0; index < 2; ++index) { + debugster("one", one); + debugster("two", two); + one.swap(two); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_007.cpp b/docs/examples/Bitmap_007.cpp new file mode 100644 index 0000000000..8e55515759 --- /dev/null +++ b/docs/examples/Bitmap_007.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=7f972d742dd78d2500034d8867e9ef2f +REG_FIDDLE(Bitmap_007, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(10, 11)); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorWHITE); + SkPaint paint; + SkFont font; + font.setEdging(SkFont::Edging::kAlias); + offscreen.drawString("&", 0, 10, font, paint); + const SkPixmap& pixmap = bitmap.pixmap(); + if (pixmap.addr()) { + SkPMColor pmWhite = *pixmap.addr32(0, 0); + for (int y = 0; y < pixmap.height(); ++y) { + for (int x = 0; x < pixmap.width(); ++x) { + SkDebugf("%c", *pixmap.addr32(x, y) == pmWhite ? '-' : 'x'); + } + SkDebugf("\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_008.cpp b/docs/examples/Bitmap_008.cpp new file mode 100644 index 0000000000..8aae2e3d10 --- /dev/null +++ b/docs/examples/Bitmap_008.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=ec47c4dc23e2925ad565eaba55a91553 +REG_FIDDLE(Bitmap_008, 256, 256, true, 4) { +void draw(SkCanvas* canvas) { + // SkBitmap source; // pre-populated with soccer ball by fiddle.skia.org + const SkImageInfo& info = source.info(); + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(), + colors[info.colorType()], alphas[info.alphaType()]); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_009.cpp b/docs/examples/Bitmap_009.cpp new file mode 100644 index 0000000000..c85fc11746 --- /dev/null +++ b/docs/examples/Bitmap_009.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=d06880c42f8bb3b4c3b67bd988046049 +REG_FIDDLE(Bitmap_009, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeA8(16, 32); + SkBitmap bitmap; + bitmap.setInfo(info); + SkDebugf("bitmap width: %d info width: %d\n", bitmap.width(), info.width()); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_010.cpp b/docs/examples/Bitmap_010.cpp new file mode 100644 index 0000000000..7cc01bc325 --- /dev/null +++ b/docs/examples/Bitmap_010.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=c79a196278c58b34cd5f551b0124ecc9 +REG_FIDDLE(Bitmap_010, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeA8(16, 32); + SkBitmap bitmap; + bitmap.setInfo(info); + SkDebugf("bitmap height: %d info height: %d\n", bitmap.height(), info.height()); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_011.cpp b/docs/examples/Bitmap_011.cpp new file mode 100644 index 0000000000..2d905c89d4 --- /dev/null +++ b/docs/examples/Bitmap_011.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=ceb77fab7326b57822a147b04aa0960e +REG_FIDDLE(Bitmap_011, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeA8(16, 32)); + SkDebugf("color type: k" "%s" "_SkColorType\n", colors[bitmap.colorType()]); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_012.cpp b/docs/examples/Bitmap_012.cpp new file mode 100644 index 0000000000..d45b507591 --- /dev/null +++ b/docs/examples/Bitmap_012.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=070b1a60232be499eb10c6ea62371804 +REG_FIDDLE(Bitmap_012, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); + SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_013.cpp b/docs/examples/Bitmap_013.cpp new file mode 100644 index 0000000000..5b2c4d513f --- /dev/null +++ b/docs/examples/Bitmap_013.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=817f95879fadba44baf87ea60e9b595a +REG_FIDDLE(Bitmap_013, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, + SkColorSpace::MakeSRGBLinear())); + SkColorSpace* colorSpace = bitmap.colorSpace(); + SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", + colorSpace->gammaCloseToSRGB() ? "true" : "false", + colorSpace->gammaIsLinear() ? "true" : "false", + colorSpace->isSRGB() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_014.cpp b/docs/examples/Bitmap_014.cpp new file mode 100644 index 0000000000..4d90ea55a3 --- /dev/null +++ b/docs/examples/Bitmap_014.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=cb028b7931da85b949ad0953b9711f9f +REG_FIDDLE(Bitmap_014, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap1, bitmap2; + bitmap1.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, + SkColorSpace::MakeSRGBLinear())); + bitmap2.setInfo(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, + bitmap1.refColorSpace())); + SkColorSpace* colorSpace = bitmap2.colorSpace(); + SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", + colorSpace->gammaCloseToSRGB() ? "true" : "false", + colorSpace->gammaIsLinear() ? "true" : "false", + colorSpace->isSRGB() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_015.cpp b/docs/examples/Bitmap_015.cpp new file mode 100644 index 0000000000..0127aa640e --- /dev/null +++ b/docs/examples/Bitmap_015.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=2a688e6f0a516c0d44a826381e9d637f +REG_FIDDLE(Bitmap_015, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkImageInfo info = SkImageInfo::MakeA8(1, 1); + SkBitmap bitmap; + for (SkColorType colorType : { + kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, + kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, + kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType + } ) { + bitmap.setInfo(info.makeColorType(colorType)); + SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n", + colors[colorType], 13 - strlen(colors[colorType]), " ", + bitmap.bytesPerPixel()); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_016.cpp b/docs/examples/Bitmap_016.cpp new file mode 100644 index 0000000000..4efe92700b --- /dev/null +++ b/docs/examples/Bitmap_016.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=03a9e08082a23a98de17c3e24871d61a +REG_FIDDLE(Bitmap_016, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + for (int rowBytes : { 4, 5, 6, 7, 8} ) { + bitmap.setInfo(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), rowBytes); + SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, bitmap.rowBytesAsPixels()); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_017.cpp b/docs/examples/Bitmap_017.cpp new file mode 100644 index 0000000000..bc2d2e0aa8 --- /dev/null +++ b/docs/examples/Bitmap_017.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=56ede4b7d45c15d5936f81ac3d74f070 +REG_FIDDLE(Bitmap_017, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkImageInfo info = SkImageInfo::MakeA8(1, 1); + SkBitmap bitmap; + for (SkColorType colorType : { + kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, + kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, + kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType + } ) { + bitmap.setInfo(info.makeColorType(colorType)); + SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n", + colors[colorType], 14 - strlen(colors[colorType]), " ", + bitmap.shiftPerPixel()); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_018.cpp b/docs/examples/Bitmap_018.cpp new file mode 100644 index 0000000000..9233ae2f33 --- /dev/null +++ b/docs/examples/Bitmap_018.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=a3762c2722b56ba55e42689c527f146c +REG_FIDDLE(Bitmap_018, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + for (int width : { 0, 2 } ) { + for (int height : { 0, 2 } ) { + bitmap.setInfo(SkImageInfo::MakeA8(width, height)); + SkDebugf("width: %d height: %d empty: %s\n", width, height, + bitmap.empty() ? "true" : "false"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_019.cpp b/docs/examples/Bitmap_019.cpp new file mode 100644 index 0000000000..01ca9158d2 --- /dev/null +++ b/docs/examples/Bitmap_019.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=211ec89418011aa6e54aa2cc9567e003 +REG_FIDDLE(Bitmap_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + SkDebugf("empty bitmap does %shave pixels\n", bitmap.isNull() ? "not " : ""); + bitmap.setInfo(SkImageInfo::MakeA8(8, 8)); + SkDebugf("bitmap with dimensions does %shave pixels\n", bitmap.isNull() ? "not " : ""); + bitmap.allocPixels(); + SkDebugf("allocated bitmap does %shave pixels\n", bitmap.isNull() ? "not " : ""); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_020.cpp b/docs/examples/Bitmap_020.cpp new file mode 100644 index 0000000000..ce68d3f826 --- /dev/null +++ b/docs/examples/Bitmap_020.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=daacf43394ce4045a362a48b5774deed +REG_FIDDLE(Bitmap_020, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + for (int w : { 0, 8 } ) { + for (bool allocate : { false, true} ) { + bitmap.setInfo(SkImageInfo::MakeA8(w, 8)); + allocate ? bitmap.allocPixels() : (void) 0 ; + SkDebugf("empty:%s isNull:%s drawsNothing:%s\n", bitmap.empty() ? "true " : "false", + bitmap.isNull() ? "true " : "false", bitmap.drawsNothing() ? "true" : "false"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_021.cpp b/docs/examples/Bitmap_021.cpp new file mode 100644 index 0000000000..a006212037 --- /dev/null +++ b/docs/examples/Bitmap_021.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=a654fd0b73f424859ae6c95e03f55099 +REG_FIDDLE(Bitmap_021, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + for (int rowBytes : { 2, 8 } ) { + bool result = bitmap.setInfo(SkImageInfo::MakeA8(4, 4), rowBytes); + SkDebugf("setInfo returned:%s rowBytes:%d\n", result ? "true " : "false", bitmap.rowBytes()); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_022.cpp b/docs/examples/Bitmap_022.cpp new file mode 100644 index 0000000000..1c53d59a42 --- /dev/null +++ b/docs/examples/Bitmap_022.cpp @@ -0,0 +1,34 @@ +// 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 "fiddle/examples.h" +// HASH=af3adcbea7b58bf90298ca5e0ea93030 +REG_FIDDLE(Bitmap_022, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"}; + SkBitmap bitmap; + SkAlphaType alphaTypes[] = { kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, + kUnpremul_SkAlphaType + }; + SkDebugf("%18s%15s%17s%18s%19s\n", "Canonical", "Unknown", "Opaque", "Premul", "Unpremul"); + for (SkColorType colorType : { + kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, + kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, + kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType + } ) { + for (SkAlphaType canonicalAlphaType : alphaTypes) { + SkColorTypeValidateAlphaType(colorType, kUnknown_SkAlphaType, &canonicalAlphaType ); + SkDebugf("%12s %9s ", colors[(int) colorType], alphas[(int) canonicalAlphaType ]); + for (SkAlphaType alphaType : alphaTypes) { + bitmap.setInfo(SkImageInfo::Make(4, 4, colorType, canonicalAlphaType)); + bool result = bitmap.setAlphaType(alphaType); + SkDebugf("%s %s ", result ? "true " : "false", alphas[(int) bitmap.alphaType()]); + } + SkDebugf("\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_023.cpp b/docs/examples/Bitmap_023.cpp new file mode 100644 index 0000000000..1c00991e26 --- /dev/null +++ b/docs/examples/Bitmap_023.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=e006bb05cf74ec8d2b3d6adeb5dba11b +REG_FIDDLE(Bitmap_023, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType)); + bitmap.allocPixels(); + bitmap.eraseColor(0x00000000); + void* baseAddr = bitmap.getPixels(); + *(SkPMColor*)baseAddr = 0xFFFFFFFF; + SkDebugf("bitmap.getColor(0, 1) %c= 0x00000000\n", + bitmap.getColor(0, 1) == 0x00000000 ? '=' : '!'); + SkDebugf("bitmap.getColor(0, 0) %c= 0xFFFFFFFF\n", + bitmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_024.cpp b/docs/examples/Bitmap_024.cpp new file mode 100644 index 0000000000..ffa91bbffb --- /dev/null +++ b/docs/examples/Bitmap_024.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=165c8f208829fc0908e8a50da60c0076 +REG_FIDDLE(Bitmap_024, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + for (int width : { 1, 1000, 1000000 } ) { + for (int height: { 1, 1000, 1000000 } ) { + SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType); + bitmap.setInfo(imageInfo, width * 5); + SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height, + bitmap.computeByteSize()); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_025.cpp b/docs/examples/Bitmap_025.cpp new file mode 100644 index 0000000000..75b0c8abe0 --- /dev/null +++ b/docs/examples/Bitmap_025.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=db61fdcd382342ee88ea1b4f27c27b95 +REG_FIDDLE(Bitmap_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap original; + SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); + if (original.tryAllocPixels(info)) { + original.setImmutable(); + SkBitmap copy; + original.extractSubset(©, {5, 10, 15, 20}); + SkDebugf("original is " "%s" "immutable\n", original.isImmutable() ? "" : "not "); + SkDebugf("copy is " "%s" "immutable\n", copy.isImmutable() ? "" : "not "); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_026.cpp b/docs/examples/Bitmap_026.cpp new file mode 100644 index 0000000000..6da97c1d75 --- /dev/null +++ b/docs/examples/Bitmap_026.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=9210060d1f4ca46e1375496237902ef3 +REG_FIDDLE(Bitmap_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeN32(4, 4, kPremul_SkAlphaType)); + bitmap.allocPixels(); + SkCanvas offscreen(bitmap); + SkDebugf("draw white\n"); + offscreen.clear(SK_ColorWHITE); + bitmap.setImmutable(); + SkDebugf("draw black\n"); + // Triggers assert if SK_DEBUG is true, runs fine otherwise. + // offscreen.clear(SK_ColorBLACK); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_027.cpp b/docs/examples/Bitmap_027.cpp new file mode 100644 index 0000000000..8908dafed6 --- /dev/null +++ b/docs/examples/Bitmap_027.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=5e76b68bb46d54315eb0c12d83bd6949 +REG_FIDDLE(Bitmap_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int height = 2; + const int width = 2; + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType)); + for (int index = 0; index < 2; ++index) { + bitmap.allocPixels(); + bitmap.eraseColor(0x00000000); + SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false"); + bitmap.eraseColor(0xFFFFFFFF); + SkDebugf("isOpaque: %s\n", bitmap.isOpaque() ? "true" : "false"); + bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType)); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_028.cpp b/docs/examples/Bitmap_028.cpp new file mode 100644 index 0000000000..517cfc53c1 --- /dev/null +++ b/docs/examples/Bitmap_028.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=23c4543ac6cdd0e8fe762816a0dc2e03 +REG_FIDDLE(Bitmap_028, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap original; + SkImageInfo info = SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType); + if (original.tryAllocPixels(info)) { + original.setIsVolatile(true); + SkBitmap copy; + original.extractSubset(©, {5, 10, 15, 20}); + SkDebugf("original is " "%s" "volatile\n", original.isVolatile() ? "" : "not "); + SkDebugf("copy is " "%s" "volatile\n", copy.isImmutable() ? "" : "not "); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_029.cpp b/docs/examples/Bitmap_029.cpp new file mode 100644 index 0000000000..91494cf9c6 --- /dev/null +++ b/docs/examples/Bitmap_029.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=e8627a4df659b896402f89a91326618f +REG_FIDDLE(Bitmap_029, 256, 20, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); + bitmap.allocPixels(); + bitmap.eraseColor(SK_ColorRED); + canvas->scale(16, 16); + canvas->drawBitmap(bitmap, 0, 0); + *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE); + canvas->drawBitmap(bitmap, 2, 0); + bitmap.setIsVolatile(true); + *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 4, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_030.cpp b/docs/examples/Bitmap_030.cpp new file mode 100644 index 0000000000..a33341220e --- /dev/null +++ b/docs/examples/Bitmap_030.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=52ccaeda67924373c5b55a2b89fe314d +REG_FIDDLE(Bitmap_030, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); + bitmap.allocPixels(); + SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(), + bitmap.isNull() ? "true" : "false"); + bitmap.reset(); + SkDebugf("width:%d height:%d isNull:%s\n", bitmap.width(), bitmap.height(), + bitmap.isNull() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_031.cpp b/docs/examples/Bitmap_031.cpp new file mode 100644 index 0000000000..98cb453d92 --- /dev/null +++ b/docs/examples/Bitmap_031.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=9df1baa17658fbd0c419780f26fd854f +REG_FIDDLE(Bitmap_031, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::Make(2, 2, kN32_SkColorType, kPremul_SkAlphaType)); + for (int index = 0; index < 2; ++index) { + bitmap.allocPixels(); + bitmap.eraseColor(0x00000000); + SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false"); + bitmap.eraseColor(0xFFFFFFFF); + SkDebugf("computeIsOpaque: %s\n", SkBitmap::ComputeIsOpaque(bitmap) ? "true" : "false"); + bitmap.setInfo(bitmap.info().makeAlphaType(kOpaque_SkAlphaType)); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_032.cpp b/docs/examples/Bitmap_032.cpp new file mode 100644 index 0000000000..2d423e4375 --- /dev/null +++ b/docs/examples/Bitmap_032.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=2431ebc7e7d1e91e6d9daafd0f7a478f +REG_FIDDLE(Bitmap_032, 256, 160, false, 3) { +void draw(SkCanvas* canvas) { + SkRect bounds; + source.getBounds(&bounds); + bounds.offset(100, 100); + SkPaint paint; + paint.setColor(SK_ColorGRAY); + canvas->scale(.25f, .25f); + canvas->drawRect(bounds, paint); + canvas->drawBitmap(source, 40, 40); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_033.cpp b/docs/examples/Bitmap_033.cpp new file mode 100644 index 0000000000..c402714a89 --- /dev/null +++ b/docs/examples/Bitmap_033.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=0c45da35172bc0a529b2faecddae62a2 +REG_FIDDLE(Bitmap_033, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkIRect bounds; + source.getBounds(&bounds); + bounds.inset(100, 100); + SkBitmap bitmap; + source.extractSubset(&bitmap, bounds); + canvas->scale(.5f, .5f); + canvas->drawBitmap(bitmap, 10, 10); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_034.cpp b/docs/examples/Bitmap_034.cpp new file mode 100644 index 0000000000..ea7b03052c --- /dev/null +++ b/docs/examples/Bitmap_034.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=3e9126152ff1cc592aef6facbcb5fc96 +REG_FIDDLE(Bitmap_034, 256, 64, false, 4) { +void draw(SkCanvas* canvas) { + canvas->scale(.5f, .5f); + SkIRect bounds = source.bounds(); + for (int x : { 0, bounds.width() } ) { + for (int y : { 0, bounds.height() } ) { + canvas->drawBitmap(source, x, y); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_035.cpp b/docs/examples/Bitmap_035.cpp new file mode 100644 index 0000000000..421dcf464e --- /dev/null +++ b/docs/examples/Bitmap_035.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=647056bcc12c27fb4413f212f33a2898 +REG_FIDDLE(Bitmap_035, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeN32(33, 55, kOpaque_SkAlphaType)); + SkISize dimensions = bitmap.dimensions(); + SkRect bounds; + bitmap.getBounds(&bounds); + SkRect dimensionsAsBounds = SkRect::Make(dimensions); + SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_036.cpp b/docs/examples/Bitmap_036.cpp new file mode 100644 index 0000000000..f2c8cfdb71 --- /dev/null +++ b/docs/examples/Bitmap_036.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=d6dd0b425aa550f21b938a18c2e1a981 +REG_FIDDLE(Bitmap_036, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + SkIRect bounds; + source.getBounds(&bounds); + bounds.inset(100, 100); + SkBitmap subset; + source.extractSubset(&subset, bounds); + SkIRect r = source.getSubset(); + SkDebugf("source: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom); + r = subset.getSubset(); + SkDebugf("subset: %d, %d, %d, %d\n", r.fLeft, r.fTop, r.fRight, r.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_037.cpp b/docs/examples/Bitmap_037.cpp new file mode 100644 index 0000000000..2c600d38b4 --- /dev/null +++ b/docs/examples/Bitmap_037.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=599ab64d0aea005498176249bbfb64eb +REG_FIDDLE(Bitmap_037, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeN32(44, 16, kOpaque_SkAlphaType)); + bitmap.allocPixels(); + bitmap.eraseColor(SK_ColorGREEN); + SkCanvas offscreen(bitmap); + SkPaint paint; + SkFont font; + offscreen.drawString("!@#$%", 0, 12, font, paint); + canvas->scale(6, 6); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_038.cpp b/docs/examples/Bitmap_038.cpp new file mode 100644 index 0000000000..5c4990c496 --- /dev/null +++ b/docs/examples/Bitmap_038.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=f1d1880d38e0aea4cefd3e11745e8a09 +REG_FIDDLE(Bitmap_038, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + if (!bitmap.tryAllocPixelsFlags(SkImageInfo::MakeN32(10000, 10000, kOpaque_SkAlphaType), + SkBitmap::kZeroPixels_AllocFlag)) { + SkDebugf("bitmap allocation failed!\n"); + } else { + SkDebugf("bitmap allocation succeeded!\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_039.cpp b/docs/examples/Bitmap_039.cpp new file mode 100644 index 0000000000..b9d6c1588e --- /dev/null +++ b/docs/examples/Bitmap_039.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=737e721c7d9e0f367d25521a1b823b9d +REG_FIDDLE(Bitmap_039, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixelsFlags(SkImageInfo::MakeN32(44, 16, kPremul_SkAlphaType), + SkBitmap::kZeroPixels_AllocFlag); + SkCanvas offscreen(bitmap); + SkPaint paint; + SkFont font; + offscreen.drawString("!@#$%", 0, 12, font, paint); + canvas->scale(6, 6); + canvas->drawBitmap(bitmap, 0, 0); + canvas->drawBitmap(bitmap, 8, 8); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_040.cpp b/docs/examples/Bitmap_040.cpp new file mode 100644 index 0000000000..56f58ce737 --- /dev/null +++ b/docs/examples/Bitmap_040.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=34479d5aa23ce9f5e334b0786c9edb22 +REG_FIDDLE(Bitmap_040, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + SkImageInfo info = SkImageInfo::Make(64, 256, kGray_8_SkColorType, kOpaque_SkAlphaType); + if (bitmap.tryAllocPixels(info, 0)) { + SkCanvas offscreen(bitmap); + offscreen.scale(.5f, .5f); + for (int x : { 0, 64, 128, 192 } ) { + offscreen.drawBitmap(source, -x, 0); + canvas->drawBitmap(bitmap, x, 0); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_041.cpp b/docs/examples/Bitmap_041.cpp new file mode 100644 index 0000000000..336646b1ca --- /dev/null +++ b/docs/examples/Bitmap_041.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=555c0f62f96602a9dcd459badcd005e0 +REG_FIDDLE(Bitmap_041, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + SkImageInfo info = SkImageInfo::Make(256, 64, kGray_8_SkColorType, kOpaque_SkAlphaType); + bitmap.allocPixels(info, info.width() * info.bytesPerPixel() + 64); + SkCanvas offscreen(bitmap); + offscreen.scale(.5f, .5f); + for (int y : { 0, 64, 128, 192 } ) { + offscreen.drawBitmap(source, 0, -y); + canvas->drawBitmap(bitmap, 0, y); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_042.cpp b/docs/examples/Bitmap_042.cpp new file mode 100644 index 0000000000..342e0739fa --- /dev/null +++ b/docs/examples/Bitmap_042.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=7ef3d043c4c5885649e591dd7dca92ff +REG_FIDDLE(Bitmap_042, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + if (bitmap.tryAllocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType))) { + SkCanvas offscreen(bitmap); + offscreen.scale(.25f, .5f); + for (int y : { 0, 64, 128, 192 } ) { + offscreen.drawBitmap(source, -y, -y); + canvas->drawBitmap(bitmap, y, y); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_043.cpp b/docs/examples/Bitmap_043.cpp new file mode 100644 index 0000000000..32c8035fd2 --- /dev/null +++ b/docs/examples/Bitmap_043.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=91f474a11a2112cd5c88c40a9015048d +REG_FIDDLE(Bitmap_043, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::Make(64, 64, kGray_8_SkColorType, kOpaque_SkAlphaType)); + SkCanvas offscreen(bitmap); + offscreen.scale(.5f, .5f); + for (int y : { 0, 64, 128, 192 } ) { + offscreen.drawBitmap(source, -y, -y); + canvas->drawBitmap(bitmap, y, y); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_044.cpp b/docs/examples/Bitmap_044.cpp new file mode 100644 index 0000000000..dca595d008 --- /dev/null +++ b/docs/examples/Bitmap_044.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=a2b1e0910f37066f15ae56368775a6d8 +REG_FIDDLE(Bitmap_044, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + if (bitmap.tryAllocN32Pixels(80, 80)) { + bitmap.eraseColor(SK_ColorTRANSPARENT); + bitmap.erase(0x7f3f7fff, SkIRect::MakeWH(50, 30)); + bitmap.erase(0x3f7fff3f, SkIRect::MakeXYWH(20, 10, 50, 30)); + bitmap.erase(0x5fff3f7f, SkIRect::MakeXYWH(40, 20, 50, 30)); + canvas->drawBitmap(bitmap, 0, 0); + for (int x : { 0, 30, 60, 90 } ) { + canvas->drawBitmap(bitmap, x, 70); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_045.cpp b/docs/examples/Bitmap_045.cpp new file mode 100644 index 0000000000..f61a667df3 --- /dev/null +++ b/docs/examples/Bitmap_045.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=c717491f9251604724c9cbde7088ec20 +REG_FIDDLE(Bitmap_045, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRandom random; + SkBitmap bitmap; + bitmap.allocN32Pixels(64, 64); + bitmap.eraseColor(SK_ColorTRANSPARENT); + for (int y = 0; y < 256; y += 64) { + for (int x = 0; x < 256; x += 64) { + SkColor color = random.nextU(); + uint32_t w = random.nextRangeU(4, 32); + uint32_t cx = random.nextRangeU(0, 64 - w); + uint32_t h = random.nextRangeU(4, 32); + uint32_t cy = random.nextRangeU(0, 64 - h); + bitmap.erase(color, SkIRect::MakeXYWH(cx, cy, w, h)); + canvas->drawBitmap(bitmap, x, y); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_046.cpp b/docs/examples/Bitmap_046.cpp new file mode 100644 index 0000000000..792cdb127f --- /dev/null +++ b/docs/examples/Bitmap_046.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=8c4f7bf73fffa1a812ee8e88e44e639c +REG_FIDDLE(Bitmap_046, 256, 256, true, 0) { +static void releaseProc(void* addr, void* ) { + SkDebugf("releaseProc called\n"); + delete[] (uint32_t*) addr; +} + +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + void* pixels = new uint32_t[8 * 8]; + SkImageInfo info = SkImageInfo::MakeN32(8, 8, kOpaque_SkAlphaType); + SkDebugf("before installPixels\n"); + bool installed = bitmap.installPixels(info, pixels, 16, releaseProc, nullptr); + SkDebugf("install " "%s" "successful\n", installed ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_047.cpp b/docs/examples/Bitmap_047.cpp new file mode 100644 index 0000000000..f58d1fb155 --- /dev/null +++ b/docs/examples/Bitmap_047.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=a7e04447b2081010c50d7920e80a6bb2 +REG_FIDDLE(Bitmap_047, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRandom random; + SkBitmap bitmap; + const int width = 8; + const int height = 8; + uint32_t pixels[width * height]; + for (unsigned x = 0; x < width * height; ++x) { + pixels[x] = random.nextU(); + } + SkImageInfo info = SkImageInfo::MakeN32(width, height, kUnpremul_SkAlphaType); + if (bitmap.installPixels(info, pixels, info.minRowBytes())) { + canvas->scale(32, 32); + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_048.cpp b/docs/examples/Bitmap_048.cpp new file mode 100644 index 0000000000..928e0bfa62 --- /dev/null +++ b/docs/examples/Bitmap_048.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=6e2a8c9358b34aebd2ec586815fe9d3a +REG_FIDDLE(Bitmap_048, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, + { 0xAC, 0xA8, 0x89, 0x47, 0x87 }, + { 0x4B, 0x25, 0x25, 0x25, 0x46 }, + { 0x90, 0x81, 0x25, 0x41, 0x33 }, + { 0x75, 0x55, 0x44, 0x20, 0x00 }}; + SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); + SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->scale(10, 10); + canvas->drawBitmap(bitmap, 0, 0); + *pixmap.writable_addr8(2, 2) = 0xFF; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 10, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_049.cpp b/docs/examples/Bitmap_049.cpp new file mode 100644 index 0000000000..5ed9d2c69a --- /dev/null +++ b/docs/examples/Bitmap_049.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=f0db16e06c9a1436917c8179f8c1718f +REG_FIDDLE(Bitmap_049, 256, 50, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }; + uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5); + canvas->scale(10, 50); + canvas->drawBitmap(bitmap, 0, 0); + bitmap.setPixels(set2); + canvas->drawBitmap(bitmap, 10, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_050.cpp b/docs/examples/Bitmap_050.cpp new file mode 100644 index 0000000000..e03dfa08a8 --- /dev/null +++ b/docs/examples/Bitmap_050.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=720e4c053fae9e929ab6518b47e49370 +REG_FIDDLE(Bitmap_050, 256, 50, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5); + canvas->scale(10, 50); + canvas->drawBitmap(bitmap, 0, 0); + if (bitmap.tryAllocPixels()) { + bitmap.eraseColor(SK_ColorBLACK); + canvas->drawBitmap(bitmap, 8, 0); + bitmap.setPixels(set1); + canvas->drawBitmap(bitmap, 16, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_051.cpp b/docs/examples/Bitmap_051.cpp new file mode 100644 index 0000000000..1a859cbb69 --- /dev/null +++ b/docs/examples/Bitmap_051.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=1219b38c788bf270fb20f8cd2d78cff8 +REG_FIDDLE(Bitmap_051, 256, 50, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t set1[5] = { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }; + uint8_t set2[5] = { 0xAC, 0xA8, 0x89, 0x47, 0x87 }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::Make(5, 1, kGray_8_SkColorType, kOpaque_SkAlphaType), set1, 5); + canvas->scale(10, 50); + canvas->drawBitmap(bitmap, 0, 0); + bitmap.allocPixels(); + bitmap.eraseColor(SK_ColorBLACK); + canvas->drawBitmap(bitmap, 8, 0); + bitmap.setPixels(set2); + canvas->drawBitmap(bitmap, 16, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_052.cpp b/docs/examples/Bitmap_052.cpp new file mode 100644 index 0000000000..54e29cb39f --- /dev/null +++ b/docs/examples/Bitmap_052.cpp @@ -0,0 +1,45 @@ +// 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 "fiddle/examples.h" +// HASH=eb6f861ca1839146d26e40d56c2a001c +REG_FIDDLE(Bitmap_052, 256, 100, false, 0) { +class LargePixelRef : public SkPixelRef { +public: + LargePixelRef(const SkImageInfo& info, char* storage, size_t rowBytes) + : SkPixelRef(info.width(), info.height(), storage, rowBytes) { + } + ~LargePixelRef() override { + delete[] (char* ) this->pixels(); + } +}; +class LargeAllocator : public SkBitmap::Allocator { +public: + bool allocPixelRef(SkBitmap* bitmap) override { + const SkImageInfo& info = bitmap->info(); + uint64_t rowBytes = info.minRowBytes64(); + uint64_t size = info.height() * rowBytes; + char* addr = new char[size]; + if (nullptr == addr) { + return false; + } + sk_sp pr = sk_sp(new LargePixelRef(info, addr, rowBytes)); + if (!pr) { + return false; + } + bitmap->setPixelRef(std::move(pr), 0, 0); + return true; + } +}; + +void draw(SkCanvas* canvas) { + LargeAllocator largeAllocator; + SkBitmap bitmap; + int width = 100; // make this 20000 + int height = 100; // and this 100000 to allocate 8 gigs on a 64-bit platform + bitmap.setInfo(SkImageInfo::MakeN32(width, height, kOpaque_SkAlphaType)); + if (bitmap.tryAllocPixels(&largeAllocator)) { + bitmap.eraseColor(0xff55aa33); + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_053.cpp b/docs/examples/Bitmap_053.cpp new file mode 100644 index 0000000000..b622ecf035 --- /dev/null +++ b/docs/examples/Bitmap_053.cpp @@ -0,0 +1,32 @@ +// 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 "fiddle/examples.h" +// HASH=1b2800d23c9ea249b45c2c21a34b6d14 +REG_FIDDLE(Bitmap_053, 256, 32, false, 0) { +class TinyAllocator : public SkBitmap::Allocator { +public: + bool allocPixelRef(SkBitmap* bitmap) override { + const SkImageInfo& info = bitmap->info(); + if (info.height() * info.minRowBytes() > sizeof(storage)) { + return false; + } + sk_sp pr = sk_sp( + new SkPixelRef(info.width(), info.height(), storage, info.minRowBytes())); + bitmap->setPixelRef(std::move(pr), 0, 0); + return true; + } + char storage[16]; +}; + +void draw(SkCanvas* canvas) { + TinyAllocator tinyAllocator; + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeN32(2, 2, kOpaque_SkAlphaType)); + if (bitmap.tryAllocPixels(&tinyAllocator)) { + bitmap.eraseColor(0xff55aa33); + bitmap.erase(0xffaa3355, SkIRect::MakeXYWH(1, 1, 1, 1)); + canvas->scale(16, 16); + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_054.cpp b/docs/examples/Bitmap_054.cpp new file mode 100644 index 0000000000..d47ed992f7 --- /dev/null +++ b/docs/examples/Bitmap_054.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=5db2d30870a7cc45f28e22578d1880c3 +REG_FIDDLE(Bitmap_054, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + SkBitmap subset; + source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256)); + SkDebugf("src ref %c= sub ref\n", source.pixelRef() == subset.pixelRef() ? '=' : '!'); + SkDebugf("src pixels %c= sub pixels\n", source.getPixels() == subset.getPixels() ? '=' : '!'); + SkDebugf("src addr %c= sub addr\n", source.getAddr(32, 64) == subset.getAddr(0, 0) ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_055.cpp b/docs/examples/Bitmap_055.cpp new file mode 100644 index 0000000000..0e97e3d4d8 --- /dev/null +++ b/docs/examples/Bitmap_055.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=6d31686c6c0829c70f284ae716526d6a +REG_FIDDLE(Bitmap_055, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + SkBitmap subset; + source.extractSubset(&subset, SkIRect::MakeXYWH(32, 64, 128, 256)); + SkIPoint sourceOrigin = source.pixelRefOrigin(); + SkIPoint subsetOrigin = subset.pixelRefOrigin(); + SkDebugf("source origin: %d, %d\n", sourceOrigin.fX, sourceOrigin.fY); + SkDebugf("subset origin: %d, %d\n", subsetOrigin.fX, subsetOrigin.fY); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_056.cpp b/docs/examples/Bitmap_056.cpp new file mode 100644 index 0000000000..07a8838657 --- /dev/null +++ b/docs/examples/Bitmap_056.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=f98cc0451c6e77a8833d261c9a484c5f +REG_FIDDLE(Bitmap_056, 256, 140, false, 5) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::Make(source.width() - 5, source.height() - 5, + kGray_8_SkColorType, kOpaque_SkAlphaType), source.rowBytes()); + bitmap.setPixelRef(sk_ref_sp(source.pixelRef()), 5, 5); + canvas->drawBitmap(bitmap, 10, 10); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_057.cpp b/docs/examples/Bitmap_057.cpp new file mode 100644 index 0000000000..9296ede423 --- /dev/null +++ b/docs/examples/Bitmap_057.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=e89c78ca992e2e789ed50944fe68f920 +REG_FIDDLE(Bitmap_057, 256, 160, false, 5) { +void draw(SkCanvas* canvas) { + if (source.readyToDraw()) { + canvas->drawBitmap(source, 10, 10); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_058.cpp b/docs/examples/Bitmap_058.cpp new file mode 100644 index 0000000000..8822e2eb8b --- /dev/null +++ b/docs/examples/Bitmap_058.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=db9dd91e0207c3941c09538555817b4b +REG_FIDDLE(Bitmap_058, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + SkDebugf("empty id %u\n", bitmap.getGenerationID()); + bitmap.allocPixels(SkImageInfo::MakeN32(64, 64, kOpaque_SkAlphaType)); + SkDebugf("alloc id %u\n", bitmap.getGenerationID()); + bitmap.eraseColor(SK_ColorRED); + SkDebugf("erase id %u\n", bitmap.getGenerationID()); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_059.cpp b/docs/examples/Bitmap_059.cpp new file mode 100644 index 0000000000..88e81fde45 --- /dev/null +++ b/docs/examples/Bitmap_059.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=8f463ed17b0ed4fb9c503a0ec71706f9 +REG_FIDDLE(Bitmap_059, 256, 20, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kOpaque_SkAlphaType)); + bitmap.allocPixels(); + bitmap.eraseColor(SK_ColorRED); + canvas->scale(16, 16); + canvas->drawBitmap(bitmap, 0, 0); + *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorBLUE); + canvas->drawBitmap(bitmap, 2, 0); + bitmap.notifyPixelsChanged(); + *(SkPMColor*) bitmap.getPixels() = SkPreMultiplyColor(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 4, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_060.cpp b/docs/examples/Bitmap_060.cpp new file mode 100644 index 0000000000..9b1d363764 --- /dev/null +++ b/docs/examples/Bitmap_060.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=418928dbfffa9eb00c8225530f44baf5 +REG_FIDDLE(Bitmap_060, 256, 20, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kOpaque_SkAlphaType)); + bitmap.eraseColor(SK_ColorRED); + canvas->scale(16, 16); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_061.cpp b/docs/examples/Bitmap_061.cpp new file mode 100644 index 0000000000..61a1dcb8e7 --- /dev/null +++ b/docs/examples/Bitmap_061.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=67277b0a1003f340473a35982533561c +REG_FIDDLE(Bitmap_061, 256, 80, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType)); + bitmap.eraseARGB(0x7f, 0xff, 0x7f, 0x3f); + canvas->scale(50, 50); + canvas->drawBitmap(bitmap, 0, 0); + canvas->drawBitmap(bitmap, .5f, .5f); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_062.cpp b/docs/examples/Bitmap_062.cpp new file mode 100644 index 0000000000..2aa7c2bee8 --- /dev/null +++ b/docs/examples/Bitmap_062.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=2c5c4230ccd2861a5d15b7cd2764ab6e +REG_FIDDLE(Bitmap_062, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32(2, 2, kPremul_SkAlphaType)); + bitmap.erase(0x7fff7f3f, SkIRect::MakeWH(1, 1)); + bitmap.erase(0x7f7f3fff, SkIRect::MakeXYWH(0, 1, 1, 1)); + bitmap.erase(0x7f3fff7f, SkIRect::MakeXYWH(1, 0, 1, 1)); + bitmap.erase(0x7f1fbf5f, SkIRect::MakeXYWH(1, 1, 1, 1)); + canvas->scale(25, 25); + canvas->drawBitmap(bitmap, 0, 0); + canvas->drawBitmap(bitmap, .5f, .5f); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_063.cpp b/docs/examples/Bitmap_063.cpp new file mode 100644 index 0000000000..772672956a --- /dev/null +++ b/docs/examples/Bitmap_063.cpp @@ -0,0 +1,33 @@ +// 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 "fiddle/examples.h" +// HASH=193d1f6d8a43b7a8e9f27ba21de38617 +REG_FIDDLE(Bitmap_063, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + SkColor colors[][w] = { + { 0x00000000, 0x2a0e002a, 0x55380055, 0x7f7f007f }, + { 0x2a000e2a, 0x551c1c55, 0x7f542a7f, 0xaaaa38aa }, + { 0x55003855, 0x7f2a547f, 0xaa7171aa, 0xd4d48dd4 }, + { 0x7f007f7f, 0xaa38aaaa, 0xd48dd4d4, 0xffffffff } + }; + SkDebugf("Premultiplied:\n"); + for (int y = 0; y < h; ++y) { + SkDebugf("(0, %d) ", y); + for (int x = 0; x < w; ++x) { + SkDebugf("0x%08x%c", colors[y][x], x == w - 1 ? '\n' : ' '); + } + } + SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), colors, w * 4); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + SkDebugf("Unpremultiplied:\n"); + for (int y = 0; y < h; ++y) { + SkDebugf("(0, %d) ", y); + for (int x = 0; x < w; ++x) { + SkDebugf("0x%08x%c", bitmap.getColor(x, y), x == w - 1 ? '\n' : ' '); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_064.cpp b/docs/examples/Bitmap_064.cpp new file mode 100644 index 0000000000..204c83f56d --- /dev/null +++ b/docs/examples/Bitmap_064.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=ffcefb2344cd38c3b99f69cfe6d64a17 +REG_FIDDLE(Bitmap_064, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + char* row0 = (char* ) source.getAddr(0, 0); + char* row1 = (char* ) source.getAddr(0, 1); + SkDebugf("addr interval %c= rowBytes\n", + (size_t) (row1 - row0) == source.rowBytes() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_065.cpp b/docs/examples/Bitmap_065.cpp new file mode 100644 index 0000000000..84f23c7d55 --- /dev/null +++ b/docs/examples/Bitmap_065.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=837a2bcc9fb9ce617a3420956cefc64a +REG_FIDDLE(Bitmap_065, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + uint32_t* row0 = source.getAddr32(0, 0); + uint32_t* row1 = source.getAddr32(0, 1); + size_t interval = (row1 - row0) * source.bytesPerPixel(); + SkDebugf("addr interval %c= rowBytes\n", interval == source.rowBytes() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_066.cpp b/docs/examples/Bitmap_066.cpp new file mode 100644 index 0000000000..855639e904 --- /dev/null +++ b/docs/examples/Bitmap_066.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=53e00899ef2e00e2096daf7a07d9b059 +REG_FIDDLE(Bitmap_066, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap16; + SkImageInfo dstInfo = SkImageInfo::Make(source.width(), source.height(), kARGB_4444_SkColorType, + kPremul_SkAlphaType); + bitmap16.allocPixels(dstInfo); + if (source.readPixels(dstInfo, bitmap16.getPixels(), bitmap16.rowBytes(), 0, 0)) { + uint16_t* row0 = bitmap16.getAddr16(0, 0); + uint16_t* row1 = bitmap16.getAddr16(0, 1); + size_t interval = (row1 - row0) * bitmap16.bytesPerPixel(); + SkDebugf("addr interval %c= rowBytes\n", interval == bitmap16.rowBytes() ? '=' : '!'); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_067.cpp b/docs/examples/Bitmap_067.cpp new file mode 100644 index 0000000000..f01eb9a82f --- /dev/null +++ b/docs/examples/Bitmap_067.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=cb9a08e8ff779b6a1cf8bb54f3883aaf +REG_FIDDLE(Bitmap_067, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + const int width = 8; + const int height = 8; + uint8_t pixels[height][width]; + SkImageInfo info = SkImageInfo::Make(width, height, kGray_8_SkColorType, kOpaque_SkAlphaType); + if (bitmap.installPixels(info, pixels, info.minRowBytes())) { + SkDebugf("&pixels[4][2] %c= bitmap.getAddr8(2, 4)\n", + &pixels[4][2] == bitmap.getAddr8(2, 4) ? '=' : '!'); + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_068.cpp b/docs/examples/Bitmap_068.cpp new file mode 100644 index 0000000000..7510b85729 --- /dev/null +++ b/docs/examples/Bitmap_068.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=304148c50c91490bfd58e9222342419c +REG_FIDDLE(Bitmap_068, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + SkIRect bounds, s; + source.getBounds(&bounds); + SkDebugf("bounds: %d, %d, %d, %d\n", bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); + SkBitmap subset; + for (int left: { -100, 0, 100, 1000 } ) { + for (int right: { 0, 100, 1000 } ) { + SkIRect b = SkIRect::MakeLTRB(left, 100, right, 200); + bool success = source.extractSubset(&subset, b); + SkDebugf("subset: %4d, %4d, %4d, %4d ", b.fLeft, b.fTop, b.fRight, b.fBottom); + SkDebugf("success; %s", success ? "true" : "false"); + if (success) { + subset.getBounds(&s); + SkDebugf(" subset: %d, %d, %d, %d", s.fLeft, s.fTop, s.fRight, s.fBottom); + } + SkDebugf("\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_069.cpp b/docs/examples/Bitmap_069.cpp new file mode 100644 index 0000000000..7da8c49244 --- /dev/null +++ b/docs/examples/Bitmap_069.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=b2cbbbbcffb618865d8aae3bc04b2a62 +REG_FIDDLE(Bitmap_069, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + const int width = 256; + const int height = 64; + SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height); + SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; + SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, + SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); + SkBitmap bitmap; + bitmap.allocPixels(srcInfo); + SkCanvas srcCanvas(bitmap); + srcCanvas.drawRect(SkRect::MakeWH(width, height), paint); + canvas->drawBitmap(bitmap, 0, 0); + SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType); + std::vector dstPixels; + dstPixels.resize(height * width); + bitmap.readPixels(dstInfo, &dstPixels.front(), width * 2, 0, 0); + SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2); + bitmap.installPixels(dstPixmap); + canvas->drawBitmap(bitmap, 0, 64); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_070.cpp b/docs/examples/Bitmap_070.cpp new file mode 100644 index 0000000000..c912d11eee --- /dev/null +++ b/docs/examples/Bitmap_070.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=e9f70cbc9827097449a386ec7a8a8188 +REG_FIDDLE(Bitmap_070, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + srcPixels.resize(source.height() * source.rowBytes()); + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < 4; ++x) { + SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width() / 4, source.height() / 4), + &srcPixels.front() + x * source.height() * source.width() / 4 + + y * source.width() / 4, source.rowBytes()); + source.readPixels(pixmap, x * source.width() / 4, y * source.height() / 4); + } + } + canvas->scale(.5f, .5f); + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width(), source.height()), + &srcPixels.front(), source.rowBytes()); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_071.cpp b/docs/examples/Bitmap_071.cpp new file mode 100644 index 0000000000..db806fd33e --- /dev/null +++ b/docs/examples/Bitmap_071.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=4590fbf052659d6e629fbfd827081ae5 +REG_FIDDLE(Bitmap_071, 256, 128, false, 3) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + srcPixels.resize(source.height() * source.width() * 8); + for (int i = 0; i < 2; ++i) { + SkPixmap pixmap(SkImageInfo::Make(source.width() * 2, source.height(), + i ? kRGBA_8888_SkColorType : kBGRA_8888_SkColorType, kPremul_SkAlphaType), + &srcPixels.front() + i * source.width(), source.rowBytes() * 2); + source.readPixels(pixmap); + } + canvas->scale(.25f, .25f); + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeN32Premul(source.width() * 2, source.height()), + &srcPixels.front(), source.rowBytes() * 2); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_072.cpp b/docs/examples/Bitmap_072.cpp new file mode 100644 index 0000000000..371535b42c --- /dev/null +++ b/docs/examples/Bitmap_072.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=9b3133a6673d2514d166398adbe1f9f4 +REG_FIDDLE(Bitmap_072, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + int width = image->width(); + int height = image->height(); + srcPixels.resize(height * width * 4); + SkPixmap pixmap(SkImageInfo::MakeN32Premul(width, height), (const void*) &srcPixels.front(), + width * 4); + image->readPixels(pixmap, 0, 0); + canvas->scale(.5f, .5f); + width /= 4; + height /= 4; + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < 4; ++x) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(width, height)); + bitmap.writePixels(pixmap, -y * width, -x * height); + canvas->drawBitmap(bitmap, x * width, y * height); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_073.cpp b/docs/examples/Bitmap_073.cpp new file mode 100644 index 0000000000..1a0efce9e5 --- /dev/null +++ b/docs/examples/Bitmap_073.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=faa5dfa466f6e16c07c124d971f32679 +REG_FIDDLE(Bitmap_073, 256, 80, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(2, 2)); + bitmap.eraseColor(SK_ColorGREEN); + SkPMColor color = 0xFF5599BB; + SkPixmap src(SkImageInfo::MakeN32Premul(1, 1), &color, 4); + bitmap.writePixels(src); + canvas->scale(40, 40); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_074.cpp b/docs/examples/Bitmap_074.cpp new file mode 100644 index 0000000000..4e65ed823f --- /dev/null +++ b/docs/examples/Bitmap_074.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=ab6577df079e6c70511cf2bfc6447b44 +REG_FIDDLE(Bitmap_074, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap alpha, bitmap; + bitmap.allocN32Pixels(100, 100); + SkCanvas offscreen(bitmap); + offscreen.clear(0); + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(SK_ColorBLUE); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + offscreen.drawCircle(50, 50, 39, paint); + offscreen.flush(); + bitmap.extractAlpha(&alpha); + paint.setColor(SK_ColorRED); + canvas->drawBitmap(bitmap, 0, 0, &paint); + canvas->drawBitmap(alpha, 100, 0, &paint); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_075.cpp b/docs/examples/Bitmap_075.cpp new file mode 100644 index 0000000000..a57ffc0b5f --- /dev/null +++ b/docs/examples/Bitmap_075.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=092739b4cd5d732a27c07ced8ef45f01 +REG_FIDDLE(Bitmap_075, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + auto radiusToSigma = [](SkScalar radius) -> SkScalar { + static const SkScalar kBLUR_SIGMA_SCALE = 0.57735f; + return radius > 0 ? kBLUR_SIGMA_SCALE * radius + 0.5f : 0.0f; + }; + SkBitmap alpha, bitmap; + bitmap.allocN32Pixels(100, 100); + SkCanvas offscreen(bitmap); + offscreen.clear(0); + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(SK_ColorBLUE); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + offscreen.drawCircle(50, 50, 39, paint); + offscreen.flush(); + paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, radiusToSigma(25))); + SkIPoint offset; + bitmap.extractAlpha(&alpha, &paint, &offset); + paint.setColor(SK_ColorRED); + canvas->drawBitmap(bitmap, 0, -offset.fY, &paint); + canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_076.cpp b/docs/examples/Bitmap_076.cpp new file mode 100644 index 0000000000..5751fd2111 --- /dev/null +++ b/docs/examples/Bitmap_076.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=cd7543fa8c9f3cede46dc2d72eb8c4bd +REG_FIDDLE(Bitmap_076, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap alpha, bitmap; + bitmap.allocN32Pixels(100, 100); + SkCanvas offscreen(bitmap); + offscreen.clear(0); + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(SK_ColorBLUE); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + offscreen.drawCircle(50, 50, 39, paint); + offscreen.flush(); + paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, 3)); + SkIPoint offset; + bitmap.extractAlpha(&alpha, &paint, nullptr, &offset); + paint.setColor(SK_ColorRED); + canvas->drawBitmap(bitmap, 0, -offset.fY, &paint); + canvas->drawBitmap(alpha, 100 + offset.fX, 0, &paint); +} +} // END FIDDLE diff --git a/docs/examples/Bitmap_077.cpp b/docs/examples/Bitmap_077.cpp new file mode 100644 index 0000000000..53f8590f6d --- /dev/null +++ b/docs/examples/Bitmap_077.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=0cc2c6a0dffa61a88711534bd3d43b40 +REG_FIDDLE(Bitmap_077, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(6, 11)); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorWHITE); + SkPaint paint; + SkFont font; + offscreen.drawString("?", 0, 10, font, paint); + SkPixmap pixmap; + if (bitmap.peekPixels(&pixmap)) { + const SkPMColor* pixels = pixmap.addr32(); + SkPMColor pmWhite = pixels[0]; + for (int y = 0; y < bitmap.height(); ++y) { + for (int x = 0; x < bitmap.width(); ++x) { + SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); + } + SkDebugf("\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_000.cpp b/docs/examples/BlendMode_000.cpp new file mode 100644 index 0000000000..8dab5e90b4 --- /dev/null +++ b/docs/examples/BlendMode_000.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=a9b56a26ca469bab9ab10e16f62fb2e2 +REG_FIDDLE(BlendMode_000, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + canvas->saveLayer(nullptr, nullptr); + canvas->drawColor(SK_ColorYELLOW, SkBlendMode::kClear); + SkPaint paint; + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { + SkColor colors[] = { color, SkColorSetA(color, 0) }; + paint.setShader(SkGradientShader::MakeRadial({ 64, 64}, 100, + colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); + canvas->drawCircle(64, 64, 100, paint); + canvas->translate(64, 64); + } + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_001.cpp b/docs/examples/BlendMode_001.cpp new file mode 100644 index 0000000000..5bcf294bbd --- /dev/null +++ b/docs/examples/BlendMode_001.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=0fc85dd916cc1a5896d36c80b9847391 +REG_FIDDLE(BlendMode_001, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->clipRect({50, 50, 200, 200}); + SkPaint srcBlend; + srcBlend.setBlendMode(SkBlendMode::kSrc); + canvas->saveLayer(nullptr, &srcBlend); + canvas->drawColor(0); + SkPaint transRed; + transRed.setColor(SkColorSetA(SK_ColorRED, 127)); + canvas->drawCircle(125, 125, 75, transRed); + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_002.cpp b/docs/examples/BlendMode_002.cpp new file mode 100644 index 0000000000..726a38cfdd --- /dev/null +++ b/docs/examples/BlendMode_002.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=35915a2273be1076f00f2e47998ce808 +REG_FIDDLE(BlendMode_002, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 125, 128 } }; + SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; + SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; + canvas->drawAtlas(image.get(), xforms, tex, colors, 2, SkBlendMode::kSrc, nullptr, nullptr); + canvas->translate(128, 0); + canvas->drawAtlas(image.get(), xforms, tex, colors, 2, SkBlendMode::kDst, nullptr, nullptr); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_003.cpp b/docs/examples/BlendMode_003.cpp new file mode 100644 index 0000000000..b301f8df15 --- /dev/null +++ b/docs/examples/BlendMode_003.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=2ea9c149964a06cdb4929158cb4f15f8 +REG_FIDDLE(BlendMode_003, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstIn); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcOver); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_004.cpp b/docs/examples/BlendMode_004.cpp new file mode 100644 index 0000000000..09b7b8ed2b --- /dev/null +++ b/docs/examples/BlendMode_004.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=10dbb4d97902956ef5f5f8562f65119e +REG_FIDDLE(BlendMode_004, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstIn); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kDstOver); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_005.cpp b/docs/examples/BlendMode_005.cpp new file mode 100644 index 0000000000..bb3d86ab4f --- /dev/null +++ b/docs/examples/BlendMode_005.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=b0833c18fe8b0eeaab9bd6d2160d272f +REG_FIDDLE(BlendMode_005, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstIn); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcIn); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_006.cpp b/docs/examples/BlendMode_006.cpp new file mode 100644 index 0000000000..4021b1b99a --- /dev/null +++ b/docs/examples/BlendMode_006.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=a5eeba05ccf6097a5d110a9d64f97c25 +REG_FIDDLE(BlendMode_006, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstIn); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kDstIn); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_007.cpp b/docs/examples/BlendMode_007.cpp new file mode 100644 index 0000000000..750a12ea2d --- /dev/null +++ b/docs/examples/BlendMode_007.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=ccc1e74226e0c9eacbc21f1eed017b84 +REG_FIDDLE(BlendMode_007, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstIn); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcOut); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_008.cpp b/docs/examples/BlendMode_008.cpp new file mode 100644 index 0000000000..f894638f8c --- /dev/null +++ b/docs/examples/BlendMode_008.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=b9a894c9accfc5d94081bbd77d5d790a +REG_FIDDLE(BlendMode_008, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstIn); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kDstOut); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_009.cpp b/docs/examples/BlendMode_009.cpp new file mode 100644 index 0000000000..0a70ceaec8 --- /dev/null +++ b/docs/examples/BlendMode_009.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=a13148977bfc985934a92752c83a2041 +REG_FIDDLE(BlendMode_009, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstIn); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcATop); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_010.cpp b/docs/examples/BlendMode_010.cpp new file mode 100644 index 0000000000..16cc52b203 --- /dev/null +++ b/docs/examples/BlendMode_010.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=1955856d45773a4fd914fcc1f813222f +REG_FIDDLE(BlendMode_010, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstATop); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kSrcATop); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_011.cpp b/docs/examples/BlendMode_011.cpp new file mode 100644 index 0000000000..b244334896 --- /dev/null +++ b/docs/examples/BlendMode_011.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=29db2c7493d9098b8a086ddbe30dd6d6 +REG_FIDDLE(BlendMode_011, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setBlendMode(SkBlendMode::kXor); + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { + SkColor colors[] = { color, SkColorSetA(color, 192), SkColorSetA(color, 128), + SkColorSetA(color, 0) }; + paint.setShader(SkGradientShader::MakeRadial({ 64, 64}, 100, + colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); + canvas->drawCircle(64, 64, 100, paint); + canvas->translate(64, 64); + } +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_012.cpp b/docs/examples/BlendMode_012.cpp new file mode 100644 index 0000000000..a385f84d33 --- /dev/null +++ b/docs/examples/BlendMode_012.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=05383441e510d54008402e128fc8ad2b +REG_FIDDLE(BlendMode_012, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + canvas->drawColor(SK_ColorBLACK); + SkPaint paint; + paint.setBlendMode(SkBlendMode::kPlus); + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { + SkColor colors[] = { color, SkColorSetA(color, 192), SkColorSetA(color, 128), + SkColorSetA(color, 0) }; + paint.setShader(SkGradientShader::MakeRadial({ 64, 64}, 100, + colors, nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); + canvas->drawCircle(64, 64, 100, paint); + canvas->translate(64, 64); + } +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_013.cpp b/docs/examples/BlendMode_013.cpp new file mode 100644 index 0000000000..2bf998ba12 --- /dev/null +++ b/docs/examples/BlendMode_013.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=3fdac2b2f48bd227d2e74234c260bc8e +REG_FIDDLE(BlendMode_013, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + auto drawSquare = [=](int dx, int dy, SkBlendMode mode, const char* label) -> void { + const SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; + const SkPoint horz[] = { { 0, 0 }, { 128, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + paint.setBlendMode(mode); + canvas->translate(dx, dy); + canvas->drawRect({0, 0, 128, 128}, paint); + paint.setBlendMode(SkBlendMode::kXor); + SkFont font; + canvas->drawString(label, 40, 100, font, paint); + }; + drawSquare(0, 0, SkBlendMode::kSrc, "destination"); + drawSquare(128, 0, SkBlendMode::kSrc, ""); + drawSquare(0, 128, SkBlendMode::kSrc, ""); + canvas->translate(-128, -128); + canvas->rotate(90, 0, 128); + drawSquare(0, 0, SkBlendMode::kSrc, "source"); + drawSquare(0, -128, SkBlendMode::kModulate, "modulate"); + drawSquare(-128, 0, SkBlendMode::kMultiply, "multiply"); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_014.cpp b/docs/examples/BlendMode_014.cpp new file mode 100644 index 0000000000..793bf17b3b --- /dev/null +++ b/docs/examples/BlendMode_014.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=b7b42965927788d853f449f08ddf46de +REG_FIDDLE(BlendMode_014, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstATop); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kScreen); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_015.cpp b/docs/examples/BlendMode_015.cpp new file mode 100644 index 0000000000..846360e9ed --- /dev/null +++ b/docs/examples/BlendMode_015.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=03bf042201de02d6d131938ccd3172eb +REG_FIDDLE(BlendMode_015, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + paint.setBlendMode(SkBlendMode::kDstATop); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(SkColorSetA(SK_ColorGREEN, 128), SkBlendMode::kOverlay); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_016.cpp b/docs/examples/BlendMode_016.cpp new file mode 100644 index 0000000000..4bf8b23679 --- /dev/null +++ b/docs/examples/BlendMode_016.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=23c974d2759f523ca2f4a78ae86855c3 +REG_FIDDLE(BlendMode_016, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + SkColor colors[] = { SK_ColorWHITE, SK_ColorBLACK }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + paint.setBlendMode(SkBlendMode::kDarken); + canvas->drawPaint(paint); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_017.cpp b/docs/examples/BlendMode_017.cpp new file mode 100644 index 0000000000..5965f8788b --- /dev/null +++ b/docs/examples/BlendMode_017.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=95cb08b8c8db3af3b2c9ad56ae7d6bc1 +REG_FIDDLE(BlendMode_017, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + SkColor colors[] = { SK_ColorBLACK, SK_ColorWHITE }; + SkPoint horz[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(horz, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode)); + paint.setBlendMode(SkBlendMode::kLighten); + canvas->drawPaint(paint); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_018.cpp b/docs/examples/BlendMode_018.cpp new file mode 100644 index 0000000000..ccac6a3868 --- /dev/null +++ b/docs/examples/BlendMode_018.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=280ad6267a7d2d77b6d2c4531c6fc0bf +REG_FIDDLE(BlendMode_018, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->clipRect({128, 0, 256, 256}); + canvas->drawColor(SkColorSetARGB(0x80, 0x90, 0x90, 0x90), SkBlendMode::kColorDodge); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_019.cpp b/docs/examples/BlendMode_019.cpp new file mode 100644 index 0000000000..e2d78f2494 --- /dev/null +++ b/docs/examples/BlendMode_019.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=3eeef529375d8083ae0d615789d55e89 +REG_FIDDLE(BlendMode_019, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->clipRect({128, 0, 256, 256}); + canvas->drawColor(SkColorSetARGB(0x80, 0x90, 0x90, 0x90), SkBlendMode::kColorBurn); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_020.cpp b/docs/examples/BlendMode_020.cpp new file mode 100644 index 0000000000..a62b6ba90e --- /dev/null +++ b/docs/examples/BlendMode_020.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=ac2fe555e2196e15863ea4ce74db3d54 +REG_FIDDLE(BlendMode_020, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + const SkColor colors[] = { 0xFFFFFFFF, 0x00000000 }; + SkPaint paint; + paint.setBlendMode(SkBlendMode::kHardLight); + paint.setShader(SkGradientShader::MakeRadial({ 128, 128}, 100, colors, + nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); + canvas->clipRect({0, 128, 256, 256}); + canvas->drawPaint(paint); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_021.cpp b/docs/examples/BlendMode_021.cpp new file mode 100644 index 0000000000..343a23a3b4 --- /dev/null +++ b/docs/examples/BlendMode_021.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=ac93f30dff13f8a8bb31398de370863b +REG_FIDDLE(BlendMode_021, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + const SkColor colors[] = { 0xFFFFFFFF, 0x3FFFFFFF }; + SkPaint paint; + paint.setBlendMode(SkBlendMode::kSoftLight); + paint.setShader(SkGradientShader::MakeRadial({ 128, 128}, 100, colors, + nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); + canvas->drawImage(image, 0, 0); + canvas->drawCircle(128, 128, 100, paint); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_022.cpp b/docs/examples/BlendMode_022.cpp new file mode 100644 index 0000000000..90acf16582 --- /dev/null +++ b/docs/examples/BlendMode_022.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=52d2c8d1b9b428de4477b4caa1543a3d +REG_FIDDLE(BlendMode_022, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->drawImage(image, 128, 0); + canvas->drawImage(image, 0, 128); + canvas->drawImage(image, 128, 128); + SkPaint paint; + paint.setBlendMode(SkBlendMode::kDstATop); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(0x80bb9977, SkBlendMode::kDifference); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_023.cpp b/docs/examples/BlendMode_023.cpp new file mode 100644 index 0000000000..3e6a0fdf66 --- /dev/null +++ b/docs/examples/BlendMode_023.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=a544ee1c67c7c557a9e54d5e99f94bb6 +REG_FIDDLE(BlendMode_023, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->drawImage(image, 128, 0); + canvas->drawImage(image, 0, 128); + canvas->drawImage(image, 128, 128); + SkPaint paint; + paint.setBlendMode(SkBlendMode::kDstATop); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(0x80bb9977, SkBlendMode::kExclusion); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_024.cpp b/docs/examples/BlendMode_024.cpp new file mode 100644 index 0000000000..e99c8021e2 --- /dev/null +++ b/docs/examples/BlendMode_024.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=eb29c896f008dfbef09e16b85114fc3a +REG_FIDDLE(BlendMode_024, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->drawImage(image, 128, 0); + canvas->drawImage(image, 0, 128); + canvas->drawImage(image, 128, 128); + SkPaint paint; + paint.setBlendMode(SkBlendMode::kDstATop); + SkColor alphas[] = { SK_ColorBLACK, SK_ColorTRANSPARENT }; + SkPoint vert[] = { { 0, 0 }, { 0, 256 } }; + paint.setShader(SkGradientShader::MakeLinear(vert, alphas, nullptr, SK_ARRAY_COUNT(alphas), + SkShader::kClamp_TileMode)); + canvas->drawPaint(paint); + canvas->clipRect( { 30, 30, 226, 226 } ); + canvas->drawColor(0x80bb9977, SkBlendMode::kMultiply); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_025.cpp b/docs/examples/BlendMode_025.cpp new file mode 100644 index 0000000000..a5ee489160 --- /dev/null +++ b/docs/examples/BlendMode_025.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=41e45570d682397d3b8ff2f51bd9c574 +REG_FIDDLE(BlendMode_025, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->drawColor(0xFF00FF00, SkBlendMode::kHue); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_026.cpp b/docs/examples/BlendMode_026.cpp new file mode 100644 index 0000000000..c47986af9c --- /dev/null +++ b/docs/examples/BlendMode_026.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=a48698975d236573cef512f94a7e360b +REG_FIDDLE(BlendMode_026, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->drawColor(0xFF00FF00, SkBlendMode::kSaturation); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_027.cpp b/docs/examples/BlendMode_027.cpp new file mode 100644 index 0000000000..0ed6a1aab4 --- /dev/null +++ b/docs/examples/BlendMode_027.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=5d7c6e23a34ca9bf3ba8cda4cdc94cc4 +REG_FIDDLE(BlendMode_027, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->drawColor(0xFF00FF00, SkBlendMode::kColor); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_028.cpp b/docs/examples/BlendMode_028.cpp new file mode 100644 index 0000000000..280df28298 --- /dev/null +++ b/docs/examples/BlendMode_028.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=7d42fe34ae20dd9e12c39dc3950e9989 +REG_FIDDLE(BlendMode_028, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawImage(image, 0, 0); + canvas->drawColor(0xFF00FF00, SkBlendMode::kLuminosity); +} +} // END FIDDLE diff --git a/docs/examples/BlendMode_029.cpp b/docs/examples/BlendMode_029.cpp new file mode 100644 index 0000000000..cc91036fda --- /dev/null +++ b/docs/examples/BlendMode_029.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=3996f4994bf4e90b4cd86524c1f9f1a6 +REG_FIDDLE(BlendMode_029, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("default blend: SkBlendMode::k%s\n", SkBlendMode_Name(SkPaint().getBlendMode())); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_000.cpp b/docs/examples/Canvas_000.cpp new file mode 100644 index 0000000000..f11b0fdc3d --- /dev/null +++ b/docs/examples/Canvas_000.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=525285073aae7e53eb8f454a398f880c +REG_FIDDLE(Canvas_000, 256, 256, true, 0) { +void draw(SkCanvas* ) { + SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); // device aligned, 32 bpp, Premultiplied + const size_t minRowBytes = info.minRowBytes(); // bytes used by one bitmap row + const size_t size = info.computeMinByteSize(); // bytes used by all rows + SkAutoTMalloc storage(size); // allocate storage for pixels + SkPMColor* pixels = storage.get(); // get pointer to allocated storage + // create a SkCanvas backed by a raster device, and delete it when the + // function goes out of scope. + std::unique_ptr canvas = SkCanvas::MakeRasterDirect(info, pixels, minRowBytes); + canvas->clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order + canvas->flush(); // ensure that pixels are cleared + SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary + SkPaint paint; // by default, draws black + canvas->drawPoint(1, 1, paint); // draw in the center + canvas->flush(); // ensure that point was drawn + for (int y = 0; y < info.height(); ++y) { + for (int x = 0; x < info.width(); ++x) { + SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); + } + SkDebugf("\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_001.cpp b/docs/examples/Canvas_001.cpp new file mode 100644 index 0000000000..7d66118bfd --- /dev/null +++ b/docs/examples/Canvas_001.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=87f55e62ec4c3535e1a5d0f1415b20c6 +REG_FIDDLE(Canvas_001, 256, 256, true, 0) { +void draw(SkCanvas* ) { + const int width = 3; + const int height = 3; + SkPMColor pixels[height][width]; // allocate a 3 by 3 Premultiplied bitmap on the stack + // create a SkCanvas backed by a raster device, and delete it when the + // function goes out of scope. + std::unique_ptr canvas = SkCanvas::MakeRasterDirectN32( + width, + height, + pixels[0], // top-left of the bitmap + sizeof(pixels[0])); // byte width of the each row + // write a Premultiplied value for white into all pixels in the bitmap + canvas->clear(SK_ColorWHITE); + SkPMColor pmWhite = pixels[0][0]; // the Premultiplied format may vary + SkPaint paint; // by default, draws black + canvas->drawPoint(1, 1, paint); // draw in the center + canvas->flush(); // ensure that pixels is ready to be read + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + SkDebugf("%c", pixels[y][x] == pmWhite ? '-' : 'x'); + } + SkDebugf("\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_002.cpp b/docs/examples/Canvas_002.cpp new file mode 100644 index 0000000000..253b4f7525 --- /dev/null +++ b/docs/examples/Canvas_002.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=4a00e6589e862fde5be532f4b6e316ce +REG_FIDDLE(Canvas_002, 256, 256, true, 0) { +static void check_for_rotated_ctm(const SkCanvas* canvas) { + const SkMatrix& matrix = canvas->getTotalMatrix(); + SkDebugf("rect stays rect is %s\n", matrix.rectStaysRect() ? "true" : "false"); +} + +void draw(SkCanvas* canvas) { + check_for_rotated_ctm(canvas); + canvas->rotate(30); + check_for_rotated_ctm(canvas); + SkCanvas defaultCanvas; + check_for_rotated_ctm(&defaultCanvas); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_003.cpp b/docs/examples/Canvas_003.cpp new file mode 100644 index 0000000000..88b5571814 --- /dev/null +++ b/docs/examples/Canvas_003.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=ce6a5ef2df447970b4453489d9d67930 +REG_FIDDLE(Canvas_003, 256, 256, true, 0) { +void draw(SkCanvas* ) { + SkCanvas canvas(10, 20); // 10 units wide, 20 units high + canvas.clipRect(SkRect::MakeXYWH(30, 40, 5, 10)); // clip is outside canvas' device + SkDebugf("canvas %s empty\n", canvas.getDeviceClipBounds().isEmpty() ? "is" : "is not"); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_004.cpp b/docs/examples/Canvas_004.cpp new file mode 100644 index 0000000000..9c8dd979a5 --- /dev/null +++ b/docs/examples/Canvas_004.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=dd92db963af190e849894038f39b598a +REG_FIDDLE(Canvas_004, 256, 256, true, 0) { +void draw(SkCanvas* ) { + SkBitmap bitmap; + // create a bitmap 5 wide and 11 high + bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); + SkCanvas canvas(bitmap); + canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order + SkPixmap pixmap; // provides guaranteed access to the drawn pixels + if (!canvas.peekPixels(&pixmap)) { + SkDebugf("peekPixels should never fail.\n"); + } + const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap + SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary + SkPaint paint; // by default, draws black, 12 point text + SkFont font; + canvas.drawString("!", 1, 10, font, paint); // 1 char at baseline (1, 10) + for (int y = 0; y < bitmap.height(); ++y) { + for (int x = 0; x < bitmap.width(); ++x) { + SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); + } + SkDebugf("\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_005.cpp b/docs/examples/Canvas_005.cpp new file mode 100644 index 0000000000..67b6e1bb60 --- /dev/null +++ b/docs/examples/Canvas_005.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=c26cfae4c42cb445240335cc12a50235 +REG_FIDDLE(Canvas_005, 256, 256, true, 0) { +void draw(SkCanvas* ) { + SkBitmap bitmap; + // create a bitmap 5 wide and 11 high + bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11)); + SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); + canvas.clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order + SkPixmap pixmap; // provides guaranteed access to the drawn pixels + if (!canvas.peekPixels(&pixmap)) { + SkDebugf("peekPixels should never fail.\n"); + } + const SkPMColor* pixels = pixmap.addr32(); // points to top-left of bitmap + SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary + SkPaint paint; // by default, draws black, 12 point text + SkFont font; + canvas.drawString("!", 1, 10, font, paint); // 1 char at baseline (1, 10) + for (int y = 0; y < bitmap.height(); ++y) { + for (int x = 0; x < bitmap.width(); ++x) { + SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); + } + SkDebugf("\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_006.cpp b/docs/examples/Canvas_006.cpp new file mode 100644 index 0000000000..f7b2678f12 --- /dev/null +++ b/docs/examples/Canvas_006.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=b7bc91ff16c9b9351b2a127f35394b82 +REG_FIDDLE(Canvas_006, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(200, 200)); + { + SkCanvas offscreen(bitmap); + SkPaint paint; + SkFont font(nullptr, 100); + offscreen.drawString("ABC", 20, 160, font, paint); + SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); + offscreen.saveLayerAlpha(&layerBounds, 128); + offscreen.clear(SK_ColorWHITE); + offscreen.drawString("DEF", 20, 160, font, paint); + } + canvas->drawBitmap(bitmap, 0, 0, nullptr); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_008.cpp b/docs/examples/Canvas_008.cpp new file mode 100644 index 0000000000..35031c1e89 --- /dev/null +++ b/docs/examples/Canvas_008.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=d93389d971f8084c4ccc7a66e4e157ee +REG_FIDDLE(Canvas_008, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkCanvas emptyCanvas; + SkImageInfo canvasInfo = emptyCanvas.imageInfo(); + SkImageInfo emptyInfo; + SkDebugf("emptyInfo %c= canvasInfo\n", emptyInfo == canvasInfo ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_009.cpp b/docs/examples/Canvas_009.cpp new file mode 100644 index 0000000000..981539cd78 --- /dev/null +++ b/docs/examples/Canvas_009.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=0fbf2dedc2619bbfbf173c9e3bc1a508 +REG_FIDDLE(Canvas_009, 256, 256, true, 0) { +void draw(SkCanvas* ) { + SkBitmap bitmap; + bitmap.allocN32Pixels(1, 1); + SkCanvas canvas(bitmap, SkSurfaceProps(0, kRGB_V_SkPixelGeometry)); + SkSurfaceProps surfaceProps(0, kUnknown_SkPixelGeometry); + SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); + if (!canvas.getProps(&surfaceProps)) { + SkDebugf("getProps failed unexpectedly.\n"); + } + SkDebugf("isRGB:%d\n", SkPixelGeometryIsRGB(surfaceProps.pixelGeometry())); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_010.cpp b/docs/examples/Canvas_010.cpp new file mode 100644 index 0000000000..75772dcfa9 --- /dev/null +++ b/docs/examples/Canvas_010.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=374e245d91cd729eca48fd20e631fdf3 +REG_FIDDLE(Canvas_010, 256, 256, true, 0) { +void draw(SkCanvas* ) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(20, 30)); + SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry)); + canvas.clipRect(SkRect::MakeWH(10, 40)); + SkIRect clipDeviceBounds = canvas.getDeviceClipBounds(); + if (clipDeviceBounds.isEmpty()) { + SkDebugf("Empty clip bounds is unexpected!\n"); + } + SkDebugf("clip=%d,%d\n", clipDeviceBounds.width(), clipDeviceBounds.height()); + SkISize baseLayerSize = canvas.getBaseLayerSize(); + SkDebugf("size=%d,%d\n", baseLayerSize.width(), baseLayerSize.height()); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_011.cpp b/docs/examples/Canvas_011.cpp new file mode 100644 index 0000000000..25bb09b123 --- /dev/null +++ b/docs/examples/Canvas_011.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=1ce28351444b41ab2b8e3128a4b9b9c2 +REG_FIDDLE(Canvas_011, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + sk_sp surface = SkSurface::MakeRasterN32Premul(5, 6); + SkCanvas* smallCanvas = surface->getCanvas(); + SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(3, 4); + sk_sp compatible = smallCanvas->makeSurface(imageInfo); + SkDebugf("compatible %c= nullptr\n", compatible == nullptr ? '=' : '!'); + SkDebugf("size = %d, %d\n", compatible->width(), compatible->height()); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_012.cpp b/docs/examples/Canvas_012.cpp new file mode 100644 index 0000000000..ccccaa39ab --- /dev/null +++ b/docs/examples/Canvas_012.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=c4ea949e5fa5a0630dcb6b0204bd498f +REG_FIDDLE(Canvas_012, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + if (canvas->getGrContext()) { + canvas->clear(SK_ColorRED); + } else { + canvas->clear(SK_ColorBLUE); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_013.cpp b/docs/examples/Canvas_013.cpp new file mode 100644 index 0000000000..1c3f8e3dd2 --- /dev/null +++ b/docs/examples/Canvas_013.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=38d0d6ca9bea146d31bcbec197856359 +REG_FIDDLE(Canvas_013, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + if (canvas->accessTopLayerPixels(nullptr, nullptr)) { + canvas->clear(SK_ColorRED); + } else { + canvas->clear(SK_ColorBLUE); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_014.cpp b/docs/examples/Canvas_014.cpp new file mode 100644 index 0000000000..a0519e0d53 --- /dev/null +++ b/docs/examples/Canvas_014.cpp @@ -0,0 +1,40 @@ +// 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 "fiddle/examples.h" +// HASH=a7ac9c21bbabcdeeca00f72a61cd0f3e +REG_FIDDLE(Canvas_014, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkFont font(nullptr, 100); + canvas->drawString("ABC", 20, 160, font, paint); + SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192); + canvas->saveLayerAlpha(&layerBounds, 128); + canvas->clear(SK_ColorWHITE); + canvas->drawString("DEF", 20, 160, font, paint); + SkImageInfo imageInfo; + size_t rowBytes; + SkIPoint origin; + uint32_t* access = (uint32_t*) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin); + if (access) { + int h = imageInfo.height(); + int v = imageInfo.width(); + int rowWords = rowBytes / sizeof(uint32_t); + for (int y = 0; y < h; ++y) { + int newY = (y - h / 2) * 2 + h / 2; + if (newY < 0 || newY >= h) { + continue; + } + for (int x = 0; x < v; ++x) { + int newX = (x - v / 2) * 2 + v / 2; + if (newX < 0 || newX >= v) { + continue; + } + if (access[y * rowWords + x] == SK_ColorBLACK) { + access[newY * rowWords + newX] = SK_ColorGRAY; + } + } + } + } + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_015.cpp b/docs/examples/Canvas_015.cpp new file mode 100644 index 0000000000..e40b25749c --- /dev/null +++ b/docs/examples/Canvas_015.cpp @@ -0,0 +1,33 @@ +// 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 "fiddle/examples.h" +// HASH=4486d0c0b22ad2931db130f42da4c80c +REG_FIDDLE(Canvas_015, 256, 256, true, 0) { +static void DeleteCallback(void*, void* context) { + delete (char*) context; +} +class CustomAllocator : public SkRasterHandleAllocator { +public: + bool allocHandle(const SkImageInfo& info, Rec* rec) override { + char* context = new char[4]{'s', 'k', 'i', 'a'}; + rec->fReleaseProc = DeleteCallback; + rec->fReleaseCtx = context; + rec->fHandle = context; + rec->fPixels = context; + rec->fRowBytes = 4; + return true; + } + void updateHandle(Handle handle, const SkMatrix& ctm, const SkIRect& clip_bounds) override { + // apply canvas matrix and clip to custom environment + } +}; + +void draw(SkCanvas* canvas) { + const SkImageInfo info = SkImageInfo::MakeN32Premul(1, 1); + std::unique_ptr c2 = + SkRasterHandleAllocator::MakeCanvas(std::unique_ptr( + new CustomAllocator()), info); + char* context = (char*) c2->accessTopRasterHandle(); + SkDebugf("context = %.4s\n", context); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_016.cpp b/docs/examples/Canvas_016.cpp new file mode 100644 index 0000000000..c3f4b78df9 --- /dev/null +++ b/docs/examples/Canvas_016.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=e9411d676d1fa13b46331abe9e14ad3e +REG_FIDDLE(Canvas_016, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPixmap pixmap; + if (canvas->peekPixels(&pixmap)) { + SkDebugf("width=%d height=%d\n", pixmap.bounds().width(), pixmap.bounds().height()); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_017.cpp b/docs/examples/Canvas_017.cpp new file mode 100644 index 0000000000..c5112dd08e --- /dev/null +++ b/docs/examples/Canvas_017.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=102d014d7f753db2a9b9ee08893aaf11 +REG_FIDDLE(Canvas_017, 64, 64, false, 0) { +void draw(SkCanvas* canvas) { + canvas->clear(SK_ColorBLUE); + SkPaint paint; + canvas->drawCircle(32, 32, 28, paint); + SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); + sk_sp data(SkData::MakeUninitialized(info.minRowBytes() * info.height())); + sk_bzero(data->writable_data(), info.minRowBytes() * info.height()); + for (int x : { 32, -32 } ) { + for (int y : { 32, -32 } ) { + canvas->readPixels(info, data->writable_data(), info.minRowBytes(), x, y); + } + } + sk_sp image = SkImage::MakeRasterData(info, data, info.minRowBytes()); + canvas->drawImage(image, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_018.cpp b/docs/examples/Canvas_018.cpp new file mode 100644 index 0000000000..e122a527c3 --- /dev/null +++ b/docs/examples/Canvas_018.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=481e990e923a0ed34654f4361b94f096 +REG_FIDDLE(Canvas_018, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + canvas->clear(0x8055aaff); + for (SkAlphaType alphaType : { kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { + uint32_t pixel = 0; + SkImageInfo info = SkImageInfo::Make(1, 1, kBGRA_8888_SkColorType, alphaType); + if (canvas->readPixels(info, &pixel, 4, 0, 0)) { + SkDebugf("pixel = %08x\n", pixel); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_019.cpp b/docs/examples/Canvas_019.cpp new file mode 100644 index 0000000000..b86a8cabfd --- /dev/null +++ b/docs/examples/Canvas_019.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=85f199032943b6483722c34a91c4e20f +REG_FIDDLE(Canvas_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + canvas->clear(0x8055aaff); + uint32_t pixels[1] = { 0 }; + SkPixmap pixmap(SkImageInfo::MakeN32Premul(1, 1), pixels, 4); + canvas->readPixels(pixmap, 0, 0); + SkDebugf("pixel = %08x\n", pixels[0]); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_020.cpp b/docs/examples/Canvas_020.cpp new file mode 100644 index 0000000000..85853990d1 --- /dev/null +++ b/docs/examples/Canvas_020.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=af6dec8ef974aa67bf102f29915bcd6a +REG_FIDDLE(Canvas_020, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + canvas->clear(0x8055aaff); + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(1, 1)); + canvas->readPixels(bitmap, 0, 0); + SkDebugf("pixel = %08x\n", bitmap.getAddr32(0, 0)[0]); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_021.cpp b/docs/examples/Canvas_021.cpp new file mode 100644 index 0000000000..849411f2cd --- /dev/null +++ b/docs/examples/Canvas_021.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=29b98ebf58aa9fd1edfaabf9f4490b3a +REG_FIDDLE(Canvas_021, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo imageInfo = SkImageInfo::MakeN32(256, 1, kPremul_SkAlphaType); + for (int y = 0; y < 256; ++y) { + uint32_t pixels[256]; + for (int x = 0; x < 256; ++x) { + pixels[x] = SkColorSetARGB(x, (x + y) % 256, x, (x - y) & 0xFF); + } + canvas->writePixels(imageInfo, &pixels, sizeof(pixels), 0, y); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_022.cpp b/docs/examples/Canvas_022.cpp new file mode 100644 index 0000000000..453dd9335e --- /dev/null +++ b/docs/examples/Canvas_022.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=8b128e067881f9251357653692fa28da +REG_FIDDLE(Canvas_022, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(2, 2); + SkBitmap bitmap; + bitmap.setInfo(imageInfo); + uint32_t pixels[4]; + bitmap.setPixels(pixels); + for (int y = 0; y < 256; y += 2) { + for (int x = 0; x < 256; x += 2) { + pixels[0] = SkColorSetRGB(x, y, x | y); + pixels[1] = SkColorSetRGB(x ^ y, y, x); + pixels[2] = SkColorSetRGB(x, x & y, y); + pixels[3] = SkColorSetRGB((~x) & 0xFF, (~y) & 0xFF, x); + canvas->writePixels(bitmap, x, y); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_023.cpp b/docs/examples/Canvas_023.cpp new file mode 100644 index 0000000000..559ebe5a09 --- /dev/null +++ b/docs/examples/Canvas_023.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=bb1dbfdca3aedf716beb6f07e2aab065 +REG_FIDDLE(Canvas_023, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + canvas->save(); // records stack depth to restore + canvas->clipRect(SkRect::MakeWH(100, 100)); // constrains drawing to clip + canvas->clear(SK_ColorRED); // draws to limit of clip + canvas->save(); // records stack depth to restore + canvas->clipRect(SkRect::MakeWH(50, 150)); // Rect below 100 is ignored + canvas->clear(SK_ColorBLUE); // draws to smaller clip + canvas->restore(); // enlarges clip + canvas->drawLine(20, 20, 150, 150, paint); // line below 100 is not drawn + canvas->restore(); // enlarges clip + canvas->drawLine(150, 20, 50, 120, paint); // line below 100 is drawn +} +} // END FIDDLE diff --git a/docs/examples/Canvas_024.cpp b/docs/examples/Canvas_024.cpp new file mode 100644 index 0000000000..4e51502531 --- /dev/null +++ b/docs/examples/Canvas_024.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=9f563a2d60aa31d4b26742e5aa17aa4e +REG_FIDDLE(Canvas_024, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + canvas->clipRect(SkRect::MakeWH(100, 100)); + canvas->clear(SK_ColorRED); + canvas->scale(.5, .5); + canvas->clipRect(SkRect::MakeWH(100, 100)); + canvas->clear(SK_ColorBLUE); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_025.cpp b/docs/examples/Canvas_025.cpp new file mode 100644 index 0000000000..d80e94deb0 --- /dev/null +++ b/docs/examples/Canvas_025.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=e477dce358a9ba3b0aa1bf33b8a376de +REG_FIDDLE(Canvas_025, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRect rect = { 0, 0, 25, 25 }; + canvas->drawRect(rect, paint); + canvas->save(); + canvas->translate(50, 50); + canvas->drawRect(rect, paint); + canvas->restore(); + paint.setColor(SK_ColorRED); + canvas->drawRect(rect, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_026.cpp b/docs/examples/Canvas_026.cpp new file mode 100644 index 0000000000..696b5ff685 --- /dev/null +++ b/docs/examples/Canvas_026.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=e78471212a67f2f4fd39496e17a30d17 +REG_FIDDLE(Canvas_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkCanvas simple; + SkDebugf("depth = %d\n", simple.getSaveCount()); + simple.restore(); + SkDebugf("depth = %d\n", simple.getSaveCount()); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_027.cpp b/docs/examples/Canvas_027.cpp new file mode 100644 index 0000000000..19e54017e9 --- /dev/null +++ b/docs/examples/Canvas_027.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=005f2b207e078baac596681924fe591e +REG_FIDDLE(Canvas_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkCanvas simple; + SkDebugf("depth = %d\n", simple.getSaveCount()); + simple.save(); + SkDebugf("depth = %d\n", simple.getSaveCount()); + simple.restore(); + SkDebugf("depth = %d\n", simple.getSaveCount()); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_028.cpp b/docs/examples/Canvas_028.cpp new file mode 100644 index 0000000000..454f37d6b3 --- /dev/null +++ b/docs/examples/Canvas_028.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=9ed0d56436e114c7097fd49eed1aea47 +REG_FIDDLE(Canvas_028, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("depth = %d\n", canvas->getSaveCount()); + canvas->save(); + canvas->save(); + SkDebugf("depth = %d\n", canvas->getSaveCount()); + canvas->restoreToCount(0); + SkDebugf("depth = %d\n", canvas->getSaveCount()); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_029.cpp b/docs/examples/Canvas_029.cpp new file mode 100644 index 0000000000..782aff6a17 --- /dev/null +++ b/docs/examples/Canvas_029.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=42318b18d403e17e07a541652da91ee2 +REG_FIDDLE(Canvas_029, 256, 128, false, 0) { +#include "SkBlurImageFilter.h" + +void draw(SkCanvas* canvas) { + SkPaint paint, blur; + blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); + canvas->saveLayer(nullptr, &blur); + SkRect rect = { 25, 25, 50, 50}; + canvas->drawRect(rect, paint); + canvas->translate(50, 50); + paint.setColor(SK_ColorRED); + canvas->drawRect(rect, paint); + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_030.cpp b/docs/examples/Canvas_030.cpp new file mode 100644 index 0000000000..94c66aba3d --- /dev/null +++ b/docs/examples/Canvas_030.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=a17aec3aa4909527be039e26a7eda694 +REG_FIDDLE(Canvas_030, 256, 128, false, 0) { +#include "SkBlurImageFilter.h" + +void draw(SkCanvas* canvas) { + SkPaint paint, blur; + blur.setImageFilter(SkBlurImageFilter::Make(3, 3, nullptr)); + canvas->saveLayer(SkRect::MakeWH(90, 90), &blur); + SkRect rect = { 25, 25, 50, 50}; + canvas->drawRect(rect, paint); + canvas->translate(50, 50); + paint.setColor(SK_ColorRED); + canvas->drawRect(rect, paint); + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_031.cpp b/docs/examples/Canvas_031.cpp new file mode 100644 index 0000000000..33d6e55112 --- /dev/null +++ b/docs/examples/Canvas_031.cpp @@ -0,0 +1,28 @@ +#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 "fiddle/examples.h" +// HASH=8460bf8b013f46c67e0bd96e13451aff +REG_FIDDLE(Canvas_031, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setLCDRenderText(true); + paint.setTextSize(20); + for (auto preserve : { false, true } ) { + preserve ? canvas->saveLayerPreserveLCDTextRequests(nullptr, nullptr) + : canvas->saveLayer(nullptr, nullptr); + SkPaint p; + p.setColor(SK_ColorWHITE); + // Comment out the next line to draw on a non-opaque background. + canvas->drawRect(SkRect::MakeLTRB(25, 40, 200, 70), p); + canvas->drawString("Hamburgefons", 30, 60, paint); + p.setColor(0xFFCCCCCC); + canvas->drawRect(SkRect::MakeLTRB(25, 70, 200, 100), p); + canvas->drawString("Hamburgefons", 30, 90, paint); + canvas->restore(); + canvas->translate(0, 80); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Canvas_032.cpp b/docs/examples/Canvas_032.cpp new file mode 100644 index 0000000000..34e09137c5 --- /dev/null +++ b/docs/examples/Canvas_032.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=8ab88d86fb438856cc48d6e2f08a6e24 +REG_FIDDLE(Canvas_032, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorRED); + canvas->drawCircle(50, 50, 50, paint); + canvas->saveLayerAlpha(nullptr, 128); + paint.setColor(SK_ColorBLUE); + canvas->drawCircle(100, 50, 50, paint); + paint.setColor(SK_ColorGREEN); + paint.setAlpha(128); + canvas->drawCircle(75, 90, 50, paint); + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_033.cpp b/docs/examples/Canvas_033.cpp new file mode 100644 index 0000000000..4bea2d5950 --- /dev/null +++ b/docs/examples/Canvas_033.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=05db6a937225e8e31ae3481173d25dae +REG_FIDDLE(Canvas_033, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint redPaint, bluePaint, scalePaint; + redPaint.setColor(SK_ColorRED); + canvas->drawCircle(21, 21, 8, redPaint); + bluePaint.setColor(SK_ColorBLUE); + canvas->drawCircle(31, 21, 8, bluePaint); + SkMatrix matrix; + matrix.setScale(4, 4); + scalePaint.setAlpha(0x40); + scalePaint.setImageFilter( + SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); + SkCanvas::SaveLayerRec saveLayerRec(nullptr, &scalePaint, + SkCanvas::kInitWithPrevious_SaveLayerFlag); + canvas->saveLayer(saveLayerRec); + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_034.cpp b/docs/examples/Canvas_034.cpp new file mode 100644 index 0000000000..0b7aeda962 --- /dev/null +++ b/docs/examples/Canvas_034.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=ee8c0b120234e27364f8c9a786cf8f89 +REG_FIDDLE(Canvas_034, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint redPaint, bluePaint; + redPaint.setAntiAlias(true); + redPaint.setColor(SK_ColorRED); + canvas->drawCircle(21, 21, 8, redPaint); + bluePaint.setColor(SK_ColorBLUE); + canvas->drawCircle(31, 21, 8, bluePaint); + SkMatrix matrix; + matrix.setScale(4, 4); + auto scaler = SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr); + SkCanvas::SaveLayerRec saveLayerRec(nullptr, nullptr, scaler.get(), 0); + canvas->saveLayer(saveLayerRec); + canvas->drawCircle(125, 85, 8, redPaint); + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_035.cpp b/docs/examples/Canvas_035.cpp new file mode 100644 index 0000000000..1416ec7ee8 --- /dev/null +++ b/docs/examples/Canvas_035.cpp @@ -0,0 +1,17 @@ +#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 "fiddle/examples.h" +// HASH=b5cea1eed80a0eb04ddbab3f36dff73f +REG_FIDDLE(Canvas_035, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkCanvas::SaveLayerRec rec1; + rec1.fSaveLayerFlags = SkCanvas::kPreserveLCDText_SaveLayerFlag; + SkCanvas::SaveLayerRec rec2(nullptr, nullptr, SkCanvas::kPreserveLCDText_SaveLayerFlag); + SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds + && rec1.fPaint == rec2.fPaint + && rec1.fBackdrop == rec2.fBackdrop + && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Canvas_036.cpp b/docs/examples/Canvas_036.cpp new file mode 100644 index 0000000000..173303d9fc --- /dev/null +++ b/docs/examples/Canvas_036.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=027f920259888fc19591ea9a90d92873 +REG_FIDDLE(Canvas_036, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkCanvas::SaveLayerRec rec1; + SkCanvas::SaveLayerRec rec2(nullptr, nullptr); + SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds + && rec1.fPaint == rec2.fPaint + && rec1.fBackdrop == rec2.fBackdrop + && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_037.cpp b/docs/examples/Canvas_037.cpp new file mode 100644 index 0000000000..cc511b4771 --- /dev/null +++ b/docs/examples/Canvas_037.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=9b7fa2fe855642ffff6538829db15328 +REG_FIDDLE(Canvas_037, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkCanvas::SaveLayerRec rec1; + SkCanvas::SaveLayerRec rec2(nullptr, nullptr, nullptr, 0); + SkDebugf("rec1 %c= rec2\n", rec1.fBounds == rec2.fBounds + && rec1.fPaint == rec2.fPaint + && rec1.fBackdrop == rec2.fBackdrop + && rec1.fSaveLayerFlags == rec2.fSaveLayerFlags ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_038.cpp b/docs/examples/Canvas_038.cpp new file mode 100644 index 0000000000..e3b26ba31f --- /dev/null +++ b/docs/examples/Canvas_038.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=7d3751e82d1b6ec328ffa3d6f48ca831 +REG_FIDDLE(Canvas_038, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + // sk_sp image = GetResourceAsImage("images/mandrill_256.png"); + canvas->drawImage(image, 0, 0, nullptr); + SkCanvas::SaveLayerRec rec; + SkPaint paint; + paint.setBlendMode(SkBlendMode::kPlus); + rec.fSaveLayerFlags = SkCanvas::kInitWithPrevious_SaveLayerFlag; + rec.fPaint = &paint; + canvas->saveLayer(rec); + paint.setBlendMode(SkBlendMode::kClear); + canvas->drawCircle(128, 128, 96, paint); + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_039.cpp b/docs/examples/Canvas_039.cpp new file mode 100644 index 0000000000..58549a36a0 --- /dev/null +++ b/docs/examples/Canvas_039.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=eb93d5fa66a5f7a10f4f9210494d7222 +REG_FIDDLE(Canvas_039, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint filledPaint; + SkPaint outlinePaint; + outlinePaint.setStyle(SkPaint::kStroke_Style); + outlinePaint.setColor(SK_ColorBLUE); + canvas->save(); + canvas->translate(50, 50); + canvas->drawCircle(28, 28, 15, outlinePaint); // blue center: (50+28, 50+28) + canvas->scale(2, 1/2.f); + canvas->drawCircle(28, 28, 15, filledPaint); // black center: (50+(28*2), 50+(28/2)) + canvas->restore(); + filledPaint.setColor(SK_ColorGRAY); + outlinePaint.setColor(SK_ColorRED); + canvas->scale(2, 1/2.f); + canvas->drawCircle(28, 28, 15, outlinePaint); // red center: (28*2, 28/2) + canvas->translate(50, 50); + canvas->drawCircle(28, 28, 15, filledPaint); // gray center: ((50+28)*2, (50+28)/2) +} +} // END FIDDLE diff --git a/docs/examples/Canvas_040.cpp b/docs/examples/Canvas_040.cpp new file mode 100644 index 0000000000..128dfa2437 --- /dev/null +++ b/docs/examples/Canvas_040.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=7d0d801ef13c6c6da51e840c22ac15b0 +REG_FIDDLE(Canvas_040, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRect rect = { 10, 20, 60, 120 }; + canvas->translate(20, 20); + canvas->drawRect(rect, paint); + canvas->scale(2, .5f); + paint.setColor(SK_ColorGRAY); + canvas->drawRect(rect, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_041.cpp b/docs/examples/Canvas_041.cpp new file mode 100644 index 0000000000..3d44c7fece --- /dev/null +++ b/docs/examples/Canvas_041.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=963789ac8498d4e505748ab3b15cdaa5 +REG_FIDDLE(Canvas_041, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + canvas->translate(128, 128); + canvas->drawCircle(0, 0, 60, paint); + canvas->save(); + canvas->rotate(10 * 360 / 60); // 10 minutes of 60 scaled to 360 degrees + canvas->drawLine(0, 0, 0, -50, paint); + canvas->restore(); + canvas->rotate((5 + 10.f/60) * 360 / 12); // 5 and 10/60 hours of 12 scaled to 360 degrees + canvas->drawLine(0, 0, 0, -30, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_042.cpp b/docs/examples/Canvas_042.cpp new file mode 100644 index 0000000000..b052bfcfa9 --- /dev/null +++ b/docs/examples/Canvas_042.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=bcf5baea1c66a957d5ffd7b54bbbfeff +REG_FIDDLE(Canvas_042, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkFont font(nullptr, 96); + canvas->drawString("A1", 130, 100, font, paint); + canvas->rotate(180, 130, 100); + canvas->drawString("A1", 130, 100, font, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_043.cpp b/docs/examples/Canvas_043.cpp new file mode 100644 index 0000000000..5e2e99db72 --- /dev/null +++ b/docs/examples/Canvas_043.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=2e2acc21d7774df7e0940a30ad2ca99e +REG_FIDDLE(Canvas_043, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkFont font(nullptr, 128); + canvas->translate(30, 130); + canvas->save(); + canvas->skew(-.5, 0); + canvas->drawString("A1", 0, 0, font, paint); + canvas->restore(); + canvas->save(); + canvas->skew(0, .5); + paint.setColor(SK_ColorRED); + canvas->drawString("A1", 0, 0, font, paint); + canvas->restore(); + canvas->skew(-.5, .5); + paint.setColor(SK_ColorBLUE); + canvas->drawString("A1", 0, 0, font, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_044.cpp b/docs/examples/Canvas_044.cpp new file mode 100644 index 0000000000..a0f766efe7 --- /dev/null +++ b/docs/examples/Canvas_044.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=8f6818b25a92a88638ad99b2dd293f61 +REG_FIDDLE(Canvas_044, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkFont font(nullptr, 80); + font.setScaleX(.3); + SkMatrix matrix; + SkRect rect[2] = {{ 10, 20, 90, 110 }, { 40, 130, 140, 180 }}; + matrix.setRectToRect(rect[0], rect[1], SkMatrix::kFill_ScaleToFit); + canvas->drawRect(rect[0], paint); + canvas->drawRect(rect[1], paint); + paint.setColor(SK_ColorWHITE); + canvas->drawString("Here", rect[0].fLeft + 10, rect[0].fBottom - 10, font, paint); + canvas->concat(matrix); + canvas->drawString("There", rect[0].fLeft + 10, rect[0].fBottom - 10, font, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_045.cpp b/docs/examples/Canvas_045.cpp new file mode 100644 index 0000000000..4b3abea6e9 --- /dev/null +++ b/docs/examples/Canvas_045.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=24b9cf7e6f9a08394e1e07413bd8733a +REG_FIDDLE(Canvas_045, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkFont font; + canvas->scale(4, 6); + canvas->drawString("truth", 2, 10, font, paint); + SkMatrix matrix; + matrix.setScale(2.8f, 6); + canvas->setMatrix(matrix); + canvas->drawString("consequences", 2, 20, font, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_046.cpp b/docs/examples/Canvas_046.cpp new file mode 100644 index 0000000000..30c9916ba5 --- /dev/null +++ b/docs/examples/Canvas_046.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=412afffdf4682baa503a4e2e99201967 +REG_FIDDLE(Canvas_046, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkFont font; + canvas->scale(4, 6); + canvas->drawString("truth", 2, 10, font, paint); + canvas->resetMatrix(); + canvas->scale(2.8f, 6); + canvas->drawString("consequences", 2, 20, font, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_047.cpp b/docs/examples/Canvas_047.cpp new file mode 100644 index 0000000000..67f1c515d5 --- /dev/null +++ b/docs/examples/Canvas_047.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=c0d5fa544759704768f47cac91ae3832 +REG_FIDDLE(Canvas_047, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("isIdentity %s\n", canvas->getTotalMatrix().isIdentity() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_048.cpp b/docs/examples/Canvas_048.cpp new file mode 100644 index 0000000000..aa163845d2 --- /dev/null +++ b/docs/examples/Canvas_048.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=862cc026601a41a58df49c0b9f0d7777 +REG_FIDDLE(Canvas_048, 256, 90, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint redPaint, scalePaint; + redPaint.setAntiAlias(true); + redPaint.setColor(SK_ColorRED); + canvas->save(); + for (bool antialias : { false, true } ) { + canvas->save(); + canvas->clipRect(SkRect::MakeWH(19.5f, 11.5f), antialias); + canvas->drawCircle(17, 11, 8, redPaint); + canvas->restore(); + canvas->translate(16, 0); + } + canvas->restore(); + SkMatrix matrix; + matrix.setScale(6, 6); + scalePaint.setImageFilter( + SkImageFilter::MakeMatrixFilter(matrix, kNone_SkFilterQuality, nullptr)); + SkCanvas::SaveLayerRec saveLayerRec( + nullptr, &scalePaint, SkCanvas::kInitWithPrevious_SaveLayerFlag); + canvas->saveLayer(saveLayerRec); + canvas->restore(); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_049.cpp b/docs/examples/Canvas_049.cpp new file mode 100644 index 0000000000..8c7cf65a64 --- /dev/null +++ b/docs/examples/Canvas_049.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=6a614faa0fbcf19958b5559c19b02d0f +REG_FIDDLE(Canvas_049, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + canvas->rotate(10); + SkPaint paint; + paint.setAntiAlias(true); + for (auto alias: { false, true } ) { + canvas->save(); + canvas->clipRect(SkRect::MakeWH(90, 80), SkClipOp::kIntersect, alias); + canvas->drawCircle(100, 60, 60, paint); + canvas->restore(); + canvas->translate(80, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_050.cpp b/docs/examples/Canvas_050.cpp new file mode 100644 index 0000000000..ce57d547ad --- /dev/null +++ b/docs/examples/Canvas_050.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=13bbc5fa5597a6cd4d704b419dbc66d9 +REG_FIDDLE(Canvas_050, 280, 192, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + for (SkClipOp op: { SkClipOp::kIntersect, SkClipOp::kDifference } ) { + canvas->save(); + canvas->clipRect(SkRect::MakeWH(90, 120), op, false); + canvas->drawCircle(100, 100, 60, paint); + canvas->restore(); + canvas->translate(80, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_051.cpp b/docs/examples/Canvas_051.cpp new file mode 100644 index 0000000000..5976312cc0 --- /dev/null +++ b/docs/examples/Canvas_051.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=1d4e0632c97e42692775d834fe10aa99 +REG_FIDDLE(Canvas_051, 256, 133, false, 0) { +void draw(SkCanvas* canvas) { + canvas->clear(SK_ColorWHITE); + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(0x8055aaff); + SkRect clipRect = { 0, 0, 87.4f, 87.4f }; + for (auto alias: { false, true } ) { + canvas->save(); + canvas->clipRect(clipRect, SkClipOp::kIntersect, alias); + canvas->drawCircle(67, 67, 60, paint); + canvas->restore(); + canvas->save(); + canvas->clipRect(clipRect, SkClipOp::kDifference, alias); + canvas->drawCircle(67, 67, 60, paint); + canvas->restore(); + canvas->translate(120, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_052.cpp b/docs/examples/Canvas_052.cpp new file mode 100644 index 0000000000..f35a4e6b1b --- /dev/null +++ b/docs/examples/Canvas_052.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=182ef48ab5e04ba3578496fda8d9fa36 +REG_FIDDLE(Canvas_052, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + canvas->clear(SK_ColorWHITE); + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(0x8055aaff); + SkRRect oval; + oval.setOval({10, 20, 90, 100}); + canvas->clipRRect(oval, SkClipOp::kIntersect, true); + canvas->drawCircle(70, 100, 60, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_053.cpp b/docs/examples/Canvas_053.cpp new file mode 100644 index 0000000000..450172b895 --- /dev/null +++ b/docs/examples/Canvas_053.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=ef6ae2eaae6761130ce38065d0364abd +REG_FIDDLE(Canvas_053, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(0x8055aaff); + auto oval = SkRRect::MakeOval({10, 20, 90, 100}); + canvas->clipRRect(oval, SkClipOp::kIntersect); + canvas->drawCircle(70, 100, 60, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_054.cpp b/docs/examples/Canvas_054.cpp new file mode 100644 index 0000000000..e7e1d5054c --- /dev/null +++ b/docs/examples/Canvas_054.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=f583114580b2176fe3e75b0994476a84 +REG_FIDDLE(Canvas_054, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + auto oval = SkRRect::MakeRectXY({10, 20, 90, 100}, 9, 13); + canvas->clipRRect(oval, true); + canvas->drawCircle(70, 100, 60, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_055.cpp b/docs/examples/Canvas_055.cpp new file mode 100644 index 0000000000..ac1a3f403c --- /dev/null +++ b/docs/examples/Canvas_055.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=ee47ae6b813bfaa55e1a7b7c053ed60d +REG_FIDDLE(Canvas_055, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPath path; + path.addRect({20, 30, 100, 110}); + path.setFillType(SkPath::kInverseWinding_FillType); + canvas->save(); + canvas->clipPath(path, SkClipOp::kDifference, false); + canvas->drawCircle(70, 100, 60, paint); + canvas->restore(); + canvas->translate(100, 100); + path.setFillType(SkPath::kWinding_FillType); + canvas->clipPath(path, SkClipOp::kIntersect, false); + canvas->drawCircle(70, 100, 60, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_056.cpp b/docs/examples/Canvas_056.cpp new file mode 100644 index 0000000000..432de664ab --- /dev/null +++ b/docs/examples/Canvas_056.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=7856755c1bf8431c286c734b353345ad +REG_FIDDLE(Canvas_056, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPath path; + path.addRect({20, 15, 100, 95}); + path.addRect({50, 65, 130, 135}); + path.setFillType(SkPath::kWinding_FillType); + canvas->save(); + canvas->clipPath(path, SkClipOp::kIntersect); + canvas->drawCircle(70, 85, 60, paint); + canvas->restore(); + canvas->translate(100, 100); + path.setFillType(SkPath::kEvenOdd_FillType); + canvas->clipPath(path, SkClipOp::kIntersect); + canvas->drawCircle(70, 85, 60, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_057.cpp b/docs/examples/Canvas_057.cpp new file mode 100644 index 0000000000..ade1fdaf07 --- /dev/null +++ b/docs/examples/Canvas_057.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=187a7ae77a8176e417181411988534b6 +REG_FIDDLE(Canvas_057, 256, 212, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPath path; + SkPoint poly[] = {{20, 20}, { 80, 20}, { 80, 80}, {40, 80}, + {40, 40}, {100, 40}, {100, 100}, {20, 100}}; + path.addPoly(poly, SK_ARRAY_COUNT(poly), true); + path.setFillType(SkPath::kWinding_FillType); + canvas->save(); + canvas->clipPath(path, SkClipOp::kIntersect); + canvas->drawCircle(50, 50, 45, paint); + canvas->restore(); + canvas->translate(100, 100); + path.setFillType(SkPath::kEvenOdd_FillType); + canvas->clipPath(path, SkClipOp::kIntersect); + canvas->drawCircle(50, 50, 45, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_058.cpp b/docs/examples/Canvas_058.cpp new file mode 100644 index 0000000000..15d7f928e4 --- /dev/null +++ b/docs/examples/Canvas_058.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=7bb57c0e456c5fda2c2cca4abb68b19e +REG_FIDDLE(Canvas_058, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkIRect iRect = {30, 40, 120, 130 }; + SkRegion region(iRect); + canvas->rotate(10); + canvas->save(); + canvas->clipRegion(region, SkClipOp::kIntersect); + canvas->drawCircle(50, 50, 45, paint); + canvas->restore(); + canvas->translate(100, 100); + canvas->clipRect(SkRect::Make(iRect), SkClipOp::kIntersect); + canvas->drawCircle(50, 50, 45, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_059.cpp b/docs/examples/Canvas_059.cpp new file mode 100644 index 0000000000..1a8c6062a5 --- /dev/null +++ b/docs/examples/Canvas_059.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=cfe4016241074477809dd45435be9cf4 +REG_FIDDLE(Canvas_059, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect testRect = {30, 30, 120, 129 }; + SkRect clipRect = {30, 130, 120, 230 }; + canvas->save(); + canvas->clipRect(clipRect); + SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); + canvas->restore(); + canvas->rotate(10); + canvas->clipRect(clipRect); + SkDebugf("quickReject %s\n", canvas->quickReject(testRect) ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_060.cpp b/docs/examples/Canvas_060.cpp new file mode 100644 index 0000000000..6d682ef98a --- /dev/null +++ b/docs/examples/Canvas_060.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=56dcd14f943aea6f7d7aafe0de7e6c25 +REG_FIDDLE(Canvas_060, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint testPoints[] = {{30, 30}, {120, 30}, {120, 129} }; + SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; + SkPath testPath, clipPath; + testPath.addPoly(testPoints, SK_ARRAY_COUNT(testPoints), true); + clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); + canvas->save(); + canvas->clipPath(clipPath); + SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); + canvas->restore(); + canvas->rotate(10); + canvas->clipPath(clipPath); + SkDebugf("quickReject %s\n", canvas->quickReject(testPath) ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_061.cpp b/docs/examples/Canvas_061.cpp new file mode 100644 index 0000000000..f78d5308b0 --- /dev/null +++ b/docs/examples/Canvas_061.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=7f60cb030d3f9b2473adbe3e34b19d91 +REG_FIDDLE(Canvas_061, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkCanvas local(256, 256); + canvas = &local; + SkRect bounds = canvas->getLocalClipBounds(); + SkDebugf("left:%g top:%g right:%g bottom:%g\n", + bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); + SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; + SkPath clipPath; + clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); + canvas->clipPath(clipPath); + bounds = canvas->getLocalClipBounds(); + SkDebugf("left:%g top:%g right:%g bottom:%g\n", + bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); + canvas->scale(2, 2); + bounds = canvas->getLocalClipBounds(); + SkDebugf("left:%g top:%g right:%g bottom:%g\n", + bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_062.cpp b/docs/examples/Canvas_062.cpp new file mode 100644 index 0000000000..76a94c0897 --- /dev/null +++ b/docs/examples/Canvas_062.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=85496614e90c66b020f8a70db8d06f4a +REG_FIDDLE(Canvas_062, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkCanvas local(256, 256); + canvas = &local; + SkRect bounds; + SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) + ? "false" : "true"); + SkPath path; + canvas->clipPath(path); + SkDebugf("local bounds empty = %s\n", canvas->getLocalClipBounds(&bounds) + ? "false" : "true"); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_063.cpp b/docs/examples/Canvas_063.cpp new file mode 100644 index 0000000000..8968963537 --- /dev/null +++ b/docs/examples/Canvas_063.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=556832ac5711af662a98c21c547185e9 +REG_FIDDLE(Canvas_063, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkCanvas device(256, 256); + canvas = &device; + SkIRect bounds = canvas->getDeviceClipBounds(); + SkDebugf("left:%d top:%d right:%d bottom:%d\n", + bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); + SkPoint clipPoints[] = {{30, 130}, {120, 130}, {120, 230} }; + SkPath clipPath; + clipPath.addPoly(clipPoints, SK_ARRAY_COUNT(clipPoints), true); + canvas->save(); + canvas->clipPath(clipPath); + bounds = canvas->getDeviceClipBounds(); + SkDebugf("left:%d top:%d right:%d bottom:%d\n", + bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); + canvas->restore(); + canvas->scale(1.f/2, 1.f/2); + canvas->clipPath(clipPath); + bounds = canvas->getDeviceClipBounds(); + SkDebugf("left:%d top:%d right:%d bottom:%d\n", + bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_064.cpp b/docs/examples/Canvas_064.cpp new file mode 100644 index 0000000000..4a0e6258e6 --- /dev/null +++ b/docs/examples/Canvas_064.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=6abb99f849a1f0e33e1dedc00d1c4f7a +REG_FIDDLE(Canvas_064, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect bounds; + SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) + ? "false" : "true"); + SkPath path; + canvas->clipPath(path); + SkDebugf("device bounds empty = %s\n", canvas->getDeviceClipBounds(&bounds) + ? "false" : "true"); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_065.cpp b/docs/examples/Canvas_065.cpp new file mode 100644 index 0000000000..81cdb27f76 --- /dev/null +++ b/docs/examples/Canvas_065.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=9cf94fead1e6b17d836c704b4eac269a +REG_FIDDLE(Canvas_065, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + canvas->drawColor(SK_ColorRED); + canvas->clipRect(SkRect::MakeWH(150, 150)); + canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00), SkBlendMode::kPlus); + canvas->clipRect(SkRect::MakeWH(75, 75)); + canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF), SkBlendMode::kPlus); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_066.cpp b/docs/examples/Canvas_066.cpp new file mode 100644 index 0000000000..fe465c55cb --- /dev/null +++ b/docs/examples/Canvas_066.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=8c4499e322f10153dcd9b0b9806233b9 +REG_FIDDLE(Canvas_066, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + canvas->save(); + canvas->clipRect(SkRect::MakeWH(256, 128)); + canvas->clear(SkColorSetARGB(0x80, 0xFF, 0x00, 0x00)); + canvas->restore(); + canvas->save(); + canvas->clipRect(SkRect::MakeWH(150, 192)); + canvas->clear(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00)); + canvas->restore(); + canvas->clipRect(SkRect::MakeWH(75, 256)); + canvas->clear(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF)); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_067.cpp b/docs/examples/Canvas_067.cpp new file mode 100644 index 0000000000..fd58d3b9a6 --- /dev/null +++ b/docs/examples/Canvas_067.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=1cd076b9b1a7c976cdca72b93c4f42dd +REG_FIDDLE(Canvas_067, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; + SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeSweep(256, 256, colors, pos, SK_ARRAY_COUNT(colors))); + canvas->drawPaint(paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_068.cpp b/docs/examples/Canvas_068.cpp new file mode 100644 index 0000000000..94af00431e --- /dev/null +++ b/docs/examples/Canvas_068.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=292b4b2008961b6f612434d3121fc4ce +REG_FIDDLE(Canvas_068, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(10); + SkPoint points[] = {{64, 32}, {96, 96}, {32, 96}}; + canvas->drawPoints(SkCanvas::kPoints_PointMode, 3, points, paint); + canvas->translate(128, 0); + canvas->drawPoints(SkCanvas::kLines_PointMode, 3, points, paint); + canvas->translate(0, 128); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, paint); + SkPath path; + path.addPoly(points, 3, false); + canvas->translate(-128, 0); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_069.cpp b/docs/examples/Canvas_069.cpp new file mode 100644 index 0000000000..ff1a3ecf21 --- /dev/null +++ b/docs/examples/Canvas_069.cpp @@ -0,0 +1,32 @@ +// 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 "fiddle/examples.h" +// HASH=635d54b4716e226e93dfbc21ad40e77d +REG_FIDDLE(Canvas_069, 256, 200, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(10); + paint.setColor(0x80349a45); + const SkPoint points[] = {{32, 16}, {48, 48}, {16, 32}}; + const SkPaint::Join join[] = { SkPaint::kRound_Join, + SkPaint::kMiter_Join, + SkPaint::kBevel_Join }; + int joinIndex = 0; + SkPath path; + path.addPoly(points, 3, false); + for (const auto cap : { SkPaint::kRound_Cap, SkPaint::kSquare_Cap, SkPaint::kButt_Cap } ) { + paint.setStrokeCap(cap); + paint.setStrokeJoin(join[joinIndex++]); + for (const auto mode : { SkCanvas::kPoints_PointMode, + SkCanvas::kLines_PointMode, + SkCanvas::kPolygon_PointMode } ) { + canvas->drawPoints(mode, 3, points, paint); + canvas->translate(64, 0); + } + canvas->drawPath(path, paint); + canvas->translate(-192, 64); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_070.cpp b/docs/examples/Canvas_070.cpp new file mode 100644 index 0000000000..cbf6d9a3b5 --- /dev/null +++ b/docs/examples/Canvas_070.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=3476b553e7b547b604a3f6969f02d933 +REG_FIDDLE(Canvas_070, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(0x80349a45); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(100); + paint.setStrokeCap(SkPaint::kRound_Cap); + canvas->scale(1, 1.2f); + canvas->drawPoint(64, 96, paint); + canvas->scale(.6f, .8f); + paint.setColor(SK_ColorWHITE); + canvas->drawPoint(106, 120, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_071.cpp b/docs/examples/Canvas_071.cpp new file mode 100644 index 0000000000..c19018ce96 --- /dev/null +++ b/docs/examples/Canvas_071.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=1a0a839061c69d870acca2bcfbdf1a41 +REG_FIDDLE(Canvas_071, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(0x80349a45); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(100); + paint.setStrokeCap(SkPaint::kSquare_Cap); + canvas->scale(1, 1.2f); + canvas->drawPoint({64, 96}, paint); + canvas->scale(.6f, .8f); + paint.setColor(SK_ColorWHITE); + canvas->drawPoint(106, 120, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_072.cpp b/docs/examples/Canvas_072.cpp new file mode 100644 index 0000000000..fcf1b0ebb0 --- /dev/null +++ b/docs/examples/Canvas_072.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=d10ee4a265f278d02afe11ad889b293b +REG_FIDDLE(Canvas_072, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(0xFF9a67be); + paint.setStrokeWidth(20); + canvas->skew(1, 0); + canvas->drawLine(32, 96, 32, 160, paint); + canvas->skew(-2, 0); + canvas->drawLine(288, 96, 288, 160, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_073.cpp b/docs/examples/Canvas_073.cpp new file mode 100644 index 0000000000..8a0af8f77e --- /dev/null +++ b/docs/examples/Canvas_073.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=f8525816cb596dde1a3855446792c8e0 +REG_FIDDLE(Canvas_073, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(0xFF9a67be); + paint.setStrokeWidth(20); + canvas->skew(1, 0); + canvas->drawLine({32, 96}, {32, 160}, paint); + canvas->skew(-2, 0); + canvas->drawLine({288, 96}, {288, 160}, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_074.cpp b/docs/examples/Canvas_074.cpp new file mode 100644 index 0000000000..1b488bc7a2 --- /dev/null +++ b/docs/examples/Canvas_074.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=871b0da9b4a23de11ae7a772ce14aed3 +REG_FIDDLE(Canvas_074, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPoint rectPts[] = { {64, 48}, {192, 160} }; + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + paint.setStrokeJoin(SkPaint::kRound_Join); + SkMatrix rotator; + rotator.setRotate(30, 128, 128); + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { + paint.setColor(color); + SkRect rect; + rect.set(rectPts[0], rectPts[1]); + canvas->drawRect(rect, paint); + rotator.mapPoints(rectPts, 2); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_075.cpp b/docs/examples/Canvas_075.cpp new file mode 100644 index 0000000000..bc4a4d049d --- /dev/null +++ b/docs/examples/Canvas_075.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=d3d8ca584134560750b1efa4a4c6e138 +REG_FIDDLE(Canvas_075, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 64, 48, 192, 160 }; + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + paint.setStrokeJoin(SkPaint::kRound_Join); + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorMAGENTA } ) { + paint.setColor(color); + canvas->drawIRect(rect, paint); + canvas->rotate(30, 128, 128); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_076.cpp b/docs/examples/Canvas_076.cpp new file mode 100644 index 0000000000..37e8cb683f --- /dev/null +++ b/docs/examples/Canvas_076.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=80309e0deca0f8add616cec7bec634ca +REG_FIDDLE(Canvas_076, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + region.op( 10, 10, 50, 50, SkRegion::kUnion_Op); + region.op( 10, 50, 90, 90, SkRegion::kUnion_Op); + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + paint.setStrokeJoin(SkPaint::kRound_Join); + canvas->drawRegion(region, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_077.cpp b/docs/examples/Canvas_077.cpp new file mode 100644 index 0000000000..f2bf141f27 --- /dev/null +++ b/docs/examples/Canvas_077.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=8b6b86f8a022811cd29a9c6ab771df12 +REG_FIDDLE(Canvas_077, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + canvas->clear(0xFF3f5f9f); + SkColor kColor1 = SkColorSetARGB(0xff, 0xff, 0x7f, 0); + SkColor g1Colors[] = { kColor1, SkColorSetA(kColor1, 0x20) }; + SkPoint g1Points[] = { { 0, 0 }, { 0, 100 } }; + SkScalar pos[] = { 0.2f, 1.0f }; + SkRect bounds = SkRect::MakeWH(80, 70); + SkPaint paint; + paint.setAntiAlias(true); + paint.setShader(SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors), + SkShader::kClamp_TileMode)); + canvas->drawOval(bounds , paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_078.cpp b/docs/examples/Canvas_078.cpp new file mode 100644 index 0000000000..8b891971a8 --- /dev/null +++ b/docs/examples/Canvas_078.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=90fed1bb11efb43aada94113338c63d8 +REG_FIDDLE(Canvas_078, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkRect outer = {30, 40, 210, 220}; + SkRect radii = {30, 50, 70, 90 }; + SkRRect rRect; + rRect.setNinePatch(outer, radii.fLeft, radii.fTop, radii.fRight, radii.fBottom); + canvas->drawRRect(rRect, paint); + paint.setColor(SK_ColorWHITE); + canvas->drawLine(outer.fLeft + radii.fLeft, outer.fTop, + outer.fLeft + radii.fLeft, outer.fBottom, paint); + canvas->drawLine(outer.fRight - radii.fRight, outer.fTop, + outer.fRight - radii.fRight, outer.fBottom, paint); + canvas->drawLine(outer.fLeft, outer.fTop + radii.fTop, + outer.fRight, outer.fTop + radii.fTop, paint); + canvas->drawLine(outer.fLeft, outer.fBottom - radii.fBottom, + outer.fRight, outer.fBottom - radii.fBottom, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_079.cpp b/docs/examples/Canvas_079.cpp new file mode 100644 index 0000000000..54e5ac279e --- /dev/null +++ b/docs/examples/Canvas_079.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=02e33141f13da2f19aef7feb7117b541 +REG_FIDDLE(Canvas_079, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); + SkRRect inner = SkRRect::MakeOval({60, 70, 170, 160}); + SkPaint paint; + canvas->drawDRRect(outer, inner, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_080.cpp b/docs/examples/Canvas_080.cpp new file mode 100644 index 0000000000..9f8a904cd2 --- /dev/null +++ b/docs/examples/Canvas_080.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=30823cb4edf884d330285ea161664931 +REG_FIDDLE(Canvas_080, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect outer = SkRRect::MakeRect({20, 40, 210, 200}); + SkRRect inner = SkRRect::MakeRectXY({60, 70, 170, 160}, 10, 10); + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + paint.setStrokeJoin(SkPaint::kRound_Join); + canvas->drawDRRect(outer, inner, paint); + paint.setStrokeWidth(1); + paint.setColor(SK_ColorWHITE); + canvas->drawDRRect(outer, inner, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_081.cpp b/docs/examples/Canvas_081.cpp new file mode 100644 index 0000000000..b966a809f3 --- /dev/null +++ b/docs/examples/Canvas_081.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=841229e25ca9dfb68bd0dc4dfff356eb +REG_FIDDLE(Canvas_081, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawCircle(128, 128, 90, paint); + paint.setColor(SK_ColorWHITE); + canvas->drawCircle(86, 86, 20, paint); + canvas->drawCircle(160, 76, 20, paint); + canvas->drawCircle(140, 150, 35, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_082.cpp b/docs/examples/Canvas_082.cpp new file mode 100644 index 0000000000..f5709ff151 --- /dev/null +++ b/docs/examples/Canvas_082.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=9303ffae45ddd0b0a1f93d816a1762f4 +REG_FIDDLE(Canvas_082, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawCircle(128, 128, 90, paint); + paint.setColor(SK_ColorWHITE); + canvas->drawCircle({86, 86}, 20, paint); + canvas->drawCircle({160, 76}, 20, paint); + canvas->drawCircle({140, 150}, 35, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_083.cpp b/docs/examples/Canvas_083.cpp new file mode 100644 index 0000000000..5dae8b9dc6 --- /dev/null +++ b/docs/examples/Canvas_083.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=11f0fbe7b30d776913c2e7c92c02ff57 +REG_FIDDLE(Canvas_083, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkRect oval = { 4, 4, 60, 60}; + for (auto useCenter : { false, true } ) { + for (auto style : { SkPaint::kFill_Style, SkPaint::kStroke_Style } ) { + paint.setStyle(style); + for (auto degrees : { 45, 90, 180, 360} ) { + canvas->drawArc(oval, 0, degrees , useCenter, paint); + canvas->translate(64, 0); + } + canvas->translate(-256, 64); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_084.cpp b/docs/examples/Canvas_084.cpp new file mode 100644 index 0000000000..b815006c0d --- /dev/null +++ b/docs/examples/Canvas_084.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=e91dbe45974489b8962c815017b7914f +REG_FIDDLE(Canvas_084, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(4); + SkRect oval = { 4, 4, 60, 60}; + float intervals[] = { 5, 5 }; + paint.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); + for (auto degrees : { 270, 360, 540, 720 } ) { + canvas->drawArc(oval, 0, degrees, false, paint); + canvas->translate(64, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_085.cpp b/docs/examples/Canvas_085.cpp new file mode 100644 index 0000000000..1b664c5153 --- /dev/null +++ b/docs/examples/Canvas_085.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=199fe818c09026c114e165bff166a39f +REG_FIDDLE(Canvas_085, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkVector radii[] = { {0, 20}, {10, 10}, {10, 20}, {10, 40} }; + SkPaint paint; + paint.setStrokeWidth(15); + paint.setStrokeJoin(SkPaint::kRound_Join); + paint.setAntiAlias(true); + for (auto style : { SkPaint::kStroke_Style, SkPaint::kFill_Style } ) { + paint.setStyle(style ); + for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) { + canvas->drawRoundRect({10, 10, 60, 40}, radii[i].fX, radii[i].fY, paint); + canvas->translate(0, 60); + } + canvas->translate(80, -240); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_086.cpp b/docs/examples/Canvas_086.cpp new file mode 100644 index 0000000000..3e4f97dc4a --- /dev/null +++ b/docs/examples/Canvas_086.cpp @@ -0,0 +1,38 @@ +// 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 "fiddle/examples.h" +// HASH=fe2294131f422b8d6752f6a880f98ad9 +REG_FIDDLE(Canvas_086, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo(20, 20); + path.quadTo(60, 20, 60, 60); + path.close(); + path.moveTo(60, 20); + path.quadTo(60, 60, 20, 60); + SkPaint paint; + paint.setStrokeWidth(10); + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + for (auto join: { SkPaint::kBevel_Join, SkPaint::kRound_Join, SkPaint::kMiter_Join } ) { + paint.setStrokeJoin(join); + for (auto cap: { SkPaint::kButt_Cap, SkPaint::kSquare_Cap, SkPaint::kRound_Cap } ) { + paint.setStrokeCap(cap); + canvas->drawPath(path, paint); + canvas->translate(80, 0); + } + canvas->translate(-240, 60); + } + paint.setStyle(SkPaint::kFill_Style); + for (auto fill : { SkPath::kWinding_FillType, + SkPath::kEvenOdd_FillType, + SkPath::kInverseWinding_FillType } ) { + path.setFillType(fill); + canvas->save(); + canvas->clipRect({0, 10, 80, 70}); + canvas->drawPath(path, paint); + canvas->restore(); + canvas->translate(80, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_087.cpp b/docs/examples/Canvas_087.cpp new file mode 100644 index 0000000000..3af5ae403a --- /dev/null +++ b/docs/examples/Canvas_087.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=185746dc0faa6f1df30c4afe098646ff +REG_FIDDLE(Canvas_087, 256, 64, false, 4) { +void draw(SkCanvas* canvas) { + // sk_sp image; + SkImage* imagePtr = image.get(); + canvas->drawImage(imagePtr, 0, 0); + SkPaint paint; + canvas->drawImage(imagePtr, 80, 0, &paint); + paint.setAlpha(0x80); + canvas->drawImage(imagePtr, 160, 0, &paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_088.cpp b/docs/examples/Canvas_088.cpp new file mode 100644 index 0000000000..bc8f3b2d3d --- /dev/null +++ b/docs/examples/Canvas_088.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=a4e877e891b1be5faa2b7fd07f673a10 +REG_FIDDLE(Canvas_088, 256, 64, false, 4) { +void draw(SkCanvas* canvas) { + // sk_sp image; + canvas->drawImage(image, 0, 0); + SkPaint paint; + canvas->drawImage(image, 80, 0, &paint); + paint.setAlpha(0x80); + canvas->drawImage(image, 160, 0, &paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_089.cpp b/docs/examples/Canvas_089.cpp new file mode 100644 index 0000000000..9a70556e0f --- /dev/null +++ b/docs/examples/Canvas_089.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=5df49d1f4da37275a1f10ef7f1a749f0 +REG_FIDDLE(Canvas_089, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap redBorder; + redBorder.allocPixels(SkImageInfo::MakeN32Premul(4, 4)); + SkCanvas checkRed(redBorder); + checkRed.clear(SK_ColorRED); + uint32_t checkers[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, + { SK_ColorWHITE, SK_ColorBLACK } }; + checkRed.writePixels( + SkImageInfo::MakeN32Premul(2, 2), (void*) checkers, sizeof(checkers[0]), 1, 1); + canvas->scale(16, 16); + canvas->drawBitmap(redBorder, 0, 0, nullptr); + canvas->resetMatrix(); + sk_sp image = SkImage::MakeFromBitmap(redBorder); + SkPaint lowPaint; + lowPaint.setFilterQuality(kLow_SkFilterQuality); + for (auto constraint : { SkCanvas::kStrict_SrcRectConstraint, + SkCanvas::kFast_SrcRectConstraint } ) { + canvas->translate(80, 0); + canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), + SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_090.cpp b/docs/examples/Canvas_090.cpp new file mode 100644 index 0000000000..ffa1f55e48 --- /dev/null +++ b/docs/examples/Canvas_090.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=bfd18e9cac896cdf94c9f154ccf94be8 +REG_FIDDLE(Canvas_090, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint32_t pixels[][4] = { + { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 }, + { 0xFFFF0000, 0xFF000000, 0xFFFFFFFF, 0xFFFF0000 }, + { 0xFFFF0000, 0xFFFFFFFF, 0xFF000000, 0xFFFF0000 }, + { 0xFFFF0000, 0xFFFF0000, 0xFFFF0000, 0xFFFF0000 } }; + SkBitmap redBorder; + redBorder.installPixels(SkImageInfo::MakeN32Premul(4, 4), + (void*) pixels, sizeof(pixels[0])); + sk_sp image = SkImage::MakeFromBitmap(redBorder); + SkPaint lowPaint; + for (auto constraint : { + SkCanvas::kFast_SrcRectConstraint, + SkCanvas::kStrict_SrcRectConstraint, + SkCanvas::kFast_SrcRectConstraint } ) { + canvas->drawImageRect(image.get(), SkRect::MakeLTRB(1, 1, 3, 3), + SkRect::MakeLTRB(16, 16, 48, 48), &lowPaint, constraint); + lowPaint.setFilterQuality(kLow_SkFilterQuality); + canvas->translate(80, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_091.cpp b/docs/examples/Canvas_091.cpp new file mode 100644 index 0000000000..f921d52556 --- /dev/null +++ b/docs/examples/Canvas_091.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=7f92cd5c9b9f4b1ac3cd933b08037bfe +REG_FIDDLE(Canvas_091, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + // sk_sp image; + for (auto i : { 1, 2, 4, 8 } ) { + canvas->drawImageRect(image.get(), SkIRect::MakeLTRB(0, 0, 100, 100), + SkRect::MakeXYWH(i * 20, i * 20, i * 20, i * 20), nullptr); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_092.cpp b/docs/examples/Canvas_092.cpp new file mode 100644 index 0000000000..b5d24c811d --- /dev/null +++ b/docs/examples/Canvas_092.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=3cf8fb639fef99993cafc064d550c739 +REG_FIDDLE(Canvas_092, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + // sk_sp image; + for (auto i : { 20, 40, 80, 160 } ) { + canvas->drawImageRect(image.get(), SkRect::MakeXYWH(i, i, i, i), nullptr); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_093.cpp b/docs/examples/Canvas_093.cpp new file mode 100644 index 0000000000..7e388c81c5 --- /dev/null +++ b/docs/examples/Canvas_093.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=d4b35a9d24c32c042bd1f529b8de3c0d +REG_FIDDLE(Canvas_093, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint32_t pixels[][2] = { { SK_ColorBLACK, SK_ColorWHITE }, + { SK_ColorWHITE, SK_ColorBLACK } }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), + (void*) pixels, sizeof(pixels[0])); + sk_sp image = SkImage::MakeFromBitmap(bitmap); + SkPaint paint; + canvas->scale(4, 4); + for (auto alpha : { 50, 100, 150, 255 } ) { + paint.setAlpha(alpha); + canvas->drawImageRect(image, SkRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); + canvas->translate(8, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_094.cpp b/docs/examples/Canvas_094.cpp new file mode 100644 index 0000000000..2c25302dbb --- /dev/null +++ b/docs/examples/Canvas_094.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=d307e7e1237f39fb54d80723e5449857 +REG_FIDDLE(Canvas_094, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint32_t pixels[][2] = { { 0x00000000, 0x55555555}, + { 0xAAAAAAAA, 0xFFFFFFFF} }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), + (void*) pixels, sizeof(pixels[0])); + sk_sp image = SkImage::MakeFromBitmap(bitmap); + SkPaint paint; + canvas->scale(4, 4); + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { + paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); + canvas->drawImageRect(image, SkIRect::MakeWH(2, 2), SkRect::MakeWH(8, 8), &paint); + canvas->translate(8, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_095.cpp b/docs/examples/Canvas_095.cpp new file mode 100644 index 0000000000..4f5a475b6a --- /dev/null +++ b/docs/examples/Canvas_095.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=3a47ef94cb70144455f80333d8653e6c +REG_FIDDLE(Canvas_095, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, + { 0xAAAA0000, 0xFFFF0000} }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), + (void*) pixels, sizeof(pixels[0])); + sk_sp image = SkImage::MakeFromBitmap(bitmap); + SkPaint paint; + canvas->scale(4, 4); + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { + paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); + canvas->drawImageRect(image, SkRect::MakeWH(8, 8), &paint); + canvas->translate(8, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_096.cpp b/docs/examples/Canvas_096.cpp new file mode 100644 index 0000000000..6b8f02f27b --- /dev/null +++ b/docs/examples/Canvas_096.cpp @@ -0,0 +1,31 @@ +// 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 "fiddle/examples.h" +// HASH=4f153cf1d0dbe1a95acf5badeec14dae +REG_FIDDLE(Canvas_096, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkIRect center = { 20, 10, 50, 40 }; + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); + SkCanvas bitCanvas(bitmap); + SkPaint paint; + SkColor gray = 0xFF000000; + int left = 0; + for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { + int top = 0; + for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { + paint.setColor(gray); + bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); + gray += 0x001f1f1f; + top = bottom; + } + left = right; + } + sk_sp image = SkImage::MakeFromBitmap(bitmap); + SkImage* imagePtr = image.get(); + for (auto dest: { 20, 30, 40, 60, 90 } ) { + canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); + canvas->translate(dest + 4, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_097.cpp b/docs/examples/Canvas_097.cpp new file mode 100644 index 0000000000..3aa922cf1e --- /dev/null +++ b/docs/examples/Canvas_097.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=d597d9af8d17fd93e634dd12017058e2 +REG_FIDDLE(Canvas_097, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkIRect center = { 20, 10, 50, 40 }; + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); + SkCanvas bitCanvas(bitmap); + SkPaint paint; + SkColor gray = 0xFF000000; + int left = 0; + for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { + int top = 0; + for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { + paint.setColor(gray); + bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); + gray += 0x001f1f1f; + top = bottom; + } + left = right; + } + sk_sp image = SkImage::MakeFromBitmap(bitmap); + for (auto dest: { 20, 30, 40, 60, 90 } ) { + canvas->drawImageNine(image, center, SkRect::MakeWH(dest, 110 - dest), nullptr); + canvas->translate(dest + 4, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_098.cpp b/docs/examples/Canvas_098.cpp new file mode 100644 index 0000000000..c119af68e3 --- /dev/null +++ b/docs/examples/Canvas_098.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=4a521be1f850058541e136a808c65e78 +REG_FIDDLE(Canvas_098, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, + { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, + { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, + { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, + { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, + { 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0x00}, + { 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0xFF} }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeA8(8, 8), + (void*) pixels, sizeof(pixels[0])); + SkPaint paint; + canvas->scale(4, 4); + for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { + paint.setColor(color); + canvas->drawBitmap(bitmap, 0, 0, &paint); + canvas->translate(12, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_099.cpp b/docs/examples/Canvas_099.cpp new file mode 100644 index 0000000000..ad6db0175b --- /dev/null +++ b/docs/examples/Canvas_099.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=7d04932f2a259cc70d6e45cd25a6feb6 +REG_FIDDLE(Canvas_099, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t pixels[][8] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, + { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, + { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, + { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, + { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, + { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, + { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeA8(8, 8), + (void*) pixels, sizeof(pixels[0])); + SkPaint paint; + paint.setMaskFilter(SkMaskFilter::MakeBlur(kSolid_SkBlurStyle, 6)); + for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { + paint.setColor(color); + canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); + canvas->translate(48, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_100.cpp b/docs/examples/Canvas_100.cpp new file mode 100644 index 0000000000..0f5ecb0321 --- /dev/null +++ b/docs/examples/Canvas_100.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=0a3c6d2459566e58cee7d4910655ee21 +REG_FIDDLE(Canvas_100, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t pixels[][8] = { { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, + { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, + { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, + { 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0xFF}, + { 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF}, + { 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF}, + { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, + { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00} }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeA8(8, 8), + (void*) pixels, sizeof(pixels[0])); + SkPaint paint; + paint.setFilterQuality(kHigh_SkFilterQuality); + for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00, 0xFF7f007f} ) { + paint.setColor(color); + canvas->drawBitmapRect(bitmap, SkIRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); + canvas->translate(48.25f, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_101.cpp b/docs/examples/Canvas_101.cpp new file mode 100644 index 0000000000..88b2e587dd --- /dev/null +++ b/docs/examples/Canvas_101.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=bdbeac3c97f60a63987b1cc8e1f1e91e +REG_FIDDLE(Canvas_101, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint32_t pixels[][2] = { { 0x00000000, 0x55550000}, + { 0xAAAA0000, 0xFFFF0000} }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeN32Premul(2, 2), + (void*) pixels, sizeof(pixels[0])); + SkPaint paint; + canvas->scale(4, 4); + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { + paint.setColorFilter(SkColorFilter::MakeModeFilter(color, SkBlendMode::kPlus)); + canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), &paint); + canvas->translate(8, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_102.cpp b/docs/examples/Canvas_102.cpp new file mode 100644 index 0000000000..85708526fc --- /dev/null +++ b/docs/examples/Canvas_102.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=e99e7be0d8f67dfacbecf85df585433d +REG_FIDDLE(Canvas_102, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkIRect center = { 20, 10, 50, 40 }; + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); + SkCanvas bitCanvas(bitmap); + SkPaint paint; + SkColor gray = 0xFF000000; + int left = 0; + for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { + int top = 0; + for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { + paint.setColor(gray); + bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); + gray += 0x001f1f1f; + top = bottom; + } + left = right; + } + for (auto dest: { 20, 30, 40, 60, 90 } ) { + canvas->drawBitmapNine(bitmap, center, SkRect::MakeWH(dest, 110 - dest), nullptr); + canvas->translate(dest + 4, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_103.cpp b/docs/examples/Canvas_103.cpp new file mode 100644 index 0000000000..79ab1a9122 --- /dev/null +++ b/docs/examples/Canvas_103.cpp @@ -0,0 +1,37 @@ +// 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 "fiddle/examples.h" +// HASH=c5bfa944e17ba4a4400dc799f032069c +REG_FIDDLE(Canvas_103, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkIRect center = { 20, 10, 50, 40 }; + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); + SkCanvas bitCanvas(bitmap); + SkPaint paint; + SkColor gray = 0xFF000000; + int left = 0; + for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { + int top = 0; + for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { + paint.setColor(gray); + bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); + gray += 0x001f1f1f; + top = bottom; + } + left = right; + } + const int xDivs[] = { center.fLeft, center.fRight }; + const int yDivs[] = { center.fTop, center.fBottom }; + SkCanvas::Lattice::RectType fillTypes[3][3]; + memset(fillTypes, 0, sizeof(fillTypes)); + fillTypes[1][1] = SkCanvas::Lattice::kTransparent; + SkColor dummy[9]; // temporary pending bug fix + SkCanvas::Lattice lattice = { xDivs, yDivs, fillTypes[0], SK_ARRAY_COUNT(xDivs), + SK_ARRAY_COUNT(yDivs), nullptr, dummy }; + for (auto dest: { 20, 30, 40, 60, 90 } ) { + canvas->drawBitmapLattice(bitmap, lattice, SkRect::MakeWH(dest, 110 - dest), nullptr); + canvas->translate(dest + 4, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_104.cpp b/docs/examples/Canvas_104.cpp new file mode 100644 index 0000000000..5e21f434af --- /dev/null +++ b/docs/examples/Canvas_104.cpp @@ -0,0 +1,31 @@ +// 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 "fiddle/examples.h" +// HASH=4f153cf1d0dbe1a95acf5badeec14dae +REG_FIDDLE(Canvas_104, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkIRect center = { 20, 10, 50, 40 }; + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(60, 60)); + SkCanvas bitCanvas(bitmap); + SkPaint paint; + SkColor gray = 0xFF000000; + int left = 0; + for (auto right: { center.fLeft, center.fRight, bitmap.width() } ) { + int top = 0; + for (auto bottom: { center.fTop, center.fBottom, bitmap.height() } ) { + paint.setColor(gray); + bitCanvas.drawIRect(SkIRect::MakeLTRB(left, top, right, bottom), paint); + gray += 0x001f1f1f; + top = bottom; + } + left = right; + } + sk_sp image = SkImage::MakeFromBitmap(bitmap); + SkImage* imagePtr = image.get(); + for (auto dest: { 20, 30, 40, 60, 90 } ) { + canvas->drawImageNine(imagePtr, center, SkRect::MakeWH(dest, dest), nullptr); + canvas->translate(dest + 4, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_105.cpp b/docs/examples/Canvas_105.cpp new file mode 100644 index 0000000000..5078d79e19 --- /dev/null +++ b/docs/examples/Canvas_105.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=55f5e59350622c5e2834d1c85789f732 +REG_FIDDLE(Canvas_105, 256, 200, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkFont font; + float textSizes[] = { 12, 18, 24, 36 }; + for (auto size: textSizes ) { + font.setSize(size); + canvas->drawString("Aa", 10, 20, font, paint); + canvas->translate(0, size * 2); + } + font = SkFont(); + float yPos = 20; + for (auto size: textSizes ) { + float scale = size / 12.f; + canvas->resetMatrix(); + canvas->translate(100, 0); + canvas->scale(scale, scale); + canvas->drawString("Aa", 10 / scale, yPos / scale, font, paint); + yPos += size * 2; + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_106.cpp b/docs/examples/Canvas_106.cpp new file mode 100644 index 0000000000..e772e0fff7 --- /dev/null +++ b/docs/examples/Canvas_106.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=85442cf8d0bce6b5a777853bc36a4dc4 +REG_FIDDLE(Canvas_106, 256, 48, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkFont font; + canvas->drawString("a small hello", 20, 20, font, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_107.cpp b/docs/examples/Canvas_107.cpp new file mode 100644 index 0000000000..dc2ce268bc --- /dev/null +++ b/docs/examples/Canvas_107.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=435178c09feb3bfec5e35d983609a013 +REG_FIDDLE(Canvas_107, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkString string("a small hello"); + canvas->drawString(string, 20, 20, SkFont(), paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_108.cpp b/docs/examples/Canvas_108.cpp new file mode 100644 index 0000000000..cce8a80de6 --- /dev/null +++ b/docs/examples/Canvas_108.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=bf0b2402533a23b6392e0676b7a8414c +REG_FIDDLE(Canvas_108, 256, 120, false, 0) { +void draw(SkCanvas* canvas) { + const char hello[] = "HeLLo!"; + const SkPoint pos[] = { {40, 100}, {82, 95}, {115, 110}, {130, 95}, {145, 85}, + {172, 100} }; + SkPaint paint; + paint.setTextSize(60); + canvas->drawPosText(hello, strlen(hello), pos, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Canvas_109.cpp b/docs/examples/Canvas_109.cpp new file mode 100644 index 0000000000..7fe4214808 --- /dev/null +++ b/docs/examples/Canvas_109.cpp @@ -0,0 +1,13 @@ +#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 "fiddle/examples.h" +// HASH=95c6a7ef82993a8d2add676080e9438a +REG_FIDDLE(Canvas_109, 256, 40, false, 0) { +void draw(SkCanvas* canvas) { + SkScalar xpos[] = { 20, 40, 80, 160 }; + SkPaint paint; + canvas->drawPosTextH("XXXX", 4, xpos, 20, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Canvas_110.cpp b/docs/examples/Canvas_110.cpp new file mode 100644 index 0000000000..34fcca023b --- /dev/null +++ b/docs/examples/Canvas_110.cpp @@ -0,0 +1,26 @@ +#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 "fiddle/examples.h" +// HASH=935c8f8b9782d297a73d7186f6ef7945 +REG_FIDDLE(Canvas_110, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + const int iterations = 26; + SkRSXform transforms[iterations]; + char alphabet[iterations]; + SkScalar angle = 0; + SkScalar scale = 1; + for (size_t i = 0; i < SK_ARRAY_COUNT(transforms); ++i) { + const SkScalar s = SkScalarSin(angle) * scale; + const SkScalar c = SkScalarCos(angle) * scale; + transforms[i] = SkRSXform::Make(-c, -s, -s * 16, c * 16); + angle += .45; + scale += .2; + alphabet[i] = 'A' + i; + } + SkPaint paint; + canvas->translate(110, 138); + canvas->drawTextRSXform(alphabet, sizeof(alphabet), transforms, nullptr, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Canvas_111.cpp b/docs/examples/Canvas_111.cpp new file mode 100644 index 0000000000..0594843de9 --- /dev/null +++ b/docs/examples/Canvas_111.cpp @@ -0,0 +1,33 @@ +#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 "fiddle/examples.h" +// HASH=005502b502c1282cb8d306d6c8d998fb +REG_FIDDLE(Canvas_111, 256, 120, false, 0) { +void draw(SkCanvas* canvas) { + SkTextBlobBuilder textBlobBuilder; + const char bunny[] = "/(^x^)\\"; + const int len = sizeof(bunny) - 1; + uint16_t glyphs[len]; + SkPaint paint; + paint.textToGlyphs(bunny, len, glyphs); + paint.setTextEncoding(kGlyphID_SkTextEncoding); + SkFont font; + int runs[] = { 3, 1, 3 }; + SkPoint textPos = { 20, 100 }; + int glyphIndex = 0; + for (auto runLen : runs) { + font.setSize(1 == runLen ? 20 : 50); + const SkTextBlobBuilder::RunBuffer& run = + textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY); + memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); + paint.setTextSize(1 == runLen ? 20 : 50); + textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr); + glyphIndex += runLen; + } + sk_sp blob = textBlobBuilder.make(); + paint.reset(); + canvas->drawTextBlob(blob.get(), 0, 0, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Canvas_112.cpp b/docs/examples/Canvas_112.cpp new file mode 100644 index 0000000000..ebde9732ac --- /dev/null +++ b/docs/examples/Canvas_112.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=1cae21e7b63b24de3eca0bbd9be1936b +REG_FIDDLE(Canvas_112, 256, 120, false, 0) { +void draw(SkCanvas* canvas) { + SkTextBlobBuilder textBlobBuilder; + SkFont font; + font.setSize(50); + const SkTextBlobBuilder::RunBuffer& run = + textBlobBuilder.allocRun(font, 1, 20, 100); + run.glyphs[0] = 20; + sk_sp blob = textBlobBuilder.make(); + SkPaint paint; + paint.setColor(SK_ColorBLUE); + canvas->drawTextBlob(blob.get(), 0, 0, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_113.cpp b/docs/examples/Canvas_113.cpp new file mode 100644 index 0000000000..01aed9f344 --- /dev/null +++ b/docs/examples/Canvas_113.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=83918a23fcffd47f59a1ef662c85a24c +REG_FIDDLE(Canvas_113, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); + for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { + SkPaint paint; + paint.setColor(color); + recordingCanvas->drawRect({10, 10, 30, 40}, paint); + recordingCanvas->translate(10, 10); + recordingCanvas->scale(1.2f, 1.4f); + } + sk_sp playback = recorder.finishRecordingAsPicture(); + canvas->drawPicture(playback); + canvas->scale(2, 2); + canvas->translate(50, 0); + canvas->drawPicture(playback); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_114.cpp b/docs/examples/Canvas_114.cpp new file mode 100644 index 0000000000..6c4c9f385b --- /dev/null +++ b/docs/examples/Canvas_114.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=83918a23fcffd47f59a1ef662c85a24c +REG_FIDDLE(Canvas_114, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); + for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { + SkPaint paint; + paint.setColor(color); + recordingCanvas->drawRect({10, 10, 30, 40}, paint); + recordingCanvas->translate(10, 10); + recordingCanvas->scale(1.2f, 1.4f); + } + sk_sp playback = recorder.finishRecordingAsPicture(); + canvas->drawPicture(playback); + canvas->scale(2, 2); + canvas->translate(50, 0); + canvas->drawPicture(playback); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_115.cpp b/docs/examples/Canvas_115.cpp new file mode 100644 index 0000000000..a40c744b5d --- /dev/null +++ b/docs/examples/Canvas_115.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=759e4e5bac680838added8f70884dcdc +REG_FIDDLE(Canvas_115, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPictureRecorder recorder; + SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); + for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { + paint.setColor(color); + recordingCanvas->drawRect({10, 10, 30, 40}, paint); + recordingCanvas->translate(10, 10); + recordingCanvas->scale(1.2f, 1.4f); + } + sk_sp playback = recorder.finishRecordingAsPicture(); + const SkPicture* playbackPtr = playback.get(); + SkMatrix matrix; + matrix.reset(); + for (auto alpha : { 70, 140, 210 } ) { + paint.setAlpha(alpha); + canvas->drawPicture(playbackPtr, &matrix, &paint); + matrix.preTranslate(70, 70); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_116.cpp b/docs/examples/Canvas_116.cpp new file mode 100644 index 0000000000..63e13d88ec --- /dev/null +++ b/docs/examples/Canvas_116.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=c4ff59439dd2fc871925d4eeb0c84ca1 +REG_FIDDLE(Canvas_116, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPictureRecorder recorder; + SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); + for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { + paint.setColor(color); + recordingCanvas->drawRect({10, 10, 30, 40}, paint); + recordingCanvas->translate(10, 10); + recordingCanvas->scale(1.2f, 1.4f); + } + sk_sp playback = recorder.finishRecordingAsPicture(); + SkMatrix matrix; + matrix.reset(); + for (auto alpha : { 70, 140, 210 } ) { + paint.setAlpha(alpha); + canvas->drawPicture(playback, &matrix, &paint); + matrix.preTranslate(70, 70); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_117.cpp b/docs/examples/Canvas_117.cpp new file mode 100644 index 0000000000..862ef5c9cf --- /dev/null +++ b/docs/examples/Canvas_117.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=f48b22eaad1bb7adcc3faaa321754af6 +REG_FIDDLE(Canvas_117, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; + auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, + SK_ARRAY_COUNT(points), points, nullptr, colors); + canvas->drawVertices(vertices.get(), SkBlendMode::kSrc, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_118.cpp b/docs/examples/Canvas_118.cpp new file mode 100644 index 0000000000..c0c913f680 --- /dev/null +++ b/docs/examples/Canvas_118.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=e8bdae9bea3227758989028424fcac3d +REG_FIDDLE(Canvas_118, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPoint points[] = { { 0, 0 }, { 250, 0 }, { 100, 100 }, { 0, 250 } }; + SkPoint texs[] = { { 0, 0 }, { 0, 250 }, { 250, 250 }, { 250, 0 } }; + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; + paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 4, + SkShader::kClamp_TileMode)); + auto vertices = SkVertices::MakeCopy(SkVertices::kTriangleFan_VertexMode, + SK_ARRAY_COUNT(points), points, texs, colors); + canvas->drawVertices(vertices, SkBlendMode::kDarken, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_119.cpp b/docs/examples/Canvas_119.cpp new file mode 100644 index 0000000000..a064649c18 --- /dev/null +++ b/docs/examples/Canvas_119.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=accb545d67984ced168f5be6ab824795 +REG_FIDDLE(Canvas_119, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + // SkBitmap source = cmbkygk; + SkPaint paint; + paint.setFilterQuality(kLow_SkFilterQuality); + paint.setAntiAlias(true); + SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, + /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, + /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; + SkColor colors[] = { 0xbfff0000, 0xbf0000ff, 0xbfff00ff, 0xbf00ffff }; + SkPoint texCoords[] = { { -30, -30 }, { 162, -30}, { 162, 162}, { -30, 162} }; + paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, + SkShader::kClamp_TileMode, nullptr)); + canvas->scale(15, 15); + for (auto blend : { SkBlendMode::kSrcOver, SkBlendMode::kModulate, SkBlendMode::kXor } ) { + canvas->drawPatch(cubics, colors, texCoords, blend, paint); + canvas->translate(4, 4); + } +} +} // END FIDDLE diff --git a/docs/examples/Canvas_120.cpp b/docs/examples/Canvas_120.cpp new file mode 100644 index 0000000000..96760649e8 --- /dev/null +++ b/docs/examples/Canvas_120.cpp @@ -0,0 +1,32 @@ +#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 "fiddle/examples.h" +// HASH=4e8b7409531c9211a2afcf632005a38c +REG_FIDDLE(Canvas_120, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, + /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, + /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; + SkColor colors[] = { SK_ColorRED, SK_ColorBLUE, SK_ColorYELLOW, SK_ColorCYAN }; + canvas->scale(30, 30); + canvas->drawPatch(cubics, colors, nullptr, paint); + SkPoint text[] = { {3,0.9f}, {4,2.5f}, {5,0.9f}, {7.5f,3.2f}, {5.5f,4.2f}, + {7.5f,5.2f}, {5,7.5f}, {4,5.9f}, {3,7.5f}, {0.5f,5.2f}, {2.5f,4.2f}, + {0.5f,3.2f} }; + paint.setTextSize(18.f / 30); + for (int i = 0; i< 10; ++i) { + char digit = '0' + i; + canvas->drawText(&digit, 1, text[i].fX, text[i].fY, paint); + } + canvas->drawString("10", text[10].fX, text[10].fY, paint); + canvas->drawString("11", text[11].fX, text[11].fY, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, 12, cubics, paint); + canvas->drawLine(cubics[11].fX, cubics[11].fY, cubics[0].fX, cubics[0].fY, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Canvas_121.cpp b/docs/examples/Canvas_121.cpp new file mode 100644 index 0000000000..673ad1bd4e --- /dev/null +++ b/docs/examples/Canvas_121.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=3412c2a16cb529af0e04878d264451f2 +REG_FIDDLE(Canvas_121, 256, 256, false, 6) { +void draw(SkCanvas* canvas) { + // SkBitmap source = checkerboard; + SkPaint paint; + paint.setFilterQuality(kLow_SkFilterQuality); + paint.setAntiAlias(true); + SkPoint cubics[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + /* { 7, 3 }, */ { 6, 4 }, { 7, 5 }, { 5, 7 }, + /* { 5, 7 }, */ { 4, 6 }, { 3, 7 }, { 1, 5 }, + /* { 1, 5 }, */ { 2, 4 }, { 1, 3 }, /* { 3, 1 } */ }; + SkPoint texCoords[] = { { 0, 0 }, { 0, 62}, { 62, 62}, { 62, 0 } }; + paint.setShader(SkShader::MakeBitmapShader(source, SkShader::kClamp_TileMode, + SkShader::kClamp_TileMode, nullptr)); + canvas->scale(30, 30); + canvas->drawPatch(cubics, nullptr, texCoords, paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_122.cpp b/docs/examples/Canvas_122.cpp new file mode 100644 index 0000000000..0922438893 --- /dev/null +++ b/docs/examples/Canvas_122.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=1df575f9b8132306ce0552a2554ed132 +REG_FIDDLE(Canvas_122, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + // SkBitmap source = mandrill; + SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; + SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; + SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; + const SkImage* imagePtr = image.get(); + canvas->drawAtlas(imagePtr, xforms, tex, colors, 2, SkBlendMode::kSrcOver, nullptr, nullptr); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_123.cpp b/docs/examples/Canvas_123.cpp new file mode 100644 index 0000000000..e320ccba2d --- /dev/null +++ b/docs/examples/Canvas_123.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=0e66a8f230a8d531bcef9f5ebdc5aac1 +REG_FIDDLE(Canvas_123, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + // SkBitmap source = mandrill; + SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; + SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; + SkColor colors[] = { 0x7f55aa00, 0x7f3333bf }; + SkPaint paint; + paint.setAlpha(127); + canvas->drawAtlas(image, xforms, tex, colors, 2, SkBlendMode::kPlus, nullptr, &paint); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_124.cpp b/docs/examples/Canvas_124.cpp new file mode 100644 index 0000000000..775736d14d --- /dev/null +++ b/docs/examples/Canvas_124.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=8dc0d0fdeab20bbc21cac6874ddbefcd +REG_FIDDLE(Canvas_124, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + // sk_sp image = mandrill; + SkRSXform xforms[] = { { .5f, 0, 0, 0 }, {0, .5f, 200, 100 } }; + SkRect tex[] = { { 0, 0, 250, 250 }, { 0, 0, 250, 250 } }; + const SkImage* imagePtr = image.get(); + canvas->drawAtlas(imagePtr, xforms, tex, 2, nullptr, nullptr); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_125.cpp b/docs/examples/Canvas_125.cpp new file mode 100644 index 0000000000..509e849c6c --- /dev/null +++ b/docs/examples/Canvas_125.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=c093c2b14bd3e6171ede7cd4049d9b57 +REG_FIDDLE(Canvas_125, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + // sk_sp image = mandrill; + SkRSXform xforms[] = { { 1, 0, 0, 0 }, {0, 1, 300, 100 } }; + SkRect tex[] = { { 0, 0, 200, 200 }, { 200, 0, 400, 200 } }; + canvas->drawAtlas(image, xforms, tex, 2, nullptr, nullptr); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_126.cpp b/docs/examples/Canvas_126.cpp new file mode 100644 index 0000000000..bdef217b17 --- /dev/null +++ b/docs/examples/Canvas_126.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=3a4dfcd08838866b5cfc0d82489195ba +REG_FIDDLE(Canvas_126, 256, 100, false, 0) { +struct MyDrawable : public SkDrawable { + SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } + void onDraw(SkCanvas* canvas) override { + SkPath path; + path.conicTo(10, 90, 50, 90, 0.9f); + SkPaint paint; + paint.setColor(SK_ColorBLUE); + canvas->drawRect(path.getBounds(), paint); + paint.setAntiAlias(true); + paint.setColor(SK_ColorWHITE); + canvas->drawPath(path, paint); + } +}; + +void draw(SkCanvas* canvas) { + sk_sp drawable(new MyDrawable); + SkMatrix matrix; + matrix.setTranslate(10, 10); + canvas->drawDrawable(drawable.get(), &matrix); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_127.cpp b/docs/examples/Canvas_127.cpp new file mode 100644 index 0000000000..b9b379f05c --- /dev/null +++ b/docs/examples/Canvas_127.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=1bdc07ad3b154c89b771722c2fcaee3f +REG_FIDDLE(Canvas_127, 256, 100, false, 0) { +struct MyDrawable : public SkDrawable { + SkRect onGetBounds() override { return SkRect::MakeWH(50, 100); } + void onDraw(SkCanvas* canvas) override { + SkPath path; + path.conicTo(10, 90, 50, 90, 0.9f); + SkPaint paint; + paint.setColor(SK_ColorBLUE); + canvas->drawRect(path.getBounds(), paint); + paint.setAntiAlias(true); + paint.setColor(SK_ColorWHITE); + canvas->drawPath(path, paint); + } +}; + +void draw(SkCanvas* canvas) { + sk_sp drawable(new MyDrawable); + canvas->drawDrawable(drawable.get(), 10, 10); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_128.cpp b/docs/examples/Canvas_128.cpp new file mode 100644 index 0000000000..c6ac7bf2ee --- /dev/null +++ b/docs/examples/Canvas_128.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=00b430bd80d740e19c6d020a940f56d5 +REG_FIDDLE(Canvas_128, 256, 1, false, 0) { +void draw(SkCanvas* canvas) { + const char text[] = "Click this link!"; + SkRect bounds; + SkPaint paint; + paint.setTextSize(40); + (void)paint.measureText(text, strlen(text), &bounds); + const char url[] = "https://www.google.com/"; + sk_sp urlData(SkData::MakeWithCString(url)); + canvas->drawAnnotation(bounds, "url_key", urlData.get()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Canvas_129.cpp b/docs/examples/Canvas_129.cpp new file mode 100644 index 0000000000..ba9c70a732 --- /dev/null +++ b/docs/examples/Canvas_129.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=00b430bd80d740e19c6d020a940f56d5 +REG_FIDDLE(Canvas_129, 256, 1, false, 0) { +void draw(SkCanvas* canvas) { + const char text[] = "Click this link!"; + SkRect bounds; + SkPaint paint; + paint.setTextSize(40); + (void)paint.measureText(text, strlen(text), &bounds); + const char url[] = "https://www.google.com/"; + sk_sp urlData(SkData::MakeWithCString(url)); + canvas->drawAnnotation(bounds, "url_key", urlData.get()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Canvas_130.cpp b/docs/examples/Canvas_130.cpp new file mode 100644 index 0000000000..1c3fe190dd --- /dev/null +++ b/docs/examples/Canvas_130.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=f106f146a58c8604308d4d8d7086d2f5 +REG_FIDDLE(Canvas_130, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); + SkPath path; + canvas->clipPath(path); + SkDebugf("clip is%s empty\n", canvas->isClipEmpty() ? "" : " not"); +} +} // END FIDDLE diff --git a/docs/examples/Canvas_131.cpp b/docs/examples/Canvas_131.cpp new file mode 100644 index 0000000000..b3cb84f31b --- /dev/null +++ b/docs/examples/Canvas_131.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=9894bfb476c78a8f6c8f49fbbca3d50d +REG_FIDDLE(Canvas_131, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); + canvas->clipRect({0, 0, 0, 0}); + SkDebugf("clip is%s rect\n", canvas->isClipRect() ? "" : " not"); +} +} // END FIDDLE diff --git a/docs/examples/Color4f_000.cpp b/docs/examples/Color4f_000.cpp new file mode 100644 index 0000000000..57c954ac40 --- /dev/null +++ b/docs/examples/Color4f_000.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=e5b34bcb7f80f2ed890cdacaa059db0d +REG_FIDDLE(Color4f_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkColor4f colorRed = { 1, 0, 0, 1 }; + SkColor4f colorNamedRed = SkColor4f::FromColor(SK_ColorRED); + SkDebugf("colorRed %c= colorNamedRed", colorRed == colorNamedRed ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Color4f_001.cpp b/docs/examples/Color4f_001.cpp new file mode 100644 index 0000000000..e8b744f51a --- /dev/null +++ b/docs/examples/Color4f_001.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=82f1a9b4c2b27aa547061786d1f33dab +REG_FIDDLE(Color4f_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkColor4f colorGray = { .5, .5, .5, 1 }; + SkColor4f colorNamedGray = SkColor4f::FromColor(SK_ColorGRAY); + SkDebugf("colorGray %c= colorNamedGray ", colorGray != colorNamedGray ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/Color4f_002.cpp b/docs/examples/Color4f_002.cpp new file mode 100644 index 0000000000..763b3d4a2a --- /dev/null +++ b/docs/examples/Color4f_002.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=229057023515224358a36acf15508cf6 +REG_FIDDLE(Color4f_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkColor4f color = SkColor4f::FromColor(0x884488CC); + SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color.fR, color.fG, color.fB, color.fA); + const float* array = color.vec(); + SkDebugf("[0]=%g [1]=%g [2]=%g [3]=%g\n", array[0], array[1], array[2], array[3]); +} +} // END FIDDLE diff --git a/docs/examples/Color4f_003.cpp b/docs/examples/Color4f_003.cpp new file mode 100644 index 0000000000..2995871bf7 --- /dev/null +++ b/docs/examples/Color4f_003.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=7420bf0a7cae5c6577c4c4a4613e7e7e +REG_FIDDLE(Color4f_003, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkColor4f color = SkColor4f::FromColor(0x884488CC); + SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color.fR, color.fG, color.fB, color.fA); + float* array = color.vec(); + array[3] = 1; + SkDebugf("[0]=%g [1]=%g [2]=%g [3]=%g\n", array[0], array[1], array[2], array[3]); +} +} // END FIDDLE diff --git a/docs/examples/Color4f_004.cpp b/docs/examples/Color4f_004.cpp new file mode 100644 index 0000000000..a1d7db0b3e --- /dev/null +++ b/docs/examples/Color4f_004.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=33b029064e8d1928e42a587c953d0e4e +REG_FIDDLE(Color4f_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + uint8_t red = 77, green = 101, blue = 153, alpha = 43; + SkColor argb = SkColorSetARGB(alpha, red, green, blue); + SkColor4f color4f = SkColor4f::FromColor(argb); + SkDebugf("red=%g green=%g blue=%g alpha=%g\n", color4f.fR, color4f.fG, color4f.fB, color4f.fA); + SkColor fromColor4f = color4f.toSkColor(); + SkDebugf("red=%d green=%d blue=%d alpha=%d\n", SkColorGetR(fromColor4f), + SkColorGetG(fromColor4f), SkColorGetB(fromColor4f), SkColorGetA(fromColor4f)); +} +} // END FIDDLE diff --git a/docs/examples/Color4f_005.cpp b/docs/examples/Color4f_005.cpp new file mode 100644 index 0000000000..264bb7f11d --- /dev/null +++ b/docs/examples/Color4f_005.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=edc5fd18d961f7607d2bcbf7f7d427e5 +REG_FIDDLE(Color4f_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + float red = 0.07, green = 0.13, blue = 0.32, alpha = 0.17; + SkColor4f color4f = { red, green, blue, alpha }; + SkColor argb = color4f.toSkColor(); + SkDebugf("red=%d green=%d blue=%d alpha=%d\n", SkColorGetR(argb), + SkColorGetG(argb), SkColorGetB(argb), SkColorGetA(argb)); + SkColor4f fromSkColor = SkColor4f::FromColor(argb); + SkDebugf("red=%g green=%g blue=%g alpha=%g\n", fromSkColor.fR, fromSkColor.fG, + fromSkColor.fB, fromSkColor.fA); +} +} // END FIDDLE diff --git a/docs/examples/Color_000.cpp b/docs/examples/Color_000.cpp new file mode 100644 index 0000000000..2717d39490 --- /dev/null +++ b/docs/examples/Color_000.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=35888f0869e01a6e03b5b93bba563734 +REG_FIDDLE(Color_000, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + canvas->drawColor(SK_ColorRED); + canvas->clipRect(SkRect::MakeWH(150, 150)); + canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0xFF, 0x00)); + canvas->clipRect(SkRect::MakeWH(75, 75)); + canvas->drawColor(SkColorSetARGB(0x80, 0x00, 0x00, 0xFF)); +} +} // END FIDDLE diff --git a/docs/examples/Color_001.cpp b/docs/examples/Color_001.cpp new file mode 100644 index 0000000000..32851f19c6 --- /dev/null +++ b/docs/examples/Color_001.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=dad12dd912197cd5edd789ac0801bf8a +REG_FIDDLE(Color_001, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + canvas->drawColor(SK_ColorRED); + canvas->clipRect(SkRect::MakeWH(150, 150)); + canvas->drawColor(SkColorSetRGB(0x00, 0xFF, 0x00)); + canvas->clipRect(SkRect::MakeWH(75, 75)); + canvas->drawColor(SkColorSetRGB(0x00, 0x00, 0xFF)); +} +} // END FIDDLE diff --git a/docs/examples/Color_002.cpp b/docs/examples/Color_002.cpp new file mode 100644 index 0000000000..9c3349140b --- /dev/null +++ b/docs/examples/Color_002.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=896ce0316b489608a95af5439ca2aab1 +REG_FIDDLE(Color_002, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorRED); + for (int alpha = 255; alpha >= 0; alpha -= 17) { + paint.setAlpha(alpha); + canvas->drawRect({5, 5, 100, 20}, paint); + SkAlpha alphaInPaint = SkColorGetA(paint.getColor()); + canvas->drawString(std::to_string(alphaInPaint).c_str(), 110, 18, SkFont(), paint); + canvas->translate(0, 15); + } +} +} // END FIDDLE diff --git a/docs/examples/Color_003.cpp b/docs/examples/Color_003.cpp new file mode 100644 index 0000000000..1dc93f99aa --- /dev/null +++ b/docs/examples/Color_003.cpp @@ -0,0 +1,17 @@ +#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 "fiddle/examples.h" +// HASH=d6da38577f189eaa6d9df75f6c3ed252 +REG_FIDDLE(Color_003, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawBitmap(source, 0, 0); + SkPaint bgPaint; + bgPaint.setColor(0xafffffff); + canvas->drawRect({20, 50, 80, 70}, bgPaint); + uint8_t red = SkColorGetR(source.getColor(226, 128)); + canvas->drawString(std::to_string(red).c_str(), 40, 65, SkPaint()); + canvas->drawLine(80, 70, 226, 128, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Color_004.cpp b/docs/examples/Color_004.cpp new file mode 100644 index 0000000000..5b912738c5 --- /dev/null +++ b/docs/examples/Color_004.cpp @@ -0,0 +1,17 @@ +#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 "fiddle/examples.h" +// HASH=535d38b2c019299d915170f7b03d5fea +REG_FIDDLE(Color_004, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawBitmap(source, 0, 0); + SkPaint bgPaint; + bgPaint.setColor(0xafffffff); + canvas->drawRect({20, 50, 80, 70}, bgPaint); + uint8_t green = SkColorGetG(source.getColor(57, 192)); + canvas->drawString(std::to_string(green).c_str(), 40, 65, SkPaint()); + canvas->drawLine(80, 70, 57, 192, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Color_005.cpp b/docs/examples/Color_005.cpp new file mode 100644 index 0000000000..c00d4c0133 --- /dev/null +++ b/docs/examples/Color_005.cpp @@ -0,0 +1,17 @@ +#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 "fiddle/examples.h" +// HASH=9ee27675284faea375611dc88123a2c5 +REG_FIDDLE(Color_005, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawBitmap(source, 0, 0); + SkPaint bgPaint; + bgPaint.setColor(0xafffffff); + canvas->drawRect({20, 50, 80, 70}, bgPaint); + uint8_t blue = SkColorGetB(source.getColor(168, 170)); + canvas->drawString(std::to_string(blue).c_str(), 40, 65, SkPaint()); + canvas->drawLine(80, 70, 168, 170, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Color_006.cpp b/docs/examples/Color_006.cpp new file mode 100644 index 0000000000..58f1858a35 --- /dev/null +++ b/docs/examples/Color_006.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=18f6f376f771f5ffa56d5e5b2ebd20fb +REG_FIDDLE(Color_006, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawBitmap(source, 0, 0); + for (int y = 0; y < 256; y += 16) { + for (int x = 0; x < 256; x += 16) { + SkColor color = source.getColor(x + 8, y + 8); + SkPaint paint; + paint.setColor(SkColorSetA(color, x + y)); + canvas->drawRect(SkRect::MakeXYWH(x, y, 16, 16), paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Color_007.cpp b/docs/examples/Color_007.cpp new file mode 100644 index 0000000000..b08ea6d0d8 --- /dev/null +++ b/docs/examples/Color_007.cpp @@ -0,0 +1,38 @@ +// 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 "fiddle/examples.h" +// HASH=bc9c7ea424d10bbcd1e5a88770d4794e +REG_FIDDLE(Color_007, 256, 128, false, 1) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + srcPixels.resize(source.height() * source.rowBytes()); + SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()), + &srcPixels.front(), source.rowBytes()); + source.readPixels(pixmap, 0, 0); + for (int y = 0; y < 16; ++y) { + for (int x = 0; x < 16; ++x) { + int32_t* blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16; + size_t transparentCount = 0; + for (int fillY = 0; fillY < source.height() / 16; ++fillY) { + for (int fillX = 0; fillX < source.width() / 16; ++fillX) { + const SkColor color = SkUnPreMultiply::PMColorToColor(blockStart[fillX]); + transparentCount += SkColorGetA(color) == SK_AlphaTRANSPARENT; + } + blockStart += source.width(); + } + if (transparentCount > 200) { + blockStart = &srcPixels.front() + y * source.width() * 16 + x * 16; + for (int fillY = 0; fillY < source.height() / 16; ++fillY) { + for (int fillX = 0; fillX < source.width() / 16; ++fillX) { + blockStart[fillX] = SK_ColorRED; + } + blockStart += source.width(); + } + } + } + } + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Color_008.cpp b/docs/examples/Color_008.cpp new file mode 100644 index 0000000000..07e18318d9 --- /dev/null +++ b/docs/examples/Color_008.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=0424f67ebc2858e8fd04ae3367b115ff +REG_FIDDLE(Color_008, 256, 128, false, 1) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + srcPixels.resize(source.height() * source.rowBytes()); + SkPixmap pixmap(SkImageInfo::MakeN32Premul(source.width(), source.height()), + &srcPixels.front(), source.rowBytes()); + source.readPixels(pixmap, 0, 0); + for (int y = 0; y < source.height(); ++y) { + for (int x = 0; x < source.width(); ++x) { + SkPMColor pixel = srcPixels[y * source.width() + x]; + const SkColor color = SkUnPreMultiply::PMColorToColor(pixel); + if (SkColorGetA(color) == SK_AlphaOPAQUE) { + srcPixels[y * source.width() + x] = SK_ColorGREEN; + } + } + } + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Color_009.cpp b/docs/examples/Color_009.cpp new file mode 100644 index 0000000000..8f383c7930 --- /dev/null +++ b/docs/examples/Color_009.cpp @@ -0,0 +1,48 @@ +#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 "fiddle/examples.h" +// HASH=1c2e38321464818847f953ddd45cb5a1 +REG_FIDDLE(Color_009, 256, 256, false, 0) { +#define SKIA_COLOR_PAIR(name) "SK_Color" #name, SK_Color##name + +void draw(SkCanvas* canvas) { + struct ColorCompare { + const char* fSVGName; + SkColor fSVGColor; + const char* fSkiaName; + SkColor fSkiaColor; + } colorCompare[] = { // see https://www.w3.org/TR/SVG/types.html#ColorKeywords + {"black", SkColorSetRGB( 0, 0, 0), SKIA_COLOR_PAIR(BLACK) }, + {"darkgray", SkColorSetRGB(169, 169, 169), SKIA_COLOR_PAIR(DKGRAY) }, + {"gray", SkColorSetRGB(128, 128, 128), SKIA_COLOR_PAIR(GRAY) }, + {"lightgray", SkColorSetRGB(211, 211, 211), SKIA_COLOR_PAIR(LTGRAY) }, + {"white", SkColorSetRGB(255, 255, 255), SKIA_COLOR_PAIR(WHITE) }, + {"red", SkColorSetRGB(255, 0, 0), SKIA_COLOR_PAIR(RED) }, + {"green", SkColorSetRGB( 0, 128, 0), SKIA_COLOR_PAIR(GREEN) }, + {"blue", SkColorSetRGB( 0, 0, 255), SKIA_COLOR_PAIR(BLUE) }, + {"yellow", SkColorSetRGB(255, 255, 0), SKIA_COLOR_PAIR(YELLOW) }, + {"aqua", SkColorSetRGB( 0, 255, 255), SKIA_COLOR_PAIR(CYAN) }, + {"fuchsia", SkColorSetRGB(255, 0, 255), SKIA_COLOR_PAIR(MAGENTA) }, + }; + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(14); + for (auto compare : colorCompare) { + paint.setStyle(SkPaint::kFill_Style); + paint.setColor(compare.fSVGColor); + canvas->drawRect({5, 5, 15, 15}, paint); + paint.setColor(SK_ColorBLACK); + canvas->drawString(compare.fSVGName, 20, 16, paint); + paint.setColor(compare.fSkiaColor); + canvas->drawRect({105, 5, 115, 15}, paint); + paint.setColor(SK_ColorBLACK); + canvas->drawString(compare.fSkiaName, 120, 16, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRect({5, 5, 15, 15}, paint); + canvas->drawRect({105, 5, 115, 15}, paint); + canvas->translate(0, 20); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Color_010.cpp b/docs/examples/Color_010.cpp new file mode 100644 index 0000000000..89458a2e3e --- /dev/null +++ b/docs/examples/Color_010.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=9ca1e2a5b9b4c92ecf4409d0813867d6 +REG_FIDDLE(Color_010, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + constexpr int width = 256; + constexpr int height = 256; + srcPixels.resize(width * height); + SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height); + SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes()); + pixmap.erase(SK_ColorTRANSPARENT); + pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } ); + pixmap.erase(SK_ColorTRANSPARENT, { 48, 48, 168, 168 } ); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); + canvas->drawBitmap(bitmap, 48, 48); +} +} // END FIDDLE diff --git a/docs/examples/Color_011.cpp b/docs/examples/Color_011.cpp new file mode 100644 index 0000000000..b6ce520e5d --- /dev/null +++ b/docs/examples/Color_011.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=6971489f28291f08e429cc6ccc73b09b +REG_FIDDLE(Color_011, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + constexpr int width = 256; + constexpr int height = 256; + srcPixels.resize(width * height); + SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height); + SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes()); + pixmap.erase(SK_ColorTRANSPARENT); + pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } ); + pixmap.erase(SK_ColorBLACK, { 48, 48, 168, 168 } ); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); + canvas->drawBitmap(bitmap, 48, 48); +} +} // END FIDDLE diff --git a/docs/examples/Color_012.cpp b/docs/examples/Color_012.cpp new file mode 100644 index 0000000000..e5e1601a4c --- /dev/null +++ b/docs/examples/Color_012.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=fce650f997e802d4e55edf62b8437a2d +REG_FIDDLE(Color_012, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + constexpr int width = 256; + constexpr int height = 256; + srcPixels.resize(width * height); + SkImageInfo imageInfo = SkImageInfo::MakeN32Premul(width, height); + SkPixmap pixmap(imageInfo, &srcPixels.front(), imageInfo.minRowBytes()); + pixmap.erase(SK_ColorTRANSPARENT); + pixmap.erase(SK_ColorRED, { 24, 24, 192, 192 } ); + pixmap.erase(SK_ColorWHITE, { 48, 48, 168, 168 } ); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); + canvas->drawBitmap(bitmap, 48, 48); +} +} // END FIDDLE diff --git a/docs/examples/Color_013.cpp b/docs/examples/Color_013.cpp new file mode 100644 index 0000000000..ddc0a7807d --- /dev/null +++ b/docs/examples/Color_013.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=4fb2da4a3d9b14ca4ac24eefb0f5126a +REG_FIDDLE(Color_013, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawBitmap(source, 0, 0); + SkPaint bgPaint; + bgPaint.setColor(0xafffffff); + canvas->drawRect({20, 30, 110, 90}, bgPaint); + SkScalar hsv[3]; + SkColor c = source.getColor(226, 128); + SkRGBToHSV(SkColorGetR(c), SkColorGetG(c), SkColorGetB(c), hsv); + canvas->drawString(("h: " + std::to_string(hsv[0]).substr(0, 6)).c_str(), 27, 45, SkPaint()); + canvas->drawString(("s: " + std::to_string(hsv[1]).substr(0, 6)).c_str(), 27, 65, SkPaint()); + canvas->drawString(("v: " + std::to_string(hsv[2]).substr(0, 6)).c_str(), 27, 85, SkPaint()); + canvas->drawLine(110, 90, 226, 128, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Color_014.cpp b/docs/examples/Color_014.cpp new file mode 100644 index 0000000000..64363378bf --- /dev/null +++ b/docs/examples/Color_014.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=1e0370f12c8aab5b84f9e824074f1e5a +REG_FIDDLE(Color_014, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawBitmap(source, 0, 0); + for (int y = 0; y < 256; ++y) { + for (int x = 0; x < 256; ++x) { + SkScalar hsv[3]; + SkColorToHSV(source.getColor(x, y), hsv); + hsv[1] = 1 - hsv[1]; + SkPaint paint; + paint.setColor(SkHSVToColor(hsv)); + canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Color_015.cpp b/docs/examples/Color_015.cpp new file mode 100644 index 0000000000..6b55948f90 --- /dev/null +++ b/docs/examples/Color_015.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=311a59931ac340b90f202cd6ac399a0a +REG_FIDDLE(Color_015, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawBitmap(source, 0, 0); + for (int y = 0; y < 256; ++y) { + for (int x = 0; x < 256; ++x) { + SkColor color = source.getColor(x, y); + SkScalar hsv[3]; + SkColorToHSV(color, hsv); + hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90; + SkPaint paint; + paint.setColor(SkHSVToColor((x + y) % 256, hsv)); + canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Color_016.cpp b/docs/examples/Color_016.cpp new file mode 100644 index 0000000000..3df3f737df --- /dev/null +++ b/docs/examples/Color_016.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=d355a17547908cdbc2c38720974b5d11 +REG_FIDDLE(Color_016, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->drawBitmap(source, 0, 0); + for (int y = 0; y < 256; ++y) { + for (int x = 0; x < 256; ++x) { + SkColor color = source.getColor(x, y); + SkScalar hsv[3]; + SkColorToHSV(color, hsv); + hsv[0] = hsv[0] + 90 >= 360 ? hsv[0] - 270 : hsv[0] + 90; + SkPaint paint; + paint.setColor(SkHSVToColor(hsv)); + canvas->drawRect(SkRect::MakeXYWH(x, y, 1, 1), paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Color_017.cpp b/docs/examples/Color_017.cpp new file mode 100644 index 0000000000..6dfd7c1d49 --- /dev/null +++ b/docs/examples/Color_017.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=756345484fd48ca0ea7b6cec350f73b8 +REG_FIDDLE(Color_017, 300, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPMColor premultiplied = SkPreMultiplyARGB(160, 128, 160, 192); + canvas->drawString("Unpremultiplied:", 20, 20, SkPaint()); + canvas->drawString("alpha=160 red=128 green=160 blue=192", 20, 40, SkPaint()); + canvas->drawString("Premultiplied:", 20, 80, SkPaint()); + std::string str = "alpha=" + std::to_string(SkColorGetA(premultiplied)); + str += " red=" + std::to_string(SkColorGetR(premultiplied)); + str += " green=" + std::to_string(SkColorGetG(premultiplied)); + str += " blue=" + std::to_string(SkColorGetB(premultiplied)); + canvas->drawString(str.c_str(), 20, 100, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Color_018.cpp b/docs/examples/Color_018.cpp new file mode 100644 index 0000000000..81d0f04d82 --- /dev/null +++ b/docs/examples/Color_018.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=0bcc0f86a2aefc899f3500503dce6968 +REG_FIDDLE(Color_018, 300, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkColor unpremultiplied = SkColorSetARGB(160, 128, 160, 192); + SkPMColor premultiplied = SkPreMultiplyColor(unpremultiplied); + canvas->drawString("Unpremultiplied:", 20, 20, SkPaint()); + std::string str = "alpha=" + std::to_string(SkColorGetA(unpremultiplied)); + str += " red=" + std::to_string(SkColorGetR(unpremultiplied)); + str += " green=" + std::to_string(SkColorGetG(unpremultiplied)); + str += " blue=" + std::to_string(SkColorGetB(unpremultiplied)); + canvas->drawString(str.c_str(), 20, 40, SkPaint()); + canvas->drawString("Premultiplied:", 20, 80, SkPaint()); + str = "alpha=" + std::to_string(SkColorGetA(premultiplied)); + str += " red=" + std::to_string(SkColorGetR(premultiplied)); + str += " green=" + std::to_string(SkColorGetG(premultiplied)); + str += " blue=" + std::to_string(SkColorGetB(premultiplied)); + canvas->drawString(str.c_str(), 20, 100, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Font_000.cpp b/docs/examples/Font_000.cpp new file mode 100644 index 0000000000..23e633936d --- /dev/null +++ b/docs/examples/Font_000.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_000, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_001.cpp b/docs/examples/Font_001.cpp new file mode 100644 index 0000000000..75f1299391 --- /dev/null +++ b/docs/examples/Font_001.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_001, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_002.cpp b/docs/examples/Font_002.cpp new file mode 100644 index 0000000000..35d3eb31a4 --- /dev/null +++ b/docs/examples/Font_002.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_002, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_003.cpp b/docs/examples/Font_003.cpp new file mode 100644 index 0000000000..d98e5c76cf --- /dev/null +++ b/docs/examples/Font_003.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_003, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_004.cpp b/docs/examples/Font_004.cpp new file mode 100644 index 0000000000..08f51b9334 --- /dev/null +++ b/docs/examples/Font_004.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_004, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_005.cpp b/docs/examples/Font_005.cpp new file mode 100644 index 0000000000..8ea371f80f --- /dev/null +++ b/docs/examples/Font_005.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_005, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_006.cpp b/docs/examples/Font_006.cpp new file mode 100644 index 0000000000..5e0836c30b --- /dev/null +++ b/docs/examples/Font_006.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_006, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_007.cpp b/docs/examples/Font_007.cpp new file mode 100644 index 0000000000..fa2e6d301d --- /dev/null +++ b/docs/examples/Font_007.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_007, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_008.cpp b/docs/examples/Font_008.cpp new file mode 100644 index 0000000000..15a345ab31 --- /dev/null +++ b/docs/examples/Font_008.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_008, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_009.cpp b/docs/examples/Font_009.cpp new file mode 100644 index 0000000000..bf229e065d --- /dev/null +++ b/docs/examples/Font_009.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_009, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_010.cpp b/docs/examples/Font_010.cpp new file mode 100644 index 0000000000..c9cc4d1b8e --- /dev/null +++ b/docs/examples/Font_010.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_010, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_011.cpp b/docs/examples/Font_011.cpp new file mode 100644 index 0000000000..fd367c7026 --- /dev/null +++ b/docs/examples/Font_011.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_011, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_012.cpp b/docs/examples/Font_012.cpp new file mode 100644 index 0000000000..8aac62a6bd --- /dev/null +++ b/docs/examples/Font_012.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_012, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_013.cpp b/docs/examples/Font_013.cpp new file mode 100644 index 0000000000..728de64682 --- /dev/null +++ b/docs/examples/Font_013.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_013, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_014.cpp b/docs/examples/Font_014.cpp new file mode 100644 index 0000000000..82b6c04ded --- /dev/null +++ b/docs/examples/Font_014.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_014, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_015.cpp b/docs/examples/Font_015.cpp new file mode 100644 index 0000000000..25fc44fbae --- /dev/null +++ b/docs/examples/Font_015.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_015, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_016.cpp b/docs/examples/Font_016.cpp new file mode 100644 index 0000000000..4bec9cf368 --- /dev/null +++ b/docs/examples/Font_016.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_016, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_017.cpp b/docs/examples/Font_017.cpp new file mode 100644 index 0000000000..4650d73e25 --- /dev/null +++ b/docs/examples/Font_017.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_017, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_018.cpp b/docs/examples/Font_018.cpp new file mode 100644 index 0000000000..7dc7049eb5 --- /dev/null +++ b/docs/examples/Font_018.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_018, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_019.cpp b/docs/examples/Font_019.cpp new file mode 100644 index 0000000000..e2a6f96071 --- /dev/null +++ b/docs/examples/Font_019.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_019, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_020.cpp b/docs/examples/Font_020.cpp new file mode 100644 index 0000000000..d1523f732b --- /dev/null +++ b/docs/examples/Font_020.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_020, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_021.cpp b/docs/examples/Font_021.cpp new file mode 100644 index 0000000000..1c46e4fb9d --- /dev/null +++ b/docs/examples/Font_021.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_021, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_022.cpp b/docs/examples/Font_022.cpp new file mode 100644 index 0000000000..1930dc7bfd --- /dev/null +++ b/docs/examples/Font_022.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_022, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_023.cpp b/docs/examples/Font_023.cpp new file mode 100644 index 0000000000..58d2eb59ec --- /dev/null +++ b/docs/examples/Font_023.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_023, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_024.cpp b/docs/examples/Font_024.cpp new file mode 100644 index 0000000000..63e5ec7840 --- /dev/null +++ b/docs/examples/Font_024.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_024, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_025.cpp b/docs/examples/Font_025.cpp new file mode 100644 index 0000000000..a9da11219d --- /dev/null +++ b/docs/examples/Font_025.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_025, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_026.cpp b/docs/examples/Font_026.cpp new file mode 100644 index 0000000000..d5f9d47e56 --- /dev/null +++ b/docs/examples/Font_026.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_026, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_027.cpp b/docs/examples/Font_027.cpp new file mode 100644 index 0000000000..7ec3e16718 --- /dev/null +++ b/docs/examples/Font_027.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_027, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_028.cpp b/docs/examples/Font_028.cpp new file mode 100644 index 0000000000..fc82a12222 --- /dev/null +++ b/docs/examples/Font_028.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_028, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_029.cpp b/docs/examples/Font_029.cpp new file mode 100644 index 0000000000..fba981ac31 --- /dev/null +++ b/docs/examples/Font_029.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_029, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_030.cpp b/docs/examples/Font_030.cpp new file mode 100644 index 0000000000..ba53e69889 --- /dev/null +++ b/docs/examples/Font_030.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_030, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_031.cpp b/docs/examples/Font_031.cpp new file mode 100644 index 0000000000..d402cecd56 --- /dev/null +++ b/docs/examples/Font_031.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_031, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_032.cpp b/docs/examples/Font_032.cpp new file mode 100644 index 0000000000..ba94ef28ea --- /dev/null +++ b/docs/examples/Font_032.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_032, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_033.cpp b/docs/examples/Font_033.cpp new file mode 100644 index 0000000000..8b44256a9b --- /dev/null +++ b/docs/examples/Font_033.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=3cad18678254526be66ef162eecd1d23 +REG_FIDDLE(Font_033, 280, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(50); + const char str[] = "Breakfast"; + const int count = sizeof(str) - 1; + canvas->drawText(str, count, 25, 50, paint); + SkScalar measuredWidth; + SkFont font; + font.setSize(50); + int partialBytes = font.breakText(str, count, kUTF8_SkTextEncoding, + 100, &measuredWidth); + canvas->drawText(str, partialBytes, 25, 100, paint); + canvas->drawLine(25, 60, 25 + 100, 60, paint); + canvas->drawLine(25, 110, 25 + measuredWidth, 110, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Font_034.cpp b/docs/examples/Font_034.cpp new file mode 100644 index 0000000000..b0b72d9f4d --- /dev/null +++ b/docs/examples/Font_034.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_034, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_035.cpp b/docs/examples/Font_035.cpp new file mode 100644 index 0000000000..e6eade1aef --- /dev/null +++ b/docs/examples/Font_035.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_035, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_036.cpp b/docs/examples/Font_036.cpp new file mode 100644 index 0000000000..6b4f555ece --- /dev/null +++ b/docs/examples/Font_036.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_036, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_037.cpp b/docs/examples/Font_037.cpp new file mode 100644 index 0000000000..7c5356033c --- /dev/null +++ b/docs/examples/Font_037.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_037, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/Font_038.cpp b/docs/examples/Font_038.cpp new file mode 100644 index 0000000000..8b36d3c982 --- /dev/null +++ b/docs/examples/Font_038.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=882e8e0103048009a25cfc20400492f7 +REG_FIDDLE(Font_038, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + // incomplete +} +} // END FIDDLE diff --git a/docs/examples/IPoint_000.cpp b/docs/examples/IPoint_000.cpp new file mode 100644 index 0000000000..e454ad7e48 --- /dev/null +++ b/docs/examples/IPoint_000.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=e5cf5159525bd3140f288a95fe641fae +REG_FIDDLE(IPoint_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint pt1 = {45, 66}; + SkIPoint pt2 = SkIPoint::Make(45, 66); + SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/IPoint_001.cpp b/docs/examples/IPoint_001.cpp new file mode 100644 index 0000000000..d16b2ec586 --- /dev/null +++ b/docs/examples/IPoint_001.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=eed4185294f8a8216fc354e6ee6b2e3a +REG_FIDDLE(IPoint_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint pt1 = {45, 66}; + SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/IPoint_002.cpp b/docs/examples/IPoint_002.cpp new file mode 100644 index 0000000000..d349617351 --- /dev/null +++ b/docs/examples/IPoint_002.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=35c41b8ba7cebf8c9a7a8494e610e14d +REG_FIDDLE(IPoint_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint pt1 = {45, 66}; + SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/IPoint_003.cpp b/docs/examples/IPoint_003.cpp new file mode 100644 index 0000000000..cfca3bed6d --- /dev/null +++ b/docs/examples/IPoint_003.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=658c1df611b4577cc7e0bb384e95737e +REG_FIDDLE(IPoint_003, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint pt = { 0, -0}; + SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/IPoint_004.cpp b/docs/examples/IPoint_004.cpp new file mode 100644 index 0000000000..c07b31dbe1 --- /dev/null +++ b/docs/examples/IPoint_004.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=165418b5718d79d8f1682a8a0ee32ba0 +REG_FIDDLE(IPoint_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint pt1, pt2 = { SK_MinS32, SK_MaxS32 }; + pt1.set(SK_MinS32, SK_MaxS32); + SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/IPoint_005.cpp b/docs/examples/IPoint_005.cpp new file mode 100644 index 0000000000..cd4bc04abc --- /dev/null +++ b/docs/examples/IPoint_005.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=b30d4780475d113a7fed3637af7f0db1 +REG_FIDDLE(IPoint_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint test[] = { {0, -0}, {-1, -2}, + { SK_MaxS32, SK_MinS32 }, + { SK_NaN32, SK_NaN32 } }; + for (const SkIPoint& pt : test) { + SkIPoint negPt = -pt; + SkDebugf("pt: %d, %d negate: %d, %d\n", pt.fX, pt.fY, negPt.fX, negPt.fY); + } +} +} // END FIDDLE diff --git a/docs/examples/IPoint_006.cpp b/docs/examples/IPoint_006.cpp new file mode 100644 index 0000000000..e7e515bc32 --- /dev/null +++ b/docs/examples/IPoint_006.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=4eb2d95c9e9a66f05296e345bb68bd51 +REG_FIDDLE(IPoint_006, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void { + for (size_t i = 0; i < count - 1; ++i) { + SkPoint p0, p1; + p0.iset(pts[i]); + p1.iset(pts[i + 1]); + canvas->drawLine(p0, p1, paint); + } + }; + SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } }; + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + canvas->scale(30, 15); + draw_lines(points, SK_ARRAY_COUNT(points), paint); + points[1] += {1, 1}; + points[2] += {-1, -1}; + paint.setColor(SK_ColorRED); + draw_lines(points, SK_ARRAY_COUNT(points), paint); +} +} // END FIDDLE diff --git a/docs/examples/IPoint_007.cpp b/docs/examples/IPoint_007.cpp new file mode 100644 index 0000000000..16963ec342 --- /dev/null +++ b/docs/examples/IPoint_007.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=a01e533dc7ab34ed728dc4e7a5f1f0ee +REG_FIDDLE(IPoint_007, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void { + for (size_t i = 0; i < count - 1; ++i) { + SkPoint p0, p1; + p0.iset(pts[i]); + p1.iset(pts[i + 1]); + canvas->drawLine(p0, p1, paint); + } + }; + SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } }; + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + canvas->scale(30, 15); + draw_lines(points, SK_ARRAY_COUNT(points), paint); + points[1] -= {1, 1}; + points[2] -= {-1, -1}; + paint.setColor(SK_ColorRED); + draw_lines(points, SK_ARRAY_COUNT(points), paint); +} +} // END FIDDLE diff --git a/docs/examples/IPoint_008.cpp b/docs/examples/IPoint_008.cpp new file mode 100644 index 0000000000..dbecb3b3fc --- /dev/null +++ b/docs/examples/IPoint_008.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=64f575d36439d5b69aaed14ffeff1cc4 +REG_FIDDLE(IPoint_008, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} }; + for (const SkIPoint& pt : test) { + SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!'); + } +} +} // END FIDDLE diff --git a/docs/examples/IPoint_009.cpp b/docs/examples/IPoint_009.cpp new file mode 100644 index 0000000000..39521350f8 --- /dev/null +++ b/docs/examples/IPoint_009.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=37ffe2817d720f99e6c252332ce70460 +REG_FIDDLE(IPoint_009, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} }; + for (const SkIPoint& pt : test) { + SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!'); + } +} +} // END FIDDLE diff --git a/docs/examples/IPoint_010.cpp b/docs/examples/IPoint_010.cpp new file mode 100644 index 0000000000..cfd975a449 --- /dev/null +++ b/docs/examples/IPoint_010.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=dd89dc48dff69b53d99530b120f204bc +REG_FIDDLE(IPoint_010, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint test[] = { {0, -0}, {-1, -2}, {SK_MaxS32, -1}, {SK_NaN32, -1} }; + for (const SkIPoint& pt : test) { + SkDebugf("pt: %d, %d %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '='); + } +} +} // END FIDDLE diff --git a/docs/examples/IPoint_011.cpp b/docs/examples/IPoint_011.cpp new file mode 100644 index 0000000000..3990bbc826 --- /dev/null +++ b/docs/examples/IPoint_011.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=e626e26bf557857b824aa7d03f723e0f +REG_FIDDLE(IPoint_011, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void { + for (size_t i = 0; i < count - 1; ++i) { + SkPoint p0, p1; + p0.iset(pts[i]); + p1.iset(pts[i + 1]); + canvas->drawLine(p0, p1, paint); + } + }; + SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } }; + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + canvas->scale(30, 15); + draw_lines(points, SK_ARRAY_COUNT(points), paint); + points[1] += points[0] - points[3]; + points[2] -= points[1] - points[0]; + paint.setColor(SK_ColorRED); + draw_lines(points, SK_ARRAY_COUNT(points), paint); +} +} // END FIDDLE diff --git a/docs/examples/IPoint_012.cpp b/docs/examples/IPoint_012.cpp new file mode 100644 index 0000000000..7176db6fc3 --- /dev/null +++ b/docs/examples/IPoint_012.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=63f4cba971c6d8434595906f865b5a29 +REG_FIDDLE(IPoint_012, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + auto draw_lines = [=](const SkIPoint pts[], size_t count, SkPaint& paint) -> void { + for (size_t i = 0; i < count - 1; ++i) { + SkPoint p0, p1; + p0.iset(pts[i]); + p1.iset(pts[i + 1]); + canvas->drawLine(p0, p1, paint); + } + }; + SkIPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 } }; + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + canvas->scale(30, 15); + draw_lines(points, SK_ARRAY_COUNT(points), paint); + SkIPoint mod = {4, 1}; + for (auto& point : points) { + point = point + mod; + mod.fX -= 1; + mod.fY += 1; + } + paint.setColor(SK_ColorRED); + draw_lines(points, SK_ARRAY_COUNT(points), paint); +} +} // END FIDDLE diff --git a/docs/examples/IRect_000.cpp b/docs/examples/IRect_000.cpp new file mode 100644 index 0000000000..6941bdc577 --- /dev/null +++ b/docs/examples/IRect_000.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=0ade3971c1d2616564992e286966ec8a +REG_FIDDLE(IRect_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = SkIRect::MakeEmpty(); + SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); + rect.offset(10, 10); + SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); + rect.inset(10, 10); + SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); + rect.outset(20, 20); + SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/IRect_001.cpp b/docs/examples/IRect_001.cpp new file mode 100644 index 0000000000..56520bad70 --- /dev/null +++ b/docs/examples/IRect_001.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=e36827a1a6ae2b1c26e7a8a08f325a07 +REG_FIDDLE(IRect_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect1 = SkIRect::MakeWH(25, 35); + SkIRect rect2 = SkIRect::MakeSize({25, 35}); + SkIRect rect3 = SkIRect::MakeXYWH(0, 0, 25, 35); + SkIRect rect4 = SkIRect::MakeLTRB(0, 0, 25, 35); + SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ? + "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/IRect_002.cpp b/docs/examples/IRect_002.cpp new file mode 100644 index 0000000000..69b5321d75 --- /dev/null +++ b/docs/examples/IRect_002.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=c6586ff8d24869c780169b0d19c75df6 +REG_FIDDLE(IRect_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkSize size = {25.5f, 35.5f}; + SkIRect rect = SkIRect::MakeSize(size.toRound()); + SkDebugf("round width: %d height: %d\n", rect.width(), rect.height()); + rect = SkIRect::MakeSize(size.toFloor()); + SkDebugf("floor width: %d height: %d\n", rect.width(), rect.height()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_003.cpp b/docs/examples/IRect_003.cpp new file mode 100644 index 0000000000..92fdaa2fc1 --- /dev/null +++ b/docs/examples/IRect_003.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=ec1473b700c594f2df9749a12a06b89b +REG_FIDDLE(IRect_003, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = SkIRect::MakeLTRB(5, 35, 15, 25); + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect.sort(); + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/IRect_004.cpp b/docs/examples/IRect_004.cpp new file mode 100644 index 0000000000..72fb980438 --- /dev/null +++ b/docs/examples/IRect_004.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=598ee14350bd1d961cae6b36fa3df17e +REG_FIDDLE(IRect_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = SkIRect::MakeXYWH(5, 35, -15, 25); + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect.sort(); + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/IRect_005.cpp b/docs/examples/IRect_005.cpp new file mode 100644 index 0000000000..9cae9c5f2c --- /dev/null +++ b/docs/examples/IRect_005.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=caf38ea4431bc246ba198f6a8c2b0f01 +REG_FIDDLE(IRect_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect unsorted = { 15, 5, 10, 25 }; + SkDebugf("unsorted.fLeft: %d unsorted.left(): %d\n", unsorted.fLeft, unsorted.left()); + SkIRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fLeft: %d sorted.left(): %d\n", sorted.fLeft, sorted.left()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_006.cpp b/docs/examples/IRect_006.cpp new file mode 100644 index 0000000000..c21356cf9d --- /dev/null +++ b/docs/examples/IRect_006.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=cbec1ae6530e95943775450b1d11f19e +REG_FIDDLE(IRect_006, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted.fTop: %d unsorted.top(): %d\n", unsorted.fTop, unsorted.top()); + SkIRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fTop: %d sorted.top(): %d\n", sorted.fTop, sorted.top()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_007.cpp b/docs/examples/IRect_007.cpp new file mode 100644 index 0000000000..ec10f3bc9b --- /dev/null +++ b/docs/examples/IRect_007.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=97e210976f1ee0387b30c70635cf114f +REG_FIDDLE(IRect_007, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted.fRight: %d unsorted.right(): %d\n", unsorted.fRight, unsorted.right()); + SkIRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fRight: %d sorted.right(): %d\n", sorted.fRight, sorted.right()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_008.cpp b/docs/examples/IRect_008.cpp new file mode 100644 index 0000000000..162b2b85c7 --- /dev/null +++ b/docs/examples/IRect_008.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=c32afebc296054a181621648a184b8e3 +REG_FIDDLE(IRect_008, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted.fBottom: %d unsorted.bottom(): %d\n", unsorted.fBottom, unsorted.bottom()); + SkIRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fBottom: %d sorted.bottom(): %d\n", sorted.fBottom, sorted.bottom()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_009.cpp b/docs/examples/IRect_009.cpp new file mode 100644 index 0000000000..7c46dca261 --- /dev/null +++ b/docs/examples/IRect_009.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=2a59cbfd1330a0db520d6ebb2b7c68c7 +REG_FIDDLE(IRect_009, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect unsorted = { 15, 5, 10, 25 }; + SkDebugf("unsorted.fLeft: %d unsorted.x(): %d\n", unsorted.fLeft, unsorted.x()); + SkIRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fLeft: %d sorted.x(): %d\n", sorted.fLeft, sorted.x()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_010.cpp b/docs/examples/IRect_010.cpp new file mode 100644 index 0000000000..79627615cd --- /dev/null +++ b/docs/examples/IRect_010.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=6ea461e71f7fc80605818fbf493caa63 +REG_FIDDLE(IRect_010, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted.fTop: %d unsorted.y(): %d\n", unsorted.fTop, unsorted.y()); + SkIRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fTop: %d sorted.y(): %d\n", sorted.fTop, sorted.y()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_011.cpp b/docs/examples/IRect_011.cpp new file mode 100644 index 0000000000..47698483b6 --- /dev/null +++ b/docs/examples/IRect_011.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=4acfbe051805940210c8916a94794142 +REG_FIDDLE(IRect_011, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted width: %d\n", unsorted.width()); + SkIRect large = { -2147483647, 1, 2147483644, 2 }; + SkDebugf("large width: %d\n", large.width()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_012.cpp b/docs/examples/IRect_012.cpp new file mode 100644 index 0000000000..98dcceef4c --- /dev/null +++ b/docs/examples/IRect_012.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=63977f97999bbd6eecfdcc7575d75492 +REG_FIDDLE(IRect_012, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect large = { -2147483647, 1, 2147483644, 2 }; + SkDebugf("width: %d width64: %lld\n", large.width(), large.width64()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_013.cpp b/docs/examples/IRect_013.cpp new file mode 100644 index 0000000000..adfc509702 --- /dev/null +++ b/docs/examples/IRect_013.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=0175bae87fafcd9433ae661574695586 +REG_FIDDLE(IRect_013, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect unsorted = { 15, 25, 10, 20 }; + SkDebugf("unsorted height: %d\n", unsorted.height()); + SkIRect large = { 1, -2147483647, 2, 2147483644 }; + SkDebugf("large height: %d\n", large.height()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_014.cpp b/docs/examples/IRect_014.cpp new file mode 100644 index 0000000000..1bf700be98 --- /dev/null +++ b/docs/examples/IRect_014.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=02dd98716e54bbd8c2f0ff23b7ef98cf +REG_FIDDLE(IRect_014, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect large = { 1, -2147483647, 2, 2147483644 }; + SkDebugf("height: %d height64: %lld\n", large.height(), large.height64()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_015.cpp b/docs/examples/IRect_015.cpp new file mode 100644 index 0000000000..d0138f5e00 --- /dev/null +++ b/docs/examples/IRect_015.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=8b3224641cb3053a7b8a5798b6cd1cf6 +REG_FIDDLE(IRect_015, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkIRect& rect) -> void { + SkISize size = rect.size(); + SkDebugf("%s ", prefix); + SkDebugf("rect: %d, %d, %d, %d ", rect.left(), rect.top(), rect.right(), rect.bottom()); + SkDebugf("size: %d, %d\n", size.width(), size.height()); + }; + SkIRect rect = {20, 30, 40, 50}; + debugster("original", rect); + rect.offset(20, 20); + debugster(" offset", rect); + rect.outset(20, 20); + debugster(" outset", rect); +} +} // END FIDDLE diff --git a/docs/examples/IRect_016.cpp b/docs/examples/IRect_016.cpp new file mode 100644 index 0000000000..a0b5d0278a --- /dev/null +++ b/docs/examples/IRect_016.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=edaad064b6de249b7a7c768dfa000adc +REG_FIDDLE(IRect_016, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; + for (auto rect : tests) { + SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "" : " not"); + rect.sort(); + SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "" : " not"); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_017.cpp b/docs/examples/IRect_017.cpp new file mode 100644 index 0000000000..a2c2a4160f --- /dev/null +++ b/docs/examples/IRect_017.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=eb905faa1084ccab3ad0605df4c27ea4 +REG_FIDDLE(IRect_017, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; + for (auto rect : tests) { + SkDebugf("rect: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty64() ? "" : " not"); + rect.sort(); + SkDebugf("sorted: {%d, %d, %d, %d} is" "%s empty\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty64() ? "" : " not"); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_018.cpp b/docs/examples/IRect_018.cpp new file mode 100644 index 0000000000..2c9bd89c21 --- /dev/null +++ b/docs/examples/IRect_018.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=bd8f028d9051062816c9116fea4237b2 +REG_FIDDLE(IRect_018, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect test = {0, 0, 2, 2}; + SkIRect sorted = test.makeSorted(); + SkDebugf("test %c= sorted\n", test == sorted ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/IRect_019.cpp b/docs/examples/IRect_019.cpp new file mode 100644 index 0000000000..144a4b4a34 --- /dev/null +++ b/docs/examples/IRect_019.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=6c4acd8aa203f632b7d85cae672abf4d +REG_FIDDLE(IRect_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect test = {2, 2, 0, 0}; + SkIRect sorted = test.makeSorted(); + SkDebugf("test %c= sorted\n", test != sorted ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/IRect_020.cpp b/docs/examples/IRect_020.cpp new file mode 100644 index 0000000000..a42cf95a8d --- /dev/null +++ b/docs/examples/IRect_020.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=94039c3cc9e911c8ab2993d56fd06210 +REG_FIDDLE(IRect_020, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = {3, 4, 1, 2}; + for (int i = 0; i < 2; ++i) { + SkDebugf("rect: {%d, %d, %d, %d} is %s" "empty\n", rect.fLeft, rect.fTop, + rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not "); + rect.setEmpty(); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_021.cpp b/docs/examples/IRect_021.cpp new file mode 100644 index 0000000000..094ec317cf --- /dev/null +++ b/docs/examples/IRect_021.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=1912c37076b7f3bf6aebfa167e971bec +REG_FIDDLE(IRect_021, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect1 = {3, 4, 1, 2}; + SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); + SkIRect rect2; + rect2.set(3, 4, 1, 2); + SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_022.cpp b/docs/examples/IRect_022.cpp new file mode 100644 index 0000000000..8a4a284946 --- /dev/null +++ b/docs/examples/IRect_022.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=ead6bdcf2ae77ec19a1c5a96f5b31af8 +REG_FIDDLE(IRect_022, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect1 = {3, 4, 1, 2}; + SkDebugf("rect1: {%d, %d, %d, %d}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); + SkIRect rect2; + rect2.setLTRB(3, 4, 1, 2); + SkDebugf("rect2: {%d, %d, %d, %d}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_023.cpp b/docs/examples/IRect_023.cpp new file mode 100644 index 0000000000..5ab3100688 --- /dev/null +++ b/docs/examples/IRect_023.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=0e1db8c86678c004e504f47641b44b17 +REG_FIDDLE(IRect_023, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect; + rect.setXYWH(5, 35, -15, 25); + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect.sort(); + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/IRect_024.cpp b/docs/examples/IRect_024.cpp new file mode 100644 index 0000000000..6faab142df --- /dev/null +++ b/docs/examples/IRect_024.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=737c747df07ddf392c05970440de0927 +REG_FIDDLE(IRect_024, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 50, 20, 60 }; + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect = rect.makeOffset(15, 32); + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/IRect_025.cpp b/docs/examples/IRect_025.cpp new file mode 100644 index 0000000000..07c19be359 --- /dev/null +++ b/docs/examples/IRect_025.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=1db94b2c76e0a7a71856532335fa56b6 +REG_FIDDLE(IRect_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 50, 20, 60 }; + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect = rect.makeInset(15, 32); + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/IRect_026.cpp b/docs/examples/IRect_026.cpp new file mode 100644 index 0000000000..09d1e6ccbb --- /dev/null +++ b/docs/examples/IRect_026.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=240e2953e3455c08f6d89255feff8416 +REG_FIDDLE(IRect_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 50, 20, 60 }; + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect = rect.makeOutset(15, 32); + SkDebugf("rect: %d, %d, %d, %d isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/IRect_027.cpp b/docs/examples/IRect_027.cpp new file mode 100644 index 0000000000..cfb1e941ea --- /dev/null +++ b/docs/examples/IRect_027.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=77e633b2174ffae923c038b303418b50 +REG_FIDDLE(IRect_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 14, 50, 73 }; + rect.offset(5, 13); + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_028.cpp b/docs/examples/IRect_028.cpp new file mode 100644 index 0000000000..202ef37221 --- /dev/null +++ b/docs/examples/IRect_028.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=31a4c575499e76def651eb65994876f0 +REG_FIDDLE(IRect_028, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 14, 50, 73 }; + rect.offset({5, 13}); + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_029.cpp b/docs/examples/IRect_029.cpp new file mode 100644 index 0000000000..1e7777b0aa --- /dev/null +++ b/docs/examples/IRect_029.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=a2734ff23b35653956a3002e5c29ff91 +REG_FIDDLE(IRect_029, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 14, 50, 73 }; + rect.offsetTo(15, 27); + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_030.cpp b/docs/examples/IRect_030.cpp new file mode 100644 index 0000000000..4c0cbca75f --- /dev/null +++ b/docs/examples/IRect_030.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=9debaded1aa8bdf5077a4de0b3015b8f +REG_FIDDLE(IRect_030, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 14, 50, 73 }; + rect.inset(5, 13); + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_031.cpp b/docs/examples/IRect_031.cpp new file mode 100644 index 0000000000..bd4d7f72a7 --- /dev/null +++ b/docs/examples/IRect_031.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=3fc62ca29428195f33a3a02b3eb74e4f +REG_FIDDLE(IRect_031, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 14, 50, 73 }; + rect.outset(5, 13); + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_032.cpp b/docs/examples/IRect_032.cpp new file mode 100644 index 0000000000..c0865711a6 --- /dev/null +++ b/docs/examples/IRect_032.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=8dc91284493dd012cca3d0ce4c66bda4 +REG_FIDDLE(IRect_032, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 8, 11, 19, 22 }; + rect.adjust(2, -1, 1, -2); + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_033.cpp b/docs/examples/IRect_033.cpp new file mode 100644 index 0000000000..13b17d176f --- /dev/null +++ b/docs/examples/IRect_033.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=a7958a4e0668f5cf805a8e78eb57f51d +REG_FIDDLE(IRect_033, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 30, 50, 40, 60 }; + SkIPoint pts[] = { { 30, 50}, { 40, 50}, { 30, 60} }; + for (auto pt : pts) { + SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d)\n", + rect.left(), rect.top(), rect.right(), rect.bottom(), + rect.contains(pt.x(), pt.y()) ? "contains" : "does not contain", pt.x(), pt.y()); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_034.cpp b/docs/examples/IRect_034.cpp new file mode 100644 index 0000000000..794d4b34ca --- /dev/null +++ b/docs/examples/IRect_034.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=eae55f284818d9965ec5834747d14a48 +REG_FIDDLE(IRect_034, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 30, 50, 40, 60 }; + SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; + for (auto contained : tests) { + bool success = rect.contains( + contained.left(), contained.top(), contained.right(), contained.bottom()); + SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", + rect.left(), rect.top(), rect.right(), rect.bottom(), + success ? "contains" : "does not contain", + contained.left(), contained.top(), contained.right(), contained.bottom()); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_035.cpp b/docs/examples/IRect_035.cpp new file mode 100644 index 0000000000..0c4cb4fc1d --- /dev/null +++ b/docs/examples/IRect_035.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=ee0185db622602b4eb19583c2f42c734 +REG_FIDDLE(IRect_035, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 30, 50, 40, 60 }; + SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; + for (auto contained : tests) { + SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", + rect.left(), rect.top(), rect.right(), rect.bottom(), + rect.contains(contained) ? "contains" : "does not contain", + contained.left(), contained.top(), contained.right(), contained.bottom()); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_036.cpp b/docs/examples/IRect_036.cpp new file mode 100644 index 0000000000..64cc462e63 --- /dev/null +++ b/docs/examples/IRect_036.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=acbd79ffb304f332e4b38ef18e19663e +REG_FIDDLE(IRect_036, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 30, 50, 40, 60 }; + SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; + for (auto contained : tests) { + SkDebugf("rect: (%d, %d, %d, %d) %s (%g, %g, %g, %g)\n", + rect.left(), rect.top(), rect.right(), rect.bottom(), + rect.contains(contained) ? "contains" : "does not contain", + contained.left(), contained.top(), contained.right(), contained.bottom()); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_037.cpp b/docs/examples/IRect_037.cpp new file mode 100644 index 0000000000..cb6ab2f9a4 --- /dev/null +++ b/docs/examples/IRect_037.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=fef2a36bee224e92500199fa9d3cbb8b +REG_FIDDLE(IRect_037, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 30, 50, 40, 60 }; + SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; + for (auto contained : tests) { + bool success = rect.containsNoEmptyCheck( + contained.left(), contained.top(), contained.right(), contained.bottom()); + SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", + rect.left(), rect.top(), rect.right(), rect.bottom(), + success ? "contains" : "does not contain", + contained.left(), contained.top(), contained.right(), contained.bottom()); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_038.cpp b/docs/examples/IRect_038.cpp new file mode 100644 index 0000000000..4faaf273ad --- /dev/null +++ b/docs/examples/IRect_038.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=8f91f58001d9c10420eb146fbc169af4 +REG_FIDDLE(IRect_038, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 30, 50, 40, 60 }; + SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; + for (auto contained : tests) { + SkDebugf("rect: (%d, %d, %d, %d) %s (%d, %d, %d, %d)\n", + rect.left(), rect.top(), rect.right(), rect.bottom(), + rect.containsNoEmptyCheck(contained) ? "contains" : "does not contain", + contained.left(), contained.top(), contained.right(), contained.bottom()); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_039.cpp b/docs/examples/IRect_039.cpp new file mode 100644 index 0000000000..29a7d16dfe --- /dev/null +++ b/docs/examples/IRect_039.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=ea233f5d5d1ae0e76fc6f2eb371c927a +REG_FIDDLE(IRect_039, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect leftRect = { 10, 40, 50, 80 }; + SkIRect rightRect = { 30, 60, 70, 90 }; + SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no "); + SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(), + leftRect.right(), leftRect.bottom()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_040.cpp b/docs/examples/IRect_040.cpp new file mode 100644 index 0000000000..f65c06a707 --- /dev/null +++ b/docs/examples/IRect_040.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=b2db0573aacf99ca52776c5522459d02 +REG_FIDDLE(IRect_040, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect result; + bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 }); + SkDebugf("%s intersection: %d, %d, %d, %d\n", intersected ? "" : "no ", + result.left(), result.top(), result.right(), result.bottom()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_041.cpp b/docs/examples/IRect_041.cpp new file mode 100644 index 0000000000..901d569824 --- /dev/null +++ b/docs/examples/IRect_041.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=d35fbc9fdea71df8b8a12fd3da50d11c +REG_FIDDLE(IRect_041, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect result; + if (result.intersectNoEmptyCheck({ 10, 40, 50, 80 }, { 30, 60, 70, 90 })) { + SkDebugf("intersection: %d, %d, %d, %d\n", + result.left(), result.top(), result.right(), result.bottom()); + } +} +} // END FIDDLE diff --git a/docs/examples/IRect_042.cpp b/docs/examples/IRect_042.cpp new file mode 100644 index 0000000000..609964eff6 --- /dev/null +++ b/docs/examples/IRect_042.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=200422990eded2f754ab9893118f2645 +REG_FIDDLE(IRect_042, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect leftRect = { 10, 40, 50, 80 }; + SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no "); + SkDebugf("%d, %d, %d, %d\n", leftRect.left(), leftRect.top(), + leftRect.right(), leftRect.bottom()); +} +} // END FIDDLE diff --git a/docs/examples/IRect_043.cpp b/docs/examples/IRect_043.cpp new file mode 100644 index 0000000000..299df667d6 --- /dev/null +++ b/docs/examples/IRect_043.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=0c67cf8981389efc7108369fb9b7976b +REG_FIDDLE(IRect_043, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("%s intersection", SkIRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no "); +} +} // END FIDDLE diff --git a/docs/examples/IRect_044.cpp b/docs/examples/IRect_044.cpp new file mode 100644 index 0000000000..5aafdd3cd7 --- /dev/null +++ b/docs/examples/IRect_044.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=dba234d15162fb5b26e1a96529ca6a2a +REG_FIDDLE(IRect_044, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("%s intersection", SkIRect::IntersectsNoEmptyCheck( + {10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no "); +} +} // END FIDDLE diff --git a/docs/examples/IRect_045.cpp b/docs/examples/IRect_045.cpp new file mode 100644 index 0000000000..0d1ea1ff0e --- /dev/null +++ b/docs/examples/IRect_045.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=c00ef06289d21db70340e465690e0e08 +REG_FIDDLE(IRect_045, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 20, 15, 25}; + rect.join(50, 60, 55, 65); + SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_046.cpp b/docs/examples/IRect_046.cpp new file mode 100644 index 0000000000..55e03c09cd --- /dev/null +++ b/docs/examples/IRect_046.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=75fd81c1d3512e63890d085593018876 +REG_FIDDLE(IRect_046, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 10, 20, 15, 25}; + rect.join({50, 60, 55, 65}); + SkDebugf("join: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_047.cpp b/docs/examples/IRect_047.cpp new file mode 100644 index 0000000000..a5892abe66 --- /dev/null +++ b/docs/examples/IRect_047.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=fa12547fcfd4c1aef3db1a1f6aae0fe4 +REG_FIDDLE(IRect_047, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 30, 50, 20, 10 }; + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + rect.sort(); + SkDebugf("sorted: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_048.cpp b/docs/examples/IRect_048.cpp new file mode 100644 index 0000000000..69633ded08 --- /dev/null +++ b/docs/examples/IRect_048.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=de89926c374aa16427916900b89a3441 +REG_FIDDLE(IRect_048, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect rect = { 30, 50, 20, 10 }; + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + SkIRect sort = rect.makeSorted(); + SkDebugf("sorted: %d, %d, %d, %d\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/IRect_049.cpp b/docs/examples/IRect_049.cpp new file mode 100644 index 0000000000..14f1917dbe --- /dev/null +++ b/docs/examples/IRect_049.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=65e0b9b52e907902630577941fb3ed6d +REG_FIDDLE(IRect_049, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const SkIRect& rect = SkIRect::EmptyIRect(); + SkDebugf("rect: %d, %d, %d, %d\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_000.cpp b/docs/examples/ImageInfo_000.cpp new file mode 100644 index 0000000000..9591910aad --- /dev/null +++ b/docs/examples/ImageInfo_000.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=79146a1a41d58d22582fdc567c6ffe4e +REG_FIDDLE(ImageInfo_000, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPMColor color = SkPreMultiplyARGB(255, 50, 100, 150); + SkString s; + s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color), + SkColorGetG(color), SkColorGetB(color)); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString(s, 10, 62, paint); + canvas->scale(50, 50); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kOpaque_SkAlphaType); + if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) { + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_001.cpp b/docs/examples/ImageInfo_001.cpp new file mode 100644 index 0000000000..9b631501b8 --- /dev/null +++ b/docs/examples/ImageInfo_001.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=ad696b39c915803d566e96896ec3a36c +REG_FIDDLE(ImageInfo_001, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPMColor color = SkPreMultiplyARGB(150, 50, 100, 150); + SkString s; + s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color), + SkColorGetG(color), SkColorGetB(color)); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString(s, 10, 62, paint); + canvas->scale(50, 50); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kPremul_SkAlphaType); + if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) { + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_002.cpp b/docs/examples/ImageInfo_002.cpp new file mode 100644 index 0000000000..c80bb14ca9 --- /dev/null +++ b/docs/examples/ImageInfo_002.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=b8216a9e5ff5bc61a0e46eba7d36307b +REG_FIDDLE(ImageInfo_002, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkColor color = SkColorSetARGB(150, 50, 100, 255); + SkString s; + s.printf("%u %u %u %u", SkColorGetA(color), SkColorGetR(color), + SkColorGetG(color), SkColorGetB(color)); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString(s, 10, 62, paint); + canvas->scale(50, 50); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(1, 1, kN32_SkColorType, kUnpremul_SkAlphaType); + if (bitmap.installPixels(imageInfo, (void*) &color, imageInfo.minRowBytes())) { + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_003.cpp b/docs/examples/ImageInfo_003.cpp new file mode 100644 index 0000000000..b530ca2c5c --- /dev/null +++ b/docs/examples/ImageInfo_003.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=21ae21e4ce53d2018e042dd457997300 +REG_FIDDLE(ImageInfo_003, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kAlpha_8_SkColorType, kOpaque_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + SkPaint orangePaint; + orangePaint.setARGB(0xFF, 0xFF, 0xA5, 0x00); + canvas->drawBitmap(bitmap, 0, 0, &orangePaint); + uint8_t alpha8[] = { 0xFF, 0xBB, 0x77, 0x33 }; + SkPixmap alphaPixmap(imageInfo, &alpha8, imageInfo.minRowBytes()); + if (bitmap.writePixels(alphaPixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 2, 2, &orangePaint); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_004.cpp b/docs/examples/ImageInfo_004.cpp new file mode 100644 index 0000000000..58e263da0a --- /dev/null +++ b/docs/examples/ImageInfo_004.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=7e7c46bb4572e21e13529ff364eb0a9c +REG_FIDDLE(ImageInfo_004, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_565_SkColorType, kOpaque_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 0, 0); + auto pack565 = [](unsigned r, unsigned g, unsigned b) -> uint16_t { + return (b << 0) | (g << 5) | (r << 11); + }; + uint16_t red565[] = { pack565(0x1F, 0x00, 0x00), pack565(0x17, 0x00, 0x00), + pack565(0x0F, 0x00, 0x00), pack565(0x07, 0x00, 0x00) }; + uint16_t blue565[] = { pack565(0x00, 0x00, 0x1F), pack565(0x00, 0x00, 0x17), + pack565(0x00, 0x00, 0x0F), pack565(0x00, 0x00, 0x07) }; + SkPixmap redPixmap(imageInfo, &red565, imageInfo.minRowBytes()); + if (bitmap.writePixels(redPixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 2, 2); + } + SkPixmap bluePixmap(imageInfo, &blue565, imageInfo.minRowBytes()); + if (bitmap.writePixels(bluePixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 4, 4); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_005.cpp b/docs/examples/ImageInfo_005.cpp new file mode 100644 index 0000000000..4278eaf6db --- /dev/null +++ b/docs/examples/ImageInfo_005.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=33a360c3404ac21db801943336843d8e +REG_FIDDLE(ImageInfo_005, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kARGB_4444_SkColorType, kPremul_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 0, 0); + auto pack4444 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint16_t { + return (a << 0) | (b << 4) | (g << 8) | (r << 12); + }; + uint16_t red4444[] = { pack4444(0xF, 0xF, 0x0, 0x0), pack4444(0xF, 0xb, 0x0, 0x0), + pack4444(0xF, 0x7, 0x0, 0x0), pack4444(0xF, 0x3, 0x0, 0x0) }; + uint16_t blue4444[] = { pack4444(0xF, 0x0, 0x0, 0xF), pack4444(0xF, 0x0, 0x0, 0xb), + pack4444(0xF, 0x0, 0x0, 0x7), pack4444(0xF, 0x0, 0x0, 0x3) }; + SkPixmap redPixmap(imageInfo, &red4444, imageInfo.minRowBytes()); + if (bitmap.writePixels(redPixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 2, 2); + } + SkPixmap bluePixmap(imageInfo, &blue4444, imageInfo.minRowBytes()); + if (bitmap.writePixels(bluePixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 4, 4); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_006.cpp b/docs/examples/ImageInfo_006.cpp new file mode 100644 index 0000000000..740b9a16a0 --- /dev/null +++ b/docs/examples/ImageInfo_006.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=947922a19d59893fe7f9d9ee1954379b +REG_FIDDLE(ImageInfo_006, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 0, 0); + auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t { + return (r << 0) | (g << 8) | (b << 16) | (a << 24); + }; + uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0), + pack8888(0xFF, 0x77, 0x0, 0x0), pack8888(0xFF, 0x33, 0x0, 0x0) }; + uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb), + pack8888(0xFF, 0x0, 0x0, 0x077), pack8888(0xFF, 0x0, 0x0, 0x033) }; + SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes()); + if (bitmap.writePixels(redPixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 2, 2); + } + SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes()); + if (bitmap.writePixels(bluePixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 4, 4); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_007.cpp b/docs/examples/ImageInfo_007.cpp new file mode 100644 index 0000000000..dd21616c4b --- /dev/null +++ b/docs/examples/ImageInfo_007.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=4260d6cc15db2c60c07f6fdc8d9ae425 +REG_FIDDLE(ImageInfo_007, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_888x_SkColorType, kOpaque_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 0, 0); + auto pack888 = [](unsigned r, unsigned g, unsigned b) -> uint32_t { + return (r << 0) | (g << 8) | (b << 16); + }; + uint32_t red888[] = { pack888(0xFF, 0x00, 0x00), pack888(0xbb, 0x00, 0x00), + pack888(0x77, 0x00, 0x00), pack888(0x33, 0x00, 0x00) }; + uint32_t blue888[] = { pack888(0x00, 0x00, 0xFF), pack888(0x00, 0x00, 0xbb), + pack888(0x00, 0x00, 0x77), pack888(0x00, 0x00, 0x33) }; + if (bitmap.installPixels(imageInfo, (void*) red888, imageInfo.minRowBytes())) { + canvas->drawBitmap(bitmap, 2, 2); + } + if (bitmap.installPixels(imageInfo, (void*) blue888, imageInfo.minRowBytes())) { + canvas->drawBitmap(bitmap, 4, 4); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_008.cpp b/docs/examples/ImageInfo_008.cpp new file mode 100644 index 0000000000..f8a6b588d7 --- /dev/null +++ b/docs/examples/ImageInfo_008.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=945ce5344fce5470f8604b2e06e9f9ae +REG_FIDDLE(ImageInfo_008, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kBGRA_8888_SkColorType, kPremul_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 0, 0); + auto pack8888 = [](unsigned a, unsigned r, unsigned g, unsigned b) -> uint32_t { + return (b << 0) | (g << 8) | (r << 16) | (a << 24); + }; + uint32_t red8888[] = { pack8888(0xFF, 0xFF, 0x0, 0x0), pack8888(0xFF, 0xbb, 0x0, 0x0), + pack8888(0xFF, 0x99, 0x0, 0x0), pack8888(0xFF, 0x55, 0x0, 0x0) }; + uint32_t blue8888[] = { pack8888(0xFF, 0x0, 0x0, 0x0FF), pack8888(0xFF, 0x0, 0x0, 0x0bb), + pack8888(0xFF, 0x0, 0x0, 0x099), pack8888(0xFF, 0x0, 0x0, 0x055) }; + SkPixmap redPixmap(imageInfo, &red8888, imageInfo.minRowBytes()); + if (bitmap.writePixels(redPixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 2, 2); + } + SkPixmap bluePixmap(imageInfo, &blue8888, imageInfo.minRowBytes()); + if (bitmap.writePixels(bluePixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 4, 4); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_009.cpp b/docs/examples/ImageInfo_009.cpp new file mode 100644 index 0000000000..e36509f8d0 --- /dev/null +++ b/docs/examples/ImageInfo_009.cpp @@ -0,0 +1,33 @@ +// 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 "fiddle/examples.h" +// HASH=1282dc1127ce1b0061544619ae4de0f0 +REG_FIDDLE(ImageInfo_009, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_1010102_SkColorType, kOpaque_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 0, 0); + auto pack1010102 = [](unsigned r, unsigned g, unsigned b, unsigned a) -> uint32_t { + return (r << 0) | (g << 10) | (b << 20) | (a << 30); + }; + uint32_t redBits[] = { pack1010102(0x3FF, 0x000, 0x000, 0x3), + pack1010102(0x2ff, 0x000, 0x000, 0x3), + pack1010102(0x1ff, 0x000, 0x000, 0x3), + pack1010102(0x0ff, 0x000, 0x000, 0x3) }; + uint32_t blueBits[] = { pack1010102(0x000, 0x000, 0x3FF, 0x3), + pack1010102(0x000, 0x000, 0x2ff, 0x3), + pack1010102(0x000, 0x000, 0x1ff, 0x3), + pack1010102(0x000, 0x000, 0x0ff, 0x3) }; + if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) { + canvas->drawBitmap(bitmap, 2, 2); + } + SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes()); + if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) { + canvas->drawBitmap(bitmap, 4, 4); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_010.cpp b/docs/examples/ImageInfo_010.cpp new file mode 100644 index 0000000000..fbcc19ab4e --- /dev/null +++ b/docs/examples/ImageInfo_010.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=92f81aa0459230459600a01e79ccff29 +REG_FIDDLE(ImageInfo_010, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGB_101010x_SkColorType, kOpaque_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 0, 0); + auto pack101010x = [](unsigned r, unsigned g, unsigned b) -> uint32_t { + return (r << 0) | (g << 10) | (b << 20); + }; + uint32_t redBits[] = { pack101010x(0x3FF, 0x000, 0x000), pack101010x(0x2ff, 0x000, 0x000), + pack101010x(0x1ff, 0x000, 0x000), pack101010x(0x0ff, 0x000, 0x000) }; + uint32_t blueBits[] = { pack101010x(0x000, 0x000, 0x3FF), pack101010x(0x000, 0x000, 0x2ff), + pack101010x(0x000, 0x000, 0x1ff), pack101010x(0x000, 0x000, 0x0ff) }; + if (bitmap.installPixels(imageInfo, (void*) redBits, imageInfo.minRowBytes())) { + canvas->drawBitmap(bitmap, 2, 2); + } + SkPixmap bluePixmap(imageInfo, &blueBits, imageInfo.minRowBytes()); + if (bitmap.installPixels(imageInfo, (void*) blueBits, imageInfo.minRowBytes())) { + canvas->drawBitmap(bitmap, 4, 4); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_011.cpp b/docs/examples/ImageInfo_011.cpp new file mode 100644 index 0000000000..0d54ca4278 --- /dev/null +++ b/docs/examples/ImageInfo_011.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=93da0eb0b6722a4f33dc7dae094abf0b +REG_FIDDLE(ImageInfo_011, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kGray_8_SkColorType, kOpaque_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 0, 0); + uint8_t gray8[] = { 0xFF, 0xBB, 0x77, 0x33 }; + SkPixmap grayPixmap(imageInfo, &gray8, imageInfo.minRowBytes()); + if (bitmap.writePixels(grayPixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 2, 2); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_012.cpp b/docs/examples/ImageInfo_012.cpp new file mode 100644 index 0000000000..0ab5ee3f69 --- /dev/null +++ b/docs/examples/ImageInfo_012.cpp @@ -0,0 +1,52 @@ +// 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 "fiddle/examples.h" +// HASH=dd81527bbdf5eaae7dd21ac04ab84f9e +REG_FIDDLE(ImageInfo_012, 256, 96, false, 0) { +union FloatUIntUnion { + uint32_t fUInt; + float fFloat; +}; +uint16_t FloatToHalf(float f) { + static const FloatUIntUnion magic = { 15 << 23 }; + static const uint32_t round_mask = ~0xfffu; + FloatUIntUnion floatUnion; + floatUnion.fFloat = f; + uint32_t sign = floatUnion.fUInt & 0x80000000u; + floatUnion.fUInt ^= sign; + floatUnion.fUInt &= round_mask; + floatUnion.fFloat *= magic.fFloat; + floatUnion.fUInt -= round_mask; + return (floatUnion.fUInt >> 13) | (sign >> 16); +} + +void draw(SkCanvas* canvas) { + canvas->scale(16, 16); + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(2, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType); + bitmap.allocPixels(imageInfo); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorGREEN); + canvas->drawBitmap(bitmap, 0, 0); + auto H = [](float c) -> uint16_t { + return FloatToHalf(c); + }; + // R G B A + uint16_t red_f16[][4] = { { H(1.0), H(0.0), H(0.0), H(1.0) }, + { H(.75), H(0.0), H(0.0), H(1.0) }, + { H(.50), H(0.0), H(0.0), H(1.0) }, + { H(.25), H(0.0), H(0.0), H(1.0) } }; + uint16_t blue_f16[][4] = { { H(0.0), H(0.0), H(1.0), H(1.0) }, + { H(0.0), H(0.0), H(.75), H(1.0) }, + { H(0.0), H(0.0), H(.50), H(1.0) }, + { H(0.0), H(0.0), H(.25), H(1.0) } }; + SkPixmap redPixmap(imageInfo, red_f16, imageInfo.minRowBytes()); + if (bitmap.writePixels(redPixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 2, 2); + } + SkPixmap bluePixmap(imageInfo, blue_f16, imageInfo.minRowBytes()); + if (bitmap.writePixels(bluePixmap, 0, 0)) { + canvas->drawBitmap(bitmap, 4, 4); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_013.cpp b/docs/examples/ImageInfo_013.cpp new file mode 100644 index 0000000000..88c2c26e72 --- /dev/null +++ b/docs/examples/ImageInfo_013.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=09ef49d07cb7005ba3e34d5ea53896f5 +REG_FIDDLE(ImageInfo_013, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16" }; + SkPaint paint; + SkFont font(SkTypeface::MakeFromName("monospace", SkFontStyle()), 10); + int y = 15; + canvas->drawString(" colorType bytes", 10, y, font, paint); + for (SkColorType colorType : { + kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, + kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, + kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType + } ) { + int result = SkColorTypeBytesPerPixel(colorType); + SkString string; + string.printf("%13s %4d", colors[(int) colorType], result); + canvas->drawString(string, 10, y += 14, font, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_014.cpp b/docs/examples/ImageInfo_014.cpp new file mode 100644 index 0000000000..b77f235d43 --- /dev/null +++ b/docs/examples/ImageInfo_014.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=9b3eb5aaa0dfea9feee54e7650fa5446 +REG_FIDDLE(ImageInfo_014, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16" }; + SkPaint paint; + SkFont font(SkTypeface::MakeFromName("monospace", SkFontStyle()), 10); + int y = 15; + canvas->drawString(" colorType bytes", 10, y, font, paint); + for (SkColorType colorType : { + kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, + kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, + kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType + } ) { + bool result = SkColorTypeIsAlwaysOpaque(colorType); + SkString string; + string.printf("%13s %6s", colors[(int) colorType], result ? "true" : "false"); + canvas->drawString(string, 10, y += 14, font, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_015.cpp b/docs/examples/ImageInfo_015.cpp new file mode 100644 index 0000000000..9048824427 --- /dev/null +++ b/docs/examples/ImageInfo_015.cpp @@ -0,0 +1,34 @@ +// 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 "fiddle/examples.h" +// HASH=befac1c29ed21507d367e4d824383a04 +REG_FIDDLE(ImageInfo_015, 256, 640, false, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16" }; + const char* alphas[] = {"Unknown ", "Opaque ", "Premul ", "Unpremul"}; + SkAlphaType alphaTypes[] = { kUnknown_SkAlphaType, kOpaque_SkAlphaType, kPremul_SkAlphaType, + kUnpremul_SkAlphaType + }; + SkPaint paint; + SkFont font(SkTypeface::MakeFromName("monospace", SkFontStyle()), 10); + int y = 15; + canvas->drawString(" colorType alphaType canonical", 10, y, font, paint); + for (SkColorType colorType : { + kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, + kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, + kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType + } ) { + for (SkAlphaType alphaType : alphaTypes) { + SkAlphaType canonicalAlphaType = kUnknown_SkAlphaType; + bool result = SkColorTypeValidateAlphaType(colorType, alphaType, &canonicalAlphaType); + SkString string; + string.printf("%13s %10s %10s", colors[(int) colorType], alphas[(int) alphaType], + result ? alphas[(int) canonicalAlphaType] : "------ "); + canvas->drawString(string, 10, y += 14, font, paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_016.cpp b/docs/examples/ImageInfo_016.cpp new file mode 100644 index 0000000000..b26855cd61 --- /dev/null +++ b/docs/examples/ImageInfo_016.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=f206f698e7a8db3d84334c26b1a702dc +REG_FIDDLE(ImageInfo_016, 256, 32, false, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo imageInfo; + size_t rowBytes; + SkIPoint origin; + (void) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin); + const char* alphaType[] = { "Unknown", "Opaque", "Premul", "Unpremul" }; + SkString string; + string.printf("k%s_SkAlphaType", alphaType[(int) imageInfo.alphaType()]); + SkPaint paint; + canvas->drawString(string, 20, 20, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_017.cpp b/docs/examples/ImageInfo_017.cpp new file mode 100644 index 0000000000..6f19b5ef3f --- /dev/null +++ b/docs/examples/ImageInfo_017.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=9f47f9c2a99473f5b1113db48096d586 +REG_FIDDLE(ImageInfo_017, 256, 48, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, + { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, + { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, + { 0x90, 0x81, 0xC5, 0x71, 0x33 }, + { 0x75, 0x55, 0x44, 0x40, 0x30 }}; + SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); + SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->scale(8, 8); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_018.cpp b/docs/examples/ImageInfo_018.cpp new file mode 100644 index 0000000000..c6f081abfb --- /dev/null +++ b/docs/examples/ImageInfo_018.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=78cea0c4cac205b61ad6f6c982cbd888 +REG_FIDDLE(ImageInfo_018, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType)); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorWHITE); + SkPaint paint; + offscreen.drawString("g", 0, 10, paint); + canvas->scale(8, 8); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_019.cpp b/docs/examples/ImageInfo_019.cpp new file mode 100644 index 0000000000..fe4e74eb75 --- /dev/null +++ b/docs/examples/ImageInfo_019.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=de418ccb42471d1589508ef3955f8c53 +REG_FIDDLE(ImageInfo_019, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + const int width = 256; + const int height = 32; + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + SkColor gradColors[] = { 0xFFAA0055, 0xFF11CC88 }; + SkPoint gradPoints[] = { { 0, 0 }, { width, 0 } }; + SkPaint gradPaint; + gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, + SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType)); + SkCanvas offScreen(bitmap); + offScreen.drawRect(SkRect::MakeWH(width, height), gradPaint); + canvas->drawBitmap(bitmap, 0, 0); + bitmap.allocPixels(SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType)); + SkCanvas sRGBOffscreen(bitmap); + sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint); + canvas->drawBitmap(bitmap, 0, 48); + SkBitmap noColorSpaceBitmap; + noColorSpaceBitmap.setInfo(SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType)); + noColorSpaceBitmap.setPixels(bitmap.getAddr(0, 0)); + canvas->drawBitmap(noColorSpaceBitmap, 0, 96); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_020.cpp b/docs/examples/ImageInfo_020.cpp new file mode 100644 index 0000000000..87c6f763fe --- /dev/null +++ b/docs/examples/ImageInfo_020.cpp @@ -0,0 +1,20 @@ +#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 "fiddle/examples.h" +// HASH=525650a67e19fdd8ca9f72b7eda65174 +REG_FIDDLE(ImageInfo_020, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(18, 18)); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorWHITE); + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(15); + offscreen.drawString("\xF0\x9F\x98\xB8", 1, 15, paint); + canvas->scale(6, 6); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_021.cpp b/docs/examples/ImageInfo_021.cpp new file mode 100644 index 0000000000..f16bf20b88 --- /dev/null +++ b/docs/examples/ImageInfo_021.cpp @@ -0,0 +1,20 @@ +#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 "fiddle/examples.h" +// HASH=b9026d7f39029756bd7cab9542c64f4e +REG_FIDDLE(ImageInfo_021, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul({18, 18})); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorWHITE); + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(15); + offscreen.drawString("\xF0\x9F\x98\xB9", 1, 15, paint); + canvas->scale(6, 6); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_022.cpp b/docs/examples/ImageInfo_022.cpp new file mode 100644 index 0000000000..1d6e02596a --- /dev/null +++ b/docs/examples/ImageInfo_022.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=547388991687b8e10d482d8b1c82777d +REG_FIDDLE(ImageInfo_022, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t pixels[][8] = { { 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00}, + { 0x00, 0x7f, 0xff, 0x3f, 0x3f, 0x7f, 0x3f, 0x00}, + { 0x3f, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f, 0x00}, + { 0x00, 0x3f, 0x00, 0x00, 0x3f, 0x7f, 0x3f, 0x00}, + { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x00, 0x00, 0x00}, + { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x3f, 0x7f, 0x3f}, + { 0x7f, 0xff, 0xff, 0x7f, 0x00, 0x7f, 0xff, 0x7f}, + { 0x3f, 0x7f, 0x7f, 0x3f, 0x00, 0x3f, 0x7f, 0x3f} }; + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeA8(8, 8), + (void*) pixels, sizeof(pixels[0])); + SkPaint paint; + canvas->scale(4, 4); + for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xFF007F00} ) { + paint.setColor(color); + canvas->drawBitmap(bitmap, 0, 0, &paint); + canvas->translate(12, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_023.cpp b/docs/examples/ImageInfo_023.cpp new file mode 100644 index 0000000000..8d3cc5cb91 --- /dev/null +++ b/docs/examples/ImageInfo_023.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=75f13a78b28b08c72baf32b7d868de1c +REG_FIDDLE(ImageInfo_023, 384, 32, false, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info; // default constructor + SkString string; + string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown(0, 0)", + info == SkImageInfo::MakeUnknown(0, 0) ? '=' : '!'); + SkPaint paint; + canvas->drawString(string, 0, 12, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_024.cpp b/docs/examples/ImageInfo_024.cpp new file mode 100644 index 0000000000..1eb2b6665d --- /dev/null +++ b/docs/examples/ImageInfo_024.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=a1af7696ae0cdd6f379546dd1f211b7a +REG_FIDDLE(ImageInfo_024, 384, 32, false, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info; // default constructor + SkString string; + string.printf("SkImageInfo() %c= SkImageInfo::MakeUnknown()", + info == SkImageInfo::MakeUnknown() ? '=' : '!'); + SkPaint paint; + canvas->drawString(string, 0, 12, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_025.cpp b/docs/examples/ImageInfo_025.cpp new file mode 100644 index 0000000000..69aad08a2a --- /dev/null +++ b/docs/examples/ImageInfo_025.cpp @@ -0,0 +1,17 @@ +#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 "fiddle/examples.h" +// HASH=e2491817695290d0218be77f091b8460 +REG_FIDDLE(ImageInfo_025, 256, 96, false, 4) { +void draw(SkCanvas* canvas) { + canvas->translate(10, 10); + canvas->drawBitmap(source, 0, 0); + SkImageInfo imageInfo = source.info(); + canvas->translate(0, imageInfo.height()); + SkPaint paint; + canvas->drawLine(0, 10, imageInfo.width(), 10, paint); + canvas->drawString("width", imageInfo.width() / 2 - 15, 25, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_026.cpp b/docs/examples/ImageInfo_026.cpp new file mode 100644 index 0000000000..019fc3a955 --- /dev/null +++ b/docs/examples/ImageInfo_026.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=72c35baaeddca1d912edf93d19429c8e +REG_FIDDLE(ImageInfo_026, 256, 96, false, 4) { +void draw(SkCanvas* canvas) { + canvas->translate(10, 20); + canvas->drawBitmap(source, 0, 0); + SkImageInfo imageInfo = source.info(); + SkPaint paint; + canvas->drawLine(imageInfo.width() + 10, 0, imageInfo.width() + 10, imageInfo.height(), paint); + canvas->drawString("height", imageInfo.width() + 15, imageInfo.height() / 2, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_027.cpp b/docs/examples/ImageInfo_027.cpp new file mode 100644 index 0000000000..a7e96ca82c --- /dev/null +++ b/docs/examples/ImageInfo_027.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=06ecc3ce7f35cc7f930cbc2a662e3105 +REG_FIDDLE(ImageInfo_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkImageInfo info = SkImageInfo::MakeA8(16, 32); + SkDebugf("color type: k" "%s" "_SkColorType\n", colors[info.colorType()]); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_028.cpp b/docs/examples/ImageInfo_028.cpp new file mode 100644 index 0000000000..6d7acd203c --- /dev/null +++ b/docs/examples/ImageInfo_028.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=5c1d2499a4056b6cff38c1cf924158a1 +REG_FIDDLE(ImageInfo_028, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + SkImageInfo info = SkImageInfo::MakeA8(16, 32); + SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[info.alphaType()]); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_029.cpp b/docs/examples/ImageInfo_029.cpp new file mode 100644 index 0000000000..c4c91894a7 --- /dev/null +++ b/docs/examples/ImageInfo_029.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=5602b816d7cf75e3851274ef36a4c10f +REG_FIDDLE(ImageInfo_029, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, + SkColorSpace::MakeSRGBLinear()); + SkColorSpace* colorSpace = info.colorSpace(); + SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", + colorSpace->gammaCloseToSRGB() ? "true" : "false", + colorSpace->gammaIsLinear() ? "true" : "false", + colorSpace->isSRGB() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_030.cpp b/docs/examples/ImageInfo_030.cpp new file mode 100644 index 0000000000..e342ae6617 --- /dev/null +++ b/docs/examples/ImageInfo_030.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=33f65524736736fd91802b4198ba6fa8 +REG_FIDDLE(ImageInfo_030, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info1 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, + SkColorSpace::MakeSRGBLinear()); + SkImageInfo info2 = SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, + info1.refColorSpace()); + SkColorSpace* colorSpace = info2.colorSpace(); + SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", + colorSpace->gammaCloseToSRGB() ? "true" : "false", + colorSpace->gammaIsLinear() ? "true" : "false", + colorSpace->isSRGB() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_031.cpp b/docs/examples/ImageInfo_031.cpp new file mode 100644 index 0000000000..4929b86493 --- /dev/null +++ b/docs/examples/ImageInfo_031.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=b8757200da5be0b43763cf79feb681a7 +REG_FIDDLE(ImageInfo_031, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + for (int width : { 0, 2 } ) { + for (int height : { 0, 2 } ) { + SkImageInfo imageInfo= SkImageInfo::MakeA8(width, height); + SkDebugf("width: %d height: %d empty: %s\n", width, height, + imageInfo.isEmpty() ? "true" : "false"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_032.cpp b/docs/examples/ImageInfo_032.cpp new file mode 100644 index 0000000000..fa130925be --- /dev/null +++ b/docs/examples/ImageInfo_032.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=e9bd4f02b6cfb3ac864cb7fee7d7299c +REG_FIDDLE(ImageInfo_032, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int height = 2; + const int width = 2; + SkBitmap bitmap; + SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); + bitmap.setInfo(imageInfo); + for (int index = 0; index < 2; ++index) { + bitmap.allocPixels(); + bitmap.eraseColor(0x00000000); + SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false"); + bitmap.eraseColor(0xFFFFFFFF); + SkDebugf("isOpaque: %s\n", imageInfo.isOpaque() ? "true" : "false"); + imageInfo = imageInfo.makeAlphaType(kOpaque_SkAlphaType); + bitmap.setInfo(imageInfo); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_033.cpp b/docs/examples/ImageInfo_033.cpp new file mode 100644 index 0000000000..b7dda33e9c --- /dev/null +++ b/docs/examples/ImageInfo_033.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=d5547cd2b302822aa85b7b0ae3f48458 +REG_FIDDLE(ImageInfo_033, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int height = 2; + const int width = 2; + SkImageInfo imageInfo = SkImageInfo::Make(width, height, kN32_SkColorType, kPremul_SkAlphaType); + SkISize dimensions = imageInfo.dimensions(); + SkIRect bounds = imageInfo.bounds(); + SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions); + SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_034.cpp b/docs/examples/ImageInfo_034.cpp new file mode 100644 index 0000000000..cf7954bf62 --- /dev/null +++ b/docs/examples/ImageInfo_034.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=a818be8945cd0c18f99ffe53e90afa48 +REG_FIDDLE(ImageInfo_034, 256, 64, false, 4) { +void draw(SkCanvas* canvas) { + canvas->scale(.5f, .5f); + SkImageInfo imageInfo = source.info(); + SkIRect bounds = imageInfo.bounds(); + for (int x : { 0, bounds.width() } ) { + for (int y : { 0, bounds.height() } ) { + canvas->drawBitmap(source, x, y); + } + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_035.cpp b/docs/examples/ImageInfo_035.cpp new file mode 100644 index 0000000000..d4a50994d0 --- /dev/null +++ b/docs/examples/ImageInfo_035.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=22df72732e898a11773fbfe07388a546 +REG_FIDDLE(ImageInfo_035, 256, 144, false, 0) { +void draw(SkCanvas* canvas) { + const int width = 256; + const int height = 64; + auto drawLabel = [=](const char* what, bool closeToSRGB) -> void { + SkString string; + string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not "); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString(string, 20, 56, paint); + }; + SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF }; + SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } }; + SkPaint gradPaint; + gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, + SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); + canvas->drawRect(SkRect::MakeWH(width, height), gradPaint); + drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB()); + SkBitmap bitmap; + SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType); + bitmap.allocPixels(offscreenInfo); + SkCanvas sRGBOffscreen(bitmap); + sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint); + canvas->translate(0, 80); + canvas->drawBitmap(bitmap, 0, 0); + drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_036.cpp b/docs/examples/ImageInfo_036.cpp new file mode 100644 index 0000000000..f86c157086 --- /dev/null +++ b/docs/examples/ImageInfo_036.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=cd203a3f9c5fb68272f21f302dd54fbc +REG_FIDDLE(ImageInfo_036, 256, 144, false, 3) { +void draw(SkCanvas* canvas) { + SkImageInfo canvasImageInfo = canvas->imageInfo(); + SkRect canvasBounds = SkRect::Make(canvasImageInfo.bounds()); + canvas->drawBitmapRect(source, source.bounds(), canvasBounds, nullptr); + SkImageInfo insetImageInfo = + canvasImageInfo.makeWH(canvasBounds.width() / 2, canvasBounds.height() / 2); + SkBitmap inset; + inset.allocPixels(insetImageInfo); + SkCanvas offscreen(inset); + offscreen.drawBitmapRect(source, source.bounds(), SkRect::Make(inset.bounds()), nullptr); + canvas->drawBitmap(inset, canvasBounds.width() / 4, canvasBounds.height() / 4); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_037.cpp b/docs/examples/ImageInfo_037.cpp new file mode 100644 index 0000000000..e75e23d5e6 --- /dev/null +++ b/docs/examples/ImageInfo_037.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=e72db006f1bea26feceaef8727ff9818 +REG_FIDDLE(ImageInfo_037, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + const int width = 256; + const int height = 128; + SkColor pixels[height][width]; + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f))); + int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f))); + int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f))); + int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f))); + pixels[y][x] = + SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255); + } + } + SkBitmap bitmap; + SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType); + bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width); + canvas->drawBitmap(source, 0, 0); + canvas->drawBitmap(bitmap, 0, 0); + SkImageInfo unpremulInfo = info.makeAlphaType(kUnpremul_SkAlphaType); + bitmap.installPixels(unpremulInfo, (void*) pixels, sizeof(SkColor) * width); + canvas->drawBitmap(bitmap, 0, 128); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_038.cpp b/docs/examples/ImageInfo_038.cpp new file mode 100644 index 0000000000..ea2d76c301 --- /dev/null +++ b/docs/examples/ImageInfo_038.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=3ac267b08b12dc83c95f91d8dd5d70ee +REG_FIDDLE(ImageInfo_038, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + const int width = 256; + const int height = 128; + SkColor pixels[height][width]; + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + int red = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 4 + y) * 0.03f))); + int blue = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 3 + y) * 0.04f))); + int green = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarSin((x * 2 + y) * 0.05f))); + int alpha = SkScalarRoundToInt(255 * SkScalarAbs(SkScalarCos((x * 1 + y) * 0.006f))); + pixels[y][x] = + SkColorSetARGB(alpha, red * alpha / 255, green * alpha / 255, blue * alpha / 255); + } + } + SkBitmap bitmap; + SkImageInfo info = SkImageInfo::Make(width, height, kBGRA_8888_SkColorType, kPremul_SkAlphaType); + bitmap.installPixels(info, (void*) pixels, sizeof(SkColor) * width); + canvas->drawBitmap(source, 0, 0); + canvas->drawBitmap(bitmap, 0, 0); + SkImageInfo rgbaInfo = info.makeColorType(kRGBA_8888_SkColorType); + bitmap.installPixels(rgbaInfo, (void*) pixels, sizeof(SkColor) * width); + canvas->drawBitmap(bitmap, 0, 128); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_039.cpp b/docs/examples/ImageInfo_039.cpp new file mode 100644 index 0000000000..7e90937faf --- /dev/null +++ b/docs/examples/ImageInfo_039.cpp @@ -0,0 +1,42 @@ +#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 "fiddle/examples.h" +// HASH=fe3c5a755d3dde29bba058a583f18901 +REG_FIDDLE(ImageInfo_039, 256, 224, false, 0) { +void draw(SkCanvas* canvas) { + const int width = 256; + const int height = 64; + auto drawLabel = [=](const char* what, bool closeToSRGB) -> void { + SkString string; + string.printf("%s gamma is %s" "close to sRGB", what, closeToSRGB ? "" : "not "); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString(string, 20, 56, paint); + }; + SkColor gradColors[] = { 0xFFFF7F00, 0xFF00FF7F, 0xFF0000FF, 0xFF7F7FFF }; + SkPoint gradPoints[] = { { 0, 0 }, { width, 0 }, { width * 2, 0 }, { width * 3, 0 } }; + SkPaint gradPaint; + gradPaint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, + SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); + canvas->drawRect(SkRect::MakeWH(width, height), gradPaint); + drawLabel("canvas", canvas->imageInfo().gammaCloseToSRGB()); + SkBitmap bitmap; + SkImageInfo offscreenInfo = SkImageInfo::MakeS32(width, height, kPremul_SkAlphaType); + bitmap.allocPixels(offscreenInfo); + SkCanvas sRGBOffscreen(bitmap); + sRGBOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint); + canvas->translate(0, 80); + canvas->drawBitmap(bitmap, 0, 0); + drawLabel("offscreen", offscreenInfo.gammaCloseToSRGB()); + SkImageInfo linearGamma = + offscreenInfo.makeColorSpace(offscreenInfo.colorSpace()->makeLinearGamma()); + bitmap.allocPixels(linearGamma); + SkCanvas lgOffscreen(bitmap); + lgOffscreen.drawRect(SkRect::MakeWH(width, height), gradPaint); + canvas->translate(0, 80); + canvas->drawBitmap(bitmap, 0, 0); + drawLabel("linear", linearGamma.gammaCloseToSRGB()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/ImageInfo_040.cpp b/docs/examples/ImageInfo_040.cpp new file mode 100644 index 0000000000..26497caaa1 --- /dev/null +++ b/docs/examples/ImageInfo_040.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=9b6de4a07b2316228e9340e5a3b82134 +REG_FIDDLE(ImageInfo_040, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + for (SkColorType colorType : { + kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, + kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, + kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType + } ) { + SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType); + SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d\n", + colors[colorType], 13 - strlen(colors[colorType]), " ", + info.bytesPerPixel()); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_041.cpp b/docs/examples/ImageInfo_041.cpp new file mode 100644 index 0000000000..a483f732cb --- /dev/null +++ b/docs/examples/ImageInfo_041.cpp @@ -0,0 +1,37 @@ +// 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 "fiddle/examples.h" +// HASH=e47b911f94fc629f756a829e523a2a89 +REG_FIDDLE(ImageInfo_041, 256, 256, true, 0) { +const char* color_type(SkColorType ct) { + switch (ct) { + case kUnknown_SkColorType: return "Unknown"; + case kAlpha_8_SkColorType: return "Alpha_8"; + case kRGB_565_SkColorType: return "RGB_565"; + case kARGB_4444_SkColorType: return "ARGB_4444"; + case kRGBA_8888_SkColorType: return "RGBA_8888"; + case kRGB_888x_SkColorType: return "RGB_888x"; + case kBGRA_8888_SkColorType: return "BGRA_8888"; + case kRGBA_1010102_SkColorType: return "RGBA_1010102"; + case kRGB_101010x_SkColorType: return "RGB_101010x"; + case kGray_8_SkColorType: return "Gray_8"; + case kRGBA_F16Norm_SkColorType: return "RGBA_F16Norm"; + case kRGBA_F16_SkColorType: return "RGBA_F16"; + case kRGBA_F32_SkColorType: return "RGBA_F32"; + default: SkASSERT(false); return nullptr; + } +} +void draw(SkCanvas* canvas) { + for (SkColorType colorType : { + kUnknown_SkColorType, kAlpha_8_SkColorType, kRGB_565_SkColorType, + kARGB_4444_SkColorType, kRGBA_8888_SkColorType, kRGB_888x_SkColorType, + kBGRA_8888_SkColorType, kRGBA_1010102_SkColorType, kRGB_101010x_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType + } ) { + SkImageInfo info = SkImageInfo::Make(1, 1, colorType, kOpaque_SkAlphaType); + SkDebugf("color: k" "%s" "_SkColorType" "%*s" "shiftPerPixel: %d\n", + color_type(colorType), 14 - strlen(color_type(colorType)), " ", + info.shiftPerPixel()); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_042.cpp b/docs/examples/ImageInfo_042.cpp new file mode 100644 index 0000000000..284e238877 --- /dev/null +++ b/docs/examples/ImageInfo_042.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=4b5d3904476726a39f1c3e276d6b6ba7 +REG_FIDDLE(ImageInfo_042, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + for (int shift = 24; shift < 32; ++shift) { + int width = 1 << shift; + SkImageInfo imageInfo = + SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType); + uint64_t minRowBytes = imageInfo.minRowBytes64(); + bool widthTooLarge = (uint64_t) (int32_t) minRowBytes != minRowBytes; + SkDebugf("RGBA_F16 width %d (0x%08x) %s\n", + width, width, widthTooLarge ? "too large" : "OK"); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_043.cpp b/docs/examples/ImageInfo_043.cpp new file mode 100644 index 0000000000..f189ea7781 --- /dev/null +++ b/docs/examples/ImageInfo_043.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=897230ecfb36095486beca324fd369f9 +REG_FIDDLE(ImageInfo_043, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + for (int shift = 24; shift < 32; ++shift) { + int width = 1 << shift; + SkImageInfo imageInfo = + SkImageInfo::Make(width, 1, kRGBA_F16_SkColorType, kPremul_SkAlphaType); + size_t minRowBytes = imageInfo.minRowBytes(); + bool widthTooLarge = !minRowBytes; + SkDebugf("RGBA_F16 width %d (0x%08x) %s\n", + width, width, widthTooLarge ? "too large" : "OK"); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_044.cpp b/docs/examples/ImageInfo_044.cpp new file mode 100644 index 0000000000..dcfad33975 --- /dev/null +++ b/docs/examples/ImageInfo_044.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=818e4e1191e39d2a642902cbf253b399 +REG_FIDDLE(ImageInfo_044, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t pixels[][12] = { { 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00}, + { 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00}, + { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00}, + { 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF}, + { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}, + { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00}, + { 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00}, + { 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00} }; + SkImageInfo imageInfo = SkImageInfo::MakeA8(8, 8); + SkBitmap bitmap; + bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0])); + SkPaint paint; + paint.setColor(SK_ColorRED); + canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(32, 32), &paint); + size_t offset = imageInfo.computeOffset(2, 3, sizeof(pixels[0])); + pixels[0][offset] = 0x7F; + offset = imageInfo.computeOffset(5, 3, sizeof(pixels[0])); + pixels[0][offset] = 0x7F; + bitmap.installPixels(imageInfo, (void*) pixels, sizeof(pixels[0])); + canvas->drawBitmapRect(bitmap, SkRect::MakeWH(8, 8), SkRect::MakeWH(128, 128), &paint); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_045.cpp b/docs/examples/ImageInfo_045.cpp new file mode 100644 index 0000000000..7a5df3dea9 --- /dev/null +++ b/docs/examples/ImageInfo_045.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=53c212c4f2449df0b0eedbc6227b6ab7 +REG_FIDDLE(ImageInfo_045, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType); + SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType); + SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!'); + info2 = info2.makeWH(10, 20); + SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!'); + info2 = info2.makeColorType(kGray_8_SkColorType); + SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!'); + info2 = info2.makeAlphaType(kPremul_SkAlphaType); + SkDebugf("info1 %c= info2\n", info1 == info2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_046.cpp b/docs/examples/ImageInfo_046.cpp new file mode 100644 index 0000000000..1eda067df1 --- /dev/null +++ b/docs/examples/ImageInfo_046.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=8c039fde0a476ac1aa62bf9de5d61c77 +REG_FIDDLE(ImageInfo_046, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info1 = SkImageInfo::Make(10, 20, kGray_8_SkColorType, kPremul_SkAlphaType); + SkImageInfo info2 = SkImageInfo::Make(20, 10, kAlpha_8_SkColorType, kUnpremul_SkAlphaType); + SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '='); + info2 = info2.makeWH(10, 20); + SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '='); + info2 = info2.makeColorType(kGray_8_SkColorType); + SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '='); + info2 = info2.makeAlphaType(kPremul_SkAlphaType); + SkDebugf("info1 %c= info2\n", info1 != info2 ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_047.cpp b/docs/examples/ImageInfo_047.cpp new file mode 100644 index 0000000000..7075ff24d0 --- /dev/null +++ b/docs/examples/ImageInfo_047.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=9def507d2295f7051effd0c83bb04436 +REG_FIDDLE(ImageInfo_047, 256, 130, false, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); + const size_t size = info.computeByteSize(100000); + SkAutoTMalloc storage(size); + SkPMColor* pixels = storage.get(); + SkBitmap bitmap; + bitmap.setInfo(info); + bitmap.setPixels(pixels); + bitmap.eraseColor(SK_ColorRED); + canvas->scale(50, 50); + canvas->rotate(8); + canvas->drawBitmap(bitmap, 2, 0); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_048.cpp b/docs/examples/ImageInfo_048.cpp new file mode 100644 index 0000000000..3d5fde7e0b --- /dev/null +++ b/docs/examples/ImageInfo_048.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=fc18640fdde437cb35338aed7c68d399 +REG_FIDDLE(ImageInfo_048, 256, 130, false, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); + const size_t size = info.computeMinByteSize(); + SkAutoTMalloc storage(size); + SkPMColor* pixels = storage.get(); + SkBitmap bitmap; + bitmap.setInfo(info); + bitmap.setPixels(pixels); + bitmap.eraseColor(SK_ColorRED); + canvas->scale(50, 50); + canvas->rotate(8); + canvas->drawBitmap(bitmap, 2, 0); +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_049.cpp b/docs/examples/ImageInfo_049.cpp new file mode 100644 index 0000000000..3cd8bb2033 --- /dev/null +++ b/docs/examples/ImageInfo_049.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=6a63dfdd62ab77ff57783af8c33d7b78 +REG_FIDDLE(ImageInfo_049, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + if (sizeof(size_t) == 8) { + SkImageInfo info = SkImageInfo::MakeN32Premul(2, 1000000000); + for (size_t rowBytes = 100000000; rowBytes < 10000000000000LL; rowBytes *= 10) { + const size_t size = info.computeByteSize(rowBytes); + SkDebugf("rowBytes:%llu size:%llu overflowed:%s\n", rowBytes, size, + SkImageInfo::ByteSizeOverflowed(size) ? "true" : "false"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_050.cpp b/docs/examples/ImageInfo_050.cpp new file mode 100644 index 0000000000..6d974cf21f --- /dev/null +++ b/docs/examples/ImageInfo_050.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=c6b0f6a3f493cb08d9abcdefe12de245 +REG_FIDDLE(ImageInfo_050, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8); + for (size_t rowBytes = 60; rowBytes < 72; rowBytes += sizeof(SkPMColor)) { + SkDebugf("validRowBytes(%llu): %s\n", rowBytes, info.validRowBytes(rowBytes) ? + "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/ImageInfo_051.cpp b/docs/examples/ImageInfo_051.cpp new file mode 100644 index 0000000000..5adf7ba0aa --- /dev/null +++ b/docs/examples/ImageInfo_051.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=ab7e73786805c936de386b6c1ebe1f13 +REG_FIDDLE(ImageInfo_051, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeN32Premul(16, 8); + SkImageInfo copy = info; + SkDebugf("info %c= copy\n", info == copy ? '=' : '!'); + copy.reset(); + SkDebugf("info %c= reset copy\n", info == copy ? '=' : '!'); + SkDebugf("SkImageInfo() %c= reset copy\n", SkImageInfo() == copy ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Image_000.cpp b/docs/examples/Image_000.cpp new file mode 100644 index 0000000000..79f5e251ad --- /dev/null +++ b/docs/examples/Image_000.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=513afec5795a9504ebf6af5373d16b6b +REG_FIDDLE(Image_000, 256, 50, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, + { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, + { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, + { 0x90, 0x81, 0xC5, 0x71, 0x33 }, + { 0x75, 0x55, 0x44, 0x40, 0x30 }}; + SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); + SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + sk_sp image = SkImage::MakeRasterCopy(pixmap); + *pixmap.writable_addr8(2, 2) = 0x00; + canvas->scale(10, 10); + canvas->drawBitmap(bitmap, 0, 0); + canvas->drawImage(image, 10, 0); +} +} // END FIDDLE diff --git a/docs/examples/Image_001.cpp b/docs/examples/Image_001.cpp new file mode 100644 index 0000000000..12b3d0aca1 --- /dev/null +++ b/docs/examples/Image_001.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=22e7ce79ab2fe94252d23319f2258127 +REG_FIDDLE(Image_001, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + size_t rowBytes = image->width() * SkColorTypeBytesPerPixel(kRGBA_8888_SkColorType); + sk_sp data = SkData::MakeUninitialized(rowBytes * image->height()); + SkImageInfo dstInfo = SkImageInfo::MakeN32(image->width(), image->height(), + kPremul_SkAlphaType); + image->readPixels(dstInfo, data->writable_data(), rowBytes, 0, 0, SkImage::kAllow_CachingHint); + sk_sp raw = SkImage::MakeRasterData(dstInfo.makeColorType(kRGBA_8888_SkColorType), + data, rowBytes); + canvas->drawImage(image, 0, 0); + canvas->drawImage(raw.get(), 128, 0); +} +} // END FIDDLE diff --git a/docs/examples/Image_002.cpp b/docs/examples/Image_002.cpp new file mode 100644 index 0000000000..be5ae12385 --- /dev/null +++ b/docs/examples/Image_002.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=275356b65d18c8868f4434137350cddc +REG_FIDDLE(Image_002, 256, 256, true, 0) { +static void releaseProc(const void* pixels, SkImage::ReleaseContext context) { + int* countPtr = static_cast(context); + *countPtr += 1; +} + +void draw(SkCanvas* canvas) { + SkColor color = 0; + SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), &color, 4); + int releaseCount = 0; + sk_sp image(SkImage::MakeFromRaster(pixmap, releaseProc, &releaseCount)); + SkDebugf("before reset: %d\n", releaseCount); + image.reset(); + SkDebugf("after reset: %d\n", releaseCount); +} +} // END FIDDLE diff --git a/docs/examples/Image_003.cpp b/docs/examples/Image_003.cpp new file mode 100644 index 0000000000..2047a7f1df --- /dev/null +++ b/docs/examples/Image_003.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=cf2cf53321e4e6a77c2841bfbc0ef707 +REG_FIDDLE(Image_003, 256, 50, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t storage[][5] = {{ 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 }, + { 0xAC, 0xA8, 0x89, 0xA7, 0x87 }, + { 0x9B, 0xB5, 0xE5, 0x95, 0x46 }, + { 0x90, 0x81, 0xC5, 0x71, 0x33 }, + { 0x75, 0x55, 0x44, 0x40, 0x30 }}; + SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kOpaque_SkAlphaType); + SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + sk_sp image1 = SkImage::MakeFromBitmap(bitmap); + bitmap.setImmutable(); + sk_sp image2 = SkImage::MakeFromBitmap(bitmap); + *pixmap.writable_addr8(2, 2) = 0x00; + canvas->scale(10, 10); + canvas->drawImage(image1, 0, 0); + canvas->drawImage(image2, 10, 0); +} +} // END FIDDLE diff --git a/docs/examples/Image_004.cpp b/docs/examples/Image_004.cpp new file mode 100644 index 0000000000..820e552398 --- /dev/null +++ b/docs/examples/Image_004.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=c2fec0746f88ca34d7dce59dd9bdef9e +REG_FIDDLE(Image_004, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + recorder.beginRecording(100, 100)->drawColor(SK_ColorRED); + auto picture = recorder.finishRecordingAsPicture(); + auto gen = SkImageGenerator::MakeFromPicture({100, 100}, picture, nullptr, nullptr, + SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); + sk_sp image = SkImage::MakeFromGenerator(std::move(gen)); + canvas->drawImage(image, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Image_005.cpp b/docs/examples/Image_005.cpp new file mode 100644 index 0000000000..dfd49887e5 --- /dev/null +++ b/docs/examples/Image_005.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=894f732ed6409b1f392bc5481421d0e9 +REG_FIDDLE(Image_005, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + int x = 0; + for (int quality : { 100, 50, 10, 1} ) { + sk_sp encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, quality); + sk_sp image = SkImage::MakeFromEncoded(encodedData); + canvas->drawImage(image, x, 0); + x += 64; + } +} +} // END FIDDLE diff --git a/docs/examples/Image_006.cpp b/docs/examples/Image_006.cpp new file mode 100644 index 0000000000..3868f1ddb1 --- /dev/null +++ b/docs/examples/Image_006.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=94e9296c53bad074bf2a48ff885dac13 +REG_FIDDLE(Image_006, 256, 128, false, 3) { +void draw(SkCanvas* canvas) { + GrContext* context = canvas->getGrContext(); + if (!context) { + return; + } + canvas->scale(.25f, .25f); + int x = 0; + for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { + sk_sp image = SkImage::MakeFromTexture(context, backEndTexture, + origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr); + canvas->drawImage(image, x, 0); + x += 512; + } +} +} // END FIDDLE diff --git a/docs/examples/Image_007.cpp b/docs/examples/Image_007.cpp new file mode 100644 index 0000000000..c5dd7259a6 --- /dev/null +++ b/docs/examples/Image_007.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=2b1e46354d823dbb53fa6af570135329 +REG_FIDDLE(Image_007, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + GrContext* context = canvas->getGrContext(); + if (!context) { + return; + } + auto debugster = [](SkImage::ReleaseContext releaseContext) -> void { + *((int *) releaseContext) += 128; + }; + int x = 0, y = 0; + for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { + sk_sp image = SkImage::MakeFromTexture(context, backEndTexture, + origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, debugster, &x); + canvas->drawImage(image, x, y); + y += 128; + } +} +} // END FIDDLE diff --git a/docs/examples/Image_008.cpp b/docs/examples/Image_008.cpp new file mode 100644 index 0000000000..b699954edb --- /dev/null +++ b/docs/examples/Image_008.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=069c7b116479e3ca46f953f07dcbdd36 +REG_FIDDLE(Image_008, 256, 64, false, 4) { +void draw(SkCanvas* canvas) { + GrContext* context = canvas->getGrContext(); + sk_sp encodedData = image->encodeToData(SkEncodedImageFormat::kJPEG, 100); + sk_sp image = SkImage::MakeCrossContextFromEncoded(context, + encodedData, false, nullptr); + canvas->drawImage(image, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Image_009.cpp b/docs/examples/Image_009.cpp new file mode 100644 index 0000000000..73c020233c --- /dev/null +++ b/docs/examples/Image_009.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=45bca8747b8f49b5be34b520897ef048 +REG_FIDDLE(Image_009, 256, 64, false, 4) { +void draw(SkCanvas* canvas) { + GrContext* context = canvas->getGrContext(); + SkPixmap pixmap; + if (source.peekPixels(&pixmap)) { + sk_sp image = SkImage::MakeCrossContextFromPixmap(context, pixmap, + false, nullptr); + canvas->drawImage(image, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Image_010.cpp b/docs/examples/Image_010.cpp new file mode 100644 index 0000000000..6e7db6c1bc --- /dev/null +++ b/docs/examples/Image_010.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=b034517e39394b7543f06ec885e36d7d +REG_FIDDLE(Image_010, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + if (!canvas->getGrContext()) { + return; + } + canvas->scale(.5f, .5f); + canvas->clear(0x7f3f5f7f); + int x = 0, y = 0; + for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) { + for (auto alpha : { kOpaque_SkAlphaType, kPremul_SkAlphaType, kUnpremul_SkAlphaType } ) { + sk_sp image = SkImage::MakeFromAdoptedTexture(canvas->getGrContext(), + backEndTexture, origin, + kRGBA_8888_SkColorType, alpha); + canvas->drawImage(image, x, y); + x += 160; + } + x -= 160 * 3; + y += 256; + } +} +} // END FIDDLE diff --git a/docs/examples/Image_011.cpp b/docs/examples/Image_011.cpp new file mode 100644 index 0000000000..d3ce9c6ee2 --- /dev/null +++ b/docs/examples/Image_011.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=4aa2879b9e44dfd6648995326d2c4dcf +REG_FIDDLE(Image_011, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPictureRecorder recorder; + SkCanvas* recordingCanvas = recorder.beginRecording(50, 50); + for (auto color : { SK_ColorRED, SK_ColorBLUE, 0xff007f00 } ) { + paint.setColor(color); + recordingCanvas->drawRect({10, 10, 30, 40}, paint); + recordingCanvas->translate(10, 10); + recordingCanvas->scale(1.2f, 1.4f); + } + sk_sp playback = recorder.finishRecordingAsPicture(); + int x = 0, y = 0; + for (auto alpha : { 70, 140, 210 } ) { + paint.setAlpha(alpha); + auto srgbColorSpace = SkColorSpace::MakeSRGB(); + sk_sp image = SkImage::MakeFromPicture(playback, {50, 50}, nullptr, &paint, + SkImage::BitDepth::kU8, srgbColorSpace); + canvas->drawImage(image, x, y); + x += 70; y += 70; + } +} +} // END FIDDLE diff --git a/docs/examples/Image_012.cpp b/docs/examples/Image_012.cpp new file mode 100644 index 0000000000..66d5e72f77 --- /dev/null +++ b/docs/examples/Image_012.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=9aec65fc252ffc9982fa8867433eca18 +REG_FIDDLE(Image_012, 256, 96, false, 4) { +void draw(SkCanvas* canvas) { + canvas->translate(10, 10); + canvas->drawImage(image, 0, 0); + canvas->translate(0, image->height()); + SkPaint paint; + canvas->drawLine(0, 10, image->width(), 10, paint); + canvas->drawString("width", image->width() / 2 - 15, 25, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_013.cpp b/docs/examples/Image_013.cpp new file mode 100644 index 0000000000..1bf1df9f1c --- /dev/null +++ b/docs/examples/Image_013.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=a4f53a0b6ac85e7bc3887245b728530d +REG_FIDDLE(Image_013, 256, 96, false, 4) { +void draw(SkCanvas* canvas) { + canvas->translate(10, 10); + canvas->drawImage(image, 0, 0); + canvas->translate(image->width(), 0); + SkPaint paint; + canvas->drawLine(10, 0, 10, image->height(), paint); + canvas->drawString("height", 34, image->height() / 2, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_014.cpp b/docs/examples/Image_014.cpp new file mode 100644 index 0000000000..4dd2810cee --- /dev/null +++ b/docs/examples/Image_014.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=96b4bc43b3667df9ba9e2dafb770d33c +REG_FIDDLE(Image_014, 256, 256, true, 4) { +void draw(SkCanvas* canvas) { + SkISize dimensions = image->dimensions(); + SkIRect bounds = image->bounds(); + SkIRect dimensionsAsBounds = SkIRect::MakeSize(dimensions); + SkDebugf("dimensionsAsBounds %c= bounds\n", dimensionsAsBounds == bounds ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Image_015.cpp b/docs/examples/Image_015.cpp new file mode 100644 index 0000000000..5892c4242f --- /dev/null +++ b/docs/examples/Image_015.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=c204b38b3fc08914b0a634aa4eaec894 +REG_FIDDLE(Image_015, 256, 128, false, 4) { +void draw(SkCanvas* canvas) { + SkIRect bounds = image->bounds(); + for (int x : { 0, bounds.width() } ) { + for (int y : { 0, bounds.height() } ) { + canvas->drawImage(image, x, y); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Image_016.cpp b/docs/examples/Image_016.cpp new file mode 100644 index 0000000000..db02f216ab --- /dev/null +++ b/docs/examples/Image_016.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=d70194c9c51e700335f95de91846d023 +REG_FIDDLE(Image_016, 256, 156, false, 5) { +void draw(SkCanvas* canvas) { + sk_sp subset = image->makeSubset({10, 20, 90, 100}); + canvas->drawImage(image, 0, 0); + canvas->drawImage(subset, 128, 0); + SkPaint paint; + SkString s; + s.printf("original id: %d", image->uniqueID()); + canvas->drawString(s, 20, image->height() + 20, paint); + s.printf("subset id: %d", subset->uniqueID()); + canvas->drawString(s, 148, subset->height() + 20, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_017.cpp b/docs/examples/Image_017.cpp new file mode 100644 index 0000000000..b4de0f09e3 --- /dev/null +++ b/docs/examples/Image_017.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=1b9f1f05026ceb14ccb6926a13cdaa83 +REG_FIDDLE(Image_017, 256, 96, false, 4) { +void draw(SkCanvas* canvas) { + const char* alphaTypeStr[] = { "Unknown", "Opaque", "Premul", "Unpremul" }; + SkAlphaType alphaType = image->alphaType(); + canvas->drawImage(image, 16, 0); + canvas->drawString(alphaTypeStr[(int) alphaType], 20, image->height() + 20, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_018.cpp b/docs/examples/Image_018.cpp new file mode 100644 index 0000000000..35e4b47c20 --- /dev/null +++ b/docs/examples/Image_018.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=50396fad4a128f58e400ca00fe09711f +REG_FIDDLE(Image_018, 256, 96, false, 4) { +void draw(SkCanvas* canvas) { + const char* colors[] = { "Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16" }; + SkColorType colorType = image->colorType(); + canvas->drawImage(image, 16, 0); + canvas->drawString(colors[(int) colorType], 20, image->height() + 20, SkFont(), SkPaint()); +} +} // END FIDDLE diff --git a/docs/examples/Image_019.cpp b/docs/examples/Image_019.cpp new file mode 100644 index 0000000000..fbf2afd365 --- /dev/null +++ b/docs/examples/Image_019.cpp @@ -0,0 +1,27 @@ +#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 "fiddle/examples.h" +// HASH=4468d573f42af6f5e234be10a5453bb2 +REG_FIDDLE(Image_019, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkPixmap pixmap; + source.peekPixels(&pixmap); + canvas->scale(.25f, .25f); + int y = 0; + for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, + SkColorSpace::kSRGB_RenderTargetGamma } ) { + int x = 0; + sk_sp colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); + for (int index = 0; index < 2; ++index) { + pixmap.setColorSpace(colorSpace); + sk_sp image = SkImage::MakeRasterCopy(pixmap); + canvas->drawImage(image, x, y); + colorSpace = image->colorSpace()->makeColorSpin(); + x += 512; + } + y += 512; + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_020.cpp b/docs/examples/Image_020.cpp new file mode 100644 index 0000000000..7b224e87e5 --- /dev/null +++ b/docs/examples/Image_020.cpp @@ -0,0 +1,27 @@ +#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 "fiddle/examples.h" +// HASH=59b2078ebfbda8736a57c0486ae33332 +REG_FIDDLE(Image_020, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkPixmap pixmap; + source.peekPixels(&pixmap); + canvas->scale(.25f, .25f); + int y = 0; + for (auto gamma : { SkColorSpace::kLinear_RenderTargetGamma, + SkColorSpace::kSRGB_RenderTargetGamma } ) { + int x = 0; + sk_sp colorSpace = SkColorSpace::MakeRGB(gamma, SkColorSpace::kSRGB_Gamut); + for (int index = 0; index < 2; ++index) { + pixmap.setColorSpace(colorSpace); + sk_sp image = SkImage::MakeRasterCopy(pixmap); + canvas->drawImage(image, x, y); + colorSpace = image->refColorSpace()->makeColorSpin(); + x += 512; + } + y += 512; + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_021.cpp b/docs/examples/Image_021.cpp new file mode 100644 index 0000000000..7bce5cf15d --- /dev/null +++ b/docs/examples/Image_021.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=50762c73b8ea91959c5a7b68fbf1062d +REG_FIDDLE(Image_021, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + uint8_t pmColors = 0; + sk_sp image = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1), &pmColors, 1}); + SkDebugf("alphaOnly = %s\n", image->isAlphaOnly() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Image_022.cpp b/docs/examples/Image_022.cpp new file mode 100644 index 0000000000..414f53d2e6 --- /dev/null +++ b/docs/examples/Image_022.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=e3340460003b74ee286d625e68589d65 +REG_FIDDLE(Image_022, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto check_isopaque = [](const SkImageInfo& imageInfo) -> void { + auto surface(SkSurface::MakeRaster(imageInfo)); + auto image(surface->makeImageSnapshot()); + SkDebugf("isOpaque = %s\n", image->isOpaque() ? "true" : "false"); + }; + check_isopaque(SkImageInfo::MakeN32Premul(5, 5)); + check_isopaque(SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType)); +} +} // END FIDDLE diff --git a/docs/examples/Image_023.cpp b/docs/examples/Image_023.cpp new file mode 100644 index 0000000000..fa9ae3c46b --- /dev/null +++ b/docs/examples/Image_023.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=1c6de6fe72b00b5be970f5f718363449 +REG_FIDDLE(Image_023, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setRotate(45); + SkPaint paint; + paint.setShader(image->makeShader(SkShader::kRepeat_TileMode, SkShader::kMirror_TileMode, + &matrix)); + canvas->drawPaint(paint); +} +} // END FIDDLE diff --git a/docs/examples/Image_024.cpp b/docs/examples/Image_024.cpp new file mode 100644 index 0000000000..d9d4864a16 --- /dev/null +++ b/docs/examples/Image_024.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=10172fca71b9dbdcade772513ffeb27e +REG_FIDDLE(Image_024, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setRotate(45); + matrix.postTranslate(125, 30); + SkPaint paint; + paint.setShader(image->makeShader(&matrix)); + canvas->drawPaint(paint); +} +} // END FIDDLE diff --git a/docs/examples/Image_025.cpp b/docs/examples/Image_025.cpp new file mode 100644 index 0000000000..308e8785bf --- /dev/null +++ b/docs/examples/Image_025.cpp @@ -0,0 +1,28 @@ +#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 "fiddle/examples.h" +// HASH=900c0eab8dfdecd8301ed5be95887f8e +REG_FIDDLE(Image_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocPixels(SkImageInfo::MakeN32Premul(12, 11)); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorWHITE); + SkPaint paint; + offscreen.drawString("%", 1, 10, paint); + sk_sp image = SkImage::MakeFromBitmap(bitmap); + SkPixmap pixmap; + if (image->peekPixels(&pixmap)) { + const SkPMColor* pixels = pixmap.addr32(); + SkPMColor pmWhite = pixels[0]; + for (int y = 0; y < image->height(); ++y) { + for (int x = 0; x < image->width(); ++x) { + SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); + } + SkDebugf("\n"); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_026.cpp b/docs/examples/Image_026.cpp new file mode 100644 index 0000000000..273d8c4f1e --- /dev/null +++ b/docs/examples/Image_026.cpp @@ -0,0 +1,30 @@ +#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 "fiddle/examples.h" +// HASH=9cf5c62a3d2243e6577ae563f360ea9d +REG_FIDDLE(Image_026, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + auto drawImage = [=](sk_sp image, const char* label) -> void { + if (nullptr == image) { + return; + } + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawImage(image, 0, 0); + canvas->drawString(label, 30, image->height() / 4, paint); + canvas->drawString(image->isTextureBacked() ? "is GPU texture" : "not GPU texture", + 20, image->height() * 3 / 4, paint); + }; + sk_sp bitmapImage(SkImage::MakeFromBitmap(source)); + sk_sp textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, + kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, + kOpaque_SkAlphaType, nullptr)); + drawImage(image, "image"); + canvas->translate(image->width(), 0); + drawImage(bitmapImage, "source"); + canvas->translate(-image->width(), image->height()); + drawImage(textureImage, "backEndTexture"); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_027.cpp b/docs/examples/Image_027.cpp new file mode 100644 index 0000000000..57c679c214 --- /dev/null +++ b/docs/examples/Image_027.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=afc62f38aebc56af8e425297ec67dd37 +REG_FIDDLE(Image_027, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + auto drawImage = [=](sk_sp image, const char* label) -> void { + if (nullptr == image) { + return; + } + 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(image->isValid(nullptr) ? "is valid on CPU" : + "not valid on CPU", 20, image->height() * 7 / 8, paint); + }; + sk_sp bitmapImage(SkImage::MakeFromBitmap(source)); + sk_sp textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, + kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, + kOpaque_SkAlphaType, nullptr)); + drawImage(image, "image"); + canvas->translate(image->width(), 0); + drawImage(bitmapImage, "source"); + canvas->translate(-image->width(), image->height()); + drawImage(textureImage, "backEndTexture"); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_028.cpp b/docs/examples/Image_028.cpp new file mode 100644 index 0000000000..3e4ba418ef --- /dev/null +++ b/docs/examples/Image_028.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=d093aad721261f421c4bef4a296aab48 +REG_FIDDLE(Image_028, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + GrContext* grContext = canvas->getGrContext(); + if (!grContext) { + canvas->drawString("GPU only!", 20, 40, SkPaint()); + return; + } + sk_sp imageFromBackend = SkImage::MakeFromAdoptedTexture(grContext, 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); + 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_029.cpp b/docs/examples/Image_029.cpp new file mode 100644 index 0000000000..c4c2cee6a2 --- /dev/null +++ b/docs/examples/Image_029.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=8aa8ca63dff4641dfc6ea8a3c555d59c +REG_FIDDLE(Image_029, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->scale(.5f, .5f); + const int width = 32; + const int height = 32; + std::vector dstPixels; + dstPixels.resize(height * width * 4); + SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); + for (int y = 0; y < 512; y += height ) { + for (int x = 0; x < 512; x += width ) { + if (image->readPixels(info, &dstPixels.front(), width * 4, x, y)) { + SkPixmap dstPixmap(info, &dstPixels.front(), width * 4); + SkBitmap bitmap; + bitmap.installPixels(dstPixmap); + canvas->drawBitmap(bitmap, 0, 0); + } + canvas->translate(48, 0); + } + canvas->translate(-16 * 48, 48); + } +} +} // END FIDDLE diff --git a/docs/examples/Image_030.cpp b/docs/examples/Image_030.cpp new file mode 100644 index 0000000000..87772ceeca --- /dev/null +++ b/docs/examples/Image_030.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=b77a73c4baa63a4a8e2a4fdd96144d0b +REG_FIDDLE(Image_030, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + int rowBytes = image->width() * 4; + int quarterWidth = image->width() / 4; + int quarterHeight = image->height() / 4; + srcPixels.resize(image->height() * rowBytes); + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < 4; ++x) { + SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight), + &srcPixels.front() + x * image->height() * quarterWidth + + y * quarterWidth, rowBytes); + image->readPixels(pixmap, x * quarterWidth, y * quarterHeight); + } + } + canvas->scale(.5f, .5f); + SkBitmap bitmap; + bitmap.installPixels(SkImageInfo::MakeN32Premul(image->width(), image->height()), + &srcPixels.front(), rowBytes); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Image_031.cpp b/docs/examples/Image_031.cpp new file mode 100644 index 0000000000..f513feba7b --- /dev/null +++ b/docs/examples/Image_031.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=5949c9a63610cae30019e5b1899ee38f +REG_FIDDLE(Image_031, 256, 128, false, 3) { +void draw(SkCanvas* canvas) { + std::vector srcPixels; + int quarterWidth = image->width() / 16; + int rowBytes = quarterWidth * 4; + int quarterHeight = image->height() / 16; + srcPixels.resize(quarterHeight * rowBytes); + SkPixmap pixmap(SkImageInfo::MakeN32Premul(quarterWidth, quarterHeight), + &srcPixels.front(), rowBytes); + canvas->scale(4, 4); + SkFilterQuality qualities[] = { kNone_SkFilterQuality, kLow_SkFilterQuality, + kMedium_SkFilterQuality, kHigh_SkFilterQuality }; + for (unsigned index = 0; index < SK_ARRAY_COUNT(qualities); ++index) { + image->scalePixels(pixmap, qualities[index]); + sk_sp filtered = SkImage::MakeFromRaster(pixmap, nullptr, nullptr); + canvas->drawImage(filtered, 16 * index, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Image_032.cpp b/docs/examples/Image_032.cpp new file mode 100644 index 0000000000..425a5eb253 --- /dev/null +++ b/docs/examples/Image_032.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=7a3bf8851bb7160e4e49c48f8c09639d +REG_FIDDLE(Image_032, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->scale(4, 4); + SkIRect subset = {0, 0, 16, 64}; + int x = 0; + for (int quality : { 0, 10, 50, 100 } ) { + sk_sp data(image->encodeToData(SkEncodedImageFormat::kJPEG, quality)); + sk_sp filtered = SkImage::MakeFromEncoded(data, &subset); + canvas->drawImage(filtered, x, 0); + x += 16; + } +} +} // END FIDDLE diff --git a/docs/examples/Image_033.cpp b/docs/examples/Image_033.cpp new file mode 100644 index 0000000000..9a50e2a818 --- /dev/null +++ b/docs/examples/Image_033.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=30cee813f6aa476b0a9c8a24283e53a3 +REG_FIDDLE(Image_033, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->scale(4, 4); + SkIRect subset = {136, 32, 200, 96}; + sk_sp data(image->encodeToData()); + sk_sp eye = SkImage::MakeFromEncoded(data, &subset); + canvas->drawImage(eye, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Image_034.cpp b/docs/examples/Image_034.cpp new file mode 100644 index 0000000000..5fa78f2c2a --- /dev/null +++ b/docs/examples/Image_034.cpp @@ -0,0 +1,28 @@ +#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 "fiddle/examples.h" +// HASH=80856fe921ce36f8d5a32d8672bccbfc +REG_FIDDLE(Image_034, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + struct { + const char* name; + sk_sp image; + } tests[] = { { "image", image }, { "bitmap", SkImage::MakeFromBitmap(source) }, + { "texture", SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, + kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, + kOpaque_SkAlphaType, nullptr) } }; + SkString string; + SkPaint paint; + for (const auto& test : tests ) { + if (!test.image) { + string.printf("no %s", test.name); + } else { + string.printf("%s" "encoded %s", test.image->refEncodedData() ? "" : "no ", test.name); + } + canvas->drawString(string, 10, 20, paint); + canvas->translate(0, 20); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_035.cpp b/docs/examples/Image_035.cpp new file mode 100644 index 0000000000..dc3ad6c424 --- /dev/null +++ b/docs/examples/Image_035.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=889e495ce3e3b3bacc96e8230932331c +REG_FIDDLE(Image_035, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + canvas->scale(.5f, .5f); + const int width = 64; + const int height = 64; + for (int y = 0; y < 512; y += height ) { + for (int x = 0; x < 512; x += width ) { + sk_sp subset(image->makeSubset({x, y, x + width, y + height})); + canvas->drawImage(subset, x * 3 / 2, y * 3 / 2); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Image_036.cpp b/docs/examples/Image_036.cpp new file mode 100644 index 0000000000..a6d028054a --- /dev/null +++ b/docs/examples/Image_036.cpp @@ -0,0 +1,30 @@ +#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 "fiddle/examples.h" +// HASH=eeec9e07e604b44d0208899a2fe5bef5 +REG_FIDDLE(Image_036, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + auto drawImage = [=](sk_sp image, GrContext* context, const char* label) -> void { + if (nullptr == image || nullptr == context) { + return; + } + SkPaint paint; + paint.setAntiAlias(true); + sk_sp texture(image->makeTextureImage(context, nullptr)); + canvas->drawImage(texture, 0, 0); + canvas->drawString(label, 20, texture->height() / 4, paint); + }; + sk_sp bitmapImage(SkImage::MakeFromBitmap(source)); + GrContext* context = canvas->getGrContext(); + sk_sp textureImage(SkImage::MakeFromTexture(context, backEndTexture, + kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, + kOpaque_SkAlphaType, nullptr)); + drawImage(image, context, "image"); + canvas->translate(image->width(), 0); + drawImage(bitmapImage, context, "source"); + canvas->translate(-image->width(), image->height()); + drawImage(textureImage, context, "backEndTexture"); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_037.cpp b/docs/examples/Image_037.cpp new file mode 100644 index 0000000000..fd80e84e7a --- /dev/null +++ b/docs/examples/Image_037.cpp @@ -0,0 +1,29 @@ +#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 "fiddle/examples.h" +// HASH=ecdbaff44a02c310ef672b7d393c6dea +REG_FIDDLE(Image_037, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + auto drawImage = [=](sk_sp image, const char* label) -> void { + if (nullptr == image) { + return; + } + SkPaint paint; + paint.setAntiAlias(true); + sk_sp nonTexture(image->makeNonTextureImage()); + canvas->drawImage(nonTexture, 0, 0); + canvas->drawString(label, 20, nonTexture->height() / 4, paint); + }; + sk_sp bitmapImage(SkImage::MakeFromBitmap(source)); + sk_sp textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, + kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, + kOpaque_SkAlphaType, nullptr)); + drawImage(image, "image"); + canvas->translate(image->width(), 0); + drawImage(bitmapImage, "source"); + canvas->translate(-image->width(), image->height()); + drawImage(textureImage, "backEndTexture"); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_038.cpp b/docs/examples/Image_038.cpp new file mode 100644 index 0000000000..9fc438d095 --- /dev/null +++ b/docs/examples/Image_038.cpp @@ -0,0 +1,29 @@ +#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 "fiddle/examples.h" +// HASH=aed5f399915d40bb5d133ab586e5bac3 +REG_FIDDLE(Image_038, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + auto drawImage = [=](sk_sp image, const char* label) -> void { + if (nullptr == image) { + return; + } + SkPaint paint; + paint.setAntiAlias(true); + sk_sp raster(image->makeRasterImage()); + canvas->drawImage(raster, 0, 0); + canvas->drawString(label, 20, raster->height() / 4, paint); + }; + sk_sp bitmapImage(SkImage::MakeFromBitmap(source)); + sk_sp textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, + kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, + kOpaque_SkAlphaType, nullptr)); + drawImage(image, "image"); + canvas->translate(image->width(), 0); + drawImage(bitmapImage, "source"); + canvas->translate(-image->width(), image->height()); + drawImage(textureImage, "backEndTexture"); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_039.cpp b/docs/examples/Image_039.cpp new file mode 100644 index 0000000000..e8e9414a1c --- /dev/null +++ b/docs/examples/Image_039.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=85a76163138a2720ac003691d6363938 +REG_FIDDLE(Image_039, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + sk_sp shadowFilter = SkDropShadowImageFilter::Make( + -10.0f * frame, 5.0f * frame, 3.0f, 3.0f, SK_ColorBLUE, + SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, + nullptr); + sk_sp offsetFilter = SkOffsetImageFilter::Make(40, 40, shadowFilter, nullptr); + SkIRect subset = image->bounds(); + SkIRect clipBounds = image->bounds(); + clipBounds.outset(60, 60); + SkIRect outSubset; + SkIPoint offset; + sk_sp filtered(image->makeWithFilter(offsetFilter.get(), subset, clipBounds, + &outSubset, &offset)); + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawLine(0, 0, offset.fX, offset.fY, paint); + canvas->translate(offset.fX, offset.fY); + canvas->drawImage(filtered, 0, 0); + canvas->drawRect(SkRect::Make(outSubset), paint); +} +} // END FIDDLE diff --git a/docs/examples/Image_040.cpp b/docs/examples/Image_040.cpp new file mode 100644 index 0000000000..7f8488e543 --- /dev/null +++ b/docs/examples/Image_040.cpp @@ -0,0 +1,34 @@ +// 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 "fiddle/examples.h" +// HASH=06aeb3cf63ffccf7b49fe556e5def351 +REG_FIDDLE(Image_040, 256, 64, false, 0) { +static sk_sp create_gpu_image(GrContext* grContext) { + const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); + auto surface(SkSurface::MakeRenderTarget(grContext, SkBudgeted::kNo, info)); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(SK_ColorWHITE); + SkPaint paint; + paint.setColor(SK_ColorBLACK); + canvas->drawRect(SkRect::MakeXYWH(5, 5, 10, 10), paint); + return surface->makeImageSnapshot(); +} + +void draw(SkCanvas* canvas) { + GrContext* grContext = canvas->getGrContext(); + if (!grContext) { + return; + } + sk_sp backEndImage = create_gpu_image(grContext); + canvas->drawImage(backEndImage, 0, 0); + GrBackendTexture texture; + SkImage::BackendTextureReleaseProc proc; + if (!SkImage::MakeBackendTextureFromSkImage(grContext, std::move(backEndImage), + &texture, &proc)) { + return; + } + sk_sp i2 = SkImage::MakeFromTexture(grContext, texture, kTopLeft_GrSurfaceOrigin, + kN32_SkColorType, kOpaque_SkAlphaType, nullptr); + canvas->drawImage(i2, 30, 30); +} +} // END FIDDLE diff --git a/docs/examples/Image_041.cpp b/docs/examples/Image_041.cpp new file mode 100644 index 0000000000..4431c9d259 --- /dev/null +++ b/docs/examples/Image_041.cpp @@ -0,0 +1,35 @@ +#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 "fiddle/examples.h" +// HASH=a8b8bd4bfe968e2c63085f867665227f +REG_FIDDLE(Image_041, 256, 80, false, 0) { +class TestImageGenerator : public SkImageGenerator { +public: + TestImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(10, 10)) {} + ~TestImageGenerator() override {} +protected: + bool onGetPixels(const SkImageInfo& info, void* pixelPtr, size_t rowBytes, + const Options& options) override { + SkPMColor* pixels = static_cast(pixelPtr); + for (int y = 0; y < info.height(); ++y) { + for (int x = 0; x < info.width(); ++x) { + pixels[y * info.width() + x] = 0xff223344 + y * 0x000C0811; + } + } + return true; + } +}; + +void draw(SkCanvas* canvas) { + auto gen = std::unique_ptr(new TestImageGenerator()); + sk_sp image(SkImage::MakeFromGenerator(std::move(gen))); + SkString lazy(image->isLazyGenerated() ? "is lazy" : "not lazy"); + canvas->scale(8, 8); + canvas->drawImage(image, 0, 0, nullptr); + SkPaint paint; + paint.setTextSize(4); + canvas->drawString(lazy, 2, 5, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_042.cpp b/docs/examples/Image_042.cpp new file mode 100644 index 0000000000..f3c040cc94 --- /dev/null +++ b/docs/examples/Image_042.cpp @@ -0,0 +1,31 @@ +#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 "fiddle/examples.h" +// HASH=f031c2a53f6a57833dc0127e674553da +REG_FIDDLE(Image_042, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + auto drawImage = [=](sk_sp image, const char* label) -> void { + if (nullptr == image) { + return; + } + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawImage(image, 0, 0); + canvas->drawString(label, 30, image->height() / 4, paint); + canvas->drawString( + image->isLazyGenerated() ? "is lazily generated" : "not lazily generated", + 20, image->height() * 3 / 4, paint); + }; + sk_sp bitmapImage(SkImage::MakeFromBitmap(source)); + sk_sp textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture, + kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType, + kOpaque_SkAlphaType, nullptr)); + drawImage(image, "image"); + canvas->translate(image->width(), 0); + drawImage(bitmapImage, "source"); + canvas->translate(-image->width(), image->height()); + drawImage(textureImage, "backEndTexture"); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Image_043.cpp b/docs/examples/Image_043.cpp new file mode 100644 index 0000000000..bbab4a3927 --- /dev/null +++ b/docs/examples/Image_043.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=dbf5f75c1275a3013672f896767140fb +REG_FIDDLE(Image_043, 256, 256, false, 5) { +void draw(SkCanvas* canvas) { + sk_sp normalColorSpace = SkColorSpace::MakeRGB( + SkColorSpace::kSRGB_RenderTargetGamma, SkColorSpace::kSRGB_Gamut); + sk_sp wackyColorSpace = normalColorSpace->makeColorSpin(); + for (auto colorSpace : { normalColorSpace, wackyColorSpace } ) { + sk_sp colorSpaced = image->makeColorSpace(colorSpace); + canvas->drawImage(colorSpaced, 0, 0); + canvas->translate(128, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_000.cpp b/docs/examples/Matrix_000.cpp new file mode 100644 index 0000000000..ec41e41ead --- /dev/null +++ b/docs/examples/Matrix_000.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=7ff17718111df6d6f95381d8a8f1b389 +REG_FIDDLE(Matrix_000, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + canvas->concat(SkMatrix::MakeScale(4, 3)); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_001.cpp b/docs/examples/Matrix_001.cpp new file mode 100644 index 0000000000..99dba42833 --- /dev/null +++ b/docs/examples/Matrix_001.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=2956aeb50fa862cdb13995e1e56a4bc8 +REG_FIDDLE(Matrix_001, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + canvas->concat(SkMatrix::MakeScale(4)); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_002.cpp b/docs/examples/Matrix_002.cpp new file mode 100644 index 0000000000..7a6fe226a1 --- /dev/null +++ b/docs/examples/Matrix_002.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=b2479df0d9cf296ff64ac31e36684557 +REG_FIDDLE(Matrix_002, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + SkMatrix matrix = SkMatrix::MakeTrans(64, 48); + for (int i = 0; i < 4; ++i) { + canvas->drawBitmap(source, 0, 0); + canvas->concat(matrix); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_003.cpp b/docs/examples/Matrix_003.cpp new file mode 100644 index 0000000000..9709cdef9f --- /dev/null +++ b/docs/examples/Matrix_003.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=6bad83b64de9266e323c29d550e04188 +REG_FIDDLE(Matrix_003, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint p; + p.setAntiAlias(true); + p.setTextSize(64); + for (SkScalar sx : { -1, 1 } ) { + for (SkScalar sy : { -1, 1 } ) { + SkAutoCanvasRestore autoRestore(canvas, true); + SkMatrix m = SkMatrix::MakeAll(sx, 1, 128, 0, sy, 128, 0, 0, 1); + canvas->concat(m); + canvas->drawString("K", 0, 0, p); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_004.cpp b/docs/examples/Matrix_004.cpp new file mode 100644 index 0000000000..ad8f1c5919 --- /dev/null +++ b/docs/examples/Matrix_004.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=ba19b36df8cd78586f3dff54e2d4c093 +REG_FIDDLE(Matrix_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkMatrix& matrix) -> void { + SkString typeMask; + typeMask += SkMatrix::kIdentity_Mask == matrix.getType() ? "kIdentity_Mask " : ""; + typeMask += SkMatrix::kTranslate_Mask & matrix.getType() ? "kTranslate_Mask " : ""; + typeMask += SkMatrix::kScale_Mask & matrix.getType() ? "kScale_Mask " : ""; + typeMask += SkMatrix::kAffine_Mask & matrix.getType() ? "kAffine_Mask " : ""; + typeMask += SkMatrix::kPerspective_Mask & matrix.getType() ? "kPerspective_Mask" : ""; + SkDebugf("after %s: %s\n", prefix, typeMask.c_str()); + }; +SkMatrix matrix; +matrix.reset(); +debugster("reset", matrix); +matrix.postTranslate(1, 0); +debugster("postTranslate", matrix); +matrix.postScale(2, 1); +debugster("postScale", matrix); +matrix.postRotate(45); +debugster("postScale", matrix); +SkPoint polys[][4] = {{{0, 0}, {0, 1}, {1, 1}, {1, 0}}, {{0, 0}, {0, 1}, {2, 1}, {1, 0}}}; +matrix.setPolyToPoly(polys[0], polys[1], 4); +debugster("setPolyToPoly", matrix); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_005.cpp b/docs/examples/Matrix_005.cpp new file mode 100644 index 0000000000..940cd68698 --- /dev/null +++ b/docs/examples/Matrix_005.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=8e45fe2dd52731bb2d4318686257e1d7 +REG_FIDDLE(Matrix_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); + SkDebugf("identity flags hex: %0x decimal: %d\n", matrix.getType(), matrix.getType()); + matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, .5f); + SkDebugf("set all flags hex: %0x decimal: %d\n", matrix.getType(), matrix.getType()); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_006.cpp b/docs/examples/Matrix_006.cpp new file mode 100644 index 0000000000..ae7a68f1c6 --- /dev/null +++ b/docs/examples/Matrix_006.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=780ab376325b3cfa889ea26c0769ec11 +REG_FIDDLE(Matrix_006, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); + SkDebugf("is identity: %s\n", matrix.isIdentity() ? "true" : "false"); + matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 2); + SkDebugf("is identity: %s\n", matrix.isIdentity() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_007.cpp b/docs/examples/Matrix_007.cpp new file mode 100644 index 0000000000..0b33783e14 --- /dev/null +++ b/docs/examples/Matrix_007.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=6287e29674a487eb94174992d45b9a34 +REG_FIDDLE(Matrix_007, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + for (SkScalar scaleX : { 1, 2 } ) { + for (SkScalar translateX : { 0, 20 } ) { + matrix.setAll(scaleX, 0, translateX, 0, 1, 0, 0, 0, 1); + SkDebugf("is scale-translate: %s\n", matrix.isScaleTranslate() ? "true" : "false"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_008.cpp b/docs/examples/Matrix_008.cpp new file mode 100644 index 0000000000..3a231d9b5c --- /dev/null +++ b/docs/examples/Matrix_008.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=73ac71a8a30841873577c11c6c9b38ee +REG_FIDDLE(Matrix_008, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + for (SkScalar scaleX : { 1, 2 } ) { + for (SkScalar translateX : { 0, 20 } ) { + matrix.setAll(scaleX, 0, translateX, 0, 1, 0, 0, 0, 1); + SkDebugf("is translate: %s\n", matrix.isTranslate() ? "true" : "false"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_009.cpp b/docs/examples/Matrix_009.cpp new file mode 100644 index 0000000000..b178cf5866 --- /dev/null +++ b/docs/examples/Matrix_009.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=ce5319c036c9b5086da8a0009fe409f8 +REG_FIDDLE(Matrix_009, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + for (SkScalar angle: { 0, 90, 180, 270 } ) { + matrix.setRotate(angle); + SkDebugf("rectStaysRect: %s\n", matrix.rectStaysRect() ? "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_010.cpp b/docs/examples/Matrix_010.cpp new file mode 100644 index 0000000000..e33c48aa60 --- /dev/null +++ b/docs/examples/Matrix_010.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=7a234c96608fb7cb8135b9940b0b15f7 +REG_FIDDLE(Matrix_010, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + for (SkScalar angle: { 0, 90, 180, 270 } ) { + matrix.setRotate(angle); + SkDebugf("preservesAxisAlignment: %s\n", matrix.preservesAxisAlignment() ? "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_011.cpp b/docs/examples/Matrix_011.cpp new file mode 100644 index 0000000000..a5113365c8 --- /dev/null +++ b/docs/examples/Matrix_011.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=688123908c733169bbbfaf11f41ecff6 +REG_FIDDLE(Matrix_011, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + canvas->concat(matrix); + SkString string; + string.printf("hasPerspective %s", matrix.hasPerspective() ? "true" : "false"); + canvas->drawBitmap(source, 0, 0); + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(48); + canvas->drawString(string, 0, source.bounds().height() + 48, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_012.cpp b/docs/examples/Matrix_012.cpp new file mode 100644 index 0000000000..8b2619b47d --- /dev/null +++ b/docs/examples/Matrix_012.cpp @@ -0,0 +1,31 @@ +#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 "fiddle/examples.h" +// HASH=8b37f4ae7fec1756433c0f984175fb14 +REG_FIDDLE(Matrix_012, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint p; + p.setAntiAlias(true); + SkMatrix m; + int below = 175; + for (SkScalar sx : { -1, 1 } ) { + for (SkScalar sy : { -1, 1 } ) { + m.setAll(sx, 1, 128, 1, sy, 32, 0, 0, 1); + bool isSimilarity = m.isSimilarity(); + SkString str; + str.printf("sx: %g sy: %g sim: %s", sx, sy, isSimilarity ? "true" : "false"); + { + SkAutoCanvasRestore autoRestore(canvas, true); + canvas->concat(m); + canvas->drawString(str, 0, 0, p); + } + if (!isSimilarity) { + canvas->drawString(str, 40, below, p); + below += 20; + } + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_013.cpp b/docs/examples/Matrix_013.cpp new file mode 100644 index 0000000000..11c21db130 --- /dev/null +++ b/docs/examples/Matrix_013.cpp @@ -0,0 +1,28 @@ +#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 "fiddle/examples.h" +// HASH=b9becf0dc24a9f00726e24a81fb72f16 +REG_FIDDLE(Matrix_013, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint p; + p.setAntiAlias(true); + SkMatrix m; + int pos = 0; + for (SkScalar sx : { 1, 2 } ) { + for (SkScalar kx : { 0, 1 } ) { + m.setAll(sx, kx, 16, 0, 1, 32, 0, 0, 1); + bool isSimilarity = m.isSimilarity(); + bool preservesRightAngles = m.preservesRightAngles(); + SkString str; + str.printf("sx: %g kx: %g %s %s", sx, kx, isSimilarity ? "sim" : "", + preservesRightAngles ? "right" : ""); + SkAutoCanvasRestore autoRestore(canvas, true); + canvas->concat(m); + canvas->drawString(str, 0, pos, p); + pos += 20; + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_014.cpp b/docs/examples/Matrix_014.cpp new file mode 100644 index 0000000000..3254caad1e --- /dev/null +++ b/docs/examples/Matrix_014.cpp @@ -0,0 +1,28 @@ +#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 "fiddle/examples.h" +// HASH=3bbf75f4748420810aa2586e3c8548d9 +REG_FIDDLE(Matrix_014, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint black; + black.setAntiAlias(true); + black.setTextSize(48); + SkPaint gray = black; + gray.setColor(0xFF9f9f9f); + SkScalar offset[] = { 1.5f, 1.5f, 20, 1.5f, 1.5f, 20, .03f, .01f, 2 }; + for (int i : { SkMatrix::kMScaleX, SkMatrix::kMSkewX, SkMatrix::kMTransX, + SkMatrix::kMSkewY, SkMatrix::kMScaleY, SkMatrix::kMTransY, + SkMatrix::kMPersp0, SkMatrix::kMPersp1, SkMatrix::kMPersp2 } ) { + SkMatrix m; + m.setIdentity(); + m.set(i, offset[i]); + SkAutoCanvasRestore autoRestore(canvas, true); + canvas->translate(22 + (i % 3) * 88, 44 + (i / 3) * 88); + canvas->drawString("&", 0, 0, gray); + canvas->concat(m); + canvas->drawString("&", 0, 0, black); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_015.cpp b/docs/examples/Matrix_015.cpp new file mode 100644 index 0000000000..8f2ac3ceef --- /dev/null +++ b/docs/examples/Matrix_015.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=e8740493abdf0c6341762db9cee56b89 +REG_FIDDLE(Matrix_015, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setScale(42, 24); + SkDebugf("matrix[SkMatrix::kMScaleX] %c= 42\n", matrix[SkMatrix::kMScaleX] == 42 ? '=' : '!'); + SkDebugf("matrix[SkMatrix::kMScaleY] %c= 24\n", matrix[SkMatrix::kMScaleY] == 24 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_016.cpp b/docs/examples/Matrix_016.cpp new file mode 100644 index 0000000000..60048ed56f --- /dev/null +++ b/docs/examples/Matrix_016.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=f5ed382bd04fa7d50b2398cce2fca23a +REG_FIDDLE(Matrix_016, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setSkew(42, 24); + SkDebugf("matrix.get(SkMatrix::kMSkewX) %c= 42\n", + matrix.get(SkMatrix::kMSkewX) == 42 ? '=' : '!'); + SkDebugf("matrix.get(SkMatrix::kMSkewY) %c= 24\n", + matrix.get(SkMatrix::kMSkewY) == 24 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_017.cpp b/docs/examples/Matrix_017.cpp new file mode 100644 index 0000000000..10224472a5 --- /dev/null +++ b/docs/examples/Matrix_017.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=ab746d9be63975041ae8e50cba84dc3d +REG_FIDDLE(Matrix_017, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setScale(42, 24); + SkDebugf("matrix.getScaleX() %c= 42\n", matrix.getScaleX() == 42 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_018.cpp b/docs/examples/Matrix_018.cpp new file mode 100644 index 0000000000..75d82faa30 --- /dev/null +++ b/docs/examples/Matrix_018.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=708b1a548a2f8661b2ab570782fbc751 +REG_FIDDLE(Matrix_018, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setScale(42, 24); + SkDebugf("matrix.getScaleY() %c= 24\n", matrix.getScaleY() == 24 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_019.cpp b/docs/examples/Matrix_019.cpp new file mode 100644 index 0000000000..0c687225de --- /dev/null +++ b/docs/examples/Matrix_019.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=6be5704506d029ffc91ba03b1d3e674b +REG_FIDDLE(Matrix_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setSkew(42, 24); + SkDebugf("matrix.getSkewY() %c= 24\n", matrix.getSkewY() == 24 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_020.cpp b/docs/examples/Matrix_020.cpp new file mode 100644 index 0000000000..33747132fb --- /dev/null +++ b/docs/examples/Matrix_020.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=df3a5d3c688e7597eae1e4e07bf91ae6 +REG_FIDDLE(Matrix_020, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setSkew(42, 24); + SkDebugf("matrix.getSkewX() %c= 42\n", matrix.getSkewX() == 42 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_021.cpp b/docs/examples/Matrix_021.cpp new file mode 100644 index 0000000000..a2def0b923 --- /dev/null +++ b/docs/examples/Matrix_021.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=6236f7f2b91aff977a66ba2ee2558ca4 +REG_FIDDLE(Matrix_021, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setTranslate(42, 24); + SkDebugf("matrix.getTranslateX() %c= 42\n", matrix.getTranslateX() == 42 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_022.cpp b/docs/examples/Matrix_022.cpp new file mode 100644 index 0000000000..2cacf70db2 --- /dev/null +++ b/docs/examples/Matrix_022.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=08464e32d22421d2b254c71a84545ef5 +REG_FIDDLE(Matrix_022, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setTranslate(42, 24); + SkDebugf("matrix.getTranslateY() %c= 24\n", matrix.getTranslateY() == 24 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_023.cpp b/docs/examples/Matrix_023.cpp new file mode 100644 index 0000000000..1c910797ac --- /dev/null +++ b/docs/examples/Matrix_023.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=a0f5bf4b55e8c33bfda29bf67e34306f +REG_FIDDLE(Matrix_023, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkMatrix m; + m.setIdentity(); + m.set(SkMatrix::kMPersp0, -0.004f); + SkAutoCanvasRestore autoRestore(canvas, true); + canvas->translate(22, 144); + SkPaint black; + black.setAntiAlias(true); + black.setTextSize(24); + SkPaint gray = black; + gray.setColor(0xFF9f9f9f); + SkString string; + string.appendScalar(m.getPerspX()); + canvas->drawString(string, 0, -72, gray); + canvas->concat(m); + canvas->drawString(string, 0, 0, black); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_024.cpp b/docs/examples/Matrix_024.cpp new file mode 100644 index 0000000000..6c256770f9 --- /dev/null +++ b/docs/examples/Matrix_024.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=424a00a73675dbd99ad20feb0267442b +REG_FIDDLE(Matrix_024, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkMatrix m; + m.setIdentity(); + m.set(SkMatrix::kMPersp1, -0.004f); + SkAutoCanvasRestore autoRestore(canvas, true); + canvas->translate(22, 144); + SkPaint black; + black.setAntiAlias(true); + black.setTextSize(24); + SkPaint gray = black; + gray.setColor(0xFF9f9f9f); + SkString string; + string.appendScalar(m.getPerspY()); + canvas->drawString(string, 0, -72, gray); + canvas->concat(m); + canvas->drawString(string, 0, 0, black); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_025.cpp b/docs/examples/Matrix_025.cpp new file mode 100644 index 0000000000..1a38f5bc78 --- /dev/null +++ b/docs/examples/Matrix_025.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=f4365ef332f51f7fd25040e0771ba9a2 +REG_FIDDLE(Matrix_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setIdentity(); + SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX); + SkScalar& skewRef = matrix[SkMatrix::kMSkewX]; + skewRef = 0; + SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); + skewRef = 1; + SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); + matrix.dirtyMatrixTypeCache(); + SkDebugf("after dirty cache: x = %g\n", matrix.mapXY(24, 42).fX); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_026.cpp b/docs/examples/Matrix_026.cpp new file mode 100644 index 0000000000..90b67449e8 --- /dev/null +++ b/docs/examples/Matrix_026.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=1d400a92ca826cc89bcb88ea051f28c8 +REG_FIDDLE(Matrix_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setIdentity(); + SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX); + matrix.set(SkMatrix::kMSkewX, 0); + SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); + matrix.set(SkMatrix::kMSkewX, 1); + SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_027.cpp b/docs/examples/Matrix_027.cpp new file mode 100644 index 0000000000..036476c918 --- /dev/null +++ b/docs/examples/Matrix_027.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=a39dfed98c3c3c3a56be9ad59fe4e21e +REG_FIDDLE(Matrix_027, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + canvas->drawString("normal", 12, 24, paint); + SkMatrix matrix; + matrix.setIdentity(); + matrix.setScaleX(3); + canvas->concat(matrix); + canvas->drawString("x scale", 0, 48, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_028.cpp b/docs/examples/Matrix_028.cpp new file mode 100644 index 0000000000..10ce3bbb98 --- /dev/null +++ b/docs/examples/Matrix_028.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=f040c6dd85a02e94eaca00d5c2832604 +REG_FIDDLE(Matrix_028, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + canvas->drawString("normal", 12, 24, paint); + SkMatrix matrix; + matrix.setIdentity(); + matrix.setScaleY(3); + canvas->concat(matrix); + canvas->drawString("y scale", 12, 48, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_029.cpp b/docs/examples/Matrix_029.cpp new file mode 100644 index 0000000000..69d0679de3 --- /dev/null +++ b/docs/examples/Matrix_029.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=b418d15df9829aefcc6aca93a37428bb +REG_FIDDLE(Matrix_029, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + canvas->drawString("normal", 12, 24, paint); + SkMatrix matrix; + matrix.setIdentity(); + matrix.setSkewY(.3f); + canvas->concat(matrix); + canvas->drawString("y skew", 12, 48, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_030.cpp b/docs/examples/Matrix_030.cpp new file mode 100644 index 0000000000..2f82a8615d --- /dev/null +++ b/docs/examples/Matrix_030.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=c7177a6fbc1545be95a5ebca87e0cd0d +REG_FIDDLE(Matrix_030, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + canvas->drawString("normal", 12, 24, paint); + SkMatrix matrix; + matrix.setIdentity(); + matrix.setSkewX(-.7f); + canvas->concat(matrix); + canvas->drawString("x skew", 36, 48, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_031.cpp b/docs/examples/Matrix_031.cpp new file mode 100644 index 0000000000..7426973566 --- /dev/null +++ b/docs/examples/Matrix_031.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=a18bc2e3607ac3a8e438bcb61fb13130 +REG_FIDDLE(Matrix_031, 256, 48, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + canvas->drawString("normal", 8, 24, paint); + SkMatrix matrix; + matrix.setIdentity(); + matrix.setTranslateX(96); + canvas->concat(matrix); + canvas->drawString("x translate", 8, 24, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_032.cpp b/docs/examples/Matrix_032.cpp new file mode 100644 index 0000000000..c94da6c582 --- /dev/null +++ b/docs/examples/Matrix_032.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=34e3c70a72b836abf7f4858d35eecc98 +REG_FIDDLE(Matrix_032, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + canvas->drawString("normal", 8, 24, paint); + SkMatrix matrix; + matrix.setIdentity(); + matrix.setTranslateY(24); + canvas->concat(matrix); + canvas->drawString("y translate", 8, 24, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_033.cpp b/docs/examples/Matrix_033.cpp new file mode 100644 index 0000000000..932065f3b1 --- /dev/null +++ b/docs/examples/Matrix_033.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=830a9e4e4bb93d25afd83b2fea63929e +REG_FIDDLE(Matrix_033, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + for (SkScalar perspX : { -.003f, 0.f, .003f, .012f } ) { + SkMatrix matrix; + matrix.setIdentity(); + matrix.setPerspX(perspX); + canvas->save(); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); + canvas->restore(); + canvas->translate(64, 64); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_034.cpp b/docs/examples/Matrix_034.cpp new file mode 100644 index 0000000000..275cdfedd9 --- /dev/null +++ b/docs/examples/Matrix_034.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=aeb258b7922c1a11b698b00f562182ec +REG_FIDDLE(Matrix_034, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + for (SkScalar perspX : { -.003f, 0.f, .003f, .012f } ) { + SkMatrix matrix; + matrix.setIdentity(); + matrix.setPerspY(perspX); + canvas->save(); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); + canvas->restore(); + canvas->translate(64, 64); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_035.cpp b/docs/examples/Matrix_035.cpp new file mode 100644 index 0000000000..8151080433 --- /dev/null +++ b/docs/examples/Matrix_035.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=95ccfc2a89ce593e6b7a9f992a844bc0 +REG_FIDDLE(Matrix_035, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint p; + p.setAntiAlias(true); + p.setTextSize(64); + SkMatrix m; + for (SkScalar sx : { -1, 1 } ) { + for (SkScalar sy : { -1, 1 } ) { + SkAutoCanvasRestore autoRestore(canvas, true); + m.setAll(sx, 1, 128, 0, sy, 64, 0, 0, 1); + canvas->concat(m); + canvas->drawString("K", 0, 0, p); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_036.cpp b/docs/examples/Matrix_036.cpp new file mode 100644 index 0000000000..8c2959c78b --- /dev/null +++ b/docs/examples/Matrix_036.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=379fc375e011050b54ed9df83c0996a7 +REG_FIDDLE(Matrix_036, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix = SkMatrix::MakeRectToRect({0, 0, 1, 1}, {3, 4, 7, 9}, + SkMatrix::kFill_ScaleToFit); + SkScalar b[9]; + matrix.get9(b); + SkDebugf("{%g, %g, %g},\n{%g, %g, %g},\n{%g, %g, %g}\n", b[0], b[1], b[2], + b[3], b[4], b[5], b[6], b[7], b[8]); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_037.cpp b/docs/examples/Matrix_037.cpp new file mode 100644 index 0000000000..d9e65cb0ed --- /dev/null +++ b/docs/examples/Matrix_037.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=ec5de0d23e5fe28ba7628625d1402e85 +REG_FIDDLE(Matrix_037, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + SkMatrix m; + SkScalar buffer[9] = {4, 0, 3, 0, 5, 4, 0, 0, 1}; + m.set9(buffer); + canvas->concat(m); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_038.cpp b/docs/examples/Matrix_038.cpp new file mode 100644 index 0000000000..16b8c88aa9 --- /dev/null +++ b/docs/examples/Matrix_038.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=ca94f7922bc37ef03bbc51ad70536fcf +REG_FIDDLE(Matrix_038, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix m; + m.reset(); + SkDebugf("m.isIdentity(): %s\n", m.isIdentity() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_039.cpp b/docs/examples/Matrix_039.cpp new file mode 100644 index 0000000000..9b3ab43f68 --- /dev/null +++ b/docs/examples/Matrix_039.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=3979c865bb482e6ef1fafc71e56bbb91 +REG_FIDDLE(Matrix_039, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix m; + m.setIdentity(); + SkDebugf("m.isIdentity(): %s\n", m.isIdentity() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_040.cpp b/docs/examples/Matrix_040.cpp new file mode 100644 index 0000000000..f808fbcee0 --- /dev/null +++ b/docs/examples/Matrix_040.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=63ca62985741b1bccb5e8b9cf734874e +REG_FIDDLE(Matrix_040, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + canvas->drawString("normal", 8, 24, paint); + SkMatrix matrix; + matrix.setTranslate(96, 24); + canvas->concat(matrix); + canvas->drawString("translate", 8, 24, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_041.cpp b/docs/examples/Matrix_041.cpp new file mode 100644 index 0000000000..53a6afbfab --- /dev/null +++ b/docs/examples/Matrix_041.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=ccfc734aff2ddea0b097c83f5621de5e +REG_FIDDLE(Matrix_041, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + canvas->drawString("normal", 8, 24, paint); + SkMatrix matrix; + matrix.setTranslate({96, 24}); + canvas->concat(matrix); + canvas->drawString("translate", 8, 24, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_042.cpp b/docs/examples/Matrix_042.cpp new file mode 100644 index 0000000000..506037b174 --- /dev/null +++ b/docs/examples/Matrix_042.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=4565a0792058178c88e0a129a87272d6 +REG_FIDDLE(Matrix_042, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint p; + p.setAntiAlias(true); + p.setTextSize(64); + SkMatrix m; + for (SkScalar sx : { -1, 1 } ) { + for (SkScalar sy : { -1, 1 } ) { + SkAutoCanvasRestore autoRestore(canvas, true); + m.setScale(sx, sy, 128, 64); + canvas->concat(m); + canvas->drawString("%", 128, 64, p); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_043.cpp b/docs/examples/Matrix_043.cpp new file mode 100644 index 0000000000..ec67714480 --- /dev/null +++ b/docs/examples/Matrix_043.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=1579d0cc109c26e69f66f73abd35fb0e +REG_FIDDLE(Matrix_043, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint p; + p.setAntiAlias(true); + p.setTextSize(64); + SkMatrix m; + for (SkScalar sx : { -1, 1 } ) { + for (SkScalar sy : { -1, 1 } ) { + SkAutoCanvasRestore autoRestore(canvas, true); + m.setScale(sx, sy); + m.postTranslate(128, 64); + canvas->concat(m); + canvas->drawString("@", 0, 0, p); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_044.cpp b/docs/examples/Matrix_044.cpp new file mode 100644 index 0000000000..211c756da2 --- /dev/null +++ b/docs/examples/Matrix_044.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=8c28db3add9cd0177225088f6df6bbb5 +REG_FIDDLE(Matrix_044, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorGRAY); + paint.setAntiAlias(true); + SkRect rect = {20, 20, 100, 100}; + canvas->drawRect(rect, paint); + paint.setColor(SK_ColorRED); + SkMatrix matrix; + matrix.setRotate(25, rect.centerX(), rect.centerY()); + canvas->concat(matrix); + canvas->drawRect(rect, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_045.cpp b/docs/examples/Matrix_045.cpp new file mode 100644 index 0000000000..a16b7e3526 --- /dev/null +++ b/docs/examples/Matrix_045.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=93efb9d191bf1b9710c173513e014d6c +REG_FIDDLE(Matrix_045, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorGRAY); + paint.setAntiAlias(true); + SkRect rect = {20, 20, 100, 100}; + canvas->drawRect(rect, paint); + paint.setColor(SK_ColorRED); + SkMatrix matrix; + matrix.setRotate(25); + canvas->translate(rect.centerX(), rect.centerY()); + canvas->concat(matrix); + canvas->translate(-rect.centerX(), -rect.centerY()); + canvas->drawRect(rect, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_046.cpp b/docs/examples/Matrix_046.cpp new file mode 100644 index 0000000000..b3542f1ecb --- /dev/null +++ b/docs/examples/Matrix_046.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=187e1d9228e2e4341ef820bd77b6fda9 +REG_FIDDLE(Matrix_046, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorGRAY); + paint.setAntiAlias(true); + SkRect rect = {20, 20, 100, 100}; + canvas->drawRect(rect, paint); + paint.setColor(SK_ColorRED); + SkMatrix matrix; + matrix.setSinCos(.25f, .85f, rect.centerX(), rect.centerY()); + canvas->concat(matrix); + canvas->drawRect(rect, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_047.cpp b/docs/examples/Matrix_047.cpp new file mode 100644 index 0000000000..4ac3dfd7cf --- /dev/null +++ b/docs/examples/Matrix_047.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=e37a94a53c959951b059fcd624639ef6 +REG_FIDDLE(Matrix_047, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorGRAY); + paint.setAntiAlias(true); + SkRect rect = {20, 20, 100, 100}; + canvas->drawRect(rect, paint); + paint.setColor(SK_ColorRED); + SkMatrix matrix; + matrix.setSinCos(.25f, .85f); + matrix.postTranslate(rect.centerX(), rect.centerY()); + canvas->concat(matrix); + canvas->translate(-rect.centerX(), -rect.centerY()); + canvas->drawRect(rect, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_048.cpp b/docs/examples/Matrix_048.cpp new file mode 100644 index 0000000000..420ff2ead6 --- /dev/null +++ b/docs/examples/Matrix_048.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=c3f5faddca466f78278b32b88fd5f5eb +REG_FIDDLE(Matrix_048, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorGRAY); + paint.setAntiAlias(true); + SkRect rect = {20, 20, 100, 100}; + canvas->drawRect(rect, paint); + paint.setColor(SK_ColorRED); + SkMatrix matrix; + matrix.setRSXform(SkRSXform::Make(.85f, .25f, rect.centerX(), rect.centerY())); + canvas->concat(matrix); + canvas->translate(-rect.centerX(), -rect.centerY()); + canvas->drawRect(rect, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_049.cpp b/docs/examples/Matrix_049.cpp new file mode 100644 index 0000000000..62a59ed8b0 --- /dev/null +++ b/docs/examples/Matrix_049.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=55e0431adc6c5b1987ebb8123cc10342 +REG_FIDDLE(Matrix_049, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint p; + p.setAntiAlias(true); + p.setTextSize(48); + SkMatrix m; + for (SkScalar sx : { -1, 0, 1 } ) { + for (SkScalar sy : { -1, 0, 1 } ) { + SkAutoCanvasRestore autoRestore(canvas, true); + m.setSkew(sx, sy, 96 + 64 * sx, 128 + 48 * sy); + canvas->concat(m); + canvas->drawString("K", 96 + 64 * sx, 128 + 48 * sy, p); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_050.cpp b/docs/examples/Matrix_050.cpp new file mode 100644 index 0000000000..84b49c29fe --- /dev/null +++ b/docs/examples/Matrix_050.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=05be7844e9afdd7b9bfc31c5423a70a2 +REG_FIDDLE(Matrix_050, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint p; + p.setAntiAlias(true); + p.setTextSize(48); + SkMatrix m; + for (SkScalar sx : { -1, 0, 1 } ) { + for (SkScalar sy : { -1, 0, 1 } ) { + SkAutoCanvasRestore autoRestore(canvas, true); + m.setSkew(sx, sy); + m.postTranslate(96 + 64 * sx, 128 + 48 * sy); + canvas->concat(m); + canvas->drawString("K", 0, 0, p); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_051.cpp b/docs/examples/Matrix_051.cpp new file mode 100644 index 0000000000..55e521ba0c --- /dev/null +++ b/docs/examples/Matrix_051.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=0381a10ac69bdefdf9d15b47cbb9fefe +REG_FIDDLE(Matrix_051, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix, matrix2; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix2.setPolyToPoly(perspect, bitmapBounds, 4); + matrix.setConcat(matrix, matrix2); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_052.cpp b/docs/examples/Matrix_052.cpp new file mode 100644 index 0000000000..030eda3675 --- /dev/null +++ b/docs/examples/Matrix_052.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=f75a9b629aa6c51ed888f8799b5ba5f7 +REG_FIDDLE(Matrix_052, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkRect rect = {20, 20, 100, 100}; + for (int i = 0; i < 2; ++i ) { + SkMatrix matrix; + i == 0 ? matrix.reset(): matrix.setRotate(25, rect.centerX(), 320); + { + SkAutoCanvasRestore acr(canvas, true); + canvas->concat(matrix); + paint.setColor(SK_ColorGRAY); + canvas->drawRect(rect, paint); + } + paint.setColor(SK_ColorRED); + for (int j = 0; j < 2; ++j ) { + SkAutoCanvasRestore acr(canvas, true); + matrix.preTranslate(40, 40); + canvas->concat(matrix); + canvas->drawCircle(0, 0, 3, paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_053.cpp b/docs/examples/Matrix_053.cpp new file mode 100644 index 0000000000..0a8f531309 --- /dev/null +++ b/docs/examples/Matrix_053.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=2531f8d1e05d7b6dc22f3efcd2fb84e4 +REG_FIDDLE(Matrix_053, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.preScale(.75f, 1.5f, source.width() / 2, source.height() / 2); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_054.cpp b/docs/examples/Matrix_054.cpp new file mode 100644 index 0000000000..59eb544a4c --- /dev/null +++ b/docs/examples/Matrix_054.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=3edbdea8e43d06086abf33ec4a9b415b +REG_FIDDLE(Matrix_054, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.preScale(.75f, 1.5f); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_055.cpp b/docs/examples/Matrix_055.cpp new file mode 100644 index 0000000000..e23e121e90 --- /dev/null +++ b/docs/examples/Matrix_055.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=a70bb18d67c06a20ab514e7a47924e5a +REG_FIDDLE(Matrix_055, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.preRotate(45, source.width() / 2, source.height() / 2); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_056.cpp b/docs/examples/Matrix_056.cpp new file mode 100644 index 0000000000..3596084c57 --- /dev/null +++ b/docs/examples/Matrix_056.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=5acd49bd931c79a808dd6c7cc0e92f72 +REG_FIDDLE(Matrix_056, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.preRotate(45); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_057.cpp b/docs/examples/Matrix_057.cpp new file mode 100644 index 0000000000..53502d2d1f --- /dev/null +++ b/docs/examples/Matrix_057.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=199a18ad61d702664ce6df1d7037aa48 +REG_FIDDLE(Matrix_057, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.preSkew(.5f, 0, source.width() / 2, source.height() / 2); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_058.cpp b/docs/examples/Matrix_058.cpp new file mode 100644 index 0000000000..ca1c3ee8ff --- /dev/null +++ b/docs/examples/Matrix_058.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=e100c543869fe8fd516ba69de79444ba +REG_FIDDLE(Matrix_058, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.preSkew(.5f, 0); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_059.cpp b/docs/examples/Matrix_059.cpp new file mode 100644 index 0000000000..fa0de10156 --- /dev/null +++ b/docs/examples/Matrix_059.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=b07e62298e7b0ab5683db199faffceb2 +REG_FIDDLE(Matrix_059, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix, matrix2; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix2.setPolyToPoly(perspect, bitmapBounds, 4); + matrix.preConcat(matrix2); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_060.cpp b/docs/examples/Matrix_060.cpp new file mode 100644 index 0000000000..35416819eb --- /dev/null +++ b/docs/examples/Matrix_060.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=f5144ef4bd7cea294fad2f756ed335af +REG_FIDDLE(Matrix_060, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkRect rect = {20, 20, 100, 100}; + for (int i = 0; i < 2; ++i ) { + SkMatrix matrix; + i == 0 ? matrix.reset(): matrix.setRotate(25, rect.centerX(), 320); + { + SkAutoCanvasRestore acr(canvas, true); + canvas->concat(matrix); + paint.setColor(SK_ColorGRAY); + canvas->drawRect(rect, paint); + } + paint.setColor(SK_ColorRED); + for (int j = 0; j < 2; ++j ) { + SkAutoCanvasRestore acr(canvas, true); + matrix.postTranslate(40, 40); + canvas->concat(matrix); + canvas->drawCircle(0, 0, 3, paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_061.cpp b/docs/examples/Matrix_061.cpp new file mode 100644 index 0000000000..acba60b24c --- /dev/null +++ b/docs/examples/Matrix_061.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=ed3aa18ba0ea95c85cc49aa3829fe384 +REG_FIDDLE(Matrix_061, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.postScale(.75f, 1.5f, source.width() / 2, source.height() / 2); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_062.cpp b/docs/examples/Matrix_062.cpp new file mode 100644 index 0000000000..e54a66f4b3 --- /dev/null +++ b/docs/examples/Matrix_062.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=1931017698766a67d3a26423453b8095 +REG_FIDDLE(Matrix_062, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.postScale(.75f, 1.5f); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_063.cpp b/docs/examples/Matrix_063.cpp new file mode 100644 index 0000000000..ef25b47afa --- /dev/null +++ b/docs/examples/Matrix_063.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=e6ad0bd2999613d9e4758b661d45070c +REG_FIDDLE(Matrix_063, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.postIDiv(1, 2); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_064.cpp b/docs/examples/Matrix_064.cpp new file mode 100644 index 0000000000..90c0c8b58d --- /dev/null +++ b/docs/examples/Matrix_064.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=e09194ee48a81e7b375ade473d340f0d +REG_FIDDLE(Matrix_064, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.postRotate(45, source.width() / 2, source.height() / 2); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_065.cpp b/docs/examples/Matrix_065.cpp new file mode 100644 index 0000000000..ec3ed3fc0c --- /dev/null +++ b/docs/examples/Matrix_065.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=52e4c53e26971af5576b30de60fa70c2 +REG_FIDDLE(Matrix_065, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.postRotate(45); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_066.cpp b/docs/examples/Matrix_066.cpp new file mode 100644 index 0000000000..3c4d96a9dd --- /dev/null +++ b/docs/examples/Matrix_066.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=8c34ae3a2b7e2742bb969819737365ec +REG_FIDDLE(Matrix_066, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.postSkew(.5f, 0, source.width() / 2, source.height() / 2); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_067.cpp b/docs/examples/Matrix_067.cpp new file mode 100644 index 0000000000..548e9bf351 --- /dev/null +++ b/docs/examples/Matrix_067.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=3aa2603225dff72ac53dd359f897f494 +REG_FIDDLE(Matrix_067, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.postSkew(.5f, 0); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_068.cpp b/docs/examples/Matrix_068.cpp new file mode 100644 index 0000000000..5967b5aeeb --- /dev/null +++ b/docs/examples/Matrix_068.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=e4226c55d9bdbc119264bd372b2b9835 +REG_FIDDLE(Matrix_068, 256, 64, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix.postConcat(matrix); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_069.cpp b/docs/examples/Matrix_069.cpp new file mode 100644 index 0000000000..e2b975a6b2 --- /dev/null +++ b/docs/examples/Matrix_069.cpp @@ -0,0 +1,31 @@ +#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 "fiddle/examples.h" +// HASH=17c3070b31b700ea8f52e48af9a66b6e +REG_FIDDLE(Matrix_069, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + const char* labels[] = { "Fill", "Start", "Center", "End" }; + SkRect rects[] = {{5, 5, 59, 59}, {5, 74, 59, 108}, {10, 123, 44, 172}, {10, 187, 54, 231}}; + SkRect bounds; + source.getBounds(&bounds); + SkPaint paint; + paint.setAntiAlias(true); + for (auto fit : { SkMatrix::kFill_ScaleToFit, SkMatrix::kStart_ScaleToFit, + SkMatrix::kCenter_ScaleToFit, SkMatrix::kEnd_ScaleToFit } ) { + for (auto rect : rects ) { + canvas->drawRect(rect, paint); + SkMatrix matrix; + if (!matrix.setRectToRect(bounds, rect, fit)) { + continue; + } + SkAutoCanvasRestore acr(canvas, true); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); + } + canvas->drawString(labels[fit], 10, 255, paint); + canvas->translate(64, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_070.cpp b/docs/examples/Matrix_070.cpp new file mode 100644 index 0000000000..7be4f295dd --- /dev/null +++ b/docs/examples/Matrix_070.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=69cdea599dcaaec35efcb24403f4287b +REG_FIDDLE(Matrix_070, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const SkRect srcs[] = { {0, 0, 0, 0}, {1, 2, 3, 4} }; + const SkRect dsts[] = { {0, 0, 0, 0}, {5, 6, 8, 9} }; + for (auto src : srcs) { + for (auto dst : dsts) { + SkMatrix matrix; + matrix.setAll(-1, -1, -1, -1, -1, -1, -1, -1, -1); + bool success = matrix.setRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); + SkDebugf("src: %g, %g, %g, %g dst: %g, %g, %g, %g success: %s\n", + src.fLeft, src.fTop, src.fRight, src.fBottom, + dst.fLeft, dst.fTop, dst.fRight, dst.fBottom, success ? "true" : "false"); + matrix.dump(); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_071.cpp b/docs/examples/Matrix_071.cpp new file mode 100644 index 0000000000..117613d6df --- /dev/null +++ b/docs/examples/Matrix_071.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=a1d6a6721b39350f81021f71a1b93208 +REG_FIDDLE(Matrix_071, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const SkRect srcs[] = { {0, 0, 0, 0}, {1, 2, 3, 4} }; + const SkRect dsts[] = { {0, 0, 0, 0}, {5, 6, 8, 9} }; + for (auto src : srcs) { + for (auto dst : dsts) { + SkMatrix matrix = SkMatrix::MakeRectToRect(src, dst, SkMatrix::kFill_ScaleToFit); + SkDebugf("src: %g, %g, %g, %g dst: %g, %g, %g, %g\n", + src.fLeft, src.fTop, src.fRight, src.fBottom, + dst.fLeft, dst.fTop, dst.fRight, dst.fBottom); + matrix.dump(); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_072.cpp b/docs/examples/Matrix_072.cpp new file mode 100644 index 0000000000..a878ce44db --- /dev/null +++ b/docs/examples/Matrix_072.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=c851d1313e8909aaea4f0591699fdb7b +REG_FIDDLE(Matrix_072, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + const SkPoint src[] = { { 0, 0}, {30, 0}, {30, -30}, { 0, -30} }; + const SkPoint dst[] = { {50, 0}, {80, -10}, {90, -30}, {60, -40} }; + SkPaint blackPaint; + blackPaint.setAntiAlias(true); + blackPaint.setTextSize(42); + SkPaint redPaint = blackPaint; + redPaint.setColor(SK_ColorRED); + for (int count : { 1, 2, 3, 4 } ) { + canvas->translate(35, 55); + for (int index = 0; index < count; ++index) { + canvas->drawCircle(src[index], 3, blackPaint); + canvas->drawCircle(dst[index], 3, blackPaint); + if (index > 0) { + canvas->drawLine(src[index], src[index - 1], blackPaint); + canvas->drawLine(dst[index], dst[index - 1], blackPaint); + } + } + SkMatrix matrix; + matrix.setPolyToPoly(src, dst, count); + canvas->drawString("A", src[0].fX, src[0].fY, redPaint); + SkAutoCanvasRestore acr(canvas, true); + canvas->concat(matrix); + canvas->drawString("A", src[0].fX, src[0].fY, redPaint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_073.cpp b/docs/examples/Matrix_073.cpp new file mode 100644 index 0000000000..881eae417d --- /dev/null +++ b/docs/examples/Matrix_073.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=0e03cd9f154603ed4b21ca56d69dae44 +REG_FIDDLE(Matrix_073, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + const SkPoint src[] = { { 10, 120}, {120, 120}, {120, 10}, { 10, 10} }; + const SkPoint dst[] = { {150, 120}, {200, 100}, {240, 30}, { 130, 40} }; + SkPaint paint; + paint.setAntiAlias(true); + SkMatrix matrix; + matrix.setPolyToPoly(src, dst, 4); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, src, paint); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, 4, dst, paint); + paint.setColor(SK_ColorBLUE); + paint.setStrokeWidth(3); + paint.setStrokeCap(SkPaint::kRound_Cap); + canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, dst, paint); + if (matrix.invert(&matrix)) { + canvas->concat(matrix); + canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, dst, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_074.cpp b/docs/examples/Matrix_074.cpp new file mode 100644 index 0000000000..2fd8d5b315 --- /dev/null +++ b/docs/examples/Matrix_074.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=e10adbd0bcc940c5d4d872db0e78e892 +REG_FIDDLE(Matrix_074, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkScalar affine[6]; + SkMatrix::SetAffineIdentity(affine); + const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" }; + for (int i = 0; i < 6; ++i) { + SkDebugf("%s: %g ", names[i], affine[i]); + } + SkDebugf("\n"); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_075.cpp b/docs/examples/Matrix_075.cpp new file mode 100644 index 0000000000..b8cff706ab --- /dev/null +++ b/docs/examples/Matrix_075.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=3325bdf82bd86d9fbc4199f248afa82c +REG_FIDDLE(Matrix_075, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setAll(2, 3, 4, 5, 6, 7, 0, 0, 1); + SkScalar affine[6]; + if (matrix.asAffine(affine)) { + const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" }; + for (int i = 0; i < 6; ++i) { + SkDebugf("%s: %g ", names[i], affine[i]); + } + SkDebugf("\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_076.cpp b/docs/examples/Matrix_076.cpp new file mode 100644 index 0000000000..9d4e2425d2 --- /dev/null +++ b/docs/examples/Matrix_076.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=f5b6d371c4d65e5b5ac6eebdd4b237d8 +REG_FIDDLE(Matrix_076, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setAll(2, 3, 4, 5, 6, 7, 0, 0, 1); + SkScalar affine[6]; + if (matrix.asAffine(affine)) { + const char* names[] = { "ScaleX", "SkewY", "SkewX", "ScaleY", "TransX", "TransY" }; + for (int i = 0; i < 6; ++i) { + SkDebugf("%s: %g ", names[i], affine[i]); + } + SkDebugf("\n"); + matrix.reset(); + matrix.setAffine(affine); + matrix.dump(); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_077.cpp b/docs/examples/Matrix_077.cpp new file mode 100644 index 0000000000..95319cc485 --- /dev/null +++ b/docs/examples/Matrix_077.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=f99dcb00296d0c56b6c0e178e94b3534 +REG_FIDDLE(Matrix_077, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.reset(); + const int count = 4; + SkPoint src[count]; + matrix.mapRectToQuad(src, {40, 70, 180, 220} ); + SkPaint paint; + paint.setARGB(77, 23, 99, 154); + for (int i = 0; i < 5; ++i) { + SkPoint dst[count]; + matrix.mapPoints(dst, src, count); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, count, dst, paint); + matrix.preRotate(35, 128, 128); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_078.cpp b/docs/examples/Matrix_078.cpp new file mode 100644 index 0000000000..4fec8992e2 --- /dev/null +++ b/docs/examples/Matrix_078.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=428ca171ae3bd0d3f992458ac598b97b +REG_FIDDLE(Matrix_078, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setRotate(35, 128, 128); + const int count = 4; + SkPoint pts[count]; + matrix.mapRectToQuad(pts, {40, 70, 180, 220} ); + SkPaint paint; + paint.setARGB(77, 23, 99, 154); + for (int i = 0; i < 5; ++i) { + canvas->drawPoints(SkCanvas::kPolygon_PointMode, count, pts, paint); + matrix.mapPoints(pts, count); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_079.cpp b/docs/examples/Matrix_079.cpp new file mode 100644 index 0000000000..2fdb66781c --- /dev/null +++ b/docs/examples/Matrix_079.cpp @@ -0,0 +1,31 @@ +// 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 "fiddle/examples.h" +// HASH=d56f93e4bc763c7ba4914321ed07a8b5 +REG_FIDDLE(Matrix_079, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPoint3 src[] = {{3, 3, 1}, {8, 2, 2}, {5, 0, 4}, {0, 1, 3}, + {3, 7, 1}, {8, 6, 2}, {5, 4, 4}, {0, 5, 3}}; + int lines[] = { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 }; + constexpr int count = SK_ARRAY_COUNT(src); + auto debugster = [=](SkPoint3 src[]) -> void { + for (size_t i = 0; i < SK_ARRAY_COUNT(lines); i += 2) { + const SkPoint3& s = src[lines[i]]; + const SkPoint3& e = src[lines[i + 1]]; + SkPaint paint; + paint.setARGB(77, 23, 99, 154); + canvas->drawLine(s.fX / s.fZ, s.fY / s.fZ, e.fX / e.fZ, e.fY / e.fZ, paint); + } + }; + canvas->save(); + canvas->translate(5, 5); + canvas->scale(15, 15); + debugster(src); + canvas->restore(); + canvas->translate(128, 128); + SkMatrix matrix; + matrix.setAll(15, 0, 0, 0, 15, 0, -0.08, 0.04, 1); + matrix.mapHomogeneousPoints(src, src, count); + debugster(src); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_080.cpp b/docs/examples/Matrix_080.cpp new file mode 100644 index 0000000000..f321aec782 --- /dev/null +++ b/docs/examples/Matrix_080.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=9e50185d502dc6903783679a84106089 +REG_FIDDLE(Matrix_080, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkMatrix matrix; + matrix.setRotate(60, 128, 128); + SkPoint lines[] = {{50, 50}, {150, 50}, {150, 150}}; + for (size_t i = 0; i < SK_ARRAY_COUNT(lines); ++i) { + SkPoint pt; + matrix.mapXY(lines[i].fX, lines[i].fY, &pt); + canvas->drawCircle(pt.fX, pt.fY, 3, paint); + } + canvas->concat(matrix); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(lines), lines, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_081.cpp b/docs/examples/Matrix_081.cpp new file mode 100644 index 0000000000..d8822d2405 --- /dev/null +++ b/docs/examples/Matrix_081.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=b1ead09c67a177ab8eace12b061610a7 +REG_FIDDLE(Matrix_081, 256, 256, false, 4) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {30, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + SkPaint paint; + paint.setAntiAlias(true); + paint.setStrokeWidth(3); + for (int x : { 0, source.width() } ) { + for (int y : { 0, source.height() } ) { + canvas->drawPoint(matrix.mapXY(x, y), paint); + } + } + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_082.cpp b/docs/examples/Matrix_082.cpp new file mode 100644 index 0000000000..831b809535 --- /dev/null +++ b/docs/examples/Matrix_082.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=918a9778c3d7d5cb306692784399f6dc +REG_FIDDLE(Matrix_082, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkMatrix matrix; + matrix.reset(); + const SkVector radii[] = {{8, 4}, {9, 1}, {6, 2}, {7, 3}}; + for (int i = 0; i < 4; ++i) { + SkVector rScaled[4]; + matrix.preScale(1.5f, 2.f); + matrix.mapVectors(rScaled, radii, SK_ARRAY_COUNT(radii)); + SkRRect rrect; + rrect.setRectRadii({20, 20, 180, 70}, rScaled); + canvas->drawRRect(rrect, paint); + canvas->translate(0, 60); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_083.cpp b/docs/examples/Matrix_083.cpp new file mode 100644 index 0000000000..76389a8e97 --- /dev/null +++ b/docs/examples/Matrix_083.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=5754501a00a1323e76353fb53153e939 +REG_FIDDLE(Matrix_083, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkMatrix matrix; + matrix.setScale(2, 3); + SkVector radii[] = {{7, 7}, {3, 3}, {2, 2}, {4, 0}}; + for (int i = 0; i < 4; ++i) { + SkRRect rrect; + rrect.setRectRadii({20, 20, 180, 70}, radii); + canvas->drawRRect(rrect, paint); + canvas->translate(0, 60); + matrix.mapVectors(radii, SK_ARRAY_COUNT(radii)); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_084.cpp b/docs/examples/Matrix_084.cpp new file mode 100644 index 0000000000..783acfb0b4 --- /dev/null +++ b/docs/examples/Matrix_084.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=aed143fc6cd0bce4ed029b98d1e61f2d +REG_FIDDLE(Matrix_084, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorGREEN); + paint.setAntiAlias(true); + paint.setTextSize(48); + SkMatrix matrix; + matrix.setRotate(90); + SkVector offset = { 7, 7 }; + for (int i = 0; i < 4; ++i) { + paint.setImageFilter(SkDropShadowImageFilter::Make(offset.fX, offset.fY, 3, 3, + SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr)); + matrix.mapVector(offset.fX, offset.fY, &offset); + canvas->translate(0, 60); + canvas->drawString("Text", 50, 0, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_085.cpp b/docs/examples/Matrix_085.cpp new file mode 100644 index 0000000000..b44694977c --- /dev/null +++ b/docs/examples/Matrix_085.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=8bf1518db3f369696cd3065b541a8bd7 +REG_FIDDLE(Matrix_085, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorGREEN); + paint.setAntiAlias(true); + paint.setTextSize(48); + SkMatrix matrix; + matrix.setRotate(90); + SkVector offset = { 7, 7 }; + for (int i = 0; i < 4; ++i) { + paint.setImageFilter(SkDropShadowImageFilter::Make(offset.fX, offset.fY, 3, 3, + SK_ColorBLUE, SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr)); + offset = matrix.mapVector(offset.fX, offset.fY); + canvas->translate(0, 60); + canvas->drawString("Text", 50, 0, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_086.cpp b/docs/examples/Matrix_086.cpp new file mode 100644 index 0000000000..2f8c37964c --- /dev/null +++ b/docs/examples/Matrix_086.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=dbcf928b035a31ca69c99392e2e2cca9 +REG_FIDDLE(Matrix_086, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkMatrix matrix; + matrix.setRotate(45, 128, 128); + SkRect rotatedBounds, bounds = {40, 50, 190, 200}; + matrix.mapRect(&rotatedBounds, bounds ); + paint.setColor(SK_ColorGRAY); + canvas->drawRect(rotatedBounds, paint); + canvas->concat(matrix); + paint.setColor(SK_ColorRED); + canvas->drawRect(bounds, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_087.cpp b/docs/examples/Matrix_087.cpp new file mode 100644 index 0000000000..1ca0069098 --- /dev/null +++ b/docs/examples/Matrix_087.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=5fafd0bd23d1ed37425b970b4a3c6cc9 +REG_FIDDLE(Matrix_087, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkMatrix matrix; + matrix.setRotate(45, 128, 128); + SkRect bounds = {40, 50, 190, 200}; + matrix.mapRect(&bounds); + paint.setColor(SK_ColorGRAY); + canvas->drawRect(bounds, paint); + canvas->concat(matrix); + paint.setColor(SK_ColorRED); + canvas->drawRect({40, 50, 190, 200}, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_088.cpp b/docs/examples/Matrix_088.cpp new file mode 100644 index 0000000000..d05d0c5b61 --- /dev/null +++ b/docs/examples/Matrix_088.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=3b7b1f884437ab450f986234e4aec27f +REG_FIDDLE(Matrix_088, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRect rect{110, 50, 180, 100}; + SkMatrix matrix; + matrix.setRotate(50, 28, 28); + SkRect mapped = matrix.mapRect(rect); + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRect(rect, paint); + canvas->drawRect(mapped, paint); + canvas->concat(matrix); + canvas->drawRect(rect, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_089.cpp b/docs/examples/Matrix_089.cpp new file mode 100644 index 0000000000..465b8de1a2 --- /dev/null +++ b/docs/examples/Matrix_089.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=c69cd2a590b5733c3cbc92cb9ceed3f5 +REG_FIDDLE(Matrix_089, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkMatrix matrix; + matrix.setRotate(60, 128, 128); + SkRect rect = {50, 50, 150, 150}; + SkPoint pts[4]; + matrix.mapRectToQuad(pts, rect); + for (int i = 0; i < 4; ++i) { + canvas->drawCircle(pts[i].fX, pts[i].fY, 3, paint); + } + canvas->concat(matrix); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRect(rect, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_090.cpp b/docs/examples/Matrix_090.cpp new file mode 100644 index 0000000000..5d78aa2557 --- /dev/null +++ b/docs/examples/Matrix_090.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=62bc26989c2b4c2a54d516596a71dd97 +REG_FIDDLE(Matrix_090, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkMatrix matrix; + SkRect rect = {100, 50, 150, 180}; + matrix.setScale(2, .5f, rect.centerX(), rect.centerY()); + SkRect rotated; + matrix.mapRectScaleTranslate(&rotated, rect); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRect(rect, paint); + paint.setColor(SK_ColorRED); + canvas->drawRect(rotated, paint); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_091.cpp b/docs/examples/Matrix_091.cpp new file mode 100644 index 0000000000..7ba64950af --- /dev/null +++ b/docs/examples/Matrix_091.cpp @@ -0,0 +1,41 @@ +#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 "fiddle/examples.h" +// HASH=6d6f2082fcf59d9f02bfb1758b87db69 +REG_FIDDLE(Matrix_091, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkMatrix matrix; + const SkPoint center = {108, 93}; + matrix.setScale(2, .5f, center.fX, center.fY); + matrix.postRotate(45, center.fX, center.fY); + const SkScalar circleRadius = 50; + SkScalar mappedRadius = matrix.mapRadius(circleRadius); + SkVector minorAxis, majorAxis; + matrix.mapVector(0, circleRadius, &minorAxis); + matrix.mapVector(circleRadius, 0, &majorAxis); + SkString mappedArea; + mappedArea.printf("area = %g", mappedRadius * mappedRadius); + canvas->drawString(mappedArea, 145, 250, paint); + canvas->drawString("mappedRadius", center.fX + mappedRadius + 3, center.fY, paint); + paint.setColor(SK_ColorRED); + SkString axArea; + axArea.printf("area = %g", majorAxis.length() * minorAxis.length()); + paint.setStyle(SkPaint::kFill_Style); + canvas->drawString(axArea, 15, 250, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRect({10, 200, 10 + majorAxis.length(), 200 + minorAxis.length()}, paint); + paint.setColor(SK_ColorBLACK); + canvas->drawLine(center.fX, center.fY, center.fX + mappedRadius, center.fY, paint); + canvas->drawLine(center.fX, center.fY, center.fX, center.fY + mappedRadius, paint); + canvas->drawRect({140, 180, 140 + mappedRadius, 180 + mappedRadius}, paint); + canvas->concat(matrix); + canvas->drawCircle(center.fX, center.fY, circleRadius, paint); + paint.setColor(SK_ColorRED); + canvas->drawLine(center.fX, center.fY, center.fX + circleRadius, center.fY, paint); + canvas->drawLine(center.fX, center.fY, center.fX, center.fY + circleRadius, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Matrix_092.cpp b/docs/examples/Matrix_092.cpp new file mode 100644 index 0000000000..65369ef301 --- /dev/null +++ b/docs/examples/Matrix_092.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=ab57b232acef69f26de9cb23d23c8a1a +REG_FIDDLE(Matrix_092, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + for (SkScalar px : { 0.0f, 0.1f } ) { + for (SkScalar py : { 0.0f, 0.1f } ) { + for (SkScalar sy : { 1, 2 } ) { + matrix.setAll(1, 0, 0, 0, sy, 0, px, py, 1); + matrix.dump(); + SkDebugf("isFixedStepInX: %s\n", matrix.isFixedStepInX() ? "true" : "false"); + } + } + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_093.cpp b/docs/examples/Matrix_093.cpp new file mode 100644 index 0000000000..84914fb934 --- /dev/null +++ b/docs/examples/Matrix_093.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=fad6b92b21b1e1deeae61978cec2d232 +REG_FIDDLE(Matrix_093, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + const SkPoint center = { 128, 128 }; + matrix.setScale(20, 25, center.fX, center.fY); + matrix.postRotate(75, center.fX, center.fY); + { + SkAutoCanvasRestore acr(canvas, true); + canvas->concat(matrix); + canvas->drawBitmap(source, 0, 0); + } + if (matrix.isFixedStepInX()) { + SkPaint paint; + paint.setAntiAlias(true); + SkVector step = matrix.fixedStepInX(128); + SkVector end = center + step; + canvas->drawLine(center, end, paint); + SkVector arrow = { step.fX + step.fY, step.fY - step.fX}; + arrow = arrow * .25f; + canvas->drawLine(end, end - arrow, paint); + canvas->drawLine(end, {end.fX + arrow.fY, end.fY - arrow.fX}, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_094.cpp b/docs/examples/Matrix_094.cpp new file mode 100644 index 0000000000..71030f2d77 --- /dev/null +++ b/docs/examples/Matrix_094.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=39016b3cfc6bbabb09348a53822ce508 +REG_FIDDLE(Matrix_094, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkMatrix& a, const SkMatrix& b) -> void { + SkDebugf("%s: a %c= b a.cheapEqualTo(b): %s\n", prefix, + a == b ? '=' : '!', a.cheapEqualTo(b) ? "true" : "false"); + }; + SkMatrix a, b; + a.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); + b.setIdentity(); + debugster("identity", a, b); + a.setAll(1, -0.0f, 0, 0, 1, 0, 0, 0, 1); + debugster("neg zero", a, b); + a.setAll(1, SK_ScalarNaN, 0, 0, 1, 0, 0, 0, 1); + debugster(" one NaN", a, b); + b.setAll(1, SK_ScalarNaN, 0, 0, 1, 0, 0, 0, 1); + debugster("both NaN", a, b); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_095.cpp b/docs/examples/Matrix_095.cpp new file mode 100644 index 0000000000..c9b8f790b0 --- /dev/null +++ b/docs/examples/Matrix_095.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=3902859150b0f0c4aeb1f25d00434baa +REG_FIDDLE(Matrix_095, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkMatrix& a, const SkMatrix& b) -> void { + SkDebugf("%s: a %c= b a.cheapEqualTo(b): %s\n", prefix, + a == b ? '=' : '!', a.cheapEqualTo(b) ? "true" : "false"); + }; + SkMatrix a, b; + a.setAll(1, 0, 0, 0, 1, 0, 0, 0, 1); + b.setScale(2, 4); + b.postScale(0.5f, 0.25f); + debugster("identity", a, b); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_096.cpp b/docs/examples/Matrix_096.cpp new file mode 100644 index 0000000000..94eaf40a86 --- /dev/null +++ b/docs/examples/Matrix_096.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=088ab41f877599f980a99523749b0afd +REG_FIDDLE(Matrix_096, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkMatrix& a, const SkMatrix& b) -> void { + SkDebugf("%s: a %c= b a.cheapEqualTo(b): %s\n", prefix, + a != b ? '!' : '=', a.cheapEqualTo(b) ? "true" : "false"); + }; + SkMatrix a, b; + a.setAll(1, 0, 0, 0, 1, 0, 1, 0, 1); + if (a.invert(&b)) { + debugster("identity", a, b); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_097.cpp b/docs/examples/Matrix_097.cpp new file mode 100644 index 0000000000..475633692a --- /dev/null +++ b/docs/examples/Matrix_097.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=8d72a4818e5a9188348f6c08ab5d8a40 +REG_FIDDLE(Matrix_097, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setRotate(45); + matrix.dump(); + SkMatrix nearlyEqual; + nearlyEqual.setAll(0.7071f, -0.7071f, 0, 0.7071f, 0.7071f, 0, 0, 0, 1); + nearlyEqual.dump(); + SkDebugf("matrix %c= nearlyEqual\n", matrix == nearlyEqual ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_098.cpp b/docs/examples/Matrix_098.cpp new file mode 100644 index 0000000000..6459cf3369 --- /dev/null +++ b/docs/examples/Matrix_098.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=1d6f67904c88a806c3731879e9af4ae5 +REG_FIDDLE(Matrix_098, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setScale(42, 24); + SkDebugf("matrix.getMinScale() %g\n", matrix.getMinScale()); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_099.cpp b/docs/examples/Matrix_099.cpp new file mode 100644 index 0000000000..e9c6061158 --- /dev/null +++ b/docs/examples/Matrix_099.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=3fee4364929899649cf9efc37897e964 +REG_FIDDLE(Matrix_099, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setScale(42, 24); + SkDebugf("matrix.getMaxScale() %g\n", matrix.getMaxScale()); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_100.cpp b/docs/examples/Matrix_100.cpp new file mode 100644 index 0000000000..a9190a3bfe --- /dev/null +++ b/docs/examples/Matrix_100.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=13adba0ecf5f82247cf051b4fa4d8a9c +REG_FIDDLE(Matrix_100, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setAll(1, 0, 0, 0, 1, 0, 0, 0, 0); + if (matrix.invert(&matrix)) { + SkScalar factor[2] = {2, 2}; + bool result = matrix.getMinMaxScales(factor); + SkDebugf("matrix.getMinMaxScales() %s %g %g\n", + result ? "true" : "false", factor[0], factor[1]); + } +} +} // END FIDDLE diff --git a/docs/examples/Matrix_101.cpp b/docs/examples/Matrix_101.cpp new file mode 100644 index 0000000000..de87d8fe1d --- /dev/null +++ b/docs/examples/Matrix_101.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=139b874da0a3ede1f3df88119085c0aa +REG_FIDDLE(Matrix_101, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setRotate(90 * SK_Scalar1); + matrix.postScale(1.f / 4, 1.f / 2); + matrix.dump(); + SkSize scale = {SK_ScalarNaN, SK_ScalarNaN}; + SkMatrix remaining; + remaining.reset(); + bool success = matrix.decomposeScale(&scale, &remaining); + SkDebugf("success: %s ", success ? "true" : "false"); + SkDebugf("scale: %g, %g\n", scale.width(), scale.height()); + remaining.dump(); + SkMatrix scaleMatrix = SkMatrix::MakeScale(scale.width(), scale.height()); + SkMatrix combined = SkMatrix::Concat(scaleMatrix, remaining); + combined.dump(); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_102.cpp b/docs/examples/Matrix_102.cpp new file mode 100644 index 0000000000..d888fc3ced --- /dev/null +++ b/docs/examples/Matrix_102.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=d961d91020f19037204a8c3fd8cb1060 +REG_FIDDLE(Matrix_102, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix m1, m2, m3; + m1.reset(); + m2.setIdentity(); + m3 = SkMatrix::I(); + SkDebugf("m1 %c= m2\n", m1 == m2 ? '=' : '!'); + SkDebugf("m2 %c= m3\n", m1 == m2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_103.cpp b/docs/examples/Matrix_103.cpp new file mode 100644 index 0000000000..32705a3dc9 --- /dev/null +++ b/docs/examples/Matrix_103.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=af0b72360c1c7a25b4754bfa47011dd5 +REG_FIDDLE(Matrix_103, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("scaleX %g\n", SkMatrix::InvalidMatrix().getScaleX()); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_104.cpp b/docs/examples/Matrix_104.cpp new file mode 100644 index 0000000000..25dfda1980 --- /dev/null +++ b/docs/examples/Matrix_104.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=6b4562c7052da94f3d5b2412dca41946 +REG_FIDDLE(Matrix_104, 256, 64, false, 4) { +void draw(SkCanvas* canvas) { + SkMatrix matrix, matrix2; + SkPoint bitmapBounds[4], perspect[4] = {{50, 10}, {180, 40}, {236, 176}, {10, 206}}; + SkRect::Make(source.bounds()).toQuad(bitmapBounds); + matrix.setPolyToPoly(bitmapBounds, perspect, 4); + matrix2.setPolyToPoly(perspect, bitmapBounds, 4); + SkMatrix concat = SkMatrix::Concat(matrix, matrix2); + canvas->concat(concat); + canvas->drawBitmap(source, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_105.cpp b/docs/examples/Matrix_105.cpp new file mode 100644 index 0000000000..bb6cc1a54c --- /dev/null +++ b/docs/examples/Matrix_105.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=f4365ef332f51f7fd25040e0771ba9a2 +REG_FIDDLE(Matrix_105, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setIdentity(); + SkDebugf("with identity matrix: x = %g\n", matrix.mapXY(24, 42).fX); + SkScalar& skewRef = matrix[SkMatrix::kMSkewX]; + skewRef = 0; + SkDebugf("after skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); + skewRef = 1; + SkDebugf("after 2nd skew x mod: x = %g\n", matrix.mapXY(24, 42).fX); + matrix.dirtyMatrixTypeCache(); + SkDebugf("after dirty cache: x = %g\n", matrix.mapXY(24, 42).fX); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_106.cpp b/docs/examples/Matrix_106.cpp new file mode 100644 index 0000000000..927ea28d62 --- /dev/null +++ b/docs/examples/Matrix_106.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=fed43797f13796529cb6731385d6f8f3 +REG_FIDDLE(Matrix_106, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix; + matrix.setScaleTranslate(1, 2, 3, 4); + matrix.dump(); +} +} // END FIDDLE diff --git a/docs/examples/Matrix_107.cpp b/docs/examples/Matrix_107.cpp new file mode 100644 index 0000000000..a9dbb93698 --- /dev/null +++ b/docs/examples/Matrix_107.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=bc6c6f6a5df770287120d87f81b922eb +REG_FIDDLE(Matrix_107, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkMatrix matrix = SkMatrix::MakeTrans(SK_ScalarNaN, 0); + matrix.dump(); + SkDebugf("matrix is finite: %s\n", matrix.isFinite() ? "true" : "false"); + SkDebugf("matrix %c= matrix\n", matrix == matrix ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_000.cpp b/docs/examples/Paint_000.cpp new file mode 100644 index 0000000000..721ccd38a8 --- /dev/null +++ b/docs/examples/Paint_000.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=c4b2186d85c142a481298f7144295ffd +REG_FIDDLE(Paint_000, 256, 1, false, 0) { +void draw(SkCanvas* canvas) { + #ifndef SkUserConfig_DEFINED + #define SkUserConfig_DEFINED + #define SkPaintDefaults_Flags 0x01 // always enable antialiasing + #define SkPaintDefaults_TextSize 24.f // double default font size + #define SkPaintDefaults_Hinting 3 // use full hinting + #define SkPaintDefaults_MiterLimit 10.f // use HTML Canvas miter limit setting + #endif +} +} // END FIDDLE diff --git a/docs/examples/Paint_001.cpp b/docs/examples/Paint_001.cpp new file mode 100644 index 0000000000..164d7a2d23 --- /dev/null +++ b/docs/examples/Paint_001.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=b99971ad0ef243d617925289d963b62d +REG_FIDDLE(Paint_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1; + paint1.setColor(SK_ColorRED); + SkPaint paint2(paint1); + paint2.setColor(SK_ColorBLUE); + SkDebugf("SK_ColorRED %c= paint1.getColor()\n", SK_ColorRED == paint1.getColor() ? '=' : '!'); + SkDebugf("SK_ColorBLUE %c= paint2.getColor()\n", SK_ColorBLUE == paint2.getColor() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_002.cpp b/docs/examples/Paint_002.cpp new file mode 100644 index 0000000000..041f0ede4a --- /dev/null +++ b/docs/examples/Paint_002.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=8ed1488a503cd5282b86a51614aa90b1 +REG_FIDDLE(Paint_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + float intervals[] = { 5, 5 }; + paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 2.5f)); + SkPaint dashed(std::move(paint)); + SkDebugf("path effect unique: %s\n", dashed.getPathEffect()->unique() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Paint_003.cpp b/docs/examples/Paint_003.cpp new file mode 100644 index 0000000000..0ee293b6f6 --- /dev/null +++ b/docs/examples/Paint_003.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=ef269937ade7e7353635121d9a64f9f7 +REG_FIDDLE(Paint_003, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setColor(SK_ColorRED); + paint1.reset(); + SkDebugf("paint1 %c= paint2", paint1 == paint2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_004.cpp b/docs/examples/Paint_004.cpp new file mode 100644 index 0000000000..883e59dd8b --- /dev/null +++ b/docs/examples/Paint_004.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=b476a9088f80dece176ed577807d3992 +REG_FIDDLE(Paint_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setColor(SK_ColorRED); + paint2 = paint1; + SkDebugf("SK_ColorRED %c= paint1.getColor()\n", SK_ColorRED == paint1.getColor() ? '=' : '!'); + SkDebugf("SK_ColorRED %c= paint2.getColor()\n", SK_ColorRED == paint2.getColor() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_005.cpp b/docs/examples/Paint_005.cpp new file mode 100644 index 0000000000..9c2cf6996e --- /dev/null +++ b/docs/examples/Paint_005.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=9fb7459b097d713f5f1fe5675afe14f5 +REG_FIDDLE(Paint_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setColor(SK_ColorRED); + paint2 = std::move(paint1); + SkDebugf("SK_ColorRED == paint2.getColor()\n", SK_ColorRED == paint2.getColor() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_006.cpp b/docs/examples/Paint_006.cpp new file mode 100644 index 0000000000..f6f7d9e314 --- /dev/null +++ b/docs/examples/Paint_006.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=7481a948e34672720337a631830586dd +REG_FIDDLE(Paint_006, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setColor(SK_ColorRED); + paint2.setColor(0xFFFF0000); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); + float intervals[] = { 5, 5 }; + paint1.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); + paint2.setPathEffect(SkDashPathEffect::Make(intervals, 2, 2.5f)); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_007.cpp b/docs/examples/Paint_007.cpp new file mode 100644 index 0000000000..077ab6ba2b --- /dev/null +++ b/docs/examples/Paint_007.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=b6c8484b1187f555b435ad5369833be4 +REG_FIDDLE(Paint_007, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setColor(SK_ColorRED); + paint2.setColor(0xFFFF0000); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); + SkDebugf("paint1 %c= paint2\n", paint1 != paint2 ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/Paint_008.cpp b/docs/examples/Paint_008.cpp new file mode 100644 index 0000000000..34e57f60f2 --- /dev/null +++ b/docs/examples/Paint_008.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=7f7e1b701361912b344f90ae6b530393 +REG_FIDDLE(Paint_008, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setColor(SK_ColorRED); + paint2.setColor(0xFFFF0000); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); + SkDebugf("paint1.getHash() %c= paint2.getHash()\n", + paint1.getHash() == paint2.getHash() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_009.cpp b/docs/examples/Paint_009.cpp new file mode 100644 index 0000000000..18d75d5f63 --- /dev/null +++ b/docs/examples/Paint_009.cpp @@ -0,0 +1,13 @@ +#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 "fiddle/examples.h" +// HASH=bb179ec5698ec1398ff18f3657ab73f7 +REG_FIDDLE(Paint_009, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint2.setHinting(SkFontHinting::kNormal); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : ':'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_010.cpp b/docs/examples/Paint_010.cpp new file mode 100644 index 0000000000..84e20b8e7a --- /dev/null +++ b/docs/examples/Paint_010.cpp @@ -0,0 +1,13 @@ +#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 "fiddle/examples.h" +// HASH=b56b70c7ea2453c41bfa58b626953bed +REG_FIDDLE(Paint_010, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("SkFontHinting::kNormal %c= paint.getHinting()\n", + SkFontHinting::kNormal == paint.getHinting() ? '=' : ':'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_011.cpp b/docs/examples/Paint_011.cpp new file mode 100644 index 0000000000..74b709229e --- /dev/null +++ b/docs/examples/Paint_011.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=8a3f8c309533388b01aa66e1267f322d +REG_FIDDLE(Paint_011, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkDebugf("(SkPaint::kAntiAlias_Flag & paint.getFlags()) %c= 0\n", + SkPaint::kAntiAlias_Flag & paint.getFlags() ? '!' : '='); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_012.cpp b/docs/examples/Paint_012.cpp new file mode 100644 index 0000000000..e07904d59c --- /dev/null +++ b/docs/examples/Paint_012.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=54baed3f6bc4b9c31ba664e27767fdc7 +REG_FIDDLE(Paint_012, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setFlags((uint32_t) (SkPaint::kAntiAlias_Flag | SkPaint::kDither_Flag)); + SkDebugf("paint.isAntiAlias()\n", paint.isAntiAlias() ? '!' : '='); + SkDebugf("paint.isDither()\n", paint.isDither() ? '!' : '='); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_013.cpp b/docs/examples/Paint_013.cpp new file mode 100644 index 0000000000..81df60eced --- /dev/null +++ b/docs/examples/Paint_013.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=a6575a49467ce8d28bb01cc7638fa04d +REG_FIDDLE(Paint_013, 512, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocN32Pixels(50, 50); + SkCanvas offscreen(bitmap); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(10); + for (bool antialias : { false, true }) { + paint.setColor(antialias ? SK_ColorRED : SK_ColorBLUE); + paint.setAntiAlias(antialias); + bitmap.eraseColor(0); + offscreen.drawLine(5, 5, 15, 30, paint); + canvas->drawLine(5, 5, 15, 30, paint); + canvas->save(); + canvas->scale(10, 10); + canvas->drawBitmap(bitmap, antialias ? 12 : 0, 0); + canvas->restore(); + canvas->translate(15, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_014.cpp b/docs/examples/Paint_014.cpp new file mode 100644 index 0000000000..eb9a1346d8 --- /dev/null +++ b/docs/examples/Paint_014.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=d7d5f4f7da7acd5104a652f490c6f7b8 +REG_FIDDLE(Paint_014, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("paint.isAntiAlias() %c= !!(paint.getFlags() & SkPaint::kAntiAlias_Flag)\n", + paint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag) ? '=' : '!'); + paint.setAntiAlias(true); + SkDebugf("paint.isAntiAlias() %c= !!(paint.getFlags() & SkPaint::kAntiAlias_Flag)\n", + paint.isAntiAlias() == !!(paint.getFlags() & SkPaint::kAntiAlias_Flag) ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_015.cpp b/docs/examples/Paint_015.cpp new file mode 100644 index 0000000000..760fd53aeb --- /dev/null +++ b/docs/examples/Paint_015.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=c2ff148374d01cbef845b223e725905c +REG_FIDDLE(Paint_015, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setAntiAlias(true); + paint2.setFlags(paint2.getFlags() | SkPaint::kAntiAlias_Flag); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_016.cpp b/docs/examples/Paint_016.cpp new file mode 100644 index 0000000000..892f7f6863 --- /dev/null +++ b/docs/examples/Paint_016.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=8b26507690b71462f44642b911890bbf +REG_FIDDLE(Paint_016, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bm16; + bm16.allocPixels(SkImageInfo::Make(32, 32, kRGB_565_SkColorType, kOpaque_SkAlphaType)); + SkCanvas c16(bm16); + SkPaint colorPaint; + for (auto dither : { false, true } ) { + colorPaint.setDither(dither); + for (auto colors : { 0xFF333333, 0xFF666666, 0xFF999999, 0xFFCCCCCC } ) { + for (auto mask : { 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFFFFFFFF } ) { + colorPaint.setColor(colors & mask); + c16.drawRect({0, 0, 8, 4}, colorPaint); + c16.translate(8, 0); + } + c16.translate(-32, 4); + } + } + canvas->scale(8, 8); + canvas->drawBitmap(bm16, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Paint_017.cpp b/docs/examples/Paint_017.cpp new file mode 100644 index 0000000000..0fe47e1da3 --- /dev/null +++ b/docs/examples/Paint_017.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=76d4d4a7931a48495e4d5f54e073be53 +REG_FIDDLE(Paint_017, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + canvas->clear(0); + SkBitmap bm32; + bm32.allocPixels(SkImageInfo::Make(20, 10, kN32_SkColorType, kPremul_SkAlphaType)); + SkCanvas c32(bm32); + SkPoint points[] = {{0, 0}, {20, 0}}; + SkColor colors[] = {0xFF334455, 0xFF662211 }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear( + points, colors, nullptr, SK_ARRAY_COUNT(colors), + SkShader::kClamp_TileMode, 0, nullptr)); + paint.setDither(true); + c32.drawPaint(paint); + canvas->scale(12, 12); + canvas->drawBitmap(bm32, 0, 0); + paint.setBlendMode(SkBlendMode::kPlus); + canvas->drawBitmap(bm32, 0, 11, &paint); + canvas->drawBitmap(bm32, 0, 11, &paint); + canvas->drawBitmap(bm32, 0, 11, &paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_018.cpp b/docs/examples/Paint_018.cpp new file mode 100644 index 0000000000..fc94d59b93 --- /dev/null +++ b/docs/examples/Paint_018.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=f4ce93f6c5e7335436a985377fd980c0 +REG_FIDDLE(Paint_018, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("paint.isDither() %c= !!(paint.getFlags() & SkPaint::kDither_Flag)\n", + paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag) ? '=' : '!'); + paint.setDither(true); + SkDebugf("paint.isDither() %c= !!(paint.getFlags() & SkPaint::kDither_Flag)\n", + paint.isDither() == !!(paint.getFlags() & SkPaint::kDither_Flag) ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_019.cpp b/docs/examples/Paint_019.cpp new file mode 100644 index 0000000000..8371e78e13 --- /dev/null +++ b/docs/examples/Paint_019.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=69b7162e8324d9239dd02dd9ada2bdff +REG_FIDDLE(Paint_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setDither(true); + paint2.setFlags(paint2.getFlags() | SkPaint::kDither_Flag); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_020.cpp b/docs/examples/Paint_020.cpp new file mode 100644 index 0000000000..8517d11d33 --- /dev/null +++ b/docs/examples/Paint_020.cpp @@ -0,0 +1,28 @@ +#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 "fiddle/examples.h" +// HASH=4606ae1be792d6bc46d496432f050ee9 +REG_FIDDLE(Paint_020, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocN32Pixels(24, 33); + SkCanvas offscreen(bitmap); + offscreen.clear(SK_ColorWHITE); + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(20); + for (bool lcd : { false, true }) { + paint.setLCDRenderText(lcd); + for (bool subpixel : { false, true }) { + paint.setSubpixelText(subpixel); + offscreen.drawString(",,,,", 0, 4, paint); + offscreen.translate(0, 7); + } + } + canvas->drawBitmap(bitmap, 4, 12); + canvas->scale(9, 9); + canvas->drawBitmap(bitmap, 4, -1); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_021.cpp b/docs/examples/Paint_021.cpp new file mode 100644 index 0000000000..f5a31cd0da --- /dev/null +++ b/docs/examples/Paint_021.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=2890ad644f980637837e6fcb386fb462 +REG_FIDDLE(Paint_021, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const char testStr[] = "xxxx xxxx"; + for (auto linearText : { false, true } ) { + paint.setLinearText(linearText); + paint.setTextSize(24); + canvas->drawString(paint.isLinearText() ? "linear" : "hinted", 128, 30, paint); + for (SkScalar textSize = 8; textSize < 30; textSize *= 1.22f) { + paint.setTextSize(textSize); + canvas->translate(0, textSize); + canvas->drawString(testStr, 10, 0, paint); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_022.cpp b/docs/examples/Paint_022.cpp new file mode 100644 index 0000000000..a027542106 --- /dev/null +++ b/docs/examples/Paint_022.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=c93bb912f3bddfb4d96d3ad70ada552b +REG_FIDDLE(Paint_022, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const char testStr[] = "abcd efgh"; + for (int textSize : { 12, 24 } ) { + paint.setTextSize(textSize); + for (auto linearText : { false, true } ) { + paint.setLinearText(linearText); + SkString width; + width.appendScalar(paint.measureText(testStr, SK_ARRAY_COUNT(testStr), nullptr)); + canvas->translate(0, textSize + 4); + canvas->drawString(testStr, 10, 0, paint); + canvas->drawString(width, 128, 0, paint); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_023.cpp b/docs/examples/Paint_023.cpp new file mode 100644 index 0000000000..d7763e5894 --- /dev/null +++ b/docs/examples/Paint_023.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=abe9afc0932e2199324ae6cbb396e67c +REG_FIDDLE(Paint_023, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("paint.isSubpixelText() %c= !!(paint.getFlags() & SkPaint::kSubpixelText_Flag)\n", + paint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag) ? '=' : '!'); + paint.setSubpixelText(true); + SkDebugf("paint.isSubpixelText() %c= !!(paint.getFlags() & SkPaint::kSubpixelText_Flag)\n", + paint.isSubpixelText() == !!(paint.getFlags() & SkPaint::kSubpixelText_Flag) ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_024.cpp b/docs/examples/Paint_024.cpp new file mode 100644 index 0000000000..38c6c78fb0 --- /dev/null +++ b/docs/examples/Paint_024.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=a77bbc1a4e3be9a8ab0f842f877c5ee4 +REG_FIDDLE(Paint_024, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setSubpixelText(true); + paint2.setFlags(paint2.getFlags() | SkPaint::kSubpixelText_Flag); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_025.cpp b/docs/examples/Paint_025.cpp new file mode 100644 index 0000000000..7965028fde --- /dev/null +++ b/docs/examples/Paint_025.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=68e1fd95dd2fd06a333899d2bd2396b9 +REG_FIDDLE(Paint_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("paint.isLCDRenderText() %c= !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)\n", + paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag) ? '=' : '!'); + paint.setLCDRenderText(true); + SkDebugf("paint.isLCDRenderText() %c= !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag)\n", + paint.isLCDRenderText() == !!(paint.getFlags() & SkPaint::kLCDRenderText_Flag) ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_026.cpp b/docs/examples/Paint_026.cpp new file mode 100644 index 0000000000..cfc1c4f27c --- /dev/null +++ b/docs/examples/Paint_026.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=50dedf8450159571a3edaf4f0050defe +REG_FIDDLE(Paint_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setLCDRenderText(true); + paint2.setFlags(paint2.getFlags() | SkPaint::kLCDRenderText_Flag); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_027.cpp b/docs/examples/Paint_027.cpp new file mode 100644 index 0000000000..ec902f5b86 --- /dev/null +++ b/docs/examples/Paint_027.cpp @@ -0,0 +1,20 @@ +#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 "fiddle/examples.h" +// HASH=eba10b27b790e87183ae451b3fc5c4b1 +REG_FIDDLE(Paint_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("paint.isEmbeddedBitmapText() %c=" + " !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)\n", + paint.isEmbeddedBitmapText() == + !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag) ? '=' : '!'); + paint.setEmbeddedBitmapText(true); + SkDebugf("paint.isEmbeddedBitmapText() %c=" + " !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag)\n", + paint.isEmbeddedBitmapText() == + !!(paint.getFlags() & SkPaint::kEmbeddedBitmapText_Flag) ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_028.cpp b/docs/examples/Paint_028.cpp new file mode 100644 index 0000000000..eaf8925f86 --- /dev/null +++ b/docs/examples/Paint_028.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=246dffdd93a484ba4ad7ecf71198a5d4 +REG_FIDDLE(Paint_028, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setEmbeddedBitmapText(true); + paint2.setFlags(paint2.getFlags() | SkPaint::kEmbeddedBitmapText_Flag); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_029.cpp b/docs/examples/Paint_029.cpp new file mode 100644 index 0000000000..55fcde7275 --- /dev/null +++ b/docs/examples/Paint_029.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=aa4781afbe3b90e7ef56a287e5b9ce1e +REG_FIDDLE(Paint_029, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + for (auto forceAutoHinting : { false, true} ) { + paint.setAutohinted(forceAutoHinting); + SkDebugf("paint.isAutohinted() %c=" + " !!(paint.getFlags() & SkPaint::kAutoHinting_Flag)\n", + paint.isAutohinted() == + !!(paint.getFlags() & SkPaint::kAutoHinting_Flag) ? '=' : '!'); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_030.cpp b/docs/examples/Paint_030.cpp new file mode 100644 index 0000000000..4cbfaf2ab8 --- /dev/null +++ b/docs/examples/Paint_030.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=4e185306d7de9390fe8445eed0139309 +REG_FIDDLE(Paint_030, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const char testStr[] = "xxxx xxxx"; + for (auto forceAutoHinting : { false, true} ) { + paint.setAutohinted(forceAutoHinting); + paint.setTextSize(24); + canvas->drawString(paint.isAutohinted() ? "auto-hinted" : "default", 108, 30, paint); + for (SkScalar textSize = 8; textSize < 30; textSize *= 1.22f) { + paint.setTextSize(textSize); + canvas->translate(0, textSize); + canvas->drawString(testStr, 10, 0, paint); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_031.cpp b/docs/examples/Paint_031.cpp new file mode 100644 index 0000000000..5bc3168cb8 --- /dev/null +++ b/docs/examples/Paint_031.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=e811f4829a2daaaeaad3795504a7e02a +REG_FIDDLE(Paint_031, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(40); + canvas->drawString("OjYy_-", 10, 35, paint); + paint.setFakeBoldText(true); + canvas->drawString("OjYy_-", 10, 75, paint); + // create a custom fake bold by varying the stroke width + paint.setFakeBoldText(false); + paint.setStyle(SkPaint::kStrokeAndFill_Style); + paint.setStrokeWidth(40.f / 48); + canvas->drawString("OjYy_-", 10, 115, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_032.cpp b/docs/examples/Paint_032.cpp new file mode 100644 index 0000000000..29bff630cf --- /dev/null +++ b/docs/examples/Paint_032.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=f54d1f85b16073b80b9eef2e1a1d151d +REG_FIDDLE(Paint_032, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("paint.isFakeBoldText() %c= !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)\n", + paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag) ? '=' : '!'); + paint.setFakeBoldText(true); + SkDebugf("paint.isFakeBoldText() %c= !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag)\n", + paint.isFakeBoldText() == !!(paint.getFlags() & SkPaint::kFakeBoldText_Flag) ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_033.cpp b/docs/examples/Paint_033.cpp new file mode 100644 index 0000000000..264adc660b --- /dev/null +++ b/docs/examples/Paint_033.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=594d47858eb11028cb626515a520910a +REG_FIDDLE(Paint_033, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setFakeBoldText(true); + paint2.setFlags(paint2.getFlags() | SkPaint::kFakeBoldText_Flag); + SkDebugf("paint1 %c= paint2\n", paint1 == paint2 ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_034.cpp b/docs/examples/Paint_034.cpp new file mode 100644 index 0000000000..5820f012e2 --- /dev/null +++ b/docs/examples/Paint_034.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=69369cff2f5b145a6f616092513266a0 +REG_FIDDLE(Paint_034, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkPaint paint; + canvas->scale(.2f, .2f); + for (SkFilterQuality q : { kNone_SkFilterQuality, kLow_SkFilterQuality, + kMedium_SkFilterQuality, kHigh_SkFilterQuality } ) { + paint.setFilterQuality(q); + canvas->drawImage(image.get(), 0, 0, &paint); + canvas->translate(550, 0); + if (kLow_SkFilterQuality == q) canvas->translate(-1100, 550); + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_035.cpp b/docs/examples/Paint_035.cpp new file mode 100644 index 0000000000..c264a95b89 --- /dev/null +++ b/docs/examples/Paint_035.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=d4ca1f23809b6835c4ba46ea98a86900 +REG_FIDDLE(Paint_035, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("kNone_SkFilterQuality %c= paint.getFilterQuality()\n", + kNone_SkFilterQuality == paint.getFilterQuality() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_036.cpp b/docs/examples/Paint_036.cpp new file mode 100644 index 0000000000..fa092348ec --- /dev/null +++ b/docs/examples/Paint_036.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=e4288fabf24ee60b645e8bb6ea0afadf +REG_FIDDLE(Paint_036, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setFilterQuality(kHigh_SkFilterQuality); + SkDebugf("kHigh_SkFilterQuality %c= paint.getFilterQuality()\n", + kHigh_SkFilterQuality == paint.getFilterQuality() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_037.cpp b/docs/examples/Paint_037.cpp new file mode 100644 index 0000000000..5ecfff50b6 --- /dev/null +++ b/docs/examples/Paint_037.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=214b559d75c65a7bef6ef4be1f860053 +REG_FIDDLE(Paint_037, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(0x8000FF00); // transparent green + canvas->drawCircle(50, 50, 40, paint); + paint.setARGB(128, 255, 0, 0); // transparent red + canvas->drawCircle(80, 50, 40, paint); + paint.setColor(SK_ColorBLUE); + paint.setAlpha(0x80); + canvas->drawCircle(65, 65, 40, paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_038.cpp b/docs/examples/Paint_038.cpp new file mode 100644 index 0000000000..7d821ea92b --- /dev/null +++ b/docs/examples/Paint_038.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=72d41f890203109a41f589a7403acae9 +REG_FIDDLE(Paint_038, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorYELLOW); + SkColor y = paint.getColor(); + SkDebugf("Yellow is %d%% red, %d%% green, and %d%% blue.\n", (int) (SkColorGetR(y) / 2.55f), + (int) (SkColorGetG(y) / 2.55f), (int) (SkColorGetB(y) / 2.55f)); +} +} // END FIDDLE diff --git a/docs/examples/Paint_039.cpp b/docs/examples/Paint_039.cpp new file mode 100644 index 0000000000..2aaced03e4 --- /dev/null +++ b/docs/examples/Paint_039.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=8512ea2176f36e8f1aeef311ff228790 +REG_FIDDLE(Paint_039, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorYELLOW); + SkColor4f y = paint.getColor4f(); + SkDebugf("Yellow is %d%% red, %d%% green, and %d%% blue.\n", (int) (y.fR * 100), + (int) (y.fG * 100), (int) (y.fB * 100)); +} +} // END FIDDLE diff --git a/docs/examples/Paint_040.cpp b/docs/examples/Paint_040.cpp new file mode 100644 index 0000000000..8a4406d706 --- /dev/null +++ b/docs/examples/Paint_040.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=6e70f18300bd676a3c056ceb6b62f8df +REG_FIDDLE(Paint_040, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint green1, green2; + unsigned a = 255; + unsigned r = 0; + unsigned g = 255; + unsigned b = 0; + green1.setColor((a << 24) + (r << 16) + (g << 8) + (b << 0)); + green2.setColor(0xFF00FF00); + SkDebugf("green1 %c= green2\n", green1 == green2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_041.cpp b/docs/examples/Paint_041.cpp new file mode 100644 index 0000000000..7ce0ca6cd9 --- /dev/null +++ b/docs/examples/Paint_041.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=fa60859e3d03bdc117a05b32e093a8f1 +REG_FIDDLE(Paint_041, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint green1, green2; + green1.setColor4f({0, 1, 0, 1}, nullptr); // R=0 G=1 B=0 A=1 + green2.setColor(0xFF00FF00); // A=255 R=0 G=255 B=0 + SkDebugf("green1 %c= green2\n", green1 == green2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_042.cpp b/docs/examples/Paint_042.cpp new file mode 100644 index 0000000000..1a144dc354 --- /dev/null +++ b/docs/examples/Paint_042.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=9a85bb62fe3d877b18fb7f952c4fa7f7 +REG_FIDDLE(Paint_042, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("255 %c= paint.getAlpha()\n", 255 == paint.getAlpha() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_043.cpp b/docs/examples/Paint_043.cpp new file mode 100644 index 0000000000..138fe600f6 --- /dev/null +++ b/docs/examples/Paint_043.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=6ddc0360512dfb9947e75c17e6a8103d +REG_FIDDLE(Paint_043, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(0x00112233); + paint.setAlpha(0x44); + SkDebugf("0x44112233 %c= paint.getColor()\n", 0x44112233 == paint.getColor() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_044.cpp b/docs/examples/Paint_044.cpp new file mode 100644 index 0000000000..0a826fd8a9 --- /dev/null +++ b/docs/examples/Paint_044.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=cb62e4755789ed32f7120dc55984959d +REG_FIDDLE(Paint_044, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint transRed1, transRed2; + transRed1.setARGB(255 / 2, 255, 0, 0); + transRed2.setColor(SkColorSetARGB(255 / 2, 255, 0, 0)); + SkDebugf("transRed1 %c= transRed2", transRed1 == transRed2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_045.cpp b/docs/examples/Paint_045.cpp new file mode 100644 index 0000000000..d445b06ddd --- /dev/null +++ b/docs/examples/Paint_045.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=1c5e18c3c0102d2dac86a78ba8c8ce01 +REG_FIDDLE(Paint_045, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("SkPaint::kFill_Style %c= paint.getStyle()\n", + SkPaint::kFill_Style == paint.getStyle() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_046.cpp b/docs/examples/Paint_046.cpp new file mode 100644 index 0000000000..2657797f9e --- /dev/null +++ b/docs/examples/Paint_046.cpp @@ -0,0 +1,32 @@ +// 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 "fiddle/examples.h" +// HASH=c7bb6248e4735b8d1a32d02fba40d344 +REG_FIDDLE(Paint_046, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeWidth(5); + SkRegion region; + region.op(140, 10, 160, 30, SkRegion::kUnion_Op); + region.op(170, 40, 190, 60, SkRegion::kUnion_Op); + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeA8(50, 50), 50); + uint8_t pixels[50][50]; + for (int x = 0; x < 50; ++x) { + for (int y = 0; y < 50; ++y) { + pixels[y][x] = (x + y) % 5 ? 0xFF : 0x00; + } + } + bitmap.setPixels(pixels); + for (auto style : { SkPaint::kFill_Style, + SkPaint::kStroke_Style, + SkPaint::kStrokeAndFill_Style }) { + paint.setStyle(style); + canvas->drawLine(10, 10, 60, 60, paint); + canvas->drawRect({80, 10, 130, 60}, paint); + canvas->drawRegion(region, paint); + canvas->drawBitmap(bitmap, 200, 10, &paint); + canvas->translate(0, 80); + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_047.cpp b/docs/examples/Paint_047.cpp new file mode 100644 index 0000000000..6ed1fb248c --- /dev/null +++ b/docs/examples/Paint_047.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=5112c7209a19e035c61cef33a624a652 +REG_FIDDLE(Paint_047, 256, 170, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + for (bool antialias : { false, true }) { + paint.setAntiAlias(antialias); + for (int width = 0; width <= 4; ++width) { + SkScalar offset = antialias * 100 + width * 20; + paint.setStrokeWidth(width * 0.25f); + canvas->drawLine(10 + offset, 10, 20 + offset, 60, paint); + canvas->drawLine(10 + offset, 110, 60 + offset, 160, paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_048.cpp b/docs/examples/Paint_048.cpp new file mode 100644 index 0000000000..476e5c6849 --- /dev/null +++ b/docs/examples/Paint_048.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=99aa73f64df8bbf06e656cd891a81b9e +REG_FIDDLE(Paint_048, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("0 %c= paint.getStrokeWidth()\n", 0 == paint.getStrokeWidth() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_049.cpp b/docs/examples/Paint_049.cpp new file mode 100644 index 0000000000..73e6103ce9 --- /dev/null +++ b/docs/examples/Paint_049.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=0c4446c0870b5c7b5a2efe77ff92afb8 +REG_FIDDLE(Paint_049, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeWidth(5); + paint.setStrokeWidth(-1); + SkDebugf("5 %c= paint.getStrokeWidth()\n", 5 == paint.getStrokeWidth() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_050.cpp b/docs/examples/Paint_050.cpp new file mode 100644 index 0000000000..1cdc48c2ab --- /dev/null +++ b/docs/examples/Paint_050.cpp @@ -0,0 +1,36 @@ +// 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 "fiddle/examples.h" +// HASH=5de2de0f00354e59074a9bb1a42d5a63 +REG_FIDDLE(Paint_050, 384, 170, false, 0) { +void draw(SkCanvas* canvas) { + SkPoint pts[] = {{ 10, 50 }, { 110, 80 }, { 10, 110 }}; + SkVector v[] = { pts[0] - pts[1], pts[2] - pts[1] }; + SkScalar angle1 = SkScalarATan2(v[0].fY, v[0].fX); + SkScalar angle2 = SkScalarATan2(v[1].fY, v[1].fX); + const SkScalar strokeWidth = 20; + SkScalar miterLimit = 1 / SkScalarSin((angle2 - angle1) / 2); + SkScalar miterLength = strokeWidth * miterLimit; + SkPath path; + path.moveTo(pts[0]); + path.lineTo(pts[1]); + path.lineTo(pts[2]); + SkPaint paint; // set to default kMiter_Join + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeMiter(miterLimit); + paint.setStrokeWidth(strokeWidth); + canvas->drawPath(path, paint); + paint.setStrokeWidth(1); + canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50, + pts[1].fX + miterLength / 2, pts[1].fY + 50, paint); + canvas->translate(200, 0); + miterLimit *= 0.99f; + paint.setStrokeMiter(miterLimit); + paint.setStrokeWidth(strokeWidth); + canvas->drawPath(path, paint); + paint.setStrokeWidth(1); + canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50, + pts[1].fX + miterLength / 2, pts[1].fY + 50, paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_051.cpp b/docs/examples/Paint_051.cpp new file mode 100644 index 0000000000..91f92a47e3 --- /dev/null +++ b/docs/examples/Paint_051.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=50da74a43b725f07a914df588c867d36 +REG_FIDDLE(Paint_051, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("default miter limit == %g\n", paint.getStrokeMiter()); +} +} // END FIDDLE diff --git a/docs/examples/Paint_052.cpp b/docs/examples/Paint_052.cpp new file mode 100644 index 0000000000..931be171f9 --- /dev/null +++ b/docs/examples/Paint_052.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=700b284dbc97785c6a9c9636088713ad +REG_FIDDLE(Paint_052, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeMiter(8); + paint.setStrokeMiter(-1); + SkDebugf("default miter limit == %g\n", paint.getStrokeMiter()); +} +} // END FIDDLE diff --git a/docs/examples/Paint_053.cpp b/docs/examples/Paint_053.cpp new file mode 100644 index 0000000000..132e754a47 --- /dev/null +++ b/docs/examples/Paint_053.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=2bffb6384cc20077e632e7d01da045ca +REG_FIDDLE(Paint_053, 256, 200, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + SkPath path; + path.moveTo(30, 30); + path.lineTo(30, 30); + path.moveTo(70, 30); + path.lineTo(90, 40); + for (SkPaint::Cap c : { SkPaint::kButt_Cap, SkPaint::kRound_Cap, SkPaint::kSquare_Cap } ) { + paint.setStrokeCap(c); + canvas->drawPath(path, paint); + canvas->translate(0, 70); + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_054.cpp b/docs/examples/Paint_054.cpp new file mode 100644 index 0000000000..2bca248016 --- /dev/null +++ b/docs/examples/Paint_054.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=aabf9baee8e026fae36fca30e955512b +REG_FIDDLE(Paint_054, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("kButt_Cap %c= default stroke cap\n", + SkPaint::kButt_Cap == paint.getStrokeCap() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_055.cpp b/docs/examples/Paint_055.cpp new file mode 100644 index 0000000000..6f9efbe1ec --- /dev/null +++ b/docs/examples/Paint_055.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=de83fbd848a4625345b4b87a6e55d98a +REG_FIDDLE(Paint_055, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeCap(SkPaint::kRound_Cap); + paint.setStrokeCap((SkPaint::Cap) SkPaint::kCapCount); + SkDebugf("kRound_Cap %c= paint.getStrokeCap()\n", + SkPaint::kRound_Cap == paint.getStrokeCap() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_056.cpp b/docs/examples/Paint_056.cpp new file mode 100644 index 0000000000..b4388bb5a8 --- /dev/null +++ b/docs/examples/Paint_056.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=917c44b504d3f9308571fd3835d90a0d +REG_FIDDLE(Paint_056, 256, 200, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + SkPath path; + path.moveTo(30, 20); + path.lineTo(40, 40); + path.conicTo(70, 20, 100, 20, .707f); + for (SkPaint::Join j : { SkPaint::kMiter_Join, SkPaint::kRound_Join, SkPaint::kBevel_Join } ) { + paint.setStrokeJoin(j); + canvas->drawPath(path, paint); + canvas->translate(0, 70); + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_057.cpp b/docs/examples/Paint_057.cpp new file mode 100644 index 0000000000..d7ede5e59e --- /dev/null +++ b/docs/examples/Paint_057.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=3b1aebacc21c1836a52876b9b0b3905e +REG_FIDDLE(Paint_057, 462, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo(10, 50); + path.quadTo(35, 110, 60, 210); + path.quadTo(105, 110, 130, 10); + SkPaint paint; // set to default kMiter_Join + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(20); + canvas->drawPath(path, paint); + canvas->translate(150, 0); + paint.setStrokeJoin(SkPaint::kBevel_Join); + canvas->drawPath(path, paint); + canvas->translate(150, 0); + paint.setStrokeJoin(SkPaint::kRound_Join); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_058.cpp b/docs/examples/Paint_058.cpp new file mode 100644 index 0000000000..01e43c430b --- /dev/null +++ b/docs/examples/Paint_058.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=31bf751d0a8ddf176b871810820d8199 +REG_FIDDLE(Paint_058, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("kMiter_Join %c= default stroke join\n", + SkPaint::kMiter_Join == paint.getStrokeJoin() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_059.cpp b/docs/examples/Paint_059.cpp new file mode 100644 index 0000000000..7f606eb9b8 --- /dev/null +++ b/docs/examples/Paint_059.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=48d963ad4286eddf680f9c511eb6da91 +REG_FIDDLE(Paint_059, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeJoin(SkPaint::kMiter_Join); + paint.setStrokeJoin((SkPaint::Join) SkPaint::kJoinCount); + SkDebugf("kMiter_Join %c= paint.getStrokeJoin()\n", + SkPaint::kMiter_Join == paint.getStrokeJoin() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_060.cpp b/docs/examples/Paint_060.cpp new file mode 100644 index 0000000000..880dc79999 --- /dev/null +++ b/docs/examples/Paint_060.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=cedd6233848198e1fca4d1e14816baaf +REG_FIDDLE(Paint_060, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint strokePaint; + strokePaint.setAntiAlias(true); + strokePaint.setStyle(SkPaint::kStroke_Style); + strokePaint.setStrokeWidth(.1f); + SkPath strokePath; + strokePath.moveTo(.08f, .08f); + strokePath.quadTo(.09f, .08f, .17f, .17f); + SkPath fillPath; + SkPaint outlinePaint(strokePaint); + outlinePaint.setStrokeWidth(2); + SkMatrix scale = SkMatrix::MakeScale(300, 300); + for (SkScalar precision : { 0.01f, .1f, 1.f, 10.f, 100.f } ) { + strokePaint.getFillPath(strokePath, &fillPath, nullptr, precision); + fillPath.transform(scale); + canvas->drawPath(fillPath, outlinePaint); + canvas->translate(60, 0); + if (1.f == precision) canvas->translate(-180, 100); + } + strokePath.transform(scale); + strokePaint.setStrokeWidth(30); + canvas->drawPath(strokePath, strokePaint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_061.cpp b/docs/examples/Paint_061.cpp new file mode 100644 index 0000000000..3b783eaadc --- /dev/null +++ b/docs/examples/Paint_061.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=e6d8ca0cc17e0b475bd54dd995825468 +REG_FIDDLE(Paint_061, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(10); + SkPath strokePath; + strokePath.moveTo(20, 20); + strokePath.lineTo(100, 100); + canvas->drawPath(strokePath, paint); + SkPath fillPath; + paint.getFillPath(strokePath, &fillPath); + paint.setStrokeWidth(2); + canvas->translate(40, 0); + canvas->drawPath(fillPath, paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_062.cpp b/docs/examples/Paint_062.cpp new file mode 100644 index 0000000000..4e265ab636 --- /dev/null +++ b/docs/examples/Paint_062.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=c015dc2010c15e1c00b4f7330232b0f7 +REG_FIDDLE(Paint_062, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPoint center = { 50, 50 }; + SkScalar radius = 50; + const SkColor colors[] = { 0xFFFFFFFF, 0xFF000000 }; + paint.setShader(SkGradientShader::MakeRadial(center, radius, colors, + nullptr, SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode)); + for (SkScalar a : { 0.3f, 0.6f, 1.0f } ) { + paint.setAlpha((int) (a * 255)); + canvas->drawCircle(center.fX, center.fY, radius, paint); + canvas->translate(70, 70); + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_063.cpp b/docs/examples/Paint_063.cpp new file mode 100644 index 0000000000..6d267bdca6 --- /dev/null +++ b/docs/examples/Paint_063.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=fe80fd80b98a20823db7fb9a077243c7 +REG_FIDDLE(Paint_063, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkBitmap bitmap; + bitmap.setInfo(SkImageInfo::MakeA8(5, 1), 5); // bitmap only contains alpha + uint8_t pixels[5] = { 0x22, 0x55, 0x88, 0xBB, 0xFF }; + bitmap.setPixels(pixels); + paint.setShader(SkShader::MakeBitmapShader(bitmap, + SkShader::kMirror_TileMode, SkShader::kMirror_TileMode)); + for (SkColor c : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN } ) { + paint.setColor(c); // all components in color affect shader + canvas->drawCircle(50, 50, 50, paint); + canvas->translate(70, 70); + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_064.cpp b/docs/examples/Paint_064.cpp new file mode 100644 index 0000000000..649a13783e --- /dev/null +++ b/docs/examples/Paint_064.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=09f15b9fd88882850da2d235eb86292f +REG_FIDDLE(Paint_064, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("nullptr %c= shader\n", paint.getShader() ? '!' : '='); + paint.setShader(SkShader::MakeEmptyShader()); + SkDebugf("nullptr %c= shader\n", paint.getShader() ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/Paint_065.cpp b/docs/examples/Paint_065.cpp new file mode 100644 index 0000000000..7ed2d3b047 --- /dev/null +++ b/docs/examples/Paint_065.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=53da0295972a418cbc9607bbb17feaa8 +REG_FIDDLE(Paint_065, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setShader(SkShader::MakeEmptyShader()); + SkDebugf("shader unique: %s\n", paint1.getShader()->unique() ? "true" : "false"); + paint2.setShader(paint1.refShader()); + SkDebugf("shader unique: %s\n", paint1.getShader()->unique() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Paint_066.cpp b/docs/examples/Paint_066.cpp new file mode 100644 index 0000000000..7ae55f3243 --- /dev/null +++ b/docs/examples/Paint_066.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=77e64d5bae9b1ba037fd99252bb4aa58 +REG_FIDDLE(Paint_066, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColor(SK_ColorBLUE); + paint.setShader(SkShader::MakeColorShader(SK_ColorRED)); + canvas->drawRect(SkRect::MakeWH(40, 40), paint); + paint.setShader(nullptr); + canvas->translate(50, 0); + canvas->drawRect(SkRect::MakeWH(40, 40), paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_067.cpp b/docs/examples/Paint_067.cpp new file mode 100644 index 0000000000..20a61bea13 --- /dev/null +++ b/docs/examples/Paint_067.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=5abde56ca2f89a18b8e231abd1b57c56 +REG_FIDDLE(Paint_067, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColorFilter(SkColorMatrixFilter::MakeLightingFilter(0xFFFFFF, 0xFF0000)); + for (SkColor c : { SK_ColorBLACK, SK_ColorGREEN } ) { + paint.setColor(c); + canvas->drawRect(SkRect::MakeXYWH(10, 10, 50, 50), paint); + paint.setAlpha(0x80); + canvas->drawRect(SkRect::MakeXYWH(60, 60, 50, 50), paint); + canvas->translate(100, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_068.cpp b/docs/examples/Paint_068.cpp new file mode 100644 index 0000000000..bd8d7d00f4 --- /dev/null +++ b/docs/examples/Paint_068.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=093bdc627d6b59002670fd290931f6c9 +REG_FIDDLE(Paint_068, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("nullptr %c= color filter\n", paint.getColorFilter() ? '!' : '='); + paint.setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY, SkBlendMode::kSrcIn)); + SkDebugf("nullptr %c= color filter\n", paint.getColorFilter() ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/Paint_069.cpp b/docs/examples/Paint_069.cpp new file mode 100644 index 0000000000..59bb7572d5 --- /dev/null +++ b/docs/examples/Paint_069.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=b588c95fa4c86ddbc4b0546762f08297 +REG_FIDDLE(Paint_069, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setColorFilter(SkColorFilter::MakeModeFilter(0xFFFF0000, SkBlendMode::kSrcATop)); + SkDebugf("color filter unique: %s\n", paint1.getColorFilter()->unique() ? "true" : "false"); + paint2.setColorFilter(paint1.refColorFilter()); + SkDebugf("color filter unique: %s\n", paint1.getColorFilter()->unique() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Paint_070.cpp b/docs/examples/Paint_070.cpp new file mode 100644 index 0000000000..eeac356f77 --- /dev/null +++ b/docs/examples/Paint_070.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=c7b786dc9b3501cd0eaba47494b6fa31 +REG_FIDDLE(Paint_070, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY, SkBlendMode::kSrcIn)); + canvas->drawRect(SkRect::MakeWH(50, 50), paint); + paint.setColorFilter(nullptr); + canvas->translate(70, 0); + canvas->drawRect(SkRect::MakeWH(50, 50), paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_071.cpp b/docs/examples/Paint_071.cpp new file mode 100644 index 0000000000..94769e7ff5 --- /dev/null +++ b/docs/examples/Paint_071.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=73092d4d06faecea3c204d852a4dd8a8 +REG_FIDDLE(Paint_071, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint normal, blender; + normal.setColor(0xFF58a889); + blender.setColor(0xFF8958a8); + canvas->clear(0); + for (SkBlendMode m : { SkBlendMode::kSrcOver, SkBlendMode::kSrcIn, SkBlendMode::kSrcOut } ) { + normal.setBlendMode(SkBlendMode::kSrcOver); + canvas->drawOval(SkRect::MakeXYWH(30, 30, 30, 80), normal); + blender.setBlendMode(m); + canvas->drawOval(SkRect::MakeXYWH(10, 50, 80, 30), blender); + canvas->translate(70, 70); + } +} +} // END FIDDLE diff --git a/docs/examples/Paint_072.cpp b/docs/examples/Paint_072.cpp new file mode 100644 index 0000000000..398df1419c --- /dev/null +++ b/docs/examples/Paint_072.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=a1e059c8f6740fa2044cc64152b39dda +REG_FIDDLE(Paint_072, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("kSrcOver %c= getBlendMode\n", + SkBlendMode::kSrcOver == paint.getBlendMode() ? '=' : '!'); + paint.setBlendMode(SkBlendMode::kSrc); + SkDebugf("kSrcOver %c= getBlendMode\n", + SkBlendMode::kSrcOver == paint.getBlendMode() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_073.cpp b/docs/examples/Paint_073.cpp new file mode 100644 index 0000000000..fa055740bb --- /dev/null +++ b/docs/examples/Paint_073.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=257c9473db7a2b3a0fb2b9e2431e59a6 +REG_FIDDLE(Paint_073, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("isSrcOver %c= true\n", paint.isSrcOver() ? '=' : '!'); + paint.setBlendMode(SkBlendMode::kSrc); + SkDebugf("isSrcOver %c= true\n", paint.isSrcOver() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_074.cpp b/docs/examples/Paint_074.cpp new file mode 100644 index 0000000000..e8f8d6aea4 --- /dev/null +++ b/docs/examples/Paint_074.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=257c9473db7a2b3a0fb2b9e2431e59a6 +REG_FIDDLE(Paint_074, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("isSrcOver %c= true\n", paint.isSrcOver() ? '=' : '!'); + paint.setBlendMode(SkBlendMode::kSrc); + SkDebugf("isSrcOver %c= true\n", paint.isSrcOver() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Paint_075.cpp b/docs/examples/Paint_075.cpp new file mode 100644 index 0000000000..b430bf0e43 --- /dev/null +++ b/docs/examples/Paint_075.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=8cf5684b187d60f09e11c4a48993ea39 +REG_FIDDLE(Paint_075, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(16); + SkScalar intervals[] = {30, 10}; + paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 1)); + canvas->drawRoundRect({20, 20, 120, 120}, 20, 20, paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_076.cpp b/docs/examples/Paint_076.cpp new file mode 100644 index 0000000000..58d04f957a --- /dev/null +++ b/docs/examples/Paint_076.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=211a1b14bfa6c4332082c8eab4fbc5fd +REG_FIDDLE(Paint_076, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("nullptr %c= path effect\n", paint.getPathEffect() ? '!' : '='); + paint.setPathEffect(SkCornerPathEffect::Make(10)); + SkDebugf("nullptr %c= path effect\n", paint.getPathEffect() ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/Paint_077.cpp b/docs/examples/Paint_077.cpp new file mode 100644 index 0000000000..e4aed13c77 --- /dev/null +++ b/docs/examples/Paint_077.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=f56039b94c702c2704c8c5100e623aca +REG_FIDDLE(Paint_077, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + SkScalar intervals[] = {1, 2}; + paint1.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 10)); + SkDebugf("path effect unique: %s\n", paint1.getPathEffect()->unique() ? "true" : "false"); + paint2.setPathEffect(paint1.refPathEffect()); + SkDebugf("path effect unique: %s\n", paint1.getPathEffect()->unique() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Paint_078.cpp b/docs/examples/Paint_078.cpp new file mode 100644 index 0000000000..1dfadf4971 --- /dev/null +++ b/docs/examples/Paint_078.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=52dd55074ca0b7d520d04e750ca2a0d7 +REG_FIDDLE(Paint_078, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setPathEffect(SkDiscretePathEffect::Make(3, 5)); + canvas->drawRect(SkRect::MakeXYWH(40, 40, 175, 175), paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_079.cpp b/docs/examples/Paint_079.cpp new file mode 100644 index 0000000000..dbac60475d --- /dev/null +++ b/docs/examples/Paint_079.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=55d7b9d482ac8e17a6153f555a8adb8d +REG_FIDDLE(Paint_079, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setMaskFilter(SkMaskFilter::MakeBlur(kSolid_SkBlurStyle, 3)); + canvas->drawRect(SkRect::MakeXYWH(40, 40, 175, 175), paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_080.cpp b/docs/examples/Paint_080.cpp new file mode 100644 index 0000000000..062f2619f7 --- /dev/null +++ b/docs/examples/Paint_080.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=5ac4b31371726da87bb7390b385e9fee +REG_FIDDLE(Paint_080, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("nullptr %c= mask filter\n", paint.getMaskFilter() ? '!' : '='); + paint.setMaskFilter(SkMaskFilter::MakeBlur(kOuter_SkBlurStyle, 3)); + SkDebugf("nullptr %c= mask filter\n", paint.getMaskFilter() ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/Paint_081.cpp b/docs/examples/Paint_081.cpp new file mode 100644 index 0000000000..2d5e215702 --- /dev/null +++ b/docs/examples/Paint_081.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=084b0dc3cebd78718c651d58f257f799 +REG_FIDDLE(Paint_081, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 1)); + SkDebugf("mask filter unique: %s\n", paint1.getMaskFilter()->unique() ? "true" : "false"); + paint2.setMaskFilter(paint1.refMaskFilter()); + SkDebugf("mask filter unique: %s\n", paint1.getMaskFilter()->unique() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Paint_082.cpp b/docs/examples/Paint_082.cpp new file mode 100644 index 0000000000..5870a9335d --- /dev/null +++ b/docs/examples/Paint_082.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=a993831c40f3e134f809134e3b74e4a6 +REG_FIDDLE(Paint_082, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(10); + paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 10)); + canvas->drawRect(SkRect::MakeXYWH(40, 40, 175, 175), paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_083.cpp b/docs/examples/Paint_083.cpp new file mode 100644 index 0000000000..93314e5612 --- /dev/null +++ b/docs/examples/Paint_083.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=1a7a5062725139760962582f599f1b97 +REG_FIDDLE(Paint_083, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTypeface(SkTypeface::MakeFromName(nullptr, SkFontStyle())); + paint.setAntiAlias(true); + paint.setTextSize(36); + canvas->drawString("A Big Hello!", 10, 40, paint); + paint.setTypeface(nullptr); + paint.setFakeBoldText(true); + canvas->drawString("A Big Hello!", 10, 80, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_084.cpp b/docs/examples/Paint_084.cpp new file mode 100644 index 0000000000..369ba3b704 --- /dev/null +++ b/docs/examples/Paint_084.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=5ce718e5a184baaac80e7098d7dad67b +REG_FIDDLE(Paint_084, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("nullptr %c= typeface\n", paint.getTypeface() ? '!' : '='); + paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle())); + SkDebugf("nullptr %c= typeface\n", paint.getTypeface() ? '!' : '='); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_085.cpp b/docs/examples/Paint_085.cpp new file mode 100644 index 0000000000..69fb1559af --- /dev/null +++ b/docs/examples/Paint_085.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=8b5aa7e555a0dc31be69db7cadf471a1 +REG_FIDDLE(Paint_085, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setTypeface(SkTypeface::MakeFromName("monospace", + SkFontStyle(SkFontStyle::kNormal_Weight, SkFontStyle::kNormal_Width, + SkFontStyle::kItalic_Slant))); + SkDebugf("typeface1 %c= typeface2\n", + paint1.getTypeface() == paint2.getTypeface() ? '=' : '!'); + paint2.setTypeface(paint1.refTypeface()); + SkDebugf("typeface1 %c= typeface2\n", + paint1.getTypeface() == paint2.getTypeface() ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_086.cpp b/docs/examples/Paint_086.cpp new file mode 100644 index 0000000000..b1427ee118 --- /dev/null +++ b/docs/examples/Paint_086.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=0e6fbb7773cd925b274552f4cd1abef2 +REG_FIDDLE(Paint_086, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTypeface(SkTypeface::MakeFromName("monospace", SkFontStyle())); + canvas->drawString("hamburgerfons", 10, 30, paint); + paint.setTypeface(nullptr); + canvas->drawString("hamburgerfons", 10, 50, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_087.cpp b/docs/examples/Paint_087.cpp new file mode 100644 index 0000000000..9b769ad3fa --- /dev/null +++ b/docs/examples/Paint_087.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=ece04ee3d3761e3425f37c8f06f054c1 +REG_FIDDLE(Paint_087, 256, 256, false, 0) { +#include "SkBlurImageFilter.h" + +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(2); + SkRegion region; + region.op( 10, 10, 50, 50, SkRegion::kUnion_Op); + region.op( 10, 50, 90, 90, SkRegion::kUnion_Op); + paint.setImageFilter(SkBlurImageFilter::Make(5.0f, 5.0f, nullptr)); + canvas->drawRegion(region, paint); + paint.setImageFilter(nullptr); + paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 5)); + canvas->translate(100, 100); + canvas->drawRegion(region, paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_088.cpp b/docs/examples/Paint_088.cpp new file mode 100644 index 0000000000..8efd0148b1 --- /dev/null +++ b/docs/examples/Paint_088.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=c11f8eaa1dd149bc18db21e23ce26904 +REG_FIDDLE(Paint_088, 256, 256, true, 0) { +#include "SkBlurImageFilter.h" + +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("nullptr %c= image filter\n", paint.getImageFilter() ? '!' : '='); + paint.setImageFilter(SkBlurImageFilter::Make(kOuter_SkBlurStyle, 3, nullptr, nullptr)); + SkDebugf("nullptr %c= image filter\n", paint.getImageFilter() ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/Paint_089.cpp b/docs/examples/Paint_089.cpp new file mode 100644 index 0000000000..40e8ac9539 --- /dev/null +++ b/docs/examples/Paint_089.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=13f09088b569251547107d14ae989dc1 +REG_FIDDLE(Paint_089, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + paint1.setImageFilter(SkOffsetImageFilter::Make(25, 25, nullptr)); + SkDebugf("image filter unique: %s\n", paint1.getImageFilter()->unique() ? "true" : "false"); + paint2.setImageFilter(paint1.refImageFilter()); + SkDebugf("image filter unique: %s\n", paint1.getImageFilter()->unique() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Paint_090.cpp b/docs/examples/Paint_090.cpp new file mode 100644 index 0000000000..b027df5e6b --- /dev/null +++ b/docs/examples/Paint_090.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=6679d6e4ec632715ee03e68391bd7f9a +REG_FIDDLE(Paint_090, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkBitmap bitmap; + bitmap.allocN32Pixels(100, 100); + SkCanvas offscreen(bitmap); + SkPaint paint; + paint.setAntiAlias(true); + paint.setColor(SK_ColorWHITE); + paint.setTextSize(96); + offscreen.clear(0); + offscreen.drawString("e", 20, 70, paint); + paint.setImageFilter( + SkLightingImageFilter::MakePointLitDiffuse(SkPoint3::Make(80, 100, 10), + SK_ColorWHITE, 1, 2, nullptr, nullptr)); + canvas->drawBitmap(bitmap, 0, 0, &paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_091.cpp b/docs/examples/Paint_091.cpp new file mode 100644 index 0000000000..cfcc748a6a --- /dev/null +++ b/docs/examples/Paint_091.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=84ec12a36e50df5ac565cc7a75ffbe9f +REG_FIDDLE(Paint_091, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkLayerDrawLooper::LayerInfo info; + info.fPaintBits = (SkLayerDrawLooper::BitFlags) SkLayerDrawLooper::kColorFilter_Bit; + info.fColorMode = SkBlendMode::kSrc; + SkLayerDrawLooper::Builder looperBuilder; + SkPaint* loopPaint = looperBuilder.addLayer(info); + loopPaint->setColor(SK_ColorRED); + info.fOffset.set(20, 20); + loopPaint = looperBuilder.addLayer(info); + loopPaint->setColor(SK_ColorBLUE); + SkPaint paint; + paint.setDrawLooper(looperBuilder.detach()); + canvas->drawCircle(50, 50, 50, paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_092.cpp b/docs/examples/Paint_092.cpp new file mode 100644 index 0000000000..408422f024 --- /dev/null +++ b/docs/examples/Paint_092.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=af4c5acc7a91e7f23c2af48018903ad4 +REG_FIDDLE(Paint_092, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("nullptr %c= draw looper\n", paint.getDrawLooper() ? '!' : '='); + SkLayerDrawLooper::Builder looperBuilder; + paint.setDrawLooper(looperBuilder.detach()); + SkDebugf("nullptr %c= draw looper\n", paint.getDrawLooper() ? '!' : '='); +} +} // END FIDDLE diff --git a/docs/examples/Paint_093.cpp b/docs/examples/Paint_093.cpp new file mode 100644 index 0000000000..3093275dd5 --- /dev/null +++ b/docs/examples/Paint_093.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=2a3782c33f04ed17a725d0e449c6f7c3 +REG_FIDDLE(Paint_093, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint1, paint2; + SkLayerDrawLooper::Builder looperBuilder; + paint1.setDrawLooper(looperBuilder.detach()); + SkDebugf("draw looper unique: %s\n", paint1.getDrawLooper()->unique() ? "true" : "false"); + paint2.setDrawLooper(paint1.refDrawLooper()); + SkDebugf("draw looper unique: %s\n", paint1.getDrawLooper()->unique() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Paint_094.cpp b/docs/examples/Paint_094.cpp new file mode 100644 index 0000000000..db39fd6e71 --- /dev/null +++ b/docs/examples/Paint_094.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=bf10f838b330f0a3a3266d42ea68a638 +REG_FIDDLE(Paint_094, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setDrawLooper(SkBlurDrawLooper::Make(0x7FFF0000, 4, -5, -10)); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(10); + paint.setAntiAlias(true); + paint.setColor(0x7f0000ff); + canvas->drawCircle(70, 70, 50, paint); +} +} // END FIDDLE diff --git a/docs/examples/Paint_095.cpp b/docs/examples/Paint_095.cpp new file mode 100644 index 0000000000..0d6f600bd1 --- /dev/null +++ b/docs/examples/Paint_095.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=91c9a3e498bb9412e4522a95d076ed5f +REG_FIDDLE(Paint_095, 256, 135, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + canvas->drawString("12 point", 10, 20, paint); + paint.setTextSize(24); + canvas->drawString("24 point", 10, 60, paint); + paint.setTextSize(48); + canvas->drawString("48 point", 10, 120, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_096.cpp b/docs/examples/Paint_096.cpp new file mode 100644 index 0000000000..4a3b2f00e4 --- /dev/null +++ b/docs/examples/Paint_096.cpp @@ -0,0 +1,12 @@ +#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 "fiddle/examples.h" +// HASH=983e2a71ba72d4ba8c945420040b8f1c +REG_FIDDLE(Paint_096, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("12 %c= default text size\n", 12 == paint.getTextSize() ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_097.cpp b/docs/examples/Paint_097.cpp new file mode 100644 index 0000000000..d25d44d196 --- /dev/null +++ b/docs/examples/Paint_097.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=6510c9e2f57b83c47e67829e7a68d493 +REG_FIDDLE(Paint_097, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("12 %c= text size\n", 12 == paint.getTextSize() ? '=' : '!'); + paint.setTextSize(-20); + SkDebugf("12 %c= text size\n", 12 == paint.getTextSize() ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_098.cpp b/docs/examples/Paint_098.cpp new file mode 100644 index 0000000000..4a3c7f9683 --- /dev/null +++ b/docs/examples/Paint_098.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=d13d787c1e36f515319fc998411c1d91 +REG_FIDDLE(Paint_098, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + paint.setTextScaleX(.8f); + canvas->drawString("narrow", 10, 20, paint); + paint.setTextScaleX(1); + canvas->drawString("normal", 10, 60, paint); + paint.setTextScaleX(1.2f); + canvas->drawString("wide", 10, 100, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_099.cpp b/docs/examples/Paint_099.cpp new file mode 100644 index 0000000000..5fc1117435 --- /dev/null +++ b/docs/examples/Paint_099.cpp @@ -0,0 +1,12 @@ +#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 "fiddle/examples.h" +// HASH=5dc8e58f6910cb8e4de9ed60f888188b +REG_FIDDLE(Paint_099, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("1 %c= default text scale x\n", 1 == paint.getTextScaleX() ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_100.cpp b/docs/examples/Paint_100.cpp new file mode 100644 index 0000000000..683f21bc93 --- /dev/null +++ b/docs/examples/Paint_100.cpp @@ -0,0 +1,13 @@ +#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 "fiddle/examples.h" +// HASH=a75bbdb8bb866b125c4c1dd5e967d470 +REG_FIDDLE(Paint_100, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextScaleX(0.f / 0.f); + SkDebugf("text scale %s-a-number\n", SkScalarIsNaN(paint.getTextScaleX()) ? "not" : "is"); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_101.cpp b/docs/examples/Paint_101.cpp new file mode 100644 index 0000000000..6ca7ebad0e --- /dev/null +++ b/docs/examples/Paint_101.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=aff208b0aab265f273045b27e683c17c +REG_FIDDLE(Paint_101, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(24); + paint.setTextSkewX(-.25f); + canvas->drawString("right-leaning", 10, 100, paint); + paint.setTextSkewX(0); + canvas->drawString("normal", 10, 60, paint); + paint.setTextSkewX(.25f); + canvas->drawString("left-leaning", 10, 20, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_102.cpp b/docs/examples/Paint_102.cpp new file mode 100644 index 0000000000..3d16133dc4 --- /dev/null +++ b/docs/examples/Paint_102.cpp @@ -0,0 +1,12 @@ +#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 "fiddle/examples.h" +// HASH=11c10f466dae0d1639dbb9f6a0040218 +REG_FIDDLE(Paint_102, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("0 %c= default text skew x\n", 0 == paint.getTextSkewX() ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_103.cpp b/docs/examples/Paint_103.cpp new file mode 100644 index 0000000000..bc18d6c21b --- /dev/null +++ b/docs/examples/Paint_103.cpp @@ -0,0 +1,13 @@ +#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 "fiddle/examples.h" +// HASH=6bd705a6e0c5f8ee24f302fe531bfabc +REG_FIDDLE(Paint_103, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextScaleX(1.f / 0.f); + SkDebugf("text scale %s-finite\n", SkScalarIsFinite(paint.getTextScaleX()) ? "is" : "not"); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_104.cpp b/docs/examples/Paint_104.cpp new file mode 100644 index 0000000000..1eccff6d7f --- /dev/null +++ b/docs/examples/Paint_104.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=767fa4e7b6300e16a419f9881f0f9d3d +REG_FIDDLE(Paint_104, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + const char hello8[] = "Hello" "\xE2" "\x98" "\xBA"; + const uint16_t hello16[] = { 'H', 'e', 'l', 'l', 'o', 0x263A }; + const uint32_t hello32[] = { 'H', 'e', 'l', 'l', 'o', 0x263A }; + paint.setTextSize(24); + canvas->drawText(hello8, sizeof(hello8) - 1, 10, 30, paint); + paint.setTextEncoding(kUTF16_SkTextEncoding); + canvas->drawText(hello16, sizeof(hello16), 10, 60, paint); + paint.setTextEncoding(kUTF32_SkTextEncoding); + canvas->drawText(hello32, sizeof(hello32), 10, 90, paint); + uint16_t glyphs[SK_ARRAY_COUNT(hello32)]; + paint.textToGlyphs(hello32, sizeof(hello32), glyphs); + paint.setTextEncoding(kGlyphID_SkTextEncoding); + canvas->drawText(glyphs, sizeof(glyphs), 10, 120, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_105.cpp b/docs/examples/Paint_105.cpp new file mode 100644 index 0000000000..e5f5c7c43b --- /dev/null +++ b/docs/examples/Paint_105.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=0d21e968e9a4c78c902ae3ef494941a0 +REG_FIDDLE(Paint_105, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("kUTF8_SkTextEncoding %c= text encoding\n", + kUTF8_SkTextEncoding == paint.getTextEncoding() ? '=' : '!'); + paint.setTextEncoding(kGlyphID_SkTextEncoding); + SkDebugf("kGlyphID_SkTextEncoding %c= text encoding\n", + kGlyphID_SkTextEncoding == paint.getTextEncoding() ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_106.cpp b/docs/examples/Paint_106.cpp new file mode 100644 index 0000000000..0fd8de7b3b --- /dev/null +++ b/docs/examples/Paint_106.cpp @@ -0,0 +1,13 @@ +#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 "fiddle/examples.h" +// HASH=a5d1ba0dbf42afb797ffdb07647b5cb9 +REG_FIDDLE(Paint_106, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextEncoding((SkTextEncoding) 4); + SkDebugf("4 %c= text encoding\n", (SkTextEncoding) 4 == paint.getTextEncoding() ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_107.cpp b/docs/examples/Paint_107.cpp new file mode 100644 index 0000000000..9f68365f8f --- /dev/null +++ b/docs/examples/Paint_107.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=59d9b8249afa1c2af6186711250ce240 +REG_FIDDLE(Paint_107, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(32); + SkScalar lineHeight = paint.getFontMetrics(nullptr); + canvas->drawString("line 1", 10, 40, paint); + canvas->drawString("line 2", 10, 40 + lineHeight, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_108.cpp b/docs/examples/Paint_108.cpp new file mode 100644 index 0000000000..219cfae351 --- /dev/null +++ b/docs/examples/Paint_108.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=424741e26e1b174e43087d67422ce14f +REG_FIDDLE(Paint_108, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + for (SkScalar textSize : { 12, 18, 24, 32 } ) { + paint.setTextSize(textSize); + SkDebugf("textSize: %g fontSpacing: %g\n", textSize, paint.getFontSpacing()); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_109.cpp b/docs/examples/Paint_109.cpp new file mode 100644 index 0000000000..c3edc2518c --- /dev/null +++ b/docs/examples/Paint_109.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=d11136d8a74f63009da2a7f550710823 +REG_FIDDLE(Paint_109, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 }; + std::vector glyphs; + int count = paint.textToGlyphs(utf8, sizeof(utf8), nullptr); + glyphs.resize(count); + (void) paint.textToGlyphs(utf8, sizeof(utf8), &glyphs.front()); + paint.setTextEncoding(kGlyphID_SkTextEncoding); + paint.setTextSize(32); + canvas->drawText(&glyphs.front(), glyphs.size() * sizeof(SkGlyphID), 10, 40, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_110.cpp b/docs/examples/Paint_110.cpp new file mode 100644 index 0000000000..30a403af25 --- /dev/null +++ b/docs/examples/Paint_110.cpp @@ -0,0 +1,13 @@ +#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 "fiddle/examples.h" +// HASH=85436c71aab5410767fc688ab0573e09 +REG_FIDDLE(Paint_110, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 }; + SkDebugf("count = %d\n", paint.countText(utf8, sizeof(utf8))); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_111.cpp b/docs/examples/Paint_111.cpp new file mode 100644 index 0000000000..268417c85a --- /dev/null +++ b/docs/examples/Paint_111.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=6a68cb3c8b81a5976c81ee004f559247 +REG_FIDDLE(Paint_111, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + const uint16_t goodGlyph = 511; + const uint16_t zeroGlyph = 0; + const uint16_t badGlyph = 65535; // larger than glyph count in font + paint.setTextEncoding(kGlyphID_SkTextEncoding); + SkDebugf("0x%04x %c= has glyph\n", goodGlyph, + paint.containsText(&goodGlyph, 2) ? '=' : '!'); + SkDebugf("0x%04x %c= has glyph\n", zeroGlyph, + paint.containsText(&zeroGlyph, 2) ? '=' : '!'); + SkDebugf("0x%04x %c= has glyph\n", badGlyph, + paint.containsText(&badGlyph, 2) ? '=' : '!'); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_112.cpp b/docs/examples/Paint_112.cpp new file mode 100644 index 0000000000..a0e1bc4c63 --- /dev/null +++ b/docs/examples/Paint_112.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=06084f609184470135a9cd9ebc5af149 +REG_FIDDLE(Paint_112, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(50); + const char str[] = "ay^jZ"; + const int count = sizeof(str) - 1; + canvas->drawText(str, count, 25, 50, paint); + SkRect bounds; + paint.measureText(str, count, &bounds); + canvas->translate(25, 50); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRect(bounds, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_113.cpp b/docs/examples/Paint_113.cpp new file mode 100644 index 0000000000..fc66e259c9 --- /dev/null +++ b/docs/examples/Paint_113.cpp @@ -0,0 +1,14 @@ +#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 "fiddle/examples.h" +// HASH=f1139a5ddd17fd47c2f45f6e642cac76 +REG_FIDDLE(Paint_113, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkDebugf("default width = %g\n", paint.measureText("!", 1)); + paint.setTextSize(paint.getTextSize() * 2); + SkDebugf("double width = %g\n", paint.measureText("!", 1)); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_114.cpp b/docs/examples/Paint_114.cpp new file mode 100644 index 0000000000..7decce9dc9 --- /dev/null +++ b/docs/examples/Paint_114.cpp @@ -0,0 +1,37 @@ +#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 "fiddle/examples.h" +// HASH=6b9e101f49e9c2c28755c5bdcef64dfb +REG_FIDDLE(Paint_114, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(50); + const char str[] = "abc"; + const int bytes = sizeof(str) - 1; + int count = paint.getTextWidths(str, bytes, nullptr); + std::vector widths; + std::vector bounds; + widths.resize(count); + bounds.resize(count); + for (int loop = 0; loop < 2; ++loop) { + (void) paint.getTextWidths(str, count, &widths.front(), &bounds.front()); + SkPoint loc = { 25, 50 }; + canvas->drawText(str, bytes, loc.fX, loc.fY, paint); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(0); + SkScalar advanceY = loc.fY + 10; + for (int index = 0; index < count; ++index) { + bounds[index].offset(loc.fX, loc.fY); + canvas->drawRect(bounds[index], paint); + canvas->drawLine(loc.fX, advanceY, loc.fX + widths[index], advanceY, paint); + loc.fX += widths[index]; + advanceY += 5; + } + canvas->translate(0, 80); + paint.setStrokeWidth(3); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_115.cpp b/docs/examples/Paint_115.cpp new file mode 100644 index 0000000000..40d8309ea8 --- /dev/null +++ b/docs/examples/Paint_115.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=7c9e6a399f898d68026c1f0865e6f73e +REG_FIDDLE(Paint_115, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(80); + SkPath path, path2; + paint.getTextPath("ABC", 3, 20, 80, &path); + path.offset(20, 20, &path2); + Op(path, path2, SkPathOp::kDifference_SkPathOp, &path); + path.addPath(path2); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPath(path, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_116.cpp b/docs/examples/Paint_116.cpp new file mode 100644 index 0000000000..c785834afa --- /dev/null +++ b/docs/examples/Paint_116.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=7f27c93472aa99a7542fb3493076f072 +REG_FIDDLE(Paint_116, 256, 85, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(80); + SkPath path, path2; + SkPoint pos[] = {{20, 60}, {30, 70}, {40, 80}}; + paint.getPosTextPath("ABC", 3, pos, &path); + Simplify(path, &path); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPath(path, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Paint_117.cpp b/docs/examples/Paint_117.cpp new file mode 100644 index 0000000000..8ee183c6c7 --- /dev/null +++ b/docs/examples/Paint_117.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=2973b05bfbb6b4c29332c8ac4fcf3995 +REG_FIDDLE(Paint_117, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPaint& p) -> void { + SkDebugf("%s nothing to draw: %s\n", prefix, + p.nothingToDraw() ? "true" : "false"); + }; + SkPaint paint; + debugster("initial", paint); + paint.setBlendMode(SkBlendMode::kDst); + debugster("blend dst", paint); + paint.setBlendMode(SkBlendMode::kSrcOver); + debugster("blend src over", paint); + paint.setAlpha(0); + debugster("alpha 0", paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_000.cpp b/docs/examples/Path_000.cpp new file mode 100644 index 0000000000..e102b7eb37 --- /dev/null +++ b/docs/examples/Path_000.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=799096fdc1298aa815934a74e76570ca +REG_FIDDLE(Path_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.lineTo(20, 20); + path.quadTo(-10, -10, 30, 30); + path.close(); + path.cubicTo(1, 2, 3, 4, 5, 6); + path.conicTo(0, 0, 0, 0, 2); + uint8_t verbs[7]; + int count = path.getVerbs(verbs, (int) SK_ARRAY_COUNT(verbs)); + const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close" }; + SkDebugf("verb count: %d\nverbs: ", count); + for (int i = 0; i < count; ++i) { + SkDebugf("k%s_Verb ", verbStr[verbs[i]]); + } + SkDebugf("\n"); +} +} // END FIDDLE diff --git a/docs/examples/Path_001.cpp b/docs/examples/Path_001.cpp new file mode 100644 index 0000000000..5d6ccba286 --- /dev/null +++ b/docs/examples/Path_001.cpp @@ -0,0 +1,32 @@ +#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 "fiddle/examples.h" +// HASH=4bbae00b40ed2cfcd0007921ad693a7b +REG_FIDDLE(Path_001, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + const SkPoint arrow[] = { {40, -5}, {45, 0}, {40, 5} }; + const SkRect rect = {10, 10, 90, 90}; + SkPaint rectPaint; + rectPaint.setAntiAlias(true); + SkPaint textPaint(rectPaint); + rectPaint.setStyle(SkPaint::kStroke_Style); + SkPaint arrowPaint(rectPaint); + SkPath arrowPath; + arrowPath.addPoly(arrow, SK_ARRAY_COUNT(arrow), true); + arrowPaint.setPathEffect(SkPath1DPathEffect::Make(arrowPath, 320, 0, + SkPath1DPathEffect::kRotate_Style)); + for (auto direction : { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { + canvas->drawRect(rect, rectPaint); + for (unsigned start : { 0, 1, 2, 3 } ) { + SkPath path; + path.addRect(rect, direction, start); + canvas->drawPath(path, arrowPaint); + } + canvas->drawString(SkPath::kCW_Direction == direction ? "CW" : "CCW", rect.centerX(), + rect.centerY(), textPaint); + canvas->translate(120, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_002.cpp b/docs/examples/Path_002.cpp new file mode 100644 index 0000000000..42465d12eb --- /dev/null +++ b/docs/examples/Path_002.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=0a0026fca638d1cd75c0ab884e3ee1c6 +REG_FIDDLE(Path_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + SkDebugf("path is " "%s" "empty", path.isEmpty() ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Path_003.cpp b/docs/examples/Path_003.cpp new file mode 100644 index 0000000000..cd0a5c4dc6 --- /dev/null +++ b/docs/examples/Path_003.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=647312aacd946c8a6eabaca797140432 +REG_FIDDLE(Path_003, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.lineTo(20, 20); + SkPath path2(path); + path2.close(); + SkDebugf("path verbs: %d\n", path.countVerbs()); + SkDebugf("path2 verbs: %d\n", path2.countVerbs()); + path.reset(); + SkDebugf("after reset\n" "path verbs: %d\n", path.countVerbs()); + SkDebugf("path2 verbs: %d\n", path2.countVerbs()); +} +} // END FIDDLE diff --git a/docs/examples/Path_004.cpp b/docs/examples/Path_004.cpp new file mode 100644 index 0000000000..e4593515c9 --- /dev/null +++ b/docs/examples/Path_004.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=01ad6be9b7d15a2217daea273eb3d466 +REG_FIDDLE(Path_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath* path = new SkPath(); + path->lineTo(20, 20); + SkPath path2(*path); + delete path; + SkDebugf("path2 is " "%s" "empty", path2.isEmpty() ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Path_005.cpp b/docs/examples/Path_005.cpp new file mode 100644 index 0000000000..0b25b5d0ba --- /dev/null +++ b/docs/examples/Path_005.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=bba288f5f77fc8e37e89d2ec08e0ac60 +REG_FIDDLE(Path_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path1; + path1.addRect({10, 20, 30, 40}); + SkPath path2 = path1; + const SkRect& b1 = path1.getBounds(); + SkDebugf("path1 bounds = %g, %g, %g, %g\n", b1.fLeft, b1.fTop, b1.fRight, b1.fBottom); + const SkRect& b2 = path2.getBounds(); + SkDebugf("path2 bounds = %g, %g, %g, %g\n", b2.fLeft, b2.fTop, b2.fRight, b2.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Path_006.cpp b/docs/examples/Path_006.cpp new file mode 100644 index 0000000000..f1f5eb0c76 --- /dev/null +++ b/docs/examples/Path_006.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=31883f51bb357f2ac5990d88f8b82e02 +REG_FIDDLE(Path_006, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& a, const SkPath& b) -> void { + SkDebugf("%s one %c= two\n", prefix, a == b ? '=' : '!'); + }; + SkPath one; + SkPath two; + debugster("empty", one, two); + one.moveTo(0, 0); + debugster("moveTo", one, two); + one.rewind(); + debugster("rewind", one, two); + one.moveTo(0, 0); + one.reset(); + debugster("reset", one, two); +} +} // END FIDDLE diff --git a/docs/examples/Path_007.cpp b/docs/examples/Path_007.cpp new file mode 100644 index 0000000000..26ac1ccd5b --- /dev/null +++ b/docs/examples/Path_007.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=bbbda1cc818d96c9c0d2a06c0c48902b +REG_FIDDLE(Path_007, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& a, const SkPath& b) -> void { + SkDebugf("%s one %c= two\n", prefix, a != b ? '!' : '='); + }; + SkPath one; + SkPath two; + debugster("empty", one, two); + one.addRect({10, 20, 30, 40}); + two.addRect({10, 20, 30, 40}); + debugster("add rect", one, two); + one.setConvexity(SkPath::kConcave_Convexity); + debugster("setConvexity", one, two); + SkDebugf("convexity %c=\n", one.getConvexity() == two.getConvexity() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Path_008.cpp b/docs/examples/Path_008.cpp new file mode 100644 index 0000000000..131d862971 --- /dev/null +++ b/docs/examples/Path_008.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=c81fc7dfaf785c3fb77209c7f2ebe5b8 +REG_FIDDLE(Path_008, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path, path2; + path.moveTo(20, 20); + path.lineTo(40, 40); + path.lineTo(20, 20); + path.lineTo(40, 40); + path.close(); + path2.addRect({20, 20, 40, 40}); + SkDebugf("paths are " "%s" "interpolatable", path.isInterpolatable(path2) ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Path_009.cpp b/docs/examples/Path_009.cpp new file mode 100644 index 0000000000..7bfc18c7f6 --- /dev/null +++ b/docs/examples/Path_009.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=404f11c5c9c9ca8a64822d484552a473 +REG_FIDDLE(Path_009, 256, 60, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPath path, path2; + path.moveTo(20, 20); + path.lineTo(40, 40); + path.lineTo(20, 40); + path.lineTo(40, 20); + path.close(); + path2.addRect({20, 20, 40, 40}); + for (SkScalar i = 0; i <= 1; i += 1.f / 6) { + SkPath interp; + path.interpolate(path2, i, &interp); + canvas->drawPath(interp, paint); + canvas->translate(30, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_010.cpp b/docs/examples/Path_010.cpp new file mode 100644 index 0000000000..963e10a51c --- /dev/null +++ b/docs/examples/Path_010.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=71fc6c069c377d808799f2453edabaf5 +REG_FIDDLE(Path_010, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.addRect({10, 10, 30, 30}, SkPath::kCW_Direction); + path.addRect({20, 20, 40, 40}, SkPath::kCW_Direction); + path.addRect({10, 60, 30, 80}, SkPath::kCW_Direction); + path.addRect({20, 70, 40, 90}, SkPath::kCCW_Direction); + SkPaint strokePaint; + strokePaint.setStyle(SkPaint::kStroke_Style); + SkRect clipRect = {0, 0, 51, 100}; + canvas->drawPath(path, strokePaint); + SkPaint fillPaint; + for (auto fillType : { SkPath::kWinding_FillType, SkPath::kEvenOdd_FillType, + SkPath::kInverseWinding_FillType, SkPath::kInverseEvenOdd_FillType } ) { + canvas->translate(51, 0); + canvas->save(); + canvas->clipRect(clipRect); + path.setFillType(fillType); + canvas->drawPath(path, fillPaint); + canvas->restore(); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_011.cpp b/docs/examples/Path_011.cpp new file mode 100644 index 0000000000..59afb760e2 --- /dev/null +++ b/docs/examples/Path_011.cpp @@ -0,0 +1,37 @@ +#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 "fiddle/examples.h" +// HASH=d2c33dc791cd165dcc2423226ba5b095 +REG_FIDDLE(Path_011, 256, 230, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.addRect({20, 10, 80, 70}, SkPath::kCW_Direction); + path.addRect({40, 30, 100, 90}, SkPath::kCW_Direction); + SkPaint strokePaint; + strokePaint.setStyle(SkPaint::kStroke_Style); + SkRect clipRect = {0, 0, 128, 128}; + canvas->drawPath(path, strokePaint); + canvas->drawLine({0, 50}, {120, 50}, strokePaint); + SkPaint textPaint; + textPaint.setAntiAlias(true); + SkScalar textHPos[] = { 10, 30, 60, 90, 110 }; + canvas->drawPosTextH("01210", 5, textHPos, 48, textPaint); + textPaint.setTextSize(18); + canvas->translate(0, 128); + canvas->scale(.5f, .5f); + canvas->drawString("inverse", 384, 150, textPaint); + SkPaint fillPaint; + for (auto fillType : { SkPath::kWinding_FillType, SkPath::kEvenOdd_FillType, + SkPath::kInverseWinding_FillType, SkPath::kInverseEvenOdd_FillType } ) { + canvas->save(); + canvas->clipRect(clipRect); + path.setFillType(fillType); + canvas->drawPath(path, fillPaint); + canvas->restore(); + canvas->drawString(fillType & 1 ? "even-odd" : "winding", 64, 170, textPaint); + canvas->translate(128, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_012.cpp b/docs/examples/Path_012.cpp new file mode 100644 index 0000000000..6c46a6e491 --- /dev/null +++ b/docs/examples/Path_012.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=019af90e778914e8a109d6305ede4fc4 +REG_FIDDLE(Path_012, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + SkDebugf("default path fill type is %s\n", + path.getFillType() == SkPath::kWinding_FillType ? "kWinding_FillType" : + path.getFillType() == SkPath::kEvenOdd_FillType ? "kEvenOdd_FillType" : + path.getFillType() == SkPath::kInverseWinding_FillType ? "kInverseWinding_FillType" : + "kInverseEvenOdd_FillType"); +} +} // END FIDDLE diff --git a/docs/examples/Path_013.cpp b/docs/examples/Path_013.cpp new file mode 100644 index 0000000000..479ff7da84 --- /dev/null +++ b/docs/examples/Path_013.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=b4a91cd7f50b2a0a0d1bec6d0ac823d2 +REG_FIDDLE(Path_013, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.setFillType(SkPath::kInverseWinding_FillType); + SkPaint paint; + paint.setColor(SK_ColorBLUE); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_014.cpp b/docs/examples/Path_014.cpp new file mode 100644 index 0000000000..a41364f7ae --- /dev/null +++ b/docs/examples/Path_014.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=2a2d39f5da611545caa18bbcea873ab2 +REG_FIDDLE(Path_014, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + SkDebugf("default path fill type is inverse: %s\n", + path.isInverseFillType() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Path_015.cpp b/docs/examples/Path_015.cpp new file mode 100644 index 0000000000..7868d40a0b --- /dev/null +++ b/docs/examples/Path_015.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=400facce23d417bc5043c5f58404afbd +REG_FIDDLE(Path_015, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + SkPaint paint; + paint.setColor(SK_ColorRED); + paint.setTextSize(80); + paint.getTextPath("ABC", 3, 20, 80, &path); + canvas->drawPath(path, paint); + path.toggleInverseFillType(); + paint.setColor(SK_ColorGREEN); + canvas->drawPath(path, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_016.cpp b/docs/examples/Path_016.cpp new file mode 100644 index 0000000000..67f9ae20f8 --- /dev/null +++ b/docs/examples/Path_016.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=ac49e8b810bd6ed5d84b4f5a3b40a0ec +REG_FIDDLE(Path_016, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPoint quad[] = {{70, 70}, {20, 20}, {120, 20}, {120, 120}}; + const char* labels[] = { "unknown", "convex", "concave" }; + for (SkScalar x : { 40, 100 } ) { + SkPath path; + quad[0].fX = x; + path.addPoly(quad, SK_ARRAY_COUNT(quad), true); + canvas->drawPath(path, paint); + canvas->drawString(labels[(int) path.getConvexity()], 30, 100, paint); + canvas->translate(100, 100); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_017.cpp b/docs/examples/Path_017.cpp new file mode 100644 index 0000000000..08d822bb6b --- /dev/null +++ b/docs/examples/Path_017.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=a8f36f2fa90003e3691fd0da0bb0c243 +REG_FIDDLE(Path_017, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + SkDebugf("%s path convexity is %s\n", prefix, + SkPath::kUnknown_Convexity == path.getConvexity() ? "unknown" : + SkPath::kConvex_Convexity == path.getConvexity() ? "convex" : "concave"); }; + SkPath path; + debugster("initial", path); + path.lineTo(50, 0); + debugster("first line", path); + path.lineTo(50, 50); + debugster("second line", path); + path.lineTo(100, 50); + debugster("third line", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_018.cpp b/docs/examples/Path_018.cpp new file mode 100644 index 0000000000..a71df2c6cd --- /dev/null +++ b/docs/examples/Path_018.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=111c59e9afadb940ab8f41bdc25378a4 +REG_FIDDLE(Path_018, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + SkDebugf("%s path convexity is %s\n", prefix, + SkPath::kUnknown_Convexity == path.getConvexityOrUnknown() ? "unknown" : + SkPath::kConvex_Convexity == path.getConvexityOrUnknown() ? "convex" : "concave"); }; + SkPath path; + debugster("initial", path); + path.lineTo(50, 0); + debugster("first line", path); + path.getConvexity(); + path.lineTo(50, 50); + debugster("second line", path); + path.lineTo(100, 50); + path.getConvexity(); + debugster("third line", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_019.cpp b/docs/examples/Path_019.cpp new file mode 100644 index 0000000000..8972bb280d --- /dev/null +++ b/docs/examples/Path_019.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=875e32b4b1cb48d739325705fc0fa42c +REG_FIDDLE(Path_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + SkDebugf("%s path convexity is %s\n", prefix, + SkPath::kUnknown_Convexity == path.getConvexity() ? "unknown" : + SkPath::kConvex_Convexity == path.getConvexity() ? "convex" : "concave"); }; + SkPoint quad[] = {{70, 70}, {20, 20}, {120, 20}, {120, 120}}; + SkPath path; + path.addPoly(quad, SK_ARRAY_COUNT(quad), true); + debugster("initial", path); + path.setConvexity(SkPath::kConcave_Convexity); + debugster("after forcing concave", path); + path.setConvexity(SkPath::kUnknown_Convexity); + debugster("after forcing unknown", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_020.cpp b/docs/examples/Path_020.cpp new file mode 100644 index 0000000000..a8b1058961 --- /dev/null +++ b/docs/examples/Path_020.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=d8be8b6e59de244e4cbf58ec9554557b +REG_FIDDLE(Path_020, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPoint quad[] = {{70, 70}, {20, 20}, {120, 20}, {120, 120}}; + for (SkScalar x : { 40, 100 } ) { + SkPath path; + quad[0].fX = x; + path.addPoly(quad, SK_ARRAY_COUNT(quad), true); + path.setConvexity(SkPath::kConvex_Convexity); + canvas->drawPath(path, paint); + canvas->drawString(path.isConvex() ? "convex" : "not convex", 30, 100, paint); + canvas->translate(100, 100); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_021.cpp b/docs/examples/Path_021.cpp new file mode 100644 index 0000000000..f813a4cc5b --- /dev/null +++ b/docs/examples/Path_021.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=a51256952b183ee0f7004f2c87cbbf5b +REG_FIDDLE(Path_021, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPath path; + path.addOval({20, 20, 220, 220}); + SkRect bounds; + if (path.isOval(&bounds)) { + paint.setColor(0xFF9FBFFF); + canvas->drawRect(bounds, paint); + } + paint.setColor(0x3f000000); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_022.cpp b/docs/examples/Path_022.cpp new file mode 100644 index 0000000000..a26864e277 --- /dev/null +++ b/docs/examples/Path_022.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=2aa939b90d96aff436b145a96305132c +REG_FIDDLE(Path_022, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPath path; + path.addRRect(SkRRect::MakeRectXY({20, 20, 220, 220}, 30, 50)); + SkRRect rrect; + if (path.isRRect(&rrect)) { + const SkRect& bounds = rrect.rect(); + paint.setColor(0xFF9FBFFF); + canvas->drawRect(bounds, paint); + } + paint.setColor(0x3f000000); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_023.cpp b/docs/examples/Path_023.cpp new file mode 100644 index 0000000000..668bd7059b --- /dev/null +++ b/docs/examples/Path_023.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=8cdca35d2964bbbecb93d79a13f71c65 +REG_FIDDLE(Path_023, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path1, path2; + path1.setFillType(SkPath::kInverseWinding_FillType); + path1.addRect({10, 20, 30, 40}); + SkDebugf("path1 %c= path2\n", path1 == path2 ? '=' : '!'); + path1.reset(); + SkDebugf("path1 %c= path2\n", path1 == path2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Path_024.cpp b/docs/examples/Path_024.cpp new file mode 100644 index 0000000000..34e3c17861 --- /dev/null +++ b/docs/examples/Path_024.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=f1fedbb89da9c2a33a91805175663012 +REG_FIDDLE(Path_024, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path1, path2; + path1.setFillType(SkPath::kInverseWinding_FillType); + path1.addRect({10, 20, 30, 40}); + SkDebugf("path1 %c= path2\n", path1 == path2 ? '=' : '!'); + path1.rewind(); + SkDebugf("path1 %c= path2\n", path1 == path2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Path_025.cpp b/docs/examples/Path_025.cpp new file mode 100644 index 0000000000..340f263a76 --- /dev/null +++ b/docs/examples/Path_025.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=0b34e6d55d11586744adeb889d2a12f4 +REG_FIDDLE(Path_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + SkDebugf("%s path is %s" "empty\n", prefix, path.isEmpty() ? "" : "not "); + }; + SkPath path; + debugster("initial", path); + path.moveTo(0, 0); + debugster("after moveTo", path); + path.rewind(); + debugster("after rewind", path); + path.lineTo(0, 0); + debugster("after lineTo", path); + path.reset(); + debugster("after reset", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_026.cpp b/docs/examples/Path_026.cpp new file mode 100644 index 0000000000..32c6b28036 --- /dev/null +++ b/docs/examples/Path_026.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=03b740ab94b9017800a52e30b5e7fee7 +REG_FIDDLE(Path_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + SkDebugf("%s last contour is %s" "closed\n", prefix, + path.isLastContourClosed() ? "" : "not "); + }; + SkPath path; + debugster("initial", path); + path.close(); + debugster("after close", path); + path.lineTo(0, 0); + debugster("after lineTo", path); + path.close(); + debugster("after close", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_027.cpp b/docs/examples/Path_027.cpp new file mode 100644 index 0000000000..a5430b1827 --- /dev/null +++ b/docs/examples/Path_027.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=dd4e4dd2aaa8039b2430729c6b3af817 +REG_FIDDLE(Path_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + SkDebugf("%s path is %s" "finite\n", prefix, path.isFinite() ? "" : "not "); + }; + SkPath path; + debugster("initial", path); + path.lineTo(SK_ScalarMax, SK_ScalarMax); + debugster("after line", path); + SkMatrix matrix; + matrix.setScale(2, 2); + path.transform(matrix); + debugster("after scale", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_028.cpp b/docs/examples/Path_028.cpp new file mode 100644 index 0000000000..3290dffbed --- /dev/null +++ b/docs/examples/Path_028.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=c722ebe8ac991d77757799ce29e509e1 +REG_FIDDLE(Path_028, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + SkDebugf("volatile by default is %s\n", path.isVolatile() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Path_029.cpp b/docs/examples/Path_029.cpp new file mode 100644 index 0000000000..b33b5ee9fb --- /dev/null +++ b/docs/examples/Path_029.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=2049ff5141f0c80aac497618622b28af +REG_FIDDLE(Path_029, 50, 50, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + SkPath path; + path.setIsVolatile(true); + path.lineTo(40, 40); + canvas->drawPath(path, paint); + path.rewind(); + path.moveTo(0, 40); + path.lineTo(40, 0); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_030.cpp b/docs/examples/Path_030.cpp new file mode 100644 index 0000000000..b8db09d370 --- /dev/null +++ b/docs/examples/Path_030.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=97a031f9186ade586928563840ce9116 +REG_FIDDLE(Path_030, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint points[] = { {100, 100}, {100.000001f, 100.000001f}, {100.0001f, 100.0001f} }; + for (size_t i = 0; i < SK_ARRAY_COUNT(points) - 1; ++i) { + for (bool exact : { false, true } ) { + SkDebugf("line from (%1.8g,%1.8g) to (%1.8g,%1.8g) is %s" "degenerate, %s\n", + points[i].fX, points[i].fY, points[i + 1].fX, points[i + 1].fY, + SkPath::IsLineDegenerate(points[i], points[i + 1], exact) + ? "" : "not ", exact ? "exactly" : "nearly"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Path_031.cpp b/docs/examples/Path_031.cpp new file mode 100644 index 0000000000..3902c48845 --- /dev/null +++ b/docs/examples/Path_031.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=a2b255a7dac1926cc3a247d318d63c62 +REG_FIDDLE(Path_031, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const SkPath& path, bool exact) -> void { + SkDebugf("quad (%1.8g,%1.8g), (%1.8g,%1.8g), (%1.8g,%1.8g) is %s" "degenerate, %s\n", + path.getPoint(0).fX, path.getPoint(0).fY, path.getPoint(1).fX, + path.getPoint(1).fY, path.getPoint(2).fX, path.getPoint(2).fY, + SkPath::IsQuadDegenerate(path.getPoint(0), path.getPoint(1), path.getPoint(2), exact) ? + "" : "not ", exact ? "exactly" : "nearly"); + }; + SkPath path, offset; + path.moveTo({100, 100}); + path.quadTo({100.00001f, 100.00001f}, {100.00002f, 100.00002f}); + offset.addPath(path, 1000, 1000); + for (bool exact : { false, true } ) { + debugster(path, exact); + debugster(offset, exact); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_032.cpp b/docs/examples/Path_032.cpp new file mode 100644 index 0000000000..48576060ae --- /dev/null +++ b/docs/examples/Path_032.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=6b97099acdae80b16df0c4241f593991 +REG_FIDDLE(Path_032, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint points[] = {{1, 0}, {0, 0}, {0, 0}, {0, 0}}; + SkScalar step = 1; + SkScalar prior, length = 0, degenerate = 0; + do { + prior = points[0].fX; + step /= 2; + if (SkPath::IsCubicDegenerate(points[0], points[1], points[2], points[3], false)) { + degenerate = prior; + points[0].fX += step; + } else { + length = prior; + points[0].fX -= step; + } + } while (prior != points[0].fX); + SkDebugf("%1.8g is degenerate\n", degenerate); + SkDebugf("%1.8g is length\n", length); +} +} // END FIDDLE diff --git a/docs/examples/Path_033.cpp b/docs/examples/Path_033.cpp new file mode 100644 index 0000000000..cdc10500b1 --- /dev/null +++ b/docs/examples/Path_033.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=1ad07d56e4258e041606d50cad969392 +REG_FIDDLE(Path_033, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + SkPoint line[2]; + if (path.isLine(line)) { + SkDebugf("%s is line (%1.8g,%1.8g) (%1.8g,%1.8g)\n", prefix, + line[0].fX, line[0].fY, line[1].fX, line[1].fY); + } else { + SkDebugf("%s is not line\n", prefix); + } + }; + SkPath path; + debugster("empty", path); + path.lineTo(0, 0); + debugster("zero line", path); + path.rewind(); + path.moveTo(10, 10); + path.lineTo(20, 20); + debugster("line", path); + path.moveTo(20, 20); + debugster("second move", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_034.cpp b/docs/examples/Path_034.cpp new file mode 100644 index 0000000000..02f5e32324 --- /dev/null +++ b/docs/examples/Path_034.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=9bc86efda08cbcd9c6f7c5f220294a24 +REG_FIDDLE(Path_034, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path, SkPoint* points, int max) -> void { + int count = path.getPoints(points, max); + SkDebugf("%s point count: %d ", prefix, count); + for (int i = 0; i < SkTMin(count, max) && points; ++i) { + SkDebugf("(%1.8g,%1.8g) ", points[i].fX, points[i].fY); + } + SkDebugf("\n"); + }; + SkPath path; + path.lineTo(20, 20); + path.lineTo(-10, -10); + SkPoint points[3]; + debugster("no points", path, nullptr, 0); + debugster("zero max", path, points, 0); + debugster("too small", path, points, 2); + debugster("just right", path, points, path.countPoints()); +} +} // END FIDDLE diff --git a/docs/examples/Path_035.cpp b/docs/examples/Path_035.cpp new file mode 100644 index 0000000000..d2c1922bc9 --- /dev/null +++ b/docs/examples/Path_035.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=bca6379ccef62cb081b10db7381deb27 +REG_FIDDLE(Path_035, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + SkDebugf("%s point count: %d\n", prefix, path.countPoints()); + }; + SkPath path; + debugster("empty", path); + path.lineTo(0, 0); + debugster("zero line", path); + path.rewind(); + path.moveTo(10, 10); + path.lineTo(20, 20); + debugster("line", path); + path.moveTo(20, 20); + debugster("second move", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_036.cpp b/docs/examples/Path_036.cpp new file mode 100644 index 0000000000..fcfb91bd30 --- /dev/null +++ b/docs/examples/Path_036.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=42885f1df13de109adccc5d531f62111 +REG_FIDDLE(Path_036, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.lineTo(20, 20); + path.offset(-10, -10); + for (int i= 0; i < path.countPoints(); ++i) { + SkDebugf("point %d: (%1.8g,%1.8g)\n", i, path.getPoint(i).fX, path.getPoint(i).fY); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_037.cpp b/docs/examples/Path_037.cpp new file mode 100644 index 0000000000..5797182af0 --- /dev/null +++ b/docs/examples/Path_037.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=af0c66aea3ef81b709664c7007f48aae +REG_FIDDLE(Path_037, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + SkDebugf("empty verb count: %d\n", path.countVerbs()); + path.addRoundRect({10, 20, 30, 40}, 5, 5); + SkDebugf("round rect verb count: %d\n", path.countVerbs()); +} +} // END FIDDLE diff --git a/docs/examples/Path_038.cpp b/docs/examples/Path_038.cpp new file mode 100644 index 0000000000..50ff065a65 --- /dev/null +++ b/docs/examples/Path_038.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=2ec66880966a6133ddd9331ce7323438 +REG_FIDDLE(Path_038, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path, uint8_t* verbs, int max) -> void { + int count = path.getVerbs(verbs, max); + SkDebugf("%s verb count: %d ", prefix, count); + const char* verbStr[] = { "move", "line", "quad", "conic", "cubic", "close" }; + for (int i = 0; i < SkTMin(count, max) && verbs; ++i) { + SkDebugf("%s ", verbStr[verbs[i]]); + } + SkDebugf("\n"); + }; + SkPath path; + path.lineTo(20, 20); + path.lineTo(-10, -10); + uint8_t verbs[3]; + debugster("no verbs", path, nullptr, 0); + debugster("zero max", path, verbs, 0); + debugster("too small", path, verbs, 2); + debugster("just right", path, verbs, path.countVerbs()); +} +} // END FIDDLE diff --git a/docs/examples/Path_039.cpp b/docs/examples/Path_039.cpp new file mode 100644 index 0000000000..f411f5cb6b --- /dev/null +++ b/docs/examples/Path_039.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=4c5ebee2b5039e5faefa07ae63a15467 +REG_FIDDLE(Path_039, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path1, path2; + path1.addRect({10, 20, 30, 40}); + path1.swap(path2); + const SkRect& b1 = path1.getBounds(); + SkDebugf("path1 bounds = %g, %g, %g, %g\n", b1.fLeft, b1.fTop, b1.fRight, b1.fBottom); + const SkRect& b2 = path2.getBounds(); + SkDebugf("path2 bounds = %g, %g, %g, %g\n", b2.fLeft, b2.fTop, b2.fRight, b2.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Path_040.cpp b/docs/examples/Path_040.cpp new file mode 100644 index 0000000000..0581e81a6c --- /dev/null +++ b/docs/examples/Path_040.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=45c0fc3acb74fab99d544b80eadd10ad +REG_FIDDLE(Path_040, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + const SkRect& bounds = path.getBounds(); + SkDebugf("%s bounds = %g, %g, %g, %g\n", prefix, + bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); + }; + SkPath path; + debugster("empty", path); + path.addCircle(50, 45, 25); + debugster("circle", path); + SkMatrix matrix; + matrix.setRotate(45, 50, 45); + path.transform(matrix); + debugster("rotated circle", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_041.cpp b/docs/examples/Path_041.cpp new file mode 100644 index 0000000000..707e7504df --- /dev/null +++ b/docs/examples/Path_041.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=bb761cd858e6d0ca05627262cd22ff5e +REG_FIDDLE(Path_041, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + double times[2] = { 0, 0 }; + int N = 100; + for (int i = 0; i < N; ++i) { + SkPath path; + for (int j = 1; j < 100; ++ j) { + path.addCircle(50 + j, 45 + j, 25 + j); + } + if (1 & i) { + path.updateBoundsCache(); + } + double start = SkTime::GetNSecs(); + (void) path.getBounds(); + times[1 & i] += SkTime::GetNSecs() - start; + } + SkDebugf("uncached avg: %g ms\n", times[0] / (double)N); + SkDebugf("cached avg: %g ms\n", times[1] / (double)N); +} +} // END FIDDLE diff --git a/docs/examples/Path_042.cpp b/docs/examples/Path_042.cpp new file mode 100644 index 0000000000..63a2e0036e --- /dev/null +++ b/docs/examples/Path_042.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=9a39c56e95b19a657133b7ad1fe0cf03 +REG_FIDDLE(Path_042, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + const SkRect& bounds = path.computeTightBounds(); + SkDebugf("%s bounds = %g, %g, %g, %g\n", prefix, + bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom); + }; + SkPath path; + debugster("empty", path); + path.addCircle(50, 45, 25); + debugster("circle", path); + SkMatrix matrix; + matrix.setRotate(45, 50, 45); + path.transform(matrix); + debugster("rotated circle", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_043.cpp b/docs/examples/Path_043.cpp new file mode 100644 index 0000000000..e17b38de13 --- /dev/null +++ b/docs/examples/Path_043.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=41638d13e40fa449ece354dde5fb1941 +REG_FIDDLE(Path_043, 256, 140, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.addRoundRect({10, 20, 54, 120}, 10, 20); + SkRect tests[] = { + { 10, 40, 54, 80 }, + { 25, 20, 39, 120 }, + { 15, 25, 49, 115 }, + { 13, 27, 51, 113 }, + }; + for (unsigned i = 0; i < SK_ARRAY_COUNT(tests); ++i) { + SkPaint paint; + paint.setColor(SK_ColorRED); + canvas->drawPath(path, paint); + bool rectInPath = path.conservativelyContainsRect(tests[i]); + paint.setColor(rectInPath ? SK_ColorBLUE : SK_ColorBLACK); + canvas->drawRect(tests[i], paint); + canvas->translate(64, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_044.cpp b/docs/examples/Path_044.cpp new file mode 100644 index 0000000000..0a09dc72b7 --- /dev/null +++ b/docs/examples/Path_044.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=f2260f2a170a54aef5bafe5b91c121b3 +REG_FIDDLE(Path_044, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + auto addPoly = [](int sides, SkScalar size, SkPath* path) -> void { + path->moveTo(size, 0); + for (int i = 1; i < sides; i++) { + SkScalar c, s = SkScalarSinCos(SK_ScalarPI * 2 * i / sides, &c); + path->lineTo(c * size, s * size); + } + path->close(); + }; + SkPath path; + path.incReserve(3 + 4 + 5 + 6 + 7 + 8 + 9); + for (int sides = 3; sides < 10; ++sides) { + addPoly(sides, sides, &path); + } + SkMatrix matrix; + matrix.setScale(10, 10, -10, -10); + path.transform(matrix); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_045.cpp b/docs/examples/Path_045.cpp new file mode 100644 index 0000000000..5abd258190 --- /dev/null +++ b/docs/examples/Path_045.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=84101d341e934a535a41ad6cf42218ce +REG_FIDDLE(Path_045, 140, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 20, 20, 120, 80 }; + SkPath path; + path.addRect(rect); + path.moveTo(rect.fLeft, rect.fTop); + path.lineTo(rect.fRight, rect.fBottom); + path.moveTo(rect.fLeft, rect.fBottom); + path.lineTo(rect.fRight, rect.fTop); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_046.cpp b/docs/examples/Path_046.cpp new file mode 100644 index 0000000000..8f442c4b7e --- /dev/null +++ b/docs/examples/Path_046.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=cb8d37990f6e7df3bcc85e7240c81274 +REG_FIDDLE(Path_046, 128, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPoint data[][3] = {{{30,40},{60,60},{90,30}}, {{30,120},{60,100},{90,120}}, + {{60,100},{60,40},{70,30}}, {{60,40},{50,20},{70,30}}}; + SkPath path; + for (unsigned i = 0; i < SK_ARRAY_COUNT(data); ++i) { + path.moveTo(data[i][0]); + path.lineTo(data[i][1]); + path.lineTo(data[i][2]); + } + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_047.cpp b/docs/examples/Path_047.cpp new file mode 100644 index 0000000000..5c2246a8c8 --- /dev/null +++ b/docs/examples/Path_047.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=63e32dec4b2d8440b427f368bf8313a4 +REG_FIDDLE(Path_047, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.addRect({20, 20, 80, 80}, SkPath::kCW_Direction, 2); + path.rMoveTo(25, 2); + SkVector arrow[] = {{0, -4}, {-20, 0}, {0, -3}, {-5, 5}, {5, 5}, {0, -3}, {20, 0}}; + for (unsigned i = 0; i < SK_ARRAY_COUNT(arrow); ++i) { + path.rLineTo(arrow[i].fX, arrow[i].fY); + } + SkPaint paint; + canvas->drawPath(path, paint); + SkPoint lastPt; + path.getLastPt(&lastPt); + canvas->drawString("start", lastPt.fX, lastPt.fY, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_048.cpp b/docs/examples/Path_048.cpp new file mode 100644 index 0000000000..d2313a4bf0 --- /dev/null +++ b/docs/examples/Path_048.cpp @@ -0,0 +1,27 @@ +#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 "fiddle/examples.h" +// HASH=e311cdd451edacec33b50cc22a4dd5dc +REG_FIDDLE(Path_048, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(72); + canvas->drawString("#", 120, 80, paint); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(5); + SkPath path; + SkPoint hash[] = {{58, 28}, {43, 80}, {37, 45}, {85, 45}}; + SkVector offsets[] = {{0, 0}, {17, 0}, {0, 0}, {-5, 17}}; + unsigned o = 0; + for (unsigned i = 0; i < SK_ARRAY_COUNT(hash); i += 2) { + for (unsigned j = 0; j < 2; o++, j++) { + path.moveTo(hash[i].fX + offsets[o].fX, hash[i].fY + offsets[o].fY); + path.lineTo(hash[i + 1].fX + offsets[o].fX, hash[i + 1].fY + offsets[o].fY); + } + } + canvas->drawPath(path, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_049.cpp b/docs/examples/Path_049.cpp new file mode 100644 index 0000000000..bb0617e62b --- /dev/null +++ b/docs/examples/Path_049.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=41001546a7f7927d08e5a818bcc304f5 +REG_FIDDLE(Path_049, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + SkVector oxo[] = {{25, 25}, {35, 35}, {25, 35}, {35, 25}, + {40, 20}, {40, 80}, {60, 20}, {60, 80}, + {20, 40}, {80, 40}, {20, 60}, {80, 60}}; + for (unsigned i = 0; i < SK_ARRAY_COUNT(oxo); i += 2) { + path.moveTo(oxo[i]); + path.lineTo(oxo[i + 1]); + } + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_050.cpp b/docs/examples/Path_050.cpp new file mode 100644 index 0000000000..24147a94f4 --- /dev/null +++ b/docs/examples/Path_050.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=6e0be0766b8ca320da51640326e608b3 +REG_FIDDLE(Path_050, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPath path; + path.moveTo(10, 98); + SkScalar x = 0, y = 0; + for (int i = 10; i < 100; i += 5) { + x += i * ((i & 2) - 1); + y += i * (((i + 1) & 2) - 1); + path.rLineTo(x, y); + } + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_051.cpp b/docs/examples/Path_051.cpp new file mode 100644 index 0000000000..1a111d41a2 --- /dev/null +++ b/docs/examples/Path_051.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=78ad51fa1cd33eb84a6f99061e56e067 +REG_FIDDLE(Path_051, 256, 110, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPoint quadPts[] = {{20, 90}, {120, 10}, {220, 90}}; + canvas->drawLine(quadPts[0], quadPts[1], paint); + canvas->drawLine(quadPts[1], quadPts[2], paint); + SkPath path; + path.moveTo(quadPts[0]); + path.quadTo(quadPts[1], quadPts[2]); + paint.setStrokeWidth(3); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_052.cpp b/docs/examples/Path_052.cpp new file mode 100644 index 0000000000..6032f31526 --- /dev/null +++ b/docs/examples/Path_052.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=4082f66a42df11bb20462b232b156bb6 +REG_FIDDLE(Path_052, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPoint quadPts[] = {{20, 150}, {120, 10}, {220, 150}}; + SkColor colors[] = { 0xff88ff00, 0xff0088bb, 0xff6600cc, 0xffbb3377 }; + for (unsigned i = 0; i < SK_ARRAY_COUNT(colors); ++i) { + paint.setColor(0x7fffffff & colors[i]); + paint.setStrokeWidth(1); + canvas->drawLine(quadPts[0], quadPts[1], paint); + canvas->drawLine(quadPts[1], quadPts[2], paint); + SkPath path; + path.moveTo(quadPts[0]); + path.quadTo(quadPts[1], quadPts[2]); + paint.setStrokeWidth(3); + paint.setColor(colors[i]); + canvas->drawPath(path, paint); + quadPts[1].fY += 30; + } +} +} // END FIDDLE diff --git a/docs/examples/Path_053.cpp b/docs/examples/Path_053.cpp new file mode 100644 index 0000000000..4f00bd4eb5 --- /dev/null +++ b/docs/examples/Path_053.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=60ee3eb747474f5781b0f0dd3a17a866 +REG_FIDDLE(Path_053, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPath path; + path.moveTo(0, -10); + for (int i = 0; i < 128; i += 16) { + path.quadTo( 10 + i, -10 - i, 10 + i, 0); + path.quadTo( 14 + i, 14 + i, 0, 14 + i); + path.quadTo(-18 - i, 18 + i, -18 - i, 0); + path.quadTo(-22 - i, -22 - i, 0, -22 - i); + } + path.offset(128, 128); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_054.cpp b/docs/examples/Path_054.cpp new file mode 100644 index 0000000000..877f96a2f5 --- /dev/null +++ b/docs/examples/Path_054.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=82621c4df8da1e589d9e627494067826 +REG_FIDDLE(Path_054, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setAntiAlias(true); + SkPath path; + SkPoint pts[] = {{128, 10}, {10, 214}, {236, 214}}; + path.moveTo(pts[1]); + for (int i = 0; i < 3; ++i) { + path.quadTo(pts[i % 3], pts[(i + 2) % 3]); + } + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_055.cpp b/docs/examples/Path_055.cpp new file mode 100644 index 0000000000..61e9c00fa7 --- /dev/null +++ b/docs/examples/Path_055.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=1c1f4cdef1c572c9aa8fdf3e461191d0 +REG_FIDDLE(Path_055, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPath path; + path.moveTo(128, 20); + path.rQuadTo(-6, 10, -7, 10); + for (int i = 1; i < 32; i += 4) { + path.rQuadTo(10 + i, 10 + i, 10 + i * 4, 10); + path.rQuadTo(-10 - i, 10 + i, -10 - (i + 2) * 4, 10); + } + path.quadTo(92, 220, 128, 215); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_056.cpp b/docs/examples/Path_056.cpp new file mode 100644 index 0000000000..8427f2638c --- /dev/null +++ b/docs/examples/Path_056.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=2aadded3d20dfef34d1c8abe28c7bc8d +REG_FIDDLE(Path_056, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* verbNames[] = { "move", "line", "quad", "conic", "cubic", "close", "done" }; + const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; + SkPath path; + path.conicTo(20, 30, 50, 60, 1); + SkPath::Iter iter(path, false); + SkPath::Verb verb; + do { + SkPoint points[4]; + verb = iter.next(points); + SkDebugf("%s ", verbNames[(int) verb]); + for (int i = 0; i < pointCount[(int) verb]; ++i) { + SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); + } + if (SkPath::kConic_Verb == verb) { + SkDebugf("weight = %g", iter.conicWeight()); + } + SkDebugf("\n"); + } while (SkPath::kDone_Verb != verb); +} +} // END FIDDLE diff --git a/docs/examples/Path_057.cpp b/docs/examples/Path_057.cpp new file mode 100644 index 0000000000..3beaf09ebb --- /dev/null +++ b/docs/examples/Path_057.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=e88f554efacfa9f75f270fb1c0add5b4 +REG_FIDDLE(Path_057, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* verbNames[] = { "move", "line", "quad", "conic", "cubic", "close", "done" }; + const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; + SkPath path; + path.arcTo(20, 0, 20, 20, 20); + SkPath::Iter iter(path, false); + SkPath::Verb verb; + do { + SkPoint points[4]; + verb = iter.next(points); + SkDebugf("%s ", verbNames[(int) verb]); + for (int i = 0; i < pointCount[(int) verb]; ++i) { + SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); + } + if (SkPath::kConic_Verb == verb) { + SkDebugf("weight = %g", iter.conicWeight()); + } + SkDebugf("\n"); + } while (SkPath::kDone_Verb != verb); +} +} // END FIDDLE diff --git a/docs/examples/Path_058.cpp b/docs/examples/Path_058.cpp new file mode 100644 index 0000000000..c1dc83cb8a --- /dev/null +++ b/docs/examples/Path_058.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=6fb11419e99297fe2fe666c296117fb9 +REG_FIDDLE(Path_058, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* verbNames[] = { "move", "line", "quad", "conic", "cubic", "close", "done" }; + const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; + SkPath path; + path.conicTo(20, 0, 20, 20, SK_ScalarInfinity); + SkPath::Iter iter(path, false); + SkPath::Verb verb; + do { + SkPoint points[4]; + verb = iter.next(points); + SkDebugf("%s ", verbNames[(int) verb]); + for (int i = 0; i < pointCount[(int) verb]; ++i) { + SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); + } + if (SkPath::kConic_Verb == verb) { + SkDebugf("weight = %g", iter.conicWeight()); + } + SkDebugf("\n"); + } while (SkPath::kDone_Verb != verb); +} +} // END FIDDLE diff --git a/docs/examples/Path_059.cpp b/docs/examples/Path_059.cpp new file mode 100644 index 0000000000..f1e94bccad --- /dev/null +++ b/docs/examples/Path_059.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=358d9b6060b528b0923c007420f09c13 +REG_FIDDLE(Path_059, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPoint conicPts[] = {{20, 150}, {120, 10}, {220, 150}}; + canvas->drawLine(conicPts[0], conicPts[1], paint); + canvas->drawLine(conicPts[1], conicPts[2], paint); + SkColor colors[] = { 0xff88ff00, 0xff0088bb, 0xff6600cc, 0xffbb3377 }; + paint.setStrokeWidth(3); + SkScalar weight = 0.5f; + for (unsigned i = 0; i < SK_ARRAY_COUNT(colors); ++i) { + SkPath path; + path.moveTo(conicPts[0]); + path.conicTo(conicPts[1], conicPts[2], weight); + paint.setColor(colors[i]); + canvas->drawPath(path, paint); + weight += 0.25f; + } +} +} // END FIDDLE diff --git a/docs/examples/Path_060.cpp b/docs/examples/Path_060.cpp new file mode 100644 index 0000000000..7651dcb0ff --- /dev/null +++ b/docs/examples/Path_060.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=22d25e03b19d5bae92118877e462361b +REG_FIDDLE(Path_060, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkRect oval = {0, 20, 120, 140}; + SkPath path; + for (int i = 0; i < 4; ++i) { + path.moveTo(oval.centerX(), oval.fTop); + path.arcTo(oval, -90, 90 - 20 * i, false); + oval.inset(15, 15); + } + path.offset(100, 0); + SkScalar conicWeights[] = { 0.707107f, 0.819152f, 0.906308f, 0.965926f }; + SkPoint conicPts[][3] = { { {40, 20}, {100, 20}, {100, 80} }, + { {40, 35}, {71.509f, 35}, {82.286f, 64.6091f} }, + { {40, 50}, {53.9892f, 50}, {62.981f, 60.7164f} }, + { {40, 65}, {44.0192f, 65}, {47.5f, 67.0096f} } }; + for (int i = 0; i < 4; ++i) { + path.moveTo(conicPts[i][0]); + path.conicTo(conicPts[i][1], conicPts[i][2], conicWeights[i]); + } + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_061.cpp b/docs/examples/Path_061.cpp new file mode 100644 index 0000000000..b82e36fac2 --- /dev/null +++ b/docs/examples/Path_061.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=3d52763e7c0e20c0b1d484a0afa622d2 +REG_FIDDLE(Path_061, 256, 140, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPath path; + path.moveTo(20, 80); + path.rConicTo( 60, 0, 60, 60, 0.707107f); + path.rConicTo( 0, -60, 60, -60, 0.707107f); + path.rConicTo(-60, 0, -60, -60, 0.707107f); + path.rConicTo( 0, 60, -60, 60, 0.707107f); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_062.cpp b/docs/examples/Path_062.cpp new file mode 100644 index 0000000000..8f8af80778 --- /dev/null +++ b/docs/examples/Path_062.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=466445ed991d86de08587066392d654a +REG_FIDDLE(Path_062, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPoint cubicPts[] = {{20, 150}, {90, 10}, {160, 150}, {230, 10}}; + SkColor colors[] = { 0xff88ff00, 0xff0088bb, 0xff6600cc, 0xffbb3377 }; + for (unsigned i = 0; i < SK_ARRAY_COUNT(colors); ++i) { + paint.setColor(0x7fffffff & colors[i]); + paint.setStrokeWidth(1); + for (unsigned j = 0; j < 3; ++j) { + canvas->drawLine(cubicPts[j], cubicPts[j + 1], paint); + } + SkPath path; + path.moveTo(cubicPts[0]); + path.cubicTo(cubicPts[1], cubicPts[2], cubicPts[3]); + paint.setStrokeWidth(3); + paint.setColor(colors[i]); + canvas->drawPath(path, paint); + cubicPts[1].fY += 30; + cubicPts[2].fX += 30; + } +} +} // END FIDDLE diff --git a/docs/examples/Path_063.cpp b/docs/examples/Path_063.cpp new file mode 100644 index 0000000000..bf44dc4576 --- /dev/null +++ b/docs/examples/Path_063.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=3e476378e3e0550ab134bbaf61112d98 +REG_FIDDLE(Path_063, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPath path; + path.moveTo(0, -10); + for (int i = 0; i < 128; i += 16) { + SkScalar c = i * 0.5f; + path.cubicTo( 10 + c, -10 - i, 10 + i, -10 - c, 10 + i, 0); + path.cubicTo( 14 + i, 14 + c, 14 + c, 14 + i, 0, 14 + i); + path.cubicTo(-18 - c, 18 + i, -18 - i, 18 + c, -18 - i, 0); + path.cubicTo(-22 - i, -22 - c, -22 - c, -22 - i, 0, -22 - i); + } + path.offset(128, 128); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_064.cpp b/docs/examples/Path_064.cpp new file mode 100644 index 0000000000..492f08b572 --- /dev/null +++ b/docs/examples/Path_064.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=d38aaf12c6ff5b8d901a2201bcee5476 +REG_FIDDLE(Path_064, 256, 84, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPoint pts[] = { {20, 20}, {300, 80}, {-140, 90}, {220, 10} }; + SkPath path; + path.moveTo(pts[0]); + path.cubicTo(pts[1], pts[2], pts[3]); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_065.cpp b/docs/examples/Path_065.cpp new file mode 100644 index 0000000000..ffef23c0bb --- /dev/null +++ b/docs/examples/Path_065.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=19f0cfc7eeba8937fe19446ec0b5f932 +REG_FIDDLE(Path_065, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkPath path; + path.moveTo(24, 108); + for (int i = 0; i < 16; i++) { + SkScalar sx, sy; + sx = SkScalarSinCos(i * SK_ScalarPI / 8, &sy); + path.rCubicTo(40 * sx, 4 * sy, 4 * sx, 40 * sy, 40 * sx, 40 * sy); + } + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_066.cpp b/docs/examples/Path_066.cpp new file mode 100644 index 0000000000..2b7b21a8d6 --- /dev/null +++ b/docs/examples/Path_066.cpp @@ -0,0 +1,47 @@ +#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 "fiddle/examples.h" +// HASH=5acc77eba0cb4d00bbf3a8f4db0c0aee +REG_FIDDLE(Path_066, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkRect oval = {8, 8, 56, 56}; + SkPaint ovalPaint; + ovalPaint.setAntiAlias(true); + SkPaint textPaint(ovalPaint); + ovalPaint.setStyle(SkPaint::kStroke_Style); + SkPaint arcPaint(ovalPaint); + arcPaint.setStrokeWidth(5); + arcPaint.setColor(SK_ColorBLUE); + canvas->translate(-64, 0); + for (char arcStyle = '1'; arcStyle <= '6'; ++arcStyle) { + '4' == arcStyle ? canvas->translate(-96, 55) : canvas->translate(64, 0); + canvas->drawText(&arcStyle, 1, 30, 36, textPaint); + canvas->drawOval(oval, ovalPaint); + SkPath path; + path.moveTo({56, 32}); + switch (arcStyle) { + case '1': + path.arcTo(oval, 0, 90, false); + break; + case '2': + canvas->drawArc(oval, 0, 90, false, arcPaint); + continue; + case '3': + path.addArc(oval, 0, 90); + break; + case '4': + path.arcTo({56, 56}, {32, 56}, 24); + break; + case '5': + path.arcTo({24, 24}, 0, SkPath::kSmall_ArcSize, SkPath::kCW_Direction, {32, 56}); + break; + case '6': + path.conicTo({56, 56}, {32, 56}, SK_ScalarRoot2Over2); + break; + } + canvas->drawPath(path, arcPaint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_067.cpp b/docs/examples/Path_067.cpp new file mode 100644 index 0000000000..edd8747d8e --- /dev/null +++ b/docs/examples/Path_067.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=5f02890edaa10cb5e1a4243a82b6a382 +REG_FIDDLE(Path_067, 256, 200, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPath path; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(4); + path.moveTo(0, 0); + path.arcTo({20, 20, 120, 120}, -90, 90, false); + canvas->drawPath(path, paint); + path.rewind(); + path.arcTo({120, 20, 220, 120}, -90, 90, false); + canvas->drawPath(path, paint); + path.rewind(); + path.moveTo(0, 0); + path.arcTo({20, 120, 120, 220}, -90, 90, true); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_068.cpp b/docs/examples/Path_068.cpp new file mode 100644 index 0000000000..3bf95c43a9 --- /dev/null +++ b/docs/examples/Path_068.cpp @@ -0,0 +1,42 @@ +#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 "fiddle/examples.h" +// HASH=386000684073fccabc224d7d6dc81cd9 +REG_FIDDLE(Path_068, 256, 226, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint tangentPaint; + tangentPaint.setAntiAlias(true); + SkPaint textPaint(tangentPaint); + tangentPaint.setStyle(SkPaint::kStroke_Style); + tangentPaint.setColor(SK_ColorGRAY); + SkPaint arcPaint(tangentPaint); + arcPaint.setStrokeWidth(5); + arcPaint.setColor(SK_ColorBLUE); + SkPath path; + SkPoint pts[] = { {56, 20}, {200, 20}, {90, 190} }; + SkScalar radius = 50; + path.moveTo(pts[0]); + path.arcTo(pts[1], pts[2], radius); + canvas->drawLine(pts[0], pts[1], tangentPaint); + canvas->drawLine(pts[1], pts[2], tangentPaint); + SkPoint lastPt; + (void) path.getLastPt(&lastPt); + SkVector radial = pts[2] - pts[1]; + radial.setLength(radius); + SkPoint center = { lastPt.fX - radial.fY, lastPt.fY + radial.fX }; + canvas->drawCircle(center, radius, tangentPaint); + canvas->drawLine(lastPt, center, tangentPaint); + radial = pts[1] - pts[0]; + radial.setLength(radius); + SkPoint arcStart = { center.fX + radial.fY, center.fY - radial.fX }; + canvas->drawLine(center, arcStart, tangentPaint); + canvas->drawPath(path, arcPaint); + canvas->drawString("(x0, y0)", pts[0].fX - 5, pts[0].fY, textPaint); + canvas->drawString("(x1, y1)", pts[1].fX + 5, pts[1].fY, textPaint); + canvas->drawString("(x2, y2)", pts[2].fX, pts[2].fY + 15, textPaint); + canvas->drawString("radius", center.fX + 15, center.fY + 25, textPaint); + canvas->drawString("radius", center.fX - 3, center.fY - 16, textPaint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_069.cpp b/docs/examples/Path_069.cpp new file mode 100644 index 0000000000..f11cfe20ad --- /dev/null +++ b/docs/examples/Path_069.cpp @@ -0,0 +1,41 @@ +#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 "fiddle/examples.h" +// HASH=78f3c65fa900610bb52518989b547095 +REG_FIDDLE(Path_069, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint tangentPaint; + tangentPaint.setAntiAlias(true); + SkPaint textPaint(tangentPaint); + tangentPaint.setStyle(SkPaint::kStroke_Style); + tangentPaint.setColor(SK_ColorGRAY); + SkPaint arcPaint(tangentPaint); + arcPaint.setStrokeWidth(5); + arcPaint.setColor(SK_ColorBLUE); + SkPath path; + SkPoint pts[] = { {156, 20}, {200, 20}, {170, 50} }; + SkScalar radius = 50; + path.moveTo(pts[0]); + path.arcTo(pts[1], pts[2], radius); + canvas->drawLine(pts[0], pts[1], tangentPaint); + canvas->drawLine(pts[1], pts[2], tangentPaint); + SkPoint lastPt; + (void) path.getLastPt(&lastPt); + SkVector radial = pts[2] - pts[1]; + radial.setLength(radius); + SkPoint center = { lastPt.fX - radial.fY, lastPt.fY + radial.fX }; + canvas->drawLine(lastPt, center, tangentPaint); + radial = pts[1] - pts[0]; + radial.setLength(radius); + SkPoint arcStart = { center.fX + radial.fY, center.fY - radial.fX }; + canvas->drawLine(center, arcStart, tangentPaint); + canvas->drawPath(path, arcPaint); + canvas->drawString("(x0, y0)", pts[0].fX, pts[0].fY - 7, textPaint); + canvas->drawString("(x1, y1)", pts[1].fX + 5, pts[1].fY, textPaint); + canvas->drawString("(x2, y2)", pts[2].fX, pts[2].fY + 15, textPaint); + canvas->drawString("radius", center.fX + 15, center.fY + 25, textPaint); + canvas->drawString("radius", center.fX - 5, center.fY - 20, textPaint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_070.cpp b/docs/examples/Path_070.cpp new file mode 100644 index 0000000000..9b83078214 --- /dev/null +++ b/docs/examples/Path_070.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=498360fa0a201cc5db04b1c27256358f +REG_FIDDLE(Path_070, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo({156, 20}); + path.arcTo(200, 20, 170, 50, 50); + SkPath::Iter iter(path, false); + SkPoint p[4]; + SkPath::Verb verb; + while (SkPath::kDone_Verb != (verb = iter.next(p))) { + switch (verb) { + case SkPath::kMove_Verb: + SkDebugf("move to (%g,%g)\n", p[0].fX, p[0].fY); + break; + case SkPath::kLine_Verb: + SkDebugf("line (%g,%g),(%g,%g)\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY); + break; + case SkPath::kConic_Verb: + SkDebugf("conic (%g,%g),(%g,%g),(%g,%g) weight %g\n", + p[0].fX, p[0].fY, p[1].fX, p[1].fY, p[2].fX, p[2].fY, iter.conicWeight()); + break; + default: + SkDebugf("unexpected verb\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Path_071.cpp b/docs/examples/Path_071.cpp new file mode 100644 index 0000000000..5391fc4fbf --- /dev/null +++ b/docs/examples/Path_071.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=0c056264a361579c18e5d02d3172d4d4 +REG_FIDDLE(Path_071, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo({156, 20}); + path.arcTo({200, 20}, {170, 20}, 50); + SkPath::Iter iter(path, false); + SkPoint p[4]; + SkPath::Verb verb; + while (SkPath::kDone_Verb != (verb = iter.next(p))) { + switch (verb) { + case SkPath::kMove_Verb: + SkDebugf("move to (%g,%g)\n", p[0].fX, p[0].fY); + break; + case SkPath::kLine_Verb: + SkDebugf("line (%g,%g),(%g,%g)\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY); + break; + case SkPath::kConic_Verb: + SkDebugf("conic (%g,%g),(%g,%g),(%g,%g) weight %g\n", + p[0].fX, p[0].fY, p[1].fX, p[1].fY, p[2].fX, p[2].fY, iter.conicWeight()); + break; + default: + SkDebugf("unexpected verb\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Path_072.cpp b/docs/examples/Path_072.cpp new file mode 100644 index 0000000000..fbc20aee4e --- /dev/null +++ b/docs/examples/Path_072.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=8e40c546eecd9cc213200717240898ba +REG_FIDDLE(Path_072, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + for (auto sweep: { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { + for (auto arcSize : { SkPath::kSmall_ArcSize, SkPath::kLarge_ArcSize } ) { + SkPath path; + path.moveTo({120, 50}); + path.arcTo(70, 40, 30, arcSize, sweep, 156, 100); + if (SkPath::kCCW_Direction == sweep && SkPath::kLarge_ArcSize == arcSize) { + paint.setColor(SK_ColorBLUE); + paint.setStrokeWidth(3); + } + canvas->drawPath(path, paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Path_073.cpp b/docs/examples/Path_073.cpp new file mode 100644 index 0000000000..bf9d9dfb83 --- /dev/null +++ b/docs/examples/Path_073.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=6b6ea44f659b27918f3a6fa621bf6173 +REG_FIDDLE(Path_073, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + for (auto sweep: { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { + for (auto arcSize : { SkPath::kSmall_ArcSize, SkPath::kLarge_ArcSize } ) { + SkPath path; + path.moveTo({120, 50}); + path.arcTo(70, 40, 30, arcSize, sweep, 120.1, 50); + if (SkPath::kCCW_Direction == sweep && SkPath::kLarge_ArcSize == arcSize) { + paint.setColor(SK_ColorBLUE); + paint.setStrokeWidth(3); + } + canvas->drawPath(path, paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Path_074.cpp b/docs/examples/Path_074.cpp new file mode 100644 index 0000000000..22f0396f94 --- /dev/null +++ b/docs/examples/Path_074.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=3f76a1007416181a4848c1a87fc81dbd +REG_FIDDLE(Path_074, 256, 108, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPath path; + const SkPoint starts[] = {{20, 20}, {120, 20}, {70, 60}}; + for (auto start : starts) { + path.moveTo(start.fX, start.fY); + path.rArcTo(20, 20, 0, SkPath::kSmall_ArcSize, SkPath::kCCW_Direction, 60, 0); + } + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_075.cpp b/docs/examples/Path_075.cpp new file mode 100644 index 0000000000..3aa835b01c --- /dev/null +++ b/docs/examples/Path_075.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=3f76a1007416181a4848c1a87fc81dbd +REG_FIDDLE(Path_075, 256, 108, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPath path; + const SkPoint starts[] = {{20, 20}, {120, 20}, {70, 60}}; + for (auto start : starts) { + path.moveTo(start.fX, start.fY); + path.rArcTo(20, 20, 0, SkPath::kSmall_ArcSize, SkPath::kCCW_Direction, 60, 0); + } + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_076.cpp b/docs/examples/Path_076.cpp new file mode 100644 index 0000000000..1f2589db14 --- /dev/null +++ b/docs/examples/Path_076.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=9235f6309271d6420fa5c45dc28664c5 +REG_FIDDLE(Path_076, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeWidth(15); + paint.setStrokeCap(SkPaint::kRound_Cap); + SkPath path; + const SkPoint points[] = {{20, 20}, {70, 20}, {40, 90}}; + path.addPoly(points, SK_ARRAY_COUNT(points), false); + for (int loop = 0; loop < 2; ++loop) { + for (auto style : {SkPaint::kStroke_Style, SkPaint::kFill_Style, + SkPaint::kStrokeAndFill_Style} ) { + paint.setStyle(style); + canvas->drawPath(path, paint); + canvas->translate(85, 0); + } + path.close(); + canvas->translate(-255, 128); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_077.cpp b/docs/examples/Path_077.cpp new file mode 100644 index 0000000000..2adb50374c --- /dev/null +++ b/docs/examples/Path_077.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=1453856a9d0c73e8192bf298c4143563 +REG_FIDDLE(Path_077, 256, 256, true, 0) { +#define nameValue(fill) { SkPath::fill, #fill } + +void draw(SkCanvas* canvas) { + struct { + SkPath::FillType fill; + const char* name; + } fills[] = { + nameValue(kWinding_FillType), + nameValue(kEvenOdd_FillType), + nameValue(kInverseWinding_FillType), + nameValue(kInverseEvenOdd_FillType), + }; + for (auto fill: fills ) { + SkDebugf("IsInverseFillType(%s) == %s\n", fill.name, SkPath::IsInverseFillType(fill.fill) ? + "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_078.cpp b/docs/examples/Path_078.cpp new file mode 100644 index 0000000000..06be1316cf --- /dev/null +++ b/docs/examples/Path_078.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=319f6b124458dcc0f9ce4d7bbde65810 +REG_FIDDLE(Path_078, 256, 256, true, 0) { +#define nameValue(fill) { SkPath::fill, #fill } + +void draw(SkCanvas* canvas) { + struct { + SkPath::FillType fill; + const char* name; + } fills[] = { + nameValue(kWinding_FillType), + nameValue(kEvenOdd_FillType), + nameValue(kInverseWinding_FillType), + nameValue(kInverseEvenOdd_FillType), + }; + for (unsigned i = 0; i < SK_ARRAY_COUNT(fills); ++i) { + if (fills[i].fill != (SkPath::FillType) i) { + SkDebugf("fills array order does not match FillType enum order"); + break; + } + SkDebugf("ConvertToNonInverseFillType(%s) == %s\n", fills[i].name, + fills[(int) SkPath::ConvertToNonInverseFillType(fills[i].fill)].name); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_079.cpp b/docs/examples/Path_079.cpp new file mode 100644 index 0000000000..57571dec09 --- /dev/null +++ b/docs/examples/Path_079.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=3ba94448a4ba48f926e643baeb5b1016 +REG_FIDDLE(Path_079, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint conicPaint; + conicPaint.setAntiAlias(true); + conicPaint.setStyle(SkPaint::kStroke_Style); + SkPaint quadPaint(conicPaint); + quadPaint.setColor(SK_ColorRED); + SkPoint conic[] = { {20, 170}, {80, 170}, {80, 230} }; + for (auto weight : { .25f, .5f, .707f, .85f, 1.f } ) { + SkPoint quads[5]; + SkPath::ConvertConicToQuads(conic[0], conic[1], conic[2], weight, quads, 1); + SkPath path; + path.moveTo(conic[0]); + path.conicTo(conic[1], conic[2], weight); + canvas->drawPath(path, conicPaint); + path.rewind(); + path.moveTo(quads[0]); + path.quadTo(quads[1], quads[2]); + path.quadTo(quads[3], quads[4]); + canvas->drawPath(path, quadPaint); + canvas->translate(50, -50); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_080.cpp b/docs/examples/Path_080.cpp new file mode 100644 index 0000000000..f61ce5cdd6 --- /dev/null +++ b/docs/examples/Path_080.cpp @@ -0,0 +1,30 @@ +// 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 "fiddle/examples.h" +// HASH=81a2aac1b8f0ff3d4c8d35ccb9149b16 +REG_FIDDLE(Path_080, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path) -> void { + SkRect rect; + SkPath::Direction direction; + bool isClosed; + path.isRect(&rect, &isClosed, &direction) ? + SkDebugf("%s is rect (%g, %g, %g, %g); is %s" "closed; direction %s\n", prefix, + rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, isClosed ? "" : "not ", + SkPath::kCW_Direction == direction ? "CW" : "CCW") : + SkDebugf("%s is not rect\n", prefix); + }; + SkPath path; + debugster("empty", path); + path.addRect({10, 20, 30, 40}); + debugster("addRect", path); + path.moveTo(60, 70); + debugster("moveTo", path); + path.lineTo(60, 70); + debugster("lineTo", path); + path.reset(); + const SkPoint pts[] = { {0, 0}, {0, 80}, {80, 80}, {80, 0}, {40, 0}, {20, 0} }; + path.addPoly(pts, SK_ARRAY_COUNT(pts), false); + debugster("addPoly", path); +} +} // END FIDDLE diff --git a/docs/examples/Path_081.cpp b/docs/examples/Path_081.cpp new file mode 100644 index 0000000000..701d90624a --- /dev/null +++ b/docs/examples/Path_081.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=77e4394caf9fa083c19c21c2462efe14 +REG_FIDDLE(Path_081, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(5); + SkPath path; + path.addRect({10, 20, 30, 40}); + paint.getFillPath(path, &path); + SkRect rects[2]; + SkPath::Direction directions[2]; + if (path.isNestedFillRects(rects, directions)) { + for (int i = 0; i < 2; ++i) { + SkDebugf("%s (%g, %g, %g, %g); direction %s\n", i ? "inner" : "outer", + rects[i].fLeft, rects[i].fTop, rects[i].fRight, rects[i].fBottom, + SkPath::kCW_Direction == directions[i] ? "CW" : "CCW"); + } + } else { + SkDebugf("is not nested rectangles\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_082.cpp b/docs/examples/Path_082.cpp new file mode 100644 index 0000000000..02d47f7e0f --- /dev/null +++ b/docs/examples/Path_082.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=0f841e4eaebb613b5069800567917c2d +REG_FIDDLE(Path_082, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeWidth(15); + paint.setStrokeCap(SkPaint::kSquare_Cap); + float intervals[] = { 5, 21.75f }; + paint.setStyle(SkPaint::kStroke_Style); + paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0)); + SkPath path; + path.addRect({20, 20, 100, 100}, SkPath::kCW_Direction); + canvas->drawPath(path, paint); + path.rewind(); + path.addRect({140, 20, 220, 100}, SkPath::kCCW_Direction); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_083.cpp b/docs/examples/Path_083.cpp new file mode 100644 index 0000000000..250d7880cc --- /dev/null +++ b/docs/examples/Path_083.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=9202430b3f4f5275af8eec5cc9d7baa8 +REG_FIDDLE(Path_083, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + const SkPoint arrow[] = { {5, -5}, {15, -5}, {20, 0}, {15, 5}, {5, 5}, {10, 0} }; + const SkRect rect = {10, 10, 54, 54}; + SkPaint rectPaint; + rectPaint.setAntiAlias(true); + rectPaint.setStyle(SkPaint::kStroke_Style); + SkPaint arrowPaint(rectPaint); + SkPath arrowPath; + arrowPath.addPoly(arrow, SK_ARRAY_COUNT(arrow), true); + arrowPaint.setPathEffect(SkPath1DPathEffect::Make(arrowPath, 176, 0, + SkPath1DPathEffect::kRotate_Style)); + for (auto direction : { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { + for (unsigned start : { 0, 1, 2, 3 } ) { + SkPath path; + path.addRect(rect, direction, start); + canvas->drawPath(path, rectPaint); + canvas->drawPath(path, arrowPaint); + canvas->translate(64, 0); + } + canvas->translate(-256, 64); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_084.cpp b/docs/examples/Path_084.cpp new file mode 100644 index 0000000000..3389ab3ec7 --- /dev/null +++ b/docs/examples/Path_084.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=3837827310e8b88b8c2e128ef9fbbd65 +REG_FIDDLE(Path_084, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeWidth(15); + paint.setStrokeCap(SkPaint::kSquare_Cap); + float intervals[] = { 5, 21.75f }; + paint.setStyle(SkPaint::kStroke_Style); + paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0)); + for (auto direction : { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { + SkPath path; + path.addRect(20, 20, 100, 100, direction); + canvas->drawPath(path, paint); + canvas->translate(128, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_085.cpp b/docs/examples/Path_085.cpp new file mode 100644 index 0000000000..ed8b1dc3f2 --- /dev/null +++ b/docs/examples/Path_085.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=cac84cf68e63a453c2a8b64c91537704 +REG_FIDDLE(Path_085, 256, 120, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkPath oval; + oval.addOval({20, 20, 160, 80}); + canvas->drawPath(oval, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_086.cpp b/docs/examples/Path_086.cpp new file mode 100644 index 0000000000..a90b34c1ec --- /dev/null +++ b/docs/examples/Path_086.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=f1122d6fffddac0167e96fab4b9a862f +REG_FIDDLE(Path_086, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + const SkPoint arrow[] = { {0, -5}, {10, 0}, {0, 5} }; + const SkRect rect = {10, 10, 54, 54}; + SkPaint ovalPaint; + ovalPaint.setAntiAlias(true); + SkPaint textPaint(ovalPaint); + ovalPaint.setStyle(SkPaint::kStroke_Style); + SkPaint arrowPaint(ovalPaint); + SkPath arrowPath; + arrowPath.addPoly(arrow, SK_ARRAY_COUNT(arrow), true); + arrowPaint.setPathEffect(SkPath1DPathEffect::Make(arrowPath, 176, 0, + SkPath1DPathEffect::kRotate_Style)); + for (auto direction : { SkPath::kCW_Direction, SkPath::kCCW_Direction } ) { + for (unsigned start : { 0, 1, 2, 3 } ) { + SkPath path; + path.addOval(rect, direction, start); + canvas->drawPath(path, ovalPaint); + canvas->drawPath(path, arrowPaint); + canvas->drawText(&"0123"[start], 1, rect.centerX(), rect.centerY() + 5, textPaint); + canvas->translate(64, 0); + } + canvas->translate(-256, 72); + canvas->drawString(SkPath::kCW_Direction == direction ? "clockwise" : "counterclockwise", + 128, 0, textPaint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_087.cpp b/docs/examples/Path_087.cpp new file mode 100644 index 0000000000..2ba6fb6c1a --- /dev/null +++ b/docs/examples/Path_087.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=bd5286cb9a5e5c32cd980f72b8f400fb +REG_FIDDLE(Path_087, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(10); + for (int size = 10; size < 300; size += 20) { + SkPath path; + path.addCircle(128, 128, size, SkPath::kCW_Direction); + canvas->drawPath(path, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_088.cpp b/docs/examples/Path_088.cpp new file mode 100644 index 0000000000..c21bc05c09 --- /dev/null +++ b/docs/examples/Path_088.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=9cf5122475624e4cf39f06c698f80b1a +REG_FIDDLE(Path_088, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + for (auto start : { 0, 90, 135, 180, 270 } ) { + for (auto sweep : { -450.f, -180.f, -90.f, 90.f, 180.f, 360.1f } ) { + SkPath path; + path.addArc({10, 10, 35, 45}, start, sweep); + canvas->drawPath(path, paint); + canvas->translate(252 / 6, 0); + } + canvas->translate(-252, 255 / 5); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_089.cpp b/docs/examples/Path_089.cpp new file mode 100644 index 0000000000..d45529b27e --- /dev/null +++ b/docs/examples/Path_089.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=24736f685f265cf533f1700c042db353 +REG_FIDDLE(Path_089, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + for (auto xradius : { 0, 7, 13, 20 } ) { + for (auto yradius : { 0, 9, 18, 40 } ) { + SkPath path; + path.addRoundRect({10, 10, 36, 46}, xradius, yradius); + paint.setColor(path.isRect(nullptr) ? SK_ColorRED : path.isOval(nullptr) ? + SK_ColorBLUE : path.isConvex() ? SK_ColorGRAY : SK_ColorGREEN); + canvas->drawPath(path, paint); + canvas->translate(64, 0); + } + canvas->translate(-256, 64); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_090.cpp b/docs/examples/Path_090.cpp new file mode 100644 index 0000000000..72cba0b4ee --- /dev/null +++ b/docs/examples/Path_090.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=c43d70606b4ee464d2befbcf448c5e73 +REG_FIDDLE(Path_090, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkScalar radii[] = { 80, 100, 0, 0, 40, 60, 0, 0 }; + SkPath path; + SkMatrix rotate90; + rotate90.setRotate(90, 128, 128); + for (int i = 0; i < 4; ++i) { + path.addRoundRect({10, 10, 110, 110}, radii); + path.transform(rotate90); + } + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_091.cpp b/docs/examples/Path_091.cpp new file mode 100644 index 0000000000..01dde235c9 --- /dev/null +++ b/docs/examples/Path_091.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=d9ecd58081b5bc77a157636fcb345dc6 +REG_FIDDLE(Path_091, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkRRect rrect; + SkVector radii[] = {{50, 50}, {0, 0}, {0, 0}, {50, 50}}; + rrect.setRectRadii({10, 10, 110, 110}, radii); + SkPath path; + SkMatrix rotate90; + rotate90.setRotate(90, 128, 128); + for (int i = 0; i < 4; ++i) { + path.addRRect(rrect); + path.transform(rotate90); + } + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_092.cpp b/docs/examples/Path_092.cpp new file mode 100644 index 0000000000..a138f315de --- /dev/null +++ b/docs/examples/Path_092.cpp @@ -0,0 +1,30 @@ +#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 "fiddle/examples.h" +// HASH=888edd4c4a91ca62ceb01bce8ab675b2 +REG_FIDDLE(Path_092, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkRRect rrect; + rrect.setRectXY({40, 40, 215, 215}, 50, 50); + SkPath path; + path.addRRect(rrect); + canvas->drawPath(path, paint); + for (int start = 0; start < 8; ++start) { + SkPath textPath; + textPath.addRRect(rrect, SkPath::kCW_Direction, start); + SkPathMeasure pathMeasure(textPath, false); + SkPoint position; + SkVector tangent; + if (!pathMeasure.getPosTan(0, &position, &tangent)) { + continue; + } + SkRSXform rsxForm = SkRSXform::Make(tangent.fX, tangent.fY, + position.fX + tangent.fY * 5, position.fY - tangent.fX * 5); + canvas->drawTextRSXform(&"01234567"[start], 1, &rsxForm, nullptr, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_093.cpp b/docs/examples/Path_093.cpp new file mode 100644 index 0000000000..5e7e4fd9a4 --- /dev/null +++ b/docs/examples/Path_093.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=182b3999772f330f3b0b891b492634ae +REG_FIDDLE(Path_093, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeWidth(15); + paint.setStrokeCap(SkPaint::kRound_Cap); + const SkPoint points[] = {{20, 20}, {70, 20}, {40, 90}}; + for (bool close : { false, true } ) { + SkPath path; + path.addPoly(points, SK_ARRAY_COUNT(points), close); + for (auto style : {SkPaint::kStroke_Style, SkPaint::kFill_Style, + SkPaint::kStrokeAndFill_Style} ) { + paint.setStyle(style); + canvas->drawPath(path, paint); + canvas->translate(85, 0); + } + canvas->translate(-255, 128); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_094.cpp b/docs/examples/Path_094.cpp new file mode 100644 index 0000000000..01f0477e92 --- /dev/null +++ b/docs/examples/Path_094.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=1a6b69acad5ceafede3c5984ec6634cb +REG_FIDDLE(Path_094, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeWidth(15); + paint.setStrokeCap(SkPaint::kRound_Cap); + for (bool close : { false, true } ) { + SkPath path; + path.addPoly({{20, 20}, {70, 20}, {40, 90}}, close); + for (auto style : {SkPaint::kStroke_Style, SkPaint::kFill_Style, + SkPaint::kStrokeAndFill_Style} ) { + paint.setStyle(style); + canvas->drawPath(path, paint); + canvas->translate(85, 0); + } + canvas->translate(-255, 128); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_095.cpp b/docs/examples/Path_095.cpp new file mode 100644 index 0000000000..34f94ea9a1 --- /dev/null +++ b/docs/examples/Path_095.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=801b02e74c64aafdb734f2e5cf3e5ab0 +REG_FIDDLE(Path_095, 256, 180, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path, path2; + path.moveTo(20, 20); + path.lineTo(20, 40); + path.lineTo(40, 20); + path2.moveTo(60, 60); + path2.lineTo(80, 60); + path2.lineTo(80, 40); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + for (int i = 0; i < 2; i++) { + for (auto addPathMode : { SkPath::kAppend_AddPathMode, SkPath::kExtend_AddPathMode } ) { + SkPath test(path); + test.addPath(path2, addPathMode); + canvas->drawPath(test, paint); + canvas->translate(100, 0); + } + canvas->translate(-200, 100); + path.close(); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_096.cpp b/docs/examples/Path_096.cpp new file mode 100644 index 0000000000..2747e77eb6 --- /dev/null +++ b/docs/examples/Path_096.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=c416bddfe286628974e1c7f0fd66f3f4 +REG_FIDDLE(Path_096, 256, 180, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + paint.setFakeBoldText(true); + SkPath dest, text; + paint.getTextPath("O", 1, 50, 120, &text); + for (int i = 0; i < 3; i++) { + dest.addPath(text, i * 20, i * 20); + } + Simplify(dest, &dest); + paint.setStyle(SkPaint::kStroke_Style); + paint.setStrokeWidth(3); + canvas->drawPath(dest, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_097.cpp b/docs/examples/Path_097.cpp new file mode 100644 index 0000000000..5ba047103d --- /dev/null +++ b/docs/examples/Path_097.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=84b2d1c0fc29f1b35e855b6fc6672f9e +REG_FIDDLE(Path_097, 256, 80, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + SkPath dest, path; + path.addOval({-80, 20, 0, 60}, SkPath::kCW_Direction, 1); + for (int i = 0; i < 2; i++) { + dest.addPath(path, SkPath::kExtend_AddPathMode); + dest.offset(100, 0); + } + canvas->drawPath(dest, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_098.cpp b/docs/examples/Path_098.cpp new file mode 100644 index 0000000000..6ca2bef2a2 --- /dev/null +++ b/docs/examples/Path_098.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=3a90a91030f7289d5df0671d342dbbad +REG_FIDDLE(Path_098, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + SkPath dest, path; + path.addOval({20, 20, 200, 120}, SkPath::kCW_Direction, 1); + for (int i = 0; i < 6; i++) { + SkMatrix matrix; + matrix.reset(); + matrix.setPerspX(i / 400.f); + dest.addPath(path, matrix); + } + canvas->drawPath(dest, paint); +} +} // END FIDDLE diff --git a/docs/examples/Path_099.cpp b/docs/examples/Path_099.cpp new file mode 100644 index 0000000000..fd6dc1d0ff --- /dev/null +++ b/docs/examples/Path_099.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=5e8513f073db09acde3ff616f6426e3d +REG_FIDDLE(Path_099, 256, 200, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo(20, 20); + path.lineTo(20, 40); + path.lineTo(40, 20); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + for (int i = 0; i < 2; i++) { + SkPath path2; + path2.moveTo(60, 60); + path2.lineTo(80, 60); + path2.lineTo(80, 40); + for (int j = 0; j < 2; j++) { + SkPath test(path); + test.reverseAddPath(path2); + canvas->drawPath(test, paint); + canvas->translate(100, 0); + path2.close(); + } + canvas->translate(-200, 100); + path.close(); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_100.cpp b/docs/examples/Path_100.cpp new file mode 100644 index 0000000000..94c0cef858 --- /dev/null +++ b/docs/examples/Path_100.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=1d1892196ba5bda257df4f3351abd084 +REG_FIDDLE(Path_100, 256, 60, false, 0) { +void draw(SkCanvas* canvas) { + SkPath pattern; + pattern.moveTo(20, 20); + pattern.lineTo(20, 40); + pattern.lineTo(40, 20); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + for (int i = 0; i < 10; i++) { + SkPath path; + pattern.offset(20 * i, 0, &path); + canvas->drawPath(path, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_101.cpp b/docs/examples/Path_101.cpp new file mode 100644 index 0000000000..7263dc5d20 --- /dev/null +++ b/docs/examples/Path_101.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=5188d77585715db30bef228f2dfbcccd +REG_FIDDLE(Path_101, 256, 60, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo(20, 20); + path.lineTo(20, 40); + path.lineTo(40, 20); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + for (int i = 0; i < 10; i++) { + canvas->drawPath(path, paint); + path.offset(20, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_102.cpp b/docs/examples/Path_102.cpp new file mode 100644 index 0000000000..c772b2af6e --- /dev/null +++ b/docs/examples/Path_102.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=99761add116ce3b0730557224c1b0105 +REG_FIDDLE(Path_102, 256, 200, false, 0) { +void draw(SkCanvas* canvas) { + SkPath pattern; + pattern.moveTo(100, 100); + pattern.lineTo(100, 20); + pattern.lineTo(20, 100); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + for (int i = 0; i < 10; i++) { + SkPath path; + SkMatrix matrix; + matrix.setRotate(36 * i, 100, 100); + pattern.transform(matrix, &path); + canvas->drawPath(path, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_103.cpp b/docs/examples/Path_103.cpp new file mode 100644 index 0000000000..895a2d4c2d --- /dev/null +++ b/docs/examples/Path_103.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=c40979a3b92a30cfb7bae36abcc1d805 +REG_FIDDLE(Path_103, 256, 200, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo(100, 100); + path.quadTo(100, 20, 20, 100); + SkPaint paint; + paint.setStyle(SkPaint::kStroke_Style); + for (int i = 0; i < 10; i++) { + SkMatrix matrix; + matrix.setRotate(36, 100, 100); + path.transform(matrix); + canvas->drawPath(path, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_104.cpp b/docs/examples/Path_104.cpp new file mode 100644 index 0000000000..642b0fd8a3 --- /dev/null +++ b/docs/examples/Path_104.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=df8160dd7ac8aa4b40fce7286fe49952 +REG_FIDDLE(Path_104, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo(100, 100); + path.quadTo(100, 20, 20, 100); + SkMatrix matrix; + matrix.setRotate(36, 100, 100); + path.transform(matrix); + SkPoint last; + path.getLastPt(&last); + SkDebugf("last point: %g, %g\n", last.fX, last.fY); +} +} // END FIDDLE diff --git a/docs/examples/Path_105.cpp b/docs/examples/Path_105.cpp new file mode 100644 index 0000000000..510dcb0317 --- /dev/null +++ b/docs/examples/Path_105.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=542c5afaea5f57baa11d0561dd402e18 +REG_FIDDLE(Path_105, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath path; + paint.getTextPath("@", 1, 60, 100, &path); + path.setLastPt(20, 120); + canvas->drawPath(path, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_106.cpp b/docs/examples/Path_106.cpp new file mode 100644 index 0000000000..607dc173fa --- /dev/null +++ b/docs/examples/Path_106.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=6fa5e8f9513b3225e106778592e27e94 +REG_FIDDLE(Path_106, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath path, path2; + paint.getTextPath("A", 1, 60, 100, &path); + paint.getTextPath("Z", 1, 60, 100, &path2); + SkPoint pt, pt2; + path.getLastPt(&pt); + path2.getLastPt(&pt2); + path.setLastPt(pt2); + path2.setLastPt(pt); + canvas->drawPath(path, paint); + canvas->drawPath(path2, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_107.cpp b/docs/examples/Path_107.cpp new file mode 100644 index 0000000000..9d0b0be688 --- /dev/null +++ b/docs/examples/Path_107.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=a61e5758574e28190ec4ed8c4ae7e7fa +REG_FIDDLE(Path_107, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.conicTo(10, 10, 20, 30, 1); + SkDebugf("Path kConic_SegmentMask is %s\n", path.getSegmentMasks() & + SkPath::kConic_SegmentMask ? "set" : "clear"); + SkDebugf("Path kQuad_SegmentMask is %s\n", path.getSegmentMasks() & + SkPath::kQuad_SegmentMask ? "set" : "clear"); +} +} // END FIDDLE diff --git a/docs/examples/Path_108.cpp b/docs/examples/Path_108.cpp new file mode 100644 index 0000000000..c34032f14d --- /dev/null +++ b/docs/examples/Path_108.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=657a3f3e11acafea92b84d6bb0c13633 +REG_FIDDLE(Path_108, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.quadTo(20, 30, 40, 50); + path.close(); + const char* masks[] = { "line", "quad", "conic", "cubic" }; + int index = 0; + for (auto mask : { SkPath::kLine_SegmentMask, SkPath::kQuad_SegmentMask, + SkPath::kConic_SegmentMask, SkPath::kCubic_SegmentMask } ) { + if (mask & path.getSegmentMasks()) { + SkDebugf("mask %s set\n", masks[index]); + } + ++index; + } +} +} // END FIDDLE diff --git a/docs/examples/Path_109.cpp b/docs/examples/Path_109.cpp new file mode 100644 index 0000000000..177a088f69 --- /dev/null +++ b/docs/examples/Path_109.cpp @@ -0,0 +1,26 @@ +#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 "fiddle/examples.h" +// HASH=c0216b3f7ebd80b9589ae5728f08fc80 +REG_FIDDLE(Path_109, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + SkPaint paint; + paint.setTextSize(256); + paint.getTextPath("&", 1, 30, 220, &path); + for (int y = 2; y < 256; y += 9) { + for (int x = 2; x < 256; x += 9) { + int coverage = 0; + for (int iy = -4; iy <= 4; iy += 2) { + for (int ix = -4; ix <= 4; ix += 2) { + coverage += path.contains(x + ix, y + iy); + } + } + paint.setColor(SkColorSetARGB(0x5f, 0xff * coverage / 25, 0, 0xff * (25 - coverage) / 25)); + canvas->drawCircle(x, y, 8, paint); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_110.cpp b/docs/examples/Path_110.cpp new file mode 100644 index 0000000000..618cbe9941 --- /dev/null +++ b/docs/examples/Path_110.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=8036d764452a62f9953af50846f0f3c0 +REG_FIDDLE(Path_110, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.quadTo(20, 30, 40, 50); + for (bool forceClose : { false, true } ) { + for (bool dumpAsHex : { false, true } ) { + path.dump(nullptr, forceClose, dumpAsHex); + SkDebugf("\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Path_111.cpp b/docs/examples/Path_111.cpp new file mode 100644 index 0000000000..441463cac0 --- /dev/null +++ b/docs/examples/Path_111.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=92e0032f85181795d1f8b5a2c8e4e4b7 +REG_FIDDLE(Path_111, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path, copy; + path.lineTo(6.f / 7, 2.f / 3); + path.dump(); + copy.setFillType(SkPath::kWinding_FillType); + copy.moveTo(0, 0); + copy.lineTo(0.857143f, 0.666667f); + SkDebugf("path is " "%s" "equal to copy\n", path == copy ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Path_112.cpp b/docs/examples/Path_112.cpp new file mode 100644 index 0000000000..b162bec47d --- /dev/null +++ b/docs/examples/Path_112.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=72a92fe058e8b3be6c8a30fad7fd1266 +REG_FIDDLE(Path_112, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path, copy; + path.lineTo(6.f / 7, 2.f / 3); + path.dumpHex(); + copy.setFillType(SkPath::kWinding_FillType); + copy.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 + copy.lineTo(SkBits2Float(0x3f5b6db7), SkBits2Float(0x3f2aaaab)); // 0.857143f, 0.666667f + SkDebugf("path is " "%s" "equal to copy\n", path == copy ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Path_113.cpp b/docs/examples/Path_113.cpp new file mode 100644 index 0000000000..c96c51e940 --- /dev/null +++ b/docs/examples/Path_113.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=e5f16eda6a1c2d759556285f72598445 +REG_FIDDLE(Path_113, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path, copy; + path.lineTo(6.f / 7, 2.f / 3); + size_t size = path.writeToMemory(nullptr); + SkTDArray storage; + storage.setCount(size); + path.writeToMemory(storage.begin()); + copy.readFromMemory(storage.begin(), size); + SkDebugf("path is " "%s" "equal to copy\n", path == copy ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Path_114.cpp b/docs/examples/Path_114.cpp new file mode 100644 index 0000000000..aff666658f --- /dev/null +++ b/docs/examples/Path_114.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=2c6aff73608cd198659db6d1eeaaae4f +REG_FIDDLE(Path_114, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path, copy; + path.lineTo(6.f / 7, 2.f / 3); + sk_sp data = path.serialize(); + copy.readFromMemory(data->data(), data->size()); + SkDebugf("path is " "%s" "equal to copy\n", path == copy ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Path_115.cpp b/docs/examples/Path_115.cpp new file mode 100644 index 0000000000..92da15d37c --- /dev/null +++ b/docs/examples/Path_115.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=9c6edd836c573a0fd232d2b8aa11a678 +REG_FIDDLE(Path_115, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path, copy; + path.lineTo(6.f / 7, 2.f / 3); + size_t size = path.writeToMemory(nullptr); + SkTDArray storage; + storage.setCount(size); + path.writeToMemory(storage.begin()); + size_t wrongSize = size - 4; + size_t bytesRead = copy.readFromMemory(storage.begin(), wrongSize); + SkDebugf("length = %u; returned by readFromMemory = %u\n", wrongSize, bytesRead); + size_t largerSize = size + 4; + bytesRead = copy.readFromMemory(storage.begin(), largerSize); + SkDebugf("length = %u; returned by readFromMemory = %u\n", largerSize, bytesRead); +} +} // END FIDDLE diff --git a/docs/examples/Path_116.cpp b/docs/examples/Path_116.cpp new file mode 100644 index 0000000000..429a9e649d --- /dev/null +++ b/docs/examples/Path_116.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=a0f166715d6479f91258d854e63e586d +REG_FIDDLE(Path_116, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + SkDebugf("empty genID = %u\n", path.getGenerationID()); + path.lineTo(1, 2); + SkDebugf("1st lineTo genID = %u\n", path.getGenerationID()); + path.rewind(); + SkDebugf("empty genID = %u\n", path.getGenerationID()); + path.lineTo(1, 2); + SkDebugf("2nd lineTo genID = %u\n", path.getGenerationID()); +} +} // END FIDDLE diff --git a/docs/examples/Path_117.cpp b/docs/examples/Path_117.cpp new file mode 100644 index 0000000000..e432731f0c --- /dev/null +++ b/docs/examples/Path_117.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=2f53df9201769ab7e7c0e164a1334309 +REG_FIDDLE(Path_117, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(256); + SkPath asterisk, path; + paint.getTextPath("*", 1, 50, 192, &asterisk); + SkPath::Iter iter(asterisk, true); + SkPoint start[4], pts[4]; + iter.next(start); // skip moveTo + iter.next(start); // first quadTo + path.moveTo((start[0] + start[1]) * 0.5f); + while (SkPath::kClose_Verb != iter.next(pts)) { + path.quadTo(pts[0], (pts[0] + pts[1]) * 0.5f); + } + path.quadTo(start[0], (start[0] + start[1]) * 0.5f); + canvas->drawPath(path, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Path_118.cpp b/docs/examples/Path_118.cpp new file mode 100644 index 0000000000..82bf4d4713 --- /dev/null +++ b/docs/examples/Path_118.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=01648775cb9b354b2f1836dad82a25ab +REG_FIDDLE(Path_118, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath::Iter iter; + SkPoint points[4]; + SkDebugf("iter is " "%s" "done\n", SkPath::kDone_Verb == iter.next(points) ? "" : "not "); + SkPath path; + iter.setPath(path, false); + SkDebugf("iter is " "%s" "done\n", SkPath::kDone_Verb == iter.next(points) ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Path_119.cpp b/docs/examples/Path_119.cpp new file mode 100644 index 0000000000..5e679b31b0 --- /dev/null +++ b/docs/examples/Path_119.cpp @@ -0,0 +1,33 @@ +// 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 "fiddle/examples.h" +// HASH=13044dbf68885c0f15322c0633b633a3 +REG_FIDDLE(Path_119, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, SkPath::Iter& iter) -> void { + SkDebugf("%s:\n", prefix); + const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; + const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; + SkPath::Verb verb; + do { + SkPoint points[4]; + verb = iter.next(points); + SkDebugf("k%s_Verb ", verbStr[(int) verb]); + for (int i = 0; i < pointCount[(int) verb]; ++i) { + SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); + } + if (SkPath::kConic_Verb == verb) { + SkDebugf("weight = %g", iter.conicWeight()); + } + SkDebugf("\n"); + } while (SkPath::kDone_Verb != verb); + SkDebugf("\n"); + }; + SkPath path; + path.quadTo(10, 20, 30, 40); + SkPath::Iter openIter(path, false); + debugster("open", openIter); + SkPath::Iter closedIter(path, true); + debugster("closed", closedIter); +} +} // END FIDDLE diff --git a/docs/examples/Path_120.cpp b/docs/examples/Path_120.cpp new file mode 100644 index 0000000000..f3d0d9883a --- /dev/null +++ b/docs/examples/Path_120.cpp @@ -0,0 +1,35 @@ +// 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 "fiddle/examples.h" +// HASH=6c9688008cea8937ad5cc188b38ecf16 +REG_FIDDLE(Path_120, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, SkPath::Iter& iter) -> void { + SkDebugf("%s:\n", prefix); + const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; + const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; + SkPath::Verb verb; + do { + SkPoint points[4]; + verb = iter.next(points); + SkDebugf("k%s_Verb ", verbStr[(int) verb]); + for (int i = 0; i < pointCount[(int) verb]; ++i) { + SkDebugf("{%g, %g}, ", points[i].fX, points[i].fY); + } + if (SkPath::kConic_Verb == verb) { + SkDebugf("weight = %g", iter.conicWeight()); + } + SkDebugf("\n"); + } while (SkPath::kDone_Verb != verb); + SkDebugf("\n"); + }; + SkPath path; + path.quadTo(10, 20, 30, 40); + SkPath::Iter iter(path, false); + debugster("quad open", iter); + SkPath path2; + path2.conicTo(1, 2, 3, 4, .5f); + iter.setPath(path2, true); + debugster("conic closed", iter); +} +} // END FIDDLE diff --git a/docs/examples/Path_121.cpp b/docs/examples/Path_121.cpp new file mode 100644 index 0000000000..e5f8e94a22 --- /dev/null +++ b/docs/examples/Path_121.cpp @@ -0,0 +1,38 @@ +// 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 "fiddle/examples.h" +// HASH=00ae8984856486bdb626d0ed6587855a +REG_FIDDLE(Path_121, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkPath& path, bool degen, bool exact) -> void { + SkPath::Iter iter(path, false); + SkDebugf("%s:\n", prefix); + const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; + const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; + SkPath::Verb verb; + do { + SkPoint points[4]; + verb = iter.next(points, degen, exact); + SkDebugf("k%s_Verb ", verbStr[(int) verb]); + for (int i = 0; i < pointCount[(int) verb]; ++i) { + SkDebugf("{%1.8g, %1.8g}, ", points[i].fX, points[i].fY); + } + SkDebugf("\n"); + } while (SkPath::kDone_Verb != verb); + SkDebugf("\n"); + }; + SkPath path; + path.moveTo(10, 10); + path.moveTo(20, 20); + path.quadTo(10, 20, 30, 40); + path.moveTo(1, 1); + path.close(); + path.moveTo(30, 30); + path.lineTo(30, 30); + path.moveTo(30, 30); + path.lineTo(30.00001f, 30); + debugster("skip degenerate", path, true, false); + debugster("skip degenerate if exact", path, true, true); + debugster("skip none", path, false, false); +} +} // END FIDDLE diff --git a/docs/examples/Path_122.cpp b/docs/examples/Path_122.cpp new file mode 100644 index 0000000000..ce1344d815 --- /dev/null +++ b/docs/examples/Path_122.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=7cdea37741d50f0594c6244eb07fd175 +REG_FIDDLE(Path_122, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.conicTo(1, 2, 3, 4, .5f); + SkPath::Iter iter(path, false); + SkPoint p[4]; + SkDebugf("first verb is " "%s" "move\n", SkPath::kMove_Verb == iter.next(p) ? "" : "not "); + SkDebugf("next verb is " "%s" "conic\n", SkPath::kConic_Verb == iter.next(p) ? "" : "not "); + SkDebugf("conic points: {%g,%g}, {%g,%g}, {%g,%g}\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY, + p[2].fX, p[2].fY); + SkDebugf("conic weight: %g\n", iter.conicWeight()); +} +} // END FIDDLE diff --git a/docs/examples/Path_123.cpp b/docs/examples/Path_123.cpp new file mode 100644 index 0000000000..b383b37ee5 --- /dev/null +++ b/docs/examples/Path_123.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=7000b501f49341629bfdd9f80e686103 +REG_FIDDLE(Path_123, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo(6, 7); + path.conicTo(1, 2, 3, 4, .5f); + path.close(); + SkPath::Iter iter(path, false); + SkPoint p[4]; + SkDebugf("1st verb is " "%s" "move\n", SkPath::kMove_Verb == iter.next(p) ? "" : "not "); + SkDebugf("moveTo point: {%g,%g}\n", p[0].fX, p[0].fY); + SkDebugf("2nd verb is " "%s" "conic\n", SkPath::kConic_Verb == iter.next(p) ? "" : "not "); + SkDebugf("3rd verb is " "%s" "line\n", SkPath::kLine_Verb == iter.next(p) ? "" : "not "); + SkDebugf("line points: {%g,%g}, {%g,%g}\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY); + SkDebugf("line " "%s" "generated by close\n", iter.isCloseLine() ? "" : "not "); + SkDebugf("4th verb is " "%s" "close\n", SkPath::kClose_Verb == iter.next(p) ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Path_124.cpp b/docs/examples/Path_124.cpp new file mode 100644 index 0000000000..ebd1c687ef --- /dev/null +++ b/docs/examples/Path_124.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=b0d48a6e949db1cb545216ae9c3c3c70 +REG_FIDDLE(Path_124, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + for (bool forceClose : { false, true } ) { + SkPath path; + path.conicTo(1, 2, 3, 4, .5f); + SkPath::Iter iter(path, forceClose); + SkDebugf("without close(), forceClose is %s: isClosedContour returns %s\n", + forceClose ? "true " : "false", iter.isClosedContour() ? "true" : "false"); + path.close(); + iter.setPath(path, forceClose); + SkDebugf("with close(), forceClose is %s: isClosedContour returns %s\n", + forceClose ? "true " : "false", iter.isClosedContour() ? "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Path_125.cpp b/docs/examples/Path_125.cpp new file mode 100644 index 0000000000..1d353df7a0 --- /dev/null +++ b/docs/examples/Path_125.cpp @@ -0,0 +1,31 @@ +// 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 "fiddle/examples.h" +// HASH=944a80c7ff8c04e1fecc4aec4a47ea60 +REG_FIDDLE(Path_125, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.moveTo(50, 60); + path.quadTo(10, 20, 30, 40); + path.close(); + path.lineTo(30, 30); + path.conicTo(1, 2, 3, 4, .5f); + path.cubicTo(-1, -2, -3, -4, -5, -6); + SkPath::RawIter iter(path); + const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; + const int pointCount[] = { 1 , 2 , 3 , 3 , 4 , 1 , 0 }; + SkPath::Verb verb; + do { + SkPoint points[4]; + verb = iter.next(points); + SkDebugf("k%s_Verb ", verbStr[(int) verb]); + for (int i = 0; i < pointCount[(int) verb]; ++i) { + SkDebugf("{%1.8g, %1.8g}, ", points[i].fX, points[i].fY); + } + if (SkPath::kConic_Verb == verb) { + SkDebugf("weight = %g", iter.conicWeight()); + } + SkDebugf("\n"); + } while (SkPath::kDone_Verb != verb); +} +} // END FIDDLE diff --git a/docs/examples/Path_126.cpp b/docs/examples/Path_126.cpp new file mode 100644 index 0000000000..fe65bc5ea9 --- /dev/null +++ b/docs/examples/Path_126.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=eb5fa5bea23059ce538e883502f828f5 +REG_FIDDLE(Path_126, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.quadTo(10, 20, 30, 40); + path.conicTo(1, 2, 3, 4, .5f); + path.cubicTo(1, 2, 3, 4, .5, 6); + SkPath::RawIter iter(path); + SkPath::Verb verb, peek = iter.peek(); + const char* verbStr[] = { "Move", "Line", "Quad", "Conic", "Cubic", "Close", "Done" }; + do { + SkPoint points[4]; + verb = iter.next(points); + SkDebugf("peek %s %c= verb %s\n", verbStr[peek], peek == verb ? '=' : '!', verbStr[verb]); + peek = iter.peek(); + } while (SkPath::kDone_Verb != verb); + SkDebugf("peek %s %c= verb %s\n", verbStr[peek], peek == verb ? '=' : '!', verbStr[verb]); +} +} // END FIDDLE diff --git a/docs/examples/Path_127.cpp b/docs/examples/Path_127.cpp new file mode 100644 index 0000000000..5816b747b4 --- /dev/null +++ b/docs/examples/Path_127.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=69f360a0ba8f40c51ef4cd9f972c5893 +REG_FIDDLE(Path_127, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPath path; + path.conicTo(1, 2, 3, 4, .5f); + SkPath::RawIter iter(path); + SkPoint p[4]; + SkDebugf("first verb is " "%s" "move\n", SkPath::kMove_Verb == iter.next(p) ? "" : "not "); + SkDebugf("next verb is " "%s" "conic\n", SkPath::kConic_Verb == iter.next(p) ? "" : "not "); + SkDebugf("conic points: {%g,%g}, {%g,%g}, {%g,%g}\n", p[0].fX, p[0].fY, p[1].fX, p[1].fY, + p[2].fX, p[2].fY); + SkDebugf("conic weight: %g\n", iter.conicWeight()); +} +} // END FIDDLE diff --git a/docs/examples/Picture_000.cpp b/docs/examples/Picture_000.cpp new file mode 100644 index 0000000000..ba2e48f578 --- /dev/null +++ b/docs/examples/Picture_000.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=56ed920dadbf2b2967ac45fb5a9bded6 +REG_FIDDLE(Picture_000, 256, 256, false, 0) { +class JustOneDraw : public SkPicture::AbortCallback { +public: + bool abort() override { return fCalls++ > 0; } +private: + int fCalls = 0; +}; + +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + JustOneDraw callback; + picture->playback(canvas, &callback); +} +} // END FIDDLE diff --git a/docs/examples/Picture_001.cpp b/docs/examples/Picture_001.cpp new file mode 100644 index 0000000000..c1909e8591 --- /dev/null +++ b/docs/examples/Picture_001.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=404fb42560a289c2004cad1caf3b96de +REG_FIDDLE(Picture_001, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + SkDynamicMemoryWStream writableStream; + picture->serialize(&writableStream); + std::unique_ptr readableStream = writableStream.detachAsStream(); + sk_sp copy = SkPicture::MakeFromStream(readableStream.get()); + copy->playback(canvas); +} +} // END FIDDLE diff --git a/docs/examples/Picture_002.cpp b/docs/examples/Picture_002.cpp new file mode 100644 index 0000000000..4cb447cda9 --- /dev/null +++ b/docs/examples/Picture_002.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=58b44bf47d8816782066618700afdecb +REG_FIDDLE(Picture_002, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + SkDynamicMemoryWStream writableStream; + picture->serialize(&writableStream); + sk_sp readableData = writableStream.detachAsData(); + sk_sp copy = SkPicture::MakeFromData(readableData.get()); + copy->playback(canvas); +} +} // END FIDDLE diff --git a/docs/examples/Picture_003.cpp b/docs/examples/Picture_003.cpp new file mode 100644 index 0000000000..50987d9f88 --- /dev/null +++ b/docs/examples/Picture_003.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=30b9f1b310187db6aff720a5d67591e2 +REG_FIDDLE(Picture_003, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + SkDynamicMemoryWStream writableStream; + picture->serialize(&writableStream); + sk_sp readableData = writableStream.detachAsData(); + sk_sp copy = SkPicture::MakeFromData(readableData->data(), readableData->size()); + copy->playback(canvas); +} +} // END FIDDLE diff --git a/docs/examples/Picture_004.cpp b/docs/examples/Picture_004.cpp new file mode 100644 index 0000000000..d7997b5d43 --- /dev/null +++ b/docs/examples/Picture_004.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=6b0ffb03ba05f526b345dc65a1c73fe4 +REG_FIDDLE(Picture_004, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + picture->playback(canvas); +} +} // END FIDDLE diff --git a/docs/examples/Picture_005.cpp b/docs/examples/Picture_005.cpp new file mode 100644 index 0000000000..9af6bcbad6 --- /dev/null +++ b/docs/examples/Picture_005.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=15bb9a9596b40c5e2045f76e8c1dcf8e +REG_FIDDLE(Picture_005, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({64, 64, 192, 192}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + picture->playback(canvas); + paint.setBlendMode(SkBlendMode::kModulate); + paint.setColor(0x40404040); + canvas->drawRect(picture->cullRect(), paint); +} +} // END FIDDLE diff --git a/docs/examples/Picture_006.cpp b/docs/examples/Picture_006.cpp new file mode 100644 index 0000000000..be74690b49 --- /dev/null +++ b/docs/examples/Picture_006.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=8e4257245c988c600410fe4fd7293f07 +REG_FIDDLE(Picture_006, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + recorder.beginRecording({0, 0, 0, 0}); + sk_sp picture = recorder.finishRecordingAsPicture(); + SkDebugf("empty picture id = %d\n", picture->uniqueID()); + sk_sp placeholder = SkPicture::MakePlaceholder({0, 0, 0, 0}); + SkDebugf("placeholder id = %d\n", placeholder->uniqueID()); +} +} // END FIDDLE diff --git a/docs/examples/Picture_007.cpp b/docs/examples/Picture_007.cpp new file mode 100644 index 0000000000..626dd2292d --- /dev/null +++ b/docs/examples/Picture_007.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=dacdebe1355c884ebd3c2ea038cc7a20 +REG_FIDDLE(Picture_007, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + sk_sp readableData = picture->serialize(); + sk_sp copy = SkPicture::MakeFromData(readableData->data(), readableData->size()); + copy->playback(canvas); +} +} // END FIDDLE diff --git a/docs/examples/Picture_008.cpp b/docs/examples/Picture_008.cpp new file mode 100644 index 0000000000..822e7f874f --- /dev/null +++ b/docs/examples/Picture_008.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=30b9f1b310187db6aff720a5d67591e2 +REG_FIDDLE(Picture_008, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + SkDynamicMemoryWStream writableStream; + picture->serialize(&writableStream); + sk_sp readableData = writableStream.detachAsData(); + sk_sp copy = SkPicture::MakeFromData(readableData->data(), readableData->size()); + copy->playback(canvas); +} +} // END FIDDLE diff --git a/docs/examples/Picture_009.cpp b/docs/examples/Picture_009.cpp new file mode 100644 index 0000000000..22f931f28d --- /dev/null +++ b/docs/examples/Picture_009.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=0d2cbf82f490ffb180e0b4531afa232c +REG_FIDDLE(Picture_009, 256, 256, false, 0) { +class MyCanvas : public SkCanvas { +public: + MyCanvas(SkCanvas* c) : canvas(c) {} + void onDrawPicture(const SkPicture* picture, const SkMatrix* , + const SkPaint* ) override { + const SkRect rect = picture->cullRect(); + SkPaint redPaint; + redPaint.setColor(SK_ColorRED); + canvas->drawRect(rect, redPaint); + } + SkCanvas* canvas; +}; + +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + sk_sp placeholder = SkPicture::MakePlaceholder({10, 40, 80, 110}); + pictureCanvas->drawPicture(placeholder); + sk_sp picture = recorder.finishRecordingAsPicture(); + MyCanvas myCanvas(canvas); + myCanvas.drawPicture(picture); +} +} // END FIDDLE diff --git a/docs/examples/Picture_010.cpp b/docs/examples/Picture_010.cpp new file mode 100644 index 0000000000..c8c55d9f99 --- /dev/null +++ b/docs/examples/Picture_010.cpp @@ -0,0 +1,20 @@ +#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 "fiddle/examples.h" +// HASH=4b3d879118ef770d1f11a23c6493b2c4 +REG_FIDDLE(Picture_010, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + picture->playback(canvas); + std::string opCount = "approximate op count: " + std::to_string(picture->approximateOpCount()); + canvas->drawString(opCount.c_str(), 50, 220, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Picture_011.cpp b/docs/examples/Picture_011.cpp new file mode 100644 index 0000000000..39ac1ed6f2 --- /dev/null +++ b/docs/examples/Picture_011.cpp @@ -0,0 +1,20 @@ +#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 "fiddle/examples.h" +// HASH=ececbda21218bd732394a305dba393a2 +REG_FIDDLE(Picture_011, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPictureRecorder recorder; + SkCanvas* pictureCanvas = recorder.beginRecording({0, 0, 256, 256}); + SkPaint paint; + pictureCanvas->drawRect(SkRect::MakeWH(200, 200), paint); + paint.setColor(SK_ColorWHITE); + pictureCanvas->drawRect(SkRect::MakeLTRB(20, 20, 180, 180), paint); + sk_sp picture = recorder.finishRecordingAsPicture(); + picture->playback(canvas); + std::string opCount = "approximate bytes used: " + std::to_string(picture->approximateBytesUsed()); + canvas->drawString(opCount.c_str(), 20, 220, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Pixmap_000.cpp b/docs/examples/Pixmap_000.cpp new file mode 100644 index 0000000000..bcdf00fe5b --- /dev/null +++ b/docs/examples/Pixmap_000.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=9547e74a9d37553a667b913ffd1312dd +REG_FIDDLE(Pixmap_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkPixmap pixmap; + for (int i = 0; i < 2; ++i) { + SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height()); + SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]); + SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]); + pixmap.reset(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType), + nullptr, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_001.cpp b/docs/examples/Pixmap_001.cpp new file mode 100644 index 0000000000..0df9717ec3 --- /dev/null +++ b/docs/examples/Pixmap_001.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=9a00774be57d7308313b3a9073e6e696 +REG_FIDDLE(Pixmap_001, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + SkDebugf("image alpha only = %s\n", image->isAlphaOnly() ? "true" : "false"); + SkPMColor pmColors = 0; + sk_sp copy = SkImage::MakeRasterCopy({SkImageInfo::MakeA8(1, 1), + (uint8_t*)&pmColors, + 1}); + SkDebugf("copy alpha only = %s\n", copy->isAlphaOnly() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_002.cpp b/docs/examples/Pixmap_002.cpp new file mode 100644 index 0000000000..9a13d3e74e --- /dev/null +++ b/docs/examples/Pixmap_002.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=d9eb583c39f4f0baea79896b89245c98 +REG_FIDDLE(Pixmap_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkPixmap pixmap(SkImageInfo::Make(25, 35, kRGBA_8888_SkColorType, kOpaque_SkAlphaType), + nullptr, 0); + for (int i = 0; i < 2; ++i) { + SkDebugf("width: %2d height: %2d", pixmap.width(), pixmap.height()); + SkDebugf(" color: k%s_SkColorType", colors[pixmap.colorType()]); + SkDebugf(" alpha: k%s_SkAlphaType\n", alphas[pixmap.alphaType()]); + pixmap.reset(); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_003.cpp b/docs/examples/Pixmap_003.cpp new file mode 100644 index 0000000000..225b59832d --- /dev/null +++ b/docs/examples/Pixmap_003.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=9a392b753167cfa849cebeefd5a6e07d +REG_FIDDLE(Pixmap_003, 256, 64, false, 4) { +void draw(SkCanvas* canvas) { + std::vector pixels; + pixels.resize(image->height() * image->width() * 4); + SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, + image->alphaType()), (const void*) &pixels.front(), image->width() * 4); + image->readPixels(pixmap, 0, 0); + int x = 0; + for (auto colorType : { kRGBA_8888_SkColorType, kBGRA_8888_SkColorType } ) { + pixmap.reset(SkImageInfo::Make(image->width(), image->height(), colorType, + image->alphaType()), (const void*) &pixels.front(), image->width() * 4); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, x, 0); + x += 128; + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_004.cpp b/docs/examples/Pixmap_004.cpp new file mode 100644 index 0000000000..0b9ee535cd --- /dev/null +++ b/docs/examples/Pixmap_004.cpp @@ -0,0 +1,16 @@ +#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 "fiddle/examples.h" +// HASH=30d70aec4de17c831dba71e03dc9664a +REG_FIDDLE(Pixmap_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPixmap pixmap; + sk_sp colorSpace1 = SkColorSpace::MakeRGB(SkColorSpace::kLinear_RenderTargetGamma, + SkColorSpace::kRec2020_Gamut); + SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not "); + pixmap.setColorSpace(colorSpace1); + SkDebugf("is %sunique\n", colorSpace1->unique() ? "" : "not "); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Pixmap_005.cpp b/docs/examples/Pixmap_005.cpp new file mode 100644 index 0000000000..a1e2525b48 --- /dev/null +++ b/docs/examples/Pixmap_005.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=febdbfac6cf4cde69837643be2e1f6dd +REG_FIDDLE(Pixmap_005, 256, 128, false, 3) { +void draw(SkCanvas* canvas) { + std::vector pixels; + pixels.resize(image->height() * image->width() * 4); + SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, + image->alphaType()), (const void*) &pixels.front(), image->width() * 4); + image->readPixels(pixmap, 0, 0); + SkPixmap inset; + if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) { + SkBitmap bitmap; + bitmap.installPixels(inset); + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_006.cpp b/docs/examples/Pixmap_006.cpp new file mode 100644 index 0000000000..5a33bc0248 --- /dev/null +++ b/docs/examples/Pixmap_006.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=6e0f558bf7fabc655041116288559134 +REG_FIDDLE(Pixmap_006, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + std::vector pixels; + pixels.resize(image->height() * image->width() * 4); + SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, + image->alphaType()), (const void*) &pixels.front(), image->width() * 4); + image->readPixels(pixmap, 0, 0); + SkPixmap inset; + if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) { + const SkImageInfo& info = inset.info(); + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", + "RGB_888x", "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkDebugf("width: %d height: %d color: %s alpha: %s\n", info.width(), info.height(), + colors[info.colorType()], alphas[info.alphaType()]); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_007.cpp b/docs/examples/Pixmap_007.cpp new file mode 100644 index 0000000000..b8fb048345 --- /dev/null +++ b/docs/examples/Pixmap_007.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=19ac8bb81854680bd408fec8cb797d5c +REG_FIDDLE(Pixmap_007, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPixmap badPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 2}; + SkPixmap okPixmap = {SkImageInfo::MakeA8(4, 4), nullptr, 8}; + for (auto& pixmap : { badPixmap, okPixmap } ) { + SkDebugf("rowBytes: %d minRowBytes: %d\n", pixmap.rowBytes(), + pixmap.info().minRowBytes()); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_008.cpp b/docs/examples/Pixmap_008.cpp new file mode 100644 index 0000000000..a9031c0f4e --- /dev/null +++ b/docs/examples/Pixmap_008.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=17bcabaaee2dbb7beba562e9ca50b55e +REG_FIDDLE(Pixmap_008, 256, 256, true, 3) { +void draw(SkCanvas* canvas) { + std::vector pixels; + pixels.resize(image->height() * image->width() * 4); + SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, + image->alphaType()), (const void*) &pixels.front(), image->width() * 4); + image->readPixels(pixmap, 0, 0); + SkDebugf("pixels address: 0x%llx\n", pixmap.addr()); + SkPixmap inset; + if (pixmap.extractSubset(&inset, {128, 128, 512, 512})) { + SkDebugf("inset address: 0x%llx\n", inset.addr()); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_009.cpp b/docs/examples/Pixmap_009.cpp new file mode 100644 index 0000000000..987a678068 --- /dev/null +++ b/docs/examples/Pixmap_009.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=f68617b7153a20b2ed3d7f9ed5c6e5e4 +REG_FIDDLE(Pixmap_009, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeA8(16, 32); + SkPixmap pixmap(info, nullptr, 64); + SkDebugf("pixmap width: %d info width: %d\n", pixmap.width(), info.width()); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_010.cpp b/docs/examples/Pixmap_010.cpp new file mode 100644 index 0000000000..9a648ded66 --- /dev/null +++ b/docs/examples/Pixmap_010.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=4a996d32122f469d51ddd0186efb48cc +REG_FIDDLE(Pixmap_010, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); + SkDebugf("pixmap height: %d info height: %d\n", pixmap.height(), pixmap.info().height()); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_011.cpp b/docs/examples/Pixmap_011.cpp new file mode 100644 index 0000000000..591f926215 --- /dev/null +++ b/docs/examples/Pixmap_011.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=0ab5c7af272685f2ce177cc79e6b9457 +REG_FIDDLE(Pixmap_011, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* colors[] = {"Unknown", "Alpha_8", "RGB_565", "ARGB_4444", "RGBA_8888", "RGB_888x", + "BGRA_8888", "RGBA_1010102", "RGB_101010x", "Gray_8", "RGBA_F16Norm", + "RGBA_F16"}; + SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); + SkDebugf("color type: k" "%s" "_SkColorType\n", colors[pixmap.colorType()]); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_012.cpp b/docs/examples/Pixmap_012.cpp new file mode 100644 index 0000000000..8b29e28698 --- /dev/null +++ b/docs/examples/Pixmap_012.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=070b1a60232be499eb10c6ea62371804 +REG_FIDDLE(Pixmap_012, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* alphas[] = {"Unknown", "Opaque", "Premul", "Unpremul"}; + SkPixmap pixmap(SkImageInfo::MakeA8(16, 32), nullptr, 64); + SkDebugf("alpha type: k" "%s" "_SkAlphaType\n", alphas[pixmap.alphaType()]); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_013.cpp b/docs/examples/Pixmap_013.cpp new file mode 100644 index 0000000000..4671266a8a --- /dev/null +++ b/docs/examples/Pixmap_013.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=3421bb20a302d563832ba7bb45e0cc58 +REG_FIDDLE(Pixmap_013, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPixmap pixmap(SkImageInfo::MakeN32(16, 32, kPremul_SkAlphaType, + SkColorSpace::MakeSRGBLinear()), nullptr, 64); + SkColorSpace* colorSpace = pixmap.colorSpace(); + SkDebugf("gammaCloseToSRGB: %s gammaIsLinear: %s isSRGB: %s\n", + colorSpace->gammaCloseToSRGB() ? "true" : "false", + colorSpace->gammaIsLinear() ? "true" : "false", + colorSpace->isSRGB() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_014.cpp b/docs/examples/Pixmap_014.cpp new file mode 100644 index 0000000000..63d4060859 --- /dev/null +++ b/docs/examples/Pixmap_014.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=efd083f121e888a523455ea8a49e50d1 +REG_FIDDLE(Pixmap_014, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + std::vector pixels; + const int height = 2; + const int width = 2; + pixels.resize(height * width * 4); + SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType, + kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4); + for (int index = 0; index < 2; ++index) { + pixmap.erase(0x00000000); + SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false"); + pixmap.erase(0xFFFFFFFF); + SkDebugf("isOpaque: %s\n", pixmap.isOpaque() ? "true" : "false"); + pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType), + (const void*) &pixels.front(), width * 4); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_015.cpp b/docs/examples/Pixmap_015.cpp new file mode 100644 index 0000000000..459c3539ad --- /dev/null +++ b/docs/examples/Pixmap_015.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=79750fb1d898a4e5c8c828b7bc9acec5 +REG_FIDDLE(Pixmap_015, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + for (int width : { 0, 2 } ) { + for (int height : { 0, 2 } ) { + SkPixmap pixmap(SkImageInfo::MakeA8(width, height), nullptr, width); + SkDebugf("width: %d height: %d empty: %s\n", width, height, + pixmap.bounds().isEmpty() ? "true" : "false"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_016.cpp b/docs/examples/Pixmap_016.cpp new file mode 100644 index 0000000000..2fa2baa7de --- /dev/null +++ b/docs/examples/Pixmap_016.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=6231bb212d0c231b5bc44eac626fbcb5 +REG_FIDDLE(Pixmap_016, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + for (int rowBytes : { 4, 5, 6, 7, 8} ) { + SkPixmap pixmap(SkImageInfo::MakeN32(1, 1, kPremul_SkAlphaType), nullptr, rowBytes); + SkDebugf("rowBytes: %d rowBytesAsPixels: %d\n", rowBytes, pixmap.rowBytesAsPixels()); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_017.cpp b/docs/examples/Pixmap_017.cpp new file mode 100644 index 0000000000..8ebdd5ace5 --- /dev/null +++ b/docs/examples/Pixmap_017.cpp @@ -0,0 +1,36 @@ +// 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 "fiddle/examples.h" +// HASH=bf31ee140e2c163c3957276e6d4c4f0c +REG_FIDDLE(Pixmap_017, 256, 256, true, 0) { +const char* color_type(SkColorType ct) { + switch (ct) { + case kUnknown_SkColorType: return "Unknown"; + case kAlpha_8_SkColorType: return "Alpha_8"; + case kRGB_565_SkColorType: return "RGB_565"; + case kARGB_4444_SkColorType: return "ARGB_4444"; + case kRGBA_8888_SkColorType: return "RGBA_8888"; + case kRGB_888x_SkColorType: return "RGB_888x"; + case kBGRA_8888_SkColorType: return "BGRA_8888"; + case kRGBA_1010102_SkColorType: return "RGBA_1010102"; + case kRGB_101010x_SkColorType: return "RGB_101010x"; + case kGray_8_SkColorType: return "Gray_8"; + case kRGBA_F16Norm_SkColorType: return "RGBA_F16Norm"; + case kRGBA_F16_SkColorType: return "RGBA_F16"; + case kRGBA_F32_SkColorType: return "RGBA_F32"; + default: SkASSERT(false); return nullptr; + } +} +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeA8(1, 1); + for (SkColorType colorType : { kUnknown_SkColorType, kAlpha_8_SkColorType, + kRGB_565_SkColorType, kARGB_4444_SkColorType, + kRGBA_8888_SkColorType, kBGRA_8888_SkColorType, + kGray_8_SkColorType, kRGBA_F16_SkColorType } ) { + SkPixmap pixmap(info.makeColorType(colorType), nullptr, 4); + SkDebugf("color: k" "%s" "_SkColorType" "%*s" "bytesPerPixel: %d shiftPerPixel: %d\n", + color_type(colorType), 10 - strlen(color_type(colorType)), " ", + pixmap.info().bytesPerPixel(), pixmap.shiftPerPixel()); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_018.cpp b/docs/examples/Pixmap_018.cpp new file mode 100644 index 0000000000..6f56de24f3 --- /dev/null +++ b/docs/examples/Pixmap_018.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=410d14ddc45d272598c5a4e52bb047de +REG_FIDDLE(Pixmap_018, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPixmap pixmap; + for (int width : { 1, 1000, 1000000 } ) { + for (int height: { 1, 1000, 1000000 } ) { + SkImageInfo imageInfo = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType); + pixmap.reset(imageInfo, nullptr, width * 5); + SkDebugf("width: %7d height: %7d computeByteSize: %13lld\n", width, height, + pixmap.computeByteSize()); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_019.cpp b/docs/examples/Pixmap_019.cpp new file mode 100644 index 0000000000..32482bd6aa --- /dev/null +++ b/docs/examples/Pixmap_019.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=6ef37d5be03d0bfaec992dbb5a94c66f +REG_FIDDLE(Pixmap_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + std::vector pixels; + const int height = 2; + const int width = 2; + pixels.resize(height * width * 4); + SkPixmap pixmap(SkImageInfo::Make(width, height, kN32_SkColorType, + kPremul_SkAlphaType), (const void*) &pixels.front(), width * 4); + for (int index = 0; index < 2; ++index) { + pixmap.erase(0x00000000); + SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false"); + pixmap.erase(0xFFFFFFFF); + SkDebugf("computeIsOpaque: %s\n", pixmap.computeIsOpaque() ? "true" : "false"); + pixmap.reset(pixmap.info().makeAlphaType(kOpaque_SkAlphaType), + (const void*) &pixels.front(), width * 4); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_020.cpp b/docs/examples/Pixmap_020.cpp new file mode 100644 index 0000000000..1d795f5070 --- /dev/null +++ b/docs/examples/Pixmap_020.cpp @@ -0,0 +1,29 @@ +// 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 "fiddle/examples.h" +// HASH=94ad244056dc80ecd87daae004266334 +REG_FIDDLE(Pixmap_020, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + std::vector storage; + storage.resize(w * h); + SkDebugf("Premultiplied:\n"); + for (int y = 0; y < h; ++y) { + SkDebugf("(0, %d) ", y); + for (int x = 0; x < w; ++x) { + int a = 0xFF * (x + y) / (w - 1 + h - 1); + storage[x + y * w] = SkPackARGB32(a, a * x / (w - 1), a * y / (h - 1), a); + SkDebugf("0x%08x%c", storage[x + y * w], x == w - 1 ? '\n' : ' '); + } + } + SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4); + SkDebugf("Unpremultiplied:\n"); + for (int y = 0; y < h; ++y) { + SkDebugf("(0, %d) ", y); + for (int x = 0; x < w; ++x) { + SkDebugf("0x%08x%c", pixmap.getColor(x, y), x == w - 1 ? '\n' : ' '); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_021.cpp b/docs/examples/Pixmap_021.cpp new file mode 100644 index 0000000000..aa393c8ee5 --- /dev/null +++ b/docs/examples/Pixmap_021.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=6e6e29e860eafed77308c973400cc84d +REG_FIDDLE(Pixmap_021, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + std::vector storage; + storage.resize(w * h); + SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), &storage.front(), w * 4); + SkDebugf("pixmap.addr(1, 2) %c= &storage[1 + 2 * w]\n", + pixmap.addr(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_022.cpp b/docs/examples/Pixmap_022.cpp new file mode 100644 index 0000000000..f716f0926b --- /dev/null +++ b/docs/examples/Pixmap_022.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=9adda80b2dd1b08ec5ccf66da7c8bd91 +REG_FIDDLE(Pixmap_022, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + uint8_t storage[w * h]; + SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType), + storage, w * sizeof(storage[0])); + SkDebugf("pixmap.addr8() %c= storage\n", + pixmap.addr8() == storage ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_023.cpp b/docs/examples/Pixmap_023.cpp new file mode 100644 index 0000000000..7e85e1ce20 --- /dev/null +++ b/docs/examples/Pixmap_023.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=9b16012d265c954c6de13f3fc960da52 +REG_FIDDLE(Pixmap_023, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + uint16_t storage[w * h]; + SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType), + storage, w * sizeof(storage[0])); + SkDebugf("pixmap.addr16() %c= storage\n", + pixmap.addr16() == storage ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_024.cpp b/docs/examples/Pixmap_024.cpp new file mode 100644 index 0000000000..b90cc16965 --- /dev/null +++ b/docs/examples/Pixmap_024.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=6b90c7ae9f254fe4ea9ef638f893a3e6 +REG_FIDDLE(Pixmap_024, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + uint32_t storage[w * h]; + SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), + storage, w * sizeof(storage[0])); + SkDebugf("pixmap.addr32() %c= storage\n", + pixmap.addr32() == storage ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_025.cpp b/docs/examples/Pixmap_025.cpp new file mode 100644 index 0000000000..b50378c7f8 --- /dev/null +++ b/docs/examples/Pixmap_025.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=0d17085a4698a8a2e2235fad9041b4b4 +REG_FIDDLE(Pixmap_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + uint64_t storage[w * h]; + SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), + storage, w * sizeof(storage[0])); + SkDebugf("pixmap.addr64() %c= storage\n", + pixmap.addr64() == storage ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_026.cpp b/docs/examples/Pixmap_026.cpp new file mode 100644 index 0000000000..7b96fff37d --- /dev/null +++ b/docs/examples/Pixmap_026.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=54e8525a592f05623c33b375aebc90c1 +REG_FIDDLE(Pixmap_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + uint16_t storage[w * h * 4]; + SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), + storage, w * 4 * sizeof(storage[0])); + SkDebugf("pixmap.addrF16() %c= storage\n", + pixmap.addrF16() == storage ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_027.cpp b/docs/examples/Pixmap_027.cpp new file mode 100644 index 0000000000..ce3f8eb1be --- /dev/null +++ b/docs/examples/Pixmap_027.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=5b986272268ef2c52045c1856f8b6107 +REG_FIDDLE(Pixmap_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + uint8_t storage[w * h]; + SkPixmap pixmap(SkImageInfo::Make(w, h, kGray_8_SkColorType, kPremul_SkAlphaType), + storage, w * sizeof(storage[0])); + SkDebugf("pixmap.addr8(1, 2) %c= &storage[1 + 2 * w]\n", + pixmap.addr8(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_028.cpp b/docs/examples/Pixmap_028.cpp new file mode 100644 index 0000000000..469d46d001 --- /dev/null +++ b/docs/examples/Pixmap_028.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=2c0c88a546d4ef093ab63ff72dac00b9 +REG_FIDDLE(Pixmap_028, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + uint16_t storage[w * h]; + SkPixmap pixmap(SkImageInfo::Make(w, h, kARGB_4444_SkColorType, kPremul_SkAlphaType), + storage, w * sizeof(storage[0])); + SkDebugf("pixmap.addr16(1, 2) %c= &storage[1 + 2 * w]\n", + pixmap.addr16(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_029.cpp b/docs/examples/Pixmap_029.cpp new file mode 100644 index 0000000000..eb59c7f270 --- /dev/null +++ b/docs/examples/Pixmap_029.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=12f8b5ce9fb25604f33df336677f5d62 +REG_FIDDLE(Pixmap_029, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + uint32_t storage[w * h]; + SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_8888_SkColorType, kPremul_SkAlphaType), + storage, w * sizeof(storage[0])); + SkDebugf("pixmap.addr32(1, 2) %c= &storage[1 + 2 * w]\n", + pixmap.addr32(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_030.cpp b/docs/examples/Pixmap_030.cpp new file mode 100644 index 0000000000..1ca459ea79 --- /dev/null +++ b/docs/examples/Pixmap_030.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=5449f65fd7673273b0b57807fd3117ff +REG_FIDDLE(Pixmap_030, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + uint64_t storage[w * h]; + SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), + storage, w * sizeof(storage[0])); + SkDebugf("pixmap.addr64(1, 2) %c= &storage[1 + 2 * w]\n", + pixmap.addr64(1, 2) == &storage[1 + 2 * w] ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_031.cpp b/docs/examples/Pixmap_031.cpp new file mode 100644 index 0000000000..0f4ccd56ed --- /dev/null +++ b/docs/examples/Pixmap_031.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=f6076cad455bc80af5d06eb121d3b6f2 +REG_FIDDLE(Pixmap_031, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + const int wordsPerPixel = 4; + const int rowWords = w * wordsPerPixel; + uint16_t storage[rowWords * h]; + SkPixmap pixmap(SkImageInfo::Make(w, h, kRGBA_F16_SkColorType, kPremul_SkAlphaType), + storage, rowWords * sizeof(storage[0])); + SkDebugf("pixmap.addrF16(1, 2) %c= &storage[1 * wordsPerPixel + 2 * rowWords]\n", + pixmap.addrF16(1, 2) == &storage[1 * wordsPerPixel + 2 * rowWords] ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_032.cpp b/docs/examples/Pixmap_032.cpp new file mode 100644 index 0000000000..090b82b494 --- /dev/null +++ b/docs/examples/Pixmap_032.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=74ef460f89ed5904334d0f8883e781c4 +REG_FIDDLE(Pixmap_032, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + SkPMColor storage[w * h * 4]; + SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4); + SkDebugf("pixmap.writable_addr() %c= (void *)storage\n", + pixmap.writable_addr() == (void *)storage ? '=' : '!'); + pixmap.erase(0x00000000); + *(SkPMColor*)pixmap.writable_addr() = 0xFFFFFFFF; + SkDebugf("pixmap.getColor(0, 1) %c= 0x00000000\n", + pixmap.getColor(0, 1) == 0x00000000 ? '=' : '!'); + SkDebugf("pixmap.getColor(0, 0) %c= 0xFFFFFFFF\n", + pixmap.getColor(0, 0) == 0xFFFFFFFF ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_033.cpp b/docs/examples/Pixmap_033.cpp new file mode 100644 index 0000000000..c739957a11 --- /dev/null +++ b/docs/examples/Pixmap_033.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=559eaca89c765bc8466ea1ba3331d4db +REG_FIDDLE(Pixmap_033, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int w = 4; + const int h = 4; + SkPMColor storage[w * h * 4]; + SkPixmap pixmap(SkImageInfo::MakeN32(w, h, kPremul_SkAlphaType), storage, w * 4); + SkDebugf("pixmap.writable_addr() %c= (void *)storage\n", + pixmap.writable_addr() == (void *)storage ? '=' : '!'); + pixmap.erase(0x00000000); + *(SkPMColor*)pixmap.writable_addr(1, 2) = 0xFFFFFFFF; + SkDebugf("pixmap.getColor(0, 0) %c= 0x00000000\n", + pixmap.getColor(0, 0) == 0x00000000 ? '=' : '!'); + SkDebugf("pixmap.getColor(1, 2) %c= 0xFFFFFFFF\n", + pixmap.getColor(1, 2) == 0xFFFFFFFF ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_034.cpp b/docs/examples/Pixmap_034.cpp new file mode 100644 index 0000000000..d3f0637ee2 --- /dev/null +++ b/docs/examples/Pixmap_034.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=809284db136748208b3efc31cd89de29 +REG_FIDDLE(Pixmap_034, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint8_t storage[][5] = {{ 0, 0, 64, 0, 0}, + { 0, 128, 255, 128, 0}, + {64, 255, 255, 255, 64}, + { 0, 128, 255, 128, 0}, + { 0, 0, 64, 0, 0}}; + SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kGray_8_SkColorType, kPremul_SkAlphaType); + SkPixmap pixmap(imageInfo, storage[0], 5); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->scale(10, 10); + canvas->drawBitmap(bitmap, 0, 0); + *pixmap.writable_addr8(2, 2) = 0; +// bitmap.installPixels(pixmap); // uncomment to fix on GPU + canvas->drawBitmap(bitmap, 10, 0); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_035.cpp b/docs/examples/Pixmap_035.cpp new file mode 100644 index 0000000000..c026a2978d --- /dev/null +++ b/docs/examples/Pixmap_035.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=6da54774f6432b46b47ea9013c15f280 +REG_FIDDLE(Pixmap_035, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + uint16_t storage[][5] = {{ 0xCABF, 0xDABE, 0xCA9D, 0xC96C, 0xA39B }, + { 0xACEE, 0xA87C, 0x893A, 0x4779, 0x8708 }, + { 0x4B7C, 0x255B, 0x2559, 0x2557, 0x4656 }, + { 0x9099, 0x8128, 0x2557, 0x4124, 0x3323 }, + { 0x7547, 0x5505, 0x4434, 0x2012, 0x0000 }}; + SkImageInfo imageInfo = SkImageInfo::Make(5, 5, kARGB_4444_SkColorType, kPremul_SkAlphaType); + SkPixmap pixmap(imageInfo, storage[0], sizeof(storage) / 5); + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->scale(10, 10); + canvas->drawBitmap(bitmap, 0, 0); + *pixmap.writable_addr16(2, 2) = 0x000F; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 10, 0); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_036.cpp b/docs/examples/Pixmap_036.cpp new file mode 100644 index 0000000000..cea073a7ec --- /dev/null +++ b/docs/examples/Pixmap_036.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=086866243bf9e4c14c3b215a2aa69ad9 +REG_FIDDLE(Pixmap_036, 256, 72, false, 4) { +void draw(SkCanvas* canvas) { + std::vector pixels; + pixels.resize(image->height() * image->width() * 4); + SkPixmap pixmap(SkImageInfo::Make(image->width(), image->height(), kN32_SkColorType, + image->alphaType()), (const void*) &pixels.front(), image->width() * 4); + image->readPixels(pixmap, 0, 0); + for (int y = 0; y < pixmap.height() / 2; ++y) { + for (int x = 0; x < pixmap.width(); ++x) { + if ((x & 4) == (y & 4)) { + *pixmap.writable_addr32(x, y) = + *pixmap.writable_addr32(pixmap.width() - x - 1, pixmap.height() - y - 1); + } + } + } + SkBitmap bitmap; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_037.cpp b/docs/examples/Pixmap_037.cpp new file mode 100644 index 0000000000..3d607464d7 --- /dev/null +++ b/docs/examples/Pixmap_037.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=de14d8d30e4a7b6462103d0e0dd96b0b +REG_FIDDLE(Pixmap_037, 256, 40, false, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::Make(3, 3, kRGBA_F16_SkColorType, kPremul_SkAlphaType); + uint64_t storage[9]; + SkPixmap pixmap(info, storage, 3 * sizeof(uint64_t)); + SkColor4f c4 { 1, 0.45f, 0.25f, 0.65f }; + pixmap.erase(c4); + SkBitmap bitmap; + canvas->scale(10, 10); + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); + *pixmap.writable_addr64(1, 1) |= 0x00ff000000000000LL; + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 10, 0); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_038.cpp b/docs/examples/Pixmap_038.cpp new file mode 100644 index 0000000000..5e1da9ee7f --- /dev/null +++ b/docs/examples/Pixmap_038.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=7822d78f5cacf5c04267cbbc6c6d0b80 +REG_FIDDLE(Pixmap_038, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::Make(1, 2, kRGBA_F16_SkColorType, kPremul_SkAlphaType); + uint16_t storage[2][4]; + SkPixmap pixmap(info, storage[0], sizeof(uint64_t)); + SkIRect topPixelBounds = {0, 0, 1, 1}; + pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds); + SkIRect bottomPixelBounds = {0, 1, 1, 2}; + pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds); + SkBitmap bitmap; + canvas->scale(20, 20); + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); + uint16_t* pixel2 = pixmap.writable_addrF16(0, 1); + for (int i = 0; i < 4; ++i) { + pixel2[i] = storage[0][i]; + } + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 4, 0); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_039.cpp b/docs/examples/Pixmap_039.cpp new file mode 100644 index 0000000000..84a51d245e --- /dev/null +++ b/docs/examples/Pixmap_039.cpp @@ -0,0 +1,31 @@ +// 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 "fiddle/examples.h" +// HASH=df4e355c4845350daede833b4fd21ec1 +REG_FIDDLE(Pixmap_039, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + std::vector pixels; + const int width = 256; + const int height = 64; + pixels.resize(height * width * 4); + SkImageInfo srcInfo = SkImageInfo::MakeN32Premul(width, height); + SkPixmap srcPixmap(srcInfo, (const void*) &pixels.front(), width * 4); + SkColor gradColors[] = { 0xFFAA3300, 0x7F881122 }; + SkPoint gradPoints[] = { { 0, 0 }, { 256, 0 } }; + SkPaint paint; + paint.setShader(SkGradientShader::MakeLinear(gradPoints, gradColors, nullptr, + SK_ARRAY_COUNT(gradColors), SkShader::kClamp_TileMode)); + SkBitmap bitmap; + bitmap.installPixels(srcPixmap); + SkCanvas srcCanvas(bitmap); + srcCanvas.drawRect(SkRect::MakeWH(width, height), paint); + canvas->drawBitmap(bitmap, 0, 0); + std::vector dstPixels; + dstPixels.resize(height * width * 2); + SkImageInfo dstInfo = srcInfo.makeColorType(kARGB_4444_SkColorType); + srcPixmap.readPixels(dstInfo, &dstPixels.front(), width * 2); + SkPixmap dstPixmap(dstInfo, &dstPixels.front(), width * 2); + bitmap.installPixels(dstPixmap); + canvas->drawBitmap(bitmap, 0, 128); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_040.cpp b/docs/examples/Pixmap_040.cpp new file mode 100644 index 0000000000..2bd656c08f --- /dev/null +++ b/docs/examples/Pixmap_040.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=094ca0bd37588cc7be241bb387a3e17b +REG_FIDDLE(Pixmap_040, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); + std::vector srcPixels; + const int rowBytes = image->width() * 4; + srcPixels.resize(image->height() * rowBytes); + SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); + image->readPixels(pixmap, 0, 0); + for (int offset : { 32, 64, 96 } ) { + std::vector dstPixels; + dstPixels.resize(image->height() * rowBytes); + pixmap.readPixels(info, &dstPixels.front(), rowBytes, offset, 0); + SkBitmap bitmap; + SkPixmap dstmap(info, &dstPixels.front(), rowBytes); + bitmap.installPixels(dstmap); + canvas->translate(32, 32); + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_041.cpp b/docs/examples/Pixmap_041.cpp new file mode 100644 index 0000000000..21d9a3482c --- /dev/null +++ b/docs/examples/Pixmap_041.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=6ec7f7b2cc163cd29f627eef6d4b061c +REG_FIDDLE(Pixmap_041, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); + std::vector srcPixels; + const int rowBytes = image->width() * 4; + srcPixels.resize(image->height() * rowBytes); + SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); + image->readPixels(pixmap, 0, 0); + for (int offset : { 32, 64, 96 } ) { + std::vector dstPixels; + dstPixels.resize(image->height() * rowBytes); + SkPixmap dstmap(info, &dstPixels.front(), rowBytes); + pixmap.readPixels(dstmap, offset, 0); + SkBitmap bitmap; + bitmap.installPixels(dstmap); + canvas->translate(32, 32); + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_042.cpp b/docs/examples/Pixmap_042.cpp new file mode 100644 index 0000000000..8fda3d0390 --- /dev/null +++ b/docs/examples/Pixmap_042.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=e18549b5ee1039cb61b0bb38c2104fc9 +REG_FIDDLE(Pixmap_042, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); + std::vector srcPixels; + const int rowBytes = image->width() * 4; + srcPixels.resize(image->height() * rowBytes); + SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); + image->readPixels(pixmap, 0, 0); + for (int index = 0; index < 3; ++index ) { + std::vector dstPixels; + dstPixels.resize(image->height() * rowBytes); + SkPixmap dstmap(info, &dstPixels.front(), rowBytes); + pixmap.readPixels(dstmap); + SkBitmap bitmap; + bitmap.installPixels(dstmap); + canvas->translate(32, 32); + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_043.cpp b/docs/examples/Pixmap_043.cpp new file mode 100644 index 0000000000..c6f18eb186 --- /dev/null +++ b/docs/examples/Pixmap_043.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=8e3c8a9c1d0d2e9b8bf66e24d274f792 +REG_FIDDLE(Pixmap_043, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkImageInfo info = SkImageInfo::MakeN32Premul(image->width(), image->height()); + std::vector srcPixels; + int rowBytes = image->width() * 4; + srcPixels.resize(image->height() * rowBytes); + SkPixmap pixmap(info, (const void*) &srcPixels.front(), rowBytes); + image->readPixels(pixmap, 0, 0); + for (int offset : { 32, 64, 96 } ) { + info = SkImageInfo::MakeN32Premul(image->width() + offset, image->height()); + rowBytes = info.width() * 4; + std::vector dstPixels; + dstPixels.resize(image->height() * rowBytes); + SkPixmap dstmap(info, &dstPixels.front(), rowBytes); + pixmap.scalePixels(dstmap, kMedium_SkFilterQuality); + SkBitmap bitmap; + bitmap.installPixels(dstmap); + canvas->translate(32, 32); + canvas->drawBitmap(bitmap, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_044.cpp b/docs/examples/Pixmap_044.cpp new file mode 100644 index 0000000000..64b9c79982 --- /dev/null +++ b/docs/examples/Pixmap_044.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=a0cdbafed4786788cc90681e7b294234 +REG_FIDDLE(Pixmap_044, 256, 50, false, 0) { +void draw(SkCanvas* canvas) { + uint32_t storage[2]; + SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2); + SkPixmap pixmap(info, storage, info.minRowBytes()); + pixmap.erase(SK_ColorBLUE, {0, 0, 1, 1}); + pixmap.erase(SK_ColorRED, {0, 1, 1, 2}); + SkBitmap bitmap; + canvas->scale(20, 20); + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_045.cpp b/docs/examples/Pixmap_045.cpp new file mode 100644 index 0000000000..8d2c5b4696 --- /dev/null +++ b/docs/examples/Pixmap_045.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=838202e0d49cad2eb3eeb495834f6d63 +REG_FIDDLE(Pixmap_045, 256, 50, false, 0) { +void draw(SkCanvas* canvas) { + uint32_t storage[2]; + SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2); + SkPixmap pixmap(info, storage, info.minRowBytes()); + pixmap.erase(SK_ColorBLUE); + SkBitmap bitmap; + canvas->scale(20, 20); + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Pixmap_046.cpp b/docs/examples/Pixmap_046.cpp new file mode 100644 index 0000000000..faa333b414 --- /dev/null +++ b/docs/examples/Pixmap_046.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=f884f3f46a565f052a5e252ae2f36e9b +REG_FIDDLE(Pixmap_046, 256, 50, false, 0) { +void draw(SkCanvas* canvas) { + uint32_t storage[2]; + SkImageInfo info = SkImageInfo::MakeN32Premul(1, 2); + SkPixmap pixmap(info, storage, info.minRowBytes()); + SkIRect topPixelBounds = {0, 0, 1, 1}; + pixmap.erase({ 0.65f, 0.45f, 0.25f, 1 }, &topPixelBounds); + SkIRect bottomPixelBounds = {0, 1, 1, 2}; + pixmap.erase({ 0.25f, 0.65f, 0.45f, 1 }, &bottomPixelBounds); + SkBitmap bitmap; + canvas->scale(20, 20); + bitmap.installPixels(pixmap); + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Point_000.cpp b/docs/examples/Point_000.cpp new file mode 100644 index 0000000000..209721dde0 --- /dev/null +++ b/docs/examples/Point_000.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=d266e70977847001f7c42f8a2513bee7 +REG_FIDDLE(Point_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint pt1 = {45, 66}; + SkPoint pt2 = SkPoint::Make(45, 66); + SkVector v1 = {45, 66}; + SkVector v2 = SkPoint::Make(45, 66); + SkDebugf("all %s" "equal\n", pt1 == pt2 && pt2 == v1 && v1 == v2 ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Point_001.cpp b/docs/examples/Point_001.cpp new file mode 100644 index 0000000000..32dbbd1d55 --- /dev/null +++ b/docs/examples/Point_001.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=9f3fe446b800ae1d940785d438634941 +REG_FIDDLE(Point_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint pt1 = {45, 66}; + SkDebugf("pt1.fX %c= pt1.x()\n", pt1.fX == pt1.x() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Point_002.cpp b/docs/examples/Point_002.cpp new file mode 100644 index 0000000000..8141026dac --- /dev/null +++ b/docs/examples/Point_002.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=4c962850c2dbea4d2325df469400680e +REG_FIDDLE(Point_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint pt1 = {45, 66}; + SkDebugf("pt1.fY %c= pt1.y()\n", pt1.fY == pt1.y() ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Point_003.cpp b/docs/examples/Point_003.cpp new file mode 100644 index 0000000000..ec084243bb --- /dev/null +++ b/docs/examples/Point_003.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=81b9665110b88ef6bcbc20464aed7da1 +REG_FIDDLE(Point_003, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint pt = { 0.f, -0.f}; + SkDebugf("pt.fX=%c%g pt.fY=%c%g\n", std::signbit(pt.fX) ? '-' : '+', fabsf(pt.fX), + std::signbit(pt.fY) ? '-' : '+', fabsf(pt.fY)); + SkDebugf("pt.isZero() == %s\n", pt.isZero() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Point_004.cpp b/docs/examples/Point_004.cpp new file mode 100644 index 0000000000..36e7c67450 --- /dev/null +++ b/docs/examples/Point_004.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=d08d1e7dafcad4342d1619fdbb2f5781 +REG_FIDDLE(Point_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint pt1, pt2 = { SK_ScalarPI, SK_ScalarSqrt2 }; + pt1.set(SK_ScalarPI, SK_ScalarSqrt2); + SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Point_005.cpp b/docs/examples/Point_005.cpp new file mode 100644 index 0000000000..b95ad76aa3 --- /dev/null +++ b/docs/examples/Point_005.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=0d9e8ed734981b5b113f22c7bfde5357 +REG_FIDDLE(Point_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint pt1, pt2 = { SK_MinS16, SK_MaxS16 }; + pt1.iset(SK_MinS16, SK_MaxS16); + SkDebugf("pt1 %c= pt2\n", pt1 == pt2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Point_006.cpp b/docs/examples/Point_006.cpp new file mode 100644 index 0000000000..1108039d38 --- /dev/null +++ b/docs/examples/Point_006.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=12b7164a769e232bb772f19c59600ee7 +REG_FIDDLE(Point_006, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIPoint iPt = { SK_MinS32, SK_MaxS32 }; + SkPoint fPt; + fPt.iset(iPt); + SkDebugf("iPt: %d, %d\n", iPt.fX, iPt.fY); + SkDebugf("fPt: %g, %g\n", fPt.fX, fPt.fY); +} +} // END FIDDLE diff --git a/docs/examples/Point_007.cpp b/docs/examples/Point_007.cpp new file mode 100644 index 0000000000..e03bf07f10 --- /dev/null +++ b/docs/examples/Point_007.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=7f70860e820b67a347cff03c00488426 +REG_FIDDLE(Point_007, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint test[] = { {0.f, -0.f}, {-1, -2}, + { SK_ScalarInfinity, SK_ScalarNegativeInfinity }, + { SK_ScalarNaN, -SK_ScalarNaN } }; + for (const SkPoint& pt : test) { + SkPoint absPt; + absPt.setAbs(pt); + SkDebugf("pt: %g, %g abs: %g, %g\n", pt.fX, pt.fY, absPt.fX, absPt.fY); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_008.cpp b/docs/examples/Point_008.cpp new file mode 100644 index 0000000000..3f0d052376 --- /dev/null +++ b/docs/examples/Point_008.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=f0f24726df78a5d797bcf311e694a0a3 +REG_FIDDLE(Point_008, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + { 6, 4 }, { 7, 5 }, { 5, 7 }, + { 4, 6 }, { 3, 7 }, { 1, 5 }, + { 2, 4 }, { 1, 3 }, { 3, 1 } }; + canvas->scale(30, 15); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); + SkPoint::Offset(points, SK_ARRAY_COUNT(points), { 1, 9 } ); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); +} +} // END FIDDLE diff --git a/docs/examples/Point_009.cpp b/docs/examples/Point_009.cpp new file mode 100644 index 0000000000..564cabfa8e --- /dev/null +++ b/docs/examples/Point_009.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=532849faa838de885b86d3ebffae3712 +REG_FIDDLE(Point_009, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + { 6, 4 }, { 7, 5 }, { 5, 7 }, + { 4, 6 }, { 3, 7 }, { 1, 5 }, + { 2, 4 }, { 1, 3 }, { 3, 1 } }; + canvas->scale(30, 15); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); + SkPoint::Offset(points, SK_ARRAY_COUNT(points), 1, 9); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); +} +} // END FIDDLE diff --git a/docs/examples/Point_010.cpp b/docs/examples/Point_010.cpp new file mode 100644 index 0000000000..496dbf0ea0 --- /dev/null +++ b/docs/examples/Point_010.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=02750ceaa874f956e6e6544ef6b858ee +REG_FIDDLE(Point_010, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + { 6, 4 }, { 7, 5 }, { 5, 7 }, + { 4, 6 }, { 3, 7 }, { 1, 5 }, + { 2, 4 }, { 1, 3 }, { 3, 1 } }; + canvas->scale(30, 15); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); + points[1].offset(1, 1); + paint.setColor(SK_ColorRED); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); +} +} // END FIDDLE diff --git a/docs/examples/Point_011.cpp b/docs/examples/Point_011.cpp new file mode 100644 index 0000000000..514e807277 --- /dev/null +++ b/docs/examples/Point_011.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=8363ab179447ee4b827679e20d3d81eb +REG_FIDDLE(Point_011, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const SkPoint points[] = { { 90, 30 }, { 120, 150 }, { 150, 30 }, { 210, 90 } }; + const SkPoint origin = {30, 140}; + for (auto point : points) { + canvas->drawLine(origin, point, paint); + SkAutoCanvasRestore acr(canvas, true); + SkScalar angle = SkScalarATan2((point.fY - origin.fY), point.fX - origin.fX); + canvas->rotate(angle * 180 / SK_ScalarPI, origin.fX, origin.fY); + SkString length("length = "); + length.appendScalar(point.length()); + canvas->drawString(length, origin.fX + 25, origin.fY - 4, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Point_012.cpp b/docs/examples/Point_012.cpp new file mode 100644 index 0000000000..11a6f7ff22 --- /dev/null +++ b/docs/examples/Point_012.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=812cf26d91b1cdcd2c6b9438a8172518 +REG_FIDDLE(Point_012, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } }; + const SkPoint origin = {0, 0}; + canvas->translate(30, 140); + for (auto point : points) { + canvas->drawLine(origin, point, paint); + SkAutoCanvasRestore acr(canvas, true); + SkScalar angle = SkScalarATan2((point.fY - origin.fY), point.fX - origin.fX); + canvas->rotate(angle * 180 / SK_ScalarPI, origin.fX, origin.fY); + SkString distance("distance = "); + distance.appendScalar(point.distanceToOrigin()); + canvas->drawString(distance, origin.fX + 25, origin.fY - 4, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Point_013.cpp b/docs/examples/Point_013.cpp new file mode 100644 index 0000000000..f060803112 --- /dev/null +++ b/docs/examples/Point_013.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=d84fce292d86c7d9ef37ae2d179c03c7 +REG_FIDDLE(Point_013, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const SkPoint lines[][2] = { {{ 30, 110 }, { 190, 30 }}, + {{ 120, 140 }, { 30, 220 }}}; + for (auto line : lines) { + canvas->drawLine(line[0], line[1], paint); + SkVector vector = line[1] - line[0]; + if (vector.normalize()) { + SkVector rotate90 = { -vector.fY, vector.fX }; + rotate90 *= 10.f; + canvas->drawLine(line[0] - rotate90, line[0] + rotate90, paint); + canvas->drawLine(line[1] - rotate90, line[1] + rotate90, paint); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Point_014.cpp b/docs/examples/Point_014.cpp new file mode 100644 index 0000000000..d75f31a390 --- /dev/null +++ b/docs/examples/Point_014.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=3e4f147d143a388802484bf0d26534c2 +REG_FIDDLE(Point_014, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } }; + const SkPoint origin = {0, 0}; + canvas->translate(30, 140); + for (auto point : points) { + paint.setStrokeWidth(1); + paint.setColor(SK_ColorBLACK); + canvas->drawLine(origin, point, paint); + SkVector normal; + normal.setNormalize(point.fX, point.fY); + normal *= 100; + paint.setStrokeWidth(10); + paint.setColor(0x3f4512bf); + canvas->drawLine(origin, normal, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_015.cpp b/docs/examples/Point_015.cpp new file mode 100644 index 0000000000..35c488965e --- /dev/null +++ b/docs/examples/Point_015.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=cbe7db206ece825aa3b9b7c3256aeaf0 +REG_FIDDLE(Point_015, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } }; + const SkPoint origin = {0, 0}; + canvas->translate(30, 140); + for (auto point : points) { + paint.setStrokeWidth(1); + paint.setColor(SK_ColorBLACK); + canvas->drawLine(origin, point, paint); + SkVector normal = point; + normal.setLength(100); + paint.setStrokeWidth(10); + paint.setColor(0x3f45bf12); + canvas->drawLine(origin, normal, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_016.cpp b/docs/examples/Point_016.cpp new file mode 100644 index 0000000000..7bb024181f --- /dev/null +++ b/docs/examples/Point_016.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=3cc0662b6fbbee1fe3442a0acfece22c +REG_FIDDLE(Point_016, 256, 160, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const SkPoint points[] = { { 60, -110 }, { 90, 10 }, { 120, -110 }, { 180, -50 } }; + const SkPoint origin = {0, 0}; + canvas->translate(30, 140); + for (auto point : points) { + paint.setStrokeWidth(1); + paint.setColor(SK_ColorBLACK); + canvas->drawLine(origin, point, paint); + SkVector normal; + normal.setLength(point.fX, point.fY, 100); + paint.setStrokeWidth(10); + paint.setColor(0x3fbf4512); + canvas->drawLine(origin, normal, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_017.cpp b/docs/examples/Point_017.cpp new file mode 100644 index 0000000000..c78beb9ae3 --- /dev/null +++ b/docs/examples/Point_017.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=972e4e230806281adb928e068bcd8551 +REG_FIDDLE(Point_017, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint point = {40, -15}, scaled; + SkPoint origin = {30, 110}; + for (auto scale : {1, 2, 3, 5}) { + paint.setStrokeWidth(scale * 5); + paint.setARGB(0x7f, 0x9f, 0xbf, 0x33 * scale); + point.scale(scale, &scaled); + canvas->drawLine(origin, origin + scaled, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_018.cpp b/docs/examples/Point_018.cpp new file mode 100644 index 0000000000..f7fc6fd252 --- /dev/null +++ b/docs/examples/Point_018.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=1060a4f27d8ef29519e6ac006ce90f2b +REG_FIDDLE(Point_018, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint point = {40, -15}; + SkPoint origin = {30, 110}; + for (auto scale : {1, 2, 3, 5}) { + paint.setStrokeWidth(scale * 5); + paint.setARGB(0x7f, 0x9f, 0xbf, 0x33 * scale); + point.scale(scale); + canvas->drawLine(origin, origin + point, paint); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_019.cpp b/docs/examples/Point_019.cpp new file mode 100644 index 0000000000..387399ddd5 --- /dev/null +++ b/docs/examples/Point_019.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=312c0c8065ab5d0adfda80cccf2d11e6 +REG_FIDDLE(Point_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint test[] = { {0.f, -0.f}, {-1, -2}, + { SK_ScalarInfinity, SK_ScalarNegativeInfinity }, + { SK_ScalarNaN, -SK_ScalarNaN } }; + for (const SkPoint& pt : test) { + SkPoint negPt = pt; + negPt.negate(); + SkDebugf("pt: %g, %g negate: %g, %g\n", pt.fX, pt.fY, negPt.fX, negPt.fY); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_020.cpp b/docs/examples/Point_020.cpp new file mode 100644 index 0000000000..10be1dcc96 --- /dev/null +++ b/docs/examples/Point_020.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=9baf247cfcd8272c0ddf6ce93f676b37 +REG_FIDDLE(Point_020, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint test[] = { {0.f, -0.f}, {-1, -2}, + { SK_ScalarInfinity, SK_ScalarNegativeInfinity }, + { SK_ScalarNaN, -SK_ScalarNaN } }; + for (const SkPoint& pt : test) { + SkPoint negPt = -pt; + SkDebugf("pt: %g, %g negate: %g, %g\n", pt.fX, pt.fY, negPt.fX, negPt.fY); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_021.cpp b/docs/examples/Point_021.cpp new file mode 100644 index 0000000000..f9bfb35116 --- /dev/null +++ b/docs/examples/Point_021.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=8b4e79109e2381345258cb744881b20c +REG_FIDDLE(Point_021, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + { 6, 4 }, { 7, 5 }, { 5, 7 }, + { 4, 6 }, { 3, 7 }, { 1, 5 }, + { 2, 4 }, { 1, 3 }, { 3, 1 } }; + canvas->scale(30, 15); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); + points[1] += {1, 1}; + points[2] += {-1, -1}; + paint.setColor(SK_ColorRED); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); +} +} // END FIDDLE diff --git a/docs/examples/Point_022.cpp b/docs/examples/Point_022.cpp new file mode 100644 index 0000000000..bb5954052a --- /dev/null +++ b/docs/examples/Point_022.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=86c0399704d8dff4091bf87b8d87d40b +REG_FIDDLE(Point_022, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + { 6, 4 }, { 7, 5 }, { 5, 7 }, + { 4, 6 }, { 3, 7 }, { 1, 5 }, + { 2, 4 }, { 1, 3 }, { 3, 1 } }; + canvas->scale(30, 15); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); + points[1] -= {1, 1}; + points[2] -= {-1, -1}; + paint.setColor(SK_ColorRED); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); +} +} // END FIDDLE diff --git a/docs/examples/Point_023.cpp b/docs/examples/Point_023.cpp new file mode 100644 index 0000000000..c74e5ecb09 --- /dev/null +++ b/docs/examples/Point_023.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=35b3bc675779de043706ae4817ee950c +REG_FIDDLE(Point_023, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + { 6, 4 }, { 7, 5 }, { 5, 7 }, + { 4, 6 }, { 3, 7 }, { 1, 5 }, + { 2, 4 }, { 1, 3 }, { 3, 1 } }; + canvas->scale(15, 10); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); + for (auto& point : points) { + point = point * 1.5f; + } + paint.setColor(SK_ColorRED); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); +} +} // END FIDDLE diff --git a/docs/examples/Point_024.cpp b/docs/examples/Point_024.cpp new file mode 100644 index 0000000000..55d28ecf31 --- /dev/null +++ b/docs/examples/Point_024.cpp @@ -0,0 +1,22 @@ +// 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 "fiddle/examples.h" +// HASH=3ce3db36235d80dbac4d39504cf756da +REG_FIDDLE(Point_024, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + { 6, 4 }, { 7, 5 }, { 5, 7 }, + { 4, 6 }, { 3, 7 }, { 1, 5 }, + { 2, 4 }, { 1, 3 }, { 3, 1 } }; + canvas->scale(15, 10); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); + for (auto& point : points) { + point *= 2; + } + paint.setColor(SK_ColorRED); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); +} +} // END FIDDLE diff --git a/docs/examples/Point_025.cpp b/docs/examples/Point_025.cpp new file mode 100644 index 0000000000..cdee460fb9 --- /dev/null +++ b/docs/examples/Point_025.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=937cc166cc0e220f33fb82501141d0b3 +REG_FIDDLE(Point_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} }; + for (const SkPoint& pt : test) { + SkDebugf("pt: %g, %g finite: %s\n", pt.fX, pt.fY, pt.isFinite() ? "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_026.cpp b/docs/examples/Point_026.cpp new file mode 100644 index 0000000000..269b7cb28c --- /dev/null +++ b/docs/examples/Point_026.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=4cecb878c8b66beffda051f26c00f817 +REG_FIDDLE(Point_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} }; + for (const SkPoint& pt : test) { + SkDebugf("pt: %g, %g %c= pt\n", pt.fX, pt.fY, pt.equals(pt.fX, pt.fY) ? '=' : '!'); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_027.cpp b/docs/examples/Point_027.cpp new file mode 100644 index 0000000000..0859829c89 --- /dev/null +++ b/docs/examples/Point_027.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=741f793334a48a35dadf4310d7ea52cb +REG_FIDDLE(Point_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} }; + for (const SkPoint& pt : test) { + SkDebugf("pt: %g, %g %c= pt\n", pt.fX, pt.fY, pt == pt ? '=' : '!'); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_028.cpp b/docs/examples/Point_028.cpp new file mode 100644 index 0000000000..fec8e11024 --- /dev/null +++ b/docs/examples/Point_028.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=8fe8572685eaa617f25a5a6767a874dc +REG_FIDDLE(Point_028, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint test[] = { {0, -0.f}, {-1, -2}, {SK_ScalarInfinity, 1}, {SK_ScalarNaN, -1} }; + for (const SkPoint& pt : test) { + SkDebugf("pt: %g, %g %c= pt\n", pt.fX, pt.fY, pt != pt ? '!' : '='); + } +} +} // END FIDDLE diff --git a/docs/examples/Point_029.cpp b/docs/examples/Point_029.cpp new file mode 100644 index 0000000000..2ee904756d --- /dev/null +++ b/docs/examples/Point_029.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=b6c4943ecd0b2dccf9d220b8944009e0 +REG_FIDDLE(Point_029, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + { 6, 4 }, { 7, 5 }, { 5, 7 }, + { 4, 6 }, { 3, 7 }, { 1, 5 }, + { 2, 4 }, { 1, 3 }, { 3, 1 } }; + canvas->scale(30, 15); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); + points[1] += points[0] - points[2]; + points[2] -= points[3] - points[5]; + paint.setColor(SK_ColorRED); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); +} +} // END FIDDLE diff --git a/docs/examples/Point_030.cpp b/docs/examples/Point_030.cpp new file mode 100644 index 0000000000..7e47134cda --- /dev/null +++ b/docs/examples/Point_030.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=911a84253dfec4dabf94dbe3c71766f0 +REG_FIDDLE(Point_030, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkPoint points[] = { { 3, 1 }, { 4, 2 }, { 5, 1 }, { 7, 3 }, + { 6, 4 }, { 7, 5 }, { 5, 7 }, + { 4, 6 }, { 3, 7 }, { 1, 5 }, + { 2, 4 }, { 1, 3 }, { 3, 1 } }; + canvas->scale(30, 15); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); + SkVector mod = {1, 1}; + for (auto& point : points) { + point = point + mod; + mod.fX *= 1.1f; + mod.fY += .2f; + } + paint.setColor(SK_ColorRED); + canvas->drawPoints(SkCanvas::kPolygon_PointMode, SK_ARRAY_COUNT(points), points, paint); +} +} // END FIDDLE diff --git a/docs/examples/Point_031.cpp b/docs/examples/Point_031.cpp new file mode 100644 index 0000000000..6507ed8bd2 --- /dev/null +++ b/docs/examples/Point_031.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=c98773d8b4509969d78cb8121e4b77f6 +REG_FIDDLE(Point_031, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const SkPoint points[] = { { 90, 30 }, { 120, 150 }, { 150, 30 }, { 210, 90 } }; + const SkPoint origin = {30, 140}; + for (auto point : points) { + canvas->drawLine(origin, point, paint); + SkAutoCanvasRestore acr(canvas, true); + SkScalar angle = SkScalarATan2((point.fY - origin.fY), point.fX - origin.fX); + canvas->rotate(angle * 180 / SK_ScalarPI, origin.fX, origin.fY); + SkString length("length = "); + length.appendScalar(SkPoint::Length(point.fX, point.fY)); + canvas->drawString(length, origin.fX + 25, origin.fY - 4, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Point_032.cpp b/docs/examples/Point_032.cpp new file mode 100644 index 0000000000..0c33b786e7 --- /dev/null +++ b/docs/examples/Point_032.cpp @@ -0,0 +1,26 @@ +#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 "fiddle/examples.h" +// HASH=60a08f3ce75374fc815384616d114df7 +REG_FIDDLE(Point_032, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const SkPoint lines[][2] = { {{ 30, 110 }, { 190, 30 }}, + {{ 30, 220 }, { 120, 140 }}}; + for (auto line : lines) { + canvas->drawLine(line[0], line[1], paint); + SkVector vector = line[1] - line[0]; + SkScalar priorLength = SkPoint::Normalize(&vector); + SkVector rotate90 = { -vector.fY, vector.fX }; + rotate90 *= 10.f; + canvas->drawLine(line[0] - rotate90, line[0] + rotate90, paint); + canvas->drawLine(line[1] - rotate90, line[1] + rotate90, paint); + SkString length("length = "); + length.appendScalar(priorLength); + canvas->drawString(length, line[0].fX + 25, line[0].fY - 4, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Point_033.cpp b/docs/examples/Point_033.cpp new file mode 100644 index 0000000000..e3fc00b9dd --- /dev/null +++ b/docs/examples/Point_033.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=9e0a2de2eb94dba4521d733e73f2bda5 +REG_FIDDLE(Point_033, 256, 192, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + const SkPoint lines[][2] = {{{-10, -10}, {90, 30}}, {{0, 0}, {150, 30}}, {{10, 25}, {120, 150}}}; + const SkPoint origin = {30, 160}; + for (auto line : lines) { + SkPoint a = origin + line[0]; + const SkPoint& b = line[1]; + canvas->drawLine(a, b, paint); + SkAutoCanvasRestore acr(canvas, true); + SkScalar angle = SkScalarATan2((b.fY - a.fY), b.fX - a.fX); + canvas->rotate(angle * 180 / SK_ScalarPI, a.fX, a.fY); + SkString distance("distance = "); + distance.appendScalar(SkPoint::Distance(a, b)); + canvas->drawString(distance, a.fX + 25, a.fY - 4, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Point_034.cpp b/docs/examples/Point_034.cpp new file mode 100644 index 0000000000..f961386d77 --- /dev/null +++ b/docs/examples/Point_034.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=496db0131a003162faba7d7f98b30340 +REG_FIDDLE(Point_034, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}}, + {{-20, -24}, {-24, -20}}}; + SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}}; + paint.setStrokeWidth(2); + for (size_t i = 0; i < 4; ++i) { + canvas->drawLine(center[i], center[i] + vectors[i][0], paint); + canvas->drawLine(center[i], center[i] + vectors[i][1], paint); + SkString str; + str.printf("dot = %g", SkPoint::DotProduct(vectors[i][0], vectors[i][1])); + canvas->drawString(str, center[i].fX, center[i].fY, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Point_035.cpp b/docs/examples/Point_035.cpp new file mode 100644 index 0000000000..118fe0438c --- /dev/null +++ b/docs/examples/Point_035.cpp @@ -0,0 +1,27 @@ +#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 "fiddle/examples.h" +// HASH=8b8a4cd8a29d22bb9c5e63b70357bd65 +REG_FIDDLE(Point_035, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}}, + {{-20, -24}, {-24, -20}}}; + SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}}; + paint.setStrokeWidth(2); + for (size_t i = 0; i < 4; ++i) { + paint.setColor(SK_ColorRED); + canvas->drawLine(center[i], center[i] + vectors[i][0], paint); + paint.setColor(SK_ColorBLUE); + canvas->drawLine(center[i], center[i] + vectors[i][1], paint); + SkString str; + SkScalar cross = SkPoint::CrossProduct(vectors[i][1], vectors[i][0]); + str.printf("cross = %g", cross); + paint.setColor(cross >= 0 ? SK_ColorRED : SK_ColorBLUE); + canvas->drawString(str, center[i].fX, center[i].fY, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Point_036.cpp b/docs/examples/Point_036.cpp new file mode 100644 index 0000000000..3a95a32f86 --- /dev/null +++ b/docs/examples/Point_036.cpp @@ -0,0 +1,27 @@ +#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 "fiddle/examples.h" +// HASH=0bc7b3997357e499817278b78bdfbf1d +REG_FIDDLE(Point_036, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}}, + {{-20, -24}, {-24, -20}}}; + SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}}; + paint.setStrokeWidth(2); + for (size_t i = 0; i < 4; ++i) { + paint.setColor(SK_ColorRED); + canvas->drawLine(center[i], center[i] + vectors[i][0], paint); + paint.setColor(SK_ColorBLUE); + canvas->drawLine(center[i], center[i] + vectors[i][1], paint); + SkString str; + SkScalar cross = vectors[i][0].cross(vectors[i][1]); + str.printf("cross = %g", cross); + paint.setColor(cross >= 0 ? SK_ColorRED : SK_ColorBLUE); + canvas->drawString(str, center[i].fX, center[i].fY, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Point_037.cpp b/docs/examples/Point_037.cpp new file mode 100644 index 0000000000..3f5b1036aa --- /dev/null +++ b/docs/examples/Point_037.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=56d01ccfedd71d3c504b09afa2875d38 +REG_FIDDLE(Point_037, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkVector vectors[][2] = {{{50, 2}, {-14, 20}}, {{0, 50}, {-50, 0}}, {{-20, 25}, {25, -20}}, + {{-20, -24}, {-24, -20}}}; + SkPoint center[] = {{32, 32}, {160, 32}, {32, 160}, {160, 160}}; + paint.setStrokeWidth(2); + for (size_t i = 0; i < 4; ++i) { + canvas->drawLine(center[i], center[i] + vectors[i][0], paint); + canvas->drawLine(center[i], center[i] + vectors[i][1], paint); + SkString str; + str.printf("dot = %g", vectors[i][0].dot(vectors[i][1])); + canvas->drawString(str, center[i].fX, center[i].fY, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_000.cpp b/docs/examples/RRect_000.cpp new file mode 100644 index 0000000000..487317fec9 --- /dev/null +++ b/docs/examples/RRect_000.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=471e7aad0feaf9ec3a21757a317a64f5 +REG_FIDDLE(RRect_000, 256, 60, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect; + SkPaint p; + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(10); + canvas->drawRRect(rrect, p); + rrect.setRect({10, 10, 100, 50}); + canvas->drawRRect(rrect, p); +} +} // END FIDDLE diff --git a/docs/examples/RRect_001.cpp b/docs/examples/RRect_001.cpp new file mode 100644 index 0000000000..66942e9d7d --- /dev/null +++ b/docs/examples/RRect_001.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=ad8f5d49edfcee60eddfe2a955b6c5f5 +REG_FIDDLE(RRect_001, 256, 60, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeRect({10, 10, 100, 50}); + SkRRect rrect2(rrect); + rrect2.inset(20, 20); + SkPaint p; + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(10); + canvas->drawRRect(rrect, p); + canvas->drawRRect(rrect2, p); +} +} // END FIDDLE diff --git a/docs/examples/RRect_002.cpp b/docs/examples/RRect_002.cpp new file mode 100644 index 0000000000..6632e9e8f2 --- /dev/null +++ b/docs/examples/RRect_002.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=52926c98c1cca00606d3ea99f23fea3d +REG_FIDDLE(RRect_002, 256, 110, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeRect({40, 40, 100, 70}); + SkRRect rrect2 = rrect; + rrect2.inset(-20, -20); + SkPaint p; + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(10); + canvas->drawRRect(rrect, p); + canvas->drawRRect(rrect2, p); +} +} // END FIDDLE diff --git a/docs/examples/RRect_003.cpp b/docs/examples/RRect_003.cpp new file mode 100644 index 0000000000..6abcbb2e8c --- /dev/null +++ b/docs/examples/RRect_003.cpp @@ -0,0 +1,27 @@ +#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 "fiddle/examples.h" +// HASH=a4233634c75b72fc7a2815ddb69bd669 +REG_FIDDLE(RRect_003, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + struct Radii { SkVector data[4]; }; + auto drawRRectType = [=](const SkRect& rect, const Radii& radii) { + SkRRect rrect; + rrect.setRectRadii(rect, radii.data); + SkPaint paint; + paint.setAntiAlias(true); + const char* typeStr[] = { "empty", "rect", "oval", "simple", "nine patch", "complex" }; + canvas->drawString(typeStr[(int) rrect.type()], rect.centerX(), rect.bottom() + 20, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRRect(rrect, paint); + }; + drawRRectType({ 45, 30, 45, 30}, {{{ 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}}}); + drawRRectType({ 90, 10, 140, 30}, {{{ 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}}}); + drawRRectType({160, 10, 210, 30}, {{{25, 10}, {25, 10}, {25, 10}, {25, 10}}}); + drawRRectType({ 20, 80, 70, 100}, {{{ 5, 5}, { 5, 5}, { 5, 5}, { 5, 5}}}); + drawRRectType({ 90, 80, 140, 100}, {{{ 5, 5}, {10, 5}, {10, 5}, { 5, 5}}}); + drawRRectType({160, 80, 210, 100}, {{{ 5, 5}, {10, 5}, { 5, 5}, { 5, 5}}}); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_004.cpp b/docs/examples/RRect_004.cpp new file mode 100644 index 0000000000..2975250a1d --- /dev/null +++ b/docs/examples/RRect_004.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=ace8f4aebf90527d43e4b7291375c9ad +REG_FIDDLE(RRect_004, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeRect({10, 10, 100, 50}); + SkRRect rrect2(rrect); + rrect2.inset(20, 20); + SkPaint p; + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(10); + std::string str("Type "); + str += SkRRect::kRect_Type == rrect2.getType() ? "=" : "!"; + str += "= SkRRect::kRect_Type"; + canvas->drawString(str.c_str(), 20, 80, SkPaint()); + canvas->drawRRect(rrect2, p); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_005.cpp b/docs/examples/RRect_005.cpp new file mode 100644 index 0000000000..a88801f355 --- /dev/null +++ b/docs/examples/RRect_005.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=1080805c8449406a4e26d694bc56d2dc +REG_FIDDLE(RRect_005, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeRect({10, 10, 100, 50}); + SkRRect rrect2(rrect); + rrect2.inset(20, 20); + SkPaint p; + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(10); + std::string str("Type "); + str += SkRRect::kEmpty_Type == rrect2.type() ? "=" : "!"; + str += "= SkRRect::kEmpty_Type"; + canvas->drawString(str.c_str(), 20, 80, SkPaint()); + canvas->drawRRect(rrect2, p); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_006.cpp b/docs/examples/RRect_006.cpp new file mode 100644 index 0000000000..08f29fc963 --- /dev/null +++ b/docs/examples/RRect_006.cpp @@ -0,0 +1,20 @@ +#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 "fiddle/examples.h" +// HASH=099d79ecfbdfb0a19c10deb7201859c3 +REG_FIDDLE(RRect_006, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(16); + SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 10, 5); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isEmpty() ? "empty" : "not empty", 64, 90, paint); + rrect.inset(40, 0); + canvas->translate(128, 0); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isEmpty() ? "empty" : "not empty", 64, 90, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_007.cpp b/docs/examples/RRect_007.cpp new file mode 100644 index 0000000000..0ee1dffc52 --- /dev/null +++ b/docs/examples/RRect_007.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=bc931c9a6eb8ffe7ea8d3fb47e07a475 +REG_FIDDLE(RRect_007, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(16); + SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60}); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isRect() ? "rect" : "not rect", 64, 90, paint); + SkVector radii[] = {{10, 10}, {0, 0}, {0, 0}, {0, 0}}; + rrect.setRectRadii(rrect.getBounds(), radii); + canvas->translate(128, 0); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isRect() ? "rect" : "not rect", 64, 90, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_008.cpp b/docs/examples/RRect_008.cpp new file mode 100644 index 0000000000..c7793965a3 --- /dev/null +++ b/docs/examples/RRect_008.cpp @@ -0,0 +1,20 @@ +#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 "fiddle/examples.h" +// HASH=4dfdb28d8343958425f2c1323fe8170d +REG_FIDDLE(RRect_008, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(16); + SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 40, 30); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isOval() ? "oval" : "not oval", 64, 90, paint); + rrect.setRectXY(rrect.getBounds(), 35, 25); + canvas->translate(128, 0); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isOval() ? "oval" : "not oval", 64, 90, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_009.cpp b/docs/examples/RRect_009.cpp new file mode 100644 index 0000000000..75a0263146 --- /dev/null +++ b/docs/examples/RRect_009.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=f6959ea422a7c6e98ddfad216a52c707 +REG_FIDDLE(RRect_009, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(16); + SkVector radii[] = {{40, 30}, {40, 30}, {40, 30}, {40, 30}}; + SkRRect rrect; + rrect.setRectRadii({30, 10, 100, 60}, radii); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isSimple() ? "simple" : "not simple", 64, 90, paint); + radii[0].fX = 35; + rrect.setRectRadii(rrect.getBounds(), radii); + canvas->translate(128, 0); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isSimple() ? "simple" : "not simple", 64, 90, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_010.cpp b/docs/examples/RRect_010.cpp new file mode 100644 index 0000000000..ef37598650 --- /dev/null +++ b/docs/examples/RRect_010.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=429f6dfd4cf6287df3c3c77fa7681c99 +REG_FIDDLE(RRect_010, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(16); + SkVector radii[] = {{20, 30}, {40, 30}, {40, 30}, {20, 30}}; + SkRRect rrect; + rrect.setRectRadii({30, 10, 100, 60}, radii); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isNinePatch() ? "9 patch" : "not 9 patch", 64, 90, paint); + radii[0].fX = 35; + rrect.setRectRadii(rrect.getBounds(), radii); + canvas->translate(128, 0); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isNinePatch() ? "9 patch" : "not 9 patch", 64, 90, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_011.cpp b/docs/examples/RRect_011.cpp new file mode 100644 index 0000000000..60ce3f0513 --- /dev/null +++ b/docs/examples/RRect_011.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=b62c183dc435d1fc091111fb2f3c3f8e +REG_FIDDLE(RRect_011, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(16); + SkVector radii[] = {{25, 30}, {40, 30}, {40, 30}, {20, 30}}; + SkRRect rrect; + rrect.setRectRadii({30, 10, 100, 60}, radii); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isComplex() ? "complex" : "not complex", 64, 90, paint); + radii[0].fX = 20; + rrect.setRectRadii(rrect.getBounds(), radii); + canvas->translate(128, 0); + canvas->drawRRect(rrect, paint); + canvas->drawString(rrect.isComplex() ? "complex" : "not complex", 64, 90, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_012.cpp b/docs/examples/RRect_012.cpp new file mode 100644 index 0000000000..cb85a8eb98 --- /dev/null +++ b/docs/examples/RRect_012.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=c675a480b41dee157f84fa2550a2a53c +REG_FIDDLE(RRect_012, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRRect unsorted = SkRRect::MakeRect({ 15, 25, 10, 5 }); + SkDebugf("unsorted width: %g\n", unsorted.width()); + SkRRect large = SkRRect::MakeRect({ -FLT_MAX, 1, FLT_MAX, 2 }); + SkDebugf("large width: %.0f\n", large.width()); +} +} // END FIDDLE diff --git a/docs/examples/RRect_013.cpp b/docs/examples/RRect_013.cpp new file mode 100644 index 0000000000..f0fbcbe448 --- /dev/null +++ b/docs/examples/RRect_013.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=5a3eb1755164a7becec33cec6e6eca31 +REG_FIDDLE(RRect_013, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRRect unsorted = SkRRect::MakeRect({ 15, 25, 10, 20 }); + SkDebugf("unsorted height: %g\n", unsorted.height()); + SkRRect large = SkRRect::MakeRect({ 1, -FLT_MAX, 2, FLT_MAX }); + SkDebugf("large height: %.0f\n", large.height()); +} +} // END FIDDLE diff --git a/docs/examples/RRect_014.cpp b/docs/examples/RRect_014.cpp new file mode 100644 index 0000000000..35d9179f94 --- /dev/null +++ b/docs/examples/RRect_014.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=81345f7619a072bb2b0cf59810fe86d0 +REG_FIDDLE(RRect_014, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + auto drawDetails = [=](const SkRRect& rrect) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setTextSize(12); + canvas->drawRRect(rrect, paint); + SkVector corner = rrect.getSimpleRadii(); + std::string label = "corner: " + std::to_string(corner.fX).substr(0, 3) + ", " + + std::to_string(corner.fY).substr(0, 3); + canvas->drawString(label.c_str(), 64, 90, paint); + canvas->translate(128, 0); + }; + SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60}); + drawDetails(rrect); + rrect.setRectXY(rrect.getBounds(), 5, 8); + drawDetails(rrect); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_015.cpp b/docs/examples/RRect_015.cpp new file mode 100644 index 0000000000..f7d17ac557 --- /dev/null +++ b/docs/examples/RRect_015.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=44e9a9c2c5ef1af2a616086ff46a9037 +REG_FIDDLE(RRect_015, 256, 80, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60}); + canvas->drawRRect(rrect, paint); + rrect.setEmpty(); + paint.setColor(SK_ColorBLUE); + canvas->drawRRect(rrect, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_016.cpp b/docs/examples/RRect_016.cpp new file mode 100644 index 0000000000..6d194941ae --- /dev/null +++ b/docs/examples/RRect_016.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=3afc3ac9bebd1d7387822cc608571e82 +REG_FIDDLE(RRect_016, 256, 90, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60}); + canvas->drawRRect(rrect, paint); + rrect.setRect({60, 30, 120, 80}); + paint.setColor(SK_ColorBLUE); + canvas->drawRRect(rrect, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_017.cpp b/docs/examples/RRect_017.cpp new file mode 100644 index 0000000000..28ad9682ed --- /dev/null +++ b/docs/examples/RRect_017.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=c6c6be3b3c137226adbb5b5af9203d27 +REG_FIDDLE(RRect_017, 256, 90, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeEmpty(); + SkRRect rrect2(rrect); + rrect2.inset(-20, -20); + SkPaint p; + p.setStyle(SkPaint::kStroke_Style); + p.setStrokeWidth(10); + std::string str("Type "); + str += SkRRect::kEmpty_Type == rrect2.type() ? "=" : "!"; + str += "= SkRRect::kEmpty_Type"; + canvas->drawString(str.c_str(), 20, 80, SkPaint()); + canvas->drawRRect(rrect2, p); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_018.cpp b/docs/examples/RRect_018.cpp new file mode 100644 index 0000000000..e60f64f5c9 --- /dev/null +++ b/docs/examples/RRect_018.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=5295b07fe4d2cdcd077979a9e19854d9 +REG_FIDDLE(RRect_018, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRRect rrect = SkRRect::MakeRect({30, 10, 100, 60}); + canvas->drawRRect(rrect, paint); + rrect.setOval(rrect.getBounds()); + paint.setColor(SK_ColorBLUE); + canvas->drawRRect(rrect, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_019.cpp b/docs/examples/RRect_019.cpp new file mode 100644 index 0000000000..d9c9439a9e --- /dev/null +++ b/docs/examples/RRect_019.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=0b99ee38fd154f769f6031242e02fa7a +REG_FIDDLE(RRect_019, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRRect rrect = SkRRect::MakeOval({30, 10, 100, 60}); + canvas->drawRRect(rrect, paint); + rrect.setRect(rrect.getBounds()); + paint.setColor(SK_ColorBLUE); + paint.setBlendMode(SkBlendMode::kDifference); + canvas->drawRRect(rrect, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_020.cpp b/docs/examples/RRect_020.cpp new file mode 100644 index 0000000000..dd61bbbec2 --- /dev/null +++ b/docs/examples/RRect_020.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=2b24a1247637cbc94f8b3c77d37ed3e2 +REG_FIDDLE(RRect_020, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 20, 20); + canvas->drawRRect(rrect, paint); + rrect.setRect(rrect.getBounds()); + paint.setColor(SK_ColorBLUE); + paint.setBlendMode(SkBlendMode::kModulate); + canvas->drawRRect(rrect, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_021.cpp b/docs/examples/RRect_021.cpp new file mode 100644 index 0000000000..58c1ea46a6 --- /dev/null +++ b/docs/examples/RRect_021.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=cf418af29cbab6243ac16aacd1217ffe +REG_FIDDLE(RRect_021, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 20, 20); + canvas->drawRRect(rrect, paint); + rrect.setOval(rrect.getBounds()); + paint.setColor(SK_ColorWHITE); + paint.setBlendMode(SkBlendMode::kExclusion); + canvas->drawRRect(rrect, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_022.cpp b/docs/examples/RRect_022.cpp new file mode 100644 index 0000000000..198679e3f0 --- /dev/null +++ b/docs/examples/RRect_022.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=6ac569e40fb68c758319e85428b9ae95 +REG_FIDDLE(RRect_022, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRRect rrect = SkRRect::MakeRectXY({30, 10, 100, 60}, 20, 20); + canvas->drawRRect(rrect, paint); + rrect.setRectXY(rrect.getBounds(), 5, 5); + paint.setColor(SK_ColorWHITE); + paint.setBlendMode(SkBlendMode::kExclusion); + canvas->drawRRect(rrect, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_023.cpp b/docs/examples/RRect_023.cpp new file mode 100644 index 0000000000..cb14e6b3ec --- /dev/null +++ b/docs/examples/RRect_023.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=c4620df2eaba447b581688d3100053b1 +REG_FIDDLE(RRect_023, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkRRect rrect; + rrect.setNinePatch({30, 10, 100, 60}, 10, 20, 20, 10); + canvas->drawRRect(rrect, paint); + paint.setColor(SK_ColorWHITE); + const SkRect r = rrect.getBounds(); + canvas->drawLine(r.fLeft, r.fTop + rrect.radii(SkRRect::kUpperLeft_Corner).fY, + r.fRight, r.fTop + rrect.radii(SkRRect::kUpperRight_Corner).fY, paint); + canvas->drawLine(r.fLeft, r.fBottom - rrect.radii(SkRRect::kLowerLeft_Corner).fY, + r.fRight, r.fBottom - rrect.radii(SkRRect::kLowerRight_Corner).fY, paint); + canvas->drawLine(r.fLeft + rrect.radii(SkRRect::kUpperLeft_Corner).fX, r.fTop, + r.fLeft + rrect.radii(SkRRect::kLowerLeft_Corner).fX, r.fBottom, paint); + canvas->drawLine(r.fRight - rrect.radii(SkRRect::kUpperRight_Corner).fX, r.fTop, + r.fRight - rrect.radii(SkRRect::kLowerRight_Corner).fX, r.fBottom, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_024.cpp b/docs/examples/RRect_024.cpp new file mode 100644 index 0000000000..0db919cbc0 --- /dev/null +++ b/docs/examples/RRect_024.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=340d6c51efaa1f7f3d0dcaf8b0e90696 +REG_FIDDLE(RRect_024, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setStrokeWidth(15); + paint.setStrokeCap(SkPaint::kSquare_Cap); + paint.setAntiAlias(true); + float intervals[] = { 5, 21.75f }; + paint.setStyle(SkPaint::kStroke_Style); + paint.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0)); + SkPath path; + SkRRect rrect; + SkVector corners[] = {{15, 17}, {17, 19}, {19, 15}, {15, 15}}; + rrect.setRectRadii({20, 20, 100, 100}, corners); + path.addRRect(rrect, SkPath::kCW_Direction); + canvas->drawPath(path, paint); + path.rewind(); + path.addRRect(rrect, SkPath::kCCW_Direction, 1); + canvas->translate(120, 0); + canvas->drawPath(path, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_025.cpp b/docs/examples/RRect_025.cpp new file mode 100644 index 0000000000..4e5744973d --- /dev/null +++ b/docs/examples/RRect_025.cpp @@ -0,0 +1,24 @@ +// 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 "fiddle/examples.h" +// HASH=9205393f30b156e1507e88aa27f1dd91 +REG_FIDDLE(RRect_025, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + SkRRect rrect; + SkVector corners[] = {{25, 17}, {17, 19}, {19, 15}, {15, 15}}; + rrect.setRectRadii({30, 10, 100, 60}, corners); + canvas->drawRRect(rrect, paint); + paint.setColor(SK_ColorWHITE); + const SkRect r = rrect.getBounds(); + canvas->drawLine(r.fLeft, r.fTop + rrect.radii(SkRRect::kUpperLeft_Corner).fY, + r.fRight, r.fTop + rrect.radii(SkRRect::kUpperRight_Corner).fY, paint); + canvas->drawLine(r.fLeft, r.fBottom - rrect.radii(SkRRect::kLowerLeft_Corner).fY, + r.fRight, r.fBottom - rrect.radii(SkRRect::kLowerRight_Corner).fY, paint); + canvas->drawLine(r.fLeft + rrect.radii(SkRRect::kUpperLeft_Corner).fX, r.fTop, + r.fLeft + rrect.radii(SkRRect::kLowerLeft_Corner).fX, r.fBottom, paint); + canvas->drawLine(r.fRight - rrect.radii(SkRRect::kUpperRight_Corner).fX, r.fTop, + r.fRight - rrect.radii(SkRRect::kLowerRight_Corner).fX, r.fBottom, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_026.cpp b/docs/examples/RRect_026.cpp new file mode 100644 index 0000000000..2ca20a367d --- /dev/null +++ b/docs/examples/RRect_026.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=6831adf4c536047f4709c686feb10c48 +REG_FIDDLE(RRect_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + for (SkScalar left : { SK_ScalarNaN, SK_ScalarInfinity, 100.f, 50.f, 25.f} ) { + SkRRect rrect1 = SkRRect::MakeRectXY({left, 20, 60, 220}, 50, 200); + SkDebugf("left bounds: (%g) %g\n", left, rrect1.rect().fLeft); + } +} +} // END FIDDLE diff --git a/docs/examples/RRect_027.cpp b/docs/examples/RRect_027.cpp new file mode 100644 index 0000000000..48b755b3e2 --- /dev/null +++ b/docs/examples/RRect_027.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=8d5c88478528584913867ada423e0d59 +REG_FIDDLE(RRect_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + for (SkScalar radiusX : { SK_ScalarNaN, SK_ScalarInfinity, 100.f, 50.f, 25.f} ) { + SkRRect rrect1 = SkRRect::MakeRectXY({10, 20, 60, 220}, radiusX, 200); + SkDebugf("left corner: (%g) %g\n", radiusX, rrect1.radii(SkRRect::kUpperLeft_Corner).fX); + } +} +} // END FIDDLE diff --git a/docs/examples/RRect_028.cpp b/docs/examples/RRect_028.cpp new file mode 100644 index 0000000000..394391c012 --- /dev/null +++ b/docs/examples/RRect_028.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=4577e2dcb086b241bb43d8b89ee0b0dd +REG_FIDDLE(RRect_028, 256, 120, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + SkRRect rrect = SkRRect::MakeRectXY({20, 20, 220, 100}, 15, 15); + canvas->drawRRect(rrect, paint); + paint.setColor(SK_ColorWHITE); + rrect = SkRRect::MakeOval(rrect.getBounds()); + canvas->drawRRect(rrect, paint); +} +} // END FIDDLE diff --git a/docs/examples/RRect_029.cpp b/docs/examples/RRect_029.cpp new file mode 100644 index 0000000000..9486ea66ce --- /dev/null +++ b/docs/examples/RRect_029.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=df181af37f1d2b06f0f45af73df7b47d +REG_FIDDLE(RRect_029, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect1 = SkRRect::MakeRectXY({10, 20, 60, 220}, 50, 200); + SkRRect rrect2 = SkRRect::MakeRectXY(rrect1.rect(), 25, 100); + SkRRect rrect3 = SkRRect::MakeOval(rrect1.rect()); + canvas->drawRRect(rrect1, SkPaint()); + std::string str = "rrect1 " + std::string(rrect1 == rrect2 ? "=" : "!") + "= rrect2"; + canvas->drawString(str.c_str(), 10, 240, SkPaint()); + canvas->translate(70, 0); + canvas->drawRRect(rrect2, SkPaint()); + canvas->translate(70, 0); + canvas->drawRRect(rrect3, SkPaint()); + str = "rrect2 " + std::string(rrect2 == rrect3 ? "=" : "!") + "= rrect3"; + canvas->drawString(str.c_str(), -20, 240, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_030.cpp b/docs/examples/RRect_030.cpp new file mode 100644 index 0000000000..4418787d4e --- /dev/null +++ b/docs/examples/RRect_030.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=505e47b3e6474ebdecdc04c3c2af2c34 +REG_FIDDLE(RRect_030, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect1 = SkRRect::MakeRectXY({10, 20, 60, 220}, 50, 100); + SkRRect rrect2 = SkRRect::MakeRectXY(rrect1.rect(), 50, 50); + SkRRect rrect3 = SkRRect::MakeOval(rrect1.rect()); + canvas->drawRRect(rrect1, SkPaint()); + std::string str = "rrect1 " + std::string(rrect1 == rrect2 ? "=" : "!") + "= rrect2"; + canvas->drawString(str.c_str(), 10, 240, SkPaint()); + canvas->translate(70, 0); + canvas->drawRRect(rrect2, SkPaint()); + canvas->translate(70, 0); + canvas->drawRRect(rrect3, SkPaint()); + str = "rrect2 " + std::string(rrect2 == rrect3 ? "=" : "!") + "= rrect3"; + canvas->drawString(str.c_str(), -20, 240, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_031.cpp b/docs/examples/RRect_031.cpp new file mode 100644 index 0000000000..1602975edc --- /dev/null +++ b/docs/examples/RRect_031.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=f02f0110d5605dac6d14dcb8d1d8cb6e +REG_FIDDLE(RRect_031, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100); + for (int index = 0; index < 25; ++index) { + canvas->drawRRect(rrect, paint); + rrect.inset(-3, 3, &rrect); + } +} +} // END FIDDLE diff --git a/docs/examples/RRect_032.cpp b/docs/examples/RRect_032.cpp new file mode 100644 index 0000000000..f16d577172 --- /dev/null +++ b/docs/examples/RRect_032.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=da61054322550a2d5ac15114da23bd23 +REG_FIDDLE(RRect_032, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkRRect rrect = SkRRect::MakeRectXY({10, 20, 180, 220}, 50, 100); + for (int index = 0; index < 25; ++index) { + canvas->drawRRect(rrect, paint); + rrect.inset(3, 3); + } +} +} // END FIDDLE diff --git a/docs/examples/RRect_033.cpp b/docs/examples/RRect_033.cpp new file mode 100644 index 0000000000..9d8c21806d --- /dev/null +++ b/docs/examples/RRect_033.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=4d69b6d9c7726c47c42827d79fc7899c +REG_FIDDLE(RRect_033, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100); + for (int index = 0; index < 25; ++index) { + canvas->drawRRect(rrect, paint); + rrect.outset(-3, 3, &rrect); + } +} +} // END FIDDLE diff --git a/docs/examples/RRect_034.cpp b/docs/examples/RRect_034.cpp new file mode 100644 index 0000000000..1dc1c8ebde --- /dev/null +++ b/docs/examples/RRect_034.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=4391cced86653dcd0f84439a5c0bb3f2 +REG_FIDDLE(RRect_034, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100); + for (int index = 0; index < 25; ++index) { + canvas->drawRRect(rrect, paint); + rrect.outset(3, 3); + } +} +} // END FIDDLE diff --git a/docs/examples/RRect_035.cpp b/docs/examples/RRect_035.cpp new file mode 100644 index 0000000000..4423528670 --- /dev/null +++ b/docs/examples/RRect_035.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=a45cdd46ef2fe0df62d84d41713e82e2 +REG_FIDDLE(RRect_035, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100); + for (int index = 0; index < 25; ++index) { + canvas->drawRRect(rrect, paint); + rrect.offset(3, 3); + } +} +} // END FIDDLE diff --git a/docs/examples/RRect_036.cpp b/docs/examples/RRect_036.cpp new file mode 100644 index 0000000000..f6afc29a80 --- /dev/null +++ b/docs/examples/RRect_036.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=c433aa41eaf5e419e3349fb970a08151 +REG_FIDDLE(RRect_036, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + SkRRect rrect = SkRRect::MakeRectXY({100, 20, 140, 220}, 50, 100); + for (int index = 0; index < 25; ++index) { + canvas->drawRRect(rrect, paint); + rrect = rrect.makeOffset(-3, 3); + } +} +} // END FIDDLE diff --git a/docs/examples/RRect_037.cpp b/docs/examples/RRect_037.cpp new file mode 100644 index 0000000000..726bd8aae0 --- /dev/null +++ b/docs/examples/RRect_037.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=0bb057140e4119234bdd2e8dd2f0fa19 +REG_FIDDLE(RRect_037, 256, 110, false, 0) { +void draw(SkCanvas* canvas) { + SkRect test = {10, 10, 110, 80}; + SkRRect rrect = SkRRect::MakeRect(test); + SkRRect oval = SkRRect::MakeOval(test); + test.inset(10, 10); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString(rrect.contains(test) ? "contains" : "does not contain", 55, 100, paint); + canvas->drawString(oval.contains(test) ? "contains" : "does not contain", 185, 100, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRRect(rrect, paint); + canvas->drawRect(test, paint); + canvas->translate(120, 0); + canvas->drawRRect(oval, paint); + canvas->drawRect(test, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_038.cpp b/docs/examples/RRect_038.cpp new file mode 100644 index 0000000000..521e3cacaf --- /dev/null +++ b/docs/examples/RRect_038.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=8cc1f21c98c0416f7724ad218f557a00 +REG_FIDDLE(RRect_038, 256, 110, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeRect({10, 10, 110, 80}); + SkRRect corrupt = rrect; + *((float*) &corrupt) = 120; + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString(rrect.isValid() ? "is valid" : "is corrupted", 55, 100, paint); + canvas->drawString(corrupt.isValid() ? "is valid" : "is corrupted", 185, 100, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRRect(rrect, paint); + canvas->translate(120, 0); + canvas->drawRRect(corrupt, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_039.cpp b/docs/examples/RRect_039.cpp new file mode 100644 index 0000000000..e978d5c4b4 --- /dev/null +++ b/docs/examples/RRect_039.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=d6f5a3d21727ddc15e10ef4d5103ff91 +REG_FIDDLE(RRect_039, 256, 110, false, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeRect({10, 10, 110, 80}); + char storage[SkRRect::kSizeInMemory]; + rrect.writeToMemory(storage); + SkRRect copy; + copy.readFromMemory(storage, sizeof(storage)); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString("rrect", 55, 100, paint); + canvas->drawString("copy", 185, 100, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRRect(rrect, paint); + canvas->translate(120, 0); + canvas->drawRRect(copy, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_040.cpp b/docs/examples/RRect_040.cpp new file mode 100644 index 0000000000..5809600d97 --- /dev/null +++ b/docs/examples/RRect_040.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=50969745cf2b23544362f4cff5592b75 +REG_FIDDLE(RRect_040, 256, 110, false, 0) { +void draw(SkCanvas* canvas) { + SkVector radii[] = {{5, 5}, {10, 10}, {15, 15}, {5, 5}}; + SkRRect rrect; + rrect.setRectRadii({10, 10, 110, 80}, radii); + char storage[SkRRect::kSizeInMemory]; + rrect.writeToMemory(storage); + SkRRect copy; + copy.readFromMemory(storage, sizeof(storage)); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString("rrect", 55, 100, paint); + canvas->drawString("copy", 185, 100, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRRect(rrect, paint); + canvas->translate(120, 0); + canvas->drawRRect(copy, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_041.cpp b/docs/examples/RRect_041.cpp new file mode 100644 index 0000000000..43fc25cae8 --- /dev/null +++ b/docs/examples/RRect_041.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=68a5d24f22e2d798608fce8a20e47fd0 +REG_FIDDLE(RRect_041, 256, 110, false, 0) { +void draw(SkCanvas* canvas) { + SkVector radii[] = {{5, 5}, {10, 10}, {15, 15}, {5, 5}}; + SkRRect rrect; + rrect.setRectRadii({10, 10, 110, 80}, radii); + SkRRect transformed; + SkMatrix matrix = SkMatrix::MakeRectToRect(rrect.rect(), {140, 30, 220, 80}, + SkMatrix::kCenter_ScaleToFit); + bool success = rrect.transform(matrix, &transformed); + SkPaint paint; + paint.setAntiAlias(true); + canvas->drawString("rrect", 55, 100, paint); + canvas->drawString(success ? "transformed" : "transform failed", 185, 100, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRRect(rrect, paint); + canvas->drawRRect(transformed, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/RRect_042.cpp b/docs/examples/RRect_042.cpp new file mode 100644 index 0000000000..3bbc253590 --- /dev/null +++ b/docs/examples/RRect_042.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=265b8d23288dc8026ff788e809360af7 +REG_FIDDLE(RRect_042, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeRect({6.f / 7, 2.f / 3, 6.f / 7, 2.f / 3}); + for (bool dumpAsHex : { false, true } ) { + rrect.dump(dumpAsHex); + } +} +} // END FIDDLE diff --git a/docs/examples/RRect_043.cpp b/docs/examples/RRect_043.cpp new file mode 100644 index 0000000000..e3ade1c002 --- /dev/null +++ b/docs/examples/RRect_043.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=f850423c7c0c4f803d479ecd92221059 +REG_FIDDLE(RRect_043, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeRect({6.f / 7, 2.f / 3, 6.f / 7, 2.f / 3}); + rrect.dump(); + SkRect bounds = SkRect::MakeLTRB(0.857143f, 0.666667f, 0.857143f, 0.666667f); + const SkPoint corners[] = { + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + { 0, 0 }, + }; + SkRRect copy; + copy.setRectRadii(bounds, corners); + SkDebugf("rrect is " "%s" "equal to copy\n", rrect == copy ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/RRect_044.cpp b/docs/examples/RRect_044.cpp new file mode 100644 index 0000000000..831e795a2e --- /dev/null +++ b/docs/examples/RRect_044.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=c73f5e2644d949b859f05bd367883454 +REG_FIDDLE(RRect_044, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRRect rrect = SkRRect::MakeRect({6.f / 7, 2.f / 3, 6.f / 7, 2.f / 3}); + rrect.dumpHex(); + SkRect bounds = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */ + SkBits2Float(0x3f2aaaab), /* 0.666667 */ + SkBits2Float(0x3f5b6db7), /* 0.857143 */ + SkBits2Float(0x3f2aaaab) /* 0.666667 */); + const SkPoint corners[] = { + { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ + { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ + { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ + { SkBits2Float(0x00000000), SkBits2Float(0x00000000) }, /* 0.000000 0.000000 */ + }; + SkRRect copy; + copy.setRectRadii(bounds, corners); + SkDebugf("rrect is " "%s" "equal to copy\n", rrect == copy ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Rect_000.cpp b/docs/examples/Rect_000.cpp new file mode 100644 index 0000000000..5e3fd696ef --- /dev/null +++ b/docs/examples/Rect_000.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=2e262d0ac4b8ef51695e0525fc3ecdf6 +REG_FIDDLE(Rect_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = SkRect::MakeEmpty(); + SkDebugf("MakeEmpty isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); + rect.offset(10, 10); + SkDebugf("offset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); + rect.inset(10, 10); + SkDebugf("inset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); + rect.outset(20, 20); + SkDebugf("outset rect isEmpty: %s\n", rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_001.cpp b/docs/examples/Rect_001.cpp new file mode 100644 index 0000000000..75aa7a5202 --- /dev/null +++ b/docs/examples/Rect_001.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=8009d30f431e01f8aea4808e9017d9bf +REG_FIDDLE(Rect_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect1 = SkRect::MakeWH(25, 35); + SkRect rect2 = SkRect::MakeIWH(25, 35); + SkRect rect3 = SkRect::MakeXYWH(0, 0, 25, 35); + SkRect rect4 = SkRect::MakeLTRB(0, 0, 25, 35); + SkDebugf("all %s" "equal\n", rect1 == rect2 && rect2 == rect3 && rect3 == rect4 ? + "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Rect_002.cpp b/docs/examples/Rect_002.cpp new file mode 100644 index 0000000000..f09af820c3 --- /dev/null +++ b/docs/examples/Rect_002.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=faa660ac19eaddc3f3eab57a0bddfdcb +REG_FIDDLE(Rect_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect i_rect = SkIRect::MakeWH(25, 35); + SkRect f_rect = SkRect::MakeIWH(25, 35); + SkDebugf("i_rect width: %d f_rect width:%g\n", i_rect.width(), f_rect.width()); + i_rect = SkIRect::MakeWH(125000111, 0); + f_rect = SkRect::MakeIWH(125000111, 0); + SkDebugf("i_rect width: %d f_rect width:%.0f\n", i_rect.width(), f_rect.width()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_003.cpp b/docs/examples/Rect_003.cpp new file mode 100644 index 0000000000..ffe097350a --- /dev/null +++ b/docs/examples/Rect_003.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=ab2c1a55016c8de9172b77fdf69e00a2 +REG_FIDDLE(Rect_003, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkSize size = {25.5f, 35.5f}; + SkRect rect = SkRect::MakeSize(size); + SkDebugf("rect width: %g height: %g\n", rect.width(), rect.height()); + SkISize floor = size.toFloor(); + rect = SkRect::MakeSize(SkSize::Make(floor)); + SkDebugf("floor width: %g height: %g\n", rect.width(), rect.height()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_004.cpp b/docs/examples/Rect_004.cpp new file mode 100644 index 0000000000..3fde17b9fe --- /dev/null +++ b/docs/examples/Rect_004.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=158b8dd9d02d65a5ae5ab7d1595a5b4c +REG_FIDDLE(Rect_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = SkRect::MakeLTRB(5, 35, 15, 25); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect.sort(); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_005.cpp b/docs/examples/Rect_005.cpp new file mode 100644 index 0000000000..8655c4cc6d --- /dev/null +++ b/docs/examples/Rect_005.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=38e464dba13be11ac21e210fbf3b5afc +REG_FIDDLE(Rect_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = SkRect::MakeXYWH(5, 35, -15, 25); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect.sort(); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_006.cpp b/docs/examples/Rect_006.cpp new file mode 100644 index 0000000000..322ca9b88e --- /dev/null +++ b/docs/examples/Rect_006.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=e866f5e4f6ac52e89acadf48e54ac8e0 +REG_FIDDLE(Rect_006, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect1 = SkRect::MakeSize({2, 35}); + SkRect rect2 = SkRect::MakeIWH(2, 35); + SkDebugf("rect1 %c= rect2\n", rect1 == rect2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Rect_007.cpp b/docs/examples/Rect_007.cpp new file mode 100644 index 0000000000..1abe2f0448 --- /dev/null +++ b/docs/examples/Rect_007.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=dd801faa1e60a0fe9e0657674461e063 +REG_FIDDLE(Rect_007, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect i_rect1 = {2, 35, 22, 53}; + SkRect f_rect = SkRect::Make(i_rect1); + f_rect.offset(0.49f, 0.49f); + SkIRect i_rect2; + f_rect.round(&i_rect2); + SkDebugf("i_rect1 %c= i_rect2\n", i_rect1 == i_rect2? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Rect_008.cpp b/docs/examples/Rect_008.cpp new file mode 100644 index 0000000000..425c434731 --- /dev/null +++ b/docs/examples/Rect_008.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=1d7b924d6ca2a6aef09684a8a632439c +REG_FIDDLE(Rect_008, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; + for (auto rect : tests) { + SkDebugf("rect: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "" : " not"); + rect.sort(); + SkDebugf("sorted: {%g, %g, %g, %g} is" "%s empty\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "" : " not"); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_009.cpp b/docs/examples/Rect_009.cpp new file mode 100644 index 0000000000..35ae9d8bd4 --- /dev/null +++ b/docs/examples/Rect_009.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=c7065a83b220a96f903dbbb65906fe7b +REG_FIDDLE(Rect_009, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect tests[] = {{20, 40, 10, 50}, {20, 40, 20, 50}}; + for (auto rect : tests) { + SkDebugf("rect: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isSorted() ? "" : " not"); + rect.sort(); + SkDebugf("sorted: {%g, %g, %g, %g} is" "%s sorted\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isSorted() ? "" : " not"); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_010.cpp b/docs/examples/Rect_010.cpp new file mode 100644 index 0000000000..33eac24d5c --- /dev/null +++ b/docs/examples/Rect_010.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=443fe5f8296d4cdb19cc9862a9cf77a4 +REG_FIDDLE(Rect_010, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect largest = { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax }; + SkDebugf("largest is finite: %s\n", largest.isFinite() ? "true" : "false"); + SkDebugf("large width %g\n", largest.width()); + SkRect widest = SkRect::MakeWH(largest.width(), largest.height()); + SkDebugf("widest is finite: %s\n", widest.isFinite() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_011.cpp b/docs/examples/Rect_011.cpp new file mode 100644 index 0000000000..4e219fd93d --- /dev/null +++ b/docs/examples/Rect_011.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=23c77a35ac54a439a2989f840aa5cb99 +REG_FIDDLE(Rect_011, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect unsorted = { 15, 5, 10, 25 }; + SkDebugf("unsorted.fLeft: %g unsorted.x(): %g\n", unsorted.fLeft, unsorted.x()); + SkRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fLeft: %g sorted.x(): %g\n", sorted.fLeft, sorted.x()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_012.cpp b/docs/examples/Rect_012.cpp new file mode 100644 index 0000000000..ed06b3f514 --- /dev/null +++ b/docs/examples/Rect_012.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=c653d9017983d2a047b1fee6a481d82b +REG_FIDDLE(Rect_012, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted.fTop: %g unsorted.y(): %g\n", unsorted.fTop, unsorted.y()); + SkRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fTop: %g sorted.y(): %g\n", sorted.fTop, sorted.y()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_013.cpp b/docs/examples/Rect_013.cpp new file mode 100644 index 0000000000..ab364b6834 --- /dev/null +++ b/docs/examples/Rect_013.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=900dc96c3549795a87036d6458c4fde6 +REG_FIDDLE(Rect_013, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect unsorted = { 15, 5, 10, 25 }; + SkDebugf("unsorted.fLeft: %g unsorted.left(): %g\n", unsorted.fLeft, unsorted.left()); + SkRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fLeft: %g sorted.left(): %g\n", sorted.fLeft, sorted.left()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_014.cpp b/docs/examples/Rect_014.cpp new file mode 100644 index 0000000000..0330199541 --- /dev/null +++ b/docs/examples/Rect_014.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=3cfc24b011aef1ca8ccb57c05711620c +REG_FIDDLE(Rect_014, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted.fTop: %g unsorted.top(): %g\n", unsorted.fTop, unsorted.top()); + SkRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fTop: %g sorted.top(): %g\n", sorted.fTop, sorted.top()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_015.cpp b/docs/examples/Rect_015.cpp new file mode 100644 index 0000000000..4b47a66c02 --- /dev/null +++ b/docs/examples/Rect_015.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=ca3de7e5e292b3ad3633b1c39a31d3ab +REG_FIDDLE(Rect_015, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted.fRight: %g unsorted.right(): %g\n", unsorted.fRight, unsorted.right()); + SkRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fRight: %g sorted.right(): %g\n", sorted.fRight, sorted.right()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_016.cpp b/docs/examples/Rect_016.cpp new file mode 100644 index 0000000000..d3d2ff3c6f --- /dev/null +++ b/docs/examples/Rect_016.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=a98993a66616ae406d8bdc54adfb1411 +REG_FIDDLE(Rect_016, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted.fBottom: %g unsorted.bottom(): %g\n", unsorted.fBottom, unsorted.bottom()); + SkRect sorted = unsorted.makeSorted(); + SkDebugf("sorted.fBottom: %g sorted.bottom(): %g\n", sorted.fBottom, sorted.bottom()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_017.cpp b/docs/examples/Rect_017.cpp new file mode 100644 index 0000000000..ab2391bab6 --- /dev/null +++ b/docs/examples/Rect_017.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=11f8f0efe6291019fee0ac17844f6c1a +REG_FIDDLE(Rect_017, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect unsorted = { 15, 25, 10, 5 }; + SkDebugf("unsorted width: %g\n", unsorted.width()); + SkRect large = { -2147483647.f, 1, 2147483644.f, 2 }; + SkDebugf("large width: %.0f\n", large.width()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_018.cpp b/docs/examples/Rect_018.cpp new file mode 100644 index 0000000000..0069824337 --- /dev/null +++ b/docs/examples/Rect_018.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=39429e45f05240218ecd511443ab3e44 +REG_FIDDLE(Rect_018, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect unsorted = { 15, 25, 10, 20 }; + SkDebugf("unsorted height: %g\n", unsorted.height()); + SkRect large = { 1, -2147483647.f, 2, 2147483644.f }; + SkDebugf("large height: %.0f\n", large.height()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_019.cpp b/docs/examples/Rect_019.cpp new file mode 100644 index 0000000000..76dc442bf3 --- /dev/null +++ b/docs/examples/Rect_019.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=d8439ba8d23a424fa032fb97147fd2d2 +REG_FIDDLE(Rect_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect tests[] = {{20, 30, 41, 51}, {-20, -30, -41, -51}}; + for (auto rect : tests) { + SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX()); + rect.sort(); + SkDebugf("left: %3g right: %3g centerX: %3g\n", rect.left(), rect.right(), rect.centerX()); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_020.cpp b/docs/examples/Rect_020.cpp new file mode 100644 index 0000000000..d05b6acfba --- /dev/null +++ b/docs/examples/Rect_020.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=ebeeafafeb8fe39d5ffc9115b02c2340 +REG_FIDDLE(Rect_020, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 2e+38, 2e+38, 3e+38, 3e+38 }; + SkDebugf("left: %g right: %g centerX: %g ", rect.left(), rect.right(), rect.centerX()); + SkDebugf("safe mid x: %g\n", rect.left() / 2 + rect.right() / 2); +} +} // END FIDDLE diff --git a/docs/examples/Rect_021.cpp b/docs/examples/Rect_021.cpp new file mode 100644 index 0000000000..ebb5c5587d --- /dev/null +++ b/docs/examples/Rect_021.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=c6c5b40cad7c3a839fdf576b380391a6 +REG_FIDDLE(Rect_021, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const SkRect& test) -> void { + SkRect negZero = {-0.0f, -0.0f, 2, 2}; + SkDebugf("{%g, %g, %g, %g} %c= {%g, %g, %g, %g} %s numerically equal\n", + test.fLeft, test.fTop, test.fRight, test.fBottom, + negZero.fLeft, negZero.fTop, negZero.fRight, negZero.fBottom, + test == negZero ? '=' : '!', + test.fLeft == negZero.fLeft && test.fTop == negZero.fTop && + test.fRight == negZero.fRight && test.fBottom == negZero.fBottom ? + "and are" : "yet are not"); + }; + SkRect tests[] = {{0, 0, 2, 2}, {-0, -0, 2, 2}, {0.0f, 0.0f, 2, 2}}; + SkDebugf("tests are %s" "equal\n", tests[0] == tests[1] && tests[1] == tests[2] ? "" : "not "); + for (auto rect : tests) { + debugster(rect); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_022.cpp b/docs/examples/Rect_022.cpp new file mode 100644 index 0000000000..88662e5d38 --- /dev/null +++ b/docs/examples/Rect_022.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=286072f8c27ff15be9eb945fa38dc9f7 +REG_FIDDLE(Rect_022, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect test = {0, 0, 2, SK_ScalarNaN}; + SkDebugf("test with NaN is %s" "equal to itself\n", test == test ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Rect_023.cpp b/docs/examples/Rect_023.cpp new file mode 100644 index 0000000000..85522958c1 --- /dev/null +++ b/docs/examples/Rect_023.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=59a6e7d202ac17ab80ec21b233e51f59 +REG_FIDDLE(Rect_023, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = {1, 2, 3, 4}; + SkPoint corners[4]; + rect.toQuad(corners); + SkDebugf("rect: {%g, %g, %g, %g}\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + SkDebugf("corners:"); + for (auto corner : corners) { + SkDebugf(" {%g, %g}", corner.fX, corner.fY); + } + SkDebugf("\n"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_024.cpp b/docs/examples/Rect_024.cpp new file mode 100644 index 0000000000..cadc0e7e14 --- /dev/null +++ b/docs/examples/Rect_024.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=cf0da15f48aa54fd1889e7f913601710 +REG_FIDDLE(Rect_024, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}}; + for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) { + SkRect rect; + rect.setBounds(points, count); + if (count > 0) { + SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY); + } else { + SkDebugf("%14s", " "); + } + SkDebugf("count: %d rect: %g, %g, %g, %g\n", count, + rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_025.cpp b/docs/examples/Rect_025.cpp new file mode 100644 index 0000000000..bc5df81aa6 --- /dev/null +++ b/docs/examples/Rect_025.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=83d879b92683b15f9daaf0c9e71c5b35 +REG_FIDDLE(Rect_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}}; + for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) { + SkRect rect; + bool success = rect.setBoundsCheck(points, count); + if (count > 0) { + SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY); + } else { + SkDebugf("%14s", " "); + } + SkDebugf("count: %d rect: %g, %g, %g, %g success: %s\n", count, + rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, success ? "true" : "false"); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_026.cpp b/docs/examples/Rect_026.cpp new file mode 100644 index 0000000000..637a174562 --- /dev/null +++ b/docs/examples/Rect_026.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=be10cb1411dbcf7e38e0198e8a9b8b0e +REG_FIDDLE(Rect_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint points[] = {{3, 4}, {1, 2}, {SK_ScalarInfinity, 6}, {SK_ScalarNaN, 8}}; + for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) { + SkRect rect; + rect.setBoundsNoCheck(points, count); + if (count > 0) { + SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY); + } else { + SkDebugf("%14s", " "); + } + SkDebugf("count: %d rect: %g, %g, %g, %g\n", count, + rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_027.cpp b/docs/examples/Rect_027.cpp new file mode 100644 index 0000000000..84ea41a45c --- /dev/null +++ b/docs/examples/Rect_027.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=2cf67542d45ef5d7a7efb673b651ff54 +REG_FIDDLE(Rect_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = {3, 4, 1, 2}; + for (int i = 0; i < 2; ++i) { + SkDebugf("rect: {%g, %g, %g, %g} is %s" "empty\n", rect.fLeft, rect.fTop, + rect.fRight, rect.fBottom, rect.isEmpty() ? "" : "not "); + rect.setEmpty(); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_028.cpp b/docs/examples/Rect_028.cpp new file mode 100644 index 0000000000..9e6780283d --- /dev/null +++ b/docs/examples/Rect_028.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=a10ad8d97062bc3f40942f47e5108917 +REG_FIDDLE(Rect_028, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkIRect i_rect = {3, 4, 1, 2}; + SkDebugf("i_rect: {%d, %d, %d, %d}\n", i_rect.fLeft, i_rect.fTop, i_rect.fRight, i_rect.fBottom); + SkRect f_rect; + f_rect.set(i_rect); + SkDebugf("f_rect: {%g, %g, %g, %g}\n", f_rect.fLeft, f_rect.fTop, f_rect.fRight, f_rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_029.cpp b/docs/examples/Rect_029.cpp new file mode 100644 index 0000000000..0f467b1c29 --- /dev/null +++ b/docs/examples/Rect_029.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=9b29ea460d69b4d47323fd9e3e17721e +REG_FIDDLE(Rect_029, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect1 = {3, 4, 1, 2}; + SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); + SkRect rect2; + rect2.set(3, 4, 1, 2); + SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_030.cpp b/docs/examples/Rect_030.cpp new file mode 100644 index 0000000000..ee2f6dde1d --- /dev/null +++ b/docs/examples/Rect_030.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=70692838793454c8e045d6eaf7edcbff +REG_FIDDLE(Rect_030, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect1 = {3, 4, 1, 2}; + SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); + SkRect rect2; + rect2.setLTRB(3, 4, 1, 2); + SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_031.cpp b/docs/examples/Rect_031.cpp new file mode 100644 index 0000000000..26a324ab4b --- /dev/null +++ b/docs/examples/Rect_031.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=94295fa5197e21256171b99b4023dd48 +REG_FIDDLE(Rect_031, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint points[] = {{3, 4}, {1, 2}, {5, 6}, {SK_ScalarNaN, 8}}; + for (int count = 0; count <= (int) SK_ARRAY_COUNT(points); ++count) { + SkRect rect; + rect.set(points, count); + if (count > 0) { + SkDebugf("added: %3g, %g ", points[count - 1].fX, points[count - 1].fY); + } else { + SkDebugf("%14s", " "); + } + SkDebugf("count: %d rect: %g, %g, %g, %g\n", count, + rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_032.cpp b/docs/examples/Rect_032.cpp new file mode 100644 index 0000000000..ffca25698f --- /dev/null +++ b/docs/examples/Rect_032.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=ee72450381f768f3869153cdbeccdc3e +REG_FIDDLE(Rect_032, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkPoint point1 = {SK_ScalarNaN, 8}; + SkPoint point2 = {3, 4}; + SkRect rect; + rect.set(point1, point2); + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + rect.set(point2, point1); + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_033.cpp b/docs/examples/Rect_033.cpp new file mode 100644 index 0000000000..93205fe12a --- /dev/null +++ b/docs/examples/Rect_033.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=373cce4c61b9da0384b735b838765163 +REG_FIDDLE(Rect_033, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect; + rect.setXYWH(5, 35, -15, 25); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect.sort(); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_034.cpp b/docs/examples/Rect_034.cpp new file mode 100644 index 0000000000..3a84c556df --- /dev/null +++ b/docs/examples/Rect_034.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=9cb5fee17802fa49341f3707bdf5d235 +REG_FIDDLE(Rect_034, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect; + rect.setWH(-15, 25); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect.sort(); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_035.cpp b/docs/examples/Rect_035.cpp new file mode 100644 index 0000000000..6251d56e38 --- /dev/null +++ b/docs/examples/Rect_035.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=18532f1aa90b76364fb8d7ea072f1892 +REG_FIDDLE(Rect_035, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect1 = {3, 4, 1, 2}; + SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); + SkRect rect2; + rect2.iset(3, 4, 1, 2); + SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_036.cpp b/docs/examples/Rect_036.cpp new file mode 100644 index 0000000000..98ecd53c9a --- /dev/null +++ b/docs/examples/Rect_036.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=ee6000080fc7123214ea404018cf9176 +REG_FIDDLE(Rect_036, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect1 = {0, 0, 1, 2}; + SkDebugf("rect1: {%g, %g, %g, %g}\n", rect1.fLeft, rect1.fTop, rect1.fRight, rect1.fBottom); + SkRect rect2; + rect2.isetWH(1, 2); + SkDebugf("rect2: {%g, %g, %g, %g}\n", rect2.fLeft, rect2.fTop, rect2.fRight, rect2.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_037.cpp b/docs/examples/Rect_037.cpp new file mode 100644 index 0000000000..21602d80c8 --- /dev/null +++ b/docs/examples/Rect_037.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=98841ab0a932f99cccd8e6a34d94ba05 +REG_FIDDLE(Rect_037, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 50, 20, 60 }; + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect = rect.makeOffset(15, 32); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_038.cpp b/docs/examples/Rect_038.cpp new file mode 100644 index 0000000000..2c6c54c076 --- /dev/null +++ b/docs/examples/Rect_038.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=b8d32ab2f7ea3d4d5fb5a4ea2156f1c5 +REG_FIDDLE(Rect_038, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 50, 20, 60 }; + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect = rect.makeInset(15, 32); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_039.cpp b/docs/examples/Rect_039.cpp new file mode 100644 index 0000000000..e2b73bdc2f --- /dev/null +++ b/docs/examples/Rect_039.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=87176fc60914cbca9c6a20998a033c24 +REG_FIDDLE(Rect_039, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 50, 20, 60 }; + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); + rect = rect.makeOutset(15, 32); + SkDebugf("rect: %g, %g, %g, %g isEmpty: %s\n", rect.left(), rect.top(), rect.right(), + rect.bottom(), rect.isEmpty() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Rect_040.cpp b/docs/examples/Rect_040.cpp new file mode 100644 index 0000000000..e4844ae4d0 --- /dev/null +++ b/docs/examples/Rect_040.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=04eb33f0fd376f2942ca5f1c7f6cbcfc +REG_FIDDLE(Rect_040, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 14, 50, 73 }; + rect.offset(5, 13); + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_041.cpp b/docs/examples/Rect_041.cpp new file mode 100644 index 0000000000..4c825a42fb --- /dev/null +++ b/docs/examples/Rect_041.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=b24cf65561c98c1858a06c39f10fb797 +REG_FIDDLE(Rect_041, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 14, 50, 73 }; + rect.offset({5, 13}); + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_042.cpp b/docs/examples/Rect_042.cpp new file mode 100644 index 0000000000..a7e47f536b --- /dev/null +++ b/docs/examples/Rect_042.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=bedb04b7b3e1af3e8039f9cffe66989e +REG_FIDDLE(Rect_042, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 14, 50, 73 }; + rect.offsetTo(15, 27); + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_043.cpp b/docs/examples/Rect_043.cpp new file mode 100644 index 0000000000..4bb4ecc874 --- /dev/null +++ b/docs/examples/Rect_043.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=dae21340941dc6e4d048816dfd9f204c +REG_FIDDLE(Rect_043, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 14, 50, 73 }; + rect.inset(5, 13); + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_044.cpp b/docs/examples/Rect_044.cpp new file mode 100644 index 0000000000..aa131c538d --- /dev/null +++ b/docs/examples/Rect_044.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=861f873ba660af8c8bf8b0b83d829cf4 +REG_FIDDLE(Rect_044, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 14, 50, 73 }; + rect.outset(5, 13); + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_045.cpp b/docs/examples/Rect_045.cpp new file mode 100644 index 0000000000..257b85b9d9 --- /dev/null +++ b/docs/examples/Rect_045.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=85be528a78945a6dc4f7dccb80a80746 +REG_FIDDLE(Rect_045, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30, 50, 40, 60 }; + SkPoint tests[] = { { 30, 50 }, { 39, 49 }, { 29, 59 } }; + for (auto contained : tests) { + SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g)\n", + rect.left(), rect.top(), rect.right(), rect.bottom(), + rect.contains(contained.x(), contained.y()) ? "contains" : "does not contain", + contained.x(), contained.y()); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_046.cpp b/docs/examples/Rect_046.cpp new file mode 100644 index 0000000000..56d397185a --- /dev/null +++ b/docs/examples/Rect_046.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=92f9e6aa5bb76791139a24cf7d8df99e +REG_FIDDLE(Rect_046, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30, 50, 40, 60 }; + SkRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; + for (auto contained : tests) { + SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g, %g, %g)\n", + rect.left(), rect.top(), rect.right(), rect.bottom(), + rect.contains(contained) ? "contains" : "does not contain", + contained.left(), contained.top(), contained.right(), contained.bottom()); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_047.cpp b/docs/examples/Rect_047.cpp new file mode 100644 index 0000000000..19be5cdaff --- /dev/null +++ b/docs/examples/Rect_047.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=dd58b699551dd44026a2c6386be27d88 +REG_FIDDLE(Rect_047, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30, 50, 40, 60 }; + SkIRect tests[] = { { 30, 50, 31, 51}, { 39, 49, 40, 50}, { 29, 59, 30, 60} }; + for (auto contained : tests) { + SkDebugf("rect: (%g, %g, %g, %g) %s (%d, %d, %d, %d)\n", + rect.left(), rect.top(), rect.right(), rect.bottom(), + rect.contains(contained) ? "contains" : "does not contain", + contained.left(), contained.top(), contained.right(), contained.bottom()); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_048.cpp b/docs/examples/Rect_048.cpp new file mode 100644 index 0000000000..f70f863efb --- /dev/null +++ b/docs/examples/Rect_048.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=5d0b12e0ef6f1c181dddded4274230ca +REG_FIDDLE(Rect_048, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect leftRect = { 10, 40, 50, 80 }; + SkRect rightRect = { 30, 60, 70, 90 }; + SkDebugf("%s intersection: ", leftRect.intersect(rightRect) ? "" : "no "); + SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(), + leftRect.right(), leftRect.bottom()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_049.cpp b/docs/examples/Rect_049.cpp new file mode 100644 index 0000000000..c8b0b537bf --- /dev/null +++ b/docs/examples/Rect_049.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=5002f65a72def2787086a33131933e70 +REG_FIDDLE(Rect_049, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect leftRect = { 10, 40, 50, 80 }; + SkDebugf("%s intersection: ", leftRect.intersect(30, 60, 70, 90) ? "" : "no "); + SkDebugf("%g, %g, %g, %g\n", leftRect.left(), leftRect.top(), + leftRect.right(), leftRect.bottom()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_050.cpp b/docs/examples/Rect_050.cpp new file mode 100644 index 0000000000..8a3d5035fd --- /dev/null +++ b/docs/examples/Rect_050.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=d610437a65dd3e952719efe605cbd0c7 +REG_FIDDLE(Rect_050, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect result; + bool intersected = result.intersect({ 10, 40, 50, 80 }, { 30, 60, 70, 90 }); + SkDebugf("%s intersection: %g, %g, %g, %g\n", intersected ? "" : "no ", + result.left(), result.top(), result.right(), result.bottom()); +} +} // END FIDDLE diff --git a/docs/examples/Rect_051.cpp b/docs/examples/Rect_051.cpp new file mode 100644 index 0000000000..192f02c56b --- /dev/null +++ b/docs/examples/Rect_051.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=7145dc17ebce4f54e892102f6c98e811 +REG_FIDDLE(Rect_051, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 40, 50, 80 }; + SkDebugf("%s intersection", rect.intersects(30, 60, 70, 90) ? "" : "no "); +} +} // END FIDDLE diff --git a/docs/examples/Rect_052.cpp b/docs/examples/Rect_052.cpp new file mode 100644 index 0000000000..fe43bb73c5 --- /dev/null +++ b/docs/examples/Rect_052.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=ca37b4231b21eb8296cb19ba9e0c781b +REG_FIDDLE(Rect_052, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 40, 50, 80 }; + SkDebugf("%s intersection", rect.intersects({30, 60, 70, 90}) ? "" : "no "); +} +} // END FIDDLE diff --git a/docs/examples/Rect_053.cpp b/docs/examples/Rect_053.cpp new file mode 100644 index 0000000000..a9cbb3717a --- /dev/null +++ b/docs/examples/Rect_053.cpp @@ -0,0 +1,9 @@ +// 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 "fiddle/examples.h" +// HASH=795061764b10c9e05efb466c9cb60644 +REG_FIDDLE(Rect_053, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("%s intersection", SkRect::Intersects({10, 40, 50, 80}, {30, 60, 70, 90}) ? "" : "no "); +} +} // END FIDDLE diff --git a/docs/examples/Rect_054.cpp b/docs/examples/Rect_054.cpp new file mode 100644 index 0000000000..0dae35d3ce --- /dev/null +++ b/docs/examples/Rect_054.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=afa9c6b4d05bb669db07fe0b7b97e6aa +REG_FIDDLE(Rect_054, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 20, 15, 25}; + rect.join(50, 60, 55, 65); + SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_055.cpp b/docs/examples/Rect_055.cpp new file mode 100644 index 0000000000..b91ff5a01d --- /dev/null +++ b/docs/examples/Rect_055.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=26500032494cf93c5fa3423110fe82af +REG_FIDDLE(Rect_055, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 20, 15, 25}; + rect.join({50, 60, 55, 65}); + SkDebugf("join: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_056.cpp b/docs/examples/Rect_056.cpp new file mode 100644 index 0000000000..58f80696fb --- /dev/null +++ b/docs/examples/Rect_056.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=88439de2aa0911262c60c0eb506396cb +REG_FIDDLE(Rect_056, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 100, 15, 0}; + SkRect sorted = rect.makeSorted(); + SkRect toJoin = { 50, 60, 55, 65 }; + rect.joinNonEmptyArg(toJoin); + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + sorted.joinNonEmptyArg(toJoin); + SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_057.cpp b/docs/examples/Rect_057.cpp new file mode 100644 index 0000000000..26a511607c --- /dev/null +++ b/docs/examples/Rect_057.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=a476548d0001296afd8e58c1eba1b70b +REG_FIDDLE(Rect_057, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 10, 100, 15, 0}; + SkRect sorted = rect.makeSorted(); + SkRect toJoin = { 50, 60, 55, 65 }; + rect.joinPossiblyEmptyRect(toJoin); + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + sorted.joinPossiblyEmptyRect(toJoin); + SkDebugf("sorted: %g, %g, %g, %g\n", sorted.fLeft, sorted.fTop, sorted.fRight, sorted.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_058.cpp b/docs/examples/Rect_058.cpp new file mode 100644 index 0000000000..865746a692 --- /dev/null +++ b/docs/examples/Rect_058.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=8b9e5a9af0a9b878f76919534d88f41e +REG_FIDDLE(Rect_058, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; + SkIRect round; + rect.round(&round); + SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_059.cpp b/docs/examples/Rect_059.cpp new file mode 100644 index 0000000000..8471e0566d --- /dev/null +++ b/docs/examples/Rect_059.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=0bd13d7e6426ae7a3befa2ab151ac5fc +REG_FIDDLE(Rect_059, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; + SkIRect round; + rect.roundOut(&round); + SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_060.cpp b/docs/examples/Rect_060.cpp new file mode 100644 index 0000000000..a59f28ddb3 --- /dev/null +++ b/docs/examples/Rect_060.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=e09a6a12869a8ac21e9c2af98a5bb686 +REG_FIDDLE(Rect_060, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; + SkRect round; + rect.roundOut(&round); + SkDebugf("round: %g, %g, %g, %g\n", round.fLeft, round.fTop, round.fRight, round.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_061.cpp b/docs/examples/Rect_061.cpp new file mode 100644 index 0000000000..2c3918b70a --- /dev/null +++ b/docs/examples/Rect_061.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=abb337da8fc1891f016c61258681c64c +REG_FIDDLE(Rect_061, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; + SkIRect round; + rect.roundIn(&round); + SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_062.cpp b/docs/examples/Rect_062.cpp new file mode 100644 index 0000000000..3515b4c324 --- /dev/null +++ b/docs/examples/Rect_062.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=ef7ae1dd522c235b0afe41b55a624f46 +REG_FIDDLE(Rect_062, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; + SkIRect round = rect.round(); + SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_063.cpp b/docs/examples/Rect_063.cpp new file mode 100644 index 0000000000..1d0533a375 --- /dev/null +++ b/docs/examples/Rect_063.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=05f0f65ae148f192656cd87df90f1d57 +REG_FIDDLE(Rect_063, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30.5f, 50.5f, 40.5f, 60.5f }; + SkIRect round = rect.roundOut(); + SkDebugf("round: %d, %d, %d, %d\n", round.fLeft, round.fTop, round.fRight, round.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_064.cpp b/docs/examples/Rect_064.cpp new file mode 100644 index 0000000000..ee6543465c --- /dev/null +++ b/docs/examples/Rect_064.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=e624fe398e3d770b573c09fc74c0c400 +REG_FIDDLE(Rect_064, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f }; + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + rect.sort(); + SkDebugf("sorted: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_065.cpp b/docs/examples/Rect_065.cpp new file mode 100644 index 0000000000..aa255e222e --- /dev/null +++ b/docs/examples/Rect_065.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=f59567042b87f6b26f9bfeeb04468032 +REG_FIDDLE(Rect_065, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = { 30.5f, 50.5f, 20.5f, 10.5f }; + SkDebugf("rect: %g, %g, %g, %g\n", rect.fLeft, rect.fTop, rect.fRight, rect.fBottom); + SkRect sort = rect.makeSorted(); + SkDebugf("sorted: %g, %g, %g, %g\n", sort.fLeft, sort.fTop, sort.fRight, sort.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Rect_066.cpp b/docs/examples/Rect_066.cpp new file mode 100644 index 0000000000..9eedba65ed --- /dev/null +++ b/docs/examples/Rect_066.cpp @@ -0,0 +1,10 @@ +// 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 "fiddle/examples.h" +// HASH=e1ea5f949d80276f3637931eae93a07c +REG_FIDDLE(Rect_066, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = {7, 11, 13, 17}; + SkDebugf("rect.asScalars() %c= &rect.fLeft\n", rect.asScalars() == &rect.fLeft? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Rect_067.cpp b/docs/examples/Rect_067.cpp new file mode 100644 index 0000000000..5b74af7f35 --- /dev/null +++ b/docs/examples/Rect_067.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=cea049ffff702a5923da41fe0ae0763b +REG_FIDDLE(Rect_067, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = {20, 30, 40, 50}; + for (bool dumpAsHex : { false, true } ) { + rect.dump(dumpAsHex); + SkDebugf("\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Rect_068.cpp b/docs/examples/Rect_068.cpp new file mode 100644 index 0000000000..18c89fc1e4 --- /dev/null +++ b/docs/examples/Rect_068.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=9fb76971b1a104a2a59816e0392267a7 +REG_FIDDLE(Rect_068, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6}; + rect.dump(); + SkRect copy = SkRect::MakeLTRB(0.857143f, 0.666667f, 2.6f, 7); + SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Rect_069.cpp b/docs/examples/Rect_069.cpp new file mode 100644 index 0000000000..51c76fb1aa --- /dev/null +++ b/docs/examples/Rect_069.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=824b5a3fcfd46a7e1c5f9e3c16e6bb39 +REG_FIDDLE(Rect_069, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRect rect = {6.f / 7, 2.f / 3, 26.f / 10, 42.f / 6}; + rect.dumpHex(); + SkRect copy = SkRect::MakeLTRB(SkBits2Float(0x3f5b6db7), /* 0.857143 */ + SkBits2Float(0x3f2aaaab), /* 0.666667 */ + SkBits2Float(0x40266666), /* 2.600000 */ + SkBits2Float(0x40e00000) /* 7.000000 */); + SkDebugf("rect is " "%s" "equal to copy\n", rect == copy ? "" : "not "); +} +} // END FIDDLE diff --git a/docs/examples/Region_000.cpp b/docs/examples/Region_000.cpp new file mode 100644 index 0000000000..be8c252381 --- /dev/null +++ b/docs/examples/Region_000.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=a2db43ee3cbf6893e9b23927fb44298a +REG_FIDDLE(Region_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion::Iterator iter; + SkRegion region; + region.setRect({1, 2, 3, 4}); + iter.reset(region); + auto r = iter.rect(); + SkDebugf("rect={%d,%d,%d,%d}\n", r.fLeft, r.fTop, r.fRight, r.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Region_001.cpp b/docs/examples/Region_001.cpp new file mode 100644 index 0000000000..bfb899f0ae --- /dev/null +++ b/docs/examples/Region_001.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=e317ceca48a6a7504219af58f35d2c95 +REG_FIDDLE(Region_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + region.setRect({1, 2, 3, 4}); + SkRegion::Iterator iter(region); + auto r = iter.rect(); + SkDebugf("rect={%d,%d,%d,%d}\n", r.fLeft, r.fTop, r.fRight, r.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Region_002.cpp b/docs/examples/Region_002.cpp new file mode 100644 index 0000000000..800bfd0189 --- /dev/null +++ b/docs/examples/Region_002.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=32d51e959d6cc720a74ec4822511e2cd +REG_FIDDLE(Region_002, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion::Iterator& iter, bool addRewind) -> void { + if (addRewind) { + bool success = iter.rewind(); + SkDebugf("%14s rewind success=%s\n", label, success ? "true" : "false"); + } + auto r = iter.rect(); + SkDebugf("%14s rect={%d,%d,%d,%d}\n", label, r.fLeft, r.fTop, r.fRight, r.fBottom); + }; + SkRegion::Iterator iter; + debugster("empty iter", iter, true); + SkRegion region; + iter.reset(region); + debugster("empty region", iter, true); + region.setRect({1, 2, 3, 4}); + iter.reset(region); + debugster("after set rect", iter, false); + debugster("after rewind", iter, true); +} +} // END FIDDLE diff --git a/docs/examples/Region_003.cpp b/docs/examples/Region_003.cpp new file mode 100644 index 0000000000..01c02ce1f1 --- /dev/null +++ b/docs/examples/Region_003.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=d153f87bd518a4ab947b7e407ea1db79 +REG_FIDDLE(Region_003, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion::Iterator& iter) -> void { + SkDebugf("%14s: done=%s\n", label, iter.done() ? "true" : "false"); + }; + SkRegion region; + SkRegion::Iterator iter(region); + debugster("empty region", iter); + region.setRect({1, 2, 3, 4}); + debugster("after set rect", iter); + iter.reset(region); + debugster("after reset", iter); +} +} // END FIDDLE diff --git a/docs/examples/Region_004.cpp b/docs/examples/Region_004.cpp new file mode 100644 index 0000000000..341b53a37c --- /dev/null +++ b/docs/examples/Region_004.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=814efa7d7f4ae52dfc861a937c1b5c25 +REG_FIDDLE(Region_004, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + SkRegion::Iterator iter(region); + SkDebugf("done=%s\n", iter.done() ? "true" : "false"); + region.setRect({1, 2, 3, 4}); + iter.rewind(); + SkDebugf("done=%s\n", iter.done() ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Region_005.cpp b/docs/examples/Region_005.cpp new file mode 100644 index 0000000000..e6279fbe47 --- /dev/null +++ b/docs/examples/Region_005.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=771236c2eadfc2fcd02a3e61a0875d39 +REG_FIDDLE(Region_005, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + SkIRect rects[] = {{1, 2, 3, 4}, {5, 6, 7, 8}}; + region.setRects(rects, SK_ARRAY_COUNT(rects)); + SkRegion::Iterator iter(region); + do { + auto r2 = iter.rect(); + SkDebugf("rect={%d,%d,%d,%d}\n", r2.fLeft, r2.fTop, r2.fRight, r2.fBottom); + iter.next(); + } while (!iter.done()); +} +} // END FIDDLE diff --git a/docs/examples/Region_006.cpp b/docs/examples/Region_006.cpp new file mode 100644 index 0000000000..8474fbc636 --- /dev/null +++ b/docs/examples/Region_006.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=0e7c58ab5d3bcfb36b1f8464cf6c7d89 +REG_FIDDLE(Region_006, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + SkRegion::Iterator iter(region); + auto r1 = iter.rect(); + SkDebugf("rect={%d,%d,%d,%d}\n", r1.fLeft, r1.fTop, r1.fRight, r1.fBottom); + region.setRect({1, 2, 3, 4}); + iter.rewind(); + auto r2 = iter.rect(); + SkDebugf("rect={%d,%d,%d,%d}\n", r2.fLeft, r2.fTop, r2.fRight, r2.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Region_007.cpp b/docs/examples/Region_007.cpp new file mode 100644 index 0000000000..ffab57593d --- /dev/null +++ b/docs/examples/Region_007.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=bbc3c454a21186e2a16e843a5b061c44 +REG_FIDDLE(Region_007, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + SkIRect rects[] = {{1, 2, 3, 4}, {3, 4, 5, 6}}; + region.setRects(rects, SK_ARRAY_COUNT(rects)); + SkRegion::Iterator iter(region); + auto r = iter.rect(); + SkDebugf("rect={%d,%d,%d,%d}\n", r.fLeft, r.fTop, r.fRight, r.fBottom); + auto b = iter.rgn()->getBounds(); + SkDebugf("bounds={%d,%d,%d,%d}\n", b.fLeft, b.fTop, b.fRight, b.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Region_008.cpp b/docs/examples/Region_008.cpp new file mode 100644 index 0000000000..90d38c671e --- /dev/null +++ b/docs/examples/Region_008.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=3831fb6006a7e0ad5d140c266c22be78 +REG_FIDDLE(Region_008, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + region.setRect({1, 2, 3, 4}); + SkRegion::Cliperator clipper(region, {0, 0, 2, 3}); + auto r = clipper.rect(); + SkDebugf("rect={%d,%d,%d,%d}\n", r.fLeft, r.fTop, r.fRight, r.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Region_009.cpp b/docs/examples/Region_009.cpp new file mode 100644 index 0000000000..b824aa9d8a --- /dev/null +++ b/docs/examples/Region_009.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=6cca7b96836266800d852664a1366453 +REG_FIDDLE(Region_009, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + SkRegion::Cliperator clipper(region, {0, 0, 5, 5}); + SkDebugf("%14s done=%s\n", label, clipper.done() ? "true" : "false"); + }; + SkRegion region; + debugster("empty region", region); + region.setRect({1, 2, 3, 4}); + debugster("after add rect", region); +} +} // END FIDDLE diff --git a/docs/examples/Region_010.cpp b/docs/examples/Region_010.cpp new file mode 100644 index 0000000000..ee3e7a2606 --- /dev/null +++ b/docs/examples/Region_010.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=3bbcc7eec19c808a8167bbcc987199f8 +REG_FIDDLE(Region_010, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + SkIRect rects[] = {{1, 2, 3, 4}, {5, 6, 7, 8}}; + region.setRects(rects, SK_ARRAY_COUNT(rects)); + SkRegion::Cliperator clipper(region, {0, 3, 8, 7}); + do { + auto r2 = clipper.rect(); + SkDebugf("rect={%d,%d,%d,%d}\n", r2.fLeft, r2.fTop, r2.fRight, r2.fBottom); + clipper.next(); + } while (!clipper.done()); +} +} // END FIDDLE diff --git a/docs/examples/Region_011.cpp b/docs/examples/Region_011.cpp new file mode 100644 index 0000000000..652bfb5c02 --- /dev/null +++ b/docs/examples/Region_011.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=05791751f00b4c2426093fa143b43bc7 +REG_FIDDLE(Region_011, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + SkRegion::Cliperator clipper(region, {0, 0, 5, 3}); + auto r = clipper.rect(); + SkDebugf("%14s rect={%d,%d,%d,%d}\n", label, r.fLeft, r.fTop, r.fRight, r.fBottom); + }; + SkRegion region; + debugster("empty region", region); + region.setRect({1, 2, 3, 4}); + debugster("after set rect", region); +} +} // END FIDDLE diff --git a/docs/examples/Region_012.cpp b/docs/examples/Region_012.cpp new file mode 100644 index 0000000000..7b146bdf44 --- /dev/null +++ b/docs/examples/Region_012.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=3073b3f8ea7252871b6156ff674dc385 +REG_FIDDLE(Region_012, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + region.setRect({1, 2, 3, 4}); + SkRegion::Spanerator spanner(region, 3, 2, 4); + int left, right; + bool result = spanner.next(&left, &right); + SkDebugf("result=%s left=%d right=%d\n", result ? "true" : "false", left, right); +} +} // END FIDDLE diff --git a/docs/examples/Region_013.cpp b/docs/examples/Region_013.cpp new file mode 100644 index 0000000000..08a7d4581a --- /dev/null +++ b/docs/examples/Region_013.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=03d02180fee5f64ec4a3347e118fb2ec +REG_FIDDLE(Region_013, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + SkRegion::Spanerator spanner(region, 3, 2, 4); + int left, right; + bool result = spanner.next(&left, &right); + SkDebugf("%14s: result=%s", label, result ? "true" : "false"); + if (result) SkDebugf(" left=%d right=%d", left, right); + SkDebugf("\n"); + }; + SkRegion region; + debugster("empty region", region); + region.setRect({1, 2, 3, 4}); + debugster("after set rect", region); +} +} // END FIDDLE diff --git a/docs/examples/Region_014.cpp b/docs/examples/Region_014.cpp new file mode 100644 index 0000000000..8c6d277955 --- /dev/null +++ b/docs/examples/Region_014.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=4549dcda3e0f9a41b3daee0ed37deca8 +REG_FIDDLE(Region_014, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + SkIRect r = region.getBounds(); + SkDebugf("region bounds: {%d, %d, %d, %d}\n", r.fLeft, r.fTop, r.fRight, r.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Region_015.cpp b/docs/examples/Region_015.cpp new file mode 100644 index 0000000000..c2dc0d3381 --- /dev/null +++ b/docs/examples/Region_015.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=3daa83fca809b9ec6560d2ef9e2da5e6 +REG_FIDDLE(Region_015, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + auto r = region.getBounds(); + SkDebugf("%14s: {%d,%d,%d,%d}\n", label, r.fLeft, r.fTop, r.fRight, r.fBottom); + }; + SkRegion region({1, 2, 3, 4}); + SkRegion region2(region); + debugster("region bounds", region); + debugster("region2 bounds", region2); + region.setEmpty(); + SkDebugf(" after region set empty:\n"); + debugster("region bounds", region); + debugster("region2 bounds", region2); +} +} // END FIDDLE diff --git a/docs/examples/Region_016.cpp b/docs/examples/Region_016.cpp new file mode 100644 index 0000000000..529925a902 --- /dev/null +++ b/docs/examples/Region_016.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=5253910233f7961c30b4c18ab911e917 +REG_FIDDLE(Region_016, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region({1, 2, 3, 4}); + SkRegion region2; + region2.setRect({1, 2, 3, 4}); + SkDebugf("region %c= region2\n", region == region2 ? '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Region_017.cpp b/docs/examples/Region_017.cpp new file mode 100644 index 0000000000..a9f8317a01 --- /dev/null +++ b/docs/examples/Region_017.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=985ff654a6b67288d322c748132a088e +REG_FIDDLE(Region_017, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion* region = new SkRegion({1, 2, 3, 4}); + SkRegion region2(*region); + delete region; + auto r = region2.getBounds(); + SkDebugf("region2 bounds: {%d,%d,%d,%d}\n", r.fLeft, r.fTop, r.fRight, r.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Region_018.cpp b/docs/examples/Region_018.cpp new file mode 100644 index 0000000000..e6c5104043 --- /dev/null +++ b/docs/examples/Region_018.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=e8513f6394c24efaa301d41921c5241a +REG_FIDDLE(Region_018, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + auto r = region.getBounds(); + SkDebugf("%14s: {%d,%d,%d,%d}\n", label, r.fLeft, r.fTop, r.fRight, r.fBottom); + }; + SkRegion region1({1, 2, 3, 4}); + SkRegion region2 = region1; + debugster("region1 bounds", region1); + debugster("region2 bounds", region2); +} +} // END FIDDLE diff --git a/docs/examples/Region_019.cpp b/docs/examples/Region_019.cpp new file mode 100644 index 0000000000..5b40e7e065 --- /dev/null +++ b/docs/examples/Region_019.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=d7f4fdc8bc63ca8410ed166ecef0aef3 +REG_FIDDLE(Region_019, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkRegion& a, const SkRegion& b) -> void { + SkDebugf("%s one %c= two\n", prefix, a == b ? '=' : '!'); + }; + SkRegion one; + SkRegion two; + debugster("empty", one, two); + one.setRect({1, 2, 3, 4}); + debugster("set rect", one, two); + one.setEmpty(); + debugster("set empty", one, two); +} +} // END FIDDLE diff --git a/docs/examples/Region_020.cpp b/docs/examples/Region_020.cpp new file mode 100644 index 0000000000..8e6e961b39 --- /dev/null +++ b/docs/examples/Region_020.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=3357caa9d8d810f200cbccb668182496 +REG_FIDDLE(Region_020, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* prefix, const SkRegion& a, const SkRegion& b) -> void { + SkDebugf("%s one %c= two\n", prefix, a != b ? '!' : '='); + }; + SkRegion one; + SkRegion two; + debugster("empty", one, two); + one.setRect({1, 2, 3, 4}); + two.setRect({1, 2, 3, 3}); + debugster("set rect", one, two); + two.op({1, 3, 3, 4}, SkRegion::kUnion_Op); + debugster("union rect", one, two); +} +} // END FIDDLE diff --git a/docs/examples/Region_021.cpp b/docs/examples/Region_021.cpp new file mode 100644 index 0000000000..692bcd33a1 --- /dev/null +++ b/docs/examples/Region_021.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=b3538117c7ae2cb7de3b42ca45fe1b13 +REG_FIDDLE(Region_021, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + auto r = region.getBounds(); + SkDebugf("%14s: {%d,%d,%d,%d}\n", label, r.fLeft, r.fTop, r.fRight, r.fBottom); + }; + SkRegion region1({1, 2, 3, 4}); + SkRegion region2; + region2.set(region1); + debugster("region1 bounds", region1); + debugster("region2 bounds", region2); +} +} // END FIDDLE diff --git a/docs/examples/Region_022.cpp b/docs/examples/Region_022.cpp new file mode 100644 index 0000000000..f4bcdc917c --- /dev/null +++ b/docs/examples/Region_022.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=ae67b7b4c198b46c58e48f5af061c8f1 +REG_FIDDLE(Region_022, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + auto r = region.getBounds(); + SkDebugf("%14s: {%d,%d,%d,%d}\n", label, r.fLeft, r.fTop, r.fRight, r.fBottom); + }; + SkRegion region1({1, 2, 3, 4}); + SkRegion region2; + region1.swap(region2); + debugster("region1 bounds", region1); + debugster("region2 bounds", region2); +} +} // END FIDDLE diff --git a/docs/examples/Region_023.cpp b/docs/examples/Region_023.cpp new file mode 100644 index 0000000000..1be6875c55 --- /dev/null +++ b/docs/examples/Region_023.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=10ef0de39e8553dd97cf8668ce185070 +REG_FIDDLE(Region_023, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + SkDebugf("%14s: region is %s" "empty\n", label, region.isEmpty() ? "" : "not "); + }; + SkRegion region; + debugster("initial", region); + region.setRect({1, 2, 3, 4}); + debugster("set rect", region); + region.setEmpty(); + debugster("set empty", region); +} +} // END FIDDLE diff --git a/docs/examples/Region_024.cpp b/docs/examples/Region_024.cpp new file mode 100644 index 0000000000..d43c7ae0a8 --- /dev/null +++ b/docs/examples/Region_024.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=b6adbdddf7fe45a1098121c4e5fd57ea +REG_FIDDLE(Region_024, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, const SkRegion& region) -> void { + SkDebugf("%s: region is %s" "rect\n", label, region.isRect() ? "" : "not "); + }; + SkRegion region; + debugster("initial", region); + region.setRect({1, 2, 3, 4}); + debugster("set rect", region); + region.setEmpty(); + debugster("set empty", region); +} +} // END FIDDLE diff --git a/docs/examples/Region_025.cpp b/docs/examples/Region_025.cpp new file mode 100644 index 0000000000..bd192c3456 --- /dev/null +++ b/docs/examples/Region_025.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=1fbd76d75ca2d280e81856311de4e54e +REG_FIDDLE(Region_025, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, const SkRegion& region) -> void { + SkDebugf("%s: region is %s" "complex\n", label, region.isComplex() ? "" : "not "); + }; + SkRegion region; + debugster("initial", region); + region.setRect({1, 2, 3, 4}); + debugster("set rect", region); + region.op({2, 3, 4, 5}, SkRegion::kUnion_Op); + debugster("op rect", region); +} +} // END FIDDLE diff --git a/docs/examples/Region_026.cpp b/docs/examples/Region_026.cpp new file mode 100644 index 0000000000..0dcb40936e --- /dev/null +++ b/docs/examples/Region_026.cpp @@ -0,0 +1,12 @@ +// 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 "fiddle/examples.h" +// HASH=651632582d385d2531e7aa551c31e331 +REG_FIDDLE(Region_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region({1, 2, 3, 4}); + region.op({2, 3, 4, 5}, SkRegion::kUnion_Op); + auto r = region.getBounds(); + SkDebugf("bounds: {%d,%d,%d,%d}\n", r.fLeft, r.fTop, r.fRight, r.fBottom); +} +} // END FIDDLE diff --git a/docs/examples/Region_027.cpp b/docs/examples/Region_027.cpp new file mode 100644 index 0000000000..f0dbe4acc4 --- /dev/null +++ b/docs/examples/Region_027.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=c4984fefdcecdd1090be160f80939d87 +REG_FIDDLE(Region_027, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, const SkRegion& region) -> void { + SkDebugf("%s: region complexity %d\n", label, region.computeRegionComplexity()); + }; + SkRegion region; + debugster("initial", region); + region.setRect({1, 2, 3, 4}); + debugster("set rect", region); + region.op({2, 3, 4, 5}, SkRegion::kUnion_Op); + debugster("op rect", region); +} +} // END FIDDLE diff --git a/docs/examples/Region_028.cpp b/docs/examples/Region_028.cpp new file mode 100644 index 0000000000..5cf216f81f --- /dev/null +++ b/docs/examples/Region_028.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=6631d36406efa3b3e27960c876421a7f +REG_FIDDLE(Region_028, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkRegion region; + region.setRect({10, 20, 90, 60}); + region.op({30, 40, 60, 80}, SkRegion::kXOR_Op); + canvas->drawRegion(region, SkPaint()); + SkPath path; + region.getBoundaryPath(&path); + path.offset(100, 0); + canvas->drawPath(path, SkPaint()); +} +} // END FIDDLE diff --git a/docs/examples/Region_029.cpp b/docs/examples/Region_029.cpp new file mode 100644 index 0000000000..c0f7a7b76e --- /dev/null +++ b/docs/examples/Region_029.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=1314f7250963775c5ee89cc5981eee24 +REG_FIDDLE(Region_029, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + auto r = region.getBounds(); + SkDebugf("%14s: {%d,%d,%d,%d}\n", label, r.fLeft, r.fTop, r.fRight, r.fBottom); + }; + SkRegion region({1, 2, 3, 4}); + debugster("region bounds", region); + region.setEmpty(); + SkDebugf(" after region set empty:\n"); + debugster("region bounds", region); +} +} // END FIDDLE diff --git a/docs/examples/Region_030.cpp b/docs/examples/Region_030.cpp new file mode 100644 index 0000000000..66f0bf4741 --- /dev/null +++ b/docs/examples/Region_030.cpp @@ -0,0 +1,13 @@ +// 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 "fiddle/examples.h" +// HASH=e12575ffcd262f2364e0e6bece98a825 +REG_FIDDLE(Region_030, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region({1, 2, 3, 4}); + SkDebugf("region is %s" "empty\n", region.isEmpty() ? "" : "not "); + bool setEmpty = region.setRect({1, 2, 1, 4}); + SkDebugf("region is %s" "empty\n", region.isEmpty() ? "" : "not "); + SkDebugf("setEmpty: %s\n", setEmpty ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Region_031.cpp b/docs/examples/Region_031.cpp new file mode 100644 index 0000000000..0fa3391798 --- /dev/null +++ b/docs/examples/Region_031.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=5b31a1b077818a8150ad50f3b19e7bfe +REG_FIDDLE(Region_031, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, bool success, SkRegion& region) -> void { + auto r = region.getBounds(); + SkDebugf("%14s: success:%s {%d,%d,%d,%d}\n", label, success ? "true" : "false", + r.fLeft, r.fTop, r.fRight, r.fBottom); + }; + SkRegion region; + bool success = region.setRect(1, 2, 3, 4); + debugster("set to: 1,2,3,4", success, region); + success = region.setRect(3, 2, 1, 4); + debugster("set to: 3,2,1,4", success, region); +} +} // END FIDDLE diff --git a/docs/examples/Region_032.cpp b/docs/examples/Region_032.cpp new file mode 100644 index 0000000000..97cc6cf960 --- /dev/null +++ b/docs/examples/Region_032.cpp @@ -0,0 +1,18 @@ +// 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 "fiddle/examples.h" +// HASH=fc793a14ed76c096a68a755c963c1ee0 +REG_FIDDLE(Region_032, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkIRect rects[] = { {10, 10, 40, 40}, {20, 20, 50, 50}, {30, 30, 60, 60} }; + SkRegion region; + region.setRects(rects, SK_ARRAY_COUNT(rects)); + canvas->drawRegion(region, SkPaint()); + region.setEmpty(); + for (auto add : rects) { + region.op(add, SkRegion::kUnion_Op); + } + region.translate(100, 0); + canvas->drawRegion(region, SkPaint()); +} +} // END FIDDLE diff --git a/docs/examples/Region_033.cpp b/docs/examples/Region_033.cpp new file mode 100644 index 0000000000..7043143f64 --- /dev/null +++ b/docs/examples/Region_033.cpp @@ -0,0 +1,21 @@ +// 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 "fiddle/examples.h" +// HASH=5d75d22bd155576838155762ab040751 +REG_FIDDLE(Region_033, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + auto r = region.getBounds(); + SkDebugf("%14s: {%d,%d,%d,%d}\n", label, r.fLeft, r.fTop, r.fRight, r.fBottom); + }; + SkRegion region({1, 2, 3, 4}); + SkRegion region2; + region2.setRegion(region); + debugster("region bounds", region); + debugster("region2 bounds", region2); + region2.setEmpty(); + SkDebugf(" after region set empty:\n"); + debugster("region bounds", region); + debugster("region2 bounds", region2); +} +} // END FIDDLE diff --git a/docs/examples/Region_034.cpp b/docs/examples/Region_034.cpp new file mode 100644 index 0000000000..a07b89a30b --- /dev/null +++ b/docs/examples/Region_034.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=45b9ea2247b9ca7f10aa22ea29a426f4 +REG_FIDDLE(Region_034, 256, 120, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath textPath; + paint.getTextPath("Q", 1, 0, 110, &textPath); + SkIRect clipRect = {20, 20, 100, 120}; + SkRegion clipRegion(clipRect); + SkRegion region; + region.setPath(textPath, clipRegion); + canvas->drawRegion(region, SkPaint()); + clipRect.offset(100, 0); + textPath.offset(100, 0); + canvas->clipRect(SkRect::Make(clipRect), false); + canvas->drawPath(textPath, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_035.cpp b/docs/examples/Region_035.cpp new file mode 100644 index 0000000000..7a79aeb9db --- /dev/null +++ b/docs/examples/Region_035.cpp @@ -0,0 +1,20 @@ +#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 "fiddle/examples.h" +// HASH=42bde0ef8c2ee372751428cd6e21c1ca +REG_FIDDLE(Region_035, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath textPath; + paint.getTextPath("W", 1, 20, 110, &textPath); + SkRegion region; + region.setPath(textPath, SkRegion({0, 0, 256, 256})); + canvas->drawRegion(region, SkPaint()); + SkIRect iRect = SkIRect::MakeXYWH(frame * 160, 55, 10, 10); + paint.setColor(region.intersects(iRect) ? SK_ColorBLUE : SK_ColorRED); + canvas->drawRect(SkRect::Make(iRect), paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_036.cpp b/docs/examples/Region_036.cpp new file mode 100644 index 0000000000..f41ddfb8c8 --- /dev/null +++ b/docs/examples/Region_036.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=4263d79ac0e7df02e90948fdde9fa965 +REG_FIDDLE(Region_036, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath hPath, dotPath; + paint.getTextPath("H", 1, 40, 110, &hPath); + paint.getTextPath(",", 1, frame * 180, 95, &dotPath); + SkRegion hRegion, dotRegion; + hRegion.setPath(hPath, SkRegion({0, 0, 256, 256})); + dotRegion.setPath(dotPath, SkRegion({0, 0, 256, 256})); + canvas->drawRegion(hRegion, paint); + paint.setColor(hRegion.intersects(dotRegion) ? SK_ColorBLUE : SK_ColorRED); + canvas->drawRegion(dotRegion, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_037.cpp b/docs/examples/Region_037.cpp new file mode 100644 index 0000000000..0f7b1249a3 --- /dev/null +++ b/docs/examples/Region_037.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=e3899c2715c332bfc7648d5f2b9eefc6 +REG_FIDDLE(Region_037, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + SkRegion xRegion; + xRegion.setPath(xPath, SkRegion({0, 0, 256, 256})); + canvas->drawRegion(xRegion, paint); + for (int y = 0; y < 128; y += 8) { + for (int x = 0; x < 128; x += 8) { + paint.setColor(xRegion.contains(x, y) ? SK_ColorWHITE : SK_ColorRED); + canvas->drawPoint(x, y, paint); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_038.cpp b/docs/examples/Region_038.cpp new file mode 100644 index 0000000000..62c6b26888 --- /dev/null +++ b/docs/examples/Region_038.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=100b4cbd5dd7406804e40035833a433c +REG_FIDDLE(Region_038, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + SkRegion xRegion; + SkIRect drawBounds = {0, 0, 128, 128}; + xRegion.setPath(xPath, SkRegion(drawBounds)); + xRegion.op(drawBounds, SkRegion::kReverseDifference_Op); + canvas->drawRegion(xRegion, paint); + SkIRect test = SkIRect::MakeXYWH(frame* 128, 64, 5, 5); + if (xRegion.contains(test)) { + paint.setColor(SK_ColorYELLOW); + canvas->drawRect(SkRect::Make(test), paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_039.cpp b/docs/examples/Region_039.cpp new file mode 100644 index 0000000000..60f5861296 --- /dev/null +++ b/docs/examples/Region_039.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=46de22da2f3e08a8d7f064634fc1c7b5 +REG_FIDDLE(Region_039, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath, testPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + paint.getTextPath("`", 1, frame * 150 - 40, 150, &testPath); + SkRegion xRegion, testRegion; + SkIRect drawBounds = {0, 0, 128, 128}; + xRegion.setPath(xPath, SkRegion(drawBounds)); + testRegion.setPath(testPath, SkRegion(drawBounds)); + xRegion.op(drawBounds, SkRegion::kReverseDifference_Op); + canvas->drawRegion(xRegion, paint); + if (xRegion.contains(testRegion)) { + paint.setColor(SK_ColorYELLOW); + canvas->drawRegion(testRegion, paint); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_040.cpp b/docs/examples/Region_040.cpp new file mode 100644 index 0000000000..3522732dc3 --- /dev/null +++ b/docs/examples/Region_040.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=d8e5eac373e2e7cfc1b8cd0229647ba6 +REG_FIDDLE(Region_040, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region({1, 2, 3, 4}); + SkIRect test = {2, 2, 3, 3}; + SkDebugf("quickContains 1: %s\n", region.quickContains(test) ? "true" : "false"); + region.op({1, 4, 3, 6}, SkRegion::kUnion_Op); + SkDebugf("quickContains 2: %s\n", region.quickContains(test) ? "true" : "false"); + region.op({1, 7, 3, 8}, SkRegion::kUnion_Op); + SkDebugf("quickContains 3: %s\n", region.quickContains(test) ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Region_041.cpp b/docs/examples/Region_041.cpp new file mode 100644 index 0000000000..21705be5fd --- /dev/null +++ b/docs/examples/Region_041.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=eb6d290887e1a3a0b051b4d7b012f5e1 +REG_FIDDLE(Region_041, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto debugster = [](const char* label, SkRegion& region) -> void { + SkDebugf("%s: %s\n", label, region.quickContains(2, 2, 3, 3) ? "true" : "false"); + }; + SkRegion region({1, 2, 3, 4}); + debugster("quickContains 1", region); + region.op({1, 4, 3, 6}, SkRegion::kUnion_Op); + debugster("quickContains 2", region); + region.op({1, 7, 3, 8}, SkRegion::kUnion_Op); + debugster("quickContains 3", region); +} +} // END FIDDLE diff --git a/docs/examples/Region_042.cpp b/docs/examples/Region_042.cpp new file mode 100644 index 0000000000..c3280bab60 --- /dev/null +++ b/docs/examples/Region_042.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=71ac24b7d91ac5ca7c14b43930d5f85d +REG_FIDDLE(Region_042, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region({1, 2, 3, 4}); + SkIRect test = {4, 2, 5, 3}; + SkDebugf("quickReject 1: %s\n", region.quickReject(test) ? "true" : "false"); + region.op({1, 4, 3, 6}, SkRegion::kUnion_Op); + SkDebugf("quickReject 2: %s\n", region.quickReject(test) ? "true" : "false"); + region.op({4, 7, 5, 8}, SkRegion::kUnion_Op); + SkDebugf("quickReject 3: %s\n", region.quickReject(test) ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Region_043.cpp b/docs/examples/Region_043.cpp new file mode 100644 index 0000000000..23fc1a7f75 --- /dev/null +++ b/docs/examples/Region_043.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=def7dba38947c33b203e4f9db6c88be3 +REG_FIDDLE(Region_043, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkRegion region({1, 2, 3, 4}); + SkRegion test; + SkIRect rects[] = {{4, 2, 5, 3}, {7, 2, 8, 3}}; + test.setRects(rects, SK_ARRAY_COUNT(rects)); + SkDebugf("quickReject 1: %s\n", region.quickReject(test) ? "true" : "false"); + region.op({1, 4, 3, 6}, SkRegion::kUnion_Op); + SkDebugf("quickReject 2: %s\n", region.quickReject(test) ? "true" : "false"); + region.op({4, 7, 5, 8}, SkRegion::kUnion_Op); + SkDebugf("quickReject 3: %s\n", region.quickReject(test) ? "true" : "false"); +} +} // END FIDDLE diff --git a/docs/examples/Region_044.cpp b/docs/examples/Region_044.cpp new file mode 100644 index 0000000000..1e4f2035ab --- /dev/null +++ b/docs/examples/Region_044.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=4e5b9e53aa1b200fed3ee6596ca01f0e +REG_FIDDLE(Region_044, 256, 90, false, 0) { +void draw(SkCanvas* canvas) { + SkRegion test; + SkIRect rects[] = {{40, 20, 50, 30}, {70, 40, 80, 50}, { 60, 10, 70, 20}}; + test.setRects(rects, SK_ARRAY_COUNT(rects)); + SkPaint paint; + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN, SK_ColorMAGENTA } ) { + paint.setColor(color); + canvas->drawRegion(test, paint); + test.translate(10, 10); + } +} +} // END FIDDLE diff --git a/docs/examples/Region_045.cpp b/docs/examples/Region_045.cpp new file mode 100644 index 0000000000..ec7d7e9d65 --- /dev/null +++ b/docs/examples/Region_045.cpp @@ -0,0 +1,20 @@ +// 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 "fiddle/examples.h" +// HASH=024200960eb52fee1f471514607e6001 +REG_FIDDLE(Region_045, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRegion test; + SkIRect rects[] = {{40, 20, 50, 30}, {70, 40, 80, 50}, { 60, 10, 70, 20}}; + test.setRects(rects, SK_ARRAY_COUNT(rects)); + SkPaint paint; + for (auto color : { SK_ColorRED, SK_ColorBLUE, SK_ColorGREEN, SK_ColorMAGENTA } ) { + paint.setColor(color); + canvas->drawRegion(test, paint); + SkRegion second; + test.translate(10, test.getBounds().fBottom, &second); + test.op(second, SkRegion::kXOR_Op); + test.translate(30, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Region_046.cpp b/docs/examples/Region_046.cpp new file mode 100644 index 0000000000..7b4586d91a --- /dev/null +++ b/docs/examples/Region_046.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=026dd8b180fe8e43f477fce43e9217b3 +REG_FIDDLE(Region_046, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkRegion operand({35, 35, 85, 85}); + const char* labels[] = {"difference", "intersect", "union", "xor", "reverse diff", "replace"}; + int index = 0; + SkPaint paint; + for (auto op : { SkRegion::kDifference_Op, SkRegion::kIntersect_Op, SkRegion::kUnion_Op, + SkRegion::kXOR_Op, SkRegion::kReverseDifference_Op, SkRegion::kReplace_Op } ) { + SkRegion target({10, 10, 60, 60}); + target.op(operand, op); + canvas->drawRegion(target, paint); + canvas->drawString(labels[index++], 40, 100, paint); + canvas->translate(80, 0); + if (SkRegion::kUnion_Op == op) { + canvas->translate(-240, 120); + } + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_047.cpp b/docs/examples/Region_047.cpp new file mode 100644 index 0000000000..369de4fbe6 --- /dev/null +++ b/docs/examples/Region_047.cpp @@ -0,0 +1,19 @@ +#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 "fiddle/examples.h" +// HASH=1790b2e054c536a54601138365700ac3 +REG_FIDDLE(Region_047, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + SkRegion xRegion; + SkIRect drawBounds = {0, 0, 128, 128}; + xRegion.setPath(xPath, SkRegion(drawBounds)); + xRegion.op(drawBounds, SkRegion::kReverseDifference_Op); + canvas->drawRegion(xRegion, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_048.cpp b/docs/examples/Region_048.cpp new file mode 100644 index 0000000000..15205552dd --- /dev/null +++ b/docs/examples/Region_048.cpp @@ -0,0 +1,20 @@ +#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 "fiddle/examples.h" +// HASH=2e3497890d523235f96680716c321098 +REG_FIDDLE(Region_048, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + SkRegion xRegion; + SkIRect drawBounds = {0, 0, 128, 128}; + xRegion.setPath(xPath, SkRegion(drawBounds)); + xRegion.op(drawBounds.fLeft + frame * drawBounds.width(), drawBounds.fTop, + drawBounds.fRight, drawBounds.fBottom, SkRegion::kReverseDifference_Op); + canvas->drawRegion(xRegion, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_049.cpp b/docs/examples/Region_049.cpp new file mode 100644 index 0000000000..b7c005b2d2 --- /dev/null +++ b/docs/examples/Region_049.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=65f4eccea3514ed7e37b5067e15efddb +REG_FIDDLE(Region_049, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath, opPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + opPath.addCircle(64, 64, frame * 64); + SkRegion xRegion, opRegion; + SkIRect drawBounds = {0, 0, 128, 128}; + opRegion.setPath(opPath, SkRegion(drawBounds)); + xRegion.setPath(xPath, SkRegion(drawBounds)); + xRegion.op(opRegion, SkRegion::kReverseDifference_Op); + canvas->drawRegion(xRegion, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_050.cpp b/docs/examples/Region_050.cpp new file mode 100644 index 0000000000..685f405094 --- /dev/null +++ b/docs/examples/Region_050.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=3f964be1e1fd2fbb977b655d3a928f0a +REG_FIDDLE(Region_050, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath, opPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + opPath.addCircle(64, 64, frame * 64); + SkRegion xRegion, opRegion, rectRegion; + SkIRect drawBounds = {0, 0, 128, 128}; + opRegion.setPath(opPath, SkRegion(drawBounds)); + xRegion.setPath(xPath, SkRegion(drawBounds)); + drawBounds.inset(frame * drawBounds.width() / 2, 0); + rectRegion.op(drawBounds, opRegion, SkRegion::kIntersect_Op); + xRegion.op(rectRegion, SkRegion::kReverseDifference_Op); + canvas->drawRegion(xRegion, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_051.cpp b/docs/examples/Region_051.cpp new file mode 100644 index 0000000000..0aeab23ad5 --- /dev/null +++ b/docs/examples/Region_051.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=e623208dd44f0b24499ac5f1593d1b39 +REG_FIDDLE(Region_051, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath, opPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + opPath.addCircle(64, 64, frame * 64); + SkRegion xRegion, opRegion, rectRegion; + SkIRect drawBounds = {0, 0, 128, 128}; + opRegion.setPath(opPath, SkRegion(drawBounds)); + xRegion.setPath(xPath, SkRegion(drawBounds)); + drawBounds.inset(frame * drawBounds.width() / 2, 0); + rectRegion.op(opRegion, drawBounds, SkRegion::kUnion_Op); + xRegion.op(rectRegion, SkRegion::kReverseDifference_Op); + canvas->drawRegion(xRegion, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_052.cpp b/docs/examples/Region_052.cpp new file mode 100644 index 0000000000..ca165c557b --- /dev/null +++ b/docs/examples/Region_052.cpp @@ -0,0 +1,26 @@ +#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 "fiddle/examples.h" +// HASH=13de1a6fcb2302a2a30278cb88d3e17d +REG_FIDDLE(Region_052, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath, opPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + xPath.setFillType(SkPath::kInverseWinding_FillType); + opPath.addCircle(64, 64, frame * 64); + opPath.setFillType(SkPath::kInverseWinding_FillType); + SkRegion xRegion, opRegion, rectRegion; + SkIRect drawBounds = {0, 0, 128, 128}; + opRegion.setPath(opPath, SkRegion(drawBounds)); + xRegion.setPath(xPath, SkRegion(drawBounds)); + drawBounds.inset(frame * drawBounds.width() / 2, 0); + rectRegion.setRect(drawBounds); + rectRegion.op(xRegion, SkRegion::kIntersect_Op); + xRegion.op(rectRegion, opRegion, SkRegion::kReverseDifference_Op); + canvas->drawRegion(xRegion, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_053.cpp b/docs/examples/Region_053.cpp new file mode 100644 index 0000000000..90e6f2407d --- /dev/null +++ b/docs/examples/Region_053.cpp @@ -0,0 +1,23 @@ +#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 "fiddle/examples.h" +// HASH=1419d2a8c22c355ab46240865d056ee5 +REG_FIDDLE(Region_053, 256, 128, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(128); + SkPath xPath; + paint.getTextPath("X", 1, 20, 110, &xPath); + SkIRect drawBounds = {0, 0, 128, 128}; + SkRegion xRegion; + xRegion.setPath(xPath, SkRegion(drawBounds)); + size_t size = xRegion.writeToMemory(nullptr); + sk_sp data = SkData::MakeUninitialized(size); + xRegion.writeToMemory(data->writable_data()); + SkRegion copy; + copy.readFromMemory(data->data(), data->size()); + canvas->drawRegion(copy, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Region_054.cpp b/docs/examples/Region_054.cpp new file mode 100644 index 0000000000..0445bb068d --- /dev/null +++ b/docs/examples/Region_054.cpp @@ -0,0 +1,15 @@ +// 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 "fiddle/examples.h" +// HASH=1ede346c430ef23df0eaaf0773dd6a15 +REG_FIDDLE(Region_054, 256, 100, false, 0) { +void draw(SkCanvas* canvas) { + SkRegion region({20, 20, 80, 80}); + size_t size = region.writeToMemory(nullptr); + sk_sp data = SkData::MakeUninitialized(size); + region.writeToMemory(data->writable_data()); + SkRegion copy; + copy.readFromMemory(data->data(), data->size()); + canvas->drawRegion(copy, SkPaint()); +} +} // END FIDDLE diff --git a/docs/examples/Surface_000.cpp b/docs/examples/Surface_000.cpp new file mode 100644 index 0000000000..9f61b68df1 --- /dev/null +++ b/docs/examples/Surface_000.cpp @@ -0,0 +1,25 @@ +// 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 "fiddle/examples.h" +// HASH=3f5aeb870104187643197354a7f1d27a +REG_FIDDLE(Surface_000, 256, 256, true, 0) { +void draw(SkCanvas* ) { + SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); + const size_t size = info.computeMinByteSize(); + SkAutoTMalloc storage(size); + SkPMColor* pixels = storage.get(); + sk_sp surface(SkSurface::MakeRasterDirect(info, pixels, info.minRowBytes())); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(SK_ColorWHITE); + SkPMColor pmWhite = pixels[0]; + SkPaint paint; + canvas->drawPoint(1, 1, paint); + canvas->flush(); // ensure that point was drawn + for (int y = 0; y < info.height(); ++y) { + for (int x = 0; x < info.width(); ++x) { + SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x'); + } + SkDebugf("\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Surface_001.cpp b/docs/examples/Surface_001.cpp new file mode 100644 index 0000000000..6b57e3cb68 --- /dev/null +++ b/docs/examples/Surface_001.cpp @@ -0,0 +1,33 @@ +// 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 "fiddle/examples.h" +// HASH=8e6530b26ab4096a9a91cfaadda1c568 +REG_FIDDLE(Surface_001, 256, 256, true, 0) { +static void release_direct_surface_storage(void* pixels, void* context) { + if (pixels == context) { + SkDebugf("expected release context\n"); + } + sk_free(pixels); +} + +void draw(SkCanvas* ) { + SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); + const size_t rowBytes = info.minRowBytes(); + void* pixels = sk_malloc_throw(info.computeByteSize(rowBytes)); + sk_sp surface(SkSurface::MakeRasterDirectReleaseProc(info, pixels, rowBytes, + release_direct_surface_storage, pixels)); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(SK_ColorWHITE); + SkPMColor* colorPtr = (SkPMColor*) pixels; + SkPMColor pmWhite = colorPtr[0]; + SkPaint paint; + canvas->drawPoint(1, 1, paint); + canvas->flush(); // ensure that point was drawn + for (int y = 0; y < info.height(); ++y) { + for (int x = 0; x < info.width(); ++x) { + SkDebugf("%c", *colorPtr++ == pmWhite ? '-' : 'x'); + } + SkDebugf("\n"); + } +} +} // END FIDDLE diff --git a/docs/examples/Surface_002.cpp b/docs/examples/Surface_002.cpp new file mode 100644 index 0000000000..651e01297a --- /dev/null +++ b/docs/examples/Surface_002.cpp @@ -0,0 +1,28 @@ +// 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 "fiddle/examples.h" +// HASH=a803910ada4f8733f0b62456afead55f +REG_FIDDLE(Surface_002, 256, 256, true, 0) { +void draw(SkCanvas* ) { + SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); + const size_t rowBytes = 64; + sk_sp surface(SkSurface::MakeRaster(info, rowBytes, nullptr)); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(SK_ColorWHITE); + SkPixmap pixmap; + if (surface->peekPixels(&pixmap)) { + const uint32_t* colorPtr = pixmap.addr32(); + SkPMColor pmWhite = colorPtr[0]; + SkPaint paint; + canvas->drawPoint(1, 1, paint); + canvas->flush(); // ensure that point was drawn + for (int y = 0; y < info.height(); ++y) { + for (int x = 0; x < info.width(); ++x) { + SkDebugf("%c", colorPtr[x] == pmWhite ? '-' : 'x'); + } + colorPtr += rowBytes / sizeof(colorPtr[0]); + SkDebugf("\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Surface_003.cpp b/docs/examples/Surface_003.cpp new file mode 100644 index 0000000000..0485f07b5d --- /dev/null +++ b/docs/examples/Surface_003.cpp @@ -0,0 +1,27 @@ +// 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 "fiddle/examples.h" +// HASH=c6197d204ef9e4ccfb583242651fb2a7 +REG_FIDDLE(Surface_003, 256, 256, true, 0) { +void draw(SkCanvas* ) { + SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); + sk_sp surface(SkSurface::MakeRaster(info)); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(SK_ColorWHITE); + SkPixmap pixmap; + if (surface->peekPixels(&pixmap)) { + const uint32_t* colorPtr = pixmap.addr32(); + SkPMColor pmWhite = colorPtr[0]; + SkPaint paint; + canvas->drawPoint(1, 1, paint); + canvas->flush(); // ensure that point was drawn + for (int y = 0; y < info.height(); ++y) { + for (int x = 0; x < info.width(); ++x) { + SkDebugf("%c", colorPtr[x] == pmWhite ? '-' : 'x'); + } + colorPtr += info.width(); + SkDebugf("\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Surface_004.cpp b/docs/examples/Surface_004.cpp new file mode 100644 index 0000000000..6560b5a3fb --- /dev/null +++ b/docs/examples/Surface_004.cpp @@ -0,0 +1,26 @@ +// 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 "fiddle/examples.h" +// HASH=b932a2bd68455fb0af2e7a1ed19e36b3 +REG_FIDDLE(Surface_004, 256, 256, true, 0) { +void draw(SkCanvas* ) { + sk_sp surface(SkSurface::MakeRasterN32Premul(3, 3)); + SkCanvas* canvas = surface->getCanvas(); + canvas->clear(SK_ColorWHITE); + SkPixmap pixmap; + if (surface->peekPixels(&pixmap)) { + const uint32_t* colorPtr = pixmap.addr32(); + SkPMColor pmWhite = colorPtr[0]; + SkPaint paint; + canvas->drawPoint(1, 1, paint); + canvas->flush(); // ensure that point was drawn + for (int y = 0; y < surface->height(); ++y) { + for (int x = 0; x < surface->width(); ++x) { + SkDebugf("%c", colorPtr[x] == pmWhite ? '-' : 'x'); + } + colorPtr += surface->width(); + SkDebugf("\n"); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Surface_005.cpp b/docs/examples/Surface_005.cpp new file mode 100644 index 0000000000..1f8d561619 --- /dev/null +++ b/docs/examples/Surface_005.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=d3aec071998f871809f515e58abb1b0e +REG_FIDDLE(Surface_005, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(32); + GrContext* context = canvas->getGrContext(); + if (!context) { + canvas->drawString("GPU only!", 20, 40, paint); + return; + } + sk_sp gpuSurface = SkSurface::MakeFromBackendTexture(context, + backEndTexture, kTopLeft_GrSurfaceOrigin, 0, + kRGBA_8888_SkColorType, nullptr, nullptr); + auto surfaceCanvas = gpuSurface->getCanvas(); + surfaceCanvas->drawString("GPU rocks!", 20, 40, 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_006.cpp b/docs/examples/Surface_006.cpp new file mode 100644 index 0000000000..23a6238338 --- /dev/null +++ b/docs/examples/Surface_006.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=5e87093b9cbe95124ae14cbe77091eb7 +REG_FIDDLE(Surface_006, 256, 256, false, 3) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(32); + GrContext* context = canvas->getGrContext(); + if (!context) { + canvas->drawString("GPU only!", 20, 40, paint); + return; + } + sk_sp gpuSurface = SkSurface::MakeFromBackendTextureAsRenderTarget( + context, backEndTexture, kTopLeft_GrSurfaceOrigin, 0, + kRGBA_8888_SkColorType, nullptr, nullptr); + auto surfaceCanvas = gpuSurface->getCanvas(); + surfaceCanvas->drawString("GPU rocks!", 20, 40, 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_007.cpp b/docs/examples/Surface_007.cpp new file mode 100644 index 0000000000..3d7bfa796b --- /dev/null +++ b/docs/examples/Surface_007.cpp @@ -0,0 +1,28 @@ +#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 "fiddle/examples.h" +// HASH=67b6609471a3f1ed0f4b1657004cdecb +REG_FIDDLE(Surface_007, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(32); + GrContext* context = canvas->getGrContext(); + if (!context) { + canvas->drawString("GPU only!", 20, 40, paint); + return; + } + SkImageInfo info = SkImageInfo::MakeN32(256, 64, kOpaque_SkAlphaType); + for (auto surfaceOrigin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin } ) { + auto gpuSurface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, + surfaceOrigin, nullptr)); + auto surfaceCanvas = gpuSurface->getCanvas(); + surfaceCanvas->clear(SK_ColorWHITE); + surfaceCanvas->drawString("GPU rocks!", 20, 40, 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_008.cpp b/docs/examples/Surface_008.cpp new file mode 100644 index 0000000000..f9c149e300 --- /dev/null +++ b/docs/examples/Surface_008.cpp @@ -0,0 +1,36 @@ +#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 "fiddle/examples.h" +// HASH=640321e8ecfb3f9329f3bc6e1f02485f +REG_FIDDLE(Surface_008, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + auto test_draw = [](SkCanvas* surfaceCanvas) -> void { + SkPaint paint; + paint.setAntiAlias(true); + 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); + }; + GrContext* context = canvas->getGrContext(); + 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); + test_draw(surface->getCanvas()); + surface->draw(canvas, 0, y, nullptr); + sk_sp image(surface->makeImageSnapshot()); + SkAutoCanvasRestore acr(canvas, true); + canvas->scale(8, 8); + canvas->drawImage(image, 12, y / 8); + y += 64; + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_009.cpp b/docs/examples/Surface_009.cpp new file mode 100644 index 0000000000..efd7db5278 --- /dev/null +++ b/docs/examples/Surface_009.cpp @@ -0,0 +1,24 @@ +#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 "fiddle/examples.h" +// HASH=5c7629c15e9ac93f098335e72560fa2e +REG_FIDDLE(Surface_009, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(32); + GrContext* context = canvas->getGrContext(); + if (!context) { + canvas->drawString("GPU only!", 20, 40, 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); + 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_010.cpp b/docs/examples/Surface_010.cpp new file mode 100644 index 0000000000..c9724b68e6 --- /dev/null +++ b/docs/examples/Surface_010.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=99a54b814ccab7d2b1143c88581649ff +REG_FIDDLE(Surface_010, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkDebugf("SkSurface::MakeNull(0, 0) %c= nullptr\n", SkSurface::MakeNull(0, 0) == nullptr ? + '=' : '!'); + const int w = 37; + const int h = 1000; + auto surf = SkSurface::MakeNull(w, h); + auto nullCanvas = surf->getCanvas(); + nullCanvas->drawPaint(SkPaint()); // does not crash, nothing draws + SkDebugf("surf->makeImageSnapshot() %c= nullptr\n", surf->makeImageSnapshot() == nullptr ? + '=' : '!'); +} +} // END FIDDLE diff --git a/docs/examples/Surface_011.cpp b/docs/examples/Surface_011.cpp new file mode 100644 index 0000000000..469a47ce0d --- /dev/null +++ b/docs/examples/Surface_011.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=df066b56dd97c7c589fd2bb6a2539de8 +REG_FIDDLE(Surface_011, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int width = 37; + const int height = 1000; + auto surf = SkSurface::MakeNull(width, height); + auto nullCanvas = surf->getCanvas(); + SkDebugf("surface width=%d canvas width=%d\n", surf->width(), + nullCanvas->getBaseLayerSize().fWidth); +} +} // END FIDDLE diff --git a/docs/examples/Surface_012.cpp b/docs/examples/Surface_012.cpp new file mode 100644 index 0000000000..e83286aac9 --- /dev/null +++ b/docs/examples/Surface_012.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=20571cc23e3146deaa09046b64cc0aef +REG_FIDDLE(Surface_012, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const int width = 37; + const int height = 1000; + auto surf = SkSurface::MakeNull(width, height); + auto nullCanvas = surf->getCanvas(); + SkDebugf("surface height=%d canvas height=%d\n", surf->height(), + nullCanvas->getBaseLayerSize().fHeight); +} +} // END FIDDLE diff --git a/docs/examples/Surface_013.cpp b/docs/examples/Surface_013.cpp new file mode 100644 index 0000000000..0b3bf5b24e --- /dev/null +++ b/docs/examples/Surface_013.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=be9574c4a14f891e1abb4ec2b1e51d6c +REG_FIDDLE(Surface_013, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto surface = SkSurface::MakeRasterN32Premul(1, 1); + for (int i = 0; i < 3; ++i) { + SkDebugf("surface generationID: %d\n", surface->generationID()); + if (0 == i) { + surface->getCanvas()->drawColor(SK_ColorBLACK); + } else { + surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Surface_014.cpp b/docs/examples/Surface_014.cpp new file mode 100644 index 0000000000..3a4045266e --- /dev/null +++ b/docs/examples/Surface_014.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=be9574c4a14f891e1abb4ec2b1e51d6c +REG_FIDDLE(Surface_014, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + auto surface = SkSurface::MakeRasterN32Premul(1, 1); + for (int i = 0; i < 3; ++i) { + SkDebugf("surface generationID: %d\n", surface->generationID()); + if (0 == i) { + surface->getCanvas()->drawColor(SK_ColorBLACK); + } else { + surface->notifyContentWillChange(SkSurface::kDiscard_ContentChangeMode); + } + } +} +} // END FIDDLE diff --git a/docs/examples/Surface_015.cpp b/docs/examples/Surface_015.cpp new file mode 100644 index 0000000000..f12da190dc --- /dev/null +++ b/docs/examples/Surface_015.cpp @@ -0,0 +1,17 @@ +#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 "fiddle/examples.h" +// HASH=33d0c5ad5a4810e533ae1010e29f8b75 +REG_FIDDLE(Surface_015, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + sk_sp surface(SkSurface::MakeRasterN32Premul(64, 64)); + SkCanvas* surfaceCanvas = surface->getCanvas(); + surfaceCanvas->clear(SK_ColorBLUE); + SkPaint paint; + paint.setTextSize(40); + surfaceCanvas->drawString("\xF0\x9F\x98\x81", 12, 45, paint); + surface->draw(canvas, 0, 0, nullptr); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_016.cpp b/docs/examples/Surface_016.cpp new file mode 100644 index 0000000000..c03c4dfcd8 --- /dev/null +++ b/docs/examples/Surface_016.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=a9889b519a26896b900da0444e423c61 +REG_FIDDLE(Surface_016, 256, 96, false, 0) { +void draw(SkCanvas* canvas) { + sk_sp big(SkSurface::MakeRasterN32Premul(64, 64)); + sk_sp lil(big->makeSurface(SkImageInfo::MakeN32(32, 32, kPremul_SkAlphaType))); + big->getCanvas()->clear(SK_ColorRED); + lil->getCanvas()->clear(SK_ColorBLACK); + SkPixmap pixmap; + if (big->peekPixels(&pixmap)) { + SkBitmap bigBits; + bigBits.installPixels(pixmap); + canvas->drawBitmap(bigBits, 0, 0); + } + if (lil->peekPixels(&pixmap)) { + SkBitmap lilBits; + lilBits.installPixels(pixmap); + canvas->drawBitmap(lilBits, 64, 64); + } +} +} // END FIDDLE diff --git a/docs/examples/Surface_017.cpp b/docs/examples/Surface_017.cpp new file mode 100644 index 0000000000..477df759f9 --- /dev/null +++ b/docs/examples/Surface_017.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=46f1fa0d95e590a64bed0140407ce5f7 +REG_FIDDLE(Surface_017, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + sk_sp big(SkSurface::MakeRasterN32Premul(64, 64)); + sk_sp lil(big->makeSurface(SkImageInfo::MakeN32(32, 32, kPremul_SkAlphaType))); + big->getCanvas()->clear(SK_ColorRED); + lil->getCanvas()->clear(SK_ColorBLACK); + sk_sp early(big->makeImageSnapshot()); + lil->draw(big->getCanvas(), 16, 16, nullptr); + sk_sp later(big->makeImageSnapshot()); + canvas->drawImage(early, 0, 0); + canvas->drawImage(later, 128, 0); +} +} // END FIDDLE diff --git a/docs/examples/Surface_018.cpp b/docs/examples/Surface_018.cpp new file mode 100644 index 0000000000..b5f560f1ca --- /dev/null +++ b/docs/examples/Surface_018.cpp @@ -0,0 +1,17 @@ +// 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 "fiddle/examples.h" +// HASH=b18b8ab693b09eb70a1d22ab63790cc7 +REG_FIDDLE(Surface_018, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + sk_sp big(SkSurface::MakeRasterN32Premul(64, 64)); + sk_sp lil(big->makeSurface(SkImageInfo::MakeN32(32, 32, kPremul_SkAlphaType))); + big->getCanvas()->clear(SK_ColorRED); + lil->getCanvas()->clear(SK_ColorBLACK); + sk_sp early(big->makeImageSnapshot()); + lil->draw(big->getCanvas(), 16, 16, nullptr); + sk_sp later(big->makeImageSnapshot({0, 0, 16, 16})); + canvas->drawImage(early, 0, 0); + canvas->drawImage(later, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Surface_019.cpp b/docs/examples/Surface_019.cpp new file mode 100644 index 0000000000..54b965d7ba --- /dev/null +++ b/docs/examples/Surface_019.cpp @@ -0,0 +1,19 @@ +// 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 "fiddle/examples.h" +// HASH=0de693f4d8dd898a60be8cfba23952be +REG_FIDDLE(Surface_019, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + sk_sp big(SkSurface::MakeRasterN32Premul(64, 64)); + sk_sp lil(big->makeSurface(SkImageInfo::MakeN32(32, 32, kPremul_SkAlphaType))); + big->getCanvas()->clear(SK_ColorRED); + lil->getCanvas()->clear(SK_ColorBLACK); + lil->draw(big->getCanvas(), 16, 16, nullptr); + SkPixmap pixmap; + if (big->peekPixels(&pixmap)) { + SkBitmap bigBits; + bigBits.installPixels(pixmap); + canvas->drawBitmap(bigBits, 0, 0); + } +} +} // END FIDDLE diff --git a/docs/examples/Surface_020.cpp b/docs/examples/Surface_020.cpp new file mode 100644 index 0000000000..521c9662d6 --- /dev/null +++ b/docs/examples/Surface_020.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=8c6184f22cfe068f021704cf92a147a1 +REG_FIDDLE(Surface_020, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + sk_sp surf(SkSurface::MakeRasterN32Premul(64, 64)); + auto surfCanvas = surf->getCanvas(); + surfCanvas->clear(SK_ColorRED); + SkPaint paint; + paint.setTextSize(40); + surfCanvas->drawString("&", 16, 48, paint); + SkPixmap pixmap; + if (surf->peekPixels(&pixmap)) { + SkBitmap surfBits; + surfBits.installPixels(pixmap); + canvas->drawBitmap(surfBits, 0, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_021.cpp b/docs/examples/Surface_021.cpp new file mode 100644 index 0000000000..ed58a381e1 --- /dev/null +++ b/docs/examples/Surface_021.cpp @@ -0,0 +1,25 @@ +#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 "fiddle/examples.h" +// HASH=9f454fb93bca6482598d198b4121f0a6 +REG_FIDDLE(Surface_021, 256, 32, false, 0) { +void draw(SkCanvas* canvas) { + sk_sp surf(SkSurface::MakeRasterN32Premul(64, 64)); + auto surfCanvas = surf->getCanvas(); + surfCanvas->clear(SK_ColorRED); + SkPaint paint; + paint.setTextSize(40); + surfCanvas->drawString("&", 0, 32, paint); + std::vector storage; + storage.resize(surf->width() * surf->height()); + SkPixmap pixmap(SkImageInfo::MakeN32Premul(32, 32), &storage.front(), + surf->width() * sizeof(storage[0])); + if (surf->readPixels(pixmap, 0, 0)) { + SkBitmap surfBits; + surfBits.installPixels(pixmap); + canvas->drawBitmap(surfBits, 0, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_022.cpp b/docs/examples/Surface_022.cpp new file mode 100644 index 0000000000..bac9aa0b8f --- /dev/null +++ b/docs/examples/Surface_022.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=484d60dab5d846bf28c7a4d48892324a +REG_FIDDLE(Surface_022, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + sk_sp surf(SkSurface::MakeRasterN32Premul(64, 64)); + auto surfCanvas = surf->getCanvas(); + surfCanvas->clear(SK_ColorRED); + SkPaint paint; + surfCanvas->drawOval({4, 8, 58, 54}, paint); + SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); + sk_sp data(SkData::MakeUninitialized(info.minRowBytes() * info.height())); + sk_bzero(data->writable_data(), info.minRowBytes() * info.height()); + for (int x : { 32, -32 } ) { + for (int y : { 32, -32 } ) { + surf->readPixels(info, data->writable_data(), info.minRowBytes(), x, y); + } + } + sk_sp image = SkImage::MakeRasterData(info, data, info.minRowBytes()); + canvas->drawImage(image, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Surface_023.cpp b/docs/examples/Surface_023.cpp new file mode 100644 index 0000000000..0d472b78c6 --- /dev/null +++ b/docs/examples/Surface_023.cpp @@ -0,0 +1,23 @@ +// 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 "fiddle/examples.h" +// HASH=2d991a231e49d1de13eeb2ba9b440e01 +REG_FIDDLE(Surface_023, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + sk_sp surf(SkSurface::MakeRasterN32Premul(64, 64)); + auto surfCanvas = surf->getCanvas(); + surfCanvas->clear(SK_ColorGREEN); + SkPaint paint; + surfCanvas->drawOval({2, 10, 58, 54}, paint); + SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType); + SkBitmap bitmap; + bitmap.setInfo(info); + bitmap.allocPixels(); + for (int x : { 32, -32 } ) { + for (int y : { 32, -32 } ) { + surf->readPixels(bitmap, x, y); + } + } + canvas->drawBitmap(bitmap, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Surface_024.cpp b/docs/examples/Surface_024.cpp new file mode 100644 index 0000000000..c91901d258 --- /dev/null +++ b/docs/examples/Surface_024.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=760793bcf0ef193fa61ea03e6e8fc825 +REG_FIDDLE(Surface_024, 256, 96, false, 4) { +void draw(SkCanvas* canvas) { + sk_sp surf(SkSurface::MakeRasterN32Premul(64, 64)); + auto surfCanvas = surf->getCanvas(); + surfCanvas->clear(SK_ColorRED); + SkPaint paint; + paint.setTextSize(40); + surfCanvas->drawString("&", 16, 40, paint); + SkPixmap pixmap; + if (surf->peekPixels(&pixmap)) { + surf->writePixels(pixmap, 25, 25); + sk_sp image(surf->makeImageSnapshot()); + canvas->drawImage(image, 0, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_025.cpp b/docs/examples/Surface_025.cpp new file mode 100644 index 0000000000..6489f499a2 --- /dev/null +++ b/docs/examples/Surface_025.cpp @@ -0,0 +1,14 @@ +// 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 "fiddle/examples.h" +// HASH=d77790dd3bc9f678fa4f582347fb8fba +REG_FIDDLE(Surface_025, 256, 96, false, 4) { +void draw(SkCanvas* canvas) { + sk_sp surf(SkSurface::MakeRasterN32Premul(64, 64)); + auto surfCanvas = surf->getCanvas(); + surfCanvas->clear(SK_ColorGREEN); + surf->writePixels(source, 25, 25); + sk_sp image(surf->makeImageSnapshot()); + canvas->drawImage(image, 0, 0); +} +} // END FIDDLE diff --git a/docs/examples/Surface_026.cpp b/docs/examples/Surface_026.cpp new file mode 100644 index 0000000000..327150561e --- /dev/null +++ b/docs/examples/Surface_026.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=13cf9e7b2894ae6e98c1fd719040bf01 +REG_FIDDLE(Surface_026, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + const char* names[] = { "Unknown", "RGB_H", "BGR_H", "RGB_V", "BGR_V" }; + sk_sp surf(SkSurface::MakeRasterN32Premul(64, 64)); + SkDebugf("surf.props(): k%s_SkPixelGeometry\n", names[surf->props().pixelGeometry()]); +} +} // END FIDDLE diff --git a/docs/examples/Surface_027.cpp b/docs/examples/Surface_027.cpp new file mode 100644 index 0000000000..3d770b9144 --- /dev/null +++ b/docs/examples/Surface_027.cpp @@ -0,0 +1,33 @@ +#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 "fiddle/examples.h" +// HASH=6de6f3ef699a72ff26da1b26b23a3316 +REG_FIDDLE(Surface_027, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(32); + GrContext* context = canvas->getGrContext(); + if (!context) { + canvas->drawString("GPU only!", 20, 40, 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); + return; + } + // start of threadable work + SkDeferredDisplayListRecorder recorder(characterization); + SkCanvas* subCanvas = recorder.getCanvas(); + subCanvas->clear(SK_ColorGREEN); + std::unique_ptr displayList = recorder.detach(); + // end of threadable work + gpuSurface->draw(displayList.get()); + sk_sp img = gpuSurface->makeImageSnapshot(); + canvas->drawImage(std::move(img), 0, 0); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/Surface_028.cpp b/docs/examples/Surface_028.cpp new file mode 100644 index 0000000000..1a3a863e97 --- /dev/null +++ b/docs/examples/Surface_028.cpp @@ -0,0 +1,27 @@ +#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 "fiddle/examples.h" +// HASH=46d9bacf593deaaeabd74ff42f2571a0 +REG_FIDDLE(Surface_028, 256, 64, false, 0) { +void draw(SkCanvas* canvas) { + SkPaint paint; + paint.setTextSize(16); + sk_sp gpuSurface = SkSurface::MakeRasterN32Premul(64, 64); + SkSurfaceCharacterization characterization; + if (!gpuSurface->characterize(&characterization)) { + canvas->drawString("characterization unsupported", 20, 40, paint); + return; + } + // start of threadable work + SkDeferredDisplayListRecorder recorder(characterization); + SkCanvas* subCanvas = recorder.getCanvas(); + subCanvas->clear(SK_ColorGREEN); + std::unique_ptr displayList = recorder.detach(); + // end of threadable work + gpuSurface->draw(displayList.get()); + sk_sp img = gpuSurface->makeImageSnapshot(); + canvas->drawImage(std::move(img), 0, 0); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlobBuilder_000.cpp b/docs/examples/TextBlobBuilder_000.cpp new file mode 100644 index 0000000000..62d81c780f --- /dev/null +++ b/docs/examples/TextBlobBuilder_000.cpp @@ -0,0 +1,11 @@ +// 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 "fiddle/examples.h" +// HASH=d9dbabfe24aad92ee3c8144513e90d81 +REG_FIDDLE(TextBlobBuilder_000, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkTextBlobBuilder builder; + sk_sp blob = builder.make(); + SkDebugf("blob " "%s" " nullptr", blob == nullptr ? "equals" : "does not equal"); +} +} // END FIDDLE diff --git a/docs/examples/TextBlobBuilder_001.cpp b/docs/examples/TextBlobBuilder_001.cpp new file mode 100644 index 0000000000..617e09e59e --- /dev/null +++ b/docs/examples/TextBlobBuilder_001.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=34c37c0212cc0aef670d96945d08fe24 +REG_FIDDLE(TextBlobBuilder_001, 256, 256, true, 0) { +void draw(SkCanvas* canvas) { + SkTextBlobBuilder builder; + sk_sp blob = builder.make(); + SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal"); + SkPaint paint; + paint.setTextEncoding(kGlyphID_SkTextEncoding); + SkFont font; + paint.textToGlyphs("x", 1, builder.allocRun(font, 1, 20, 20).glyphs); + blob = builder.make(); + SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal"); + blob = builder.make(); + SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal"); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlobBuilder_002.cpp b/docs/examples/TextBlobBuilder_002.cpp new file mode 100644 index 0000000000..1a0832689b --- /dev/null +++ b/docs/examples/TextBlobBuilder_002.cpp @@ -0,0 +1,17 @@ +#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 "fiddle/examples.h" +// HASH=f0e584aec20eaee7a5bfed62aa885eee +REG_FIDDLE(TextBlobBuilder_002, 256, 60, false, 0) { +void draw(SkCanvas* canvas) { + SkTextBlobBuilder builder; + SkFont font; + SkPaint paint; + const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(font, 5, 20, 20); + paint.textToGlyphs("hello", 5, run.glyphs); + canvas->drawRect({20, 20, 30, 30}, paint); + canvas->drawTextBlob(builder.make(), 20, 20, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlobBuilder_003.cpp b/docs/examples/TextBlobBuilder_003.cpp new file mode 100644 index 0000000000..f4ff890ef6 --- /dev/null +++ b/docs/examples/TextBlobBuilder_003.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=c77ac50f506106fdfef94d20bc1a6934 +REG_FIDDLE(TextBlobBuilder_003, 256, 60, false, 0) { +void draw(SkCanvas* canvas) { + SkTextBlobBuilder builder; + SkPaint paint; + SkFont font; + const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPosH(font, 5, 20); + paint.textToGlyphs("hello", 5, run.glyphs); + SkScalar positions[] = {0, 10, 20, 40, 80}; + memcpy(run.pos, positions, sizeof(positions)); + canvas->drawTextBlob(builder.make(), 20, 20, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlobBuilder_004.cpp b/docs/examples/TextBlobBuilder_004.cpp new file mode 100644 index 0000000000..4bca56f5f6 --- /dev/null +++ b/docs/examples/TextBlobBuilder_004.cpp @@ -0,0 +1,18 @@ +#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 "fiddle/examples.h" +// HASH=da4fcb4a972b500996be9aff6c6c40e1 +REG_FIDDLE(TextBlobBuilder_004, 256, 90, false, 0) { +void draw(SkCanvas* canvas) { + SkTextBlobBuilder builder; + SkPaint paint; + SkFont font; + const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPos(font, 5); + paint.textToGlyphs("hello", 5, run.glyphs); + SkPoint positions[] = {{0, 0}, {10, 10}, {20, 20}, {40, 40}, {80, 80}}; + memcpy(run.pos, positions, sizeof(positions)); + canvas->drawTextBlob(builder.make(), 20, 20, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlob_000.cpp b/docs/examples/TextBlob_000.cpp new file mode 100644 index 0000000000..c2706cef0a --- /dev/null +++ b/docs/examples/TextBlob_000.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=fb8b2502bbe52d2029aecdf569dd9fdb +REG_FIDDLE(TextBlob_000, 256, 70, false, 0) { +void draw(SkCanvas* canvas) { + SkTextBlobBuilder textBlobBuilder; + const char bunny[] = "/(^x^)\\"; + const int len = sizeof(bunny) - 1; + uint16_t glyphs[len]; + SkPaint paint; + paint.textToGlyphs(bunny, len, glyphs); + paint.setTextEncoding(kGlyphID_SkTextEncoding); + SkFont font; + int runs[] = { 3, 1, 3 }; + SkPoint textPos = { 20, 50 }; + int glyphIndex = 0; + for (auto runLen : runs) { + font.setSize(1 == runLen ? 20 : 50); + paint.setTextSize(1 == runLen ? 20 : 50); + const SkTextBlobBuilder::RunBuffer& run = + textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY); + memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); + textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr); + glyphIndex += runLen; + } + sk_sp blob = textBlobBuilder.make(); + canvas->drawTextBlob(blob.get(), 0, 0, paint); + paint.setStyle(SkPaint::kStroke_Style); + canvas->drawRect(blob->bounds(), paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlob_001.cpp b/docs/examples/TextBlob_001.cpp new file mode 100644 index 0000000000..6992079d86 --- /dev/null +++ b/docs/examples/TextBlob_001.cpp @@ -0,0 +1,40 @@ +#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 "fiddle/examples.h" +// HASH=6e12cceca981ddabc0fc18c380543f34 +REG_FIDDLE(TextBlob_001, 256, 256, false, 0) { +void draw(SkCanvas* canvas) { + for (int index = 0; index < 2; ++index) { + SkTextBlobBuilder textBlobBuilder; + const char bunny[] = "/(^x^)\\"; + const int len = sizeof(bunny) - 1; + uint16_t glyphs[len]; + SkPaint paint; + paint.textToGlyphs(bunny, len, glyphs); + paint.setTextEncoding(kGlyphID_SkTextEncoding); + paint.setTextScaleX(0.5); + SkFont font; + font.setScaleX(0.5); + int runs[] = { 3, 1, 3 }; + SkPoint textPos = { 20, 50 }; + int glyphIndex = 0; + for (auto runLen : runs) { + font.setSize(1 == runLen ? 20 : 50); + paint.setTextSize(1 == runLen ? 20 : 50); + const SkTextBlobBuilder::RunBuffer& run = + textBlobBuilder.allocRun(font, runLen, textPos.fX, textPos.fY); + memcpy(run.glyphs, &glyphs[glyphIndex], sizeof(glyphs[0]) * runLen); + textPos.fX += paint.measureText(&glyphs[glyphIndex], sizeof(glyphs[0]) * runLen, nullptr); + glyphIndex += runLen; + } + sk_sp blob = textBlobBuilder.make(); + paint.reset(); + canvas->drawTextBlob(blob.get(), 0, 0, paint); + std::string id = "unique ID:" + std::to_string(blob->uniqueID()); + canvas->drawString(id.c_str(), 30, blob->bounds().fBottom + 15, paint); + canvas->translate(blob->bounds().fRight + 10, 0); + } +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlob_002.cpp b/docs/examples/TextBlob_002.cpp new file mode 100644 index 0000000000..39415c11b8 --- /dev/null +++ b/docs/examples/TextBlob_002.cpp @@ -0,0 +1,35 @@ +#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 "fiddle/examples.h" +// HASH=e9d4eb8ece521b1329e7433d4b243fdf +REG_FIDDLE(TextBlob_002, 256, 143, false, 0) { +void draw(SkCanvas* canvas) { + SkFont font; + font.setSize(120); + SkPoint textPos = { 20, 110 }; + int len = 3; + SkTextBlobBuilder textBlobBuilder; + const SkTextBlobBuilder::RunBuffer& run = + textBlobBuilder.allocRun(font, len, textPos.fX, textPos.fY); + run.glyphs[0] = 10; + run.glyphs[1] = 20; + run.glyphs[2] = 30; + sk_sp blob = textBlobBuilder.make(); + SkPaint paint; + SkScalar bounds[] = { 116, 134 }; + int count = blob->getIntercepts(bounds, nullptr); + std::vector intervals; + intervals.resize(count); + (void) paint.getTextBlobIntercepts(blob.get(), bounds, &intervals.front()); + canvas->drawTextBlob(blob.get(), 0, 0, paint); + paint.setColor(0xFFFF7777); + SkScalar x = textPos.fX; + for (int i = 0; i < count; i+= 2) { + canvas->drawRect({x, bounds[0], intervals[i], bounds[1]}, paint); + x = intervals[i + 1]; + } + canvas->drawRect({intervals[count - 1], bounds[0], 180, bounds[1]}, paint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlob_003.cpp b/docs/examples/TextBlob_003.cpp new file mode 100644 index 0000000000..d917cec4bd --- /dev/null +++ b/docs/examples/TextBlob_003.cpp @@ -0,0 +1,17 @@ +#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 "fiddle/examples.h" +// HASH=bec2252bc36dc8fd023015629d60c405 +REG_FIDDLE(TextBlob_003, 256, 24, false, 0) { +void draw(SkCanvas* canvas) { + SkFont font; + font.setSize(24); + SkPaint canvasPaint; + canvasPaint.setColor(SK_ColorBLUE); // respected + canvasPaint.setTextSize(2); // ignored + sk_sp blob = SkTextBlob::MakeFromText("Hello World", 11, font); + canvas->drawTextBlob(blob, 20, 20, canvasPaint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlob_004.cpp b/docs/examples/TextBlob_004.cpp new file mode 100644 index 0000000000..2a7df84110 --- /dev/null +++ b/docs/examples/TextBlob_004.cpp @@ -0,0 +1,17 @@ +#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 "fiddle/examples.h" +// HASH=a5af182e793eed3f2bb3b0efc2cf4852 +REG_FIDDLE(TextBlob_004, 256, 24, false, 0) { +void draw(SkCanvas* canvas) { + SkFont font; + font.setSize(24); + SkPaint canvasPaint; + canvasPaint.setColor(SK_ColorBLUE); // respected + canvasPaint.setTextSize(2); // ignored + sk_sp blob = SkTextBlob::MakeFromString("Hello World", font); + canvas->drawTextBlob(blob, 20, 20, canvasPaint); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlob_005.cpp b/docs/examples/TextBlob_005.cpp new file mode 100644 index 0000000000..4a87e81c79 --- /dev/null +++ b/docs/examples/TextBlob_005.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=90ce8c327d407b1faac73baa2ebd0378 +REG_FIDDLE(TextBlob_005, 256, 64, false, 0) { +#include "SkSerialProcs.h" + +void draw(SkCanvas* canvas) { + SkFont blobFont; + blobFont.setSize(24); + sk_sp blob = SkTextBlob::MakeFromText("Hello World", 11, blobFont); + char storage[2048]; + size_t used = blob->serialize(SkSerialProcs(), storage, sizeof(storage)); + sk_sp copy = SkTextBlob::Deserialize(storage, used, SkDeserialProcs()); + canvas->drawTextBlob(copy, 20, 20, SkPaint()); + std::string usage = "size=" + std::to_string(sizeof(storage)) + " used=" + std::to_string(used); + canvas->drawString(usage.c_str(), 20, 40, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/docs/examples/TextBlob_006.cpp b/docs/examples/TextBlob_006.cpp new file mode 100644 index 0000000000..e59629130a --- /dev/null +++ b/docs/examples/TextBlob_006.cpp @@ -0,0 +1,16 @@ +// 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 "fiddle/examples.h" +// HASH=464201a828f7e94fc01cd57facfcd2f4 +REG_FIDDLE(TextBlob_006, 256, 24, false, 0) { +#include "SkSerialProcs.h" + +void draw(SkCanvas* canvas) { + SkFont blobFont; + blobFont.setSize(24); + sk_sp blob = SkTextBlob::MakeFromText("Hello World", 11, blobFont); + sk_sp data = blob->serialize(SkSerialProcs()); + sk_sp copy = SkTextBlob::Deserialize(data->data(), data->size(), SkDeserialProcs()); + canvas->drawTextBlob(copy, 20, 20, SkPaint()); +} +} // END FIDDLE diff --git a/docs/examples/TextBlob_007.cpp b/docs/examples/TextBlob_007.cpp new file mode 100644 index 0000000000..24e7180b16 --- /dev/null +++ b/docs/examples/TextBlob_007.cpp @@ -0,0 +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 "fiddle/examples.h" +// HASH=68b6d0208eb0b4de67fc152381af7a58 +REG_FIDDLE(TextBlob_007, 256, 24, false, 0) { +#include "SkSerialProcs.h" + +void draw(SkCanvas* canvas) { + SkFont blobFont; + blobFont.setSize(24); + sk_sp blob = SkTextBlob::MakeFromText("Hello World!", 12, blobFont); + sk_sp data = blob->serialize(SkSerialProcs()); + uint16_t glyphs[6]; + SkPaint blobPaint; + blobPaint.textToGlyphs("Hacker", 6, glyphs); + memcpy((char*)data->writable_data() + 0x54, glyphs, sizeof(glyphs)); + sk_sp copy = SkTextBlob::Deserialize(data->data(), data->size(), SkDeserialProcs()); + canvas->drawTextBlob(copy, 20, 20, SkPaint()); +} +} // END FIDDLE +#endif // Disabled until updated to use current API. diff --git a/gn/examples.gni b/gn/examples.gni new file mode 100644 index 0000000000..c1cf137c15 --- /dev/null +++ b/gn/examples.gni @@ -0,0 +1,1133 @@ +# Copyright 2019 Google LLC. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +examples_sources = get_path_info([ + "../docs/examples/AutoCanvasRestore_000.cpp", + "../docs/examples/AutoCanvasRestore_001.cpp", + "../docs/examples/Bitmap_000.cpp", + "../docs/examples/Bitmap_001.cpp", + "../docs/examples/Bitmap_002.cpp", + "../docs/examples/Bitmap_003.cpp", + "../docs/examples/Bitmap_004.cpp", + "../docs/examples/Bitmap_005.cpp", + "../docs/examples/Bitmap_006.cpp", + "../docs/examples/Bitmap_007.cpp", + "../docs/examples/Bitmap_008.cpp", + "../docs/examples/Bitmap_009.cpp", + "../docs/examples/Bitmap_010.cpp", + "../docs/examples/Bitmap_011.cpp", + "../docs/examples/Bitmap_012.cpp", + "../docs/examples/Bitmap_013.cpp", + "../docs/examples/Bitmap_014.cpp", + "../docs/examples/Bitmap_015.cpp", + "../docs/examples/Bitmap_016.cpp", + "../docs/examples/Bitmap_017.cpp", + "../docs/examples/Bitmap_018.cpp", + "../docs/examples/Bitmap_019.cpp", + "../docs/examples/Bitmap_020.cpp", + "../docs/examples/Bitmap_021.cpp", + "../docs/examples/Bitmap_022.cpp", + "../docs/examples/Bitmap_023.cpp", + "../docs/examples/Bitmap_024.cpp", + "../docs/examples/Bitmap_025.cpp", + "../docs/examples/Bitmap_026.cpp", + "../docs/examples/Bitmap_027.cpp", + "../docs/examples/Bitmap_028.cpp", + "../docs/examples/Bitmap_029.cpp", + "../docs/examples/Bitmap_030.cpp", + "../docs/examples/Bitmap_031.cpp", + "../docs/examples/Bitmap_032.cpp", + "../docs/examples/Bitmap_033.cpp", + "../docs/examples/Bitmap_034.cpp", + "../docs/examples/Bitmap_035.cpp", + "../docs/examples/Bitmap_036.cpp", + "../docs/examples/Bitmap_037.cpp", + "../docs/examples/Bitmap_038.cpp", + "../docs/examples/Bitmap_039.cpp", + "../docs/examples/Bitmap_040.cpp", + "../docs/examples/Bitmap_041.cpp", + "../docs/examples/Bitmap_042.cpp", + "../docs/examples/Bitmap_043.cpp", + "../docs/examples/Bitmap_044.cpp", + "../docs/examples/Bitmap_045.cpp", + "../docs/examples/Bitmap_046.cpp", + "../docs/examples/Bitmap_047.cpp", + "../docs/examples/Bitmap_048.cpp", + "../docs/examples/Bitmap_049.cpp", + "../docs/examples/Bitmap_050.cpp", + "../docs/examples/Bitmap_051.cpp", + "../docs/examples/Bitmap_052.cpp", + "../docs/examples/Bitmap_053.cpp", + "../docs/examples/Bitmap_054.cpp", + "../docs/examples/Bitmap_055.cpp", + "../docs/examples/Bitmap_056.cpp", + "../docs/examples/Bitmap_057.cpp", + "../docs/examples/Bitmap_058.cpp", + "../docs/examples/Bitmap_059.cpp", + "../docs/examples/Bitmap_060.cpp", + "../docs/examples/Bitmap_061.cpp", + "../docs/examples/Bitmap_062.cpp", + "../docs/examples/Bitmap_063.cpp", + "../docs/examples/Bitmap_064.cpp", + "../docs/examples/Bitmap_065.cpp", + "../docs/examples/Bitmap_066.cpp", + "../docs/examples/Bitmap_067.cpp", + "../docs/examples/Bitmap_068.cpp", + "../docs/examples/Bitmap_069.cpp", + "../docs/examples/Bitmap_070.cpp", + "../docs/examples/Bitmap_071.cpp", + "../docs/examples/Bitmap_072.cpp", + "../docs/examples/Bitmap_073.cpp", + "../docs/examples/Bitmap_074.cpp", + "../docs/examples/Bitmap_075.cpp", + "../docs/examples/Bitmap_076.cpp", + "../docs/examples/Bitmap_077.cpp", + "../docs/examples/BlendMode_000.cpp", + "../docs/examples/BlendMode_001.cpp", + "../docs/examples/BlendMode_002.cpp", + "../docs/examples/BlendMode_003.cpp", + "../docs/examples/BlendMode_004.cpp", + "../docs/examples/BlendMode_005.cpp", + "../docs/examples/BlendMode_006.cpp", + "../docs/examples/BlendMode_007.cpp", + "../docs/examples/BlendMode_008.cpp", + "../docs/examples/BlendMode_009.cpp", + "../docs/examples/BlendMode_010.cpp", + "../docs/examples/BlendMode_011.cpp", + "../docs/examples/BlendMode_012.cpp", + "../docs/examples/BlendMode_013.cpp", + "../docs/examples/BlendMode_014.cpp", + "../docs/examples/BlendMode_015.cpp", + "../docs/examples/BlendMode_016.cpp", + "../docs/examples/BlendMode_017.cpp", + "../docs/examples/BlendMode_018.cpp", + "../docs/examples/BlendMode_019.cpp", + "../docs/examples/BlendMode_020.cpp", + "../docs/examples/BlendMode_021.cpp", + "../docs/examples/BlendMode_022.cpp", + "../docs/examples/BlendMode_023.cpp", + "../docs/examples/BlendMode_024.cpp", + "../docs/examples/BlendMode_025.cpp", + "../docs/examples/BlendMode_026.cpp", + "../docs/examples/BlendMode_027.cpp", + "../docs/examples/BlendMode_028.cpp", + "../docs/examples/BlendMode_029.cpp", + "../docs/examples/Canvas_000.cpp", + "../docs/examples/Canvas_001.cpp", + "../docs/examples/Canvas_002.cpp", + "../docs/examples/Canvas_003.cpp", + "../docs/examples/Canvas_004.cpp", + "../docs/examples/Canvas_005.cpp", + "../docs/examples/Canvas_006.cpp", + "../docs/examples/Canvas_008.cpp", + "../docs/examples/Canvas_009.cpp", + "../docs/examples/Canvas_010.cpp", + "../docs/examples/Canvas_011.cpp", + "../docs/examples/Canvas_012.cpp", + "../docs/examples/Canvas_013.cpp", + "../docs/examples/Canvas_014.cpp", + "../docs/examples/Canvas_015.cpp", + "../docs/examples/Canvas_016.cpp", + "../docs/examples/Canvas_017.cpp", + "../docs/examples/Canvas_018.cpp", + "../docs/examples/Canvas_019.cpp", + "../docs/examples/Canvas_020.cpp", + "../docs/examples/Canvas_021.cpp", + "../docs/examples/Canvas_022.cpp", + "../docs/examples/Canvas_023.cpp", + "../docs/examples/Canvas_024.cpp", + "../docs/examples/Canvas_025.cpp", + "../docs/examples/Canvas_026.cpp", + "../docs/examples/Canvas_027.cpp", + "../docs/examples/Canvas_028.cpp", + "../docs/examples/Canvas_029.cpp", + "../docs/examples/Canvas_030.cpp", + "../docs/examples/Canvas_031.cpp", + "../docs/examples/Canvas_032.cpp", + "../docs/examples/Canvas_033.cpp", + "../docs/examples/Canvas_034.cpp", + "../docs/examples/Canvas_035.cpp", + "../docs/examples/Canvas_036.cpp", + "../docs/examples/Canvas_037.cpp", + "../docs/examples/Canvas_038.cpp", + "../docs/examples/Canvas_039.cpp", + "../docs/examples/Canvas_040.cpp", + "../docs/examples/Canvas_041.cpp", + "../docs/examples/Canvas_042.cpp", + "../docs/examples/Canvas_043.cpp", + "../docs/examples/Canvas_044.cpp", + "../docs/examples/Canvas_045.cpp", + "../docs/examples/Canvas_046.cpp", + "../docs/examples/Canvas_047.cpp", + "../docs/examples/Canvas_048.cpp", + "../docs/examples/Canvas_049.cpp", + "../docs/examples/Canvas_050.cpp", + "../docs/examples/Canvas_051.cpp", + "../docs/examples/Canvas_052.cpp", + "../docs/examples/Canvas_053.cpp", + "../docs/examples/Canvas_054.cpp", + "../docs/examples/Canvas_055.cpp", + "../docs/examples/Canvas_056.cpp", + "../docs/examples/Canvas_057.cpp", + "../docs/examples/Canvas_058.cpp", + "../docs/examples/Canvas_059.cpp", + "../docs/examples/Canvas_060.cpp", + "../docs/examples/Canvas_061.cpp", + "../docs/examples/Canvas_062.cpp", + "../docs/examples/Canvas_063.cpp", + "../docs/examples/Canvas_064.cpp", + "../docs/examples/Canvas_065.cpp", + "../docs/examples/Canvas_066.cpp", + "../docs/examples/Canvas_067.cpp", + "../docs/examples/Canvas_068.cpp", + "../docs/examples/Canvas_069.cpp", + "../docs/examples/Canvas_070.cpp", + "../docs/examples/Canvas_071.cpp", + "../docs/examples/Canvas_072.cpp", + "../docs/examples/Canvas_073.cpp", + "../docs/examples/Canvas_074.cpp", + "../docs/examples/Canvas_075.cpp", + "../docs/examples/Canvas_076.cpp", + "../docs/examples/Canvas_077.cpp", + "../docs/examples/Canvas_078.cpp", + "../docs/examples/Canvas_079.cpp", + "../docs/examples/Canvas_080.cpp", + "../docs/examples/Canvas_081.cpp", + "../docs/examples/Canvas_082.cpp", + "../docs/examples/Canvas_083.cpp", + "../docs/examples/Canvas_084.cpp", + "../docs/examples/Canvas_085.cpp", + "../docs/examples/Canvas_086.cpp", + "../docs/examples/Canvas_087.cpp", + "../docs/examples/Canvas_088.cpp", + "../docs/examples/Canvas_089.cpp", + "../docs/examples/Canvas_090.cpp", + "../docs/examples/Canvas_091.cpp", + "../docs/examples/Canvas_092.cpp", + "../docs/examples/Canvas_093.cpp", + "../docs/examples/Canvas_094.cpp", + "../docs/examples/Canvas_095.cpp", + "../docs/examples/Canvas_096.cpp", + "../docs/examples/Canvas_097.cpp", + "../docs/examples/Canvas_098.cpp", + "../docs/examples/Canvas_099.cpp", + "../docs/examples/Canvas_100.cpp", + "../docs/examples/Canvas_101.cpp", + "../docs/examples/Canvas_102.cpp", + "../docs/examples/Canvas_103.cpp", + "../docs/examples/Canvas_104.cpp", + "../docs/examples/Canvas_105.cpp", + "../docs/examples/Canvas_106.cpp", + "../docs/examples/Canvas_107.cpp", + "../docs/examples/Canvas_108.cpp", + "../docs/examples/Canvas_109.cpp", + "../docs/examples/Canvas_110.cpp", + "../docs/examples/Canvas_111.cpp", + "../docs/examples/Canvas_112.cpp", + "../docs/examples/Canvas_113.cpp", + "../docs/examples/Canvas_114.cpp", + "../docs/examples/Canvas_115.cpp", + "../docs/examples/Canvas_116.cpp", + "../docs/examples/Canvas_117.cpp", + "../docs/examples/Canvas_118.cpp", + "../docs/examples/Canvas_119.cpp", + "../docs/examples/Canvas_120.cpp", + "../docs/examples/Canvas_121.cpp", + "../docs/examples/Canvas_122.cpp", + "../docs/examples/Canvas_123.cpp", + "../docs/examples/Canvas_124.cpp", + "../docs/examples/Canvas_125.cpp", + "../docs/examples/Canvas_126.cpp", + "../docs/examples/Canvas_127.cpp", + "../docs/examples/Canvas_128.cpp", + "../docs/examples/Canvas_129.cpp", + "../docs/examples/Canvas_130.cpp", + "../docs/examples/Canvas_131.cpp", + "../docs/examples/Color4f_000.cpp", + "../docs/examples/Color4f_001.cpp", + "../docs/examples/Color4f_002.cpp", + "../docs/examples/Color4f_003.cpp", + "../docs/examples/Color4f_004.cpp", + "../docs/examples/Color4f_005.cpp", + "../docs/examples/Color_000.cpp", + "../docs/examples/Color_001.cpp", + "../docs/examples/Color_002.cpp", + "../docs/examples/Color_003.cpp", + "../docs/examples/Color_004.cpp", + "../docs/examples/Color_005.cpp", + "../docs/examples/Color_006.cpp", + "../docs/examples/Color_007.cpp", + "../docs/examples/Color_008.cpp", + "../docs/examples/Color_009.cpp", + "../docs/examples/Color_010.cpp", + "../docs/examples/Color_011.cpp", + "../docs/examples/Color_012.cpp", + "../docs/examples/Color_013.cpp", + "../docs/examples/Color_014.cpp", + "../docs/examples/Color_015.cpp", + "../docs/examples/Color_016.cpp", + "../docs/examples/Color_017.cpp", + "../docs/examples/Color_018.cpp", + "../docs/examples/Font_000.cpp", + "../docs/examples/Font_001.cpp", + "../docs/examples/Font_002.cpp", + "../docs/examples/Font_003.cpp", + "../docs/examples/Font_004.cpp", + "../docs/examples/Font_005.cpp", + "../docs/examples/Font_006.cpp", + "../docs/examples/Font_007.cpp", + "../docs/examples/Font_008.cpp", + "../docs/examples/Font_009.cpp", + "../docs/examples/Font_010.cpp", + "../docs/examples/Font_011.cpp", + "../docs/examples/Font_012.cpp", + "../docs/examples/Font_013.cpp", + "../docs/examples/Font_014.cpp", + "../docs/examples/Font_015.cpp", + "../docs/examples/Font_016.cpp", + "../docs/examples/Font_017.cpp", + "../docs/examples/Font_018.cpp", + "../docs/examples/Font_019.cpp", + "../docs/examples/Font_020.cpp", + "../docs/examples/Font_021.cpp", + "../docs/examples/Font_022.cpp", + "../docs/examples/Font_023.cpp", + "../docs/examples/Font_024.cpp", + "../docs/examples/Font_025.cpp", + "../docs/examples/Font_026.cpp", + "../docs/examples/Font_027.cpp", + "../docs/examples/Font_028.cpp", + "../docs/examples/Font_029.cpp", + "../docs/examples/Font_030.cpp", + "../docs/examples/Font_031.cpp", + "../docs/examples/Font_032.cpp", + "../docs/examples/Font_033.cpp", + "../docs/examples/Font_034.cpp", + "../docs/examples/Font_035.cpp", + "../docs/examples/Font_036.cpp", + "../docs/examples/Font_037.cpp", + "../docs/examples/Font_038.cpp", + "../docs/examples/IPoint_000.cpp", + "../docs/examples/IPoint_001.cpp", + "../docs/examples/IPoint_002.cpp", + "../docs/examples/IPoint_003.cpp", + "../docs/examples/IPoint_004.cpp", + "../docs/examples/IPoint_005.cpp", + "../docs/examples/IPoint_006.cpp", + "../docs/examples/IPoint_007.cpp", + "../docs/examples/IPoint_008.cpp", + "../docs/examples/IPoint_009.cpp", + "../docs/examples/IPoint_010.cpp", + "../docs/examples/IPoint_011.cpp", + "../docs/examples/IPoint_012.cpp", + "../docs/examples/IRect_000.cpp", + "../docs/examples/IRect_001.cpp", + "../docs/examples/IRect_002.cpp", + "../docs/examples/IRect_003.cpp", + "../docs/examples/IRect_004.cpp", + "../docs/examples/IRect_005.cpp", + "../docs/examples/IRect_006.cpp", + "../docs/examples/IRect_007.cpp", + "../docs/examples/IRect_008.cpp", + "../docs/examples/IRect_009.cpp", + "../docs/examples/IRect_010.cpp", + "../docs/examples/IRect_011.cpp", + "../docs/examples/IRect_012.cpp", + "../docs/examples/IRect_013.cpp", + "../docs/examples/IRect_014.cpp", + "../docs/examples/IRect_015.cpp", + "../docs/examples/IRect_016.cpp", + "../docs/examples/IRect_017.cpp", + "../docs/examples/IRect_018.cpp", + "../docs/examples/IRect_019.cpp", + "../docs/examples/IRect_020.cpp", + "../docs/examples/IRect_021.cpp", + "../docs/examples/IRect_022.cpp", + "../docs/examples/IRect_023.cpp", + "../docs/examples/IRect_024.cpp", + "../docs/examples/IRect_025.cpp", + "../docs/examples/IRect_026.cpp", + "../docs/examples/IRect_027.cpp", + "../docs/examples/IRect_028.cpp", + "../docs/examples/IRect_029.cpp", + "../docs/examples/IRect_030.cpp", + "../docs/examples/IRect_031.cpp", + "../docs/examples/IRect_032.cpp", + "../docs/examples/IRect_033.cpp", + "../docs/examples/IRect_034.cpp", + "../docs/examples/IRect_035.cpp", + "../docs/examples/IRect_036.cpp", + "../docs/examples/IRect_037.cpp", + "../docs/examples/IRect_038.cpp", + "../docs/examples/IRect_039.cpp", + "../docs/examples/IRect_040.cpp", + "../docs/examples/IRect_041.cpp", + "../docs/examples/IRect_042.cpp", + "../docs/examples/IRect_043.cpp", + "../docs/examples/IRect_044.cpp", + "../docs/examples/IRect_045.cpp", + "../docs/examples/IRect_046.cpp", + "../docs/examples/IRect_047.cpp", + "../docs/examples/IRect_048.cpp", + "../docs/examples/IRect_049.cpp", + "../docs/examples/ImageInfo_000.cpp", + "../docs/examples/ImageInfo_001.cpp", + "../docs/examples/ImageInfo_002.cpp", + "../docs/examples/ImageInfo_003.cpp", + "../docs/examples/ImageInfo_004.cpp", + "../docs/examples/ImageInfo_005.cpp", + "../docs/examples/ImageInfo_006.cpp", + "../docs/examples/ImageInfo_007.cpp", + "../docs/examples/ImageInfo_008.cpp", + "../docs/examples/ImageInfo_009.cpp", + "../docs/examples/ImageInfo_010.cpp", + "../docs/examples/ImageInfo_011.cpp", + "../docs/examples/ImageInfo_012.cpp", + "../docs/examples/ImageInfo_013.cpp", + "../docs/examples/ImageInfo_014.cpp", + "../docs/examples/ImageInfo_015.cpp", + "../docs/examples/ImageInfo_016.cpp", + "../docs/examples/ImageInfo_017.cpp", + "../docs/examples/ImageInfo_018.cpp", + "../docs/examples/ImageInfo_019.cpp", + "../docs/examples/ImageInfo_020.cpp", + "../docs/examples/ImageInfo_021.cpp", + "../docs/examples/ImageInfo_022.cpp", + "../docs/examples/ImageInfo_023.cpp", + "../docs/examples/ImageInfo_024.cpp", + "../docs/examples/ImageInfo_025.cpp", + "../docs/examples/ImageInfo_026.cpp", + "../docs/examples/ImageInfo_027.cpp", + "../docs/examples/ImageInfo_028.cpp", + "../docs/examples/ImageInfo_029.cpp", + "../docs/examples/ImageInfo_030.cpp", + "../docs/examples/ImageInfo_031.cpp", + "../docs/examples/ImageInfo_032.cpp", + "../docs/examples/ImageInfo_033.cpp", + "../docs/examples/ImageInfo_034.cpp", + "../docs/examples/ImageInfo_035.cpp", + "../docs/examples/ImageInfo_036.cpp", + "../docs/examples/ImageInfo_037.cpp", + "../docs/examples/ImageInfo_038.cpp", + "../docs/examples/ImageInfo_039.cpp", + "../docs/examples/ImageInfo_040.cpp", + "../docs/examples/ImageInfo_041.cpp", + "../docs/examples/ImageInfo_042.cpp", + "../docs/examples/ImageInfo_043.cpp", + "../docs/examples/ImageInfo_044.cpp", + "../docs/examples/ImageInfo_045.cpp", + "../docs/examples/ImageInfo_046.cpp", + "../docs/examples/ImageInfo_047.cpp", + "../docs/examples/ImageInfo_048.cpp", + "../docs/examples/ImageInfo_049.cpp", + "../docs/examples/ImageInfo_050.cpp", + "../docs/examples/ImageInfo_051.cpp", + "../docs/examples/Image_000.cpp", + "../docs/examples/Image_001.cpp", + "../docs/examples/Image_002.cpp", + "../docs/examples/Image_003.cpp", + "../docs/examples/Image_004.cpp", + "../docs/examples/Image_005.cpp", + "../docs/examples/Image_006.cpp", + "../docs/examples/Image_007.cpp", + "../docs/examples/Image_008.cpp", + "../docs/examples/Image_009.cpp", + "../docs/examples/Image_010.cpp", + "../docs/examples/Image_011.cpp", + "../docs/examples/Image_012.cpp", + "../docs/examples/Image_013.cpp", + "../docs/examples/Image_014.cpp", + "../docs/examples/Image_015.cpp", + "../docs/examples/Image_016.cpp", + "../docs/examples/Image_017.cpp", + "../docs/examples/Image_018.cpp", + "../docs/examples/Image_019.cpp", + "../docs/examples/Image_020.cpp", + "../docs/examples/Image_021.cpp", + "../docs/examples/Image_022.cpp", + "../docs/examples/Image_023.cpp", + "../docs/examples/Image_024.cpp", + "../docs/examples/Image_025.cpp", + "../docs/examples/Image_026.cpp", + "../docs/examples/Image_027.cpp", + "../docs/examples/Image_028.cpp", + "../docs/examples/Image_029.cpp", + "../docs/examples/Image_030.cpp", + "../docs/examples/Image_031.cpp", + "../docs/examples/Image_032.cpp", + "../docs/examples/Image_033.cpp", + "../docs/examples/Image_034.cpp", + "../docs/examples/Image_035.cpp", + "../docs/examples/Image_036.cpp", + "../docs/examples/Image_037.cpp", + "../docs/examples/Image_038.cpp", + "../docs/examples/Image_039.cpp", + "../docs/examples/Image_040.cpp", + "../docs/examples/Image_041.cpp", + "../docs/examples/Image_042.cpp", + "../docs/examples/Image_043.cpp", + "../docs/examples/Matrix_000.cpp", + "../docs/examples/Matrix_001.cpp", + "../docs/examples/Matrix_002.cpp", + "../docs/examples/Matrix_003.cpp", + "../docs/examples/Matrix_004.cpp", + "../docs/examples/Matrix_005.cpp", + "../docs/examples/Matrix_006.cpp", + "../docs/examples/Matrix_007.cpp", + "../docs/examples/Matrix_008.cpp", + "../docs/examples/Matrix_009.cpp", + "../docs/examples/Matrix_010.cpp", + "../docs/examples/Matrix_011.cpp", + "../docs/examples/Matrix_012.cpp", + "../docs/examples/Matrix_013.cpp", + "../docs/examples/Matrix_014.cpp", + "../docs/examples/Matrix_015.cpp", + "../docs/examples/Matrix_016.cpp", + "../docs/examples/Matrix_017.cpp", + "../docs/examples/Matrix_018.cpp", + "../docs/examples/Matrix_019.cpp", + "../docs/examples/Matrix_020.cpp", + "../docs/examples/Matrix_021.cpp", + "../docs/examples/Matrix_022.cpp", + "../docs/examples/Matrix_023.cpp", + "../docs/examples/Matrix_024.cpp", + "../docs/examples/Matrix_025.cpp", + "../docs/examples/Matrix_026.cpp", + "../docs/examples/Matrix_027.cpp", + "../docs/examples/Matrix_028.cpp", + "../docs/examples/Matrix_029.cpp", + "../docs/examples/Matrix_030.cpp", + "../docs/examples/Matrix_031.cpp", + "../docs/examples/Matrix_032.cpp", + "../docs/examples/Matrix_033.cpp", + "../docs/examples/Matrix_034.cpp", + "../docs/examples/Matrix_035.cpp", + "../docs/examples/Matrix_036.cpp", + "../docs/examples/Matrix_037.cpp", + "../docs/examples/Matrix_038.cpp", + "../docs/examples/Matrix_039.cpp", + "../docs/examples/Matrix_040.cpp", + "../docs/examples/Matrix_041.cpp", + "../docs/examples/Matrix_042.cpp", + "../docs/examples/Matrix_043.cpp", + "../docs/examples/Matrix_044.cpp", + "../docs/examples/Matrix_045.cpp", + "../docs/examples/Matrix_046.cpp", + "../docs/examples/Matrix_047.cpp", + "../docs/examples/Matrix_048.cpp", + "../docs/examples/Matrix_049.cpp", + "../docs/examples/Matrix_050.cpp", + "../docs/examples/Matrix_051.cpp", + "../docs/examples/Matrix_052.cpp", + "../docs/examples/Matrix_053.cpp", + "../docs/examples/Matrix_054.cpp", + "../docs/examples/Matrix_055.cpp", + "../docs/examples/Matrix_056.cpp", + "../docs/examples/Matrix_057.cpp", + "../docs/examples/Matrix_058.cpp", + "../docs/examples/Matrix_059.cpp", + "../docs/examples/Matrix_060.cpp", + "../docs/examples/Matrix_061.cpp", + "../docs/examples/Matrix_062.cpp", + "../docs/examples/Matrix_063.cpp", + "../docs/examples/Matrix_064.cpp", + "../docs/examples/Matrix_065.cpp", + "../docs/examples/Matrix_066.cpp", + "../docs/examples/Matrix_067.cpp", + "../docs/examples/Matrix_068.cpp", + "../docs/examples/Matrix_069.cpp", + "../docs/examples/Matrix_070.cpp", + "../docs/examples/Matrix_071.cpp", + "../docs/examples/Matrix_072.cpp", + "../docs/examples/Matrix_073.cpp", + "../docs/examples/Matrix_074.cpp", + "../docs/examples/Matrix_075.cpp", + "../docs/examples/Matrix_076.cpp", + "../docs/examples/Matrix_077.cpp", + "../docs/examples/Matrix_078.cpp", + "../docs/examples/Matrix_079.cpp", + "../docs/examples/Matrix_080.cpp", + "../docs/examples/Matrix_081.cpp", + "../docs/examples/Matrix_082.cpp", + "../docs/examples/Matrix_083.cpp", + "../docs/examples/Matrix_084.cpp", + "../docs/examples/Matrix_085.cpp", + "../docs/examples/Matrix_086.cpp", + "../docs/examples/Matrix_087.cpp", + "../docs/examples/Matrix_088.cpp", + "../docs/examples/Matrix_089.cpp", + "../docs/examples/Matrix_090.cpp", + "../docs/examples/Matrix_091.cpp", + "../docs/examples/Matrix_092.cpp", + "../docs/examples/Matrix_093.cpp", + "../docs/examples/Matrix_094.cpp", + "../docs/examples/Matrix_095.cpp", + "../docs/examples/Matrix_096.cpp", + "../docs/examples/Matrix_097.cpp", + "../docs/examples/Matrix_098.cpp", + "../docs/examples/Matrix_099.cpp", + "../docs/examples/Matrix_100.cpp", + "../docs/examples/Matrix_101.cpp", + "../docs/examples/Matrix_102.cpp", + "../docs/examples/Matrix_103.cpp", + "../docs/examples/Matrix_104.cpp", + "../docs/examples/Matrix_105.cpp", + "../docs/examples/Matrix_106.cpp", + "../docs/examples/Matrix_107.cpp", + "../docs/examples/Paint_000.cpp", + "../docs/examples/Paint_001.cpp", + "../docs/examples/Paint_002.cpp", + "../docs/examples/Paint_003.cpp", + "../docs/examples/Paint_004.cpp", + "../docs/examples/Paint_005.cpp", + "../docs/examples/Paint_006.cpp", + "../docs/examples/Paint_007.cpp", + "../docs/examples/Paint_008.cpp", + "../docs/examples/Paint_009.cpp", + "../docs/examples/Paint_010.cpp", + "../docs/examples/Paint_011.cpp", + "../docs/examples/Paint_012.cpp", + "../docs/examples/Paint_013.cpp", + "../docs/examples/Paint_014.cpp", + "../docs/examples/Paint_015.cpp", + "../docs/examples/Paint_016.cpp", + "../docs/examples/Paint_017.cpp", + "../docs/examples/Paint_018.cpp", + "../docs/examples/Paint_019.cpp", + "../docs/examples/Paint_020.cpp", + "../docs/examples/Paint_021.cpp", + "../docs/examples/Paint_022.cpp", + "../docs/examples/Paint_023.cpp", + "../docs/examples/Paint_024.cpp", + "../docs/examples/Paint_025.cpp", + "../docs/examples/Paint_026.cpp", + "../docs/examples/Paint_027.cpp", + "../docs/examples/Paint_028.cpp", + "../docs/examples/Paint_029.cpp", + "../docs/examples/Paint_030.cpp", + "../docs/examples/Paint_031.cpp", + "../docs/examples/Paint_032.cpp", + "../docs/examples/Paint_033.cpp", + "../docs/examples/Paint_034.cpp", + "../docs/examples/Paint_035.cpp", + "../docs/examples/Paint_036.cpp", + "../docs/examples/Paint_037.cpp", + "../docs/examples/Paint_038.cpp", + "../docs/examples/Paint_039.cpp", + "../docs/examples/Paint_040.cpp", + "../docs/examples/Paint_041.cpp", + "../docs/examples/Paint_042.cpp", + "../docs/examples/Paint_043.cpp", + "../docs/examples/Paint_044.cpp", + "../docs/examples/Paint_045.cpp", + "../docs/examples/Paint_046.cpp", + "../docs/examples/Paint_047.cpp", + "../docs/examples/Paint_048.cpp", + "../docs/examples/Paint_049.cpp", + "../docs/examples/Paint_050.cpp", + "../docs/examples/Paint_051.cpp", + "../docs/examples/Paint_052.cpp", + "../docs/examples/Paint_053.cpp", + "../docs/examples/Paint_054.cpp", + "../docs/examples/Paint_055.cpp", + "../docs/examples/Paint_056.cpp", + "../docs/examples/Paint_057.cpp", + "../docs/examples/Paint_058.cpp", + "../docs/examples/Paint_059.cpp", + "../docs/examples/Paint_060.cpp", + "../docs/examples/Paint_061.cpp", + "../docs/examples/Paint_062.cpp", + "../docs/examples/Paint_063.cpp", + "../docs/examples/Paint_064.cpp", + "../docs/examples/Paint_065.cpp", + "../docs/examples/Paint_066.cpp", + "../docs/examples/Paint_067.cpp", + "../docs/examples/Paint_068.cpp", + "../docs/examples/Paint_069.cpp", + "../docs/examples/Paint_070.cpp", + "../docs/examples/Paint_071.cpp", + "../docs/examples/Paint_072.cpp", + "../docs/examples/Paint_073.cpp", + "../docs/examples/Paint_074.cpp", + "../docs/examples/Paint_075.cpp", + "../docs/examples/Paint_076.cpp", + "../docs/examples/Paint_077.cpp", + "../docs/examples/Paint_078.cpp", + "../docs/examples/Paint_079.cpp", + "../docs/examples/Paint_080.cpp", + "../docs/examples/Paint_081.cpp", + "../docs/examples/Paint_082.cpp", + "../docs/examples/Paint_083.cpp", + "../docs/examples/Paint_084.cpp", + "../docs/examples/Paint_085.cpp", + "../docs/examples/Paint_086.cpp", + "../docs/examples/Paint_087.cpp", + "../docs/examples/Paint_088.cpp", + "../docs/examples/Paint_089.cpp", + "../docs/examples/Paint_090.cpp", + "../docs/examples/Paint_091.cpp", + "../docs/examples/Paint_092.cpp", + "../docs/examples/Paint_093.cpp", + "../docs/examples/Paint_094.cpp", + "../docs/examples/Paint_095.cpp", + "../docs/examples/Paint_096.cpp", + "../docs/examples/Paint_097.cpp", + "../docs/examples/Paint_098.cpp", + "../docs/examples/Paint_099.cpp", + "../docs/examples/Paint_100.cpp", + "../docs/examples/Paint_101.cpp", + "../docs/examples/Paint_102.cpp", + "../docs/examples/Paint_103.cpp", + "../docs/examples/Paint_104.cpp", + "../docs/examples/Paint_105.cpp", + "../docs/examples/Paint_106.cpp", + "../docs/examples/Paint_107.cpp", + "../docs/examples/Paint_108.cpp", + "../docs/examples/Paint_109.cpp", + "../docs/examples/Paint_110.cpp", + "../docs/examples/Paint_111.cpp", + "../docs/examples/Paint_112.cpp", + "../docs/examples/Paint_113.cpp", + "../docs/examples/Paint_114.cpp", + "../docs/examples/Paint_115.cpp", + "../docs/examples/Paint_116.cpp", + "../docs/examples/Paint_117.cpp", + "../docs/examples/Path_000.cpp", + "../docs/examples/Path_001.cpp", + "../docs/examples/Path_002.cpp", + "../docs/examples/Path_003.cpp", + "../docs/examples/Path_004.cpp", + "../docs/examples/Path_005.cpp", + "../docs/examples/Path_006.cpp", + "../docs/examples/Path_007.cpp", + "../docs/examples/Path_008.cpp", + "../docs/examples/Path_009.cpp", + "../docs/examples/Path_010.cpp", + "../docs/examples/Path_011.cpp", + "../docs/examples/Path_012.cpp", + "../docs/examples/Path_013.cpp", + "../docs/examples/Path_014.cpp", + "../docs/examples/Path_015.cpp", + "../docs/examples/Path_016.cpp", + "../docs/examples/Path_017.cpp", + "../docs/examples/Path_018.cpp", + "../docs/examples/Path_019.cpp", + "../docs/examples/Path_020.cpp", + "../docs/examples/Path_021.cpp", + "../docs/examples/Path_022.cpp", + "../docs/examples/Path_023.cpp", + "../docs/examples/Path_024.cpp", + "../docs/examples/Path_025.cpp", + "../docs/examples/Path_026.cpp", + "../docs/examples/Path_027.cpp", + "../docs/examples/Path_028.cpp", + "../docs/examples/Path_029.cpp", + "../docs/examples/Path_030.cpp", + "../docs/examples/Path_031.cpp", + "../docs/examples/Path_032.cpp", + "../docs/examples/Path_033.cpp", + "../docs/examples/Path_034.cpp", + "../docs/examples/Path_035.cpp", + "../docs/examples/Path_036.cpp", + "../docs/examples/Path_037.cpp", + "../docs/examples/Path_038.cpp", + "../docs/examples/Path_039.cpp", + "../docs/examples/Path_040.cpp", + "../docs/examples/Path_041.cpp", + "../docs/examples/Path_042.cpp", + "../docs/examples/Path_043.cpp", + "../docs/examples/Path_044.cpp", + "../docs/examples/Path_045.cpp", + "../docs/examples/Path_046.cpp", + "../docs/examples/Path_047.cpp", + "../docs/examples/Path_048.cpp", + "../docs/examples/Path_049.cpp", + "../docs/examples/Path_050.cpp", + "../docs/examples/Path_051.cpp", + "../docs/examples/Path_052.cpp", + "../docs/examples/Path_053.cpp", + "../docs/examples/Path_054.cpp", + "../docs/examples/Path_055.cpp", + "../docs/examples/Path_056.cpp", + "../docs/examples/Path_057.cpp", + "../docs/examples/Path_058.cpp", + "../docs/examples/Path_059.cpp", + "../docs/examples/Path_060.cpp", + "../docs/examples/Path_061.cpp", + "../docs/examples/Path_062.cpp", + "../docs/examples/Path_063.cpp", + "../docs/examples/Path_064.cpp", + "../docs/examples/Path_065.cpp", + "../docs/examples/Path_066.cpp", + "../docs/examples/Path_067.cpp", + "../docs/examples/Path_068.cpp", + "../docs/examples/Path_069.cpp", + "../docs/examples/Path_070.cpp", + "../docs/examples/Path_071.cpp", + "../docs/examples/Path_072.cpp", + "../docs/examples/Path_073.cpp", + "../docs/examples/Path_074.cpp", + "../docs/examples/Path_075.cpp", + "../docs/examples/Path_076.cpp", + "../docs/examples/Path_077.cpp", + "../docs/examples/Path_078.cpp", + "../docs/examples/Path_079.cpp", + "../docs/examples/Path_080.cpp", + "../docs/examples/Path_081.cpp", + "../docs/examples/Path_082.cpp", + "../docs/examples/Path_083.cpp", + "../docs/examples/Path_084.cpp", + "../docs/examples/Path_085.cpp", + "../docs/examples/Path_086.cpp", + "../docs/examples/Path_087.cpp", + "../docs/examples/Path_088.cpp", + "../docs/examples/Path_089.cpp", + "../docs/examples/Path_090.cpp", + "../docs/examples/Path_091.cpp", + "../docs/examples/Path_092.cpp", + "../docs/examples/Path_093.cpp", + "../docs/examples/Path_094.cpp", + "../docs/examples/Path_095.cpp", + "../docs/examples/Path_096.cpp", + "../docs/examples/Path_097.cpp", + "../docs/examples/Path_098.cpp", + "../docs/examples/Path_099.cpp", + "../docs/examples/Path_100.cpp", + "../docs/examples/Path_101.cpp", + "../docs/examples/Path_102.cpp", + "../docs/examples/Path_103.cpp", + "../docs/examples/Path_104.cpp", + "../docs/examples/Path_105.cpp", + "../docs/examples/Path_106.cpp", + "../docs/examples/Path_107.cpp", + "../docs/examples/Path_108.cpp", + "../docs/examples/Path_109.cpp", + "../docs/examples/Path_110.cpp", + "../docs/examples/Path_111.cpp", + "../docs/examples/Path_112.cpp", + "../docs/examples/Path_113.cpp", + "../docs/examples/Path_114.cpp", + "../docs/examples/Path_115.cpp", + "../docs/examples/Path_116.cpp", + "../docs/examples/Path_117.cpp", + "../docs/examples/Path_118.cpp", + "../docs/examples/Path_119.cpp", + "../docs/examples/Path_120.cpp", + "../docs/examples/Path_121.cpp", + "../docs/examples/Path_122.cpp", + "../docs/examples/Path_123.cpp", + "../docs/examples/Path_124.cpp", + "../docs/examples/Path_125.cpp", + "../docs/examples/Path_126.cpp", + "../docs/examples/Path_127.cpp", + "../docs/examples/Picture_000.cpp", + "../docs/examples/Picture_001.cpp", + "../docs/examples/Picture_002.cpp", + "../docs/examples/Picture_003.cpp", + "../docs/examples/Picture_004.cpp", + "../docs/examples/Picture_005.cpp", + "../docs/examples/Picture_006.cpp", + "../docs/examples/Picture_007.cpp", + "../docs/examples/Picture_008.cpp", + "../docs/examples/Picture_009.cpp", + "../docs/examples/Picture_010.cpp", + "../docs/examples/Picture_011.cpp", + "../docs/examples/Pixmap_000.cpp", + "../docs/examples/Pixmap_001.cpp", + "../docs/examples/Pixmap_002.cpp", + "../docs/examples/Pixmap_003.cpp", + "../docs/examples/Pixmap_004.cpp", + "../docs/examples/Pixmap_005.cpp", + "../docs/examples/Pixmap_006.cpp", + "../docs/examples/Pixmap_007.cpp", + "../docs/examples/Pixmap_008.cpp", + "../docs/examples/Pixmap_009.cpp", + "../docs/examples/Pixmap_010.cpp", + "../docs/examples/Pixmap_011.cpp", + "../docs/examples/Pixmap_012.cpp", + "../docs/examples/Pixmap_013.cpp", + "../docs/examples/Pixmap_014.cpp", + "../docs/examples/Pixmap_015.cpp", + "../docs/examples/Pixmap_016.cpp", + "../docs/examples/Pixmap_017.cpp", + "../docs/examples/Pixmap_018.cpp", + "../docs/examples/Pixmap_019.cpp", + "../docs/examples/Pixmap_020.cpp", + "../docs/examples/Pixmap_021.cpp", + "../docs/examples/Pixmap_022.cpp", + "../docs/examples/Pixmap_023.cpp", + "../docs/examples/Pixmap_024.cpp", + "../docs/examples/Pixmap_025.cpp", + "../docs/examples/Pixmap_026.cpp", + "../docs/examples/Pixmap_027.cpp", + "../docs/examples/Pixmap_028.cpp", + "../docs/examples/Pixmap_029.cpp", + "../docs/examples/Pixmap_030.cpp", + "../docs/examples/Pixmap_031.cpp", + "../docs/examples/Pixmap_032.cpp", + "../docs/examples/Pixmap_033.cpp", + "../docs/examples/Pixmap_034.cpp", + "../docs/examples/Pixmap_035.cpp", + "../docs/examples/Pixmap_036.cpp", + "../docs/examples/Pixmap_037.cpp", + "../docs/examples/Pixmap_038.cpp", + "../docs/examples/Pixmap_039.cpp", + "../docs/examples/Pixmap_040.cpp", + "../docs/examples/Pixmap_041.cpp", + "../docs/examples/Pixmap_042.cpp", + "../docs/examples/Pixmap_043.cpp", + "../docs/examples/Pixmap_044.cpp", + "../docs/examples/Pixmap_045.cpp", + "../docs/examples/Pixmap_046.cpp", + "../docs/examples/Point_000.cpp", + "../docs/examples/Point_001.cpp", + "../docs/examples/Point_002.cpp", + "../docs/examples/Point_003.cpp", + "../docs/examples/Point_004.cpp", + "../docs/examples/Point_005.cpp", + "../docs/examples/Point_006.cpp", + "../docs/examples/Point_007.cpp", + "../docs/examples/Point_008.cpp", + "../docs/examples/Point_009.cpp", + "../docs/examples/Point_010.cpp", + "../docs/examples/Point_011.cpp", + "../docs/examples/Point_012.cpp", + "../docs/examples/Point_013.cpp", + "../docs/examples/Point_014.cpp", + "../docs/examples/Point_015.cpp", + "../docs/examples/Point_016.cpp", + "../docs/examples/Point_017.cpp", + "../docs/examples/Point_018.cpp", + "../docs/examples/Point_019.cpp", + "../docs/examples/Point_020.cpp", + "../docs/examples/Point_021.cpp", + "../docs/examples/Point_022.cpp", + "../docs/examples/Point_023.cpp", + "../docs/examples/Point_024.cpp", + "../docs/examples/Point_025.cpp", + "../docs/examples/Point_026.cpp", + "../docs/examples/Point_027.cpp", + "../docs/examples/Point_028.cpp", + "../docs/examples/Point_029.cpp", + "../docs/examples/Point_030.cpp", + "../docs/examples/Point_031.cpp", + "../docs/examples/Point_032.cpp", + "../docs/examples/Point_033.cpp", + "../docs/examples/Point_034.cpp", + "../docs/examples/Point_035.cpp", + "../docs/examples/Point_036.cpp", + "../docs/examples/Point_037.cpp", + "../docs/examples/RRect_000.cpp", + "../docs/examples/RRect_001.cpp", + "../docs/examples/RRect_002.cpp", + "../docs/examples/RRect_003.cpp", + "../docs/examples/RRect_004.cpp", + "../docs/examples/RRect_005.cpp", + "../docs/examples/RRect_006.cpp", + "../docs/examples/RRect_007.cpp", + "../docs/examples/RRect_008.cpp", + "../docs/examples/RRect_009.cpp", + "../docs/examples/RRect_010.cpp", + "../docs/examples/RRect_011.cpp", + "../docs/examples/RRect_012.cpp", + "../docs/examples/RRect_013.cpp", + "../docs/examples/RRect_014.cpp", + "../docs/examples/RRect_015.cpp", + "../docs/examples/RRect_016.cpp", + "../docs/examples/RRect_017.cpp", + "../docs/examples/RRect_018.cpp", + "../docs/examples/RRect_019.cpp", + "../docs/examples/RRect_020.cpp", + "../docs/examples/RRect_021.cpp", + "../docs/examples/RRect_022.cpp", + "../docs/examples/RRect_023.cpp", + "../docs/examples/RRect_024.cpp", + "../docs/examples/RRect_025.cpp", + "../docs/examples/RRect_026.cpp", + "../docs/examples/RRect_027.cpp", + "../docs/examples/RRect_028.cpp", + "../docs/examples/RRect_029.cpp", + "../docs/examples/RRect_030.cpp", + "../docs/examples/RRect_031.cpp", + "../docs/examples/RRect_032.cpp", + "../docs/examples/RRect_033.cpp", + "../docs/examples/RRect_034.cpp", + "../docs/examples/RRect_035.cpp", + "../docs/examples/RRect_036.cpp", + "../docs/examples/RRect_037.cpp", + "../docs/examples/RRect_038.cpp", + "../docs/examples/RRect_039.cpp", + "../docs/examples/RRect_040.cpp", + "../docs/examples/RRect_041.cpp", + "../docs/examples/RRect_042.cpp", + "../docs/examples/RRect_043.cpp", + "../docs/examples/RRect_044.cpp", + "../docs/examples/Rect_000.cpp", + "../docs/examples/Rect_001.cpp", + "../docs/examples/Rect_002.cpp", + "../docs/examples/Rect_003.cpp", + "../docs/examples/Rect_004.cpp", + "../docs/examples/Rect_005.cpp", + "../docs/examples/Rect_006.cpp", + "../docs/examples/Rect_007.cpp", + "../docs/examples/Rect_008.cpp", + "../docs/examples/Rect_009.cpp", + "../docs/examples/Rect_010.cpp", + "../docs/examples/Rect_011.cpp", + "../docs/examples/Rect_012.cpp", + "../docs/examples/Rect_013.cpp", + "../docs/examples/Rect_014.cpp", + "../docs/examples/Rect_015.cpp", + "../docs/examples/Rect_016.cpp", + "../docs/examples/Rect_017.cpp", + "../docs/examples/Rect_018.cpp", + "../docs/examples/Rect_019.cpp", + "../docs/examples/Rect_020.cpp", + "../docs/examples/Rect_021.cpp", + "../docs/examples/Rect_022.cpp", + "../docs/examples/Rect_023.cpp", + "../docs/examples/Rect_024.cpp", + "../docs/examples/Rect_025.cpp", + "../docs/examples/Rect_026.cpp", + "../docs/examples/Rect_027.cpp", + "../docs/examples/Rect_028.cpp", + "../docs/examples/Rect_029.cpp", + "../docs/examples/Rect_030.cpp", + "../docs/examples/Rect_031.cpp", + "../docs/examples/Rect_032.cpp", + "../docs/examples/Rect_033.cpp", + "../docs/examples/Rect_034.cpp", + "../docs/examples/Rect_035.cpp", + "../docs/examples/Rect_036.cpp", + "../docs/examples/Rect_037.cpp", + "../docs/examples/Rect_038.cpp", + "../docs/examples/Rect_039.cpp", + "../docs/examples/Rect_040.cpp", + "../docs/examples/Rect_041.cpp", + "../docs/examples/Rect_042.cpp", + "../docs/examples/Rect_043.cpp", + "../docs/examples/Rect_044.cpp", + "../docs/examples/Rect_045.cpp", + "../docs/examples/Rect_046.cpp", + "../docs/examples/Rect_047.cpp", + "../docs/examples/Rect_048.cpp", + "../docs/examples/Rect_049.cpp", + "../docs/examples/Rect_050.cpp", + "../docs/examples/Rect_051.cpp", + "../docs/examples/Rect_052.cpp", + "../docs/examples/Rect_053.cpp", + "../docs/examples/Rect_054.cpp", + "../docs/examples/Rect_055.cpp", + "../docs/examples/Rect_056.cpp", + "../docs/examples/Rect_057.cpp", + "../docs/examples/Rect_058.cpp", + "../docs/examples/Rect_059.cpp", + "../docs/examples/Rect_060.cpp", + "../docs/examples/Rect_061.cpp", + "../docs/examples/Rect_062.cpp", + "../docs/examples/Rect_063.cpp", + "../docs/examples/Rect_064.cpp", + "../docs/examples/Rect_065.cpp", + "../docs/examples/Rect_066.cpp", + "../docs/examples/Rect_067.cpp", + "../docs/examples/Rect_068.cpp", + "../docs/examples/Rect_069.cpp", + "../docs/examples/Region_000.cpp", + "../docs/examples/Region_001.cpp", + "../docs/examples/Region_002.cpp", + "../docs/examples/Region_003.cpp", + "../docs/examples/Region_004.cpp", + "../docs/examples/Region_005.cpp", + "../docs/examples/Region_006.cpp", + "../docs/examples/Region_007.cpp", + "../docs/examples/Region_008.cpp", + "../docs/examples/Region_009.cpp", + "../docs/examples/Region_010.cpp", + "../docs/examples/Region_011.cpp", + "../docs/examples/Region_012.cpp", + "../docs/examples/Region_013.cpp", + "../docs/examples/Region_014.cpp", + "../docs/examples/Region_015.cpp", + "../docs/examples/Region_016.cpp", + "../docs/examples/Region_017.cpp", + "../docs/examples/Region_018.cpp", + "../docs/examples/Region_019.cpp", + "../docs/examples/Region_020.cpp", + "../docs/examples/Region_021.cpp", + "../docs/examples/Region_022.cpp", + "../docs/examples/Region_023.cpp", + "../docs/examples/Region_024.cpp", + "../docs/examples/Region_025.cpp", + "../docs/examples/Region_026.cpp", + "../docs/examples/Region_027.cpp", + "../docs/examples/Region_028.cpp", + "../docs/examples/Region_029.cpp", + "../docs/examples/Region_030.cpp", + "../docs/examples/Region_031.cpp", + "../docs/examples/Region_032.cpp", + "../docs/examples/Region_033.cpp", + "../docs/examples/Region_034.cpp", + "../docs/examples/Region_035.cpp", + "../docs/examples/Region_036.cpp", + "../docs/examples/Region_037.cpp", + "../docs/examples/Region_038.cpp", + "../docs/examples/Region_039.cpp", + "../docs/examples/Region_040.cpp", + "../docs/examples/Region_041.cpp", + "../docs/examples/Region_042.cpp", + "../docs/examples/Region_043.cpp", + "../docs/examples/Region_044.cpp", + "../docs/examples/Region_045.cpp", + "../docs/examples/Region_046.cpp", + "../docs/examples/Region_047.cpp", + "../docs/examples/Region_048.cpp", + "../docs/examples/Region_049.cpp", + "../docs/examples/Region_050.cpp", + "../docs/examples/Region_051.cpp", + "../docs/examples/Region_052.cpp", + "../docs/examples/Region_053.cpp", + "../docs/examples/Region_054.cpp", + "../docs/examples/Surface_000.cpp", + "../docs/examples/Surface_001.cpp", + "../docs/examples/Surface_002.cpp", + "../docs/examples/Surface_003.cpp", + "../docs/examples/Surface_004.cpp", + "../docs/examples/Surface_005.cpp", + "../docs/examples/Surface_006.cpp", + "../docs/examples/Surface_007.cpp", + "../docs/examples/Surface_008.cpp", + "../docs/examples/Surface_009.cpp", + "../docs/examples/Surface_010.cpp", + "../docs/examples/Surface_011.cpp", + "../docs/examples/Surface_012.cpp", + "../docs/examples/Surface_013.cpp", + "../docs/examples/Surface_014.cpp", + "../docs/examples/Surface_015.cpp", + "../docs/examples/Surface_016.cpp", + "../docs/examples/Surface_017.cpp", + "../docs/examples/Surface_018.cpp", + "../docs/examples/Surface_019.cpp", + "../docs/examples/Surface_020.cpp", + "../docs/examples/Surface_021.cpp", + "../docs/examples/Surface_022.cpp", + "../docs/examples/Surface_023.cpp", + "../docs/examples/Surface_024.cpp", + "../docs/examples/Surface_025.cpp", + "../docs/examples/Surface_026.cpp", + "../docs/examples/Surface_027.cpp", + "../docs/examples/Surface_028.cpp", + "../docs/examples/TextBlobBuilder_000.cpp", + "../docs/examples/TextBlobBuilder_001.cpp", + "../docs/examples/TextBlobBuilder_002.cpp", + "../docs/examples/TextBlobBuilder_003.cpp", + "../docs/examples/TextBlobBuilder_004.cpp", + "../docs/examples/TextBlob_000.cpp", + "../docs/examples/TextBlob_001.cpp", + "../docs/examples/TextBlob_002.cpp", + "../docs/examples/TextBlob_003.cpp", + "../docs/examples/TextBlob_004.cpp", + "../docs/examples/TextBlob_005.cpp", + "../docs/examples/TextBlob_006.cpp", + "../docs/examples/TextBlob_007.cpp", +], "abspath") diff --git a/gn/make_examples_gni.py b/gn/make_examples_gni.py new file mode 100755 index 0000000000..2fa2e97641 --- /dev/null +++ b/gn/make_examples_gni.py @@ -0,0 +1,19 @@ +#! /usr/bin/env python +# Copyright 2019 Google LLC. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +import glob +import os +head = '''# Copyright 2019 Google LLC. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. +''' +def gni(path, name, files): + with open(path, 'w') as o: + o.write('%s\n%s = get_path_info([\n' % (head, name)) + for x in sorted(files): + o.write(' "%s",\n' % x) + o.write('], "abspath")\n') +if __name__ == '__main__': + os.chdir(os.path.dirname(__file__)) + gni('examples.gni', 'examples_sources', glob.glob('../docs/examples/*.cpp')) diff --git a/resources/images/example_1.png b/resources/images/example_1.png new file mode 100644 index 0000000000..6608834acb Binary files /dev/null and b/resources/images/example_1.png differ diff --git a/resources/images/example_2.png b/resources/images/example_2.png new file mode 100644 index 0000000000..85428dcc18 Binary files /dev/null and b/resources/images/example_2.png differ diff --git a/resources/images/example_3.png b/resources/images/example_3.png new file mode 100644 index 0000000000..188cae51b5 Binary files /dev/null and b/resources/images/example_3.png differ diff --git a/resources/images/example_4.png b/resources/images/example_4.png new file mode 100644 index 0000000000..9a16234920 Binary files /dev/null and b/resources/images/example_4.png differ diff --git a/resources/images/example_5.png b/resources/images/example_5.png new file mode 100644 index 0000000000..a8e58cc67f Binary files /dev/null and b/resources/images/example_5.png differ diff --git a/resources/images/example_6.png b/resources/images/example_6.png new file mode 100644 index 0000000000..2eea6a7464 Binary files /dev/null and b/resources/images/example_6.png differ diff --git a/tools/fiddle/examples.cpp b/tools/fiddle/examples.cpp new file mode 100644 index 0000000000..d5cd06703c --- /dev/null +++ b/tools/fiddle/examples.cpp @@ -0,0 +1,37 @@ +// 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 "examples.h" + +template sk_tools::Registry* sk_tools::Registry::gHead; + +// These globals are needed by fiddles: +GrBackendTexture backEndTexture; +GrBackendRenderTarget backEndRenderTarget; +GrBackendTexture backEndTextureRenderTarget; +SkBitmap source; +sk_sp image; +double duration = 1.0; +double frame = 1.0; + +int main() { + constexpr int kImgCount = 7; + sk_sp images[kImgCount]; + SkBitmap bitmaps[kImgCount]; + for (int i = 1; i < kImgCount; ++i) { + SkString path = SkStringPrintf("resources/images/example_%d.png", i); + images[i] = SkImage::MakeFromEncoded(SkData::MakeFromFileName(path.c_str())); + SkAssertResult(images[i] && images[i]->asLegacyBitmap(&bitmaps[i])); + } + for (const fiddle::Example& example : sk_tools::Registry::Range()) { + SkASSERT((unsigned)example.fImageIndex < (unsigned)kImgCount); + image = images[example.fImageIndex]; + source = bitmaps[example.fImageIndex]; + SkBitmap bmp; + bmp.allocN32Pixels(example.fWidth, example.fHeight); + bmp.eraseColor(SK_ColorWHITE); + SkCanvas canvas(bmp); + SkDebugf("==> %s\n", example.fName); + example.fFunc(&canvas); + } +} diff --git a/tools/fiddle/examples.h b/tools/fiddle/examples.h new file mode 100644 index 0000000000..70927b8f87 --- /dev/null +++ b/tools/fiddle/examples.h @@ -0,0 +1,41 @@ +// Copyright 2019 Google LLC. +// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. +#ifndef examples_DEFINED +#define examples_DEFINED + +#include "Registry.h" +#include "skia.h" + +#include +#include + +namespace fiddle { +struct Example { + void (*fFunc)(SkCanvas*); + const char* fName; + int fImageIndex; + int fWidth; + int fHeight; + bool fText; + bool fSRGB; + bool fF16; + bool fAnimation; + bool fOffscreen; +}; +} + +extern GrBackendTexture backEndTexture; +extern GrBackendRenderTarget backEndRenderTarget; +extern GrBackendTexture backEndTextureRenderTarget; +extern SkBitmap source; +extern sk_sp image; +extern double duration; // The total duration of the animation in seconds. +extern double frame; // A value in [0, 1] of where we are in the animation. + +#define REG_FIDDLE(NAME, W, H, TEXT, I) \ + namespace example_##NAME { void draw(SkCanvas*); } \ + sk_tools::Registry reg_##NAME( \ + fiddle::Example{&example_##NAME::draw, #NAME, I, W, H, TEXT, false, false, false, false}); \ + namespace example_##NAME + +#endif // examples_DEFINED