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

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

Issue 43753002: cc: Keep track of busy resources in ResourcePool (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 1 month 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
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/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
18 #include "base/memory/weak_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
34 namespace WebKit { class WebGraphicsContext3D; } 35 namespace WebKit { class WebGraphicsContext3D; }
35 36
36 namespace gfx { 37 namespace gfx {
37 class Rect; 38 class Rect;
38 class Vector2d; 39 class Vector2d;
39 } 40 }
40 41
41 namespace cc { 42 namespace cc {
42 class SharedBitmap; 43 class SharedBitmap;
43 class SharedBitmapManager; 44 class SharedBitmapManager;
44 class TextureUploader; 45 class TextureUploader;
46 class ResourceProviderClient;
45 47
46 // This class is not thread-safe and can only be called from the thread it was 48 // This class is not thread-safe and can only be called from the thread it was
47 // created on (in practice, the impl thread). 49 // created on (in practice, the impl thread).
48 class CC_EXPORT ResourceProvider { 50 class CC_EXPORT ResourceProvider
51 : public base::SupportsWeakPtr<ResourceProvider> {
piman 2013/10/25 21:51:11 we want to remove the use of SupportsWeakPtr in th
49 public: 52 public:
50 typedef unsigned ResourceId; 53 typedef unsigned ResourceId;
51 typedef std::vector<ResourceId> ResourceIdArray; 54 typedef std::vector<ResourceId> ResourceIdArray;
52 typedef std::set<ResourceId> ResourceIdSet; 55 typedef std::set<ResourceId> ResourceIdSet;
53 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; 56 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap;
54 enum TextureUsageHint { 57 enum TextureUsageHint {
55 TextureUsageAny, 58 TextureUsageAny,
56 TextureUsageFramebuffer, 59 TextureUsageFramebuffer,
57 }; 60 };
58 enum ResourceType { 61 enum ResourceType {
59 InvalidType = 0, 62 InvalidType = 0,
60 GLTexture = 1, 63 GLTexture = 1,
61 Bitmap, 64 Bitmap,
62 }; 65 };
63 66
64 static scoped_ptr<ResourceProvider> Create( 67 static scoped_ptr<ResourceProvider> Create(
65 OutputSurface* output_surface, 68 OutputSurface* output_surface,
66 SharedBitmapManager* shared_bitmap_manager, 69 SharedBitmapManager* shared_bitmap_manager,
67 int highp_threshold_min, 70 int highp_threshold_min,
68 bool use_rgba_4444_texture_format); 71 bool use_rgba_4444_texture_format);
69 virtual ~ResourceProvider(); 72 virtual ~ResourceProvider();
70 73
74 void SetClient(ResourceProviderClient* client);
75
71 void InitializeSoftware(); 76 void InitializeSoftware();
72 bool InitializeGL(); 77 bool InitializeGL();
73 78
74 void DidLoseOutputSurface() { lost_output_surface_ = true; } 79 void DidLoseOutputSurface() { lost_output_surface_ = true; }
75 80
76 int max_texture_size() const { return max_texture_size_; } 81 int max_texture_size() const { return max_texture_size_; }
77 ResourceFormat memory_efficient_texture_format() const { 82 ResourceFormat memory_efficient_texture_format() const {
78 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_; 83 return use_rgba_4444_texture_format_ ? RGBA_4444 : best_texture_format_;
79 } 84 }
80 ResourceFormat best_texture_format() const { return best_texture_format_; } 85 ResourceFormat best_texture_format() const { return best_texture_format_; }
81 size_t num_resources() const { return resources_.size(); } 86 size_t num_resources() const { return resources_.size(); }
82 87
83 // Checks whether a resource is in use by a consumer. 88 // Checks whether a resource is in use by a consumer.
84 bool InUseByConsumer(ResourceId id); 89 bool InUseByConsumer(ResourceId id);
85 90
86 bool IsLost(ResourceId id); 91 bool IsLost(ResourceId id);
92 bool IsExported(ResourceId id);
87 93
88 // Producer interface. 94 // Producer interface.
89 95
90 ResourceType default_resource_type() const { return default_resource_type_; } 96 ResourceType default_resource_type() const { return default_resource_type_; }
91 ResourceType GetResourceType(ResourceId id); 97 ResourceType GetResourceType(ResourceId id);
92 98
93 // Creates a resource of the default resource type. 99 // Creates a resource of the default resource type.
94 ResourceId CreateResource(gfx::Size size, 100 ResourceId CreateResource(gfx::Size size,
95 GLint wrap_mode, 101 GLint wrap_mode,
96 TextureUsageHint hint, 102 TextureUsageHint hint,
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 // specified filter for both minification and magnification. The resource 468 // specified filter for both minification and magnification. The resource
463 // must be locked for reading. 469 // must be locked for reading.
464 void BindForSampling(ResourceProvider::ResourceId resource_id, 470 void BindForSampling(ResourceProvider::ResourceId resource_id,
465 GLenum target, 471 GLenum target,
466 GLenum unit, 472 GLenum unit,
467 GLenum filter); 473 GLenum filter);
468 474
469 // Returns NULL if the output_surface_ does not have a ContextProvider. 475 // Returns NULL if the output_surface_ does not have a ContextProvider.
470 WebKit::WebGraphicsContext3D* Context3d() const; 476 WebKit::WebGraphicsContext3D* Context3d() const;
471 477
478 ResourceProviderClient* client_;
472 OutputSurface* output_surface_; 479 OutputSurface* output_surface_;
473 SharedBitmapManager* shared_bitmap_manager_; 480 SharedBitmapManager* shared_bitmap_manager_;
474 bool lost_output_surface_; 481 bool lost_output_surface_;
475 int highp_threshold_min_; 482 int highp_threshold_min_;
476 ResourceId next_id_; 483 ResourceId next_id_;
477 ResourceMap resources_; 484 ResourceMap resources_;
478 int next_child_; 485 int next_child_;
479 ChildMap children_; 486 ChildMap children_;
480 487
481 ResourceType default_resource_type_; 488 ResourceType default_resource_type_;
482 bool use_texture_storage_ext_; 489 bool use_texture_storage_ext_;
483 bool use_texture_usage_hint_; 490 bool use_texture_usage_hint_;
484 bool use_shallow_flush_; 491 bool use_shallow_flush_;
485 bool use_compressed_texture_etc1_; 492 bool use_compressed_texture_etc1_;
486 scoped_ptr<TextureUploader> texture_uploader_; 493 scoped_ptr<TextureUploader> texture_uploader_;
487 int max_texture_size_; 494 int max_texture_size_;
488 ResourceFormat best_texture_format_; 495 ResourceFormat best_texture_format_;
489 496
490 base::ThreadChecker thread_checker_; 497 base::ThreadChecker thread_checker_;
491 498
492 scoped_refptr<Fence> current_read_lock_fence_; 499 scoped_refptr<Fence> current_read_lock_fence_;
493 bool use_rgba_4444_texture_format_; 500 bool use_rgba_4444_texture_format_;
494 501
495 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); 502 DISALLOW_COPY_AND_ASSIGN(ResourceProvider);
496 }; 503 };
497 504
505 class ResourceProviderClient {
506 public:
507 virtual void ResourceExported(ResourceProvider::ResourceId id) = 0;
508 virtual void ResourceReturned(ResourceProvider::ResourceId id) = 0;
509 };
498 510
499 // TODO(epenner): Move these format conversions to resource_format.h 511 // TODO(epenner): Move these format conversions to resource_format.h
500 // once that builds on mac (npapi.h currently #includes OpenGL.h). 512 // once that builds on mac (npapi.h currently #includes OpenGL.h).
501 inline unsigned BitsPerPixel(ResourceFormat format) { 513 inline unsigned BitsPerPixel(ResourceFormat format) {
502 DCHECK_LE(format, RESOURCE_FORMAT_MAX); 514 DCHECK_LE(format, RESOURCE_FORMAT_MAX);
503 static const unsigned format_bits_per_pixel[RESOURCE_FORMAT_MAX + 1] = { 515 static const unsigned format_bits_per_pixel[RESOURCE_FORMAT_MAX + 1] = {
504 32, // RGBA_8888 516 32, // RGBA_8888
505 16, // RGBA_4444 517 16, // RGBA_4444
506 32, // BGRA_8888 518 32, // BGRA_8888
507 8, // LUMINANCE_8 519 8, // LUMINANCE_8
(...skipping 29 matching lines...) Expand all
537 return format_gl_data_format[format]; 549 return format_gl_data_format[format];
538 } 550 }
539 551
540 inline GLenum GLInternalFormat(ResourceFormat format) { 552 inline GLenum GLInternalFormat(ResourceFormat format) {
541 return GLDataFormat(format); 553 return GLDataFormat(format);
542 } 554 }
543 555
544 } // namespace cc 556 } // namespace cc
545 557
546 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_ 558 #endif // CC_RESOURCES_RESOURCE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698