Bug 875218 - Ensure the GrContext's lifetime is managed properly by DrawTargetSkia r=bjacob

This commit is contained in:
George Wright 2013-05-29 14:04:25 -04:00
parent d439609bcf
commit dc4ca76cb2
5 changed files with 17 additions and 15 deletions

View File

@ -936,7 +936,7 @@ public:
#ifdef USE_SKIA_GPU
static TemporaryRef<DrawTarget>
CreateSkiaDrawTargetForFBO(unsigned int aFBOID, GrContext *aContext, const IntSize &aSize, SurfaceFormat aFormat);
CreateSkiaDrawTargetForFBO(unsigned int aFBOID, GrContext* aContext, const IntSize &aSize, SurfaceFormat aFormat);
#endif
#ifdef WIN32

View File

@ -602,8 +602,9 @@ DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat)
#ifdef USE_SKIA_GPU
void
DrawTargetSkia::InitWithFBO(unsigned int aFBOID, GrContext* aGrContext, const IntSize &aSize, SurfaceFormat aFormat)
DrawTargetSkia::InitWithFBO(unsigned int aFBOID, SkRefPtr<GrContext> aGrContext, const IntSize &aSize, SurfaceFormat aFormat)
{
mGrContext = aGrContext;
GrBackendRenderTargetDesc targetDescriptor;
targetDescriptor.fWidth = aSize.width;
@ -615,7 +616,7 @@ DrawTargetSkia::InitWithFBO(unsigned int aFBOID, GrContext* aGrContext, const In
SkAutoTUnref<GrRenderTarget> target(aGrContext->wrapBackendRenderTarget(targetDescriptor));
SkAutoTUnref<SkDevice> device(new SkGpuDevice(aGrContext, target.get()));
SkAutoTUnref<SkDevice> device(new SkGpuDevice(mGrContext.get(), target.get()));
SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get()));
mSize = aSize;

View File

@ -98,7 +98,7 @@ public:
bool Init(const IntSize &aSize, SurfaceFormat aFormat);
void Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
#ifdef USE_SKIA_GPU
void InitWithFBO(unsigned int aFBOID, GrContext* aGrContext, const IntSize &aSize, SurfaceFormat aFormat);
void InitWithFBO(unsigned int aFBOID, SkRefPtr<GrContext> aGrContext, const IntSize &aSize, SurfaceFormat aFormat);
#endif
operator std::string() const {
@ -117,6 +117,10 @@ private:
IntSize mSize;
SkRefPtr<SkCanvas> mCanvas;
std::vector<SourceSurfaceSkia*> mSnapshots;
#ifdef USE_SKIA_GPU
SkRefPtr<GrContext> mGrContext;
#endif
};
}

View File

@ -451,7 +451,7 @@ Factory::D2DCleanup()
#ifdef USE_SKIA_GPU
TemporaryRef<DrawTarget>
Factory::CreateSkiaDrawTargetForFBO(unsigned int aFBOID, GrContext *aGrContext, const IntSize &aSize, SurfaceFormat aFormat)
Factory::CreateSkiaDrawTargetForFBO(unsigned int aFBOID, GrContext* aGrContext, const IntSize &aSize, SurfaceFormat aFormat)
{
RefPtr<DrawTargetSkia> newTarget = new DrawTargetSkia();
newTarget->InitWithFBO(aFBOID, aGrContext, aSize, aFormat);

View File

@ -827,21 +827,18 @@ RefPtr<DrawTarget>
gfxPlatform::CreateDrawTargetForFBO(unsigned int aFBOID, mozilla::gl::GLContext* aGLContext, const IntSize& aSize, SurfaceFormat aFormat)
{
NS_ASSERTION(mPreferredCanvasBackend, "No backend.");
RefPtr<DrawTarget> target = nullptr;
#ifdef USE_SKIA_GPU
if (mPreferredCanvasBackend == BACKEND_SKIA) {
static uint8_t sGrContextKey;
GrContext* ctx = reinterpret_cast<GrContext*>(aGLContext->GetUserData(&sGrContextKey));
if (!ctx) {
GrGLInterface* grInterface = CreateGrInterfaceFromGLContext(aGLContext);
ctx = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)grInterface);
aGLContext->SetUserData(&sGrContextKey, ctx);
}
GrGLInterface* grInterface = CreateGrInterfaceFromGLContext(aGLContext);
GrContext* ctx = GrContext::Create(kOpenGL_GrBackend, (GrBackendContext)grInterface);
// Unfortunately Factory can't depend on GLContext, so it needs to be passed a GrContext instead
return Factory::CreateSkiaDrawTargetForFBO(aFBOID, ctx, aSize, aFormat);
// Unfortunately Factory can't depend on GLContext, so it needs to be passed a
// GrContext instead.
target = Factory::CreateSkiaDrawTargetForFBO(aFBOID, ctx, aSize, aFormat);
}
#endif
return nullptr;
return target;
}
/* static */ BackendType