|
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/. */ |
|
6 |
|
7 #ifndef nsCoreAnimationSupport_h__ |
|
8 #define nsCoreAnimationSupport_h__ |
|
9 #ifdef XP_MACOSX |
|
10 |
|
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" |
|
17 #include "nsError.h" |
|
18 |
|
19 // Get the system color space. |
|
20 CGColorSpaceRef CreateSystemColorSpace(); |
|
21 |
|
22 // Manages a CARenderer |
|
23 struct _CGLPBufferObject; |
|
24 struct _CGLContextObject; |
|
25 |
|
26 enum AllowOfflineRendererEnum { ALLOW_OFFLINE_RENDERER, DISALLOW_OFFLINE_RENDERER }; |
|
27 |
|
28 class nsCARenderer : public mozilla::RefCounted<nsCARenderer> { |
|
29 public: |
|
30 MOZ_DECLARE_REFCOUNTED_TYPENAME(nsCARenderer) |
|
31 nsCARenderer() : mCARenderer(nullptr), mWrapperCALayer(nullptr), mFBOTexture(0), |
|
32 mOpenGLContext(nullptr), mCGImage(nullptr), mCGData(nullptr), |
|
33 mIOSurface(nullptr), mFBO(0), mIOTexture(0), |
|
34 mUnsupportedWidth(UINT32_MAX), mUnsupportedHeight(UINT32_MAX), |
|
35 mAllowOfflineRenderer(DISALLOW_OFFLINE_RENDERER), |
|
36 mContentsScaleFactor(1.0) {} |
|
37 ~nsCARenderer(); |
|
38 // aWidth and aHeight are in "display pixels". A "display pixel" is the |
|
39 // smallest fully addressable part of a display. But in HiDPI modes each |
|
40 // "display pixel" corresponds to more than one device pixel. Multiply |
|
41 // display pixels by aContentsScaleFactor to get device pixels. |
|
42 nsresult SetupRenderer(void* aCALayer, int aWidth, int aHeight, |
|
43 double aContentsScaleFactor, |
|
44 AllowOfflineRendererEnum aAllowOfflineRenderer); |
|
45 // aWidth and aHeight are in "display pixels". Multiply by |
|
46 // aContentsScaleFactor to get device pixels. |
|
47 nsresult Render(int aWidth, int aHeight, |
|
48 double aContentsScaleFactor, |
|
49 CGImageRef *aOutCAImage); |
|
50 bool isInit() { return mCARenderer != nullptr; } |
|
51 /* |
|
52 * Render the CALayer to an IOSurface. If no IOSurface |
|
53 * is attached then an internal pixel buffer will be |
|
54 * used. |
|
55 */ |
|
56 void AttachIOSurface(mozilla::RefPtr<MacIOSurface> aSurface); |
|
57 IOSurfaceID GetIOSurfaceID(); |
|
58 // aX, aY, aWidth and aHeight are in "display pixels". Multiply by |
|
59 // surf->GetContentsScaleFactor() to get device pixels. |
|
60 static nsresult DrawSurfaceToCGContext(CGContextRef aContext, |
|
61 MacIOSurface *surf, |
|
62 CGColorSpaceRef aColorSpace, |
|
63 int aX, int aY, |
|
64 size_t aWidth, size_t aHeight); |
|
65 |
|
66 // Remove & Add the layer without destroying |
|
67 // the renderer for fast back buffer swapping. |
|
68 void DetachCALayer(); |
|
69 void AttachCALayer(void *aCALayer); |
|
70 #ifdef DEBUG |
|
71 static void SaveToDisk(MacIOSurface *surf); |
|
72 #endif |
|
73 private: |
|
74 // aWidth and aHeight are in "display pixels". Multiply by |
|
75 // mContentsScaleFactor to get device pixels. |
|
76 void SetBounds(int aWidth, int aHeight); |
|
77 // aWidth and aHeight are in "display pixels". Multiply by |
|
78 // mContentsScaleFactor to get device pixels. |
|
79 void SetViewport(int aWidth, int aHeight); |
|
80 void Destroy(); |
|
81 |
|
82 void *mCARenderer; |
|
83 void *mWrapperCALayer; |
|
84 GLuint mFBOTexture; |
|
85 _CGLContextObject *mOpenGLContext; |
|
86 CGImageRef mCGImage; |
|
87 void *mCGData; |
|
88 mozilla::RefPtr<MacIOSurface> mIOSurface; |
|
89 uint32_t mFBO; |
|
90 uint32_t mIOTexture; |
|
91 int mUnsupportedWidth; |
|
92 int mUnsupportedHeight; |
|
93 AllowOfflineRendererEnum mAllowOfflineRenderer; |
|
94 double mContentsScaleFactor; |
|
95 }; |
|
96 |
|
97 #endif // XP_MACOSX |
|
98 #endif // nsCoreAnimationSupport_h__ |
|
99 |