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 #include "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "CCResourceProvider.h" | 7 #include "CCResourceProvider.h" |
8 #ifdef LOG | 8 #ifdef LOG |
9 #undef LOG | 9 #undef LOG |
10 #endif | 10 #endif |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 } | 44 } |
45 | 45 |
46 return storageFormat; | 46 return storageFormat; |
47 } | 47 } |
48 | 48 |
49 static bool isTextureFormatSupportedForStorage(GC3Denum format) | 49 static bool isTextureFormatSupportedForStorage(GC3Denum format) |
50 { | 50 { |
51 return (format == GraphicsContext3D::RGBA || format == Extensions3D::BGRA_EX
T); | 51 return (format == GraphicsContext3D::RGBA || format == Extensions3D::BGRA_EX
T); |
52 } | 52 } |
53 | 53 |
54 CCResourceProvider::TransferableResourceList::TransferableResourceList() | 54 ResourceProvider::TransferableResourceList::TransferableResourceList() |
55 { | 55 { |
56 } | 56 } |
57 | 57 |
58 CCResourceProvider::TransferableResourceList::~TransferableResourceList() | 58 ResourceProvider::TransferableResourceList::~TransferableResourceList() |
59 { | 59 { |
60 } | 60 } |
61 | 61 |
62 CCResourceProvider::Resource::Resource() | 62 ResourceProvider::Resource::Resource() |
63 : glId(0) | 63 : glId(0) |
64 , pixels(0) | 64 , pixels(0) |
65 , pool(0) | 65 , pool(0) |
66 , lockForReadCount(0) | 66 , lockForReadCount(0) |
67 , lockedForWrite(false) | 67 , lockedForWrite(false) |
68 , external(false) | 68 , external(false) |
69 , exported(false) | 69 , exported(false) |
70 , markedForDeletion(false) | 70 , markedForDeletion(false) |
71 , size() | 71 , size() |
72 , format(0) | 72 , format(0) |
73 , type(static_cast<ResourceType>(0)) | 73 , type(static_cast<ResourceType>(0)) |
74 { | 74 { |
75 } | 75 } |
76 | 76 |
77 CCResourceProvider::Resource::Resource(unsigned textureId, int pool, const IntSi
ze& size, GC3Denum format) | 77 ResourceProvider::Resource::Resource(unsigned textureId, int pool, const IntSize
& size, GC3Denum format) |
78 : glId(textureId) | 78 : glId(textureId) |
79 , pixels(0) | 79 , pixels(0) |
80 , pool(pool) | 80 , pool(pool) |
81 , lockForReadCount(0) | 81 , lockForReadCount(0) |
82 , lockedForWrite(false) | 82 , lockedForWrite(false) |
83 , external(false) | 83 , external(false) |
84 , exported(false) | 84 , exported(false) |
85 , markedForDeletion(false) | 85 , markedForDeletion(false) |
86 , size(size) | 86 , size(size) |
87 , format(format) | 87 , format(format) |
88 , type(GLTexture) | 88 , type(GLTexture) |
89 { | 89 { |
90 } | 90 } |
91 | 91 |
92 CCResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const IntSize&
size, GC3Denum format) | 92 ResourceProvider::Resource::Resource(uint8_t* pixels, int pool, const IntSize& s
ize, GC3Denum format) |
93 : glId(0) | 93 : glId(0) |
94 , pixels(pixels) | 94 , pixels(pixels) |
95 , pool(pool) | 95 , pool(pool) |
96 , lockForReadCount(0) | 96 , lockForReadCount(0) |
97 , lockedForWrite(false) | 97 , lockedForWrite(false) |
98 , external(false) | 98 , external(false) |
99 , exported(false) | 99 , exported(false) |
100 , markedForDeletion(false) | 100 , markedForDeletion(false) |
101 , size(size) | 101 , size(size) |
102 , format(format) | 102 , format(format) |
103 , type(Bitmap) | 103 , type(Bitmap) |
104 { | 104 { |
105 } | 105 } |
106 | 106 |
107 CCResourceProvider::Child::Child() | 107 ResourceProvider::Child::Child() |
108 { | 108 { |
109 } | 109 } |
110 | 110 |
111 CCResourceProvider::Child::~Child() | 111 ResourceProvider::Child::~Child() |
112 { | 112 { |
113 } | 113 } |
114 | 114 |
115 scoped_ptr<CCResourceProvider> CCResourceProvider::create(CCGraphicsContext* con
text) | 115 scoped_ptr<ResourceProvider> ResourceProvider::create(GraphicsContext* context) |
116 { | 116 { |
117 scoped_ptr<CCResourceProvider> resourceProvider(new CCResourceProvider(conte
xt)); | 117 scoped_ptr<ResourceProvider> resourceProvider(new ResourceProvider(context))
; |
118 if (!resourceProvider->initialize()) | 118 if (!resourceProvider->initialize()) |
119 return scoped_ptr<CCResourceProvider>(); | 119 return scoped_ptr<ResourceProvider>(); |
120 return resourceProvider.Pass(); | 120 return resourceProvider.Pass(); |
121 } | 121 } |
122 | 122 |
123 CCResourceProvider::~CCResourceProvider() | 123 ResourceProvider::~ResourceProvider() |
124 { | 124 { |
125 WebGraphicsContext3D* context3d = m_context->context3D(); | 125 WebGraphicsContext3D* context3d = m_context->context3D(); |
126 if (!context3d || !context3d->makeContextCurrent()) | 126 if (!context3d || !context3d->makeContextCurrent()) |
127 return; | 127 return; |
128 m_textureUploader.reset(); | 128 m_textureUploader.reset(); |
129 m_textureCopier.reset(); | 129 m_textureCopier.reset(); |
130 } | 130 } |
131 | 131 |
132 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D() | 132 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() |
133 { | 133 { |
134 ASSERT(CCProxy::isImplThread()); | 134 ASSERT(Proxy::isImplThread()); |
135 return m_context->context3D(); | 135 return m_context->context3D(); |
136 } | 136 } |
137 | 137 |
138 bool CCResourceProvider::inUseByConsumer(ResourceId id) | 138 bool ResourceProvider::inUseByConsumer(ResourceId id) |
139 { | 139 { |
140 ASSERT(CCProxy::isImplThread()); | 140 ASSERT(Proxy::isImplThread()); |
141 ResourceMap::iterator it = m_resources.find(id); | 141 ResourceMap::iterator it = m_resources.find(id); |
142 CHECK(it != m_resources.end()); | 142 CHECK(it != m_resources.end()); |
143 Resource* resource = &it->second; | 143 Resource* resource = &it->second; |
144 return !!resource->lockForReadCount || resource->exported; | 144 return !!resource->lockForReadCount || resource->exported; |
145 } | 145 } |
146 | 146 |
147 CCResourceProvider::ResourceId CCResourceProvider::createResource(int pool, cons
t IntSize& size, GC3Denum format, TextureUsageHint hint) | 147 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const In
tSize& size, GC3Denum format, TextureUsageHint hint) |
148 { | 148 { |
149 switch (m_defaultResourceType) { | 149 switch (m_defaultResourceType) { |
150 case GLTexture: | 150 case GLTexture: |
151 return createGLTexture(pool, size, format, hint); | 151 return createGLTexture(pool, size, format, hint); |
152 case Bitmap: | 152 case Bitmap: |
153 ASSERT(format == GraphicsContext3D::RGBA); | 153 ASSERT(format == GraphicsContext3D::RGBA); |
154 return createBitmap(pool, size); | 154 return createBitmap(pool, size); |
155 } | 155 } |
156 | 156 |
157 CRASH(); | 157 CRASH(); |
158 return 0; | 158 return 0; |
159 } | 159 } |
160 | 160 |
161 CCResourceProvider::ResourceId CCResourceProvider::createGLTexture(int pool, con
st IntSize& size, GC3Denum format, TextureUsageHint hint) | 161 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const I
ntSize& size, GC3Denum format, TextureUsageHint hint) |
162 { | 162 { |
163 ASSERT(CCProxy::isImplThread()); | 163 ASSERT(Proxy::isImplThread()); |
164 unsigned textureId = 0; | 164 unsigned textureId = 0; |
165 WebGraphicsContext3D* context3d = m_context->context3D(); | 165 WebGraphicsContext3D* context3d = m_context->context3D(); |
166 ASSERT(context3d); | 166 ASSERT(context3d); |
167 GLC(context3d, textureId = context3d->createTexture()); | 167 GLC(context3d, textureId = context3d->createTexture()); |
168 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, texture
Id)); | 168 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, texture
Id)); |
169 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); | 169 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MIN_FILTER, GraphicsContext3D::LINEAR)); |
170 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); | 170 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_MAG_FILTER, GraphicsContext3D::LINEAR)); |
171 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); | 171 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::CLAMP_TO_EDGE)); |
172 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); | 172 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, Graph
icsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::CLAMP_TO_EDGE)); |
173 | 173 |
174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
175 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E
xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE
R_ATTACHMENT_ANGLE)); | 175 GLC(context3d, context3d->texParameteri(GraphicsContext3D::TEXTURE_2D, E
xtensions3DChromium::GL_TEXTURE_USAGE_ANGLE, Extensions3DChromium::GL_FRAMEBUFFE
R_ATTACHMENT_ANGLE)); |
176 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 176 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
177 GC3Denum storageFormat = textureToStorageFormat(format); | 177 GC3Denum storageFormat = textureToStorageFormat(format); |
178 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D,
1, storageFormat, size.width(), size.height())); | 178 GLC(context3d, context3d->texStorage2DEXT(GraphicsContext3D::TEXTURE_2D,
1, storageFormat, size.width(), size.height())); |
179 } else | 179 } else |
180 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f
ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE,
0)); | 180 GLC(context3d, context3d->texImage2D(GraphicsContext3D::TEXTURE_2D, 0, f
ormat, size.width(), size.height(), 0, format, GraphicsContext3D::UNSIGNED_BYTE,
0)); |
181 ResourceId id = m_nextId++; | 181 ResourceId id = m_nextId++; |
182 Resource resource(textureId, pool, size, format); | 182 Resource resource(textureId, pool, size, format); |
183 m_resources[id] = resource; | 183 m_resources[id] = resource; |
184 return id; | 184 return id; |
185 } | 185 } |
186 | 186 |
187 CCResourceProvider::ResourceId CCResourceProvider::createBitmap(int pool, const
IntSize& size) | 187 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const IntS
ize& size) |
188 { | 188 { |
189 ASSERT(CCProxy::isImplThread()); | 189 ASSERT(Proxy::isImplThread()); |
190 | 190 |
191 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 191 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
192 | 192 |
193 ResourceId id = m_nextId++; | 193 ResourceId id = m_nextId++; |
194 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA); | 194 Resource resource(pixels, pool, size, GraphicsContext3D::RGBA); |
195 m_resources[id] = resource; | 195 m_resources[id] = resource; |
196 return id; | 196 return id; |
197 } | 197 } |
198 | 198 |
199 CCResourceProvider::ResourceId CCResourceProvider::createResourceFromExternalTex
ture(unsigned textureId) | 199 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) |
200 { | 200 { |
201 ASSERT(CCProxy::isImplThread()); | 201 ASSERT(Proxy::isImplThread()); |
202 ASSERT(m_context->context3D()); | 202 ASSERT(m_context->context3D()); |
203 ResourceId id = m_nextId++; | 203 ResourceId id = m_nextId++; |
204 Resource resource(textureId, 0, IntSize(), 0); | 204 Resource resource(textureId, 0, IntSize(), 0); |
205 resource.external = true; | 205 resource.external = true; |
206 m_resources[id] = resource; | 206 m_resources[id] = resource; |
207 return id; | 207 return id; |
208 } | 208 } |
209 | 209 |
210 void CCResourceProvider::deleteResource(ResourceId id) | 210 void ResourceProvider::deleteResource(ResourceId id) |
211 { | 211 { |
212 ASSERT(CCProxy::isImplThread()); | 212 ASSERT(Proxy::isImplThread()); |
213 ResourceMap::iterator it = m_resources.find(id); | 213 ResourceMap::iterator it = m_resources.find(id); |
214 CHECK(it != m_resources.end()); | 214 CHECK(it != m_resources.end()); |
215 Resource* resource = &it->second; | 215 Resource* resource = &it->second; |
216 ASSERT(!resource->lockedForWrite); | 216 ASSERT(!resource->lockedForWrite); |
217 ASSERT(!resource->lockForReadCount); | 217 ASSERT(!resource->lockForReadCount); |
218 ASSERT(!resource->markedForDeletion); | 218 ASSERT(!resource->markedForDeletion); |
219 | 219 |
220 if (resource->exported) { | 220 if (resource->exported) { |
221 resource->markedForDeletion = true; | 221 resource->markedForDeletion = true; |
222 return; | 222 return; |
223 } else | 223 } else |
224 deleteResourceInternal(it); | 224 deleteResourceInternal(it); |
225 } | 225 } |
226 | 226 |
227 void CCResourceProvider::deleteResourceInternal(ResourceMap::iterator it) | 227 void ResourceProvider::deleteResourceInternal(ResourceMap::iterator it) |
228 { | 228 { |
229 Resource* resource = &it->second; | 229 Resource* resource = &it->second; |
230 if (resource->glId && !resource->external) { | 230 if (resource->glId && !resource->external) { |
231 WebGraphicsContext3D* context3d = m_context->context3D(); | 231 WebGraphicsContext3D* context3d = m_context->context3D(); |
232 ASSERT(context3d); | 232 ASSERT(context3d); |
233 GLC(context3d, context3d->deleteTexture(resource->glId)); | 233 GLC(context3d, context3d->deleteTexture(resource->glId)); |
234 } | 234 } |
235 if (resource->pixels) | 235 if (resource->pixels) |
236 delete resource->pixels; | 236 delete resource->pixels; |
237 | 237 |
238 m_resources.erase(it); | 238 m_resources.erase(it); |
239 } | 239 } |
240 | 240 |
241 void CCResourceProvider::deleteOwnedResources(int pool) | 241 void ResourceProvider::deleteOwnedResources(int pool) |
242 { | 242 { |
243 ASSERT(CCProxy::isImplThread()); | 243 ASSERT(Proxy::isImplThread()); |
244 ResourceIdArray toDelete; | 244 ResourceIdArray toDelete; |
245 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { | 245 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { |
246 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) | 246 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) |
247 toDelete.push_back(it->first); | 247 toDelete.push_back(it->first); |
248 } | 248 } |
249 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) | 249 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) |
250 deleteResource(*it); | 250 deleteResource(*it); |
251 } | 251 } |
252 | 252 |
253 CCResourceProvider::ResourceType CCResourceProvider::resourceType(ResourceId id) | 253 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) |
254 { | 254 { |
255 ResourceMap::iterator it = m_resources.find(id); | 255 ResourceMap::iterator it = m_resources.find(id); |
256 CHECK(it != m_resources.end()); | 256 CHECK(it != m_resources.end()); |
257 Resource* resource = &it->second; | 257 Resource* resource = &it->second; |
258 return resource->type; | 258 return resource->type; |
259 } | 259 } |
260 | 260 |
261 void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
ct& imageRect, const IntRect& sourceRect, const IntSize& destOffset) | 261 void ResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRect
& imageRect, const IntRect& sourceRect, const IntSize& destOffset) |
262 { | 262 { |
263 ASSERT(CCProxy::isImplThread()); | 263 ASSERT(Proxy::isImplThread()); |
264 ResourceMap::iterator it = m_resources.find(id); | 264 ResourceMap::iterator it = m_resources.find(id); |
265 CHECK(it != m_resources.end()); | 265 CHECK(it != m_resources.end()); |
266 Resource* resource = &it->second; | 266 Resource* resource = &it->second; |
267 ASSERT(!resource->lockedForWrite); | 267 ASSERT(!resource->lockedForWrite); |
268 ASSERT(!resource->lockForReadCount); | 268 ASSERT(!resource->lockForReadCount); |
269 ASSERT(!resource->external); | 269 ASSERT(!resource->external); |
270 ASSERT(!resource->exported); | 270 ASSERT(!resource->exported); |
271 | 271 |
272 if (resource->glId) { | 272 if (resource->glId) { |
273 WebGraphicsContext3D* context3d = m_context->context3D(); | 273 WebGraphicsContext3D* context3d = m_context->context3D(); |
(...skipping 11 matching lines...) Expand all Loading... |
285 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); | 285 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); |
286 skSourceRect.offset(-imageRect.x(), -imageRect.y()); | 286 skSourceRect.offset(-imageRect.x(), -imageRect.y()); |
287 srcFull.extractSubset(&srcSubset, skSourceRect); | 287 srcFull.extractSubset(&srcSubset, skSourceRect); |
288 | 288 |
289 ScopedWriteLockSoftware lock(this, id); | 289 ScopedWriteLockSoftware lock(this, id); |
290 SkCanvas* dest = lock.skCanvas(); | 290 SkCanvas* dest = lock.skCanvas(); |
291 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); | 291 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); |
292 } | 292 } |
293 } | 293 } |
294 | 294 |
295 void CCResourceProvider::flush() | 295 void ResourceProvider::flush() |
296 { | 296 { |
297 ASSERT(CCProxy::isImplThread()); | 297 ASSERT(Proxy::isImplThread()); |
298 WebGraphicsContext3D* context3d = m_context->context3D(); | 298 WebGraphicsContext3D* context3d = m_context->context3D(); |
299 if (context3d) | 299 if (context3d) |
300 context3d->flush(); | 300 context3d->flush(); |
301 } | 301 } |
302 | 302 |
303 bool CCResourceProvider::shallowFlushIfSupported() | 303 bool ResourceProvider::shallowFlushIfSupported() |
304 { | 304 { |
305 ASSERT(CCProxy::isImplThread()); | 305 ASSERT(Proxy::isImplThread()); |
306 WebGraphicsContext3D* context3d = m_context->context3D(); | 306 WebGraphicsContext3D* context3d = m_context->context3D(); |
307 if (!context3d || !m_useShallowFlush) | 307 if (!context3d || !m_useShallowFlush) |
308 return false; | 308 return false; |
309 | 309 |
310 context3d->shallowFlushCHROMIUM(); | 310 context3d->shallowFlushCHROMIUM(); |
311 return true; | 311 return true; |
312 } | 312 } |
313 | 313 |
314 const CCResourceProvider::Resource* CCResourceProvider::lockForRead(ResourceId i
d) | 314 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
315 { | 315 { |
316 ASSERT(CCProxy::isImplThread()); | 316 ASSERT(Proxy::isImplThread()); |
317 ResourceMap::iterator it = m_resources.find(id); | 317 ResourceMap::iterator it = m_resources.find(id); |
318 CHECK(it != m_resources.end()); | 318 CHECK(it != m_resources.end()); |
319 | 319 |
320 Resource* resource = &it->second; | 320 Resource* resource = &it->second; |
321 ASSERT(!resource->lockedForWrite); | 321 ASSERT(!resource->lockedForWrite); |
322 ASSERT(!resource->exported); | 322 ASSERT(!resource->exported); |
323 resource->lockForReadCount++; | 323 resource->lockForReadCount++; |
324 return resource; | 324 return resource; |
325 } | 325 } |
326 | 326 |
327 void CCResourceProvider::unlockForRead(ResourceId id) | 327 void ResourceProvider::unlockForRead(ResourceId id) |
328 { | 328 { |
329 ASSERT(CCProxy::isImplThread()); | 329 ASSERT(Proxy::isImplThread()); |
330 ResourceMap::iterator it = m_resources.find(id); | 330 ResourceMap::iterator it = m_resources.find(id); |
331 CHECK(it != m_resources.end()); | 331 CHECK(it != m_resources.end()); |
332 Resource* resource = &it->second; | 332 Resource* resource = &it->second; |
333 ASSERT(resource->lockForReadCount > 0); | 333 ASSERT(resource->lockForReadCount > 0); |
334 ASSERT(!resource->exported); | 334 ASSERT(!resource->exported); |
335 resource->lockForReadCount--; | 335 resource->lockForReadCount--; |
336 } | 336 } |
337 | 337 |
338 const CCResourceProvider::Resource* CCResourceProvider::lockForWrite(ResourceId
id) | 338 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) |
339 { | 339 { |
340 ASSERT(CCProxy::isImplThread()); | 340 ASSERT(Proxy::isImplThread()); |
341 ResourceMap::iterator it = m_resources.find(id); | 341 ResourceMap::iterator it = m_resources.find(id); |
342 CHECK(it != m_resources.end()); | 342 CHECK(it != m_resources.end()); |
343 Resource* resource = &it->second; | 343 Resource* resource = &it->second; |
344 ASSERT(!resource->lockedForWrite); | 344 ASSERT(!resource->lockedForWrite); |
345 ASSERT(!resource->lockForReadCount); | 345 ASSERT(!resource->lockForReadCount); |
346 ASSERT(!resource->exported); | 346 ASSERT(!resource->exported); |
347 ASSERT(!resource->external); | 347 ASSERT(!resource->external); |
348 resource->lockedForWrite = true; | 348 resource->lockedForWrite = true; |
349 return resource; | 349 return resource; |
350 } | 350 } |
351 | 351 |
352 void CCResourceProvider::unlockForWrite(ResourceId id) | 352 void ResourceProvider::unlockForWrite(ResourceId id) |
353 { | 353 { |
354 ASSERT(CCProxy::isImplThread()); | 354 ASSERT(Proxy::isImplThread()); |
355 ResourceMap::iterator it = m_resources.find(id); | 355 ResourceMap::iterator it = m_resources.find(id); |
356 CHECK(it != m_resources.end()); | 356 CHECK(it != m_resources.end()); |
357 Resource* resource = &it->second; | 357 Resource* resource = &it->second; |
358 ASSERT(resource->lockedForWrite); | 358 ASSERT(resource->lockedForWrite); |
359 ASSERT(!resource->exported); | 359 ASSERT(!resource->exported); |
360 ASSERT(!resource->external); | 360 ASSERT(!resource->external); |
361 resource->lockedForWrite = false; | 361 resource->lockedForWrite = false; |
362 } | 362 } |
363 | 363 |
364 CCResourceProvider::ScopedReadLockGL::ScopedReadLockGL(CCResourceProvider* resou
rceProvider, CCResourceProvider::ResourceId resourceId) | 364 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(ResourceProvider* resourceP
rovider, ResourceProvider::ResourceId resourceId) |
365 : m_resourceProvider(resourceProvider) | 365 : m_resourceProvider(resourceProvider) |
366 , m_resourceId(resourceId) | 366 , m_resourceId(resourceId) |
367 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) | 367 , m_textureId(resourceProvider->lockForRead(resourceId)->glId) |
368 { | 368 { |
369 ASSERT(m_textureId); | 369 ASSERT(m_textureId); |
370 } | 370 } |
371 | 371 |
372 CCResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() | 372 ResourceProvider::ScopedReadLockGL::~ScopedReadLockGL() |
373 { | 373 { |
374 m_resourceProvider->unlockForRead(m_resourceId); | 374 m_resourceProvider->unlockForRead(m_resourceId); |
375 } | 375 } |
376 | 376 |
377 CCResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(CCResourceProvider* res
ourceProvider, CCResourceProvider::ResourceId resourceId) | 377 ResourceProvider::ScopedWriteLockGL::ScopedWriteLockGL(ResourceProvider* resourc
eProvider, ResourceProvider::ResourceId resourceId) |
378 : m_resourceProvider(resourceProvider) | 378 : m_resourceProvider(resourceProvider) |
379 , m_resourceId(resourceId) | 379 , m_resourceId(resourceId) |
380 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId) | 380 , m_textureId(resourceProvider->lockForWrite(resourceId)->glId) |
381 { | 381 { |
382 ASSERT(m_textureId); | 382 ASSERT(m_textureId); |
383 } | 383 } |
384 | 384 |
385 CCResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() | 385 ResourceProvider::ScopedWriteLockGL::~ScopedWriteLockGL() |
386 { | 386 { |
387 m_resourceProvider->unlockForWrite(m_resourceId); | 387 m_resourceProvider->unlockForWrite(m_resourceId); |
388 } | 388 } |
389 | 389 |
390 void CCResourceProvider::populateSkBitmapWithResource(SkBitmap* skBitmap, const
Resource* resource) | 390 void ResourceProvider::populateSkBitmapWithResource(SkBitmap* skBitmap, const Re
source* resource) |
391 { | 391 { |
392 ASSERT(resource->pixels); | 392 ASSERT(resource->pixels); |
393 ASSERT(resource->format == GraphicsContext3D::RGBA); | 393 ASSERT(resource->format == GraphicsContext3D::RGBA); |
394 skBitmap->setConfig(SkBitmap::kARGB_8888_Config, resource->size.width(), res
ource->size.height()); | 394 skBitmap->setConfig(SkBitmap::kARGB_8888_Config, resource->size.width(), res
ource->size.height()); |
395 skBitmap->setPixels(resource->pixels); | 395 skBitmap->setPixels(resource->pixels); |
396 } | 396 } |
397 | 397 |
398 CCResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(CCResourcePro
vider* resourceProvider, CCResourceProvider::ResourceId resourceId) | 398 ResourceProvider::ScopedReadLockSoftware::ScopedReadLockSoftware(ResourceProvide
r* resourceProvider, ResourceProvider::ResourceId resourceId) |
399 : m_resourceProvider(resourceProvider) | 399 : m_resourceProvider(resourceProvider) |
400 , m_resourceId(resourceId) | 400 , m_resourceId(resourceId) |
401 { | 401 { |
402 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid
er->lockForRead(resourceId)); | 402 ResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvider
->lockForRead(resourceId)); |
403 } | 403 } |
404 | 404 |
405 CCResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() | 405 ResourceProvider::ScopedReadLockSoftware::~ScopedReadLockSoftware() |
406 { | 406 { |
407 m_resourceProvider->unlockForRead(m_resourceId); | 407 m_resourceProvider->unlockForRead(m_resourceId); |
408 } | 408 } |
409 | 409 |
410 CCResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware(CCResourceP
rovider* resourceProvider, CCResourceProvider::ResourceId resourceId) | 410 ResourceProvider::ScopedWriteLockSoftware::ScopedWriteLockSoftware(ResourceProvi
der* resourceProvider, ResourceProvider::ResourceId resourceId) |
411 : m_resourceProvider(resourceProvider) | 411 : m_resourceProvider(resourceProvider) |
412 , m_resourceId(resourceId) | 412 , m_resourceId(resourceId) |
413 { | 413 { |
414 CCResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvid
er->lockForWrite(resourceId)); | 414 ResourceProvider::populateSkBitmapWithResource(&m_skBitmap, resourceProvider
->lockForWrite(resourceId)); |
415 m_skCanvas.reset(new SkCanvas(m_skBitmap)); | 415 m_skCanvas.reset(new SkCanvas(m_skBitmap)); |
416 } | 416 } |
417 | 417 |
418 CCResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() | 418 ResourceProvider::ScopedWriteLockSoftware::~ScopedWriteLockSoftware() |
419 { | 419 { |
420 m_resourceProvider->unlockForWrite(m_resourceId); | 420 m_resourceProvider->unlockForWrite(m_resourceId); |
421 } | 421 } |
422 | 422 |
423 CCResourceProvider::CCResourceProvider(CCGraphicsContext* context) | 423 ResourceProvider::ResourceProvider(GraphicsContext* context) |
424 : m_context(context) | 424 : m_context(context) |
425 , m_nextId(1) | 425 , m_nextId(1) |
426 , m_nextChild(1) | 426 , m_nextChild(1) |
427 , m_defaultResourceType(GLTexture) | 427 , m_defaultResourceType(GLTexture) |
428 , m_useTextureStorageExt(false) | 428 , m_useTextureStorageExt(false) |
429 , m_useTextureUsageHint(false) | 429 , m_useTextureUsageHint(false) |
430 , m_useShallowFlush(false) | 430 , m_useShallowFlush(false) |
431 , m_maxTextureSize(0) | 431 , m_maxTextureSize(0) |
432 { | 432 { |
433 } | 433 } |
434 | 434 |
435 bool CCResourceProvider::initialize() | 435 bool ResourceProvider::initialize() |
436 { | 436 { |
437 ASSERT(CCProxy::isImplThread()); | 437 ASSERT(Proxy::isImplThread()); |
438 WebGraphicsContext3D* context3d = m_context->context3D(); | 438 WebGraphicsContext3D* context3d = m_context->context3D(); |
439 if (!context3d) { | 439 if (!context3d) { |
440 m_maxTextureSize = INT_MAX / 2; | 440 m_maxTextureSize = INT_MAX / 2; |
441 m_textureUploader = UnthrottledTextureUploader::create(); | 441 m_textureUploader = UnthrottledTextureUploader::create(); |
442 return true; | 442 return true; |
443 } | 443 } |
444 if (!context3d->makeContextCurrent()) | 444 if (!context3d->makeContextCurrent()) |
445 return false; | 445 return false; |
446 | 446 |
447 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon
text3D::EXTENSIONS)); | 447 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon
text3D::EXTENSIONS)); |
(...skipping 15 matching lines...) Expand all Loading... |
463 } | 463 } |
464 | 464 |
465 m_texSubImage.reset(new LayerTextureSubImage(useMapSub)); | 465 m_texSubImage.reset(new LayerTextureSubImage(useMapSub)); |
466 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); | 466 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); |
467 | 467 |
468 m_textureUploader = ThrottledTextureUploader::create(context3d); | 468 m_textureUploader = ThrottledTextureUploader::create(context3d); |
469 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); | 469 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); |
470 return true; | 470 return true; |
471 } | 471 } |
472 | 472 |
473 int CCResourceProvider::createChild(int pool) | 473 int ResourceProvider::createChild(int pool) |
474 { | 474 { |
475 ASSERT(CCProxy::isImplThread()); | 475 ASSERT(Proxy::isImplThread()); |
476 Child childInfo; | 476 Child childInfo; |
477 childInfo.pool = pool; | 477 childInfo.pool = pool; |
478 int child = m_nextChild++; | 478 int child = m_nextChild++; |
479 m_children[child] = childInfo; | 479 m_children[child] = childInfo; |
480 return child; | 480 return child; |
481 } | 481 } |
482 | 482 |
483 void CCResourceProvider::destroyChild(int child) | 483 void ResourceProvider::destroyChild(int child) |
484 { | 484 { |
485 ASSERT(CCProxy::isImplThread()); | 485 ASSERT(Proxy::isImplThread()); |
486 ChildMap::iterator it = m_children.find(child); | 486 ChildMap::iterator it = m_children.find(child); |
487 ASSERT(it != m_children.end()); | 487 ASSERT(it != m_children.end()); |
488 deleteOwnedResources(it->second.pool); | 488 deleteOwnedResources(it->second.pool); |
489 m_children.erase(it); | 489 m_children.erase(it); |
490 trimMailboxDeque(); | 490 trimMailboxDeque(); |
491 } | 491 } |
492 | 492 |
493 const CCResourceProvider::ResourceIdMap& CCResourceProvider::getChildToParentMap
(int child) const | 493 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
child) const |
494 { | 494 { |
495 ASSERT(CCProxy::isImplThread()); | 495 ASSERT(Proxy::isImplThread()); |
496 ChildMap::const_iterator it = m_children.find(child); | 496 ChildMap::const_iterator it = m_children.find(child); |
497 ASSERT(it != m_children.end()); | 497 ASSERT(it != m_children.end()); |
498 return it->second.childToParentMap; | 498 return it->second.childToParentMap; |
499 } | 499 } |
500 | 500 |
501 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToPa
rent(const ResourceIdArray& resources) | 501 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToParent
(const ResourceIdArray& resources) |
502 { | 502 { |
503 ASSERT(CCProxy::isImplThread()); | 503 ASSERT(Proxy::isImplThread()); |
504 TransferableResourceList list; | 504 TransferableResourceList list; |
505 list.syncPoint = 0; | 505 list.syncPoint = 0; |
506 WebGraphicsContext3D* context3d = m_context->context3D(); | 506 WebGraphicsContext3D* context3d = m_context->context3D(); |
507 if (!context3d || !context3d->makeContextCurrent()) { | 507 if (!context3d || !context3d->makeContextCurrent()) { |
508 // FIXME: Implement this path for software compositing. | 508 // FIXME: Implement this path for software compositing. |
509 return list; | 509 return list; |
510 } | 510 } |
511 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 511 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
512 TransferableResource resource; | 512 TransferableResource resource; |
513 if (transferResource(context3d, *it, &resource)) { | 513 if (transferResource(context3d, *it, &resource)) { |
514 m_resources.find(*it)->second.exported = true; | 514 m_resources.find(*it)->second.exported = true; |
515 list.resources.push_back(resource); | 515 list.resources.push_back(resource); |
516 } | 516 } |
517 } | 517 } |
518 if (list.resources.size()) | 518 if (list.resources.size()) |
519 list.syncPoint = context3d->insertSyncPoint(); | 519 list.syncPoint = context3d->insertSyncPoint(); |
520 return list; | 520 return list; |
521 } | 521 } |
522 | 522 |
523 CCResourceProvider::TransferableResourceList CCResourceProvider::prepareSendToCh
ild(int child, const ResourceIdArray& resources) | 523 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild(
int child, const ResourceIdArray& resources) |
524 { | 524 { |
525 ASSERT(CCProxy::isImplThread()); | 525 ASSERT(Proxy::isImplThread()); |
526 TransferableResourceList list; | 526 TransferableResourceList list; |
527 list.syncPoint = 0; | 527 list.syncPoint = 0; |
528 WebGraphicsContext3D* context3d = m_context->context3D(); | 528 WebGraphicsContext3D* context3d = m_context->context3D(); |
529 if (!context3d || !context3d->makeContextCurrent()) { | 529 if (!context3d || !context3d->makeContextCurrent()) { |
530 // FIXME: Implement this path for software compositing. | 530 // FIXME: Implement this path for software compositing. |
531 return list; | 531 return list; |
532 } | 532 } |
533 Child& childInfo = m_children.find(child)->second; | 533 Child& childInfo = m_children.find(child)->second; |
534 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 534 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
535 TransferableResource resource; | 535 TransferableResource resource; |
536 if (!transferResource(context3d, *it, &resource)) | 536 if (!transferResource(context3d, *it, &resource)) |
537 ASSERT_NOT_REACHED(); | 537 ASSERT_NOT_REACHED(); |
538 ASSERT(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); | 538 ASSERT(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); |
539 resource.id = childInfo.parentToChildMap[*it]; | 539 resource.id = childInfo.parentToChildMap[*it]; |
540 childInfo.parentToChildMap.erase(*it); | 540 childInfo.parentToChildMap.erase(*it); |
541 childInfo.childToParentMap.erase(resource.id); | 541 childInfo.childToParentMap.erase(resource.id); |
542 list.resources.push_back(resource); | 542 list.resources.push_back(resource); |
543 deleteResource(*it); | 543 deleteResource(*it); |
544 } | 544 } |
545 if (list.resources.size()) | 545 if (list.resources.size()) |
546 list.syncPoint = context3d->insertSyncPoint(); | 546 list.syncPoint = context3d->insertSyncPoint(); |
547 return list; | 547 return list; |
548 } | 548 } |
549 | 549 |
550 void CCResourceProvider::receiveFromChild(int child, const TransferableResourceL
ist& resources) | 550 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) |
551 { | 551 { |
552 ASSERT(CCProxy::isImplThread()); | 552 ASSERT(Proxy::isImplThread()); |
553 WebGraphicsContext3D* context3d = m_context->context3D(); | 553 WebGraphicsContext3D* context3d = m_context->context3D(); |
554 if (!context3d || !context3d->makeContextCurrent()) { | 554 if (!context3d || !context3d->makeContextCurrent()) { |
555 // FIXME: Implement this path for software compositing. | 555 // FIXME: Implement this path for software compositing. |
556 return; | 556 return; |
557 } | 557 } |
558 if (resources.syncPoint) { | 558 if (resources.syncPoint) { |
559 // NOTE: If the parent is a browser and the child a renderer, the parent | 559 // NOTE: If the parent is a browser and the child a renderer, the parent |
560 // is not supposed to have its context wait, because that could induce | 560 // is not supposed to have its context wait, because that could induce |
561 // deadlocks and/or security issues. The caller is responsible for | 561 // deadlocks and/or security issues. The caller is responsible for |
562 // waiting asynchronously, and resetting syncPoint before calling this. | 562 // waiting asynchronously, and resetting syncPoint before calling this. |
563 // However if the parent is a renderer (e.g. browser tag), it may be ok | 563 // However if the parent is a renderer (e.g. browser tag), it may be ok |
564 // (and is simpler) to wait. | 564 // (and is simpler) to wait. |
565 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 565 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
566 } | 566 } |
567 Child& childInfo = m_children.find(child)->second; | 567 Child& childInfo = m_children.find(child)->second; |
568 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { | 568 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
569 unsigned textureId; | 569 unsigned textureId; |
570 GLC(context3d, textureId = context3d->createTexture()); | 570 GLC(context3d, textureId = context3d->createTexture()); |
571 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, tex
tureId)); | 571 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, tex
tureId)); |
572 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 572 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
573 ResourceId id = m_nextId++; | 573 ResourceId id = m_nextId++; |
574 Resource resource(textureId, childInfo.pool, it->size, it->format); | 574 Resource resource(textureId, childInfo.pool, it->size, it->format); |
575 m_resources[id] = resource; | 575 m_resources[id] = resource; |
576 m_mailboxes.push_back(it->mailbox); | 576 m_mailboxes.push_back(it->mailbox); |
577 childInfo.parentToChildMap[id] = it->id; | 577 childInfo.parentToChildMap[id] = it->id; |
578 childInfo.childToParentMap[it->id] = id; | 578 childInfo.childToParentMap[it->id] = id; |
579 } | 579 } |
580 } | 580 } |
581 | 581 |
582 void CCResourceProvider::receiveFromParent(const TransferableResourceList& resou
rces) | 582 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) |
583 { | 583 { |
584 ASSERT(CCProxy::isImplThread()); | 584 ASSERT(Proxy::isImplThread()); |
585 WebGraphicsContext3D* context3d = m_context->context3D(); | 585 WebGraphicsContext3D* context3d = m_context->context3D(); |
586 if (!context3d || !context3d->makeContextCurrent()) { | 586 if (!context3d || !context3d->makeContextCurrent()) { |
587 // FIXME: Implement this path for software compositing. | 587 // FIXME: Implement this path for software compositing. |
588 return; | 588 return; |
589 } | 589 } |
590 if (resources.syncPoint) | 590 if (resources.syncPoint) |
591 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 591 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
592 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { | 592 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
593 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 593 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
594 ASSERT(mapIterator != m_resources.end()); | 594 ASSERT(mapIterator != m_resources.end()); |
595 Resource* resource = &mapIterator->second; | 595 Resource* resource = &mapIterator->second; |
596 ASSERT(resource->exported); | 596 ASSERT(resource->exported); |
597 resource->exported = false; | 597 resource->exported = false; |
598 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); | 598 GLC(context3d, context3d->bindTexture(GraphicsContext3D::TEXTURE_2D, res
ource->glId)); |
599 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); | 599 GLC(context3d, context3d->consumeTextureCHROMIUM(GraphicsContext3D::TEXT
URE_2D, it->mailbox.name)); |
600 m_mailboxes.push_back(it->mailbox); | 600 m_mailboxes.push_back(it->mailbox); |
601 if (resource->markedForDeletion) | 601 if (resource->markedForDeletion) |
602 deleteResourceInternal(mapIterator); | 602 deleteResourceInternal(mapIterator); |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 bool CCResourceProvider::transferResource(WebGraphicsContext3D* context, Resourc
eId id, TransferableResource* resource) | 606 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) |
607 { | 607 { |
608 ASSERT(CCProxy::isImplThread()); | 608 ASSERT(Proxy::isImplThread()); |
609 ResourceMap::const_iterator it = m_resources.find(id); | 609 ResourceMap::const_iterator it = m_resources.find(id); |
610 CHECK(it != m_resources.end()); | 610 CHECK(it != m_resources.end()); |
611 const Resource* source = &it->second; | 611 const Resource* source = &it->second; |
612 ASSERT(!source->lockedForWrite); | 612 ASSERT(!source->lockedForWrite); |
613 ASSERT(!source->lockForReadCount); | 613 ASSERT(!source->lockForReadCount); |
614 ASSERT(!source->external); | 614 ASSERT(!source->external); |
615 if (source->exported) | 615 if (source->exported) |
616 return false; | 616 return false; |
617 resource->id = id; | 617 resource->id = id; |
618 resource->format = source->format; | 618 resource->format = source->format; |
619 resource->size = source->size; | 619 resource->size = source->size; |
620 if (m_mailboxes.size()) { | 620 if (m_mailboxes.size()) { |
621 resource->mailbox = m_mailboxes.front(); | 621 resource->mailbox = m_mailboxes.front(); |
622 m_mailboxes.pop_front(); | 622 m_mailboxes.pop_front(); |
623 } | 623 } |
624 else | 624 else |
625 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); | 625 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); |
626 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); | 626 GLC(context, context->bindTexture(GraphicsContext3D::TEXTURE_2D, source->glI
d)); |
627 GLC(context, context->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D,
resource->mailbox.name)); | 627 GLC(context, context->produceTextureCHROMIUM(GraphicsContext3D::TEXTURE_2D,
resource->mailbox.name)); |
628 return true; | 628 return true; |
629 } | 629 } |
630 | 630 |
631 void CCResourceProvider::trimMailboxDeque() | 631 void ResourceProvider::trimMailboxDeque() |
632 { | 632 { |
633 // Trim the mailbox deque to the maximum number of resources we may need to | 633 // Trim the mailbox deque to the maximum number of resources we may need to |
634 // send. | 634 // send. |
635 // If we have a parent, any non-external resource not already transfered is | 635 // If we have a parent, any non-external resource not already transfered is |
636 // eligible to be sent to the parent. Otherwise, all resources belonging to | 636 // eligible to be sent to the parent. Otherwise, all resources belonging to |
637 // a child might need to be sent back to the child. | 637 // a child might need to be sent back to the child. |
638 size_t maxMailboxCount = 0; | 638 size_t maxMailboxCount = 0; |
639 if (m_context->capabilities().hasParentCompositor) { | 639 if (m_context->capabilities().hasParentCompositor) { |
640 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { | 640 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { |
641 if (!it->second.exported && !it->second.external) | 641 if (!it->second.exported && !it->second.external) |
642 ++maxMailboxCount; | 642 ++maxMailboxCount; |
643 } | 643 } |
644 } else { | 644 } else { |
645 base::hash_set<int> childPoolSet; | 645 base::hash_set<int> childPoolSet; |
646 for (ChildMap::iterator it = m_children.begin(); it != m_children.end();
++it) | 646 for (ChildMap::iterator it = m_children.begin(); it != m_children.end();
++it) |
647 childPoolSet.insert(it->second.pool); | 647 childPoolSet.insert(it->second.pool); |
648 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { | 648 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { |
649 if (ContainsKey(childPoolSet, it->second.pool)) | 649 if (ContainsKey(childPoolSet, it->second.pool)) |
650 ++maxMailboxCount; | 650 ++maxMailboxCount; |
651 } | 651 } |
652 } | 652 } |
653 while (m_mailboxes.size() > maxMailboxCount) | 653 while (m_mailboxes.size() > maxMailboxCount) |
654 m_mailboxes.pop_front(); | 654 m_mailboxes.pop_front(); |
655 } | 655 } |
656 | 656 |
657 } | 657 } |
OLD | NEW |