gfx/2d/SourceSurfaceD2D1.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     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/. */
     6 #ifndef MOZILLA_GFX_SOURCESURFACED2D1_H_
     7 #define MOZILLA_GFX_SOURCESURFACED2D1_H_
     9 #include "2D.h"
    10 #include "HelpersD2D.h"
    11 #include <vector>
    12 #include <d3d11.h>
    13 #include <d2d1_1.h>
    15 namespace mozilla {
    16 namespace gfx {
    18 class DrawTargetD2D1;
    20 class SourceSurfaceD2D1 : public SourceSurface
    21 {
    22 public:
    23   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceD2D1)
    24   SourceSurfaceD2D1(ID2D1Image* aImage, ID2D1DeviceContext *aDC,
    25                     SurfaceFormat aFormat, const IntSize &aSize,
    26                     DrawTargetD2D1 *aDT = nullptr);
    27   ~SourceSurfaceD2D1();
    29   virtual SurfaceType GetType() const { return SurfaceType::D2D1_1_IMAGE; }
    30   virtual IntSize GetSize() const { return mSize; }
    31   virtual SurfaceFormat GetFormat() const { return mFormat; }
    32   virtual TemporaryRef<DataSourceSurface> GetDataSurface();
    34   ID2D1Image *GetImage() { return mImage; }
    36   void EnsureIndependent() { if (!mDrawTarget) return; DrawTargetWillChange(); }
    38 private:
    39   friend class DrawTargetD2D1;
    41   void EnsureRealizedBitmap();
    43   // This function is called by the draw target this texture belongs to when
    44   // it is about to be changed. The texture will be required to make a copy
    45   // of itself when this happens.
    46   void DrawTargetWillChange();
    48   // This will mark the surface as no longer depending on its drawtarget,
    49   // this may happen on destruction or copying.
    50   void MarkIndependent();
    52   RefPtr<ID2D1Image> mImage;
    53   // This may be null if we were created for a non-bitmap image and have not
    54   // had a reason yet to realize ourselves.
    55   RefPtr<ID2D1Bitmap1> mRealizedBitmap;
    56   RefPtr<ID2D1DeviceContext> mDC;
    58   SurfaceFormat mFormat;
    59   IntSize mSize;
    60   RefPtr<DrawTargetD2D1> mDrawTarget;
    61 };
    63 class DataSourceSurfaceD2D1 : public DataSourceSurface
    64 {
    65 public:
    66   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceD2D1)
    67   DataSourceSurfaceD2D1(ID2D1Bitmap1 *aMappableBitmap, SurfaceFormat aFormat);
    68   ~DataSourceSurfaceD2D1();
    70   virtual SurfaceType GetType() const { return SurfaceType::DATA; }
    71   virtual IntSize GetSize() const;
    72   virtual SurfaceFormat GetFormat() const { return mFormat; }
    73   virtual uint8_t *GetData();
    74   virtual int32_t Stride();
    75   virtual bool Map(MapType, MappedSurface *aMappedSurface);
    76   virtual void Unmap();
    78 private:
    79   friend class SourceSurfaceD2DTarget;
    80   void EnsureMapped();
    82   mutable RefPtr<ID2D1Bitmap1> mBitmap;
    83   SurfaceFormat mFormat;
    84   D2D1_MAPPED_RECT mMap;
    85   bool mMapped;
    86 };
    88 }
    89 }
    91 #endif /* MOZILLA_GFX_SOURCESURFACED2D2TARGET_H_ */

mercurial