Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkImageFilterCache.h
Go to the documentation of this file.
1/*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkImageFilterCache_DEFINED
9#define SkImageFilterCache_DEFINED
10
12#include "include/core/SkRect.h"
16
17#include <cstddef>
18#include <cstdint>
19
20class SkImageFilter;
21namespace skif { class FilterResult; }
22
24 SkImageFilterCacheKey(const uint32_t uniqueID, const SkMatrix& matrix,
25 const SkIRect& clipBounds, uint32_t srcGenID, const SkIRect& srcSubset)
26 : fUniqueID(uniqueID)
27 , fMatrix(matrix)
28 , fClipBounds(clipBounds)
29 , fSrcGenID(srcGenID)
30 , fSrcSubset(srcSubset) {
31 // Assert that Key is tightly-packed, since it is hashed.
32 static_assert(sizeof(SkImageFilterCacheKey) == sizeof(uint32_t) + sizeof(SkMatrix) +
33 sizeof(SkIRect) + sizeof(uint32_t) + 4 * sizeof(int32_t),
34 "image_filter_key_tight_packing");
35 fMatrix.getType(); // force initialization of type, so hashes match
36 SkASSERT(fMatrix.isFinite()); // otherwise we can't rely on == self when comparing keys
37 }
38
39 uint32_t fUniqueID;
42 uint32_t fSrcGenID;
44
45 bool operator==(const SkImageFilterCacheKey& other) const {
46 return fUniqueID == other.fUniqueID &&
47 fMatrix == other.fMatrix &&
48 fClipBounds == other.fClipBounds &&
49 fSrcGenID == other.fSrcGenID &&
50 fSrcSubset == other.fSrcSubset;
51 }
52};
53
54// This cache maps from (filter's unique ID + CTM + clipBounds + src bitmap generation ID) to result
55// NOTE: this is the _specific_ unique ID of the image filter, so refiltering the same image with a
56// copy of the image filter (with exactly the same parameters) will not yield a cache hit.
58public:
59 static constexpr size_t kDefaultTransientSize = 32 * 1024 * 1024;
60
61 ~SkImageFilterCache() override {}
62 static sk_sp<SkImageFilterCache> Create(size_t maxBytes);
63
64 // Whether to create the cache if it doesn't yet exist.
65 enum class CreateIfNecessary : bool { kNo, kYes };
67
68 // Returns true on cache hit and updates 'result' to be the cached result. Returns false when
69 // not in the cache, in which case 'result' is not modified.
70 virtual bool get(const SkImageFilterCacheKey& key,
71 skif::FilterResult* result) const = 0;
72 // 'filter' is included in the caching to allow the purging of all of an image filter's cached
73 // results when it is destroyed.
74 virtual void set(const SkImageFilterCacheKey& key, const SkImageFilter* filter,
75 const skif::FilterResult& result) = 0;
76 virtual void purge() = 0;
77 virtual void purgeByImageFilter(const SkImageFilter*) = 0;
78 SkDEBUGCODE(virtual int count() const = 0;)
79};
80
81#endif
int count
static sk_sp< Effect > Create()
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
virtual bool get(const SkImageFilterCacheKey &key, skif::FilterResult *result) const =0
virtual void set(const SkImageFilterCacheKey &key, const SkImageFilter *filter, const skif::FilterResult &result)=0
virtual void purge()=0
static sk_sp< SkImageFilterCache > Get(CreateIfNecessary=CreateIfNecessary::kYes)
virtual void purgeByImageFilter(const SkImageFilter *)=0
static constexpr size_t kDefaultTransientSize
bool isFinite() const
Definition SkMatrix.h:1834
TypeMask getType() const
Definition SkMatrix.h:207
GAsyncResult * result
SkImageFilterCacheKey(const uint32_t uniqueID, const SkMatrix &matrix, const SkIRect &clipBounds, uint32_t srcGenID, const SkIRect &srcSubset)
bool operator==(const SkImageFilterCacheKey &other) const