gfx/thebes/gfxQuartzNativeDrawing.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/thebes/gfxQuartzNativeDrawing.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,77 @@
     1.4 +/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef _GFXQUARTZNATIVEDRAWING_H_
    1.10 +#define _GFXQUARTZNATIVEDRAWING_H_
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +
    1.14 +#include "gfxContext.h"
    1.15 +#include "gfxQuartzSurface.h"
    1.16 +#include "mozilla/gfx/BorrowedContext.h"
    1.17 +#include "nsAutoPtr.h"
    1.18 +
    1.19 +class gfxQuartzNativeDrawing {
    1.20 +public:
    1.21 +
    1.22 +    /* Create native Quartz drawing for a rectangle bounded by
    1.23 +     * nativeRect.
    1.24 +     *
    1.25 +     * Typical usage looks like:
    1.26 +     *
    1.27 +     *   gfxQuartzNativeDrawing nativeDraw(ctx, nativeRect);
    1.28 +     *   CGContextRef cgContext = nativeDraw.BeginNativeDrawing();
    1.29 +     *   if (!cgContext)
    1.30 +     *     return NS_ERROR_FAILURE;
    1.31 +     *
    1.32 +     *     ... call Quartz operations on CGContextRef to draw to nativeRect ...
    1.33 +     *
    1.34 +     *   nativeDraw.EndNativeDrawing();
    1.35 +     *
    1.36 +     * aNativeRect is the size of the surface (in Quartz/Cocoa points) that
    1.37 +     * will be created _if_ the gfxQuartzNativeDrawing decides to create a new
    1.38 +     * surface and CGContext for its drawing operations, which it then
    1.39 +     * composites into the target gfxContext.
    1.40 +     *
    1.41 +     * (Note that aNativeRect will be ignored if the gfxQuartzNativeDrawing
    1.42 +     * uses the target gfxContext directly.)
    1.43 +     *
    1.44 +     * The optional aBackingScale parameter is a scaling factor that will be
    1.45 +     * applied when creating and rendering into such a temporary surface.
    1.46 +     */
    1.47 +    gfxQuartzNativeDrawing(gfxContext *ctx,
    1.48 +                           const gfxRect& aNativeRect,
    1.49 +                           gfxFloat aBackingScale = 1.0f);
    1.50 +
    1.51 +    /* Returns a CGContextRef which may be used for native drawing.  This
    1.52 +     * CGContextRef is valid until EndNativeDrawing is called; if it is used
    1.53 +     * for drawing after that time, the result is undefined. */
    1.54 +    CGContextRef BeginNativeDrawing();
    1.55 +
    1.56 +    /* Marks the end of native drawing */
    1.57 +    void EndNativeDrawing();
    1.58 +
    1.59 +private:
    1.60 +    // don't allow copying via construction or assignment
    1.61 +    gfxQuartzNativeDrawing(const gfxQuartzNativeDrawing&) MOZ_DELETE;
    1.62 +    const gfxQuartzNativeDrawing& operator=(const gfxQuartzNativeDrawing&) MOZ_DELETE;
    1.63 +
    1.64 +
    1.65 +    // Final destination context
    1.66 +    nsRefPtr<gfxContext> mContext;
    1.67 +    mozilla::RefPtr<mozilla::gfx::DrawTarget> mDrawTarget;
    1.68 +    mozilla::gfx::BorrowedCGContext mBorrowedContext;
    1.69 +    // context that draws to mQuartzSurface; can be different from mContext
    1.70 +    // if mContext is not drawing to Quartz
    1.71 +    nsRefPtr<gfxContext> mSurfaceContext;
    1.72 +    gfxRect mNativeRect;
    1.73 +    gfxFloat mBackingScale;
    1.74 +
    1.75 +    // saved state
    1.76 +    nsRefPtr<gfxQuartzSurface> mQuartzSurface;
    1.77 +    CGContextRef mCGContext;
    1.78 +};
    1.79 +
    1.80 +#endif

mercurial