1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/2d/QuartzSupport.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +// vim:set ts=2 sts=2 sw=2 et cin: 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsCoreAnimationSupport_h__ 1.11 +#define nsCoreAnimationSupport_h__ 1.12 +#ifdef XP_MACOSX 1.13 + 1.14 +#import <OpenGL/OpenGL.h> 1.15 +#import <OpenGL/gl.h> 1.16 +#import "ApplicationServices/ApplicationServices.h" 1.17 +#include "gfxTypes.h" 1.18 +#include "mozilla/RefPtr.h" 1.19 +#include "mozilla/gfx/MacIOSurface.h" 1.20 +#include "nsError.h" 1.21 + 1.22 +// Get the system color space. 1.23 +CGColorSpaceRef CreateSystemColorSpace(); 1.24 + 1.25 +// Manages a CARenderer 1.26 +struct _CGLPBufferObject; 1.27 +struct _CGLContextObject; 1.28 + 1.29 +enum AllowOfflineRendererEnum { ALLOW_OFFLINE_RENDERER, DISALLOW_OFFLINE_RENDERER }; 1.30 + 1.31 +class nsCARenderer : public mozilla::RefCounted<nsCARenderer> { 1.32 +public: 1.33 + MOZ_DECLARE_REFCOUNTED_TYPENAME(nsCARenderer) 1.34 + nsCARenderer() : mCARenderer(nullptr), mWrapperCALayer(nullptr), mFBOTexture(0), 1.35 + mOpenGLContext(nullptr), mCGImage(nullptr), mCGData(nullptr), 1.36 + mIOSurface(nullptr), mFBO(0), mIOTexture(0), 1.37 + mUnsupportedWidth(UINT32_MAX), mUnsupportedHeight(UINT32_MAX), 1.38 + mAllowOfflineRenderer(DISALLOW_OFFLINE_RENDERER), 1.39 + mContentsScaleFactor(1.0) {} 1.40 + ~nsCARenderer(); 1.41 + // aWidth and aHeight are in "display pixels". A "display pixel" is the 1.42 + // smallest fully addressable part of a display. But in HiDPI modes each 1.43 + // "display pixel" corresponds to more than one device pixel. Multiply 1.44 + // display pixels by aContentsScaleFactor to get device pixels. 1.45 + nsresult SetupRenderer(void* aCALayer, int aWidth, int aHeight, 1.46 + double aContentsScaleFactor, 1.47 + AllowOfflineRendererEnum aAllowOfflineRenderer); 1.48 + // aWidth and aHeight are in "display pixels". Multiply by 1.49 + // aContentsScaleFactor to get device pixels. 1.50 + nsresult Render(int aWidth, int aHeight, 1.51 + double aContentsScaleFactor, 1.52 + CGImageRef *aOutCAImage); 1.53 + bool isInit() { return mCARenderer != nullptr; } 1.54 + /* 1.55 + * Render the CALayer to an IOSurface. If no IOSurface 1.56 + * is attached then an internal pixel buffer will be 1.57 + * used. 1.58 + */ 1.59 + void AttachIOSurface(mozilla::RefPtr<MacIOSurface> aSurface); 1.60 + IOSurfaceID GetIOSurfaceID(); 1.61 + // aX, aY, aWidth and aHeight are in "display pixels". Multiply by 1.62 + // surf->GetContentsScaleFactor() to get device pixels. 1.63 + static nsresult DrawSurfaceToCGContext(CGContextRef aContext, 1.64 + MacIOSurface *surf, 1.65 + CGColorSpaceRef aColorSpace, 1.66 + int aX, int aY, 1.67 + size_t aWidth, size_t aHeight); 1.68 + 1.69 + // Remove & Add the layer without destroying 1.70 + // the renderer for fast back buffer swapping. 1.71 + void DetachCALayer(); 1.72 + void AttachCALayer(void *aCALayer); 1.73 +#ifdef DEBUG 1.74 + static void SaveToDisk(MacIOSurface *surf); 1.75 +#endif 1.76 +private: 1.77 + // aWidth and aHeight are in "display pixels". Multiply by 1.78 + // mContentsScaleFactor to get device pixels. 1.79 + void SetBounds(int aWidth, int aHeight); 1.80 + // aWidth and aHeight are in "display pixels". Multiply by 1.81 + // mContentsScaleFactor to get device pixels. 1.82 + void SetViewport(int aWidth, int aHeight); 1.83 + void Destroy(); 1.84 + 1.85 + void *mCARenderer; 1.86 + void *mWrapperCALayer; 1.87 + GLuint mFBOTexture; 1.88 + _CGLContextObject *mOpenGLContext; 1.89 + CGImageRef mCGImage; 1.90 + void *mCGData; 1.91 + mozilla::RefPtr<MacIOSurface> mIOSurface; 1.92 + uint32_t mFBO; 1.93 + uint32_t mIOTexture; 1.94 + int mUnsupportedWidth; 1.95 + int mUnsupportedHeight; 1.96 + AllowOfflineRendererEnum mAllowOfflineRenderer; 1.97 + double mContentsScaleFactor; 1.98 +}; 1.99 + 1.100 +#endif // XP_MACOSX 1.101 +#endif // nsCoreAnimationSupport_h__ 1.102 +