OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
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 #include "SkAnnotation.h" | 9 #include "SkAnnotation.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 225 } |
226 | 226 |
227 void flushRecording(bool detachCurrentBlock); | 227 void flushRecording(bool detachCurrentBlock); |
228 size_t freeMemoryIfPossible(size_t bytesToFree); | 228 size_t freeMemoryIfPossible(size_t bytesToFree); |
229 | 229 |
230 size_t storageAllocatedForRecording() { | 230 size_t storageAllocatedForRecording() { |
231 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->bytesAllocated(); | 231 return (NULL == fBitmapHeap) ? 0 : fBitmapHeap->bytesAllocated(); |
232 } | 232 } |
233 | 233 |
234 // overrides from SkCanvas | 234 // overrides from SkCanvas |
235 virtual bool isDrawingToLayer() const SK_OVERRIDE; | |
236 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; | 235 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; |
237 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], | 236 virtual void drawPoints(PointMode, size_t count, const SkPoint pts[], |
238 const SkPaint&) SK_OVERRIDE; | 237 const SkPaint&) SK_OVERRIDE; |
239 virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; | 238 virtual void drawOval(const SkRect&, const SkPaint&) SK_OVERRIDE; |
240 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; | 239 virtual void drawRect(const SkRect& rect, const SkPaint&) SK_OVERRIDE; |
241 virtual void drawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE; | 240 virtual void drawRRect(const SkRRect&, const SkPaint&) SK_OVERRIDE; |
242 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; | 241 virtual void drawPath(const SkPath& path, const SkPaint&) SK_OVERRIDE; |
243 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, | 242 virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top, |
244 const SkPaint*) SK_OVERRIDE; | 243 const SkPaint*) SK_OVERRIDE; |
245 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, | 244 virtual void drawBitmapRectToRect(const SkBitmap&, const SkRect* src, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; | 291 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERR
IDE; |
293 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; | 292 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; |
294 | 293 |
295 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
) SK_OVERRIDE; | 294 virtual void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*
) SK_OVERRIDE; |
296 | 295 |
297 private: | 296 private: |
298 void recordTranslate(const SkMatrix&); | 297 void recordTranslate(const SkMatrix&); |
299 void recordScale(const SkMatrix&); | 298 void recordScale(const SkMatrix&); |
300 void recordConcat(const SkMatrix&); | 299 void recordConcat(const SkMatrix&); |
301 | 300 |
302 enum { | |
303 kNoSaveLayer = -1, | |
304 }; | |
305 SkNamedFactorySet* fFactorySet; | 301 SkNamedFactorySet* fFactorySet; |
306 int fFirstSaveLayerStackLevel; | |
307 SkBitmapHeap* fBitmapHeap; | 302 SkBitmapHeap* fBitmapHeap; |
308 SkGPipeController* fController; | 303 SkGPipeController* fController; |
309 SkWriter32& fWriter; | 304 SkWriter32& fWriter; |
310 size_t fBlockSize; // amount allocated for writer | 305 size_t fBlockSize; // amount allocated for writer |
311 size_t fBytesNotified; | 306 size_t fBytesNotified; |
312 bool fDone; | 307 bool fDone; |
313 const uint32_t fFlags; | 308 const uint32_t fFlags; |
314 | 309 |
315 SkRefCntSet fTypefaceSet; | 310 SkRefCntSet fTypefaceSet; |
316 | 311 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 , fFactorySet(is_cross_process(flags) ? SkNEW(SkNamedFactorySet) : NULL) | 436 , fFactorySet(is_cross_process(flags) ? SkNEW(SkNamedFactorySet) : NULL) |
442 , fWriter(*writer) | 437 , fWriter(*writer) |
443 , fFlags(flags) | 438 , fFlags(flags) |
444 , fFlattenableHeap(FLATTENABLES_TO_KEEP, fFactorySet, is_cross_process(flags
)) | 439 , fFlattenableHeap(FLATTENABLES_TO_KEEP, fFactorySet, is_cross_process(flags
)) |
445 , fFlatDictionary(&fFlattenableHeap) | 440 , fFlatDictionary(&fFlattenableHeap) |
446 { | 441 { |
447 fController = controller; | 442 fController = controller; |
448 fDone = false; | 443 fDone = false; |
449 fBlockSize = 0; // need first block from controller | 444 fBlockSize = 0; // need first block from controller |
450 fBytesNotified = 0; | 445 fBytesNotified = 0; |
451 fFirstSaveLayerStackLevel = kNoSaveLayer; | |
452 sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex)); | 446 sk_bzero(fCurrFlatIndex, sizeof(fCurrFlatIndex)); |
453 | 447 |
454 // Tell the reader the appropriate flags to use. | 448 // Tell the reader the appropriate flags to use. |
455 if (this->needOpBytes()) { | 449 if (this->needOpBytes()) { |
456 this->writeOp(kReportFlags_DrawOp, fFlags, 0); | 450 this->writeOp(kReportFlags_DrawOp, fFlags, 0); |
457 } | 451 } |
458 | 452 |
459 if (shouldFlattenBitmaps(flags)) { | 453 if (shouldFlattenBitmaps(flags)) { |
460 fBitmapShuttle.reset(SkNEW_ARGS(BitmapShuttle, (this))); | 454 fBitmapShuttle.reset(SkNEW_ARGS(BitmapShuttle, (this))); |
461 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO
_KEEP)); | 455 fBitmapHeap = SkNEW_ARGS(SkBitmapHeap, (fBitmapShuttle.get(), BITMAPS_TO
_KEEP)); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 this->writePaint(*paint); | 543 this->writePaint(*paint); |
550 } | 544 } |
551 | 545 |
552 if (this->needOpBytes(size)) { | 546 if (this->needOpBytes(size)) { |
553 this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags); | 547 this->writeOp(kSaveLayer_DrawOp, opFlags, saveFlags); |
554 if (bounds) { | 548 if (bounds) { |
555 fWriter.writeRect(*bounds); | 549 fWriter.writeRect(*bounds); |
556 } | 550 } |
557 } | 551 } |
558 | 552 |
559 if (kNoSaveLayer == fFirstSaveLayerStackLevel){ | |
560 fFirstSaveLayerStackLevel = this->getSaveCount(); | |
561 } | |
562 | |
563 this->INHERITED::willSaveLayer(bounds, paint, saveFlags); | 553 this->INHERITED::willSaveLayer(bounds, paint, saveFlags); |
564 // we don't create a layer | 554 // we don't create a layer |
565 return kNoLayer_SaveLayerStrategy; | 555 return kNoLayer_SaveLayerStrategy; |
566 } | 556 } |
567 | 557 |
568 void SkGPipeCanvas::willRestore() { | 558 void SkGPipeCanvas::willRestore() { |
569 NOTIFY_SETUP(this); | 559 NOTIFY_SETUP(this); |
570 if (this->needOpBytes()) { | 560 if (this->needOpBytes()) { |
571 this->writeOp(kRestore_DrawOp); | 561 this->writeOp(kRestore_DrawOp); |
572 } | 562 } |
573 | 563 |
574 if (this->getSaveCount() - 1 == fFirstSaveLayerStackLevel){ | |
575 fFirstSaveLayerStackLevel = kNoSaveLayer; | |
576 } | |
577 | |
578 this->INHERITED::willRestore(); | 564 this->INHERITED::willRestore(); |
579 } | 565 } |
580 | 566 |
581 bool SkGPipeCanvas::isDrawingToLayer() const { | |
582 return kNoSaveLayer != fFirstSaveLayerStackLevel; | |
583 } | |
584 | |
585 void SkGPipeCanvas::recordTranslate(const SkMatrix& m) { | 567 void SkGPipeCanvas::recordTranslate(const SkMatrix& m) { |
586 if (this->needOpBytes(2 * sizeof(SkScalar))) { | 568 if (this->needOpBytes(2 * sizeof(SkScalar))) { |
587 this->writeOp(kTranslate_DrawOp); | 569 this->writeOp(kTranslate_DrawOp); |
588 fWriter.writeScalar(m.getTranslateX()); | 570 fWriter.writeScalar(m.getTranslateX()); |
589 fWriter.writeScalar(m.getTranslateY()); | 571 fWriter.writeScalar(m.getTranslateY()); |
590 } | 572 } |
591 } | 573 } |
592 | 574 |
593 void SkGPipeCanvas::recordScale(const SkMatrix& m) { | 575 void SkGPipeCanvas::recordScale(const SkMatrix& m) { |
594 if (this->needOpBytes(2 * sizeof(SkScalar))) { | 576 if (this->needOpBytes(2 * sizeof(SkScalar))) { |
(...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 return fCanvas->shuttleBitmap(bitmap, slot); | 1349 return fCanvas->shuttleBitmap(bitmap, slot); |
1368 } | 1350 } |
1369 | 1351 |
1370 void BitmapShuttle::removeCanvas() { | 1352 void BitmapShuttle::removeCanvas() { |
1371 if (NULL == fCanvas) { | 1353 if (NULL == fCanvas) { |
1372 return; | 1354 return; |
1373 } | 1355 } |
1374 fCanvas->unref(); | 1356 fCanvas->unref(); |
1375 fCanvas = NULL; | 1357 fCanvas = NULL; |
1376 } | 1358 } |
OLD | NEW |