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