2010-04-20 14:52:19 +00: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 11:12:37 +00: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 14:52:19 +00:00
|
|
|
|
|
|
|
#ifndef nsCoreAnimationSupport_h__
|
|
|
|
#define nsCoreAnimationSupport_h__
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
|
2012-02-01 02:18:30 +00:00
|
|
|
#import <OpenGL/OpenGL.h>
|
2013-09-20 15:56:45 +00:00
|
|
|
#import <OpenGL/gl.h>
|
2010-04-20 14:52:19 +00:00
|
|
|
#import "ApplicationServices/ApplicationServices.h"
|
|
|
|
#include "gfxTypes.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2012-07-31 15:11:57 +00:00
|
|
|
#include "mozilla/gfx/MacIOSurface.h"
|
2013-07-11 20:21:45 +00:00
|
|
|
#include "nsError.h"
|
2010-04-20 14:52:19 +00:00
|
|
|
|
|
|
|
// Get the system color space.
|
2013-05-29 21:59:24 +00:00
|
|
|
CGColorSpaceRef CreateSystemColorSpace();
|
2010-04-20 14:52:19 +00:00
|
|
|
|
|
|
|
// Manages a CARenderer
|
|
|
|
struct _CGLContextObject;
|
|
|
|
|
2011-10-20 20:32:38 +00:00
|
|
|
enum AllowOfflineRendererEnum { ALLOW_OFFLINE_RENDERER, DISALLOW_OFFLINE_RENDERER };
|
|
|
|
|
2012-07-31 15:11:57 +00:00
|
|
|
class nsCARenderer : public mozilla::RefCounted<nsCARenderer> {
|
2010-04-20 14:52:19 +00:00
|
|
|
public:
|
2014-02-21 02:33:49 +00:00
|
|
|
MOZ_DECLARE_REFCOUNTED_TYPENAME(nsCARenderer)
|
2013-01-23 22:19:15 +00:00
|
|
|
nsCARenderer() : mCARenderer(nullptr), mWrapperCALayer(nullptr), mFBOTexture(0),
|
|
|
|
mOpenGLContext(nullptr), mCGImage(nullptr), mCGData(nullptr),
|
|
|
|
mIOSurface(nullptr), mFBO(0), mIOTexture(0),
|
2011-10-20 20:32:38 +00:00
|
|
|
mUnsupportedWidth(UINT32_MAX), mUnsupportedHeight(UINT32_MAX),
|
2012-10-02 19:48:05 +00:00
|
|
|
mAllowOfflineRenderer(DISALLOW_OFFLINE_RENDERER),
|
|
|
|
mContentsScaleFactor(1.0) {}
|
2010-04-20 14:52:19 +00:00
|
|
|
~nsCARenderer();
|
2012-10-02 19:48:05 +00:00
|
|
|
// aWidth and aHeight are in "display pixels". A "display pixel" is the
|
|
|
|
// smallest fully addressable part of a display. But in HiDPI modes each
|
|
|
|
// "display pixel" corresponds to more than one device pixel. Multiply
|
|
|
|
// display pixels by aContentsScaleFactor to get device pixels.
|
2011-10-20 20:32:38 +00:00
|
|
|
nsresult SetupRenderer(void* aCALayer, int aWidth, int aHeight,
|
2012-10-02 19:48:05 +00:00
|
|
|
double aContentsScaleFactor,
|
2011-10-20 20:32:38 +00:00
|
|
|
AllowOfflineRendererEnum aAllowOfflineRenderer);
|
2012-10-02 19:48:05 +00:00
|
|
|
// aWidth and aHeight are in "display pixels". Multiply by
|
|
|
|
// aContentsScaleFactor to get device pixels.
|
|
|
|
nsresult Render(int aWidth, int aHeight,
|
|
|
|
double aContentsScaleFactor,
|
|
|
|
CGImageRef *aOutCAImage);
|
2012-08-12 10:43:47 +00:00
|
|
|
bool isInit() { return mCARenderer != nullptr; }
|
2010-04-20 14:52:19 +00:00
|
|
|
/*
|
|
|
|
* Render the CALayer to an IOSurface. If no IOSurface
|
|
|
|
* is attached then an internal pixel buffer will be
|
|
|
|
* used.
|
2011-10-13 14:36:59 +00:00
|
|
|
*/
|
2014-06-11 22:08:17 +00:00
|
|
|
void AttachIOSurface(MacIOSurface *aSurface);
|
2011-07-12 14:31:18 +00:00
|
|
|
IOSurfaceID GetIOSurfaceID();
|
2012-10-02 19:48:05 +00:00
|
|
|
// aX, aY, aWidth and aHeight are in "display pixels". Multiply by
|
|
|
|
// surf->GetContentsScaleFactor() to get device pixels.
|
2011-10-13 14:36:59 +00:00
|
|
|
static nsresult DrawSurfaceToCGContext(CGContextRef aContext,
|
2012-07-31 15:11:57 +00:00
|
|
|
MacIOSurface *surf,
|
2011-10-13 14:36:59 +00:00
|
|
|
CGColorSpaceRef aColorSpace,
|
2010-04-20 14:52:19 +00:00
|
|
|
int aX, int aY,
|
2011-06-24 14:49:42 +00:00
|
|
|
size_t aWidth, size_t aHeight);
|
2011-10-13 14:36:59 +00:00
|
|
|
|
2011-07-12 14:31:18 +00:00
|
|
|
// Remove & Add the layer without destroying
|
|
|
|
// the renderer for fast back buffer swapping.
|
2013-01-23 22:19:15 +00:00
|
|
|
void DetachCALayer();
|
2011-07-12 14:31:18 +00:00
|
|
|
void AttachCALayer(void *aCALayer);
|
2011-06-30 16:46:25 +00:00
|
|
|
#ifdef DEBUG
|
2012-07-31 15:11:57 +00:00
|
|
|
static void SaveToDisk(MacIOSurface *surf);
|
2011-06-30 16:46:25 +00:00
|
|
|
#endif
|
2010-04-20 14:52:19 +00:00
|
|
|
private:
|
2012-10-02 19:48:05 +00:00
|
|
|
// aWidth and aHeight are in "display pixels". Multiply by
|
|
|
|
// mContentsScaleFactor to get device pixels.
|
2011-11-15 22:36:06 +00:00
|
|
|
void SetBounds(int aWidth, int aHeight);
|
2012-10-02 19:48:05 +00:00
|
|
|
// aWidth and aHeight are in "display pixels". Multiply by
|
|
|
|
// mContentsScaleFactor to get device pixels.
|
2011-11-15 22:36:06 +00:00
|
|
|
void SetViewport(int aWidth, int aHeight);
|
2010-04-20 14:52:19 +00:00
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
void *mCARenderer;
|
2013-01-23 22:19:15 +00:00
|
|
|
void *mWrapperCALayer;
|
2011-10-20 20:32:38 +00:00
|
|
|
GLuint mFBOTexture;
|
|
|
|
_CGLContextObject *mOpenGLContext;
|
|
|
|
CGImageRef mCGImage;
|
|
|
|
void *mCGData;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<MacIOSurface> mIOSurface;
|
2011-10-20 20:32:38 +00:00
|
|
|
uint32_t mFBO;
|
|
|
|
uint32_t mIOTexture;
|
2013-10-09 05:42:26 +00:00
|
|
|
int mUnsupportedWidth;
|
|
|
|
int mUnsupportedHeight;
|
2011-10-20 20:32:38 +00:00
|
|
|
AllowOfflineRendererEnum mAllowOfflineRenderer;
|
2012-10-02 19:48:05 +00:00
|
|
|
double mContentsScaleFactor;
|
2010-04-20 14:52:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // XP_MACOSX
|
|
|
|
#endif // nsCoreAnimationSupport_h__
|
|
|
|
|