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