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> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
17 #include "base/memory/linked_ptr.h" | 17 #include "base/memory/linked_ptr.h" |
18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
19 #include "base/threading/thread_checker.h" | 19 #include "base/threading/thread_checker.h" |
20 #include "cc/base/cc_export.h" | 20 #include "cc/base/cc_export.h" |
21 #include "cc/output/context_provider.h" | 21 #include "cc/output/context_provider.h" |
22 #include "cc/output/output_surface.h" | 22 #include "cc/output/output_surface.h" |
23 #include "cc/resources/raster_buffer.h" | |
24 #include "cc/resources/release_callback_impl.h" | 23 #include "cc/resources/release_callback_impl.h" |
25 #include "cc/resources/resource_format.h" | 24 #include "cc/resources/resource_format.h" |
26 #include "cc/resources/return_callback.h" | 25 #include "cc/resources/return_callback.h" |
27 #include "cc/resources/shared_bitmap.h" | 26 #include "cc/resources/shared_bitmap.h" |
28 #include "cc/resources/single_release_callback_impl.h" | 27 #include "cc/resources/single_release_callback_impl.h" |
29 #include "cc/resources/texture_mailbox.h" | 28 #include "cc/resources/texture_mailbox.h" |
30 #include "cc/resources/transferable_resource.h" | 29 #include "cc/resources/transferable_resource.h" |
31 #include "third_party/khronos/GLES2/gl2.h" | 30 #include "third_party/khronos/GLES2/gl2.h" |
32 #include "third_party/khronos/GLES2/gl2ext.h" | 31 #include "third_party/khronos/GLES2/gl2ext.h" |
33 #include "third_party/skia/include/core/SkBitmap.h" | 32 #include "third_party/skia/include/core/SkBitmap.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 virtual bool HasPassed() = 0; | 311 virtual bool HasPassed() = 0; |
313 | 312 |
314 protected: | 313 protected: |
315 friend class base::RefCounted<Fence>; | 314 friend class base::RefCounted<Fence>; |
316 virtual ~Fence() {} | 315 virtual ~Fence() {} |
317 | 316 |
318 private: | 317 private: |
319 DISALLOW_COPY_AND_ASSIGN(Fence); | 318 DISALLOW_COPY_AND_ASSIGN(Fence); |
320 }; | 319 }; |
321 | 320 |
322 // Returns a RasterBuffer for gpu rasterization. | 321 // Acquire pixel buffer for resource. The pixel buffer can be used to |
323 // Call Release before the resource can be read or used for compositing. | 322 // set resource pixels without performing unnecessary copying. |
324 // It is used for direct gpu rasterization. | 323 void AcquirePixelBuffer(ResourceId resource); |
325 RasterBuffer* AcquireGpuRasterBuffer(ResourceId id); | 324 void ReleasePixelBuffer(ResourceId resource); |
326 void ReleaseGpuRasterBuffer(ResourceId id); | 325 // Map/unmap the acquired pixel buffer. |
327 | 326 uint8_t* MapPixelBuffer(ResourceId id, int* stride); |
328 // Returns a RasterBuffer backed by an image buffer. ReleaseImageRasterBuffer | 327 void UnmapPixelBuffer(ResourceId id); |
329 // returns true if RasterBuffer was written to while acquired. | |
330 // Rasterizing to the RasterBuffer writes the content into the image buffer, | |
331 // which is internally bound to the underlying resource when read. | |
332 // Call Release before the resource can be read or used for compositing. | |
333 // It is used by ImageRasterWorkerPool. | |
334 RasterBuffer* AcquireImageRasterBuffer(ResourceId id); | |
335 bool ReleaseImageRasterBuffer(ResourceId id); | |
336 | |
337 // Returns a RasterBuffer backed by pixel buffer. ReleasePixelRasterBuffer | |
338 // returns true if RasterBuffer was written to while acquired. | |
339 // The pixel buffer needs to be uploaded to the underlying resource | |
340 // using BeginSetPixels before the resouce can be used for compositing. | |
341 // It is used by PixelRasterWorkerPool. | |
342 RasterBuffer* AcquirePixelRasterBuffer(ResourceId id); | |
343 bool ReleasePixelRasterBuffer(ResourceId id); | |
344 | |
345 // Asynchronously update pixels from acquired pixel buffer. | 328 // Asynchronously update pixels from acquired pixel buffer. |
346 void BeginSetPixels(ResourceId id); | 329 void BeginSetPixels(ResourceId id); |
347 void ForceSetPixelsToComplete(ResourceId id); | 330 void ForceSetPixelsToComplete(ResourceId id); |
348 bool DidSetPixelsComplete(ResourceId id); | 331 bool DidSetPixelsComplete(ResourceId id); |
349 | 332 |
| 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 |
350 // For tests only! This prevents detecting uninitialized reads. | 349 // For tests only! This prevents detecting uninitialized reads. |
351 // Use SetPixels or LockForWrite to allocate implicitly. | 350 // Use SetPixels or LockForWrite to allocate implicitly. |
352 void AllocateForTesting(ResourceId id); | 351 void AllocateForTesting(ResourceId id); |
353 | 352 |
354 // For tests only! | 353 // For tests only! |
355 void CreateForTesting(ResourceId id); | 354 void CreateForTesting(ResourceId id); |
356 | 355 |
357 GLenum TargetForTesting(ResourceId id); | 356 GLenum TargetForTesting(ResourceId id); |
358 | 357 |
359 // Sets the current read fence. If a resource is locked for read | 358 // Sets the current read fence. If a resource is locked for read |
360 // and has read fences enabled, the resource will not allow writes | 359 // and has read fences enabled, the resource will not allow writes |
361 // until this fence has passed. | 360 // until this fence has passed. |
362 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } | 361 void SetReadLockFence(Fence* fence) { current_read_lock_fence_ = fence; } |
363 | 362 |
364 // Enable read lock fences for a specific resource. | 363 // Enable read lock fences for a specific resource. |
365 void EnableReadLockFences(ResourceProvider::ResourceId id); | 364 void EnableReadLockFences(ResourceId id); |
366 | 365 |
367 // Indicates if we can currently lock this resource for write. | 366 // Indicates if we can currently lock this resource for write. |
368 bool CanLockForWrite(ResourceId id); | 367 bool CanLockForWrite(ResourceId id); |
369 | 368 |
370 // Copy pixels from source to destination. | 369 // Copy pixels from source to destination. |
371 void CopyResource(ResourceId source_id, ResourceId dest_id); | 370 void CopyResource(ResourceId source_id, ResourceId dest_id); |
372 | 371 |
373 void WaitSyncPointIfNeeded(ResourceId id); | 372 void WaitSyncPointIfNeeded(ResourceId id); |
374 | 373 |
375 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); | 374 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); |
376 | 375 |
377 private: | 376 private: |
378 class GpuRasterBuffer; | |
379 class ImageRasterBuffer; | |
380 class PixelRasterBuffer; | |
381 | |
382 struct Resource { | 377 struct Resource { |
383 enum Origin { Internal, External, Delegated }; | 378 enum Origin { Internal, External, Delegated }; |
384 | 379 |
385 Resource(); | 380 Resource(); |
386 ~Resource(); | 381 ~Resource(); |
387 Resource(unsigned texture_id, | 382 Resource(unsigned texture_id, |
388 const gfx::Size& size, | 383 const gfx::Size& size, |
389 Origin origin, | 384 Origin origin, |
390 GLenum target, | 385 GLenum target, |
391 GLenum filter, | 386 GLenum filter, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 GLenum filter; | 433 GLenum filter; |
439 unsigned image_id; | 434 unsigned image_id; |
440 unsigned bound_image_id; | 435 unsigned bound_image_id; |
441 GLenum texture_pool; | 436 GLenum texture_pool; |
442 GLint wrap_mode; | 437 GLint wrap_mode; |
443 TextureHint hint; | 438 TextureHint hint; |
444 ResourceType type; | 439 ResourceType type; |
445 ResourceFormat format; | 440 ResourceFormat format; |
446 SharedBitmapId shared_bitmap_id; | 441 SharedBitmapId shared_bitmap_id; |
447 SharedBitmap* shared_bitmap; | 442 SharedBitmap* shared_bitmap; |
448 linked_ptr<GpuRasterBuffer> gpu_raster_buffer; | 443 skia::RefPtr<SkSurface> sk_surface; |
449 linked_ptr<ImageRasterBuffer> image_raster_buffer; | |
450 linked_ptr<PixelRasterBuffer> pixel_raster_buffer; | |
451 }; | 444 }; |
452 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 445 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
453 | 446 |
454 class GpuRasterBuffer : public RasterBuffer { | |
455 public: | |
456 GpuRasterBuffer(const Resource* resource, | |
457 ResourceProvider* resource_provider, | |
458 bool use_distance_field_text); | |
459 virtual ~GpuRasterBuffer(); | |
460 | |
461 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE; | |
462 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE; | |
463 | |
464 private: | |
465 const Resource* resource_; | |
466 ResourceProvider* resource_provider_; | |
467 skia::RefPtr<SkSurface> surface_; | |
468 | |
469 DISALLOW_COPY_AND_ASSIGN(GpuRasterBuffer); | |
470 }; | |
471 | |
472 class ImageRasterBuffer : public RasterBuffer { | |
473 public: | |
474 ImageRasterBuffer(const Resource* resource, | |
475 ResourceProvider* resource_provider); | |
476 virtual ~ImageRasterBuffer(); | |
477 | |
478 void MapBuffer(); | |
479 bool UnmapBuffer(); | |
480 | |
481 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE; | |
482 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE; | |
483 | |
484 private: | |
485 const Resource* resource_; | |
486 ResourceProvider* resource_provider_; | |
487 uint8_t* mapped_buffer_; | |
488 SkBitmap raster_bitmap_; | |
489 bool raster_bitmap_changed_; | |
490 int stride_; | |
491 | |
492 DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer); | |
493 }; | |
494 | |
495 class PixelRasterBuffer : public RasterBuffer { | |
496 public: | |
497 PixelRasterBuffer(const Resource* resource, | |
498 ResourceProvider* resource_provider); | |
499 virtual ~PixelRasterBuffer(); | |
500 | |
501 void MapBuffer(); | |
502 bool UnmapBuffer(); | |
503 | |
504 virtual skia::RefPtr<SkCanvas> AcquireSkCanvas() OVERRIDE; | |
505 virtual void ReleaseSkCanvas(const skia::RefPtr<SkCanvas>& canvas) OVERRIDE; | |
506 | |
507 private: | |
508 const Resource* resource_; | |
509 ResourceProvider* resource_provider_; | |
510 uint8_t* mapped_buffer_; | |
511 SkBitmap raster_bitmap_; | |
512 bool raster_bitmap_changed_; | |
513 int stride_; | |
514 | |
515 DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer); | |
516 }; | |
517 | |
518 static bool CompareResourceMapIteratorsByChildId( | 447 static bool CompareResourceMapIteratorsByChildId( |
519 const std::pair<ReturnedResource, ResourceMap::iterator>& a, | 448 const std::pair<ReturnedResource, ResourceMap::iterator>& a, |
520 const std::pair<ReturnedResource, ResourceMap::iterator>& b); | 449 const std::pair<ReturnedResource, ResourceMap::iterator>& b); |
521 | 450 |
522 struct Child { | 451 struct Child { |
523 Child(); | 452 Child(); |
524 ~Child(); | 453 ~Child(); |
525 | 454 |
526 ResourceIdMap child_to_parent_map; | 455 ResourceIdMap child_to_parent_map; |
527 ResourceIdMap parent_to_child_map; | 456 ResourceIdMap parent_to_child_map; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 ForShutdown, | 491 ForShutdown, |
563 }; | 492 }; |
564 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style); | 493 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style); |
565 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it, | 494 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it, |
566 DeleteStyle style, | 495 DeleteStyle style, |
567 const ResourceIdArray& unused); | 496 const ResourceIdArray& unused); |
568 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style); | 497 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style); |
569 void LazyCreate(Resource* resource); | 498 void LazyCreate(Resource* resource); |
570 void LazyAllocate(Resource* resource); | 499 void LazyAllocate(Resource* resource); |
571 | 500 |
572 // TODO(alokp): Move the implementation to PixelRasterBuffer. | |
573 // Acquire pixel buffer for resource. The pixel buffer can be used to | |
574 // set resource pixels without performing unnecessary copying. | |
575 void AcquirePixelBuffer(Resource* resource); | |
576 void ReleasePixelBuffer(Resource* resource); | |
577 // Map/unmap the acquired pixel buffer. | |
578 uint8_t* MapPixelBuffer(const Resource* resource, int* stride); | |
579 void UnmapPixelBuffer(const Resource* resource); | |
580 | |
581 // TODO(alokp): Move the implementation to ImageRasterBuffer. | |
582 // Acquire and release an image. The image allows direct | |
583 // manipulation of texture memory. | |
584 void AcquireImage(Resource* resource); | |
585 void ReleaseImage(Resource* resource); | |
586 // Maps the acquired image so that its pixels could be modified. | |
587 // Unmap is called when all pixels are set. | |
588 uint8_t* MapImage(const Resource* resource, int* stride); | |
589 void UnmapImage(const Resource* resource); | |
590 | |
591 void BindImageForSampling(Resource* resource); | 501 void BindImageForSampling(Resource* resource); |
592 // Binds the given GL resource to a texture target for sampling using the | 502 // Binds the given GL resource to a texture target for sampling using the |
593 // specified filter for both minification and magnification. Returns the | 503 // specified filter for both minification and magnification. Returns the |
594 // texture target used. The resource must be locked for reading. | 504 // texture target used. The resource must be locked for reading. |
595 GLenum BindForSampling(ResourceProvider::ResourceId resource_id, | 505 GLenum BindForSampling(ResourceId resource_id, GLenum unit, GLenum filter); |
596 GLenum unit, | |
597 GLenum filter); | |
598 | 506 |
599 // Returns NULL if the output_surface_ does not have a ContextProvider. | 507 // Returns NULL if the output_surface_ does not have a ContextProvider. |
600 gpu::gles2::GLES2Interface* ContextGL() const; | 508 gpu::gles2::GLES2Interface* ContextGL() const; |
601 class GrContext* GrContext() const; | 509 class GrContext* GrContext() const; |
602 | 510 |
603 OutputSurface* output_surface_; | 511 OutputSurface* output_surface_; |
604 SharedBitmapManager* shared_bitmap_manager_; | 512 SharedBitmapManager* shared_bitmap_manager_; |
605 BlockingTaskRunner* blocking_main_thread_task_runner_; | 513 BlockingTaskRunner* blocking_main_thread_task_runner_; |
606 bool lost_output_surface_; | 514 bool lost_output_surface_; |
607 int highp_threshold_min_; | 515 int highp_threshold_min_; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 return format_gl_data_format[format]; | 588 return format_gl_data_format[format]; |
681 } | 589 } |
682 | 590 |
683 inline GLenum GLInternalFormat(ResourceFormat format) { | 591 inline GLenum GLInternalFormat(ResourceFormat format) { |
684 return GLDataFormat(format); | 592 return GLDataFormat(format); |
685 } | 593 } |
686 | 594 |
687 } // namespace cc | 595 } // namespace cc |
688 | 596 |
689 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ | 597 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ |
OLD | NEW |