| 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> | 12 #include <limits.h> |
| 13 | 13 |
| 14 #include "base/debug/alias.h" | 14 #include "base/debug/alias.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 "CCProxy.h" | 17 #include "CCProxy.h" |
| 18 #include "CCRendererGL.h" // For the GLC() macro. | 18 #include "CCRendererGL.h" // For the GLC() macro. |
| 19 #include "Extensions3DChromium.h" | 19 #include "Extensions3DChromium.h" |
| 20 #include "IntRect.h" | 20 #include "IntRect.h" |
| 21 #include "LayerTextureSubImage.h" | 21 #include "LayerTextureSubImage.h" |
| 22 #include "SkGpuDevice.h" |
| 22 #include "ThrottledTextureUploader.h" | 23 #include "ThrottledTextureUploader.h" |
| 23 #include "UnthrottledTextureUploader.h" | 24 #include "UnthrottledTextureUploader.h" |
| 24 #include <public/WebGraphicsContext3D.h> | 25 #include <public/WebGraphicsContext3D.h> |
| 26 #include <public/WebSharedGraphicsContext3D.h> |
| 25 #include <wtf/HashSet.h> | 27 #include <wtf/HashSet.h> |
| 26 | 28 |
| 27 using WebKit::WebGraphicsContext3D; | 29 using WebKit::WebGraphicsContext3D; |
| 30 using WebKit::WebSharedGraphicsContext3D; |
| 28 | 31 |
| 29 namespace { | 32 namespace { |
| 30 // Temporary variables for debugging crashes in issue 151428 in canary. | 33 // Temporary variables for debugging crashes in issue 151428 in canary. |
| 31 // Do not use these! | 34 // Do not use these! |
| 32 const int g_debugMaxResourcesTracked = 64; | 35 const int g_debugMaxResourcesTracked = 64; |
| 33 unsigned int g_debugZone = 0; | 36 unsigned int g_debugZone = 0; |
| 34 int64 g_debugResDestroyedCount = 0; | 37 int64 g_debugResDestroyedCount = 0; |
| 35 cc::CCResourceProvider::ResourceId g_debugResDestroyed[g_debugMaxResourcesTr
acked] = { 0 }; | 38 cc::CCResourceProvider::ResourceId g_debugResDestroyed[g_debugMaxResourcesTr
acked] = { 0 }; |
| 39 |
| 40 PassOwnPtr<SkCanvas> createAcceleratedCanvas(GrContext* grContext, |
| 41 cc::IntSize canvasSize, |
| 42 unsigned textureId) |
| 43 { |
| 44 GrPlatformTextureDesc textureDesc; |
| 45 textureDesc.fFlags = kRenderTarget_GrPlatformTextureFlag; |
| 46 textureDesc.fWidth = canvasSize.width(); |
| 47 textureDesc.fHeight = canvasSize.height(); |
| 48 textureDesc.fConfig = kSkia8888_GrPixelConfig; |
| 49 textureDesc.fTextureHandle = textureId; |
| 50 SkAutoTUnref<GrTexture> target( |
| 51 grContext->createPlatformTexture(textureDesc)); |
| 52 SkAutoTUnref<SkDevice> device(new SkGpuDevice(grContext, target.get())); |
| 53 return adoptPtr(new SkCanvas(device.get())); |
| 54 } |
| 55 |
| 36 } | 56 } |
| 37 | 57 |
| 38 namespace cc { | 58 namespace cc { |
| 39 | 59 |
| 40 static GC3Denum textureToStorageFormat(GC3Denum textureFormat) | 60 static GC3Denum textureToStorageFormat(GC3Denum textureFormat) |
| 41 { | 61 { |
| 42 GC3Denum storageFormat = Extensions3D::RGBA8_OES; | 62 GC3Denum storageFormat = Extensions3D::RGBA8_OES; |
| 43 switch (textureFormat) { | 63 switch (textureFormat) { |
| 44 case GraphicsContext3D::RGBA: | 64 case GraphicsContext3D::RGBA: |
| 45 break; | 65 break; |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); | 322 SkIRect skSourceRect = SkIRect::MakeXYWH(sourceRect.x(), sourceRect.y(),
sourceRect.width(), sourceRect.height()); |
| 303 skSourceRect.offset(-imageRect.x(), -imageRect.y()); | 323 skSourceRect.offset(-imageRect.x(), -imageRect.y()); |
| 304 srcFull.extractSubset(&srcSubset, skSourceRect); | 324 srcFull.extractSubset(&srcSubset, skSourceRect); |
| 305 | 325 |
| 306 ScopedWriteLockSoftware lock(this, id); | 326 ScopedWriteLockSoftware lock(this, id); |
| 307 SkCanvas* dest = lock.skCanvas(); | 327 SkCanvas* dest = lock.skCanvas(); |
| 308 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); | 328 dest->writePixels(srcSubset, destOffset.width(), destOffset.height()); |
| 309 } | 329 } |
| 310 } | 330 } |
| 311 | 331 |
| 332 void CCResourceProvider::acceleratedUpdate(ResourceId id, SkPicture* picture, co
nst IntRect& pictureRect, const IntRect& sourceRect, const IntSize& destOffset) |
| 333 { |
| 334 ASSERT(CCProxy::isImplThread()); |
| 335 ResourceMap::iterator it = m_resources.find(id); |
| 336 CHECK(it != m_resources.end()); |
| 337 #if WTF_NEW_HASHMAP_ITERATORS_INTERFACE |
| 338 Resource* resource = &it->value; |
| 339 #else |
| 340 Resource* resource = &it->second; |
| 341 #endif |
| 342 ASSERT(!resource->lockedForWrite); |
| 343 ASSERT(!resource->lockForReadCount); |
| 344 ASSERT(!resource->external); |
| 345 |
| 346 if (resource->glId) { |
| 347 WebGraphicsContext3D* paintContext = CCProxy::hasImplThread() ? WebShare
dGraphicsContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::main
ThreadContext(); |
| 348 GrContext* paintGrContext = CCProxy::hasImplThread() ? WebSharedGraphics
Context3D::compositorThreadGrContext() : WebSharedGraphicsContext3D::mainThreadG
rContext(); |
| 349 |
| 350 // Flush the context in which the backing texture is created so that it |
| 351 // is available in other shared contexts. It is important to do here |
| 352 // because the backing texture is created in one context while it is |
| 353 // being written to in another. |
| 354 flush(); |
| 355 |
| 356 ScopedWriteLockGL lock(this, id); |
| 357 |
| 358 // Make sure ganesh uses the correct GL context. |
| 359 paintContext->makeContextCurrent(); |
| 360 |
| 361 // Create an accelerated canvas to draw on. |
| 362 OwnPtr<SkCanvas> canvas = createAcceleratedCanvas(paintGrContext, resour
ce->size, resource->glId); |
| 363 |
| 364 // The compositor expects the textures to be upside-down so it can flip |
| 365 // the final composited image. Ganesh renders the image upright so we |
| 366 // need to do a y-flip. |
| 367 canvas->translate(0.0, resource->size.height()); |
| 368 canvas->scale(1.0, -1.0); |
| 369 // Clip to the destination on the texture that must be updated. |
| 370 canvas->clipRect(SkRect::MakeXYWH(destOffset.width(), destOffset.height(
), sourceRect.width(), sourceRect.height())); |
| 371 // Translate the origin of pictureRect to destOffset. |
| 372 // Note that destOffset is defined relative to sourceRect. |
| 373 canvas->translate( |
| 374 pictureRect.x() - sourceRect.x() + destOffset.width(), |
| 375 pictureRect.y() - sourceRect.y() + destOffset.height()); |
| 376 canvas->drawPicture(*picture); |
| 377 |
| 378 // Flush ganesh context so that all the rendered stuff appears on the te
xture. |
| 379 paintGrContext->flush(); |
| 380 |
| 381 // Flush the GL context so rendering results from this context are visib
le in the compositor's context. |
| 382 paintContext->flush(); |
| 383 } |
| 384 |
| 385 if (resource->pixels) { |
| 386 ScopedWriteLockSoftware lock(this, id); |
| 387 SkCanvas* canvas = lock.skCanvas(); |
| 388 canvas->save(); |
| 389 // Translate the origin of pictureRect to that of sourceRect. |
| 390 canvas->translate(pictureRect.x() - sourceRect.x(), |
| 391 pictureRect.y() - sourceRect.y()); |
| 392 canvas->drawPicture(*picture); |
| 393 canvas->restore(); |
| 394 } |
| 395 } |
| 396 |
| 312 void CCResourceProvider::flush() | 397 void CCResourceProvider::flush() |
| 313 { | 398 { |
| 314 ASSERT(CCProxy::isImplThread()); | 399 ASSERT(CCProxy::isImplThread()); |
| 315 WebGraphicsContext3D* context3d = m_context->context3D(); | 400 WebGraphicsContext3D* context3d = m_context->context3D(); |
| 316 if (context3d) | 401 if (context3d) |
| 317 context3d->flush(); | 402 context3d->flush(); |
| 318 } | 403 } |
| 319 | 404 |
| 320 bool CCResourceProvider::shallowFlushIfSupported() | 405 bool CCResourceProvider::shallowFlushIfSupported() |
| 321 { | 406 { |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 { | 821 { |
| 737 g_debugZone = zone; | 822 g_debugZone = zone; |
| 738 } | 823 } |
| 739 | 824 |
| 740 void CCResourceProvider::debugNotifyLeaveZone() | 825 void CCResourceProvider::debugNotifyLeaveZone() |
| 741 { | 826 { |
| 742 g_debugZone = 0; | 827 g_debugZone = 0; |
| 743 } | 828 } |
| 744 | 829 |
| 745 } | 830 } |
| OLD | NEW |