Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2495)

Unified Diff: cc/CCResourceProvider.cpp

Issue 11074009: cc: Remove LayerTextureUpdater::Texture::updateRect() callback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/CCResourceProvider.cpp
diff --git a/cc/CCResourceProvider.cpp b/cc/CCResourceProvider.cpp
index af5da1fea21013f176eff2ab9a4ba152c03f0891..ad5be7a5ae07963d41b94abd31872948b4f02921 100644
--- a/cc/CCResourceProvider.cpp
+++ b/cc/CCResourceProvider.cpp
@@ -19,12 +19,15 @@
#include "Extensions3DChromium.h"
#include "IntRect.h"
#include "LayerTextureSubImage.h"
+#include "SkGpuDevice.h"
#include "ThrottledTextureUploader.h"
#include "UnthrottledTextureUploader.h"
#include <public/WebGraphicsContext3D.h>
+#include <public/WebSharedGraphicsContext3D.h>
#include <wtf/HashSet.h>
using WebKit::WebGraphicsContext3D;
+using WebKit::WebSharedGraphicsContext3D;
namespace {
// Temporary variables for debugging crashes in issue 151428 in canary.
@@ -33,6 +36,23 @@ namespace {
unsigned int g_debugZone = 0;
int64 g_debugResDestroyedCount = 0;
cc::CCResourceProvider::ResourceId g_debugResDestroyed[g_debugMaxResourcesTracked] = { 0 };
+
+PassOwnPtr<SkCanvas> createAcceleratedCanvas(GrContext* grContext,
+ cc::IntSize canvasSize,
+ unsigned textureId)
+{
+ GrPlatformTextureDesc textureDesc;
+ textureDesc.fFlags = kRenderTarget_GrPlatformTextureFlag;
+ textureDesc.fWidth = canvasSize.width();
+ textureDesc.fHeight = canvasSize.height();
+ textureDesc.fConfig = kSkia8888_GrPixelConfig;
+ textureDesc.fTextureHandle = textureId;
+ SkAutoTUnref<GrTexture> target(
+ grContext->createPlatformTexture(textureDesc));
+ SkAutoTUnref<SkDevice> device(new SkGpuDevice(grContext, target.get()));
+ return adoptPtr(new SkCanvas(device.get()));
+}
+
}
namespace cc {
@@ -309,6 +329,71 @@ void CCResourceProvider::upload(ResourceId id, const uint8_t* image, const IntRe
}
}
+void CCResourceProvider::acceleratedUpdate(ResourceId id, SkPicture* picture, const IntRect& pictureRect, const IntRect& sourceRect, const IntSize& destOffset)
+{
+ ASSERT(CCProxy::isImplThread());
+ ResourceMap::iterator it = m_resources.find(id);
+ CHECK(it != m_resources.end());
+#if WTF_NEW_HASHMAP_ITERATORS_INTERFACE
+ Resource* resource = &it->value;
+#else
+ Resource* resource = &it->second;
+#endif
+ ASSERT(!resource->lockedForWrite);
+ ASSERT(!resource->lockForReadCount);
+ ASSERT(!resource->external);
+
+ if (resource->glId) {
+ WebGraphicsContext3D* paintContext = CCProxy::hasImplThread() ? WebSharedGraphicsContext3D::compositorThreadContext() : WebSharedGraphicsContext3D::mainThreadContext();
+ GrContext* paintGrContext = CCProxy::hasImplThread() ? WebSharedGraphicsContext3D::compositorThreadGrContext() : WebSharedGraphicsContext3D::mainThreadGrContext();
+
+ // Flush the context in which the backing texture is created so that it
+ // is available in other shared contexts. It is important to do here
+ // because the backing texture is created in one context while it is
+ // being written to in another.
+ flush();
+
+ ScopedWriteLockGL lock(this, id);
+
+ // Make sure ganesh uses the correct GL context.
+ paintContext->makeContextCurrent();
+
+ // Create an accelerated canvas to draw on.
+ OwnPtr<SkCanvas> canvas = createAcceleratedCanvas(paintGrContext, resource->size, resource->glId);
+
+ // The compositor expects the textures to be upside-down so it can flip
+ // the final composited image. Ganesh renders the image upright so we
+ // need to do a y-flip.
+ canvas->translate(0.0, resource->size.height());
+ canvas->scale(1.0, -1.0);
+ // Clip to the destination on the texture that must be updated.
+ canvas->clipRect(SkRect::MakeXYWH(destOffset.width(), destOffset.height(), sourceRect.width(), sourceRect.height()));
+ // Translate the origin of pictureRect to destOffset.
+ // Note that destOffset is defined relative to sourceRect.
+ canvas->translate(
+ pictureRect.x() - sourceRect.x() + destOffset.width(),
+ pictureRect.y() - sourceRect.y() + destOffset.height());
+ canvas->drawPicture(*picture);
+
+ // Flush ganesh context so that all the rendered stuff appears on the texture.
+ paintGrContext->flush();
+
+ // Flush the GL context so rendering results from this context are visible in the compositor's context.
+ paintContext->flush();
+ }
+
+ if (resource->pixels) {
+ ScopedWriteLockSoftware lock(this, id);
+ SkCanvas* canvas = lock.skCanvas();
+ canvas->save();
+ // Translate the origin of pictureRect to that of sourceRect.
+ canvas->translate(pictureRect.x() - sourceRect.x(),
+ pictureRect.y() - sourceRect.y());
+ canvas->drawPicture(*picture);
+ canvas->restore();
+ }
+}
+
void CCResourceProvider::flush()
{
ASSERT(CCProxy::isImplThread());

Powered by Google App Engine
This is Rietveld 408576698