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 "IntSize.h" | |
9 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
10 #include "base/hash_tables.h" | 9 #include "base/hash_tables.h" |
11 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
12 #include "cc/graphics_context.h" | 11 #include "cc/graphics_context.h" |
13 #include "cc/texture_copier.h" | 12 #include "cc/texture_copier.h" |
14 #include "third_party/khronos/GLES2/gl2.h" | 13 #include "third_party/khronos/GLES2/gl2.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "third_party/skia/include/core/SkCanvas.h" | 15 #include "third_party/skia/include/core/SkCanvas.h" |
| 16 #include "ui/gfx/size.h" |
17 #include <deque> | 17 #include <deque> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 namespace WebKit { | 20 namespace WebKit { |
21 class WebGraphicsContext3D; | 21 class WebGraphicsContext3D; |
22 } | 22 } |
23 | 23 |
| 24 namespace gfx { |
| 25 class Rect; |
| 26 class Vector2d; |
| 27 } |
| 28 |
24 namespace cc { | 29 namespace cc { |
25 | 30 |
26 class IntRect; | |
27 class LayerTextureSubImage; | 31 class LayerTextureSubImage; |
28 class TextureCopier; | 32 class TextureCopier; |
29 class TextureUploader; | 33 class TextureUploader; |
30 | 34 |
31 // Thread-safety notes: this class is not thread-safe and can only be called | 35 // 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). | 36 // from the thread it was created on (in practice, the compositor thread). |
33 class ResourceProvider { | 37 class ResourceProvider { |
34 public: | 38 public: |
35 typedef unsigned ResourceId; | 39 typedef unsigned ResourceId; |
36 typedef std::vector<ResourceId> ResourceIdArray; | 40 typedef std::vector<ResourceId> ResourceIdArray; |
37 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; | 41 typedef base::hash_map<ResourceId, ResourceId> ResourceIdMap; |
38 enum TextureUsageHint { TextureUsageAny, TextureUsageFramebuffer }; | 42 enum TextureUsageHint { TextureUsageAny, TextureUsageFramebuffer }; |
39 enum ResourceType { | 43 enum ResourceType { |
40 GLTexture = 1, | 44 GLTexture = 1, |
41 Bitmap, | 45 Bitmap, |
42 }; | 46 }; |
43 struct Mailbox { | 47 struct Mailbox { |
44 GLbyte name[64]; | 48 GLbyte name[64]; |
45 }; | 49 }; |
46 struct TransferableResource { | 50 struct TransferableResource { |
47 unsigned id; | 51 unsigned id; |
48 GLenum format; | 52 GLenum format; |
49 IntSize size; | 53 gfx::Size size; |
50 Mailbox mailbox; | 54 Mailbox mailbox; |
51 }; | 55 }; |
52 typedef std::vector<TransferableResource> TransferableResourceArray; | 56 typedef std::vector<TransferableResource> TransferableResourceArray; |
53 struct TransferableResourceList { | 57 struct TransferableResourceList { |
54 TransferableResourceList(); | 58 TransferableResourceList(); |
55 ~TransferableResourceList(); | 59 ~TransferableResourceList(); |
56 | 60 |
57 TransferableResourceArray resources; | 61 TransferableResourceArray resources; |
58 unsigned syncPoint; | 62 unsigned syncPoint; |
59 }; | 63 }; |
(...skipping 11 matching lines...) Expand all Loading... |
71 bool inUseByConsumer(ResourceId); | 75 bool inUseByConsumer(ResourceId); |
72 | 76 |
73 | 77 |
74 // Producer interface. | 78 // Producer interface. |
75 | 79 |
76 void setDefaultResourceType(ResourceType type) { m_defaultResourceType = typ
e; } | 80 void setDefaultResourceType(ResourceType type) { m_defaultResourceType = typ
e; } |
77 ResourceType defaultResourceType() const { return m_defaultResourceType; } | 81 ResourceType defaultResourceType() const { return m_defaultResourceType; } |
78 ResourceType resourceType(ResourceId); | 82 ResourceType resourceType(ResourceId); |
79 | 83 |
80 // Creates a resource of the default resource type. | 84 // Creates a resource of the default resource type. |
81 ResourceId createResource(int pool, const IntSize&, GLenum format, TextureUs
ageHint); | 85 ResourceId createResource(int pool, const gfx::Size&, GLenum format, Texture
UsageHint); |
82 | 86 |
83 // You can also explicitly create a specific resource type. | 87 // You can also explicitly create a specific resource type. |
84 ResourceId createGLTexture(int pool, const IntSize&, GLenum format, TextureU
sageHint); | 88 ResourceId createGLTexture(int pool, const gfx::Size&, GLenum format, Textur
eUsageHint); |
85 ResourceId createBitmap(int pool, const IntSize&); | 89 ResourceId createBitmap(int pool, const gfx::Size&); |
86 // Wraps an external texture into a GL resource. | 90 // Wraps an external texture into a GL resource. |
87 ResourceId createResourceFromExternalTexture(unsigned textureId); | 91 ResourceId createResourceFromExternalTexture(unsigned textureId); |
88 | 92 |
89 void deleteResource(ResourceId); | 93 void deleteResource(ResourceId); |
90 | 94 |
91 // Deletes all resources owned by a given pool. | 95 // Deletes all resources owned by a given pool. |
92 void deleteOwnedResources(int pool); | 96 void deleteOwnedResources(int pool); |
93 | 97 |
94 // Upload data from image, copying sourceRect (in image) into destRect (in t
he resource). | 98 // Upload data from image, copying sourceRect (in image) into destRect (in t
he resource). |
95 void upload(ResourceId, const uint8_t* image, const IntRect& imageRect, cons
t IntRect& sourceRect, const IntSize& destOffset); | 99 void upload(ResourceId, const uint8_t* image, const gfx::Rect& imageRect, co
nst gfx::Rect& sourceRect, const gfx::Vector2d& destOffset); |
96 | 100 |
97 // Check upload status. | 101 // Check upload status. |
98 size_t numBlockingUploads(); | 102 size_t numBlockingUploads(); |
99 void markPendingUploadsAsNonBlocking(); | 103 void markPendingUploadsAsNonBlocking(); |
100 double estimatedUploadsPerSecond(); | 104 double estimatedUploadsPerSecond(); |
101 | 105 |
102 // Flush all context operations, kicking uploads and ensuring ordering with | 106 // Flush all context operations, kicking uploads and ensuring ordering with |
103 // respect to other contexts. | 107 // respect to other contexts. |
104 void flush(); | 108 void flush(); |
105 | 109 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 }; | 216 }; |
213 | 217 |
214 // Temporary functions for debugging crashes in issue 151428 in canary. | 218 // Temporary functions for debugging crashes in issue 151428 in canary. |
215 // Do not use these! | 219 // Do not use these! |
216 static void debugNotifyEnterZone(unsigned int index); | 220 static void debugNotifyEnterZone(unsigned int index); |
217 static void debugNotifyLeaveZone(); | 221 static void debugNotifyLeaveZone(); |
218 | 222 |
219 private: | 223 private: |
220 struct Resource { | 224 struct Resource { |
221 Resource(); | 225 Resource(); |
222 Resource(unsigned textureId, int pool, const IntSize& size, GLenum forma
t); | 226 Resource(unsigned textureId, int pool, const gfx::Size& size, GLenum for
mat); |
223 Resource(uint8_t* pixels, int pool, const IntSize& size, GLenum format); | 227 Resource(uint8_t* pixels, int pool, const gfx::Size& size, GLenum format
); |
224 | 228 |
225 unsigned glId; | 229 unsigned glId; |
226 uint8_t* pixels; | 230 uint8_t* pixels; |
227 int pool; | 231 int pool; |
228 int lockForReadCount; | 232 int lockForReadCount; |
229 bool lockedForWrite; | 233 bool lockedForWrite; |
230 bool external; | 234 bool external; |
231 bool exported; | 235 bool exported; |
232 bool markedForDeletion; | 236 bool markedForDeletion; |
233 IntSize size; | 237 gfx::Size size; |
234 GLenum format; | 238 GLenum format; |
235 ResourceType type; | 239 ResourceType type; |
236 }; | 240 }; |
237 typedef base::hash_map<ResourceId, Resource> ResourceMap; | 241 typedef base::hash_map<ResourceId, Resource> ResourceMap; |
238 struct Child { | 242 struct Child { |
239 Child(); | 243 Child(); |
240 ~Child(); | 244 ~Child(); |
241 | 245 |
242 int pool; | 246 int pool; |
243 ResourceIdMap childToParentMap; | 247 ResourceIdMap childToParentMap; |
(...skipping 29 matching lines...) Expand all Loading... |
273 scoped_ptr<TextureUploader> m_textureUploader; | 277 scoped_ptr<TextureUploader> m_textureUploader; |
274 scoped_ptr<AcceleratedTextureCopier> m_textureCopier; | 278 scoped_ptr<AcceleratedTextureCopier> m_textureCopier; |
275 int m_maxTextureSize; | 279 int m_maxTextureSize; |
276 | 280 |
277 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); | 281 DISALLOW_COPY_AND_ASSIGN(ResourceProvider); |
278 }; | 282 }; |
279 | 283 |
280 } | 284 } |
281 | 285 |
282 #endif | 286 #endif |
OLD | NEW |