Bug 1311642 - Remove BeginUpdate and EndUpdate from GLTextureImage. r=nical

Only DirectUpdate was actually being used, so remove the dead
code. TextureImageCGL does't do anything over BasicTextureImage any more
so remove it too.

MozReview-Commit-ID: D7jpC9M7aTT

--HG--
extra : rebase_source : 7846439aa5cb320704b8f811f3203fe7fd31c51e
This commit is contained in:
Jamie Nicol 2016-10-20 17:11:00 +01:00
Родитель ae9ba130ae
Коммит 9a0a722f7b
10 изменённых файлов: 7 добавлений и 630 удалений

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

@ -5,7 +5,6 @@
#include "GLContextProvider.h"
#include "GLContextCGL.h"
#include "TextureImageCGL.h"
#include "nsDebug.h"
#include "nsIWidget.h"
#include <OpenGL/gl.h>

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

@ -15,9 +15,6 @@
#include "GfxTexturesReporter.h"
#include "TextureImageEGL.h"
#ifdef XP_MACOSX
#include "TextureImageCGL.h"
#endif
using namespace mozilla::gfx;
@ -33,10 +30,6 @@ CreateTextureImage(GLContext* gl,
TextureImage::ImageFormat aImageFormat)
{
switch (gl->GetContextType()) {
#ifdef XP_MACOSX
case GLContextType::CGL:
return CreateTextureImageCGL(gl, aSize, aContentType, aWrapMode, aFlags, aImageFormat);
#endif
case GLContextType::EGL:
return CreateTextureImageEGL(gl, aSize, aContentType, aWrapMode, aFlags, aImageFormat);
default: {
@ -61,10 +54,6 @@ TileGenFunc(GLContext* gl,
TextureImage::ImageFormat aImageFormat)
{
switch (gl->GetContextType()) {
#ifdef XP_MACOSX
case GLContextType::CGL:
return TileGenFuncCGL(gl, aSize, aContentType, aFlags);
#endif
case GLContextType::EGL:
return TileGenFuncEGL(gl, aSize, aContentType, aFlags, aImageFormat);
default:
@ -131,77 +120,6 @@ BasicTextureImage::~BasicTextureImage()
}
}
gfx::DrawTarget*
BasicTextureImage::BeginUpdate(nsIntRegion& aRegion)
{
NS_ASSERTION(!mUpdateDrawTarget, "BeginUpdate() without EndUpdate()?");
// determine the region the client will need to repaint
if (CanUploadSubTextures(mGLContext)) {
GetUpdateRegion(aRegion);
} else {
aRegion = IntRect(IntPoint(0, 0), mSize);
}
mUpdateRegion = aRegion;
IntRect rgnSize = mUpdateRegion.GetBounds();
if (!IntRect(IntPoint(0, 0), mSize).Contains(rgnSize)) {
NS_ERROR("update outside of image");
return nullptr;
}
gfx::SurfaceFormat format =
(GetContentType() == gfxContentType::COLOR) ?
gfx::SurfaceFormat::B8G8R8X8 : gfx::SurfaceFormat::B8G8R8A8;
mUpdateDrawTarget =
GetDrawTargetForUpdate(gfx::IntSize(rgnSize.width, rgnSize.height), format);
return mUpdateDrawTarget;
}
void
BasicTextureImage::GetUpdateRegion(nsIntRegion& aForRegion)
{
// if the texture hasn't been initialized yet, or something important
// changed, we need to recreate our backing surface and force the
// client to paint everything
if (mTextureState != Valid) {
aForRegion = IntRect(IntPoint(0, 0), mSize);
}
}
void
BasicTextureImage::EndUpdate()
{
NS_ASSERTION(!!mUpdateDrawTarget, "EndUpdate() without BeginUpdate()?");
// FIXME: this is the slow boat. Make me fast (with GLXPixmap?).
RefPtr<gfx::SourceSurface> updateSnapshot = mUpdateDrawTarget->Snapshot();
RefPtr<gfx::DataSourceSurface> updateData = updateSnapshot->GetDataSurface();
bool relative = FinishedSurfaceUpdate();
bool needInit = mTextureState == Created;
size_t uploadSize;
mTextureFormat =
UploadSurfaceToTexture(mGLContext,
updateData,
mUpdateRegion,
mTexture,
&uploadSize,
needInit,
mUpdateOffset,
relative);
FinishedSurfaceUpload();
if (uploadSize > 0) {
UpdateUploadSize(uploadSize);
}
mUpdateDrawTarget = nullptr;
mTextureState = Valid;
}
void
BasicTextureImage::BindTexture(GLenum aTextureUnit)
{
@ -210,23 +128,6 @@ BasicTextureImage::BindTexture(GLenum aTextureUnit)
mGLContext->fActiveTexture(LOCAL_GL_TEXTURE0);
}
already_AddRefed<gfx::DrawTarget>
BasicTextureImage::GetDrawTargetForUpdate(const gfx::IntSize& aSize, gfx::SurfaceFormat aFmt)
{
return gfx::Factory::CreateDrawTarget(gfx::BackendType::CAIRO, aSize, aFmt);
}
bool
BasicTextureImage::FinishedSurfaceUpdate()
{
return false;
}
void
BasicTextureImage::FinishedSurfaceUpload()
{
}
bool
BasicTextureImage::DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom /* = gfx::IntPoint(0, 0) */)
{
@ -260,8 +161,6 @@ BasicTextureImage::DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion
void
BasicTextureImage::Resize(const gfx::IntSize& aSize)
{
NS_ASSERTION(!mUpdateDrawTarget, "Resize() while in update?");
mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
// This matches the logic in UploadImageDataToTexture so that
@ -317,7 +216,6 @@ BasicTextureImage::BasicTextureImage(GLuint aTexture,
, mTexture(aTexture)
, mTextureState(Created)
, mGLContext(aContext)
, mUpdateOffset(0, 0)
{}
static bool
@ -347,7 +245,6 @@ TiledTextureImage::TiledTextureImage(GLContext* aGL,
, mCurrentImage(0)
, mIterationCallback(nullptr)
, mIterationCallbackData(nullptr)
, mInUpdate(false)
, mRows(0)
, mColumns(0)
, mGL(aGL)
@ -426,153 +323,6 @@ TiledTextureImage::DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion
return result;
}
void
TiledTextureImage::GetUpdateRegion(nsIntRegion& aForRegion)
{
if (mTextureState != Valid) {
// if the texture hasn't been initialized yet, or something important
// changed, we need to recreate our backing surface and force the
// client to paint everything
aForRegion = IntRect(IntPoint(0, 0), mSize);
return;
}
nsIntRegion newRegion;
// We need to query each texture with the region it will be drawing and
// set aForRegion to be the combination of all of these regions
for (unsigned i = 0; i < mImages.Length(); i++) {
int xPos = (i % mColumns) * mTileSize;
int yPos = (i / mColumns) * mTileSize;
IntRect imageRect = IntRect(IntPoint(xPos,yPos),
mImages[i]->GetSize());
if (aForRegion.Intersects(imageRect)) {
// Make a copy of the region
nsIntRegion subRegion;
subRegion.And(aForRegion, imageRect);
// Translate it into tile-space
subRegion.MoveBy(-xPos, -yPos);
// Query region
mImages[i]->GetUpdateRegion(subRegion);
// Translate back
subRegion.MoveBy(xPos, yPos);
// Add to the accumulated region
newRegion.Or(newRegion, subRegion);
}
}
aForRegion = newRegion;
}
gfx::DrawTarget*
TiledTextureImage::BeginUpdate(nsIntRegion& aRegion)
{
NS_ASSERTION(!mInUpdate, "nested update");
mInUpdate = true;
// Note, we don't call GetUpdateRegion here as if the updated region is
// fully contained in a single tile, we get to avoid iterating through
// the tiles again (and a little copying).
if (mTextureState != Valid)
{
// if the texture hasn't been initialized yet, or something important
// changed, we need to recreate our backing surface and force the
// client to paint everything
aRegion = IntRect(IntPoint(0, 0), mSize);
}
IntRect bounds = aRegion.GetBounds();
for (unsigned i = 0; i < mImages.Length(); i++) {
int xPos = (i % mColumns) * mTileSize;
int yPos = (i / mColumns) * mTileSize;
nsIntRegion imageRegion =
nsIntRegion(IntRect(IntPoint(xPos,yPos),
mImages[i]->GetSize()));
// a single Image can handle this update request
if (imageRegion.Contains(aRegion)) {
// adjust for tile offset
aRegion.MoveBy(-xPos, -yPos);
// forward the actual call
RefPtr<gfx::DrawTarget> drawTarget = mImages[i]->BeginUpdate(aRegion);
// caller expects container space
aRegion.MoveBy(xPos, yPos);
// we don't have a temp surface
mUpdateDrawTarget = nullptr;
// remember which image to EndUpdate
mCurrentImage = i;
return drawTarget.get();
}
}
// Get the real updated region, taking into account the capabilities of
// each TextureImage tile
GetUpdateRegion(aRegion);
mUpdateRegion = aRegion;
bounds = aRegion.GetBounds();
// update covers multiple Images - create a temp surface to paint in
gfx::SurfaceFormat format =
(GetContentType() == gfxContentType::COLOR) ?
gfx::SurfaceFormat::B8G8R8X8: gfx::SurfaceFormat::B8G8R8A8;
mUpdateDrawTarget = gfx::Factory::CreateDrawTarget(gfx::BackendType::CAIRO,
bounds.Size(),
format);
return mUpdateDrawTarget;;
}
void
TiledTextureImage::EndUpdate()
{
NS_ASSERTION(mInUpdate, "EndUpdate not in update");
if (!mUpdateDrawTarget) { // update was to a single TextureImage
mImages[mCurrentImage]->EndUpdate();
mInUpdate = false;
mTextureState = Valid;
mTextureFormat = mImages[mCurrentImage]->GetTextureFormat();
return;
}
RefPtr<gfx::SourceSurface> updateSnapshot = mUpdateDrawTarget->Snapshot();
RefPtr<gfx::DataSourceSurface> updateData = updateSnapshot->GetDataSurface();
// upload tiles from temp surface
for (unsigned i = 0; i < mImages.Length(); i++) {
int xPos = (i % mColumns) * mTileSize;
int yPos = (i / mColumns) * mTileSize;
IntRect imageRect = IntRect(IntPoint(xPos,yPos), mImages[i]->GetSize());
nsIntRegion subregion;
subregion.And(mUpdateRegion, imageRect);
if (subregion.IsEmpty())
continue;
subregion.MoveBy(-xPos, -yPos); // Tile-local space
// copy tile from temp target
gfx::DrawTarget* drawTarget = mImages[i]->BeginUpdate(subregion);
MOZ_ASSERT(drawTarget->GetBackendType() == BackendType::CAIRO,
"updateSnapshot should not have been converted to data");
gfxUtils::ClipToRegion(drawTarget, subregion);
Size size(updateData->GetSize().width,
updateData->GetSize().height);
drawTarget->DrawSurface(updateData,
Rect(Point(-xPos, -yPos), size),
Rect(Point(0, 0), size),
DrawSurfaceOptions(),
DrawOptions(1.0, CompositionOp::OP_SOURCE,
AntialiasMode::NONE));
drawTarget->PopClip();
mImages[i]->EndUpdate();
}
mUpdateDrawTarget = nullptr;
mInUpdate = false;
mTextureFormat = mImages[0]->GetTextureFormat();
mTextureState = Valid;
}
void TiledTextureImage::BeginBigImageIteration()
{
mCurrentImage = 0;

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

@ -27,20 +27,9 @@ namespace gl {
class GLContext;
/**
* A TextureImage encapsulates a surface that can be drawn to by a
* Thebes gfxContext and (hopefully efficiently!) synchronized to a
* texture in the server. TextureImages are associated with one and
* only one GLContext.
*
* Implementation note: TextureImages attempt to unify two categories
* of backends
*
* (1) proxy to server-side object that can be bound to a texture;
* e.g. Pixmap on X11.
*
* (2) efficient manager of texture memory; e.g. by having clients draw
* into a scratch buffer which is then uploaded with
* glTexSubImage2D().
* A TextureImage provides a mechanism to synchronize data from a
* surface to a texture in the server. TextureImages are associated
* with one and only one GLContext.
*/
class TextureImage
{
@ -70,46 +59,6 @@ public:
GLenum aWrapMode,
TextureImage::Flags aFlags = TextureImage::NoFlags);
/**
* Returns a gfxASurface for updating |aRegion| of the client's
* image if successul, nullptr if not. |aRegion|'s bounds must fit
* within Size(); its coordinate space (if any) is ignored. If
* the update begins successfully, the returned gfxASurface is
* owned by this. Otherwise, nullptr is returned.
*
* |aRegion| is an inout param: the returned region is what the
* client must repaint. Category (1) regions above can
* efficiently handle repaints to "scattered" regions, while (2)
* can only efficiently handle repaints to rects.
*
* Painting the returned surface outside of |aRegion| results
* in undefined behavior.
*
* BeginUpdate() calls cannot be "nested", and each successful
* BeginUpdate() must be followed by exactly one EndUpdate() (see
* below). Failure to do so can leave this in a possibly
* inconsistent state. Unsuccessful BeginUpdate()s must not be
* followed by EndUpdate().
*/
virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion) = 0;
/**
* Retrieves the region that will require updating, given a
* region that needs to be updated. This can be used for
* making decisions about updating before calling BeginUpdate().
*
* |aRegion| is an inout param.
*/
virtual void GetUpdateRegion(nsIntRegion& aForRegion) {
}
/**
* Finish the active update and synchronize with the server, if
* necessary.
*
* BeginUpdate() must have been called exactly once before
* EndUpdate().
*/
virtual void EndUpdate() = 0;
/**
* The Image may contain several textures for different regions (tiles).
* These functions iterate over each sub texture image tile.
@ -143,18 +92,10 @@ public:
/**
* Set this TextureImage's size, and ensure a texture has been
* allocated. Must not be called between BeginUpdate and EndUpdate.
* allocated.
* After a resize, the contents are undefined.
*
* If this isn't implemented by a subclass, it will just perform
* a dummy BeginUpdate/EndUpdate pair.
*/
virtual void Resize(const gfx::IntSize& aSize) {
mSize = aSize;
nsIntRegion r(gfx::IntRect(0, 0, aSize.width, aSize.height));
BeginUpdate(r);
EndUpdate();
}
virtual void Resize(const gfx::IntSize& aSize) = 0;
/**
* Mark this texture as having valid contents. Call this after modifying
@ -175,8 +116,8 @@ public:
virtual void BindTexture(GLenum aTextureUnit) = 0;
/**
* Returns the image format of the texture. Only valid after a matching
* BeginUpdate/EndUpdate pair have been called.
* Returns the image format of the texture. Only valid after
* DirectUpdate has been called.
*/
virtual gfx::SurfaceFormat GetTextureFormat() {
return mTextureFormat;
@ -194,7 +135,6 @@ public:
gfx::IntSize GetSize() const;
ContentType GetContentType() const { return mContentType; }
virtual bool InUpdate() const = 0;
GLenum GetWrapMode() const { return mWrapMode; }
void SetSamplingFilter(gfx::SamplingFilter aSamplingFilter) {
@ -256,37 +196,17 @@ public:
virtual void BindTexture(GLenum aTextureUnit);
virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
virtual void GetUpdateRegion(nsIntRegion& aForRegion);
virtual void EndUpdate();
virtual bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom = gfx::IntPoint(0,0));
virtual GLuint GetTextureID() { return mTexture; }
virtual already_AddRefed<gfx::DrawTarget>
GetDrawTargetForUpdate(const gfx::IntSize& aSize, gfx::SurfaceFormat aFmt);
virtual void MarkValid() { mTextureState = Valid; }
// Call when drawing into the update surface is complete.
// Returns true if textures should be upload with a relative
// offset - See UploadSurfaceToTexture.
virtual bool FinishedSurfaceUpdate();
// Call after surface data has been uploaded to a texture.
virtual void FinishedSurfaceUpload();
virtual bool InUpdate() const { return !!mUpdateDrawTarget; }
virtual void Resize(const gfx::IntSize& aSize);
protected:
GLuint mTexture;
TextureState mTextureState;
RefPtr<GLContext> mGLContext;
RefPtr<gfx::DrawTarget> mUpdateDrawTarget;
nsIntRegion mUpdateRegion;
// The offset into the update surface at which the update rect is located.
nsIntPoint mUpdateOffset;
};
/**
@ -305,9 +225,6 @@ public:
TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
~TiledTextureImage();
void DumpDiv();
virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
virtual void GetUpdateRegion(nsIntRegion& aForRegion);
virtual void EndUpdate();
virtual void Resize(const gfx::IntSize& aSize);
virtual uint32_t GetTileCount();
virtual void BeginBigImageIteration();
@ -319,7 +236,6 @@ public:
return mImages[mCurrentImage]->GetTextureID();
}
virtual bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom = gfx::IntPoint(0,0));
virtual bool InUpdate() const { return mInUpdate; }
virtual void BindTexture(GLenum);
protected:
@ -329,14 +245,9 @@ protected:
BigImageIterationCallback mIterationCallback;
void* mIterationCallbackData;
nsTArray< RefPtr<TextureImage> > mImages;
bool mInUpdate;
unsigned int mTileSize;
unsigned int mRows, mColumns;
GLContext* mGL;
// A temporary draw target to faciliate cross-tile updates.
RefPtr<gfx::DrawTarget> mUpdateDrawTarget;
// The region of update requested
nsIntRegion mUpdateRegion;
TextureState mTextureState;
TextureImage::ImageFormat mImageFormat;
};

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

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
#ifndef TextureImageCGL_h_
#define TextureImageCGL_h_
#include "GLTextureImage.h"
#include "GLContextTypes.h"
#include "nsSize.h"
namespace mozilla {
namespace gl {
class TextureImageCGL : public BasicTextureImage
{
public:
TextureImageCGL(GLuint aTexture,
const gfx::IntSize& aSize,
GLenum aWrapMode,
ContentType aContentType,
GLContext* aContext,
TextureImage::Flags aFlags = TextureImage::NoFlags);
~TextureImageCGL();
protected:
bool FinishedSurfaceUpdate();
void FinishedSurfaceUpload();
private:
GLuint mPixelBuffer;
bool mBoundPixelBuffer;
};
already_AddRefed<TextureImage>
CreateTextureImageCGL(GLContext* gl,
const gfx::IntSize& aSize,
TextureImage::ContentType aContentType,
GLenum aWrapMode,
TextureImage::Flags aFlags,
TextureImage::ImageFormat aImageFormat);
already_AddRefed<TextureImage>
TileGenFuncCGL(GLContext* gl,
const gfx::IntSize& aSize,
TextureImage::ContentType aContentType,
TextureImage::Flags aFlags);
} // namespace gl
} // namespace mozilla
#endif

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

@ -1,109 +0,0 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 "TextureImageCGL.h"
#include "GLContext.h"
#include "gfx2DGlue.h"
#include "gfxQuartzSurface.h"
#include "gfxPlatform.h"
#include "gfxFailure.h"
namespace mozilla {
using namespace gfx;
namespace gl {
TextureImageCGL::TextureImageCGL(GLuint aTexture,
const IntSize& aSize,
GLenum aWrapMode,
ContentType aContentType,
GLContext* aContext,
TextureImage::Flags aFlags)
: BasicTextureImage(aTexture, aSize, aWrapMode, aContentType,
aContext, aFlags)
, mPixelBuffer(0)
, mBoundPixelBuffer(false)
{}
TextureImageCGL::~TextureImageCGL()
{
if (mPixelBuffer) {
mGLContext->MakeCurrent();
mGLContext->fDeleteBuffers(1, &mPixelBuffer);
}
}
bool
TextureImageCGL::FinishedSurfaceUpdate()
{
if (mBoundPixelBuffer) {
mGLContext->MakeCurrent();
mGLContext->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, mPixelBuffer);
mGLContext->fUnmapBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER);
return true;
}
return false;
}
void
TextureImageCGL::FinishedSurfaceUpload()
{
if (mBoundPixelBuffer) {
mGLContext->MakeCurrent();
mGLContext->fBindBuffer(LOCAL_GL_PIXEL_UNPACK_BUFFER, 0);
mBoundPixelBuffer = false;
}
}
already_AddRefed<TextureImage>
CreateTextureImageCGL(GLContext* gl,
const gfx::IntSize& aSize,
TextureImage::ContentType aContentType,
GLenum aWrapMode,
TextureImage::Flags aFlags,
TextureImage::ImageFormat aImageFormat)
{
if (!gl->IsOffscreenSizeAllowed(aSize) &&
gfxPlatform::OffMainThreadCompositingEnabled()) {
NS_ASSERTION(aWrapMode == LOCAL_GL_CLAMP_TO_EDGE, "Can't support wrapping with tiles!");
RefPtr<TextureImage> t = new gl::TiledTextureImage(gl, aSize, aContentType,
aFlags, aImageFormat);
return t.forget();
}
return CreateBasicTextureImage(gl, aSize, aContentType, aWrapMode,
aFlags);
}
already_AddRefed<TextureImage>
TileGenFuncCGL(GLContext* gl,
const IntSize& aSize,
TextureImage::ContentType aContentType,
TextureImage::Flags aFlags)
{
bool useNearestFilter = aFlags & TextureImage::UseNearestFilter;
gl->MakeCurrent();
GLuint texture;
gl->fGenTextures(1, &texture);
gl->fActiveTexture(LOCAL_GL_TEXTURE0);
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, texture);
GLint texfilter = useNearestFilter ? LOCAL_GL_NEAREST : LOCAL_GL_LINEAR;
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, texfilter);
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, texfilter);
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
RefPtr<TextureImageCGL> teximage
(new TextureImageCGL(texture, aSize, LOCAL_GL_CLAMP_TO_EDGE, aContentType,
gl, aFlags));
return teximage.forget();
}
} // namespace gl
} // namespace mozilla

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

@ -95,105 +95,6 @@ TextureImageEGL::~TextureImageEGL()
DestroyEGLSurface();
}
void
TextureImageEGL::GetUpdateRegion(nsIntRegion& aForRegion)
{
if (mTextureState != Valid) {
// if the texture hasn't been initialized yet, force the
// client to paint everything
aForRegion = gfx::IntRect(gfx::IntPoint(0, 0), mSize);
}
// We can only draw a rectangle, not subregions due to
// the way that our texture upload functions work. If
// needed, we /could/ do multiple texture uploads if we have
// non-overlapping rects, but that's a tradeoff.
aForRegion = nsIntRegion(aForRegion.GetBounds());
}
gfx::DrawTarget*
TextureImageEGL::BeginUpdate(nsIntRegion& aRegion)
{
NS_ASSERTION(!mUpdateDrawTarget, "BeginUpdate() without EndUpdate()?");
// determine the region the client will need to repaint
GetUpdateRegion(aRegion);
mUpdateRect = aRegion.GetBounds();
//printf_stderr("BeginUpdate with updateRect [%d %d %d %d]\n", mUpdateRect.x, mUpdateRect.y, mUpdateRect.width, mUpdateRect.height);
if (!gfx::IntRect(gfx::IntPoint(0, 0), mSize).Contains(mUpdateRect)) {
NS_ERROR("update outside of image");
return nullptr;
}
//printf_stderr("creating image surface %dx%d format %d\n", mUpdateRect.width, mUpdateRect.height, mUpdateFormat);
mUpdateDrawTarget = gfx::Factory::CreateDrawTarget(gfx::BackendType::CAIRO,
gfx::IntSize(mUpdateRect.width, mUpdateRect.height),
mUpdateFormat);
return mUpdateDrawTarget;
}
void
TextureImageEGL::EndUpdate()
{
NS_ASSERTION(!!mUpdateDrawTarget, "EndUpdate() without BeginUpdate()?");
//printf_stderr("EndUpdate: slow path");
// This is the slower path -- we didn't have any way to set up
// a fast mapping between our cairo target surface and the GL
// texture, so we have to upload data.
RefPtr<gfx::SourceSurface> updateSurface = nullptr;
RefPtr<gfx::DataSourceSurface> uploadImage = nullptr;
gfx::IntSize updateSize(mUpdateRect.width, mUpdateRect.height);
NS_ASSERTION(mUpdateDrawTarget->GetSize() == updateSize,
"Upload image is the wrong size!");
updateSurface = mUpdateDrawTarget->Snapshot();
uploadImage = updateSurface->GetDataSurface();
if (!uploadImage) {
return;
}
mGLContext->MakeCurrent();
mGLContext->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexture);
if (mTextureState != Valid) {
NS_ASSERTION(mUpdateRect.x == 0 && mUpdateRect.y == 0 &&
mUpdateRect.Size() == mSize,
"Bad initial update on non-created texture!");
mGLContext->fTexImage2D(LOCAL_GL_TEXTURE_2D,
0,
GLFormatForImage(mUpdateFormat),
mUpdateRect.width,
mUpdateRect.height,
0,
GLFormatForImage(uploadImage->GetFormat()),
GLTypeForImage(uploadImage->GetFormat()),
uploadImage->GetData());
} else {
mGLContext->fTexSubImage2D(LOCAL_GL_TEXTURE_2D,
0,
mUpdateRect.x,
mUpdateRect.y,
mUpdateRect.width,
mUpdateRect.height,
GLFormatForImage(uploadImage->GetFormat()),
GLTypeForImage(uploadImage->GetFormat()),
uploadImage->GetData());
}
mUpdateDrawTarget = nullptr;
mTextureState = Valid;
return; // mTexture is bound
}
bool
TextureImageEGL::DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom /* = gfx::IntPoint(0,0) */)
{
@ -242,8 +143,6 @@ TextureImageEGL::BindTexture(GLenum aTextureUnit)
void
TextureImageEGL::Resize(const gfx::IntSize& aSize)
{
NS_ASSERTION(!mUpdateDrawTarget, "Resize() while in update?");
if (mSize == aSize && mTextureState != Created)
return;

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

@ -26,12 +26,6 @@ public:
virtual ~TextureImageEGL();
virtual void GetUpdateRegion(nsIntRegion& aForRegion);
virtual gfx::DrawTarget* BeginUpdate(nsIntRegion& aRegion);
virtual void EndUpdate();
virtual bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion, const gfx::IntPoint& aFrom = gfx::IntPoint(0,0));
virtual void BindTexture(GLenum aTextureUnit);
@ -45,8 +39,6 @@ public:
return mTexture;
};
virtual bool InUpdate() const { return !!mUpdateDrawTarget; }
virtual void Resize(const gfx::IntSize& aSize);
bool BindTexImage();
@ -65,9 +57,7 @@ protected:
GLContext* mGLContext;
gfx::IntRect mUpdateRect;
gfx::SurfaceFormat mUpdateFormat;
RefPtr<gfx::DrawTarget> mUpdateDrawTarget;
EGLImage mEGLImage;
GLuint mTexture;
EGLSurface mSurface;

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

@ -94,7 +94,6 @@ if gl_provider == 'CGL':
# These files include Mac headers that are unfriendly to unified builds
SOURCES += [
"GLContextProviderCGL.mm",
"TextureImageCGL.mm"
]
EXPORTS += [
'GLContextCGL.h',

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

@ -42,8 +42,6 @@ GLBlitTextureImageHelper::BlitTextureImage(TextureImage *aSrc, const gfx::IntRec
TextureImage *aDst, const gfx::IntRect& aDstRect)
{
GLContext *gl = mCompositor->gl();
NS_ASSERTION(!aSrc->InUpdate(), "Source texture is in update!");
NS_ASSERTION(!aDst->InUpdate(), "Destination texture is in update!");
if (!aSrc || !aDst || aSrcRect.IsEmpty() || aDstRect.IsEmpty())
return;

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

@ -193,9 +193,6 @@ TextureImageTextureSourceOGL::Update(gfx::DataSourceSurface* aSurface,
mTexImage->UpdateFromDataSource(aSurface, aDestRegion, aSrcOffset);
if (mTexImage->InUpdate()) {
mTexImage->EndUpdate();
}
return true;
}