| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCResourceProvider.h" | 7 #include "CCResourceProvider.h" |
| 8 #ifdef LOG | 8 #ifdef LOG |
| 9 #undef LOG | 9 #undef LOG |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include <limits.h> |
| 13 |
| 12 #include "base/string_split.h" | 14 #include "base/string_split.h" |
| 13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 14 #include "CCProxy.h" | 16 #include "CCProxy.h" |
| 15 #include "CCRendererGL.h" // For the GLC() macro. | 17 #include "CCRendererGL.h" // For the GLC() macro. |
| 16 #include "Extensions3DChromium.h" | 18 #include "Extensions3DChromium.h" |
| 17 #include "IntRect.h" | 19 #include "IntRect.h" |
| 18 #include "LayerTextureSubImage.h" | 20 #include "LayerTextureSubImage.h" |
| 19 #include <limits.h> | 21 #include "ThrottledTextureUploader.h" |
| 22 #include "UnthrottledTextureUploader.h" |
| 20 #include <public/WebGraphicsContext3D.h> | 23 #include <public/WebGraphicsContext3D.h> |
| 21 #include <wtf/HashSet.h> | 24 #include <wtf/HashSet.h> |
| 22 | 25 |
| 23 using WebKit::WebGraphicsContext3D; | 26 using WebKit::WebGraphicsContext3D; |
| 24 | 27 |
| 25 namespace cc { | 28 namespace cc { |
| 26 | 29 |
| 27 static GC3Denum textureToStorageFormat(GC3Denum textureFormat) | 30 static GC3Denum textureToStorageFormat(GC3Denum textureFormat) |
| 28 { | 31 { |
| 29 GC3Denum storageFormat = Extensions3D::RGBA8_OES; | 32 GC3Denum storageFormat = Extensions3D::RGBA8_OES; |
| 30 switch (textureFormat) { | 33 switch (textureFormat) { |
| 31 case GraphicsContext3D::RGBA: | 34 case GraphicsContext3D::RGBA: |
| 32 break; | 35 break; |
| 33 case Extensions3D::BGRA_EXT: | 36 case Extensions3D::BGRA_EXT: |
| 34 storageFormat = Extensions3DChromium::BGRA8_EXT; | 37 storageFormat = Extensions3DChromium::BGRA8_EXT; |
| 35 break; | 38 break; |
| 36 default: | 39 default: |
| 37 ASSERT_NOT_REACHED(); | 40 ASSERT_NOT_REACHED(); |
| 38 break; | 41 break; |
| 39 } | 42 } |
| 40 | 43 |
| 41 return storageFormat; | 44 return storageFormat; |
| 42 } | 45 } |
| 43 | 46 |
| 44 static bool isTextureFormatSupportedForStorage(GC3Denum format) | 47 static bool isTextureFormatSupportedForStorage(GC3Denum format) |
| 45 { | 48 { |
| 46 return (format == GraphicsContext3D::RGBA || format == Extensions3D::BGRA_EX
T); | 49 return (format == GraphicsContext3D::RGBA || format == Extensions3D::BGRA_EX
T); |
| 47 } | 50 } |
| 48 | 51 |
| 49 PassOwnPtr<CCResourceProvider> CCResourceProvider::create(CCGraphicsContext* con
text) | 52 PassOwnPtr<CCResourceProvider> CCResourceProvider::create(CCGraphicsContext* con
text, TextureUploaderOption option) |
| 50 { | 53 { |
| 51 OwnPtr<CCResourceProvider> resourceProvider(adoptPtr(new CCResourceProvider(
context))); | 54 OwnPtr<CCResourceProvider> resourceProvider(adoptPtr(new CCResourceProvider(
context))); |
| 52 if (!resourceProvider->initialize()) | 55 if (!resourceProvider->initialize(option)) |
| 53 return nullptr; | 56 return nullptr; |
| 54 return resourceProvider.release(); | 57 return resourceProvider.release(); |
| 55 } | 58 } |
| 56 | 59 |
| 57 CCResourceProvider::~CCResourceProvider() | 60 CCResourceProvider::~CCResourceProvider() |
| 58 { | 61 { |
| 62 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 63 if (!context3d || !context3d->makeContextCurrent()) |
| 64 return; |
| 65 m_textureUploader.clear(); |
| 66 m_textureCopier.clear(); |
| 59 } | 67 } |
| 60 | 68 |
| 61 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D() | 69 WebGraphicsContext3D* CCResourceProvider::graphicsContext3D() |
| 62 { | 70 { |
| 63 ASSERT(CCProxy::isImplThread()); | 71 ASSERT(CCProxy::isImplThread()); |
| 64 return m_context->context3D(); | 72 return m_context->context3D(); |
| 65 } | 73 } |
| 66 | 74 |
| 67 bool CCResourceProvider::inUseByConsumer(ResourceId id) | 75 bool CCResourceProvider::inUseByConsumer(ResourceId id) |
| 68 { | 76 { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 , m_nextId(1) | 337 , m_nextId(1) |
| 330 , m_nextChild(1) | 338 , m_nextChild(1) |
| 331 , m_defaultResourceType(GLTexture) | 339 , m_defaultResourceType(GLTexture) |
| 332 , m_useTextureStorageExt(false) | 340 , m_useTextureStorageExt(false) |
| 333 , m_useTextureUsageHint(false) | 341 , m_useTextureUsageHint(false) |
| 334 , m_useShallowFlush(false) | 342 , m_useShallowFlush(false) |
| 335 , m_maxTextureSize(0) | 343 , m_maxTextureSize(0) |
| 336 { | 344 { |
| 337 } | 345 } |
| 338 | 346 |
| 339 bool CCResourceProvider::initialize() | 347 bool CCResourceProvider::initialize(TextureUploaderOption textureUploaderOption) |
| 340 { | 348 { |
| 341 ASSERT(CCProxy::isImplThread()); | 349 ASSERT(CCProxy::isImplThread()); |
| 342 WebGraphicsContext3D* context3d = m_context->context3D(); | 350 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 343 if (!context3d) { | 351 if (!context3d) { |
| 344 m_maxTextureSize = INT_MAX; | 352 m_maxTextureSize = INT_MAX; |
| 353 m_textureUploader = UnthrottledTextureUploader::create(); |
| 345 | 354 |
| 346 // FIXME: Implement this path for software compositing. | 355 // FIXME: Implement this path for software compositing. |
| 347 return false; | 356 return false; |
| 348 } | 357 } |
| 349 if (!context3d->makeContextCurrent()) | 358 if (!context3d->makeContextCurrent()) |
| 350 return false; | 359 return false; |
| 351 | 360 |
| 352 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon
text3D::EXTENSIONS)); | 361 std::string extensionsString = UTF16ToASCII(context3d->getString(GraphicsCon
text3D::EXTENSIONS)); |
| 353 std::vector<std::string> extensions; | 362 std::vector<std::string> extensions; |
| 354 base::SplitString(extensionsString, ' ', &extensions); | 363 base::SplitString(extensionsString, ' ', &extensions); |
| 355 bool useMapSub = false; | 364 bool useMapSub = false; |
| 365 bool useBindUniform = false; |
| 356 for (size_t i = 0; i < extensions.size(); ++i) { | 366 for (size_t i = 0; i < extensions.size(); ++i) { |
| 357 if (extensions[i] == "GL_EXT_texture_storage") | 367 if (extensions[i] == "GL_EXT_texture_storage") |
| 358 m_useTextureStorageExt = true; | 368 m_useTextureStorageExt = true; |
| 359 else if (extensions[i] == "GL_ANGLE_texture_usage") | 369 else if (extensions[i] == "GL_ANGLE_texture_usage") |
| 360 m_useTextureUsageHint = true; | 370 m_useTextureUsageHint = true; |
| 361 else if (extensions[i] == "GL_CHROMIUM_map_sub") | 371 else if (extensions[i] == "GL_CHROMIUM_map_sub") |
| 362 useMapSub = true; | 372 useMapSub = true; |
| 363 else if (extensions[i] == "GL_CHROMIUM_shallow_flush") | 373 else if (extensions[i] == "GL_CHROMIUM_shallow_flush") |
| 364 m_useShallowFlush = true; | 374 m_useShallowFlush = true; |
| 375 else if (extensions[i] == "GL_CHROMIUM_bind_uniform_location") |
| 376 useBindUniform = true; |
| 365 } | 377 } |
| 366 | 378 |
| 367 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub)); | 379 m_texSubImage = adoptPtr(new LayerTextureSubImage(useMapSub)); |
| 380 m_textureCopier = AcceleratedTextureCopier::create(context3d, useBindUniform
); |
| 381 |
| 382 if (textureUploaderOption == ThrottledUploader) |
| 383 m_textureUploader = ThrottledTextureUploader::create(context3d); |
| 384 else |
| 385 m_textureUploader = UnthrottledTextureUploader::create(); |
| 368 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); | 386 GLC(context3d, context3d->getIntegerv(GraphicsContext3D::MAX_TEXTURE_SIZE, &
m_maxTextureSize)); |
| 369 return true; | 387 return true; |
| 370 } | 388 } |
| 371 | 389 |
| 372 int CCResourceProvider::createChild(int pool) | 390 int CCResourceProvider::createChild(int pool) |
| 373 { | 391 { |
| 374 ASSERT(CCProxy::isImplThread()); | 392 ASSERT(CCProxy::isImplThread()); |
| 375 Child childInfo; | 393 Child childInfo; |
| 376 childInfo.pool = pool; | 394 childInfo.pool = pool; |
| 377 int child = m_nextChild++; | 395 int child = m_nextChild++; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { | 557 for (ResourceMap::iterator it = m_resources.begin(); it != m_resources.e
nd(); ++it) { |
| 540 if (childPoolSet.contains(it->second.pool)) | 558 if (childPoolSet.contains(it->second.pool)) |
| 541 ++maxMailboxCount; | 559 ++maxMailboxCount; |
| 542 } | 560 } |
| 543 } | 561 } |
| 544 while (m_mailboxes.size() > maxMailboxCount) | 562 while (m_mailboxes.size() > maxMailboxCount) |
| 545 m_mailboxes.removeFirst(); | 563 m_mailboxes.removeFirst(); |
| 546 } | 564 } |
| 547 | 565 |
| 548 } | 566 } |
| OLD | NEW |