Skip to content

Commit

Permalink
Bug 1209812 (part 6) - Convert all gfxImageFormat values to SurfaceFo…
Browse files Browse the repository at this point in the history
…rmat equivalents. r=jrmuizel.

This patch:

- Makes the following substitutions (plus necessary namespace qualifiers:

    gfxImageFormat::ARGB32      --> SurfaceFormat::A8R8G8B8_UINT32
    gfxImageFormat::RGB24       --> SurfaceFormat::X8R8G8B8_UINT32
    gfxImageFormat::A8          --> SurfaceFormat::A8
    gfxImageFormat::RGB16_565   --> SurfaceFormat::R5G6B5_UINT16
    gfxImageFormat::Unknown     --> SurfaceFormat::UNKNOWN

- Changes gfxImageFormat to be a typedef to gfx::SurfaceFormat. This will be
  removed soon.

- Removes gfxCairoFormatToImageFormat() and gfxImageFormatToCairoFormat() and
  replace calls to them with CairoFormatToGfxFormat() and
  GfxFormatToCairoFormat().

- Removes ParamTraits<gfxImageFormat>.

- Add namespace qualifiers to SurfaceFormat instances where necessary.

--HG--
extra : rebase_source : f56e92b1593957a9e4e00171100bc7605816e696
  • Loading branch information
nnethercote committed Jan 8, 2016
1 parent ff6a816 commit 88696a3
Show file tree
Hide file tree
Showing 48 changed files with 160 additions and 189 deletions.
2 changes: 1 addition & 1 deletion dom/base/ImageEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ ImageEncoder::ExtractDataInternal(const nsAString& aType,
if (aImage->GetFormat() == ImageFormat::PLANAR_YCBCR) {
nsTArray<uint8_t> data;
layers::PlanarYCbCrImage* ycbcrImage = static_cast<layers::PlanarYCbCrImage*> (aImage);
gfxImageFormat format = gfxImageFormat::ARGB32;
gfxImageFormat format = SurfaceFormat::A8R8G8B8_UINT32;
uint32_t stride = GetAlignedStride<16>(aSize.width * 4);
size_t length = BufferSizeFromStrideAndHeight(stride, aSize.height);
data.SetCapacity(length);
Expand Down
2 changes: 1 addition & 1 deletion dom/canvas/CanvasRenderingContext2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5423,7 +5423,7 @@ CanvasRenderingContext2D::PutImageData_explicit(int32_t x, int32_t y, uint32_t w
uint32_t copyWidth = dirtyRect.Width();
uint32_t copyHeight = dirtyRect.Height();
RefPtr<gfxImageSurface> imgsurf = new gfxImageSurface(gfx::IntSize(copyWidth, copyHeight),
gfxImageFormat::ARGB32,
SurfaceFormat::A8R8G8B8_UINT32,
false);
if (!imgsurf || imgsurf->CairoStatus()) {
return NS_ERROR_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion dom/media/android/AndroidMediaReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ AndroidMediaReader::ImageBufferCallback::operator()(size_t aWidth, size_t aHeigh
case MPAPI::RGB565:
image = mozilla::layers::CreateSharedRGBImage(mImageContainer,
nsIntSize(aWidth, aHeight),
gfxImageFormat::RGB16_565);
SurfaceFormat::R5G6B5_UINT16);
if (!image) {
NS_WARNING("Could not create rgb image");
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion dom/media/webrtc/MediaEngineTabVideoSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ MediaEngineTabVideoSource::Draw() {
}
}

gfxImageFormat format = gfxImageFormat::RGB24;
gfxImageFormat format = SurfaceFormat::X8R8G8B8_UINT32;
uint32_t stride = gfxASurface::FormatStrideForWidth(format, size.width);

if (mDataSize < static_cast<size_t>(stride * size.height)) {
Expand Down
2 changes: 1 addition & 1 deletion dom/plugins/base/nsPluginInstanceOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2922,7 +2922,7 @@ void nsPluginInstanceOwner::Paint(gfxContext* aContext,
aFrameRect.height != pluginSurface->Height()) {

pluginSurface = new gfxImageSurface(gfx::IntSize(aFrameRect.width, aFrameRect.height),
gfxImageFormat::ARGB32);
SurfaceFormat::A8R8G8B8_UINT32);
if (!pluginSurface)
return;
}
Expand Down
14 changes: 7 additions & 7 deletions dom/plugins/ipc/PluginInstanceChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3067,15 +3067,15 @@ PluginInstanceChild::CreateOptSurface(void)
// Use an opaque surface unless we're transparent and *don't* have
// a background to source from.
gfxImageFormat format =
(mIsTransparent && !mBackground) ? gfxImageFormat::ARGB32 :
gfxImageFormat::RGB24;
(mIsTransparent && !mBackground) ? SurfaceFormat::A8R8G8B8_UINT32 :
SurfaceFormat::X8R8G8B8_UINT32;

#ifdef MOZ_X11
Display* dpy = mWsInfo.display;
Screen* screen = DefaultScreenOfDisplay(dpy);
if (format == gfxImageFormat::RGB24 &&
if (format == SurfaceFormat::X8R8G8B8_UINT32 &&
DefaultDepth(dpy, DefaultScreen(dpy)) == 16) {
format = gfxImageFormat::RGB16_565;
format = SurfaceFormat::R5G6B5_UINT16;
}

if (mSurfaceType == gfxSurfaceType::Xlib) {
Expand Down Expand Up @@ -3517,7 +3517,7 @@ PluginInstanceChild::PaintRectWithAlphaExtraction(const nsIntRect& aRect,
gfxImageSurface* surfaceAsImage =
static_cast<gfxImageSurface*>(aSurface);
useSurfaceSubimageForBlack =
(surfaceAsImage->Format() == gfxImageFormat::ARGB32);
(surfaceAsImage->Format() == SurfaceFormat::A8R8G8B8_UINT32);
// If we're going to use a subimage, nudge the rect so that we
// can use optimal alpha recovery. If we're not using a
// subimage, the temporaries should automatically get
Expand All @@ -3536,7 +3536,7 @@ PluginInstanceChild::PaintRectWithAlphaExtraction(const nsIntRect& aRect,
gfxPoint deviceOffset = -targetRect.TopLeft();

// We always use a temporary "white image"
whiteImage = new gfxImageSurface(targetSize, gfxImageFormat::RGB24);
whiteImage = new gfxImageSurface(targetSize, SurfaceFormat::X8R8G8B8_UINT32);
if (whiteImage->CairoStatus()) {
return;
}
Expand Down Expand Up @@ -3577,7 +3577,7 @@ PluginInstanceChild::PaintRectWithAlphaExtraction(const nsIntRect& aRect,
blackImage = surface->GetSubimage(targetRect);
} else {
blackImage = new gfxImageSurface(targetSize,
gfxImageFormat::ARGB32);
SurfaceFormat::A8R8G8B8_UINT32);
}

// Paint onto black background
Expand Down
2 changes: 1 addition & 1 deletion dom/plugins/ipc/PluginInstanceParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ PluginInstanceParent::CreateBackground(const nsIntSize& aSize)
gfxSharedImageSurface::CreateUnsafe(
this,
mozilla::gfx::IntSize(aSize.width, aSize.height),
gfxImageFormat::RGB24);
mozilla::gfx::SurfaceFormat::X8R8G8B8_UINT32);
return !!mBackground;
#else
return false;
Expand Down
3 changes: 3 additions & 0 deletions gfx/2d/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,9 @@ enum class JobStatus {
} // namespace gfx
} // namespace mozilla

// XXX: temporary
typedef mozilla::gfx::SurfaceFormat gfxImageFormat;

#if defined(XP_WIN) && defined(MOZ_GFX)
#ifdef GFX2D_INTERNAL
#define GFX2D_API __declspec(dllexport)
Expand Down
6 changes: 3 additions & 3 deletions gfx/gl/GLReadTexImageHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ class GLReadTexImageHelper final

/**
* Read the image data contained in aTexture, and return it as an ImageSurface.
* If GL_RGBA is given as the format, a gfxImageFormat::ARGB32 surface is returned.
* If GL_RGBA is given as the format, a SurfaceFormat::A8R8G8B8_UINT32 surface is returned.
* Not implemented yet:
* If GL_RGB is given as the format, a gfxImageFormat::RGB24 surface is returned.
* If GL_LUMINANCE is given as the format, a gfxImageFormat::A8 surface is returned.
* If GL_RGB is given as the format, a SurfaceFormat::X8R8G8B8_UINT32 surface is returned.
* If GL_LUMINANCE is given as the format, a SurfaceFormat::A8 surface is returned.
*
* THIS IS EXPENSIVE. It is ridiculously expensive. Only do this
* if you absolutely positively must, and never in any performance
Expand Down
10 changes: 5 additions & 5 deletions gfx/gl/GLTextureImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class TextureImage
TextureImage(const gfx::IntSize& aSize,
GLenum aWrapMode, ContentType aContentType,
Flags aFlags = NoFlags,
ImageFormat aImageFormat = gfxImageFormat::Unknown);
ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);

// Protected destructor, to discourage deletion outside of Release():
virtual ~TextureImage() {}
Expand Down Expand Up @@ -248,7 +248,7 @@ class BasicTextureImage
ContentType aContentType,
GLContext* aContext,
TextureImage::Flags aFlags = TextureImage::NoFlags,
TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);

virtual void BindTexture(GLenum aTextureUnit);

Expand Down Expand Up @@ -298,7 +298,7 @@ class TiledTextureImage final
gfx::IntSize aSize,
TextureImage::ContentType,
TextureImage::Flags aFlags = TextureImage::NoFlags,
TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
~TiledTextureImage();
void DumpDiv();
virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
Expand Down Expand Up @@ -348,7 +348,7 @@ CreateBasicTextureImage(GLContext* aGL,
TextureImage::ContentType aContentType,
GLenum aWrapMode,
TextureImage::Flags aFlags,
TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);

/**
* Return a valid, allocated TextureImage of |aSize| with
Expand All @@ -373,7 +373,7 @@ CreateTextureImage(GLContext* gl,
TextureImage::ContentType aContentType,
GLenum aWrapMode,
TextureImage::Flags aFlags = TextureImage::NoFlags,
TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);

} // namespace gl
} // namespace mozilla
Expand Down
2 changes: 1 addition & 1 deletion gfx/gl/SharedSurfaceGLX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SharedSurface_GLXDrawable::Create(GLContext* prodGL,
UniquePtr<SharedSurface_GLXDrawable> ret;
Display* display = DefaultXDisplay();
Screen* screen = XDefaultScreenOfDisplay(display);
Visual* visual = gfxXlibSurface::FindVisual(screen, gfxImageFormat::ARGB32);
Visual* visual = gfxXlibSurface::FindVisual(screen, gfx::SurfaceFormat::A8R8G8B8_UINT32);

RefPtr<gfxXlibSurface> surf = gfxXlibSurface::Create(screen, visual, size);
if (!deallocateClient)
Expand Down
2 changes: 1 addition & 1 deletion gfx/gl/TextureImageCGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TextureImageCGL : public BasicTextureImage
ContentType aContentType,
GLContext* aContext,
TextureImage::Flags aFlags = TextureImage::NoFlags,
TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);

~TextureImageCGL();

Expand Down
2 changes: 1 addition & 1 deletion gfx/gl/TextureImageEGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TextureImageEGL final
GLContext* aContext,
Flags aFlags = TextureImage::NoFlags,
TextureState aTextureState = Created,
TextureImage::ImageFormat aImageFormat = gfxImageFormat::Unknown);
TextureImage::ImageFormat aImageFormat = SurfaceFormat::UNKNOWN);

virtual ~TextureImageEGL();

Expand Down
12 changes: 2 additions & 10 deletions gfx/ipc/GfxMessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,6 @@ struct ParamTraits<mozilla::layers::ScaleMode>
mozilla::layers::ScaleMode::SENTINEL>
{};

template <>
struct ParamTraits<gfxImageFormat>
: public ContiguousEnumSerializer<
gfxImageFormat,
gfxImageFormat::ARGB32,
gfxImageFormat::Unknown>
{};

template <>
struct ParamTraits<mozilla::gfx::AttributeName>
: public ContiguousEnumSerializer<
Expand Down Expand Up @@ -287,8 +279,8 @@ struct ParamTraits<mozilla::layers::DiagnosticTypes>
template <>
struct ParamTraits<mozilla::PixelFormat>
: public EnumSerializer<mozilla::PixelFormat,
gfxImageFormat::ARGB32,
gfxImageFormat::Unknown>
SurfaceFormat::A8R8G8B8_UINT32,
SurfaceFormat::UNKNOWN>
{};
*/

Expand Down
2 changes: 1 addition & 1 deletion gfx/ipc/SharedDIBSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SharedDIBSurface::InitSurface(uint32_t aWidth, uint32_t aHeight,
long stride = long(aWidth * SharedDIB::kBytesPerPixel);
unsigned char* data = reinterpret_cast<unsigned char*>(mSharedDIB.GetBits());

gfxImageFormat format = aTransparent ? gfxImageFormat::ARGB32 : gfxImageFormat::RGB24;
gfxImageFormat format = aTransparent ? SurfaceFormat::A8R8G8B8_UINT32 : SurfaceFormat::X8R8G8B8_UINT32;

gfxImageSurface::InitWithData(data, IntSize(aWidth, aHeight),
stride, format);
Expand Down
4 changes: 2 additions & 2 deletions gfx/layers/ImageContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ ImageContainer::NotifyCompositeInternal(const ImageCompositeNotification& aNotif

PlanarYCbCrImage::PlanarYCbCrImage()
: Image(nullptr, ImageFormat::PLANAR_YCBCR)
, mOffscreenFormat(gfxImageFormat::Unknown)
, mOffscreenFormat(SurfaceFormat::UNKNOWN)
, mBufferSize(0)
{
}
Expand Down Expand Up @@ -480,7 +480,7 @@ RecyclingPlanarYCbCrImage::SetData(const Data &aData)
gfxImageFormat
PlanarYCbCrImage::GetOffscreenFormat()
{
return mOffscreenFormat == gfxImageFormat::Unknown ?
return mOffscreenFormat == SurfaceFormat::UNKNOWN ?
gfxPlatform::GetPlatform()->GetOffscreenFormat() :
mOffscreenFormat;
}
Expand Down
1 change: 0 additions & 1 deletion gfx/layers/ImageDataSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "ImageDataSerializer.h"
#include <string.h> // for memcpy
#include "gfx2DGlue.h" // for SurfaceFormatToImageFormat
#include "mozilla/gfx/Point.h" // for IntSize
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
Expand Down
4 changes: 2 additions & 2 deletions gfx/layers/basic/BasicLayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ Transform(const gfxImageSurface* aDest,
gfxPoint aDestOffset)
{
IntSize destSize = aDest->GetSize();
pixman_image_t* dest = pixman_image_create_bits(aDest->Format() == gfxImageFormat::ARGB32 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
pixman_image_t* dest = pixman_image_create_bits(aDest->Format() == SurfaceFormat::A8R8G8B8_UINT32 ? PIXMAN_a8r8g8b8 : PIXMAN_x8r8g8b8,
destSize.width,
destSize.height,
(uint32_t*)aDest->Data(),
Expand Down Expand Up @@ -865,7 +865,7 @@ Transform3D(RefPtr<SourceSurface> aSource,
RefPtr<gfxASurface> dest = aDest->CurrentSurface();
RefPtr<gfxImageSurface> destImage = new gfxImageSurface(IntSize(aDestRect.width,
aDestRect.height),
gfxImageFormat::ARGB32);
SurfaceFormat::A8R8G8B8_UINT32);
gfxPoint offset = aDestRect.TopLeft();

// Include a translation to the correct origin.
Expand Down
6 changes: 3 additions & 3 deletions gfx/layers/ipc/SharedRGBImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ CreateSharedRGBImage(ImageContainer *aImageContainer,
gfx::IntSize aSize,
gfxImageFormat aImageFormat)
{
NS_ASSERTION(aImageFormat == gfxImageFormat::ARGB32 ||
aImageFormat == gfxImageFormat::RGB24 ||
aImageFormat == gfxImageFormat::RGB16_565,
NS_ASSERTION(aImageFormat == gfx::SurfaceFormat::A8R8G8B8_UINT32 ||
aImageFormat == gfx::SurfaceFormat::X8R8G8B8_UINT32 ||
aImageFormat == gfx::SurfaceFormat::R5G6B5_UINT16,
"RGB formats supported only");

if (!aImageContainer) {
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/opengl/CompositorOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ CompositorOGL::CreateContext()
if (!context && gfxEnv::LayersPreferOffscreen()) {
SurfaceCaps caps = SurfaceCaps::ForRGB();
caps.preserve = false;
caps.bpp16 = gfxPlatform::GetPlatform()->GetOffscreenFormat() == gfxImageFormat::RGB16_565;
caps.bpp16 = gfxPlatform::GetPlatform()->GetOffscreenFormat() == SurfaceFormat::R5G6B5_UINT16;

context = GLContextProvider::CreateOffscreen(mSurfaceSize,
caps, CreateContextFlags::REQUIRE_COMPAT_PROFILE);
Expand Down
12 changes: 6 additions & 6 deletions gfx/tests/gtest/TestTextures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ void TestTextureClientYCbCr(TextureClient* client, PlanarYCbCrData& ycbcrData) {
TEST(Layers, TextureSerialization) {
// the test is run on all the following image formats
gfxImageFormat formats[3] = {
gfxImageFormat::ARGB32,
gfxImageFormat::RGB24,
gfxImageFormat::A8,
SurfaceFormat::A8R8G8B8_UINT32,
SurfaceFormat::X8R8G8B8_UINT32,
SurfaceFormat::A8,
};

for (int f = 0; f < 3; ++f) {
Expand All @@ -240,9 +240,9 @@ TEST(Layers, TextureSerialization) {
}

TEST(Layers, TextureYCbCrSerialization) {
RefPtr<gfxImageSurface> ySurface = new gfxImageSurface(IntSize(400,300), gfxImageFormat::A8);
RefPtr<gfxImageSurface> cbSurface = new gfxImageSurface(IntSize(200,150), gfxImageFormat::A8);
RefPtr<gfxImageSurface> crSurface = new gfxImageSurface(IntSize(200,150), gfxImageFormat::A8);
RefPtr<gfxImageSurface> ySurface = new gfxImageSurface(IntSize(400,300), SurfaceFormat::A8);
RefPtr<gfxImageSurface> cbSurface = new gfxImageSurface(IntSize(200,150), SurfaceFormat::A8);
RefPtr<gfxImageSurface> crSurface = new gfxImageSurface(IntSize(200,150), SurfaceFormat::A8);
SetupSurface(ySurface.get());
SetupSurface(cbSurface.get());
SetupSurface(crSurface.get());
Expand Down
2 changes: 1 addition & 1 deletion gfx/tests/gtest/gfxSurfaceRefCountTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TestNewSurface () {
int failures = 0;
int destroyed = 0;

RefPtr<gfxASurface> s = new gfxImageSurface (mozilla::gfx::IntSize(10, 10), gfxImageFormat::ARGB32);
RefPtr<gfxASurface> s = new gfxImageSurface (mozilla::gfx::IntSize(10, 10), SurfaceFormat::A8R8G8B8_UINT32);
cairo_surface_t *cs = s->CairoSurface();

cairo_surface_set_user_data (cs, &destruction_key, &destroyed, SurfaceDestroyNotifier);
Expand Down
20 changes: 10 additions & 10 deletions gfx/thebes/gfx2DGlue.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,31 @@ inline gfxImageFormat SurfaceFormatToImageFormat(SurfaceFormat aFormat)
{
switch (aFormat) {
case SurfaceFormat::B8G8R8A8:
return gfxImageFormat::ARGB32;
return SurfaceFormat::A8R8G8B8_UINT32;
case SurfaceFormat::B8G8R8X8:
return gfxImageFormat::RGB24;
return SurfaceFormat::X8R8G8B8_UINT32;
case SurfaceFormat::R5G6B5_UINT16:
return gfxImageFormat::RGB16_565;
return SurfaceFormat::R5G6B5_UINT16;
case SurfaceFormat::A8:
return gfxImageFormat::A8;
return SurfaceFormat::A8;
default:
return gfxImageFormat::Unknown;
return SurfaceFormat::UNKNOWN;
}
}

inline SurfaceFormat ImageFormatToSurfaceFormat(gfxImageFormat aFormat)
{
switch (aFormat) {
case gfxImageFormat::ARGB32:
case SurfaceFormat::A8R8G8B8_UINT32:
return SurfaceFormat::B8G8R8A8;
case gfxImageFormat::RGB24:
case SurfaceFormat::X8R8G8B8_UINT32:
return SurfaceFormat::B8G8R8X8;
case gfxImageFormat::RGB16_565:
case SurfaceFormat::R5G6B5_UINT16:
return SurfaceFormat::R5G6B5_UINT16;
case gfxImageFormat::A8:
case SurfaceFormat::A8:
return SurfaceFormat::A8;
default:
case gfxImageFormat::Unknown:
case SurfaceFormat::UNKNOWN:
return SurfaceFormat::B8G8R8A8;
}
}
Expand Down
Loading

0 comments on commit 88696a3

Please sign in to comment.