SkSpecialSurface.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright 2016 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 SkSpecialSurface_DEFINED
  8. #define SkSpecialSurface_DEFINED
  9. #include "include/core/SkImageInfo.h"
  10. #include "include/core/SkRefCnt.h"
  11. #include "include/core/SkSurfaceProps.h"
  12. #if SK_SUPPORT_GPU
  13. #include "include/private/GrTypesPriv.h"
  14. #endif
  15. class GrBackendFormat;
  16. class GrContext;
  17. class GrRecordingContext;
  18. class SkBitmap;
  19. class SkCanvas;
  20. class SkSpecialImage;
  21. /**
  22. * SkSpecialSurface is a restricted form of SkSurface solely for internal use. It differs
  23. * from SkSurface in that:
  24. * - it can be backed by GrTextures larger than [ fWidth, fHeight ]
  25. * - it can't be used for tiling
  26. * - it becomes inactive once a snapshot of it is taken (i.e., no copy-on-write)
  27. * - it has no generation ID
  28. */
  29. class SkSpecialSurface : public SkRefCnt {
  30. public:
  31. const SkSurfaceProps& props() const { return fProps; }
  32. int width() const { return fSubset.width(); }
  33. int height() const { return fSubset.height(); }
  34. /**
  35. * Return a canvas that will draw into this surface. This will always
  36. * return the same canvas for a given surface, and is managed/owned by the
  37. * surface.
  38. *
  39. * The canvas will be invalid after 'newImageSnapshot' is called.
  40. */
  41. SkCanvas* getCanvas();
  42. /**
  43. * Returns an image of the current state of the surface pixels up to this
  44. * point. The canvas returned by 'getCanvas' becomes invalidated by this
  45. * call and no more drawing to this surface is allowed.
  46. *
  47. * Note: the caller inherits a ref from this call that must be balanced
  48. */
  49. sk_sp<SkSpecialImage> makeImageSnapshot();
  50. #if SK_SUPPORT_GPU
  51. /**
  52. * Allocate a new GPU-backed SkSpecialSurface. If the requested surface cannot
  53. * be created, nullptr will be returned.
  54. */
  55. static sk_sp<SkSpecialSurface> MakeRenderTarget(GrRecordingContext*, int width, int height,
  56. GrColorType, sk_sp<SkColorSpace> colorSpace,
  57. const SkSurfaceProps* = nullptr);
  58. #endif
  59. /**
  60. * Use and existing SkBitmap as the backing store.
  61. */
  62. static sk_sp<SkSpecialSurface> MakeFromBitmap(const SkIRect& subset, SkBitmap& bm,
  63. const SkSurfaceProps* = nullptr);
  64. /**
  65. * Return a new CPU-backed surface, with the memory for the pixels automatically
  66. * allocated.
  67. *
  68. * If the requested surface cannot be created, or the request is not a
  69. * supported configuration, nullptr will be returned.
  70. */
  71. static sk_sp<SkSpecialSurface> MakeRaster(const SkImageInfo&,
  72. const SkSurfaceProps* = nullptr);
  73. protected:
  74. SkSpecialSurface(const SkIRect& subset, const SkSurfaceProps*);
  75. // For testing only
  76. friend class TestingSpecialSurfaceAccess;
  77. const SkIRect& subset() const { return fSubset; }
  78. private:
  79. const SkSurfaceProps fProps;
  80. const SkIRect fSubset;
  81. typedef SkRefCnt INHERITED;
  82. };
  83. #endif