paint_worklet_job.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2019 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_PAINT_WORKLET_JOB_H_
  5. #define CC_PAINT_PAINT_WORKLET_JOB_H_
  6. #include <vector>
  7. #include "base/containers/flat_map.h"
  8. #include "base/memory/scoped_refptr.h"
  9. #include "cc/paint/paint_export.h"
  10. #include "cc/paint/paint_record.h"
  11. #include "cc/paint/paint_worklet_input.h"
  12. #include "third_party/skia/include/core/SkRefCnt.h"
  13. namespace cc {
  14. // A PaintWorkletJob instance encapsulates the data that needs to be passed
  15. // around in order to dispatch PaintWorklets to the worklet thread, paint them,
  16. // and return the results to cc-impl.
  17. class CC_PAINT_EXPORT PaintWorkletJob {
  18. public:
  19. // A map from animated property name to its compositor-provided value, used to
  20. // override the Blink-provided value for properties which are being animated.
  21. // For a custom property, its name is sufficient to uniquely identify it.
  22. // TODO(xidachen): support more property types such as color.
  23. using AnimatedPropertyValues =
  24. base::flat_map<PaintWorkletInput::PropertyKey,
  25. PaintWorkletInput::PropertyValue>;
  26. PaintWorkletJob(int layer_id,
  27. scoped_refptr<const PaintWorkletInput> input,
  28. AnimatedPropertyValues animated_property_values);
  29. PaintWorkletJob(const PaintWorkletJob& other);
  30. PaintWorkletJob(PaintWorkletJob&& other);
  31. ~PaintWorkletJob();
  32. int layer_id() const { return layer_id_; }
  33. const scoped_refptr<const PaintWorkletInput>& input() const { return input_; }
  34. const AnimatedPropertyValues& GetAnimatedPropertyValues() const {
  35. return animated_property_values_;
  36. }
  37. const sk_sp<PaintRecord>& output() const { return output_; }
  38. void SetOutput(sk_sp<PaintRecord> output);
  39. private:
  40. // The id for the layer that the PaintWorkletInput is associated with.
  41. int layer_id_;
  42. // The input for a PaintWorkletJob is encapsulated in a PaintWorkletInput
  43. // instance; see class-level comments on |PaintWorkletInput| for details.
  44. // The style map in the |input_| is un-mutable once constructed. Overridden
  45. // values can be set on |animated_property_values_| below.
  46. scoped_refptr<const PaintWorkletInput> input_;
  47. // A set of 'overrides' for animated properties where the compositor animation
  48. // system has produced a different value that should be used instead of the
  49. // old value contributed by Blink.
  50. AnimatedPropertyValues animated_property_values_;
  51. // The output for a PaintWorkletJob is a series of paint ops for the painted
  52. // content, that can be passed to raster.
  53. sk_sp<PaintRecord> output_;
  54. };
  55. // The PaintWorklet dispatcher logic passes the PaintWorkletJobVector to the
  56. // worklet thread during painting. To keep the structure alive on both the
  57. // compositor and worklet side (as technically the compositor could be town down
  58. // whilst the worklet is still painting), we use base::RefCountedJob for it.
  59. using PaintWorkletJobVector =
  60. base::RefCountedData<std::vector<PaintWorkletJob>>;
  61. using PaintWorkletId = int;
  62. using PaintWorkletJobMap =
  63. base::flat_map<PaintWorkletId, scoped_refptr<PaintWorkletJobVector>>;
  64. } // namespace cc
  65. #endif // CC_PAINT_PAINT_WORKLET_JOB_H_