xref: /aosp_15_r20/external/skia/src/text/gpu/SlugImpl.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2023 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 #ifndef sktext_SlugImpl_DEFINED
8 #define sktext_SlugImpl_DEFINED
9 
10 #include "include/core/SkPoint.h"
11 #include "include/core/SkRect.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/private/base/SkAssert.h"
14 #include "include/private/chromium/Slug.h"
15 #include "src/text/gpu/SubRunAllocator.h"
16 #include "src/text/gpu/SubRunContainer.h"
17 
18 #include <cstddef>
19 
20 class SkMatrix;
21 class SkPaint;
22 class SkReadBuffer;
23 class SkStrikeClient;
24 class SkWriteBuffer;
25 struct SkStrikeDeviceInfo;
26 
27 namespace sktext {
28 class GlyphRunList;
29 class StrikeForGPUCacheInterface;
30 }
31 
32 namespace sktext::gpu {
33 
34 class SlugImpl final : public Slug {
35 public:
36     SlugImpl(SubRunAllocator&& alloc,
37              gpu::SubRunContainerOwner subRuns,
38              SkRect sourceBounds,
39              SkPoint origin);
40     ~SlugImpl() override = default;
41 
42     static sk_sp<SlugImpl> Make(const SkMatrix& viewMatrix,
43                                 const sktext::GlyphRunList& glyphRunList,
44                                 const SkPaint& paint,
45                                 SkStrikeDeviceInfo strikeDeviceInfo,
46                                 sktext::StrikeForGPUCacheInterface* strikeCache);
47     static sk_sp<Slug> MakeFromBuffer(SkReadBuffer& buffer,
48                                       const SkStrikeClient* client);
49     void doFlatten(SkWriteBuffer& buffer) const override;
50 
sourceBounds()51     SkRect sourceBounds() const override { return fSourceBounds; }
sourceBoundsWithOrigin()52     SkRect sourceBoundsWithOrigin() const override { return fSourceBounds.makeOffset(fOrigin); }
53 
initialPositionMatrix()54     const SkMatrix& initialPositionMatrix() const { return fSubRuns->initialPosition(); }
origin()55     SkPoint origin() const { return fOrigin; }
56 
subRuns()57     const gpu::SubRunContainerOwner& subRuns() const { return fSubRuns; }
58 
59     // Change memory management to handle the data after Slug, but in the same allocation
60     // of memory. Only allow placement new.
delete(void * p)61     void operator delete(void* p) { ::operator delete(p); }
new(size_t)62     void* operator new(size_t) { SK_ABORT("All slugs are created by placement new."); }
new(size_t,void * p)63     void* operator new(size_t, void* p) { return p; }
64 
65 private:
66     // The allocator must come first because it needs to be destroyed last. Other fields of this
67     // structure may have pointers into it.
68     SubRunAllocator fAlloc;
69     gpu::SubRunContainerOwner fSubRuns;
70     const SkRect fSourceBounds;
71     const SkPoint fOrigin;
72 };
73 
74 }  // namespace sktext::gpu
75 
76 #endif
77