blob: a365a5aec77f06c28551b19e3bfe8fc2b7bfb840 [file] [log] [blame]
bsalomonc8dc1f72014-08-21 13:02:13 -07001
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef GrResourceCache2_DEFINED
10#define GrResourceCache2_DEFINED
11
bsalomon744998e2014-08-28 09:54:34 -070012#include "GrGpuResource.h"
13#include "GrResourceKey.h"
bsalomonc8dc1f72014-08-21 13:02:13 -070014#include "SkTInternalLList.h"
bsalomon744998e2014-08-28 09:54:34 -070015#include "SkTMultiMap.h"
bsalomonc8dc1f72014-08-21 13:02:13 -070016
17/**
18 * Eventual replacement for GrResourceCache. Currently it simply holds a list
19 * of all GrGpuResource objects for a GrContext. It is used to invalidate all
20 * the resources when necessary.
21 */
22class GrResourceCache2 {
23public:
24 GrResourceCache2() : fCount(0) {};
25 ~GrResourceCache2();
26
bsalomonbcf0a522014-10-08 08:40:09 -070027 void insertResource(GrGpuResource*);
bsalomonc8dc1f72014-08-21 13:02:13 -070028
bsalomonbcf0a522014-10-08 08:40:09 -070029 void removeResource(GrGpuResource*);
bsalomonc8dc1f72014-08-21 13:02:13 -070030
31 void abandonAll();
32
33 void releaseAll();
34
bsalomon000f8292014-10-15 19:04:14 -070035 enum {
36 /** Preferentially returns scratch resources with no pending IO. */
37 kPreferNoPendingIO_ScratchFlag = 0x1,
38 /** Will not return any resources that match but have pending IO. */
39 kRequireNoPendingIO_ScratchFlag = 0x2,
40 };
41 GrGpuResource* findAndRefScratchResource(const GrResourceKey& scratchKey, uint32_t flags = 0);
bsalomonbcf0a522014-10-08 08:40:09 -070042
bsalomonc8dc1f72014-08-21 13:02:13 -070043private:
bsalomon16961262014-08-26 14:01:07 -070044#ifdef SK_DEBUG
bsalomon37dd3312014-11-03 08:47:23 -080045 bool isInCache(const GrGpuResource* r) const { return fResources.isInList(r); }
bsalomon16961262014-08-26 14:01:07 -070046#endif
47
bsalomonbcf0a522014-10-08 08:40:09 -070048 class AvailableForScratchUse;
bsalomon744998e2014-08-28 09:54:34 -070049
bsalomon744998e2014-08-28 09:54:34 -070050 struct ScratchMapTraits {
51 static const GrResourceKey& GetKey(const GrGpuResource& r) {
52 return r.getScratchKey();
53 }
54
55 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); }
56 };
57 typedef SkTMultiMap<GrGpuResource, GrResourceKey, ScratchMapTraits> ScratchMap;
58
59 int fCount;
60 SkTInternalLList<GrGpuResource> fResources;
61 // This map holds all resources that can be used as scratch resources.
62 ScratchMap fScratchMap;
bsalomonc8dc1f72014-08-21 13:02:13 -070063};
64
65#endif