xref: /aosp_15_r20/external/skia/tools/gpu/TestCanvas.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 // TestCanvas 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 TestCanvas_DEFINED
16 #define TestCanvas_DEFINED
17 
18 #include "include/core/SkCanvas.h"
19 #include "include/core/SkRefCnt.h"
20 #include "include/private/chromium/SkChromeRemoteGlyphCache.h"
21 
22 #include <memory>
23 
24 class SkPaint;
25 
26 namespace sktext { class GlyphRunList; }
27 
28 namespace skiatest {
29 
30 // You can only make template specializations of TestCanvas.
31 template <typename Key> class TestCanvas;
32 
33 // A test canvas to test using slug rendering instead of text blob rendering.
34 struct SkSlugTestKey {};
35 template <>
36 class TestCanvas<SkSlugTestKey> : public SkCanvas {
37 public:
38     TestCanvas(SkCanvas* canvas);
39     void onDrawGlyphRunList(
40             const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override;
41 };
42 
43 struct SkSerializeSlugTestKey {};
44 template <>
45 class TestCanvas<SkSerializeSlugTestKey> : public SkCanvas {
46 public:
47     TestCanvas(SkCanvas* canvas);
48     void onDrawGlyphRunList(
49             const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override;
50 };
51 
52 struct SkRemoteSlugTestKey {};
53 template <>
54 class TestCanvas<SkRemoteSlugTestKey> : public SkCanvas {
55 public:
56     TestCanvas(SkCanvas* canvas);
57     ~TestCanvas() override;
58     void onDrawGlyphRunList(
59             const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override;
60 
61 private:
62     std::unique_ptr<SkStrikeServer::DiscardableHandleManager> fServerHandleManager;
63     sk_sp<SkStrikeClient::DiscardableHandleManager> fClientHandleManager;
64     SkStrikeServer fStrikeServer;
65     SkStrikeClient fStrikeClient;
66 };
67 
68 }  // namespace skiatest
69 
70 #endif  // TestCanvas_DEFINED
71