summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/modules/csspaint/paint_worklet_pending_generator_registry.h
blob: e65c2c60ff7a0bc8db356c77c4f4b7093cda9ca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_CSSPAINT_PAINT_WORKLET_PENDING_GENERATOR_REGISTRY_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_CSSPAINT_PAINT_WORKLET_PENDING_GENERATOR_REGISTRY_H_

#include "base/macros.h"
#include "third_party/blink/renderer/modules/csspaint/css_paint_image_generator_impl.h"
#include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/heap/heap_allocator.h"

namespace blink {

class CSSPaintDefinition;

// Keeps pending CSSPaintImageGeneratorImpls until corresponding
// CSSPaintDefinitions are registered. This is primarily owned by the
// PaintWorklet instance.
class PaintWorkletPendingGeneratorRegistry
    : public GarbageCollected<PaintWorkletPendingGeneratorRegistry> {
 public:
  PaintWorkletPendingGeneratorRegistry() = default;

  void NotifyGeneratorReady(const String& name);
  void AddPendingGenerator(const String& name, CSSPaintImageGeneratorImpl*);

  void Trace(Visitor*);

 private:
  // The map of CSSPaintImageGeneratorImpl which are waiting for a
  // CSSPaintDefinition to be registered. Owners of this registry is expected to
  // outlive the generators hence are held onto with a WeakMember.
  using GeneratorHashSet = HeapHashSet<WeakMember<CSSPaintImageGeneratorImpl>>;
  using PendingGeneratorMap = HeapHashMap<String, Member<GeneratorHashSet>>;
  PendingGeneratorMap pending_generators_;

  DISALLOW_COPY_AND_ASSIGN(PaintWorkletPendingGeneratorRegistry);
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_CSSPAINT_PAINT_WORKLET_PENDING_GENERATOR_REGISTRY_H_