Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: src/gpu/GrResourceCache2.cpp

Issue 608883003: GrResourceCache2 manages scratch texture. (Closed) Base URL: https://skia.googlesource.com/skia.git@surfimpl
Patch Set: fix and document hack Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #include "GrResourceCache2.h" 10 #include "GrResourceCache2.h"
11 #include "GrGpuResource.h" 11 #include "GrGpuResource.h"
12 #include "SkRefCnt.h"
12 13
13 GrResourceCache2::~GrResourceCache2() { 14 GrResourceCache2::~GrResourceCache2() {
14 this->releaseAll(); 15 this->releaseAll();
15 } 16 }
16 17
17 void GrResourceCache2::insertResource(GrGpuResource* resource) { 18 void GrResourceCache2::insertResource(GrGpuResource* resource) {
18 SkASSERT(resource); 19 SkASSERT(resource);
19 SkASSERT(!resource->wasDestroyed()); 20 SkASSERT(!resource->wasDestroyed());
20 SkASSERT(!this->isInCache(resource)); 21 SkASSERT(!this->isInCache(resource));
21 fResources.addToHead(resource); 22 fResources.addToHead(resource);
(...skipping 26 matching lines...) Expand all
48 void GrResourceCache2::releaseAll() { 49 void GrResourceCache2::releaseAll() {
49 while (GrGpuResource* head = fResources.head()) { 50 while (GrGpuResource* head = fResources.head()) {
50 SkASSERT(!head->wasDestroyed()); 51 SkASSERT(!head->wasDestroyed());
51 head->release(); 52 head->release();
52 // release should have already removed this from the list. 53 // release should have already removed this from the list.
53 SkASSERT(head != fResources.head()); 54 SkASSERT(head != fResources.head());
54 } 55 }
55 SkASSERT(!fScratchMap.count()); 56 SkASSERT(!fScratchMap.count());
56 SkASSERT(!fCount); 57 SkASSERT(!fCount);
57 } 58 }
59
60 class GrResourceCache2::AvailableForScratchUse {
61 public:
62 AvailableForScratchUse(uint32_t internalFlags) : fFlags(internalFlags) { }
63
64 bool operator()(const GrGpuResource* resource) const {
65 if (fFlags) {
robertphillips 2014/10/07 13:59:34 f;ush ?
bsalomon 2014/10/07 14:20:13 Rewrote the comment. Changed from uint32_t fFlags
66 // If flags is set then this request is coming during draw buffer f; ush, in which
67 // case no refs, either by drawing code or for pending io operations , are allowed.
robertphillips 2014/10/07 13:59:34 Flags -> fFlags ?
bsalomon 2014/10/07 14:20:13 done (comment rewritten).
68 // Flags will be removed when flush no longer creates resources.
69 return resource->reffedOnlyByCache() && !resource->internalHasPendin gIO() &&
70 GrIORef::kYes_IsScratch == resource->fIsScratch;
71 } else {
72 // Because duties are currently shared between GrResourceCache and G rResourceCache2, the
73 // current interpretation of this rule is that only GrResourceCache has a ref but that
74 // it has been marked as a scratch resource.
75 return resource->reffedOnlyByCache() && GrIORef::kYes_IsScratch == r esource->fIsScratch;
76 }
77 }
78 private:
79 uint32_t fFlags;
80 };
81
82 GrGpuResource* GrResourceCache2::findAndRefScratchResource(const GrResourceKey& scratchKey,
83 uint32_t internalFlag s) {
84 SkASSERT(scratchKey.isScratch());
85 return SkSafeRef(fScratchMap.find(scratchKey, AvailableForScratchUse(interna lFlags)));
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698