| 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 { | 26 namespace { |
| 28 // Temporary variables for debugging crashes in issue 151428 in canary. | 27 // Temporary variables for debugging crashes in issue 151428 in canary. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 { | 129 { |
| 131 WebGraphicsContext3D* context3d = m_context->context3D(); | 130 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 132 if (!context3d || !context3d->makeContextCurrent()) | 131 if (!context3d || !context3d->makeContextCurrent()) |
| 133 return; | 132 return; |
| 134 m_textureUploader.reset(); | 133 m_textureUploader.reset(); |
| 135 m_textureCopier.reset(); | 134 m_textureCopier.reset(); |
| 136 } | 135 } |
| 137 | 136 |
| 138 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() | 137 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() |
| 139 { | 138 { |
| 140 DCHECK(Proxy::isImplThread()); | 139 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 141 return m_context->context3D(); | 140 return m_context->context3D(); |
| 142 } | 141 } |
| 143 | 142 |
| 144 bool ResourceProvider::inUseByConsumer(ResourceId id) | 143 bool ResourceProvider::inUseByConsumer(ResourceId id) |
| 145 { | 144 { |
| 146 DCHECK(Proxy::isImplThread()); | 145 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 147 ResourceMap::iterator it = m_resources.find(id); | 146 ResourceMap::iterator it = m_resources.find(id); |
| 148 CHECK(it != m_resources.end()); | 147 CHECK(it != m_resources.end()); |
| 149 Resource* resource = &it->second; | 148 Resource* resource = &it->second; |
| 150 return !!resource->lockForReadCount || resource->exported; | 149 return !!resource->lockForReadCount || resource->exported; |
| 151 } | 150 } |
| 152 | 151 |
| 153 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const In
tSize& size, GLenum format, TextureUsageHint hint) | 152 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const In
tSize& size, GLenum format, TextureUsageHint hint) |
| 154 { | 153 { |
| 155 switch (m_defaultResourceType) { | 154 switch (m_defaultResourceType) { |
| 156 case GLTexture: | 155 case GLTexture: |
| 157 return createGLTexture(pool, size, format, hint); | 156 return createGLTexture(pool, size, format, hint); |
| 158 case Bitmap: | 157 case Bitmap: |
| 159 DCHECK(format == GL_RGBA); | 158 DCHECK(format == GL_RGBA); |
| 160 return createBitmap(pool, size); | 159 return createBitmap(pool, size); |
| 161 } | 160 } |
| 162 | 161 |
| 163 CRASH(); | 162 CRASH(); |
| 164 return 0; | 163 return 0; |
| 165 } | 164 } |
| 166 | 165 |
| 167 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const I
ntSize& size, GLenum format, TextureUsageHint hint) | 166 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const I
ntSize& size, GLenum format, TextureUsageHint hint) |
| 168 { | 167 { |
| 169 DCHECK(Proxy::isImplThread()); | 168 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 170 unsigned textureId = 0; | 169 unsigned textureId = 0; |
| 171 WebGraphicsContext3D* context3d = m_context->context3D(); | 170 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 172 DCHECK(context3d); | 171 DCHECK(context3d); |
| 173 GLC(context3d, textureId = context3d->createTexture()); | 172 GLC(context3d, textureId = context3d->createTexture()); |
| 174 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 173 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
| 175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 174 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
| 176 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
| 177 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 176 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
| 178 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 177 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
| 179 | 178 |
| 180 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 179 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
| 181 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 180 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
| 182 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 181 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
| 183 GLenum storageFormat = textureToStorageFormat(format); | 182 GLenum storageFormat = textureToStorageFormat(format); |
| 184 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); | 183 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); |
| 185 } else | 184 } else |
| 186 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | 185 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); |
| 187 ResourceId id = m_nextId++; | 186 ResourceId id = m_nextId++; |
| 188 Resource resource(textureId, pool, size, format); | 187 Resource resource(textureId, pool, size, format); |
| 189 m_resources[id] = resource; | 188 m_resources[id] = resource; |
| 190 return id; | 189 return id; |
| 191 } | 190 } |
| 192 | 191 |
| 193 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const IntS
ize& size) | 192 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const IntS
ize& size) |
| 194 { | 193 { |
| 195 DCHECK(Proxy::isImplThread()); | 194 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 196 | 195 |
| 197 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 196 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
| 198 | 197 |
| 199 ResourceId id = m_nextId++; | 198 ResourceId id = m_nextId++; |
| 200 Resource resource(pixels, pool, size, GL_RGBA); | 199 Resource resource(pixels, pool, size, GL_RGBA); |
| 201 m_resources[id] = resource; | 200 m_resources[id] = resource; |
| 202 return id; | 201 return id; |
| 203 } | 202 } |
| 204 | 203 |
| 205 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) | 204 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) |
| 206 { | 205 { |
| 207 DCHECK(Proxy::isImplThread()); | 206 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 208 DCHECK(m_context->context3D()); | 207 DCHECK(m_context->context3D()); |
| 209 ResourceId id = m_nextId++; | 208 ResourceId id = m_nextId++; |
| 210 Resource resource(textureId, 0, IntSize(), 0); | 209 Resource resource(textureId, 0, IntSize(), 0); |
| 211 resource.external = true; | 210 resource.external = true; |
| 212 m_resources[id] = resource; | 211 m_resources[id] = resource; |
| 213 return id; | 212 return id; |
| 214 } | 213 } |
| 215 | 214 |
| 216 void ResourceProvider::deleteResource(ResourceId id) | 215 void ResourceProvider::deleteResource(ResourceId id) |
| 217 { | 216 { |
| 218 DCHECK(Proxy::isImplThread()); | 217 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 219 ResourceMap::iterator it = m_resources.find(id); | 218 ResourceMap::iterator it = m_resources.find(id); |
| 220 CHECK(it != m_resources.end()); | 219 CHECK(it != m_resources.end()); |
| 221 Resource* resource = &it->second; | 220 Resource* resource = &it->second; |
| 222 DCHECK(!resource->lockedForWrite); | 221 DCHECK(!resource->lockedForWrite); |
| 223 DCHECK(!resource->lockForReadCount); | 222 DCHECK(!resource->lockForReadCount); |
| 224 DCHECK(!resource->markedForDeletion); | 223 DCHECK(!resource->markedForDeletion); |
| 225 | 224 |
| 226 if (resource->exported) { | 225 if (resource->exported) { |
| 227 resource->markedForDeletion = true; | 226 resource->markedForDeletion = true; |
| 228 return; | 227 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 240 } | 239 } |
| 241 if (resource->pixels) | 240 if (resource->pixels) |
| 242 delete resource->pixels; | 241 delete resource->pixels; |
| 243 | 242 |
| 244 g_debugResDestroyed[g_debugResDestroyedCount % g_debugMaxResourcesTracked] =
(*it).first | g_debugZone; | 243 g_debugResDestroyed[g_debugResDestroyedCount % g_debugMaxResourcesTracked] =
(*it).first | g_debugZone; |
| 245 m_resources.erase(it); | 244 m_resources.erase(it); |
| 246 } | 245 } |
| 247 | 246 |
| 248 void ResourceProvider::deleteOwnedResources(int pool) | 247 void ResourceProvider::deleteOwnedResources(int pool) |
| 249 { | 248 { |
| 250 DCHECK(Proxy::isImplThread()); | 249 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 251 ResourceIdArray toDelete; | 250 ResourceIdArray toDelete; |
| 252 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { | 251 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.end()
; ++it) { |
| 253 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) | 252 if (it->second.pool == pool && !it->second.external && !it->second.marke
dForDeletion) |
| 254 toDelete.push_back(it->first); | 253 toDelete.push_back(it->first); |
| 255 } | 254 } |
| 256 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) | 255 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) |
| 257 deleteResource(*it); | 256 deleteResource(*it); |
| 258 } | 257 } |
| 259 | 258 |
| 260 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) | 259 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) |
| 261 { | 260 { |
| 262 ResourceMap::iterator it = m_resources.find(id); | 261 ResourceMap::iterator it = m_resources.find(id); |
| 263 CHECK(it != m_resources.end()); | 262 CHECK(it != m_resources.end()); |
| 264 Resource* resource = &it->second; | 263 Resource* resource = &it->second; |
| 265 return resource->type; | 264 return resource->type; |
| 266 } | 265 } |
| 267 | 266 |
| 268 void ResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRect
& imageRect, const IntRect& sourceRect, const IntSize& destOffset) | 267 void ResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRect
& imageRect, const IntRect& sourceRect, const IntSize& destOffset) |
| 269 { | 268 { |
| 270 DCHECK(Proxy::isImplThread()); | 269 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 271 ResourceMap::iterator it = m_resources.find(id); | 270 ResourceMap::iterator it = m_resources.find(id); |
| 272 CHECK(it != m_resources.end()); | 271 CHECK(it != m_resources.end()); |
| 273 Resource* resource = &it->second; | 272 Resource* resource = &it->second; |
| 274 DCHECK(!resource->lockedForWrite); | 273 DCHECK(!resource->lockedForWrite); |
| 275 DCHECK(!resource->lockForReadCount); | 274 DCHECK(!resource->lockForReadCount); |
| 276 DCHECK(!resource->external); | 275 DCHECK(!resource->external); |
| 277 DCHECK(!resource->exported); | 276 DCHECK(!resource->exported); |
| 278 | 277 |
| 279 if (resource->glId) { | 278 if (resource->glId) { |
| 280 WebGraphicsContext3D* context3d = m_context->context3D(); | 279 WebGraphicsContext3D* context3d = m_context->context3D(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 double ResourceProvider::estimatedUploadsPerSecond() | 322 double ResourceProvider::estimatedUploadsPerSecond() |
| 324 { | 323 { |
| 325 if (!m_textureUploader) | 324 if (!m_textureUploader) |
| 326 return 0.0; | 325 return 0.0; |
| 327 | 326 |
| 328 return m_textureUploader->estimatedTexturesPerSecond(); | 327 return m_textureUploader->estimatedTexturesPerSecond(); |
| 329 } | 328 } |
| 330 | 329 |
| 331 void ResourceProvider::flush() | 330 void ResourceProvider::flush() |
| 332 { | 331 { |
| 333 DCHECK(Proxy::isImplThread()); | 332 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 334 WebGraphicsContext3D* context3d = m_context->context3D(); | 333 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 335 if (context3d) | 334 if (context3d) |
| 336 context3d->flush(); | 335 context3d->flush(); |
| 337 } | 336 } |
| 338 | 337 |
| 339 bool ResourceProvider::shallowFlushIfSupported() | 338 bool ResourceProvider::shallowFlushIfSupported() |
| 340 { | 339 { |
| 341 DCHECK(Proxy::isImplThread()); | 340 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 342 WebGraphicsContext3D* context3d = m_context->context3D(); | 341 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 343 if (!context3d || !m_useShallowFlush) | 342 if (!context3d || !m_useShallowFlush) |
| 344 return false; | 343 return false; |
| 345 | 344 |
| 346 context3d->shallowFlushCHROMIUM(); | 345 context3d->shallowFlushCHROMIUM(); |
| 347 return true; | 346 return true; |
| 348 } | 347 } |
| 349 | 348 |
| 350 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) | 349 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
| 351 { | 350 { |
| 352 DCHECK(Proxy::isImplThread()); | 351 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 353 ResourceMap::iterator it = m_resources.find(id); | 352 ResourceMap::iterator it = m_resources.find(id); |
| 354 | 353 |
| 355 if (it == m_resources.end()) { | 354 if (it == m_resources.end()) { |
| 356 int resourceCount = m_resources.size(); | 355 int resourceCount = m_resources.size(); |
| 357 int64 resDestroyedCount = g_debugResDestroyedCount; | 356 int64 resDestroyedCount = g_debugResDestroyedCount; |
| 358 ResourceId resDestroyed[g_debugMaxResourcesTracked]; | 357 ResourceId resDestroyed[g_debugMaxResourcesTracked]; |
| 359 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) | 358 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) |
| 360 resDestroyed[i] = g_debugResDestroyed[i]; | 359 resDestroyed[i] = g_debugResDestroyed[i]; |
| 361 ResourceId resToDestroy = id; | 360 ResourceId resToDestroy = id; |
| 362 | 361 |
| 363 base::debug::Alias(&resourceCount); | 362 base::debug::Alias(&resourceCount); |
| 364 base::debug::Alias(&resDestroyedCount); | 363 base::debug::Alias(&resDestroyedCount); |
| 365 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) | 364 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) |
| 366 base::debug::Alias(&resDestroyed[i]); | 365 base::debug::Alias(&resDestroyed[i]); |
| 367 base::debug::Alias(&resToDestroy); | 366 base::debug::Alias(&resToDestroy); |
| 368 CHECK(it != m_resources.end()); | 367 CHECK(it != m_resources.end()); |
| 369 } | 368 } |
| 370 | 369 |
| 371 Resource* resource = &it->second; | 370 Resource* resource = &it->second; |
| 372 DCHECK(!resource->lockedForWrite); | 371 DCHECK(!resource->lockedForWrite); |
| 373 DCHECK(!resource->exported); | 372 DCHECK(!resource->exported); |
| 374 resource->lockForReadCount++; | 373 resource->lockForReadCount++; |
| 375 return resource; | 374 return resource; |
| 376 } | 375 } |
| 377 | 376 |
| 378 void ResourceProvider::unlockForRead(ResourceId id) | 377 void ResourceProvider::unlockForRead(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->lockForReadCount > 0); | 383 DCHECK(resource->lockForReadCount > 0); |
| 385 DCHECK(!resource->exported); | 384 DCHECK(!resource->exported); |
| 386 resource->lockForReadCount--; | 385 resource->lockForReadCount--; |
| 387 } | 386 } |
| 388 | 387 |
| 389 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) | 388 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) |
| 390 { | 389 { |
| 391 DCHECK(Proxy::isImplThread()); | 390 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 392 ResourceMap::iterator it = m_resources.find(id); | 391 ResourceMap::iterator it = m_resources.find(id); |
| 393 CHECK(it != m_resources.end()); | 392 CHECK(it != m_resources.end()); |
| 394 Resource* resource = &it->second; | 393 Resource* resource = &it->second; |
| 395 DCHECK(!resource->lockedForWrite); | 394 DCHECK(!resource->lockedForWrite); |
| 396 DCHECK(!resource->lockForReadCount); | 395 DCHECK(!resource->lockForReadCount); |
| 397 DCHECK(!resource->exported); | 396 DCHECK(!resource->exported); |
| 398 DCHECK(!resource->external); | 397 DCHECK(!resource->external); |
| 399 resource->lockedForWrite = true; | 398 resource->lockedForWrite = true; |
| 400 return resource; | 399 return resource; |
| 401 } | 400 } |
| 402 | 401 |
| 403 void ResourceProvider::unlockForWrite(ResourceId id) | 402 void ResourceProvider::unlockForWrite(ResourceId id) |
| 404 { | 403 { |
| 405 DCHECK(Proxy::isImplThread()); | 404 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 406 ResourceMap::iterator it = m_resources.find(id); | 405 ResourceMap::iterator it = m_resources.find(id); |
| 407 CHECK(it != m_resources.end()); | 406 CHECK(it != m_resources.end()); |
| 408 Resource* resource = &it->second; | 407 Resource* resource = &it->second; |
| 409 DCHECK(resource->lockedForWrite); | 408 DCHECK(resource->lockedForWrite); |
| 410 DCHECK(!resource->exported); | 409 DCHECK(!resource->exported); |
| 411 DCHECK(!resource->external); | 410 DCHECK(!resource->external); |
| 412 resource->lockedForWrite = false; | 411 resource->lockedForWrite = false; |
| 413 } | 412 } |
| 414 | 413 |
| 415 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(ResourceProvider* resourceP
rovider, ResourceProvider::ResourceId resourceId) | 414 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(ResourceProvider* resourceP
rovider, ResourceProvider::ResourceId resourceId) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 , m_defaultResourceType(GLTexture) | 477 , m_defaultResourceType(GLTexture) |
| 479 , m_useTextureStorageExt(false) | 478 , m_useTextureStorageExt(false) |
| 480 , m_useTextureUsageHint(false) | 479 , m_useTextureUsageHint(false) |
| 481 , m_useShallowFlush(false) | 480 , m_useShallowFlush(false) |
| 482 , m_maxTextureSize(0) | 481 , m_maxTextureSize(0) |
| 483 { | 482 { |
| 484 } | 483 } |
| 485 | 484 |
| 486 bool ResourceProvider::initialize() | 485 bool ResourceProvider::initialize() |
| 487 { | 486 { |
| 488 DCHECK(Proxy::isImplThread()); | 487 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 489 WebGraphicsContext3D* context3d = m_context->context3D(); | 488 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 490 if (!context3d) { | 489 if (!context3d) { |
| 491 m_maxTextureSize = INT_MAX / 2; | 490 m_maxTextureSize = INT_MAX / 2; |
| 492 return true; | 491 return true; |
| 493 } | 492 } |
| 494 if (!context3d->makeContextCurrent()) | 493 if (!context3d->makeContextCurrent()) |
| 495 return false; | 494 return false; |
| 496 | 495 |
| 497 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); | 496 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); |
| 498 std::vector<std::string> extensions; | 497 std::vector<std::string> extensions; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 514 | 513 |
| 515 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); | 514 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); |
| 516 | 515 |
| 517 m_textureUploader = TextureUploader::create(context3d, useMapSub); | 516 m_textureUploader = TextureUploader::create(context3d, useMapSub); |
| 518 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize
)); | 517 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize
)); |
| 519 return true; | 518 return true; |
| 520 } | 519 } |
| 521 | 520 |
| 522 int ResourceProvider::createChild(int pool) | 521 int ResourceProvider::createChild(int pool) |
| 523 { | 522 { |
| 524 DCHECK(Proxy::isImplThread()); | 523 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 525 Child childInfo; | 524 Child childInfo; |
| 526 childInfo.pool = pool; | 525 childInfo.pool = pool; |
| 527 int child = m_nextChild++; | 526 int child = m_nextChild++; |
| 528 m_children[child] = childInfo; | 527 m_children[child] = childInfo; |
| 529 return child; | 528 return child; |
| 530 } | 529 } |
| 531 | 530 |
| 532 void ResourceProvider::destroyChild(int child) | 531 void ResourceProvider::destroyChild(int child) |
| 533 { | 532 { |
| 534 DCHECK(Proxy::isImplThread()); | 533 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 535 ChildMap::iterator it = m_children.find(child); | 534 ChildMap::iterator it = m_children.find(child); |
| 536 DCHECK(it != m_children.end()); | 535 DCHECK(it != m_children.end()); |
| 537 deleteOwnedResources(it->second.pool); | 536 deleteOwnedResources(it->second.pool); |
| 538 m_children.erase(it); | 537 m_children.erase(it); |
| 539 trimMailboxDeque(); | 538 trimMailboxDeque(); |
| 540 } | 539 } |
| 541 | 540 |
| 542 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
child) const | 541 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
child) const |
| 543 { | 542 { |
| 544 DCHECK(Proxy::isImplThread()); | 543 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 545 ChildMap::const_iterator it = m_children.find(child); | 544 ChildMap::const_iterator it = m_children.find(child); |
| 546 DCHECK(it != m_children.end()); | 545 DCHECK(it != m_children.end()); |
| 547 return it->second.childToParentMap; | 546 return it->second.childToParentMap; |
| 548 } | 547 } |
| 549 | 548 |
| 550 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToParent
(const ResourceIdArray& resources) | 549 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToParent
(const ResourceIdArray& resources) |
| 551 { | 550 { |
| 552 DCHECK(Proxy::isImplThread()); | 551 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 553 TransferableResourceList list; | 552 TransferableResourceList list; |
| 554 list.syncPoint = 0; | 553 list.syncPoint = 0; |
| 555 WebGraphicsContext3D* context3d = m_context->context3D(); | 554 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 556 if (!context3d || !context3d->makeContextCurrent()) { | 555 if (!context3d || !context3d->makeContextCurrent()) { |
| 557 // FIXME: Implement this path for software compositing. | 556 // FIXME: Implement this path for software compositing. |
| 558 return list; | 557 return list; |
| 559 } | 558 } |
| 560 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 559 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
| 561 TransferableResource resource; | 560 TransferableResource resource; |
| 562 if (transferResource(context3d, *it, &resource)) { | 561 if (transferResource(context3d, *it, &resource)) { |
| 563 m_resources.find(*it)->second.exported = true; | 562 m_resources.find(*it)->second.exported = true; |
| 564 list.resources.push_back(resource); | 563 list.resources.push_back(resource); |
| 565 } | 564 } |
| 566 } | 565 } |
| 567 if (list.resources.size()) | 566 if (list.resources.size()) |
| 568 list.syncPoint = context3d->insertSyncPoint(); | 567 list.syncPoint = context3d->insertSyncPoint(); |
| 569 return list; | 568 return list; |
| 570 } | 569 } |
| 571 | 570 |
| 572 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild(
int child, const ResourceIdArray& resources) | 571 ResourceProvider::TransferableResourceList ResourceProvider::prepareSendToChild(
int child, const ResourceIdArray& resources) |
| 573 { | 572 { |
| 574 DCHECK(Proxy::isImplThread()); | 573 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 575 TransferableResourceList list; | 574 TransferableResourceList list; |
| 576 list.syncPoint = 0; | 575 list.syncPoint = 0; |
| 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 list; | 579 return list; |
| 581 } | 580 } |
| 582 Child& childInfo = m_children.find(child)->second; | 581 Child& childInfo = m_children.find(child)->second; |
| 583 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 582 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
| 584 TransferableResource resource; | 583 TransferableResource resource; |
| 585 if (!transferResource(context3d, *it, &resource)) | 584 if (!transferResource(context3d, *it, &resource)) |
| 586 NOTREACHED(); | 585 NOTREACHED(); |
| 587 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); | 586 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); |
| 588 resource.id = childInfo.parentToChildMap[*it]; | 587 resource.id = childInfo.parentToChildMap[*it]; |
| 589 childInfo.parentToChildMap.erase(*it); | 588 childInfo.parentToChildMap.erase(*it); |
| 590 childInfo.childToParentMap.erase(resource.id); | 589 childInfo.childToParentMap.erase(resource.id); |
| 591 list.resources.push_back(resource); | 590 list.resources.push_back(resource); |
| 592 deleteResource(*it); | 591 deleteResource(*it); |
| 593 } | 592 } |
| 594 if (list.resources.size()) | 593 if (list.resources.size()) |
| 595 list.syncPoint = context3d->insertSyncPoint(); | 594 list.syncPoint = context3d->insertSyncPoint(); |
| 596 return list; | 595 return list; |
| 597 } | 596 } |
| 598 | 597 |
| 599 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) | 598 void ResourceProvider::receiveFromChild(int child, const TransferableResourceLis
t& resources) |
| 600 { | 599 { |
| 601 DCHECK(Proxy::isImplThread()); | 600 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 602 WebGraphicsContext3D* context3d = m_context->context3D(); | 601 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 603 if (!context3d || !context3d->makeContextCurrent()) { | 602 if (!context3d || !context3d->makeContextCurrent()) { |
| 604 // FIXME: Implement this path for software compositing. | 603 // FIXME: Implement this path for software compositing. |
| 605 return; | 604 return; |
| 606 } | 605 } |
| 607 if (resources.syncPoint) { | 606 if (resources.syncPoint) { |
| 608 // NOTE: If the parent is a browser and the child a renderer, the parent | 607 // NOTE: If the parent is a browser and the child a renderer, the parent |
| 609 // is not supposed to have its context wait, because that could induce | 608 // is not supposed to have its context wait, because that could induce |
| 610 // deadlocks and/or security issues. The caller is responsible for | 609 // deadlocks and/or security issues. The caller is responsible for |
| 611 // waiting asynchronously, and resetting syncPoint before calling this. | 610 // waiting asynchronously, and resetting syncPoint before calling this. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 623 Resource resource(textureId, childInfo.pool, it->size, it->format); | 622 Resource resource(textureId, childInfo.pool, it->size, it->format); |
| 624 m_resources[id] = resource; | 623 m_resources[id] = resource; |
| 625 m_mailboxes.push_back(it->mailbox); | 624 m_mailboxes.push_back(it->mailbox); |
| 626 childInfo.parentToChildMap[id] = it->id; | 625 childInfo.parentToChildMap[id] = it->id; |
| 627 childInfo.childToParentMap[it->id] = id; | 626 childInfo.childToParentMap[it->id] = id; |
| 628 } | 627 } |
| 629 } | 628 } |
| 630 | 629 |
| 631 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) | 630 void ResourceProvider::receiveFromParent(const TransferableResourceList& resourc
es) |
| 632 { | 631 { |
| 633 DCHECK(Proxy::isImplThread()); | 632 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 634 WebGraphicsContext3D* context3d = m_context->context3D(); | 633 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 635 if (!context3d || !context3d->makeContextCurrent()) { | 634 if (!context3d || !context3d->makeContextCurrent()) { |
| 636 // FIXME: Implement this path for software compositing. | 635 // FIXME: Implement this path for software compositing. |
| 637 return; | 636 return; |
| 638 } | 637 } |
| 639 if (resources.syncPoint) | 638 if (resources.syncPoint) |
| 640 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); | 639 GLC(context3d, context3d->waitSyncPoint(resources.syncPoint)); |
| 641 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { | 640 for (TransferableResourceArray::const_iterator it = resources.resources.begi
n(); it != resources.resources.end(); ++it) { |
| 642 ResourceMap::iterator mapIterator = m_resources.find(it->id); | 641 ResourceMap::iterator mapIterator = m_resources.find(it->id); |
| 643 DCHECK(mapIterator != m_resources.end()); | 642 DCHECK(mapIterator != m_resources.end()); |
| 644 Resource* resource = &mapIterator->second; | 643 Resource* resource = &mapIterator->second; |
| 645 DCHECK(resource->exported); | 644 DCHECK(resource->exported); |
| 646 resource->exported = false; | 645 resource->exported = false; |
| 647 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); | 646 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->glId)); |
| 648 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); | 647 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, it->mail
box.name)); |
| 649 m_mailboxes.push_back(it->mailbox); | 648 m_mailboxes.push_back(it->mailbox); |
| 650 if (resource->markedForDeletion) | 649 if (resource->markedForDeletion) |
| 651 deleteResourceInternal(mapIterator); | 650 deleteResourceInternal(mapIterator); |
| 652 } | 651 } |
| 653 } | 652 } |
| 654 | 653 |
| 655 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) | 654 bool ResourceProvider::transferResource(WebGraphicsContext3D* context, ResourceI
d id, TransferableResource* resource) |
| 656 { | 655 { |
| 657 DCHECK(Proxy::isImplThread()); | 656 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 658 ResourceMap::const_iterator it = m_resources.find(id); | 657 ResourceMap::const_iterator it = m_resources.find(id); |
| 659 CHECK(it != m_resources.end()); | 658 CHECK(it != m_resources.end()); |
| 660 const Resource* source = &it->second; | 659 const Resource* source = &it->second; |
| 661 DCHECK(!source->lockedForWrite); | 660 DCHECK(!source->lockedForWrite); |
| 662 DCHECK(!source->lockForReadCount); | 661 DCHECK(!source->lockForReadCount); |
| 663 DCHECK(!source->external); | 662 DCHECK(!source->external); |
| 664 if (source->exported) | 663 if (source->exported) |
| 665 return false; | 664 return false; |
| 666 resource->id = id; | 665 resource->id = id; |
| 667 resource->format = source->format; | 666 resource->format = source->format; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 g_debugZone = zone; | 707 g_debugZone = zone; |
| 709 } | 708 } |
| 710 | 709 |
| 711 void ResourceProvider::debugNotifyLeaveZone() | 710 void ResourceProvider::debugNotifyLeaveZone() |
| 712 { | 711 { |
| 713 g_debugZone = 0; | 712 g_debugZone = 0; |
| 714 } | 713 } |
| 715 | 714 |
| 716 | 715 |
| 717 } | 716 } |
| OLD | NEW |