gfx/2d/DrawTargetSkia.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.

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_SOURCESURFACESKIA_H
michael@0 7 #define _MOZILLA_GFX_SOURCESURFACESKIA_H
michael@0 8
michael@0 9 #ifdef USE_SKIA_GPU
michael@0 10 #include "skia/GrContext.h"
michael@0 11 #include "skia/GrGLInterface.h"
michael@0 12 #endif
michael@0 13
michael@0 14 #include "skia/SkCanvas.h"
michael@0 15
michael@0 16 #include "2D.h"
michael@0 17 #include "Rect.h"
michael@0 18 #include "PathSkia.h"
michael@0 19 #include <sstream>
michael@0 20 #include <vector>
michael@0 21
michael@0 22 namespace mozilla {
michael@0 23 namespace gfx {
michael@0 24
michael@0 25 class SourceSurfaceSkia;
michael@0 26
michael@0 27 class DrawTargetSkia : public DrawTarget
michael@0 28 {
michael@0 29 public:
michael@0 30 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetSkia)
michael@0 31 DrawTargetSkia();
michael@0 32 virtual ~DrawTargetSkia();
michael@0 33
michael@0 34 virtual BackendType GetType() const { return BackendType::SKIA; }
michael@0 35 virtual TemporaryRef<SourceSurface> Snapshot();
michael@0 36 virtual IntSize GetSize() { return mSize; }
michael@0 37 virtual void Flush();
michael@0 38 virtual void DrawSurface(SourceSurface *aSurface,
michael@0 39 const Rect &aDest,
michael@0 40 const Rect &aSource,
michael@0 41 const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(),
michael@0 42 const DrawOptions &aOptions = DrawOptions());
michael@0 43 virtual void DrawFilter(FilterNode *aNode,
michael@0 44 const Rect &aSourceRect,
michael@0 45 const Point &aDestPoint,
michael@0 46 const DrawOptions &aOptions = DrawOptions());
michael@0 47 virtual void DrawSurfaceWithShadow(SourceSurface *aSurface,
michael@0 48 const Point &aDest,
michael@0 49 const Color &aColor,
michael@0 50 const Point &aOffset,
michael@0 51 Float aSigma,
michael@0 52 CompositionOp aOperator);
michael@0 53 virtual void ClearRect(const Rect &aRect);
michael@0 54 virtual void CopySurface(SourceSurface *aSurface,
michael@0 55 const IntRect &aSourceRect,
michael@0 56 const IntPoint &aDestination);
michael@0 57 virtual void FillRect(const Rect &aRect,
michael@0 58 const Pattern &aPattern,
michael@0 59 const DrawOptions &aOptions = DrawOptions());
michael@0 60 virtual void StrokeRect(const Rect &aRect,
michael@0 61 const Pattern &aPattern,
michael@0 62 const StrokeOptions &aStrokeOptions = StrokeOptions(),
michael@0 63 const DrawOptions &aOptions = DrawOptions());
michael@0 64 virtual void StrokeLine(const Point &aStart,
michael@0 65 const Point &aEnd,
michael@0 66 const Pattern &aPattern,
michael@0 67 const StrokeOptions &aStrokeOptions = StrokeOptions(),
michael@0 68 const DrawOptions &aOptions = DrawOptions());
michael@0 69 virtual void Stroke(const Path *aPath,
michael@0 70 const Pattern &aPattern,
michael@0 71 const StrokeOptions &aStrokeOptions = StrokeOptions(),
michael@0 72 const DrawOptions &aOptions = DrawOptions());
michael@0 73 virtual void Fill(const Path *aPath,
michael@0 74 const Pattern &aPattern,
michael@0 75 const DrawOptions &aOptions = DrawOptions());
michael@0 76 virtual void FillGlyphs(ScaledFont *aFont,
michael@0 77 const GlyphBuffer &aBuffer,
michael@0 78 const Pattern &aPattern,
michael@0 79 const DrawOptions &aOptions = DrawOptions(),
michael@0 80 const GlyphRenderingOptions *aRenderingOptions = nullptr);
michael@0 81 virtual void Mask(const Pattern &aSource,
michael@0 82 const Pattern &aMask,
michael@0 83 const DrawOptions &aOptions = DrawOptions());
michael@0 84 virtual void MaskSurface(const Pattern &aSource,
michael@0 85 SourceSurface *aMask,
michael@0 86 Point aOffset,
michael@0 87 const DrawOptions &aOptions = DrawOptions());
michael@0 88 virtual void PushClip(const Path *aPath);
michael@0 89 virtual void PushClipRect(const Rect& aRect);
michael@0 90 virtual void PopClip();
michael@0 91 virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData,
michael@0 92 const IntSize &aSize,
michael@0 93 int32_t aStride,
michael@0 94 SurfaceFormat aFormat) const;
michael@0 95 virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const;
michael@0 96 virtual TemporaryRef<SourceSurface>
michael@0 97 CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const;
michael@0 98 virtual TemporaryRef<DrawTarget>
michael@0 99 CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const;
michael@0 100 virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const;
michael@0 101 virtual TemporaryRef<GradientStops> CreateGradientStops(GradientStop *aStops, uint32_t aNumStops, ExtendMode aExtendMode = ExtendMode::CLAMP) const;
michael@0 102 virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType);
michael@0 103 virtual void SetTransform(const Matrix &aTransform);
michael@0 104 virtual void *GetNativeSurface(NativeSurfaceType aType);
michael@0 105
michael@0 106 bool Init(const IntSize &aSize, SurfaceFormat aFormat);
michael@0 107 void Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
michael@0 108
michael@0 109 #ifdef USE_SKIA_GPU
michael@0 110 bool InitWithGrContext(GrContext* aGrContext,
michael@0 111 const IntSize &aSize,
michael@0 112 SurfaceFormat aFormat) MOZ_OVERRIDE;
michael@0 113 #endif
michael@0 114
michael@0 115 operator std::string() const {
michael@0 116 std::stringstream stream;
michael@0 117 stream << "DrawTargetSkia(" << this << ")";
michael@0 118 return stream.str();
michael@0 119 }
michael@0 120
michael@0 121 private:
michael@0 122 friend class SourceSurfaceSkia;
michael@0 123 void SnapshotDestroyed();
michael@0 124
michael@0 125 void MarkChanged();
michael@0 126
michael@0 127 SkRect SkRectCoveringWholeSurface() const;
michael@0 128
michael@0 129 #ifdef USE_SKIA_GPU
michael@0 130 SkRefPtr<GrContext> mGrContext;
michael@0 131 uint32_t mTexture;
michael@0 132 #endif
michael@0 133
michael@0 134 IntSize mSize;
michael@0 135 SkRefPtr<SkCanvas> mCanvas;
michael@0 136 SourceSurfaceSkia* mSnapshot;
michael@0 137 };
michael@0 138
michael@0 139 }
michael@0 140 }
michael@0 141
michael@0 142 #endif // _MOZILLA_GFX_SOURCESURFACESKIA_H

mercurial