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 #include "SkPictureFlat.h" | 10 #include "SkPictureFlat.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 | 25 |
26 #include "SkReader32.h" | 26 #include "SkReader32.h" |
27 #include "SkWriter32.h" | 27 #include "SkWriter32.h" |
28 #include "SkRTree.h" | 28 #include "SkRTree.h" |
29 #include "SkBBoxHierarchyRecord.h" | 29 #include "SkBBoxHierarchyRecord.h" |
30 | 30 |
31 #if SK_SUPPORT_GPU | 31 #if SK_SUPPORT_GPU |
32 #include "GrContext.h" | 32 #include "GrContext.h" |
33 #endif | 33 #endif |
34 | 34 |
| 35 #include "SkRecord.h" |
| 36 #include "SkRecordDraw.h" |
| 37 |
35 template <typename T> int SafeCount(const T* obj) { | 38 template <typename T> int SafeCount(const T* obj) { |
36 return obj ? obj->count() : 0; | 39 return obj ? obj->count() : 0; |
37 } | 40 } |
38 | 41 |
39 #define DUMP_BUFFER_SIZE 65536 | 42 #define DUMP_BUFFER_SIZE 65536 |
40 | 43 |
41 //#define ENABLE_TIME_DRAW // dumps milliseconds for each draw | 44 //#define ENABLE_TIME_DRAW // dumps milliseconds for each draw |
42 | 45 |
43 | 46 |
44 #ifdef SK_DEBUG | 47 #ifdef SK_DEBUG |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 SkASSERT(scaleX == 0 || skewX == 0); | 119 SkASSERT(scaleX == 0 || skewX == 0); |
117 SkASSERT(scaleY == 0 || skewY == 0); | 120 SkASSERT(scaleY == 0 || skewY == 0); |
118 SkASSERT(perspX == 0); | 121 SkASSERT(perspX == 0); |
119 SkASSERT(perspY == 0); | 122 SkASSERT(perspY == 0); |
120 } | 123 } |
121 #endif | 124 #endif |
122 | 125 |
123 | 126 |
124 /////////////////////////////////////////////////////////////////////////////// | 127 /////////////////////////////////////////////////////////////////////////////// |
125 | 128 |
| 129 // fRecord OK |
126 SkPicture::SkPicture() | 130 SkPicture::SkPicture() |
127 : fAccelData(NULL) { | 131 : fWidth(0) |
| 132 , fHeight(0) { |
128 this->needsNewGenID(); | 133 this->needsNewGenID(); |
129 fPlayback = NULL; | |
130 fWidth = fHeight = 0; | |
131 } | 134 } |
132 | 135 |
| 136 // fRecord OK |
133 SkPicture::SkPicture(int width, int height, | 137 SkPicture::SkPicture(int width, int height, |
134 const SkPictureRecord& record, | 138 const SkPictureRecord& record, |
135 bool deepCopyOps) | 139 bool deepCopyOps) |
136 : fWidth(width) | 140 : fWidth(width) |
137 , fHeight(height) | 141 , fHeight(height) { |
138 , fAccelData(NULL) { | |
139 this->needsNewGenID(); | 142 this->needsNewGenID(); |
140 | 143 |
141 SkPictInfo info; | 144 SkPictInfo info; |
142 this->createHeader(&info); | 145 this->createHeader(&info); |
143 fPlayback = SkNEW_ARGS(SkPicturePlayback, (record, info, deepCopyOps)); | 146 fPlayback.reset(SkNEW_ARGS(SkPicturePlayback, (record, info, deepCopyOps))); |
144 } | 147 } |
145 | 148 |
146 SkPicture::SkPicture(const SkPicture& src) | 149 // fRecord TODO |
147 : INHERITED() | 150 SkPicture::SkPicture(const SkPicture& src) : INHERITED() { |
148 , fAccelData(NULL) { | |
149 this->needsNewGenID(); | 151 this->needsNewGenID(); |
150 fWidth = src.fWidth; | 152 fWidth = src.fWidth; |
151 fHeight = src.fHeight; | 153 fHeight = src.fHeight; |
152 | 154 |
153 if (src.fPlayback) { | 155 if (src.fPlayback.get()) { |
154 fPlayback = SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback)); | 156 fPlayback.reset(SkNEW_ARGS(SkPicturePlayback, (*src.fPlayback))); |
155 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 | 157 fUniqueID = src.uniqueID(); // need to call method to ensure != 0 |
156 } else { | |
157 fPlayback = NULL; | |
158 } | 158 } |
159 } | 159 } |
160 | 160 |
161 SkPicture::~SkPicture() { | 161 // fRecord OK |
162 SkDELETE(fPlayback); | 162 SkPicture::~SkPicture() {} |
163 SkSafeUnref(fAccelData); | 163 |
| 164 // fRecord OK |
| 165 void SkPicture::swap(SkPicture& other) { |
| 166 SkTSwap(fUniqueID, other.fUniqueID); |
| 167 SkTSwap(fWidth, other.fWidth); |
| 168 SkTSwap(fHeight, other.fHeight); |
| 169 |
| 170 fAccelData.swap(&other.fAccelData); |
| 171 fPlayback.swap(&other.fPlayback); |
| 172 fRecord.swap(&other.fRecord); |
164 } | 173 } |
165 | 174 |
166 void SkPicture::swap(SkPicture& other) { | 175 // fRecord TODO |
167 SkTSwap(fUniqueID, other.fUniqueID); | |
168 SkTSwap(fPlayback, other.fPlayback); | |
169 SkTSwap(fAccelData, other.fAccelData); | |
170 SkTSwap(fWidth, other.fWidth); | |
171 SkTSwap(fHeight, other.fHeight); | |
172 } | |
173 | |
174 SkPicture* SkPicture::clone() const { | 176 SkPicture* SkPicture::clone() const { |
175 SkPicture* clonedPicture = SkNEW(SkPicture); | 177 SkPicture* clonedPicture = SkNEW(SkPicture); |
176 this->clone(clonedPicture, 1); | 178 this->clone(clonedPicture, 1); |
177 return clonedPicture; | 179 return clonedPicture; |
178 } | 180 } |
179 | 181 |
| 182 // fRecord TODO |
180 void SkPicture::clone(SkPicture* pictures, int count) const { | 183 void SkPicture::clone(SkPicture* pictures, int count) const { |
181 SkPictCopyInfo copyInfo; | 184 SkPictCopyInfo copyInfo; |
182 | 185 |
183 for (int i = 0; i < count; i++) { | 186 for (int i = 0; i < count; i++) { |
184 SkPicture* clone = &pictures[i]; | 187 SkPicture* clone = &pictures[i]; |
185 | 188 |
186 clone->needsNewGenID(); | 189 clone->needsNewGenID(); |
187 clone->fWidth = fWidth; | 190 clone->fWidth = fWidth; |
188 clone->fHeight = fHeight; | 191 clone->fHeight = fHeight; |
189 SkDELETE(clone->fPlayback); | 192 clone->fPlayback.reset(NULL); |
190 | 193 |
191 /* We want to copy the src's playback. However, if that hasn't been bui
lt | 194 /* We want to copy the src's playback. However, if that hasn't been bui
lt |
192 yet, we need to fake a call to endRecording() without actually calli
ng | 195 yet, we need to fake a call to endRecording() without actually calli
ng |
193 it (since it is destructive, and we don't want to change src). | 196 it (since it is destructive, and we don't want to change src). |
194 */ | 197 */ |
195 if (fPlayback) { | 198 if (fPlayback.get()) { |
196 if (!copyInfo.initialized) { | 199 if (!copyInfo.initialized) { |
197 int paintCount = SafeCount(fPlayback->fPaints); | 200 int paintCount = SafeCount(fPlayback->fPaints); |
198 | 201 |
199 /* The alternative to doing this is to have a clone method on th
e paint and have it | 202 /* The alternative to doing this is to have a clone method on th
e paint and have it |
200 * make the deep copy of its internal structures as needed. The
holdup to doing | 203 * make the deep copy of its internal structures as needed. The
holdup to doing |
201 * that is at this point we would need to pass the SkBitmapHeap
so that we don't | 204 * that is at this point we would need to pass the SkBitmapHeap
so that we don't |
202 * unnecessarily flatten the pixels in a bitmap shader. | 205 * unnecessarily flatten the pixels in a bitmap shader. |
203 */ | 206 */ |
204 copyInfo.paintData.setCount(paintCount); | 207 copyInfo.paintData.setCount(paintCount); |
205 | 208 |
(...skipping 22 matching lines...) Expand all Loading... |
228 copyInfo.paintData[i] = NULL; | 231 copyInfo.paintData[i] = NULL; |
229 } | 232 } |
230 } | 233 } |
231 SkASSERT(SafeCount(fPlayback->fBitmapHeap.get()) == heapSize); | 234 SkASSERT(SafeCount(fPlayback->fBitmapHeap.get()) == heapSize); |
232 | 235 |
233 // needed to create typeface playback | 236 // needed to create typeface playback |
234 copyInfo.controller.setupPlaybacks(); | 237 copyInfo.controller.setupPlaybacks(); |
235 copyInfo.initialized = true; | 238 copyInfo.initialized = true; |
236 } | 239 } |
237 | 240 |
238 clone->fPlayback = SkNEW_ARGS(SkPicturePlayback, (*fPlayback, ©I
nfo)); | 241 clone->fPlayback.reset(SkNEW_ARGS(SkPicturePlayback, (*fPlayback, &c
opyInfo))); |
239 clone->fUniqueID = this->uniqueID(); // need to call method to ensur
e != 0 | 242 clone->fUniqueID = this->uniqueID(); // need to call method to ensur
e != 0 |
240 } else { | |
241 clone->fPlayback = NULL; | |
242 } | 243 } |
243 } | 244 } |
244 } | 245 } |
245 | 246 |
| 247 // fRecord OK |
| 248 void SkPicture::EXPERIMENTAL_addAccelData(const SkPicture::AccelData* data) cons
t { |
| 249 fAccelData.reset(SkRef(data)); |
| 250 } |
| 251 |
| 252 // fRecord OK |
| 253 const SkPicture::AccelData* SkPicture::EXPERIMENTAL_getAccelData( |
| 254 SkPicture::AccelData::Key key) const { |
| 255 if (NULL != fAccelData.get() && fAccelData->getKey() == key) { |
| 256 return fAccelData.get(); |
| 257 } |
| 258 return NULL; |
| 259 } |
| 260 |
| 261 // fRecord OK |
246 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { | 262 SkPicture::AccelData::Domain SkPicture::AccelData::GenerateDomain() { |
247 static int32_t gNextID = 0; | 263 static int32_t gNextID = 0; |
248 | 264 |
249 int32_t id = sk_atomic_inc(&gNextID); | 265 int32_t id = sk_atomic_inc(&gNextID); |
250 if (id >= 1 << (8 * sizeof(Domain))) { | 266 if (id >= 1 << (8 * sizeof(Domain))) { |
251 SK_CRASH(); | 267 SK_CRASH(); |
252 } | 268 } |
253 | 269 |
254 return static_cast<Domain>(id); | 270 return static_cast<Domain>(id); |
255 } | 271 } |
256 | 272 |
257 /////////////////////////////////////////////////////////////////////////////// | 273 /////////////////////////////////////////////////////////////////////////////// |
258 | 274 |
| 275 // fRecord OK |
259 const SkPicture::OperationList& SkPicture::OperationList::InvalidList() { | 276 const SkPicture::OperationList& SkPicture::OperationList::InvalidList() { |
260 static OperationList gInvalid; | 277 static OperationList gInvalid; |
261 return gInvalid; | 278 return gInvalid; |
262 } | 279 } |
263 | 280 |
| 281 // fRecord TODO |
264 const SkPicture::OperationList& SkPicture::EXPERIMENTAL_getActiveOps(const SkIRe
ct& queryRect) const { | 282 const SkPicture::OperationList& SkPicture::EXPERIMENTAL_getActiveOps(const SkIRe
ct& queryRect) const { |
265 SkASSERT(NULL != fPlayback); | 283 SkASSERT(NULL != fPlayback.get()); |
266 if (NULL != fPlayback) { | 284 if (NULL != fPlayback.get()) { |
267 return fPlayback->getActiveOps(queryRect); | 285 return fPlayback->getActiveOps(queryRect); |
268 } | 286 } |
269 return OperationList::InvalidList(); | 287 return OperationList::InvalidList(); |
270 } | 288 } |
271 | 289 |
| 290 // fRecord TODO |
272 size_t SkPicture::EXPERIMENTAL_curOpID() const { | 291 size_t SkPicture::EXPERIMENTAL_curOpID() const { |
273 if (NULL != fPlayback) { | 292 if (NULL != fPlayback.get()) { |
274 return fPlayback->curOpID(); | 293 return fPlayback->curOpID(); |
275 } | 294 } |
276 return 0; | 295 return 0; |
277 } | 296 } |
278 | 297 |
279 void SkPicture::draw(SkCanvas* surface, SkDrawPictureCallback* callback) const { | 298 // fRecord OK |
280 SkASSERT(NULL != fPlayback); | 299 void SkPicture::draw(SkCanvas* canvas, SkDrawPictureCallback* callback) const { |
281 if (NULL != fPlayback) { | 300 SkASSERT(NULL != canvas); |
282 fPlayback->draw(*surface, callback); | 301 SkASSERT(NULL != fPlayback.get() || NULL != fRecord.get()); |
| 302 |
| 303 if (NULL != fPlayback.get()) { |
| 304 fPlayback->draw(*canvas, callback); |
| 305 } |
| 306 if (NULL != fRecord.get()) { |
| 307 // TODO: support SkDrawPictureCallback |
| 308 SkRecordDraw(*fRecord, canvas); |
283 } | 309 } |
284 } | 310 } |
285 | 311 |
286 /////////////////////////////////////////////////////////////////////////////// | 312 /////////////////////////////////////////////////////////////////////////////// |
287 | 313 |
288 #include "SkStream.h" | 314 #include "SkStream.h" |
289 | 315 |
290 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; | 316 static const char kMagic[] = { 's', 'k', 'i', 'a', 'p', 'i', 'c', 't' }; |
291 | 317 |
| 318 // fRecord OK |
292 bool SkPicture::IsValidPictInfo(const SkPictInfo& info) { | 319 bool SkPicture::IsValidPictInfo(const SkPictInfo& info) { |
293 if (0 != memcmp(info.fMagic, kMagic, sizeof(kMagic))) { | 320 if (0 != memcmp(info.fMagic, kMagic, sizeof(kMagic))) { |
294 return false; | 321 return false; |
295 } | 322 } |
296 | 323 |
297 if (info.fVersion < MIN_PICTURE_VERSION || | 324 if (info.fVersion < MIN_PICTURE_VERSION || |
298 info.fVersion > CURRENT_PICTURE_VERSION) { | 325 info.fVersion > CURRENT_PICTURE_VERSION) { |
299 return false; | 326 return false; |
300 } | 327 } |
301 | 328 |
302 return true; | 329 return true; |
303 } | 330 } |
304 | 331 |
| 332 // fRecord OK |
305 bool SkPicture::InternalOnly_StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) { | 333 bool SkPicture::InternalOnly_StreamIsSKP(SkStream* stream, SkPictInfo* pInfo) { |
306 if (NULL == stream) { | 334 if (NULL == stream) { |
307 return false; | 335 return false; |
308 } | 336 } |
309 | 337 |
310 // Check magic bytes. | 338 // Check magic bytes. |
311 SkPictInfo info; | 339 SkPictInfo info; |
312 SkASSERT(sizeof(kMagic) == sizeof(info.fMagic)); | 340 SkASSERT(sizeof(kMagic) == sizeof(info.fMagic)); |
313 if (!stream->read(&info, sizeof(info)) || !IsValidPictInfo(info)) { | 341 if (!stream->read(&info, sizeof(info)) || !IsValidPictInfo(info)) { |
314 return false; | 342 return false; |
315 } | 343 } |
316 | 344 |
317 if (pInfo != NULL) { | 345 if (pInfo != NULL) { |
318 *pInfo = info; | 346 *pInfo = info; |
319 } | 347 } |
320 return true; | 348 return true; |
321 } | 349 } |
322 | 350 |
| 351 // fRecord OK |
323 bool SkPicture::InternalOnly_BufferIsSKP(SkReadBuffer& buffer, SkPictInfo* pInfo
) { | 352 bool SkPicture::InternalOnly_BufferIsSKP(SkReadBuffer& buffer, SkPictInfo* pInfo
) { |
324 // Check magic bytes. | 353 // Check magic bytes. |
325 SkPictInfo info; | 354 SkPictInfo info; |
326 SkASSERT(sizeof(kMagic) == sizeof(info.fMagic)); | 355 SkASSERT(sizeof(kMagic) == sizeof(info.fMagic)); |
327 if (!buffer.readByteArray(&info, sizeof(info)) || !IsValidPictInfo(info)) { | 356 if (!buffer.readByteArray(&info, sizeof(info)) || !IsValidPictInfo(info)) { |
328 return false; | 357 return false; |
329 } | 358 } |
330 | 359 |
331 if (pInfo != NULL) { | 360 if (pInfo != NULL) { |
332 *pInfo = info; | 361 *pInfo = info; |
333 } | 362 } |
334 return true; | 363 return true; |
335 } | 364 } |
336 | 365 |
| 366 // fRecord OK |
337 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) | 367 SkPicture::SkPicture(SkPicturePlayback* playback, int width, int height) |
338 : fPlayback(playback) | 368 : fPlayback(playback) |
339 , fWidth(width) | 369 , fWidth(width) |
340 , fHeight(height) | 370 , fHeight(height) { |
341 , fAccelData(NULL) { | |
342 this->needsNewGenID(); | 371 this->needsNewGenID(); |
343 } | 372 } |
344 | 373 |
| 374 // fRecord OK |
345 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro
c) { | 375 SkPicture* SkPicture::CreateFromStream(SkStream* stream, InstallPixelRefProc pro
c) { |
346 SkPictInfo info; | 376 SkPictInfo info; |
347 | 377 |
348 if (!InternalOnly_StreamIsSKP(stream, &info)) { | 378 if (!InternalOnly_StreamIsSKP(stream, &info)) { |
349 return NULL; | 379 return NULL; |
350 } | 380 } |
351 | 381 |
352 // Check to see if there is a playback to recreate. | 382 // Check to see if there is a playback to recreate. |
353 if (stream->readBool()) { | 383 if (stream->readBool()) { |
354 SkPicturePlayback* playback = SkPicturePlayback::CreateFromStream(stream
, info, proc); | 384 SkPicturePlayback* playback = SkPicturePlayback::CreateFromStream(stream
, info, proc); |
355 if (NULL == playback) { | 385 if (NULL == playback) { |
356 return NULL; | 386 return NULL; |
357 } | 387 } |
358 | 388 |
359 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); | 389 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); |
360 } | 390 } |
361 | 391 |
362 return NULL; | 392 return NULL; |
363 } | 393 } |
364 | 394 |
| 395 // fRecord OK |
365 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { | 396 SkPicture* SkPicture::CreateFromBuffer(SkReadBuffer& buffer) { |
366 SkPictInfo info; | 397 SkPictInfo info; |
367 | 398 |
368 if (!InternalOnly_BufferIsSKP(buffer, &info)) { | 399 if (!InternalOnly_BufferIsSKP(buffer, &info)) { |
369 return NULL; | 400 return NULL; |
370 } | 401 } |
371 | 402 |
372 // Check to see if there is a playback to recreate. | 403 // Check to see if there is a playback to recreate. |
373 if (buffer.readBool()) { | 404 if (buffer.readBool()) { |
374 SkPicturePlayback* playback = SkPicturePlayback::CreateFromBuffer(buffer
, info); | 405 SkPicturePlayback* playback = SkPicturePlayback::CreateFromBuffer(buffer
, info); |
375 if (NULL == playback) { | 406 if (NULL == playback) { |
376 return NULL; | 407 return NULL; |
377 } | 408 } |
378 | 409 |
379 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); | 410 return SkNEW_ARGS(SkPicture, (playback, info.fWidth, info.fHeight)); |
380 } | 411 } |
381 | 412 |
382 return NULL; | 413 return NULL; |
383 } | 414 } |
384 | 415 |
| 416 // fRecord OK |
385 void SkPicture::createHeader(SkPictInfo* info) const { | 417 void SkPicture::createHeader(SkPictInfo* info) const { |
386 // Copy magic bytes at the beginning of the header | 418 // Copy magic bytes at the beginning of the header |
387 SkASSERT(sizeof(kMagic) == 8); | 419 SkASSERT(sizeof(kMagic) == 8); |
388 SkASSERT(sizeof(kMagic) == sizeof(info->fMagic)); | 420 SkASSERT(sizeof(kMagic) == sizeof(info->fMagic)); |
389 memcpy(info->fMagic, kMagic, sizeof(kMagic)); | 421 memcpy(info->fMagic, kMagic, sizeof(kMagic)); |
390 | 422 |
391 // Set picture info after magic bytes in the header | 423 // Set picture info after magic bytes in the header |
392 info->fVersion = CURRENT_PICTURE_VERSION; | 424 info->fVersion = CURRENT_PICTURE_VERSION; |
393 info->fWidth = fWidth; | 425 info->fWidth = fWidth; |
394 info->fHeight = fHeight; | 426 info->fHeight = fHeight; |
395 info->fFlags = SkPictInfo::kCrossProcess_Flag; | 427 info->fFlags = SkPictInfo::kCrossProcess_Flag; |
396 // TODO: remove this flag, since we're always float (now) | 428 // TODO: remove this flag, since we're always float (now) |
397 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; | 429 info->fFlags |= SkPictInfo::kScalarIsFloat_Flag; |
398 | 430 |
399 if (8 == sizeof(void*)) { | 431 if (8 == sizeof(void*)) { |
400 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; | 432 info->fFlags |= SkPictInfo::kPtrIs64Bit_Flag; |
401 } | 433 } |
402 } | 434 } |
403 | 435 |
| 436 // fRecord TODO |
404 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { | 437 void SkPicture::serialize(SkWStream* stream, EncodeBitmap encoder) const { |
405 SkPicturePlayback* playback = fPlayback; | 438 SkPicturePlayback* playback = fPlayback.get(); |
406 | 439 |
407 SkPictInfo info; | 440 SkPictInfo info; |
408 this->createHeader(&info); | 441 this->createHeader(&info); |
409 stream->write(&info, sizeof(info)); | 442 stream->write(&info, sizeof(info)); |
410 if (playback) { | 443 if (playback) { |
411 stream->writeBool(true); | 444 stream->writeBool(true); |
412 playback->serialize(stream, encoder); | 445 playback->serialize(stream, encoder); |
413 // delete playback if it is a local version (i.e. cons'd up just now) | 446 // delete playback if it is a local version (i.e. cons'd up just now) |
414 if (playback != fPlayback) { | 447 if (playback != fPlayback.get()) { |
415 SkDELETE(playback); | 448 SkDELETE(playback); |
416 } | 449 } |
417 } else { | 450 } else { |
418 stream->writeBool(false); | 451 stream->writeBool(false); |
419 } | 452 } |
420 } | 453 } |
421 | 454 |
| 455 // fRecord OK |
422 void SkPicture::WriteTagSize(SkWriteBuffer& buffer, uint32_t tag, size_t size) { | 456 void SkPicture::WriteTagSize(SkWriteBuffer& buffer, uint32_t tag, size_t size) { |
423 buffer.writeUInt(tag); | 457 buffer.writeUInt(tag); |
424 buffer.writeUInt(SkToU32(size)); | 458 buffer.writeUInt(SkToU32(size)); |
425 } | 459 } |
426 | 460 |
| 461 // fRecord OK |
427 void SkPicture::WriteTagSize(SkWStream* stream, uint32_t tag, size_t size) { | 462 void SkPicture::WriteTagSize(SkWStream* stream, uint32_t tag, size_t size) { |
428 stream->write32(tag); | 463 stream->write32(tag); |
429 stream->write32(SkToU32(size)); | 464 stream->write32(SkToU32(size)); |
430 } | 465 } |
431 | 466 |
| 467 // fRecord TODO |
432 void SkPicture::flatten(SkWriteBuffer& buffer) const { | 468 void SkPicture::flatten(SkWriteBuffer& buffer) const { |
433 SkPicturePlayback* playback = fPlayback; | 469 SkPicturePlayback* playback = fPlayback.get(); |
434 | 470 |
435 SkPictInfo info; | 471 SkPictInfo info; |
436 this->createHeader(&info); | 472 this->createHeader(&info); |
437 buffer.writeByteArray(&info, sizeof(info)); | 473 buffer.writeByteArray(&info, sizeof(info)); |
438 if (playback) { | 474 if (playback) { |
439 buffer.writeBool(true); | 475 buffer.writeBool(true); |
440 playback->flatten(buffer); | 476 playback->flatten(buffer); |
441 // delete playback if it is a local version (i.e. cons'd up just now) | 477 // delete playback if it is a local version (i.e. cons'd up just now) |
442 if (playback != fPlayback) { | 478 if (playback != fPlayback.get()) { |
443 SkDELETE(playback); | 479 SkDELETE(playback); |
444 } | 480 } |
445 } else { | 481 } else { |
446 buffer.writeBool(false); | 482 buffer.writeBool(false); |
447 } | 483 } |
448 } | 484 } |
449 | 485 |
450 #if SK_SUPPORT_GPU | 486 #if SK_SUPPORT_GPU |
| 487 // fRecord TODO |
451 bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **rea
son) const { | 488 bool SkPicture::suitableForGpuRasterization(GrContext* context, const char **rea
son) const { |
452 if (NULL == fPlayback) { | 489 if (NULL == fPlayback.get()) { |
453 if (NULL != reason) { | 490 if (NULL != reason) { |
454 *reason = "Missing playback object."; | 491 *reason = "Missing playback object."; |
455 } | 492 } |
456 return false; | 493 return false; |
457 } | 494 } |
458 | 495 |
459 return fPlayback->suitableForGpuRasterization(context, reason); | 496 return fPlayback->suitableForGpuRasterization(context, reason); |
460 } | 497 } |
461 #endif | 498 #endif |
462 | 499 |
| 500 // fRecord TODO |
463 bool SkPicture::willPlayBackBitmaps() const { | 501 bool SkPicture::willPlayBackBitmaps() const { |
464 if (!fPlayback) { | 502 if (!fPlayback.get()) { |
465 return false; | 503 return false; |
466 } | 504 } |
467 return fPlayback->containsBitmaps(); | 505 return fPlayback->containsBitmaps(); |
468 } | 506 } |
469 | 507 |
470 #ifdef SK_BUILD_FOR_ANDROID | 508 #ifdef SK_BUILD_FOR_ANDROID |
| 509 // fRecord TODO |
471 void SkPicture::abortPlayback() { | 510 void SkPicture::abortPlayback() { |
472 if (NULL == fPlayback) { | 511 if (NULL == fPlayback.get()) { |
473 return; | 512 return; |
474 } | 513 } |
475 fPlayback->abort(); | 514 fPlayback->abort(); |
476 } | 515 } |
477 #endif | 516 #endif |
478 | 517 |
| 518 // fRecord OK |
479 static int32_t next_picture_generation_id() { | 519 static int32_t next_picture_generation_id() { |
480 static int32_t gPictureGenerationID = 0; | 520 static int32_t gPictureGenerationID = 0; |
481 // do a loop in case our global wraps around, as we never want to | 521 // do a loop in case our global wraps around, as we never want to |
482 // return a 0 | 522 // return a 0 |
483 int32_t genID; | 523 int32_t genID; |
484 do { | 524 do { |
485 genID = sk_atomic_inc(&gPictureGenerationID) + 1; | 525 genID = sk_atomic_inc(&gPictureGenerationID) + 1; |
486 } while (SK_InvalidGenID == genID); | 526 } while (SK_InvalidGenID == genID); |
487 return genID; | 527 return genID; |
488 } | 528 } |
489 | 529 |
| 530 // fRecord OK |
490 uint32_t SkPicture::uniqueID() const { | 531 uint32_t SkPicture::uniqueID() const { |
491 if (SK_InvalidGenID == fUniqueID) { | 532 if (SK_InvalidGenID == fUniqueID) { |
492 fUniqueID = next_picture_generation_id(); | 533 fUniqueID = next_picture_generation_id(); |
493 } | 534 } |
494 return fUniqueID; | 535 return fUniqueID; |
495 } | 536 } |
| 537 |
| 538 // fRecord OK |
| 539 SkPicture::SkPicture(int width, int height, SkRecord* record) |
| 540 : fWidth(width) |
| 541 , fHeight(height) |
| 542 , fRecord(record) { |
| 543 this->needsNewGenID(); |
| 544 } |
OLD | NEW |