paint_cache.cc 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  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. #include "ui/compositor/paint_cache.h"
  5. #include "cc/paint/display_item_list.h"
  6. #include "cc/paint/paint_op_buffer.h"
  7. #include "ui/compositor/paint_context.h"
  8. namespace ui {
  9. PaintCache::PaintCache() = default;
  10. PaintCache::~PaintCache() = default;
  11. bool PaintCache::UseCache(const PaintContext& context,
  12. const gfx::Size& size_in_context) {
  13. if (!paint_op_buffer_ ||
  14. context.device_scale_factor() != device_scale_factor_) {
  15. return false;
  16. }
  17. DCHECK(context.list_);
  18. context.list_->StartPaint();
  19. context.list_->push<cc::DrawRecordOp>(paint_op_buffer_);
  20. gfx::Rect bounds_in_layer = context.ToLayerSpaceBounds(size_in_context);
  21. context.list_->EndPaintOfUnpaired(bounds_in_layer);
  22. return true;
  23. }
  24. void PaintCache::SetPaintOpBuffer(sk_sp<cc::PaintOpBuffer> paint_op_buffer,
  25. float device_scale_factor) {
  26. paint_op_buffer_ = std::move(paint_op_buffer);
  27. device_scale_factor_ = device_scale_factor;
  28. }
  29. } // namespace ui