gfx/thebes/gfxQuartzNativeDrawing.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 #ifndef _GFXQUARTZNATIVEDRAWING_H_
     7 #define _GFXQUARTZNATIVEDRAWING_H_
     9 #include "mozilla/Attributes.h"
    11 #include "gfxContext.h"
    12 #include "gfxQuartzSurface.h"
    13 #include "mozilla/gfx/BorrowedContext.h"
    14 #include "nsAutoPtr.h"
    16 class gfxQuartzNativeDrawing {
    17 public:
    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);
    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();
    53     /* Marks the end of native drawing */
    54     void EndNativeDrawing();
    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;
    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;
    72     // saved state
    73     nsRefPtr<gfxQuartzSurface> mQuartzSurface;
    74     CGContextRef mCGContext;
    75 };
    77 #endif

mercurial