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 NSRENDERINGCONTEXT__H__ |
michael@0 | 7 | #define NSRENDERINGCONTEXT__H__ |
michael@0 | 8 | |
michael@0 | 9 | #include <stdint.h> // for uint32_t |
michael@0 | 10 | #include <sys/types.h> // for int32_t |
michael@0 | 11 | #include "gfxContext.h" // for gfxContext |
michael@0 | 12 | #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2 |
michael@0 | 13 | #include "mozilla/gfx/2D.h" |
michael@0 | 14 | #include "mozilla/gfx/UserData.h" // for UserData, UserDataKey |
michael@0 | 15 | #include "nsAutoPtr.h" // for nsRefPtr |
michael@0 | 16 | #include "nsBoundingMetrics.h" // for nsBoundingMetrics |
michael@0 | 17 | #include "nsColor.h" // for nscolor |
michael@0 | 18 | #include "nsCoord.h" // for nscoord, NSToIntRound |
michael@0 | 19 | #include "nsDeviceContext.h" // for nsDeviceContext |
michael@0 | 20 | #include "nsFontMetrics.h" // for nsFontMetrics |
michael@0 | 21 | #include "nsISupports.h" // for NS_INLINE_DECL_REFCOUNTING, etc |
michael@0 | 22 | #include "nsString.h" // for nsString |
michael@0 | 23 | #include "nscore.h" // for char16_t |
michael@0 | 24 | |
michael@0 | 25 | class gfxASurface; |
michael@0 | 26 | class nsIntRegion; |
michael@0 | 27 | struct nsPoint; |
michael@0 | 28 | struct nsRect; |
michael@0 | 29 | |
michael@0 | 30 | typedef enum { |
michael@0 | 31 | nsLineStyle_kNone = 0, |
michael@0 | 32 | nsLineStyle_kSolid = 1, |
michael@0 | 33 | nsLineStyle_kDashed = 2, |
michael@0 | 34 | nsLineStyle_kDotted = 3 |
michael@0 | 35 | } nsLineStyle; |
michael@0 | 36 | |
michael@0 | 37 | class nsRenderingContext MOZ_FINAL |
michael@0 | 38 | { |
michael@0 | 39 | typedef mozilla::gfx::UserData UserData; |
michael@0 | 40 | typedef mozilla::gfx::UserDataKey UserDataKey; |
michael@0 | 41 | typedef mozilla::gfx::DrawTarget DrawTarget; |
michael@0 | 42 | |
michael@0 | 43 | public: |
michael@0 | 44 | nsRenderingContext() : mP2A(0.) {} |
michael@0 | 45 | |
michael@0 | 46 | NS_INLINE_DECL_REFCOUNTING(nsRenderingContext) |
michael@0 | 47 | |
michael@0 | 48 | void Init(nsDeviceContext* aContext, gfxASurface* aThebesSurface); |
michael@0 | 49 | void Init(nsDeviceContext* aContext, gfxContext* aThebesContext); |
michael@0 | 50 | void Init(nsDeviceContext* aContext, DrawTarget* aDrawTarget); |
michael@0 | 51 | |
michael@0 | 52 | // These accessors will never return null. |
michael@0 | 53 | gfxContext *ThebesContext() { return mThebes; } |
michael@0 | 54 | DrawTarget *GetDrawTarget() { return mThebes->GetDrawTarget(); } |
michael@0 | 55 | nsDeviceContext *DeviceContext() { return mDeviceContext; } |
michael@0 | 56 | int32_t AppUnitsPerDevPixel() { return NSToIntRound(mP2A); } |
michael@0 | 57 | |
michael@0 | 58 | // Graphics state |
michael@0 | 59 | |
michael@0 | 60 | void PushState(void); |
michael@0 | 61 | void PopState(void); |
michael@0 | 62 | void IntersectClip(const nsRect& aRect); |
michael@0 | 63 | void SetClip(const nsIntRegion& aRegion); |
michael@0 | 64 | void SetLineStyle(nsLineStyle aLineStyle); |
michael@0 | 65 | void SetColor(nscolor aColor); |
michael@0 | 66 | void Translate(const nsPoint& aPt); |
michael@0 | 67 | void Scale(float aSx, float aSy); |
michael@0 | 68 | |
michael@0 | 69 | class AutoPushTranslation { |
michael@0 | 70 | nsRenderingContext* mCtx; |
michael@0 | 71 | public: |
michael@0 | 72 | AutoPushTranslation(nsRenderingContext* aCtx, const nsPoint& aPt) |
michael@0 | 73 | : mCtx(aCtx) { |
michael@0 | 74 | mCtx->PushState(); |
michael@0 | 75 | mCtx->Translate(aPt); |
michael@0 | 76 | } |
michael@0 | 77 | ~AutoPushTranslation() { |
michael@0 | 78 | mCtx->PopState(); |
michael@0 | 79 | } |
michael@0 | 80 | }; |
michael@0 | 81 | |
michael@0 | 82 | // Shapes |
michael@0 | 83 | |
michael@0 | 84 | void DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt); |
michael@0 | 85 | void DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1); |
michael@0 | 86 | void DrawRect(const nsRect& aRect); |
michael@0 | 87 | void DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); |
michael@0 | 88 | void DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); |
michael@0 | 89 | |
michael@0 | 90 | void FillRect(const nsRect& aRect); |
michael@0 | 91 | void FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); |
michael@0 | 92 | void FillPolygon(const nsPoint aPoints[], int32_t aNumPoints); |
michael@0 | 93 | |
michael@0 | 94 | void FillEllipse(const nsRect& aRect); |
michael@0 | 95 | void FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight); |
michael@0 | 96 | |
michael@0 | 97 | void InvertRect(const nsRect& aRect); |
michael@0 | 98 | |
michael@0 | 99 | // Text |
michael@0 | 100 | |
michael@0 | 101 | void SetFont(nsFontMetrics *aFontMetrics); |
michael@0 | 102 | nsFontMetrics *FontMetrics() { return mFontMetrics; } // may be null |
michael@0 | 103 | |
michael@0 | 104 | void SetTextRunRTL(bool aIsRTL); |
michael@0 | 105 | |
michael@0 | 106 | nscoord GetWidth(char aC); |
michael@0 | 107 | nscoord GetWidth(char16_t aC); |
michael@0 | 108 | nscoord GetWidth(const nsString& aString); |
michael@0 | 109 | nscoord GetWidth(const char* aString); |
michael@0 | 110 | nscoord GetWidth(const char* aString, uint32_t aLength); |
michael@0 | 111 | nscoord GetWidth(const char16_t *aString, uint32_t aLength); |
michael@0 | 112 | |
michael@0 | 113 | nsBoundingMetrics GetBoundingMetrics(const char16_t *aString, |
michael@0 | 114 | uint32_t aLength); |
michael@0 | 115 | |
michael@0 | 116 | void DrawString(const nsString& aString, nscoord aX, nscoord aY); |
michael@0 | 117 | void DrawString(const char *aString, uint32_t aLength, |
michael@0 | 118 | nscoord aX, nscoord aY); |
michael@0 | 119 | void DrawString(const char16_t *aString, uint32_t aLength, |
michael@0 | 120 | nscoord aX, nscoord aY); |
michael@0 | 121 | |
michael@0 | 122 | void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) { |
michael@0 | 123 | mUserData.Add(key, userData, destroy); |
michael@0 | 124 | } |
michael@0 | 125 | void *GetUserData(UserDataKey *key) { |
michael@0 | 126 | return mUserData.Get(key); |
michael@0 | 127 | } |
michael@0 | 128 | void *RemoveUserData(UserDataKey *key) { |
michael@0 | 129 | return mUserData.Remove(key); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | private: |
michael@0 | 133 | // Private destructor, to discourage deletion outside of Release(): |
michael@0 | 134 | ~nsRenderingContext() |
michael@0 | 135 | { |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | int32_t GetMaxChunkLength(); |
michael@0 | 139 | |
michael@0 | 140 | nsRefPtr<gfxContext> mThebes; |
michael@0 | 141 | nsRefPtr<nsDeviceContext> mDeviceContext; |
michael@0 | 142 | nsRefPtr<nsFontMetrics> mFontMetrics; |
michael@0 | 143 | |
michael@0 | 144 | double mP2A; // cached app units per device pixel value |
michael@0 | 145 | |
michael@0 | 146 | UserData mUserData; |
michael@0 | 147 | }; |
michael@0 | 148 | |
michael@0 | 149 | #endif // NSRENDERINGCONTEXT__H__ |