Bug 732988 - Part 1: Add ScaleToSize API to ImageLayers. r=roc

This commit is contained in:
Bas Schouten 2012-03-11 22:33:22 +00:00
parent a6618e22c1
commit a1cb5a3d28
5 changed files with 47 additions and 18 deletions

View File

@ -581,6 +581,12 @@ private:
*/
class THEBES_API ImageLayer : public Layer {
public:
enum ScaleMode {
SCALE_NONE,
SCALE_STRETCH // Unimplemented on GL layers and e10s
// Unimplemented - SCALE_PRESERVE_ASPECT_RATIO_CONTAIN
};
/**
* CONSTRUCTION PHASE ONLY
* Set the ImageContainer. aContainer must have the same layer manager
@ -596,6 +602,17 @@ public:
*/
void SetFilter(gfxPattern::GraphicsFilter aFilter) { mFilter = aFilter; }
/**
* CONSTRUCTION PHASE ONLY
* Set the size to scale the image to and the mode at which to scale.
*/
void SetScaleToSize(const gfxIntSize &aSize, ScaleMode aMode)
{
mScaleToSize = aSize;
mScaleMode = aMode;
}
ImageContainer* GetContainer() { return mContainer; }
gfxPattern::GraphicsFilter GetFilter() { return mFilter; }
@ -620,12 +637,16 @@ public:
protected:
ImageLayer(LayerManager* aManager, void* aImplData)
: Layer(aManager, aImplData), mFilter(gfxPattern::FILTER_GOOD) {}
: Layer(aManager, aImplData), mFilter(gfxPattern::FILTER_GOOD)
, mScaleMode(SCALE_NONE) {}
virtual nsACString& PrintInfo(nsACString& aTo, const char* aPrefix);
nsRefPtr<ImageContainer> mContainer;
gfxPattern::GraphicsFilter mFilter;
gfxIntSize mScaleToSize;
ScaleMode mScaleMode;
};
/****** Image subtypes for the different formats ******/

View File

