gfx/2d/FilterNodeSoftware.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_FILTERNODESOFTWARE_H_
michael@0 7 #define _MOZILLA_GFX_FILTERNODESOFTWARE_H_
michael@0 8
michael@0 9 #include "Filters.h"
michael@0 10 #include <vector>
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13 namespace gfx {
michael@0 14
michael@0 15 class DataSourceSurface;
michael@0 16 class DrawTarget;
michael@0 17 struct DrawOptions;
michael@0 18 class FilterNodeSoftware;
michael@0 19
michael@0 20 /**
michael@0 21 * Can be attached to FilterNodeSoftware instances using
michael@0 22 * AddInvalidationListener. FilterInvalidated is called whenever the output of
michael@0 23 * the observed filter may have changed; that is, whenever cached GetOutput()
michael@0 24 * results (and results derived from them) need to discarded.
michael@0 25 */
michael@0 26 class FilterInvalidationListener
michael@0 27 {
michael@0 28 public:
michael@0 29 virtual void FilterInvalidated(FilterNodeSoftware* aFilter) = 0;
michael@0 30 };
michael@0 31
michael@0 32 /**
michael@0 33 * This is the base class for the software (i.e. pure CPU, non-accelerated)
michael@0 34 * FilterNode implementation. The software implementation is backend-agnostic,
michael@0 35 * so it can be used as a fallback for all DrawTarget implementations.
michael@0 36 */
michael@0 37 class FilterNodeSoftware : public FilterNode,
michael@0 38 public FilterInvalidationListener
michael@0 39 {
michael@0 40 public:
michael@0 41 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeSoftware)
michael@0 42 virtual ~FilterNodeSoftware();
michael@0 43
michael@0 44 // Factory method, intended to be called from DrawTarget*::CreateFilter.
michael@0 45 static TemporaryRef<FilterNode> Create(FilterType aType);
michael@0 46
michael@0 47 // Draw the filter, intended to be called by DrawTarget*::DrawFilter.
michael@0 48 void Draw(DrawTarget* aDrawTarget, const Rect &aSourceRect,
michael@0 49 const Point &aDestPoint, const DrawOptions &aOptions);
michael@0 50
michael@0 51 virtual FilterBackend GetBackendType() MOZ_OVERRIDE { return FILTER_BACKEND_SOFTWARE; }
michael@0 52 virtual void SetInput(uint32_t aIndex, SourceSurface *aSurface) MOZ_OVERRIDE;
michael@0 53 virtual void SetInput(uint32_t aIndex, FilterNode *aFilter) MOZ_OVERRIDE;
michael@0 54
michael@0 55 virtual const char* GetName() { return "Unknown"; }
michael@0 56
michael@0 57 virtual void AddInvalidationListener(FilterInvalidationListener* aListener);
michael@0 58 virtual void RemoveInvalidationListener(FilterInvalidationListener* aListener);
michael@0 59
michael@0 60 // FilterInvalidationListener implementation
michael@0 61 virtual void FilterInvalidated(FilterNodeSoftware* aFilter);
michael@0 62
michael@0 63 protected:
michael@0 64
michael@0 65 // The following methods are intended to be overriden by subclasses.
michael@0 66
michael@0 67 /**
michael@0 68 * Translates a *FilterInputs enum value into an index for the
michael@0 69 * mInputFilters / mInputSurfaces arrays. Returns -1 for invalid inputs.
michael@0 70 * If somebody calls SetInput(enumValue, input) with an enumValue for which
michael@0 71 * InputIndex(enumValue) is -1, we abort.
michael@0 72 */
michael@0 73 virtual int32_t InputIndex(uint32_t aInputEnumIndex) { return -1; }
michael@0 74
michael@0 75 /**
michael@0 76 * Every filter node has an output rect, which can also be infinite. The
michael@0 77 * output rect can depend on the values of any set attributes and on the
michael@0 78 * output rects of any input filters or surfaces.
michael@0 79 * This method returns the intersection of the filter's output rect with
michael@0 80 * aInRect. Filters with unconstrained output always return aInRect.
michael@0 81 */
michael@0 82 virtual IntRect GetOutputRectInRect(const IntRect& aInRect) = 0;
michael@0 83
michael@0 84 /**
michael@0 85 * Return a surface with the rendered output which is of size aRect.Size().
michael@0 86 * aRect is required to be a subrect of this filter's output rect; in other
michael@0 87 * words, aRect == GetOutputRectInRect(aRect) must always be true.
michael@0 88 * May return nullptr in error conditions or for an empty aRect.
michael@0 89 * Implementations are not required to allocate a new surface and may even
michael@0 90 * pass through input surfaces unchanged.
michael@0 91 * Callers need to treat the returned surface as immutable.
michael@0 92 */
michael@0 93 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) = 0;
michael@0 94
michael@0 95 /**
michael@0 96 * Call RequestRect (see below) on any input filters with the desired input
michael@0 97 * rect, so that the input filter knows what to cache the next time it
michael@0 98 * renders.
michael@0 99 */
michael@0 100 virtual void RequestFromInputsForRect(const IntRect &aRect) {}
michael@0 101
michael@0 102 /**
michael@0 103 * This method provides a caching default implementation but can be overriden
michael@0 104 * by subclasses that don't want to cache their output. Those classes should
michael@0 105 * call Render(aRect) directly from here.
michael@0 106 */
michael@0 107 virtual TemporaryRef<DataSourceSurface> GetOutput(const IntRect &aRect);
michael@0 108
michael@0 109 // The following methods are non-virtual helper methods.
michael@0 110
michael@0 111 /**
michael@0 112 * Format hints for GetInputDataSourceSurface. Some callers of
michael@0 113 * GetInputDataSourceSurface can handle both B8G8R8A8 and A8 surfaces, these
michael@0 114 * should pass CAN_HANDLE_A8 in order to avoid unnecessary conversions.
michael@0 115 * Callers that can only handle B8G8R8A8 surfaces pass NEED_COLOR_CHANNELS.
michael@0 116 */
michael@0 117 enum FormatHint {
michael@0 118 CAN_HANDLE_A8,
michael@0 119 NEED_COLOR_CHANNELS
michael@0 120 };
michael@0 121
michael@0 122 /**
michael@0 123 * Returns SurfaceFormat::B8G8R8A8 or SurfaceFormat::A8, depending on the current surface
michael@0 124 * format and the format hint.
michael@0 125 */
michael@0 126 SurfaceFormat DesiredFormat(SurfaceFormat aCurrentFormat,
michael@0 127 FormatHint aFormatHint);
michael@0 128
michael@0 129 /**
michael@0 130 * Intended to be called by FilterNodeSoftware::Render implementations.
michael@0 131 * Returns a surface of size aRect.Size() or nullptr in error conditions. The
michael@0 132 * returned surface contains the output of the specified input filter or
michael@0 133 * input surface in aRect. If aRect extends beyond the input filter's output
michael@0 134 * rect (or the input surface's dimensions), the remaining area is filled
michael@0 135 * according to aEdgeMode: The default, EDGE_MODE_NONE, simply pads with
michael@0 136 * transparent black.
michael@0 137 * If non-null, the returned surface is guaranteed to be of SurfaceFormat::A8 or
michael@0 138 * SurfaceFormat::B8G8R8A8. If aFormatHint is NEED_COLOR_CHANNELS, the returned
michael@0 139 * surface is guaranteed to be of SurfaceFormat::B8G8R8A8 always.
michael@0 140 * Each pixel row of the returned surface is guaranteed to be 16-byte aligned.
michael@0 141 */
michael@0 142 TemporaryRef<DataSourceSurface>
michael@0 143 GetInputDataSourceSurface(uint32_t aInputEnumIndex, const IntRect& aRect,
michael@0 144 FormatHint aFormatHint = CAN_HANDLE_A8,
michael@0 145 ConvolveMatrixEdgeMode aEdgeMode = EDGE_MODE_NONE,
michael@0 146 const IntRect *aTransparencyPaddedSourceRect = nullptr);
michael@0 147
michael@0 148 /**
michael@0 149 * Returns the intersection of the input filter's or surface's output rect
michael@0 150 * with aInRect.
michael@0 151 */
michael@0 152 IntRect GetInputRectInRect(uint32_t aInputEnumIndex, const IntRect& aInRect);
michael@0 153
michael@0 154 /**
michael@0 155 * Calls RequestRect on the specified input, if it's a filter.
michael@0 156 */
michael@0 157 void RequestInputRect(uint32_t aInputEnumIndex, const IntRect& aRect);
michael@0 158
michael@0 159 /**
michael@0 160 * Returns the number of set input filters or surfaces. Needed for filters
michael@0 161 * which can have an arbitrary number of inputs.
michael@0 162 */
michael@0 163 size_t NumberOfSetInputs();
michael@0 164
michael@0 165 /**
michael@0 166 * Discard the cached surface that was stored in the GetOutput default
michael@0 167 * implementation. Needs to be called whenever attributes or inputs are set
michael@0 168 * that might change the result of a Render() call.
michael@0 169 */
michael@0 170 void Invalidate();
michael@0 171
michael@0 172 /**
michael@0 173 * Called in order to let this filter know what to cache during the next
michael@0 174 * GetOutput call. Expected to call RequestRect on this filter's input
michael@0 175 * filters.
michael@0 176 */
michael@0 177 void RequestRect(const IntRect &aRect);
michael@0 178
michael@0 179 /**
michael@0 180 * Set input filter and clear input surface for this input index, or set
michael@0 181 * input surface and clear input filter. One of aSurface and aFilter should
michael@0 182 * be null.
michael@0 183 */
michael@0 184 void SetInput(uint32_t aIndex, SourceSurface *aSurface,
michael@0 185 FilterNodeSoftware *aFilter);
michael@0 186
michael@0 187 protected:
michael@0 188 /**
michael@0 189 * mInputSurfaces / mInputFilters: For each input index, either a surface or
michael@0 190 * a filter is set, and the other is null.
michael@0 191 */
michael@0 192 std::vector<RefPtr<SourceSurface> > mInputSurfaces;
michael@0 193 std::vector<RefPtr<FilterNodeSoftware> > mInputFilters;
michael@0 194
michael@0 195 /**
michael@0 196 * Weak pointers to our invalidation listeners, i.e. to those filters who
michael@0 197 * have this filter as an input. Invalidation listeners are required to
michael@0 198 * unsubscribe themselves from us when they let go of their reference to us.
michael@0 199 * This ensures that the pointers in this array are never stale.
michael@0 200 */
michael@0 201 std::vector<FilterInvalidationListener*> mInvalidationListeners;
michael@0 202
michael@0 203 /**
michael@0 204 * Stores the rect which we want to render and cache on the next call to
michael@0 205 * GetOutput.
michael@0 206 */
michael@0 207 IntRect mRequestedRect;
michael@0 208
michael@0 209 /**
michael@0 210 * Stores our cached output.
michael@0 211 */
michael@0 212 IntRect mCachedRect;
michael@0 213 RefPtr<DataSourceSurface> mCachedOutput;
michael@0 214 };
michael@0 215
michael@0 216 // Subclasses for specific filters.
michael@0 217
michael@0 218 class FilterNodeTransformSoftware : public FilterNodeSoftware
michael@0 219 {
michael@0 220 public:
michael@0 221 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTransformSoftware)
michael@0 222 FilterNodeTransformSoftware();
michael@0 223 virtual const char* GetName() MOZ_OVERRIDE { return "Transform"; }
michael@0 224 using FilterNodeSoftware::SetAttribute;
michael@0 225 virtual void SetAttribute(uint32_t aIndex, uint32_t aGraphicsFilter) MOZ_OVERRIDE;
michael@0 226 virtual void SetAttribute(uint32_t aIndex, const Matrix &aMatrix) MOZ_OVERRIDE;
michael@0 227
michael@0 228 protected:
michael@0 229 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 230 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 231 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 232 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 233 IntRect SourceRectForOutputRect(const IntRect &aRect);
michael@0 234
michael@0 235 private:
michael@0 236 Matrix mMatrix;
michael@0 237 Filter mFilter;
michael@0 238 };
michael@0 239
michael@0 240 class FilterNodeBlendSoftware : public FilterNodeSoftware
michael@0 241 {
michael@0 242 public:
michael@0 243 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlendSoftware)
michael@0 244 FilterNodeBlendSoftware();
michael@0 245 virtual const char* GetName() MOZ_OVERRIDE { return "Blend"; }
michael@0 246 using FilterNodeSoftware::SetAttribute;
michael@0 247 virtual void SetAttribute(uint32_t aIndex, uint32_t aBlendMode) MOZ_OVERRIDE;
michael@0 248
michael@0 249 protected:
michael@0 250 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 251 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 252 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 253 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 254
michael@0 255 private:
michael@0 256 BlendMode mBlendMode;
michael@0 257 };
michael@0 258
michael@0 259 class FilterNodeMorphologySoftware : public FilterNodeSoftware
michael@0 260 {
michael@0 261 public:
michael@0 262 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeMorphologySoftware)
michael@0 263 FilterNodeMorphologySoftware();
michael@0 264 virtual const char* GetName() MOZ_OVERRIDE { return "Morphology"; }
michael@0 265 using FilterNodeSoftware::SetAttribute;
michael@0 266 virtual void SetAttribute(uint32_t aIndex, const IntSize &aRadii) MOZ_OVERRIDE;
michael@0 267 virtual void SetAttribute(uint32_t aIndex, uint32_t aOperator) MOZ_OVERRIDE;
michael@0 268
michael@0 269 protected:
michael@0 270 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 271 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 272 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 273 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 274
michael@0 275 private:
michael@0 276 IntSize mRadii;
michael@0 277 MorphologyOperator mOperator;
michael@0 278 };
michael@0 279
michael@0 280 class FilterNodeColorMatrixSoftware : public FilterNodeSoftware
michael@0 281 {
michael@0 282 public:
michael@0 283 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeColorMatrixSoftware)
michael@0 284 virtual const char* GetName() MOZ_OVERRIDE { return "ColorMatrix"; }
michael@0 285 using FilterNodeSoftware::SetAttribute;
michael@0 286 virtual void SetAttribute(uint32_t aIndex, const Matrix5x4 &aMatrix) MOZ_OVERRIDE;
michael@0 287 virtual void SetAttribute(uint32_t aIndex, uint32_t aAlphaMode) MOZ_OVERRIDE;
michael@0 288
michael@0 289 protected:
michael@0 290 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 291 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 292 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 293 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 294
michael@0 295 private:
michael@0 296 Matrix5x4 mMatrix;
michael@0 297 AlphaMode mAlphaMode;
michael@0 298 };
michael@0 299
michael@0 300 class FilterNodeFloodSoftware : public FilterNodeSoftware
michael@0 301 {
michael@0 302 public:
michael@0 303 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeFloodSoftware)
michael@0 304 virtual const char* GetName() MOZ_OVERRIDE { return "Flood"; }
michael@0 305 using FilterNodeSoftware::SetAttribute;
michael@0 306 virtual void SetAttribute(uint32_t aIndex, const Color &aColor) MOZ_OVERRIDE;
michael@0 307
michael@0 308 protected:
michael@0 309 virtual TemporaryRef<DataSourceSurface> GetOutput(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 310 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 311 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 312
michael@0 313 private:
michael@0 314 Color mColor;
michael@0 315 };
michael@0 316
michael@0 317 class FilterNodeTileSoftware : public FilterNodeSoftware
michael@0 318 {
michael@0 319 public:
michael@0 320 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTileSoftware)
michael@0 321 virtual const char* GetName() MOZ_OVERRIDE { return "Tile"; }
michael@0 322 using FilterNodeSoftware::SetAttribute;
michael@0 323 virtual void SetAttribute(uint32_t aIndex, const IntRect &aSourceRect) MOZ_OVERRIDE;
michael@0 324
michael@0 325 protected:
michael@0 326 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 327 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 328 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 329 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 330
michael@0 331 private:
michael@0 332 IntRect mSourceRect;
michael@0 333 };
michael@0 334
michael@0 335 /**
michael@0 336 * Baseclass for the four different component transfer filters.
michael@0 337 */
michael@0 338 class FilterNodeComponentTransferSoftware : public FilterNodeSoftware
michael@0 339 {
michael@0 340 public:
michael@0 341 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeComponentTransferSoftware)
michael@0 342 FilterNodeComponentTransferSoftware();
michael@0 343
michael@0 344 using FilterNodeSoftware::SetAttribute;
michael@0 345 virtual void SetAttribute(uint32_t aIndex, bool aDisable) MOZ_OVERRIDE;
michael@0 346
michael@0 347 protected:
michael@0 348 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 349 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 350 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 351 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 352 virtual void GenerateLookupTable(ptrdiff_t aComponent, uint8_t aTables[4][256],
michael@0 353 bool aDisabled);
michael@0 354 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) = 0;
michael@0 355
michael@0 356 bool mDisableR;
michael@0 357 bool mDisableG;
michael@0 358 bool mDisableB;
michael@0 359 bool mDisableA;
michael@0 360 };
michael@0 361
michael@0 362 class FilterNodeTableTransferSoftware : public FilterNodeComponentTransferSoftware
michael@0 363 {
michael@0 364 public:
michael@0 365 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTableTransferSoftware)
michael@0 366 virtual const char* GetName() MOZ_OVERRIDE { return "TableTransfer"; }
michael@0 367 using FilterNodeComponentTransferSoftware::SetAttribute;
michael@0 368 virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) MOZ_OVERRIDE;
michael@0 369
michael@0 370 protected:
michael@0 371 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE;
michael@0 372
michael@0 373 private:
michael@0 374 void FillLookupTableImpl(std::vector<Float>& aTableValues, uint8_t aTable[256]);
michael@0 375
michael@0 376 std::vector<Float> mTableR;
michael@0 377 std::vector<Float> mTableG;
michael@0 378 std::vector<Float> mTableB;
michael@0 379 std::vector<Float> mTableA;
michael@0 380 };
michael@0 381
michael@0 382 class FilterNodeDiscreteTransferSoftware : public FilterNodeComponentTransferSoftware
michael@0 383 {
michael@0 384 public:
michael@0 385 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDiscreteTransferSoftware)
michael@0 386 virtual const char* GetName() MOZ_OVERRIDE { return "DiscreteTransfer"; }
michael@0 387 using FilterNodeComponentTransferSoftware::SetAttribute;
michael@0 388 virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) MOZ_OVERRIDE;
michael@0 389
michael@0 390 protected:
michael@0 391 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE;
michael@0 392
michael@0 393 private:
michael@0 394 void FillLookupTableImpl(std::vector<Float>& aTableValues, uint8_t aTable[256]);
michael@0 395
michael@0 396 std::vector<Float> mTableR;
michael@0 397 std::vector<Float> mTableG;
michael@0 398 std::vector<Float> mTableB;
michael@0 399 std::vector<Float> mTableA;
michael@0 400 };
michael@0 401
michael@0 402 class FilterNodeLinearTransferSoftware : public FilterNodeComponentTransferSoftware
michael@0 403 {
michael@0 404 public:
michael@0 405 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeLinearTransformSoftware)
michael@0 406 FilterNodeLinearTransferSoftware();
michael@0 407 virtual const char* GetName() MOZ_OVERRIDE { return "LinearTransfer"; }
michael@0 408 using FilterNodeComponentTransferSoftware::SetAttribute;
michael@0 409 virtual void SetAttribute(uint32_t aIndex, Float aValue) MOZ_OVERRIDE;
michael@0 410
michael@0 411 protected:
michael@0 412 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE;
michael@0 413
michael@0 414 private:
michael@0 415 void FillLookupTableImpl(Float aSlope, Float aIntercept, uint8_t aTable[256]);
michael@0 416
michael@0 417 Float mSlopeR;
michael@0 418 Float mSlopeG;
michael@0 419 Float mSlopeB;
michael@0 420 Float mSlopeA;
michael@0 421 Float mInterceptR;
michael@0 422 Float mInterceptG;
michael@0 423 Float mInterceptB;
michael@0 424 Float mInterceptA;
michael@0 425 };
michael@0 426
michael@0 427 class FilterNodeGammaTransferSoftware : public FilterNodeComponentTransferSoftware
michael@0 428 {
michael@0 429 public:
michael@0 430 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGammaTransferSoftware)
michael@0 431 FilterNodeGammaTransferSoftware();
michael@0 432 virtual const char* GetName() MOZ_OVERRIDE { return "GammaTransfer"; }
michael@0 433 using FilterNodeComponentTransferSoftware::SetAttribute;
michael@0 434 virtual void SetAttribute(uint32_t aIndex, Float aValue) MOZ_OVERRIDE;
michael@0 435
michael@0 436 protected:
michael@0 437 virtual void FillLookupTable(ptrdiff_t aComponent, uint8_t aTable[256]) MOZ_OVERRIDE;
michael@0 438
michael@0 439 private:
michael@0 440 void FillLookupTableImpl(Float aAmplitude, Float aExponent, Float aOffset, uint8_t aTable[256]);
michael@0 441
michael@0 442 Float mAmplitudeR;
michael@0 443 Float mAmplitudeG;
michael@0 444 Float mAmplitudeB;
michael@0 445 Float mAmplitudeA;
michael@0 446 Float mExponentR;
michael@0 447 Float mExponentG;
michael@0 448 Float mExponentB;
michael@0 449 Float mExponentA;
michael@0 450 Float mOffsetR;
michael@0 451 Float mOffsetG;
michael@0 452 Float mOffsetB;
michael@0 453 Float mOffsetA;
michael@0 454 };
michael@0 455
michael@0 456 class FilterNodeConvolveMatrixSoftware : public FilterNodeSoftware
michael@0 457 {
michael@0 458 public:
michael@0 459 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeConvolveMatrixSoftware)
michael@0 460 FilterNodeConvolveMatrixSoftware();
michael@0 461 virtual const char* GetName() MOZ_OVERRIDE { return "ConvolveMatrix"; }
michael@0 462 using FilterNodeSoftware::SetAttribute;
michael@0 463 virtual void SetAttribute(uint32_t aIndex, const IntSize &aKernelSize) MOZ_OVERRIDE;
michael@0 464 virtual void SetAttribute(uint32_t aIndex, const Float* aMatrix, uint32_t aSize) MOZ_OVERRIDE;
michael@0 465 virtual void SetAttribute(uint32_t aIndex, Float aValue) MOZ_OVERRIDE;
michael@0 466 virtual void SetAttribute(uint32_t aIndex, const Size &aKernelUnitLength) MOZ_OVERRIDE;
michael@0 467 virtual void SetAttribute(uint32_t aIndex, const IntRect &aSourceRect) MOZ_OVERRIDE;
michael@0 468 virtual void SetAttribute(uint32_t aIndex, const IntPoint &aTarget) MOZ_OVERRIDE;
michael@0 469 virtual void SetAttribute(uint32_t aIndex, uint32_t aEdgeMode) MOZ_OVERRIDE;
michael@0 470 virtual void SetAttribute(uint32_t aIndex, bool aPreserveAlpha) MOZ_OVERRIDE;
michael@0 471
michael@0 472 protected:
michael@0 473 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 474 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 475 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 476 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 477
michael@0 478 private:
michael@0 479 template<typename CoordType>
michael@0 480 TemporaryRef<DataSourceSurface> DoRender(const IntRect& aRect,
michael@0 481 CoordType aKernelUnitLengthX,
michael@0 482 CoordType aKernelUnitLengthY);
michael@0 483
michael@0 484 IntRect InflatedSourceRect(const IntRect &aDestRect);
michael@0 485 IntRect InflatedDestRect(const IntRect &aSourceRect);
michael@0 486
michael@0 487 IntSize mKernelSize;
michael@0 488 std::vector<Float> mKernelMatrix;
michael@0 489 Float mDivisor;
michael@0 490 Float mBias;
michael@0 491 IntPoint mTarget;
michael@0 492 IntRect mSourceRect;
michael@0 493 ConvolveMatrixEdgeMode mEdgeMode;
michael@0 494 Size mKernelUnitLength;
michael@0 495 bool mPreserveAlpha;
michael@0 496 };
michael@0 497
michael@0 498 class FilterNodeDisplacementMapSoftware : public FilterNodeSoftware
michael@0 499 {
michael@0 500 public:
michael@0 501 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDisplacementMapSoftware)
michael@0 502 FilterNodeDisplacementMapSoftware();
michael@0 503 virtual const char* GetName() MOZ_OVERRIDE { return "DisplacementMap"; }
michael@0 504 using FilterNodeSoftware::SetAttribute;
michael@0 505 virtual void SetAttribute(uint32_t aIndex, Float aScale) MOZ_OVERRIDE;
michael@0 506 virtual void SetAttribute(uint32_t aIndex, uint32_t aValue) MOZ_OVERRIDE;
michael@0 507
michael@0 508 protected:
michael@0 509 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 510 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 511 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 512 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 513
michael@0 514 private:
michael@0 515 IntRect InflatedSourceOrDestRect(const IntRect &aDestOrSourceRect);
michael@0 516
michael@0 517 Float mScale;
michael@0 518 ColorChannel mChannelX;
michael@0 519 ColorChannel mChannelY;
michael@0 520 };
michael@0 521
michael@0 522 class FilterNodeTurbulenceSoftware : public FilterNodeSoftware
michael@0 523 {
michael@0 524 public:
michael@0 525 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeTurbulenceSoftware)
michael@0 526 FilterNodeTurbulenceSoftware();
michael@0 527 virtual const char* GetName() MOZ_OVERRIDE { return "Turbulence"; }
michael@0 528 using FilterNodeSoftware::SetAttribute;
michael@0 529 virtual void SetAttribute(uint32_t aIndex, const Size &aSize) MOZ_OVERRIDE;
michael@0 530 virtual void SetAttribute(uint32_t aIndex, const IntRect &aRenderRect) MOZ_OVERRIDE;
michael@0 531 virtual void SetAttribute(uint32_t aIndex, bool aStitchable) MOZ_OVERRIDE;
michael@0 532 virtual void SetAttribute(uint32_t aIndex, uint32_t aValue) MOZ_OVERRIDE;
michael@0 533
michael@0 534 protected:
michael@0 535 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 536 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 537 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 538
michael@0 539 private:
michael@0 540 IntRect mRenderRect;
michael@0 541 Size mBaseFrequency;
michael@0 542 uint32_t mNumOctaves;
michael@0 543 uint32_t mSeed;
michael@0 544 bool mStitchable;
michael@0 545 TurbulenceType mType;
michael@0 546 };
michael@0 547
michael@0 548 class FilterNodeArithmeticCombineSoftware : public FilterNodeSoftware
michael@0 549 {
michael@0 550 public:
michael@0 551 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeArithmeticCombineSoftware)
michael@0 552 FilterNodeArithmeticCombineSoftware();
michael@0 553 virtual const char* GetName() MOZ_OVERRIDE { return "ArithmeticCombine"; }
michael@0 554 using FilterNodeSoftware::SetAttribute;
michael@0 555 virtual void SetAttribute(uint32_t aIndex, const Float* aFloat, uint32_t aSize) MOZ_OVERRIDE;
michael@0 556
michael@0 557 protected:
michael@0 558 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 559 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 560 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 561 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 562
michael@0 563 private:
michael@0 564 Float mK1;
michael@0 565 Float mK2;
michael@0 566 Float mK3;
michael@0 567 Float mK4;
michael@0 568 };
michael@0 569
michael@0 570 class FilterNodeCompositeSoftware : public FilterNodeSoftware
michael@0 571 {
michael@0 572 public:
michael@0 573 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCompositeSoftware)
michael@0 574 FilterNodeCompositeSoftware();
michael@0 575 virtual const char* GetName() MOZ_OVERRIDE { return "Composite"; }
michael@0 576 using FilterNodeSoftware::SetAttribute;
michael@0 577 virtual void SetAttribute(uint32_t aIndex, uint32_t aOperator) MOZ_OVERRIDE;
michael@0 578
michael@0 579 protected:
michael@0 580 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 581 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 582 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 583 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 584
michael@0 585 private:
michael@0 586 CompositeOperator mOperator;
michael@0 587 };
michael@0 588
michael@0 589 // Base class for FilterNodeGaussianBlurSoftware and
michael@0 590 // FilterNodeDirectionalBlurSoftware.
michael@0 591 class FilterNodeBlurXYSoftware : public FilterNodeSoftware
michael@0 592 {
michael@0 593 public:
michael@0 594 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeBlurXYSoftware)
michael@0 595 protected:
michael@0 596 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 597 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 598 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 599 IntRect InflatedSourceOrDestRect(const IntRect &aDestRect);
michael@0 600 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 601
michael@0 602 // Implemented by subclasses.
michael@0 603 virtual Size StdDeviationXY() = 0;
michael@0 604 };
michael@0 605
michael@0 606 class FilterNodeGaussianBlurSoftware : public FilterNodeBlurXYSoftware
michael@0 607 {
michael@0 608 public:
michael@0 609 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeGaussianBlurSoftware)
michael@0 610 FilterNodeGaussianBlurSoftware();
michael@0 611 virtual const char* GetName() MOZ_OVERRIDE { return "GaussianBlur"; }
michael@0 612 using FilterNodeSoftware::SetAttribute;
michael@0 613 virtual void SetAttribute(uint32_t aIndex, Float aStdDeviation) MOZ_OVERRIDE;
michael@0 614
michael@0 615 protected:
michael@0 616 virtual Size StdDeviationXY() MOZ_OVERRIDE;
michael@0 617
michael@0 618 private:
michael@0 619 Float mStdDeviation;
michael@0 620 };
michael@0 621
michael@0 622 class FilterNodeDirectionalBlurSoftware : public FilterNodeBlurXYSoftware
michael@0 623 {
michael@0 624 public:
michael@0 625 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeDirectionalBlurSoftware)
michael@0 626 FilterNodeDirectionalBlurSoftware();
michael@0 627 virtual const char* GetName() MOZ_OVERRIDE { return "DirectionalBlur"; }
michael@0 628 using FilterNodeSoftware::SetAttribute;
michael@0 629 virtual void SetAttribute(uint32_t aIndex, Float aStdDeviation) MOZ_OVERRIDE;
michael@0 630 virtual void SetAttribute(uint32_t aIndex, uint32_t aBlurDirection) MOZ_OVERRIDE;
michael@0 631
michael@0 632 protected:
michael@0 633 virtual Size StdDeviationXY() MOZ_OVERRIDE;
michael@0 634
michael@0 635 private:
michael@0 636 Float mStdDeviation;
michael@0 637 BlurDirection mBlurDirection;
michael@0 638 };
michael@0 639
michael@0 640 class FilterNodeCropSoftware : public FilterNodeSoftware
michael@0 641 {
michael@0 642 public:
michael@0 643 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeCropSoftware)
michael@0 644 virtual const char* GetName() MOZ_OVERRIDE { return "Crop"; }
michael@0 645 using FilterNodeSoftware::SetAttribute;
michael@0 646 virtual void SetAttribute(uint32_t aIndex, const Rect &aSourceRect) MOZ_OVERRIDE;
michael@0 647
michael@0 648 protected:
michael@0 649 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 650 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 651 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 652 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 653
michael@0 654 private:
michael@0 655 IntRect mCropRect;
michael@0 656 };
michael@0 657
michael@0 658 class FilterNodePremultiplySoftware : public FilterNodeSoftware
michael@0 659 {
michael@0 660 public:
michael@0 661 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodePremultiplySoftware)
michael@0 662 virtual const char* GetName() MOZ_OVERRIDE { return "Premultiply"; }
michael@0 663 protected:
michael@0 664 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 665 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 666 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 667 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 668 };
michael@0 669
michael@0 670 class FilterNodeUnpremultiplySoftware : public FilterNodeSoftware
michael@0 671 {
michael@0 672 public:
michael@0 673 MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(FilterNodeUnpremultiplySoftware)
michael@0 674 virtual const char* GetName() MOZ_OVERRIDE { return "Unpremultiply"; }
michael@0 675 protected:
michael@0 676 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 677 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 678 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 679 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 680 };
michael@0 681
michael@0 682 template<typename LightType, typename LightingType>
michael@0 683 class FilterNodeLightingSoftware : public FilterNodeSoftware
michael@0 684 {
michael@0 685 public:
michael@0 686 #if defined(MOZILLA_INTERNAL_API) && (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
michael@0 687 // Helpers for refcounted
michael@0 688 virtual const char* typeName() const MOZ_OVERRIDE { return mTypeName; }
michael@0 689 virtual size_t typeSize() const MOZ_OVERRIDE { return sizeof(*this); }
michael@0 690 #endif
michael@0 691 explicit FilterNodeLightingSoftware(const char* aTypeName);
michael@0 692 virtual const char* GetName() MOZ_OVERRIDE { return "Lighting"; }
michael@0 693 using FilterNodeSoftware::SetAttribute;
michael@0 694 virtual void SetAttribute(uint32_t aIndex, Float) MOZ_OVERRIDE;
michael@0 695 virtual void SetAttribute(uint32_t aIndex, const Size &) MOZ_OVERRIDE;
michael@0 696 virtual void SetAttribute(uint32_t aIndex, const Point3D &) MOZ_OVERRIDE;
michael@0 697 virtual void SetAttribute(uint32_t aIndex, const Color &) MOZ_OVERRIDE;
michael@0 698
michael@0 699 protected:
michael@0 700 virtual TemporaryRef<DataSourceSurface> Render(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 701 virtual IntRect GetOutputRectInRect(const IntRect& aRect) MOZ_OVERRIDE;
michael@0 702 virtual int32_t InputIndex(uint32_t aInputEnumIndex) MOZ_OVERRIDE;
michael@0 703 virtual void RequestFromInputsForRect(const IntRect &aRect) MOZ_OVERRIDE;
michael@0 704
michael@0 705 private:
michael@0 706 template<typename CoordType>
michael@0 707 TemporaryRef<DataSourceSurface> DoRender(const IntRect& aRect,
michael@0 708 CoordType aKernelUnitLengthX,
michael@0 709 CoordType aKernelUnitLengthY);
michael@0 710
michael@0 711 LightType mLight;
michael@0 712 LightingType mLighting;
michael@0 713 Float mSurfaceScale;
michael@0 714 Size mKernelUnitLength;
michael@0 715 Color mColor;
michael@0 716 #if defined(MOZILLA_INTERNAL_API) && (defined(DEBUG) || defined(FORCE_BUILD_REFCNT_LOGGING))
michael@0 717 const char* mTypeName;
michael@0 718 #endif
michael@0 719 };
michael@0 720
michael@0 721 }
michael@0 722 }
michael@0 723
michael@0 724 #endif // _MOZILLA_GFX_FILTERNODESOFTWARE_H_

mercurial