filter_operations.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef CC_PAINT_FILTER_OPERATIONS_H_
  5. #define CC_PAINT_FILTER_OPERATIONS_H_
  6. #include <stddef.h>
  7. #include <memory>
  8. #include <string>
  9. #include <vector>
  10. #include "base/check_op.h"
  11. #include "cc/paint/filter_operation.h"
  12. namespace base {
  13. namespace trace_event {
  14. class TracedValue;
  15. }
  16. } // namespace base
  17. namespace gfx {
  18. class Rect;
  19. }
  20. namespace cc {
  21. // An ordered list of filter operations.
  22. class CC_PAINT_EXPORT FilterOperations {
  23. public:
  24. FilterOperations();
  25. FilterOperations(const FilterOperations& other);
  26. explicit FilterOperations(std::vector<FilterOperation>&& operations);
  27. ~FilterOperations();
  28. FilterOperations& operator=(const FilterOperations& other);
  29. FilterOperations& operator=(FilterOperations&& other);
  30. bool operator==(const FilterOperations& other) const;
  31. bool operator!=(const FilterOperations& other) const {
  32. return !(*this == other);
  33. }
  34. void Append(const FilterOperation& filter);
  35. // Removes all filter operations.
  36. void Clear();
  37. bool IsEmpty() const;
  38. // Maps "forward" to determine which pixels in a destination rect are affected
  39. // by pixels in the source rect.
  40. gfx::Rect MapRect(const gfx::Rect& rect, const SkMatrix& matrix) const;
  41. // Maps "backward" to determine which pixels in the source affect the pixels
  42. // in the destination rect.
  43. gfx::Rect MapRectReverse(const gfx::Rect& rect, const SkMatrix& matrix) const;
  44. bool HasFilterThatMovesPixels() const;
  45. float MaximumPixelMovement() const;
  46. bool HasFilterThatAffectsOpacity() const;
  47. bool HasReferenceFilter() const;
  48. bool HasFilterOfType(FilterOperation::FilterType type) const;
  49. size_t size() const { return operations_.size(); }
  50. const std::vector<FilterOperation>& operations() const { return operations_; }
  51. const FilterOperation& at(size_t index) const {
  52. DCHECK_LT(index, size());
  53. return operations_[index];
  54. }
  55. // If |from| is of the same size as this, where in each position, the filter
  56. // in |from| is of the same type as the filter in this, and if this doesn't
  57. // contain any reference filters, returns a FilterOperations formed by
  58. // linearly interpolating at each position a |progress| fraction of the way
  59. // from the filter in |from| to the filter in this. If |from| and this are of
  60. // different lengths, they are treated as having the same length by padding
  61. // the shorter sequence with no-op filters of the same type as the filters in
  62. // the corresponding positions in the longer sequence. If either sequence has
  63. // a reference filter or if there is a type mismatch at some position, returns
  64. // a copy of this.
  65. FilterOperations Blend(const FilterOperations& from, double progress) const;
  66. void AsValueInto(base::trace_event::TracedValue* value) const;
  67. std::string ToString() const;
  68. private:
  69. std::vector<FilterOperation> operations_;
  70. };
  71. } // namespace cc
  72. #endif // CC_PAINT_FILTER_OPERATIONS_H_