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

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: updated unittests 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/single_release_callback.h" 26 #include "cc/resources/single_release_callback.h"
26 #include "cc/resources/texture_mailbox.h" 27 #include "cc/resources/texture_mailbox.h"
27 #include "cc/resources/transferable_resource.h" 28 #include "cc/resources/transferable_resource.h"
28 #include "third_party/khronos/GLES2/gl2.h" 29 #include "third_party/khronos/GLES2/gl2.h"
29 #include "third_party/khronos/GLES2/gl2ext.h" 30 #include "third_party/khronos/GLES2/gl2ext.h"
30 #include "third_party/skia/include/core/SkBitmap.h" 31 #include "third_party/skia/include/core/SkBitmap.h"
31 #include "third_party/skia/include/core/SkCanvas.h" 32 #include "third_party/skia/include/core/SkCanvas.h"
32 #include "ui/gfx/size.h" 33 #include "ui/gfx/size.h"
33 34
35 class GrContext;
36
34 namespace gpu { 37 namespace gpu {
35 namespace gles { 38 namespace gles {
36 class GLES2Interface; 39 class GLES2Interface;
37 } 40 }
38 } 41 }
39 42
40 namespace gfx { 43 namespace gfx {
41 class Rect; 44 class Rect;
42 class Vector2d; 45 class Vector2d;
43 } 46 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 virtual bool HasPassed() = 0; 303 virtual bool HasPassed() = 0;
301 304
302 protected: 305 protected:
303 friend class base::RefCounted<Fence>; 306 friend class base::RefCounted<Fence>;
304 virtual ~Fence() {} 307 virtual ~Fence() {}
305 308
306 private: 309 private:
307 DISALLOW_COPY_AND_ASSIGN(Fence); 310 DISALLOW_COPY_AND_ASSIGN(Fence);
308 }; 311 };
309 312
310 // Acquire pixel buffer for resource. The pixel buffer can be used to 313 SkCanvas* MapDirectRasterBuffer(ResourceId id);
311 // set resource pixels without performing unnecessary copying. 314 void UnmapDirectRasterBuffer(ResourceId id);
reveman 2014/02/12 01:45:12 Not clear to me what the "Direct" means here. Writ
alokp 2014/02/12 07:17:42 I consider image and pixel raster buffers indirect
reveman 2014/02/12 17:23:40 Each RasterWorkerPool implementation is responsibl
312 void AcquirePixelBuffer(ResourceId id);
313 void ReleasePixelBuffer(ResourceId id);
314 315
315 // Map/unmap the acquired pixel buffer. 316 SkCanvas* MapImageRasterBuffer(ResourceId id);
316 uint8_t* MapPixelBuffer(ResourceId id); 317 void UnmapImageRasterBuffer(ResourceId id);
317 void UnmapPixelBuffer(ResourceId id); 318
319 void AcquirePixelRasterBuffer(ResourceId id);
320 void ReleasePixelRasterBuffer(ResourceId id);
321 SkCanvas* MapPixelRasterBuffer(ResourceId id);
322 void UnmapPixelRasterBuffer(ResourceId id);
318 323
319 // Asynchronously update pixels from acquired pixel buffer. 324 // Asynchronously update pixels from acquired pixel buffer.
320 void BeginSetPixels(ResourceId id); 325 void BeginSetPixels(ResourceId id);
321 void ForceSetPixelsToComplete(ResourceId id); 326 void ForceSetPixelsToComplete(ResourceId id);
322 bool DidSetPixelsComplete(ResourceId id); 327 bool DidSetPixelsComplete(ResourceId id);
323 328
324 // Acquire and release an image. The image allows direct
325 // manipulation of texture memory.
326 void AcquireImage(ResourceId id);
327 void ReleaseImage(ResourceId id);
328
329 // Maps the acquired image so that its pixels could be modified.
330 // Unmap is called when all pixels are set.
331 uint8_t* MapImage(ResourceId id);
332 void UnmapImage(ResourceId id);
333
334 // Returns the stride for the image.
335 int GetImageStride(ResourceId id);
336
337 // For tests only! This prevents detecting uninitialized reads. 329 // For tests only! This prevents detecting uninitialized reads.
338 // Use SetPixels or LockForWrite to allocate implicitly. 330 // Use SetPixels or LockForWrite to allocate implicitly.
339 void AllocateForTesting(ResourceId id); 331 void AllocateForTesting(ResourceId id);
340 332
341 // For tests only! 333 // For tests only!
342 void CreateForTesting(ResourceId id); 334 void CreateForTesting(ResourceId id);
343 335
344 GLenum TargetForTesting(ResourceId id); 336 GLenum TargetForTesting(ResourceId id);
345 337
346 // Sets the current read fence. If a resource is locked for read 338 // Sets the current read fence. If a resource is locked for read
347 // and has read fences enabled, the resource will not allow writes 339 // and has read fences enabled, the resource will not allow writes
348 // until this fence has passed. 340 // until this fence has passed.
349 void SetReadLockFence(scoped_refptr<Fence> fence) { 341 void SetReadLockFence(scoped_refptr<Fence> fence) {
350 current_read_lock_fence_ = fence; 342 current_read_lock_fence_ = fence;
351 } 343 }
352 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); } 344 Fence* GetReadLockFence() { return current_read_lock_fence_.get(); }
353 345
354 // Enable read lock fences for a specific resource. 346 // Enable read lock fences for a specific resource.
355 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable); 347 void EnableReadLockFences(ResourceProvider::ResourceId id, bool enable);
356 348
357 // Indicates if we can currently lock this resource for write. 349 // Indicates if we can currently lock this resource for write.
358 bool CanLockForWrite(ResourceId id); 350 bool CanLockForWrite(ResourceId id);
359 351
360 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); 352 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl);
361 353
362 private: 354 private:
355 class DirectRasterBuffer;
356 class ImageRasterBuffer;
357 class PixelRasterBuffer;
358
363 struct Resource { 359 struct Resource {
364 enum Origin { Internal, External, Delegated }; 360 enum Origin { Internal, External, Delegated };
365 361
366 Resource(); 362 Resource();
367 ~Resource(); 363 ~Resource();
368 Resource(unsigned texture_id, 364 Resource(unsigned texture_id,
369 const gfx::Size& size, 365 const gfx::Size& size,
370 Origin origin, 366 Origin origin,
371 GLenum target, 367 GLenum target,
372 GLenum filter, 368 GLenum filter,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 unsigned image_id; 406 unsigned image_id;
411 unsigned bound_image_id; 407 unsigned bound_image_id;
412 bool dirty_image; 408 bool dirty_image;
413 GLenum texture_pool; 409 GLenum texture_pool;
414 GLint wrap_mode; 410 GLint wrap_mode;
415 bool lost; 411 bool lost;
416 TextureUsageHint hint; 412 TextureUsageHint hint;
417 ResourceType type; 413 ResourceType type;
418 ResourceFormat format; 414 ResourceFormat format;
419 SharedBitmap* shared_bitmap; 415 SharedBitmap* shared_bitmap;
416 linked_ptr<DirectRasterBuffer> direct_raster_buffer;
417 linked_ptr<ImageRasterBuffer> image_raster_buffer;
418 linked_ptr<PixelRasterBuffer> pixel_raster_buffer;
420 }; 419 };
421 typedef base::hash_map<ResourceId, Resource> ResourceMap; 420 typedef base::hash_map<ResourceId, Resource> ResourceMap;
422 421
422 class RasterBuffer {
423 public:
424 virtual ~RasterBuffer();
425
426 SkCanvas* LockForWrite();
427 void UnlockForWrite();
428
429 protected:
430 RasterBuffer(const Resource* resource, ResourceProvider* resource_provider);
431 const Resource* resource() const { return resource_; }
432 ResourceProvider* resource_provider() const { return resource_provider_; }
433
434 virtual SkCanvas* DoLockForWrite() = 0;
435 virtual void DoUnlockForWrite() = 0;
436
437 private:
438 const Resource* resource_;
439 ResourceProvider* resource_provider_;
440 SkCanvas* locked_canvas_;
441 int canvas_save_count_;
442 };
443
444 class DirectRasterBuffer : public RasterBuffer {
445 public:
446 DirectRasterBuffer(const Resource* resource,
447 ResourceProvider* resource_provider);
448 virtual ~DirectRasterBuffer();
449
450 protected:
451 virtual SkCanvas* DoLockForWrite() OVERRIDE;
452 virtual void DoUnlockForWrite() OVERRIDE;
453 skia::RefPtr<SkSurface> CreateSurface();
454
455 private:
456 skia::RefPtr<SkSurface> surface_;
457 DISALLOW_COPY_AND_ASSIGN(DirectRasterBuffer);
458 };
459
460 class BitmapRasterBuffer : public RasterBuffer {
461 public:
462 virtual ~BitmapRasterBuffer();
463
464 protected:
465 BitmapRasterBuffer(const Resource* resource,
466 ResourceProvider* resource_provider);
467
468 virtual SkCanvas* DoLockForWrite() OVERRIDE;
469 virtual void DoUnlockForWrite() OVERRIDE;
470
471 virtual uint8_t* MapBuffer(int* stride) = 0;
472 virtual void UnmapBuffer() = 0;
473
474 private:
475 uint8_t* mapped_buffer_;
476 SkBitmap raster_bitmap_;
477 skia::RefPtr<SkCanvas> raster_canvas_;
478 };
479
480 class ImageRasterBuffer : public BitmapRasterBuffer {
481 public:
482 ImageRasterBuffer(const Resource* resource,
483 ResourceProvider* resource_provider);
484 virtual ~ImageRasterBuffer();
485
486 protected:
487 virtual uint8_t* MapBuffer(int* stride) OVERRIDE;
488 virtual void UnmapBuffer() OVERRIDE;
489
490 private:
491 DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer);
492 };
493
494 class PixelRasterBuffer : public BitmapRasterBuffer {
495 public:
496 PixelRasterBuffer(const Resource* resource,
497 ResourceProvider* resource_provider);
498 virtual ~PixelRasterBuffer();
499
500 protected:
501 virtual uint8_t* MapBuffer(int* stride) OVERRIDE;
502 virtual void UnmapBuffer() OVERRIDE;
503
504 private:
505 DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer);
506 };
507
423 static bool CompareResourceMapIteratorsByChildId( 508 static bool CompareResourceMapIteratorsByChildId(
424 const std::pair<ReturnedResource, ResourceMap::iterator>& a, 509 const std::pair<ReturnedResource, ResourceMap::iterator>& a,
425 const std::pair<ReturnedResource, ResourceMap::iterator>& b); 510 const std::pair<ReturnedResource, ResourceMap::iterator>& b);
426 511
427 struct Child { 512 struct Child {
428 Child(); 513 Child();
429 ~Child(); 514 ~Child();
430 515
431 ResourceIdMap child_to_parent_map; 516 ResourceIdMap child_to_parent_map;
432 ResourceIdMap parent_to_child_map; 517 ResourceIdMap parent_to_child_map;
433 ReturnCallback return_callback; 518 ReturnCallback return_callback;
434 ResourceIdSet in_use_resources; 519 ResourceIdSet in_use_resources;
435 bool marked_for_deletion; 520 bool marked_for_deletion;
436 }; 521 };
437 typedef base::hash_map<int, Child> ChildMap; 522 typedef base::hash_map<int, Child> ChildMap;
438 523
439 bool ReadLockFenceHasPassed(Resource* resource) { 524 bool ReadLockFenceHasPassed(const Resource* resource) {
440 return !resource->read_lock_fence.get() || 525 return !resource->read_lock_fence.get() ||
441 resource->read_lock_fence->HasPassed(); 526 resource->read_lock_fence->HasPassed();
442 } 527 }
443 528
444 ResourceProvider(OutputSurface* output_surface, 529 ResourceProvider(OutputSurface* output_surface,
445 SharedBitmapManager* shared_bitmap_manager, 530 SharedBitmapManager* shared_bitmap_manager,
446 int highp_threshold_min, 531 int highp_threshold_min,
447 bool use_rgba_4444_texture_format, 532 bool use_rgba_4444_texture_format,
448 size_t id_allocation_chunk_size); 533 size_t id_allocation_chunk_size);
449 534
(...skipping 14 matching lines...) Expand all
464 Normal, 549 Normal,
465 ForShutdown, 550 ForShutdown,
466 }; 551 };
467 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style); 552 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style);
468 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it, 553 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it,
469 DeleteStyle style, 554 DeleteStyle style,
470 const ResourceIdArray& unused); 555 const ResourceIdArray& unused);
471 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style); 556 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style);
472 void LazyCreate(Resource* resource); 557 void LazyCreate(Resource* resource);
473 void LazyAllocate(Resource* resource); 558 void LazyAllocate(Resource* resource);
559
560 // TODO(alokp): Move the implementation to PixelRasterBuffer.
561 // Acquire pixel buffer for resource. The pixel buffer can be used to
562 // set resource pixels without performing unnecessary copying.
563 void AcquirePixelBuffer(Resource* resource);
564 void ReleasePixelBuffer(Resource* resource);
565 // Map/unmap the acquired pixel buffer.
566 uint8_t* MapPixelBuffer(const Resource* resource, int* stride);
567 void UnmapPixelBuffer(const Resource* resource);
568
569 // TODO(alokp): Move the implementation to ImageRasterBuffer.
570 // Acquire and release an image. The image allows direct
571 // manipulation of texture memory.
572 void AcquireImage(Resource* resource);
573 void ReleaseImage(Resource* resource);
574 // Maps the acquired image so that its pixels could be modified.
575 // Unmap is called when all pixels are set.
576 uint8_t* MapImage(const Resource* resource, int* stride);
577 void UnmapImage(const Resource* resource);
578
474 void BindImageForSampling(Resource* resource); 579 void BindImageForSampling(Resource* resource);
475
476 // Binds the given GL resource to a texture target for sampling using the 580 // Binds the given GL resource to a texture target for sampling using the
477 // specified filter for both minification and magnification. Returns the 581 // specified filter for both minification and magnification. Returns the
478 // texture target used. The resource must be locked for reading. 582 // texture target used. The resource must be locked for reading.
479 GLenum BindForSampling(ResourceProvider::ResourceId resource_id, 583 GLenum BindForSampling(ResourceProvider::ResourceId resource_id,
480 GLenum unit, 584 GLenum unit,
481 GLenum filter); 585 GLenum filter);
482 586
483 // Returns NULL if the output_surface_ does not have a ContextProvider. 587 // Returns NULL if the output_surface_ does not have a ContextProvider.
484 gpu::gles2::GLES2Interface* ContextGL() const; 588 gpu::gles2::GLES2Interface* ContextGL() const;
589 class GrContext* GrContext() const;
485 590
486 OutputSurface* output_surface_; 591 OutputSurface* output_surface_;
487 SharedBitmapManager* shared_bitmap_manager_; 592 SharedBitmapManager* shared_bitmap_manager_;
488 bool lost_output_surface_; 593 bool lost_output_surface_;
489 int highp_threshold_min_; 594 int highp_threshold_min_;
490 ResourceId next_id_; 595 ResourceId next_id_;
491 ResourceMap resources_; 596 ResourceMap resources_;
492 int next_child_; 597 int next_child_;
493 ChildMap children_; 598 ChildMap children_;
494 599
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 return format_gl_data_format[format]; 659 return format_gl_data_format[format];
555 } 660 }
556 661
557 inline GLenum GLInternalFormat(ResourceFormat format) { 662 inline GLenum GLInternalFormat(ResourceFormat format) {
558 return GLDataFormat(format); 663 return GLDataFormat(format);
559 } 664 }
560 665
561 } // namespace cc 666 } // namespace cc
562 667
563 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 668 #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