GrTexture.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Copyright 2011 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 GrTexture_DEFINED
  8. #define GrTexture_DEFINED
  9. #include "GrBackendSurface.h"
  10. #include "GrSamplerState.h"
  11. #include "GrSurface.h"
  12. #include "SkImage.h"
  13. #include "SkPoint.h"
  14. #include "SkRefCnt.h"
  15. #include "../private/GrTypesPriv.h"
  16. class GrTexturePriv;
  17. class GrTexture : virtual public GrSurface {
  18. public:
  19. GrTexture* asTexture() override { return this; }
  20. const GrTexture* asTexture() const override { return this; }
  21. virtual GrBackendTexture getBackendTexture() const = 0;
  22. /**
  23. * This function indicates that the texture parameters (wrap mode, filtering, ...) have been
  24. * changed externally to Skia.
  25. */
  26. virtual void textureParamsModified() = 0;
  27. /**
  28. * This function steals the backend texture from a uniquely owned GrTexture with no pending
  29. * IO, passing it out to the caller. The GrTexture is deleted in the process.
  30. *
  31. * Note that if the GrTexture is not uniquely owned (no other refs), or has pending IO, this
  32. * function will fail.
  33. */
  34. static bool StealBackendTexture(sk_sp<GrTexture>&&,
  35. GrBackendTexture*,
  36. SkImage::BackendTextureReleaseProc*);
  37. #ifdef SK_DEBUG
  38. void validate() const {
  39. this->INHERITED::validate();
  40. }
  41. #endif
  42. virtual void setRelease(sk_sp<GrReleaseProcHelper> releaseHelper) = 0;
  43. // These match the definitions in SkImage, from whence they came.
  44. // TODO: Either move Chrome over to new api or remove their need to call this on GrTexture
  45. typedef void* ReleaseCtx;
  46. typedef void (*ReleaseProc)(ReleaseCtx);
  47. void setRelease(ReleaseProc proc, ReleaseCtx ctx) {
  48. sk_sp<GrReleaseProcHelper> helper(new GrReleaseProcHelper(proc, ctx));
  49. this->setRelease(std::move(helper));
  50. }
  51. /** Access methods that are only to be used within Skia code. */
  52. inline GrTexturePriv texturePriv();
  53. inline const GrTexturePriv texturePriv() const;
  54. protected:
  55. GrTexture(GrGpu*, const GrSurfaceDesc&, GrTextureType, GrMipMapsStatus);
  56. virtual bool onStealBackendTexture(GrBackendTexture*, SkImage::BackendTextureReleaseProc*) = 0;
  57. private:
  58. void computeScratchKey(GrScratchKey*) const override;
  59. size_t onGpuMemorySize() const override;
  60. void markMipMapsDirty();
  61. void markMipMapsClean();
  62. GrTextureType fTextureType;
  63. GrMipMapsStatus fMipMapsStatus;
  64. int fMaxMipMapLevel;
  65. friend class GrTexturePriv;
  66. typedef GrSurface INHERITED;
  67. };
  68. #endif