2019-04-17 21:10:04 +00:00
|
|
|
// Copyright (c) 2019 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_OSR_OSR_HOST_DISPLAY_CLIENT_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_OSR_OSR_HOST_DISPLAY_CLIENT_H_
|
2019-04-17 21:10:04 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "base/callback.h"
|
2019-05-01 00:18:22 +00:00
|
|
|
#include "base/memory/shared_memory_mapping.h"
|
2019-04-17 21:10:04 +00:00
|
|
|
#include "components/viz/host/host_display_client.h"
|
2019-08-02 23:56:46 +00:00
|
|
|
#include "services/viz/privileged/mojom/compositing/layered_window_updater.mojom.h"
|
2019-04-17 21:10:04 +00:00
|
|
|
#include "third_party/skia/include/core/SkBitmap.h"
|
|
|
|
#include "third_party/skia/include/core/SkCanvas.h"
|
|
|
|
#include "ui/gfx/native_widget_types.h"
|
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
2021-05-06 22:01:04 +00:00
|
|
|
typedef base::RepeatingCallback<void(const gfx::Rect&, const SkBitmap&)>
|
|
|
|
OnPaintCallback;
|
2019-04-17 21:10:04 +00:00
|
|
|
|
|
|
|
class LayeredWindowUpdater : public viz::mojom::LayeredWindowUpdater {
|
|
|
|
public:
|
2020-02-27 19:00:07 +00:00
|
|
|
explicit LayeredWindowUpdater(
|
|
|
|
mojo::PendingReceiver<viz::mojom::LayeredWindowUpdater> receiver,
|
|
|
|
OnPaintCallback callback);
|
2019-04-17 21:10:04 +00:00
|
|
|
~LayeredWindowUpdater() override;
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
LayeredWindowUpdater(const LayeredWindowUpdater&) = delete;
|
|
|
|
LayeredWindowUpdater& operator=(const LayeredWindowUpdater&) = delete;
|
|
|
|
|
2019-04-17 21:10:04 +00:00
|
|
|
void SetActive(bool active);
|
|
|
|
|
|
|
|
// viz::mojom::LayeredWindowUpdater implementation.
|
2019-07-03 01:22:09 +00:00
|
|
|
void OnAllocatedSharedMemory(const gfx::Size& pixel_size,
|
|
|
|
base::UnsafeSharedMemoryRegion region) override;
|
2019-04-17 21:10:04 +00:00
|
|
|
void Draw(const gfx::Rect& damage_rect, DrawCallback draw_callback) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
OnPaintCallback callback_;
|
2020-02-27 19:00:07 +00:00
|
|
|
mojo::Receiver<viz::mojom::LayeredWindowUpdater> receiver_;
|
2019-04-17 21:10:04 +00:00
|
|
|
std::unique_ptr<SkCanvas> canvas_;
|
|
|
|
bool active_ = false;
|
|
|
|
|
|
|
|
#if !defined(WIN32)
|
|
|
|
base::WritableSharedMemoryMapping shm_mapping_;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
class OffScreenHostDisplayClient : public viz::HostDisplayClient {
|
|
|
|
public:
|
|
|
|
explicit OffScreenHostDisplayClient(gfx::AcceleratedWidget widget,
|
|
|
|
OnPaintCallback callback);
|
|
|
|
~OffScreenHostDisplayClient() override;
|
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
OffScreenHostDisplayClient(const OffScreenHostDisplayClient&) = delete;
|
|
|
|
OffScreenHostDisplayClient& operator=(const OffScreenHostDisplayClient&) =
|
|
|
|
delete;
|
|
|
|
|
2019-04-17 21:10:04 +00:00
|
|
|
void SetActive(bool active);
|
|
|
|
|
|
|
|
private:
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-04-17 21:10:04 +00:00
|
|
|
void OnDisplayReceivedCALayerParams(
|
|
|
|
const gfx::CALayerParams& ca_layer_params) override;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void CreateLayeredWindowUpdater(
|
2020-02-27 19:00:07 +00:00
|
|
|
mojo::PendingReceiver<viz::mojom::LayeredWindowUpdater> receiver)
|
|
|
|
override;
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_LINUX) && !BUILDFLAG(IS_CHROMEOS)
|
2020-02-27 19:00:07 +00:00
|
|
|
void DidCompleteSwapWithNewSize(const gfx::Size& size) override;
|
|
|
|
#endif
|
2019-04-17 21:10:04 +00:00
|
|
|
|
|
|
|
std::unique_ptr<LayeredWindowUpdater> layered_window_updater_;
|
|
|
|
OnPaintCallback callback_;
|
|
|
|
bool active_ = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace electron
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_OSR_OSR_HOST_DISPLAY_CLIENT_H_
|