| 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 CCResourceProvider_h | 5 #ifndef CCResourceProvider_h |
| 6 #define CCResourceProvider_h | 6 #define CCResourceProvider_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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace cc { | 24 namespace cc { |
| 25 | 25 |
| 26 class IntRect; | 26 class IntRect; |
| 27 class LayerTextureSubImage; | 27 class LayerTextureSubImage; |
| 28 class TextureCopier; | 28 class TextureCopier; |
| 29 class TextureUploader; | 29 class TextureUploader; |
| 30 | 30 |
| 31 // Thread-safety notes: this class is not thread-safe and can only be called | 31 // Thread-safety notes: this class is not thread-safe and can only be called |
| 32 // from the thread it was created on (in practice, the compositor thread). | 32 // from the thread it was created on (in practice, the compositor thread). |
| 33 class CCResourceProvider { | 33 class ResourceProvider { |
| 34 public: | 34 public: |
| 35 typedef unsigned ResourceId; | 35 typedef unsigned ResourceId; |
| 36 typedef std::vector<ResourceId> ResourceIdArray; | 36 typedef std::vector<ResourceId> ResourceIdArray; |
| 37 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; | 37 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; |
| 38 enum TextureUsageHint { TextureUsageAny, TextureUsageFramebuffer }; | 38 enum TextureUsageHint { TextureUsageAny, TextureUsageFramebuffer }; |
| 39 enum ResourceType { | 39 enum ResourceType { |
| 40 GLTexture = 1, | 40 GLTexture = 1, |
| 41 Bitmap, | 41 Bitmap, |
| 42 }; | 42 }; |
| 43 struct Mailbox { | 43 struct Mailbox { |
| 44 GC3Dbyte name[64]; | 44 GC3Dbyte name[64]; |
| 45 }; | 45 }; |
| 46 struct TransferableResource { | 46 struct TransferableResource { |
| 47 unsigned id; | 47 unsigned id; |
| 48 GC3Denum format; | 48 GC3Denum format; |
| 49 IntSize size; | 49 IntSize size; |
| 50 Mailbox mailbox; | 50 Mailbox mailbox; |
| 51 }; | 51 }; |
| 52 typedef std::vector<TransferableResource> TransferableResourceArray; | 52 typedef std::vector<TransferableResource> TransferableResourceArray; |
| 53 struct TransferableResourceList { | 53 struct TransferableResourceList { |
| 54 TransferableResourceList(); | 54 TransferableResourceList(); |
| 55 ~TransferableResourceList(); | 55 ~TransferableResourceList(); |
| 56 | 56 |
| 57 TransferableResourceArray resources; | 57 TransferableResourceArray resources; |
| 58 unsigned syncPoint; | 58 unsigned syncPoint; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 static scoped_ptr<CCResourceProvider> create(CCGraphicsContext*); | 61 static scoped_ptr<ResourceProvider> create(GraphicsContext*); |
| 62 | 62 |
| 63 virtual ~CCResourceProvider(); | 63 virtual ~ResourceProvider(); |
| 64 | 64 |
| 65 WebKit::WebGraphicsContext3D* graphicsContext3D(); | 65 WebKit::WebGraphicsContext3D* graphicsContext3D(); |
| 66 TextureUploader* textureUploader() const { return m_textureUploader.get(); } | 66 TextureUploader* textureUploader() const { return m_textureUploader.get(); } |
| 67 TextureCopier* textureCopier() const { return m_textureCopier.get(); } | 67 TextureCopier* textureCopier() const { return m_textureCopier.get(); } |
| 68 int maxTextureSize() const { return m_maxTextureSize; } | 68 int maxTextureSize() const { return m_maxTextureSize; } |
| 69 unsigned numResources() const { return m_resources.size(); } | 69 unsigned numResources() const { return m_resources.size(); } |
| 70 | 70 |
| 71 // Checks whether a resource is in use by a consumer. | 71 // Checks whether a resource is in use by a consumer. |
| 72 bool inUseByConsumer(ResourceId); | 72 bool inUseByConsumer(ResourceId); |
| 73 | 73 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 int createChild(int pool); | 108 int createChild(int pool); |
| 109 | 109 |
| 110 // Destroys accounting for the child, deleting all resources from that pool. | 110 // Destroys accounting for the child, deleting all resources from that pool. |
| 111 void destroyChild(int child); | 111 void destroyChild(int child); |
| 112 | 112 |
| 113 // Gets the child->parent resource ID map. | 113 // Gets the child->parent resource ID map. |
| 114 const ResourceIdMap& getChildToParentMap(int child) const; | 114 const ResourceIdMap& getChildToParentMap(int child) const; |
| 115 | 115 |
| 116 // Prepares resources to be transfered to the parent, moving them to | 116 // Prepares resources to be transfered to the parent, moving them to |
| 117 // mailboxes and serializing meta-data into TransferableResources. | 117 // mailboxes and serializing meta-data into TransferableResources. |
| 118 // Resources are not removed from the CCResourceProvider, but are markes as | 118 // Resources are not removed from the ResourceProvider, but are markes as |
| 119 // "in use". | 119 // "in use". |
| 120 TransferableResourceList prepareSendToParent(const ResourceIdArray&); | 120 TransferableResourceList prepareSendToParent(const ResourceIdArray&); |
| 121 | 121 |
| 122 // Prepares resources to be transfered back to the child, moving them to | 122 // Prepares resources to be transfered back to the child, moving them to |
| 123 // mailboxes and serializing meta-data into TransferableResources. | 123 // mailboxes and serializing meta-data into TransferableResources. |
| 124 // Resources are removed from the CCResourceProvider. Note: the resource IDs | 124 // Resources are removed from the ResourceProvider. Note: the resource IDs |
| 125 // passed are in the parent namespace and will be translated to the child | 125 // passed are in the parent namespace and will be translated to the child |
| 126 // namespace when returned. | 126 // namespace when returned. |
| 127 TransferableResourceList prepareSendToChild(int child, const ResourceIdArray
&); | 127 TransferableResourceList prepareSendToChild(int child, const ResourceIdArray
&); |
| 128 | 128 |
| 129 // Receives resources from a child, moving them from mailboxes. Resource IDs | 129 // Receives resources from a child, moving them from mailboxes. Resource IDs |
| 130 // passed are in the child namespace, and will be translated to the parent | 130 // passed are in the child namespace, and will be translated to the parent |
| 131 // namespace, added to the child->parent map. | 131 // namespace, added to the child->parent map. |
| 132 // NOTE: if the syncPoint filed in TransferableResourceList is set, this | 132 // NOTE: if the syncPoint filed in TransferableResourceList is set, this |
| 133 // will wait on it. | 133 // will wait on it. |
| 134 void receiveFromChild(int child, const TransferableResourceList&); | 134 void receiveFromChild(int child, const TransferableResourceList&); |
| 135 | 135 |
| 136 // Receives resources from the parent, moving them from mailboxes. Resource
IDs | 136 // Receives resources from the parent, moving them from mailboxes. Resource
IDs |
| 137 // passed are in the child namespace. | 137 // passed are in the child namespace. |
| 138 // NOTE: if the syncPoint filed in TransferableResourceList is set, this | 138 // NOTE: if the syncPoint filed in TransferableResourceList is set, this |
| 139 // will wait on it. | 139 // will wait on it. |
| 140 void receiveFromParent(const TransferableResourceList&); | 140 void receiveFromParent(const TransferableResourceList&); |
| 141 | 141 |
| 142 // Only for testing | 142 // Only for testing |
| 143 size_t mailboxCount() const { return m_mailboxes.size(); } | 143 size_t mailboxCount() const { return m_mailboxes.size(); } |
| 144 | 144 |
| 145 // The following lock classes are part of the CCResourceProvider API and are | 145 // The following lock classes are part of the ResourceProvider API and are |
| 146 // needed to read and write the resource contents. The user must ensure | 146 // needed to read and write the resource contents. The user must ensure |
| 147 // that they only use GL locks on GL resources, etc, and this is enforced | 147 // that they only use GL locks on GL resources, etc, and this is enforced |
| 148 // by assertions. | 148 // by assertions. |
| 149 class ScopedReadLockGL { | 149 class ScopedReadLockGL { |
| 150 public: | 150 public: |
| 151 ScopedReadLockGL(CCResourceProvider*, CCResourceProvider::ResourceId); | 151 ScopedReadLockGL(ResourceProvider*, ResourceProvider::ResourceId); |
| 152 ~ScopedReadLockGL(); | 152 ~ScopedReadLockGL(); |
| 153 | 153 |
| 154 unsigned textureId() const { return m_textureId; } | 154 unsigned textureId() const { return m_textureId; } |
| 155 | 155 |
| 156 private: | 156 private: |
| 157 CCResourceProvider* m_resourceProvider; | 157 ResourceProvider* m_resourceProvider; |
| 158 CCResourceProvider::ResourceId m_resourceId; | 158 ResourceProvider::ResourceId m_resourceId; |
| 159 unsigned m_textureId; | 159 unsigned m_textureId; |
| 160 | 160 |
| 161 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); | 161 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockGL); |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 class ScopedWriteLockGL { | 164 class ScopedWriteLockGL { |
| 165 public: | 165 public: |
| 166 ScopedWriteLockGL(CCResourceProvider*, CCResourceProvider::ResourceId); | 166 ScopedWriteLockGL(ResourceProvider*, ResourceProvider::ResourceId); |
| 167 ~ScopedWriteLockGL(); | 167 ~ScopedWriteLockGL(); |
| 168 | 168 |
| 169 unsigned textureId() const { return m_textureId; } | 169 unsigned textureId() const { return m_textureId; } |
| 170 | 170 |
| 171 private: | 171 private: |
| 172 CCResourceProvider* m_resourceProvider; | 172 ResourceProvider* m_resourceProvider; |
| 173 CCResourceProvider::ResourceId m_resourceId; | 173 ResourceProvider::ResourceId m_resourceId; |
| 174 unsigned m_textureId; | 174 unsigned m_textureId; |
| 175 | 175 |
| 176 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); | 176 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockGL); |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 class ScopedReadLockSoftware { | 179 class ScopedReadLockSoftware { |
| 180 public: | 180 public: |
| 181 ScopedReadLockSoftware(CCResourceProvider*, CCResourceProvider::Resource
Id); | 181 ScopedReadLockSoftware(ResourceProvider*, ResourceProvider::ResourceId); |
| 182 ~ScopedReadLockSoftware(); | 182 ~ScopedReadLockSoftware(); |
| 183 | 183 |
| 184 const SkBitmap* skBitmap() const { return &m_skBitmap; } | 184 const SkBitmap* skBitmap() const { return &m_skBitmap; } |
| 185 | 185 |
| 186 private: | 186 private: |
| 187 CCResourceProvider* m_resourceProvider; | 187 ResourceProvider* m_resourceProvider; |
| 188 CCResourceProvider::ResourceId m_resourceId; | 188 ResourceProvider::ResourceId m_resourceId; |
| 189 SkBitmap m_skBitmap; | 189 SkBitmap m_skBitmap; |
| 190 | 190 |
| 191 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockSoftware); | 191 DISALLOW_COPY_AND_ASSIGN(ScopedReadLockSoftware); |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 class ScopedWriteLockSoftware { | 194 class ScopedWriteLockSoftware { |
| 195 public: | 195 public: |
| 196 ScopedWriteLockSoftware(CCResourceProvider*, CCResourceProvider::Resourc
eId); | 196 ScopedWriteLockSoftware(ResourceProvider*, ResourceProvider::ResourceId)
; |
| 197 ~ScopedWriteLockSoftware(); | 197 ~ScopedWriteLockSoftware(); |
| 198 | 198 |
| 199 SkCanvas* skCanvas() { return m_skCanvas.get(); } | 199 SkCanvas* skCanvas() { return m_skCanvas.get(); } |
| 200 | 200 |
| 201 private: | 201 private: |
| 202 CCResourceProvider* m_resourceProvider; | 202 ResourceProvider* m_resourceProvider; |
| 203 CCResourceProvider::ResourceId m_resourceId; | 203 ResourceProvider::ResourceId m_resourceId; |
| 204 SkBitmap m_skBitmap; | 204 SkBitmap m_skBitmap; |
| 205 scoped_ptr<SkCanvas> m_skCanvas; | 205 scoped_ptr<SkCanvas> m_skCanvas; |
| 206 | 206 |
| 207 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); | 207 DISALLOW_COPY_AND_ASSIGN(ScopedWriteLockSoftware); |
| 208 }; | 208 }; |
| 209 | 209 |
| 210 private: | 210 private: |
| 211 struct Resource { | 211 struct Resource { |
| 212 Resource(); | 212 Resource(); |
| 213 Resource(unsigned textureId, int pool, const IntSize& size, GC3Denum for
mat); | 213 Resource(unsigned textureId, int pool, const IntSize& size, GC3Denum for
mat); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 229 struct Child { | 229 struct Child { |
| 230 Child(); | 230 Child(); |
| 231 ~Child(); | 231 ~Child(); |
| 232 | 232 |
| 233 int pool; | 233 int pool; |
| 234 ResourceIdMap childToParentMap; | 234 ResourceIdMap childToParentMap; |
| 235 ResourceIdMap parentToChildMap; | 235 ResourceIdMap parentToChildMap; |
| 236 }; | 236 }; |
| 237 typedef base::hash_map<int, Child> ChildMap; | 237 typedef base::hash_map<int, Child> ChildMap; |
| 238 | 238 |
| 239 explicit CCResourceProvider(CCGraphicsContext*); | 239 explicit ResourceProvider(GraphicsContext*); |
| 240 bool initialize(); | 240 bool initialize(); |
| 241 | 241 |
| 242 const Resource* lockForRead(ResourceId); | 242 const Resource* lockForRead(ResourceId); |
| 243 void unlockForRead(ResourceId); | 243 void unlockForRead(ResourceId); |
| 244 const Resource* lockForWrite(ResourceId); | 244 const Resource* lockForWrite(ResourceId); |
| 245 void unlockForWrite(ResourceId); | 245 void unlockForWrite(ResourceId); |
| 246 static void populateSkBitmapWithResource(SkBitmap*, const Resource*); | 246 static void populateSkBitmapWithResource(SkBitmap*, const Resource*); |
| 247 | 247 |
| 248 bool transferResource(WebKit::WebGraphicsContext3D*, ResourceId, Transferabl
eResource*); | 248 bool transferResource(WebKit::WebGraphicsContext3D*, ResourceId, Transferabl
eResource*); |
| 249 void trimMailboxDeque(); | 249 void trimMailboxDeque(); |
| 250 void deleteResourceInternal(ResourceMap::iterator it); | 250 void deleteResourceInternal(ResourceMap::iterator it); |
| 251 | 251 |
| 252 CCGraphicsContext* m_context; | 252 GraphicsContext* m_context; |
| 253 ResourceId m_nextId; | 253 ResourceId m_nextId; |
| 254 ResourceMap m_resources; | 254 ResourceMap m_resources; |
| 255 int m_nextChild; | 255 int m_nextChild; |
| 256 ChildMap m_children; | 256 ChildMap m_children; |
| 257 | 257 |
| 258 std::deque<Mailbox> m_mailboxes; | 258 std::deque<Mailbox> m_mailboxes; |
| 259 | 259 |
| 260 ResourceType m_defaultResourceType; | 260 ResourceType m_defaultResourceType; |
| 261 bool m_useTextureStorageExt; | 261 bool m_useTextureStorageExt; |
| 262 bool m_useTextureUsageHint; | 262 bool m_useTextureUsageHint; |
| 263 bool m_useShallowFlush; | 263 bool m_useShallowFlush; |
| 264 scoped_ptr<LayerTextureSubImage> m_texSubImage; | 264 scoped_ptr<LayerTextureSubImage> m_texSubImage; |
| 265 scoped_ptr<TextureUploader> m_textureUploader; | 265 scoped_ptr<TextureUploader> m_textureUploader; |
| 266 scoped_ptr<AcceleratedTextureCopier> m_textureCopier; | 266 scoped_ptr<AcceleratedTextureCopier> m_textureCopier; |
| 267 int m_maxTextureSize; | 267 int m_maxTextureSize; |
| 268 | 268 |
| 269 DISALLOW_COPY_AND_ASSIGN(CCResourceProvider); | 269 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
| 270 }; | 270 }; |
| 271 | 271 |
| 272 } | 272 } |
| 273 | 273 |
| 274 #endif | 274 #endif |
| OLD | NEW |