Allow launch to set the framebuffer size
This is work in progress: we need to finish the work to
point everything at these values.
Change-Id: Idaa366939d8e225f2a3685114d328f0d39867153
diff --git a/common/vsoc/framebuffer/Android.bp b/common/vsoc/framebuffer/Android.bp
index f30b18b..50ad9ea 100644
--- a/common/vsoc/framebuffer/Android.bp
+++ b/common/vsoc/framebuffer/Android.bp
@@ -16,7 +16,7 @@
cc_library_host_static {
name: "libvsoc_framebuffer",
srcs: [
- "fb_bcast_region.cpp",
+ "fb_bcast_region_view.cpp",
],
static_libs: [
"vsoc_lib",
diff --git a/common/vsoc/framebuffer/Android.mk b/common/vsoc/framebuffer/Android.mk
index 1213e05..fc59c2d 100644
--- a/common/vsoc/framebuffer/Android.mk
+++ b/common/vsoc/framebuffer/Android.mk
@@ -21,7 +21,7 @@
LOCAL_SRC_FILES := \
../../../common/vsoc/lib/fb_bcast_layout.cpp \
- fb_bcast_region.cpp
+ fb_bcast_region_view.cpp
LOCAL_C_INCLUDES += \
device/google/cuttlefish_common/common/vsoc/framebuffer \
diff --git a/common/vsoc/framebuffer/fb_bcast_region.h b/common/vsoc/framebuffer/fb_bcast_region.h
deleted file mode 100644
index d2c9f00..0000000
--- a/common/vsoc/framebuffer/fb_bcast_region.h
+++ /dev/null
@@ -1,98 +0,0 @@
-#pragma once
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "common/vsoc/lib/typed_region_view.h"
-#include "common/vsoc/shm/fb_bcast_layout.h"
-#include "common/vsoc/shm/graphics.h"
-#include "uapi/vsoc_shm.h"
-
-namespace vsoc {
-namespace framebuffer {
-
-// TODO(jemoreira): Convert to host only region.
-class FBBroadcastRegion : public vsoc::TypedRegionView<
- vsoc::layout::framebuffer::FBBroadcastLayout> {
- public:
- static FBBroadcastRegion* GetInstance();
-
- // These values should be initialized by the hwcomposer host daemon, but it
- // will be implemented at a later time, so we return constant values until
- // then.
- struct DisplayProperties {
- // Screen width in pixels
- int x_res() const {
- // TODO(jemoreira): region_->data()->x_res;
- return kFbXres;
- }
- // Screen height in pixels
- int y_res() const {
- // TODO(jemoreira): region_->data()->y_res;
- return kFbYres;
- }
- // Dots per inch
- int dpi() const {
- // TODO(jemoreira): region_->data()->dpi;
- return kFbDpi;
- }
- // Refresh rate in Hertz
- int refresh_rate_hz() const {
- // TODO(jemoreira): region_->data()->refresh_rate_hz;
- return kFbRefreshRateHz;
- }
- constexpr uint32_t pixel_format() const {
- return kFbPixelFormat;
- }
- constexpr uint32_t bytes_per_pixel() const {
- return vsoc::PixelFormatProperties<kFbPixelFormat>::bytes_per_pixel;
- }
- DisplayProperties(FBBroadcastRegion* /*region*/) /*: region_(region)*/ {}
- private:
- static constexpr uint32_t kFbPixelFormat = vsoc::VSOC_PIXEL_FORMAT_RGBA_8888;
- static constexpr int kFbXres = 800;
- static constexpr int kFbYres = 1280;
- static constexpr int kFbDpi = 160;
- static constexpr int kFbRefreshRateHz = 60;
- // FBBroadcastRegion* region_;
- };
-
- // Broadcasts a new frame. Meant to be used exclusively by the hwcomposer.
- // Zero is an invalid frame_num, used to indicate that there is no frame
- // available. It's expected that frame_num increases monotonically over time,
- // but there is no hard requirement for this.
- // frame_offset is the offset of the current frame in the gralloc region.
- void BroadcastNewFrame(uint32_t frame_num, vsoc_reg_off_t frame_offset);
-
- // Waits for a new frame (one with a different seq_num than last one we saw).
- // Returns the offset of the new frame or zero if there was an error, stores
- // the new sequential number in *last_seq_num.
- vsoc_reg_off_t WaitForNewFrameSince(uint32_t* last_seq_num);
-
- const DisplayProperties& display_properties() const {
- return properties_;
- }
-
- protected:
- FBBroadcastRegion();
- FBBroadcastRegion(const FBBroadcastRegion&);
- FBBroadcastRegion& operator=(const FBBroadcastRegion&);
-
- bool is_open_;
- const DisplayProperties properties_;
-};
-
-} // namespace framebuffer
-} // namespace vsoc
diff --git a/common/vsoc/framebuffer/fb_bcast_region.cpp b/common/vsoc/framebuffer/fb_bcast_region_view.cpp
similarity index 76%
rename from common/vsoc/framebuffer/fb_bcast_region.cpp
rename to common/vsoc/framebuffer/fb_bcast_region_view.cpp
index e4c5222..c761a9b 100644
--- a/common/vsoc/framebuffer/fb_bcast_region.cpp
+++ b/common/vsoc/framebuffer/fb_bcast_region_view.cpp
@@ -14,29 +14,19 @@
* limitations under the License.
*/
-#include "common/vsoc/framebuffer/fb_bcast_region.h"
+#include "common/vsoc/framebuffer/fb_bcast_region_view.h"
#include "common/libs/glog/logging.h"
#include "common/vsoc/lib/lock_guard.h"
-using vsoc::framebuffer::FBBroadcastRegion;
-using vsoc::layout::GuestAndHostLock;
-
-FBBroadcastRegion* FBBroadcastRegion::GetInstance() {
- static FBBroadcastRegion region;
- if (!region.is_open_) {
- LOG(FATAL) << "Unable to open framebuffer broadcast region";
- return nullptr;
- }
- return ®ion;
-}
+using vsoc::framebuffer::FBBroadcastRegionView;
// We can use a locking protocol because we decided that the streamer should
// have more priority than the hwcomposer, so it's OK to block the hwcomposer
// waiting for the streamer to complete, while the streamer will only block on
// the hwcomposer when it's ran out of work to do and needs to get more from the
// hwcomposer.
-void FBBroadcastRegion::BroadcastNewFrame(uint32_t seq_num,
+void FBBroadcastRegionView::BroadcastNewFrame(uint32_t seq_num,
vsoc_reg_off_t frame_offset) {
{
auto lock_guard(make_lock_guard(&data()->bcast_lock));
@@ -52,7 +42,7 @@
SendSignal(side, &data()->seq_num);
}
-vsoc_reg_off_t FBBroadcastRegion::WaitForNewFrameSince(uint32_t* last_seq_num) {
+vsoc_reg_off_t FBBroadcastRegionView::WaitForNewFrameSince(uint32_t* last_seq_num) {
static std::unique_ptr<RegionWorker> worker = StartWorker();
// It's ok to read seq_num here without holding the lock because the lock will
// be acquired immediately after so we'll block if necessary to wait for the
@@ -71,9 +61,3 @@
return data()->frame_offset;
}
}
-
-FBBroadcastRegion::FBBroadcastRegion() : properties_(this) {
- // Open here since the constructor in the singleton is thread safe.
- // TODO(jemoreira): Get the domain from somewhere
- is_open_ = Open(nullptr);
-}
diff --git a/common/vsoc/framebuffer/fb_bcast_region_view.h b/common/vsoc/framebuffer/fb_bcast_region_view.h
new file mode 100644
index 0000000..26bc588
--- /dev/null
+++ b/common/vsoc/framebuffer/fb_bcast_region_view.h
@@ -0,0 +1,75 @@
+#pragma once
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common/vsoc/lib/typed_region_view.h"
+#include "common/vsoc/shm/fb_bcast_layout.h"
+#include "common/vsoc/shm/graphics.h"
+#include "uapi/vsoc_shm.h"
+
+namespace vsoc {
+namespace framebuffer {
+
+class FBBroadcastRegionView : public vsoc::TypedRegionView<
+ vsoc::layout::framebuffer::FBBroadcastLayout> {
+ public:
+ // Screen width in pixels
+ int x_res() const {
+ return data().x_res;
+ }
+
+ // Screen height in pixels
+ int y_res() const {
+ return data().y_res;
+ }
+
+ // Dots per inch
+ int dpi() const {
+ return data().dpi;
+ }
+
+ // Refresh rate in Hertz
+ int refresh_rate_hz() const {
+ // TODO(jemoreira): region_->data()->refresh_rate_hz;
+ return kFbRefreshRateHz;
+ }
+
+ uint32_t pixel_format() const {
+ return kFbPixelFormat;
+ }
+
+ uint32_t bytes_per_pixel() const {
+ return vsoc::PixelFormatProperties<kFbPixelFormat>::bytes_per_pixel;
+ }
+
+ // Broadcasts a new frame. Meant to be used exclusively by the hwcomposer.
+ // Zero is an invalid frame_num, used to indicate that there is no frame
+ // available. It's expected that frame_num increases monotonically over time,
+ // but there is no hard requirement for this.
+ // frame_offset is the offset of the current frame in the gralloc region.
+ void BroadcastNewFrame(uint32_t frame_num, vsoc_reg_off_t frame_offset);
+
+ // Waits for a new frame (one with a different seq_num than last one we saw).
+ // Returns the offset of the new frame or zero if there was an error, stores
+ // the new sequential number in *last_seq_num.
+ vsoc_reg_off_t WaitForNewFrameSince(uint32_t* last_seq_num);
+
+ private:
+ static constexpr uint32_t kFbPixelFormat = vsoc::VSOC_PIXEL_FORMAT_RGBA_8888;
+ static constexpr int kFbRefreshRateHz = 60;
+};
+} // namespace framebuffer
+} // namespace vsoc
diff --git a/common/vsoc/framebuffer/test_fb.cpp b/common/vsoc/framebuffer/test_fb.cpp
index 56a3dcf..6f311ff 100644
--- a/common/vsoc/framebuffer/test_fb.cpp
+++ b/common/vsoc/framebuffer/test_fb.cpp
@@ -13,22 +13,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include "fb_bcast_region.h"
+#include "fb_bcast_region_view.h"
#include <stdio.h>
-using vsoc::framebuffer::FBBroadcastRegion;
+using vsoc::framebuffer::FBBroadcastRegionView;
int main() {
uint32_t frame_num = 0;
vsoc_reg_off_t offset = 0;
- FBBroadcastRegion* region = FBBroadcastRegion::GetInstance();
- if (!region) {
+ FBBroadcastRegionView region;
+ if (!region.Open()) {
fprintf(stderr, "Error opening region\n");
return 1;
}
while (1) {
- offset = region->WaitForNewFrameSince(&frame_num);
+ offset = region.WaitForNewFrameSince(&frame_num);
printf("Signaled frame_num = %d, offset = 0x%x\n", frame_num, offset);
}
diff --git a/common/vsoc/lib/region_view.h b/common/vsoc/lib/region_view.h
index 0e20808..985c59e 100644
--- a/common/vsoc/lib/region_view.h
+++ b/common/vsoc/lib/region_view.h
@@ -136,6 +136,14 @@
// must store the returned unique_ptr as a class member.
std::unique_ptr<RegionWorker> StartWorker();
+ // Returns a pointer to the start of region data that is cast to the given
+ // type. Initializers that run in the launcher use this to get a typed view of the region. Most other cases should be handled via TypedRegionView.
+ template <typename LayoutType>
+ LayoutType* GetLayoutPointer() {
+ return this->region_offset_to_pointer<LayoutType>(
+ control_->region_desc().offset_of_region_data);
+ }
+
protected:
template <typename T>
T* region_offset_to_pointer(vsoc_reg_off_t offset) {
diff --git a/common/vsoc/lib/typed_region_view.h b/common/vsoc/lib/typed_region_view.h
index b869a72..72100ee 100644
--- a/common/vsoc/lib/typed_region_view.h
+++ b/common/vsoc/lib/typed_region_view.h
@@ -41,8 +41,7 @@
/* Returns a pointer to the region with a type that matches the layout */
LayoutType* data() {
- return this->region_offset_to_pointer<LayoutType>(
- control_->region_desc().offset_of_region_data);
+ return this->GetLayoutPointer<LayoutType>();
}
const LayoutType& data() const {
diff --git a/guest/hals/hwcomposer/Android.mk b/guest/hals/hwcomposer/Android.mk
index 1101635..f83aa5a 100644
--- a/guest/hals/hwcomposer/Android.mk
+++ b/guest/hals/hwcomposer/Android.mk
@@ -37,7 +37,8 @@
LOCAL_SHARED_LIBRARIES := \
libbase \
liblog \
- libvsoc_framebuffer
+ libvsoc_framebuffer \
+ libvsoc
ifeq (0, $(shell test $(PLATFORM_SDK_VERSION) -ge 21; echo $$?))
LOCAL_MODULE_RELATIVE_PATH := hw
diff --git a/guest/hals/hwcomposer/hwcomposer.cpp b/guest/hals/hwcomposer/hwcomposer.cpp
index f3cddff..48b9c87 100644
--- a/guest/hals/hwcomposer/hwcomposer.cpp
+++ b/guest/hals/hwcomposer/hwcomposer.cpp
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-#include <common/vsoc/framebuffer/fb_bcast_region.h>
+#include <common/vsoc/framebuffer/fb_bcast_region_view.h>
#include <guest/hals/gralloc/gralloc_vsoc_priv.h>
#include <hardware/hwcomposer.h>
#include <hardware/hwcomposer_defs.h>
@@ -26,7 +26,14 @@
// This file contains just a skeleton hwcomposer, the first step in the
// multisided vsoc hwcomposer for cuttlefish.
-using vsoc::framebuffer::FBBroadcastRegion;
+using vsoc::framebuffer::FBBroadcastRegionView;
+
+// TODO(jemoreira): FBBroadcastRegionView may belong in the HWC region
+
+FBBroadcastRegionView* GetFBBroadcastRegionView() {
+ static FBBroadcastRegionView instance;
+ return &instance;
+}
namespace {
@@ -89,7 +96,7 @@
pthread_t vsync_thread;
int64_t vsync_base_timestamp;
int32_t vsync_period_ns;
- FBBroadcastRegion* fb_broadcast;
+ FBBroadcastRegionView* fb_broadcast;
uint32_t frame_num;
};
@@ -250,15 +257,15 @@
int32_t vsoc_hwc_attribute(vsoc_hwc_device* pdev, uint32_t attribute) {
switch (attribute) {
case HWC_DISPLAY_VSYNC_PERIOD:
- return 1000000000/pdev->fb_broadcast->display_properties().refresh_rate_hz();
+ return 1000000000/pdev->fb_broadcast->refresh_rate_hz();
case HWC_DISPLAY_WIDTH:
- return pdev->fb_broadcast->display_properties().x_res();
+ return pdev->fb_broadcast->x_res();
case HWC_DISPLAY_HEIGHT:
- return pdev->fb_broadcast->display_properties().y_res();
+ return pdev->fb_broadcast->y_res();
case HWC_DISPLAY_DPI_X:
case HWC_DISPLAY_DPI_Y:
// The number of pixels per thousand inches
- return pdev->fb_broadcast->display_properties().dpi() * 1000;
+ return pdev->fb_broadcast->dpi() * 1000;
case HWC_DISPLAY_COLOR_TRANSFORM:
// TODO(jemoreira): Add the other color transformations
return HAL_COLOR_TRANSFORM_IDENTITY;
@@ -336,8 +343,8 @@
dev->base.getDisplayConfigs = hwc_getDisplayConfigs;
dev->base.getDisplayAttributes = hwc_getDisplayAttributes;
- dev->fb_broadcast = FBBroadcastRegion::GetInstance();
- if (!dev->fb_broadcast) {
+ dev->fb_broadcast = GetFBBroadcastRegionView();
+ if (!dev->fb_broadcast->Open()) {
ALOGE("Unable to open framebuffer broadcaster (%s)", __FUNCTION__);
delete dev;
return -1;
diff --git a/host/commands/launch/Android.bp b/host/commands/launch/Android.bp
index afe7f77..3aa0235 100644
--- a/host/commands/launch/Android.bp
+++ b/host/commands/launch/Android.bp
@@ -2,11 +2,13 @@
name: "launch_cuttlefish",
srcs: [
"main.cc",
+ "fb_bcast_region_handler.cc",
],
header_libs: [
"cuttlefish_glog",
],
static_libs: [
+ "vsoc_lib",
"libcuttlefish_host_config",
"libivserver",
"libvadb",
diff --git a/host/commands/launch/fb_bcast_region_handler.cc b/host/commands/launch/fb_bcast_region_handler.cc
new file mode 100644
index 0000000..54ca92d
--- /dev/null
+++ b/host/commands/launch/fb_bcast_region_handler.cc
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <glog/logging.h>
+#include <gflags/gflags.h>
+#include "common/vsoc/framebuffer/fb_bcast_region_view.h"
+
+// TODO(jemoreira): Change these to something sensible once everything is
+// ported.
+DEFINE_int32(x_res, 1280, "Width of the screen in pixels");
+DEFINE_int32(y_res, 720, "Height of the screen in pixels");
+DEFINE_int32(dpi, 160, "Pixels per inch for the screen");
+
+void IniitializeFBBroadcastRegion(const char* domain) {
+ vsoc::framebuffer::FBBroadcastRegionView region;
+ if (!region.Open(domain)) {
+ LOG(INFO) << "Framebuffer region was not found";
+ return;
+ }
+ auto dest = region.data();
+ dest->x_res = FLAGS_x_res;
+ dest->y_res = FLAGS_y_res;
+ dest->dpi = FLAGS_dpi;
+}
diff --git a/host/commands/launch/main.cc b/host/commands/launch/main.cc
index 808354e..5e9ecb2 100644
--- a/host/commands/launch/main.cc
+++ b/host/commands/launch/main.cc
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -17,6 +33,7 @@
#include "host/libs/ivserver/options.h"
#include "host/libs/usbip/server.h"
#include "host/libs/vadb/virtual_adb_server.h"
+#include "host/vsoc/lib/region_control.h"
namespace {
std::string StringFromEnv(const char* varname, std::string defval) {
@@ -44,7 +61,6 @@
"Target location for the shmem file.");
DEFINE_int32(shmsize, 0, "(ignored)");
DEFINE_string(qemusocket, "/tmp/ivshmem_socket_qemu", "QEmu socket path");
-DEFINE_string(clientsocket, "/tmp/ivshmem_socket_client", "Client socket path");
DEFINE_string(system_image_dir,
StringFromEnv("ANDROID_PRODUCT_OUT", StringFromEnv("HOME", ".")),
@@ -58,6 +74,7 @@
DEFINE_string(vendor_image, "", "Location of the vendor partition image.");
DEFINE_string(usbipsocket, "android_usbip", "Name of the USB/IP socket.");
+DEFINE_string(vsoc_domain, vsoc::DEFAULT_DOMAIN, "Client socket path");
DEFINE_bool(log_xml, false, "Log the XML machine configuration");
namespace {
@@ -125,7 +142,7 @@
public:
IVServerManager(const Json::Value& json_root)
: server_(ivserver::IVServerOptions(FLAGS_layout, FLAGS_mempath,
- FLAGS_qemusocket, FLAGS_clientsocket),
+ FLAGS_qemusocket, FLAGS_vsoc_domain),
json_root) {}
~IVServerManager() = default;
diff --git a/host/frontend/vnc_server/Android.bp b/host/frontend/vnc_server/Android.bp
index 7d93ba5..87e4590 100644
--- a/host/frontend/vnc_server/Android.bp
+++ b/host/frontend/vnc_server/Android.bp
@@ -26,6 +26,7 @@
"virtual_input_device.cpp",
"vnc_client_connection.cpp",
"vnc_server.cpp",
+ "vnc_utils.cpp",
],
header_libs: [
"cuttlefish_glog",
diff --git a/host/frontend/vnc_server/main.cpp b/host/frontend/vnc_server/main.cpp
index 046b2b7..02a5f84 100644
--- a/host/frontend/vnc_server/main.cpp
+++ b/host/frontend/vnc_server/main.cpp
@@ -19,15 +19,22 @@
#include <gflags/gflags.h>
+#include "host/vsoc/lib/region_control.h"
#include "host/frontend/vnc_server/vnc_server.h"
+#include "host/frontend/vnc_server/vnc_utils.h"
+#include "common/libs/glog/logging.h"
DEFINE_bool(agressive, false, "Whether to use agressive server");
DEFINE_int32(port, 6444, "Port where to listen for connections");
+DEFINE_string(vsoc_domain, vsoc::DEFAULT_DOMAIN, "Client socket path");
int main(int argc, char* argv[]) {
using ::android::base::ERROR;
::android::base::InitLogging(argv, android::base::StderrLogger);
::gflags::ParseCommandLineFlags(&argc, &argv, true);
+ if (!avd::vnc::GetFBBroadcastRegionView()->Open(FLAGS_vsoc_domain.c_str())) {
+ LOG(FATAL) << "Unable to open FBBroadcastRegion";
+ }
avd::vnc::VncServer vnc_server(FLAGS_port, FLAGS_agressive);
vnc_server.MainLoop();
}
diff --git a/host/frontend/vnc_server/simulated_hw_composer.cpp b/host/frontend/vnc_server/simulated_hw_composer.cpp
index 5052b94..db9b866 100644
--- a/host/frontend/vnc_server/simulated_hw_composer.cpp
+++ b/host/frontend/vnc_server/simulated_hw_composer.cpp
@@ -28,10 +28,9 @@
#ifdef FUZZ_TEST_VNC
engine_{std::random_device{}()},
#endif
- fb_region_{vsoc::framebuffer::FBBroadcastRegion::GetInstance()},
bb_{bb},
stripes_(kMaxQueueElements, &SimulatedHWComposer::EraseHalfOfElements) {
- stripe_maker_ = std::thread(&SimulatedHWComposer::MakeStripes, this);
+ stripe_maker_ = std::thread(&SimulatedHWComposer::MakeStripes, this);
}
SimulatedHWComposer::~SimulatedHWComposer() {
@@ -78,7 +77,7 @@
while (!closed()) {
bb_->WaitForAtLeastOneClientConnection();
vsoc_reg_off_t buffer_offset =
- fb_region_->WaitForNewFrameSince(&previous_seq_num);
+ GetFBBroadcastRegionView()->WaitForNewFrameSince(&previous_seq_num);
const auto* frame_start =
GrallocBufferRegion::GetInstance()->OffsetToBufferPtr(buffer_offset);
diff --git a/host/frontend/vnc_server/simulated_hw_composer.h b/host/frontend/vnc_server/simulated_hw_composer.h
index 2ac9eb7..0a50d62 100644
--- a/host/frontend/vnc_server/simulated_hw_composer.h
+++ b/host/frontend/vnc_server/simulated_hw_composer.h
@@ -25,7 +25,7 @@
#include "common/libs/thread_safe_queue/thread_safe_queue.h"
#include "common/libs/threads/thread_annotations.h"
-#include "common/vsoc/framebuffer/fb_bcast_region.h"
+#include "common/vsoc/framebuffer/fb_bcast_region_view.h"
#include "host/frontend/vnc_server/blackboard.h"
namespace avd {
@@ -57,7 +57,6 @@
constexpr static std::size_t kMaxQueueElements = 64;
bool closed_ GUARDED_BY(m_){};
std::mutex m_;
- vsoc::framebuffer::FBBroadcastRegion* fb_region_;
BlackBoard* bb_{};
ThreadSafeQueue<Stripe> stripes_;
std::thread stripe_maker_;
diff --git a/host/frontend/vnc_server/vnc_utils.cpp b/host/frontend/vnc_server/vnc_utils.cpp
new file mode 100644
index 0000000..78414fb
--- /dev/null
+++ b/host/frontend/vnc_server/vnc_utils.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "common/vsoc/framebuffer/fb_bcast_region_view.h"
+
+using vsoc::framebuffer::FBBroadcastRegionView;
+
+namespace avd {
+namespace vnc {
+
+FBBroadcastRegionView* GetFBBroadcastRegionView() {
+ static FBBroadcastRegionView instance;
+ return &instance;
+}
+
+} // namespace vnc
+} // namespace avd
diff --git a/host/frontend/vnc_server/vnc_utils.h b/host/frontend/vnc_server/vnc_utils.h
index 9822a7c..ff75a8b 100644
--- a/host/frontend/vnc_server/vnc_utils.h
+++ b/host/frontend/vnc_server/vnc_utils.h
@@ -21,7 +21,7 @@
#include <utility>
#include <vector>
-#include "common/vsoc/framebuffer/fb_bcast_region.h"
+#include "common/vsoc/framebuffer/fb_bcast_region_view.h"
namespace avd {
namespace vnc {
@@ -62,24 +62,20 @@
ScreenOrientation orientation{};
};
+vsoc::framebuffer::FBBroadcastRegionView* GetFBBroadcastRegionView();
+
inline int BytesPerPixel() {
- return vsoc::framebuffer::FBBroadcastRegion::GetInstance()
- ->display_properties()
- .bytes_per_pixel();
+ return GetFBBroadcastRegionView()->bytes_per_pixel();
}
// The width of the screen regardless of orientation. Does not change.
inline int ActualScreenWidth() {
- return vsoc::framebuffer::FBBroadcastRegion::GetInstance()
- ->display_properties()
- .x_res();
+ return GetFBBroadcastRegionView()->x_res();
}
// The height of the screen regardless of orientation. Does not change.
inline int ActualScreenHeight() {
- return vsoc::framebuffer::FBBroadcastRegion::GetInstance()
- ->display_properties()
- .y_res();
+ return GetFBBroadcastRegionView()->y_res();
}
inline int ScreenSizeInBytes() {
diff --git a/host/vsoc/lib/host_region.h b/host/vsoc/lib/host_region.h
deleted file mode 100644
index 3c12896..0000000
--- a/host/vsoc/lib/host_region.h
+++ /dev/null
@@ -1,119 +0,0 @@
-#pragma once
-
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-// Object that represents a region on the Host
-
-#include "common/vsoc/lib/region.h"
-
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <atomic>
-#include <cstdint>
-
-#include "common/libs/fs/shared_fd.h"
-#include "common/libs/fs/shared_select.h"
-#include "uapi/vsoc_shm.h"
-
-namespace vsoc {
-
-/**
- * Accessor class for VSoC regions designed for use from processes on the
- * host. This mainly affects the implementatio of Open.
- *
- * Subclass to use this or use TypedRegionView with a suitable Layout.
- */
-class OpenableRegionView : public RegionView {
- public:
- virtual ~OpenableRegionView() {}
-
- // Returns a pointer to the table that will be scanned for signals
- virtual vsoc_signal_table_layout* incoming_signal_table() {
- return ®ion_desc_.guest_to_host_signal_table;
- }
-
- // Returns a pointer to the table that will be used to post signals
- virtual vsoc_signal_table_layout* outgoing_signal_table() {
- return ®ion_desc_.host_to_guest_signal_table;
- }
-
- // Interrupt our peer, causing it to scan the outgoing_signal_table
- virtual void InterruptPeer() {
- if (!region_offset_to_pointer<std::atomic<uint32_t>>(
- outgoing_signal_table()->interrupt_signalled_offset)
- ->exchange(1)) {
- uint64_t one = 1;
- ssize_t rval = outgoing_interrupt_fd_->Write(&one, sizeof(one));
- if (rval != sizeof(one)) {
- LOG(FATAL) << __FUNCTION__ << ": rval (" << rval << ") != sizeof(one))";
- }
- }
- }
-
- // Wake the local signal table scanner. Primarily used during shutdown
- virtual void InterruptSelf() {
- uint64_t one = 1;
- ssize_t rval = incoming_interrupt_fd_->Write(&one, sizeof(one));
- if (rval != sizeof(one)) {
- LOG(FATAL) << __FUNCTION__ << ": rval (" << rval << ") != sizeof(one))";
- }
- }
-
- // Wait for an interrupt from our peer
- virtual void WaitForInterrupt() {
- while (1) {
- if (region_offset_to_pointer<std::atomic<uint32_t>>(
- incoming_signal_table()->interrupt_signalled_offset)
- ->exchange(0)) {
- // The eventfd isn't cleared by design. This is a optimization: if
- // an interrupt is pending we avoid the sleep, lowering the latency.
- // It does mean that we do some extra work the next time that we go
- // to sleep. However, an extra delay in sleeping is preferable to a
- // delay in waking.
- return;
- }
- // Check then act isn't a problem here: the other side does
- // the following things in exactly this order:
- // 1. exchanges 1 with interrupt_signalled
- // 2. if interrupt_signalled was 0 it increments the eventfd
- // eventfd increments are persistent, so if interrupt_signalled was set
- // back to 1 while we are going to sleep the sleep will return
- // immediately.
- uint64_t missed{};
- avd::SharedFDSet readset;
- readset.Set(incoming_interrupt_fd_);
- avd::Select(&readset, NULL, NULL, NULL);
- ssize_t rval = incoming_interrupt_fd_->Read(&missed, sizeof(missed));
- if (rval != sizeof(missed)) {
- LOG(FATAL) << __FUNCTION__ << ": rval (" << rval
- << ") != sizeof(missed))";
- }
- if (!missed) {
- LOG(FATAL) << __FUNCTION__ << ": woke with 0 interrupts";
- }
- }
- }
-
- protected:
- OpenableRegionView() {}
-
- bool Open(const char* name, const char* domain = nullptr);
-
- avd::SharedFD incoming_interrupt_fd_;
- avd::SharedFD outgoing_interrupt_fd_;
-};
-} // namespace vsoc
diff --git a/host/vsoc/lib/region_control.cpp b/host/vsoc/lib/region_control.cpp
index 37f45ab..f8b5c09 100644
--- a/host/vsoc/lib/region_control.cpp
+++ b/host/vsoc/lib/region_control.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
#include "common/vsoc/lib/region_view.h"
+#include "host/vsoc/lib/region_control.h"
#define LOG_TAG "vsoc: region_host"
@@ -124,8 +125,6 @@
// Default path to the ivshmem_server socket. This can vary when we're
// launching multiple AVDs.
-const char DEFAULT_DOMAIN[] = "/tmp/ivshmem_socket_client";
-
constexpr int kMaxSupportedProtocolVersion = 0;
bool HostRegionControl::InitializeRegion() {
diff --git a/host/vsoc/lib/region_control.h b/host/vsoc/lib/region_control.h
new file mode 100644
index 0000000..e7d3e5c
--- /dev/null
+++ b/host/vsoc/lib/region_control.h
@@ -0,0 +1,23 @@
+#pragma once
+
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* Host-specific values associated with RegionControl. */
+
+namespace vsoc {
+const char* const DEFAULT_DOMAIN{"/tmp/ivshmem_socket_client"};
+} // namespace vsoc