Bug 1497294 - P2. Move type related constant methods to Types.h r=nical

The methods BytesPerPixel, SurfaceFormatForColorDepth, BitDepthForColorDepth, ColorDepthForBitDepth and RescalingFactorForColorDepth all directly depends on the types defined in Types.h, they also return constant values.

As such it makes more sense to have them defined at the same level where the types themselves are declared.

Depends on D8065

Differential Revision: https://phabricator.services.mozilla.com/D8073

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2018-10-09 12:56:25 +00:00
Родитель 786dffc1c6
Коммит b5f4d81b93
5 изменённых файлов: 111 добавлений и 114 удалений

Просмотреть файл

@ -16,7 +16,6 @@
#include "HelpersD2D.h"
#include "FilterNodeD2D1.h"
#include "ExtendInputEffectD2D1.h"
#include "Tools.h"
#include "nsAppRunner.h"
#include "MainThreadUtils.h"

Просмотреть файл

@ -15,7 +15,6 @@
#include <versionhelpers.h>
#include "2D.h"
#include "Logging.h"
#include "Tools.h"
#include "ImageScaling.h"
#include "ScaledFontDWrite.h"
@ -330,7 +329,7 @@ static inline bool IsPatternSupportedByD2D(const Pattern &aPattern)
const RadialGradientPattern *pat =
static_cast<const RadialGradientPattern*>(&aPattern);
if (pat->mRadius1 != 0) {
return false;
}
@ -427,7 +426,7 @@ DWriteGlyphRunFromGlyphs(const GlyphBuffer &aGlyphs, ScaledFontDWrite *aFont, Au
offsets[i].advanceOffset = aGlyphs.mGlyphs[i].mPosition.x;
offsets[i].ascenderOffset = -aGlyphs.mGlyphs[i].mPosition.y;
}
run->bidiLevel = 0;
run->fontFace = aFont->mFontFace;
run->fontEmSize = aFont->GetSize();
@ -582,7 +581,7 @@ CreatePartialBitmapForSurface(DataSourceSurface *aSurface, const Matrix &aDestin
uploadRect = Rect(aSourceRect->X(), aSourceRect->Y(), aSourceRect->Width(), aSourceRect->Height());
}
// Limit the uploadRect as much as possible without supporting discontiguous uploads
// Limit the uploadRect as much as possible without supporting discontiguous uploads
//
// region we will paint from
// uploadRect

Просмотреть файл

