OLD | NEW |
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_RESOURCE_PROVIDER_H_ | 5 #ifndef CC_RESOURCE_PROVIDER_H_ |
6 #define CC_RESOURCE_PROVIDER_H_ | 6 #define CC_RESOURCE_PROVIDER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 class TextureUploader; | 34 class TextureUploader; |
35 | 35 |
36 // This class is not thread-safe and can only be called from the thread it was | 36 // This class is not thread-safe and can only be called from the thread it was |
37 // created on (in practice, the impl thread). | 37 // created on (in practice, the impl thread). |
38 class CC_EXPORT ResourceProvider { | 38 class CC_EXPORT ResourceProvider { |
39 public: | 39 public: |
40 typedef unsigned ResourceId; | 40 typedef unsigned ResourceId; |
41 typedef std::vector<ResourceId> ResourceIdArray; | 41 typedef std::vector<ResourceId> ResourceIdArray; |
42 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; | 42 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; |
43 enum TextureUsageHint { TextureUsageAny, TextureUsageFramebuffer }; | 43 enum TextureUsageHint { |
| 44 TextureUsageAny, |
| 45 TextureUsageFramebuffer, |
| 46 }; |
44 enum ResourceType { | 47 enum ResourceType { |
45 GLTexture = 1, | 48 GLTexture = 1, |
46 Bitmap, | 49 Bitmap, |
47 }; | 50 }; |
48 | 51 |
49 static scoped_ptr<ResourceProvider> create(OutputSurface*); | 52 static scoped_ptr<ResourceProvider> create(OutputSurface*); |
50 | 53 |
51 virtual ~ResourceProvider(); | 54 virtual ~ResourceProvider(); |
52 | 55 |
53 WebKit::WebGraphicsContext3D* graphicsContext3D(); | 56 WebKit::WebGraphicsContext3D* graphicsContext3D(); |
54 TextureCopier* textureCopier() const { return m_textureCopier.get(); } | 57 TextureCopier* textureCopier() const { return m_textureCopier.get(); } |
55 int maxTextureSize() const { return m_maxTextureSize; } | 58 int maxTextureSize() const { return m_maxTextureSize; } |
56 GLenum bestTextureFormat() const { return m_bestTextureFormat; } | 59 GLenum bestTextureFormat() const { return m_bestTextureFormat; } |
57 unsigned numResources() const { return m_resources.size(); } | 60 unsigned numResources() const { return m_resources.size(); } |
58 | 61 |
59 // Checks whether a resource is in use by a consumer. | 62 // Checks whether a resource is in use by a consumer. |
60 bool inUseByConsumer(ResourceId); | 63 bool inUseByConsumer(ResourceId); |
61 | 64 |
62 | 65 |
63 // Producer interface. | 66 // Producer interface. |
64 | 67 |
65 void setDefaultResourceType(ResourceType type) { m_defaultResourceType = typ
e; } | 68 void setDefaultResourceType(ResourceType type) { m_defaultResourceType = typ
e; } |
66 ResourceType defaultResourceType() const { return m_defaultResourceType; } | 69 ResourceType defaultResourceType() const { return m_defaultResourceType; } |
67 ResourceType resourceType(ResourceId); | 70 ResourceType resourceType(ResourceId); |
68 | 71 |
69 // Creates a resource of the default resource type. | 72 // Creates a resource of the default resource type. |
70 ResourceId createResource(int pool, const gfx::Size&, GLenum format, Texture
UsageHint); | 73 ResourceId createResource(const gfx::Size&, GLenum format, TextureUsageHint)
; |
71 | 74 |
72 // You can also explicitly create a specific resource type. | 75 // You can also explicitly create a specific resource type. |
73 ResourceId createGLTexture(int pool, const gfx::Size&, GLenum format, Textur
eUsageHint); | 76 ResourceId createGLTexture(const gfx::Size&, GLenum format, TextureUsageHint
); |
74 ResourceId createBitmap(int pool, const gfx::Size&); | 77 ResourceId createBitmap(const gfx::Size&); |
75 // Wraps an external texture into a GL resource. | 78 // Wraps an external texture into a GL resource. |
76 ResourceId createResourceFromExternalTexture(unsigned textureId); | 79 ResourceId createResourceFromExternalTexture(unsigned textureId); |
77 | 80 |
78 void deleteResource(ResourceId); | 81 void deleteResource(ResourceId); |
79 | 82 |
80 // Deletes all resources owned by a given pool. | |
81 void deleteOwnedResources(int pool); | |
82 | |
83 // Update pixels from image, copying sourceRect (in image) into destRect (in
the resource). | 83 // Update pixels from image, copying sourceRect (in image) into destRect (in
the resource). |
84 void setPixels(ResourceId, const uint8_t* image, const gfx::Rect& imageRect,
const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset); | 84 void setPixels(ResourceId, const uint8_t* image, const gfx::Rect& imageRect,
const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset); |
85 | 85 |
86 // Check upload status. | 86 // Check upload status. |
87 size_t numBlockingUploads(); | 87 size_t numBlockingUploads(); |
88 void markPendingUploadsAsNonBlocking(); | 88 void markPendingUploadsAsNonBlocking(); |
89 double estimatedUploadsPerSecond(); | 89 double estimatedUploadsPerSecond(); |
90 void flushUploads(); | 90 void flushUploads(); |
91 | 91 |
92 // Flush all context operations, kicking uploads and ensuring ordering with | 92 // Flush all context operations, kicking uploads and ensuring ordering with |
93 // respect to other contexts. | 93 // respect to other contexts. |
94 void flush(); | 94 void flush(); |
95 | 95 |
96 // Only flush the command buffer if supported. | 96 // Only flush the command buffer if supported. |
97 // Returns true if the shallow flush occurred, false otherwise. | 97 // Returns true if the shallow flush occurred, false otherwise. |
98 bool shallowFlushIfSupported(); | 98 bool shallowFlushIfSupported(); |
99 | 99 |
100 // Creates accounting for a child, and associate it with a pool. Resources | 100 // Creates accounting for a child. Returns a child ID. |
101 // transfered from that child will go to that pool. Returns a child ID. | 101 int createChild(); |
102 int createChild(int pool); | |
103 | 102 |
104 // Destroys accounting for the child, deleting all resources from that pool. | 103 // Destroys accounting for the child, deleting all accounted resources. |
105 void destroyChild(int child); | 104 void destroyChild(int child); |
106 | 105 |
107 // Gets the child->parent resource ID map. | 106 // Gets the child->parent resource ID map. |
108 const ResourceIdMap& getChildToParentMap(int child) const; | 107 const ResourceIdMap& getChildToParentMap(int child) const; |
109 | 108 |
110 // Prepares resources to be transfered to the parent, moving them to | 109 // Prepares resources to be transfered to the parent, moving them to |
111 // mailboxes and serializing meta-data into TransferableResources. | 110 // mailboxes and serializing meta-data into TransferableResources. |
112 // Resources are not removed from the ResourceProvider, but are marked as | 111 // Resources are not removed from the ResourceProvider, but are marked as |
113 // "in use". | 112 // "in use". |
114 void prepareSendToParent(const ResourceIdArray&, TransferableResourceList*); | 113 void prepareSendToParent(const ResourceIdArray&, TransferableResourceList*); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // Update pixels from acquired pixel buffer. | 222 // Update pixels from acquired pixel buffer. |
224 void setPixelsFromBuffer(ResourceId id); | 223 void setPixelsFromBuffer(ResourceId id); |
225 | 224 |
226 // Asynchronously update pixels from acquired pixel buffer. | 225 // Asynchronously update pixels from acquired pixel buffer. |
227 void beginSetPixels(ResourceId id); | 226 void beginSetPixels(ResourceId id); |
228 bool didSetPixelsComplete(ResourceId id); | 227 bool didSetPixelsComplete(ResourceId id); |
229 | 228 |
230 private: | 229 private: |
231 struct Resource { | 230 struct Resource { |
232 Resource(); | 231 Resource(); |
233 Resource(unsigned textureId, int pool, const gfx::Size& size, GLenum for
mat, GLenum filter); | 232 Resource(unsigned textureId, const gfx::Size& size, GLenum format, GLenu
m filter); |
234 Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format
, GLenum filter); | 233 Resource(uint8_t* pixels, const gfx::Size& size, GLenum format, GLenum f
ilter); |
235 | 234 |
236 unsigned glId; | 235 unsigned glId; |
237 // Pixel buffer used for set pixels without unnecessary copying. | 236 // Pixel buffer used for set pixels without unnecessary copying. |
238 unsigned glPixelBufferId; | 237 unsigned glPixelBufferId; |
239 // Query used to determine when asynchronous set pixels complete. | 238 // Query used to determine when asynchronous set pixels complete. |
240 unsigned glUploadQueryId; | 239 unsigned glUploadQueryId; |
241 Mailbox mailbox; | 240 Mailbox mailbox; |
242 uint8_t* pixels; | 241 uint8_t* pixels; |
243 uint8_t* pixelBuffer; | 242 uint8_t* pixelBuffer; |
244 int pool; | |
245 int lockForReadCount; | 243 int lockForReadCount; |
246 bool lockedForWrite; | 244 bool lockedForWrite; |
247 bool external; | 245 bool external; |
248 bool exported; | 246 bool exported; |
249 bool markedForDeletion; | 247 bool markedForDeletion; |
250 bool pendingSetPixels; | 248 bool pendingSetPixels; |
251 gfx::Size size; | 249 gfx::Size size; |
252 GLenum format; | 250 GLenum format; |
253 // TODO(skyostil): Use a separate sampler object for filter state. | 251 // TODO(skyostil): Use a separate sampler object for filter state. |
254 GLenum filter; | 252 GLenum filter; |
255 ResourceType type; | 253 ResourceType type; |
256 }; | 254 }; |
257 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 255 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
258 struct Child { | 256 struct Child { |
259 Child(); | 257 Child(); |
260 ~Child(); | 258 ~Child(); |
261 | 259 |
262 int pool; | |
263 ResourceIdMap childToParentMap; | 260 ResourceIdMap childToParentMap; |
264 ResourceIdMap parentToChildMap; | 261 ResourceIdMap parentToChildMap; |
265 }; | 262 }; |
266 typedef base::hash_map<int, Child> ChildMap; | 263 typedef base::hash_map<int, Child> ChildMap; |
267 | 264 |
268 explicit ResourceProvider(OutputSurface*); | 265 explicit ResourceProvider(OutputSurface*); |
269 bool initialize(); | 266 bool initialize(); |
270 | 267 |
271 const Resource* lockForRead(ResourceId); | 268 const Resource* lockForRead(ResourceId); |
272 void unlockForRead(ResourceId); | 269 void unlockForRead(ResourceId); |
(...skipping 20 matching lines...) Expand all Loading... |
293 GLenum m_bestTextureFormat; | 290 GLenum m_bestTextureFormat; |
294 | 291 |
295 base::ThreadChecker m_threadChecker; | 292 base::ThreadChecker m_threadChecker; |
296 | 293 |
297 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 294 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
298 }; | 295 }; |
299 | 296 |
300 } | 297 } |
301 | 298 |
302 #endif // CC_RESOURCE_PROVIDER_H_ | 299 #endif // CC_RESOURCE_PROVIDER_H_ |
OLD | NEW |