2010-08-06 22:09:18 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 04:12:37 -07: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-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
#ifndef GFX_IMAGELAYEROGL_H
|
|
|
|
#define GFX_IMAGELAYEROGL_H
|
|
|
|
|
2013-04-24 11:42:40 -07:00
|
|
|
#include "mozilla/layers/PLayerTransaction.h"
|
2010-10-13 15:55:45 -07:00
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
#include "LayerManagerOGL.h"
|
|
|
|
#include "ImageLayers.h"
|
2012-08-19 12:33:25 -07:00
|
|
|
#include "ImageContainer.h"
|
2010-09-02 20:50:42 -07:00
|
|
|
#include "yuv_convert.h"
|
2010-04-08 00:29:55 -07:00
|
|
|
#include "mozilla/Mutex.h"
|
2010-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
class CairoImage;
|
|
|
|
class PlanarYCbCrImage;
|
2013-05-23 00:17:10 -07:00
|
|
|
class BlobYCbCrSurface;
|
2012-08-19 12:33:25 -07:00
|
|
|
|
2010-05-16 16:08:01 -07:00
|
|
|
/**
|
|
|
|
* This class wraps a GL texture. It includes a GLContext reference
|
|
|
|
* so we can use to free the texture when destroyed. The implementation
|
|
|
|
* makes sure to always free the texture on the main thread, even if the
|
|
|
|
* destructor runs on another thread.
|
|
|
|
*
|
|
|
|
* We ensure that the GLContext reference is only addrefed and released
|
|
|
|
* on the main thread, although it uses threadsafe recounting so we don't
|
|
|
|
* really have to.
|
|
|
|
*
|
|
|
|
* Initially the texture is not allocated --- it's in a "null" state.
|
|
|
|
*/
|
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 02:20:52 -07:00
|
|
|
class GLTexture
|
|
|
|
{
|
2010-05-16 16:08:01 -07:00
|
|
|
typedef mozilla::gl::GLContext GLContext;
|
|
|
|
|
|
|
|
public:
|
|
|
|
GLTexture() : mTexture(0) {}
|
|
|
|
~GLTexture() { Release(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allocate the texture. This can only be called on the main thread.
|
|
|
|
*/
|
|
|
|
void Allocate(GLContext *aContext);
|
|
|
|
/**
|
|
|
|
* Move the state of aOther to this GLTexture. If this GLTexture currently
|
|
|
|
* has a texture, it is released. This can be called on any thread.
|
|
|
|
*/
|
|
|
|
void TakeFrom(GLTexture *aOther);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsAllocated() { return mTexture != 0; }
|
2010-05-16 16:08:01 -07:00
|
|
|
GLuint GetTextureID() { return mTexture; }
|
|
|
|
GLContext *GetGLContext() { return mContext; }
|
|
|
|
|
|
|
|
void Release();
|
2012-05-15 12:17:33 -07:00
|
|
|
private:
|
2010-05-16 16:08:01 -07:00
|
|
|
|
|
|
|
nsRefPtr<GLContext> mContext;
|
|
|
|
GLuint mTexture;
|
|
|
|
};
|
|
|
|
|
2010-05-16 16:08:41 -07:00
|
|
|
/**
|
2012-01-31 18:18:30 -08:00
|
|
|
* A RecycleBin is owned by an ImageLayer. We store textures in it that we
|
|
|
|
* want to recycle from one image to the next. It's a separate object from
|
|
|
|
* ImageContainer because images need to store a strong ref to their RecycleBin
|
|
|
|
* and we must avoid creating a reference loop between an ImageContainer and
|
|
|
|
* its active image.
|
2010-05-16 16:08:41 -07:00
|
|
|
*/
|
2012-01-31 18:18:30 -08:00
|
|
|
class TextureRecycleBin {
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureRecycleBin)
|
2010-05-16 16:08:41 -07:00
|
|
|
|
2010-05-16 16:09:28 -07:00
|
|
|
typedef mozilla::gl::GLContext GLContext;
|
|
|
|
|
2010-05-16 16:08:41 -07:00
|
|
|
public:
|
2012-01-31 18:18:30 -08:00
|
|
|
TextureRecycleBin();
|
2010-05-16 16:08:41 -07:00
|
|
|
|
2010-05-16 16:09:28 -07:00
|
|
|
enum TextureType {
|
|
|
|
TEXTURE_Y,
|
|
|
|
TEXTURE_C
|
|
|
|
};
|
|
|
|
|
|
|
|
void RecycleTexture(GLTexture *aTexture, TextureType aType,
|
|
|
|
const gfxIntSize& aSize);
|
2010-08-06 22:09:18 -07:00
|
|
|
void GetTexture(TextureType aType, const gfxIntSize& aSize,
|
|
|
|
GLContext *aContext, GLTexture *aOutTexture);
|
2010-05-16 16:09:28 -07:00
|
|
|
|
2010-05-16 16:08:41 -07:00
|
|
|
private:
|
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2010-05-16 16:09:28 -07:00
|
|
|
// This protects mRecycledBuffers, mRecycledBufferSize, mRecycledTextures
|
|
|
|
// and mRecycledTextureSizes
|
2010-05-16 16:08:41 -07:00
|
|
|
Mutex mLock;
|
|
|
|
|
2010-05-16 16:09:28 -07:00
|
|
|
nsTArray<GLTexture> mRecycledTextures[2];
|
|
|
|
gfxIntSize mRecycledTextureSizes[2];
|
2010-05-16 16:08:41 -07:00
|
|
|
};
|
|
|
|
|
2013-05-29 14:59:24 -07:00
|
|
|
class ImageLayerOGL : public ImageLayer,
|
|
|
|
public LayerOGL
|
2010-03-29 21:48:52 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-01-31 18:18:30 -08:00
|
|
|
ImageLayerOGL(LayerManagerOGL *aManager);
|
2010-08-06 22:09:18 -07:00
|
|
|
~ImageLayerOGL() { Destroy(); }
|
2010-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
// LayerOGL Implementation
|
2011-10-17 07:59:28 -07:00
|
|
|
virtual void Destroy() { mDestroyed = true; }
|
2010-03-29 21:48:52 -07:00
|
|
|
virtual Layer* GetLayer();
|
2012-03-18 13:08:49 -07:00
|
|
|
virtual bool LoadAsTexture(GLuint aTextureUnit, gfxIntSize* aSize);
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
virtual void RenderLayer(int aPreviousFrameBuffer,
|
|
|
|
const nsIntPoint& aOffset);
|
2012-01-15 21:41:55 -08:00
|
|
|
virtual void CleanupResources() {}
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2012-03-18 13:08:49 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
void AllocateTexturesYCbCr(PlanarYCbCrImage *aImage);
|
|
|
|
void AllocateTexturesCairo(CairoImage *aImage);
|
2010-05-16 16:08:01 -07:00
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
protected:
|
|
|
|
nsRefPtr<TextureRecycleBin> mTextureRecycleBin;
|
|
|
|
};
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2013-05-29 14:59:24 -07:00
|
|
|
struct PlanarYCbCrOGLBackendData : public ImageBackendData
|
2012-01-31 18:18:30 -08:00
|
|
|
{
|
|
|
|
~PlanarYCbCrOGLBackendData()
|
|
|
|
{
|
|
|
|
if (HasTextures()) {
|
|
|
|
mTextureRecycleBin->RecycleTexture(&mTextures[0], TextureRecycleBin::TEXTURE_Y, mYSize);
|
|
|
|
mTextureRecycleBin->RecycleTexture(&mTextures[1], TextureRecycleBin::TEXTURE_C, mCbCrSize);
|
|
|
|
mTextureRecycleBin->RecycleTexture(&mTextures[2], TextureRecycleBin::TEXTURE_C, mCbCrSize);
|
|
|
|
}
|
|
|
|
}
|
2010-08-06 22:09:18 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasTextures()
|
2010-05-16 16:08:01 -07:00
|
|
|
{
|
|
|
|
return mTextures[0].IsAllocated() && mTextures[1].IsAllocated() &&
|
|
|
|
mTextures[2].IsAllocated();
|
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-05-16 16:08:01 -07:00
|
|
|
GLTexture mTextures[3];
|
2012-01-31 18:18:30 -08:00
|
|
|
gfxIntSize mYSize, mCbCrSize;
|
|
|
|
nsRefPtr<TextureRecycleBin> mTextureRecycleBin;
|
2010-03-29 21:48:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
struct CairoOGLBackendData : public ImageBackendData
|
2010-03-29 21:48:52 -07:00
|
|
|
{
|
2012-03-17 15:22:22 -07:00
|
|
|
CairoOGLBackendData() : mLayerProgram(gl::RGBALayerProgramType) {}
|
2010-05-16 16:08:01 -07:00
|
|
|
GLTexture mTexture;
|
2010-12-16 23:27:56 -08:00
|
|
|
gl::ShaderProgramType mLayerProgram;
|
2012-03-18 13:08:49 -07:00
|
|
|
gfxIntSize mTextureSize;
|
2010-03-29 21:48:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|
|
|
|
#endif /* GFX_IMAGELAYEROGL_H */
|