Flutter Engine
The Flutter Engine
RasterPathAtlas.cpp
Go to the documentation of this file.
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
9
12#include "src/core/SkIPoint16.h"
18
19namespace skgpu::graphite {
20
21static constexpr uint32_t kDefaultAtlasDim = 4096;
22
23static constexpr uint32_t kSmallPathPlotWidth = 512;
24static constexpr uint32_t kSmallPathPlotHeight = 256;
25
28 , fCachedAtlasMgr(fWidth, fHeight, fWidth, fHeight, recorder->priv().caps())
29 , fSmallPathAtlasMgr(std::max(fWidth/2, kSmallPathPlotWidth),
30 std::max(fHeight/2, kSmallPathPlotHeight),
32 recorder->priv().caps())
33 , fUncachedAtlasMgr(fWidth, fHeight, fWidth, fHeight, recorder->priv().caps()) {
34 SkASSERT(recorder);
35}
36
38 fCachedAtlasMgr.recordUploads(dc, fRecorder);
39 fSmallPathAtlasMgr.recordUploads(dc, fRecorder);
40 fUncachedAtlasMgr.recordUploads(dc, fRecorder);
41}
42
44 const Transform& transform,
45 const SkStrokeRec& strokeRec,
46 skvx::half2 maskSize,
47 skvx::half2* outPos) {
48 skgpu::UniqueKey maskKey;
49 bool hasKey = shape.hasKey();
50 if (hasKey) {
51 constexpr int kMaxSmallPathSize = 162;
52 // Try to locate or add to cached DrawAtlas
53 const TextureProxy* proxy = nullptr;
54 if (maskSize.x() <= kMaxSmallPathSize && maskSize.y() <= kMaxSmallPathSize) {
55 proxy = fSmallPathAtlasMgr.findOrCreateEntry(fRecorder,
56 shape,
58 strokeRec,
59 maskSize,
60 outPos);
61 }
62 if (!proxy) {
63 proxy = fCachedAtlasMgr.findOrCreateEntry(fRecorder,
64 shape,
66 strokeRec,
67 maskSize,
68 outPos);
69 }
70 if (proxy) {
71 return proxy;
72 }
73 }
74
75 // try to add to uncached DrawAtlas
76 AtlasLocator loc;
77 return fUncachedAtlasMgr.addToAtlas(fRecorder,
78 shape,
80 strokeRec,
81 maskSize,
82 outPos,
83 &loc);
84}
85
86/////////////////////////////////////////////////////////////////////////////////////////
87
88bool RasterPathAtlas::RasterAtlasMgr::onAddToAtlas(const Shape& shape,
89 const Transform& transform,
90 const SkStrokeRec& strokeRec,
91 SkIRect shapeBounds,
92 const AtlasLocator& locator) {
93 // Rasterize path to backing pixmap.
94 // This pixmap will be the size of the Plot that contains the given rect, not the entire atlas,
95 // and hence the position we render at will be relative to that Plot.
96 // The value of outPos is relative to the entire texture, to be used for texture coords.
98 SkIPoint renderPos = fDrawAtlas->prepForRender(locator, &dst);
99
100 RasterMaskHelper helper(&dst);
101 if (!helper.init(fDrawAtlas->plotSize())) {
102 return false;
103 }
104 // Offset to plot location and draw
105 shapeBounds.offset(renderPos.x()+kEntryPadding, renderPos.y()+kEntryPadding);
106 helper.drawShape(shape, transform, strokeRec, shapeBounds);
107
108 return true;
109}
110
111} // namespace skgpu::graphite
#define SkASSERT(cond)
Definition: SkAssert.h:116
const TextureProxy * onAddShape(const Shape &, const Transform &transform, const SkStrokeRec &, skvx::half2 maskSize, skvx::half2 *outPos) override
bool hasKey() const
Definition: Shape.h:159
FlPixelBufferTexturePrivate * priv
static float max(float r, float g, float b)
Definition: hsl.cpp:49
dst
Definition: cp.py:12
static constexpr uint32_t kSmallPathPlotWidth
static constexpr uint32_t kDefaultAtlasDim
static constexpr uint32_t kSmallPathPlotHeight
Definition: ref_ptr.h:256
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
constexpr int32_t y() const
Definition: SkPoint_impl.h:52
constexpr int32_t x() const
Definition: SkPoint_impl.h:46
Definition: SkRect.h:32
void offset(int32_t dx, int32_t dy)
Definition: SkRect.h:367
Definition: SkVx.h:83