mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
84 lines
2.2 KiB
C++
84 lines
2.2 KiB
C++
// Copyright 2016 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#ifndef FLUTTER_FLOW_RASTER_CACHE_H_
|
|
#define FLUTTER_FLOW_RASTER_CACHE_H_
|
|
|
|
#include <memory>
|
|
#include <unordered_map>
|
|
|
|
#include "flutter/flow/instrumentation.h"
|
|
#include "flutter/flow/raster_cache_key.h"
|
|
#include "lib/ftl/macros.h"
|
|
#include "lib/ftl/memory/weak_ptr.h"
|
|
#include "third_party/skia/include/core/SkImage.h"
|
|
#include "third_party/skia/include/core/SkSize.h"
|
|
|
|
namespace flow {
|
|
|
|
class RasterCacheResult {
|
|
public:
|
|
RasterCacheResult()
|
|
: source_rect_(SkRect::MakeEmpty()),
|
|
destination_rect_(SkRect::MakeEmpty()) {}
|
|
|
|
RasterCacheResult(sk_sp<SkImage> image, SkRect source, SkRect destination)
|
|
: image_(std::move(image)),
|
|
source_rect_(source),
|
|
destination_rect_(destination) {}
|
|
|
|
operator bool() const { return static_cast<bool>(image_); }
|
|
|
|
bool is_valid() const { return static_cast<bool>(image_); };
|
|
|
|
sk_sp<SkImage> image() const { return image_; }
|
|
|
|
const SkRect& source_rect() const { return source_rect_; }
|
|
|
|
const SkRect& destination_rect() const { return destination_rect_; }
|
|
|
|
private:
|
|
sk_sp<SkImage> image_;
|
|
SkRect source_rect_;
|
|
SkRect destination_rect_;
|
|
};
|
|
|
|
class RasterCache {
|
|
public:
|
|
explicit RasterCache(size_t threshold = 3);
|
|
|
|
~RasterCache();
|
|
|
|
RasterCacheResult GetPrerolledImage(GrContext* context,
|
|
SkPicture* picture,
|
|
const SkMatrix& transformation_matrix,
|
|
SkColorSpace* dst_color_space,
|
|
bool is_complex,
|
|
bool will_change);
|
|
|
|
void SweepAfterFrame();
|
|
|
|
void Clear();
|
|
|
|
void SetCheckboardCacheImages(bool checkerboard);
|
|
|
|
private:
|
|
struct Entry {
|
|
bool used_this_frame = false;
|
|
size_t access_count = 0;
|
|
RasterCacheResult image;
|
|
};
|
|
|
|
const size_t threshold_;
|
|
RasterCacheKey::Map<Entry> cache_;
|
|
bool checkerboard_images_;
|
|
ftl::WeakPtrFactory<RasterCache> weak_factory_;
|
|
|
|
FTL_DISALLOW_COPY_AND_ASSIGN(RasterCache);
|
|
};
|
|
|
|
} // namespace flow
|
|
|
|
#endif // FLUTTER_FLOW_RASTER_CACHE_H_
|