2019-07-16 22:09:04 +02:00
|
|
|
// Copyright 2019 The Chromium Embedded Framework Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/osr/host_display_client_osr.h"
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "libcef/browser/osr/render_widget_host_view_osr.h"
|
|
|
|
|
2020-02-10 18:10:17 +01:00
|
|
|
#include "base/memory/shared_memory_mapping.h"
|
2019-07-16 22:09:04 +02:00
|
|
|
#include "components/viz/common/resources/resource_format.h"
|
|
|
|
#include "components/viz/common/resources/resource_sizes.h"
|
|
|
|
#include "mojo/public/cpp/system/platform_handle.h"
|
2019-10-01 15:55:16 +02:00
|
|
|
#include "services/viz/privileged/mojom/compositing/layered_window_updater.mojom.h"
|
2019-07-16 22:09:04 +02:00
|
|
|
#include "skia/ext/platform_canvas.h"
|
|
|
|
#include "third_party/skia/include/core/SkColor.h"
|
|
|
|
#include "third_party/skia/include/core/SkRect.h"
|
|
|
|
#include "third_party/skia/src/core/SkDevice.h"
|
|
|
|
#include "ui/gfx/skia_util.h"
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-07-16 22:09:04 +02:00
|
|
|
#include "skia/ext/skia_utils_win.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class CefLayeredWindowUpdaterOSR : public viz::mojom::LayeredWindowUpdater {
|
|
|
|
public:
|
2019-11-12 17:11:44 +01:00
|
|
|
CefLayeredWindowUpdaterOSR(
|
|
|
|
CefRenderWidgetHostViewOSR* const view,
|
|
|
|
mojo::PendingReceiver<viz::mojom::LayeredWindowUpdater> receiver);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefLayeredWindowUpdaterOSR(const CefLayeredWindowUpdaterOSR&) = delete;
|
|
|
|
CefLayeredWindowUpdaterOSR& operator=(const CefLayeredWindowUpdaterOSR&) =
|
|
|
|
delete;
|
|
|
|
|
2019-07-16 22:09:04 +02:00
|
|
|
~CefLayeredWindowUpdaterOSR() override;
|
|
|
|
|
|
|
|
void SetActive(bool active);
|
|
|
|
const void* GetPixelMemory() const;
|
|
|
|
gfx::Size GetPixelSize() const;
|
|
|
|
|
|
|
|
// viz::mojom::LayeredWindowUpdater implementation.
|
2019-09-04 17:13:32 +02:00
|
|
|
void OnAllocatedSharedMemory(const gfx::Size& pixel_size,
|
|
|
|
base::UnsafeSharedMemoryRegion region) override;
|
2019-07-16 22:09:04 +02:00
|
|
|
void Draw(const gfx::Rect& damage_rect, DrawCallback draw_callback) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRenderWidgetHostViewOSR* const view_;
|
2019-11-12 17:11:44 +01:00
|
|
|
mojo::Receiver<viz::mojom::LayeredWindowUpdater> receiver_;
|
2019-07-16 22:09:04 +02:00
|
|
|
bool active_ = false;
|
2019-09-04 17:13:32 +02:00
|
|
|
base::WritableSharedMemoryMapping shared_memory_;
|
2019-07-16 22:09:04 +02:00
|
|
|
gfx::Size pixel_size_;
|
|
|
|
};
|
|
|
|
|
|
|
|
CefLayeredWindowUpdaterOSR::CefLayeredWindowUpdaterOSR(
|
|
|
|
CefRenderWidgetHostViewOSR* const view,
|
2019-11-12 17:11:44 +01:00
|
|
|
mojo::PendingReceiver<viz::mojom::LayeredWindowUpdater> receiver)
|
|
|
|
: view_(view), receiver_(this, std::move(receiver)) {}
|
2019-07-16 22:09:04 +02:00
|
|
|
|
|
|
|
CefLayeredWindowUpdaterOSR::~CefLayeredWindowUpdaterOSR() = default;
|
|
|
|
|
|
|
|
void CefLayeredWindowUpdaterOSR::SetActive(bool active) {
|
|
|
|
active_ = active;
|
|
|
|
}
|
|
|
|
|
|
|
|
const void* CefLayeredWindowUpdaterOSR::GetPixelMemory() const {
|
|
|
|
return shared_memory_.memory();
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size CefLayeredWindowUpdaterOSR::GetPixelSize() const {
|
|
|
|
return pixel_size_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefLayeredWindowUpdaterOSR::OnAllocatedSharedMemory(
|
|
|
|
const gfx::Size& pixel_size,
|
2019-09-04 17:13:32 +02:00
|
|
|
base::UnsafeSharedMemoryRegion region) {
|
2019-07-16 22:09:04 +02:00
|
|
|
// Make sure |pixel_size| is sane.
|
|
|
|
size_t expected_bytes;
|
|
|
|
bool size_result = viz::ResourceSizes::MaybeSizeInBytes(
|
2023-06-26 12:13:38 +02:00
|
|
|
pixel_size, viz::SinglePlaneFormat::kRGBA_8888, &expected_bytes);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!size_result) {
|
2019-07-16 22:09:04 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-07-16 22:09:04 +02:00
|
|
|
|
|
|
|
pixel_size_ = pixel_size;
|
2019-09-04 17:13:32 +02:00
|
|
|
shared_memory_ = region.Map();
|
2019-07-16 22:09:04 +02:00
|
|
|
DCHECK(shared_memory_.IsValid());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefLayeredWindowUpdaterOSR::Draw(const gfx::Rect& damage_rect,
|
|
|
|
DrawCallback draw_callback) {
|
|
|
|
if (active_) {
|
|
|
|
const void* memory = GetPixelMemory();
|
|
|
|
if (memory) {
|
|
|
|
view_->OnPaint(damage_rect, pixel_size_, memory);
|
|
|
|
} else {
|
|
|
|
LOG(WARNING) << "Failed to read pixels";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::move(draw_callback).Run();
|
|
|
|
}
|
|
|
|
|
|
|
|
CefHostDisplayClientOSR::CefHostDisplayClientOSR(
|
|
|
|
CefRenderWidgetHostViewOSR* const view,
|
|
|
|
gfx::AcceleratedWidget widget)
|
|
|
|
: viz::HostDisplayClient(widget), view_(view) {}
|
|
|
|
|
|
|
|
CefHostDisplayClientOSR::~CefHostDisplayClientOSR() {}
|
|
|
|
|
|
|
|
void CefHostDisplayClientOSR::SetActive(bool active) {
|
|
|
|
active_ = active;
|
|
|
|
if (layered_window_updater_) {
|
|
|
|
layered_window_updater_->SetActive(active_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const void* CefHostDisplayClientOSR::GetPixelMemory() const {
|
|
|
|
return layered_window_updater_ ? layered_window_updater_->GetPixelMemory()
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size CefHostDisplayClientOSR::GetPixelSize() const {
|
|
|
|
return layered_window_updater_ ? layered_window_updater_->GetPixelSize()
|
|
|
|
: gfx::Size{};
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefHostDisplayClientOSR::UseProxyOutputDevice(
|
|
|
|
UseProxyOutputDeviceCallback callback) {
|
|
|
|
std::move(callback).Run(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefHostDisplayClientOSR::CreateLayeredWindowUpdater(
|
2019-11-12 17:11:44 +01:00
|
|
|
mojo::PendingReceiver<viz::mojom::LayeredWindowUpdater> receiver) {
|
2019-07-16 22:09:04 +02:00
|
|
|
layered_window_updater_ =
|
2019-11-12 17:11:44 +01:00
|
|
|
std::make_unique<CefLayeredWindowUpdaterOSR>(view_, std::move(receiver));
|
2019-07-16 22:09:04 +02:00
|
|
|
layered_window_updater_->SetActive(active_);
|
|
|
|
}
|
2019-11-12 17:11:44 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2019-11-12 17:11:44 +01:00
|
|
|
void CefHostDisplayClientOSR::DidCompleteSwapWithNewSize(
|
|
|
|
const gfx::Size& size) {}
|
|
|
|
#endif
|