DDLTileHelper.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2018 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 DDLTileHelper_DEFINED
  8. #define DDLTileHelper_DEFINED
  9. #include "include/core/SkRect.h"
  10. #include "include/core/SkRefCnt.h"
  11. #include "include/core/SkSurfaceCharacterization.h"
  12. class DDLPromiseImageHelper;
  13. class SkCanvas;
  14. class SkData;
  15. class SkDeferredDisplayList;
  16. class SkPicture;
  17. class SkSurface;
  18. class SkSurfaceCharacterization;
  19. class DDLTileHelper {
  20. public:
  21. // TileData class encapsulates the information and behavior for a single tile/thread in
  22. // a DDL rendering.
  23. class TileData {
  24. public:
  25. TileData(sk_sp<SkSurface>, const SkIRect& clip);
  26. // This method can be invoked in parallel
  27. // In each thread we will reconvert the compressedPictureData into an SkPicture
  28. // replacing each image-index with a promise image.
  29. void createTileSpecificSKP(SkData* compressedPictureData,
  30. const DDLPromiseImageHelper& helper);
  31. // This method can be invoked in parallel
  32. // Create the per-tile DDL from the per-tile SKP
  33. void createDDL();
  34. // This method operates serially and replays the recorded DDL into the tile surface.
  35. void draw();
  36. // This method also operates serially and composes the results of replaying the DDL into
  37. // the final destination surface.
  38. void compose(SkCanvas* dst);
  39. void reset();
  40. private:
  41. sk_sp<SkSurface> fSurface;
  42. SkSurfaceCharacterization fCharacterization;
  43. SkIRect fClip; // in the device space of the dest canvas
  44. sk_sp<SkPicture> fReconstitutedPicture;
  45. SkTArray<sk_sp<SkImage>> fPromiseImages; // All the promise images in the
  46. // reconstituted picture
  47. std::unique_ptr<SkDeferredDisplayList> fDisplayList;
  48. };
  49. DDLTileHelper(SkCanvas* canvas, const SkIRect& viewport, int numDivisions);
  50. void createSKPPerTile(SkData* compressedPictureData, const DDLPromiseImageHelper& helper);
  51. void createDDLsInParallel();
  52. void drawAllTilesAndFlush(GrContext*, bool flush);
  53. void composeAllTiles(SkCanvas* dstCanvas);
  54. void resetAllTiles();
  55. private:
  56. int fNumDivisions; // number of tiles along a side
  57. SkTArray<TileData> fTiles;
  58. };
  59. #endif