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> #include <string>
#endif #endif
#ifdef USE_SKIA_GPU
#include <skia/SkRefCnt.h>
#endif
struct _cairo_surface; struct _cairo_surface;
typedef _cairo_surface cairo_surface_t; typedef _cairo_surface cairo_surface_t;
@ -921,7 +925,7 @@ public:
#ifdef USE_SKIA_GPU #ifdef USE_SKIA_GPU
static TemporaryRef<DrawTarget> 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 #endif
#ifdef WIN32 #ifdef WIN32

View File

@ -602,8 +602,10 @@ DrawTargetSkia::Init(const IntSize &aSize, SurfaceFormat aFormat)
#ifdef USE_SKIA_GPU #ifdef USE_SKIA_GPU
void 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; GrPlatformRenderTargetDesc targetDescriptor;
targetDescriptor.fWidth = aSize.width; targetDescriptor.fWidth = aSize.width;
@ -614,7 +616,7 @@ DrawTargetSkia::InitWithFBO(unsigned int aFBOID, GrContext* aGrContext, const In
SkAutoTUnref<GrRenderTarget> target(aGrContext->createPlatformRenderTarget(targetDescriptor)); 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())); SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get()));
mSize = aSize; mSize = aSize;

View File

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

View File

@ -451,7 +451,7 @@ Factory::D2DCleanup()
#ifdef USE_SKIA_GPU #ifdef USE_SKIA_GPU
TemporaryRef<DrawTarget> 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(); RefPtr<DrawTargetSkia> newTarget = new DrawTargetSkia();
newTarget->InitWithFBO(aFBOID, aGrContext, aSize, aFormat); 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) gfxPlatform::CreateDrawTargetForFBO(unsigned int aFBOID, mozilla::gl::GLContext* aGLContext, const IntSize& aSize, SurfaceFormat aFormat)
{ {
NS_ASSERTION(mPreferredCanvasBackend, "No backend."); NS_ASSERTION(mPreferredCanvasBackend, "No backend.");
RefPtr<DrawTarget> target = nullptr;
#ifdef USE_SKIA_GPU #ifdef USE_SKIA_GPU
if (mPreferredCanvasBackend == BACKEND_SKIA) { if (mPreferredCanvasBackend == BACKEND_SKIA) {
static uint8_t sGrContextKey; static uint8_t sGrContextKey;
GrContext* ctx = reinterpret_cast<GrContext*>(aGLContext->GetUserData(&sGrContextKey)); GrGLInterface* grInterface = CreateGrInterfaceFromGLContext(aGLContext);
if (!ctx) { SkRefPtr<GrContext> ctx = GrContext::Create(kOpenGL_Shaders_GrEngine, (GrPlatform3DContext)grInterface);
GrGLInterface* grInterface = CreateGrInterfaceFromGLContext(aGLContext);
ctx = GrContext::Create(kOpenGL_Shaders_GrEngine, (GrPlatform3DContext)grInterface);
aGLContext->SetUserData(&sGrContextKey, ctx);
}
// Unfortunately Factory can't depend on GLContext, so it needs to be passed a GrContext instead // Unfortunately Factory can't depend on GLContext, so it needs to be passed a
return Factory::CreateSkiaDrawTargetForFBO(aFBOID, ctx, aSize, aFormat); // GrContext instead.
target = Factory::CreateSkiaDrawTargetForFBO(aFBOID, ctx, aSize, aFormat);
// Finally, lose our ref to ctx as we are passing ownership to DrawTargetSkia
} }
#endif #endif
return nullptr; return target;
} }
/* static */ BackendType /* static */ BackendType