2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 4; -*- */
|
2012-12-18 05:58:44 +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/. */
|
|
|
|
|
|
|
|
#ifndef GLTEXTUREIMAGE_H_
|
|
|
|
#define GLTEXTUREIMAGE_H_
|
|
|
|
|
|
|
|
#include "nsRegion.h"
|
2013-03-17 11:55:16 +04:00
|
|
|
#include "nsTArray.h"
|
2013-09-25 00:45:14 +04:00
|
|
|
#include "gfxTypes.h"
|
2012-12-18 05:58:44 +04:00
|
|
|
#include "GLContextTypes.h"
|
2013-07-30 13:59:51 +04:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2013-07-30 13:59:51 +04:00
|
|
|
|
2013-09-25 00:45:14 +04:00
|
|
|
class gfxASurface;
|
|
|
|
|
2013-07-30 13:59:51 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
class DataSourceSurface;
|
2014-02-13 22:00:01 +04:00
|
|
|
class DrawTarget;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2012-12-18 05:58:44 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
|
|
|
|
|
|
|
/**
|
2016-10-20 19:11:00 +03:00
|
|
|
* 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.
|
2012-12-18 05:58:44 +04:00
|
|
|
*/
|
|
|
|
class TextureImage {
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(TextureImage)
|
|
|
|
public:
|
|
|
|
enum TextureState {
|
|
|
|
Created, // Texture created, but has not had glTexImage called to
|
|
|
|
// initialize it.
|
|
|
|
Allocated, // Texture memory exists, but contents are invalid.
|
|
|
|
Valid // Texture fully ready to use.
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
enum Flags {
|
|
|
|
NoFlags = 0x0,
|
|
|
|
UseNearestFilter = 0x1,
|
2014-11-18 04:02:19 +03:00
|
|
|
OriginBottomLeft = 0x2,
|
2013-08-02 03:02:06 +04:00
|
|
|
DisallowBigImage = 0x4
|
2012-12-18 05:58:44 +04:00
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-09-25 00:45:13 +04:00
|
|
|
typedef gfxContentType ContentType;
|
|
|
|
typedef gfxImageFormat ImageFormat;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-08-13 17:44:53 +04:00
|
|
|
static already_AddRefed<TextureImage> Create(
|
|
|
|
GLContext* gl, const gfx::IntSize& aSize,
|
|
|
|
TextureImage::ContentType aContentType, GLenum aWrapMode,
|
|
|
|
TextureImage::Flags aFlags = TextureImage::NoFlags);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
/**
|
|
|
|
* The Image may contain several textures for different regions (tiles).
|
|
|
|
* These functions iterate over each sub texture image tile.
|
|
|
|
*/
|
2014-04-28 15:27:25 +04:00
|
|
|
virtual void BeginBigImageIteration() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
virtual bool NextTile() { return false; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
// Function prototype for a tile iteration callback. Returning false will
|
|
|
|
// cause iteration to be interrupted (i.e. the corresponding NextTile call
|
|
|
|
// will return false).
|
2014-04-28 15:27:25 +04:00
|
|
|
typedef bool (*BigImageIterationCallback)(TextureImage* aImage,
|
2012-12-18 05:58:44 +04:00
|
|
|
int aTileNumber,
|
|
|
|
void* aCallbackData);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
// Sets a callback to be called every time NextTile is called.
|
2014-04-28 15:27:25 +04:00
|
|
|
virtual void SetIterationCallback(BigImageIterationCallback aCallback,
|
2012-12-18 05:58:44 +04:00
|
|
|
void* aCallbackData) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-08-13 17:44:53 +04:00
|
|
|
virtual gfx::IntRect GetTileRect();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
virtual GLuint GetTextureID() = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
virtual uint32_t GetTileCount() { return 1; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
/**
|
|
|
|
* Set this TextureImage's size, and ensure a texture has been
|
2016-10-20 19:11:00 +03:00
|
|
|
* allocated.
|
2012-12-18 05:58:44 +04:00
|
|
|
* After a resize, the contents are undefined.
|
|
|
|
*/
|
2016-10-20 19:11:00 +03:00
|
|
|
virtual void Resize(const gfx::IntSize& aSize) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
/**
|
|
|
|
* Mark this texture as having valid contents. Call this after modifying
|
|
|
|
* the texture contents externally.
|
|
|
|
*/
|
|
|
|
virtual void MarkValid() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
/**
|
|
|
|
* aSurf - the source surface to update from
|
|
|
|
* aRegion - the region in this image to update
|
|
|
|
* aFrom - offset in the source to update from
|
|
|
|
*/
|
2014-02-13 20:25:55 +04:00
|
|
|
virtual bool DirectUpdate(gfx::DataSourceSurface* aSurf,
|
|
|
|
const nsIntRegion& aRegion,
|
|
|
|
const gfx::IntPoint& aFrom = gfx::IntPoint(0,
|
|
|
|
0)) = 0;
|
2016-06-11 04:37:07 +03:00
|
|
|
bool UpdateFromDataSource(gfx::DataSourceSurface* aSurf,
|
2013-07-30 13:59:51 +04:00
|
|
|
const nsIntRegion* aDstRegion = nullptr,
|
|
|
|
const gfx::IntPoint* aSrcOffset = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
virtual void BindTexture(GLenum aTextureUnit) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
/**
|
2016-10-20 19:11:00 +03:00
|
|
|
* Returns the image format of the texture. Only valid after
|
|
|
|
* DirectUpdate has been called.
|
2012-12-18 05:58:44 +04:00
|
|
|
*/
|
2013-07-04 21:25:50 +04:00
|
|
|
virtual gfx::SurfaceFormat GetTextureFormat() { return mTextureFormat; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
/** Can be called safely at any time. */
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
/**
|
|
|
|
* If this TextureImage has a permanent gfxASurface backing,
|
2013-04-28 15:52:10 +04:00
|
|
|
* return it. Otherwise return nullptr.
|
2012-12-18 05:58:44 +04:00
|
|
|
*/
|
|
|
|
virtual already_AddRefed<gfxASurface> GetBackingSurface() { return nullptr; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-08-13 17:44:53 +04:00
|
|
|
gfx::IntSize GetSize() const;
|
2012-12-18 05:58:44 +04:00
|
|
|
ContentType GetContentType() const { return mContentType; }
|
|
|
|
GLenum GetWrapMode() const { return mWrapMode; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-05-25 19:01:18 +03:00
|
|
|
void SetSamplingFilter(gfx::SamplingFilter aSamplingFilter) {
|
|
|
|
mSamplingFilter = aSamplingFilter;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
protected:
|
|
|
|
friend class GLContext;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-01-27 00:03:37 +03:00
|
|
|
void UpdateUploadSize(size_t amount);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
/**
|
|
|
|
* After the ctor, the TextureImage is invalid. Implementations
|
|
|
|
* must allocate resources successfully before returning the new
|
|
|
|
* TextureImage from GLContext::CreateTextureImage(). That is,
|
|
|
|
* clients must not be given partially-constructed TextureImages.
|
|
|
|
*/
|
2013-08-13 17:44:53 +04:00
|
|
|
TextureImage(const gfx::IntSize& aSize, GLenum aWrapMode,
|
|
|
|
ContentType aContentType, Flags aFlags = NoFlags);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
2016-01-27 00:03:37 +03:00
|
|
|
virtual ~TextureImage() { UpdateUploadSize(0); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-08-13 17:44:53 +04:00
|
|
|
virtual gfx::IntRect GetSrcTileRect();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-12-13 21:32:06 +04:00
|
|
|
gfx::IntSize mSize;
|
2012-12-18 05:58:44 +04:00
|
|
|
GLenum mWrapMode;
|
|
|
|
ContentType mContentType;
|
2013-07-04 21:25:50 +04:00
|
|
|
gfx::SurfaceFormat mTextureFormat;
|
2016-05-25 19:01:18 +03:00
|
|
|
gfx::SamplingFilter mSamplingFilter;
|
2012-12-18 05:58:44 +04:00
|
|
|
Flags mFlags;
|
2016-01-27 00:03:37 +03:00
|
|
|
size_t mUploadSize;
|
2012-12-18 05:58:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* BasicTextureImage is the baseline TextureImage implementation ---
|
|
|
|
* it updates its texture by allocating a scratch buffer for the
|
|
|
|
* client to draw into, then using glTexSubImage2D() to upload the new
|
|
|
|
* pixels. Platforms must provide the code to create a new surface
|
|
|
|
* into which the updated pixels will be drawn, and the code to
|
|
|
|
* convert the update surface's pixels into an image on which we can
|
|
|
|
* glTexSubImage2D().
|
|
|
|
*/
|
|
|
|
class BasicTextureImage : public TextureImage {
|
|
|
|
public:
|
|
|
|
virtual ~BasicTextureImage();
|
|
|
|
|
2013-08-13 17:44:53 +04:00
|
|
|
BasicTextureImage(GLuint aTexture, const gfx::IntSize& aSize,
|
|
|
|
GLenum aWrapMode, ContentType aContentType,
|
|
|
|
GLContext* aContext,
|
2016-01-13 10:10:56 +03:00
|
|
|
TextureImage::Flags aFlags = TextureImage::NoFlags);
|
2013-08-13 17:44:53 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void BindTexture(GLenum aTextureUnit) override;
|
2012-12-18 05:58:44 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion,
|
|
|
|
const gfx::IntPoint& aFrom = gfx::IntPoint(0, 0)) override;
|
|
|
|
GLuint GetTextureID() override { return mTexture; }
|
2012-12-18 05:58:44 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void MarkValid() override { mTextureState = Valid; }
|
2012-12-18 05:58:44 +04:00
|
|
|
|
2019-04-11 15:36:51 +03:00
|
|
|
void Resize(const gfx::IntSize& aSize) override;
|
2012-12-18 05:58:44 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
GLuint mTexture;
|
|
|
|
TextureState mTextureState;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<GLContext> mGLContext;
|
2012-12-18 05:58:44 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A container class that complements many sub TextureImages into a big
|
|
|
|
* TextureImage. Aims to behave just like the real thing.
|
|
|
|
*/
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class TiledTextureImage final : public TextureImage {
|
2012-12-18 05:58:44 +04:00
|
|
|
public:
|
|
|
|
TiledTextureImage(
|
2013-08-08 02:38:21 +04:00
|
|
|
GLContext* aGL, gfx::IntSize aSize, TextureImage::ContentType,
|
|
|
|
TextureImage::Flags aFlags = TextureImage::NoFlags,
|
2016-01-08 07:57:38 +03:00
|
|
|
TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
|
2019-04-11 15:36:51 +03:00
|
|
|
virtual ~TiledTextureImage();
|
2012-12-18 05:58:44 +04:00
|
|
|
void DumpDiv();
|
2019-04-11 15:36:51 +03:00
|
|
|
void Resize(const gfx::IntSize& aSize) override;
|
|
|
|
uint32_t GetTileCount() override;
|
|
|
|
void BeginBigImageIteration() override;
|
|
|
|
bool NextTile() override;
|
|
|
|
void SetIterationCallback(BigImageIterationCallback aCallback,
|
|
|
|
void* aCallbackData) override;
|
|
|
|
gfx::IntRect GetTileRect() override;
|
|
|
|
GLuint GetTextureID() override {
|
2012-12-18 05:58:44 +04:00
|
|
|
return mImages[mCurrentImage]->GetTextureID();
|
|
|
|
}
|
2019-04-11 15:36:51 +03:00
|
|
|
bool DirectUpdate(gfx::DataSourceSurface* aSurf, const nsIntRegion& aRegion,
|
|
|
|
const gfx::IntPoint& aFrom = gfx::IntPoint(0, 0)) override;
|
|
|
|
void BindTexture(GLenum) override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
protected:
|
2019-04-11 15:36:51 +03:00
|
|
|
gfx::IntRect GetSrcTileRect() override;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
unsigned int mCurrentImage;
|
2014-04-28 15:27:25 +04:00
|
|
|
BigImageIterationCallback mIterationCallback;
|
2012-12-18 05:58:44 +04:00
|
|
|
void* mIterationCallbackData;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<TextureImage> > mImages;
|
2012-12-18 05:58:44 +04:00
|
|
|
unsigned int mTileSize;
|
|
|
|
unsigned int mRows, mColumns;
|
|
|
|
GLContext* mGL;
|
|
|
|
TextureState mTextureState;
|
2013-08-08 02:38:21 +04:00
|
|
|
TextureImage::ImageFormat mImageFormat;
|
2012-12-18 05:58:44 +04: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
|
|
|
/**
|
|
|
|
* Creates a TextureImage of the basic implementation, can be useful in cases
|
|
|
|
* where we know we don't want to use platform-specific TextureImage.
|
|
|
|
* In doubt, use GLContext::CreateTextureImage instead.
|
|
|
|
*/
|
|
|
|
already_AddRefed<TextureImage> CreateBasicTextureImage(
|
2013-12-13 21:32:06 +04:00
|
|
|
GLContext* aGL, const gfx::IntSize& aSize,
|
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
|
|
|
TextureImage::ContentType aContentType, GLenum aWrapMode,
|
2016-01-13 10:10:56 +03:00
|
|
|
TextureImage::Flags aFlags);
|
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
|
|
|
|
2016-06-09 23:39:11 +03:00
|
|
|
/**
|
|
|
|
* Creates a TiledTextureImage backed by platform-specific or basic
|
|
|
|
* TextureImages. In doubt, use GLContext::CreateTextureImage instead.
|
|
|
|
*/
|
|
|
|
already_AddRefed<TextureImage> CreateTiledTextureImage(
|
|
|
|
GLContext* aGL, const gfx::IntSize& aSize,
|
|
|
|
TextureImage::ContentType aContentType, TextureImage::Flags aFlags,
|
|
|
|
TextureImage::ImageFormat aImageFormat);
|
|
|
|
|
2013-12-03 22:44:38 +04:00
|
|
|
/**
|
|
|
|
* Return a valid, allocated TextureImage of |aSize| with
|
|
|
|
* |aContentType|. If |aContentType| is COLOR, |aImageFormat| can be used
|
|
|
|
* to hint at the preferred RGB format, however it is not necessarily
|
|
|
|
* respected. The TextureImage's texture is configured to use
|
|
|
|
* |aWrapMode| (usually GL_CLAMP_TO_EDGE or GL_REPEAT) and by
|
|
|
|
* default, GL_LINEAR filtering. Specify
|
|
|
|
* |aFlags=UseNearestFilter| for GL_NEAREST filtering. Specify
|
2014-11-18 04:02:19 +03:00
|
|
|
* |aFlags=OriginBottomLeft| if the image is origin-bottom-left, instead of the
|
|
|
|
* default origin-top-left. Return
|
2013-12-03 22:44:38 +04:00
|
|
|
* nullptr if creating the TextureImage fails.
|
|
|
|
*
|
|
|
|
* The returned TextureImage may only be used with this GLContext.
|
|
|
|
* Attempting to use the returned TextureImage after this
|
|
|
|
* GLContext is destroyed will result in undefined (and likely
|
|
|
|
* crashy) behavior.
|
|
|
|
*/
|
|
|
|
already_AddRefed<TextureImage> CreateTextureImage(
|
2013-12-13 21:32:06 +04:00
|
|
|
GLContext* gl, const gfx::IntSize& aSize,
|
2013-12-03 22:44:38 +04:00
|
|
|
TextureImage::ContentType aContentType, GLenum aWrapMode,
|
|
|
|
TextureImage::Flags aFlags = TextureImage::NoFlags,
|
2016-01-08 07:57:38 +03:00
|
|
|
TextureImage::ImageFormat aImageFormat = gfx::SurfaceFormat::UNKNOWN);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-12-18 05:58:44 +04:00
|
|
|
} // namespace gl
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif /* GLTEXTUREIMAGE_H_ */
|