Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: src/pipe/SkGPipePriv.h

Issue 1568883003: remove SkGPipe (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « samplecode/SampleCode.h ('k') | src/pipe/SkGPipeRead.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1
2 /*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10
11 #ifndef SkGPipePriv_DEFINED
12 #define SkGPipePriv_DEFINED
13
14 #include "SkTypes.h"
15
16 #define UNIMPLEMENTED
17
18 // these must be contiguous, 0...N-1
19 enum PaintFlats {
20 kColorFilter_PaintFlat,
21 kDrawLooper_PaintFlat,
22 kImageFilter_PaintFlat,
23 kMaskFilter_PaintFlat,
24 kPathEffect_PaintFlat,
25 kRasterizer_PaintFlat,
26 kShader_PaintFlat,
27 kXfermode_PaintFlat,
28
29 kLast_PaintFlat = kXfermode_PaintFlat
30 };
31 #define kCount_PaintFlats (kLast_PaintFlat + 1)
32
33 enum DrawOps {
34 kSkip_DrawOp, // skip an addition N bytes (N == data)
35
36 // these match Canvas apis
37 kClipPath_DrawOp,
38 kClipRegion_DrawOp,
39 kClipRect_DrawOp,
40 kClipRRect_DrawOp,
41 kConcat_DrawOp,
42 kDrawAtlas_DrawOp,
43 kDrawBitmap_DrawOp,
44 kDrawBitmapNine_DrawOp,
45 kDrawBitmapRect_DrawOp,
46 kDrawDRRect_DrawOp,
47 kDrawImage_DrawOp,
48 kDrawImageRect_DrawOp,
49 kDrawImageNine_DrawOp,
50 kDrawOval_DrawOp,
51 kDrawPaint_DrawOp,
52 kDrawPatch_DrawOp,
53 kDrawPath_DrawOp,
54 kDrawPicture_DrawOp,
55 kDrawPoints_DrawOp,
56 kDrawPosText_DrawOp,
57 kDrawPosTextH_DrawOp,
58 kDrawRect_DrawOp,
59 kDrawRRect_DrawOp,
60 kDrawText_DrawOp,
61 kDrawTextBlob_DrawOp,
62 kDrawTextOnPath_DrawOp,
63 kDrawVertices_DrawOp,
64 kRestore_DrawOp,
65 kRotate_DrawOp,
66 kSave_DrawOp,
67 kSaveLayer_DrawOp,
68 kScale_DrawOp,
69 kSetMatrix_DrawOp,
70 kSkew_DrawOp,
71 kTranslate_DrawOp,
72
73 kPaintOp_DrawOp,
74 kSetTypeface_DrawOp,
75 kSetAnnotation_DrawOp,
76
77 kDef_Typeface_DrawOp,
78 kDef_Flattenable_DrawOp,
79 kDef_Bitmap_DrawOp,
80 kDef_Factory_DrawOp,
81
82 // these are signals to playback, not drawing verbs
83 kReportFlags_DrawOp,
84 kShareBitmapHeap_DrawOp,
85 kShareImageHeap_DrawOp,
86 kDone_DrawOp,
87 };
88
89 /**
90 * DrawOp packs into a 32bit int as follows
91 *
92 * DrawOp:8 - Flags:4 - Data:20
93 *
94 * Flags and Data are called out separately, so we can reuse Data between
95 * different Ops that might have different Flags. e.g. Data might be a Paint
96 * index for both drawRect (no flags) and saveLayer (does have flags).
97 *
98 * All Ops that take a SkPaint use their Data field to store the index to
99 * the paint (previously defined with kPaintOp_DrawOp).
100 */
101
102 #define DRAWOPS_OP_BITS 8
103 #define DRAWOPS_FLAG_BITS 4
104 #define DRAWOPS_DATA_BITS 20
105
106 #define DRAWOPS_OP_MASK ((1 << DRAWOPS_OP_BITS) - 1)
107 #define DRAWOPS_FLAG_MASK ((1 << DRAWOPS_FLAG_BITS) - 1)
108 #define DRAWOPS_DATA_MASK ((1 << DRAWOPS_DATA_BITS) - 1)
109
110 static inline unsigned DrawOp_unpackOp(uint32_t op32) {
111 return (op32 >> (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS));
112 }
113
114 static inline unsigned DrawOp_unpackFlags(uint32_t op32) {
115 return (op32 >> DRAWOPS_DATA_BITS) & DRAWOPS_FLAG_MASK;
116 }
117
118 static inline unsigned DrawOp_unpackData(uint32_t op32) {
119 return op32 & DRAWOPS_DATA_MASK;
120 }
121
122 static inline uint32_t DrawOp_packOpFlagData(DrawOps op, unsigned flags, unsigne d data) {
123 SkASSERT(0 == (op & ~DRAWOPS_OP_MASK));
124 SkASSERT(0 == (flags & ~DRAWOPS_FLAG_MASK));
125 SkASSERT(0 == (data & ~DRAWOPS_DATA_MASK));
126
127 return (op << (DRAWOPS_FLAG_BITS + DRAWOPS_DATA_BITS)) |
128 (flags << DRAWOPS_DATA_BITS) |
129 data;
130 }
131
132 /** DrawOp specific flag bits
133 */
134
135 enum {
136 kSaveLayer_HasBounds_DrawOpFlag = 1 << 0,
137 kSaveLayer_HasPaint_DrawOpFlag = 1 << 1,
138 };
139 enum {
140 kDrawTextOnPath_HasMatrix_DrawOpFlag = 1 << 0
141 };
142 enum {
143 kDrawVertices_HasTexs_DrawOpFlag = 1 << 0,
144 kDrawVertices_HasColors_DrawOpFlag = 1 << 1,
145 kDrawVertices_HasIndices_DrawOpFlag = 1 << 2,
146 kDrawVertices_HasXfermode_DrawOpFlag = 1 << 3,
147 };
148 enum {
149 kDrawAtlas_HasPaint_DrawOpFlag = 1 << 0,
150 kDrawAtlas_HasColors_DrawOpFlag = 1 << 1,
151 kDrawAtlas_HasCull_DrawOpFlag = 1 << 2,
152 };
153 // These are shared between drawbitmap and drawimage
154 enum {
155 kDrawBitmap_HasPaint_DrawOpFlag = 1 << 0,
156 // Specific to drawBitmapRect, but needs to be different from HasPaint,
157 // which is used for all drawBitmap calls, so include it here.
158 kDrawBitmap_HasSrcRect_DrawOpFlag = 1 << 1,
159 // SkCanvas::DrawBitmapRectFlags::kBleed_DrawBitmapRectFlag is
160 // converted into and out of this flag to save space
161 kDrawBitmap_Bleed_DrawOpFlag = 1 << 2,
162 };
163 enum {
164 kClip_HasAntiAlias_DrawOpFlag = 1 << 0,
165 };
166 ///////////////////////////////////////////////////////////////////////////////
167
168 class BitmapInfo : SkNoncopyable {
169 public:
170 BitmapInfo(SkBitmap* bitmap, uint32_t genID, int toBeDrawnCount)
171 : fBitmap(bitmap)
172 , fGenID(genID)
173 , fBytesAllocated(0)
174 , fMoreRecentlyUsed(nullptr)
175 , fLessRecentlyUsed(nullptr)
176 , fToBeDrawnCount(toBeDrawnCount)
177 {}
178
179 ~BitmapInfo() {
180 SkASSERT(0 == fToBeDrawnCount);
181 delete fBitmap;
182 }
183
184 void addDraws(int drawsToAdd) {
185 if (0 == fToBeDrawnCount) {
186 // The readers will only ever decrement the count, so once the
187 // count is zero, the writer will be the only one modifying it,
188 // so it does not need to be an atomic operation.
189 fToBeDrawnCount = drawsToAdd;
190 } else {
191 sk_atomic_add(&fToBeDrawnCount, drawsToAdd);
192 }
193 }
194
195 void decDraws() {
196 sk_atomic_dec(&fToBeDrawnCount);
197 }
198
199 int drawCount() const {
200 return fToBeDrawnCount;
201 }
202
203 SkBitmap* fBitmap;
204 // Store the generation ID of the original bitmap, since copying does
205 // not copy this field, so fBitmap's generation ID will not be useful
206 // for comparing.
207 // FIXME: Is it reasonable to make copying a bitmap/pixelref copy the
208 // generation ID?
209 uint32_t fGenID;
210 // Keep track of the bytes allocated for this bitmap. When replacing the
211 // bitmap or removing this BitmapInfo we know how much memory has been
212 // reclaimed.
213 size_t fBytesAllocated;
214 // TODO: Generalize the LRU caching mechanism
215 BitmapInfo* fMoreRecentlyUsed;
216 BitmapInfo* fLessRecentlyUsed;
217 private:
218 int fToBeDrawnCount;
219 };
220
221 static inline bool shouldFlattenBitmaps(uint32_t flags) {
222 return SkToBool(flags & SkGPipeWriter::kCrossProcess_Flag
223 && !(flags & SkGPipeWriter::kSharedAddressSpace_Flag));
224 }
225
226 class SkImageHeap : public SkRefCnt {
227 public:
228 SkImageHeap();
229 virtual ~SkImageHeap();
230
231 size_t bytesInCache() const { return fBytesInCache; }
232 void reset();
233 // slot must be "valid" -- 0 is never valid
234 const SkImage* get(int32_t slot) const;
235 // returns 0 if not found, else returns slot
236 int32_t find(const SkImage*) const;
237 // returns non-zero value for where the image was stored
238 int32_t insert(const SkImage*);
239
240 private:
241 SkTDArray<const SkImage*> fArray;
242 size_t fBytesInCache;
243 };
244
245 ///////////////////////////////////////////////////////////////////////////////
246
247 enum PaintOps {
248 kReset_PaintOp, // no arg
249
250 kFlags_PaintOp, // arg inline
251 kColor_PaintOp, // arg 32
252 kFilterLevel_PaintOp, // arg inline
253 kStyle_PaintOp, // arg inline
254 kJoin_PaintOp, // arg inline
255 kCap_PaintOp, // arg inline
256 kWidth_PaintOp, // arg scalar
257 kMiter_PaintOp, // arg scalar
258
259 kEncoding_PaintOp, // arg inline - text
260 kHinting_PaintOp, // arg inline - text
261 kAlign_PaintOp, // arg inline - text
262 kTextSize_PaintOp, // arg scalar - text
263 kTextScaleX_PaintOp,// arg scalar - text
264 kTextSkewX_PaintOp, // arg scalar - text
265 kTypeface_PaintOp, // arg inline (index) - text
266
267 kFlatIndex_PaintOp, // flags=paintflat, data=index
268 };
269
270 #define PAINTOPS_OP_BITS 8
271 #define PAINTOPS_FLAG_BITS 4
272 #define PAINTOPS_DATA_BITS 20
273
274 #define PAINTOPS_OP_MASK ((1 << PAINTOPS_OP_BITS) - 1)
275 #define PAINTOPS_FLAG_MASK ((1 << PAINTOPS_FLAG_BITS) - 1)
276 #define PAINTOPS_DATA_MASK ((1 << PAINTOPS_DATA_BITS) - 1)
277
278 static inline unsigned PaintOp_unpackOp(uint32_t op32) {
279 return (op32 >> (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS));
280 }
281
282 static inline unsigned PaintOp_unpackFlags(uint32_t op32) {
283 return (op32 >> PAINTOPS_DATA_BITS) & PAINTOPS_FLAG_MASK;
284 }
285
286 static inline unsigned PaintOp_unpackData(uint32_t op32) {
287 return op32 & PAINTOPS_DATA_MASK;
288 }
289
290 static inline uint32_t PaintOp_packOp(PaintOps op) {
291 SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
292
293 return op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS);
294 }
295
296 static inline uint32_t PaintOp_packOpData(PaintOps op, unsigned data) {
297 SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
298 SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
299
300 return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) | data;
301 }
302
303 static inline uint32_t PaintOp_packOpFlagData(PaintOps op, unsigned flags, unsig ned data) {
304 SkASSERT(0 == (op & ~PAINTOPS_OP_MASK));
305 SkASSERT(0 == (flags & ~PAINTOPS_FLAG_MASK));
306 SkASSERT(0 == (data & ~PAINTOPS_DATA_MASK));
307
308 return (op << (PAINTOPS_FLAG_BITS + PAINTOPS_DATA_BITS)) |
309 (flags << PAINTOPS_DATA_BITS) |
310 data;
311 }
312
313 #endif
OLDNEW
« no previous file with comments | « samplecode/SampleCode.h ('k') | src/pipe/SkGPipeRead.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698