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

Side by Side Diff: cc/prioritized_texture.cc

Issue 11369109: cc: Rename PrioritizedTexture to PrioritizedResource. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « cc/prioritized_texture.h ('k') | cc/prioritized_texture_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6
7 #include "cc/prioritized_texture.h"
8
9 #include "cc/platform_color.h"
10 #include "cc/prioritized_texture_manager.h"
11 #include "cc/priority_calculator.h"
12 #include "cc/proxy.h"
13 #include <algorithm>
14
15 using namespace std;
16
17 namespace cc {
18
19 PrioritizedTexture::PrioritizedTexture(PrioritizedTextureManager* manager, gfx:: Size size, GLenum format)
20 : m_size(size)
21 , m_format(format)
22 , m_bytes(0)
23 , m_contentsSwizzled(false)
24 , m_priority(PriorityCalculator::lowestPriority())
25 , m_isAbovePriorityCutoff(false)
26 , m_isSelfManaged(false)
27 , m_backing(0)
28 , m_manager(0)
29 {
30 // m_manager is set in registerTexture() so validity can be checked.
31 DCHECK(format || size.IsEmpty());
32 if (format)
33 m_bytes = Texture::memorySizeBytes(size, format);
34 if (manager)
35 manager->registerTexture(this);
36 }
37
38 PrioritizedTexture::~PrioritizedTexture()
39 {
40 if (m_manager)
41 m_manager->unregisterTexture(this);
42 }
43
44 void PrioritizedTexture::setTextureManager(PrioritizedTextureManager* manager)
45 {
46 if (m_manager == manager)
47 return;
48 if (m_manager)
49 m_manager->unregisterTexture(this);
50 if (manager)
51 manager->registerTexture(this);
52 }
53
54 void PrioritizedTexture::setDimensions(gfx::Size size, GLenum format)
55 {
56 if (m_format != format || m_size != size) {
57 m_isAbovePriorityCutoff = false;
58 m_format = format;
59 m_size = size;
60 m_bytes = Texture::memorySizeBytes(size, format);
61 DCHECK(m_manager || !m_backing);
62 if (m_manager)
63 m_manager->returnBackingTexture(this);
64 }
65 }
66
67 bool PrioritizedTexture::requestLate()
68 {
69 if (!m_manager)
70 return false;
71 return m_manager->requestLate(this);
72 }
73
74 bool PrioritizedTexture::backingResourceWasEvicted() const
75 {
76 return m_backing ? m_backing->resourceHasBeenDeleted() : false;
77 }
78
79 void PrioritizedTexture::acquireBackingTexture(ResourceProvider* resourceProvide r)
80 {
81 DCHECK(m_isAbovePriorityCutoff);
82 if (m_isAbovePriorityCutoff)
83 m_manager->acquireBackingTextureIfNeeded(this, resourceProvider);
84 }
85
86 ResourceProvider::ResourceId PrioritizedTexture::resourceId() const
87 {
88 if (m_backing)
89 return m_backing->id();
90 return 0;
91 }
92
93 void PrioritizedTexture::setPixels(ResourceProvider* resourceProvider,
94 const uint8_t* image, const gfx::Rect& imageR ect,
95 const gfx::Rect& sourceRect, const gfx::Vecto r2d& destOffset)
96 {
97 DCHECK(m_isAbovePriorityCutoff);
98 if (m_isAbovePriorityCutoff)
99 acquireBackingTexture(resourceProvider);
100 DCHECK(m_backing);
101 resourceProvider->setPixels(resourceId(), image, imageRect, sourceRect, dest Offset);
102
103 // The component order may be bgra if we uploaded bgra pixels to rgba
104 // texture. Mark contents as swizzled if image component order is
105 // different than texture format.
106 m_contentsSwizzled = !PlatformColor::sameComponentOrder(m_format);
107 }
108
109 void PrioritizedTexture::link(Backing* backing)
110 {
111 DCHECK(backing);
112 DCHECK(!backing->m_owner);
113 DCHECK(!m_backing);
114
115 m_backing = backing;
116 m_backing->m_owner = this;
117 }
118
119 void PrioritizedTexture::unlink()
120 {
121 DCHECK(m_backing);
122 DCHECK(m_backing->m_owner == this);
123
124 m_backing->m_owner = 0;
125 m_backing = 0;
126 }
127
128 void PrioritizedTexture::setToSelfManagedMemoryPlaceholder(size_t bytes)
129 {
130 setDimensions(gfx::Size(), GL_RGBA);
131 setIsSelfManaged(true);
132 m_bytes = bytes;
133 }
134
135 PrioritizedTexture::Backing::Backing(unsigned id, ResourceProvider* resourceProv ider, gfx::Size size, GLenum format)
136 : Texture(id, size, format)
137 , m_owner(0)
138 , m_priorityAtLastPriorityUpdate(PriorityCalculator::lowestPriority())
139 , m_wasAbovePriorityCutoffAtLastPriorityUpdate(false)
140 , m_inDrawingImplTree(false)
141 , m_resourceHasBeenDeleted(false)
142 #ifndef NDEBUG
143 , m_resourceProvider(resourceProvider)
144 #endif
145 {
146 }
147
148 PrioritizedTexture::Backing::~Backing()
149 {
150 DCHECK(!m_owner);
151 DCHECK(m_resourceHasBeenDeleted);
152 }
153
154 void PrioritizedTexture::Backing::deleteResource(ResourceProvider* resourceProvi der)
155 {
156 DCHECK(Proxy::isImplThread());
157 DCHECK(!m_resourceHasBeenDeleted);
158 #ifndef NDEBUG
159 DCHECK(resourceProvider == m_resourceProvider);
160 #endif
161
162 resourceProvider->deleteResource(id());
163 setId(0);
164 m_resourceHasBeenDeleted = true;
165 }
166
167 bool PrioritizedTexture::Backing::resourceHasBeenDeleted() const
168 {
169 DCHECK(Proxy::isImplThread());
170 return m_resourceHasBeenDeleted;
171 }
172
173 bool PrioritizedTexture::Backing::canBeRecycled() const
174 {
175 DCHECK(Proxy::isImplThread());
176 return !m_wasAbovePriorityCutoffAtLastPriorityUpdate && !m_inDrawingImplTree ;
177 }
178
179 void PrioritizedTexture::Backing::updatePriority()
180 {
181 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked());
182 if (m_owner) {
183 m_priorityAtLastPriorityUpdate = m_owner->requestPriority();
184 m_wasAbovePriorityCutoffAtLastPriorityUpdate = m_owner->isAbovePriorityC utoff();
185 } else {
186 m_priorityAtLastPriorityUpdate = PriorityCalculator::lowestPriority();
187 m_wasAbovePriorityCutoffAtLastPriorityUpdate = false;
188 }
189 }
190
191 void PrioritizedTexture::Backing::updateInDrawingImplTree()
192 {
193 DCHECK(Proxy::isImplThread() && Proxy::isMainThreadBlocked());
194 m_inDrawingImplTree = !!owner();
195 if (!m_inDrawingImplTree)
196 DCHECK(m_priorityAtLastPriorityUpdate == PriorityCalculator::lowestPrior ity());
197 }
198
199 void PrioritizedTexture::returnBackingTexture()
200 {
201 DCHECK(m_manager || !m_backing);
202 if (m_manager)
203 m_manager->returnBackingTexture(this);
204 }
205
206 } // namespace cc
OLDNEW
« no previous file with comments | « cc/prioritized_texture.h ('k') | cc/prioritized_texture_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698