Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: cc/resources/resource_provider.h

Issue 157293002: cc: Refactor WorkerPoolTaskClient::AcquireBufferForRaster (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed cc_perftests compile error Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/resources/raster_worker_pool_unittest.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
18 #include "base/threading/thread_checker.h" 19 #include "base/threading/thread_checker.h"
19 #include "cc/base/cc_export.h" 20 #include "cc/base/cc_export.h"
20 #include "cc/output/context_provider.h" 21 #include "cc/output/context_provider.h"
21 #include "cc/output/output_surface.h" 22 #include "cc/output/output_surface.h"
22 #include "cc/resources/release_callback.h" 23 #include "cc/resources/release_callback.h"
23 #include "cc/resources/resource_format.h" 24 #include "cc/resources/resource_format.h"
24 #include "cc/resources/return_callback.h" 25 #include "cc/resources/return_callback.h"
25 #include "cc/resources/shared_bitmap.h" 26 #include "cc/resources/shared_bitmap.h"
26 #include "cc/resources/single_release_callback.h" 27 #include "cc/resources/single_release_callback.h"
27 #include "cc/resources/texture_mailbox.h" 28 #include "cc/resources/texture_mailbox.h"
28 #include "cc/resources/transferable_resource.h" 29 #include "cc/resources/transferable_resource.h"
29 #include "third_party/khronos/GLES2/gl2.h" 30 #include "third_party/khronos/GLES2/gl2.h"
30 #include "third_party/khronos/GLES2/gl2ext.h" 31 #include "third_party/khronos/GLES2/gl2ext.h"
31 #include "third_party/skia/include/core/SkBitmap.h" 32 #include "third_party/skia/include/core/SkBitmap.h"
32 #include "third_party/skia/include/core/SkCanvas.h" 33 #include "third_party/skia/include/core/SkCanvas.h"
33 #include "ui/gfx/size.h" 34 #include "ui/gfx/size.h"
34 35
36 class GrContext;
37
35 namespace gpu { 38 namespace gpu {
36 namespace gles { 39 namespace gles {
37 class GLES2Interface; 40 class GLES2Interface;
38 } 41 }
39 } 42 }
40 43
41 namespace gfx { 44 namespace gfx {
42 class Rect; 45 class Rect;
43 class Vector2d; 46 class Vector2d;
44 } 47 }
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 virtual bool HasPassed() = 0; 310 virtual bool HasPassed() = 0;
308 311
309 protected: 312 protected:
310 friend class base::RefCounted<Fence>; 313 friend class base::RefCounted<Fence>;
311 virtual ~Fence() {} 314 virtual ~Fence() {}
312 315
313 private: 316 private:
314 DISALLOW_COPY_AND_ASSIGN(Fence); 317 DISALLOW_COPY_AND_ASSIGN(Fence);
315 }; 318 };
316 319
317 // Acquire pixel buffer for resource. The pixel buffer can be used to 320 // Returns a canvas for direct rasterization.
318 // set resource pixels without performing unnecessary copying. 321 // Call Unmap before the resource can be read or used for compositing.
319 void AcquirePixelBuffer(ResourceId id); 322 // It is used for direct gpu rasterization.
320 void ReleasePixelBuffer(ResourceId id); 323 SkCanvas* MapDirectRasterBuffer(ResourceId id);
324 void UnmapDirectRasterBuffer(ResourceId id);
321 325
322 // Map/unmap the acquired pixel buffer. 326 // Returns a canvas backed by an image buffer.
323 uint8_t* MapPixelBuffer(ResourceId id); 327 // Rasterizing to the canvas writes the content into the image buffer,
324 void UnmapPixelBuffer(ResourceId id); 328 // which is internally bound to the underlying resource when read.
329 // Call Unmap before the resource can be read or used for compositing.
330 // It is used by ImageRasterWorkerPool.
331 SkCanvas* MapImageRasterBuffer(ResourceId id);
332 void UnmapImageRasterBuffer(ResourceId id);
333
334 // Returns a canvas backed by pixel buffer.
335 // The pixel buffer needs to be uploaded to the underlying resource
336 // using BeginSetPixels before the resouce can be used for compositing.
337 // It is used by PixelRasterWorkerPool.
338 void AcquirePixelRasterBuffer(ResourceId id);
339 void ReleasePixelRasterBuffer(ResourceId id);
340 SkCanvas* MapPixelRasterBuffer(ResourceId id);
341 void UnmapPixelRasterBuffer(ResourceId id);
325 342
326 // Asynchronously update pixels from acquired pixel buffer. 343 // Asynchronously update pixels from acquired pixel buffer.
327 void BeginSetPixels(ResourceId id); 344 void BeginSetPixels(ResourceId id);
328 void ForceSetPixelsToComplete(ResourceId id); 345 void ForceSetPixelsToComplete(ResourceId id);
329 bool DidSetPixelsComplete(ResourceId id); 346 bool DidSetPixelsComplete(ResourceId id);
330 347
331 // Acquire and release an image. The image allows direct
332 // manipulation of texture memory.
333 void AcquireImage(ResourceId id);
334 void ReleaseImage(ResourceId id);
335
336 // Maps the acquired image so that its pixels could be modified.
337 // Unmap is called when all pixels are set.
338 uint8_t* MapImage(ResourceId id);
339 void UnmapImage(ResourceId id);
340
341 // Returns the stride for the image.
342 int GetImageStride(ResourceId id);
343
344 // For tests only! This prevents detecting uninitialized reads. 348 // For tests only! This prevents detecting uninitialized reads.
345 // Use SetPixels or LockForWrite to allocate implicitly. 349 // Use SetPixels or LockForWrite to allocate implicitly.
346 void AllocateForTesting(ResourceId id); 350 void AllocateForTesting(ResourceId id);
347 351
348 // For tests only! 352 // For tests only!
349 void CreateForTesting(ResourceId id); 353 void CreateForTesting(ResourceId id);
350 354
351 GLenum TargetForTesting(ResourceId id); 355 GLenum TargetForTesting(ResourceId id);
352 356
353 // Sets the current read fence. If a resource is locked for read 357 // Sets the current read fence. If a resource is locked for read
354 // and has read fences enabled, the resource will not allow writes 358 // and has read fences enabled, the resource will not allow writes
355 // until this fence has passed. 359 // until this fence has passed.
356 void SetReadLockFence(scoped_refptr<Fence> fence) { 360 void SetReadLockFence(scoped_refptr<Fence> fence) {
357 current_read_lock_fence_ = fence; 361 current_read_lock_fence_ = fence;
358 } 362 }
359 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } 363 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); }
360 364
361 // Enable read lock fences for a specific resource. 365 // Enable read lock fences for a specific resource.
362 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); 366 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable);
363 367
364 // Indicates if we can currently lock this resource for write. 368 // Indicates if we can currently lock this resource for write.
365 bool CanLockForWrite(ResourceId id); 369 bool CanLockForWrite(ResourceId id);
366 370
367 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); 371 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl);
368 372
369 private: 373 private:
374 class DirectRasterBuffer;
375 class ImageRasterBuffer;
376 class PixelRasterBuffer;
377
370 struct Resource { 378 struct Resource {
371 enum Origin { Internal, External, Delegated }; 379 enum Origin { Internal, External, Delegated };
372 380
373 Resource(); 381 Resource();
374 ~Resource(); 382 ~Resource();
375 Resource(unsigned texture_id, 383 Resource(unsigned texture_id,
376 const gfx::Size& size, 384 const gfx::Size& size,
377 Origin origin, 385 Origin origin,
378 GLenum target, 386 GLenum target,
379 GLenum filter, 387 GLenum filter,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 bool dirty_image; 432 bool dirty_image;
425 GLenum texture_pool; 433 GLenum texture_pool;
426 GLint wrap_mode; 434 GLint wrap_mode;
427 bool lost; 435 bool lost;
428 TextureUsageHint hint; 436 TextureUsageHint hint;
429 ResourceType type; 437 ResourceType type;
430 ResourceFormat format; 438 ResourceFormat format;
431 bool has_shared_bitmap_id; 439 bool has_shared_bitmap_id;
432 SharedBitmapId shared_bitmap_id; 440 SharedBitmapId shared_bitmap_id;
433 SharedBitmap* shared_bitmap; 441 SharedBitmap* shared_bitmap;
442 linked_ptr<DirectRasterBuffer> direct_raster_buffer;
443 linked_ptr<ImageRasterBuffer> image_raster_buffer;
444 linked_ptr<PixelRasterBuffer> pixel_raster_buffer;
434 }; 445 };
435 typedef base::hash_map<ResourceId, Resource> ResourceMap; 446 typedef base::hash_map<ResourceId, Resource> ResourceMap;
436 447
448 class RasterBuffer {
449 public:
450 virtual ~RasterBuffer();
451
452 SkCanvas* LockForWrite();
453 void UnlockForWrite();
454
455 protected:
456 RasterBuffer(const Resource* resource, ResourceProvider* resource_provider);
457 const Resource* resource() const { return resource_; }
458 ResourceProvider* resource_provider() const { return resource_provider_; }
459
460 virtual SkCanvas* DoLockForWrite() = 0;
461 virtual void DoUnlockForWrite() = 0;
462
463 private:
464 const Resource* resource_;
465 ResourceProvider* resource_provider_;
466 SkCanvas* locked_canvas_;
467 int canvas_save_count_;
468 };
469
470 class DirectRasterBuffer : public RasterBuffer {
471 public:
472 DirectRasterBuffer(const Resource* resource,
473 ResourceProvider* resource_provider);
474 virtual ~DirectRasterBuffer();
475
476 protected:
477 virtual SkCanvas* DoLockForWrite() OVERRIDE;
478 virtual void DoUnlockForWrite() OVERRIDE;
479 skia::RefPtr<SkSurface> CreateSurface();
480
481 private:
482 skia::RefPtr<SkSurface> surface_;
483 DISALLOW_COPY_AND_ASSIGN(DirectRasterBuffer);
484 };
485
486 class BitmapRasterBuffer : public RasterBuffer {
487 public:
488 virtual ~BitmapRasterBuffer();
489
490 protected:
491 BitmapRasterBuffer(const Resource* resource,
492 ResourceProvider* resource_provider);
493
494 virtual SkCanvas* DoLockForWrite() OVERRIDE;
495 virtual void DoUnlockForWrite() OVERRIDE;
496
497 virtual uint8_t* MapBuffer(int* stride) = 0;
498 virtual void UnmapBuffer() = 0;
499
500 private:
501 uint8_t* mapped_buffer_;
502 SkBitmap raster_bitmap_;
503 skia::RefPtr<SkCanvas> raster_canvas_;
504 };
505
506 class ImageRasterBuffer : public BitmapRasterBuffer {
507 public:
508 ImageRasterBuffer(const Resource* resource,
509 ResourceProvider* resource_provider);
510 virtual ~ImageRasterBuffer();
511
512 protected:
513 virtual uint8_t* MapBuffer(int* stride) OVERRIDE;
514 virtual void UnmapBuffer() OVERRIDE;
515
516 private:
517 DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer);
518 };
519
520 class PixelRasterBuffer : public BitmapRasterBuffer {
521 public:
522 PixelRasterBuffer(const Resource* resource,
523 ResourceProvider* resource_provider);
524 virtual ~PixelRasterBuffer();
525
526 protected:
527 virtual uint8_t* MapBuffer(int* stride) OVERRIDE;
528 virtual void UnmapBuffer() OVERRIDE;
529
530 private:
531 DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer);
532 };
533
437 static bool CompareResourceMapIteratorsByChildId( 534 static bool CompareResourceMapIteratorsByChildId(
438 const std::pair<ReturnedResource, ResourceMap::iterator>& a, 535 const std::pair<ReturnedResource, ResourceMap::iterator>& a,
439 const std::pair<ReturnedResource, ResourceMap::iterator>& b); 536 const std::pair<ReturnedResource, ResourceMap::iterator>& b);
440 537
441 struct Child { 538 struct Child {
442 Child(); 539 Child();
443 ~Child(); 540 ~Child();
444 541
445 ResourceIdMap child_to_parent_map; 542 ResourceIdMap child_to_parent_map;
446 ResourceIdMap parent_to_child_map; 543 ResourceIdMap parent_to_child_map;
447 ReturnCallback return_callback; 544 ReturnCallback return_callback;
448 ResourceIdSet in_use_resources; 545 ResourceIdSet in_use_resources;
449 bool marked_for_deletion; 546 bool marked_for_deletion;
450 }; 547 };
451 typedef base::hash_map<int, Child> ChildMap; 548 typedef base::hash_map<int, Child> ChildMap;
452 549
453 bool ReadLockFenceHasPassed(Resource* resource) { 550 bool ReadLockFenceHasPassed(const Resource* resource) {
454 return !resource->read_lock_fence.get() || 551 return !resource->read_lock_fence.get() ||
455 resource->read_lock_fence->HasPassed(); 552 resource->read_lock_fence->HasPassed();
456 } 553 }
457 554
458 ResourceProvider(OutputSurface* output_surface, 555 ResourceProvider(OutputSurface* output_surface,
459 SharedBitmapManager* shared_bitmap_manager, 556 SharedBitmapManager* shared_bitmap_manager,
460 int highp_threshold_min, 557 int highp_threshold_min,
461 bool use_rgba_4444_texture_format, 558 bool use_rgba_4444_texture_format,
462 size_t id_allocation_chunk_size); 559 size_t id_allocation_chunk_size);
463 560
(...skipping 14 matching lines...) Expand all
478 Normal, 575 Normal,
479 ForShutdown, 576 ForShutdown,
480 }; 577 };
481 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style); 578 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style);
482 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it, 579 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it,
483 DeleteStyle style, 580 DeleteStyle style,
484 const ResourceIdArray& unused); 581 const ResourceIdArray& unused);
485 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style); 582 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style);
486 void LazyCreate(Resource* resource); 583 void LazyCreate(Resource* resource);
487 void LazyAllocate(Resource* resource); 584 void LazyAllocate(Resource* resource);
585
586 // TODO(alokp): Move the implementation to PixelRasterBuffer.
587 // Acquire pixel buffer for resource. The pixel buffer can be used to
588 // set resource pixels without performing unnecessary copying.
589 void AcquirePixelBuffer(Resource* resource);
590 void ReleasePixelBuffer(Resource* resource);
591 // Map/unmap the acquired pixel buffer.
592 uint8_t* MapPixelBuffer(const Resource* resource, int* stride);
593 void UnmapPixelBuffer(const Resource* resource);
594
595 // TODO(alokp): Move the implementation to ImageRasterBuffer.
596 // Acquire and release an image. The image allows direct
597 // manipulation of texture memory.
598 void AcquireImage(Resource* resource);
599 void ReleaseImage(Resource* resource);
600 // Maps the acquired image so that its pixels could be modified.
601 // Unmap is called when all pixels are set.
602 uint8_t* MapImage(const Resource* resource, int* stride);
603 void UnmapImage(const Resource* resource);
604
488 void BindImageForSampling(Resource* resource); 605 void BindImageForSampling(Resource* resource);
489
490 // Binds the given GL resource to a texture target for sampling using the 606 // Binds the given GL resource to a texture target for sampling using the
491 // specified filter for both minification and magnification. Returns the 607 // specified filter for both minification and magnification. Returns the
492 // texture target used. The resource must be locked for reading. 608 // texture target used. The resource must be locked for reading.
493 GLenum BindForSampling(ResourceProvider::ResourceId resource_id, 609 GLenum BindForSampling(ResourceProvider::ResourceId resource_id,
494 GLenum unit, 610 GLenum unit,
495 GLenum filter); 611 GLenum filter);
496 612
497 // Returns NULL if the output_surface_ does not have a ContextProvider. 613 // Returns NULL if the output_surface_ does not have a ContextProvider.
498 gpu::gles2::GLES2Interface* ContextGL() const; 614 gpu::gles2::GLES2Interface* ContextGL() const;
615 class GrContext* GrContext() const;
499 616
500 OutputSurface* output_surface_; 617 OutputSurface* output_surface_;
501 SharedBitmapManager* shared_bitmap_manager_; 618 SharedBitmapManager* shared_bitmap_manager_;
502 bool lost_output_surface_; 619 bool lost_output_surface_;
503 int highp_threshold_min_; 620 int highp_threshold_min_;
504 ResourceId next_id_; 621 ResourceId next_id_;
505 ResourceMap resources_; 622 ResourceMap resources_;
506 int next_child_; 623 int next_child_;
507 ChildMap children_; 624 ChildMap children_;
508 625
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 return format_gl_data_format[format]; 685 return format_gl_data_format[format];
569 } 686 }
570 687
571 inline GLenum GLInternalFormat(ResourceFormat format) { 688 inline GLenum GLInternalFormat(ResourceFormat format) {
572 return GLDataFormat(format); 689 return GLDataFormat(format);
573 } 690 }
574 691
575 } // namespace cc 692 } // namespace cc
576 693
577 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 694 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW
« no previous file with comments | « cc/resources/raster_worker_pool_unittest.cc ('k') | cc/resources/resource_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698