File: resource_manager_impl.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (111 lines) | stat: -rw-r--r-- 4,062 bytes parent folder | download | duplicates (4)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_
#define UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_

#include <array>
#include <memory>
#include <unordered_map>
#include <unordered_set>

#include "base/android/scoped_java_ref.h"
#include "base/memory/raw_ptr.h"
#include "base/trace_event/memory_dump_provider.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/android/resources/resource_manager.h"
#include "ui/android/ui_android_export.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/native_widget_types.h"

namespace cc {
class UIResourceManager;
}  // namespace cc

namespace ui {

class UI_ANDROID_EXPORT ResourceManagerImpl
    : public ResourceManager,
      public base::trace_event::MemoryDumpProvider {
 public:
  static ResourceManagerImpl* FromJavaObject(
      const base::android::JavaRef<jobject>& jobj);

  explicit ResourceManagerImpl(gfx::NativeWindow native_window);

  ResourceManagerImpl(const ResourceManagerImpl&) = delete;
  ResourceManagerImpl& operator=(const ResourceManagerImpl&) = delete;

  ~ResourceManagerImpl() override;

  void Init(cc::UIResourceManager* ui_resource_manager);

  // ResourceManager implementation.
  base::android::ScopedJavaLocalRef<jobject> GetJavaObject() override;
  Resource* GetResource(AndroidResourceType res_type, int res_id) override;
  Resource* GetStaticResourceWithTint(
      int res_id, SkColor tint_color) override;
  Resource* GetStaticResourceWithTint(int res_id,
                                      SkColor tint_color,
                                      bool preserve_color_alpha) override;
  void PreloadResource(AndroidResourceType res_type, int res_id) override;
  void OnFrameUpdatesFinished() override;

  // Called from Java
  // ----------------------------------------------------------
  void OnResourceReady(JNIEnv* env,
                       const base::android::JavaRef<jobject>& jobj,
                       jint res_type,
                       jint res_id,
                       const base::android::JavaRef<jobject>& bitmap,
                       jint width,
                       jint height,
                       jlong native_resource);
  void RemoveResource(
      JNIEnv* env,
      const base::android::JavaRef<jobject>& jobj,
      jint res_type,
      jint res_id);
  void ClearTintedResourceCache(JNIEnv* env,
      const base::android::JavaRef<jobject>& jobj);
  void DumpIfNoResource(JNIEnv* env,
                        const base::android::JavaRef<jobject>& jobj,
                        jint res_type,
                        jint res_id);

  // base::trace_event::MemoryDumpProvider implementation.
  bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
                    base::trace_event::ProcessMemoryDump* pmd) override;

 private:
  friend class TestResourceManagerImpl;

  // Start loading the resource. virtual for testing.
  virtual void PreloadResourceFromJava(AndroidResourceType res_type,
                                       int res_id);
  virtual void RequestResourceFromJava(AndroidResourceType res_type,
                                       int res_id);

  // Remove tints that were unused in the current frame being built. This
  // function takes a set |used_tints| and removes all the tints not in the set
  // from the cache.
  void RemoveUnusedTints();

  using ResourceMap = std::unordered_map<int, std::unique_ptr<Resource>>;
  using TintedResourceMap =
      std::unordered_map<SkColor, std::unique_ptr<ResourceMap>>;

  raw_ptr<cc::UIResourceManager> ui_resource_manager_;
  std::array<ResourceMap, ANDROID_RESOURCE_TYPE_COUNT> resources_;
  TintedResourceMap tinted_resources_;

  // The set of tints that are used for resources in the current frame.
  std::unordered_set<SkColor> used_tints_;

  base::android::ScopedJavaGlobalRef<jobject> java_obj_;
};

}  // namespace ui

#endif  // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_IMPL_H_