Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | // vim:set ts=2 sts=2 sw=2 et cin: |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsCoreAnimationSupport_h__ |
michael@0 | 8 | #define nsCoreAnimationSupport_h__ |
michael@0 | 9 | #ifdef XP_MACOSX |
michael@0 | 10 | |
michael@0 | 11 | #import <OpenGL/OpenGL.h> |
michael@0 | 12 | #import <OpenGL/gl.h> |
michael@0 | 13 | #import "ApplicationServices/ApplicationServices.h" |
michael@0 | 14 | #include "gfxTypes.h" |
michael@0 | 15 | #include "mozilla/RefPtr.h" |
michael@0 | 16 | #include "mozilla/gfx/MacIOSurface.h" |
michael@0 | 17 | #include "nsError.h" |
michael@0 | 18 | |
michael@0 | 19 | // Get the system color space. |
michael@0 | 20 | CGColorSpaceRef CreateSystemColorSpace(); |
michael@0 | 21 | |
michael@0 | 22 | // Manages a CARenderer |
michael@0 | 23 | struct _CGLPBufferObject; |
michael@0 | 24 | struct _CGLContextObject; |
michael@0 | 25 | |
michael@0 | 26 | enum AllowOfflineRendererEnum { ALLOW_OFFLINE_RENDERER, DISALLOW_OFFLINE_RENDERER }; |
michael@0 | 27 | |
michael@0 | 28 | class nsCARenderer : public mozilla::RefCounted<nsCARenderer> { |
michael@0 | 29 | public: |
michael@0 | 30 | MOZ_DECLARE_REFCOUNTED_TYPENAME(nsCARenderer) |
michael@0 | 31 | nsCARenderer() : mCARenderer(nullptr), mWrapperCALayer(nullptr), mFBOTexture(0), |
michael@0 | 32 | mOpenGLContext(nullptr), mCGImage(nullptr), mCGData(nullptr), |
michael@0 | 33 | mIOSurface(nullptr), mFBO(0), mIOTexture(0), |
michael@0 | 34 | mUnsupportedWidth(UINT32_MAX), mUnsupportedHeight(UINT32_MAX), |
michael@0 | 35 | mAllowOfflineRenderer(DISALLOW_OFFLINE_RENDERER), |
michael@0 | 36 | mContentsScaleFactor(1.0) {} |
michael@0 | 37 | ~nsCARenderer(); |
michael@0 | 38 | // aWidth and aHeight are in "display pixels". A "display pixel" is the |
michael@0 | 39 | // smallest fully addressable part of a display. But in HiDPI modes each |
michael@0 | 40 | // "display pixel" corresponds to more than one device pixel. Multiply |
michael@0 | 41 | // display pixels by aContentsScaleFactor to get device pixels. |
michael@0 | 42 | nsresult SetupRenderer(void* aCALayer, int aWidth, int aHeight, |
michael@0 | 43 | double aContentsScaleFactor, |
michael@0 | 44 | AllowOfflineRendererEnum aAllowOfflineRenderer); |
michael@0 | 45 | // aWidth and aHeight are in "display pixels". Multiply by |
michael@0 | 46 | // aContentsScaleFactor to get device pixels. |
michael@0 | 47 | nsresult Render(int aWidth, int aHeight, |
michael@0 | 48 | double aContentsScaleFactor, |
michael@0 | 49 | CGImageRef *aOutCAImage); |
michael@0 | 50 | bool isInit() { return mCARenderer != nullptr; } |
michael@0 | 51 | /* |
michael@0 | 52 | * Render the CALayer to an IOSurface. If no IOSurface |
michael@0 | 53 | * is attached then an internal pixel buffer will be |
michael@0 | 54 | * used. |
michael@0 | 55 | */ |
michael@0 | 56 | void AttachIOSurface(mozilla::RefPtr<MacIOSurface> aSurface); |
michael@0 | 57 | IOSurfaceID GetIOSurfaceID(); |
michael@0 | 58 | // aX, aY, aWidth and aHeight are in "display pixels". Multiply by |
michael@0 | 59 | // surf->GetContentsScaleFactor() to get device pixels. |
michael@0 | 60 | static nsresult DrawSurfaceToCGContext(CGContextRef aContext, |
michael@0 | 61 | MacIOSurface *surf, |
michael@0 | 62 | CGColorSpaceRef aColorSpace, |
michael@0 | 63 | int aX, int aY, |
michael@0 | 64 | size_t aWidth, size_t aHeight); |
michael@0 | 65 | |
michael@0 | 66 | // Remove & Add the layer without destroying |
michael@0 | 67 | // the renderer for fast back buffer swapping. |
michael@0 | 68 | void DetachCALayer(); |
michael@0 | 69 | void AttachCALayer(void *aCALayer); |
michael@0 | 70 | #ifdef DEBUG |
michael@0 | 71 | static void SaveToDisk(MacIOSurface *surf); |
michael@0 | 72 | #endif |
michael@0 | 73 | private: |
michael@0 | 74 | // aWidth and aHeight are in "display pixels". Multiply by |
michael@0 | 75 | // mContentsScaleFactor to get device pixels. |
michael@0 | 76 | void SetBounds(int aWidth, int aHeight); |
michael@0 | 77 | // aWidth and aHeight are in "display pixels". Multiply by |
michael@0 | 78 | // mContentsScaleFactor to get device pixels. |
michael@0 | 79 | void SetViewport(int aWidth, int aHeight); |
michael@0 | 80 | void Destroy(); |
michael@0 | 81 | |
michael@0 | 82 | void *mCARenderer; |
michael@0 | 83 | void *mWrapperCALayer; |
michael@0 | 84 | GLuint mFBOTexture; |
michael@0 | 85 | _CGLContextObject *mOpenGLContext; |
michael@0 | 86 | CGImageRef mCGImage; |
michael@0 | 87 | void *mCGData; |
michael@0 | 88 | mozilla::RefPtr<MacIOSurface> mIOSurface; |
michael@0 | 89 | uint32_t mFBO; |
michael@0 | 90 | uint32_t mIOTexture; |
michael@0 | 91 | int mUnsupportedWidth; |
michael@0 | 92 | int mUnsupportedHeight; |
michael@0 | 93 | AllowOfflineRendererEnum mAllowOfflineRenderer; |
michael@0 | 94 | double mContentsScaleFactor; |
michael@0 | 95 | }; |
michael@0 | 96 | |
michael@0 | 97 | #endif // XP_MACOSX |
michael@0 | 98 | #endif // nsCoreAnimationSupport_h__ |
michael@0 | 99 |