1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 // vim:set ts=2 sts=2 sw=2 et cin:
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef nsCoreAnimationSupport_h__
8 #define nsCoreAnimationSupport_h__
11 #import <OpenGL/OpenGL.h>
13 #import "ApplicationServices/ApplicationServices.h"
15 #include "mozilla/RefPtr.h"
16 #include "mozilla/gfx/MacIOSurface.h"
19 // Get the system color space.
20 CGColorSpaceRef
CreateSystemColorSpace();
22 // Manages a CARenderer
23 struct _CGLPBufferObject
;
24 struct _CGLContextObject
;
26 enum AllowOfflineRendererEnum
{ ALLOW_OFFLINE_RENDERER
, DISALLOW_OFFLINE_RENDERER
};
28 class nsCARenderer
: public mozilla::RefCounted
<nsCARenderer
> {
30 nsCARenderer() : mCARenderer(nullptr), mWrapperCALayer(nullptr), mFBOTexture(0),
31 mOpenGLContext(nullptr), mCGImage(nullptr), mCGData(nullptr),
32 mIOSurface(nullptr), mFBO(0), mIOTexture(0),
33 mUnsupportedWidth(UINT32_MAX
), mUnsupportedHeight(UINT32_MAX
),
34 mAllowOfflineRenderer(DISALLOW_OFFLINE_RENDERER
),
35 mContentsScaleFactor(1.0) {}
37 // aWidth and aHeight are in "display pixels". A "display pixel" is the
38 // smallest fully addressable part of a display. But in HiDPI modes each
39 // "display pixel" corresponds to more than one device pixel. Multiply
40 // display pixels by aContentsScaleFactor to get device pixels.
41 nsresult
SetupRenderer(void* aCALayer
, int aWidth
, int aHeight
,
42 double aContentsScaleFactor
,
43 AllowOfflineRendererEnum aAllowOfflineRenderer
);
44 // aWidth and aHeight are in "display pixels". Multiply by
45 // aContentsScaleFactor to get device pixels.
46 nsresult
Render(int aWidth
, int aHeight
,
47 double aContentsScaleFactor
,
48 CGImageRef
*aOutCAImage
);
49 bool isInit() { return mCARenderer
!= nullptr; }
51 * Render the CALayer to an IOSurface. If no IOSurface
52 * is attached then an internal pixel buffer will be
55 void AttachIOSurface(mozilla::RefPtr
<MacIOSurface
> aSurface
);
56 IOSurfaceID
GetIOSurfaceID();
57 // aX, aY, aWidth and aHeight are in "display pixels". Multiply by
58 // surf->GetContentsScaleFactor() to get device pixels.
59 static nsresult
DrawSurfaceToCGContext(CGContextRef aContext
,
61 CGColorSpaceRef aColorSpace
,
63 size_t aWidth
, size_t aHeight
);
65 // Remove & Add the layer without destroying
66 // the renderer for fast back buffer swapping.
68 void AttachCALayer(void *aCALayer
);
70 static void SaveToDisk(MacIOSurface
*surf
);
73 // aWidth and aHeight are in "display pixels". Multiply by
74 // mContentsScaleFactor to get device pixels.
75 void SetBounds(int aWidth
, int aHeight
);
76 // aWidth and aHeight are in "display pixels". Multiply by
77 // mContentsScaleFactor to get device pixels.
78 void SetViewport(int aWidth
, int aHeight
);
82 void *mWrapperCALayer
;
84 _CGLContextObject
*mOpenGLContext
;
87 mozilla::RefPtr
<MacIOSurface
> mIOSurface
;
90 int mUnsupportedWidth
;
91 int mUnsupportedHeight
;
92 AllowOfflineRendererEnum mAllowOfflineRenderer
;
93 double mContentsScaleFactor
;
97 #endif // nsCoreAnimationSupport_h__