1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 // SkTestCanvas is a simple way to make a testing canvas which is allowed to use private 9 // facilities of SkCanvas without having to add a friend to SkCanvas.h. 10 // 11 // You create a Key (a simple empty struct) to make a template specialization class. You need to 12 // make a key for each of the different Canvases you need. The implementations of the canvases 13 // are in SkCanvas.cpp, which allows the use of helper classes. 14 15 #ifndef SkTestCanvas_DEFINED 16 #define SkTestCanvas_DEFINED 17 18 #include "include/core/SkSize.h" 19 #include "include/private/chromium/SkChromeRemoteGlyphCache.h" 20 #include "include/utils/SkNWayCanvas.h" 21 #include "src/core/SkDevice.h" 22 #include "src/text/GlyphRun.h" 23 24 // You can only make template specializations of SkTestCanvas. 25 template <typename Key> class SkTestCanvas; 26 27 // A test canvas to test using slug rendering instead of text blob rendering. 28 struct SkSlugTestKey {}; 29 template <> 30 class SkTestCanvas<SkSlugTestKey> : public SkCanvas { 31 public: 32 SkTestCanvas(SkCanvas* canvas); 33 void onDrawGlyphRunList( 34 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override; 35 }; 36 37 struct SkSerializeSlugTestKey {}; 38 template <> 39 class SkTestCanvas<SkSerializeSlugTestKey> : public SkCanvas { 40 public: 41 SkTestCanvas(SkCanvas* canvas); 42 void onDrawGlyphRunList( 43 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override; 44 }; 45 46 struct SkRemoteSlugTestKey {}; 47 template <> 48 class SkTestCanvas<SkRemoteSlugTestKey> : public SkCanvas { 49 public: 50 SkTestCanvas(SkCanvas* canvas); 51 ~SkTestCanvas() override; 52 void onDrawGlyphRunList( 53 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override; 54 55 private: 56 std::unique_ptr<SkStrikeServer::DiscardableHandleManager> fServerHandleManager; 57 sk_sp<SkStrikeClient::DiscardableHandleManager> fClientHandleManager; 58 SkStrikeServer fStrikeServer; 59 SkStrikeClient fStrikeClient; 60 }; 61 62 #endif // SkTestCanvas_DEFINED 63