SkPicturePlayback.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2014 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. #ifndef SkPicturePlayback_DEFINED
  8. #define SkPicturePlayback_DEFINED
  9. #include "src/core/SkPictureFlat.h"
  10. class SkBitmap;
  11. class SkCanvas;
  12. class SkPaint;
  13. class SkPictureData;
  14. // The basic picture playback class replays the provided picture into a canvas.
  15. class SkPicturePlayback final : SkNoncopyable {
  16. public:
  17. SkPicturePlayback(const SkPictureData* data)
  18. : fPictureData(data)
  19. , fCurOffset(0) {
  20. }
  21. void draw(SkCanvas* canvas, SkPicture::AbortCallback*, SkReadBuffer* buffer);
  22. // TODO: remove the curOp calls after cleaning up GrGatherDevice
  23. // Return the ID of the operation currently being executed when playing
  24. // back. 0 indicates no call is active.
  25. size_t curOpID() const { return fCurOffset; }
  26. void resetOpID() { fCurOffset = 0; }
  27. protected:
  28. const SkPictureData* fPictureData;
  29. // The offset of the current operation when within the draw method
  30. size_t fCurOffset;
  31. void handleOp(SkReadBuffer* reader,
  32. DrawType op,
  33. uint32_t size,
  34. SkCanvas* canvas,
  35. const SkMatrix& initialMatrix);
  36. static DrawType ReadOpAndSize(SkReadBuffer* reader, uint32_t* size);
  37. class AutoResetOpID {
  38. public:
  39. AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { }
  40. ~AutoResetOpID() {
  41. if (fPlayback) {
  42. fPlayback->resetOpID();
  43. }
  44. }
  45. private:
  46. SkPicturePlayback* fPlayback;
  47. };
  48. private:
  49. typedef SkNoncopyable INHERITED;
  50. };
  51. #endif