forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathraster_cache.h
57 lines (42 loc) · 1.35 KB
/
raster_cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// 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 "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 RasterCache {
public:
RasterCache();
~RasterCache();
sk_sp<SkImage> GetPrerolledImage(GrContext* context,
SkPicture* picture,
const SkMatrix& ctm,
bool is_complex,
bool will_change);
void SweepAfterFrame();
void Clear();
void SetCheckboardCacheImages(bool checkerboard);
private:
struct Entry {
Entry();
~Entry();
bool used_this_frame = false;
int access_count = 0;
SkISize physical_size;
sk_sp<SkImage> image;
};
using Cache = std::unordered_map<uint32_t, Entry>;
Cache cache_;
bool checkerboard_images_;
ftl::WeakPtrFactory<RasterCache> weak_factory_;
FTL_DISALLOW_COPY_AND_ASSIGN(RasterCache);
};
} // namespace flow
#endif // FLUTTER_FLOW_RASTER_CACHE_H_