paint_cache.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2015 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 UI_COMPOSITOR_PAINT_CACHE_H_
  5. #define UI_COMPOSITOR_PAINT_CACHE_H_
  6. #include "third_party/skia/include/core/SkRefCnt.h"
  7. #include "ui/compositor/compositor_export.h"
  8. #include "ui/gfx/geometry/rect.h"
  9. namespace cc {
  10. class PaintOpBuffer;
  11. }
  12. namespace ui {
  13. class PaintContext;
  14. class PaintRecorder;
  15. // A class that holds the output of a PaintRecorder to be reused when the
  16. // object that created the PaintRecorder has not been changed/invalidated.
  17. class COMPOSITOR_EXPORT PaintCache {
  18. public:
  19. PaintCache();
  20. PaintCache(const PaintCache&) = delete;
  21. PaintCache& operator=(const PaintCache&) = delete;
  22. ~PaintCache();
  23. // Returns true if the PaintCache was able to insert a previously-saved
  24. // painting output into the PaintContext. If it returns false, the caller
  25. // needs to do the work of painting, which can be stored into the PaintCache
  26. // to be used next time.
  27. bool UseCache(const PaintContext& context, const gfx::Size& size_in_context);
  28. private:
  29. // Only PaintRecorder can modify these.
  30. friend PaintRecorder;
  31. void SetPaintOpBuffer(sk_sp<cc::PaintOpBuffer> paint_op_buffer,
  32. float device_scale_factor);
  33. // Stored in an sk_sp because PaintOpBuffer requires this to append the cached
  34. // items into it.
  35. sk_sp<cc::PaintOpBuffer> paint_op_buffer_;
  36. // This allows paint cache to be device scale factor aware. If a request for
  37. // a cache entry is made that does not match the stored cache entry's DSF,
  38. // then we can reject it instead of returning the incorrect cache entry.
  39. // See https://crbug.com/834114 for details.
  40. float device_scale_factor_ = 0.f;
  41. };
  42. } // namespace ui
  43. #endif // UI_COMPOSITOR_PAINT_CACHE_H_