tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

gfxQuartzNativeDrawing.h (2410B)


      1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
      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/. */
      5 
      6 #ifndef _GFXQUARTZNATIVEDRAWING_H_
      7 #define _GFXQUARTZNATIVEDRAWING_H_
      8 
      9 #include "mozilla/gfx/2D.h"
     10 #include "mozilla/gfx/BorrowedContext.h"
     11 #include "mozilla/RefPtr.h"
     12 
     13 class gfxQuartzNativeDrawing {
     14  typedef mozilla::gfx::DrawTarget DrawTarget;
     15  typedef mozilla::gfx::Rect Rect;
     16 
     17 public:
     18  /* Create native Quartz drawing for a rectangle bounded by
     19   * nativeRect.
     20   *
     21   * Typical usage looks like:
     22   *
     23   *   gfxQuartzNativeDrawing nativeDraw(ctx, nativeRect);
     24   *   CGContextRef cgContext = nativeDraw.BeginNativeDrawing();
     25   *   if (!cgContext)
     26   *     return NS_ERROR_FAILURE;
     27   *
     28   *     ... call Quartz operations on CGContextRef to draw to nativeRect ...
     29   *
     30   *   nativeDraw.EndNativeDrawing();
     31   *
     32   * aNativeRect is the size of the surface (in Quartz/Cocoa points) that
     33   * will be created _if_ the gfxQuartzNativeDrawing decides to create a new
     34   * surface and CGContext for its drawing operations, which it then
     35   * composites into the target DrawTarget.
     36   *
     37   * (Note that aNativeRect will be ignored if the gfxQuartzNativeDrawing
     38   * uses the target DrawTarget directly.)
     39   *
     40   * The optional aBackingScale parameter is a scaling factor that will be
     41   * applied when creating and rendering into such a temporary surface.
     42   */
     43  gfxQuartzNativeDrawing(DrawTarget& aDrawTarget, const Rect& aNativeRect);
     44 
     45  /* Returns a CGContextRef which may be used for native drawing.  This
     46   * CGContextRef is valid until EndNativeDrawing is called; if it is used
     47   * for drawing after that time, the result is undefined. */
     48  CGContextRef BeginNativeDrawing();
     49 
     50  /* Marks the end of native drawing */
     51  void EndNativeDrawing();
     52 
     53 private:
     54  // don't allow copying via construction or assignment
     55  gfxQuartzNativeDrawing(const gfxQuartzNativeDrawing&) = delete;
     56  const gfxQuartzNativeDrawing& operator=(const gfxQuartzNativeDrawing&) =
     57      delete;
     58 
     59  // Final destination context
     60  RefPtr<DrawTarget> mDrawTarget;
     61  RefPtr<DrawTarget> mTempDrawTarget;
     62  mozilla::gfx::BorrowedCGContext mBorrowedContext;
     63  mozilla::gfx::Rect mNativeRect;
     64 
     65  // saved state
     66  CGContextRef mCGContext;
     67 };
     68 
     69 #endif