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

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

Issue 485043003: cc: Use correct message loop proxy in BlockingTaskRunner (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 6 years, 3 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/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" 23 #include "cc/resources/raster_buffer.h"
24 #include "cc/resources/release_callback.h" 24 #include "cc/resources/release_callback_impl.h"
25 #include "cc/resources/resource_format.h" 25 #include "cc/resources/resource_format.h"
26 #include "cc/resources/return_callback.h" 26 #include "cc/resources/return_callback.h"
27 #include "cc/resources/shared_bitmap.h" 27 #include "cc/resources/shared_bitmap.h"
28 #include "cc/resources/single_release_callback.h" 28 #include "cc/resources/single_release_callback_impl.h"
29 #include "cc/resources/texture_mailbox.h" 29 #include "cc/resources/texture_mailbox.h"
30 #include "cc/resources/transferable_resource.h" 30 #include "cc/resources/transferable_resource.h"
31 #include "third_party/khronos/GLES2/gl2.h" 31 #include "third_party/khronos/GLES2/gl2.h"
32 #include "third_party/khronos/GLES2/gl2ext.h" 32 #include "third_party/khronos/GLES2/gl2ext.h"
33 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
34 #include "third_party/skia/include/core/SkCanvas.h" 34 #include "third_party/skia/include/core/SkCanvas.h"
35 #include "ui/gfx/size.h" 35 #include "ui/gfx/size.h"
36 36
37 class GrContext; 37 class GrContext;
38 38
39 namespace gpu { 39 namespace gpu {
40 namespace gles { 40 namespace gles {
41 class GLES2Interface; 41 class GLES2Interface;
42 } 42 }
43 } 43 }
44 44
45 namespace gfx { 45 namespace gfx {
46 class Rect; 46 class Rect;
47 class Vector2d; 47 class Vector2d;
48 } 48 }
49 49
50 namespace cc { 50 namespace cc {
51 class BlockingTaskRunner;
51 class IdAllocator; 52 class IdAllocator;
52 class SharedBitmap; 53 class SharedBitmap;
53 class SharedBitmapManager; 54 class SharedBitmapManager;
54 class TextureUploader; 55 class TextureUploader;
55 56
56 // This class is not thread-safe and can only be called from the thread it was 57 // This class is not thread-safe and can only be called from the thread it was
57 // created on (in practice, the impl thread). 58 // created on (in practice, the impl thread).
58 class CC_EXPORT ResourceProvider { 59 class CC_EXPORT ResourceProvider {
59 public: 60 public:
60 typedef unsigned ResourceId; 61 typedef unsigned ResourceId;
61 typedef std::vector<ResourceId> ResourceIdArray; 62 typedef std::vector<ResourceId> ResourceIdArray;
62 typedef std::set<ResourceId> ResourceIdSet; 63 typedef std::set<ResourceId> ResourceIdSet;
63 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; 64 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap;
64 enum TextureHint { 65 enum TextureHint {
65 TextureHintDefault = 0x0, 66 TextureHintDefault = 0x0,
66 TextureHintImmutable = 0x1, 67 TextureHintImmutable = 0x1,
67 TextureHintFramebuffer = 0x2, 68 TextureHintFramebuffer = 0x2,
68 TextureHintImmutableFramebuffer = 69 TextureHintImmutableFramebuffer =
69 TextureHintImmutable | TextureHintFramebuffer 70 TextureHintImmutable | TextureHintFramebuffer
70 }; 71 };
71 enum ResourceType { 72 enum ResourceType {
72 InvalidType = 0, 73 InvalidType = 0,
73 GLTexture = 1, 74 GLTexture = 1,
74 Bitmap, 75 Bitmap,
75 }; 76 };
76 77
77 static scoped_ptr<ResourceProvider> Create( 78 static scoped_ptr<ResourceProvider> Create(
78 OutputSurface* output_surface, 79 OutputSurface* output_surface,
79 SharedBitmapManager* shared_bitmap_manager, 80 SharedBitmapManager* shared_bitmap_manager,
81 BlockingTaskRunner* blocking_main_thread_task_runner,
80 int highp_threshold_min, 82 int highp_threshold_min,
81 bool use_rgba_4444_texture_format, 83 bool use_rgba_4444_texture_format,
82 size_t id_allocation_chunk_size, 84 size_t id_allocation_chunk_size,
83 bool use_distance_field_text); 85 bool use_distance_field_text);
84 virtual ~ResourceProvider(); 86 virtual ~ResourceProvider();
85 87
86 void InitializeSoftware(); 88 void InitializeSoftware();
87 void InitializeGL(); 89 void InitializeGL();
88 90
89 void DidLoseOutputSurface() { lost_output_surface_ = true; } 91 void DidLoseOutputSurface() { lost_output_surface_ = true; }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 ResourceFormat format); 132 ResourceFormat format);
131 133
132 ResourceId CreateBitmap(const gfx::Size& size, GLint wrap_mode); 134 ResourceId CreateBitmap(const gfx::Size& size, GLint wrap_mode);
133 // Wraps an IOSurface into a GL resource. 135 // Wraps an IOSurface into a GL resource.
134 ResourceId CreateResourceFromIOSurface(const gfx::Size& size, 136 ResourceId CreateResourceFromIOSurface(const gfx::Size& size,
135 unsigned io_surface_id); 137 unsigned io_surface_id);
136 138
137 // Wraps an external texture mailbox into a GL resource. 139 // Wraps an external texture mailbox into a GL resource.
138 ResourceId CreateResourceFromTextureMailbox( 140 ResourceId CreateResourceFromTextureMailbox(
139 const TextureMailbox& mailbox, 141 const TextureMailbox& mailbox,
140 scoped_ptr<SingleReleaseCallback> release_callback); 142 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl);
141 143
142 void DeleteResource(ResourceId id); 144 void DeleteResource(ResourceId id);
143 145
144 // Update pixels from image, copying source_rect (in image) to dest_offset (in 146 // Update pixels from image, copying source_rect (in image) to dest_offset (in
145 // the resource). 147 // the resource).
146 void SetPixels(ResourceId id, 148 void SetPixels(ResourceId id,
147 const uint8_t* image, 149 const uint8_t* image,
148 const gfx::Rect& image_rect, 150 const gfx::Rect& image_rect,
149 const gfx::Rect& source_rect, 151 const gfx::Rect& source_rect,
150 const gfx::Vector2d& dest_offset); 152 const gfx::Vector2d& dest_offset);
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 // Indicates if we can currently lock this resource for write. 367 // Indicates if we can currently lock this resource for write.
366 bool CanLockForWrite(ResourceId id); 368 bool CanLockForWrite(ResourceId id);
367 369
368 // Copy pixels from source to destination. 370 // Copy pixels from source to destination.
369 void CopyResource(ResourceId source_id, ResourceId dest_id); 371 void CopyResource(ResourceId source_id, ResourceId dest_id);
370 372
371 void WaitSyncPointIfNeeded(ResourceId id); 373 void WaitSyncPointIfNeeded(ResourceId id);
372 374
373 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl); 375 static GLint GetActiveTextureUnit(gpu::gles2::GLES2Interface* gl);
374 376
377 BlockingTaskRunner* blocking_main_thread_task_runner() const {
danakj 2014/09/03 16:09:36 remove this
Sami 2014/09/03 17:59:12 Done.
378 return blocking_main_thread_task_runner_;
379 }
380
375 private: 381 private:
376 class GpuRasterBuffer; 382 class GpuRasterBuffer;
377 class ImageRasterBuffer; 383 class ImageRasterBuffer;
378 class PixelRasterBuffer; 384 class PixelRasterBuffer;
379 385
380 struct Resource { 386 struct Resource {
381 enum Origin { Internal, External, Delegated }; 387 enum Origin { Internal, External, Delegated };
382 388
383 Resource(); 389 Resource();
384 ~Resource(); 390 ~Resource();
(...skipping 20 matching lines...) Expand all
405 411
406 int child_id; 412 int child_id;
407 unsigned gl_id; 413 unsigned gl_id;
408 // Pixel buffer used for set pixels without unnecessary copying. 414 // Pixel buffer used for set pixels without unnecessary copying.
409 unsigned gl_pixel_buffer_id; 415 unsigned gl_pixel_buffer_id;
410 // Query used to determine when asynchronous set pixels complete. 416 // Query used to determine when asynchronous set pixels complete.
411 unsigned gl_upload_query_id; 417 unsigned gl_upload_query_id;
412 // Query used to determine when read lock fence has passed. 418 // Query used to determine when read lock fence has passed.
413 unsigned gl_read_lock_query_id; 419 unsigned gl_read_lock_query_id;
414 TextureMailbox mailbox; 420 TextureMailbox mailbox;
415 ReleaseCallback release_callback; 421 ReleaseCallbackImpl release_callback_impl;
416 uint8_t* pixels; 422 uint8_t* pixels;
417 int lock_for_read_count; 423 int lock_for_read_count;
418 int imported_count; 424 int imported_count;
419 int exported_count; 425 int exported_count;
420 bool dirty_image : 1; 426 bool dirty_image : 1;
421 bool locked_for_write : 1; 427 bool locked_for_write : 1;
422 bool lost : 1; 428 bool lost : 1;
423 bool marked_for_deletion : 1; 429 bool marked_for_deletion : 1;
424 bool pending_set_pixels : 1; 430 bool pending_set_pixels : 1;
425 bool set_pixels_completion_forced : 1; 431 bool set_pixels_completion_forced : 1;
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 }; 535 };
530 typedef base::hash_map<int, Child> ChildMap; 536 typedef base::hash_map<int, Child> ChildMap;
531 537
532 bool ReadLockFenceHasPassed(const Resource* resource) { 538 bool ReadLockFenceHasPassed(const Resource* resource) {
533 return !resource->read_lock_fence.get() || 539 return !resource->read_lock_fence.get() ||
534 resource->read_lock_fence->HasPassed(); 540 resource->read_lock_fence->HasPassed();
535 } 541 }
536 542
537 ResourceProvider(OutputSurface* output_surface, 543 ResourceProvider(OutputSurface* output_surface,
538 SharedBitmapManager* shared_bitmap_manager, 544 SharedBitmapManager* shared_bitmap_manager,
545 BlockingTaskRunner* blocking_main_thread_task_runner,
539 int highp_threshold_min, 546 int highp_threshold_min,
540 bool use_rgba_4444_texture_format, 547 bool use_rgba_4444_texture_format,
541 size_t id_allocation_chunk_size, 548 size_t id_allocation_chunk_size,
542 bool use_distance_field_text); 549 bool use_distance_field_text);
543 550
544 void CleanUpGLIfNeeded(); 551 void CleanUpGLIfNeeded();
545 552
546 Resource* GetResource(ResourceId id); 553 Resource* GetResource(ResourceId id);
547 const Resource* LockForRead(ResourceId id); 554 const Resource* LockForRead(ResourceId id);
548 void UnlockForRead(ResourceId id); 555 void UnlockForRead(ResourceId id);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 GLenum BindForSampling(ResourceProvider::ResourceId resource_id, 599 GLenum BindForSampling(ResourceProvider::ResourceId resource_id,
593 GLenum unit, 600 GLenum unit,
594 GLenum filter); 601 GLenum filter);
595 602
596 // Returns NULL if the output_surface_ does not have a ContextProvider. 603 // Returns NULL if the output_surface_ does not have a ContextProvider.
597 gpu::gles2::GLES2Interface* ContextGL() const; 604 gpu::gles2::GLES2Interface* ContextGL() const;
598 class GrContext* GrContext() const; 605 class GrContext* GrContext() const;
599 606
600 OutputSurface* output_surface_; 607 OutputSurface* output_surface_;
601 SharedBitmapManager* shared_bitmap_manager_; 608 SharedBitmapManager* shared_bitmap_manager_;
609 BlockingTaskRunner* blocking_main_thread_task_runner_;
602 bool lost_output_surface_; 610 bool lost_output_surface_;
603 int highp_threshold_min_; 611 int highp_threshold_min_;
604 ResourceId next_id_; 612 ResourceId next_id_;
605 ResourceMap resources_; 613 ResourceMap resources_;
606 int next_child_; 614 int next_child_;
607 ChildMap children_; 615 ChildMap children_;
608 616
609 ResourceType default_resource_type_; 617 ResourceType default_resource_type_;
610 bool use_texture_storage_ext_; 618 bool use_texture_storage_ext_;
611 bool use_texture_format_bgra_; 619 bool use_texture_format_bgra_;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 return format_gl_data_format[format]; 684 return format_gl_data_format[format];
677 } 685 }
678 686
679 inline GLenum GLInternalFormat(ResourceFormat format) { 687 inline GLenum GLInternalFormat(ResourceFormat format) {
680 return GLDataFormat(format); 688 return GLDataFormat(format);
681 } 689 }
682 690
683 } // namespace cc 691 } // namespace cc
684 692
685 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 693 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698