зеркало из https://github.com/mozilla/gecko-dev.git
Bug 877115 - Remove GetTexImage from GLContext helper. r=nical
This commit is contained in:
Родитель
1231f90835
Коммит
0955c3684b
|
@ -13,6 +13,8 @@
|
|||
#include "mozilla/gfx/2D.h"
|
||||
#include "gfx2DGlue.h"
|
||||
|
||||
using namespace mozilla::gfx;
|
||||
|
||||
namespace mozilla {
|
||||
namespace gl {
|
||||
|
||||
|
@ -204,14 +206,14 @@ GetActualReadFormats(GLContext* gl, GLenum destFormat, GLenum destType,
|
|||
}
|
||||
}
|
||||
|
||||
static void SwapRAndBComponents(gfxImageSurface* surf)
|
||||
static void SwapRAndBComponents(DataSourceSurface* surf)
|
||||
{
|
||||
uint8_t *row = surf->Data();
|
||||
uint8_t *row = surf->GetData();
|
||||
|
||||
size_t rowBytes = surf->Width()*4;
|
||||
size_t rowBytes = surf->GetSize().width*4;
|
||||
size_t rowHole = surf->Stride() - rowBytes;
|
||||
|
||||
size_t rows = surf->Height();
|
||||
size_t rows = surf->GetSize().height;
|
||||
|
||||
while (rows) {
|
||||
|
||||
|
@ -282,19 +284,19 @@ ReadPixelsIntoImageSurface(GLContext* gl, gfxImageSurface* dest) {
|
|||
if (gl->DebugMode()) {
|
||||
NS_WARNING("Needing intermediary surface for ReadPixels. This will be slow!");
|
||||
}
|
||||
gfx::SurfaceFormat readFormatGFX;
|
||||
SurfaceFormat readFormatGFX;
|
||||
|
||||
switch (readFormat) {
|
||||
case LOCAL_GL_RGBA:
|
||||
case LOCAL_GL_BGRA: {
|
||||
readFormatGFX = hasAlpha ? gfx::FORMAT_B8G8R8A8
|
||||
: gfx::FORMAT_B8G8R8X8;
|
||||
readFormatGFX = hasAlpha ? FORMAT_B8G8R8A8
|
||||
: FORMAT_B8G8R8X8;
|
||||
break;
|
||||
}
|
||||
case LOCAL_GL_RGB: {
|
||||
MOZ_ASSERT(readPixelSize == 2);
|
||||
MOZ_ASSERT(readType == LOCAL_GL_UNSIGNED_SHORT_5_6_5_REV);
|
||||
readFormatGFX = gfx::FORMAT_R5G6B5;
|
||||
readFormatGFX = FORMAT_R5G6B5;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
@ -358,7 +360,12 @@ ReadPixelsIntoImageSurface(GLContext* gl, gfxImageSurface* dest) {
|
|||
// So we just copied in RGBA in big endian, or le: 0xAABBGGRR.
|
||||
// We want 0xAARRGGBB, so swap R and B:
|
||||
dest->Flush();
|
||||
SwapRAndBComponents(readSurf);
|
||||
RefPtr<DataSourceSurface> readDSurf =
|
||||
Factory::CreateWrappingDataSourceSurface(readSurf->Data(),
|
||||
readSurf->Stride(),
|
||||
ToIntSize(readSurf->GetSize()),
|
||||
ImageFormatToSurfaceFormat(readSurf->Format()));
|
||||
SwapRAndBComponents(readDSurf);
|
||||
dest->MarkDirty();
|
||||
|
||||
gfxContext ctx(dest);
|
||||
|
@ -397,33 +404,50 @@ ReadPixelsIntoImageSurface(GLContext* gl, gfxImageSurface* dest) {
|
|||
#endif
|
||||
}
|
||||
|
||||
static already_AddRefed<gfxImageSurface> YInvertImageSurface(gfxImageSurface* aSurf)
|
||||
static TemporaryRef<DataSourceSurface> YInvertImageSurface(DataSourceSurface* aSurf)
|
||||
{
|
||||
gfxIntSize size = aSurf->GetSize();
|
||||
nsRefPtr<gfxImageSurface> temp = new gfxImageSurface(size, aSurf->Format());
|
||||
nsRefPtr<gfxContext> ctx = new gfxContext(temp);
|
||||
RefPtr<DataSourceSurface> temp =
|
||||
Factory::CreateDataSourceSurfaceWithStride(aSurf->GetSize(),
|
||||
aSurf->GetFormat(),
|
||||
aSurf->Stride());
|
||||
RefPtr<DrawTarget> dt =
|
||||
Factory::CreateDrawTargetForData(BACKEND_CAIRO,
|
||||
temp->GetData(),
|
||||
temp->GetSize(),
|
||||
temp->Stride(),
|
||||
temp->GetFormat());
|
||||
nsRefPtr<gfxContext> ctx = new gfxContext(dt);
|
||||
ctx->SetOperator(gfxContext::OPERATOR_SOURCE);
|
||||
ctx->Scale(1.0, -1.0);
|
||||
ctx->Translate(-gfxPoint(0.0, size.height));
|
||||
ctx->SetSource(aSurf);
|
||||
ctx->Translate(-gfxPoint(0.0, aSurf->GetSize().height));
|
||||
|
||||
nsRefPtr<gfxImageSurface> thebesSurf =
|
||||
new gfxImageSurface(aSurf->GetData(),
|
||||
ThebesIntSize(aSurf->GetSize()),
|
||||
aSurf->Stride(),
|
||||
SurfaceFormatToImageFormat(aSurf->GetFormat()));
|
||||
ctx->SetSource(thebesSurf);
|
||||
ctx->Paint();
|
||||
return temp.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<gfxImageSurface>
|
||||
GetTexImage(GLContext* gl, GLuint aTexture, bool aYInvert, gfx::SurfaceFormat aFormat)
|
||||
TemporaryRef<DataSourceSurface>
|
||||
ReadBackSurface(GLContext* gl, GLuint aTexture, bool aYInvert, SurfaceFormat aFormat)
|
||||
{
|
||||
gl->MakeCurrent();
|
||||
gl->GuaranteeResolve();
|
||||
gl->fActiveTexture(LOCAL_GL_TEXTURE0);
|
||||
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, aTexture);
|
||||
|
||||
gfxIntSize size;
|
||||
IntSize size;
|
||||
gl->fGetTexLevelParameteriv(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_TEXTURE_WIDTH, &size.width);
|
||||
gl->fGetTexLevelParameteriv(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_TEXTURE_HEIGHT, &size.height);
|
||||
|
||||
nsRefPtr<gfxImageSurface> surf = new gfxImageSurface(size, gfxImageFormatARGB32);
|
||||
if (!surf || surf->CairoStatus()) {
|
||||
RefPtr<DataSourceSurface> surf =
|
||||
Factory::CreateDataSourceSurfaceWithStride(size, FORMAT_B8G8R8A8,
|
||||
GetAlignedStride<4>(size.width * BytesPerPixel(FORMAT_B8G8R8A8)));
|
||||
|
||||
if (!surf) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -432,31 +456,18 @@ GetTexImage(GLContext* gl, GLuint aTexture, bool aYInvert, gfx::SurfaceFormat aF
|
|||
if (currentPackAlignment != 4) {
|
||||
gl->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, 4);
|
||||
}
|
||||
gl->fGetTexImage(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, surf->Data());
|
||||
gl->fGetTexImage(LOCAL_GL_TEXTURE_2D, 0, LOCAL_GL_RGBA, LOCAL_GL_UNSIGNED_BYTE, surf->GetData());
|
||||
if (currentPackAlignment != 4) {
|
||||
gl->fPixelStorei(LOCAL_GL_PACK_ALIGNMENT, currentPackAlignment);
|
||||
}
|
||||
|
||||
if (aFormat == gfx::FORMAT_R8G8B8A8 || aFormat == gfx::FORMAT_R8G8B8X8) {
|
||||
if (aFormat == FORMAT_R8G8B8A8 || aFormat == FORMAT_R8G8B8X8) {
|
||||
SwapRAndBComponents(surf);
|
||||
}
|
||||
|
||||
if (aYInvert) {
|
||||
surf = YInvertImageSurface(surf);
|
||||
}
|
||||
return surf.forget();
|
||||
}
|
||||
|
||||
TemporaryRef<gfx::DataSourceSurface>
|
||||
ReadBackSurface(GLContext* gl, GLuint aTexture, bool aYInvert, gfx::SurfaceFormat aFormat)
|
||||
{
|
||||
nsRefPtr<gfxImageSurface> image = GetTexImage(gl, aTexture, aYInvert, aFormat);
|
||||
RefPtr<gfx::DataSourceSurface> surf =
|
||||
gfx::Factory::CreateDataSourceSurface(gfx::ToIntSize(image->GetSize()), aFormat);
|
||||
|
||||
if (!image->CopyTo(surf)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return surf.forget();
|
||||
}
|
||||
|
|
|
@ -27,9 +27,6 @@ namespace gl {
|
|||
void ReadPixelsIntoImageSurface(GLContext* aGL, gfxImageSurface* aSurface);
|
||||
void ReadScreenIntoImageSurface(GLContext* aGL, gfxImageSurface* aSurface);
|
||||
|
||||
already_AddRefed<gfxImageSurface>
|
||||
GetTexImage(GLContext* gl, GLuint aTexture, bool aYInvert, gfx::SurfaceFormat aFormat);
|
||||
|
||||
TemporaryRef<gfx::DataSourceSurface>
|
||||
ReadBackSurface(GLContext* gl, GLuint aTexture, bool aYInvert, gfx::SurfaceFormat aFormat);
|
||||
|
||||
|
|
|
@ -1129,14 +1129,24 @@ void WriteSnapshotToDumpFile_internal(T* aObj, gfxASurface* aSurf)
|
|||
}
|
||||
}
|
||||
|
||||
void WriteSnapshotToDumpFile(Layer* aLayer, gfxASurface* aSurf)
|
||||
void WriteSnapshotToDumpFile(Layer* aLayer, DataSourceSurface* aSurf)
|
||||
{
|
||||
WriteSnapshotToDumpFile_internal(aLayer, aSurf);
|
||||
nsRefPtr<gfxImageSurface> surf =
|
||||
new gfxImageSurface(aSurf->GetData(),
|
||||
ThebesIntSize(aSurf->GetSize()),
|
||||
aSurf->Stride(),
|
||||
SurfaceFormatToImageFormat(aSurf->GetFormat()));
|
||||
WriteSnapshotToDumpFile_internal(aLayer, surf);
|
||||
}
|
||||
|
||||
void WriteSnapshotToDumpFile(LayerManager* aManager, gfxASurface* aSurf)
|
||||
void WriteSnapshotToDumpFile(LayerManager* aManager, DataSourceSurface* aSurf)
|
||||
{
|
||||
WriteSnapshotToDumpFile_internal(aManager, aSurf);
|
||||
nsRefPtr<gfxImageSurface> surf =
|
||||
new gfxImageSurface(aSurf->GetData(),
|
||||
ThebesIntSize(aSurf->GetSize()),
|
||||
aSurf->Stride(),
|
||||
SurfaceFormatToImageFormat(aSurf->GetFormat()));
|
||||
WriteSnapshotToDumpFile_internal(aManager, surf);
|
||||
}
|
||||
|
||||
void WriteSnapshotToDumpFile(Compositor* aCompositor, DrawTarget* aTarget)
|
||||
|
|
|
@ -2046,8 +2046,8 @@ void SetAntialiasingFlags(Layer* aLayer, gfxContext* aTarget);
|
|||
void SetAntialiasingFlags(Layer* aLayer, gfx::DrawTarget* aTarget);
|
||||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
void WriteSnapshotToDumpFile(Layer* aLayer, gfxASurface* aSurf);
|
||||
void WriteSnapshotToDumpFile(LayerManager* aManager, gfxASurface* aSurf);
|
||||
void WriteSnapshotToDumpFile(Layer* aLayer, gfx::DataSourceSurface* aSurf);
|
||||
void WriteSnapshotToDumpFile(LayerManager* aManager, gfx::DataSourceSurface* aSurf);
|
||||
void WriteSnapshotToDumpFile(Compositor* aCompositor, gfx::DrawTarget* aTarget);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -70,13 +70,7 @@ CanvasLayerComposite::RenderLayer(const nsIntRect& aClipRect)
|
|||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
if (gfxUtils::sDumpPainting) {
|
||||
RefPtr<gfx::DataSourceSurface> dSurf = mImageHost->GetAsSurface();
|
||||
gfxPlatform *platform = gfxPlatform::GetPlatform();
|
||||
RefPtr<gfx::DrawTarget> dt = platform->CreateDrawTargetForData(dSurf->GetData(),
|
||||
dSurf->GetSize(),
|
||||
dSurf->Stride(),
|
||||
dSurf->GetFormat());
|
||||
nsRefPtr<gfxASurface> surf = platform->GetThebesSurfaceForDrawTarget(dt);
|
||||
RefPtr<gfx::DataSourceSurface> surf = mImageHost->GetAsSurface();
|
||||
WriteSnapshotToDumpFile(this, surf);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -333,7 +333,7 @@ ContainerRender(ContainerT* aContainer,
|
|||
// Unbind the current surface and rebind the previous one.
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
if (gfxUtils::sDumpPainting) {
|
||||
nsRefPtr<gfxImageSurface> surf = surface->Dump(aManager->GetCompositor());
|
||||
RefPtr<gfx::DataSourceSurface> surf = surface->Dump(aManager->GetCompositor());
|
||||
WriteSnapshotToDumpFile(aContainer, surf);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -84,13 +84,7 @@ ImageLayerComposite::RenderLayer(const nsIntRect& aClipRect)
|
|||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
if (gfxUtils::sDumpPainting) {
|
||||
RefPtr<gfx::DataSourceSurface> dSurf = mImageHost->GetAsSurface();
|
||||
gfxPlatform *platform = gfxPlatform::GetPlatform();
|
||||
RefPtr<gfx::DrawTarget> dt = platform->CreateDrawTargetForData(dSurf->GetData(),
|
||||
dSurf->GetSize(),
|
||||
dSurf->Stride(),
|
||||
dSurf->GetFormat());
|
||||
nsRefPtr<gfxASurface> surf = platform->GetThebesSurfaceForDrawTarget(dt);
|
||||
RefPtr<gfx::DataSourceSurface> surf = mImageHost->GetAsSurface();
|
||||
WriteSnapshotToDumpFile(this, surf);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -843,7 +843,7 @@ public:
|
|||
virtual ~CompositingRenderTarget() {}
|
||||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
virtual already_AddRefed<gfxImageSurface> Dump(Compositor* aCompositor) { return nullptr; }
|
||||
virtual TemporaryRef<gfx::DataSourceSurface> Dump(Compositor* aCompositor) { return nullptr; }
|
||||
#endif
|
||||
|
||||
const gfx::IntPoint& GetOrigin() { return mOrigin; }
|
||||
|
|
|
@ -111,14 +111,8 @@ ThebesLayerComposite::RenderLayer(const nsIntRect& aClipRect)
|
|||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
if (gfxUtils::sDumpPainting) {
|
||||
RefPtr<gfx::DataSourceSurface> dSurf = mBuffer->GetAsSurface();
|
||||
if (dSurf) {
|
||||
gfxPlatform *platform = gfxPlatform::GetPlatform();
|
||||
RefPtr<gfx::DrawTarget> dt = platform->CreateDrawTargetForData(dSurf->GetData(),
|
||||
dSurf->GetSize(),
|
||||
dSurf->Stride(),
|
||||
dSurf->GetFormat());
|
||||
nsRefPtr<gfxASurface> surf = platform->GetThebesSurfaceForDrawTarget(dt);
|
||||
RefPtr<gfx::DataSourceSurface> surf = mBuffer->GetAsSurface();
|
||||
if (surf) {
|
||||
WriteSnapshotToDumpFile(this, surf);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,11 @@
|
|||
#include "CompositingRenderTargetOGL.h"
|
||||
#include "GLContext.h"
|
||||
#include "GLReadTexImageHelper.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::gfx;
|
||||
using namespace mozilla::gl;
|
||||
using namespace mozilla::layers;
|
||||
|
||||
CompositingRenderTargetOGL::~CompositingRenderTargetOGL()
|
||||
|
@ -57,12 +60,12 @@ CompositingRenderTargetOGL::BindRenderTarget()
|
|||
}
|
||||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
already_AddRefed<gfxImageSurface>
|
||||
TemporaryRef<DataSourceSurface>
|
||||
CompositingRenderTargetOGL::Dump(Compositor* aCompositor)
|
||||
{
|
||||
MOZ_ASSERT(mInitParams.mStatus == InitParams::INITIALIZED);
|
||||
CompositorOGL* compositorOGL = static_cast<CompositorOGL*>(aCompositor);
|
||||
return GetTexImage(mGL, mTextureHandle, true, compositorOGL->GetFBOFormat());
|
||||
return ReadBackSurface(mGL, mTextureHandle, true, compositorOGL->GetFBOFormat());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ namespace mozilla {
|
|||
namespace gl {
|
||||
class BindableTexture;
|
||||
}
|
||||
namespace gfx {
|
||||
class DataSourceSurface;
|
||||
}
|
||||
|
||||
namespace layers {
|
||||
|
||||
|
@ -152,7 +155,7 @@ public:
|
|||
}
|
||||
|
||||
#ifdef MOZ_DUMP_PAINTING
|
||||
virtual already_AddRefed<gfxImageSurface> Dump(Compositor* aCompositor);
|
||||
virtual TemporaryRef<gfx::DataSourceSurface> Dump(Compositor* aCompositor);
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
|
Загрузка…
Ссылка в новой задаче