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