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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 uint8_t* mapPixelBuffer(ResourceId id); | 223 uint8_t* mapPixelBuffer(ResourceId id); |
224 void unmapPixelBuffer(ResourceId id); | 224 void unmapPixelBuffer(ResourceId id); |
225 | 225 |
226 // Update pixels from acquired pixel buffer. | 226 // Update pixels from acquired pixel buffer. |
227 void setPixelsFromBuffer(ResourceId id); | 227 void setPixelsFromBuffer(ResourceId id); |
228 | 228 |
229 // Asynchronously update pixels from acquired pixel buffer. | 229 // Asynchronously update pixels from acquired pixel buffer. |
230 void beginSetPixels(ResourceId id); | 230 void beginSetPixels(ResourceId id); |
231 bool didSetPixelsComplete(ResourceId id); | 231 bool didSetPixelsComplete(ResourceId id); |
232 | 232 |
233 // For tests only! This prevents detecting uninitialized reads. | |
234 // Use setPixels or lockForWrite to allocate implicitly. | |
235 void allocateForTesting(ResourceId id); | |
236 | |
237 private: | 233 private: |
238 struct Resource { | 234 struct Resource { |
239 Resource(); | 235 Resource(); |
240 Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenu
m filter); | 236 Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenu
m filter); |
241 Resource(uint8_t* pixels, const gfx::Size& size, GLenum format, GLenum f
ilter); | 237 Resource(uint8_t* pixels, const gfx::Size& size, GLenum format, GLenum f
ilter); |
242 | 238 |
243 unsigned glId; | 239 unsigned glId; |
244 // Pixel buffer used for set pixels without unnecessary copying. | 240 // Pixel buffer used for set pixels without unnecessary copying. |
245 unsigned glPixelBufferId; | 241 unsigned glPixelBufferId; |
246 // Query used to determine when asynchronous set pixels complete. | 242 // Query used to determine when asynchronous set pixels complete. |
247 unsigned glUploadQueryId; | 243 unsigned glUploadQueryId; |
248 Mailbox mailbox; | 244 Mailbox mailbox; |
249 uint8_t* pixels; | 245 uint8_t* pixels; |
250 uint8_t* pixelBuffer; | 246 uint8_t* pixelBuffer; |
251 int lockForReadCount; | 247 int lockForReadCount; |
252 bool lockedForWrite; | 248 bool lockedForWrite; |
253 bool external; | 249 bool external; |
254 bool exported; | 250 bool exported; |
255 bool markedForDeletion; | 251 bool markedForDeletion; |
256 bool pendingSetPixels; | 252 bool pendingSetPixels; |
257 bool allocated; | |
258 gfx::Size size; | 253 gfx::Size size; |
259 GLenum format; | 254 GLenum format; |
260 // TODO(skyostil): Use a separate sampler object for filter state. | 255 // TODO(skyostil): Use a separate sampler object for filter state. |
261 GLenum filter; | 256 GLenum filter; |
262 ResourceType type; | 257 ResourceType type; |
263 }; | 258 }; |
264 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 259 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
265 struct Child { | 260 struct Child { |
266 Child(); | 261 Child(); |
267 ~Child(); | 262 ~Child(); |
268 | 263 |
269 ResourceIdMap childToParentMap; | 264 ResourceIdMap childToParentMap; |
270 ResourceIdMap parentToChildMap; | 265 ResourceIdMap parentToChildMap; |
271 }; | 266 }; |
272 typedef base::hash_map<int, Child> ChildMap; | 267 typedef base::hash_map<int, Child> ChildMap; |
273 | 268 |
274 explicit ResourceProvider(OutputSurface*); | 269 explicit ResourceProvider(OutputSurface*); |
275 bool initialize(); | 270 bool initialize(); |
276 | 271 |
277 const Resource* lockForRead(ResourceId); | 272 const Resource* lockForRead(ResourceId); |
278 void unlockForRead(ResourceId); | 273 void unlockForRead(ResourceId); |
279 const Resource* lockForWrite(ResourceId); | 274 const Resource* lockForWrite(ResourceId); |
280 void unlockForWrite(ResourceId); | 275 void unlockForWrite(ResourceId); |
281 static void populateSkBitmapWithResource(SkBitmap*, const Resource*); | 276 static void populateSkBitmapWithResource(SkBitmap*, const Resource*); |
282 | 277 |
283 bool transferResource(WebKit::WebGraphicsContext3D*, ResourceId, Transferabl
eResource*); | 278 bool transferResource(WebKit::WebGraphicsContext3D*, ResourceId, Transferabl
eResource*); |
284 void deleteResourceInternal(ResourceMap::iterator it); | 279 void deleteResourceInternal(ResourceMap::iterator it); |
285 void lazyAllocate(Resource*); | |
286 | 280 |
287 OutputSurface* m_outputSurface; | 281 OutputSurface* m_outputSurface; |
288 ResourceId m_nextId; | 282 ResourceId m_nextId; |
289 ResourceMap m_resources; | 283 ResourceMap m_resources; |
290 int m_nextChild; | 284 int m_nextChild; |
291 ChildMap m_children; | 285 ChildMap m_children; |
292 | 286 |
293 ResourceType m_defaultResourceType; | 287 ResourceType m_defaultResourceType; |
294 bool m_useTextureStorageExt; | 288 bool m_useTextureStorageExt; |
295 bool m_useTextureUsageHint; | 289 bool m_useTextureUsageHint; |
296 bool m_useShallowFlush; | 290 bool m_useShallowFlush; |
297 scoped_ptr<TextureUploader> m_textureUploader; | 291 scoped_ptr<TextureUploader> m_textureUploader; |
298 scoped_ptr<AcceleratedTextureCopier> m_textureCopier; | 292 scoped_ptr<AcceleratedTextureCopier> m_textureCopier; |
299 int m_maxTextureSize; | 293 int m_maxTextureSize; |
300 GLenum m_bestTextureFormat; | 294 GLenum m_bestTextureFormat; |
301 | 295 |
302 base::ThreadChecker m_threadChecker; | 296 base::ThreadChecker m_threadChecker; |
303 | 297 |
304 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 298 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
305 }; | 299 }; |
306 | 300 |
307 } | 301 } |
308 | 302 |
309 #endif // CC_RESOURCE_PROVIDER_H_ | 303 #endif // CC_RESOURCE_PROVIDER_H_ |
OLD | NEW |