| Index: cc/grcontext_provider.cc
|
| diff --git a/cc/grcontext_provider.cc b/cc/grcontext_provider.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..11664b8efa00c4f090a05d71b2ba68f3843dd6ab
|
| --- /dev/null
|
| +++ b/cc/grcontext_provider.cc
|
| @@ -0,0 +1,114 @@
|
| +// Copyright 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "cc/grcontext_provider.h"
|
| +
|
| +#include "cc/resource_provider.h"
|
| +#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
|
| +#include "third_party/skia/include/gpu/GrContext.h"
|
| +#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
|
| +
|
| +namespace cc {
|
| +
|
| +GrContextProvider::GrContextProvider() : context3d_(NULL) {}
|
| +
|
| +GrContextProvider::~GrContextProvider() {
|
| + if (gr_context_)
|
| + gr_context_->contextDestroyed();
|
| +}
|
| +
|
| +static void BindWebGraphicsContext3DGLContextCallback(
|
| + const GrGLInterface* interface) {
|
| + reinterpret_cast<WebKit::WebGraphicsContext3D*>(
|
| + interface->fCallbackData)->makeContextCurrent();
|
| +}
|
| +
|
| +void GrContextProvider::SetContext3d(
|
| + WebKit::WebGraphicsContext3D* context3d) {
|
| + if (context3d == context3d_)
|
| + return;
|
| + context3d_ = context3d;
|
| + if (gr_context_)
|
| + gr_context_->contextDestroyed();
|
| + gr_context_.clear();
|
| +
|
| + if (!context3d_)
|
| + return;
|
| +
|
| + skia::RefPtr<GrGLInterface> interface = skia::AdoptRef(
|
| + context3d->createGrGLInterface());
|
| + if (!interface)
|
| + return;
|
| +
|
| + interface->fCallback = BindWebGraphicsContext3DGLContextCallback;
|
| + interface->fCallbackData =
|
| + reinterpret_cast<GrGLInterfaceCallbackData>(context3d);
|
| +
|
| + gr_context_ = skia::AdoptRef(GrContext::Create(
|
| + kOpenGL_Shaders_GrEngine,
|
| + reinterpret_cast<GrPlatform3DContext>(interface.get())));
|
| +
|
| + if (!gr_context_)
|
| + return;
|
| +
|
| + // TODO(danakj): Register the callback with content/.
|
| + // TODO(danakj): Talk to the GPU mem manager directly.
|
| + context3d_->setMemoryAllocationChangedCallbackCHROMIUM(this);
|
| +
|
| + bool nonzero_allocation = true;
|
| + SetGaneshContextMemoryLimit(nonzero_allocation);
|
| +}
|
| +
|
| +void GrContextProvider::SetGaneshContextMemoryLimit(bool nonzero_allocation) {
|
| + if (!gr_context_)
|
| + return;
|
| +
|
| + if (nonzero_allocation) {
|
| + // The limit of the number of textures we hold in the GrContext's
|
| + // bitmap->texture cache.
|
| + const int kMaxGaneshTextureCacheCount = 2048;
|
| + // The limit of the bytes allocated toward textures in the GrContext's
|
| + // bitmap->texture cache.
|
| + const size_t kMaxGaneshTextureCacheBytes = 96 * 1024 * 1024;
|
| +
|
| + gr_context_->setTextureCacheLimits(
|
| + kMaxGaneshTextureCacheCount, kMaxGaneshTextureCacheBytes);
|
| + return;
|
| + }
|
| + gr_context_->freeGpuResources();
|
| + gr_context_->setTextureCacheLimits(0, 0);
|
| +}
|
| +
|
| +// WebGraphicsMemoryAllocationChangedCallbackCHROMIUM implementation.
|
| +void GrContextProvider::onMemoryAllocationChanged(
|
| + WebKit::WebGraphicsMemoryAllocation allocation) {
|
| + SetGaneshContextMemoryLimit(!!allocation.gpuResourceSizeInBytes);
|
| +}
|
| +
|
| +GrContextProvider::ScopedContexts::ScopedContexts(
|
| + GrContextProvider* grcontext_provider)
|
| + : grcontext_provider_(grcontext_provider) {
|
| +}
|
| +
|
| +GrContextProvider::ScopedContexts::~ScopedContexts() {}
|
| +
|
| +GrContextProvider::ScopedContextsFlushed::ScopedContextsFlushed(
|
| + ResourceProvider* resource_provider,
|
| + GrContextProvider* grcontext_provider)
|
| + : ScopedContexts(grcontext_provider) {
|
| + resource_provider->flush();
|
| +}
|
| +
|
| +GrContextProvider::ScopedContextsFlushed::~ScopedContextsFlushed() {
|
| + // Flush gr context so that all the rendered stuff appears on the
|
| + // texture.
|
| + if (gr_context())
|
| + gr_context()->flush();
|
| + // Flush the GL context so rendering results from this context are
|
| + // visible in the compositor's context.
|
| + if (context3d())
|
| + context3d()->flush();
|
| +}
|
| +
|
| +} // namespace cc
|
|
|