2010-05-27 13:04:26 -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-05-17 21:04:22 -07:00
|
|
|
|
|
|
|
#include "CanvasLayerOGL.h"
|
2013-09-04 05:14:52 -07:00
|
|
|
#include "GLContext.h" // for GLContext
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "GLScreenBuffer.h" // for GLScreenBuffer
|
|
|
|
#include "SharedSurface.h" // for SharedSurface
|
|
|
|
#include "SharedSurfaceGL.h" // for SharedSurface_Basic, etc
|
|
|
|
#include "SurfaceStream.h" // for SurfaceStream, etc
|
|
|
|
#include "SurfaceTypes.h" // for SharedSurfaceType, etc
|
|
|
|
#include "gfx3DMatrix.h" // for gfx3DMatrix
|
|
|
|
#include "gfxImageSurface.h" // for gfxImageSurface
|
|
|
|
#include "gfxPlatform.h" // for gfxPlatform
|
|
|
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
|
|
|
#include "mozilla/gfx/Types.h" // for SurfaceFormat, etc
|
|
|
|
#include "nsDebug.h" // for NS_ABORT_IF_FALSE, etc
|
|
|
|
#include "nsPoint.h" // for nsIntPoint
|
|
|
|
#include "nsRect.h" // for nsIntRect
|
|
|
|
#include "nsRegion.h" // for nsIntRegion
|
|
|
|
#include "nsSize.h" // for nsIntSize
|
|
|
|
#include "LayerManagerOGL.h" // for LayerOGL::GLContext, etc
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2012-08-19 12:33:25 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include "mozilla/gfx/MacIOSurface.h"
|
2013-07-17 20:24:15 -07:00
|
|
|
#include "SharedSurfaceIO.h"
|
2012-08-19 12:33:25 -07:00
|
|
|
#endif
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include "gfxWindowsSurface.h"
|
|
|
|
#include "WGLLibrary.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
#include <OpenGL/OpenGL.h>
|
|
|
|
#endif
|
|
|
|
|
2013-04-29 20:16:04 -07:00
|
|
|
#ifdef GL_PROVIDER_GLX
|
2013-08-11 16:17:23 -07:00
|
|
|
#include "GLXLibrary.h" // for GLXLibrary, sDefGLXLib
|
2011-04-20 14:45:57 -07:00
|
|
|
#include "gfxXlibSurface.h"
|
|
|
|
#endif
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::gl;
|
2013-02-13 15:26:24 -08:00
|
|
|
using namespace mozilla::gfx;
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2012-05-31 18:30:08 -07: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 15:48:40 -07: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-17 20:24:14 -07:00
|
|
|
ioSurface->CGLTexImageIOSurface2D(nativeCtx);
|
2012-07-31 15:48:40 -07: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 02:20:52 -07:00
|
|
|
#endif
|
2012-07-31 15:48:40 -07:00
|
|
|
|
2010-08-06 22:09:18 -07:00
|
|
|
void
|
|
|
|
CanvasLayerOGL::Destroy()
|
2010-05-17 21:04:22 -07:00
|
|
|
{
|
2010-08-06 22:09:18 -07:00
|
|
|
if (!mDestroyed) {
|
2012-01-15 21:41:55 -08:00
|
|
|
CleanupResources();
|
2011-10-17 07:59:28 -07:00
|
|
|
mDestroyed = true;
|
2010-06-18 02:21:42 -07:00
|
|
|
}
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CanvasLayerOGL::Initialize(const Data& aData)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_ASSERTION(mCanvasSurface == nullptr, "BasicCanvasLayer::Initialize called twice!");
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
if (aData.mGLContext != nullptr &&
|
|
|
|
aData.mSurface != nullptr)
|
2010-07-18 22:01:14 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
NS_WARNING("CanvasLayerOGL can't have both surface and WebGLContext");
|
2010-07-18 22:01:14 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-03-08 13:41:10 -08:00
|
|
|
mOGLManager->MakeCurrent();
|
|
|
|
|
2012-07-31 15:48:40 -07: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 12:55:03 -07:00
|
|
|
mDrawTarget = aData.mDrawTarget;
|
2013-02-25 13:18:52 -08:00
|
|
|
mCanvasSurface = gfxPlatform::GetPlatform()->CreateThebesSurfaceAliasForDrawTarget_hack(mDrawTarget);
|
2011-11-02 12:55:03 -07:00
|
|
|
mNeedsYFlip = false;
|
|
|
|
} else if (aData.mSurface) {
|
2010-05-24 23:35:35 -07:00
|
|
|
mCanvasSurface = aData.mSurface;
|
2011-10-17 07:59:28 -07:00
|
|
|
mNeedsYFlip = false;
|
2013-04-29 20:16:04 -07:00
|
|
|
#if defined(GL_PROVIDER_GLX)
|
2011-08-04 18:13:25 -07:00
|
|
|
if (aData.mSurface->GetType() == gfxASurface::SurfaceTypeXlib) {
|
|
|
|
gfxXlibSurface *xsurf = static_cast<gfxXlibSurface*>(aData.mSurface);
|
|
|
|
mPixmap = xsurf->GetGLXPixmap();
|
|
|
|
if (mPixmap) {
|
2013-07-04 10:25:50 -07:00
|
|
|
mLayerProgram = ShaderProgramFromContentType(aData.mSurface->GetContentType());
|
2013-02-13 15:26:24 -08:00
|
|
|
MakeTextureIfNeeded(gl(), mUploadTexture);
|
2011-03-08 13:41:10 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-17 21:04:22 -07:00
|
|
|
} else if (aData.mGLContext) {
|
2013-02-13 15:26:24 -08: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-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
if (factory) {
|
|
|
|
screen->Morph(factory, streamType);
|
|
|
|
}
|
2010-05-17 21:04:22 -07: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 11:36:12 -07:00
|
|
|
|
2010-12-16 23:19:28 -08: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 02:20:52 -07:00
|
|
|
GLint texSize = 0;
|
2013-03-07 14:13:09 -08: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 02:20:52 -07:00
|
|
|
MOZ_ASSERT(texSize != 0);
|
2010-12-16 23:19:28 -08:00
|
|
|
if (mBounds.width > (2 + texSize) || mBounds.height > (2 + texSize)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mDelayedUpdates = true;
|
2013-02-13 15:26:24 -08:00
|
|
|
MakeTextureIfNeeded(gl(), mUploadTexture);
|
2010-12-16 23:19:28 -08:00
|
|
|
// This should only ever occur with 2d canvas, WebGL can't already have a texture
|
|
|
|
// of this size can it?
|
2012-07-30 11:36:12 -07:00
|
|
|
NS_ABORT_IF_FALSE(mCanvasSurface || mDrawTarget,
|
2010-12-16 23:19:28 -08:00
|
|
|
"Invalid texture size when WebGL surface already exists at that size?");
|
|
|
|
}
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2011-12-19 11:21:56 -08: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-17 21:04:22 -07:00
|
|
|
void
|
2011-03-27 16:59:46 -07:00
|
|
|
CanvasLayerOGL::UpdateSurface()
|
2010-05-17 21:04:22 -07:00
|
|
|
{
|
2012-09-29 23:20:25 -07:00
|
|
|
if (!IsDirty())
|
2011-03-27 16:59:46 -07:00
|
|
|
return;
|
2012-09-29 23:20:25 -07:00
|
|
|
Painted();
|
2011-03-27 16:59:46 -07:00
|
|
|
|
2010-12-16 23:19:28 -08:00
|
|
|
if (mDestroyed || mDelayedUpdates) {
|
2010-08-06 22:09:18 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-29 20:16:04 -07:00
|
|
|
#if defined(GL_PROVIDER_GLX)
|
2011-03-08 13:41:10 -08:00
|
|
|
if (mPixmap) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-02-13 15:26:24 -08: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-17 20:24:15 -07:00
|
|
|
#ifdef XP_MACOSX
|
|
|
|
case SharedSurfaceType::IOSurface: {
|
|
|
|
SharedSurface_IOSurface *ioSurf = SharedSurface_IOSurface::Cast(surf);
|
|
|
|
mTexture = ioSurf->Texture();
|
|
|
|
mTextureTarget = ioSurf->TextureTarget();
|
2013-07-17 20:24:15 -07:00
|
|
|
mLayerProgram = ioSurf->HasAlpha() ? RGBARectLayerProgramType : RGBXRectLayerProgramType;
|
2013-07-17 20:24:15 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2013-02-13 15:26:24 -08:00
|
|
|
default:
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("Unacceptable SharedSurface type.");
|
2013-02-13 15:26:24 -08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nothingToShow = true;
|
2010-06-23 07:02:32 -07:00
|
|
|
}
|
2013-02-13 15:26:24 -08:00
|
|
|
} else if (mCanvasSurface) {
|
2012-07-31 15:48:40 -07:00
|
|
|
#ifdef XP_MACOSX
|
2013-02-13 15:26:24 -08: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 10:25:50 -07:00
|
|
|
mLayerProgram = RGBARectLayerProgramType;
|
2013-02-13 15:26:24 -08:00
|
|
|
}
|
|
|
|
mDrawTarget->Flush();
|
|
|
|
return;
|
2012-07-31 15:48:40 -07:00
|
|
|
}
|
|
|
|
#endif
|
2013-02-13 15:26:24 -08:00
|
|
|
updatedSurface = mCanvasSurface;
|
2012-08-31 16:44:33 -07:00
|
|
|
} else {
|
2013-06-28 18:38:30 -07:00
|
|
|
MOZ_CRASH("Unhandled canvas layer type.");
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
2012-08-31 16:44:33 -07:00
|
|
|
|
2013-02-13 15:26:24 -08:00
|
|
|
if (updatedSurface) {
|
|
|
|
mOGLManager->MakeCurrent();
|
2013-07-04 10:25:50 -07:00
|
|
|
gfx::SurfaceFormat format =
|
|
|
|
gl()->UploadSurfaceToTexture(updatedSurface,
|
|
|
|
mBounds,
|
|
|
|
mUploadTexture,
|
|
|
|
true,//false,
|
|
|
|
nsIntPoint(0, 0));
|
|
|
|
mLayerProgram = ShaderProgramFromSurfaceFormat(format);
|
2013-02-13 15:26:24 -08:00
|
|
|
mTexture = mUploadTexture;
|
|
|
|
|
|
|
|
if (temporarySurface)
|
|
|
|
delete temporarySurface;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mTexture || nothingToShow);
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-20 20:20:48 -07:00
|
|
|
CanvasLayerOGL::RenderLayer(int aPreviousDestination,
|
2010-11-08 01:06:15 -08:00
|
|
|
const nsIntPoint& aOffset)
|
2010-05-17 21:04:22 -07:00
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
FirePreTransactionCallback();
|
2011-03-27 16:59:46 -07:00
|
|
|
UpdateSurface();
|
2012-08-13 03:10:10 -07:00
|
|
|
if (mOGLManager->CompositingDisabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2011-03-27 16:59:46 -07:00
|
|
|
FireDidTransactionCallback();
|
2011-03-27 16:59:46 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
mOGLManager->MakeCurrent();
|
2010-05-17 21:04:22 -07: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-17 21:04:22 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2010-07-18 22:01:14 -07:00
|
|
|
if (mTexture) {
|
2012-07-31 08:17:43 -07:00
|
|
|
gl()->fBindTexture(mTextureTarget, mTexture);
|
2010-07-18 22:01:14 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
ShaderProgramOGL *program = nullptr;
|
2010-12-16 23:28:30 -08:00
|
|
|
|
2010-12-16 23:19:28 -08:00
|
|
|
nsIntRect drawRect = mBounds;
|
2013-02-13 15:26:24 -08:00
|
|
|
if (mDelayedUpdates) {
|
2012-01-16 13:55:43 -08:00
|
|
|
NS_ABORT_IF_FALSE(mCanvasSurface || mDrawTarget, "WebGL canvases should always be using full texture upload");
|
2012-07-25 08:37:04 -07:00
|
|
|
|
2010-12-16 23:19:28 -08:00
|
|
|
drawRect.IntersectRect(drawRect, GetEffectiveVisibleRegion().GetBounds());
|
|
|
|
|
2013-07-04 10:25:50 -07:00
|
|
|
gfx::SurfaceFormat format =
|
2012-07-25 19:30:20 -07:00
|
|
|
gl()->UploadSurfaceToTexture(mCanvasSurface,
|
2011-02-14 15:23:50 -08:00
|
|
|
nsIntRect(0, 0, drawRect.width, drawRect.height),
|
2013-02-13 15:26:24 -08:00
|
|
|
mUploadTexture,
|
2011-02-14 15:23:50 -08:00
|
|
|
true,
|
|
|
|
drawRect.TopLeft());
|
2013-07-04 10:25:50 -07:00
|
|
|
mLayerProgram = ShaderProgramFromSurfaceFormat(format);
|
2013-02-13 15:26:24 -08:00
|
|
|
mTexture = mUploadTexture;
|
2010-12-16 23:28:30 -08:00
|
|
|
}
|
2011-12-19 11:21:56 -08:00
|
|
|
|
|
|
|
if (!program) {
|
2012-03-18 13:08:53 -07:00
|
|
|
program = mOGLManager->GetProgram(mLayerProgram, GetMaskLayer());
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
|
|
|
|
2013-04-29 20:16:04 -07:00
|
|
|
#if defined(GL_PROVIDER_GLX)
|
2011-03-08 13:41:10 -08:00
|
|
|
if (mPixmap && !mDelayedUpdates) {
|
2012-09-06 17:16:30 -07:00
|
|
|
sDefGLXLib.BindTexImage(mPixmap);
|
2011-03-08 13:41:10 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-10-16 19:31:15 -07:00
|
|
|
gl()->ApplyFilterToBoundTexture(mFilter);
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
program->Activate();
|
2013-07-17 20:24:15 -07:00
|
|
|
if (mLayerProgram == RGBARectLayerProgramType ||
|
|
|
|
mLayerProgram == RGBXRectLayerProgramType) {
|
2012-07-31 08:17:43 -07:00
|
|
|
// This is used by IOSurface that use 0,0...w,h coordinate rather then 0,0..1,1.
|
2013-07-17 20:24:15 -07:00
|
|
|
program->SetTexCoordMultiplier(mBounds.width, mBounds.height);
|
2012-07-31 08:17:43 -07:00
|
|
|
}
|
2010-12-16 23:19:28 -08:00
|
|
|
program->SetLayerQuadRect(drawRect);
|
2010-11-08 01:06:15 -08:00
|
|
|
program->SetLayerTransform(GetEffectiveTransform());
|
2013-07-18 20:05:06 -07:00
|
|
|
program->SetTextureTransform(gfx3DMatrix());
|
2010-11-08 01:06:15 -08:00
|
|
|
program->SetLayerOpacity(GetEffectiveOpacity());
|
2010-05-24 23:35:35 -07:00
|
|
|
program->SetRenderOffset(aOffset);
|
|
|
|
program->SetTextureUnit(0);
|
2012-03-18 13:08:53 -07:00
|
|
|
program->LoadMask(GetMaskLayer());
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2012-02-18 18:23:06 -08:00
|
|
|
if (gl()->CanUploadNonPowerOfTwo()) {
|
|
|
|
mOGLManager->BindAndDrawQuad(program, mNeedsYFlip ? true : false);
|
|
|
|
} else {
|
|
|
|
mOGLManager->BindAndDrawQuadWithTextureRect(program, drawRect, drawRect.Size());
|
|
|
|
}
|
2010-05-17 21:04:22 -07:00
|
|
|
|
2013-04-29 20:16:04 -07:00
|
|
|
#if defined(GL_PROVIDER_GLX)
|
2011-03-08 13:41:10 -08:00
|
|
|
if (mPixmap && !mDelayedUpdates) {
|
2012-09-06 17:16:30 -07:00
|
|
|
sDefGLXLib.ReleaseTexImage(mPixmap);
|
2011-03-08 13:41:10 -08:00
|
|
|
}
|
|
|
|
#endif
|
2010-05-17 21:04:22 -07:00
|
|
|
}
|
2010-10-13 15:55:45 -07:00
|
|
|
|
2012-01-15 21:41:55 -08:00
|
|
|
void
|
|
|
|
CanvasLayerOGL::CleanupResources()
|
|
|
|
{
|
2013-02-13 15:26:24 -08:00
|
|
|
if (mUploadTexture) {
|
2012-03-21 22:48:41 -07:00
|
|
|
gl()->MakeCurrent();
|
2013-02-13 15:26:24 -08:00
|
|
|
gl()->fDeleteTextures(1, &mUploadTexture);
|
|
|
|
mUploadTexture = 0;
|
2012-01-15 21:41:55 -08:00
|
|
|
}
|
|
|
|
}
|