@ -6,7 +6,6 @@
#include "SourceSurfaceD2D1.h"
#include "DrawTargetD2D1.h"
#include "Tools.h"
namespace mozilla {
namespace gfx {
@ -70,7 +69,7 @@ SourceSurfaceD2D1::GetDataSurface()
D2D1_POINT_2U point = D2D1::Point2U(0, 0);
D2D1_RECT_U rect = D2D1::RectU(0, 0, mSize.width, mSize.height);
hr = softwareBitmap->CopyFromBitmap(&point, mRealizedBitmap, &rect);
if (FAILED(hr)) {

Просмотреть файл

@ -87,113 +87,6 @@ Distance(Point aA, Point aB)
return hypotf(aB.x - aA.x, aB.y - aA.y);
}
static inline int
BytesPerPixel(SurfaceFormat aFormat)
{
switch (aFormat) {
case SurfaceFormat::A8:
return 1;
case SurfaceFormat::R5G6B5_UINT16:
case SurfaceFormat::A16:
return 2;
case SurfaceFormat::R8G8B8:
case SurfaceFormat::B8G8R8:
return 3;
case SurfaceFormat::HSV:
case SurfaceFormat::Lab:
return 3 * sizeof(float);
case SurfaceFormat::Depth:
return sizeof(uint16_t);
default:
return 4;
}
}
static inline SurfaceFormat
SurfaceFormatForColorDepth(ColorDepth aColorDepth)
{
SurfaceFormat format = SurfaceFormat::A8;
switch (aColorDepth) {
case ColorDepth::COLOR_8:
break;
case ColorDepth::COLOR_10:
case ColorDepth::COLOR_12:
case ColorDepth::COLOR_16:
format = SurfaceFormat::A16;
break;
case ColorDepth::UNKNOWN:
MOZ_ASSERT_UNREACHABLE("invalid color depth value");
}
return format;
}
static inline uint32_t
BitDepthForColorDepth(ColorDepth aColorDepth)
{
uint32_t depth = 8;
switch (aColorDepth) {
case ColorDepth::COLOR_8:
break;
case ColorDepth::COLOR_10:
depth = 10;
break;
case ColorDepth::COLOR_12:
depth = 12;
break;
case ColorDepth::COLOR_16:
depth = 16;
break;
case ColorDepth::UNKNOWN:
MOZ_ASSERT_UNREACHABLE("invalid color depth value");
}
return depth;
}
static inline ColorDepth
ColorDepthForBitDepth(uint8_t aBitDepth)
{
ColorDepth depth = ColorDepth::COLOR_8;
switch (aBitDepth) {
case 8:
break;
case 10:
depth = ColorDepth::COLOR_10;
break;
case 12:
depth = ColorDepth::COLOR_12;
break;
case 16:
depth = ColorDepth::COLOR_16;
break;
default:
MOZ_ASSERT_UNREACHABLE("invalid color depth value");
}
return depth;
}
// 10 and 12 bits color depth image are using 16 bits integers for storage
// As such we need to rescale the value from 10 or 12 bits to 16.
static inline uint32_t
RescalingFactorForColorDepth(ColorDepth aColorDepth)
{
uint32_t factor = 1;
switch (aColorDepth) {
case ColorDepth::COLOR_8:
break;
case ColorDepth::COLOR_10:
factor = 64;
break;
case ColorDepth::COLOR_12:
factor = 16;
break;
case ColorDepth::COLOR_16:
break;
case ColorDepth::UNKNOWN:
MOZ_ASSERT_UNREACHABLE("invalid color depth value");
}
return factor;
}
template<typename T, int alignment = 16>
struct AlignedArray
{

Просмотреть файл

@ -87,6 +87,28 @@ enum class SurfaceFormat : int8_t {
#endif
};
static inline int
BytesPerPixel(SurfaceFormat aFormat)
{
switch (aFormat) {
case SurfaceFormat::A8:
return 1;
case SurfaceFormat::R5G6B5_UINT16:
case SurfaceFormat::A16:
return 2;
case SurfaceFormat::R8G8B8:
case SurfaceFormat::B8G8R8:
return 3;
case SurfaceFormat::HSV:
case SurfaceFormat::Lab:
return 3 * sizeof(float);
case SurfaceFormat::Depth:
return sizeof(uint16_t);
default:
return 4;
}
}
inline bool IsOpaque(SurfaceFormat aFormat)
{
switch (aFormat) {
@ -117,6 +139,91 @@ enum class ColorDepth : uint8_t {
UNKNOWN
};
static inline SurfaceFormat
SurfaceFormatForColorDepth(ColorDepth aColorDepth)
{
SurfaceFormat format = SurfaceFormat::A8;
switch (aColorDepth) {
case ColorDepth::COLOR_8:
break;
case ColorDepth::COLOR_10:
case ColorDepth::COLOR_12:
case ColorDepth::COLOR_16:
format = SurfaceFormat::A16;
break;
case ColorDepth::UNKNOWN:
MOZ_ASSERT_UNREACHABLE("invalid color depth value");
}
return format;
}
static inline uint32_t
BitDepthForColorDepth(ColorDepth aColorDepth)
{
uint32_t depth = 8;
switch (aColorDepth) {
case ColorDepth::COLOR_8:
break;
case ColorDepth::COLOR_10:
depth = 10;
break;
case ColorDepth::COLOR_12:
depth = 12;
break;
case ColorDepth::COLOR_16:
depth = 16;
break;
case ColorDepth::UNKNOWN:
MOZ_ASSERT_UNREACHABLE("invalid color depth value");
}
return depth;
}
static inline ColorDepth
ColorDepthForBitDepth(uint8_t aBitDepth)
{
ColorDepth depth = ColorDepth::COLOR_8;
switch (aBitDepth) {
case 8:
break;
case 10:
depth = ColorDepth::COLOR_10;
break;
case 12:
depth = ColorDepth::COLOR_12;
break;
case 16:
depth = ColorDepth::COLOR_16;
break;
default:
MOZ_ASSERT_UNREACHABLE("invalid color depth value");
}
return depth;
}
// 10 and 12 bits color depth image are using 16 bits integers for storage
// As such we need to rescale the value from 10 or 12 bits to 16.
static inline uint32_t
RescalingFactorForColorDepth(ColorDepth aColorDepth)
{
uint32_t factor = 1;
switch (aColorDepth) {
case ColorDepth::COLOR_8:
break;
case ColorDepth::COLOR_10:
factor = 64;
break;
case ColorDepth::COLOR_12:
factor = 16;
break;
case ColorDepth::COLOR_16:
break;
case ColorDepth::UNKNOWN:
MOZ_ASSERT_UNREACHABLE("invalid color depth value");
}
return factor;
}
enum class FilterType : int8_t {
BLEND = 0,
TRANSFORM,