OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2007 The Android Open Source Project | 3 * Copyright 2007 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkPicture_DEFINED | 10 #ifndef SkPicture_DEFINED |
(...skipping 17 matching lines...) Expand all Loading... |
28 class SkWStream; | 28 class SkWStream; |
29 | 29 |
30 struct SkPictInfo; | 30 struct SkPictInfo; |
31 | 31 |
32 class SkRecord; | 32 class SkRecord; |
33 | 33 |
34 namespace SkRecords { | 34 namespace SkRecords { |
35 class CollectLayers; | 35 class CollectLayers; |
36 }; | 36 }; |
37 | 37 |
| 38 //#define SK_LEGACY_ENCODE_BITMAP |
| 39 |
| 40 #ifdef SK_LEGACY_ENCODE_BITMAP |
| 41 #include "SkPixelSerializer.h" |
| 42 #else |
| 43 class SkPixelSerializer; |
| 44 #endif |
| 45 |
38 /** \class SkPicture | 46 /** \class SkPicture |
39 | 47 |
40 The SkPicture class records the drawing commands made to a canvas, to | 48 The SkPicture class records the drawing commands made to a canvas, to |
41 be played back at a later time. | 49 be played back at a later time. |
42 */ | 50 */ |
43 class SK_API SkPicture : public SkNVRefCnt<SkPicture> { | 51 class SK_API SkPicture : public SkNVRefCnt<SkPicture> { |
44 public: | 52 public: |
45 // AccelData provides a base class for device-specific acceleration | 53 // AccelData provides a base class for device-specific acceleration |
46 // data. It is added to the picture via EXPERIMENTAL_addAccelData. | 54 // data. It is added to the picture via EXPERIMENTAL_addAccelData. |
47 class AccelData : public SkRefCnt { | 55 class AccelData : public SkRefCnt { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 * signature can be passed to serialize() and SkWriteBuffer. | 145 * signature can be passed to serialize() and SkWriteBuffer. |
138 * Returning NULL will tell the SkWriteBuffer to use | 146 * Returning NULL will tell the SkWriteBuffer to use |
139 * SkBitmap::flatten() to store the bitmap. | 147 * SkBitmap::flatten() to store the bitmap. |
140 * | 148 * |
141 * @param pixelRefOffset DEPRECATED -- caller assumes it will return 0. | 149 * @param pixelRefOffset DEPRECATED -- caller assumes it will return 0. |
142 * @return SkData If non-NULL, holds encoded data representing the passed | 150 * @return SkData If non-NULL, holds encoded data representing the passed |
143 * in bitmap. The caller is responsible for calling unref(). | 151 * in bitmap. The caller is responsible for calling unref(). |
144 */ | 152 */ |
145 typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm); | 153 typedef SkData* (*EncodeBitmap)(size_t* pixelRefOffset, const SkBitmap& bm); |
146 | 154 |
| 155 #ifdef SK_LEGACY_ENCODE_BITMAP |
147 /** | 156 /** |
148 * Serialize to a stream. If non NULL, encoder will be used to encode | 157 * Serialize to a stream. If non NULL, encoder will be used to encode |
149 * any bitmaps in the picture. | 158 * any bitmaps in the picture. |
150 * encoder will never be called with a NULL pixelRefOffset. | 159 * encoder will never be called with a NULL pixelRefOffset. |
151 */ | 160 */ |
152 void serialize(SkWStream*, EncodeBitmap encoder = NULL) const; | 161 void serialize(SkWStream* wStream, EncodeBitmap encoder) const { |
| 162 EncodeBitmapSerializer serializer(encoder); |
| 163 this->serialize(wStream, &serializer); |
| 164 } |
| 165 #endif |
| 166 |
| 167 void serialize(SkWStream*, SkPixelSerializer* serializer = NULL) const; |
153 | 168 |
154 /** | 169 /** |
155 * Serialize to a buffer. | 170 * Serialize to a buffer. |
156 */ | 171 */ |
157 void flatten(SkWriteBuffer&) const; | 172 void flatten(SkWriteBuffer&) const; |
158 | 173 |
159 /** | 174 /** |
160 * Returns true if any bitmaps may be produced when this SkPicture | 175 * Returns true if any bitmaps may be produced when this SkPicture |
161 * is replayed. | 176 * is replayed. |
162 */ | 177 */ |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 | 303 |
289 bool fWillPlaybackBitmaps; | 304 bool fWillPlaybackBitmaps; |
290 bool fHasText; | 305 bool fHasText; |
291 int fNumPaintWithPathEffectUses; | 306 int fNumPaintWithPathEffectUses; |
292 int fNumFastPathDashEffects; | 307 int fNumFastPathDashEffects; |
293 int fNumAAConcavePaths; | 308 int fNumAAConcavePaths; |
294 int fNumAAHairlineConcavePaths; | 309 int fNumAAHairlineConcavePaths; |
295 int fNumAADFEligibleConcavePaths; | 310 int fNumAADFEligibleConcavePaths; |
296 } fAnalysis; | 311 } fAnalysis; |
297 | 312 |
| 313 #ifdef SK_LEGACY_ENCODE_BITMAP |
| 314 // Helper to use the new API. |
| 315 class EncodeBitmapSerializer : public SkPixelSerializer { |
| 316 public: |
| 317 explicit EncodeBitmapSerializer(EncodeBitmap encoder) |
| 318 : fEncoder(encoder) |
| 319 { |
| 320 SkASSERT(fEncoder); |
| 321 } |
| 322 |
| 323 bool useEncodedData(SkData*) SK_OVERRIDE { return true; } |
| 324 |
| 325 SkData* encodePixels(const SkImageInfo& info, void* pixels, size_t rowBy
tes) SK_OVERRIDE { |
| 326 size_t unused; |
| 327 SkBitmap bm; |
| 328 bm.installPixels(info, pixels, rowBytes); |
| 329 return fEncoder(&unused, bm); |
| 330 } |
| 331 |
| 332 private: |
| 333 EncodeBitmap fEncoder; |
| 334 }; |
| 335 #endif |
| 336 |
298 friend class SkPictureRecorder; // SkRecord-based constructor. | 337 friend class SkPictureRecorder; // SkRecord-based constructor. |
299 friend class GrLayerHoister; // access to fRecord | 338 friend class GrLayerHoister; // access to fRecord |
300 friend class ReplaceDraw; | 339 friend class ReplaceDraw; |
301 friend class SkPictureUtils; | 340 friend class SkPictureUtils; |
302 friend class SkRecordedDrawable; | 341 friend class SkRecordedDrawable; |
303 }; | 342 }; |
304 SK_COMPILE_ASSERT(sizeof(SkPicture) <= 96, SkPictureSize); | 343 SK_COMPILE_ASSERT(sizeof(SkPicture) <= 96, SkPictureSize); |
305 | 344 |
306 #endif | 345 #endif |
OLD | NEW |