Bumping manifests a=b2g-bump
[gecko.git] / gfx / src / nsRenderingContext.h
blob5b14abb80a92b39c500abb492bb626339af20318
1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef NSRENDERINGCONTEXT__H__
7 #define NSRENDERINGCONTEXT__H__
9 #include <stdint.h> // for uint32_t
10 #include <sys/types.h> // for int32_t
11 #include "gfxContext.h" // for gfxContext
12 #include "mozilla/Assertions.h" // for MOZ_ASSERT_HELPER2
13 #include "mozilla/gfx/2D.h"
14 #include "mozilla/gfx/UserData.h" // for UserData, UserDataKey
15 #include "nsAutoPtr.h" // for nsRefPtr
16 #include "nsBoundingMetrics.h" // for nsBoundingMetrics
17 #include "nsColor.h" // for nscolor
18 #include "nsCoord.h" // for nscoord, NSToIntRound
19 #include "nsDeviceContext.h" // for nsDeviceContext
20 #include "nsFontMetrics.h" // for nsFontMetrics
21 #include "nsISupports.h" // for NS_INLINE_DECL_REFCOUNTING, etc
22 #include "nsString.h" // for nsString
23 #include "nscore.h" // for char16_t
25 class nsIntRegion;
26 struct nsPoint;
27 struct nsRect;
29 typedef enum {
30 nsLineStyle_kNone = 0,
31 nsLineStyle_kSolid = 1,
32 nsLineStyle_kDashed = 2,
33 nsLineStyle_kDotted = 3
34 } nsLineStyle;
36 class nsRenderingContext MOZ_FINAL
38 typedef mozilla::gfx::UserData UserData;
39 typedef mozilla::gfx::UserDataKey UserDataKey;
40 typedef mozilla::gfx::DrawTarget DrawTarget;
42 public:
43 nsRenderingContext() : mP2A(0.) {}
45 NS_INLINE_DECL_REFCOUNTING(nsRenderingContext)
47 void Init(nsDeviceContext* aContext, gfxContext* aThebesContext);
48 void Init(nsDeviceContext* aContext, DrawTarget* aDrawTarget);
50 // These accessors will never return null.
51 gfxContext *ThebesContext() { return mThebes; }
52 DrawTarget *GetDrawTarget() { return mThebes->GetDrawTarget(); }
53 nsDeviceContext *DeviceContext() { return mDeviceContext; }
55 // Graphics state
57 void PushState(void);
58 void PopState(void);
59 void IntersectClip(const nsRect& aRect);
60 void SetClip(const nsIntRegion& aRegion);
61 void SetLineStyle(nsLineStyle aLineStyle);
62 void SetColor(nscolor aColor);
63 void Translate(const nsPoint& aPt);
64 void Scale(float aSx, float aSy);
66 class AutoPushTranslation {
67 nsRenderingContext* mCtx;
68 public:
69 AutoPushTranslation(nsRenderingContext* aCtx, const nsPoint& aPt)
70 : mCtx(aCtx) {
71 mCtx->PushState();
72 mCtx->Translate(aPt);
74 ~AutoPushTranslation() {
75 mCtx->PopState();
79 // Shapes
81 void DrawLine(const nsPoint& aStartPt, const nsPoint& aEndPt);
82 void DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
83 void DrawRect(const nsRect& aRect);
84 void DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
85 void DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
87 void FillRect(const nsRect& aRect);
88 void FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
89 void FillPolygon(const nsPoint aPoints[], int32_t aNumPoints);
91 void FillEllipse(const nsRect& aRect);
92 void FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
94 void InvertRect(const nsRect& aRect);
96 // Text
98 void SetFont(nsFontMetrics *aFontMetrics);
99 nsFontMetrics *FontMetrics() { return mFontMetrics; } // may be null
101 void SetTextRunRTL(bool aIsRTL);
103 nscoord GetWidth(char aC);
104 nscoord GetWidth(char16_t aC);
105 nscoord GetWidth(const nsString& aString);
106 nscoord GetWidth(const char* aString);
107 nscoord GetWidth(const char* aString, uint32_t aLength);
108 nscoord GetWidth(const char16_t *aString, uint32_t aLength);
110 nsBoundingMetrics GetBoundingMetrics(const char16_t *aString,
111 uint32_t aLength);
113 void DrawString(const nsString& aString, nscoord aX, nscoord aY);
114 void DrawString(const char *aString, uint32_t aLength,
115 nscoord aX, nscoord aY);
116 void DrawString(const char16_t *aString, uint32_t aLength,
117 nscoord aX, nscoord aY);
119 void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) {
120 mUserData.Add(key, userData, destroy);
122 void *GetUserData(UserDataKey *key) {
123 return mUserData.Get(key);
125 void *RemoveUserData(UserDataKey *key) {
126 return mUserData.Remove(key);
129 private:
130 // Private destructor, to discourage deletion outside of Release():
131 ~nsRenderingContext()
135 int32_t GetMaxChunkLength();
137 nsRefPtr<gfxContext> mThebes;
138 nsRefPtr<nsDeviceContext> mDeviceContext;
139 nsRefPtr<nsFontMetrics> mFontMetrics;
141 double mP2A; // cached app units per device pixel value
143 UserData mUserData;
146 #endif // NSRENDERINGCONTEXT__H__