зеркало из https://github.com/mozilla/gecko-dev.git
Bug 561957. Support GL backend on Mac OS X. r=vlad
This commit is contained in:
Родитель
352f57cb25
Коммит
2c6e57bb9c
|
@ -48,19 +48,11 @@
|
|||
* We don't include GLDefs.h here since we don't want to drag in all defines
|
||||
* in for all our users.
|
||||
*/
|
||||
#if defined(__APPLE__)
|
||||
typedef unsigned long GLenum;
|
||||
typedef unsigned long GLbitfield;
|
||||
typedef unsigned long GLuint;
|
||||
typedef long GLint;
|
||||
typedef long GLsizei;
|
||||
#else
|
||||
typedef unsigned int GLenum;
|
||||
typedef unsigned int GLbitfield;
|
||||
typedef unsigned int GLuint;
|
||||
typedef int GLint;
|
||||
typedef int GLsizei;
|
||||
#endif
|
||||
|
||||
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
||||
|
||||
|
|
|
@ -37,6 +37,6 @@ static const GLchar *sYUVLayerPS = SHADER_GLOBAL_VARS "void main() \
|
|||
color.r = yuv.g * 1.164 + yuv.r * 1.596; \
|
||||
color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b; \
|
||||
color.b = yuv.g * 1.164 + yuv.b * 2.018; \
|
||||
color.a = 1.0f; \
|
||||
color.a = 1.0; \
|
||||
gl_FragColor = color * uLayerOpacity; \
|
||||
}";
|
||||
|
|
|
@ -106,6 +106,7 @@ public:
|
|||
virtual PRBool MakeCurrent() = 0;
|
||||
virtual PRBool SetupLookupFunction() = 0;
|
||||
|
||||
virtual void *GetNativeContext() { return NULL; }
|
||||
protected:
|
||||
|
||||
PRBool mInitialized;
|
||||
|
|
|
@ -45,19 +45,11 @@
|
|||
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__APPLE__)
|
||||
typedef unsigned long GLenum;
|
||||
typedef unsigned long GLbitfield;
|
||||
typedef unsigned long GLuint;
|
||||
typedef long GLint;
|
||||
typedef long GLsizei;
|
||||
#else
|
||||
typedef unsigned int GLenum;
|
||||
typedef unsigned int GLbitfield;
|
||||
typedef unsigned int GLuint;
|
||||
typedef int GLint;
|
||||
typedef int GLsizei;
|
||||
#endif
|
||||
typedef char realGLboolean;
|
||||
typedef signed char GLbyte;
|
||||
typedef short GLshort;
|
||||
|
|
|
@ -0,0 +1,157 @@
|
|||
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Mozilla Foundation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Bas Schouten <bschouten@mozilla.com>
|
||||
* Matt Woodrow <mwoodrow@mozilla.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "GLContextProvider.h"
|
||||
#include "nsDebug.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "OpenGL/OpenGL.h"
|
||||
#include <OpenGL/gl.h>
|
||||
#include <AppKit/NSOpenGL.h>
|
||||
|
||||
namespace mozilla {
|
||||
namespace gl {
|
||||
|
||||
GLContextProvider sGLContextProvider;
|
||||
|
||||
class CGLLibrary
|
||||
{
|
||||
public:
|
||||
CGLLibrary() : mInitialized(PR_FALSE) {}
|
||||
|
||||
PRBool EnsureInitialized()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
if (!mOGLLibrary) {
|
||||
mOGLLibrary = PR_LoadLibrary("/System/Library/Frameworks/OpenGL.framework/OpenGL");
|
||||
if (!mOGLLibrary) {
|
||||
NS_WARNING("Couldn't load OpenGL Framework.");
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
mInitialized = PR_TRUE;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
private:
|
||||
PRBool mInitialized;
|
||||
PRLibrary *mOGLLibrary;
|
||||
};
|
||||
|
||||
CGLLibrary sCGLLibrary;
|
||||
|
||||
class GLContextCGL : public GLContext
|
||||
{
|
||||
public:
|
||||
GLContextCGL(NSOpenGLContext *aContext)
|
||||
: mContext(aContext) {}
|
||||
|
||||
~GLContextCGL()
|
||||
{
|
||||
[mContext release];
|
||||
}
|
||||
|
||||
PRBool Init()
|
||||
{
|
||||
MakeCurrent();
|
||||
return InitWithPrefix("gl", PR_TRUE);
|
||||
}
|
||||
|
||||
void *GetNativeContext()
|
||||
{
|
||||
return mContext;
|
||||
}
|
||||
|
||||
PRBool MakeCurrent()
|
||||
{
|
||||
[mContext makeCurrentContext];
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool SetupLookupFunction()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
private:
|
||||
NSOpenGLContext *mContext;
|
||||
};
|
||||
|
||||
already_AddRefed<GLContext>
|
||||
GLContextProvider::CreateForWindow(nsIWidget *aWidget)
|
||||
{
|
||||
if (!sCGLLibrary.EnsureInitialized()) {
|
||||
return nsnull;
|
||||
}
|
||||
NSOpenGLPixelFormatAttribute attributes [] = {
|
||||
NSOpenGLPFAAccelerated,
|
||||
(NSOpenGLPixelFormatAttribute)nil
|
||||
};
|
||||
|
||||
NSOpenGLPixelFormat *pixelFormat = [[(NSOpenGLPixelFormat *)[NSOpenGLPixelFormat alloc]
|
||||
initWithAttributes:attributes]
|
||||
autorelease];
|
||||
NSOpenGLContext *context = [[NSOpenGLContext alloc]
|
||||
initWithFormat:pixelFormat
|
||||
shareContext:NULL];
|
||||
|
||||
if (context == nil) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsRefPtr<GLContextCGL> glContext = new GLContextCGL(context);
|
||||
if (!glContext->Init()) {
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
NSView *childView = (NSView *)aWidget->GetNativeData(NS_NATIVE_WIDGET);
|
||||
if ([context view] != childView) {
|
||||
[context setView:childView];
|
||||
}
|
||||
|
||||
return glContext.forget().get();
|
||||
}
|
||||
|
||||
already_AddRefed<GLContext>
|
||||
GLContextProvider::CreatePbuffer(const gfxSize &)
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
} /* namespace gl */
|
||||
} /* namespace mozilla */
|
|
@ -177,7 +177,7 @@ CPPSRCS += gfxQuartzNativeDrawing.cpp
|
|||
CMMSRCS = gfxMacPlatformFontList.mm
|
||||
|
||||
# Always link with OpenGL/AGL
|
||||
EXTRA_DSO_LDOPTS += -framework OpenGL -framework AGL -framework QuickTime
|
||||
EXTRA_DSO_LDOPTS += -framework OpenGL -framework AGL -framework QuickTime -framework AppKit
|
||||
endif
|
||||
|
||||
CSRCS += woff.c
|
||||
|
@ -191,8 +191,12 @@ else
|
|||
CPPSRCS += GLContextProviderNull.cpp
|
||||
endif
|
||||
else
|
||||
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
|
||||
CMMSRCS += GLContextProviderCGL.mm
|
||||
else
|
||||
CPPSRCS += GLContextProviderNull.cpp
|
||||
endif
|
||||
endif
|
||||
|
||||
DEFINES += -DIMPL_THEBES -DWOFF_MOZILLA_CLIENT
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
|
||||
#import <Carbon/Carbon.h>
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <AppKit/NSOpenGL.h>
|
||||
|
||||
class gfxASurface;
|
||||
class nsChildView;
|
||||
|
@ -161,6 +162,8 @@ extern "C" long TSMProcessRawKeyEvent(EventRef carbonEvent);
|
|||
TSMDocumentID mPluginTSMDoc;
|
||||
#endif
|
||||
|
||||
NSOpenGLContext *mContext;
|
||||
|
||||
// Simple gestures support
|
||||
//
|
||||
// mGestureState is used to detect when Cocoa has called both
|
||||
|
@ -209,6 +212,10 @@ extern "C" long TSMProcessRawKeyEvent(EventRef carbonEvent);
|
|||
- (void) processPluginKeyEvent:(EventRef)aKeyEvent;
|
||||
#endif
|
||||
|
||||
- (void)update;
|
||||
- (void)lockFocus;
|
||||
- (void) _surfaceNeedsUpdate:(NSNotification*)notification;
|
||||
|
||||
// Simple gestures support
|
||||
//
|
||||
// XXX - The swipeWithEvent, beginGestureWithEvent, magnifyWithEvent,
|
||||
|
@ -279,6 +286,8 @@ public:
|
|||
NS_IMETHOD SetParent(nsIWidget* aNewParent);
|
||||
virtual nsIWidget* GetParent(void);
|
||||
|
||||
LayerManager* GetLayerManager();
|
||||
|
||||
NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
|
||||
PRInt32 *aX, PRInt32 *aY);
|
||||
NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
|
||||
|
|
|
@ -78,11 +78,14 @@
|
|||
#include "gfxContext.h"
|
||||
#include "gfxQuartzSurface.h"
|
||||
#include "nsRegion.h"
|
||||
#include "Layers.h"
|
||||
#include "LayerManagerOGL.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
using namespace mozilla::layers;
|
||||
#undef DEBUG_IME
|
||||
#undef DEBUG_UPDATE
|
||||
#undef INVALIDATE_DEBUGGING // flash areas as they are invalidated
|
||||
|
@ -952,6 +955,17 @@ nsChildView::GetParent()
|
|||
return mParentWidget;
|
||||
}
|
||||
|
||||
LayerManager*
|
||||
nsChildView::GetLayerManager()
|
||||
{
|
||||
nsCocoaWindow* window = GetXULWindowWidget();
|
||||
if (window->GetAcceleratedRendering() != mUseAcceleratedRendering) {
|
||||
mLayerManager = NULL;
|
||||
mUseAcceleratedRendering = window->GetAcceleratedRendering();
|
||||
}
|
||||
return nsBaseWidget::GetLayerManager();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChildView::Enable(PRBool aState)
|
||||
{
|
||||
return NS_OK;
|
||||
|
@ -2231,6 +2245,10 @@ NSEvent* gLastDragMouseDownEvent = nil;
|
|||
name:@"AppleAquaScrollBarVariantChanged"
|
||||
object:nil
|
||||
suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(_surfaceNeedsUpdate:)
|
||||
name:NSViewGlobalFrameDidChangeNotification
|
||||
object:self];
|
||||
|
||||
return self;
|
||||
|
||||
|
@ -2504,6 +2522,14 @@ NSEvent* gLastDragMouseDownEvent = nil;
|
|||
|
||||
[super lockFocus];
|
||||
|
||||
if (mContext) {
|
||||
if ([mContext view] != self) {
|
||||
[mContext setView:self];
|
||||
}
|
||||
|
||||
[mContext makeCurrentContext];
|
||||
}
|
||||
|
||||
NS_OBJC_END_TRY_ABORT_BLOCK;
|
||||
}
|
||||
|
||||
|
@ -2543,6 +2569,18 @@ static BOOL DrawingAtWindowTop(CGContextRef aContext)
|
|||
}
|
||||
}
|
||||
|
||||
-(void)update
|
||||
{
|
||||
if (mContext) {
|
||||
[mContext update];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) _surfaceNeedsUpdate:(NSNotification*)notification
|
||||
{
|
||||
[self update];
|
||||
}
|
||||
|
||||
// The display system has told us that a portion of our view is dirty. Tell
|
||||
// gecko to paint it
|
||||
- (void)drawRect:(NSRect)aRect
|
||||
|
@ -2576,14 +2614,6 @@ static BOOL DrawingAtWindowTop(CGContextRef aContext)
|
|||
CGAffineTransform xform = CGContextGetCTM(aContext);
|
||||
fprintf (stderr, " xform in: [%f %f %f %f %f %f]\n", xform.a, xform.b, xform.c, xform.d, xform.tx, xform.ty);
|
||||
#endif
|
||||
|
||||
// Create Cairo objects.
|
||||
NSSize bufferSize = [self bounds].size;
|
||||
nsRefPtr<gfxQuartzSurface> targetSurface =
|
||||
new gfxQuartzSurface(aContext, gfxSize(bufferSize.width, bufferSize.height));
|
||||
|
||||
nsRefPtr<gfxContext> targetContext = new gfxContext(targetSurface);
|
||||
|
||||
// Create the event so we can fill in its region
|
||||
nsPaintEvent paintEvent(PR_TRUE, NS_PAINT, mGeckoChild);
|
||||
|
||||
|
@ -2612,6 +2642,25 @@ static BOOL DrawingAtWindowTop(CGContextRef aContext)
|
|||
paintEvent.region.Sub(paintEvent.region,
|
||||
nsIntRect(frame.origin.x, frame.origin.y, frame.size.width, frame.size.height));
|
||||
}
|
||||
|
||||
if (mGeckoChild->GetLayerManager()->GetBackendType() == LayerManager::LAYERS_OPENGL) {
|
||||
LayerManagerOGL *manager = static_cast<LayerManagerOGL*>(mGeckoChild->GetLayerManager());
|
||||
manager->SetClippingRegion(paintEvent.region);
|
||||
if (!mContext) {
|
||||
mContext = (NSOpenGLContext *)manager->gl()->GetNativeContext();
|
||||
}
|
||||
[mContext makeCurrentContext];
|
||||
mGeckoChild->DispatchWindowEvent(paintEvent);
|
||||
[mContext flushBuffer];
|
||||
return;
|
||||
}
|
||||
|
||||
// Create Cairo objects.
|
||||
NSSize bufferSize = [self bounds].size;
|
||||
nsRefPtr<gfxQuartzSurface> targetSurface =
|
||||
new gfxQuartzSurface(aContext, gfxSize(bufferSize.width, bufferSize.height));
|
||||
|
||||
nsRefPtr<gfxContext> targetContext = new gfxContext(targetSurface);
|
||||
|
||||
// Set up the clip region.
|
||||
nsIntRegionRectIterator iter(paintEvent.region);
|
||||
|
|
Загрузка…
Ссылка в новой задаче