/src/skia/src/core/SkCanvasPriv.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2018 Google Inc. |
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 | | #include "src/core/SkCanvasPriv.h" |
9 | | |
10 | | #include "src/core/SkAutoMalloc.h" |
11 | | #include "src/core/SkDevice.h" |
12 | | #include "src/core/SkReadBuffer.h" |
13 | | #include "src/core/SkWriter32.h" |
14 | | |
15 | | #include <locale> |
16 | | |
17 | | SkAutoCanvasMatrixPaint::SkAutoCanvasMatrixPaint(SkCanvas* canvas, const SkMatrix* matrix, |
18 | | const SkPaint* paint, const SkRect& bounds) |
19 | | : fCanvas(canvas) |
20 | 95.1k | , fSaveCount(canvas->getSaveCount()) { |
21 | 95.1k | if (paint) { |
22 | 6.05k | SkRect newBounds = bounds; |
23 | 6.05k | if (matrix) { |
24 | 219 | matrix->mapRect(&newBounds); |
25 | 219 | } |
26 | 6.05k | canvas->saveLayer(&newBounds, paint); |
27 | 89.0k | } else if (matrix) { |
28 | 2.59k | canvas->save(); |
29 | 2.59k | } |
30 | | |
31 | 95.1k | if (matrix) { |
32 | 2.81k | canvas->concat(*matrix); |
33 | 2.81k | } |
34 | 95.1k | } |
35 | | |
36 | 95.1k | SkAutoCanvasMatrixPaint::~SkAutoCanvasMatrixPaint() { |
37 | 95.1k | fCanvas->restoreToCount(fSaveCount); |
38 | 95.1k | } |
39 | | |
40 | | /////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | | |
42 | 0 | bool SkCanvasPriv::ReadLattice(SkReadBuffer& buffer, SkCanvas::Lattice* lattice) { |
43 | 0 | lattice->fXCount = buffer.readInt(); |
44 | 0 | lattice->fXDivs = buffer.skipT<int32_t>(lattice->fXCount); |
45 | 0 | lattice->fYCount = buffer.readInt(); |
46 | 0 | lattice->fYDivs = buffer.skipT<int32_t>(lattice->fYCount); |
47 | 0 | int flagCount = buffer.readInt(); |
48 | 0 | lattice->fRectTypes = nullptr; |
49 | 0 | lattice->fColors = nullptr; |
50 | 0 | if (flagCount) { |
51 | 0 | lattice->fRectTypes = buffer.skipT<SkCanvas::Lattice::RectType>(flagCount); |
52 | 0 | lattice->fColors = buffer.skipT<SkColor>(flagCount); |
53 | 0 | } |
54 | 0 | lattice->fBounds = buffer.skipT<SkIRect>(); |
55 | 0 | return buffer.isValid(); |
56 | 0 | } |
57 | | |
58 | 0 | size_t SkCanvasPriv::WriteLattice(void* buffer, const SkCanvas::Lattice& lattice) { |
59 | 0 | int flagCount = lattice.fRectTypes ? (lattice.fXCount + 1) * (lattice.fYCount + 1) : 0; |
60 | |
|
61 | 0 | const size_t size = (1 + lattice.fXCount + 1 + lattice.fYCount + 1) * sizeof(int32_t) + |
62 | 0 | SkAlign4(flagCount * sizeof(SkCanvas::Lattice::RectType)) + |
63 | 0 | SkAlign4(flagCount * sizeof(SkColor)) + |
64 | 0 | sizeof(SkIRect); |
65 | |
|
66 | 0 | if (buffer) { |
67 | 0 | SkWriter32 writer(buffer, size); |
68 | 0 | writer.write32(lattice.fXCount); |
69 | 0 | writer.write(lattice.fXDivs, lattice.fXCount * sizeof(uint32_t)); |
70 | 0 | writer.write32(lattice.fYCount); |
71 | 0 | writer.write(lattice.fYDivs, lattice.fYCount * sizeof(uint32_t)); |
72 | 0 | writer.write32(flagCount); |
73 | 0 | writer.writePad(lattice.fRectTypes, flagCount * sizeof(uint8_t)); |
74 | 0 | writer.write(lattice.fColors, flagCount * sizeof(SkColor)); |
75 | 0 | SkASSERT(lattice.fBounds); |
76 | 0 | writer.write(lattice.fBounds, sizeof(SkIRect)); |
77 | 0 | SkASSERT(writer.bytesWritten() == size); |
78 | 0 | } |
79 | 0 | return size; |
80 | 0 | }; Unexecuted instantiation: SkCanvasPriv::WriteLattice(void*, SkCanvas::Lattice const&) Unexecuted instantiation: SkCanvasPriv::WriteLattice(void*, SkCanvas::Lattice const&) |
81 | | |
82 | 0 | void SkCanvasPriv::WriteLattice(SkWriteBuffer& buffer, const SkCanvas::Lattice& lattice) { |
83 | 0 | const size_t size = WriteLattice(nullptr, lattice); |
84 | 0 | SkAutoSMalloc<1024> storage(size); |
85 | 0 | WriteLattice(storage.get(), lattice); |
86 | 0 | buffer.writePad32(storage.get(), size); |
87 | 0 | } |
88 | | |
89 | | void SkCanvasPriv::GetDstClipAndMatrixCounts(const SkCanvas::ImageSetEntry set[], int count, |
90 | 1 | int* totalDstClipCount, int* totalMatrixCount) { |
91 | 1 | int dstClipCount = 0; |
92 | 1 | int maxMatrixIndex = -1; |
93 | 1 | for (int i = 0; i < count; ++i) { |
94 | 0 | dstClipCount += 4 * set[i].fHasClip; |
95 | 0 | if (set[i].fMatrixIndex > maxMatrixIndex) { |
96 | 0 | maxMatrixIndex = set[i].fMatrixIndex; |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | 1 | *totalDstClipCount = dstClipCount; |
101 | 1 | *totalMatrixCount = maxMatrixIndex + 1; |
102 | 1 | } |
103 | | |
104 | 0 | bool SkCanvasPriv::ValidateMarker(const char* name) { |
105 | 0 | if (!name) { |
106 | 0 | return false; |
107 | 0 | } |
108 | | |
109 | 0 | std::locale loc(std::locale::classic()); |
110 | 0 | if (!std::isalpha(*name, loc)) { |
111 | 0 | return false; |
112 | 0 | } |
113 | 0 | while (*(++name)) { |
114 | 0 | if (!std::isalnum(*name, loc) && *name != '_') { |
115 | 0 | return false; |
116 | 0 | } |
117 | 0 | } |
118 | 0 | return true; |
119 | 0 | } |
120 | | |
121 | | #if GR_TEST_UTILS |
122 | | |
123 | | #if SK_SUPPORT_GPU |
124 | | #include "src/gpu/BaseDevice.h" |
125 | | |
126 | | #if SK_GPU_V1 |
127 | 0 | skgpu::v1::SurfaceDrawContext* SkCanvasPriv::TopDeviceSurfaceDrawContext(SkCanvas* canvas) { |
128 | 0 | if (auto gpuDevice = canvas->topDevice()->asGpuDevice()) { |
129 | 0 | return gpuDevice->surfaceDrawContext(); |
130 | 0 | } |
131 | | |
132 | 0 | return nullptr; |
133 | 0 | } |
134 | | #endif // SK_GPU_V1 |
135 | | |
136 | 0 | skgpu::SurfaceFillContext* SkCanvasPriv::TopDeviceSurfaceFillContext(SkCanvas* canvas) { |
137 | 0 | if (auto gpuDevice = canvas->topDevice()->asGpuDevice()) { |
138 | 0 | return gpuDevice->surfaceFillContext(); |
139 | 0 | } |
140 | | |
141 | 0 | return nullptr; |
142 | 0 | } |
143 | | |
144 | | #else // SK_SUPPORT_GPU |
145 | | |
146 | | #if SK_GPU_V1 |
147 | | skgpu::v1::SurfaceDrawContext* SkCanvasPriv::TopDeviceSurfaceDrawContext(SkCanvas* canvas) { |
148 | | return nullptr; |
149 | | } |
150 | | #endif // SK_GPU_V1 |
151 | | |
152 | | skgpu::SurfaceFillContext* SkCanvasPriv::TopDeviceSurfaceFillContext(SkCanvas* canvas) { |
153 | | return nullptr; |
154 | | } |
155 | | |
156 | | #endif // SK_SUPPORT_GPU |
157 | | |
158 | | #endif // GR_TEST_UTILS |
159 | | |
160 | | #if SK_SUPPORT_GPU |
161 | | #include "src/gpu/BaseDevice.h" |
162 | | |
163 | 0 | GrRenderTargetProxy* SkCanvasPriv::TopDeviceTargetProxy(SkCanvas* canvas) { |
164 | 0 | if (auto gpuDevice = canvas->topDevice()->asGpuDevice()) { |
165 | 0 | return gpuDevice->targetProxy(); |
166 | 0 | } |
167 | | |
168 | 0 | return nullptr; |
169 | 0 | } |
170 | | |
171 | | #else // SK_SUPPORT_GPU |
172 | | |
173 | | GrRenderTargetProxy* SkCanvasPriv::TopDeviceTargetProxy(SkCanvas* canvas) { |
174 | | return nullptr; |
175 | | } |
176 | | |
177 | | #endif // SK_SUPPORT_GPU |