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 003954977b
commit f71f7293a2
5 changed files with 23 additions and 14 deletions

View File

@ -20,6 +20,10 @@
#include <string>
#endif
#ifdef USE_SKIA_GPU
#include <skia/SkRefCnt.h>
#endif
struct _cairo_surface;
typedef _cairo_surface cairo_surface_t;
@ -921,7 +925,7 @@ public:
#ifdef USE_SKIA_GPU
static TemporaryRef<DrawTarget>
CreateSkiaDrawTargetForFBO(unsigned int aFBOID, GrContext *aContext, const IntSize &aSize, SurfaceFormat aFormat);
CreateSkiaDrawTargetForFBO(unsigned int aFBOID, SkRefPtr<GrContext> aContext, const IntSize &aSize, SurfaceFormat aFormat);
#endif
#ifdef WIN32

View File

@ -602,8 +602,10 @@ 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;
GrPlatformRenderTargetDesc targetDescriptor;
targetDescriptor.fWidth = aSize.width;
@ -614,7 +616,7 @@ DrawTargetSkia::InitWithFBO(unsigned int aFBOID, GrContext* aGrContext, const In
SkAutoTUnref<GrRenderTarget> target(aGrContext->createPlatformRenderTarget(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

@ -94,7 +94,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 {
@ -113,6 +113,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, SkRefPtr<GrContext> aGrContext, const IntSize &aSize, SurfaceFormat aFormat)
{
RefPtr<DrawTargetSkia> newTarget = new DrawTargetSkia();
newTarget->InitWithFBO(aFBOID, aGrContext, aSize, aFormat);

View File

@ -831,21 +831,20 @@ 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_Shaders_GrEngine, (GrPlatform3DContext)grInterface);
aGLContext->SetUserData(&sGrContextKey, ctx);
}
GrGLInterface* grInterface = CreateGrInterfaceFromGLContext(aGLContext);
SkRefPtr<GrContext> ctx = GrContext::Create(kOpenGL_Shaders_GrEngine, (GrPlatform3DContext)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);
// Finally, lose our ref to ctx as we are passing ownership to DrawTargetSkia
}
#endif
return nullptr;
return target;
}
/* static */ BackendType