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: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #ifndef _GFXQUARTZNATIVEDRAWING_H_ |
michael@0 | 7 | #define _GFXQUARTZNATIVEDRAWING_H_ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | |
michael@0 | 11 | #include "gfxContext.h" |
michael@0 | 12 | #include "gfxQuartzSurface.h" |
michael@0 | 13 | #include "mozilla/gfx/BorrowedContext.h" |
michael@0 | 14 | #include "nsAutoPtr.h" |
michael@0 | 15 | |
michael@0 | 16 | class gfxQuartzNativeDrawing { |
michael@0 | 17 | public: |
michael@0 | 18 | |
michael@0 | 19 | /* Create native Quartz drawing for a rectangle bounded by |
michael@0 | 20 | * nativeRect. |
michael@0 | 21 | * |
michael@0 | 22 | * Typical usage looks like: |
michael@0 | 23 | * |
michael@0 | 24 | * gfxQuartzNativeDrawing nativeDraw(ctx, nativeRect); |
michael@0 | 25 | * CGContextRef cgContext = nativeDraw.BeginNativeDrawing(); |
michael@0 | 26 | * if (!cgContext) |
michael@0 | 27 | * return NS_ERROR_FAILURE; |
michael@0 | 28 | * |
michael@0 | 29 | * ... call Quartz operations on CGContextRef to draw to nativeRect ... |
michael@0 | 30 | * |
michael@0 | 31 | * nativeDraw.EndNativeDrawing(); |
michael@0 | 32 | * |
michael@0 | 33 | * aNativeRect is the size of the surface (in Quartz/Cocoa points) that |
michael@0 | 34 | * will be created _if_ the gfxQuartzNativeDrawing decides to create a new |
michael@0 | 35 | * surface and CGContext for its drawing operations, which it then |
michael@0 | 36 | * composites into the target gfxContext. |
michael@0 | 37 | * |
michael@0 | 38 | * (Note that aNativeRect will be ignored if the gfxQuartzNativeDrawing |
michael@0 | 39 | * uses the target gfxContext directly.) |
michael@0 | 40 | * |
michael@0 | 41 | * The optional aBackingScale parameter is a scaling factor that will be |
michael@0 | 42 | * applied when creating and rendering into such a temporary surface. |
michael@0 | 43 | */ |
michael@0 | 44 | gfxQuartzNativeDrawing(gfxContext *ctx, |
michael@0 | 45 | const gfxRect& aNativeRect, |
michael@0 | 46 | gfxFloat aBackingScale = 1.0f); |
michael@0 | 47 | |
michael@0 | 48 | /* Returns a CGContextRef which may be used for native drawing. This |
michael@0 | 49 | * CGContextRef is valid until EndNativeDrawing is called; if it is used |
michael@0 | 50 | * for drawing after that time, the result is undefined. */ |
michael@0 | 51 | CGContextRef BeginNativeDrawing(); |
michael@0 | 52 | |
michael@0 | 53 | /* Marks the end of native drawing */ |
michael@0 | 54 | void EndNativeDrawing(); |
michael@0 | 55 | |
michael@0 | 56 | private: |
michael@0 | 57 | // don't allow copying via construction or assignment |
michael@0 | 58 | gfxQuartzNativeDrawing(const gfxQuartzNativeDrawing&) MOZ_DELETE; |
michael@0 | 59 | const gfxQuartzNativeDrawing& operator=(const gfxQuartzNativeDrawing&) MOZ_DELETE; |
michael@0 | 60 | |
michael@0 | 61 | |
michael@0 | 62 | // Final destination context |
michael@0 | 63 | nsRefPtr<gfxContext> mContext; |
michael@0 | 64 | mozilla::RefPtr<mozilla::gfx::DrawTarget> mDrawTarget; |
michael@0 | 65 | mozilla::gfx::BorrowedCGContext mBorrowedContext; |
michael@0 | 66 | // context that draws to mQuartzSurface; can be different from mContext |
michael@0 | 67 | // if mContext is not drawing to Quartz |
michael@0 | 68 | nsRefPtr<gfxContext> mSurfaceContext; |
michael@0 | 69 | gfxRect mNativeRect; |
michael@0 | 70 | gfxFloat mBackingScale; |
michael@0 | 71 | |
michael@0 | 72 | // saved state |
michael@0 | 73 | nsRefPtr<gfxQuartzSurface> mQuartzSurface; |
michael@0 | 74 | CGContextRef mCGContext; |
michael@0 | 75 | }; |
michael@0 | 76 | |
michael@0 | 77 | #endif |