blob: b97555e6095647b0e16ced90e6163cb764df32e2 [file] [log] [blame]
Kaido Kert25902c62024-06-17 17:10:28 -07001// Copyright 2016 The Chromium Authors
Kaido Kert56d7c4e2024-04-13 12:59:27 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_GFX_WIN_RENDERING_WINDOW_MANAGER_H_
6#define UI_GFX_WIN_RENDERING_WINDOW_MANAGER_H_
7
8#include <windows.h>
9
10#include "base/containers/flat_map.h"
11#include "base/memory/scoped_refptr.h"
12#include "base/no_destructor.h"
13#include "ui/gfx/gfx_export.h"
14
15namespace base {
16class SingleThreadTaskRunner;
17}
18
19namespace gfx {
20
21// This keeps track of whether a given HWND has a child window which the GPU
22// process renders into. This should only be used from the UI thread unless
23// otherwise noted.
24class GFX_EXPORT RenderingWindowManager {
25 public:
26 // The first call to GetInstance() should happen on the UI thread.
27 static RenderingWindowManager* GetInstance();
28
29 RenderingWindowManager(const RenderingWindowManager&) = delete;
30 RenderingWindowManager& operator=(const RenderingWindowManager&) = delete;
31
32 void RegisterParent(HWND parent);
33 // Registers |child| as child window for |parent|. Allows the GPU process to
34 // draw into the |child| HWND instead of |parent|. This will fail and do
35 // nothing if:
36 // 1. |parent| isn't registered.
37 // 2. |child| doesn't belong to |expected_child_process_id|.
38 //
39 // Can be called from any thread, as long GetInstance() has already been
40 // called on the UI thread at least once.
41 void RegisterChild(HWND parent, HWND child, DWORD expected_child_process_id);
42 void UnregisterParent(HWND parent);
43 bool HasValidChildWindow(HWND parent);
44
45 private:
46 friend class base::NoDestructor<RenderingWindowManager>;
47
48 RenderingWindowManager();
49 ~RenderingWindowManager();
50
51 // UI thread task runner.
52 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
53 // Map from registered parent HWND to child HWND.
54 base::flat_map<HWND, HWND> registered_hwnds_;
55};
56
57} // namespace gfx
58
59#endif // UI_GFX_WIN_RENDERING_WINDOW_MANAGER_H_