SkBitmapProvider.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright 2015 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 SkBitmapProvider_DEFINED
  8. #define SkBitmapProvider_DEFINED
  9. #include "include/core/SkImage.h"
  10. #include "src/core/SkBitmapCache.h"
  11. class SkBitmapProvider {
  12. public:
  13. explicit SkBitmapProvider(const SkImage* img)
  14. : fImage(img) {
  15. SkASSERT(img);
  16. }
  17. SkBitmapProvider(const SkBitmapProvider& other)
  18. : fImage(other.fImage)
  19. {}
  20. SkBitmapCacheDesc makeCacheDesc() const;
  21. void notifyAddedToCache() const;
  22. // Only call this if you're sure you need the bits, since it maybe expensive
  23. // ... cause a decode and cache, or gpu-readback
  24. bool asBitmap(SkBitmap*) const;
  25. private:
  26. // Stack-allocated only.
  27. void* operator new(size_t) = delete;
  28. void* operator new(size_t, void*) = delete;
  29. // SkBitmapProvider is always short-lived/stack allocated, and the source image is guaranteed
  30. // to outlive its scope => we can store a raw ptr to avoid ref churn.
  31. const SkImage* fImage;
  32. };
  33. #endif