GrSurface.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2012 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 GrSurface_DEFINED
  8. #define GrSurface_DEFINED
  9. #include "GrTypes.h"
  10. #include "GrBackendSurface.h"
  11. #include "GrGpuResource.h"
  12. #include "SkImageInfo.h"
  13. #include "SkRect.h"
  14. class GrRenderTarget;
  15. class GrSurfacePriv;
  16. class GrTexture;
  17. class SK_API GrSurface : public GrGpuResource {
  18. public:
  19. /**
  20. * Retrieves the width of the surface.
  21. */
  22. int width() const { return fWidth; }
  23. /**
  24. * Retrieves the height of the surface.
  25. */
  26. int height() const { return fHeight; }
  27. /**
  28. * Helper that gets the width and height of the surface as a bounding rectangle.
  29. */
  30. SkRect getBoundsRect() const { return SkRect::MakeIWH(this->width(), this->height()); }
  31. /**
  32. * Retrieves the pixel config specified when the surface was created.
  33. * For render targets this can be kUnknown_GrPixelConfig
  34. * if client asked us to render to a target that has a pixel
  35. * config that isn't equivalent with one of our configs.
  36. */
  37. GrPixelConfig config() const { return fConfig; }
  38. virtual GrBackendFormat backendFormat() const = 0;
  39. /**
  40. * @return the texture associated with the surface, may be null.
  41. */
  42. virtual GrTexture* asTexture() { return nullptr; }
  43. virtual const GrTexture* asTexture() const { return nullptr; }
  44. /**
  45. * @return the render target underlying this surface, may be null.
  46. */
  47. virtual GrRenderTarget* asRenderTarget() { return nullptr; }
  48. virtual const GrRenderTarget* asRenderTarget() const { return nullptr; }
  49. /** Access methods that are only to be used within Skia code. */
  50. inline GrSurfacePriv surfacePriv();
  51. inline const GrSurfacePriv surfacePriv() const;
  52. static size_t WorstCaseSize(const GrSurfaceDesc& desc, bool useNextPow2 = false);
  53. static size_t ComputeSize(GrPixelConfig config, int width, int height, int colorSamplesPerPixel,
  54. GrMipMapped, bool useNextPow2 = false);
  55. protected:
  56. void setHasMixedSamples() {
  57. SkASSERT(this->asRenderTarget());
  58. fSurfaceFlags |= GrInternalSurfaceFlags::kMixedSampled;
  59. }
  60. bool hasMixedSamples() const { return fSurfaceFlags & GrInternalSurfaceFlags::kMixedSampled; }
  61. void setSupportsWindowRects() {
  62. SkASSERT(this->asRenderTarget());
  63. fSurfaceFlags |= GrInternalSurfaceFlags::kWindowRectsSupport;
  64. }
  65. bool supportsWindowRects() const {
  66. return fSurfaceFlags & GrInternalSurfaceFlags::kWindowRectsSupport;
  67. }
  68. void setGLRTFBOIDIs0() {
  69. SkASSERT(this->asRenderTarget());
  70. fSurfaceFlags |= GrInternalSurfaceFlags::kGLRTFBOIDIs0;
  71. }
  72. bool glRTFBOIDis0() const {
  73. return fSurfaceFlags & GrInternalSurfaceFlags::kGLRTFBOIDIs0;
  74. }
  75. // Methods made available via GrSurfacePriv
  76. bool hasPendingRead() const;
  77. bool hasPendingWrite() const;
  78. bool hasPendingIO() const;
  79. // Provides access to methods that should be public within Skia code.
  80. friend class GrSurfacePriv;
  81. GrSurface(GrGpu* gpu, const GrSurfaceDesc& desc)
  82. : INHERITED(gpu)
  83. , fConfig(desc.fConfig)
  84. , fWidth(desc.fWidth)
  85. , fHeight(desc.fHeight)
  86. , fSurfaceFlags(GrInternalSurfaceFlags::kNone) {
  87. }
  88. ~GrSurface() override {}
  89. void onRelease() override;
  90. void onAbandon() override;
  91. private:
  92. const char* getResourceType() const override { return "Surface"; }
  93. GrPixelConfig fConfig;
  94. int fWidth;
  95. int fHeight;
  96. GrInternalSurfaceFlags fSurfaceFlags;
  97. typedef GrGpuResource INHERITED;
  98. };
  99. #endif