OLD | NEW |
| (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 "CCPrioritizedTexture.h" | |
8 | |
9 #include "CCPrioritizedTextureManager.h" | |
10 #include "CCPriorityCalculator.h" | |
11 #include "CCProxy.h" | |
12 #include <algorithm> | |
13 | |
14 using namespace std; | |
15 | |
16 namespace cc { | |
17 | |
18 CCPrioritizedTexture::CCPrioritizedTexture(CCPrioritizedTextureManager* manager,
IntSize size, GC3Denum format) | |
19 : m_size(size) | |
20 , m_format(format) | |
21 , m_bytes(0) | |
22 , m_priority(CCPriorityCalculator::lowestPriority()) | |
23 , m_isAbovePriorityCutoff(false) | |
24 , m_isSelfManaged(false) | |
25 , m_backing(0) | |
26 , m_manager(0) | |
27 { | |
28 // m_manager is set in registerTexture() so validity can be checked. | |
29 ASSERT(format || size.isEmpty()); | |
30 if (format) | |
31 m_bytes = CCTexture::memorySizeBytes(size, format); | |
32 if (manager) | |
33 manager->registerTexture(this); | |
34 } | |
35 | |
36 CCPrioritizedTexture::~CCPrioritizedTexture() | |
37 { | |
38 if (m_manager) | |
39 m_manager->unregisterTexture(this); | |
40 } | |
41 | |
42 void CCPrioritizedTexture::setTextureManager(CCPrioritizedTextureManager* manage
r) | |
43 { | |
44 if (m_manager == manager) | |
45 return; | |
46 if (m_manager) | |
47 m_manager->unregisterTexture(this); | |
48 if (manager) | |
49 manager->registerTexture(this); | |
50 } | |
51 | |
52 void CCPrioritizedTexture::setDimensions(IntSize size, GC3Denum format) | |
53 { | |
54 if (m_format != format || m_size != size) { | |
55 m_isAbovePriorityCutoff = false; | |
56 m_format = format; | |
57 m_size = size; | |
58 m_bytes = CCTexture::memorySizeBytes(size, format); | |
59 ASSERT(m_manager || !m_backing); | |
60 if (m_manager) | |
61 m_manager->returnBackingTexture(this); | |
62 } | |
63 } | |
64 | |
65 bool CCPrioritizedTexture::requestLate() | |
66 { | |
67 if (!m_manager) | |
68 return false; | |
69 return m_manager->requestLate(this); | |
70 } | |
71 | |
72 bool CCPrioritizedTexture::backingResourceWasEvicted() const | |
73 { | |
74 return m_backing ? m_backing->resourceHasBeenDeleted() : false; | |
75 } | |
76 | |
77 void CCPrioritizedTexture::acquireBackingTexture(CCResourceProvider* resourcePro
vider) | |
78 { | |
79 ASSERT(m_isAbovePriorityCutoff); | |
80 if (m_isAbovePriorityCutoff) | |
81 m_manager->acquireBackingTextureIfNeeded(this, resourceProvider); | |
82 } | |
83 | |
84 CCResourceProvider::ResourceId CCPrioritizedTexture::resourceId() const | |
85 { | |
86 if (m_backing) | |
87 return m_backing->id(); | |
88 return 0; | |
89 } | |
90 | |
91 void CCPrioritizedTexture::upload(CCResourceProvider* resourceProvider, | |
92 const uint8_t* image, const IntRect& imageRect
, | |
93 const IntRect& sourceRect, const IntSize& dest
Offset) | |
94 { | |
95 ASSERT(m_isAbovePriorityCutoff); | |
96 if (m_isAbovePriorityCutoff) | |
97 acquireBackingTexture(resourceProvider); | |
98 ASSERT(m_backing); | |
99 resourceProvider->upload(resourceId(), image, imageRect, sourceRect, destOff
set); | |
100 } | |
101 | |
102 void CCPrioritizedTexture::link(Backing* backing) | |
103 { | |
104 ASSERT(backing); | |
105 ASSERT(!backing->m_owner); | |
106 ASSERT(!m_backing); | |
107 | |
108 m_backing = backing; | |
109 m_backing->m_owner = this; | |
110 } | |
111 | |
112 void CCPrioritizedTexture::unlink() | |
113 { | |
114 ASSERT(m_backing); | |
115 ASSERT(m_backing->m_owner == this); | |
116 | |
117 m_backing->m_owner = 0; | |
118 m_backing = 0; | |
119 } | |
120 | |
121 void CCPrioritizedTexture::setToSelfManagedMemoryPlaceholder(size_t bytes) | |
122 { | |
123 setDimensions(IntSize(), GraphicsContext3D::RGBA); | |
124 setIsSelfManaged(true); | |
125 m_bytes = bytes; | |
126 } | |
127 | |
128 CCPrioritizedTexture::Backing::Backing(unsigned id, CCResourceProvider* resource
Provider, IntSize size, GC3Denum format) | |
129 : CCTexture(id, size, format) | |
130 , m_owner(0) | |
131 , m_priorityAtLastPriorityUpdate(CCPriorityCalculator::lowestPriority()) | |
132 , m_ownerExistedAtLastPriorityUpdate(false) | |
133 , m_wasAbovePriorityCutoffAtLastPriorityUpdate(false) | |
134 , m_resourceHasBeenDeleted(false) | |
135 #ifndef NDEBUG | |
136 , m_resourceProvider(resourceProvider) | |
137 #endif | |
138 { | |
139 } | |
140 | |
141 CCPrioritizedTexture::Backing::~Backing() | |
142 { | |
143 ASSERT(!m_owner); | |
144 ASSERT(m_resourceHasBeenDeleted); | |
145 } | |
146 | |
147 void CCPrioritizedTexture::Backing::deleteResource(CCResourceProvider* resourceP
rovider) | |
148 { | |
149 ASSERT(CCProxy::isImplThread()); | |
150 ASSERT(!m_resourceHasBeenDeleted); | |
151 #ifndef NDEBUG | |
152 ASSERT(resourceProvider == m_resourceProvider); | |
153 #endif | |
154 | |
155 resourceProvider->deleteResource(id()); | |
156 setId(0); | |
157 m_resourceHasBeenDeleted = true; | |
158 } | |
159 | |
160 bool CCPrioritizedTexture::Backing::resourceHasBeenDeleted() const | |
161 { | |
162 ASSERT(CCProxy::isImplThread()); | |
163 return m_resourceHasBeenDeleted; | |
164 } | |
165 | |
166 void CCPrioritizedTexture::Backing::updatePriority() | |
167 { | |
168 ASSERT(CCProxy::isImplThread() && CCProxy::isMainThreadBlocked()); | |
169 if (m_owner) { | |
170 m_ownerExistedAtLastPriorityUpdate = true; | |
171 m_priorityAtLastPriorityUpdate = m_owner->requestPriority(); | |
172 m_wasAbovePriorityCutoffAtLastPriorityUpdate = m_owner->isAbovePriorityC
utoff(); | |
173 } else { | |
174 m_ownerExistedAtLastPriorityUpdate = false; | |
175 m_priorityAtLastPriorityUpdate = CCPriorityCalculator::lowestPriority(); | |
176 m_wasAbovePriorityCutoffAtLastPriorityUpdate = false; | |
177 } | |
178 } | |
179 | |
180 } // namespace cc | |
OLD | NEW |