SkBitmapCache.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 SkBitmapCache_DEFINED
  8. #define SkBitmapCache_DEFINED
  9. #include "include/core/SkRect.h"
  10. #include <memory>
  11. class SkBitmap;
  12. class SkBitmapProvider;
  13. class SkImage;
  14. struct SkImageInfo;
  15. class SkMipMap;
  16. class SkPixmap;
  17. class SkResourceCache;
  18. uint64_t SkMakeResourceCacheSharedIDForBitmap(uint32_t bitmapGenID);
  19. void SkNotifyBitmapGenIDIsStale(uint32_t bitmapGenID);
  20. struct SkBitmapCacheDesc {
  21. uint32_t fImageID; // != 0
  22. SkIRect fSubset; // always set to a valid rect (entire or subset)
  23. void validate() const {
  24. SkASSERT(fImageID);
  25. SkASSERT(fSubset.fLeft >= 0 && fSubset.fTop >= 0);
  26. SkASSERT(fSubset.width() > 0 && fSubset.height() > 0);
  27. }
  28. static SkBitmapCacheDesc Make(const SkImage*);
  29. static SkBitmapCacheDesc Make(uint32_t genID, const SkIRect& subset);
  30. };
  31. class SkBitmapCache {
  32. public:
  33. /**
  34. * Search based on the desc. If found, returns true and
  35. * result will be set to the matching bitmap with its pixels already locked.
  36. */
  37. static bool Find(const SkBitmapCacheDesc&, SkBitmap* result);
  38. class Rec;
  39. struct RecDeleter { void operator()(Rec* r) { PrivateDeleteRec(r); } };
  40. typedef std::unique_ptr<Rec, RecDeleter> RecPtr;
  41. static RecPtr Alloc(const SkBitmapCacheDesc&, const SkImageInfo&, SkPixmap*);
  42. static void Add(RecPtr, SkBitmap*);
  43. private:
  44. static void PrivateDeleteRec(Rec*);
  45. };
  46. class SkMipMapCache {
  47. public:
  48. static const SkMipMap* FindAndRef(const SkBitmapCacheDesc&,
  49. SkResourceCache* localCache = nullptr);
  50. static const SkMipMap* AddAndRef(const SkBitmapProvider&,
  51. SkResourceCache* localCache = nullptr);
  52. };
  53. #endif