| 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_RESOURCES_RESOURCE_PROVIDER_H_ | 5 #ifndef CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ | 6 #define CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 296 |
| 297 private: | 297 private: |
| 298 ResourceProvider* resource_provider_; | 298 ResourceProvider* resource_provider_; |
| 299 ResourceProvider::ResourceId resource_id_; | 299 ResourceProvider::ResourceId resource_id_; |
| 300 SkBitmap sk_bitmap_; | 300 SkBitmap sk_bitmap_; |
| 301 scoped_ptr<SkCanvas> sk_canvas_; | 301 scoped_ptr<SkCanvas> sk_canvas_; |
| 302 | 302 |
| 303 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); | 303 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); |
| 304 }; | 304 }; |
| 305 | 305 |
| 306 class CC_EXPORT ScopedWriteLockGpuMemoryBuffer { |
| 307 public: |
| 308 ScopedWriteLockGpuMemoryBuffer(ResourceProvider* resource_provider, |
| 309 ResourceProvider::ResourceId resource_id); |
| 310 ~ScopedWriteLockGpuMemoryBuffer(); |
| 311 |
| 312 void* gpu_memory_buffer() { return gpu_memory_buffer_; } |
| 313 int stride() const { return stride_; } |
| 314 |
| 315 private: |
| 316 ResourceProvider* resource_provider_; |
| 317 ResourceProvider::ResourceId resource_id_; |
| 318 unsigned image_id_; |
| 319 void* gpu_memory_buffer_; |
| 320 int stride_; |
| 321 |
| 322 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGpuMemoryBuffer); |
| 323 }; |
| 324 |
| 325 class CC_EXPORT ScopedWriteLockGr { |
| 326 public: |
| 327 ScopedWriteLockGr(ResourceProvider* resource_provider, |
| 328 ResourceProvider::ResourceId resource_id); |
| 329 ~ScopedWriteLockGr(); |
| 330 |
| 331 SkSurface* sk_surface() { return sk_surface_; } |
| 332 |
| 333 private: |
| 334 ResourceProvider* resource_provider_; |
| 335 ResourceProvider::ResourceId resource_id_; |
| 336 SkSurface* sk_surface_; |
| 337 |
| 338 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGr); |
| 339 }; |
| 340 |
| 306 class Fence : public base::RefCounted<Fence> { | 341 class Fence : public base::RefCounted<Fence> { |
| 307 public: | 342 public: |
| 308 Fence() {} | 343 Fence() {} |
| 309 | 344 |
| 310 virtual void Set() = 0; | 345 virtual void Set() = 0; |
| 311 virtual bool HasPassed() = 0; | 346 virtual bool HasPassed() = 0; |
| 312 | 347 |
| 313 protected: | 348 protected: |
| 314 friend class base::RefCounted<Fence>; | 349 friend class base::RefCounted<Fence>; |
| 315 virtual ~Fence() {} | 350 virtual ~Fence() {} |
| 316 | 351 |
| 317 private: | 352 private: |
| 318 DISALLOW_COPY_AND_ASSIGN(Fence); | 353 DISALLOW_COPY_AND_ASSIGN(Fence); |
| 319 }; | 354 }; |
| 320 | 355 |
| 321 // Acquire pixel buffer for resource. The pixel buffer can be used to | 356 // Acquire pixel buffer for resource. The pixel buffer can be used to |
| 322 // set resource pixels without performing unnecessary copying. | 357 // set resource pixels without performing unnecessary copying. |
| 323 void AcquirePixelBuffer(ResourceId resource); | 358 void AcquirePixelBuffer(ResourceId resource); |
| 324 void ReleasePixelBuffer(ResourceId resource); | 359 void ReleasePixelBuffer(ResourceId resource); |
| 325 // Map/unmap the acquired pixel buffer. | 360 // Map/unmap the acquired pixel buffer. |
| 326 uint8_t* MapPixelBuffer(ResourceId id, int* stride); | 361 uint8_t* MapPixelBuffer(ResourceId id, int* stride); |
| 327 void UnmapPixelBuffer(ResourceId id); | 362 void UnmapPixelBuffer(ResourceId id); |
| 328 // Asynchronously update pixels from acquired pixel buffer. | 363 // Asynchronously update pixels from acquired pixel buffer. |
| 329 void BeginSetPixels(ResourceId id); | 364 void BeginSetPixels(ResourceId id); |
| 330 void ForceSetPixelsToComplete(ResourceId id); | 365 void ForceSetPixelsToComplete(ResourceId id); |
| 331 bool DidSetPixelsComplete(ResourceId id); | 366 bool DidSetPixelsComplete(ResourceId id); |
| 332 | 367 |
| 333 // Acquire and release an image. The image allows direct | |
| 334 // manipulation of texture memory. | |
| 335 void AcquireImage(ResourceId id); | |
| 336 void ReleaseImage(ResourceId id); | |
| 337 // Maps the acquired image so that its pixels could be modified. | |
| 338 // Unmap is called when all pixels are set. | |
| 339 uint8_t* MapImage(ResourceId id, int* stride); | |
| 340 void UnmapImage(ResourceId id); | |
| 341 | |
| 342 // Acquire and release a SkSurface. | |
| 343 void AcquireSkSurface(ResourceId id); | |
| 344 void ReleaseSkSurface(ResourceId id); | |
| 345 // Lock/unlock resource for writing to SkSurface. | |
| 346 SkSurface* LockForWriteToSkSurface(ResourceId id); | |
| 347 void UnlockForWriteToSkSurface(ResourceId id); | |
| 348 | |
| 349 // For tests only! This prevents detecting uninitialized reads. | 368 // For tests only! This prevents detecting uninitialized reads. |
| 350 // Use SetPixels or LockForWrite to allocate implicitly. | 369 // Use SetPixels or LockForWrite to allocate implicitly. |
| 351 void AllocateForTesting(ResourceId id); | 370 void AllocateForTesting(ResourceId id); |
| 352 | 371 |
| 353 // For tests only! | 372 // For tests only! |
| 354 void CreateForTesting(ResourceId id); | 373 void CreateForTesting(ResourceId id); |
| 355 | 374 |
| 356 GLenum TargetForTesting(ResourceId id); | 375 GLenum TargetForTesting(ResourceId id); |
| 357 | 376 |
| 358 // Sets the current read fence. If a resource is locked for read | 377 // Sets the current read fence. If a resource is locked for read |
| 359 // and has read fences enabled, the resource will not allow writes | 378 // and has read fences enabled, the resource will not allow writes |
| 360 // until this fence has passed. | 379 // until this fence has passed. |
| 361 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } | 380 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } |
| 362 | 381 |
| 363 // Enable read lock fences for a specific resource. | |
| 364 void EnableReadLockFences(ResourceId id); | |
| 365 | |
| 366 // Indicates if we can currently lock this resource for write. | 382 // Indicates if we can currently lock this resource for write. |
| 367 bool CanLockForWrite(ResourceId id); | 383 bool CanLockForWrite(ResourceId id); |
| 368 | 384 |
| 369 // Copy pixels from source to destination. | 385 // Copy pixels from source to destination. |
| 370 void CopyResource(ResourceId source_id, ResourceId dest_id); | 386 void CopyResource(ResourceId source_id, ResourceId dest_id); |
| 371 | 387 |
| 372 void WaitSyncPointIfNeeded(ResourceId id); | 388 void WaitSyncPointIfNeeded(ResourceId id); |
| 373 | 389 |
| 374 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); | 390 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); |
| 375 | 391 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 size_t id_allocation_chunk_size, | 489 size_t id_allocation_chunk_size, |
| 474 bool use_distance_field_text); | 490 bool use_distance_field_text); |
| 475 | 491 |
| 476 void CleanUpGLIfNeeded(); | 492 void CleanUpGLIfNeeded(); |
| 477 | 493 |
| 478 Resource* GetResource(ResourceId id); | 494 Resource* GetResource(ResourceId id); |
| 479 const Resource* LockForRead(ResourceId id); | 495 const Resource* LockForRead(ResourceId id); |
| 480 void UnlockForRead(ResourceId id); | 496 void UnlockForRead(ResourceId id); |
| 481 const Resource* LockForWrite(ResourceId id); | 497 const Resource* LockForWrite(ResourceId id); |
| 482 void UnlockForWrite(ResourceId id); | 498 void UnlockForWrite(ResourceId id); |
| 499 const Resource* LockForWriteToGpuMemoryBuffer(ResourceId id); |
| 500 void UnlockForWriteToGpuMemoryBuffer(ResourceId id); |
| 501 const Resource* LockForWriteToSkSurface(ResourceId id); |
| 502 void UnlockForWriteToSkSurface(ResourceId id); |
| 503 |
| 483 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, | 504 static void PopulateSkBitmapWithResource(SkBitmap* sk_bitmap, |
| 484 const Resource* resource); | 505 const Resource* resource); |
| 485 | 506 |
| 486 void TransferResource(gpu::gles2::GLES2Interface* gl, | 507 void TransferResource(gpu::gles2::GLES2Interface* gl, |
| 487 ResourceId id, | 508 ResourceId id, |
| 488 TransferableResource* resource); | 509 TransferableResource* resource); |
| 489 enum DeleteStyle { | 510 enum DeleteStyle { |
| 490 Normal, | 511 Normal, |
| 491 ForShutdown, | 512 ForShutdown, |
| 492 }; | 513 }; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 return format_gl_data_format[format]; | 609 return format_gl_data_format[format]; |
| 589 } | 610 } |
| 590 | 611 |
| 591 inline GLenum GLInternalFormat(ResourceFormat format) { | 612 inline GLenum GLInternalFormat(ResourceFormat format) { |
| 592 return GLDataFormat(format); | 613 return GLDataFormat(format); |
| 593 } | 614 } |
| 594 | 615 |
| 595 } // namespace cc | 616 } // namespace cc |
| 596 | 617 |
| 597 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 618 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
| OLD | NEW |