| 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 "base/debug/alias.h" | 11 #include "base/debug/alias.h" |
| 12 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/string_split.h" | 14 #include "base/string_split.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "cc/gl_renderer.h" // For the GLC() macro. | 16 #include "cc/gl_renderer.h" // For the GLC() macro. |
| 17 #include "cc/proxy.h" | |
| 18 #include "cc/texture_uploader.h" | 17 #include "cc/texture_uploader.h" |
| 19 #include "cc/transferable_resource.h" | 18 #include "cc/transferable_resource.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 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
| 23 #include "ui/gfx/vector2d.h" | 22 #include "ui/gfx/vector2d.h" |
| 24 | 23 |
| 25 #include <public/WebGraphicsContext3D.h> | 24 #include <public/WebGraphicsContext3D.h> |
| 26 | 25 |
| 27 using WebKit::WebGraphicsContext3D; | 26 using WebKit::WebGraphicsContext3D; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 { | 123 { |
| 125 WebGraphicsContext3D* context3d = m_context->context3D(); | 124 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 126 if (!context3d || !context3d->makeContextCurrent()) | 125 if (!context3d || !context3d->makeContextCurrent()) |
| 127 return; | 126 return; |
| 128 m_textureUploader.reset(); | 127 m_textureUploader.reset(); |
| 129 m_textureCopier.reset(); | 128 m_textureCopier.reset(); |
| 130 } | 129 } |
| 131 | 130 |
| 132 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() | 131 WebGraphicsContext3D* ResourceProvider::graphicsContext3D() |
| 133 { | 132 { |
| 134 DCHECK(Proxy::isImplThread()); | 133 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 135 return m_context->context3D(); | 134 return m_context->context3D(); |
| 136 } | 135 } |
| 137 | 136 |
| 138 bool ResourceProvider::inUseByConsumer(ResourceId id) | 137 bool ResourceProvider::inUseByConsumer(ResourceId id) |
| 139 { | 138 { |
| 140 DCHECK(Proxy::isImplThread()); | 139 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 141 ResourceMap::iterator it = m_resources.find(id); | 140 ResourceMap::iterator it = m_resources.find(id); |
| 142 CHECK(it != m_resources.end()); | 141 CHECK(it != m_resources.end()); |
| 143 Resource* resource = &it->second; | 142 Resource* resource = &it->second; |
| 144 return !!resource->lockForReadCount || resource->exported; | 143 return !!resource->lockForReadCount || resource->exported; |
| 145 } | 144 } |
| 146 | 145 |
| 147 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const gf
x::Size& size, GLenum format, TextureUsageHint hint) | 146 ResourceProvider::ResourceId ResourceProvider::createResource(int pool, const gf
x::Size& size, GLenum format, TextureUsageHint hint) |
| 148 { | 147 { |
| 149 switch (m_defaultResourceType) { | 148 switch (m_defaultResourceType) { |
| 150 case GLTexture: | 149 case GLTexture: |
| 151 return createGLTexture(pool, size, format, hint); | 150 return createGLTexture(pool, size, format, hint); |
| 152 case Bitmap: | 151 case Bitmap: |
| 153 DCHECK(format == GL_RGBA); | 152 DCHECK(format == GL_RGBA); |
| 154 return createBitmap(pool, size); | 153 return createBitmap(pool, size); |
| 155 } | 154 } |
| 156 | 155 |
| 157 CRASH(); | 156 CRASH(); |
| 158 return 0; | 157 return 0; |
| 159 } | 158 } |
| 160 | 159 |
| 161 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g
fx::Size& size, GLenum format, TextureUsageHint hint) | 160 ResourceProvider::ResourceId ResourceProvider::createGLTexture(int pool, const g
fx::Size& size, GLenum format, TextureUsageHint hint) |
| 162 { | 161 { |
| 163 DCHECK(Proxy::isImplThread()); | 162 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 164 unsigned textureId = 0; | 163 unsigned textureId = 0; |
| 165 WebGraphicsContext3D* context3d = m_context->context3D(); | 164 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 166 DCHECK(context3d); | 165 DCHECK(context3d); |
| 167 GLC(context3d, textureId = context3d->createTexture()); | 166 GLC(context3d, textureId = context3d->createTexture()); |
| 168 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); | 167 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, textureId)); |
| 169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); | 168 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER
, GL_LINEAR)); |
| 170 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); | 169 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER
, GL_LINEAR)); |
| 171 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); | 170 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL
_CLAMP_TO_EDGE)); |
| 172 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); | 171 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL
_CLAMP_TO_EDGE)); |
| 173 | 172 |
| 174 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) | 173 if (m_useTextureUsageHint && hint == TextureUsageFramebuffer) |
| 175 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); | 174 GLC(context3d, context3d->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_USAGE_
ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE)); |
| 176 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { | 175 if (m_useTextureStorageExt && isTextureFormatSupportedForStorage(format)) { |
| 177 GLenum storageFormat = textureToStorageFormat(format); | 176 GLenum storageFormat = textureToStorageFormat(format); |
| 178 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); | 177 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, 1, storageForma
t, size.width(), size.height())); |
| 179 } else | 178 } else |
| 180 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); | 179 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 0, format, size.widt
h(), size.height(), 0, format, GL_UNSIGNED_BYTE, 0)); |
| 181 ResourceId id = m_nextId++; | 180 ResourceId id = m_nextId++; |
| 182 Resource resource(textureId, pool, size, format); | 181 Resource resource(textureId, pool, size, format); |
| 183 m_resources[id] = resource; | 182 m_resources[id] = resource; |
| 184 return id; | 183 return id; |
| 185 } | 184 } |
| 186 | 185 |
| 187 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx:
:Size& size) | 186 ResourceProvider::ResourceId ResourceProvider::createBitmap(int pool, const gfx:
:Size& size) |
| 188 { | 187 { |
| 189 DCHECK(Proxy::isImplThread()); | 188 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 190 | 189 |
| 191 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; | 190 uint8_t* pixels = new uint8_t[size.width() * size.height() * 4]; |
| 192 | 191 |
| 193 ResourceId id = m_nextId++; | 192 ResourceId id = m_nextId++; |
| 194 Resource resource(pixels, pool, size, GL_RGBA); | 193 Resource resource(pixels, pool, size, GL_RGBA); |
| 195 m_resources[id] = resource; | 194 m_resources[id] = resource; |
| 196 return id; | 195 return id; |
| 197 } | 196 } |
| 198 | 197 |
| 199 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) | 198 ResourceProvider::ResourceId ResourceProvider::createResourceFromExternalTexture
(unsigned textureId) |
| 200 { | 199 { |
| 201 DCHECK(Proxy::isImplThread()); | 200 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 202 DCHECK(m_context->context3D()); | 201 DCHECK(m_context->context3D()); |
| 203 ResourceId id = m_nextId++; | 202 ResourceId id = m_nextId++; |
| 204 Resource resource(textureId, 0, gfx::Size(), 0); | 203 Resource resource(textureId, 0, gfx::Size(), 0); |
| 205 resource.external = true; | 204 resource.external = true; |
| 206 m_resources[id] = resource; | 205 m_resources[id] = resource; |
| 207 return id; | 206 return id; |
| 208 } | 207 } |
| 209 | 208 |
| 210 void ResourceProvider::deleteResource(ResourceId id) | 209 void ResourceProvider::deleteResource(ResourceId id) |
| 211 { | 210 { |
| 212 DCHECK(Proxy::isImplThread()); | 211 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 213 ResourceMap::iterator it = m_resources.find(id); | 212 ResourceMap::iterator it = m_resources.find(id); |
| 214 CHECK(it != m_resources.end()); | 213 CHECK(it != m_resources.end()); |
| 215 Resource* resource = &it->second; | 214 Resource* resource = &it->second; |
| 216 DCHECK(!resource->lockedForWrite); | 215 DCHECK(!resource->lockedForWrite); |
| 217 DCHECK(!resource->lockForReadCount); | 216 DCHECK(!resource->lockForReadCount); |
| 218 DCHECK(!resource->markedForDeletion); | 217 DCHECK(!resource->markedForDeletion); |
| 219 | 218 |
| 220 if (resource->exported) { | 219 if (resource->exported) { |
| 221 resource->markedForDeletion = true; | 220 resource->markedForDeletion = true; |
| 222 return; | 221 return; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 234 } | 233 } |
| 235 if (resource->pixels) | 234 if (resource->pixels) |
| 236 delete[] resource->pixels; | 235 delete[] resource->pixels; |
| 237 | 236 |
| 238 g_debugResDestroyed[g_debugResDestroyedCount % g_debugMaxResourcesTracked] =
(*it).first | g_debugZone; | 237 g_debugResDestroyed[g_debugResDestroyedCount % g_debugMaxResourcesTracked] =
(*it).first | g_debugZone; |
| 239 m_resources.erase(it); | 238 m_resources.erase(it); |
| 240 } | 239 } |
| 241 | 240 |
| 242 void ResourceProvider::deleteOwnedResources(int pool) | 241 void ResourceProvider::deleteOwnedResources(int pool) |
| 243 { | 242 { |
| 244 DCHECK(Proxy::isImplThread()); | 243 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 245 ResourceIdArray toDelete; | 244 ResourceIdArray toDelete; |
| 246 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) { |
| 247 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) |
| 248 toDelete.push_back(it->first); | 247 toDelete.push_back(it->first); |
| 249 } | 248 } |
| 250 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) | 249 for (ResourceIdArray::iterator it = toDelete.begin(); it != toDelete.end();
++it) |
| 251 deleteResource(*it); | 250 deleteResource(*it); |
| 252 } | 251 } |
| 253 | 252 |
| 254 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) | 253 ResourceProvider::ResourceType ResourceProvider::resourceType(ResourceId id) |
| 255 { | 254 { |
| 256 ResourceMap::iterator it = m_resources.find(id); | 255 ResourceMap::iterator it = m_resources.find(id); |
| 257 CHECK(it != m_resources.end()); | 256 CHECK(it != m_resources.end()); |
| 258 Resource* resource = &it->second; | 257 Resource* resource = &it->second; |
| 259 return resource->type; | 258 return resource->type; |
| 260 } | 259 } |
| 261 | 260 |
| 262 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx:
:Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) | 261 void ResourceProvider::setPixels(ResourceId id, const uint8_t* image, const gfx:
:Rect& imageRect, const gfx::Rect& sourceRect, const gfx::Vector2d& destOffset) |
| 263 { | 262 { |
| 264 DCHECK(Proxy::isImplThread()); | 263 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 265 ResourceMap::iterator it = m_resources.find(id); | 264 ResourceMap::iterator it = m_resources.find(id); |
| 266 CHECK(it != m_resources.end()); | 265 CHECK(it != m_resources.end()); |
| 267 Resource* resource = &it->second; | 266 Resource* resource = &it->second; |
| 268 DCHECK(!resource->lockedForWrite); | 267 DCHECK(!resource->lockedForWrite); |
| 269 DCHECK(!resource->lockForReadCount); | 268 DCHECK(!resource->lockForReadCount); |
| 270 DCHECK(!resource->external); | 269 DCHECK(!resource->external); |
| 271 DCHECK(!resource->exported); | 270 DCHECK(!resource->exported); |
| 272 | 271 |
| 273 if (resource->glId) { | 272 if (resource->glId) { |
| 274 WebGraphicsContext3D* context3d = m_context->context3D(); | 273 WebGraphicsContext3D* context3d = m_context->context3D(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 void ResourceProvider::flushUploads() | 324 void ResourceProvider::flushUploads() |
| 326 { | 325 { |
| 327 if (!m_textureUploader) | 326 if (!m_textureUploader) |
| 328 return; | 327 return; |
| 329 | 328 |
| 330 m_textureUploader->flush(); | 329 m_textureUploader->flush(); |
| 331 } | 330 } |
| 332 | 331 |
| 333 void ResourceProvider::flush() | 332 void ResourceProvider::flush() |
| 334 { | 333 { |
| 335 DCHECK(Proxy::isImplThread()); | 334 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 336 WebGraphicsContext3D* context3d = m_context->context3D(); | 335 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 337 if (context3d) | 336 if (context3d) |
| 338 context3d->flush(); | 337 context3d->flush(); |
| 339 } | 338 } |
| 340 | 339 |
| 341 bool ResourceProvider::shallowFlushIfSupported() | 340 bool ResourceProvider::shallowFlushIfSupported() |
| 342 { | 341 { |
| 343 DCHECK(Proxy::isImplThread()); | 342 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 344 WebGraphicsContext3D* context3d = m_context->context3D(); | 343 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 345 if (!context3d || !m_useShallowFlush) | 344 if (!context3d || !m_useShallowFlush) |
| 346 return false; | 345 return false; |
| 347 | 346 |
| 348 context3d->shallowFlushCHROMIUM(); | 347 context3d->shallowFlushCHROMIUM(); |
| 349 return true; | 348 return true; |
| 350 } | 349 } |
| 351 | 350 |
| 352 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) | 351 const ResourceProvider::Resource* ResourceProvider::lockForRead(ResourceId id) |
| 353 { | 352 { |
| 354 DCHECK(Proxy::isImplThread()); | 353 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 355 ResourceMap::iterator it = m_resources.find(id); | 354 ResourceMap::iterator it = m_resources.find(id); |
| 356 | 355 |
| 357 if (it == m_resources.end()) { | 356 if (it == m_resources.end()) { |
| 358 int resourceCount = m_resources.size(); | 357 int resourceCount = m_resources.size(); |
| 359 int64 resDestroyedCount = g_debugResDestroyedCount; | 358 int64 resDestroyedCount = g_debugResDestroyedCount; |
| 360 ResourceId resDestroyed[g_debugMaxResourcesTracked]; | 359 ResourceId resDestroyed[g_debugMaxResourcesTracked]; |
| 361 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) | 360 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) |
| 362 resDestroyed[i] = g_debugResDestroyed[i]; | 361 resDestroyed[i] = g_debugResDestroyed[i]; |
| 363 ResourceId resToDestroy = id; | 362 ResourceId resToDestroy = id; |
| 364 | 363 |
| 365 base::debug::Alias(&resourceCount); | 364 base::debug::Alias(&resourceCount); |
| 366 base::debug::Alias(&resDestroyedCount); | 365 base::debug::Alias(&resDestroyedCount); |
| 367 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) | 366 for (int64 i = 0; i < g_debugMaxResourcesTracked; ++i) |
| 368 base::debug::Alias(&resDestroyed[i]); | 367 base::debug::Alias(&resDestroyed[i]); |
| 369 base::debug::Alias(&resToDestroy); | 368 base::debug::Alias(&resToDestroy); |
| 370 CHECK(it != m_resources.end()); | 369 CHECK(it != m_resources.end()); |
| 371 } | 370 } |
| 372 | 371 |
| 373 Resource* resource = &it->second; | 372 Resource* resource = &it->second; |
| 374 DCHECK(!resource->lockedForWrite); | 373 DCHECK(!resource->lockedForWrite); |
| 375 DCHECK(!resource->exported); | 374 DCHECK(!resource->exported); |
| 376 resource->lockForReadCount++; | 375 resource->lockForReadCount++; |
| 377 return resource; | 376 return resource; |
| 378 } | 377 } |
| 379 | 378 |
| 380 void ResourceProvider::unlockForRead(ResourceId id) | 379 void ResourceProvider::unlockForRead(ResourceId id) |
| 381 { | 380 { |
| 382 DCHECK(Proxy::isImplThread()); | 381 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 383 ResourceMap::iterator it = m_resources.find(id); | 382 ResourceMap::iterator it = m_resources.find(id); |
| 384 CHECK(it != m_resources.end()); | 383 CHECK(it != m_resources.end()); |
| 385 Resource* resource = &it->second; | 384 Resource* resource = &it->second; |
| 386 DCHECK(resource->lockForReadCount > 0); | 385 DCHECK(resource->lockForReadCount > 0); |
| 387 DCHECK(!resource->exported); | 386 DCHECK(!resource->exported); |
| 388 resource->lockForReadCount--; | 387 resource->lockForReadCount--; |
| 389 } | 388 } |
| 390 | 389 |
| 391 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) | 390 const ResourceProvider::Resource* ResourceProvider::lockForWrite(ResourceId id) |
| 392 { | 391 { |
| 393 DCHECK(Proxy::isImplThread()); | 392 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 394 ResourceMap::iterator it = m_resources.find(id); | 393 ResourceMap::iterator it = m_resources.find(id); |
| 395 CHECK(it != m_resources.end()); | 394 CHECK(it != m_resources.end()); |
| 396 Resource* resource = &it->second; | 395 Resource* resource = &it->second; |
| 397 DCHECK(!resource->lockedForWrite); | 396 DCHECK(!resource->lockedForWrite); |
| 398 DCHECK(!resource->lockForReadCount); | 397 DCHECK(!resource->lockForReadCount); |
| 399 DCHECK(!resource->exported); | 398 DCHECK(!resource->exported); |
| 400 DCHECK(!resource->external); | 399 DCHECK(!resource->external); |
| 401 resource->lockedForWrite = true; | 400 resource->lockedForWrite = true; |
| 402 return resource; | 401 return resource; |
| 403 } | 402 } |
| 404 | 403 |
| 405 void ResourceProvider::unlockForWrite(ResourceId id) | 404 void ResourceProvider::unlockForWrite(ResourceId id) |
| 406 { | 405 { |
| 407 DCHECK(Proxy::isImplThread()); | 406 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 408 ResourceMap::iterator it = m_resources.find(id); | 407 ResourceMap::iterator it = m_resources.find(id); |
| 409 CHECK(it != m_resources.end()); | 408 CHECK(it != m_resources.end()); |
| 410 Resource* resource = &it->second; | 409 Resource* resource = &it->second; |
| 411 DCHECK(resource->lockedForWrite); | 410 DCHECK(resource->lockedForWrite); |
| 412 DCHECK(!resource->exported); | 411 DCHECK(!resource->exported); |
| 413 DCHECK(!resource->external); | 412 DCHECK(!resource->external); |
| 414 resource->lockedForWrite = false; | 413 resource->lockedForWrite = false; |
| 415 } | 414 } |
| 416 | 415 |
| 417 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(ResourceProvider* resourceP
rovider, ResourceProvider::ResourceId resourceId) | 416 ResourceProvider::ScopedReadLockGL::ScopedReadLockGL(ResourceProvider* resourceP
rovider, ResourceProvider::ResourceId resourceId) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 , m_defaultResourceType(GLTexture) | 479 , m_defaultResourceType(GLTexture) |
| 481 , m_useTextureStorageExt(false) | 480 , m_useTextureStorageExt(false) |
| 482 , m_useTextureUsageHint(false) | 481 , m_useTextureUsageHint(false) |
| 483 , m_useShallowFlush(false) | 482 , m_useShallowFlush(false) |
| 484 , m_maxTextureSize(0) | 483 , m_maxTextureSize(0) |
| 485 { | 484 { |
| 486 } | 485 } |
| 487 | 486 |
| 488 bool ResourceProvider::initialize() | 487 bool ResourceProvider::initialize() |
| 489 { | 488 { |
| 490 DCHECK(Proxy::isImplThread()); | 489 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 491 WebGraphicsContext3D* context3d = m_context->context3D(); | 490 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 492 if (!context3d) { | 491 if (!context3d) { |
| 493 m_maxTextureSize = INT_MAX / 2; | 492 m_maxTextureSize = INT_MAX / 2; |
| 494 return true; | 493 return true; |
| 495 } | 494 } |
| 496 if (!context3d->makeContextCurrent()) | 495 if (!context3d->makeContextCurrent()) |
| 497 return false; | 496 return false; |
| 498 | 497 |
| 499 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); | 498 std::string extensionsString = UTF16ToASCII(context3d->getString(GL_EXTENSIO
NS)); |
| 500 std::vector<std::string> extensions; | 499 std::vector<std::string> extensions; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 516 | 515 |
| 517 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); | 516 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); |
| 518 | 517 |
| 519 m_textureUploader = TextureUploader::create(context3d, useMapSub, m_useShall
owFlush); | 518 m_textureUploader = TextureUploader::create(context3d, useMapSub, m_useShall
owFlush); |
| 520 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize
)); | 519 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize
)); |
| 521 return true; | 520 return true; |
| 522 } | 521 } |
| 523 | 522 |
| 524 int ResourceProvider::createChild(int pool) | 523 int ResourceProvider::createChild(int pool) |
| 525 { | 524 { |
| 526 DCHECK(Proxy::isImplThread()); | 525 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 527 Child childInfo; | 526 Child childInfo; |
| 528 childInfo.pool = pool; | 527 childInfo.pool = pool; |
| 529 int child = m_nextChild++; | 528 int child = m_nextChild++; |
| 530 m_children[child] = childInfo; | 529 m_children[child] = childInfo; |
| 531 return child; | 530 return child; |
| 532 } | 531 } |
| 533 | 532 |
| 534 void ResourceProvider::destroyChild(int child) | 533 void ResourceProvider::destroyChild(int child) |
| 535 { | 534 { |
| 536 DCHECK(Proxy::isImplThread()); | 535 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 537 ChildMap::iterator it = m_children.find(child); | 536 ChildMap::iterator it = m_children.find(child); |
| 538 DCHECK(it != m_children.end()); | 537 DCHECK(it != m_children.end()); |
| 539 deleteOwnedResources(it->second.pool); | 538 deleteOwnedResources(it->second.pool); |
| 540 m_children.erase(it); | 539 m_children.erase(it); |
| 541 trimMailboxDeque(); | 540 trimMailboxDeque(); |
| 542 } | 541 } |
| 543 | 542 |
| 544 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
child) const | 543 const ResourceProvider::ResourceIdMap& ResourceProvider::getChildToParentMap(int
child) const |
| 545 { | 544 { |
| 546 DCHECK(Proxy::isImplThread()); | 545 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 547 ChildMap::const_iterator it = m_children.find(child); | 546 ChildMap::const_iterator it = m_children.find(child); |
| 548 DCHECK(it != m_children.end()); | 547 DCHECK(it != m_children.end()); |
| 549 return it->second.childToParentMap; | 548 return it->second.childToParentMap; |
| 550 } | 549 } |
| 551 | 550 |
| 552 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra
nsferableResourceList* list) | 551 void ResourceProvider::prepareSendToParent(const ResourceIdArray& resources, Tra
nsferableResourceList* list) |
| 553 { | 552 { |
| 554 DCHECK(Proxy::isImplThread()); | 553 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 555 list->sync_point = 0; | 554 list->sync_point = 0; |
| 556 list->resources.clear(); | 555 list->resources.clear(); |
| 557 WebGraphicsContext3D* context3d = m_context->context3D(); | 556 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 558 if (!context3d || !context3d->makeContextCurrent()) { | 557 if (!context3d || !context3d->makeContextCurrent()) { |
| 559 // FIXME: Implement this path for software compositing. | 558 // FIXME: Implement this path for software compositing. |
| 560 return; | 559 return; |
| 561 } | 560 } |
| 562 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 561 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
| 563 TransferableResource resource; | 562 TransferableResource resource; |
| 564 if (transferResource(context3d, *it, &resource)) { | 563 if (transferResource(context3d, *it, &resource)) { |
| 565 m_resources.find(*it)->second.exported = true; | 564 m_resources.find(*it)->second.exported = true; |
| 566 list->resources.push_back(resource); | 565 list->resources.push_back(resource); |
| 567 } | 566 } |
| 568 } | 567 } |
| 569 if (list->resources.size()) | 568 if (list->resources.size()) |
| 570 list->sync_point = context3d->insertSyncPoint(); | 569 list->sync_point = context3d->insertSyncPoint(); |
| 571 } | 570 } |
| 572 | 571 |
| 573 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso
urces, TransferableResourceList* list) | 572 void ResourceProvider::prepareSendToChild(int child, const ResourceIdArray& reso
urces, TransferableResourceList* list) |
| 574 { | 573 { |
| 575 DCHECK(Proxy::isImplThread()); | 574 DCHECK(m_threadChecker.CalledOnValidThread()); |
| 576 list->sync_point = 0; | 575 list->sync_point = 0; |
| 577 list->resources.clear(); | 576 list->resources.clear(); |
| 578 WebGraphicsContext3D* context3d = m_context->context3D(); | 577 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 579 if (!context3d || !context3d->makeContextCurrent()) { | 578 if (!context3d || !context3d->makeContextCurrent()) { |
| 580 // FIXME: Implement this path for software compositing. | 579 // FIXME: Implement this path for software compositing. |
| 581 return; | 580 return; |
| 582 } | 581 } |
| 583 Child& childInfo = m_children.find(child)->second; | 582 Child& childInfo = m_children.find(child)->second; |
| 584 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { | 583 for (ResourceIdArray::const_iterator it = resources.begin(); it != resources
.end(); ++it) { |
| 585 TransferableResource resource; | 584 TransferableResource resource; |
| 586 if (!transferResource(context3d, *it, &resource)) | 585 if (!transferResource(context3d, *it, &resource)) |
| 587 NOTREACHED(); | 586 NOTREACHED(); |
| 588 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); | 587 DCHECK(childInfo.parentToChildMap.find(*it) != childInfo.parentToChildMa
p.end()); |
| 589 resource.id = childInfo.parentToChildMap[*it]; | 588 resource.id = childInfo.parentToChildMap[*it]; |
| 590 childInfo.parentToChildMap.erase(*it); | 589 childInfo.parentToChildMap.erase(*it); |
| 591 childInfo.childToParentMap.erase(resource.id); | 590 childInfo.childToParentMap.erase(resource.id); |
| 592 list->resources.push_back(resource); | 591 list->resources.push_back(resource); |
| 593 deleteResource(*it); | 592 deleteResource(*it); |
| 594 } | 593 } |
| 595 if (list->resources.size()) | 594 if (list->resources.size()) |
| 596 list->sync_point = context3d->insertSyncPoint(); | 595 list->sync_point = context3d->insertSyncPoint(); |
| 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.sync_point) { | 606 if (resources.sync_point) { |
| 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 sync_point before calling this. | 610 // waiting asynchronously, and resetting sync_point 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.sync_point) | 638 if (resources.sync_point) |
| 640 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); | 639 GLC(context3d, context3d->waitSyncPoint(resources.sync_point)); |
| 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 } // namespace cc | 716 } // namespace cc |
| OLD | NEW |