2010-04-20 07:52:19 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:set ts=2 sts=2 sw=2 et cin:
|
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-04-20 07:52:19 -07:00
|
|
|
|
|
|
|
#ifndef nsCoreAnimationSupport_h__
|
|
|
|
#define nsCoreAnimationSupport_h__
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
|
2012-01-31 18:18:30 -08:00
|
|
|
#import <OpenGL/OpenGL.h>
|
2010-04-20 07:52:19 -07:00
|
|
|
#import "ApplicationServices/ApplicationServices.h"
|
|
|
|
#include "gfxTypes.h"
|
2012-07-31 08:11:57 -07:00
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "mozilla/gfx/MacIOSurface.h"
|
2010-04-20 07:52:19 -07:00
|
|
|
|
|
|
|
// Get the system color space.
|
2010-05-20 14:48:15 -07:00
|
|
|
CGColorSpaceRef THEBES_API CreateSystemColorSpace();
|
2010-04-20 07:52:19 -07:00
|
|
|
|
|
|
|
// Manages a CARenderer
|
|
|
|
struct _CGLPBufferObject;
|
|
|
|
struct _CGLContextObject;
|
|
|
|
|
2011-10-20 13:32:38 -07:00
|
|
|
enum AllowOfflineRendererEnum { ALLOW_OFFLINE_RENDERER, DISALLOW_OFFLINE_RENDERER };
|
|
|
|
|
2012-07-31 08:11:57 -07:00
|
|
|
class nsCARenderer : public mozilla::RefCounted<nsCARenderer> {
|
2010-04-20 07:52:19 -07:00
|
|
|
public:
|
2012-08-12 03:43:47 -07:00
|
|
|
nsCARenderer() : mCARenderer(nullptr), mFBOTexture(0), mOpenGLContext(nullptr),
|
|
|
|
mCGImage(nullptr), mCGData(nullptr), mIOSurface(nullptr), mFBO(0),
|
2012-07-20 04:16:17 -07:00
|
|
|
mIOTexture(0),
|
2011-10-20 13:32:38 -07:00
|
|
|
mUnsupportedWidth(UINT32_MAX), mUnsupportedHeight(UINT32_MAX),
|
|
|
|
mAllowOfflineRenderer(DISALLOW_OFFLINE_RENDERER) {}
|
2010-04-20 07:52:19 -07:00
|
|
|
~nsCARenderer();
|
2011-10-20 13:32:38 -07:00
|
|
|
nsresult SetupRenderer(void* aCALayer, int aWidth, int aHeight,
|
|
|
|
AllowOfflineRendererEnum aAllowOfflineRenderer);
|
2010-04-20 07:52:19 -07:00
|
|
|
nsresult Render(int aWidth, int aHeight, CGImageRef *aOutCAImage);
|
2012-08-12 03:43:47 -07:00
|
|
|
bool isInit() { return mCARenderer != nullptr; }
|
2010-04-20 07:52:19 -07:00
|
|
|
/*
|
|
|
|
* Render the CALayer to an IOSurface. If no IOSurface
|
|
|
|
* is attached then an internal pixel buffer will be
|
|
|
|
* used.
|
2011-10-13 07:36:59 -07:00
|
|
|
*/
|
2012-07-31 08:11:57 -07:00
|
|
|
void AttachIOSurface(mozilla::RefPtr<MacIOSurface> aSurface);
|
2011-07-12 07:31:18 -07:00
|
|
|
IOSurfaceID GetIOSurfaceID();
|
2011-10-13 07:36:59 -07:00
|
|
|
static nsresult DrawSurfaceToCGContext(CGContextRef aContext,
|
2012-07-31 08:11:57 -07:00
|
|
|
MacIOSurface *surf,
|
2011-10-13 07:36:59 -07:00
|
|
|
CGColorSpaceRef aColorSpace,
|
2010-04-20 07:52:19 -07:00
|
|
|
int aX, int aY,
|
2011-06-24 07:49:42 -07:00
|
|
|
size_t aWidth, size_t aHeight);
|
2011-10-13 07:36:59 -07:00
|
|
|
|
2011-07-12 07:31:18 -07:00
|
|
|
// Remove & Add the layer without destroying
|
|
|
|
// the renderer for fast back buffer swapping.
|
|
|
|
void DettachCALayer();
|
|
|
|
void AttachCALayer(void *aCALayer);
|
2011-06-30 09:46:25 -07:00
|
|
|
#ifdef DEBUG
|
2012-07-31 08:11:57 -07:00
|
|
|
static void SaveToDisk(MacIOSurface *surf);
|
2011-06-30 09:46:25 -07:00
|
|
|
#endif
|
2010-04-20 07:52:19 -07:00
|
|
|
private:
|
2011-11-15 14:36:06 -08:00
|
|
|
void SetBounds(int aWidth, int aHeight);
|
|
|
|
void SetViewport(int aWidth, int aHeight);
|
2010-04-20 07:52:19 -07:00
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
void *mCARenderer;
|
2011-10-20 13:32:38 -07:00
|
|
|
GLuint mFBOTexture;
|
|
|
|
_CGLContextObject *mOpenGLContext;
|
|
|
|
CGImageRef mCGImage;
|
|
|
|
void *mCGData;
|
2012-07-31 08:11:57 -07:00
|
|
|
mozilla::RefPtr<MacIOSurface> mIOSurface;
|
2011-10-20 13:32:38 -07:00
|
|
|
uint32_t mFBO;
|
|
|
|
uint32_t mIOTexture;
|
|
|
|
uint32_t mUnsupportedWidth;
|
|
|
|
uint32_t mUnsupportedHeight;
|
|
|
|
AllowOfflineRendererEnum mAllowOfflineRenderer;
|
2010-04-20 07:52:19 -07:00
|
|
|
};
|
|
|
|
|
2012-07-31 08:11:57 -07:00
|
|
|
enum CGContextType {
|
|
|
|
CG_CONTEXT_TYPE_UNKNOWN = 0,
|
|
|
|
// These are found by inspection, it's possible they could be changed
|
|
|
|
CG_CONTEXT_TYPE_BITMAP = 4,
|
|
|
|
CG_CONTEXT_TYPE_IOSURFACE = 8
|
|
|
|
};
|
|
|
|
|
|
|
|
CGContextType GetContextType(CGContextRef ref);
|
|
|
|
|
2010-04-20 07:52:19 -07:00
|
|
|
#endif // XP_MACOSX
|
|
|
|
#endif // nsCoreAnimationSupport_h__
|
|
|
|
|