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