2010-05-27 20:04:26 +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-05-18 04:04:22 +00:00
|
|
|
|
2012-07-12 12:51:58 +00:00
|
|
|
#include "ipc/AutoOpenSurface.h"
|
2013-04-24 18:42:40 +00:00
|
|
|
#include "mozilla/layers/PLayerTransaction.h"
|
2011-07-04 13:15:05 +00:00
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
|
|
|
|
2011-04-03 02:14:00 +00:00
|
|
|
#include "gfxSharedImageSurface.h"
|
2010-10-13 22:55:45 +00:00
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
#include "CanvasLayerOGL.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxContext.h"
|
2010-06-23 14:02:32 +00:00
|
|
|
#include "GLContextProvider.h"
|
2011-11-02 19:55:03 +00:00
|
|
|
#include "gfxPlatform.h"
|
2013-02-13 23:26:24 +00:00
|
|
|
#include "SharedSurfaceGL.h"
|
|
|
|
#include "SharedSurfaceEGL.h"
|
|
|
|
#include "SurfaceStream.h"
|
|
|
|
#include "gfxColor.h"
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2012-08-19 19:33:25 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "mozilla/gfx/MacIOSurface.h"
|
2013-07-18 03:24:15 +00:00
|
|
|
#include "SharedSurfaceIO.h"
|
2012-08-19 19:33:25 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "gfxWindowsSurface.h"
|
|
|
|
#include "WGLLibrary.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include <OpenGL/OpenGL.h>
|
|
|
|
#endif
|
|
|
|
|
2013-04-30 03:16:04 +00:00
|
|
|
#ifdef GL_PROVIDER_GLX
|
2011-04-20 21:45:57 +00:00
|
|
|
#include "gfxXlibSurface.h"
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 04:04:22 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::gl;
|
2013-02-13 23:26:24 +00:00
|
|
|
using namespace mozilla::gfx;
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2012-06-01 01:30:08 +00:00
|
|
|
static void
|
|
|
|
MakeTextureIfNeeded(GLContext* gl, GLuint& aTexture)
|
|
|
|
{
|
|
|
|
if (aTexture != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl->fGenTextures(1, &aTexture);
|
|
|
|
|
|
|
|
gl->fActiveTexture(LOCAL_GL_TEXTURE0);
|
|
|
|
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, aTexture);
|
|
|
|
|
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
|
|
|
gl->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-07-31 22:48:40 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
static GLuint
|
|
|
|
MakeIOSurfaceTexture(void* aCGIOSurfaceContext, mozilla::gl::GLContext* aGL)
|
|
|
|
{
|
|
|
|
GLuint ioSurfaceTexture;
|
|
|
|
|
|
|
|
aGL->MakeCurrent();
|
|
|
|
|
|
|
|
aGL->fGenTextures(1, &ioSurfaceTexture);
|
|
|
|
|
|
|
|
aGL->fActiveTexture(LOCAL_GL_TEXTURE0);
|
|
|
|
aGL->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, ioSurfaceTexture);
|
|
|
|
|
|
|
|
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
|
|
|
|
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
|
|
|
|
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T, LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
RefPtr<MacIOSurface> ioSurface = MacIOSurface::IOSurfaceContextGetSurface((CGContextRef)aCGIOSurfaceContext);
|
|
|
|
void *nativeCtx = aGL->GetNativeData(GLContext::NativeGLContext);
|
|
|
|
|
2013-07-18 03:24:14 +00:00
|
|
|
ioSurface->CGLTexImageIOSurface2D(nativeCtx);
|
2012-07-31 22:48:40 +00:00
|
|
|
|
|
|
|
aGL->fBindTexture(LOCAL_GL_TEXTURE_RECTANGLE_ARB, 0);
|
|
|
|
|
|
|
|
return ioSurfaceTexture;
|
|
|
|
}
|
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 09:20:52 +00:00
|
|
|
#endif
|
2012-07-31 22:48:40 +00:00
|
|
|
|
2010-08-07 05:09:18 +00:00
|
|
|
void
|
|
|
|
CanvasLayerOGL::Destroy()
|
2010-05-18 04:04:22 +00:00
|
|
|
{
|
2010-08-07 05:09:18 +00:00
|
|
|
if (!mDestroyed) {
|
2012-01-16 05:41:55 +00:00
|
|
|
CleanupResources();
|
2011-10-17 14:59:28 +00:00
|
|
|
mDestroyed = true;
|
2010-06-18 09:21:42 +00:00
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CanvasLayerOGL::Initialize(const Data& aData)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
NS_ASSERTION(mCanvasSurface == nullptr, "BasicCanvasLayer::Initialize called twice!");
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
if (aData.mGLContext != nullptr &&
|
|
|
|
aData.mSurface != nullptr)
|
2010-07-19 05:01:14 +00:00
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
NS_WARNING("CanvasLayerOGL can't have both surface and WebGLContext");
|
2010-07-19 05:01:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-08 21:41:10 +00:00
|
|
|
mOGLManager->MakeCurrent();
|
|
|
|
|
2012-07-31 22:48:40 +00:00
|
|
|
if (aData.mDrawTarget &&
|
|
|
|
aData.mDrawTarget->GetNativeSurface(gfx::NATIVE_SURFACE_CGCONTEXT_ACCELERATED)) {
|
|
|
|
mDrawTarget = aData.mDrawTarget;
|
|
|
|
mNeedsYFlip = false;
|
|
|
|
mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height);
|
|
|
|
return;
|
|
|
|
} else if (aData.mDrawTarget) {
|
2011-11-02 19:55:03 +00:00
|
|
|
mDrawTarget = aData.mDrawTarget;
|
2013-02-25 21:18:52 +00:00
|
|
|
mCanvasSurface = gfxPlatform::GetPlatform()->CreateThebesSurfaceAliasForDrawTarget_hack(mDrawTarget);
|
2011-11-02 19:55:03 +00:00
|
|
|
mNeedsYFlip = false;
|
|
|
|
} else if (aData.mSurface) {
|
2010-05-25 06:35:35 +00:00
|
|
|
mCanvasSurface = aData.mSurface;
|
2011-10-17 14:59:28 +00:00
|
|
|
mNeedsYFlip = false;
|
2013-04-30 03:16:04 +00:00
|
|
|
#if defined(GL_PROVIDER_GLX)
|
2011-08-05 01:13:25 +00:00
|
|
|
if (aData.mSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
|
|
|
|
gfxXlibSurface *xsurf = static_cast<gfxXlibSurface*>(aData.mSurface);
|
|
|
|
mPixmap = xsurf->GetGLXPixmap();
|
|
|
|
if (mPixmap) {
|
2013-07-04 17:25:50 +00:00
|
|
|
mLayerProgram = ShaderProgramFromContentType(aData.mSurface->GetContentType());
|
2013-02-13 23:26:24 +00:00
|
|
|
MakeTextureIfNeeded(gl(), mUploadTexture);
|
2011-03-08 21:41:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 04:04:22 +00:00
|
|
|
} else if (aData.mGLContext) {
|
2013-02-13 23:26:24 +00:00
|
|
|
mGLContext = aData.mGLContext;
|
|
|
|
NS_ASSERTION(mGLContext->IsOffscreen(), "Canvas GLContext must be offscreen.");
|
|
|
|
mIsGLAlphaPremult = aData.mIsGLAlphaPremult;
|
|
|
|
mNeedsYFlip = true;
|
|
|
|
|
|
|
|
// [OGL Layers, MTC] WebGL layer init.
|
|
|
|
|
|
|
|
GLScreenBuffer* screen = mGLContext->Screen();
|
|
|
|
SurfaceStreamType streamType =
|
|
|
|
SurfaceStream::ChooseGLStreamType(SurfaceStream::MainThread,
|
|
|
|
screen->PreserveBuffer());
|
|
|
|
SurfaceFactory_GL* factory = nullptr;
|
|
|
|
if (!mForceReadback) {
|
|
|
|
factory = new SurfaceFactory_GLTexture(mGLContext, gl(), screen->Caps());
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
if (factory) {
|
|
|
|
screen->Morph(factory, streamType);
|
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
} else {
|
|
|
|
NS_WARNING("CanvasLayerOGL::Initialize called without surface or GL context!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height);
|
2012-07-30 18:36:12 +00:00
|
|
|
|
2010-12-17 07:19:28 +00:00
|
|
|
// Check the maximum texture size supported by GL. glTexImage2D supports
|
|
|
|
// images of up to 2 + GL_MAX_TEXTURE_SIZE
|
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 09:20:52 +00:00
|
|
|
GLint texSize = 0;
|
2013-03-07 22:13:09 +00:00
|
|
|
gl()->fGetIntegerv(LOCAL_GL_MAX_TEXTURE_SIZE, &texSize);
|
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 09:20:52 +00:00
|
|
|
MOZ_ASSERT(texSize != 0);
|
2010-12-17 07:19:28 +00:00
|
|
|
if (mBounds.width > (2 + texSize) || mBounds.height > (2 + texSize)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mDelayedUpdates = true;
|
2013-02-13 23:26:24 +00:00
|
|
|
MakeTextureIfNeeded(gl(), mUploadTexture);
|
2010-12-17 07:19:28 +00:00
|
|
|
// This should only ever occur with 2d canvas, WebGL can't already have a texture
|
|
|
|
// of this size can it?
|
2012-07-30 18:36:12 +00:00
|
|
|
NS_ABORT_IF_FALSE(mCanvasSurface || mDrawTarget,
|
2010-12-17 07:19:28 +00:00
|
|
|
"Invalid texture size when WebGL surface already exists at that size?");
|
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2011-12-19 19:21:56 +00:00
|
|
|
/**
|
|
|
|
* Following UpdateSurface(), mTexture on context this->gl() should contain the data we want,
|
|
|
|
* unless mDelayedUpdates is true because of a too-large surface.
|
|
|
|
*/
|
2010-05-18 04:04:22 +00:00
|
|
|
void
|
2011-03-27 23:59:46 +00:00
|
|
|
CanvasLayerOGL::UpdateSurface()
|
2010-05-18 04:04:22 +00:00
|
|
|
{
|
2012-09-30 06:20:25 +00:00
|
|
|
if (!IsDirty())
|
2011-03-27 23:59:46 +00:00
|
|
|
return;
|
2012-09-30 06:20:25 +00:00
|
|
|
Painted();
|
2011-03-27 23:59:46 +00:00
|
|
|
|
2010-12-17 07:19:28 +00:00
|
|
|
if (mDestroyed || mDelayedUpdates) {
|
2010-08-07 05:09:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-30 03:16:04 +00:00
|
|
|
#if defined(GL_PROVIDER_GLX)
|
2011-03-08 21:41:10 +00:00
|
|
|
if (mPixmap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
gfxASurface* updatedSurface = nullptr;
|
|
|
|
gfxImageSurface* temporarySurface = nullptr;
|
|
|
|
bool nothingToShow = false;
|
|
|
|
if (mGLContext) {
|
|
|
|
SharedSurface* surf = mGLContext->RequestFrame();
|
|
|
|
if (surf) {
|
|
|
|
mLayerProgram = surf->HasAlpha() ? RGBALayerProgramType
|
|
|
|
: RGBXLayerProgramType;
|
|
|
|
switch (surf->Type()) {
|
|
|
|
case SharedSurfaceType::Basic: {
|
|
|
|
SharedSurface_Basic* readbackSurf = SharedSurface_Basic::Cast(surf);
|
|
|
|
updatedSurface = readbackSurf->GetData();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SharedSurfaceType::GLTextureShare: {
|
|
|
|
SharedSurface_GLTexture* textureSurf = SharedSurface_GLTexture::Cast(surf);
|
|
|
|
mTexture = textureSurf->Texture();
|
|
|
|
break;
|
|
|
|
}
|
2013-07-18 03:24:15 +00:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case SharedSurfaceType::IOSurface: {
|
|
|
|
SharedSurface_IOSurface *ioSurf = SharedSurface_IOSurface::Cast(surf);
|
|
|
|
mTexture = ioSurf->Texture();
|
|
|
|
mTextureTarget = ioSurf->TextureTarget();
|
|
|
|
mLayerProgram = RGBARectLayerProgramType;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2013-02-13 23:26:24 +00:00
|
|
|
default:
|
2013-06-29 01:38:30 +00:00
|
|
|
MOZ_CRASH("Unacceptable SharedSurface type.");
|
2013-02-13 23:26:24 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nothingToShow = true;
|
2010-06-23 14:02:32 +00:00
|
|
|
}
|
2013-02-13 23:26:24 +00:00
|
|
|
} else if (mCanvasSurface) {
|
2012-07-31 22:48:40 +00:00
|
|
|
#ifdef XP_MACOSX
|
2013-02-13 23:26:24 +00:00
|
|
|
if (mDrawTarget && mDrawTarget->GetNativeSurface(gfx::NATIVE_SURFACE_CGCONTEXT_ACCELERATED)) {
|
|
|
|
if (!mTexture) {
|
|
|
|
mTexture = MakeIOSurfaceTexture((CGContextRef)mDrawTarget->GetNativeSurface(
|
|
|
|
gfx::NATIVE_SURFACE_CGCONTEXT_ACCELERATED),
|
|
|
|
gl());
|
|
|
|
mTextureTarget = LOCAL_GL_TEXTURE_RECTANGLE_ARB;
|
2013-07-04 17:25:50 +00:00
|
|
|
mLayerProgram = RGBARectLayerProgramType;
|
2013-02-13 23:26:24 +00:00
|
|
|
}
|
|
|
|
mDrawTarget->Flush();
|
|
|
|
return;
|
2012-07-31 22:48:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-02-13 23:26:24 +00:00
|
|
|
updatedSurface = mCanvasSurface;
|
2012-08-31 23:44:33 +00:00
|
|
|
} else {
|
2013-06-29 01:38:30 +00:00
|
|
|
MOZ_CRASH("Unhandled canvas layer type.");
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
2012-08-31 23:44:33 +00:00
|
|
|
|
2013-02-13 23:26:24 +00:00
|
|
|
if (updatedSurface) {
|
|
|
|
mOGLManager->MakeCurrent();
|
2013-07-04 17:25:50 +00:00
|
|
|
gfx::SurfaceFormat format =
|
|
|
|
gl()->UploadSurfaceToTexture(updatedSurface,
|
|
|
|
mBounds,
|
|
|
|
mUploadTexture,
|
|
|
|
true,//false,
|
|
|
|
nsIntPoint(0, 0));
|
|
|
|
mLayerProgram = ShaderProgramFromSurfaceFormat(format);
|
2013-02-13 23:26:24 +00:00
|
|
|
mTexture = mUploadTexture;
|
|
|
|
|
|
|
|
if (temporarySurface)
|
|
|
|
delete temporarySurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mTexture || nothingToShow);
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-21 03:20:48 +00:00
|
|
|
CanvasLayerOGL::RenderLayer(int aPreviousDestination,
|
2010-11-08 09:06:15 +00:00
|
|
|
const nsIntPoint& aOffset)
|
2010-05-18 04:04:22 +00:00
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
FirePreTransactionCallback();
|
2011-03-27 23:59:46 +00:00
|
|
|
UpdateSurface();
|
2012-08-13 10:10:10 +00:00
|
|
|
if (mOGLManager->CompositingDisabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-27 23:59:46 +00:00
|
|
|
FireDidTransactionCallback();
|
2011-03-27 23:59:46 +00:00
|
|
|
|
2010-05-25 06:35:35 +00:00
|
|
|
mOGLManager->MakeCurrent();
|
2010-05-18 04:04:22 +00:00
|
|
|
|
|
|
|
// XXX We're going to need a different program depending on if
|
|
|
|
// mGLBufferIsPremultiplied is TRUE or not. The RGBLayerProgram
|
|
|
|
// assumes that it's true.
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2010-05-25 06:35:35 +00:00
|
|
|
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2010-07-19 05:01:14 +00:00
|
|
|
if (mTexture) {
|
2012-07-31 15:17:43 +00:00
|
|
|
gl()->fBindTexture(mTextureTarget, mTexture);
|
2010-07-19 05:01:14 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
ShaderProgramOGL *program = nullptr;
|
2010-12-17 07:28:30 +00:00
|
|
|
|
2010-12-17 07:19:28 +00:00
|
|
|
nsIntRect drawRect = mBounds;
|
2013-02-13 23:26:24 +00:00
|
|
|
if (mDelayedUpdates) {
|
2012-01-16 21:55:43 +00:00
|
|
|
NS_ABORT_IF_FALSE(mCanvasSurface || mDrawTarget, "WebGL canvases should always be using full texture upload");
|
2012-07-25 15:37:04 +00:00
|
|
|
|
2010-12-17 07:19:28 +00:00
|
|
|
drawRect.IntersectRect(drawRect, GetEffectiveVisibleRegion().GetBounds());
|
|
|
|
|
2013-07-04 17:25:50 +00:00
|
|
|
gfx::SurfaceFormat format =
|
2012-07-26 02:30:20 +00:00
|
|
|
gl()->UploadSurfaceToTexture(mCanvasSurface,
|
2011-02-14 23:23:50 +00:00
|
|
|
nsIntRect(0, 0, drawRect.width, drawRect.height),
|
2013-02-13 23:26:24 +00:00
|
|
|
mUploadTexture,
|
2011-02-14 23:23:50 +00:00
|
|
|
true,
|
|
|
|
drawRect.TopLeft());
|
2013-07-04 17:25:50 +00:00
|
|
|
mLayerProgram = ShaderProgramFromSurfaceFormat(format);
|
2013-02-13 23:26:24 +00:00
|
|
|
mTexture = mUploadTexture;
|
2010-12-17 07:28:30 +00:00
|
|
|
}
|
2011-12-19 19:21:56 +00:00
|
|
|
|
|
|
|
if (!program) {
|
2012-03-18 20:08:53 +00:00
|
|
|
program = mOGLManager->GetProgram(mLayerProgram, GetMaskLayer());
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 03:16:04 +00:00
|
|
|
#if defined(GL_PROVIDER_GLX)
|
2011-03-08 21:41:10 +00:00
|
|
|
if (mPixmap && !mDelayedUpdates) {
|
2012-09-07 00:16:30 +00:00
|
|
|
sDefGLXLib.BindTexImage(mPixmap);
|
2011-03-08 21:41:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-17 02:31:15 +00:00
|
|
|
gl()->ApplyFilterToBoundTexture(mFilter);
|
|
|
|
|
2010-05-25 06:35:35 +00:00
|
|
|
program->Activate();
|
2013-07-04 17:25:50 +00:00
|
|
|
if (mLayerProgram == RGBARectLayerProgramType) {
|
2012-07-31 15:17:43 +00:00
|
|
|
// This is used by IOSurface that use 0,0...w,h coordinate rather then 0,0..1,1.
|
2013-07-18 03:24:15 +00:00
|
|
|
program->SetTexCoordMultiplier(mBounds.width, mBounds.height);
|
2012-07-31 15:17:43 +00:00
|
|
|
}
|
2010-12-17 07:19:28 +00:00
|
|
|
program->SetLayerQuadRect(drawRect);
|
2010-11-08 09:06:15 +00:00
|
|
|
program->SetLayerTransform(GetEffectiveTransform());
|
|
|
|
program->SetLayerOpacity(GetEffectiveOpacity());
|
2010-05-25 06:35:35 +00:00
|
|
|
program->SetRenderOffset(aOffset);
|
|
|
|
program->SetTextureUnit(0);
|
2012-03-18 20:08:53 +00:00
|
|
|
program->LoadMask(GetMaskLayer());
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2012-02-19 02:23:06 +00:00
|
|
|
if (gl()->CanUploadNonPowerOfTwo()) {
|
|
|
|
mOGLManager->BindAndDrawQuad(program, mNeedsYFlip ? true : false);
|
|
|
|
} else {
|
|
|
|
mOGLManager->BindAndDrawQuadWithTextureRect(program, drawRect, drawRect.Size());
|
|
|
|
}
|
2010-05-18 04:04:22 +00:00
|
|
|
|
2013-04-30 03:16:04 +00:00
|
|
|
#if defined(GL_PROVIDER_GLX)
|
2011-03-08 21:41:10 +00:00
|
|
|
if (mPixmap && !mDelayedUpdates) {
|
2012-09-07 00:16:30 +00:00
|
|
|
sDefGLXLib.ReleaseTexImage(mPixmap);
|
2011-03-08 21:41:10 +00:00
|
|
|
}
|
|
|
|
#endif
|
2010-05-18 04:04:22 +00:00
|
|
|
}
|
2010-10-13 22:55:45 +00:00
|
|
|
|
2012-01-16 05:41:55 +00:00
|
|
|
void
|
|
|
|
CanvasLayerOGL::CleanupResources()
|
|
|
|
{
|
2013-02-13 23:26:24 +00:00
|
|
|
if (mUploadTexture) {
|
2012-03-22 05:48:41 +00:00
|
|
|
gl()->MakeCurrent();
|
2013-02-13 23:26:24 +00:00
|
|
|
gl()->fDeleteTextures(1, &mUploadTexture);
|
|
|
|
mUploadTexture = 0;
|
2012-01-16 05:41:55 +00:00
|
|
|
}
|
|
|
|
}
|