Bug 877115 - Moz2Dify GLContext and GLTextureImage. r=nical

This commit is contained in:
Adrian May 2013-08-13 15:44:53 +02:00
parent ec7e8fbbfa
commit 89808cf57b
7 changed files with 144 additions and 39 deletions

View File

@ -1994,7 +1994,7 @@ GLContext::BlitTextureImage(TextureImage *aSrc, const nsIntRect& aSrcRect,
do {
// calculate portion of the tile that is going to be painted to
nsIntRect dstSubRect;
nsIntRect dstTextureRect = aDst->GetTileRect();
nsIntRect dstTextureRect = ThebesIntRect(aDst->GetTileRect());
dstSubRect.IntersectRect(aDstRect, dstTextureRect);
// this tile is not part of the destination rectangle aDstRect
@ -2016,7 +2016,7 @@ GLContext::BlitTextureImage(TextureImage *aSrc, const nsIntRect& aSrcRect,
do {
// calculate portion of the source tile that is in the source rect
nsIntRect srcSubRect;
nsIntRect srcTextureRect = aSrc->GetTileRect();
nsIntRect srcTextureRect = ThebesIntRect(aSrc->GetTileRect());
srcSubRect.IntersectRect(aSrcRect, srcTextureRect);
// this tile is not part of the source rect

View File

@ -23,6 +23,17 @@ TextureImage::Create(GLContext* gl,
return gl->CreateTextureImage(size, contentType, wrapMode, flags);
}
// Moz2D equivalent...
already_AddRefed<TextureImage>
TextureImage::Create(GLContext* gl,
const gfx::IntSize& size,
TextureImage::ContentType contentType,
GLenum wrapMode,
TextureImage::Flags flags)
{
return Create(gl, ThebesIntSize(size), contentType, wrapMode, flags);
}
bool
TextureImage::UpdateFromDataSource(gfx::DataSourceSurface *aSurface,
const nsIntRegion* aDestRegion,
@ -42,6 +53,14 @@ TextureImage::UpdateFromDataSource(gfx::DataSourceSurface *aSurface,
return DirectUpdate(thebesSurf, destRegion, thebesSrcPoint);
}
gfx::IntRect TextureImage::GetTileRect() {
return gfx::IntRect(gfx::IntPoint(0,0), ToIntSize(mSize));
}
gfx::IntRect TextureImage::GetSrcTileRect() {
return GetTileRect();
}
BasicTextureImage::~BasicTextureImage()
{
GLContext *ctx = mGLContext;
@ -208,6 +227,49 @@ BasicTextureImage::Resize(const nsIntSize& aSize)
mSize = aSize;
}
// Moz2D equivalents...
void TextureImage::Resize(const gfx::IntSize& aSize) {
Resize(ThebesIntSize(aSize));
}
gfx::IntSize TextureImage::GetSize() const {
return ToIntSize(mSize);
}
TextureImage::TextureImage(const gfx::IntSize& aSize,
GLenum aWrapMode, ContentType aContentType,
Flags aFlags)
: mSize(ThebesIntSize(aSize))
, mWrapMode(aWrapMode)
, mContentType(aContentType)
, mFilter(gfxPattern::FILTER_GOOD)
, mFlags(aFlags)
{}
BasicTextureImage::BasicTextureImage(GLuint aTexture,
const gfx::IntSize& aSize,
GLenum aWrapMode,
ContentType aContentType,
GLContext* aContext,
TextureImage::Flags aFlags,
TextureImage::ImageFormat aImageFormat)
: TextureImage(ThebesIntSize(aSize), aWrapMode, aContentType, aFlags, aImageFormat)
, mTexture(aTexture)
, mTextureState(Created)
, mGLContext(aContext)
, mUpdateOffset(0, 0)
{}
already_AddRefed<TextureImage>
CreateBasicTextureImage(GLContext* aGL,
const gfx::IntSize& aSize,
TextureImage::ContentType aContentType,
GLenum aWrapMode,
TextureImage::Flags aFlags)
{
return CreateBasicTextureImage(aGL, ThebesIntSize(aSize), aContentType, aWrapMode, aFlags);
}
TiledTextureImage::TiledTextureImage(GLContext* aGL,
nsIntSize aSize,
TextureImage::ContentType aContentType,
@ -257,7 +319,7 @@ TiledTextureImage::DirectUpdate(gfxASurface* aSurf, const nsIntRegion& aRegion,
int oldCurrentImage = mCurrentImage;
BeginTileIteration();
do {
nsIntRect tileRect = GetSrcTileRect();
nsIntRect tileRect = ThebesIntRect(GetSrcTileRect());
int xPos = tileRect.x;
int yPos = tileRect.y;
@ -313,7 +375,8 @@ TiledTextureImage::GetUpdateRegion(nsIntRegion& aForRegion)
for (unsigned i = 0; i < mImages.Length(); i++) {
int xPos = (i % mColumns) * mTileSize;
int yPos = (i / mColumns) * mTileSize;
nsIntRect imageRect = nsIntRect(nsIntRect(nsIntPoint(xPos,yPos), mImages[i]->GetSize()));
nsIntRect imageRect = nsIntRect(nsIntPoint(xPos,yPos),
ThebesIntSize(mImages[i]->GetSize()));
if (aForRegion.Intersects(imageRect)) {
// Make a copy of the region
@ -355,7 +418,9 @@ TiledTextureImage::BeginUpdate(nsIntRegion& aRegion)
for (unsigned i = 0; i < mImages.Length(); i++) {
int xPos = (i % mColumns) * mTileSize;
int yPos = (i / mColumns) * mTileSize;
nsIntRegion imageRegion = nsIntRegion(nsIntRect(nsIntPoint(xPos,yPos), mImages[i]->GetSize()));
nsIntRegion imageRegion =
nsIntRegion(nsIntRect(nsIntPoint(xPos,yPos),
ThebesIntSize(mImages[i]->GetSize())));
// a single Image can handle this update request
if (imageRegion.Contains(aRegion)) {
@ -410,7 +475,8 @@ TiledTextureImage::EndUpdate()
for (unsigned i = 0; i < mImages.Length(); i++) {
int xPos = (i % mColumns) * mTileSize;
int yPos = (i / mColumns) * mTileSize;
nsIntRect imageRect = nsIntRect(nsIntPoint(xPos,yPos), mImages[i]->GetSize());
nsIntRect imageRect = nsIntRect(nsIntPoint(xPos,yPos),
ThebesIntSize(mImages[i]->GetSize()));
nsIntRegion subregion;
subregion.And(mUpdateRegion, imageRect);
@ -460,25 +526,25 @@ void TiledTextureImage::SetIterationCallback(TileIterationCallback aCallback,
mIterationCallbackData = aCallbackData;
}
nsIntRect TiledTextureImage::GetTileRect()
gfx::IntRect TiledTextureImage::GetTileRect()
{
if (!GetTileCount()) {
return nsIntRect();
return gfx::IntRect();
}
nsIntRect rect = mImages[mCurrentImage]->GetTileRect();
gfx::IntRect rect = mImages[mCurrentImage]->GetTileRect();
unsigned int xPos = (mCurrentImage % mColumns) * mTileSize;
unsigned int yPos = (mCurrentImage / mColumns) * mTileSize;
rect.MoveBy(xPos, yPos);
return rect;
}
nsIntRect TiledTextureImage::GetSrcTileRect()
gfx::IntRect TiledTextureImage::GetSrcTileRect()
{
nsIntRect rect = GetTileRect();
gfx::IntRect rect = GetTileRect();
unsigned int srcY = mFlags & NeedsYFlip
? mSize.height - rect.height - rect.y
: rect.y;
return nsIntRect(rect.x, srcY, rect.width, rect.height);
return gfx::IntRect(rect.x, srcY, rect.width, rect.height);
}
void

View File

@ -67,6 +67,13 @@ public:
TextureImage::ContentType aContentType,
GLenum aWrapMode,
TextureImage::Flags aFlags = TextureImage::NoFlags);
// Moz2D equivalent...
static already_AddRefed<TextureImage> Create(
GLContext* gl,
const gfx::IntSize& aSize,
TextureImage::ContentType aContentType,
GLenum aWrapMode,
TextureImage::Flags aFlags = TextureImage::NoFlags);
virtual ~TextureImage() {}
@ -133,9 +140,7 @@ public:
void* aCallbackData) {
}
virtual nsIntRect GetTileRect() {
return nsIntRect(nsIntPoint(0,0), mSize);
}
virtual gfx::IntRect GetTileRect();
virtual GLuint GetTextureID() = 0;
@ -157,6 +162,8 @@ public:
BeginUpdate(r);
EndUpdate();
}
// Moz2D equivalent...
void Resize(const gfx::IntSize& aSize);
/**
* Mark this texture as having valid contents. Call this after modifying
@ -229,7 +236,8 @@ public:
virtual already_AddRefed<gfxASurface> GetBackingSurface()
{ return nullptr; }
const nsIntSize& GetSize() const { return mSize; }
gfx::IntSize GetSize() const;
ContentType GetContentType() const { return mContentType; }
ImageFormat GetImageFormat() const { return mImageFormat; }
virtual bool InUpdate() const = 0;
@ -264,9 +272,12 @@ protected:
, mFlags(aFlags)
{}
virtual nsIntRect GetSrcTileRect() {
return nsIntRect(nsIntPoint(0,0), mSize);
}
// Moz2D equivalent...
TextureImage(const gfx::IntSize& aSize,
GLenum aWrapMode, ContentType aContentType,
Flags aFlags = NoFlags);
virtual gfx::IntRect GetSrcTileRect();
nsIntSize mSize;
GLenum mWrapMode;
@ -306,6 +317,14 @@ public:
, mUpdateOffset(0, 0)
{}
BasicTextureImage(GLuint aTexture,
const gfx::IntSize& aSize,
GLenum aWrapMode,
ContentType aContentType,
GLContext* aContext,
TextureImage::Flags aFlags = TextureImage::NoFlags,
TextureImage::ImageFormat aImageFormat = gfxASurface::ImageFormatUnknown);
virtual void BindTexture(GLenum aTextureUnit);
virtual gfxASurface* BeginUpdate(nsIntRegion& aRegion);
@ -369,7 +388,7 @@ public:
virtual bool NextTile();
virtual void SetIterationCallback(TileIterationCallback aCallback,
void* aCallbackData);
virtual nsIntRect GetTileRect();
virtual gfx::IntRect GetTileRect();
virtual GLuint GetTextureID() {
return mImages[mCurrentImage]->GetTextureID();
}
@ -379,7 +398,7 @@ public:
virtual void ApplyFilter();
protected:
virtual nsIntRect GetSrcTileRect();
virtual gfx::IntRect GetSrcTileRect();
unsigned int mCurrentImage;
TileIterationCallback mIterationCallback;
@ -411,6 +430,13 @@ CreateBasicTextureImage(GLContext* aGL,
TextureImage::Flags aFlags,
TextureImage::ImageFormat aImageFormat = gfxASurface::ImageFormatUnknown);
already_AddRefed<TextureImage>
CreateBasicTextureImage(GLContext* aGL,
const gfx::IntSize& aSize,
TextureImage::ContentType aContentType,
GLenum aWrapMode,
TextureImage::Flags aFlags);
} // namespace gl
} // namespace mozilla

View File

@ -178,10 +178,9 @@ TextureImageTextureSourceOGL::GetSize() const
{
if (mTexImage) {
if (mIterating) {
nsIntRect rect = mTexImage->GetTileRect();
return gfx::IntSize(rect.width, rect.height);
return mTexImage->GetTileRect().Size();
}
return gfx::IntSize(mTexImage->GetSize().width, mTexImage->GetSize().height);
return mTexImage->GetSize();
}
NS_WARNING("Trying to query the size of an empty TextureSource.");
return gfx::IntSize(0, 0);
@ -194,6 +193,11 @@ TextureImageTextureSourceOGL::GetFormat() const
return mTexImage->GetTextureFormat();
}
nsIntRect TextureImageTextureSourceOGL::GetTileRect()
{
return ThebesIntRect(mTexImage->GetTileRect());
}
void
TextureImageTextureSourceOGL::BindTexture(GLenum aTextureUnit)
{
@ -358,14 +362,18 @@ TextureImageDeprecatedTextureHostOGL::GetSize() const
{
if (mTexture) {
if (mIterating) {
nsIntRect rect = mTexture->GetTileRect();
return gfx::IntSize(rect.width, rect.height);
return mTexture->GetTileRect().Size();
}
return gfx::IntSize(mTexture->GetSize().width, mTexture->GetSize().height);
return mTexture->GetSize();
}
return gfx::IntSize(0, 0);
}
nsIntRect TextureImageDeprecatedTextureHostOGL::GetTileRect()
{
return ThebesIntRect(mTexture->GetTileRect());
}
void
TextureImageDeprecatedTextureHostOGL::SetCompositor(Compositor* aCompositor)
{

View File

@ -157,10 +157,7 @@ public:
mIterating = false;
}
virtual nsIntRect GetTileRect() MOZ_OVERRIDE
{
return mTexImage->GetTileRect();
}
virtual nsIntRect GetTileRect() MOZ_OVERRIDE;
virtual size_t GetTileCount() MOZ_OVERRIDE
{
@ -397,10 +394,7 @@ public:
mIterating = false;
}
nsIntRect GetTileRect() MOZ_OVERRIDE
{
return mTexture->GetTileRect();
}
nsIntRect GetTileRect() MOZ_OVERRIDE;
size_t GetTileCount() MOZ_OVERRIDE
{

View File

@ -14,6 +14,7 @@
#include "ThebesLayerOGL.h"
#include "gfxUtils.h"
#include "gfxTeeSurface.h"
#include "gfx2DGlue.h"
#include "gfxPlatform.h"
#include "base/message_loop.h"
@ -91,7 +92,7 @@ public:
nsIntSize GetSize() {
if (mTexImage)
return mTexImage->GetSize();
return ThebesIntSize(mTexImage->GetSize());
return nsIntSize(0, 0);
}
@ -204,7 +205,7 @@ ThebesLayerBufferOGL::RenderTo(const nsIntPoint& aOffset,
region.MoveBy(-origin); // translate into TexImage space, buffer origin might not be at texture (0,0)
// Figure out the intersecting draw region
nsIntSize texSize = mTexImage->GetSize();
nsIntSize texSize = ThebesIntSize(mTexImage->GetSize());
nsIntRect textureRect = nsIntRect(0, 0, texSize.width, texSize.height);
textureRect.MoveBy(region.GetBounds().TopLeft());
nsIntRegion subregion;
@ -236,10 +237,10 @@ ThebesLayerBufferOGL::RenderTo(const nsIntPoint& aOffset,
bool usingTiles = (mTexImage->GetTileCount() > 1);
do {
if (mTexImageOnWhite) {
NS_ASSERTION(mTexImageOnWhite->GetTileRect() == mTexImage->GetTileRect(), "component alpha textures should be the same size.");
NS_ASSERTION(ThebesIntRect(mTexImageOnWhite->GetTileRect()) == ThebesIntRect(mTexImage->GetTileRect()), "component alpha textures should be the same size.");
}
nsIntRect tileRect = mTexImage->GetTileRect();
nsIntRect tileRect = ThebesIntRect(mTexImage->GetTileRect());
// Bind textures.
TextureImage::ScopedBindTexture texBind(mTexImage, LOCAL_GL_TEXTURE0);

View File

@ -32,6 +32,11 @@ inline Rect ToRect(const gfxRect &aRect)
Float(aRect.width), Float(aRect.height));
}
inline IntRect ToIntRect(const nsIntRect &aRect)
{
return IntRect(aRect.x, aRect.y, aRect.width, aRect.height);
}
inline Color ToColor(const gfxRGBA &aRGBA)
{
return Color(Float(aRGBA.r), Float(aRGBA.g),
@ -123,6 +128,11 @@ inline gfxRect ThebesRect(const Rect &aRect)
return gfxRect(aRect.x, aRect.y, aRect.width, aRect.height);
}
inline nsIntRect ThebesIntRect(const IntRect &aRect)
{
return nsIntRect(aRect.x, aRect.y, aRect.width, aRect.height);
}
inline gfxRGBA ThebesRGBA(const Color &aColor)
{
return gfxRGBA(aColor.r, aColor.g, aColor.b, aColor.a);