1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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>
12 # import <OpenGL/gl.h>
13 # import "ApplicationServices/ApplicationServices.h"
14 # include "gfxTypes.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 _CGLContextObject
;
25 enum AllowOfflineRendererEnum
{
26 ALLOW_OFFLINE_RENDERER
,
27 DISALLOW_OFFLINE_RENDERER
30 class nsCARenderer
: public mozilla::RefCounted
<nsCARenderer
> {
32 MOZ_DECLARE_REFCOUNTED_TYPENAME(nsCARenderer
)
34 : mCARenderer(nullptr),
35 mWrapperCALayer(nullptr),
37 mOpenGLContext(nullptr),
43 mUnsupportedWidth(UINT32_MAX
),
44 mUnsupportedHeight(UINT32_MAX
),
45 mAllowOfflineRenderer(DISALLOW_OFFLINE_RENDERER
),
46 mContentsScaleFactor(1.0) {}
48 // aWidth and aHeight are in "display pixels". A "display pixel" is the
49 // smallest fully addressable part of a display. But in HiDPI modes each
50 // "display pixel" corresponds to more than one device pixel. Multiply
51 // display pixels by aContentsScaleFactor to get device pixels.
52 nsresult
SetupRenderer(void* aCALayer
, int aWidth
, int aHeight
,
53 double aContentsScaleFactor
,
54 AllowOfflineRendererEnum aAllowOfflineRenderer
);
55 // aWidth and aHeight are in "display pixels". Multiply by
56 // aContentsScaleFactor to get device pixels.
57 nsresult
Render(int aWidth
, int aHeight
, double aContentsScaleFactor
,
58 CGImageRef
* aOutCAImage
);
59 bool isInit() { return mCARenderer
!= nullptr; }
61 * Render the CALayer to an IOSurface. If no IOSurface
62 * is attached then an internal pixel buffer will be
65 void AttachIOSurface(MacIOSurface
* aSurface
);
66 IOSurfaceID
GetIOSurfaceID();
67 // aX, aY, aWidth and aHeight are in "display pixels". Multiply by
68 // surf->GetContentsScaleFactor() to get device pixels.
69 static nsresult
DrawSurfaceToCGContext(CGContextRef aContext
,
71 CGColorSpaceRef aColorSpace
, int aX
,
72 int aY
, size_t aWidth
, size_t aHeight
);
74 // Remove & Add the layer without destroying
75 // the renderer for fast back buffer swapping.
77 void AttachCALayer(void* aCALayer
);
79 static void SaveToDisk(MacIOSurface
* surf
);
82 // aWidth and aHeight are in "display pixels". Multiply by
83 // mContentsScaleFactor to get device pixels.
84 void SetBounds(int aWidth
, int aHeight
);
85 // aWidth and aHeight are in "display pixels". Multiply by
86 // mContentsScaleFactor to get device pixels.
87 void SetViewport(int aWidth
, int aHeight
);
91 void* mWrapperCALayer
;
93 _CGLContextObject
* mOpenGLContext
;
96 RefPtr
<MacIOSurface
> mIOSurface
;
99 int mUnsupportedWidth
;
100 int mUnsupportedHeight
;
101 AllowOfflineRendererEnum mAllowOfflineRenderer
;
102 double mContentsScaleFactor
;
106 #endif // nsCoreAnimationSupport_h__