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 "nscore.h"
|
|
|
|
#include "gfxTypes.h"
|
2011-07-12 07:31:18 -07:00
|
|
|
#include "nsAutoPtr.h"
|
2012-01-31 18:18:30 -08:00
|
|
|
#include "nsIOSurface.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 };
|
|
|
|
|
2010-04-20 07:52:19 -07:00
|
|
|
class THEBES_API nsCARenderer {
|
2011-07-12 07:31:18 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(nsCARenderer)
|
2010-04-20 07:52:19 -07:00
|
|
|
public:
|
2012-07-30 07:20:58 -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-07-30 07:20:58 -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
|
|
|
*/
|
2011-07-12 07:31:18 -07:00
|
|
|
void AttachIOSurface(nsRefPtr<nsIOSurface> aSurface);
|
|
|
|
IOSurfaceID GetIOSurfaceID();
|
2011-10-13 07:36:59 -07:00
|
|
|
static nsresult DrawSurfaceToCGContext(CGContextRef aContext,
|
|
|
|
nsIOSurface *surf,
|
|
|
|
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
|
|
|
|
static void SaveToDisk(nsIOSurface *surf);
|
|
|
|
#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;
|
|
|
|
nsRefPtr<nsIOSurface> mIOSurface;
|
|
|
|
uint32_t mFBO;
|
|
|
|
uint32_t mIOTexture;
|
|
|
|
uint32_t mUnsupportedWidth;
|
|
|
|
uint32_t mUnsupportedHeight;
|
|
|
|
AllowOfflineRendererEnum mAllowOfflineRenderer;
|
2010-04-20 07:52:19 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // XP_MACOSX
|
|
|
|
#endif // nsCoreAnimationSupport_h__
|
|
|
|
|