gfx/2d/DrawTargetD2D1.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef MOZILLA_GFX_DRAWTARGETD2D1_H_
michael@0 7 #define MOZILLA_GFX_DRAWTARGETD2D1_H_
michael@0 8
michael@0 9 #include "2D.h"
michael@0 10 #include <d3d11.h>
michael@0 11 #include <d2d1_1.h>
michael@0 12 #include "PathD2D.h"
michael@0 13 #include "HelpersD2D.h"
michael@0 14
michael@0 15 #include <vector>
michael@0 16 #include <sstream>
michael@0 17
michael@0 18 #ifdef _MSC_VER
michael@0 19 #include <hash_set>
michael@0 20 #else
michael@0 21 #include <unordered_set>
michael@0 22 #endif
michael@0 23
michael@0 24 struct IDWriteFactory;
michael@0 25
michael@0 26 namespace mozilla {
michael@0 27 namespace gfx {
michael@0 28
michael@0 29 class SourceSurfaceD2D1;
michael@0 30 class GradientStopsD2D;
michael@0 31 class ScaledFontDWrite;
michael@0 32
michael@0 33 const int32_t kLayerCacheSize1 = 5;
michael@0 34
michael@0 35 class DrawTargetD2D1 : public DrawTarget
michael@0 36 {
michael@0 37 public:
michael@0 38 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetD2D1)
michael@0 39 DrawTargetD2D1();
michael@0 40 virtual ~DrawTargetD2D1();
michael@0 41
michael@0 42 virtual BackendType GetType() const { return BackendType::DIRECT2D1_1; }
michael@0 43 virtual TemporaryRef<SourceSurface> Snapshot();
michael@0 44 virtual IntSize GetSize() { return mSize; }
michael@0 45
michael@0 46 virtual void Flush();
michael@0 47 virtual void DrawSurface(SourceSurface *aSurface,
michael@0 48 const Rect &aDest,
michael@0 49 const Rect &aSource,
michael@0 50 const DrawSurfaceOptions &aSurfOptions,
michael@0 51 const DrawOptions &aOptions);
michael@0 52 virtual void DrawFilter(FilterNode *aNode,
michael@0 53 const Rect &aSourceRect,
michael@0 54 const Point &aDestPoint,
michael@0 55 const DrawOptions &aOptions = DrawOptions());
michael@0 56 virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
michael@0 57 const Point &aDest,
michael@0 58 const Color &aColor,
michael@0 59 const Point &aOffset,
michael@0 60 Float aSigma,
michael@0 61 CompositionOp aOperator);
michael@0 62 virtual void ClearRect(const Rect &aRect);
michael@0 63 virtual void MaskSurface(const Pattern &aSource,
michael@0 64 SourceSurface *aMask,
michael@0 65 Point aOffset,
michael@0 66 const DrawOptions &aOptions = DrawOptions());
michael@0 67
michael@0 68 virtual void CopySurface(SourceSurface *aSurface,
michael@0 69 const IntRect &aSourceRect,
michael@0 70 const IntPoint &aDestination);
michael@0 71
michael@0 72 virtual void FillRect(const Rect &aRect,
michael@0 73 const Pattern &aPattern,
michael@0 74 const DrawOptions &aOptions = DrawOptions());
michael@0 75 virtual void StrokeRect(const Rect &aRect,
michael@0 76 const Pattern &aPattern,
michael@0 77 const StrokeOptions &aStrokeOptions = StrokeOptions(),
michael@0 78 const DrawOptions &aOptions = DrawOptions());
michael@0 79 virtual void StrokeLine(const Point &aStart,
michael@0 80 const Point &aEnd,
michael@0 81 const Pattern &aPattern,
michael@0 82 const StrokeOptions &aStrokeOptions = StrokeOptions(),
michael@0 83 const DrawOptions &aOptions = DrawOptions());
michael@0 84 virtual void Stroke(const Path *aPath,
michael@0 85 const Pattern &aPattern,
michael@0 86 const StrokeOptions &aStrokeOptions = StrokeOptions(),
michael@0 87 const DrawOptions &aOptions = DrawOptions());
michael@0 88 virtual void Fill(const Path *aPath,
michael@0 89 const Pattern &aPattern,
michael@0 90 const DrawOptions &aOptions = DrawOptions());
michael@0 91 virtual void FillGlyphs(ScaledFont *aFont,
michael@0 92 const GlyphBuffer &aBuffer,
michael@0 93 const Pattern &aPattern,
michael@0 94 const DrawOptions &aOptions = DrawOptions(),
michael@0 95 const GlyphRenderingOptions *aRenderingOptions = nullptr);
michael@0 96 virtual void Mask(const Pattern &aSource,
michael@0 97 const Pattern &aMask,
michael@0 98 const DrawOptions &aOptions = DrawOptions());
michael@0 99 virtual void PushClip(const Path *aPath);
michael@0 100 virtual void PushClipRect(const Rect &aRect);
michael@0 101 virtual void PopClip();
michael@0 102
michael@0 103 virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
michael@0 104 const IntSize &aSize,
michael@0 105 int32_t aStride,
michael@0 106 SurfaceFormat aFormat) const;
michael@0 107 virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const;
michael@0 108
michael@0 109 virtual TemporaryRef<SourceSurface>
michael@0 110 CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const { return nullptr; }
michael@0 111
michael@0 112 virtual TemporaryRef<DrawTarget>
michael@0 113 CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
michael@0 114
michael@0 115 virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
michael@0 116
michael@0 117 virtual TemporaryRef<GradientStops>
michael@0 118 CreateGradientStops(GradientStop *aStops,
michael@0 119 uint32_t aNumStops,
michael@0 120 ExtendMode aExtendMode = ExtendMode::CLAMP) const;
michael@0 121
michael@0 122 virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType);
michael@0 123
michael@0 124 virtual void *GetNativeSurface(NativeSurfaceType aType) { return nullptr; }
michael@0 125
michael@0 126 bool Init(const IntSize &aSize, SurfaceFormat aFormat);
michael@0 127 uint32_t GetByteSize() const;
michael@0 128
michael@0 129 TemporaryRef<ID2D1Image> GetImageForSurface(SourceSurface *aSurface, Matrix &aSourceTransform,
michael@0 130 ExtendMode aExtendMode);
michael@0 131
michael@0 132 TemporaryRef<ID2D1Image> GetImageForSurface(SourceSurface *aSurface, ExtendMode aExtendMode) {
michael@0 133 Matrix mat;
michael@0 134 return GetImageForSurface(aSurface, mat, aExtendMode);
michael@0 135 }
michael@0 136
michael@0 137 static ID2D1Factory1 *factory();
michael@0 138 static void CleanupD2D();
michael@0 139 static IDWriteFactory *GetDWriteFactory();
michael@0 140
michael@0 141 operator std::string() const {
michael@0 142 std::stringstream stream;
michael@0 143 stream << "DrawTargetD2D 1.1 (" << this << ")";
michael@0 144 return stream.str();
michael@0 145 }
michael@0 146
michael@0 147 static uint64_t mVRAMUsageDT;
michael@0 148 static uint64_t mVRAMUsageSS;
michael@0 149
michael@0 150 private:
michael@0 151 friend class SourceSurfaceD2D1;
michael@0 152
michael@0 153 #ifdef _MSC_VER
michael@0 154 typedef stdext::hash_set<DrawTargetD2D1*> TargetSet;
michael@0 155 #else
michael@0 156 typedef std::unordered_set<DrawTargetD2D1*> TargetSet;
michael@0 157 #endif
michael@0 158
michael@0 159 // This function will mark the surface as changing, and make sure any
michael@0 160 // copy-on-write snapshots are notified.
michael@0 161 void MarkChanged();
michael@0 162 void PrepareForDrawing(CompositionOp aOp, const Pattern &aPattern);
michael@0 163 void FinalizeDrawing(CompositionOp aOp, const Pattern &aPattern);
michael@0 164 void FlushTransformToDC() {
michael@0 165 if (mTransformDirty) {
michael@0 166 mDC->SetTransform(D2DMatrix(mTransform));
michael@0 167 mTransformDirty = false;
michael@0 168 }
michael@0 169 }
michael@0 170 void AddDependencyOnSource(SourceSurfaceD2D1* aSource);
michael@0 171
michael@0 172 void PopAllClips();
michael@0 173 void PushClipsToDC(ID2D1DeviceContext *aDC);
michael@0 174 void PopClipsFromDC(ID2D1DeviceContext *aDC);
michael@0 175
michael@0 176 TemporaryRef<ID2D1Brush> CreateBrushForPattern(const Pattern &aPattern, Float aAlpha = 1.0f);
michael@0 177
michael@0 178 void PushD2DLayer(ID2D1DeviceContext *aDC, ID2D1Geometry *aGeometry, const D2D1_MATRIX_3X2_F &aTransform);
michael@0 179
michael@0 180 IntSize mSize;
michael@0 181
michael@0 182 RefPtr<ID3D11Device> mDevice;
michael@0 183 RefPtr<ID3D11Texture2D> mTexture;
michael@0 184 // This is only valid if mCurrentClippedGeometry is non-null. And will
michael@0 185 // only be the intersection of all pixel-aligned retangular clips. This is in
michael@0 186 // device space.
michael@0 187 IntRect mCurrentClipBounds;
michael@0 188 mutable RefPtr<ID2D1DeviceContext> mDC;
michael@0 189 RefPtr<ID2D1Bitmap1> mBitmap;
michael@0 190 RefPtr<ID2D1Bitmap1> mTempBitmap;
michael@0 191
michael@0 192 // We store this to prevent excessive SetTextRenderingParams calls.
michael@0 193 RefPtr<IDWriteRenderingParams> mTextRenderingParams;
michael@0 194
michael@0 195 // List of pushed clips.
michael@0 196 struct PushedClip
michael@0 197 {
michael@0 198 D2D1_RECT_F mBounds;
michael@0 199 union {
michael@0 200 // If mPath is non-null, the mTransform member will be used, otherwise
michael@0 201 // the mIsPixelAligned member is valid.
michael@0 202 D2D1_MATRIX_3X2_F mTransform;
michael@0 203 bool mIsPixelAligned;
michael@0 204 };
michael@0 205 RefPtr<PathD2D> mPath;
michael@0 206 };
michael@0 207 std::vector<PushedClip> mPushedClips;
michael@0 208
michael@0 209 // The latest snapshot of this surface. This needs to be told when this
michael@0 210 // target is modified. We keep it alive as a cache.
michael@0 211 RefPtr<SourceSurfaceD2D1> mSnapshot;
michael@0 212 // A list of targets we need to flush when we're modified.
michael@0 213 TargetSet mDependentTargets;
michael@0 214 // A list of targets which have this object in their mDependentTargets set
michael@0 215 TargetSet mDependingOnTargets;
michael@0 216
michael@0 217 // True of the current clip stack is pushed to the main RT.
michael@0 218 bool mClipsArePushed;
michael@0 219 static ID2D1Factory1 *mFactory;
michael@0 220 static IDWriteFactory *mDWriteFactory;
michael@0 221 };
michael@0 222
michael@0 223 }
michael@0 224 }
michael@0 225
michael@0 226 #endif /* MOZILLA_GFX_DRAWTARGETD2D_H_ */

mercurial