2010-05-18 08:04:22 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
#include "gfxUtils.h"
|
2010-08-13 17:30:02 +04:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxPlatform.h"
|
2010-08-13 17:30:27 +04:00
|
|
|
#include "gfxDrawable.h"
|
2010-09-03 06:31:42 +04:00
|
|
|
#include "nsRegion.h"
|
2011-09-28 02:19:24 +04:00
|
|
|
#include "yuv_convert.h"
|
|
|
|
#include "ycbcr_to_rgb565.h"
|
2013-03-18 18:25:50 +04:00
|
|
|
#include "GeckoProfiler.h"
|
2010-08-13 17:30:02 +04:00
|
|
|
|
2011-06-18 13:04:30 +04:00
|
|
|
#ifdef XP_WIN
|
2010-08-13 17:30:02 +04:00
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#endif
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2011-09-28 02:19:24 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
2011-11-17 07:44:16 +04:00
|
|
|
using namespace mozilla::gfx;
|
2011-09-28 02:19:24 +04:00
|
|
|
|
2013-01-08 23:09:32 +04:00
|
|
|
#include "PremultiplyTables.h"
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint8_t PremultiplyValue(uint8_t a, uint8_t v) {
|
2012-12-17 04:20:01 +04:00
|
|
|
return gfxUtils::sPremultiplyTable[a*256+v];
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint8_t UnpremultiplyValue(uint8_t a, uint8_t v) {
|
2012-12-17 04:20:01 +04:00
|
|
|
return gfxUtils::sUnpremultiplyTable[a*256+v];
|
2010-05-18 08:04:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUtils::PremultiplyImageSurface(gfxImageSurface *aSourceSurface,
|
|
|
|
gfxImageSurface *aDestSurface)
|
|
|
|
{
|
|
|
|
if (!aDestSurface)
|
|
|
|
aDestSurface = aSourceSurface;
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
MOZ_ASSERT(aSourceSurface->Format() == aDestSurface->Format() &&
|
|
|
|
aSourceSurface->Width() == aDestSurface->Width() &&
|
|
|
|
aSourceSurface->Height() == aDestSurface->Height() &&
|
|
|
|
aSourceSurface->Stride() == aDestSurface->Stride(),
|
|
|
|
"Source and destination surfaces don't have identical characteristics");
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
MOZ_ASSERT(aSourceSurface->Stride() == aSourceSurface->Width() * 4,
|
|
|
|
"Source surface stride isn't tightly packed");
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
// Only premultiply ARGB32
|
|
|
|
if (aSourceSurface->Format() != gfxASurface::ImageFormatARGB32) {
|
|
|
|
if (aDestSurface != aSourceSurface) {
|
|
|
|
memcpy(aDestSurface->Data(), aSourceSurface->Data(),
|
|
|
|
aSourceSurface->Stride() * aSourceSurface->Height());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t *src = aSourceSurface->Data();
|
|
|
|
uint8_t *dst = aDestSurface->Data();
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dim = aSourceSurface->Width() * aSourceSurface->Height();
|
|
|
|
for (uint32_t i = 0; i < dim; ++i) {
|
2010-05-18 08:04:22 +04:00
|
|
|
#ifdef IS_LITTLE_ENDIAN
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t b = *src++;
|
|
|
|
uint8_t g = *src++;
|
|
|
|
uint8_t r = *src++;
|
|
|
|
uint8_t a = *src++;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
*dst++ = PremultiplyValue(a, b);
|
|
|
|
*dst++ = PremultiplyValue(a, g);
|
|
|
|
*dst++ = PremultiplyValue(a, r);
|
|
|
|
*dst++ = a;
|
|
|
|
#else
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t a = *src++;
|
|
|
|
uint8_t r = *src++;
|
|
|
|
uint8_t g = *src++;
|
|
|
|
uint8_t b = *src++;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
*dst++ = a;
|
|
|
|
*dst++ = PremultiplyValue(a, r);
|
|
|
|
*dst++ = PremultiplyValue(a, g);
|
|
|
|
*dst++ = PremultiplyValue(a, b);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUtils::UnpremultiplyImageSurface(gfxImageSurface *aSourceSurface,
|
|
|
|
gfxImageSurface *aDestSurface)
|
|
|
|
{
|
|
|
|
if (!aDestSurface)
|
|
|
|
aDestSurface = aSourceSurface;
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
MOZ_ASSERT(aSourceSurface->Format() == aDestSurface->Format() &&
|
|
|
|
aSourceSurface->Width() == aDestSurface->Width() &&
|
|
|
|
aSourceSurface->Height() == aDestSurface->Height() &&
|
|
|
|
aSourceSurface->Stride() == aDestSurface->Stride(),
|
|
|
|
"Source and destination surfaces don't have identical characteristics");
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
MOZ_ASSERT(aSourceSurface->Stride() == aSourceSurface->Width() * 4,
|
|
|
|
"Source surface stride isn't tightly packed");
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
// Only premultiply ARGB32
|
|
|
|
if (aSourceSurface->Format() != gfxASurface::ImageFormatARGB32) {
|
|
|
|
if (aDestSurface != aSourceSurface) {
|
|
|
|
memcpy(aDestSurface->Data(), aSourceSurface->Data(),
|
|
|
|
aSourceSurface->Stride() * aSourceSurface->Height());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t *src = aSourceSurface->Data();
|
|
|
|
uint8_t *dst = aDestSurface->Data();
|
2010-05-18 08:04:22 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dim = aSourceSurface->Width() * aSourceSurface->Height();
|
|
|
|
for (uint32_t i = 0; i < dim; ++i) {
|
2010-05-18 08:04:22 +04:00
|
|
|
#ifdef IS_LITTLE_ENDIAN
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t b = *src++;
|
|
|
|
uint8_t g = *src++;
|
|
|
|
uint8_t r = *src++;
|
|
|
|
uint8_t a = *src++;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
*dst++ = UnpremultiplyValue(a, b);
|
|
|
|
*dst++ = UnpremultiplyValue(a, g);
|
|
|
|
*dst++ = UnpremultiplyValue(a, r);
|
|
|
|
*dst++ = a;
|
|
|
|
#else
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t a = *src++;
|
|
|
|
uint8_t r = *src++;
|
|
|
|
uint8_t g = *src++;
|
|
|
|
uint8_t b = *src++;
|
2010-05-18 08:04:22 +04:00
|
|
|
|
|
|
|
*dst++ = a;
|
|
|
|
*dst++ = UnpremultiplyValue(a, r);
|
|
|
|
*dst++ = UnpremultiplyValue(a, g);
|
|
|
|
*dst++ = UnpremultiplyValue(a, b);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2010-08-13 17:30:02 +04:00
|
|
|
|
2012-03-24 02:10:50 +04:00
|
|
|
void
|
|
|
|
gfxUtils::ConvertBGRAtoRGBA(gfxImageSurface *aSourceSurface,
|
|
|
|
gfxImageSurface *aDestSurface) {
|
|
|
|
if (!aDestSurface)
|
|
|
|
aDestSurface = aSourceSurface;
|
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
MOZ_ASSERT(aSourceSurface->Format() == aDestSurface->Format() &&
|
|
|
|
aSourceSurface->Width() == aDestSurface->Width() &&
|
|
|
|
aSourceSurface->Height() == aDestSurface->Height() &&
|
|
|
|
aSourceSurface->Stride() == aDestSurface->Stride(),
|
|
|
|
"Source and destination surfaces don't have identical characteristics");
|
2012-03-24 02:10:50 +04:00
|
|
|
|
2013-02-14 03:26:24 +04:00
|
|
|
MOZ_ASSERT(aSourceSurface->Stride() == aSourceSurface->Width() * 4,
|
|
|
|
"Source surface stride isn't tightly packed");
|
2012-03-24 02:10:50 +04:00
|
|
|
|
2013-07-30 00:24:57 +04:00
|
|
|
MOZ_ASSERT(aSourceSurface->Format() == gfxASurface::ImageFormatARGB32 || aSourceSurface->Format() == gfxASurface::ImageFormatRGB24,
|
|
|
|
"Surfaces must be ARGB32 or RGB24");
|
2012-03-24 02:10:50 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t *src = aSourceSurface->Data();
|
|
|
|
uint8_t *dst = aDestSurface->Data();
|
2012-03-24 02:10:50 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dim = aSourceSurface->Width() * aSourceSurface->Height();
|
|
|
|
uint8_t *srcEnd = src + 4*dim;
|
2012-03-24 02:10:50 +04:00
|
|
|
|
|
|
|
if (src == dst) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t buffer[4];
|
2012-03-24 02:10:50 +04:00
|
|
|
for (; src != srcEnd; src += 4) {
|
|
|
|
buffer[0] = src[2];
|
|
|
|
buffer[1] = src[1];
|
|
|
|
buffer[2] = src[0];
|
|
|
|
|
|
|
|
src[0] = buffer[0];
|
|
|
|
src[1] = buffer[1];
|
|
|
|
src[2] = buffer[2];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (; src != srcEnd; src += 4, dst += 4) {
|
|
|
|
dst[0] = src[2];
|
|
|
|
dst[1] = src[1];
|
|
|
|
dst[2] = src[0];
|
|
|
|
dst[3] = src[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2010-08-13 17:30:02 +04:00
|
|
|
IsSafeImageTransformComponent(gfxFloat aValue)
|
|
|
|
{
|
|
|
|
return aValue >= -32768 && aValue <= 32767;
|
|
|
|
}
|
|
|
|
|
2010-10-08 20:02:58 +04:00
|
|
|
/**
|
|
|
|
* This returns the fastest operator to use for solid surfaces which have no
|
|
|
|
* alpha channel or their alpha channel is uniformly opaque.
|
|
|
|
* This differs per render mode.
|
|
|
|
*/
|
|
|
|
static gfxContext::GraphicsOperator
|
|
|
|
OptimalFillOperator()
|
|
|
|
{
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (gfxWindowsPlatform::GetPlatform()->GetRenderMode() ==
|
|
|
|
gfxWindowsPlatform::RENDER_DIRECT2D) {
|
|
|
|
// D2D -really- hates operator source.
|
|
|
|
return gfxContext::OPERATOR_OVER;
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
return gfxContext::OPERATOR_SOURCE;
|
|
|
|
#ifdef XP_WIN
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-01-22 01:54:42 +04:00
|
|
|
#ifndef MOZ_GFX_OPTIMIZE_MOBILE
|
2010-08-13 17:30:02 +04:00
|
|
|
// EXTEND_PAD won't help us here; we have to create a temporary surface to hold
|
|
|
|
// the subimage of pixels we're allowed to sample.
|
2010-08-13 17:30:27 +04:00
|
|
|
static already_AddRefed<gfxDrawable>
|
|
|
|
CreateSamplingRestrictedDrawable(gfxDrawable* aDrawable,
|
|
|
|
gfxContext* aContext,
|
|
|
|
const gfxMatrix& aUserSpaceToImageSpace,
|
|
|
|
const gfxRect& aSourceRect,
|
|
|
|
const gfxRect& aSubimage,
|
|
|
|
const gfxImageSurface::gfxImageFormat aFormat)
|
2010-08-13 17:30:02 +04:00
|
|
|
{
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("gfxUtils", "CreateSamplingRestricedDrawable");
|
2010-08-13 17:30:02 +04:00
|
|
|
gfxRect userSpaceClipExtents = aContext->GetClipExtents();
|
|
|
|
// This isn't optimal --- if aContext has a rotation then GetClipExtents
|
|
|
|
// will have to do a bounding-box computation, and TransformBounds might
|
|
|
|
// too, so we could get a better result if we computed image space clip
|
|
|
|
// extents in one go --- but it doesn't really matter and this is easier
|
|
|
|
// to understand.
|
|
|
|
gfxRect imageSpaceClipExtents =
|
|
|
|
aUserSpaceToImageSpace.TransformBounds(userSpaceClipExtents);
|
|
|
|
// Inflate by one pixel because bilinear filtering will sample at most
|
|
|
|
// one pixel beyond the computed image pixel coordinate.
|
2011-04-19 07:07:51 +04:00
|
|
|
imageSpaceClipExtents.Inflate(1.0);
|
2010-08-13 17:30:02 +04:00
|
|
|
|
|
|
|
gfxRect needed = imageSpaceClipExtents.Intersect(aSourceRect);
|
|
|
|
needed = needed.Intersect(aSubimage);
|
|
|
|
needed.RoundOut();
|
|
|
|
|
|
|
|
// if 'needed' is empty, nothing will be drawn since aFill
|
|
|
|
// must be entirely outside the clip region, so it doesn't
|
|
|
|
// matter what we do here, but we should avoid trying to
|
|
|
|
// create a zero-size surface.
|
|
|
|
if (needed.IsEmpty())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-08-13 17:30:02 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxIntSize size(int32_t(needed.Width()), int32_t(needed.Height()));
|
2010-08-13 17:30:02 +04:00
|
|
|
nsRefPtr<gfxASurface> temp =
|
2010-09-17 01:34:53 +04:00
|
|
|
gfxPlatform::GetPlatform()->CreateOffscreenSurface(size, gfxASurface::ContentFromFormat(aFormat));
|
2010-08-13 17:30:02 +04:00
|
|
|
if (!temp || temp->CairoStatus())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-08-13 17:30:02 +04:00
|
|
|
|
2010-10-15 14:20:22 +04:00
|
|
|
nsRefPtr<gfxContext> tmpCtx = new gfxContext(temp);
|
|
|
|
tmpCtx->SetOperator(OptimalFillOperator());
|
2011-10-17 18:59:28 +04:00
|
|
|
aDrawable->Draw(tmpCtx, needed - needed.TopLeft(), true,
|
2011-04-19 07:07:21 +04:00
|
|
|
gfxPattern::FILTER_FAST, gfxMatrix().Translate(needed.TopLeft()));
|
2010-08-13 17:30:02 +04:00
|
|
|
|
2010-08-13 17:30:27 +04:00
|
|
|
nsRefPtr<gfxDrawable> drawable =
|
2011-04-19 07:07:21 +04:00
|
|
|
new gfxSurfaceDrawable(temp, size, gfxMatrix().Translate(-needed.TopLeft()));
|
2010-08-13 17:30:27 +04:00
|
|
|
return drawable.forget();
|
2010-08-13 17:30:02 +04:00
|
|
|
}
|
2013-01-22 01:54:42 +04:00
|
|
|
#endif // !MOZ_GFX_OPTIMIZE_MOBILE
|
2010-08-13 17:30:02 +04:00
|
|
|
|
|
|
|
// working around cairo/pixman bug (bug 364968)
|
|
|
|
// Our device-space-to-image-space transform may not be acceptable to pixman.
|
2013-04-12 07:20:37 +04:00
|
|
|
struct MOZ_STACK_CLASS AutoCairoPixmanBugWorkaround
|
2010-08-13 17:30:02 +04:00
|
|
|
{
|
|
|
|
AutoCairoPixmanBugWorkaround(gfxContext* aContext,
|
|
|
|
const gfxMatrix& aDeviceSpaceToImageSpace,
|
|
|
|
const gfxRect& aFill,
|
2012-01-05 11:17:51 +04:00
|
|
|
const gfxASurface* aSurface)
|
2011-10-17 18:59:28 +04:00
|
|
|
: mContext(aContext), mSucceeded(true), mPushedGroup(false)
|
2010-08-13 17:30:02 +04:00
|
|
|
{
|
|
|
|
// Quartz's limits for matrix are much larger than pixman
|
2012-01-05 11:17:51 +04:00
|
|
|
if (!aSurface || aSurface->GetType() == gfxASurface::SurfaceTypeQuartz)
|
2010-08-13 17:30:02 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!IsSafeImageTransformComponent(aDeviceSpaceToImageSpace.xx) ||
|
|
|
|
!IsSafeImageTransformComponent(aDeviceSpaceToImageSpace.xy) ||
|
|
|
|
!IsSafeImageTransformComponent(aDeviceSpaceToImageSpace.yx) ||
|
|
|
|
!IsSafeImageTransformComponent(aDeviceSpaceToImageSpace.yy)) {
|
|
|
|
NS_WARNING("Scaling up too much, bailing out");
|
2011-10-17 18:59:28 +04:00
|
|
|
mSucceeded = false;
|
2010-08-13 17:30:02 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsSafeImageTransformComponent(aDeviceSpaceToImageSpace.x0) &&
|
|
|
|
IsSafeImageTransformComponent(aDeviceSpaceToImageSpace.y0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// We'll push a group, which will hopefully reduce our transform's
|
|
|
|
// translation so it's in bounds.
|
|
|
|
gfxMatrix currentMatrix = mContext->CurrentMatrix();
|
|
|
|
mContext->Save();
|
|
|
|
|
|
|
|
// Clip the rounded-out-to-device-pixels bounds of the
|
|
|
|
// transformed fill area. This is the area for the group we
|
|
|
|
// want to push.
|
|
|
|
mContext->IdentityMatrix();
|
|
|
|
gfxRect bounds = currentMatrix.TransformBounds(aFill);
|
|
|
|
bounds.RoundOut();
|
|
|
|
mContext->Clip(bounds);
|
|
|
|
mContext->SetMatrix(currentMatrix);
|
|
|
|
mContext->PushGroup(gfxASurface::CONTENT_COLOR_ALPHA);
|
|
|
|
mContext->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mPushedGroup = true;
|
2010-08-13 17:30:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
~AutoCairoPixmanBugWorkaround()
|
|
|
|
{
|
|
|
|
if (mPushedGroup) {
|
|
|
|
mContext->PopGroupToSource();
|
|
|
|
mContext->Paint();
|
|
|
|
mContext->Restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool PushedGroup() { return mPushedGroup; }
|
|
|
|
bool Succeeded() { return mSucceeded; }
|
2010-08-13 17:30:02 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
gfxContext* mContext;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSucceeded;
|
|
|
|
bool mPushedGroup;
|
2010-08-13 17:30:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static gfxMatrix
|
|
|
|
DeviceToImageTransform(gfxContext* aContext,
|
|
|
|
const gfxMatrix& aUserSpaceToImageSpace)
|
|
|
|
{
|
|
|
|
gfxFloat deviceX, deviceY;
|
|
|
|
nsRefPtr<gfxASurface> currentTarget =
|
|
|
|
aContext->CurrentSurface(&deviceX, &deviceY);
|
|
|
|
gfxMatrix currentMatrix = aContext->CurrentMatrix();
|
|
|
|
gfxMatrix deviceToUser = gfxMatrix(currentMatrix).Invert();
|
|
|
|
deviceToUser.Translate(-gfxPoint(-deviceX, -deviceY));
|
|
|
|
return gfxMatrix(deviceToUser).Multiply(aUserSpaceToImageSpace);
|
|
|
|
}
|
|
|
|
|
2012-05-02 00:35:04 +04:00
|
|
|
/* These heuristics are based on Source/WebCore/platform/graphics/skia/ImageSkia.cpp:computeResamplingMode() */
|
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
static gfxPattern::GraphicsFilter ReduceResamplingFilter(gfxPattern::GraphicsFilter aFilter,
|
|
|
|
int aImgWidth, int aImgHeight,
|
|
|
|
float aSourceWidth, float aSourceHeight)
|
|
|
|
{
|
|
|
|
// Images smaller than this in either direction are considered "small" and
|
|
|
|
// are not resampled ever (see below).
|
|
|
|
const int kSmallImageSizeThreshold = 8;
|
|
|
|
|
|
|
|
// The amount an image can be stretched in a single direction before we
|
|
|
|
// say that it is being stretched so much that it must be a line or
|
|
|
|
// background that doesn't need resampling.
|
|
|
|
const float kLargeStretch = 3.0f;
|
|
|
|
|
|
|
|
if (aImgWidth <= kSmallImageSizeThreshold
|
|
|
|
|| aImgHeight <= kSmallImageSizeThreshold) {
|
|
|
|
// Never resample small images. These are often used for borders and
|
|
|
|
// rules (think 1x1 images used to make lines).
|
|
|
|
return gfxPattern::FILTER_NEAREST;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aImgHeight * kLargeStretch <= aSourceHeight || aImgWidth * kLargeStretch <= aSourceWidth) {
|
|
|
|
// Large image tiling detected.
|
|
|
|
|
|
|
|
// Don't resample if it is being tiled a lot in only one direction.
|
|
|
|
// This is trying to catch cases where somebody has created a border
|
|
|
|
// (which might be large) and then is stretching it to fill some part
|
|
|
|
// of the page.
|
|
|
|
if (fabs(aSourceWidth - aImgWidth)/aImgWidth < 0.5 || fabs(aSourceHeight - aImgHeight)/aImgHeight < 0.5)
|
|
|
|
return gfxPattern::FILTER_NEAREST;
|
|
|
|
|
|
|
|
// The image is growing a lot and in more than one direction. Resampling
|
|
|
|
// is slow and doesn't give us very much when growing a lot.
|
|
|
|
return aFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Some notes on other heuristics:
|
|
|
|
The Skia backend also uses nearest for backgrounds that are stretched by
|
|
|
|
a large amount. I'm not sure this is common enough for us to worry about
|
|
|
|
now. It also uses nearest for backgrounds/avoids high quality for images
|
|
|
|
that are very slightly scaled. I'm also not sure that very slightly
|
|
|
|
scaled backgrounds are common enough us to worry about.
|
|
|
|
|
|
|
|
We don't currently have much support for doing high quality interpolation.
|
|
|
|
The only place this currently happens is on Quartz and we don't have as
|
|
|
|
much control over it as would be needed. Webkit avoids using high quality
|
|
|
|
resampling during load. It also avoids high quality if the transformation
|
|
|
|
is not just a scale and translation
|
|
|
|
|
|
|
|
WebKit bug #40045 added code to avoid resampling different parts
|
|
|
|
of an image with different methods by using a resampling hint size.
|
|
|
|
It currently looks unused in WebKit but it's something to watch out for.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return aFilter;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static gfxPattern::GraphicsFilter ReduceResamplingFilter(gfxPattern::GraphicsFilter aFilter,
|
|
|
|
int aImgWidth, int aImgHeight,
|
|
|
|
int aSourceWidth, int aSourceHeight)
|
|
|
|
{
|
|
|
|
// Just pass the filter through unchanged
|
|
|
|
return aFilter;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-13 17:30:02 +04:00
|
|
|
/* static */ void
|
|
|
|
gfxUtils::DrawPixelSnapped(gfxContext* aContext,
|
2010-08-13 17:30:27 +04:00
|
|
|
gfxDrawable* aDrawable,
|
2010-08-13 17:30:02 +04:00
|
|
|
const gfxMatrix& aUserSpaceToImageSpace,
|
|
|
|
const gfxRect& aSubimage,
|
|
|
|
const gfxRect& aSourceRect,
|
|
|
|
const gfxRect& aImageRect,
|
|
|
|
const gfxRect& aFill,
|
|
|
|
const gfxImageSurface::gfxImageFormat aFormat,
|
2012-05-02 00:35:04 +04:00
|
|
|
gfxPattern::GraphicsFilter aFilter,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aImageFlags)
|
2010-08-13 17:30:02 +04:00
|
|
|
{
|
2013-03-16 08:47:02 +04:00
|
|
|
PROFILER_LABEL("gfxUtils", "DrawPixelSnapped");
|
2012-04-18 02:04:15 +04:00
|
|
|
bool doTile = !aImageRect.Contains(aSourceRect) &&
|
|
|
|
!(aImageFlags & imgIContainer::FLAG_CLAMP);
|
2010-08-13 17:30:02 +04:00
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> currentTarget = aContext->CurrentSurface();
|
|
|
|
gfxMatrix deviceSpaceToImageSpace =
|
|
|
|
DeviceToImageTransform(aContext, aUserSpaceToImageSpace);
|
|
|
|
|
|
|
|
AutoCairoPixmanBugWorkaround workaround(aContext, deviceSpaceToImageSpace,
|
2012-01-05 11:17:51 +04:00
|
|
|
aFill, currentTarget);
|
2010-08-13 17:30:02 +04:00
|
|
|
if (!workaround.Succeeded())
|
|
|
|
return;
|
|
|
|
|
2010-08-13 17:30:27 +04:00
|
|
|
nsRefPtr<gfxDrawable> drawable = aDrawable;
|
2010-08-13 17:30:02 +04:00
|
|
|
|
2012-05-02 00:35:04 +04:00
|
|
|
aFilter = ReduceResamplingFilter(aFilter, aImageRect.Width(), aImageRect.Height(), aSourceRect.Width(), aSourceRect.Height());
|
|
|
|
|
2012-05-28 05:11:18 +04:00
|
|
|
gfxMatrix userSpaceToImageSpace = aUserSpaceToImageSpace;
|
|
|
|
|
2012-05-16 18:03:08 +04:00
|
|
|
// On Mobile, we don't ever want to do this; it has the potential for
|
|
|
|
// allocating very large temporary surfaces, especially since we'll
|
|
|
|
// do full-page snapshots often (see bug 749426).
|
2012-05-28 05:11:18 +04:00
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
// If the pattern translation is large we can get into trouble with pixman's
|
|
|
|
// 16 bit coordinate limits. For now, we only do this on platforms where
|
|
|
|
// we know we have the pixman limits. 16384.0 is a somewhat arbitrary
|
|
|
|
// large number to make sure we avoid the expensive fmod when we can, but
|
|
|
|
// still maintain a safe margin from the actual limit
|
|
|
|
if (doTile && (userSpaceToImageSpace.y0 > 16384.0 || userSpaceToImageSpace.x0 > 16384.0)) {
|
|
|
|
userSpaceToImageSpace.x0 = fmod(userSpaceToImageSpace.x0, aImageRect.width);
|
|
|
|
userSpaceToImageSpace.y0 = fmod(userSpaceToImageSpace.y0, aImageRect.height);
|
|
|
|
}
|
|
|
|
#else
|
2010-08-13 17:30:02 +04:00
|
|
|
// OK now, the hard part left is to account for the subimage sampling
|
|
|
|
// restriction. If all the transforms involved are just integer
|
|
|
|
// translations, then we assume no resampling will occur so there's
|
|
|
|
// nothing to do.
|
|
|
|
// XXX if only we had source-clipping in cairo!
|
2010-08-13 17:30:27 +04:00
|
|
|
if (aContext->CurrentMatrix().HasNonIntegerTranslation() ||
|
|
|
|
aUserSpaceToImageSpace.HasNonIntegerTranslation()) {
|
2010-08-13 17:30:02 +04:00
|
|
|
if (doTile || !aSubimage.Contains(aImageRect)) {
|
2010-08-13 17:30:27 +04:00
|
|
|
nsRefPtr<gfxDrawable> restrictedDrawable =
|
|
|
|
CreateSamplingRestrictedDrawable(aDrawable, aContext,
|
|
|
|
aUserSpaceToImageSpace, aSourceRect,
|
|
|
|
aSubimage, aFormat);
|
|
|
|
if (restrictedDrawable) {
|
|
|
|
drawable.swap(restrictedDrawable);
|
2010-08-13 17:30:02 +04:00
|
|
|
}
|
|
|
|
}
|
2010-08-13 17:30:27 +04:00
|
|
|
// We no longer need to tile: Either we never needed to, or we already
|
|
|
|
// filled a surface with the tiled pattern; this surface can now be
|
|
|
|
// drawn without tiling.
|
2011-10-17 18:59:28 +04:00
|
|
|
doTile = false;
|
2010-08-13 17:30:02 +04:00
|
|
|
}
|
2012-05-16 18:03:08 +04:00
|
|
|
#endif
|
2010-08-13 17:30:02 +04:00
|
|
|
|
|
|
|
gfxContext::GraphicsOperator op = aContext->CurrentOperator();
|
|
|
|
if ((op == gfxContext::OPERATOR_OVER || workaround.PushedGroup()) &&
|
|
|
|
aFormat == gfxASurface::ImageFormatRGB24) {
|
|
|
|
aContext->SetOperator(OptimalFillOperator());
|
|
|
|
}
|
|
|
|
|
2012-05-28 05:11:18 +04:00
|
|
|
drawable->Draw(aContext, aFill, doTile, aFilter, userSpaceToImageSpace);
|
2010-08-13 17:30:02 +04:00
|
|
|
|
|
|
|
aContext->SetOperator(op);
|
|
|
|
}
|
|
|
|
|
2010-09-08 04:36:57 +04:00
|
|
|
/* static */ int
|
|
|
|
gfxUtils::ImageFormatToDepth(gfxASurface::gfxImageFormat aFormat)
|
|
|
|
{
|
|
|
|
switch (aFormat) {
|
|
|
|
case gfxASurface::ImageFormatARGB32:
|
|
|
|
return 32;
|
|
|
|
case gfxASurface::ImageFormatRGB24:
|
|
|
|
return 24;
|
|
|
|
case gfxASurface::ImageFormatRGB16_565:
|
|
|
|
return 16;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2011-01-26 09:26:37 +03:00
|
|
|
|
2010-09-03 06:31:42 +04:00
|
|
|
static void
|
2011-01-26 09:26:37 +03:00
|
|
|
PathFromRegionInternal(gfxContext* aContext, const nsIntRegion& aRegion,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aSnap)
|
2010-09-03 06:31:42 +04:00
|
|
|
{
|
|
|
|
aContext->NewPath();
|
|
|
|
nsIntRegionRectIterator iter(aRegion);
|
|
|
|
const nsIntRect* r;
|
2012-07-30 18:20:58 +04:00
|
|
|
while ((r = iter.Next()) != nullptr) {
|
2010-09-03 06:31:42 +04:00
|
|
|
aContext->Rectangle(gfxRect(r->x, r->y, r->width, r->height), aSnap);
|
|
|
|
}
|
2011-01-26 09:26:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ClipToRegionInternal(gfxContext* aContext, const nsIntRegion& aRegion,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aSnap)
|
2011-01-26 09:26:37 +03:00
|
|
|
{
|
|
|
|
PathFromRegionInternal(aContext, aRegion, aSnap);
|
2010-09-03 06:31:42 +04:00
|
|
|
aContext->Clip();
|
|
|
|
}
|
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
static TemporaryRef<Path>
|
|
|
|
PathFromRegionInternal(gfx::DrawTarget* aTarget, const nsIntRegion& aRegion,
|
|
|
|
bool aSnap)
|
|
|
|
{
|
|
|
|
Matrix mat = aTarget->GetTransform();
|
|
|
|
const gfxFloat epsilon = 0.000001;
|
|
|
|
#define WITHIN_E(a,b) (fabs((a)-(b)) < epsilon)
|
|
|
|
// We're essentially duplicating the logic in UserToDevicePixelSnapped here.
|
|
|
|
bool shouldNotSnap = !aSnap || (WITHIN_E(mat._11,1.0) &&
|
|
|
|
WITHIN_E(mat._22,1.0) &&
|
|
|
|
WITHIN_E(mat._12,0.0) &&
|
|
|
|
WITHIN_E(mat._21,0.0));
|
|
|
|
#undef WITHIN_E
|
|
|
|
|
|
|
|
RefPtr<PathBuilder> pb = aTarget->CreatePathBuilder();
|
|
|
|
nsIntRegionRectIterator iter(aRegion);
|
|
|
|
|
|
|
|
const nsIntRect* r;
|
|
|
|
if (shouldNotSnap) {
|
|
|
|
while ((r = iter.Next()) != nullptr) {
|
|
|
|
pb->MoveTo(Point(r->x, r->y));
|
|
|
|
pb->LineTo(Point(r->XMost(), r->y));
|
|
|
|
pb->LineTo(Point(r->XMost(), r->YMost()));
|
|
|
|
pb->LineTo(Point(r->x, r->YMost()));
|
|
|
|
pb->Close();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while ((r = iter.Next()) != nullptr) {
|
|
|
|
Rect rect(r->x, r->y, r->width, r->height);
|
|
|
|
|
|
|
|
rect.Round();
|
|
|
|
pb->MoveTo(rect.TopLeft());
|
|
|
|
pb->LineTo(rect.TopRight());
|
|
|
|
pb->LineTo(rect.BottomRight());
|
|
|
|
pb->LineTo(rect.BottomLeft());
|
|
|
|
pb->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RefPtr<Path> path = pb->Finish();
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ClipToRegionInternal(gfx::DrawTarget* aTarget, const nsIntRegion& aRegion,
|
|
|
|
bool aSnap)
|
|
|
|
{
|
|
|
|
RefPtr<Path> path = PathFromRegionInternal(aTarget, aRegion, aSnap);
|
|
|
|
aTarget->PushClip(path);
|
|
|
|
}
|
|
|
|
|
2010-09-03 06:31:42 +04:00
|
|
|
/*static*/ void
|
|
|
|
gfxUtils::ClipToRegion(gfxContext* aContext, const nsIntRegion& aRegion)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
ClipToRegionInternal(aContext, aRegion, false);
|
2010-09-03 06:31:42 +04:00
|
|
|
}
|
|
|
|
|
2013-07-09 08:21:05 +04:00
|
|
|
/*static*/ void
|
|
|
|
gfxUtils::ClipToRegion(DrawTarget* aTarget, const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
ClipToRegionInternal(aTarget, aRegion, false);
|
|
|
|
}
|
|
|
|
|
2010-09-03 06:31:42 +04:00
|
|
|
/*static*/ void
|
|
|
|
gfxUtils::ClipToRegionSnapped(gfxContext* aContext, const nsIntRegion& aRegion)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
ClipToRegionInternal(aContext, aRegion, true);
|
2010-09-03 06:31:42 +04:00
|
|
|
}
|
2010-11-24 12:35:21 +03:00
|
|
|
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
/*static*/ void
|
|
|
|
gfxUtils::ClipToRegionSnapped(DrawTarget* aTarget, const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
ClipToRegionInternal(aTarget, aRegion, true);
|
|
|
|
}
|
|
|
|
|
2011-02-08 23:35:54 +03:00
|
|
|
/*static*/ gfxFloat
|
|
|
|
gfxUtils::ClampToScaleFactor(gfxFloat aVal)
|
|
|
|
{
|
|
|
|
// Arbitary scale factor limitation. We can increase this
|
|
|
|
// for better scaling performance at the cost of worse
|
|
|
|
// quality.
|
|
|
|
static const gfxFloat kScaleResolution = 2;
|
|
|
|
|
|
|
|
// Negative scaling is just a flip and irrelevant to
|
|
|
|
// our resolution calculation.
|
|
|
|
if (aVal < 0.0) {
|
|
|
|
aVal = -aVal;
|
|
|
|
}
|
|
|
|
|
2012-12-17 08:30:51 +04:00
|
|
|
bool inverse = false;
|
|
|
|
if (aVal < 1.0) {
|
|
|
|
inverse = true;
|
|
|
|
aVal = 1 / aVal;
|
|
|
|
}
|
|
|
|
|
2011-02-08 23:35:54 +03:00
|
|
|
gfxFloat power = log(aVal)/log(kScaleResolution);
|
|
|
|
|
|
|
|
// If power is within 1e-6 of an integer, round to nearest to
|
|
|
|
// prevent floating point errors, otherwise round up to the
|
|
|
|
// next integer value.
|
|
|
|
if (fabs(power - NS_round(power)) < 1e-6) {
|
|
|
|
power = NS_round(power);
|
2012-12-17 08:30:51 +04:00
|
|
|
} else if (inverse) {
|
|
|
|
power = floor(power);
|
2011-02-08 23:35:54 +03:00
|
|
|
} else {
|
2011-05-30 23:08:55 +04:00
|
|
|
power = ceil(power);
|
2011-02-08 23:35:54 +03:00
|
|
|
}
|
|
|
|
|
2012-04-30 01:41:13 +04:00
|
|
|
gfxFloat scale = pow(kScaleResolution, power);
|
|
|
|
|
2012-12-17 08:30:51 +04:00
|
|
|
if (inverse) {
|
|
|
|
scale = 1 / scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
return scale;
|
2011-02-08 23:35:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-26 09:26:37 +03:00
|
|
|
/*static*/ void
|
|
|
|
gfxUtils::PathFromRegion(gfxContext* aContext, const nsIntRegion& aRegion)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
PathFromRegionInternal(aContext, aRegion, false);
|
2011-01-26 09:26:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ void
|
|
|
|
gfxUtils::PathFromRegionSnapped(gfxContext* aContext, const nsIntRegion& aRegion)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
PathFromRegionInternal(aContext, aRegion, true);
|
2011-01-26 09:26:37 +03:00
|
|
|
}
|
|
|
|
|
2012-12-07 03:58:13 +04:00
|
|
|
gfxMatrix
|
|
|
|
gfxUtils::TransformRectToRect(const gfxRect& aFrom, const gfxPoint& aToTopLeft,
|
|
|
|
const gfxPoint& aToTopRight, const gfxPoint& aToBottomRight)
|
|
|
|
{
|
|
|
|
gfxMatrix m;
|
|
|
|
if (aToTopRight.y == aToTopLeft.y && aToTopRight.x == aToBottomRight.x) {
|
|
|
|
// Not a rotation, so xy and yx are zero
|
|
|
|
m.xy = m.yx = 0.0;
|
|
|
|
m.xx = (aToBottomRight.x - aToTopLeft.x)/aFrom.width;
|
|
|
|
m.yy = (aToBottomRight.y - aToTopLeft.y)/aFrom.height;
|
|
|
|
m.x0 = aToTopLeft.x - m.xx*aFrom.x;
|
|
|
|
m.y0 = aToTopLeft.y - m.yy*aFrom.y;
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(aToTopRight.y == aToBottomRight.y && aToTopRight.x == aToTopLeft.x,
|
|
|
|
"Destination rectangle not axis-aligned");
|
|
|
|
m.xx = m.yy = 0.0;
|
|
|
|
m.xy = (aToBottomRight.x - aToTopLeft.x)/aFrom.height;
|
|
|
|
m.yx = (aToBottomRight.y - aToTopLeft.y)/aFrom.width;
|
|
|
|
m.x0 = aToTopLeft.x - m.xy*aFrom.y;
|
|
|
|
m.y0 = aToTopLeft.y - m.yx*aFrom.x;
|
|
|
|
}
|
|
|
|
return m;
|
|
|
|
}
|
2011-01-26 09:26:37 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-11-24 12:35:21 +03:00
|
|
|
gfxUtils::GfxRectToIntRect(const gfxRect& aIn, nsIntRect* aOut)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
*aOut = nsIntRect(int32_t(aIn.X()), int32_t(aIn.Y()),
|
|
|
|
int32_t(aIn.Width()), int32_t(aIn.Height()));
|
2011-04-19 07:07:23 +04:00
|
|
|
return gfxRect(aOut->x, aOut->y, aOut->width, aOut->height).IsEqualEdges(aIn);
|
2010-11-24 12:35:21 +03:00
|
|
|
}
|
|
|
|
|
2011-09-28 02:19:24 +04:00
|
|
|
void
|
|
|
|
gfxUtils::GetYCbCrToRGBDestFormatAndSize(const PlanarYCbCrImage::Data& aData,
|
|
|
|
gfxASurface::gfxImageFormat& aSuggestedFormat,
|
|
|
|
gfxIntSize& aSuggestedSize)
|
|
|
|
{
|
|
|
|
gfx::YUVType yuvtype =
|
|
|
|
gfx::TypeFromSize(aData.mYSize.width,
|
|
|
|
aData.mYSize.height,
|
|
|
|
aData.mCbCrSize.width,
|
|
|
|
aData.mCbCrSize.height);
|
|
|
|
|
|
|
|
// 'prescale' is true if the scaling is to be done as part of the
|
|
|
|
// YCbCr to RGB conversion rather than on the RGB data when rendered.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool prescale = aSuggestedSize.width > 0 && aSuggestedSize.height > 0 &&
|
2011-09-28 02:19:24 +04:00
|
|
|
aSuggestedSize != aData.mPicSize;
|
|
|
|
|
|
|
|
if (aSuggestedFormat == gfxASurface::ImageFormatRGB16_565) {
|
|
|
|
#if defined(HAVE_YCBCR_TO_RGB565)
|
|
|
|
if (prescale &&
|
|
|
|
!gfx::IsScaleYCbCrToRGB565Fast(aData.mPicX,
|
|
|
|
aData.mPicY,
|
|
|
|
aData.mPicSize.width,
|
|
|
|
aData.mPicSize.height,
|
|
|
|
aSuggestedSize.width,
|
|
|
|
aSuggestedSize.height,
|
|
|
|
yuvtype,
|
|
|
|
gfx::FILTER_BILINEAR) &&
|
|
|
|
gfx::IsConvertYCbCrToRGB565Fast(aData.mPicX,
|
|
|
|
aData.mPicY,
|
|
|
|
aData.mPicSize.width,
|
|
|
|
aData.mPicSize.height,
|
|
|
|
yuvtype)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
prescale = false;
|
2011-09-28 02:19:24 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
// yuv2rgb16 function not available
|
|
|
|
aSuggestedFormat = gfxASurface::ImageFormatRGB24;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (aSuggestedFormat != gfxASurface::ImageFormatRGB24) {
|
|
|
|
// No other formats are currently supported.
|
|
|
|
aSuggestedFormat = gfxASurface::ImageFormatRGB24;
|
|
|
|
}
|
|
|
|
if (aSuggestedFormat == gfxASurface::ImageFormatRGB24) {
|
|
|
|
/* ScaleYCbCrToRGB32 does not support a picture offset, nor 4:4:4 data.
|
|
|
|
See bugs 639415 and 640073. */
|
|
|
|
if (aData.mPicX != 0 || aData.mPicY != 0 || yuvtype == gfx::YV24)
|
2011-10-17 18:59:28 +04:00
|
|
|
prescale = false;
|
2011-09-28 02:19:24 +04:00
|
|
|
}
|
|
|
|
if (!prescale) {
|
|
|
|
aSuggestedSize = aData.mPicSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxUtils::ConvertYCbCrToRGB(const PlanarYCbCrImage::Data& aData,
|
|
|
|
const gfxASurface::gfxImageFormat& aDestFormat,
|
|
|
|
const gfxIntSize& aDestSize,
|
|
|
|
unsigned char* aDestBuffer,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aStride)
|
2011-09-28 02:19:24 +04:00
|
|
|
{
|
2012-10-16 07:03:43 +04:00
|
|
|
// ConvertYCbCrToRGB et al. assume the chroma planes are rounded up if the
|
|
|
|
// luma plane is odd sized.
|
|
|
|
MOZ_ASSERT((aData.mCbCrSize.width == aData.mYSize.width ||
|
|
|
|
aData.mCbCrSize.width == (aData.mYSize.width + 1) >> 1) &&
|
|
|
|
(aData.mCbCrSize.height == aData.mYSize.height ||
|
|
|
|
aData.mCbCrSize.height == (aData.mYSize.height + 1) >> 1));
|
2011-09-28 02:19:24 +04:00
|
|
|
gfx::YUVType yuvtype =
|
|
|
|
gfx::TypeFromSize(aData.mYSize.width,
|
|
|
|
aData.mYSize.height,
|
|
|
|
aData.mCbCrSize.width,
|
|
|
|
aData.mCbCrSize.height);
|
|
|
|
|
|
|
|
// Convert from YCbCr to RGB now, scaling the image if needed.
|
|
|
|
if (aDestSize != aData.mPicSize) {
|
|
|
|
#if defined(HAVE_YCBCR_TO_RGB565)
|
|
|
|
if (aDestFormat == gfxASurface::ImageFormatRGB16_565) {
|
|
|
|
gfx::ScaleYCbCrToRGB565(aData.mYChannel,
|
|
|
|
aData.mCbChannel,
|
|
|
|
aData.mCrChannel,
|
|
|
|
aDestBuffer,
|
|
|
|
aData.mPicX,
|
|
|
|
aData.mPicY,
|
|
|
|
aData.mPicSize.width,
|
|
|
|
aData.mPicSize.height,
|
|
|
|
aDestSize.width,
|
|
|
|
aDestSize.height,
|
|
|
|
aData.mYStride,
|
|
|
|
aData.mCbCrStride,
|
|
|
|
aStride,
|
|
|
|
yuvtype,
|
|
|
|
gfx::FILTER_BILINEAR);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
gfx::ScaleYCbCrToRGB32(aData.mYChannel,
|
|
|
|
aData.mCbChannel,
|
|
|
|
aData.mCrChannel,
|
|
|
|
aDestBuffer,
|
|
|
|
aData.mPicSize.width,
|
|
|
|
aData.mPicSize.height,
|
|
|
|
aDestSize.width,
|
|
|
|
aDestSize.height,
|
|
|
|
aData.mYStride,
|
|
|
|
aData.mCbCrStride,
|
|
|
|
aStride,
|
|
|
|
yuvtype,
|
|
|
|
gfx::ROTATE_0,
|
|
|
|
gfx::FILTER_BILINEAR);
|
|
|
|
} else { // no prescale
|
|
|
|
#if defined(HAVE_YCBCR_TO_RGB565)
|
|
|
|
if (aDestFormat == gfxASurface::ImageFormatRGB16_565) {
|
|
|
|
gfx::ConvertYCbCrToRGB565(aData.mYChannel,
|
|
|
|
aData.mCbChannel,
|
|
|
|
aData.mCrChannel,
|
|
|
|
aDestBuffer,
|
|
|
|
aData.mPicX,
|
|
|
|
aData.mPicY,
|
|
|
|
aData.mPicSize.width,
|
|
|
|
aData.mPicSize.height,
|
|
|
|
aData.mYStride,
|
|
|
|
aData.mCbCrStride,
|
|
|
|
aStride,
|
|
|
|
yuvtype);
|
|
|
|
} else // aDestFormat != gfxASurface::ImageFormatRGB16_565
|
|
|
|
#endif
|
|
|
|
gfx::ConvertYCbCrToRGB32(aData.mYChannel,
|
|
|
|
aData.mCbChannel,
|
|
|
|
aData.mCrChannel,
|
|
|
|
aDestBuffer,
|
|
|
|
aData.mPicX,
|
|
|
|
aData.mPicY,
|
|
|
|
aData.mPicSize.width,
|
|
|
|
aData.mPicSize.height,
|
|
|
|
aData.mYStride,
|
|
|
|
aData.mCbCrStride,
|
|
|
|
aStride,
|
|
|
|
yuvtype);
|
|
|
|
}
|
|
|
|
}
|
2011-11-17 07:44:16 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_DUMP_PAINTING
|
|
|
|
/* static */ void
|
|
|
|
gfxUtils::WriteAsPNG(DrawTarget* aDT, const char* aFile)
|
|
|
|
{
|
|
|
|
aDT->Flush();
|
|
|
|
nsRefPtr<gfxASurface> surf = gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(aDT);
|
|
|
|
if (surf) {
|
|
|
|
surf->WriteAsPNG(aFile);
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Failed to get Thebes surface!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
gfxUtils::DumpAsDataURL(DrawTarget* aDT)
|
|
|
|
{
|
|
|
|
aDT->Flush();
|
|
|
|
nsRefPtr<gfxASurface> surf = gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(aDT);
|
|
|
|
if (surf) {
|
|
|
|
surf->DumpAsDataURL();
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Failed to get Thebes surface!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
gfxUtils::CopyAsDataURL(DrawTarget* aDT)
|
|
|
|
{
|
|
|
|
aDT->Flush();
|
|
|
|
nsRefPtr<gfxASurface> surf = gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(aDT);
|
|
|
|
if (surf) {
|
|
|
|
surf->CopyAsDataURL();
|
|
|
|
} else {
|
|
|
|
NS_WARNING("Failed to get Thebes surface!");
|
|
|
|
}
|
|
|
|
}
|
2012-03-01 12:26:09 +04:00
|
|
|
|
2012-03-28 22:10:28 +04:00
|
|
|
bool gfxUtils::sDumpPaintList = getenv("MOZ_DUMP_PAINT_LIST") != 0;
|
|
|
|
bool gfxUtils::sDumpPainting = getenv("MOZ_DUMP_PAINT") != 0;
|
2012-03-01 12:26:09 +04:00
|
|
|
bool gfxUtils::sDumpPaintingToFile = getenv("MOZ_DUMP_PAINT_TO_FILE") != 0;
|
|
|
|
FILE *gfxUtils::sDumpPaintFile = NULL;
|
2011-11-17 07:44:16 +04:00
|
|
|
#endif
|