gecko-dev/gfx/ipc/SharedDIBSurface.cpp
Benoit Jacob 55d6cf1e20 Bug 913872 - Take nested enums out of gfxASurface - 1/3 : automatic changes - r=jrmuizel
Generated by these regexes:

find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/gfx[A-Za-z0-9_]*Surface\:\:[a-z]*\(\(ImageFormat\|SurfaceType\|ContentType\|MemoryLocation\)[0-9A-Za-z_]*\)/gfx\1/g'

find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/gfx[A-Za-z0-9_]*Surface\:\:[a-z]*\(\(CONTENT_\|MEMORY_\)[0-9A-Za-z_]*\)/GFX_\1/g'

find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)\(CONTENT_COLOR\|CONTENT_ALPHA\|CONTENT_COLOR_ALPHA\|CONTENT_SENTINEL\|MEMORY_IN_PROCESS_HEAP\|MEMORY_IN_PROCESS_NONHEAP\|MEMORY_OUT_OF_PROCESS\)\($\|[^A-Za-z0-9_]\)/\1GFX_\2\3/g'

find . -name '*.h' -o -name '*.cpp' -o -name '*.mm' | grep -v '\.hg' | grep -v '^\.\/obj' | xargs sed -i 's/\(^\|[^A-Za-z0-9_]\)\(ImageFormatARGB32\|ImageFormatRGB24\|ImageFormatA8\|ImageFormatA1\|ImageFormatRGB16_565\|ImageFormatUnknown\|SurfaceTypeImage\|SurfaceTypePDF\|SurfaceTypePS\|SurfaceTypeXlib\|SurfaceTypeXcb\|SurfaceTypeGlitz\|SurfaceTypeQuartz\|SurfaceTypeWin32\|SurfaceTypeBeOS\|SurfaceTypeDirectFB\|SurfaceTypeSVG\|SurfaceTypeOS2\|SurfaceTypeWin32Printing\|SurfaceTypeQuartzImage\|SurfaceTypeScript\|SurfaceTypeQPainter\|SurfaceTypeRecording\|SurfaceTypeVG\|SurfaceTypeGL\|SurfaceTypeDRM\|SurfaceTypeTee\|SurfaceTypeXML\|SurfaceTypeSkia\|SurfaceTypeSubsurface\|SurfaceTypeD2D\|SurfaceTypeMax\)\($\|[^A-Za-z0-9_]\)/\1gfx\2\3/g'
2013-09-24 16:45:13 -04:00

66 lines
1.8 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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 "SharedDIBSurface.h"
#include "cairo.h"
namespace mozilla {
namespace gfx {
static const cairo_user_data_key_t SHAREDDIB_KEY = {0};
static const long kBytesPerPixel = 4;
bool
SharedDIBSurface::Create(HDC adc, uint32_t aWidth, uint32_t aHeight,
bool aTransparent)
{
nsresult rv = mSharedDIB.Create(adc, aWidth, aHeight, aTransparent);
if (NS_FAILED(rv) || !mSharedDIB.IsValid())
return false;
InitSurface(aWidth, aHeight, aTransparent);
return true;
}
bool
SharedDIBSurface::Attach(Handle aHandle, uint32_t aWidth, uint32_t aHeight,
bool aTransparent)
{
nsresult rv = mSharedDIB.Attach(aHandle, aWidth, aHeight, aTransparent);
if (NS_FAILED(rv) || !mSharedDIB.IsValid())
return false;
InitSurface(aWidth, aHeight, aTransparent);
return true;
}
void
SharedDIBSurface::InitSurface(uint32_t aWidth, uint32_t aHeight,
bool aTransparent)
{
long stride = long(aWidth * kBytesPerPixel);
unsigned char* data = reinterpret_cast<unsigned char*>(mSharedDIB.GetBits());
gfxImageFormat format = aTransparent ? gfxImageFormatARGB32 : gfxImageFormatRGB24;
gfxImageSurface::InitWithData(data, gfxIntSize(aWidth, aHeight),
stride, format);
cairo_surface_set_user_data(mSurface, &SHAREDDIB_KEY, this, nullptr);
}
bool
SharedDIBSurface::IsSharedDIBSurface(gfxASurface* aSurface)
{
return aSurface &&
aSurface->GetType() == gfxSurfaceTypeImage &&
aSurface->GetData(&SHAREDDIB_KEY);
}
} // namespace gfx
} // namespace mozilla