GrGradientBitmapCache.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 GrGradientBitmapCache_DEFINED
  8. #define GrGradientBitmapCache_DEFINED
  9. #include "include/core/SkBitmap.h"
  10. #include "include/private/SkColorData.h"
  11. #include "include/private/SkMutex.h"
  12. #include "include/private/SkNoncopyable.h"
  13. class GrGradientBitmapCache : SkNoncopyable {
  14. public:
  15. GrGradientBitmapCache(int maxEntries, int resolution);
  16. ~GrGradientBitmapCache();
  17. // Assumes colors are compatible with the specified alphaType (e.g. if it's premul then colors
  18. // are already premultiplied). Thread safe.
  19. void getGradient(const SkPMColor4f* colors, const SkScalar* positions, int count,
  20. SkColorType colorType, SkAlphaType alphaType, SkBitmap* bitmap);
  21. private:
  22. SkMutex fMutex;
  23. int fEntryCount;
  24. const int fMaxEntries;
  25. const int fResolution;
  26. struct Entry;
  27. mutable Entry* fHead;
  28. mutable Entry* fTail;
  29. inline Entry* release(Entry*) const;
  30. inline void attachToHead(Entry*) const;
  31. bool find(const void* buffer, size_t len, SkBitmap*) const;
  32. void add(const void* buffer, size_t len, const SkBitmap&);
  33. void fillGradient(const SkPMColor4f* colors, const SkScalar* positions, int count,
  34. SkColorType colorType, SkBitmap* bitmap);
  35. #ifdef SK_DEBUG
  36. void validate() const;
  37. #else
  38. void validate() const {}
  39. #endif
  40. class AutoValidate : SkNoncopyable {
  41. public:
  42. AutoValidate(const GrGradientBitmapCache* bc) : fBC(bc) { bc->validate(); }
  43. ~AutoValidate() { fBC->validate(); }
  44. private:
  45. const GrGradientBitmapCache* fBC;
  46. };
  47. };
  48. #endif