michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: // vim:set ts=2 sts=2 sw=2 et cin: michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsCoreAnimationSupport_h__ michael@0: #define nsCoreAnimationSupport_h__ michael@0: #ifdef XP_MACOSX michael@0: michael@0: #import michael@0: #import michael@0: #import "ApplicationServices/ApplicationServices.h" michael@0: #include "gfxTypes.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "mozilla/gfx/MacIOSurface.h" michael@0: #include "nsError.h" michael@0: michael@0: // Get the system color space. michael@0: CGColorSpaceRef CreateSystemColorSpace(); michael@0: michael@0: // Manages a CARenderer michael@0: struct _CGLPBufferObject; michael@0: struct _CGLContextObject; michael@0: michael@0: enum AllowOfflineRendererEnum { ALLOW_OFFLINE_RENDERER, DISALLOW_OFFLINE_RENDERER }; michael@0: michael@0: class nsCARenderer : public mozilla::RefCounted { michael@0: public: michael@0: MOZ_DECLARE_REFCOUNTED_TYPENAME(nsCARenderer) michael@0: nsCARenderer() : mCARenderer(nullptr), mWrapperCALayer(nullptr), mFBOTexture(0), michael@0: mOpenGLContext(nullptr), mCGImage(nullptr), mCGData(nullptr), michael@0: mIOSurface(nullptr), mFBO(0), mIOTexture(0), michael@0: mUnsupportedWidth(UINT32_MAX), mUnsupportedHeight(UINT32_MAX), michael@0: mAllowOfflineRenderer(DISALLOW_OFFLINE_RENDERER), michael@0: mContentsScaleFactor(1.0) {} michael@0: ~nsCARenderer(); michael@0: // aWidth and aHeight are in "display pixels". A "display pixel" is the michael@0: // smallest fully addressable part of a display. But in HiDPI modes each michael@0: // "display pixel" corresponds to more than one device pixel. Multiply michael@0: // display pixels by aContentsScaleFactor to get device pixels. michael@0: nsresult SetupRenderer(void* aCALayer, int aWidth, int aHeight, michael@0: double aContentsScaleFactor, michael@0: AllowOfflineRendererEnum aAllowOfflineRenderer); michael@0: // aWidth and aHeight are in "display pixels". Multiply by michael@0: // aContentsScaleFactor to get device pixels. michael@0: nsresult Render(int aWidth, int aHeight, michael@0: double aContentsScaleFactor, michael@0: CGImageRef *aOutCAImage); michael@0: bool isInit() { return mCARenderer != nullptr; } michael@0: /* michael@0: * Render the CALayer to an IOSurface. If no IOSurface michael@0: * is attached then an internal pixel buffer will be michael@0: * used. michael@0: */ michael@0: void AttachIOSurface(mozilla::RefPtr aSurface); michael@0: IOSurfaceID GetIOSurfaceID(); michael@0: // aX, aY, aWidth and aHeight are in "display pixels". Multiply by michael@0: // surf->GetContentsScaleFactor() to get device pixels. michael@0: static nsresult DrawSurfaceToCGContext(CGContextRef aContext, michael@0: MacIOSurface *surf, michael@0: CGColorSpaceRef aColorSpace, michael@0: int aX, int aY, michael@0: size_t aWidth, size_t aHeight); michael@0: michael@0: // Remove & Add the layer without destroying michael@0: // the renderer for fast back buffer swapping. michael@0: void DetachCALayer(); michael@0: void AttachCALayer(void *aCALayer); michael@0: #ifdef DEBUG michael@0: static void SaveToDisk(MacIOSurface *surf); michael@0: #endif michael@0: private: michael@0: // aWidth and aHeight are in "display pixels". Multiply by michael@0: // mContentsScaleFactor to get device pixels. michael@0: void SetBounds(int aWidth, int aHeight); michael@0: // aWidth and aHeight are in "display pixels". Multiply by michael@0: // mContentsScaleFactor to get device pixels. michael@0: void SetViewport(int aWidth, int aHeight); michael@0: void Destroy(); michael@0: michael@0: void *mCARenderer; michael@0: void *mWrapperCALayer; michael@0: GLuint mFBOTexture; michael@0: _CGLContextObject *mOpenGLContext; michael@0: CGImageRef mCGImage; michael@0: void *mCGData; michael@0: mozilla::RefPtr mIOSurface; michael@0: uint32_t mFBO; michael@0: uint32_t mIOTexture; michael@0: int mUnsupportedWidth; michael@0: int mUnsupportedHeight; michael@0: AllowOfflineRendererEnum mAllowOfflineRenderer; michael@0: double mContentsScaleFactor; michael@0: }; michael@0: michael@0: #endif // XP_MACOSX michael@0: #endif // nsCoreAnimationSupport_h__ michael@0: