forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic screen-sharing for lacros.
This CL creates a new mojo interface: ScreenManager. This interface has a single method TakeScreenSnapshot which returns a bitmap of the screen's contents. Lacros-chrome uses this interface to implement a rudimentary version of screen-sharing. This in turn allows meet.google.com screen sharing to function properly. This interface will eventually be supplemented with methods to allow window-sharing as well. The whole interface will likely be overhauled in the future to create a more performant and fully-featured version of screen/window sharing. Change-Id: I821c59464ea4d2ff57665381038837f29645750d Bug: 1094460 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261430 Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org> Reviewed-by: Ken Rockot <rockot@google.com> Reviewed-by: James Cook <jamescook@chromium.org> Reviewed-by: Hidehiko Abe <hidehiko@chromium.org> Reviewed-by: Avi Drissman <avi@chromium.org> Commit-Queue: Ken Rockot <rockot@google.com> Auto-Submit: Erik Chen <erikchen@chromium.org> Cr-Commit-Position: refs/heads/master@{#786507}
- Loading branch information
Showing
25 changed files
with
563 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2020 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. | ||
|
||
#include "chrome/browser/chromeos/lacros/screen_manager_crosapi.h" | ||
|
||
#include <utility> | ||
#include <vector> | ||
|
||
#include "ash/shell.h" | ||
#include "base/files/file_path.h" | ||
#include "base/numerics/checked_math.h" | ||
#include "base/numerics/safe_conversions.h" | ||
#include "chromeos/lacros/cpp/window_snapshot.h" | ||
#include "ui/snapshot/snapshot.h" | ||
|
||
ScreenManagerCrosapi::ScreenManagerCrosapi() = default; | ||
|
||
ScreenManagerCrosapi::~ScreenManagerCrosapi() = default; | ||
|
||
void ScreenManagerCrosapi::BindReceiver( | ||
mojo::PendingReceiver<lacros::mojom::ScreenManager> receiver) { | ||
receivers_.Add(this, std::move(receiver)); | ||
} | ||
|
||
void ScreenManagerCrosapi::TakeScreenSnapshot( | ||
TakeScreenSnapshotCallback callback) { | ||
// TODO(https://crbug.com/1094460): Handle display selection and multiple | ||
// displays. | ||
aura::Window* primary_window = ash::Shell::GetPrimaryRootWindow(); | ||
|
||
ui::GrabWindowSnapshotAsync( | ||
primary_window, primary_window->bounds(), | ||
base::BindOnce(&ScreenManagerCrosapi::DidTakeScreenSnapshot, | ||
weak_factory_.GetWeakPtr(), std::move(callback))); | ||
} | ||
|
||
void ScreenManagerCrosapi::DidTakeScreenSnapshot( | ||
TakeScreenSnapshotCallback callback, | ||
gfx::Image image) { | ||
SkBitmap bitmap = image.AsBitmap(); | ||
|
||
// This code currently relies on the assumption that the bitmap is unpadded, | ||
// and uses 4 bytes per pixel. | ||
int size; | ||
size = base::CheckMul(bitmap.width(), bitmap.height()).ValueOrDie(); | ||
size = base::CheckMul(size, 4).ValueOrDie(); | ||
CHECK_EQ(bitmap.computeByteSize(), base::checked_cast<size_t>(size)); | ||
|
||
uint8_t* base = static_cast<uint8_t*>(bitmap.getPixels()); | ||
std::vector<uint8_t> bytes(base, base + bitmap.computeByteSize()); | ||
|
||
lacros::WindowSnapshot snapshot; | ||
snapshot.width = bitmap.width(); | ||
snapshot.height = bitmap.height(); | ||
snapshot.bitmap.swap(bytes); | ||
std::move(callback).Run(std::move(snapshot)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2020 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 CHROME_BROWSER_CHROMEOS_LACROS_SCREEN_MANAGER_CROSAPI_H_ | ||
#define CHROME_BROWSER_CHROMEOS_LACROS_SCREEN_MANAGER_CROSAPI_H_ | ||
|
||
#include "base/memory/weak_ptr.h" | ||
#include "chromeos/lacros/mojom/screen_manager.mojom.h" | ||
#include "mojo/public/cpp/bindings/pending_receiver.h" | ||
#include "mojo/public/cpp/bindings/receiver_set.h" | ||
#include "ui/gfx/image/image.h" | ||
|
||
// This class is the ash-chrome implementation of the ScreenManager interface. | ||
// This class must only be used from the main thread. | ||
class ScreenManagerCrosapi : public lacros::mojom::ScreenManager { | ||
public: | ||
ScreenManagerCrosapi(); | ||
ScreenManagerCrosapi(const ScreenManagerCrosapi&) = delete; | ||
ScreenManagerCrosapi& operator=(const ScreenManagerCrosapi&) = delete; | ||
~ScreenManagerCrosapi() override; | ||
|
||
void BindReceiver( | ||
mojo::PendingReceiver<lacros::mojom::ScreenManager> receiver); | ||
|
||
// lacros::mojom::ScreenManager: | ||
void TakeScreenSnapshot(TakeScreenSnapshotCallback callback) override; | ||
|
||
private: | ||
void DidTakeScreenSnapshot(TakeScreenSnapshotCallback callback, | ||
gfx::Image image); | ||
|
||
// This class supports any number of connections. This allows the client to | ||
// have multiple, potentially thread-affine, remotes. This is needed by | ||
// WebRTC. | ||
mojo::ReceiverSet<lacros::mojom::ScreenManager> receivers_; | ||
|
||
base::WeakPtrFactory<ScreenManagerCrosapi> weak_factory_{this}; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_CHROMEOS_LACROS_SCREEN_MANAGER_CROSAPI_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright 2020 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. | ||
|
||
# C++ components used by both lacros-chrome and ash-chrome. | ||
config("lacros_implementation") { | ||
defines = [ "IS_LACROS_IMPL" ] | ||
} | ||
|
||
component("cpp") { | ||
output_name = "lacros_public_cpp" | ||
sources = [ | ||
"window_snapshot.cc", | ||
"window_snapshot.h", | ||
] | ||
configs += [ ":lacros_implementation" ] | ||
deps = [ "//base" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright 2020 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. | ||
|
||
#include "chromeos/lacros/cpp/window_snapshot.h" | ||
|
||
namespace lacros { | ||
|
||
WindowSnapshot::WindowSnapshot() = default; | ||
WindowSnapshot::~WindowSnapshot() = default; | ||
|
||
} // namespace lacros |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2020 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 CHROMEOS_LACROS_CPP_WINDOW_SNAPSHOT_H_ | ||
#define CHROMEOS_LACROS_CPP_WINDOW_SNAPSHOT_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#include <vector> | ||
|
||
#include "base/component_export.h" | ||
|
||
namespace lacros { | ||
|
||
// bitmap is a 4-byte RGBA bitmap representation of the window. Its size must | ||
// be exactly equal to width * height * 4. | ||
struct COMPONENT_EXPORT(LACROS) WindowSnapshot { | ||
WindowSnapshot(); | ||
~WindowSnapshot(); | ||
uint32_t width = 0; | ||
uint32_t height = 0; | ||
std::vector<uint8_t> bitmap; | ||
}; | ||
|
||
} // namespace lacros | ||
|
||
#endif // CHROMEOS_LACROS_CPP_WINDOW_SNAPSHOT_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
per-file *.mojom=set noparent | ||
per-file *.mojom=file://ipc/SECURITY_OWNERS | ||
|
||
# Prefer Chrome OS owners for large changes to the Lacros API. | ||
per-file *.mojom=file://chromeos/SECURITY_OWNERS | ||
|
||
per-file *_mojom_traits*.*=set noparent | ||
per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS | ||
per-file *.mojom_traits*.*=file://chromeos/SECURITY_OWNERS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2020 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. | ||
|
||
module lacros.mojom; | ||
|
||
// A bitmap representation of the current contents of a window or screen. Each | ||
// pixel is represented by 4 bytes [RGBA]. | ||
struct WindowSnapshot { | ||
uint32 width; | ||
uint32 height; | ||
array<uint8> bitmap; | ||
}; | ||
|
||
// This interface is implemented by ash-chrome. It allows lacros-chrome to query | ||
// information about existing windows, screens, and displays. | ||
// | ||
// This interface cannot be used to make changes to screens, windows or | ||
// displays. That's because Wayland is the protocol for that, and attempting to | ||
// introduce another protocol would require careful synchronization between the | ||
// two, which we'd like to avoid. | ||
// | ||
// TODO(https://crbug.com/1094460): This is a very simple interface. We will | ||
// likely want to replace it with a more feature-complete and performant | ||
// interface in the future. | ||
interface ScreenManager { | ||
// TODO(https://crbug.com/1094460): We will need to add more methods for | ||
// querying screens, windows, etc. Details still TBD. | ||
|
||
// TODO(https://crbug.com/1094460): Use a more performant transport | ||
// mechanism. | ||
// This method assumes that there's exactly one screen. The implementation | ||
// of this method takes a screenshot and converts it into a bitmap. Each | ||
// pixel is represented by 4 bytes [RGBA]. | ||
// | ||
// The media screen capture implementation assumes that every platform | ||
// provides a synchronous method to take a snapshot of the screen. | ||
[Sync] | ||
TakeScreenSnapshot@0() => (WindowSnapshot snapshot); | ||
}; | ||
|
Oops, something went wrong.