| 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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 | 214 |
| 215 private: | 215 private: |
| 216 ResourceProvider* m_resourceProvider; | 216 ResourceProvider* m_resourceProvider; |
| 217 ResourceProvider::ResourceId m_resourceId; | 217 ResourceProvider::ResourceId m_resourceId; |
| 218 SkBitmap m_skBitmap; | 218 SkBitmap m_skBitmap; |
| 219 scoped_ptr<SkCanvas> m_skCanvas; | 219 scoped_ptr<SkCanvas> m_skCanvas; |
| 220 | 220 |
| 221 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); | 221 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 class Fence : public base::RefCounted<Fence> { |
| 225 public: |
| 226 virtual bool hasPassed() = 0; |
| 227 protected: |
| 228 friend class base::RefCounted<Fence>; |
| 229 virtual ~Fence() {} |
| 230 }; |
| 231 |
| 224 // Acquire pixel buffer for resource. The pixel buffer can be used to | 232 // Acquire pixel buffer for resource. The pixel buffer can be used to |
| 225 // set resource pixels without performing unnecessary copying. | 233 // set resource pixels without performing unnecessary copying. |
| 226 void acquirePixelBuffer(ResourceId id); | 234 void acquirePixelBuffer(ResourceId id); |
| 227 void releasePixelBuffer(ResourceId id); | 235 void releasePixelBuffer(ResourceId id); |
| 228 | 236 |
| 229 // Map/unmap the acquired pixel buffer. | 237 // Map/unmap the acquired pixel buffer. |
| 230 uint8_t* mapPixelBuffer(ResourceId id); | 238 uint8_t* mapPixelBuffer(ResourceId id); |
| 231 void unmapPixelBuffer(ResourceId id); | 239 void unmapPixelBuffer(ResourceId id); |
| 232 | 240 |
| 233 // Update pixels from acquired pixel buffer. | 241 // Update pixels from acquired pixel buffer. |
| 234 void setPixelsFromBuffer(ResourceId id); | 242 void setPixelsFromBuffer(ResourceId id); |
| 235 | 243 |
| 236 // Asynchronously update pixels from acquired pixel buffer. | 244 // Asynchronously update pixels from acquired pixel buffer. |
| 237 void beginSetPixels(ResourceId id); | 245 void beginSetPixels(ResourceId id); |
| 238 bool didSetPixelsComplete(ResourceId id); | 246 bool didSetPixelsComplete(ResourceId id); |
| 239 | 247 |
| 240 // For tests only! This prevents detecting uninitialized reads. | 248 // For tests only! This prevents detecting uninitialized reads. |
| 241 // Use setPixels or lockForWrite to allocate implicitly. | 249 // Use setPixels or lockForWrite to allocate implicitly. |
| 242 void allocateForTesting(ResourceId id); | 250 void allocateForTesting(ResourceId id); |
| 243 | 251 |
| 252 // Sets the current read fence. If a resource is locked for read |
| 253 // and has read fences enabled, the resource will not allow writes |
| 254 // until this fence has passed. |
| 255 void setReadLockFence(scoped_refptr<Fence> fence) { m_currentReadLockFence =
fence; } |
| 256 Fence* getReadLockFence() { return m_currentReadLockFence; } |
| 257 |
| 258 // Enable read lock fences for a specific resource. |
| 259 void enableReadLockFences(ResourceProvider::ResourceId, bool enable); |
| 260 |
| 261 // Indicates if we can currently lock this resource for write. |
| 262 bool canLockForWrite(ResourceId); |
| 263 |
| 244 private: | 264 private: |
| 245 struct Resource { | 265 struct Resource { |
| 246 Resource(); | 266 Resource(); |
| 247 ~Resource(); | 267 ~Resource(); |
| 248 Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenu
m filter); | 268 Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenu
m filter); |
| 249 Resource(uint8_t* pixels, const gfx::Size& size, GLenum format, GLenum f
ilter); | 269 Resource(uint8_t* pixels, const gfx::Size& size, GLenum format, GLenum f
ilter); |
| 250 | 270 |
| 251 unsigned glId; | 271 unsigned glId; |
| 252 // Pixel buffer used for set pixels without unnecessary copying. | 272 // Pixel buffer used for set pixels without unnecessary copying. |
| 253 unsigned glPixelBufferId; | 273 unsigned glPixelBufferId; |
| 254 // Query used to determine when asynchronous set pixels complete. | 274 // Query used to determine when asynchronous set pixels complete. |
| 255 unsigned glUploadQueryId; | 275 unsigned glUploadQueryId; |
| 256 TextureMailbox mailbox; | 276 TextureMailbox mailbox; |
| 257 uint8_t* pixels; | 277 uint8_t* pixels; |
| 258 uint8_t* pixelBuffer; | 278 uint8_t* pixelBuffer; |
| 259 int lockForReadCount; | 279 int lockForReadCount; |
| 260 bool lockedForWrite; | 280 bool lockedForWrite; |
| 261 bool external; | 281 bool external; |
| 262 bool exported; | 282 bool exported; |
| 263 bool markedForDeletion; | 283 bool markedForDeletion; |
| 264 bool pendingSetPixels; | 284 bool pendingSetPixels; |
| 265 bool allocated; | 285 bool allocated; |
| 286 bool enableReadLockFences; |
| 287 scoped_refptr<Fence> readLockFence; |
| 266 gfx::Size size; | 288 gfx::Size size; |
| 267 GLenum format; | 289 GLenum format; |
| 268 // TODO(skyostil): Use a separate sampler object for filter state. | 290 // TODO(skyostil): Use a separate sampler object for filter state. |
| 269 GLenum filter; | 291 GLenum filter; |
| 270 ResourceType type; | 292 ResourceType type; |
| 271 }; | 293 }; |
| 272 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 294 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
| 273 struct Child { | 295 struct Child { |
| 274 Child(); | 296 Child(); |
| 275 ~Child(); | 297 ~Child(); |
| 276 | 298 |
| 277 ResourceIdMap childToParentMap; | 299 ResourceIdMap childToParentMap; |
| 278 ResourceIdMap parentToChildMap; | 300 ResourceIdMap parentToChildMap; |
| 279 }; | 301 }; |
| 280 typedef base::hash_map<int, Child> ChildMap; | 302 typedef base::hash_map<int, Child> ChildMap; |
| 281 | 303 |
| 304 bool readLockFenceHasPassed(Resource* resource) { return !resource->readLock
Fence || |
| 305 resource->readLock
Fence->hasPassed(); } |
| 306 |
| 282 explicit ResourceProvider(OutputSurface*); | 307 explicit ResourceProvider(OutputSurface*); |
| 283 bool initialize(); | 308 bool initialize(); |
| 284 | 309 |
| 285 const Resource* lockForRead(ResourceId); | 310 const Resource* lockForRead(ResourceId); |
| 286 void unlockForRead(ResourceId); | 311 void unlockForRead(ResourceId); |
| 287 const Resource* lockForWrite(ResourceId); | 312 const Resource* lockForWrite(ResourceId); |
| 288 void unlockForWrite(ResourceId); | 313 void unlockForWrite(ResourceId); |
| 289 static void populateSkBitmapWithResource(SkBitmap*, const Resource*); | 314 static void populateSkBitmapWithResource(SkBitmap*, const Resource*); |
| 290 | 315 |
| 291 bool transferResource(WebKit::WebGraphicsContext3D*, ResourceId, Transferabl
eResource*); | 316 bool transferResource(WebKit::WebGraphicsContext3D*, ResourceId, Transferabl
eResource*); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 302 bool m_useTextureStorageExt; | 327 bool m_useTextureStorageExt; |
| 303 bool m_useTextureUsageHint; | 328 bool m_useTextureUsageHint; |
| 304 bool m_useShallowFlush; | 329 bool m_useShallowFlush; |
| 305 scoped_ptr<TextureUploader> m_textureUploader; | 330 scoped_ptr<TextureUploader> m_textureUploader; |
| 306 scoped_ptr<AcceleratedTextureCopier> m_textureCopier; | 331 scoped_ptr<AcceleratedTextureCopier> m_textureCopier; |
| 307 int m_maxTextureSize; | 332 int m_maxTextureSize; |
| 308 GLenum m_bestTextureFormat; | 333 GLenum m_bestTextureFormat; |
| 309 | 334 |
| 310 base::ThreadChecker m_threadChecker; | 335 base::ThreadChecker m_threadChecker; |
| 311 | 336 |
| 337 scoped_refptr<Fence> m_currentReadLockFence; |
| 338 |
| 312 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 339 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 313 }; | 340 }; |
| 314 | 341 |
| 315 } | 342 } |
| 316 | 343 |
| 317 #endif // CC_RESOURCE_PROVIDER_H_ | 344 #endif // CC_RESOURCE_PROVIDER_H_ |
| OLD | NEW |