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