decode_stashing_image_provider.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CC_PAINT_DECODE_STASHING_IMAGE_PROVIDER_H_
  5. #define CC_PAINT_DECODE_STASHING_IMAGE_PROVIDER_H_
  6. #include "base/containers/stack_container.h"
  7. #include "cc/paint/image_provider.h"
  8. #include "cc/paint/paint_export.h"
  9. namespace cc {
  10. // An ImageProvider that passes decode requests through to the
  11. // |source_provider| but keeps the decode cached throughtout its lifetime,
  12. // instead of passing the ref to the caller.
  13. class CC_PAINT_EXPORT DecodeStashingImageProvider : public ImageProvider {
  14. public:
  15. // |source_provider| must outlive this class.
  16. explicit DecodeStashingImageProvider(ImageProvider* source_provider);
  17. DecodeStashingImageProvider(const DecodeStashingImageProvider&) = delete;
  18. ~DecodeStashingImageProvider() override;
  19. DecodeStashingImageProvider& operator=(const DecodeStashingImageProvider&) =
  20. delete;
  21. // ImageProvider implementation.
  22. ImageProvider::ScopedResult GetRasterContent(
  23. const DrawImage& draw_image) override;
  24. // Releases all stashed images. The caller must ensure that it is safe to
  25. // unlock any images acquired before this.
  26. void Reset();
  27. private:
  28. ImageProvider* source_provider_;
  29. base::StackVector<ScopedResult, 1> decoded_images_;
  30. };
  31. } // namespace cc
  32. #endif // CC_PAINT_DECODE_STASHING_IMAGE_PROVIDER_H_