OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_RESOURCE_PROVIDER_H_ | 5 #ifndef CC_RESOURCE_PROVIDER_H_ |
6 #define CC_RESOURCE_PROVIDER_H_ | 6 #define CC_RESOURCE_PROVIDER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 // NOTE: if the syncPoint filed in TransferableResourceList is set, this | 125 // NOTE: if the syncPoint filed in TransferableResourceList is set, this |
126 // will wait on it. | 126 // will wait on it. |
127 void receiveFromChild(int child, const TransferableResourceList&); | 127 void receiveFromChild(int child, const TransferableResourceList&); |
128 | 128 |
129 // Receives resources from the parent, moving them from mailboxes. Resource
IDs | 129 // Receives resources from the parent, moving them from mailboxes. Resource
IDs |
130 // passed are in the child namespace. | 130 // passed are in the child namespace. |
131 // NOTE: if the syncPoint filed in TransferableResourceList is set, this | 131 // NOTE: if the syncPoint filed in TransferableResourceList is set, this |
132 // will wait on it. | 132 // will wait on it. |
133 void receiveFromParent(const TransferableResourceList&); | 133 void receiveFromParent(const TransferableResourceList&); |
134 | 134 |
| 135 // Bind the given GL resource to a texture target for sampling using the |
| 136 // specified filter for both minification and magnification. The resource |
| 137 // must be locked for reading. |
| 138 void bindForSampling(ResourceProvider::ResourceId, GLenum target, GLenum fil
ter); |
| 139 |
135 // The following lock classes are part of the ResourceProvider API and are | 140 // The following lock classes are part of the ResourceProvider API and are |
136 // needed to read and write the resource contents. The user must ensure | 141 // needed to read and write the resource contents. The user must ensure |
137 // that they only use GL locks on GL resources, etc, and this is enforced | 142 // that they only use GL locks on GL resources, etc, and this is enforced |
138 // by assertions. | 143 // by assertions. |
139 class CC_EXPORT ScopedReadLockGL { | 144 class CC_EXPORT ScopedReadLockGL { |
140 public: | 145 public: |
141 ScopedReadLockGL(ResourceProvider*, ResourceProvider::ResourceId); | 146 ScopedReadLockGL(ResourceProvider*, ResourceProvider::ResourceId); |
142 ~ScopedReadLockGL(); | 147 ~ScopedReadLockGL(); |
143 | 148 |
144 unsigned textureId() const { return m_textureId; } | 149 unsigned textureId() const { return m_textureId; } |
145 | 150 |
146 private: | 151 private: |
147 ResourceProvider* m_resourceProvider; | 152 ResourceProvider* m_resourceProvider; |
148 ResourceProvider::ResourceId m_resourceId; | 153 ResourceProvider::ResourceId m_resourceId; |
149 unsigned m_textureId; | 154 unsigned m_textureId; |
150 | 155 |
151 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); | 156 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); |
152 }; | 157 }; |
153 | 158 |
| 159 class CC_EXPORT ScopedSamplerGL : public ScopedReadLockGL { |
| 160 public: |
| 161 ScopedSamplerGL(ResourceProvider*, ResourceProvider::ResourceId, GLenum
target, GLenum filter); |
| 162 |
| 163 private: |
| 164 DISALLOW_COPY_AND_ASSIGN(ScopedSamplerGL); |
| 165 }; |
| 166 |
154 class CC_EXPORT ScopedWriteLockGL { | 167 class CC_EXPORT ScopedWriteLockGL { |
155 public: | 168 public: |
156 ScopedWriteLockGL(ResourceProvider*, ResourceProvider::ResourceId); | 169 ScopedWriteLockGL(ResourceProvider*, ResourceProvider::ResourceId); |
157 ~ScopedWriteLockGL(); | 170 ~ScopedWriteLockGL(); |
158 | 171 |
159 unsigned textureId() const { return m_textureId; } | 172 unsigned textureId() const { return m_textureId; } |
160 | 173 |
161 private: | 174 private: |
162 ResourceProvider* m_resourceProvider; | 175 ResourceProvider* m_resourceProvider; |
163 ResourceProvider::ResourceId m_resourceId; | 176 ResourceProvider::ResourceId m_resourceId; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // Map/unmap the acquired pixel buffer. | 218 // Map/unmap the acquired pixel buffer. |
206 uint8_t* mapPixelBuffer(ResourceId id); | 219 uint8_t* mapPixelBuffer(ResourceId id); |
207 void unmapPixelBuffer(ResourceId id); | 220 void unmapPixelBuffer(ResourceId id); |
208 | 221 |
209 // Update pixels from acquired pixel buffer. | 222 // Update pixels from acquired pixel buffer. |
210 void setPixelsFromBuffer(ResourceId id); | 223 void setPixelsFromBuffer(ResourceId id); |
211 | 224 |
212 private: | 225 private: |
213 struct Resource { | 226 struct Resource { |
214 Resource(); | 227 Resource(); |
215 Resource(unsigned textureId, int pool, const gfx::Size& size, GLenum for
mat); | 228 Resource(unsigned textureId, int pool, const gfx::Size& size, GLenum for
mat, GLenum filter); |
216 Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format
); | 229 Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format
, GLenum filter); |
217 | 230 |
218 unsigned glId; | 231 unsigned glId; |
219 // Pixel buffer used for set pixels without unnecessary copying. | 232 // Pixel buffer used for set pixels without unnecessary copying. |
220 unsigned glPixelBufferId; | 233 unsigned glPixelBufferId; |
221 Mailbox mailbox; | 234 Mailbox mailbox; |
222 uint8_t* pixels; | 235 uint8_t* pixels; |
223 uint8_t* pixelBuffer; | 236 uint8_t* pixelBuffer; |
224 int pool; | 237 int pool; |
225 int lockForReadCount; | 238 int lockForReadCount; |
226 bool lockedForWrite; | 239 bool lockedForWrite; |
227 bool external; | 240 bool external; |
228 bool exported; | 241 bool exported; |
229 bool markedForDeletion; | 242 bool markedForDeletion; |
230 gfx::Size size; | 243 gfx::Size size; |
231 GLenum format; | 244 GLenum format; |
| 245 // TODO(skyostil): Use a separate sampler object for filter state. |
| 246 GLenum filter; |
232 ResourceType type; | 247 ResourceType type; |
233 }; | 248 }; |
234 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 249 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
235 struct Child { | 250 struct Child { |
236 Child(); | 251 Child(); |
237 ~Child(); | 252 ~Child(); |
238 | 253 |
239 int pool; | 254 int pool; |
240 ResourceIdMap childToParentMap; | 255 ResourceIdMap childToParentMap; |
241 ResourceIdMap parentToChildMap; | 256 ResourceIdMap parentToChildMap; |
(...skipping 27 matching lines...) Expand all Loading... |
269 int m_maxTextureSize; | 284 int m_maxTextureSize; |
270 | 285 |
271 base::ThreadChecker m_threadChecker; | 286 base::ThreadChecker m_threadChecker; |
272 | 287 |
273 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 288 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
274 }; | 289 }; |
275 | 290 |
276 } | 291 } |
277 | 292 |
278 #endif // CC_RESOURCE_PROVIDER_H_ | 293 #endif // CC_RESOURCE_PROVIDER_H_ |
OLD | NEW |