2010-08-07 05:09:18 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 11:12:37 +00: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-30 04:48:52 +00:00
|
|
|
|
|
|
|
#ifndef GFX_IMAGELAYEROGL_H
|
|
|
|
#define GFX_IMAGELAYEROGL_H
|
|
|
|
|
2011-04-03 02:14:00 +00:00
|
|
|
#include "mozilla/layers/PLayers.h"
|
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
2010-10-13 22:55:45 +00:00
|
|
|
|
2010-03-30 04:48:52 +00:00
|
|
|
#include "LayerManagerOGL.h"
|
|
|
|
#include "ImageLayers.h"
|
2010-09-03 03:50:42 +00:00
|
|
|
#include "yuv_convert.h"
|
2010-04-08 07:29:55 +00:00
|
|
|
#include "mozilla/Mutex.h"
|
2010-03-30 04:48:52 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2010-05-16 23:08:01 +00: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.
|
|
|
|
*/
|
|
|
|
class GLTexture {
|
|
|
|
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-29 06:19:26 +00:00
|
|
|
bool IsAllocated() { return mTexture != 0; }
|
2010-05-16 23:08:01 +00:00
|
|
|
GLuint GetTextureID() { return mTexture; }
|
|
|
|
GLContext *GetGLContext() { return mContext; }
|
|
|
|
|
|
|
|
void Release();
|
2012-05-15 19:17:33 +00:00
|
|
|
private:
|
2010-05-16 23:08:01 +00:00
|
|
|
|
|
|
|
nsRefPtr<GLContext> mContext;
|
|
|
|
GLuint mTexture;
|
|
|
|
};
|
|
|
|
|
2010-05-16 23:08:41 +00:00
|
|
|
/**
|
2012-02-01 02:18:30 +00: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 23:08:41 +00:00
|
|
|
*/
|
2012-02-01 02:18:30 +00:00
|
|
|
class TextureRecycleBin {
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(TextureRecycleBin)
|
2010-05-16 23:08:41 +00:00
|
|
|
|
2010-05-16 23:09:28 +00:00
|
|
|
typedef mozilla::gl::GLContext GLContext;
|
|
|
|
|
2010-05-16 23:08:41 +00:00
|
|
|
public:
|
2012-02-01 02:18:30 +00:00
|
|
|
TextureRecycleBin();
|
2010-05-16 23:08:41 +00:00
|
|
|
|
2010-05-16 23:09:28 +00:00
|
|
|
enum TextureType {
|
|
|
|
TEXTURE_Y,
|
|
|
|
TEXTURE_C
|
|
|
|
};
|
|
|
|
|
|
|
|
void RecycleTexture(GLTexture *aTexture, TextureType aType,
|
|
|
|
const gfxIntSize& aSize);
|
2010-08-07 05:09:18 +00:00
|
|
|
void GetTexture(TextureType aType, const gfxIntSize& aSize,
|
|
|
|
GLContext *aContext, GLTexture *aOutTexture);
|
2010-05-16 23:09:28 +00:00
|
|
|
|
2010-05-16 23:08:41 +00:00
|
|
|
private:
|
|
|
|
typedef mozilla::Mutex Mutex;
|
|
|
|
|
2010-05-16 23:09:28 +00:00
|
|
|
// This protects mRecycledBuffers, mRecycledBufferSize, mRecycledTextures
|
|
|
|
// and mRecycledTextureSizes
|
2010-05-16 23:08:41 +00:00
|
|
|
Mutex mLock;
|
|
|
|
|
2010-05-16 23:09:28 +00:00
|
|
|
nsTArray<GLTexture> mRecycledTextures[2];
|
|
|
|
gfxIntSize mRecycledTextureSizes[2];
|
2010-05-16 23:08:41 +00:00
|
|
|
};
|
|
|
|
|
2010-03-30 04:48:52 +00:00
|
|
|
class THEBES_API ImageLayerOGL : public ImageLayer,
|
|
|
|
public LayerOGL
|
|
|
|
{
|
|
|
|
public:
|
2012-02-01 02:18:30 +00:00
|
|
|
ImageLayerOGL(LayerManagerOGL *aManager);
|
2010-08-07 05:09:18 +00:00
|
|
|
~ImageLayerOGL() { Destroy(); }
|
2010-03-30 04:48:52 +00:00
|
|
|
|
|
|
|
// LayerOGL Implementation
|
2011-10-17 14:59:28 +00:00
|
|
|
virtual void Destroy() { mDestroyed = true; }
|
2010-03-30 04:48:52 +00:00
|
|
|
virtual Layer* GetLayer();
|
2012-03-18 20:08:49 +00:00
|
|
|
virtual bool LoadAsTexture(GLuint aTextureUnit, gfxIntSize* aSize);
|
2010-03-30 04:48:52 +00:00
|
|
|
|
2010-05-25 06:35:35 +00:00
|
|
|
virtual void RenderLayer(int aPreviousFrameBuffer,
|
|
|
|
const nsIntPoint& aOffset);
|
2012-01-16 05:41:55 +00:00
|
|
|
virtual void CleanupResources() {}
|
2010-03-30 04:48:52 +00:00
|
|
|
|
2012-03-18 20:08:49 +00:00
|
|
|
|
2012-02-01 02:18:30 +00:00
|
|
|
void AllocateTexturesYCbCr(PlanarYCbCrImage *aImage);
|
|
|
|
void AllocateTexturesCairo(CairoImage *aImage);
|
2010-05-16 23:08:01 +00:00
|
|
|
|
2012-02-01 02:18:30 +00:00
|
|
|
protected:
|
|
|
|
nsRefPtr<TextureRecycleBin> mTextureRecycleBin;
|
|
|
|
};
|
2010-03-30 04:48:52 +00:00
|
|
|
|
2012-02-01 02:18:30 +00:00
|
|
|
struct THEBES_API PlanarYCbCrOGLBackendData : public ImageBackendData
|
|
|
|
{
|
|
|
|
~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-07 05:09:18 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool HasTextures()
|
2010-05-16 23:08:01 +00:00
|
|
|
{
|
|
|
|
return mTextures[0].IsAllocated() && mTextures[1].IsAllocated() &&
|
|
|
|
mTextures[2].IsAllocated();
|
|
|
|
}
|
2010-03-30 04:48:52 +00:00
|
|
|
|
2010-05-16 23:08:01 +00:00
|
|
|
GLTexture mTextures[3];
|
2012-02-01 02:18:30 +00:00
|
|
|
gfxIntSize mYSize, mCbCrSize;
|
|
|
|
nsRefPtr<TextureRecycleBin> mTextureRecycleBin;
|
2010-03-30 04:48:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-01 02:18:30 +00:00
|
|
|
struct CairoOGLBackendData : public ImageBackendData
|
2010-03-30 04:48:52 +00:00
|
|
|
{
|
2012-03-17 22:22:22 +00:00
|
|
|
CairoOGLBackendData() : mLayerProgram(gl::RGBALayerProgramType) {}
|
2010-05-16 23:08:01 +00:00
|
|
|
GLTexture mTexture;
|
2010-12-17 07:27:56 +00:00
|
|
|
gl::ShaderProgramType mLayerProgram;
|
2012-03-18 20:08:49 +00:00
|
|
|
gfxIntSize mTextureSize;
|
2010-03-30 04:48:52 +00:00
|
|
|
};
|
|
|
|
|
2010-10-13 22:55:45 +00:00
|
|
|
class ShadowImageLayerOGL : public ShadowImageLayer,
|
|
|
|
public LayerOGL
|
|
|
|
{
|
|
|
|
typedef gl::TextureImage TextureImage;
|
|
|
|
|
|
|
|
public:
|
|
|
|
ShadowImageLayerOGL(LayerManagerOGL* aManager);
|
|
|
|
virtual ~ShadowImageLayerOGL();
|
|
|
|
|
|
|
|
// ShadowImageLayer impl
|
2011-09-27 22:19:26 +00:00
|
|
|
virtual void Swap(const SharedImage& aFront,
|
|
|
|
SharedImage* aNewBack);
|
2010-10-13 22:55:45 +00:00
|
|
|
|
2011-01-06 04:54:47 +00:00
|
|
|
virtual void Disconnect();
|
|
|
|
|
2010-10-13 22:55:45 +00:00
|
|
|
// LayerOGL impl
|
|
|
|
virtual void Destroy();
|
2012-03-18 23:02:38 +00:00
|
|
|
virtual bool LoadAsTexture(GLuint aTextureUnit, gfxIntSize* aSize);
|
2010-10-13 22:55:45 +00:00
|
|
|
|
|
|
|
virtual Layer* GetLayer();
|
|
|
|
|
|
|
|
virtual void RenderLayer(int aPreviousFrameBuffer,
|
|
|
|
const nsIntPoint& aOffset);
|
|
|
|
|
2012-01-16 05:41:55 +00:00
|
|
|
virtual void CleanupResources();
|
|
|
|
|
2010-10-13 22:55:45 +00:00
|
|
|
private:
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Init(const SharedImage& aFront);
|
2011-09-27 22:19:26 +00:00
|
|
|
|
2010-10-13 22:55:45 +00:00
|
|
|
nsRefPtr<TextureImage> mTexImage;
|
2011-04-21 04:38:39 +00:00
|
|
|
GLTexture mYUVTexture[3];
|
|
|
|
gfxIntSize mSize;
|
2011-09-27 22:19:26 +00:00
|
|
|
gfxIntSize mCbCrSize;
|
2011-07-05 02:52:00 +00:00
|
|
|
nsIntRect mPictureRect;
|
2010-10-13 22:55:45 +00:00
|
|
|
};
|
|
|
|
|
2010-03-30 04:48:52 +00:00
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|
|
|
|
#endif /* GFX_IMAGELAYEROGL_H */
|