Merge m-c to inbound.
[gecko.git] / gfx / 2d / QuartzSupport.h
blobdd9a1968426a718c191d6e9096c79af02640a8e0
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__
9 #ifdef XP_MACOSX
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"
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> {
29 public:
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) {}
36 ~nsCARenderer();
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
53 * used.
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,
60 MacIOSurface *surf,
61 CGColorSpaceRef aColorSpace,
62 int aX, int aY,
63 size_t aWidth, size_t aHeight);
65 // Remove & Add the layer without destroying
66 // the renderer for fast back buffer swapping.
67 void DetachCALayer();
68 void AttachCALayer(void *aCALayer);
69 #ifdef DEBUG
70 static void SaveToDisk(MacIOSurface *surf);
71 #endif
72 private:
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);
79 void Destroy();
81 void *mCARenderer;
82 void *mWrapperCALayer;
83 GLuint mFBOTexture;
84 _CGLContextObject *mOpenGLContext;
85 CGImageRef mCGImage;
86 void *mCGData;
87 mozilla::RefPtr<MacIOSurface> mIOSurface;
88 uint32_t mFBO;
89 uint32_t mIOTexture;
90 int mUnsupportedWidth;
91 int mUnsupportedHeight;
92 AllowOfflineRendererEnum mAllowOfflineRenderer;
93 double mContentsScaleFactor;
96 #endif // XP_MACOSX
97 #endif // nsCoreAnimationSupport_h__