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 "cc/resource_provider.h" | 7 #include "cc/resource_provider.h" |
8 | 8 |
9 #include <limits.h> | 9 #include <limits.h> |
10 | 10 |
11 #include "IntRect.h" | 11 #include "IntRect.h" |
12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
13 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/string_split.h" | 15 #include "base/string_split.h" |
16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
17 #include "cc/gl_renderer.h" // For the GLC() macro. | 17 #include "cc/gl_renderer.h" // For the GLC() macro. |
18 #include "cc/proxy.h" | |
19 #include "cc/texture_uploader.h" | 18 #include "cc/texture_uploader.h" |
20 #include "third_party/khronos/GLES2/gl2.h" | 19 #include "third_party/khronos/GLES2/gl2.h" |
21 #include "third_party/khronos/GLES2/gl2ext.h" | 20 #include "third_party/khronos/GLES2/gl2ext.h" |
22 | 21 |
23 #include <public/WebGraphicsContext3D.h> | 22 #include <public/WebGraphicsContext3D.h> |
24 | 23 |
25 using WebKit::WebGraphicsContext3D; | 24 using WebKit::WebGraphicsContext3D; |
26 | 25 |
27 namespace cc { | 26 namespace cc { |
28 | 27 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 { | 120 { |
122 WebGraphicsContext3D* context3d = m_context->context3D(); | 121 WebGraphicsContext3D* context3d = m_context->context3D(); |
123 if (!context3d || !context3d->makeContextCurrent()) | 122 if (!context3d || !context3d->makeContextCurrent()) |
124 return; | 123 return; |
125 m_textureUploader.reset(); | 124 m_textureUploader.reset(); |
126 m_textureCopier.reset(); | 125 m_textureCopier.reset(); |
127 } | 126 } |
128 | 127 |
129 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() | 128 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() |
130 { | 129 { |
131 DCHECK(Proxy::isImplThread()); | 130 DCHECK(m_threadChecker.CalledOnValidThread()); |
132 return m_context->context3D(); | 131 return m_context->context3D(); |
133 } | 132 } |
134 | 133 |
135 bool ResourceProvider::inUseByConsumer(ResourceId id) | 134 bool ResourceProvider::inUseByConsumer(ResourceId id) |
136 { | 135 { |
137 DCHECK(Proxy::isImplThread()); | 136 DCHECK(m_threadChecker.CalledOnValidThread()); |
138 ResourceMap::iterator it = m_resources.find(id); | 137 ResourceMap::iterator it = m_resources.find(id); |
139 CHECK(it != m_resources.end()); | 138 CHECK(it != m_resources.end()); |
140 Resource* resource = &it->second; | 139 Resource* resource = &it->second; |
141 return !!resource->lockForReadCount || resource->exported; | 140 return !!resource->lockForReadCount || resource->exported; |
142 } | 141 } |
143 | 142 |
144 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const In
tSize& size, GLenum format, TextureUsageHint hint) | 143 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const In
tSize& size, GLenum format, TextureUsageHint hint) |
145 { | 144 { |
146 switch (m_defaultResourceType) { | 145 switch (m_defaultResourceType) { |
147 case GLTexture: | 146 case GLTexture: |
148 return createGLTexture(pool, size, format, hint); | 147 return createGLTexture(pool, size, format, hint); |
149 case Bitmap: | 148 case Bitmap: |
150 DCHECK(format == GL_RGBA); | 149 DCHECK(format == GL_RGBA); |
151 return createBitmap(pool, size); | 150 return createBitmap(pool, size); |
152 } | 151 } |
153 | 152 |
154 CRASH(); | 153 CRASH(); |
155 return 0; | 154 return 0; |
156 } | 155 } |
157 | 156 |
158 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const I
ntSize& size, GLenum format, TextureUsageHint hint) | 157 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const I
ntSize& size, GLenum format, TextureUsageHint hint) |
159 { | 158 { |
160 DCHECK(Proxy::isImplThread()); | 159 DCHECK(m_threadChecker.CalledOnValidThread()); |
161 unsigned textureId = 0; | 160 unsigned textureId = 0; |
162 WebGraphicsContext3D* context3d = m_context->context3D(); | 161 WebGraphicsContext3D* context3d = m_context->context3D(); |
163 DCHECK(context3d); | 162 DCHECK(context3d); |
164 GLC(context3d, textureId = context3d->createTexture()); | 163 GLC(context3d, textureId = context3d->createTexture()); |
165 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 164 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
166 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 165 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
167 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 166 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
168 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 167 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 168 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
170 | 169 |
171 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 170 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 171 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
173 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 172 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
174 GLenum storageFormat = textureToStorageFormat(format); | 173 GLenum storageFormat = textureToStorageFormat(format); |
175 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); | 174 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); |
176 } else | 175 } else |
177 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | 176 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); |
178 ResourceId id = m_nextId++; | 177 ResourceId id = m_nextId++; |
179 Resource resource(textureId, pool, size, format); | 178 Resource resource(textureId, pool, size, format); |
180 m_resources[id] = resource; | 179 m_resources[id] = resource; |
181 return id; | 180 return id; |
182 } | 181 } |
183 | 182 |
184 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const IntS
ize& size) | 183 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const IntS
ize& size) |
185 { | 184 { |
186 DCHECK(Proxy::isImplThread()); | 185 DCHECK(m_threadChecker.CalledOnValidThread()); |
187 | 186 |
188 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 187 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
189 | 188 |
190 ResourceId id = m_nextId++; | 189 ResourceId id = m_nextId++; |
191 Resource resource(pixels, pool, size, GL_RGBA); | 190 Resource resource(pixels, pool, size, GL_RGBA); |
192 m_resources[id] = resource; | 191 m_resources[id] = resource; |
193 return id; | 192 return id; |
194 } | 193 } |
195 | 194 |
196 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) | 195 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) |
197 { | 196 { |
198 DCHECK(Proxy::isImplThread()); | 197 DCHECK(m_threadChecker.CalledOnValidThread()); |
199 DCHECK(m_context->context3D()); | 198 DCHECK(m_context->context3D()); |
200 ResourceId id = m_nextId++; | 199 ResourceId id = m_nextId++; |
201 Resource resource(textureId, 0, IntSize(), 0); | 200 Resource resource(textureId, 0, IntSize(), 0); |
202 resource.external = true; | 201 resource.external = true; |
203 m_resources[id] = resource; | 202 m_resources[id] = resource; |
204 return id; | 203 return id; |
205 } | 204 } |
206 | 205 |
207 void ResourceProvider::deleteResource(ResourceId id) | 206 void ResourceProvider::deleteResource(ResourceId id) |
208 { | 207 { |
209 DCHECK(Proxy::isImplThread()); | 208 DCHECK(m_threadChecker.CalledOnValidThread()); |
210 ResourceMap::iterator it = m_resources.find(id); | 209 ResourceMap::iterator it = m_resources.find(id); |
211 CHECK(it != m_resources.end()); | 210 CHECK(it != m_resources.end()); |
212 Resource* resource = &it->second; | 211 Resource* resource = &it->second; |
213 DCHECK(!resource->lockedForWrite); | 212 DCHECK(!resource->lockedForWrite); |
214 DCHECK(!resource->lockForReadCount); | 213 DCHECK(!resource->lockForReadCount); |
215 DCHECK(!resource->markedForDeletion); | 214 DCHECK(!resource->markedForDeletion); |
216 | 215 |
217 if (resource->exported) { | 216 if (resource->exported) { |
218 resource->markedForDeletion = true; | 217 resource->markedForDeletion = true; |
219 return; | 218 return; |
(...skipping 10 matching lines...) Expand all Loading... |
230 GLC(context3d, context3d->deleteTexture(resource->glId)); | 229 GLC(context3d, context3d->deleteTexture(resource->glId)); |
231 } | 230 } |
232 if (resource->pixels) | 231 if (resource->pixels) |
233 delete resource->pixels; | 232 delete resource->pixels; |
234 | 233 |
235 m_resources.erase(it); | 234 m_resources.erase(it); |
236 } | 235 } |
237 | 236 |
238 void ResourceProvider::deleteOwnedResources(int pool) | 237 void ResourceProvider::deleteOwnedResources(int pool) |
239 { | 238 { |
240 DCHECK(Proxy::isImplThread()); | 239 DCHECK(m_threadChecker.CalledOnValidThread()); |
241 ResourceIdArray toDelete; | 240 ResourceIdArray toDelete; |
242 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { | 241 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { |
243 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) | 242 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) |
244 toDelete.push_back(it->first); | 243 toDelete.push_back(it->first); |
245 } | 244 } |
246 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) | 245 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) |
247 deleteResource(*it); | 246 deleteResource(*it); |
248 } | 247 } |
249 | 248 |
250 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) | 249 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) |
251 { | 250 { |
252 ResourceMap::iterator it = m_resources.find(id); | 251 ResourceMap::iterator it = m_resources.find(id); |
253 CHECK(it != m_resources.end()); | 252 CHECK(it != m_resources.end()); |
254 Resource* resource = &it->second; | 253 Resource* resource = &it->second; |
255 return resource->type; | 254 return resource->type; |
256 } | 255 } |
257 | 256 |
258 void ResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRect
& imageRect, const IntRect& sourceRect, const IntSize& destOffset) | 257 void ResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRect
& imageRect, const IntRect& sourceRect, const IntSize& destOffset) |
259 { | 258 { |
260 DCHECK(Proxy::isImplThread()); | 259 DCHECK(m_threadChecker.CalledOnValidThread()); |
261 ResourceMap::iterator it = m_resources.find(id); | 260 ResourceMap::iterator it = m_resources.find(id); |
262 CHECK(it != m_resources.end()); | 261 CHECK(it != m_resources.end()); |
263 Resource* resource = &it->second; | 262 Resource* resource = &it->second; |
264 DCHECK(!resource->lockedForWrite); | 263 DCHECK(!resource->lockedForWrite); |
265 DCHECK(!resource->lockForReadCount); | 264 DCHECK(!resource->lockForReadCount); |
266 DCHECK(!resource->external); | 265 DCHECK(!resource->external); |
267 DCHECK(!resource->exported); | 266 DCHECK(!resource->exported); |
268 | 267 |
269 if (resource->glId) { | 268 if (resource->glId) { |
270 WebGraphicsContext3D* context3d = m_context->context3D(); | 269 WebGraphicsContext3D* context3d = m_context->context3D(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 double ResourceProvider::estimatedUploadsPerSecond() | 312 double ResourceProvider::estimatedUploadsPerSecond() |
314 { | 313 { |
315 if (!m_textureUploader) | 314 if (!m_textureUploader) |
316 return 0.0; | 315 return 0.0; |
317 | 316 |
318 return m_textureUploader->estimatedTexturesPerSecond(); | 317 return m_textureUploader->estimatedTexturesPerSecond(); |
319 } | 318 } |
320 | 319 |
321 void ResourceProvider::flush() | 320 void ResourceProvider::flush() |
322 { | 321 { |
323 DCHECK(Proxy::isImplThread()); | 322 DCHECK(m_threadChecker.CalledOnValidThread()); |
324 WebGraphicsContext3D* context3d = m_context->context3D(); | 323 WebGraphicsContext3D* context3d = m_context->context3D(); |
325 if (context3d) | 324 if (context3d) |
326 context3d->flush(); | 325 context3d->flush(); |
327 } | 326 } |
328 | 327 |
329 bool ResourceProvider::shallowFlushIfSupported() | 328 bool ResourceProvider::shallowFlushIfSupported() |
330 { | 329 { |
331 DCHECK(Proxy::isImplThread()); | 330 DCHECK(m_threadChecker.CalledOnValidThread()); |
332 WebGraphicsContext3D* context3d = m_context->context3D(); | 331 WebGraphicsContext3D* context3d = m_context->context3D(); |
333 if (!context3d || !m_useShallowFlush) | 332 if (!context3d || !m_useShallowFlush) |
334 return false; | 333 return false; |
335 | 334 |
336 context3d->shallowFlushCHROMIUM(); | 335 context3d->shallowFlushCHROMIUM(); |
337 return true; | 336 return true; |
338 } | 337 } |
339 | 338 |
340 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) | 339 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
341 { | 340 { |
342 DCHECK(Proxy::isImplThread()); | 341 DCHECK(m_threadChecker.CalledOnValidThread()); |
343 ResourceMap::iterator it = m_resources.find(id); | 342 ResourceMap::iterator it = m_resources.find(id); |
344 CHECK(it != m_resources.end()); | 343 CHECK(it != m_resources.end()); |
345 | 344 |
346 Resource* resource = &it->second; | 345 Resource* resource = &it->second; |
347 DCHECK(!resource->lockedForWrite); | 346 DCHECK(!resource->lockedForWrite); |
348 DCHECK(!resource->exported); | 347 DCHECK(!resource->exported); |
349 resource->lockForReadCount++; | 348 resource->lockForReadCount++; |
350 return resource; | 349 return resource; |
351 } | 350 } |
352 | 351 |
353 void ResourceProvider::unlockForRead(ResourceId id) | 352 void ResourceProvider::unlockForRead(ResourceId id) |
354 { | 353 { |
355 DCHECK(Proxy::isImplThread()); | 354 DCHECK(m_threadChecker.CalledOnValidThread()); |
356 ResourceMap::iterator it = m_resources.find(id); | 355 ResourceMap::iterator it = m_resources.find(id); |
357 CHECK(it != m_resources.end()); | 356 CHECK(it != m_resources.end()); |
358 Resource* resource = &it->second; | 357 Resource* resource = &it->second; |
359 DCHECK(resource->lockForReadCount > 0); | 358 DCHECK(resource->lockForReadCount > 0); |
360 DCHECK(!resource->exported); | 359 DCHECK(!resource->exported); |
361 resource->lockForReadCount--; | 360 resource->lockForReadCount--; |
362 } | 361 } |
363 | 362 |
364 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) | 363 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) |
365 { | 364 { |
366 DCHECK(Proxy::isImplThread()); | 365 DCHECK(m_threadChecker.CalledOnValidThread()); |
367 ResourceMap::iterator it = m_resources.find(id); | 366 ResourceMap::iterator it = m_resources.find(id); |
368 CHECK(it != m_resources.end()); | 367 CHECK(it != m_resources.end()); |
369 Resource* resource = &it->second; | 368 Resource* resource = &it->second; |
370 DCHECK(!resource->lockedForWrite); | 369 DCHECK(!resource->lockedForWrite); |
371 DCHECK(!resource->lockForReadCount); | 370 DCHECK(!resource->lockForReadCount); |
372 DCHECK(!resource->exported); | 371 DCHECK(!resource->exported); |
373 DCHECK(!resource->external); | 372 DCHECK(!resource->external); |
374 resource->lockedForWrite = true; | 373 resource->lockedForWrite = true; |
375 return resource; | 374 return resource; |
376 } | 375 } |
377 | 376 |
378 void ResourceProvider::unlockForWrite(ResourceId id) | 377 void ResourceProvider::unlockForWrite(ResourceId id) |
379 { | 378 { |
380 DCHECK(Proxy::isImplThread()); | 379 DCHECK(m_threadChecker.CalledOnValidThread()); |
381 ResourceMap::iterator it = m_resources.find(id); | 380 ResourceMap::iterator it = m_resources.find(id); |
382 CHECK(it != m_resources.end()); | 381 CHECK(it != m_resources.end()); |
383 Resource* resource = &it->second; | 382 Resource* resource = &it->second; |
384 DCHECK(resource->lockedForWrite); | 383 DCHECK(resource->lockedForWrite); |
385 DCHECK(!resource->exported); | 384 DCHECK(!resource->exported); |
386 DCHECK(!resource->external); | 385 DCHECK(!resource->external); |
387 resource->lockedForWrite = false; | 386 resource->lockedForWrite = false; |
388 } | 387 } |
389 | 388 |
390 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(ResourceProvider* resourceP
rovider, ResourceProvider::ResourceId resourceId) | 389 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(ResourceProvider* resourceP
rovider, ResourceProvider::ResourceId resourceId) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 , m_defaultResourceType(GLTexture) | 452 , m_defaultResourceType(GLTexture) |
454 , m_useTextureStorageExt(false) | 453 , m_useTextureStorageExt(false) |
455 , m_useTextureUsageHint(false) | 454 , m_useTextureUsageHint(false) |
456 , m_useShallowFlush(false) | 455 , m_useShallowFlush(false) |
457 , m_maxTextureSize(0) | 456 , m_maxTextureSize(0) |
458 { | 457 { |
459 } | 458 } |
460 | 459 |
461 bool ResourceProvider::initialize() | 460 bool ResourceProvider::initialize() |
462 { | 461 { |
463 DCHECK(Proxy::isImplThread()); | 462 DCHECK(m_threadChecker.CalledOnValidThread()); |
464 WebGraphicsContext3D* context3d = m_context->context3D(); | 463 WebGraphicsContext3D* context3d = m_context->context3D(); |
465 if (!context3d) { | 464 if (!context3d) { |
466 m_maxTextureSize = INT_MAX / 2; | 465 m_maxTextureSize = INT_MAX / 2; |
467 return true; | 466 return true; |
468 } | 467 } |
469 if (!context3d->makeContextCurrent()) | 468 if (!context3d->makeContextCurrent()) |
470 return false; | 469 return false; |
471 | 470 |
472 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); | 471 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); |
473 std::vector<std::string> extensions; | 472 std::vector<std::string> extensions; |
(...skipping 15 matching lines...) Expand all Loading... |
489 | 488 |
490 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); | 489 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); |
491 | 490 |
492 m_textureUploader = TextureUploader::create(context3d, useMapSub); | 491 m_textureUploader = TextureUploader::create(context3d, useMapSub); |
493 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize
)); | 492 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize
)); |
494 return true; | 493 return true; |
495 } | 494 } |
496 | 495 |
497 int ResourceProvider::createChild(int pool) | 496 int ResourceProvider::createChild(int pool) |
498 { | 497 { |
499 DCHECK(Proxy::isImplThread()); | 498 DCHECK(m_threadChecker.CalledOnValidThread()); |
500 Child childInfo; | 499 Child childInfo; |
501 childInfo.pool = pool; | 500 childInfo.pool = pool; |
502 int child = m_nextChild++; | 501 int child = m_nextChild++; |
503 m_children[child] = childInfo; | 502 m_children[child] = childInfo; |
504 return child; | 503 return child; |
505 } | 504 } |
506 | 505 |
507 void ResourceProvider::destroyChild(int child) | 506 void ResourceProvider::destroyChild(int child) |
508 { | 507 { |
509 DCHECK(Proxy::isImplThread()); | 508 DCHECK(m_threadChecker.CalledOnValidThread()); |
510 ChildMap::iterator it = m_children.find(child); | 509 ChildMap::iterator it = m_children.find(child); |
511 DCHECK(it != m_children.end()); | 510 DCHECK(it != m_children.end()); |
512 deleteOwnedResources(it->second.pool); | 511 deleteOwnedResources(it->second.pool); |
513 m_children.erase(it); | 512 m_children.erase(it); |
514 trimMailboxDeque(); | 513 trimMailboxDeque(); |
515 } | 514 } |
516 | 515 |
517 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
child) const | 516 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
child) const |
518 { | 517 { |
519 DCHECK(Proxy::isImplThread()); | 518 DCHECK(m_threadChecker.CalledOnValidThread()); |
520 ChildMap::const_iterator it = m_children.find(child); | 519 ChildMap::const_iterator it = m_children.find(child); |
521 DCHECK(it != m_children.end()); | 520 DCHECK(it != m_children.end()); |
522 return it->second.childToParentMap; | 521 return it->second.childToParentMap; |
523 } | 522 } |
524 | 523 |
525 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToParent
(const ResourceIdArray& resources) | 524 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToParent
(const ResourceIdArray& resources) |
526 { | 525 { |
527 DCHECK(Proxy::isImplThread()); | 526 DCHECK(m_threadChecker.CalledOnValidThread()); |
528 TransferableResourceList list; | 527 TransferableResourceList list; |
529 list.syncPoint = 0; | 528 list.syncPoint = 0; |
530 WebGraphicsContext3D* context3d = m_context->context3D(); | 529 WebGraphicsContext3D* context3d = m_context->context3D(); |
531 if (!context3d || !context3d->makeContextCurrent()) { | 530 if (!context3d || !context3d->makeContextCurrent()) { |
532 // FIXME: Implement this path for software compositing. | 531 // FIXME: Implement this path for software compositing. |
533 return list; | 532 return list; |
534 } | 533 } |
535 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 534 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
536 TransferableResource resource; | 535 TransferableResource resource; |
537 if (transferResource(context3d, *it, &resource)) { | 536 if (transferResource(context3d, *it, &resource)) { |
538 m_resources.find(*it)->second.exported = true; | 537 m_resources.find(*it)->second.exported = true; |
539 list.resources.push_back(resource); | 538 list.resources.push_back(resource); |
540 } | 539 } |
541 } | 540 } |
542 if (list.resources.size()) | 541 if (list.resources.size()) |
543 list.syncPoint = context3d->insertSyncPoint(); | 542 list.syncPoint = context3d->insertSyncPoint(); |
544 return list; | 543 return list; |
545 } | 544 } |
546 | 545 |
547 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild(
int child, const ResourceIdArray& resources) | 546 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild(
int child, const ResourceIdArray& resources) |
548 { | 547 { |
549 DCHECK(Proxy::isImplThread()); | 548 DCHECK(m_threadChecker.CalledOnValidThread()); |
550 TransferableResourceList list; | 549 TransferableResourceList list; |
551 list.syncPoint = 0; | 550 list.syncPoint = 0; |
552 WebGraphicsContext3D* context3d = m_context->context3D(); | 551 WebGraphicsContext3D* context3d = m_context->context3D(); |
553 if (!context3d || !context3d->makeContextCurrent()) { | 552 if (!context3d || !context3d->makeContextCurrent()) { |
554 // FIXME: Implement this path for software compositing. | 553 // FIXME: Implement this path for software compositing. |
555 return list; | 554 return list; |
556 } | 555 } |
557 Child& childInfo = m_children.find(child)->second; | 556 Child& childInfo = m_children.find(child)->second; |
558 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 557 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
559 TransferableResource resource; | 558 TransferableResource resource; |
560 if (!transferResource(context3d, *it, &resource)) | 559 if (!transferResource(context3d, *it, &resource)) |
561 NOTREACHED(); | 560 NOTREACHED(); |
562 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); | 561 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); |
563 resource.id = childInfo.parentToChildMap[*it]; | 562 resource.id = childInfo.parentToChildMap[*it]; |
564 childInfo.parentToChildMap.erase(*it); | 563 childInfo.parentToChildMap.erase(*it); |
565 childInfo.childToParentMap.erase(resource.id); | 564 childInfo.childToParentMap.erase(resource.id); |
566 list.resources.push_back(resource); | 565 list.resources.push_back(resource); |
567 deleteResource(*it); | 566 deleteResource(*it); |
568 } | 567 } |
569 if (list.resources.size()) | 568 if (list.resources.size()) |
570 list.syncPoint = context3d->insertSyncPoint(); | 569 list.syncPoint = context3d->insertSyncPoint(); |
571 return list; | 570 return list; |
572 } | 571 } |
573 | 572 |
574 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) | 573 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) |
575 { | 574 { |
576 DCHECK(Proxy::isImplThread()); | 575 DCHECK(m_threadChecker.CalledOnValidThread()); |
577 WebGraphicsContext3D* context3d = m_context->context3D(); | 576 WebGraphicsContext3D* context3d = m_context->context3D(); |
578 if (!context3d || !context3d->makeContextCurrent()) { | 577 if (!context3d || !context3d->makeContextCurrent()) { |
579 // FIXME: Implement this path for software compositing. | 578 // FIXME: Implement this path for software compositing. |
580 return; | 579 return; |
581 } | 580 } |
582 if (resources.syncPoint) { | 581 if (resources.syncPoint) { |
583 // NOTE: If the parent is a browser and the child a renderer, the parent | 582 // NOTE: If the parent is a browser and the child a renderer, the parent |
584 // is not supposed to have its context wait, because that could induce | 583 // is not supposed to have its context wait, because that could induce |
585 // deadlocks and/or security issues. The caller is responsible for | 584 // deadlocks and/or security issues. The caller is responsible for |
586 // waiting asynchronously, and resetting syncPoint before calling this. | 585 // waiting asynchronously, and resetting syncPoint before calling this. |
(...skipping 11 matching lines...) Expand all Loading... |
598 Resource resource(textureId, childInfo.pool, it->size, it->format); | 597 Resource resource(textureId, childInfo.pool, it->size, it->format); |
599 m_resources[id] = resource; | 598 m_resources[id] = resource; |
600 m_mailboxes.push_back(it->mailbox); | 599 m_mailboxes.push_back(it->mailbox); |
601 childInfo.parentToChildMap[id] = it->id; | 600 childInfo.parentToChildMap[id] = it->id; |
602 childInfo.childToParentMap[it->id] = id; | 601 childInfo.childToParentMap[it->id] = id; |
603 } | 602 } |
604 } | 603 } |
605 | 604 |
606 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) | 605 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) |
607 { | 606 { |
608 DCHECK(Proxy::isImplThread()); | 607 DCHECK(m_threadChecker.CalledOnValidThread()); |
609 WebGraphicsContext3D* context3d = m_context->context3D(); | 608 WebGraphicsContext3D* context3d = m_context->context3D(); |
610 if (!context3d || !context3d->makeContextCurrent()) { | 609 if (!context3d || !context3d->makeContextCurrent()) { |
611 // FIXME: Implement this path for software compositing. | 610 // FIXME: Implement this path for software compositing. |
612 return; | 611 return; |
613 } | 612 } |
614 if (resources.syncPoint) | 613 if (resources.syncPoint) |
615 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 614 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
616 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { | 615 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
617 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 616 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
618 DCHECK(mapIterator != m_resources.end()); | 617 DCHECK(mapIterator != m_resources.end()); |
619 Resource* resource = &mapIterator->second; | 618 Resource* resource = &mapIterator->second; |
620 DCHECK(resource->exported); | 619 DCHECK(resource->exported); |
621 resource->exported = false; | 620 resource->exported = false; |
622 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 621 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
623 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); | 622 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); |
624 m_mailboxes.push_back(it->mailbox); | 623 m_mailboxes.push_back(it->mailbox); |
625 if (resource->markedForDeletion) | 624 if (resource->markedForDeletion) |
626 deleteResourceInternal(mapIterator); | 625 deleteResourceInternal(mapIterator); |
627 } | 626 } |
628 } | 627 } |
629 | 628 |
630 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) | 629 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) |
631 { | 630 { |
632 DCHECK(Proxy::isImplThread()); | 631 DCHECK(m_threadChecker.CalledOnValidThread()); |
633 ResourceMap::const_iterator it = m_resources.find(id); | 632 ResourceMap::const_iterator it = m_resources.find(id); |
634 CHECK(it != m_resources.end()); | 633 CHECK(it != m_resources.end()); |
635 const Resource* source = &it->second; | 634 const Resource* source = &it->second; |
636 DCHECK(!source->lockedForWrite); | 635 DCHECK(!source->lockedForWrite); |
637 DCHECK(!source->lockForReadCount); | 636 DCHECK(!source->lockForReadCount); |
638 DCHECK(!source->external); | 637 DCHECK(!source->external); |
639 if (source->exported) | 638 if (source->exported) |
640 return false; | 639 return false; |
641 resource->id = id; | 640 resource->id = id; |
642 resource->format = source->format; | 641 resource->format = source->format; |
(...skipping 29 matching lines...) Expand all Loading... |
672 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { | 671 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { |
673 if (ContainsKey(childPoolSet, it->second.pool)) | 672 if (ContainsKey(childPoolSet, it->second.pool)) |
674 ++maxMailboxCount; | 673 ++maxMailboxCount; |
675 } | 674 } |
676 } | 675 } |
677 while (m_mailboxes.size() > maxMailboxCount) | 676 while (m_mailboxes.size() > maxMailboxCount) |
678 m_mailboxes.pop_front(); | 677 m_mailboxes.pop_front(); |
679 } | 678 } |
680 | 679 |
681 } | 680 } |
OLD | NEW |