2008-02-20 11:33:27 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-02-20 11:33:27 +00:00
|
|
|
|
|
|
|
#ifndef _GFXQUARTZNATIVEDRAWING_H_
|
|
|
|
#define _GFXQUARTZNATIVEDRAWING_H_
|
|
|
|
|
2011-12-16 19:42:07 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2014-10-24 07:26:27 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-09-23 03:28:16 +00:00
|
|
|
#include "mozilla/gfx/BorrowedContext.h"
|
2015-10-18 05:24:48 +00:00
|
|
|
#include "mozilla/RefPtr.h"
|
2008-02-20 11:33:27 +00:00
|
|
|
|
2013-05-29 21:59:24 +00:00
|
|
|
class gfxQuartzNativeDrawing {
|
2014-10-24 07:26:27 +00:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
|
|
|
typedef mozilla::gfx::Rect Rect;
|
2008-02-20 11:33:27 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
/* Create native Quartz drawing for a rectangle bounded by
|
|
|
|
* nativeRect.
|
|
|
|
*
|
|
|
|
* Typical usage looks like:
|
|
|
|
*
|
|
|
|
* gfxQuartzNativeDrawing nativeDraw(ctx, nativeRect);
|
|
|
|
* CGContextRef cgContext = nativeDraw.BeginNativeDrawing();
|
|
|
|
* if (!cgContext)
|
|
|
|
* return NS_ERROR_FAILURE;
|
|
|
|
*
|
|
|
|
* ... call Quartz operations on CGContextRef to draw to nativeRect ...
|
|
|
|
*
|
|
|
|
* nativeDraw.EndNativeDrawing();
|
2012-10-29 09:22:30 +00:00
|
|
|
*
|
|
|
|
* aNativeRect is the size of the surface (in Quartz/Cocoa points) that
|
|
|
|
* will be created _if_ the gfxQuartzNativeDrawing decides to create a new
|
|
|
|
* surface and CGContext for its drawing operations, which it then
|
2014-10-24 07:26:27 +00:00
|
|
|
* composites into the target DrawTarget.
|
2012-10-29 09:22:30 +00:00
|
|
|
*
|
|
|
|
* (Note that aNativeRect will be ignored if the gfxQuartzNativeDrawing
|
2014-10-24 07:26:27 +00:00
|
|
|
* uses the target DrawTarget directly.)
|
2012-10-29 09:22:30 +00:00
|
|
|
*
|
|
|
|
* The optional aBackingScale parameter is a scaling factor that will be
|
|
|
|
* applied when creating and rendering into such a temporary surface.
|
2008-02-20 11:33:27 +00:00
|
|
|
*/
|
2014-10-24 07:26:27 +00:00
|
|
|
gfxQuartzNativeDrawing(DrawTarget& aDrawTarget,
|
|
|
|
const Rect& aNativeRect);
|
2008-02-20 11:33:27 +00:00
|
|
|
|
|
|
|
/* Returns a CGContextRef which may be used for native drawing. This
|
|
|
|
* CGContextRef is valid until EndNativeDrawing is called; if it is used
|
|
|
|
* for drawing after that time, the result is undefined. */
|
|
|
|
CGContextRef BeginNativeDrawing();
|
|
|
|
|
|
|
|
/* Marks the end of native drawing */
|
|
|
|
void EndNativeDrawing();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// don't allow copying via construction or assignment
|
2015-01-06 23:35:02 +00:00
|
|
|
gfxQuartzNativeDrawing(const gfxQuartzNativeDrawing&) = delete;
|
|
|
|
const gfxQuartzNativeDrawing& operator=(const gfxQuartzNativeDrawing&) = delete;
|
2008-02-20 11:33:27 +00:00
|
|
|
|
2010-08-23 09:30:07 +00:00
|
|
|
// Final destination context
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DrawTarget> mDrawTarget;
|
|
|
|
RefPtr<DrawTarget> mTempDrawTarget;
|
2013-07-12 21:19:29 +00:00
|
|
|
mozilla::gfx::BorrowedCGContext mBorrowedContext;
|
2014-08-29 03:08:15 +00:00
|
|
|
mozilla::gfx::Rect mNativeRect;
|
2008-02-20 11:33:27 +00:00
|
|
|
|
|
|
|
// saved state
|
|
|
|
CGContextRef mCGContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|