2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +04: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 14:33:27 +03:00
|
|
|
|
|
|
|
#ifndef _GFXQUARTZNATIVEDRAWING_H_
|
|
|
|
#define _GFXQUARTZNATIVEDRAWING_H_
|
|
|
|
|
2011-12-16 23:42:07 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2014-10-24 11:26:27 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2013-09-23 07:28:16 +04:00
|
|
|
#include "mozilla/gfx/BorrowedContext.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2008-02-20 14:33:27 +03:00
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxQuartzNativeDrawing {
|
2014-10-24 11:26:27 +04:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
|
|
|
typedef mozilla::gfx::Rect Rect;
|
2008-02-20 14:33:27 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2008-02-20 14:33:27 +03:00
|
|
|
/* 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 13:22:30 +04: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 11:26:27 +04:00
|
|
|
* composites into the target DrawTarget.
|
2012-10-29 13:22:30 +04:00
|
|
|
*
|
|
|
|
* (Note that aNativeRect will be ignored if the gfxQuartzNativeDrawing
|
2014-10-24 11:26:27 +04:00
|
|
|
* uses the target DrawTarget directly.)
|
2012-10-29 13:22:30 +04: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 14:33:27 +03:00
|
|
|
*/
|
2014-10-24 11:26:27 +04:00
|
|
|
gfxQuartzNativeDrawing(DrawTarget& aDrawTarget, const Rect& aNativeRect);
|
2008-02-20 14:33:27 +03: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-07 02:35:02 +03:00
|
|
|
gfxQuartzNativeDrawing(const gfxQuartzNativeDrawing&) = delete;
|
|
|
|
const gfxQuartzNativeDrawing& operator=(const gfxQuartzNativeDrawing&) =
|
|
|
|
delete;
|
2008-02-20 14:33:27 +03:00
|
|
|
|
2010-08-23 13:30:07 +04:00
|
|
|
// Final destination context
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<DrawTarget> mDrawTarget;
|
|
|
|
RefPtr<DrawTarget> mTempDrawTarget;
|
2013-07-13 01:19:29 +04:00
|
|
|
mozilla::gfx::BorrowedCGContext mBorrowedContext;
|
2014-08-29 07:08:15 +04:00
|
|
|
mozilla::gfx::Rect mNativeRect;
|
2008-02-20 14:33:27 +03:00
|
|
|
|
|
|
|
// saved state
|
|
|
|
CGContextRef mCGContext;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|