Tue, 06 Jan 2015 21:39:09 +0100
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_2D_H |
michael@0 | 7 | #define _MOZILLA_GFX_2D_H |
michael@0 | 8 | |
michael@0 | 9 | #include "Types.h" |
michael@0 | 10 | #include "Point.h" |
michael@0 | 11 | #include "Rect.h" |
michael@0 | 12 | #include "Matrix.h" |
michael@0 | 13 | #include "UserData.h" |
michael@0 | 14 | |
michael@0 | 15 | // GenericRefCountedBase allows us to hold on to refcounted objects of any type |
michael@0 | 16 | // (contrary to RefCounted<T> which requires knowing the type T) and, in particular, |
michael@0 | 17 | // without having a dependency on that type. This is used for DrawTargetSkia |
michael@0 | 18 | // to be able to hold on to a GLContext. |
michael@0 | 19 | #include "mozilla/GenericRefCounted.h" |
michael@0 | 20 | |
michael@0 | 21 | // This RefPtr class isn't ideal for usage in Azure, as it doesn't allow T** |
michael@0 | 22 | // outparams using the &-operator. But it will have to do as there's no easy |
michael@0 | 23 | // solution. |
michael@0 | 24 | #include "mozilla/RefPtr.h" |
michael@0 | 25 | |
michael@0 | 26 | #include "mozilla/DebugOnly.h" |
michael@0 | 27 | |
michael@0 | 28 | #ifdef MOZ_ENABLE_FREETYPE |
michael@0 | 29 | #include <string> |
michael@0 | 30 | #endif |
michael@0 | 31 | |
michael@0 | 32 | struct _cairo_surface; |
michael@0 | 33 | typedef _cairo_surface cairo_surface_t; |
michael@0 | 34 | |
michael@0 | 35 | struct _cairo_scaled_font; |
michael@0 | 36 | typedef _cairo_scaled_font cairo_scaled_font_t; |
michael@0 | 37 | |
michael@0 | 38 | struct ID3D10Device1; |
michael@0 | 39 | struct ID3D10Texture2D; |
michael@0 | 40 | struct ID3D11Device; |
michael@0 | 41 | struct ID2D1Device; |
michael@0 | 42 | struct IDWriteRenderingParams; |
michael@0 | 43 | |
michael@0 | 44 | class GrContext; |
michael@0 | 45 | struct GrGLInterface; |
michael@0 | 46 | |
michael@0 | 47 | struct CGContext; |
michael@0 | 48 | typedef struct CGContext *CGContextRef; |
michael@0 | 49 | |
michael@0 | 50 | namespace mozilla { |
michael@0 | 51 | |
michael@0 | 52 | namespace gfx { |
michael@0 | 53 | |
michael@0 | 54 | class SourceSurface; |
michael@0 | 55 | class DataSourceSurface; |
michael@0 | 56 | class DrawTarget; |
michael@0 | 57 | class DrawEventRecorder; |
michael@0 | 58 | class FilterNode; |
michael@0 | 59 | |
michael@0 | 60 | struct NativeSurface { |
michael@0 | 61 | NativeSurfaceType mType; |
michael@0 | 62 | SurfaceFormat mFormat; |
michael@0 | 63 | gfx::IntSize mSize; |
michael@0 | 64 | void *mSurface; |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | struct NativeFont { |
michael@0 | 68 | NativeFontType mType; |
michael@0 | 69 | void *mFont; |
michael@0 | 70 | }; |
michael@0 | 71 | |
michael@0 | 72 | /* |
michael@0 | 73 | * This structure is used to send draw options that are universal to all drawing |
michael@0 | 74 | * operations. It consists of the following: |
michael@0 | 75 | * |
michael@0 | 76 | * mAlpha - Alpha value by which the mask generated by this operation is |
michael@0 | 77 | * multiplied. |
michael@0 | 78 | * mCompositionOp - The operator that indicates how the source and destination |
michael@0 | 79 | * patterns are blended. |
michael@0 | 80 | * mAntiAliasMode - The AntiAlias mode used for this drawing operation. |
michael@0 | 81 | */ |
michael@0 | 82 | struct DrawOptions { |
michael@0 | 83 | DrawOptions(Float aAlpha = 1.0f, |
michael@0 | 84 | CompositionOp aCompositionOp = CompositionOp::OP_OVER, |
michael@0 | 85 | AntialiasMode aAntialiasMode = AntialiasMode::DEFAULT) |
michael@0 | 86 | : mAlpha(aAlpha) |
michael@0 | 87 | , mCompositionOp(aCompositionOp) |
michael@0 | 88 | , mAntialiasMode(aAntialiasMode) |
michael@0 | 89 | {} |
michael@0 | 90 | |
michael@0 | 91 | Float mAlpha; |
michael@0 | 92 | CompositionOp mCompositionOp; |
michael@0 | 93 | AntialiasMode mAntialiasMode; |
michael@0 | 94 | }; |
michael@0 | 95 | |
michael@0 | 96 | /* |
michael@0 | 97 | * This structure is used to send stroke options that are used in stroking |
michael@0 | 98 | * operations. It consists of the following: |
michael@0 | 99 | * |
michael@0 | 100 | * mLineWidth - Width of the stroke in userspace. |
michael@0 | 101 | * mLineJoin - Join style used for joining lines. |
michael@0 | 102 | * mLineCap - Cap style used for capping lines. |
michael@0 | 103 | * mMiterLimit - Miter limit in units of linewidth |
michael@0 | 104 | * mDashPattern - Series of on/off userspace lengths defining dash. |
michael@0 | 105 | * Owned by the caller; must live at least as long as |
michael@0 | 106 | * this StrokeOptions. |
michael@0 | 107 | * mDashPattern != null <=> mDashLength > 0. |
michael@0 | 108 | * mDashLength - Number of on/off lengths in mDashPattern. |
michael@0 | 109 | * mDashOffset - Userspace offset within mDashPattern at which stroking |
michael@0 | 110 | * begins. |
michael@0 | 111 | */ |
michael@0 | 112 | struct StrokeOptions { |
michael@0 | 113 | StrokeOptions(Float aLineWidth = 1.0f, |
michael@0 | 114 | JoinStyle aLineJoin = JoinStyle::MITER_OR_BEVEL, |
michael@0 | 115 | CapStyle aLineCap = CapStyle::BUTT, |
michael@0 | 116 | Float aMiterLimit = 10.0f, |
michael@0 | 117 | size_t aDashLength = 0, |
michael@0 | 118 | const Float* aDashPattern = 0, |
michael@0 | 119 | Float aDashOffset = 0.f) |
michael@0 | 120 | : mLineWidth(aLineWidth) |
michael@0 | 121 | , mMiterLimit(aMiterLimit) |
michael@0 | 122 | , mDashPattern(aDashLength > 0 ? aDashPattern : 0) |
michael@0 | 123 | , mDashLength(aDashLength) |
michael@0 | 124 | , mDashOffset(aDashOffset) |
michael@0 | 125 | , mLineJoin(aLineJoin) |
michael@0 | 126 | , mLineCap(aLineCap) |
michael@0 | 127 | { |
michael@0 | 128 | MOZ_ASSERT(aDashLength == 0 || aDashPattern); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | Float mLineWidth; |
michael@0 | 132 | Float mMiterLimit; |
michael@0 | 133 | const Float* mDashPattern; |
michael@0 | 134 | size_t mDashLength; |
michael@0 | 135 | Float mDashOffset; |
michael@0 | 136 | JoinStyle mLineJoin; |
michael@0 | 137 | CapStyle mLineCap; |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | /* |
michael@0 | 141 | * This structure supplies additional options for calls to DrawSurface. |
michael@0 | 142 | * |
michael@0 | 143 | * mFilter - Filter used when resampling source surface region to the |
michael@0 | 144 | * destination region. |
michael@0 | 145 | * aSamplingBounds - This indicates whether the implementation is allowed |
michael@0 | 146 | * to sample pixels outside the source rectangle as |
michael@0 | 147 | * specified in DrawSurface on the surface. |
michael@0 | 148 | */ |
michael@0 | 149 | struct DrawSurfaceOptions { |
michael@0 | 150 | DrawSurfaceOptions(Filter aFilter = Filter::LINEAR, |
michael@0 | 151 | SamplingBounds aSamplingBounds = SamplingBounds::UNBOUNDED) |
michael@0 | 152 | : mFilter(aFilter) |
michael@0 | 153 | , mSamplingBounds(aSamplingBounds) |
michael@0 | 154 | { } |
michael@0 | 155 | |
michael@0 | 156 | Filter mFilter; |
michael@0 | 157 | SamplingBounds mSamplingBounds; |
michael@0 | 158 | }; |
michael@0 | 159 | |
michael@0 | 160 | /* |
michael@0 | 161 | * This class is used to store gradient stops, it can only be used with a |
michael@0 | 162 | * matching DrawTarget. Not adhering to this condition will make a draw call |
michael@0 | 163 | * fail. |
michael@0 | 164 | */ |
michael@0 | 165 | class GradientStops : public RefCounted<GradientStops> |
michael@0 | 166 | { |
michael@0 | 167 | public: |
michael@0 | 168 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GradientStops) |
michael@0 | 169 | virtual ~GradientStops() {} |
michael@0 | 170 | |
michael@0 | 171 | virtual BackendType GetBackendType() const = 0; |
michael@0 | 172 | |
michael@0 | 173 | protected: |
michael@0 | 174 | GradientStops() {} |
michael@0 | 175 | }; |
michael@0 | 176 | |
michael@0 | 177 | /* |
michael@0 | 178 | * This is the base class for 'patterns'. Patterns describe the pixels used as |
michael@0 | 179 | * the source for a masked composition operation that is done by the different |
michael@0 | 180 | * drawing commands. These objects are not backend specific, however for |
michael@0 | 181 | * example the gradient stops on a gradient pattern can be backend specific. |
michael@0 | 182 | */ |
michael@0 | 183 | class Pattern |
michael@0 | 184 | { |
michael@0 | 185 | public: |
michael@0 | 186 | virtual ~Pattern() {} |
michael@0 | 187 | |
michael@0 | 188 | virtual PatternType GetType() const = 0; |
michael@0 | 189 | |
michael@0 | 190 | protected: |
michael@0 | 191 | Pattern() {} |
michael@0 | 192 | }; |
michael@0 | 193 | |
michael@0 | 194 | class ColorPattern : public Pattern |
michael@0 | 195 | { |
michael@0 | 196 | public: |
michael@0 | 197 | ColorPattern(const Color &aColor) |
michael@0 | 198 | : mColor(aColor) |
michael@0 | 199 | {} |
michael@0 | 200 | |
michael@0 | 201 | virtual PatternType GetType() const { return PatternType::COLOR; } |
michael@0 | 202 | |
michael@0 | 203 | Color mColor; |
michael@0 | 204 | }; |
michael@0 | 205 | |
michael@0 | 206 | /* |
michael@0 | 207 | * This class is used for Linear Gradient Patterns, the gradient stops are |
michael@0 | 208 | * stored in a separate object and are backend dependent. This class itself |
michael@0 | 209 | * may be used on the stack. |
michael@0 | 210 | */ |
michael@0 | 211 | class LinearGradientPattern : public Pattern |
michael@0 | 212 | { |
michael@0 | 213 | public: |
michael@0 | 214 | /* |
michael@0 | 215 | * aBegin Start of the linear gradient |
michael@0 | 216 | * aEnd End of the linear gradient - NOTE: In the case of a zero length |
michael@0 | 217 | * gradient it will act as the color of the last stop. |
michael@0 | 218 | * aStops GradientStops object for this gradient, this should match the |
michael@0 | 219 | * backend type of the draw target this pattern will be used with. |
michael@0 | 220 | * aMatrix A matrix that transforms the pattern into user space |
michael@0 | 221 | */ |
michael@0 | 222 | LinearGradientPattern(const Point &aBegin, |
michael@0 | 223 | const Point &aEnd, |
michael@0 | 224 | GradientStops *aStops, |
michael@0 | 225 | const Matrix &aMatrix = Matrix()) |
michael@0 | 226 | : mBegin(aBegin) |
michael@0 | 227 | , mEnd(aEnd) |
michael@0 | 228 | , mStops(aStops) |
michael@0 | 229 | , mMatrix(aMatrix) |
michael@0 | 230 | { |
michael@0 | 231 | } |
michael@0 | 232 | |
michael@0 | 233 | virtual PatternType GetType() const { return PatternType::LINEAR_GRADIENT; } |
michael@0 | 234 | |
michael@0 | 235 | Point mBegin; |
michael@0 | 236 | Point mEnd; |
michael@0 | 237 | RefPtr<GradientStops> mStops; |
michael@0 | 238 | Matrix mMatrix; |
michael@0 | 239 | }; |
michael@0 | 240 | |
michael@0 | 241 | /* |
michael@0 | 242 | * This class is used for Radial Gradient Patterns, the gradient stops are |
michael@0 | 243 | * stored in a separate object and are backend dependent. This class itself |
michael@0 | 244 | * may be used on the stack. |
michael@0 | 245 | */ |
michael@0 | 246 | class RadialGradientPattern : public Pattern |
michael@0 | 247 | { |
michael@0 | 248 | public: |
michael@0 | 249 | /* |
michael@0 | 250 | * aCenter1 Center of the inner (focal) circle. |
michael@0 | 251 | * aCenter2 Center of the outer circle. |
michael@0 | 252 | * aRadius1 Radius of the inner (focal) circle. |
michael@0 | 253 | * aRadius2 Radius of the outer circle. |
michael@0 | 254 | * aStops GradientStops object for this gradient, this should match the |
michael@0 | 255 | * backend type of the draw target this pattern will be used with. |
michael@0 | 256 | * aMatrix A matrix that transforms the pattern into user space |
michael@0 | 257 | */ |
michael@0 | 258 | RadialGradientPattern(const Point &aCenter1, |
michael@0 | 259 | const Point &aCenter2, |
michael@0 | 260 | Float aRadius1, |
michael@0 | 261 | Float aRadius2, |
michael@0 | 262 | GradientStops *aStops, |
michael@0 | 263 | const Matrix &aMatrix = Matrix()) |
michael@0 | 264 | : mCenter1(aCenter1) |
michael@0 | 265 | , mCenter2(aCenter2) |
michael@0 | 266 | , mRadius1(aRadius1) |
michael@0 | 267 | , mRadius2(aRadius2) |
michael@0 | 268 | , mStops(aStops) |
michael@0 | 269 | , mMatrix(aMatrix) |
michael@0 | 270 | { |
michael@0 | 271 | } |
michael@0 | 272 | |
michael@0 | 273 | virtual PatternType GetType() const { return PatternType::RADIAL_GRADIENT; } |
michael@0 | 274 | |
michael@0 | 275 | Point mCenter1; |
michael@0 | 276 | Point mCenter2; |
michael@0 | 277 | Float mRadius1; |
michael@0 | 278 | Float mRadius2; |
michael@0 | 279 | RefPtr<GradientStops> mStops; |
michael@0 | 280 | Matrix mMatrix; |
michael@0 | 281 | }; |
michael@0 | 282 | |
michael@0 | 283 | /* |
michael@0 | 284 | * This class is used for Surface Patterns, they wrap a surface and a |
michael@0 | 285 | * repetition mode for the surface. This may be used on the stack. |
michael@0 | 286 | */ |
michael@0 | 287 | class SurfacePattern : public Pattern |
michael@0 | 288 | { |
michael@0 | 289 | public: |
michael@0 | 290 | /* |
michael@0 | 291 | * aSourceSurface Surface to use for drawing |
michael@0 | 292 | * aExtendMode This determines how the image is extended outside the bounds |
michael@0 | 293 | * of the image. |
michael@0 | 294 | * aMatrix A matrix that transforms the pattern into user space |
michael@0 | 295 | * aFilter Resampling filter used for resampling the image. |
michael@0 | 296 | */ |
michael@0 | 297 | SurfacePattern(SourceSurface *aSourceSurface, ExtendMode aExtendMode, |
michael@0 | 298 | const Matrix &aMatrix = Matrix(), Filter aFilter = Filter::GOOD) |
michael@0 | 299 | : mSurface(aSourceSurface) |
michael@0 | 300 | , mExtendMode(aExtendMode) |
michael@0 | 301 | , mFilter(aFilter) |
michael@0 | 302 | , mMatrix(aMatrix) |
michael@0 | 303 | {} |
michael@0 | 304 | |
michael@0 | 305 | virtual PatternType GetType() const { return PatternType::SURFACE; } |
michael@0 | 306 | |
michael@0 | 307 | RefPtr<SourceSurface> mSurface; |
michael@0 | 308 | ExtendMode mExtendMode; |
michael@0 | 309 | Filter mFilter; |
michael@0 | 310 | Matrix mMatrix; |
michael@0 | 311 | }; |
michael@0 | 312 | |
michael@0 | 313 | /* |
michael@0 | 314 | * This is the base class for source surfaces. These objects are surfaces |
michael@0 | 315 | * which may be used as a source in a SurfacePattern or a DrawSurface call. |
michael@0 | 316 | * They cannot be drawn to directly. |
michael@0 | 317 | */ |
michael@0 | 318 | class SourceSurface : public RefCounted<SourceSurface> |
michael@0 | 319 | { |
michael@0 | 320 | public: |
michael@0 | 321 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurface) |
michael@0 | 322 | virtual ~SourceSurface() {} |
michael@0 | 323 | |
michael@0 | 324 | virtual SurfaceType GetType() const = 0; |
michael@0 | 325 | virtual IntSize GetSize() const = 0; |
michael@0 | 326 | virtual SurfaceFormat GetFormat() const = 0; |
michael@0 | 327 | |
michael@0 | 328 | /* This returns false if some event has made this source surface invalid for |
michael@0 | 329 | * usage with current DrawTargets. For example in the case of Direct2D this |
michael@0 | 330 | * could return false if we have switched devices since this surface was |
michael@0 | 331 | * created. |
michael@0 | 332 | */ |
michael@0 | 333 | virtual bool IsValid() const { return true; } |
michael@0 | 334 | |
michael@0 | 335 | /* |
michael@0 | 336 | * This function will get a DataSourceSurface for this surface, a |
michael@0 | 337 | * DataSourceSurface's data can be accessed directly. |
michael@0 | 338 | */ |
michael@0 | 339 | virtual TemporaryRef<DataSourceSurface> GetDataSurface() = 0; |
michael@0 | 340 | |
michael@0 | 341 | /* Tries to get this SourceSurface's native surface. This will fail if aType |
michael@0 | 342 | * is not the type of this SourceSurface's native surface. |
michael@0 | 343 | */ |
michael@0 | 344 | virtual void *GetNativeSurface(NativeSurfaceType aType) { |
michael@0 | 345 | return nullptr; |
michael@0 | 346 | } |
michael@0 | 347 | |
michael@0 | 348 | void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) { |
michael@0 | 349 | mUserData.Add(key, userData, destroy); |
michael@0 | 350 | } |
michael@0 | 351 | void *GetUserData(UserDataKey *key) { |
michael@0 | 352 | return mUserData.Get(key); |
michael@0 | 353 | } |
michael@0 | 354 | |
michael@0 | 355 | protected: |
michael@0 | 356 | UserData mUserData; |
michael@0 | 357 | }; |
michael@0 | 358 | |
michael@0 | 359 | class DataSourceSurface : public SourceSurface |
michael@0 | 360 | { |
michael@0 | 361 | public: |
michael@0 | 362 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurface) |
michael@0 | 363 | DataSourceSurface() |
michael@0 | 364 | : mIsMapped(false) |
michael@0 | 365 | { |
michael@0 | 366 | } |
michael@0 | 367 | |
michael@0 | 368 | #ifdef DEBUG |
michael@0 | 369 | virtual ~DataSourceSurface() |
michael@0 | 370 | { |
michael@0 | 371 | MOZ_ASSERT(!mIsMapped, "Someone forgot to call Unmap()"); |
michael@0 | 372 | } |
michael@0 | 373 | #endif |
michael@0 | 374 | |
michael@0 | 375 | struct MappedSurface { |
michael@0 | 376 | uint8_t *mData; |
michael@0 | 377 | int32_t mStride; |
michael@0 | 378 | }; |
michael@0 | 379 | |
michael@0 | 380 | enum MapType { |
michael@0 | 381 | READ, |
michael@0 | 382 | WRITE, |
michael@0 | 383 | READ_WRITE |
michael@0 | 384 | }; |
michael@0 | 385 | |
michael@0 | 386 | virtual SurfaceType GetType() const { return SurfaceType::DATA; } |
michael@0 | 387 | /* [DEPRECATED] |
michael@0 | 388 | * Get the raw bitmap data of the surface. |
michael@0 | 389 | * Can return null if there was OOM allocating surface data. |
michael@0 | 390 | */ |
michael@0 | 391 | virtual uint8_t *GetData() = 0; |
michael@0 | 392 | |
michael@0 | 393 | /* [DEPRECATED] |
michael@0 | 394 | * Stride of the surface, distance in bytes between the start of the image |
michael@0 | 395 | * data belonging to row y and row y+1. This may be negative. |
michael@0 | 396 | * Can return 0 if there was OOM allocating surface data. |
michael@0 | 397 | */ |
michael@0 | 398 | virtual int32_t Stride() = 0; |
michael@0 | 399 | |
michael@0 | 400 | virtual bool Map(MapType, MappedSurface *aMappedSurface) |
michael@0 | 401 | { |
michael@0 | 402 | aMappedSurface->mData = GetData(); |
michael@0 | 403 | aMappedSurface->mStride = Stride(); |
michael@0 | 404 | mIsMapped = true; |
michael@0 | 405 | return true; |
michael@0 | 406 | } |
michael@0 | 407 | |
michael@0 | 408 | virtual void Unmap() |
michael@0 | 409 | { |
michael@0 | 410 | MOZ_ASSERT(mIsMapped); |
michael@0 | 411 | mIsMapped = false; |
michael@0 | 412 | } |
michael@0 | 413 | |
michael@0 | 414 | /* |
michael@0 | 415 | * Returns a DataSourceSurface with the same data as this one, but |
michael@0 | 416 | * guaranteed to have surface->GetType() == SurfaceType::DATA. |
michael@0 | 417 | */ |
michael@0 | 418 | virtual TemporaryRef<DataSourceSurface> GetDataSurface(); |
michael@0 | 419 | |
michael@0 | 420 | bool mIsMapped; |
michael@0 | 421 | }; |
michael@0 | 422 | |
michael@0 | 423 | /* This is an abstract object that accepts path segments. */ |
michael@0 | 424 | class PathSink : public RefCounted<PathSink> |
michael@0 | 425 | { |
michael@0 | 426 | public: |
michael@0 | 427 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathSink) |
michael@0 | 428 | virtual ~PathSink() {} |
michael@0 | 429 | |
michael@0 | 430 | /* Move the current point in the path, any figure currently being drawn will |
michael@0 | 431 | * be considered closed during fill operations, however when stroking the |
michael@0 | 432 | * closing line segment will not be drawn. |
michael@0 | 433 | */ |
michael@0 | 434 | virtual void MoveTo(const Point &aPoint) = 0; |
michael@0 | 435 | /* Add a linesegment to the current figure */ |
michael@0 | 436 | virtual void LineTo(const Point &aPoint) = 0; |
michael@0 | 437 | /* Add a cubic bezier curve to the current figure */ |
michael@0 | 438 | virtual void BezierTo(const Point &aCP1, |
michael@0 | 439 | const Point &aCP2, |
michael@0 | 440 | const Point &aCP3) = 0; |
michael@0 | 441 | /* Add a quadratic bezier curve to the current figure */ |
michael@0 | 442 | virtual void QuadraticBezierTo(const Point &aCP1, |
michael@0 | 443 | const Point &aCP2) = 0; |
michael@0 | 444 | /* Close the current figure, this will essentially generate a line segment |
michael@0 | 445 | * from the current point to the starting point for the current figure |
michael@0 | 446 | */ |
michael@0 | 447 | virtual void Close() = 0; |
michael@0 | 448 | /* Add an arc to the current figure */ |
michael@0 | 449 | virtual void Arc(const Point &aOrigin, float aRadius, float aStartAngle, |
michael@0 | 450 | float aEndAngle, bool aAntiClockwise = false) = 0; |
michael@0 | 451 | /* Point the current subpath is at - or where the next subpath will start |
michael@0 | 452 | * if there is no active subpath. |
michael@0 | 453 | */ |
michael@0 | 454 | virtual Point CurrentPoint() const = 0; |
michael@0 | 455 | }; |
michael@0 | 456 | |
michael@0 | 457 | class PathBuilder; |
michael@0 | 458 | class FlattenedPath; |
michael@0 | 459 | |
michael@0 | 460 | /* The path class is used to create (sets of) figures of any shape that can be |
michael@0 | 461 | * filled or stroked to a DrawTarget |
michael@0 | 462 | */ |
michael@0 | 463 | class Path : public RefCounted<Path> |
michael@0 | 464 | { |
michael@0 | 465 | public: |
michael@0 | 466 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(Path) |
michael@0 | 467 | virtual ~Path(); |
michael@0 | 468 | |
michael@0 | 469 | virtual BackendType GetBackendType() const = 0; |
michael@0 | 470 | |
michael@0 | 471 | /* This returns a PathBuilder object that contains a copy of the contents of |
michael@0 | 472 | * this path and is still writable. |
michael@0 | 473 | */ |
michael@0 | 474 | virtual TemporaryRef<PathBuilder> CopyToBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const = 0; |
michael@0 | 475 | virtual TemporaryRef<PathBuilder> TransformedCopyToBuilder(const Matrix &aTransform, |
michael@0 | 476 | FillRule aFillRule = FillRule::FILL_WINDING) const = 0; |
michael@0 | 477 | |
michael@0 | 478 | /* This function checks if a point lies within a path. It allows passing a |
michael@0 | 479 | * transform that will transform the path to the coordinate space in which |
michael@0 | 480 | * aPoint is given. |
michael@0 | 481 | */ |
michael@0 | 482 | virtual bool ContainsPoint(const Point &aPoint, const Matrix &aTransform) const = 0; |
michael@0 | 483 | |
michael@0 | 484 | |
michael@0 | 485 | /* This function checks if a point lies within the stroke of a path using the |
michael@0 | 486 | * specified strokeoptions. It allows passing a transform that will transform |
michael@0 | 487 | * the path to the coordinate space in which aPoint is given. |
michael@0 | 488 | */ |
michael@0 | 489 | virtual bool StrokeContainsPoint(const StrokeOptions &aStrokeOptions, |
michael@0 | 490 | const Point &aPoint, |
michael@0 | 491 | const Matrix &aTransform) const = 0; |
michael@0 | 492 | |
michael@0 | 493 | /* This functions gets the bounds of this path. These bounds are not |
michael@0 | 494 | * guaranteed to be tight. A transform may be specified that gives the bounds |
michael@0 | 495 | * after application of the transform. |
michael@0 | 496 | */ |
michael@0 | 497 | virtual Rect GetBounds(const Matrix &aTransform = Matrix()) const = 0; |
michael@0 | 498 | |
michael@0 | 499 | /* This function gets the bounds of the stroke of this path using the |
michael@0 | 500 | * specified strokeoptions. These bounds are not guaranteed to be tight. |
michael@0 | 501 | * A transform may be specified that gives the bounds after application of |
michael@0 | 502 | * the transform. |
michael@0 | 503 | */ |
michael@0 | 504 | virtual Rect GetStrokedBounds(const StrokeOptions &aStrokeOptions, |
michael@0 | 505 | const Matrix &aTransform = Matrix()) const = 0; |
michael@0 | 506 | |
michael@0 | 507 | /* Take the contents of this path and stream it to another sink, this works |
michael@0 | 508 | * regardless of the backend that might be used for the destination sink. |
michael@0 | 509 | */ |
michael@0 | 510 | virtual void StreamToSink(PathSink *aSink) const = 0; |
michael@0 | 511 | |
michael@0 | 512 | /* This gets the fillrule this path's builder was created with. This is not |
michael@0 | 513 | * mutable. |
michael@0 | 514 | */ |
michael@0 | 515 | virtual FillRule GetFillRule() const = 0; |
michael@0 | 516 | |
michael@0 | 517 | virtual Float ComputeLength(); |
michael@0 | 518 | |
michael@0 | 519 | virtual Point ComputePointAtLength(Float aLength, |
michael@0 | 520 | Point* aTangent = nullptr); |
michael@0 | 521 | |
michael@0 | 522 | protected: |
michael@0 | 523 | Path(); |
michael@0 | 524 | void EnsureFlattenedPath(); |
michael@0 | 525 | |
michael@0 | 526 | RefPtr<FlattenedPath> mFlattenedPath; |
michael@0 | 527 | }; |
michael@0 | 528 | |
michael@0 | 529 | /* The PathBuilder class allows path creation. Once finish is called on the |
michael@0 | 530 | * pathbuilder it may no longer be written to. |
michael@0 | 531 | */ |
michael@0 | 532 | class PathBuilder : public PathSink |
michael@0 | 533 | { |
michael@0 | 534 | public: |
michael@0 | 535 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(PathBuilder) |
michael@0 | 536 | /* Finish writing to the path and return a Path object that can be used for |
michael@0 | 537 | * drawing. Future use of the builder results in a crash! |
michael@0 | 538 | */ |
michael@0 | 539 | virtual TemporaryRef<Path> Finish() = 0; |
michael@0 | 540 | }; |
michael@0 | 541 | |
michael@0 | 542 | struct Glyph |
michael@0 | 543 | { |
michael@0 | 544 | uint32_t mIndex; |
michael@0 | 545 | Point mPosition; |
michael@0 | 546 | }; |
michael@0 | 547 | |
michael@0 | 548 | /* This class functions as a glyph buffer that can be drawn to a DrawTarget. |
michael@0 | 549 | * XXX - This should probably contain the guts of gfxTextRun in the future as |
michael@0 | 550 | * roc suggested. But for now it's a simple container for a glyph vector. |
michael@0 | 551 | */ |
michael@0 | 552 | struct GlyphBuffer |
michael@0 | 553 | { |
michael@0 | 554 | // A pointer to a buffer of glyphs. Managed by the caller. |
michael@0 | 555 | const Glyph *mGlyphs; |
michael@0 | 556 | // Number of glyphs mGlyphs points to. |
michael@0 | 557 | uint32_t mNumGlyphs; |
michael@0 | 558 | }; |
michael@0 | 559 | |
michael@0 | 560 | /* This class is an abstraction of a backend/platform specific font object |
michael@0 | 561 | * at a particular size. It is passed into text drawing calls to describe |
michael@0 | 562 | * the font used for the drawing call. |
michael@0 | 563 | */ |
michael@0 | 564 | class ScaledFont : public RefCounted<ScaledFont> |
michael@0 | 565 | { |
michael@0 | 566 | public: |
michael@0 | 567 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(ScaledFont) |
michael@0 | 568 | virtual ~ScaledFont() {} |
michael@0 | 569 | |
michael@0 | 570 | typedef void (*FontFileDataOutput)(const uint8_t *aData, uint32_t aLength, uint32_t aIndex, Float aGlyphSize, void *aBaton); |
michael@0 | 571 | |
michael@0 | 572 | virtual FontType GetType() const = 0; |
michael@0 | 573 | |
michael@0 | 574 | /* This allows getting a path that describes the outline of a set of glyphs. |
michael@0 | 575 | * A target is passed in so that the guarantee is made the returned path |
michael@0 | 576 | * can be used with any DrawTarget that has the same backend as the one |
michael@0 | 577 | * passed in. |
michael@0 | 578 | */ |
michael@0 | 579 | virtual TemporaryRef<Path> GetPathForGlyphs(const GlyphBuffer &aBuffer, const DrawTarget *aTarget) = 0; |
michael@0 | 580 | |
michael@0 | 581 | /* This copies the path describing the glyphs into a PathBuilder. We use this |
michael@0 | 582 | * API rather than a generic API to append paths because it allows easier |
michael@0 | 583 | * implementation in some backends, and more efficient implementation in |
michael@0 | 584 | * others. |
michael@0 | 585 | */ |
michael@0 | 586 | virtual void CopyGlyphsToBuilder(const GlyphBuffer &aBuffer, PathBuilder *aBuilder, BackendType aBackendType, const Matrix *aTransformHint = nullptr) = 0; |
michael@0 | 587 | |
michael@0 | 588 | virtual bool GetFontFileData(FontFileDataOutput, void *) { return false; } |
michael@0 | 589 | |
michael@0 | 590 | void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) { |
michael@0 | 591 | mUserData.Add(key, userData, destroy); |
michael@0 | 592 | } |
michael@0 | 593 | void *GetUserData(UserDataKey *key) { |
michael@0 | 594 | return mUserData.Get(key); |
michael@0 | 595 | } |
michael@0 | 596 | |
michael@0 | 597 | protected: |
michael@0 | 598 | ScaledFont() {} |
michael@0 | 599 | |
michael@0 | 600 | UserData mUserData; |
michael@0 | 601 | }; |
michael@0 | 602 | |
michael@0 | 603 | #ifdef MOZ_ENABLE_FREETYPE |
michael@0 | 604 | /** |
michael@0 | 605 | * Describes a font |
michael@0 | 606 | * Used to pass the key informatin from a gfxFont into Azure |
michael@0 | 607 | * XXX Should be replaced by a more long term solution, perhaps Bug 738014 |
michael@0 | 608 | */ |
michael@0 | 609 | struct FontOptions |
michael@0 | 610 | { |
michael@0 | 611 | std::string mName; |
michael@0 | 612 | FontStyle mStyle; |
michael@0 | 613 | }; |
michael@0 | 614 | #endif |
michael@0 | 615 | |
michael@0 | 616 | |
michael@0 | 617 | /* This class is designed to allow passing additional glyph rendering |
michael@0 | 618 | * parameters to the glyph drawing functions. This is an empty wrapper class |
michael@0 | 619 | * merely used to allow holding on to and passing around platform specific |
michael@0 | 620 | * parameters. This is because different platforms have unique rendering |
michael@0 | 621 | * parameters. |
michael@0 | 622 | */ |
michael@0 | 623 | class GlyphRenderingOptions : public RefCounted<GlyphRenderingOptions> |
michael@0 | 624 | { |
michael@0 | 625 | public: |
michael@0 | 626 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GlyphRenderingOptions) |
michael@0 | 627 | virtual ~GlyphRenderingOptions() {} |
michael@0 | 628 | |
michael@0 | 629 | virtual FontType GetType() const = 0; |
michael@0 | 630 | |
michael@0 | 631 | protected: |
michael@0 | 632 | GlyphRenderingOptions() {} |
michael@0 | 633 | }; |
michael@0 | 634 | |
michael@0 | 635 | /* This is the main class used for all the drawing. It is created through the |
michael@0 | 636 | * factory and accepts drawing commands. The results of drawing to a target |
michael@0 | 637 | * may be used either through a Snapshot or by flushing the target and directly |
michael@0 | 638 | * accessing the backing store a DrawTarget was created with. |
michael@0 | 639 | */ |
michael@0 | 640 | class DrawTarget : public RefCounted<DrawTarget> |
michael@0 | 641 | { |
michael@0 | 642 | public: |
michael@0 | 643 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTarget) |
michael@0 | 644 | DrawTarget() : mTransformDirty(false), mPermitSubpixelAA(false) {} |
michael@0 | 645 | virtual ~DrawTarget() {} |
michael@0 | 646 | |
michael@0 | 647 | virtual BackendType GetType() const = 0; |
michael@0 | 648 | /** |
michael@0 | 649 | * Returns a SourceSurface which is a snapshot of the current contents of the DrawTarget. |
michael@0 | 650 | * Multiple calls to Snapshot() without any drawing operations in between will |
michael@0 | 651 | * normally return the same SourceSurface object. |
michael@0 | 652 | */ |
michael@0 | 653 | virtual TemporaryRef<SourceSurface> Snapshot() = 0; |
michael@0 | 654 | virtual IntSize GetSize() = 0; |
michael@0 | 655 | |
michael@0 | 656 | /** |
michael@0 | 657 | * If possible returns the bits to this DrawTarget for direct manipulation. While |
michael@0 | 658 | * the bits is locked any modifications to this DrawTarget is forbidden. |
michael@0 | 659 | * Release takes the original data pointer for safety. |
michael@0 | 660 | */ |
michael@0 | 661 | virtual bool LockBits(uint8_t** aData, IntSize* aSize, |
michael@0 | 662 | int32_t* aStride, SurfaceFormat* aFormat) { return false; } |
michael@0 | 663 | virtual void ReleaseBits(uint8_t* aData) {} |
michael@0 | 664 | |
michael@0 | 665 | /* Ensure that the DrawTarget backend has flushed all drawing operations to |
michael@0 | 666 | * this draw target. This must be called before using the backing surface of |
michael@0 | 667 | * this draw target outside of GFX 2D code. |
michael@0 | 668 | */ |
michael@0 | 669 | virtual void Flush() = 0; |
michael@0 | 670 | |
michael@0 | 671 | /* |
michael@0 | 672 | * Draw a surface to the draw target. Possibly doing partial drawing or |
michael@0 | 673 | * applying scaling. No sampling happens outside the source. |
michael@0 | 674 | * |
michael@0 | 675 | * aSurface Source surface to draw |
michael@0 | 676 | * aDest Destination rectangle that this drawing operation should draw to |
michael@0 | 677 | * aSource Source rectangle in aSurface coordinates, this area of aSurface |
michael@0 | 678 | * will be stretched to the size of aDest. |
michael@0 | 679 | * aOptions General draw options that are applied to the operation |
michael@0 | 680 | * aSurfOptions DrawSurface options that are applied |
michael@0 | 681 | */ |
michael@0 | 682 | virtual void DrawSurface(SourceSurface *aSurface, |
michael@0 | 683 | const Rect &aDest, |
michael@0 | 684 | const Rect &aSource, |
michael@0 | 685 | const DrawSurfaceOptions &aSurfOptions = DrawSurfaceOptions(), |
michael@0 | 686 | const DrawOptions &aOptions = DrawOptions()) = 0; |
michael@0 | 687 | |
michael@0 | 688 | /* |
michael@0 | 689 | * Draw the output of a FilterNode to the DrawTarget. |
michael@0 | 690 | * |
michael@0 | 691 | * aNode FilterNode to draw |
michael@0 | 692 | * aSourceRect Source rectangle in FilterNode space to draw |
michael@0 | 693 | * aDestPoint Destination point on the DrawTarget to draw the |
michael@0 | 694 | * SourceRectangle of the filter output to |
michael@0 | 695 | */ |
michael@0 | 696 | virtual void DrawFilter(FilterNode *aNode, |
michael@0 | 697 | const Rect &aSourceRect, |
michael@0 | 698 | const Point &aDestPoint, |
michael@0 | 699 | const DrawOptions &aOptions = DrawOptions()) = 0; |
michael@0 | 700 | |
michael@0 | 701 | /* |
michael@0 | 702 | * Blend a surface to the draw target with a shadow. The shadow is drawn as a |
michael@0 | 703 | * gaussian blur using a specified sigma. The shadow is clipped to the size |
michael@0 | 704 | * of the input surface, so the input surface should contain a transparent |
michael@0 | 705 | * border the size of the approximate coverage of the blur (3 * aSigma). |
michael@0 | 706 | * NOTE: This function works in device space! |
michael@0 | 707 | * |
michael@0 | 708 | * aSurface Source surface to draw. |
michael@0 | 709 | * aDest Destination point that this drawing operation should draw to. |
michael@0 | 710 | * aColor Color of the drawn shadow |
michael@0 | 711 | * aOffset Offset of the shadow |
michael@0 | 712 | * aSigma Sigma used for the guassian filter kernel |
michael@0 | 713 | * aOperator Composition operator used |
michael@0 | 714 | */ |
michael@0 | 715 | virtual void DrawSurfaceWithShadow(SourceSurface *aSurface, |
michael@0 | 716 | const Point &aDest, |
michael@0 | 717 | const Color &aColor, |
michael@0 | 718 | const Point &aOffset, |
michael@0 | 719 | Float aSigma, |
michael@0 | 720 | CompositionOp aOperator) = 0; |
michael@0 | 721 | |
michael@0 | 722 | /* |
michael@0 | 723 | * Clear a rectangle on the draw target to transparent black. This will |
michael@0 | 724 | * respect the clipping region and transform. |
michael@0 | 725 | * |
michael@0 | 726 | * aRect Rectangle to clear |
michael@0 | 727 | */ |
michael@0 | 728 | virtual void ClearRect(const Rect &aRect) = 0; |
michael@0 | 729 | |
michael@0 | 730 | /* |
michael@0 | 731 | * This is essentially a 'memcpy' between two surfaces. It moves a pixel |
michael@0 | 732 | * aligned area from the source surface unscaled directly onto the |
michael@0 | 733 | * drawtarget. This ignores both transform and clip. |
michael@0 | 734 | * |
michael@0 | 735 | * aSurface Surface to copy from |
michael@0 | 736 | * aSourceRect Source rectangle to be copied |
michael@0 | 737 | * aDest Destination point to copy the surface to |
michael@0 | 738 | */ |
michael@0 | 739 | virtual void CopySurface(SourceSurface *aSurface, |
michael@0 | 740 | const IntRect &aSourceRect, |
michael@0 | 741 | const IntPoint &aDestination) = 0; |
michael@0 | 742 | |
michael@0 | 743 | /* |
michael@0 | 744 | * Same as CopySurface, except uses itself as the source. |
michael@0 | 745 | * |
michael@0 | 746 | * Some backends may be able to optimize this better |
michael@0 | 747 | * than just taking a snapshot and using CopySurface. |
michael@0 | 748 | */ |
michael@0 | 749 | virtual void CopyRect(const IntRect &aSourceRect, |
michael@0 | 750 | const IntPoint &aDestination) |
michael@0 | 751 | { |
michael@0 | 752 | RefPtr<SourceSurface> source = Snapshot(); |
michael@0 | 753 | CopySurface(source, aSourceRect, aDestination); |
michael@0 | 754 | } |
michael@0 | 755 | |
michael@0 | 756 | /* |
michael@0 | 757 | * Fill a rectangle on the DrawTarget with a certain source pattern. |
michael@0 | 758 | * |
michael@0 | 759 | * aRect Rectangle that forms the mask of this filling operation |
michael@0 | 760 | * aPattern Pattern that forms the source of this filling operation |
michael@0 | 761 | * aOptions Options that are applied to this operation |
michael@0 | 762 | */ |
michael@0 | 763 | virtual void FillRect(const Rect &aRect, |
michael@0 | 764 | const Pattern &aPattern, |
michael@0 | 765 | const DrawOptions &aOptions = DrawOptions()) = 0; |
michael@0 | 766 | |
michael@0 | 767 | /* |
michael@0 | 768 | * Stroke a rectangle on the DrawTarget with a certain source pattern. |
michael@0 | 769 | * |
michael@0 | 770 | * aRect Rectangle that forms the mask of this stroking operation |
michael@0 | 771 | * aPattern Pattern that forms the source of this stroking operation |
michael@0 | 772 | * aOptions Options that are applied to this operation |
michael@0 | 773 | */ |
michael@0 | 774 | virtual void StrokeRect(const Rect &aRect, |
michael@0 | 775 | const Pattern &aPattern, |
michael@0 | 776 | const StrokeOptions &aStrokeOptions = StrokeOptions(), |
michael@0 | 777 | const DrawOptions &aOptions = DrawOptions()) = 0; |
michael@0 | 778 | |
michael@0 | 779 | /* |
michael@0 | 780 | * Stroke a line on the DrawTarget with a certain source pattern. |
michael@0 | 781 | * |
michael@0 | 782 | * aStart Starting point of the line |
michael@0 | 783 | * aEnd End point of the line |
michael@0 | 784 | * aPattern Pattern that forms the source of this stroking operation |
michael@0 | 785 | * aOptions Options that are applied to this operation |
michael@0 | 786 | */ |
michael@0 | 787 | virtual void StrokeLine(const Point &aStart, |
michael@0 | 788 | const Point &aEnd, |
michael@0 | 789 | const Pattern &aPattern, |
michael@0 | 790 | const StrokeOptions &aStrokeOptions = StrokeOptions(), |
michael@0 | 791 | const DrawOptions &aOptions = DrawOptions()) = 0; |
michael@0 | 792 | |
michael@0 | 793 | /* |
michael@0 | 794 | * Stroke a path on the draw target with a certain source pattern. |
michael@0 | 795 | * |
michael@0 | 796 | * aPath Path that is to be stroked |
michael@0 | 797 | * aPattern Pattern that should be used for the stroke |
michael@0 | 798 | * aStrokeOptions Stroke options used for this operation |
michael@0 | 799 | * aOptions Draw options used for this operation |
michael@0 | 800 | */ |
michael@0 | 801 | virtual void Stroke(const Path *aPath, |
michael@0 | 802 | const Pattern &aPattern, |
michael@0 | 803 | const StrokeOptions &aStrokeOptions = StrokeOptions(), |
michael@0 | 804 | const DrawOptions &aOptions = DrawOptions()) = 0; |
michael@0 | 805 | |
michael@0 | 806 | /* |
michael@0 | 807 | * Fill a path on the draw target with a certain source pattern. |
michael@0 | 808 | * |
michael@0 | 809 | * aPath Path that is to be filled |
michael@0 | 810 | * aPattern Pattern that should be used for the fill |
michael@0 | 811 | * aOptions Draw options used for this operation |
michael@0 | 812 | */ |
michael@0 | 813 | virtual void Fill(const Path *aPath, |
michael@0 | 814 | const Pattern &aPattern, |
michael@0 | 815 | const DrawOptions &aOptions = DrawOptions()) = 0; |
michael@0 | 816 | |
michael@0 | 817 | /* |
michael@0 | 818 | * Fill a series of clyphs on the draw target with a certain source pattern. |
michael@0 | 819 | */ |
michael@0 | 820 | virtual void FillGlyphs(ScaledFont *aFont, |
michael@0 | 821 | const GlyphBuffer &aBuffer, |
michael@0 | 822 | const Pattern &aPattern, |
michael@0 | 823 | const DrawOptions &aOptions = DrawOptions(), |
michael@0 | 824 | const GlyphRenderingOptions *aRenderingOptions = nullptr) = 0; |
michael@0 | 825 | |
michael@0 | 826 | /* |
michael@0 | 827 | * This takes a source pattern and a mask, and composites the source pattern |
michael@0 | 828 | * onto the destination surface using the alpha channel of the mask pattern |
michael@0 | 829 | * as a mask for the operation. |
michael@0 | 830 | * |
michael@0 | 831 | * aSource Source pattern |
michael@0 | 832 | * aMask Mask pattern |
michael@0 | 833 | * aOptions Drawing options |
michael@0 | 834 | */ |
michael@0 | 835 | virtual void Mask(const Pattern &aSource, |
michael@0 | 836 | const Pattern &aMask, |
michael@0 | 837 | const DrawOptions &aOptions = DrawOptions()) = 0; |
michael@0 | 838 | |
michael@0 | 839 | /* |
michael@0 | 840 | * This takes a source pattern and a mask, and composites the source pattern |
michael@0 | 841 | * onto the destination surface using the alpha channel of the mask source. |
michael@0 | 842 | * The operation is bound by the extents of the mask. |
michael@0 | 843 | * |
michael@0 | 844 | * aSource Source pattern |
michael@0 | 845 | * aMask Mask surface |
michael@0 | 846 | * aOffset a transformed offset that the surface is masked at |
michael@0 | 847 | * aOptions Drawing options |
michael@0 | 848 | */ |
michael@0 | 849 | virtual void MaskSurface(const Pattern &aSource, |
michael@0 | 850 | SourceSurface *aMask, |
michael@0 | 851 | Point aOffset, |
michael@0 | 852 | const DrawOptions &aOptions = DrawOptions()) = 0; |
michael@0 | 853 | |
michael@0 | 854 | /* |
michael@0 | 855 | * Push a clip to the DrawTarget. |
michael@0 | 856 | * |
michael@0 | 857 | * aPath The path to clip to |
michael@0 | 858 | */ |
michael@0 | 859 | virtual void PushClip(const Path *aPath) = 0; |
michael@0 | 860 | |
michael@0 | 861 | /* |
michael@0 | 862 | * Push an axis-aligned rectangular clip to the DrawTarget. This rectangle |
michael@0 | 863 | * is specified in user space. |
michael@0 | 864 | * |
michael@0 | 865 | * aRect The rect to clip to |
michael@0 | 866 | */ |
michael@0 | 867 | virtual void PushClipRect(const Rect &aRect) = 0; |
michael@0 | 868 | |
michael@0 | 869 | /* Pop a clip from the DrawTarget. A pop without a corresponding push will |
michael@0 | 870 | * be ignored. |
michael@0 | 871 | */ |
michael@0 | 872 | virtual void PopClip() = 0; |
michael@0 | 873 | |
michael@0 | 874 | /* |
michael@0 | 875 | * Create a SourceSurface optimized for use with this DrawTarget from |
michael@0 | 876 | * existing bitmap data in memory. |
michael@0 | 877 | * |
michael@0 | 878 | * The SourceSurface does not take ownership of aData, and may be freed at any time. |
michael@0 | 879 | */ |
michael@0 | 880 | virtual TemporaryRef<SourceSurface> CreateSourceSurfaceFromData(unsigned char *aData, |
michael@0 | 881 | const IntSize &aSize, |
michael@0 | 882 | int32_t aStride, |
michael@0 | 883 | SurfaceFormat aFormat) const = 0; |
michael@0 | 884 | |
michael@0 | 885 | /* |
michael@0 | 886 | * Create a SourceSurface optimized for use with this DrawTarget from an |
michael@0 | 887 | * arbitrary SourceSurface type supported by this backend. This may return |
michael@0 | 888 | * aSourceSurface or some other existing surface. |
michael@0 | 889 | */ |
michael@0 | 890 | virtual TemporaryRef<SourceSurface> OptimizeSourceSurface(SourceSurface *aSurface) const = 0; |
michael@0 | 891 | |
michael@0 | 892 | /* |
michael@0 | 893 | * Create a SourceSurface for a type of NativeSurface. This may fail if the |
michael@0 | 894 | * draw target does not know how to deal with the type of NativeSurface passed |
michael@0 | 895 | * in. |
michael@0 | 896 | */ |
michael@0 | 897 | virtual TemporaryRef<SourceSurface> |
michael@0 | 898 | CreateSourceSurfaceFromNativeSurface(const NativeSurface &aSurface) const = 0; |
michael@0 | 899 | |
michael@0 | 900 | /* |
michael@0 | 901 | * Create a DrawTarget whose snapshot is optimized for use with this DrawTarget. |
michael@0 | 902 | */ |
michael@0 | 903 | virtual TemporaryRef<DrawTarget> |
michael@0 | 904 | CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const = 0; |
michael@0 | 905 | |
michael@0 | 906 | /* |
michael@0 | 907 | * Create a draw target optimized for drawing a shadow. |
michael@0 | 908 | * |
michael@0 | 909 | * Note that aSigma is the blur radius that must be used when we draw the |
michael@0 | 910 | * shadow. Also note that this doesn't affect the size of the allocated |
michael@0 | 911 | * surface, the caller is still responsible for including the shadow area in |
michael@0 | 912 | * its size. |
michael@0 | 913 | */ |
michael@0 | 914 | virtual TemporaryRef<DrawTarget> |
michael@0 | 915 | CreateShadowDrawTarget(const IntSize &aSize, SurfaceFormat aFormat, |
michael@0 | 916 | float aSigma) const |
michael@0 | 917 | { |
michael@0 | 918 | return CreateSimilarDrawTarget(aSize, aFormat); |
michael@0 | 919 | } |
michael@0 | 920 | |
michael@0 | 921 | /* |
michael@0 | 922 | * Create a path builder with the specified fillmode. |
michael@0 | 923 | * |
michael@0 | 924 | * We need the fill mode up front because of Direct2D. |
michael@0 | 925 | * ID2D1SimplifiedGeometrySink requires the fill mode |
michael@0 | 926 | * to be set before calling BeginFigure(). |
michael@0 | 927 | */ |
michael@0 | 928 | virtual TemporaryRef<PathBuilder> CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const = 0; |
michael@0 | 929 | |
michael@0 | 930 | /* |
michael@0 | 931 | * Create a GradientStops object that holds information about a set of |
michael@0 | 932 | * gradient stops, this object is required for linear or radial gradient |
michael@0 | 933 | * patterns to represent the color stops in the gradient. |
michael@0 | 934 | * |
michael@0 | 935 | * aStops An array of gradient stops |
michael@0 | 936 | * aNumStops Number of stops in the array aStops |
michael@0 | 937 | * aExtendNone This describes how to extend the stop color outside of the |
michael@0 | 938 | * gradient area. |
michael@0 | 939 | */ |
michael@0 | 940 | virtual TemporaryRef<GradientStops> |
michael@0 | 941 | CreateGradientStops(GradientStop *aStops, |
michael@0 | 942 | uint32_t aNumStops, |
michael@0 | 943 | ExtendMode aExtendMode = ExtendMode::CLAMP) const = 0; |
michael@0 | 944 | |
michael@0 | 945 | /* |
michael@0 | 946 | * Create a FilterNode object that can be used to apply a filter to various |
michael@0 | 947 | * inputs. |
michael@0 | 948 | * |
michael@0 | 949 | * aType Type of filter node to be created. |
michael@0 | 950 | */ |
michael@0 | 951 | virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType) = 0; |
michael@0 | 952 | |
michael@0 | 953 | const Matrix &GetTransform() const { return mTransform; } |
michael@0 | 954 | |
michael@0 | 955 | /* |
michael@0 | 956 | * Set a transform on the surface, this transform is applied at drawing time |
michael@0 | 957 | * to both the mask and source of the operation. |
michael@0 | 958 | */ |
michael@0 | 959 | virtual void SetTransform(const Matrix &aTransform) |
michael@0 | 960 | { mTransform = aTransform; mTransformDirty = true; } |
michael@0 | 961 | |
michael@0 | 962 | SurfaceFormat GetFormat() { return mFormat; } |
michael@0 | 963 | |
michael@0 | 964 | /* Tries to get a native surface for a DrawTarget, this may fail if the |
michael@0 | 965 | * draw target cannot convert to this surface type. |
michael@0 | 966 | */ |
michael@0 | 967 | virtual void *GetNativeSurface(NativeSurfaceType aType) { return nullptr; } |
michael@0 | 968 | |
michael@0 | 969 | virtual bool IsDualDrawTarget() { return false; } |
michael@0 | 970 | |
michael@0 | 971 | void AddUserData(UserDataKey *key, void *userData, void (*destroy)(void*)) { |
michael@0 | 972 | mUserData.Add(key, userData, destroy); |
michael@0 | 973 | } |
michael@0 | 974 | void *GetUserData(UserDataKey *key) { |
michael@0 | 975 | return mUserData.Get(key); |
michael@0 | 976 | } |
michael@0 | 977 | |
michael@0 | 978 | /* Within this rectangle all pixels will be opaque by the time the result of |
michael@0 | 979 | * this DrawTarget is first used for drawing. Either by the underlying surface |
michael@0 | 980 | * being used as an input to external drawing, or Snapshot() being called. |
michael@0 | 981 | * This rectangle is specified in device space. |
michael@0 | 982 | */ |
michael@0 | 983 | void SetOpaqueRect(const IntRect &aRect) { |
michael@0 | 984 | mOpaqueRect = aRect; |
michael@0 | 985 | } |
michael@0 | 986 | |
michael@0 | 987 | const IntRect &GetOpaqueRect() const { |
michael@0 | 988 | return mOpaqueRect; |
michael@0 | 989 | } |
michael@0 | 990 | |
michael@0 | 991 | virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA) { |
michael@0 | 992 | mPermitSubpixelAA = aPermitSubpixelAA; |
michael@0 | 993 | } |
michael@0 | 994 | |
michael@0 | 995 | bool GetPermitSubpixelAA() { |
michael@0 | 996 | return mPermitSubpixelAA; |
michael@0 | 997 | } |
michael@0 | 998 | |
michael@0 | 999 | #ifdef USE_SKIA_GPU |
michael@0 | 1000 | virtual bool InitWithGrContext(GrContext* aGrContext, |
michael@0 | 1001 | const IntSize &aSize, |
michael@0 | 1002 | SurfaceFormat aFormat) |
michael@0 | 1003 | { |
michael@0 | 1004 | MOZ_CRASH(); |
michael@0 | 1005 | } |
michael@0 | 1006 | #endif |
michael@0 | 1007 | |
michael@0 | 1008 | protected: |
michael@0 | 1009 | UserData mUserData; |
michael@0 | 1010 | Matrix mTransform; |
michael@0 | 1011 | IntRect mOpaqueRect; |
michael@0 | 1012 | bool mTransformDirty : 1; |
michael@0 | 1013 | bool mPermitSubpixelAA : 1; |
michael@0 | 1014 | |
michael@0 | 1015 | SurfaceFormat mFormat; |
michael@0 | 1016 | }; |
michael@0 | 1017 | |
michael@0 | 1018 | class DrawEventRecorder : public RefCounted<DrawEventRecorder> |
michael@0 | 1019 | { |
michael@0 | 1020 | public: |
michael@0 | 1021 | MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorder) |
michael@0 | 1022 | virtual ~DrawEventRecorder() { } |
michael@0 | 1023 | }; |
michael@0 | 1024 | |
michael@0 | 1025 | class GFX2D_API Factory |
michael@0 | 1026 | { |
michael@0 | 1027 | public: |
michael@0 | 1028 | static bool HasSSE2(); |
michael@0 | 1029 | |
michael@0 | 1030 | /* Make sure that the given dimensions don't overflow a 32-bit signed int |
michael@0 | 1031 | * using 4 bytes per pixel; optionally, make sure that either dimension |
michael@0 | 1032 | * doesn't exceed the given limit. |
michael@0 | 1033 | */ |
michael@0 | 1034 | static bool CheckSurfaceSize(const IntSize &sz, int32_t limit = 0); |
michael@0 | 1035 | |
michael@0 | 1036 | static TemporaryRef<DrawTarget> CreateDrawTargetForCairoSurface(cairo_surface_t* aSurface, const IntSize& aSize, SurfaceFormat* aFormat = nullptr); |
michael@0 | 1037 | |
michael@0 | 1038 | static TemporaryRef<DrawTarget> |
michael@0 | 1039 | CreateDrawTarget(BackendType aBackend, const IntSize &aSize, SurfaceFormat aFormat); |
michael@0 | 1040 | |
michael@0 | 1041 | static TemporaryRef<DrawTarget> |
michael@0 | 1042 | CreateRecordingDrawTarget(DrawEventRecorder *aRecorder, DrawTarget *aDT); |
michael@0 | 1043 | |
michael@0 | 1044 | static TemporaryRef<DrawTarget> |
michael@0 | 1045 | CreateDrawTargetForData(BackendType aBackend, unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat); |
michael@0 | 1046 | |
michael@0 | 1047 | static TemporaryRef<ScaledFont> |
michael@0 | 1048 | CreateScaledFontForNativeFont(const NativeFont &aNativeFont, Float aSize); |
michael@0 | 1049 | |
michael@0 | 1050 | /** |
michael@0 | 1051 | * This creates a ScaledFont from TrueType data. |
michael@0 | 1052 | * |
michael@0 | 1053 | * aData - Pointer to the data |
michael@0 | 1054 | * aSize - Size of the TrueType data |
michael@0 | 1055 | * aFaceIndex - Index of the font face in the truetype data this ScaledFont needs to represent. |
michael@0 | 1056 | * aGlyphSize - Size of the glyphs in this ScaledFont |
michael@0 | 1057 | * aType - Type of ScaledFont that should be created. |
michael@0 | 1058 | */ |
michael@0 | 1059 | static TemporaryRef<ScaledFont> |
michael@0 | 1060 | CreateScaledFontForTrueTypeData(uint8_t *aData, uint32_t aSize, uint32_t aFaceIndex, Float aGlyphSize, FontType aType); |
michael@0 | 1061 | |
michael@0 | 1062 | /* |
michael@0 | 1063 | * This creates a scaled font with an associated cairo_scaled_font_t, and |
michael@0 | 1064 | * must be used when using the Cairo backend. The NativeFont and |
michael@0 | 1065 | * cairo_scaled_font_t* parameters must correspond to the same font. |
michael@0 | 1066 | */ |
michael@0 | 1067 | static TemporaryRef<ScaledFont> |
michael@0 | 1068 | CreateScaledFontWithCairo(const NativeFont &aNativeFont, Float aSize, cairo_scaled_font_t* aScaledFont); |
michael@0 | 1069 | |
michael@0 | 1070 | /* |
michael@0 | 1071 | * This creates a simple data source surface for a certain size. It allocates |
michael@0 | 1072 | * new memory for the surface. This memory is freed when the surface is |
michael@0 | 1073 | * destroyed. |
michael@0 | 1074 | */ |
michael@0 | 1075 | static TemporaryRef<DataSourceSurface> |
michael@0 | 1076 | CreateDataSourceSurface(const IntSize &aSize, SurfaceFormat aFormat); |
michael@0 | 1077 | |
michael@0 | 1078 | /* |
michael@0 | 1079 | * This creates a simple data source surface for a certain size with a |
michael@0 | 1080 | * specific stride, which must be large enough to fit all pixels. |
michael@0 | 1081 | * It allocates new memory for the surface. This memory is freed when |
michael@0 | 1082 | * the surface is destroyed. |
michael@0 | 1083 | */ |
michael@0 | 1084 | static TemporaryRef<DataSourceSurface> |
michael@0 | 1085 | CreateDataSourceSurfaceWithStride(const IntSize &aSize, SurfaceFormat aFormat, int32_t aStride); |
michael@0 | 1086 | |
michael@0 | 1087 | /* |
michael@0 | 1088 | * This creates a simple data source surface for some existing data. It will |
michael@0 | 1089 | * wrap this data and the data for this source surface. The caller is |
michael@0 | 1090 | * responsible for deallocating the memory only after destruction of the |
michael@0 | 1091 | * surface. |
michael@0 | 1092 | */ |
michael@0 | 1093 | static TemporaryRef<DataSourceSurface> |
michael@0 | 1094 | CreateWrappingDataSourceSurface(uint8_t *aData, int32_t aStride, |
michael@0 | 1095 | const IntSize &aSize, SurfaceFormat aFormat); |
michael@0 | 1096 | |
michael@0 | 1097 | static TemporaryRef<DrawEventRecorder> |
michael@0 | 1098 | CreateEventRecorderForFile(const char *aFilename); |
michael@0 | 1099 | |
michael@0 | 1100 | static void SetGlobalEventRecorder(DrawEventRecorder *aRecorder); |
michael@0 | 1101 | |
michael@0 | 1102 | #ifdef USE_SKIA_GPU |
michael@0 | 1103 | static TemporaryRef<DrawTarget> |
michael@0 | 1104 | CreateDrawTargetSkiaWithGrContext(GrContext* aGrContext, |
michael@0 | 1105 | const IntSize &aSize, |
michael@0 | 1106 | SurfaceFormat aFormat); |
michael@0 | 1107 | #endif |
michael@0 | 1108 | |
michael@0 | 1109 | static void PurgeAllCaches(); |
michael@0 | 1110 | |
michael@0 | 1111 | #if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE) |
michael@0 | 1112 | static TemporaryRef<GlyphRenderingOptions> |
michael@0 | 1113 | CreateCairoGlyphRenderingOptions(FontHinting aHinting, bool aAutoHinting); |
michael@0 | 1114 | #endif |
michael@0 | 1115 | static TemporaryRef<DrawTarget> |
michael@0 | 1116 | CreateDualDrawTarget(DrawTarget *targetA, DrawTarget *targetB); |
michael@0 | 1117 | |
michael@0 | 1118 | #ifdef XP_MACOSX |
michael@0 | 1119 | static TemporaryRef<DrawTarget> CreateDrawTargetForCairoCGContext(CGContextRef cg, const IntSize& aSize); |
michael@0 | 1120 | #endif |
michael@0 | 1121 | |
michael@0 | 1122 | #ifdef WIN32 |
michael@0 | 1123 | static TemporaryRef<DrawTarget> CreateDrawTargetForD3D10Texture(ID3D10Texture2D *aTexture, SurfaceFormat aFormat); |
michael@0 | 1124 | static TemporaryRef<DrawTarget> |
michael@0 | 1125 | CreateDualDrawTargetForD3D10Textures(ID3D10Texture2D *aTextureA, |
michael@0 | 1126 | ID3D10Texture2D *aTextureB, |
michael@0 | 1127 | SurfaceFormat aFormat); |
michael@0 | 1128 | |
michael@0 | 1129 | static void SetDirect3D10Device(ID3D10Device1 *aDevice); |
michael@0 | 1130 | static ID3D10Device1 *GetDirect3D10Device(); |
michael@0 | 1131 | #ifdef USE_D2D1_1 |
michael@0 | 1132 | static void SetDirect3D11Device(ID3D11Device *aDevice); |
michael@0 | 1133 | static ID3D11Device *GetDirect3D11Device(); |
michael@0 | 1134 | static ID2D1Device *GetD2D1Device(); |
michael@0 | 1135 | #endif |
michael@0 | 1136 | |
michael@0 | 1137 | static TemporaryRef<GlyphRenderingOptions> |
michael@0 | 1138 | CreateDWriteGlyphRenderingOptions(IDWriteRenderingParams *aParams); |
michael@0 | 1139 | |
michael@0 | 1140 | static uint64_t GetD2DVRAMUsageDrawTarget(); |
michael@0 | 1141 | static uint64_t GetD2DVRAMUsageSourceSurface(); |
michael@0 | 1142 | static void D2DCleanup(); |
michael@0 | 1143 | |
michael@0 | 1144 | private: |
michael@0 | 1145 | static ID3D10Device1 *mD3D10Device; |
michael@0 | 1146 | #ifdef USE_D2D1_1 |
michael@0 | 1147 | static ID3D11Device *mD3D11Device; |
michael@0 | 1148 | static ID2D1Device *mD2D1Device; |
michael@0 | 1149 | #endif |
michael@0 | 1150 | #endif |
michael@0 | 1151 | |
michael@0 | 1152 | static DrawEventRecorder *mRecorder; |
michael@0 | 1153 | }; |
michael@0 | 1154 | |
michael@0 | 1155 | } |
michael@0 | 1156 | } |
michael@0 | 1157 | |
michael@0 | 1158 | #endif // _MOZILLA_GFX_2D_H |