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

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: implement acquire/release/map/unmap 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
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);
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;
reveman 2014/02/11 02:00:44 scoped_ptr would be preferred but I assume this ne
alokp 2014/02/11 07:05:21 Yes. It needs to be copyable.
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* buffer_;
476 skia::RefPtr<SkCanvas> canvas_;
477 };
478
479 class ImageRasterBuffer : public BitmapRasterBuffer {
480 public:
481 ImageRasterBuffer(const Resource* resource,
482 ResourceProvider* resource_provider);
483 virtual ~ImageRasterBuffer();
484
485 protected:
486 virtual uint8_t* MapBuffer(int* stride) OVERRIDE;
487 virtual void UnmapBuffer() OVERRIDE;
488
489 private:
490 DISALLOW_COPY_AND_ASSIGN(ImageRasterBuffer);
491 };
492
493 class PixelRasterBuffer : public BitmapRasterBuffer {
494 public:
495 PixelRasterBuffer(const Resource* resource,
496 ResourceProvider* resource_provider);
497 virtual ~PixelRasterBuffer();
498
499 protected:
500 virtual uint8_t* MapBuffer(int* stride) OVERRIDE;
501 virtual void UnmapBuffer() OVERRIDE;
502
503 private:
504 DISALLOW_COPY_AND_ASSIGN(PixelRasterBuffer);
505 };
506
423 static bool CompareResourceMapIteratorsByChildId( 507 static bool CompareResourceMapIteratorsByChildId(
424 const std::pair<ReturnedResource, ResourceMap::iterator>& a, 508 const std::pair<ReturnedResource, ResourceMap::iterator>& a,
425 const std::pair<ReturnedResource, ResourceMap::iterator>& b); 509 const std::pair<ReturnedResource, ResourceMap::iterator>& b);
426 510
427 struct Child { 511 struct Child {
428 Child(); 512 Child();
429 ~Child(); 513 ~Child();
430 514
431 ResourceIdMap child_to_parent_map; 515 ResourceIdMap child_to_parent_map;
432 ResourceIdMap parent_to_child_map; 516 ResourceIdMap parent_to_child_map;
433 ReturnCallback return_callback; 517 ReturnCallback return_callback;
434 ResourceIdSet in_use_resources; 518 ResourceIdSet in_use_resources;
435 bool marked_for_deletion; 519 bool marked_for_deletion;
436 }; 520 };
437 typedef base::hash_map<int, Child> ChildMap; 521 typedef base::hash_map<int, Child> ChildMap;
438 522
439 bool ReadLockFenceHasPassed(Resource* resource) { 523 bool ReadLockFenceHasPassed(const Resource* resource) {
440 return !resource->read_lock_fence.get() || 524 return !resource->read_lock_fence.get() ||
441 resource->read_lock_fence->HasPassed(); 525 resource->read_lock_fence->HasPassed();
442 } 526 }
443 527
444 ResourceProvider(OutputSurface* output_surface, 528 ResourceProvider(OutputSurface* output_surface,
445 SharedBitmapManager* shared_bitmap_manager, 529 SharedBitmapManager* shared_bitmap_manager,
446 int highp_threshold_min, 530 int highp_threshold_min,
447 bool use_rgba_4444_texture_format, 531 bool use_rgba_4444_texture_format,
448 size_t id_allocation_chunk_size); 532 size_t id_allocation_chunk_size);
449 533
(...skipping 14 matching lines...) Expand all
464 Normal, 548 Normal,
465 ForShutdown, 549 ForShutdown,
466 }; 550 };
467 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style); 551 void DeleteResourceInternal(ResourceMap::iterator it, DeleteStyle style);
468 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it, 552 void DeleteAndReturnUnusedResourcesToChild(ChildMap::iterator child_it,
469 DeleteStyle style, 553 DeleteStyle style,
470 const ResourceIdArray& unused); 554 const ResourceIdArray& unused);
471 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style); 555 void DestroyChildInternal(ChildMap::iterator it, DeleteStyle style);
472 void LazyCreate(Resource* resource); 556 void LazyCreate(Resource* resource);
473 void LazyAllocate(Resource* resource); 557 void LazyAllocate(Resource* resource);
558
559 // TODO(alokp): Move the implementation to PixelRasterBuffer.
560 // Acquire pixel buffer for resource. The pixel buffer can be used to
561 // set resource pixels without performing unnecessary copying.
562 void AcquirePixelBuffer(Resource* resource);
563 void ReleasePixelBuffer(Resource* resource);
564 // Map/unmap the acquired pixel buffer.
565 uint8_t* MapPixelBuffer(const Resource* resource, int* stride);
566 void UnmapPixelBuffer(const Resource* resource);
567
568 // TODO(alokp): Move the implementation to ImageRasterBuffer.
569 // Acquire and release an image. The image allows direct
570 // manipulation of texture memory.
571 void AcquireImage(Resource* resource);
572 void ReleaseImage(Resource* resource);
573 // Maps the acquired image so that its pixels could be modified.
574 // Unmap is called when all pixels are set.
575 uint8_t* MapImage(const Resource* resource, int* stride);
576 void UnmapImage(const Resource* resource);
577
474 void BindImageForSampling(Resource* resource); 578 void BindImageForSampling(Resource* resource);
475
476 // Binds the given GL resource to a texture target for sampling using the 579 // Binds the given GL resource to a texture target for sampling using the
477 // specified filter for both minification and magnification. Returns the 580 // specified filter for both minification and magnification. Returns the
478 // texture target used. The resource must be locked for reading. 581 // texture target used. The resource must be locked for reading.
479 GLenum BindForSampling(ResourceProvider::ResourceId resource_id, 582 GLenum BindForSampling(ResourceProvider::ResourceId resource_id,
480 GLenum unit, 583 GLenum unit,
481 GLenum filter); 584 GLenum filter);
482 585
483 // Returns NULL if the output_surface_ does not have a ContextProvider. 586 // Returns NULL if the output_surface_ does not have a ContextProvider.
484 gpu::gles2::GLES2Interface* ContextGL() const; 587 gpu::gles2::GLES2Interface* ContextGL() const;
588 class GrContext* GrContext() const;
485 589
486 OutputSurface* output_surface_; 590 OutputSurface* output_surface_;
487 SharedBitmapManager* shared_bitmap_manager_; 591 SharedBitmapManager* shared_bitmap_manager_;
488 bool lost_output_surface_; 592 bool lost_output_surface_;
489 int highp_threshold_min_; 593 int highp_threshold_min_;
490 ResourceId next_id_; 594 ResourceId next_id_;
491 ResourceMap resources_; 595 ResourceMap resources_;
492 int next_child_; 596 int next_child_;
493 ChildMap children_; 597 ChildMap children_;
494 598
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 return format_gl_data_format[format]; 658 return format_gl_data_format[format];
555 } 659 }
556 660
557 inline GLenum GLInternalFormat(ResourceFormat format) { 661 inline GLenum GLInternalFormat(ResourceFormat format) {
558 return GLDataFormat(format); 662 return GLDataFormat(format);
559 } 663 }
560 664
561 } // namespace cc 665 } // namespace cc
562 666
563 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 667 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698