michael@0: /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef _GFXQUARTZNATIVEDRAWING_H_ michael@0: #define _GFXQUARTZNATIVEDRAWING_H_ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #include "gfxContext.h" michael@0: #include "gfxQuartzSurface.h" michael@0: #include "mozilla/gfx/BorrowedContext.h" michael@0: #include "nsAutoPtr.h" michael@0: michael@0: class gfxQuartzNativeDrawing { michael@0: public: michael@0: michael@0: /* Create native Quartz drawing for a rectangle bounded by michael@0: * nativeRect. michael@0: * michael@0: * Typical usage looks like: michael@0: * michael@0: * gfxQuartzNativeDrawing nativeDraw(ctx, nativeRect); michael@0: * CGContextRef cgContext = nativeDraw.BeginNativeDrawing(); michael@0: * if (!cgContext) michael@0: * return NS_ERROR_FAILURE; michael@0: * michael@0: * ... call Quartz operations on CGContextRef to draw to nativeRect ... michael@0: * michael@0: * nativeDraw.EndNativeDrawing(); michael@0: * michael@0: * aNativeRect is the size of the surface (in Quartz/Cocoa points) that michael@0: * will be created _if_ the gfxQuartzNativeDrawing decides to create a new michael@0: * surface and CGContext for its drawing operations, which it then michael@0: * composites into the target gfxContext. michael@0: * michael@0: * (Note that aNativeRect will be ignored if the gfxQuartzNativeDrawing michael@0: * uses the target gfxContext directly.) michael@0: * michael@0: * The optional aBackingScale parameter is a scaling factor that will be michael@0: * applied when creating and rendering into such a temporary surface. michael@0: */ michael@0: gfxQuartzNativeDrawing(gfxContext *ctx, michael@0: const gfxRect& aNativeRect, michael@0: gfxFloat aBackingScale = 1.0f); michael@0: michael@0: /* Returns a CGContextRef which may be used for native drawing. This michael@0: * CGContextRef is valid until EndNativeDrawing is called; if it is used michael@0: * for drawing after that time, the result is undefined. */ michael@0: CGContextRef BeginNativeDrawing(); michael@0: michael@0: /* Marks the end of native drawing */ michael@0: void EndNativeDrawing(); michael@0: michael@0: private: michael@0: // don't allow copying via construction or assignment michael@0: gfxQuartzNativeDrawing(const gfxQuartzNativeDrawing&) MOZ_DELETE; michael@0: const gfxQuartzNativeDrawing& operator=(const gfxQuartzNativeDrawing&) MOZ_DELETE; michael@0: michael@0: michael@0: // Final destination context michael@0: nsRefPtr mContext; michael@0: mozilla::RefPtr mDrawTarget; michael@0: mozilla::gfx::BorrowedCGContext mBorrowedContext; michael@0: // context that draws to mQuartzSurface; can be different from mContext michael@0: // if mContext is not drawing to Quartz michael@0: nsRefPtr mSurfaceContext; michael@0: gfxRect mNativeRect; michael@0: gfxFloat mBackingScale; michael@0: michael@0: // saved state michael@0: nsRefPtr mQuartzSurface; michael@0: CGContextRef mCGContext; michael@0: }; michael@0: michael@0: #endif