@ -867,8 +867,7 @@ BasicThebesLayerBuffer::SetBackingBufferAndUpdateFrom(
class BasicImageLayer : public ImageLayer, public BasicImplData {
public:
BasicImageLayer(BasicLayerManager* aLayerManager) :
ImageLayer(aLayerManager, static_cast<BasicImplData*>(this)),
mSize(-1, -1)
ImageLayer(aLayerManager, static_cast<BasicImplData*>(this))
{
MOZ_COUNT_CTOR(BasicImageLayer);
}
@ -901,8 +900,6 @@ protected:
already_AddRefed<gfxPattern>
GetAndPaintCurrentImage(gfxContext* aContext,
float aOpacity);
gfxIntSize mSize;
};
void
@ -926,7 +923,7 @@ BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext,
nsRefPtr<gfxASurface> surface;
AutoLockImage autoLock(mContainer, getter_AddRefs(surface));
Image *image = autoLock.GetImage();
mSize = autoLock.GetSize();
gfxIntSize size = autoLock.GetSize();
if (!surface || surface->CairoStatus()) {
return nsnull;
@ -938,6 +935,15 @@ BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext,
}
pat->SetFilter(mFilter);
gfxIntSize sourceSize = surface->GetSize();
if (mScaleMode != SCALE_NONE) {
NS_ASSERTION(mScaleMode == SCALE_STRETCH,
"No other scalemodes than stretch and none supported yet.");
gfxMatrix mat = pat->GetMatrix();
mat.Scale(float(sourceSize.width) / mScaleToSize.width, float(sourceSize.height) / mScaleToSize.height);
pat->SetMatrix(mat);
size = mScaleToSize;
}
// The visible region can extend outside the image. If we're not
// tiling, we don't want to draw into that area, so just draw within
@ -945,7 +951,7 @@ BasicImageLayer::GetAndPaintCurrentImage(gfxContext* aContext,
const nsIntRect* tileSrcRect = GetTileSourceRect();
AutoSetOperator setOperator(aContext, GetOperator());
PaintContext(pat,
tileSrcRect ? GetVisibleRegion() : nsIntRegion(nsIntRect(0, 0, mSize.width, mSize.height)),
tileSrcRect ? GetVisibleRegion() : nsIntRegion(nsIntRect(0, 0, size.width, size.height)),
tileSrcRect,
aOpacity, aContext);
@ -2469,7 +2475,8 @@ class BasicShadowableImageLayer : public BasicImageLayer,
public:
BasicShadowableImageLayer(BasicShadowLayerManager* aManager) :
BasicImageLayer(aManager),
mBufferIsOpaque(false)
mBufferIsOpaque(false),
mSize(-1, -1)
{
MOZ_COUNT_CTOR(BasicShadowableImageLayer);
}
@ -2536,6 +2543,7 @@ private:
nsRefPtr<gfxSharedImageSurface> mBackBufferU;
nsRefPtr<gfxSharedImageSurface> mBackBufferV;
gfxIntSize mCbCrSize;
gfxIntSize mSize;
};
void

View File

@ -130,6 +130,8 @@ ImageLayerD3D10::RenderLayer()
return;
}
gfxIntSize size = mScaleMode == SCALE_NONE ? image->GetSize() : mScaleToSize;
SetEffectTransformAndOpacity();
ID3D10EffectTechnique *technique;
@ -137,7 +139,6 @@ ImageLayerD3D10::RenderLayer()
if (image->GetFormat() == Image::CAIRO_SURFACE || image->GetFormat() == Image::REMOTE_IMAGE_BITMAP)
{
bool hasAlpha = false;
gfxIntSize size;
if (image->GetFormat() == Image::REMOTE_IMAGE_BITMAP) {
RemoteBitmapImage *remoteImage =
@ -154,7 +155,6 @@ ImageLayerD3D10::RenderLayer()
}
hasAlpha = remoteImage->mFormat == RemoteImageData::BGRA32;
size = remoteImage->mSize;
} else {
CairoImage *cairoImage =
static_cast<CairoImage*>(image);
@ -174,7 +174,6 @@ ImageLayerD3D10::RenderLayer()
}
hasAlpha = cairoImage->mSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA;
size = cairoImage->mSize;
}
TextureD3D10BackendData *data =
@ -286,8 +285,8 @@ ImageLayerD3D10::RenderLayer()
ShaderConstantRectD3D10(
(float)0,
(float)0,
(float)yuvImage->mSize.width,
(float)yuvImage->mSize.height)
(float)size.width,
(float)size.height)
);
effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector(

View File

@ -325,10 +325,11 @@ ImageLayerD3D9::RenderLayer()
SetShaderTransformAndOpacity();
gfxIntSize size = mScaleMode == SCALE_NONE ? image->GetSize() : mScaleToSize;
if (image->GetFormat() == Image::CAIRO_SURFACE || image->GetFormat() == Image::REMOTE_IMAGE_BITMAP)
{
bool hasAlpha = false;
gfxIntSize size;
if (image->GetFormat() == Image::REMOTE_IMAGE_BITMAP) {
RemoteBitmapImage *remoteImage =
@ -343,7 +344,6 @@ ImageLayerD3D9::RenderLayer()
}
hasAlpha = remoteImage->mFormat == RemoteImageData::BGRA32;
size = remoteImage->mSize;
} else {
CairoImage *cairoImage =
static_cast<CairoImage*>(image);
@ -361,7 +361,6 @@ ImageLayerD3D9::RenderLayer()
}
hasAlpha = cairoImage->mSurface->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA;
size = cairoImage->mSize;
}
TextureD3D9BackendData *data =
@ -433,8 +432,8 @@ ImageLayerD3D9::RenderLayer()
device()->SetVertexShaderConstantF(CBvLayerQuad,
ShaderConstantRect(0,
0,
yuvImage->mSize.width,
yuvImage->mSize.height),
size.width,
size.height),
1);
device()->SetVertexShaderConstantF(CBvTextureCoords,

View File

@ -230,6 +230,8 @@ ImageLayerOGL::RenderLayer(int,
NS_ASSERTION(image->GetFormat() != Image::REMOTE_IMAGE_BITMAP,
"Remote images aren't handled yet in OGL layers!");
NS_ASSERTION(mScaleMode == SCALE_NONE || image->GetSize() == mScaleToSize,
"Scale modes other than none not handled yet in OGL layers!");
if (image->GetFormat() == Image::PLANAR_YCBCR) {
PlanarYCbCrImage *yuvImage =