Created
November 7, 2013 02:39
-
-
Save vvuk/7348038 to your computer and use it in GitHub Desktop.
SkiaGL hacking patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/content/canvas/src/CanvasRenderingContext2D.cpp b/content/canvas/src/CanvasRenderingContext2D.cpp | |
index 35c5059..bdc9a50 100644 | |
--- a/content/canvas/src/CanvasRenderingContext2D.cpp | |
+++ b/content/canvas/src/CanvasRenderingContext2D.cpp | |
@@ -120,6 +120,8 @@ using namespace mozilla::gfx; | |
using namespace mozilla::ipc; | |
using namespace mozilla::layers; | |
+using mozilla::gl::GLContextSkiaUtils; | |
+ | |
namespace mgfx = mozilla::gfx; | |
namespace mozilla { | |
@@ -868,7 +870,7 @@ CanvasRenderingContext2D::EnsureTarget() | |
} | |
if (glContext) { | |
- SkAutoTUnref<GrGLInterface> i(CreateGrGLInterfaceFromGLContext(glContext)); | |
+ SkAutoTUnref<GrGLInterface> i(GLContextSkiaUtils::CreateGrGLInterfaceFromGLContext(glContext)); | |
mTarget = Factory::CreateDrawTargetSkiaWithGLContextAndGrGLInterface(glContext, i, size, format); | |
AddDemotableContext(this); | |
} else { | |
diff --git a/content/canvas/test/test_canvas.html b/content/canvas/test/test_canvas.html | |
index 2bc155b..f649568 100644 | |
--- a/content/canvas/test/test_canvas.html | |
+++ b/content/canvas/test/test_canvas.html | |
@@ -51,12 +51,12 @@ function IsAzureSkia() { | |
return enabled; | |
} | |
-function IsAcceleratedSkia() { | |
+function IsAcceleratedSkiaCanvas() { | |
var enabled = false; | |
try { | |
var props = Cc["@mozilla.org/gfx/info;1"].getService(SpecialPowers.Ci.nsIGfxInfo).getInfo(); | |
- enabled = props.AzureCanvasBackend == "skia" && props.AzureSkiaAccelerated; | |
+ enabled = props.AzureCanvasBackend == "skia" && props.AzureSkiaCanvasAccelerated; | |
} catch(e) { } | |
return enabled; | |
@@ -6652,7 +6652,7 @@ isPixel(ctx, 98,48, 0,255,0,255, 0); | |
function test_2d_gradient_radial_inside1() { | |
-if (IsAcceleratedSkia()) | |
+if (IsAcceleratedSkiaCanvas()) | |
return; | |
var canvas = document.getElementById('c240'); | |
diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h | |
index c02d319..b422a5e 100644 | |
--- a/gfx/2d/2D.h | |
+++ b/gfx/2d/2D.h | |
@@ -39,6 +39,7 @@ struct ID3D11Device; | |
struct ID2D1Device; | |
struct IDWriteRenderingParams; | |
+class SkDevice; | |
class GrContext; | |
struct GrGLInterface; | |
@@ -912,6 +913,11 @@ public: | |
{ | |
MOZ_CRASH(); | |
} | |
+ | |
+ virtual void InitWithSkDevice(SkDevice *aDevice) | |
+ { | |
+ MOZ_CRASH(); | |
+ } | |
#endif | |
protected: | |
@@ -1003,6 +1009,15 @@ public: | |
const IntSize &aSize, | |
SurfaceFormat aFormat); | |
+ static TemporaryRef<DrawTarget> | |
+ CreateDrawTargetSkiaWithGLContextAndGrContext(GenericRefCountedBase* aGLContext, | |
+ GrContext* aGrContext, | |
+ const IntSize &aSize, | |
+ SurfaceFormat aFormat); | |
+ | |
+ static TemporaryRef<DrawTarget> | |
+ CreateDrawTargetSkiaForSkDevice(SkDevice* aDevice); | |
+ | |
static void | |
SetGlobalSkiaCacheLimits(int aCount, int aSizeInBytes); | |
#endif | |
diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp | |
index f83ef85..9cb737c 100644 | |
--- a/gfx/2d/DrawTargetSkia.cpp | |
+++ b/gfx/2d/DrawTargetSkia.cpp | |
@@ -132,6 +132,9 @@ DrawTargetSkia::SetGlobalCacheLimits(int aCount, int aSizeInBytes) | |
DrawTargetSkia::DrawTargetSkia() | |
: mSnapshot(nullptr) | |
+#ifdef USE_SKIA_GPU | |
+ , mGrTextureID(0) | |
+#endif | |
{ | |
} | |
@@ -585,19 +588,39 @@ DrawTargetSkia::Mask(const Pattern &aSource, | |
raster->addLayer(maskPaint); | |
SkSafeUnref(paint.mPaint.setRasterizer(raster)); | |
- // Skia only uses the mask rasterizer when we are drawing a path/rect. | |
- // Take our destination bounds and convert them into user space to use | |
- // as the path to draw. | |
- SkPath path; | |
- path.addRect(SkRect::MakeWH(SkScalar(mSize.width), SkScalar(mSize.height))); | |
- | |
- Matrix temp = mTransform; | |
- temp.Invert(); | |
- SkMatrix mat; | |
- GfxMatrixToSkiaMatrix(temp, mat); | |
- path.transform(mat); | |
+ mCanvas->drawRect(SkRectCoveringWholeSurface(), paint.mPaint); | |
+} | |
+ | |
+void | |
+DrawTargetSkia::MaskSurface(const Pattern &aSource, | |
+ SourceSurface *aMask, | |
+ Point aOffset, | |
+ const DrawOptions &aOptions) | |
+{ | |
+#if 1 | |
+ MarkChanged(); | |
+ AutoPaintSetup paint(mCanvas.get(), aOptions, aSource); | |
- mCanvas->drawPath(path, paint.mPaint); | |
+ SkPaint maskPaint; | |
+ SetPaintPattern(maskPaint, SurfacePattern(aMask, EXTEND_CLAMP)); | |
+ | |
+ SkLayerRasterizer *raster = new SkLayerRasterizer(); | |
+ raster->addLayer(maskPaint, SkFloatToScalar(aOffset.x), SkFloatToScalar(aOffset.y)); | |
+ SkSafeUnref(paint.mPaint.setRasterizer(raster)); | |
+ | |
+ IntSize size = aMask->GetSize(); | |
+ Rect rect = Rect(aOffset.x, aOffset.y, size.width, size.height); | |
+ | |
+ mCanvas->drawRect(RectToSkRect(rect), paint.mPaint); | |
+#else | |
+ IntSize size = aMask->GetSize(); | |
+ Rect maskRect = Rect(0.f, 0.f, Float(size.width), Float(size.height)); | |
+ | |
+ Rect dest = Rect(aOffset.x, aOffset.y, Float(size.width), Float(size.height)); | |
+ | |
+ FillRect(dest, ColorPattern(Color(1.0, 0.0, 0.0, 1.0)), aOptions); | |
+ /*MOZ_ASSERT(0);*/ | |
+#endif | |
} | |
TemporaryRef<SourceSurface> | |
@@ -729,6 +752,20 @@ DrawTargetSkia::InitWithGLContextAndGrGLInterface(GenericRefCountedBase* aGLCont | |
} | |
void | |
+DrawTargetSkia::InitWithSkDevice(SkDevice *aDevice) | |
+{ | |
+ mSize = IntSize(aDevice->width(), aDevice->height()); | |
+ mFormat = SkiaConfigToGfxFormat(aDevice->config()); | |
+ | |
+ SkAutoTUnref<SkCanvas> canvas(new SkCanvas(aDevice)); | |
+ mCanvas = canvas.get(); | |
+ | |
+ if (aDevice->getDeviceCapabilities() && SkDevice::kGL_Capability) { | |
+ AddGLDrawTarget(this); | |
+ } | |
+} | |
+ | |
+void | |
DrawTargetSkia::SetCacheLimits(int aCount, int aSizeInBytes) | |
{ | |
MOZ_ASSERT(mGrContext, "No GrContext!"); | |
@@ -746,15 +783,12 @@ DrawTargetSkia::Init(unsigned char* aData, const IntSize &aSize, int32_t aStride | |
isOpaque = true; | |
} | |
- SkAutoTUnref<SkDevice> device(new SkDevice(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, isOpaque)); | |
- | |
- SkBitmap bitmap = (SkBitmap)device->accessBitmap(true); | |
- bitmap.lockPixels(); | |
- bitmap.setPixels(aData); | |
+ SkBitmap bitmap; | |
bitmap.setConfig(GfxFormatToSkiaConfig(aFormat), aSize.width, aSize.height, aStride); | |
- bitmap.unlockPixels(); | |
- bitmap.notifyPixelsChanged(); | |
+ bitmap.setPixels(aData); | |
+ bitmap.setIsOpaque(isOpaque); | |
+ SkAutoTUnref<SkDevice> device(new SkDevice(bitmap)); | |
SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get())); | |
mSize = aSize; | |
@@ -840,11 +874,39 @@ DrawTargetSkia::MarkChanged() | |
} | |
} | |
+// Return a rect (in user space) that covers the entire surface by applying | |
+// the inverse of GetTransform() to (0, 0, mSize.width, mSize.height). | |
+SkRect | |
+DrawTargetSkia::SkRectCoveringWholeSurface() const | |
+{ | |
+ return RectToSkRect(mTransform.TransformBounds(Rect(0, 0, mSize.width, mSize.height))); | |
+} | |
+ | |
void | |
DrawTargetSkia::SnapshotDestroyed() | |
{ | |
mSnapshot = nullptr; | |
} | |
+void * | |
+DrawTargetSkia::GetNativeSurface(NativeSurfaceType aType) | |
+{ | |
+ if (aType == NATIVE_SURFACE_SKIA_SKCANVAS) { | |
+ return mCanvas.get(); | |
+ } | |
+ | |
+#ifdef USE_SKIA_GPU | |
+ if (aType == NATIVE_SURFACE_SKIA_GRCONTEXT) { | |
+ return mGrContext.get(); | |
+ } | |
+ | |
+ if (aType == NATIVE_SURFACE_SKIA_GL_TEXTURE) { | |
+ return reinterpret_cast<void*>(mGrTextureID); | |
+ } | |
+#endif | |
+ | |
+ return nullptr; | |
+} | |
+ | |
} | |
} | |
diff --git a/gfx/2d/DrawTargetSkia.h b/gfx/2d/DrawTargetSkia.h | |
index 4e90f7a..5668c71 100644 | |
--- a/gfx/2d/DrawTargetSkia.h | |
+++ b/gfx/2d/DrawTargetSkia.h | |
@@ -78,7 +78,7 @@ public: | |
virtual void MaskSurface(const Pattern &aSource, | |
SourceSurface *aMask, | |
Point aOffset, | |
- const DrawOptions &aOptions = DrawOptions()) { MOZ_ASSERT(0); }; | |
+ const DrawOptions &aOptions = DrawOptions()); | |
virtual void PushClip(const Path *aPath); | |
virtual void PushClipRect(const Rect& aRect); | |
virtual void PopClip(); | |
@@ -98,12 +98,15 @@ public: | |
bool Init(const IntSize &aSize, SurfaceFormat aFormat); | |
void Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat); | |
+ virtual void *GetNativeSurface(NativeSurfaceType aType) MOZ_OVERRIDE; | |
+ | |
#ifdef USE_SKIA_GPU | |
virtual GenericRefCountedBase* GetGLContext() const MOZ_OVERRIDE { return mGLContext; } | |
void InitWithGLContextAndGrGLInterface(GenericRefCountedBase* aGLContext, | |
GrGLInterface* aGrGLInterface, | |
const IntSize &aSize, | |
SurfaceFormat aFormat) MOZ_OVERRIDE; | |
+ void InitWithSkDevice(SkDevice *aDevice) MOZ_OVERRIDE; | |
void SetCacheLimits(int aCount, int aSizeInBytes); | |
static void SetGlobalCacheLimits(int aCount, int aSizeInBytes); | |
@@ -121,6 +124,7 @@ private: | |
void SnapshotDestroyed(); | |
void MarkChanged(); | |
+ SkRect SkRectCoveringWholeSurface() const; | |
#ifdef USE_SKIA_GPU | |
/* | |
@@ -132,6 +136,7 @@ private: | |
RefPtr<GenericRefCountedBase> mGLContext; | |
SkRefPtr<GrGLInterface> mGrGLInterface; | |
SkRefPtr<GrContext> mGrContext; | |
+ uint32_t mGrTextureID; | |
static int sTextureCacheCount; | |
static int sTextureCacheSizeInBytes; | |
diff --git a/gfx/2d/Factory.cpp b/gfx/2d/Factory.cpp | |
index 287ab3a..338b766 100644 | |
--- a/gfx/2d/Factory.cpp | |
+++ b/gfx/2d/Factory.cpp | |
@@ -267,8 +267,10 @@ Factory::CreateDrawTargetForData(BackendType aBackend, | |
{ | |
RefPtr<DrawTargetSkia> newTarget; | |
newTarget = new DrawTargetSkia(); | |
+ // Skia's Init here doesn't return anything | |
newTarget->Init(aData, aSize, aStride, aFormat); | |
retVal = newTarget; | |
+ break; | |
} | |
#endif | |
#ifdef XP_MACOSX | |
@@ -276,7 +278,7 @@ Factory::CreateDrawTargetForData(BackendType aBackend, | |
{ | |
RefPtr<DrawTargetCG> newTarget = new DrawTargetCG(); | |
if (newTarget->Init(aBackend, aData, aSize, aStride, aFormat)) | |
- return newTarget; | |
+ retVal = newTarget; | |
break; | |
} | |
#endif | |
@@ -290,9 +292,11 @@ Factory::CreateDrawTargetForData(BackendType aBackend, | |
return recordDT; | |
} | |
- gfxDebug() << "Failed to create DrawTarget, Type: " << aBackend << " Size: " << aSize; | |
- // Failed | |
- return nullptr; | |
+ if (!retVal) { | |
+ gfxDebug() << "Failed to create DrawTarget, Type: " << aBackend << " Size: " << aSize; | |
+ } | |
+ | |
+ return retVal; | |
} | |
TemporaryRef<ScaledFont> | |
@@ -514,6 +518,15 @@ Factory::CreateDrawTargetSkiaWithGLContextAndGrGLInterface(GenericRefCountedBase | |
return newTarget; | |
} | |
+TemporaryRef<DrawTarget> | |
+Factory::CreateDrawTargetSkiaForSkDevice(SkDevice *aDevice) | |
+{ | |
+ DrawTargetSkia* newDrawTargetSkia = new DrawTargetSkia(); | |
+ newDrawTargetSkia->InitWithSkDevice(aDevice); | |
+ RefPtr<DrawTarget> newTarget = newDrawTargetSkia; | |
+ return newTarget; | |
+} | |
+ | |
void | |
Factory::SetGlobalSkiaCacheLimits(int aCount, int aSizeInBytes) | |
{ | |
diff --git a/gfx/2d/Types.h b/gfx/2d/Types.h | |
index 89e3dcb..c0a33e1 100644 | |
--- a/gfx/2d/Types.h | |
+++ b/gfx/2d/Types.h | |
@@ -71,7 +71,10 @@ enum NativeSurfaceType | |
NATIVE_SURFACE_CAIRO_SURFACE, | |
NATIVE_SURFACE_CAIRO_CONTEXT, | |
NATIVE_SURFACE_CGCONTEXT, | |
- NATIVE_SURFACE_CGCONTEXT_ACCELERATED | |
+ NATIVE_SURFACE_CGCONTEXT_ACCELERATED, | |
+ NATIVE_SURFACE_SKIA_SKCANVAS, | |
+ NATIVE_SURFACE_SKIA_GRCONTEXT, | |
+ NATIVE_SURFACE_SKIA_GL_TEXTURE | |
}; | |
enum NativeFontType | |
diff --git a/gfx/gl/GLContext.cpp b/gfx/gl/GLContext.cpp | |
index 7708fc0..06707c3 100644 | |
--- a/gfx/gl/GLContext.cpp | |
+++ b/gfx/gl/GLContext.cpp | |
@@ -457,7 +457,11 @@ GLContext::InitWithPrefix(const char *prefix, bool trygl) | |
unsigned int version = 0; | |
bool parseSuccess = ParseGLVersion(this, &version); | |
+#ifdef DEBUG | |
printf_stderr("OpenGL version detected: %u\n", version); | |
+ printf_stderr("OpenGL vendor: %s\n", fGetString(LOCAL_GL_VENDOR)); | |
+ printf_stderr("OpenGL renderer: %s\n", fGetString(LOCAL_GL_RENDERER)); | |
+#endif | |
if (version >= mVersion) { | |
mVersion = version; | |
diff --git a/gfx/gl/GLContext.h b/gfx/gl/GLContext.h | |
index 6d7b2cd..4e8f5ea 100644 | |
--- a/gfx/gl/GLContext.h | |
+++ b/gfx/gl/GLContext.h | |
@@ -2380,11 +2380,15 @@ public: | |
#endif | |
bool MakeCurrent(bool aForce = false) { | |
+ void *p = PR_GetThreadPrivate(sCurrentGLContextTLS); | |
+ if (!aForce && p == this) | |
+ return true; | |
+ | |
#ifdef DEBUG | |
- PR_SetThreadPrivate(sCurrentGLContextTLS, this); | |
+ PR_SetThreadPrivate(sCurrentGLContextTLS, this); | |
- // XXX this assertion is disabled because it's triggering on Mac; | |
- // we need to figure out why and reenable it. | |
+ // XXX this assertion is disabled because it's triggering on Mac; | |
+ // we need to figure out why and reenable it. | |
#if 0 | |
// IsOwningThreadCurrent is a bit of a misnomer; | |
// the "owning thread" is the creation thread, | |
diff --git a/gfx/gl/GLContextProviderWGL.cpp b/gfx/gl/GLContextProviderWGL.cpp | |
index f293c28..e6fe994 100644 | |
--- a/gfx/gl/GLContextProviderWGL.cpp | |
+++ b/gfx/gl/GLContextProviderWGL.cpp | |
@@ -568,6 +568,8 @@ CreatePBufferOffscreenContext(const gfxIntSize& aSize, | |
HDC pbdc = wgl.fGetPbufferDC(pbuffer); | |
NS_ASSERTION(pbdc, "expected a dc"); | |
+ GLContextWGL *shareContext = GetGlobalContextWGL(); | |
+ | |
HGLRC context; | |
if (wgl.HasRobustness()) { | |
int attribs[] = { | |
@@ -576,9 +578,16 @@ CreatePBufferOffscreenContext(const gfxIntSize& aSize, | |
0 | |
}; | |
- context = wgl.fCreateContextAttribs(pbdc, nullptr, attribs); | |
+ context = wgl.fCreateContextAttribs(pbdc, | |
+ shareContext ? shareContext->Context() : nullptr, | |
+ attribs); | |
} else { | |
context = wgl.fCreateContext(pbdc); | |
+ if (context && shareContext && | |
+ !sWGLLib[aLibToUse].fShareLists(shareContext->Context(), context)) | |
+ { | |
+ NS_WARNING("wglShareLists failed for pbuffer!"); | |
+ } | |
} | |
if (!context) { | |
@@ -588,7 +597,7 @@ CreatePBufferOffscreenContext(const gfxIntSize& aSize, | |
SurfaceCaps dummyCaps = SurfaceCaps::Any(); | |
nsRefPtr<GLContextWGL> glContext = new GLContextWGL(dummyCaps, | |
- nullptr, true, | |
+ shareContext, true, | |
pbuffer, | |
pbdc, | |
context, | |
diff --git a/gfx/gl/GLContextSkia.cpp b/gfx/gl/GLContextSkia.cpp | |
index 5cc4480..9162bf2 100644 | |
--- a/gfx/gl/GLContextSkia.cpp | |
+++ b/gfx/gl/GLContextSkia.cpp | |
@@ -3,7 +3,10 @@ | |
* License, v. 2.0. If a copy of the MPL was not distributed with this | |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
+#include "prenv.h" | |
+ | |
#include "skia/GrGLInterface.h" | |
+#include "skia/GrContext.h" | |
#include "mozilla/gfx/2D.h" | |
#include "mozilla/ThreadLocal.h" | |
#include "mozilla/DebugOnly.h" | |
@@ -16,6 +19,11 @@ | |
#endif | |
#include "GLContext.h" | |
+#include "GLContextProvider.h" | |
+#include "GLContextSkia.h" | |
+ | |
+using namespace mozilla::gl; | |
+using namespace mozilla::gfx; | |
using mozilla::gl::GLContext; | |
using mozilla::gfx::DrawTarget; | |
@@ -26,8 +34,20 @@ extern "C" { | |
void EnsureGLContext(const GrGLInterface* i) | |
{ | |
- const DrawTarget* drawTarget = reinterpret_cast<const DrawTarget*>(i->fCallbackData); | |
- GLContext* gl = static_cast<GLContext*>(drawTarget->GetGLContext()); | |
+ // see gfxPlatform.cpp CreateSkiaGLTarget for what this hack is. | |
+ GLContext* gl; | |
+ | |
+ intptr_t rawPtr = static_cast<intptr_t>(i->fCallbackData); | |
+ if ((rawPtr & 0x1) == 1) { | |
+ // it's an actual GLContext, as it always should be -- we should transition | |
+ // to this always | |
+ gl = reinterpret_cast<GLContext*>(rawPtr & ~0x1LL); | |
+ } else { | |
+ // it's a DrawTarget, we can grab the glcontext from that | |
+ const DrawTarget* drawTarget = reinterpret_cast<const DrawTarget*>(i->fCallbackData); | |
+ gl = static_cast<GLContext*>(drawTarget->GetGLContext()); | |
+ } | |
+ | |
gl->MakeCurrent(); | |
if (!sGLContext.initialized()) { | |
@@ -712,7 +732,8 @@ GrGLvoid glGenVertexArrays_mozilla(GrGLsizei n, GrGLuint *arrays) { | |
} // extern "C" | |
-GrGLInterface* CreateGrGLInterfaceFromGLContext(GLContext* context) | |
+GrGLInterface* | |
+GLContextSkiaUtils::CreateGrGLInterfaceFromGLContext(GLContext* context) | |
{ | |
GrGLInterface* i = new GrGLInterface(); | |
i->fCallback = EnsureGLContext; | |
@@ -857,3 +878,64 @@ GrGLInterface* CreateGrGLInterfaceFromGLContext(GLContext* context) | |
return i; | |
} | |
+ | |
+static nsRefPtr<mozilla::gl::GLContext> skiaContentGLContext; | |
+static SkRefPtr<GrGLInterface> skiaContentGrGLInterface; | |
+static SkRefPtr<GrContext> skiaContentGrContext; | |
+ | |
+void | |
+EnsureContentContexts() | |
+{ | |
+ if (skiaContentGLContext) | |
+ return; | |
+ | |
+ static int preferEGL = -1; | |
+ | |
+ // uhh, I really want to know if we have a layerManager here, so that I can | |
+ // get the ISurfaceAllocator from the ShadowForwarder for Gonk | |
+ //nsRefPtr<LayerManager> layerManager = nullptr; | |
+ | |
+ if (preferEGL == -1) { | |
+ preferEGL = PR_GetEnv("MOZ_LAYERS_PREFER_EGL") != nullptr ? 1 : 0; | |
+ } | |
+ | |
+ if (preferEGL) { | |
+ skiaContentGLContext = mozilla::gl::GLContextProviderEGL::CreateOffscreen(gfxIntSize(16, 16), | |
+ SurfaceCaps::ForRGBA()); | |
+ } else { | |
+ skiaContentGLContext = mozilla::gl::GLContextProvider::CreateOffscreen(gfxIntSize(16, 16), | |
+ SurfaceCaps::ForRGBA()); | |
+ } | |
+ | |
+ if (!skiaContentGLContext) | |
+ return; | |
+ | |
+ skiaContentGrGLInterface = GLContextSkiaUtils::CreateGrGLInterfaceFromGLContext(skiaContentGLContext); | |
+ | |
+ intptr_t p = reinterpret_cast<intptr_t>(skiaContentGLContext.get()); | |
+ p |= 1; // XXX HACK ! we need a flag. tagged pointers are back in vogue. | |
+ skiaContentGrGLInterface->fCallbackData = (GrGLInterfaceCallbackData) p; | |
+ skiaContentGrContext = GrContext::Create | |
+ (kOpenGL_GrBackend, reinterpret_cast<GrBackendContext>(skiaContentGrGLInterface.get())); | |
+} | |
+ | |
+GrContext* | |
+GLContextSkiaUtils::GetSkiaContentGrContext() | |
+{ | |
+ EnsureContentContexts(); | |
+ return skiaContentGrContext.get(); | |
+} | |
+ | |
+GLContext* | |
+GLContextSkiaUtils::GetSkiaContentGLContext() | |
+{ | |
+ EnsureContentContexts(); | |
+ return skiaContentGLContext.get(); | |
+} | |
+ | |
+GrGLInterface* | |
+GLContextSkiaUtils::GetSkiaContentGrGLInterface() | |
+{ | |
+ EnsureContentContexts(); | |
+ return skiaContentGrGLInterface.get(); | |
+} | |
diff --git a/gfx/gl/GLContextSkia.h b/gfx/gl/GLContextSkia.h | |
index 2f9994e..ede5e22 100644 | |
--- a/gfx/gl/GLContextSkia.h | |
+++ b/gfx/gl/GLContextSkia.h | |
@@ -5,4 +5,20 @@ | |
#include "skia/GrGLInterface.h" | |
-GrGLInterface* CreateGrGLInterfaceFromGLContext(mozilla::gl::GLContext* context); | |
+namespace mozilla { | |
+namespace gl { | |
+ | |
+class GLContextSkiaUtils { | |
+public: | |
+ static GrGLInterface* CreateGrGLInterfaceFromGLContext(mozilla::gl::GLContext* context); | |
+ | |
+ static GrContext* GetSkiaContentGrContext(); | |
+ static GLContext* GetSkiaContentGLContext(); | |
+ static GrGLInterface* GetSkiaContentGrGLInterface(); | |
+private: | |
+ // not constructable | |
+ GLContextSkiaUtils(); | |
+}; | |
+ | |
+} | |
+} | |
diff --git a/gfx/layers/client/CompositableClient.cpp b/gfx/layers/client/CompositableClient.cpp | |
index d580a3a..7c47d41 100644 | |
--- a/gfx/layers/client/CompositableClient.cpp | |
+++ b/gfx/layers/client/CompositableClient.cpp | |
@@ -155,6 +155,10 @@ CompositableClient::CreateDeprecatedTextureClient(DeprecatedTextureClientType aD | |
break; | |
} | |
#endif | |
+ if (parentBackend == LAYERS_OPENGL && gfxPlatform::GetPlatform()->UseAcceleratedSkiaContent()) { | |
+ result = new DeprecatedTextureClientSkiaGLTexture(GetForwarder(), GetTextureInfo()); | |
+ break; | |
+ } | |
// fall through to TEXTURE_SHMEM | |
case TEXTURE_SHMEM: | |
result = new DeprecatedTextureClientShmem(GetForwarder(), GetTextureInfo()); | |
diff --git a/gfx/layers/client/TextureClient.cpp b/gfx/layers/client/TextureClient.cpp | |
index 0759b85..983ee4b 100644 | |
--- a/gfx/layers/client/TextureClient.cpp | |
+++ b/gfx/layers/client/TextureClient.cpp | |
@@ -519,6 +519,8 @@ DeprecatedTextureClientShmem::Unlock() | |
gfxImageSurface* | |
DeprecatedTextureClientShmem::LockImageSurface() | |
{ | |
+ return nullptr; | |
+ | |
if (!mSurfaceAsImage) { | |
gfxASurface* surface = GetSurface(); | |
if (!surface) { | |
diff --git a/gfx/layers/client/TextureClient.h b/gfx/layers/client/TextureClient.h | |
index 8811d50..696d7b3 100644 | |
--- a/gfx/layers/client/TextureClient.h | |
+++ b/gfx/layers/client/TextureClient.h | |
@@ -514,11 +514,15 @@ public: | |
return aType == TEXTURE_SHMEM || aType == TEXTURE_CONTENT || aType == TEXTURE_FALLBACK; | |
} | |
virtual gfxImageSurface* LockImageSurface() MOZ_OVERRIDE; | |
- virtual gfxASurface* LockSurface() MOZ_OVERRIDE { return GetSurface(); } | |
+ virtual gfxASurface* LockSurface() MOZ_OVERRIDE { return nullptr; } | |
virtual gfx::DrawTarget* LockDrawTarget(); | |
virtual gfx::BackendType BackendType() MOZ_OVERRIDE | |
{ | |
+#if 0 | |
return gfx::BACKEND_CAIRO; | |
+#else | |
+ return gfx::BACKEND_SKIA; | |
+#endif | |
} | |
virtual void Unlock() MOZ_OVERRIDE; | |
virtual bool EnsureAllocated(gfx::IntSize aSize, gfxContentType aType) MOZ_OVERRIDE; | |
diff --git a/gfx/layers/ipc/LayersSurfaces.ipdlh b/gfx/layers/ipc/LayersSurfaces.ipdlh | |
index 46679b7..0f39f9e 100644 | |
--- a/gfx/layers/ipc/LayersSurfaces.ipdlh | |
+++ b/gfx/layers/ipc/LayersSurfaces.ipdlh | |
@@ -51,6 +51,15 @@ struct SurfaceDescriptorD3D10 { | |
bool hasAlpha; | |
}; | |
+// A direct GL texture from the global share | |
+// pool, for where we have GL context sharing | |
+struct SurfaceDescriptorSharedGLTexture { | |
+ uint32_t texture; | |
+ uint32_t format; // gfx::SurfaceFormat | |
+ nsIntSize size; | |
+ bool flipped; // y-flip? | |
+}; | |
+ | |
struct SharedTextureDescriptor { | |
SharedTextureShareType shareType; | |
SharedTextureHandle handle; | |
@@ -182,6 +191,7 @@ union SurfaceDescriptor { | |
Shmem; // XXX - deprecated | |
RGBImage; // XXX - deprecated | |
MemoryImage; // XXX - deprecated | |
+ SurfaceDescriptorSharedGLTexture; | |
null_t; | |
}; | |
diff --git a/gfx/layers/ipc/ShadowLayerUtilsD3D10.cpp b/gfx/layers/ipc/ShadowLayerUtilsD3D10.cpp | |
index 88f73d4..3c1b965 100644 | |
--- a/gfx/layers/ipc/ShadowLayerUtilsD3D10.cpp | |
+++ b/gfx/layers/ipc/ShadowLayerUtilsD3D10.cpp | |
@@ -72,7 +72,7 @@ ShadowLayerForwarder::PlatformGetDescriptorSurfaceImageFormat( | |
} | |
bool | |
-ShadowLayerForwarder::PlatformDestroySharedSurface(SurfaceDescriptor*) | |
+ShadowLayerForwarder::PlatformDestroySharedSurface(SurfaceDescriptor *) | |
{ | |
return false; | |
} | |
@@ -83,8 +83,13 @@ ShadowLayerForwarder::PlatformSyncBeforeUpdate() | |
} | |
bool | |
-ISurfaceAllocator::PlatformDestroySharedSurface(SurfaceDescriptor*) | |
+ISurfaceAllocator::PlatformDestroySharedSurface(SurfaceDescriptor *aDesc) | |
{ | |
+ if (aDesc->type() == SurfaceDescriptor::TSurfaceDescriptorSharedGLTexture) { | |
+ // nothing to do | |
+ return true; | |
+ } | |
+ | |
return false; | |
} | |
diff --git a/gfx/layers/opengl/CompositorOGL.cpp b/gfx/layers/opengl/CompositorOGL.cpp | |
index 55f3f13..5816e6e 100644 | |
--- a/gfx/layers/opengl/CompositorOGL.cpp | |
+++ b/gfx/layers/opengl/CompositorOGL.cpp | |
@@ -189,6 +189,8 @@ FPSState::DrawFPS(TimeStamp aNow, | |
} | |
aContext->fTexImage2D(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA, 64, 8, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, buf); | |
free(buf); | |
+ | |
+ printf_stderr("FPS TEXTURE %d\n", mTexture); | |
} | |
mVBOs.Reset(); | |
diff --git a/gfx/layers/opengl/TextureClientOGL.cpp b/gfx/layers/opengl/TextureClientOGL.cpp | |
index b7c63d6..e25b491 100644 | |
--- a/gfx/layers/opengl/TextureClientOGL.cpp | |
+++ b/gfx/layers/opengl/TextureClientOGL.cpp | |
@@ -8,6 +8,11 @@ | |
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc | |
#include "mozilla/layers/ISurfaceAllocator.h" | |
#include "nsSize.h" // for nsIntSize | |
+#include "gfxPlatform.h" | |
+ | |
+#include "skia/SkGpuDevice.h" | |
+#include "GLContextSkia.h" | |
+#include "mozilla/gfx/2D.h" | |
using namespace mozilla::gl; | |
@@ -96,5 +101,78 @@ DeprecatedTextureClientSharedOGL::EnsureAllocated(gfx::IntSize aSize, | |
} | |
+DeprecatedTextureClientSkiaGLTexture::DeprecatedTextureClientSkiaGLTexture(CompositableForwarder* aForwarder, | |
+ const TextureInfo& aTextureInfo) | |
+ : DeprecatedTextureClient(aForwarder, aTextureInfo) | |
+{ | |
+} | |
+ | |
+void | |
+DeprecatedTextureClientSkiaGLTexture::ReleaseResources() | |
+{ | |
+ if (IsSurfaceDescriptorValid(mDescriptor)) { | |
+ MOZ_ASSERT(mDescriptor.type() == SurfaceDescriptor::TSurfaceDescriptorSharedGLTexture); | |
+ mDescriptor = SurfaceDescriptor(); | |
+ } | |
+ | |
+ mDrawTarget = nullptr; | |
+ mSize.SizeTo(0, 0); | |
+} | |
+ | |
+bool | |
+DeprecatedTextureClientSkiaGLTexture::EnsureAllocated(gfx::IntSize aSize, | |
+ gfxContentType aContentType) | |
+{ | |
+ if (mSize == aSize && mContentType == aContentType) { | |
+ return true; | |
+ } | |
+ | |
+ mFormat = aContentType == GFX_CONTENT_COLOR_ALPHA ? gfx::FORMAT_R8G8B8A8 : gfx::FORMAT_R8G8B8X8; | |
+ mSize = aSize; | |
+ mContentType = aContentType; | |
+ | |
+ GrTextureDesc desc; | |
+ desc.fFlags = kRenderTarget_GrTextureFlagBit; | |
+ desc.fWidth = aSize.width; | |
+ desc.fHeight = aSize.height; | |
+ desc.fConfig = kSkia8888_GrPixelConfig; | |
+ desc.fSampleCnt = 0; // XXX more? | |
+ | |
+ GrContext *grc = GLContextSkiaUtils::GetSkiaContentGrContext(); | |
+ | |
+ SkAutoTUnref<GrTexture> sktex(grc->createUncachedTexture(desc, NULL, 0)); | |
+ if (!sktex) { | |
+ return false; | |
+ } | |
+ mSkiaTexture = sktex; | |
+ | |
+ SkAutoTUnref<SkGpuDevice> dev(SkGpuDevice::Create(sktex->asRenderTarget())); | |
+ | |
+ mDrawTarget = mozilla::gfx::Factory::CreateDrawTargetSkiaForSkDevice(dev); | |
+ | |
+ //uint32_t tex = (uint32_t) mDrawTarget->GetNativeSurface(gfx::NATIVE_SURFACE_SKIA_GL_TEXTURE); | |
+ uint32_t tex = (uint32_t) sktex->getTextureHandle(); | |
+ | |
+ if (tex == 0) { | |
+ printf_stderr("Failed to get NATIVE_SURFACE_SKIA_GL_TEXTURE from DT!"); | |
+ return false; | |
+ } | |
+ | |
+ printf_stderr("DrawTargetSkiaGL texture client, GrTextureID: %d\n", tex); | |
+ | |
+ mDescriptor = SurfaceDescriptorSharedGLTexture(tex, mFormat, | |
+ nsIntSize(mSize.width, mSize.height), | |
+ true); | |
+ | |
+ return true; | |
+} | |
+ | |
+void | |
+DeprecatedTextureClientSkiaGLTexture::Unlock() | |
+{ | |
+ mDrawTarget->Flush(); | |
+ GLContextSkiaUtils::GetSkiaContentGLContext()->fFinish(); | |
+} | |
+ | |
} // namespace | |
} // namespace | |
diff --git a/gfx/layers/opengl/TextureClientOGL.h b/gfx/layers/opengl/TextureClientOGL.h | |
index f60729f..f70cd26 100644 | |
--- a/gfx/layers/opengl/TextureClientOGL.h | |
+++ b/gfx/layers/opengl/TextureClientOGL.h | |
@@ -14,6 +14,12 @@ | |
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor | |
#include "mozilla/layers/TextureClient.h" // for DeprecatedTextureClient, etc | |
+#ifdef USE_SKIA | |
+#include "skia/SkGraphics.h" | |
+#include "skia/GrContext.h" | |
+#include "skia/GrTexture.h" | |
+#endif | |
+ | |
namespace mozilla { | |
namespace layers { | |
@@ -76,6 +82,34 @@ protected: | |
friend class CompositingFactory; | |
}; | |
+class DeprecatedTextureClientSkiaGLTexture : public DeprecatedTextureClient | |
+{ | |
+public: | |
+ DeprecatedTextureClientSkiaGLTexture(CompositableForwarder* aForwarder, const TextureInfo& aTextureInfo); | |
+ ~DeprecatedTextureClientSkiaGLTexture() { ReleaseResources(); } | |
+ | |
+ virtual bool SupportsType(DeprecatedTextureClientType aType) MOZ_OVERRIDE { return aType == TEXTURE_CONTENT; } | |
+ virtual bool EnsureAllocated(gfx::IntSize aSize, gfxContentType aType); | |
+ virtual void ReleaseResources(); | |
+ virtual gfxContentType GetContentType() MOZ_OVERRIDE { return mContentType; } | |
+ | |
+ virtual gfx::DrawTarget* LockDrawTarget() MOZ_OVERRIDE { return mDrawTarget.get(); } | |
+ virtual gfx::BackendType BackendType() MOZ_OVERRIDE { return gfx::BACKEND_SKIA; } | |
+ virtual void Unlock() MOZ_OVERRIDE; | |
+ | |
+protected: | |
+ gfx::IntSize mSize; | |
+ gfxContentType mContentType; | |
+ gfx::SurfaceFormat mFormat; | |
+ | |
+ RefPtr<gfx::DrawTarget> mDrawTarget; | |
+ | |
+ SkRefPtr<GrTexture> mSkiaTexture; | |
+ | |
+ friend class CompositingFactory; | |
+}; | |
+ | |
+ | |
// Doesn't own the surface descriptor, so we shouldn't delete it | |
class DeprecatedTextureClientSharedOGLExternal : public DeprecatedTextureClientSharedOGL | |
{ | |
diff --git a/gfx/layers/opengl/TextureHostOGL.cpp b/gfx/layers/opengl/TextureHostOGL.cpp | |
index 0d65282c..4383976 100644 | |
--- a/gfx/layers/opengl/TextureHostOGL.cpp | |
+++ b/gfx/layers/opengl/TextureHostOGL.cpp | |
@@ -68,6 +68,8 @@ CreateDeprecatedTextureHostOGL(SurfaceDescriptorType aDescriptorType, | |
} else if (aDescriptorType == SurfaceDescriptor::TSurfaceDescriptorGralloc) { | |
result = new GrallocDeprecatedTextureHostOGL(); | |
#endif | |
+ } else if (aDescriptorType == SurfaceDescriptor::TSurfaceDescriptorSharedGLTexture) { | |
+ result = new DeprecatedTextureHostOGLTexture(); | |
} else if (aDeprecatedTextureHostFlags & TEXTURE_HOST_TILED) { | |
result = new TiledDeprecatedTextureHostOGL(); | |
} else { | |
@@ -1351,5 +1353,59 @@ GrallocDeprecatedTextureHostOGL::GetAsSurface() { | |
} | |
#endif // MOZ_WIDGET_GONK | |
+void | |
+DeprecatedTextureHostOGLTexture::SetCompositor(Compositor* aCompositor) | |
+{ | |
+ CompositorOGL* glCompositor = static_cast<CompositorOGL*>(aCompositor); | |
+ mGL = glCompositor ? glCompositor->gl() : nullptr; | |
+} | |
+ | |
+void | |
+DeprecatedTextureHostOGLTexture::UpdateImpl(const SurfaceDescriptor& aImage, | |
+ nsIntRegion* aRegion, | |
+ nsIntPoint* aOffset) | |
+{ | |
+ SwapTexturesImpl(aImage, aRegion); | |
+} | |
+ | |
+void | |
+DeprecatedTextureHostOGLTexture::SwapTexturesImpl(const SurfaceDescriptor& aImage, | |
+ nsIntRegion* aRegion) | |
+{ | |
+ NS_ASSERTION(aImage.type() == SurfaceDescriptor::TSurfaceDescriptorSharedGLTexture, | |
+ "Invalid descriptor"); | |
+ | |
+ SurfaceDescriptorSharedGLTexture desc = aImage.get_SurfaceDescriptorSharedGLTexture(); | |
+ | |
+ nsIntSize size = desc.size(); | |
+ mSize = gfx::IntSize(size.width, size.height); | |
+ if (desc.flipped()) { | |
+ mFlags |= TEXTURE_NEEDS_Y_FLIP; | |
+ } | |
+ | |
+ mFormat = (gfx::SurfaceFormat) desc.format(); | |
+ mTextureHandle = desc.texture(); | |
+} | |
+ | |
+void | |
+DeprecatedTextureHostOGLTexture::BindTexture(GLenum aTextureUnit) | |
+{ | |
+ mGL->fActiveTexture(aTextureUnit); | |
+ mGL->fBindTexture(GetTextureTarget(), mTextureHandle); | |
+} | |
+ | |
+gfx3DMatrix | |
+DeprecatedTextureHostOGLTexture::GetTextureTransform() | |
+{ | |
+ gfx3DMatrix m; | |
+ if (mFlags & TEXTURE_NEEDS_Y_FLIP) | |
+ { | |
+ m.Translate(gfxPoint3D(0.0f, 1.0f, 0.0f)); | |
+ m.Scale(1.0f, -1.0f, 1.0f); | |
+ } | |
+ | |
+ return m; | |
+} | |
+ | |
} // namespace | |
} // namespace | |
diff --git a/gfx/layers/opengl/TextureHostOGL.h b/gfx/layers/opengl/TextureHostOGL.h | |
index 1b327d7..ae665e1 100644 | |
--- a/gfx/layers/opengl/TextureHostOGL.h | |
+++ b/gfx/layers/opengl/TextureHostOGL.h | |
@@ -689,6 +689,89 @@ protected: | |
gl::SharedTextureShareType mShareType; | |
}; | |
+class DeprecatedTextureHostOGLTexture : public DeprecatedTextureHost | |
+ , public TextureSourceOGL | |
+{ | |
+public: | |
+ typedef gfxContentType ContentType; | |
+ typedef mozilla::gl::GLContext GLContext; | |
+ typedef mozilla::gl::TextureImage TextureImage; | |
+ | |
+ DeprecatedTextureHostOGLTexture() | |
+ : mGL(nullptr) | |
+ , mTextureHandle(0) | |
+ , mWrapMode(LOCAL_GL_CLAMP_TO_EDGE) | |
+ {} | |
+ | |
+ virtual void SetCompositor(Compositor* aCompositor) MOZ_OVERRIDE; | |
+ | |
+ virtual ~DeprecatedTextureHostOGLTexture() | |
+ { | |
+ } | |
+ | |
+ virtual GLuint GetTextureHandle() | |
+ { | |
+ return mTextureHandle; | |
+ } | |
+ | |
+ virtual gfx::SurfaceFormat GetFormat() const MOZ_OVERRIDE | |
+ { | |
+ return DeprecatedTextureHost::GetFormat(); | |
+ } | |
+ | |
+ virtual TextureSourceOGL* AsSourceOGL() MOZ_OVERRIDE { return this; } | |
+ | |
+ bool IsValid() const MOZ_OVERRIDE { return !!mTextureHandle; } | |
+ | |
+ // override from DeprecatedTextureHost, we support both buffered | |
+ // and unbuffered operation. | |
+ virtual void UpdateImpl(const SurfaceDescriptor& aImage, | |
+ nsIntRegion* aRegion = nullptr, | |
+ nsIntPoint* aOffset = nullptr) MOZ_OVERRIDE; | |
+ virtual void SwapTexturesImpl(const SurfaceDescriptor& aImage, | |
+ nsIntRegion* aRegion = nullptr) MOZ_OVERRIDE; | |
+ | |
+ virtual GLenum GetWrapMode() const MOZ_OVERRIDE { return mWrapMode; } | |
+ virtual void SetWrapMode(GLenum aMode) { mWrapMode = aMode; } | |
+ | |
+ virtual GLenum GetTextureTarget() const MOZ_OVERRIDE | |
+ { | |
+ return LOCAL_GL_TEXTURE_2D; | |
+ } | |
+ | |
+ gfx::IntSize GetSize() const MOZ_OVERRIDE { | |
+ return mSize; | |
+ } | |
+ | |
+ void BindTexture(GLenum activetex) MOZ_OVERRIDE; | |
+ void UnbindTexture() MOZ_OVERRIDE {} | |
+ | |
+ GLuint GetTextureID() { return mTextureHandle; } | |
+ ContentType GetContentType() | |
+ { | |
+ return (mFormat == gfx::FORMAT_B8G8R8A8) ? | |
+ GFX_CONTENT_COLOR_ALPHA : | |
+ GFX_CONTENT_COLOR; | |
+ } | |
+ | |
+ virtual gfx3DMatrix GetTextureTransform() MOZ_OVERRIDE; | |
+ | |
+ virtual already_AddRefed<gfxImageSurface> GetAsSurface() MOZ_OVERRIDE | |
+ { | |
+ return nullptr; | |
+ } | |
+ | |
+#ifdef MOZ_LAYERS_HAVE_LOG | |
+ virtual const char* Name() { return "DeprecatedTextureHostOGLTexture"; } | |
+#endif | |
+ | |
+protected: | |
+ nsRefPtr<gl::GLContext> mGL; | |
+ gfx::IntSize mSize; | |
+ GLuint mTextureHandle; | |
+ GLenum mWrapMode; | |
+}; | |
+ | |
class SurfaceStreamHostOGL : public DeprecatedTextureHost | |
, public TextureSourceOGL | |
{ | |
diff --git a/gfx/skia/src/gpu/gl/GrGLShaderBuilder.cpp b/gfx/skia/src/gpu/gl/GrGLShaderBuilder.cpp | |
index f7ecf36..a12bbb6 100644 | |
--- a/gfx/skia/src/gpu/gl/GrGLShaderBuilder.cpp | |
+++ b/gfx/skia/src/gpu/gl/GrGLShaderBuilder.cpp | |
@@ -83,6 +83,8 @@ void append_swizzle(SkString* outAppend, | |
if (memcmp(swizzle, "rgba", 4)) { | |
outAppend->appendf(".%s", swizzle); | |
} | |
+ | |
+ //outAppend->appendf(".rbga"); | |
} | |
} | |
diff --git a/gfx/thebes/gfxPlatform.cpp b/gfx/thebes/gfxPlatform.cpp | |
index 3656df9..938a393 100644 | |
--- a/gfx/thebes/gfxPlatform.cpp | |
+++ b/gfx/thebes/gfxPlatform.cpp | |
@@ -56,6 +56,7 @@ | |
#include "nsCRT.h" | |
#include "GLContext.h" | |
#include "GLContextProvider.h" | |
+#include "GLContextSkia.h" | |
#ifdef MOZ_WIDGET_ANDROID | |
#include "TexturePoolOGL.h" | |
@@ -64,6 +65,7 @@ | |
#ifdef USE_SKIA | |
#include "mozilla/Hal.h" | |
#include "skia/SkGraphics.h" | |
+#include "skia/GrContext.h" | |
#endif | |
#include "mozilla/Preferences.h" | |
@@ -101,6 +103,8 @@ static bool sDrawFrameCounter = false; | |
#include "mozilla/gfx/2D.h" | |
using namespace mozilla::gfx; | |
+using mozilla::gl::GLContextSkiaUtils; | |
+ | |
// logs shared across gfx | |
#ifdef PR_LOGGING | |
static PRLogModuleInfo *sFontlistLog = nullptr; | |
@@ -583,7 +587,31 @@ cairo_user_data_key_t kDrawTarget; | |
RefPtr<DrawTarget> | |
gfxPlatform::CreateDrawTargetForSurface(gfxASurface *aSurface, const IntSize& aSize) | |
{ | |
- RefPtr<DrawTarget> drawTarget = Factory::CreateDrawTargetForCairoSurface(aSurface->CairoSurface(), aSize); | |
+ RefPtr<DrawTarget> drawTarget; | |
+ if (aSurface->GetType() == gfxSurfaceTypeImage) { | |
+ // go skia! | |
+ gfxImageSurface *is = (gfxImageSurface*) aSurface; | |
+ SurfaceFormat format; | |
+ switch (is->Format()) { | |
+ case gfxImageFormatARGB32: format = FORMAT_B8G8R8A8; break; | |
+ case gfxImageFormatRGB24: format = FORMAT_B8G8R8X8; break; | |
+ case gfxImageFormatA8: format = FORMAT_A8; break; | |
+ case gfxImageFormatRGB16_565: format = FORMAT_R5G6B5; break; | |
+ default: format = FORMAT_UNKNOWN; | |
+ } | |
+ | |
+ if (format != FORMAT_UNKNOWN) { | |
+ drawTarget = Factory::CreateDrawTargetForData(BACKEND_SKIA, | |
+ is->Data(), | |
+ IntSize(is->Width(), is->Height()), | |
+ is->Stride(), | |
+ format); | |
+ } | |
+ } | |
+ | |
+ if (!drawTarget) { | |
+ drawTarget = Factory::CreateDrawTargetForCairoSurface(aSurface->CairoSurface(), aSize); | |
+ } | |
aSurface->SetData(&kDrawTarget, drawTarget, nullptr); | |
return drawTarget; | |
} | |
@@ -821,13 +849,27 @@ gfxPlatform::SupportsAzureContentForDrawTarget(DrawTarget* aTarget) | |
bool | |
gfxPlatform::UseAcceleratedSkiaCanvas() | |
{ | |
- return Preferences::GetBool("gfx.canvas.azure.accelerated", false) && | |
- mPreferredCanvasBackend == BACKEND_SKIA; | |
+ static int acceleratedAzure = -1; | |
+ if (acceleratedAzure == -1) { | |
+ acceleratedAzure = Preferences::GetBool("gfx.canvas.azure.accelerated", false) ? 1 : 0; | |
+ } | |
+ return acceleratedAzure && mPreferredCanvasBackend == BACKEND_SKIA; | |
+} | |
+ | |
+bool | |
+gfxPlatform::UseAcceleratedSkiaContent() | |
+{ | |
+ static int acceleratedContent = -1; | |
+ if (acceleratedContent == -1) { | |
+ acceleratedContent = Preferences::GetBool("gfx.content.skia.accelerated", false) ? 1 : 0; | |
+ } | |
+ return acceleratedContent && mContentBackend == BACKEND_SKIA; | |
} | |
void | |
gfxPlatform::InitializeSkiaCaches() | |
{ | |
+ // XX This will need reworking for content separate from canvas | |
#ifdef USE_SKIA_GPU | |
if (UseAcceleratedSkiaCanvas()) { | |
bool usingDynamicCache = Preferences::GetBool("gfx.canvas.skiagl.dynamic-cache", false); | |
@@ -916,9 +958,9 @@ gfxPlatform::CreateDrawTargetForBackend(BackendType aBackend, const IntSize& aSi | |
} | |
return CreateDrawTargetForSurface(surf, aSize); | |
- } else { | |
- return Factory::CreateDrawTarget(aBackend, aSize, aFormat); | |
} | |
+ | |
+ return Factory::CreateDrawTarget(aBackend, aSize, aFormat); | |
} | |
RefPtr<DrawTarget> | |
diff --git a/gfx/thebes/gfxPlatform.h b/gfx/thebes/gfxPlatform.h | |
index 9d7b8f1..de3e765 100644 | |
--- a/gfx/thebes/gfxPlatform.h | |
+++ b/gfx/thebes/gfxPlatform.h | |
@@ -40,6 +40,7 @@ class nsIURI; | |
class nsIAtom; | |
class nsIObserver; | |
struct gfxRGBA; | |
+class GrContext; | |
namespace mozilla { | |
namespace gl { | |
@@ -278,11 +279,14 @@ public: | |
virtual bool UseAcceleratedSkiaCanvas(); | |
+ virtual bool UseAcceleratedSkiaContent(); | |
+ | |
virtual void InitializeSkiaCaches(); | |
void GetAzureBackendInfo(mozilla::widget::InfoObject &aObj) { | |
aObj.DefineProperty("AzureCanvasBackend", GetBackendName(mPreferredCanvasBackend)); | |
- aObj.DefineProperty("AzureSkiaAccelerated", UseAcceleratedSkiaCanvas()); | |
+ aObj.DefineProperty("AzureSkiaCanvasAccelerated", UseAcceleratedSkiaCanvas()); | |
+ aObj.DefineProperty("AzureSkiaContentAccelerated", UseAcceleratedSkiaContent()); | |
aObj.DefineProperty("AzureFallbackCanvasBackend", GetBackendName(mFallbackCanvasBackend)); | |
aObj.DefineProperty("AzureContentBackend", GetBackendName(mContentBackend)); | |
} | |
diff --git a/gfx/thebes/gfxWindowsPlatform.cpp b/gfx/thebes/gfxWindowsPlatform.cpp | |
index 5e85d10..3af4fe6 100644 | |
--- a/gfx/thebes/gfxWindowsPlatform.cpp | |
+++ b/gfx/thebes/gfxWindowsPlatform.cpp | |
@@ -513,6 +513,7 @@ gfxWindowsPlatform::UpdateRenderMode() | |
contentMask |= 1 << BACKEND_DIRECT2D; | |
} else { | |
canvasMask |= 1 << BACKEND_SKIA; | |
+ contentMask |= 1 << BACKEND_SKIA; | |
} | |
InitBackendPrefs(canvasMask, contentMask); | |
} | |
@@ -1531,6 +1532,26 @@ gfxWindowsPlatform::IsOptimus() | |
return GetModuleHandleA("nvumdshim.dll"); | |
} | |
+int | |
+gfxWindowsPlatform::GetScreenDepth() const | |
+{ | |
+ // if the system doesn't have all displays with the same | |
+ // pixel format, just return 24 and move on with life. | |
+ if (!GetSystemMetrics(SM_SAMEDISPLAYFORMAT)) | |
+ return 24; | |
+ | |
+ HDC hdc = GetDC(nullptr); | |
+ if (!hdc) | |
+ return 24; | |
+ | |
+ int depth = GetDeviceCaps(hdc, BITSPIXEL) * | |
+ GetDeviceCaps(hdc, PLANES); | |
+ | |
+ ReleaseDC(nullptr, hdc); | |
+ | |
+ return depth; | |
+} | |
+ | |
IDXGIAdapter1* | |
gfxWindowsPlatform::GetDXGIAdapter() | |
{ | |
diff --git a/gfx/thebes/gfxWindowsPlatform.h b/gfx/thebes/gfxWindowsPlatform.h | |
index 9037586..fb27191 100644 | |
--- a/gfx/thebes/gfxWindowsPlatform.h | |
+++ b/gfx/thebes/gfxWindowsPlatform.h | |
@@ -153,6 +153,8 @@ public: | |
RENDER_MODE_MAX | |
}; | |
+ int GetScreenDepth() const; | |
+ | |
RenderMode GetRenderMode() { return mRenderMode; } | |
void SetRenderMode(RenderMode rmode) { mRenderMode = rmode; } | |
diff --git a/layout/tools/reftest/reftest.js b/layout/tools/reftest/reftest.js | |
index 88403fb..c606258 100644 | |
--- a/layout/tools/reftest/reftest.js | |
+++ b/layout/tools/reftest/reftest.js | |
@@ -585,10 +585,14 @@ function BuildConditionSandbox(aURL) { | |
var info = gfxInfo.getInfo(); | |
sandbox.azureQuartz = info.AzureCanvasBackend == "quartz"; | |
sandbox.azureSkia = info.AzureCanvasBackend == "skia"; | |
- sandbox.azureSkiaGL = info.AzureSkiaAccelerated; // FIXME: assumes GL right now | |
- // true if we are using the same Azure backend for rendering canvas and content | |
- sandbox.contentSameGfxBackendAsCanvas = info.AzureContentBackend == info.AzureCanvasBackend | |
- || (info.AzureContentBackend == "none" && info.AzureCanvasBackend == "cairo"); | |
+ sandbox.azureSkiaGL = info.AzureSkiaCanvasAccelerated; | |
+ sandbox.azureSkiaGLContent = info.AzureSkiaContentAccelerated; | |
+ // true if we are using the same Azure backend for rendering canvas and content; | |
+ // if it's skia, check if both are accelerated | |
+ sandbox.contentSameGfxBackendAsCanvas = | |
+ ((info.AzureContentBackend == info.AzureCanvasBackend) && | |
+ (info.AzureContentBackend != "skia" || (info.AzureSkiaContentAccelerated == info.AzureSkiaCanvasAccelerated))) && | |
+ || (info.AzureContentBackend == "none" && info.AzureCanvasBackend == "cairo"); | |
sandbox.layersGPUAccelerated = | |
gWindowUtils.layerManagerType != "Basic"; | |
diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp | |
index 20a3d6e..3d5ee0b 100644 | |
--- a/toolkit/xre/nsAppRunner.cpp | |
+++ b/toolkit/xre/nsAppRunner.cpp | |
@@ -4054,7 +4054,7 @@ XREMain::XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) | |
} else { | |
// We will have a real shutdown, let ShutdownXPCOM poison writes to | |
// find any late ones. | |
- mozilla::EnableWritePoisoning(); | |
+ //mozilla::EnableWritePoisoning(); | |
} | |
if (!mShuttingDown) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment