Skip to content

Commit

Permalink
b=570660; add ability to resize pbuffer GL contexts; r=joe
Browse files Browse the repository at this point in the history
  • Loading branch information
vvuk committed Jun 9, 2010
1 parent 70bc39d commit 77abe94
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 15 deletions.
16 changes: 16 additions & 0 deletions content/canvas/src/WebGLContext.cpp
Expand Up @@ -152,6 +152,22 @@ WebGLContext::SetDimensions(PRInt32 width, PRInt32 height)
if (mWidth == width && mHeight == height)
return NS_OK;

if (gl) {
// hey we already have something
if (gl->Resize(gfxIntSize(width, height))) {

mWidth = width;
mHeight = height;

gl->fViewport(0, 0, mWidth, mHeight);
gl->fClearColor(0, 0, 0, 0);
gl->fClear(LOCAL_GL_COLOR_BUFFER_BIT | LOCAL_GL_DEPTH_BUFFER_BIT | LOCAL_GL_STENCIL_BUFFER_BIT);

// great success!
return NS_OK;
}
}

LogMessage("Canvas 3D: creating PBuffer...");

GLContextProvider::ContextFormat format(GLContextProvider::ContextFormat::BasicRGBA32);
Expand Down
35 changes: 23 additions & 12 deletions gfx/thebes/public/GLContext.h
@@ -1,3 +1,4 @@
/* -*- Mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40; -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
Expand Down Expand Up @@ -45,7 +46,7 @@
#endif

#include "GLDefs.h"
#include "gfxTypes.h"
#include "gfxRect.h"
#include "nsISupportsImpl.h"
#include "prlink.h"

Expand Down Expand Up @@ -84,19 +85,19 @@ class LibrarySymbolLoader
} SymLoadStruct;

PRBool LoadSymbols(SymLoadStruct *firstStruct,
PRBool tryplatform = PR_FALSE,
const char *prefix = nsnull);
PRBool tryplatform = PR_FALSE,
const char *prefix = nsnull);

/*
* Static version of the functions in this class
*/
static PRFuncPtr LookupSymbol(PRLibrary *lib,
const char *symname,
PlatformLookupFunction lookupFunction = nsnull);
const char *symname,
PlatformLookupFunction lookupFunction = nsnull);
static PRBool LoadSymbols(PRLibrary *lib,
SymLoadStruct *firstStruct,
PlatformLookupFunction lookupFunction = nsnull,
const char *prefix = nsnull);
SymLoadStruct *firstStruct,
PlatformLookupFunction lookupFunction = nsnull,
const char *prefix = nsnull);
protected:
LibrarySymbolLoader() {
mLibrary = nsnull;
Expand Down Expand Up @@ -125,13 +126,13 @@ class GLContext
virtual PRBool SetupLookupFunction() = 0;

void *GetUserData(void *aKey) {
void *result = nsnull;
mUserData.Get(aKey, &result);
return result;
void *result = nsnull;
mUserData.Get(aKey, &result);
return result;
}

void SetUserData(void *aKey, void *aValue) {
mUserData.Put(aKey, aValue);
mUserData.Put(aKey, aValue);
}

enum NativeDataType {
Expand All @@ -143,6 +144,16 @@ class GLContext
};

virtual void *GetNativeData(NativeDataType aType) { return NULL; }

/* If this is a PBuffer context, resize the pbufer to the given dimensions,
* keping the same format and attributes. If the resize succeeds, return
* PR_TRUE. Otherwise, or if this is not a pbuffer, return PR_FALSE.
*
* On a successful resize, the previous contents of the pbuffer are cleared,
* and the new contents are undefined.
*/
virtual PRBool Resize(const gfxIntSize& aNewSize) { return PR_FALSE; }

protected:

PRBool mInitialized;
Expand Down
49 changes: 46 additions & 3 deletions gfx/thebes/src/GLContextProviderWGL.cpp
Expand Up @@ -181,11 +181,12 @@ class GLContextWGL : public GLContext
{
public:
GLContextWGL(HDC aDC, HGLRC aContext)
: mContext(aContext), mDC(aDC), mPBuffer(nsnull)
: mContext(aContext), mDC(aDC), mPBuffer(nsnull), mPixelFormat(-1)
{ }

GLContextWGL(HANDLE aPBuffer) {
GLContextWGL(HANDLE aPBuffer, int aPixelFormat) {
mPBuffer = aPBuffer;
mPixelFormat = aPixelFormat;
mDC = sWGLLibrary.fGetPbufferDC(mPBuffer);
mContext = sWGLLibrary.fCreateContext(mDC);
}
Expand Down Expand Up @@ -241,10 +242,52 @@ class GLContextWGL : public GLContext
}
}

PRBool Resize(const gfxIntSize& aNewSize) {
if (!mPBuffer)
return PR_FALSE;

nsTArray<int> pbattribs;
pbattribs.AppendElement(LOCAL_WGL_TEXTURE_FORMAT_ARB);
// XXX fixme after bug 571092 lands and we have the format available
if (true /*aFormat.alpha > 0*/) {
pbattribs.AppendElement(LOCAL_WGL_TEXTURE_RGBA_ARB);
} else {
pbattribs.AppendElement(LOCAL_WGL_TEXTURE_RGB_ARB);
}
pbattribs.AppendElement(LOCAL_WGL_TEXTURE_TARGET_ARB);
pbattribs.AppendElement(LOCAL_WGL_TEXTURE_2D_ARB);

pbattribs.AppendElement(0);

HANDLE newbuf = sWGLLibrary.fCreatePbuffer(gDummyWindowDC, mPixelFormat,
aNewSize.width, aNewSize.height,
pbattribs.Elements());
if (!newbuf)
return PR_FALSE;

bool isCurrent = false;
if (sWGLLibrary.fGetCurrentContext() == mContext) {
sWGLLibrary.fMakeCurrent(NULL, NULL);
isCurrent = true;
}

// hey, it worked!
sWGLLibrary.fDestroyPbuffer(mPBuffer);

mPBuffer = newbuf;
mDC = sWGLLibrary.fGetPbufferDC(mPBuffer);

if (isCurrent)
MakeCurrent();

return PR_TRUE;
}

private:
HGLRC mContext;
HDC mDC;
HANDLE mPBuffer;
int mPixelFormat;
};

already_AddRefed<GLContext>
Expand Down Expand Up @@ -362,7 +405,7 @@ GLContextProvider::CreatePBuffer(const gfxIntSize& aSize, const ContextFormat& a
return nsnull;
}

nsRefPtr<GLContextWGL> glContext = new GLContextWGL(pbuffer);
nsRefPtr<GLContextWGL> glContext = new GLContextWGL(pbuffer, chosenFormat);
glContext->Init();

return glContext.forget().get();
Expand Down

0 comments on commit 77abe94

Please sign in to comment.