Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eb7d088b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I9f2ea67c,I34588df1,I88a56236

* changes:
  Use generic libpdx event bits facility in libvrflinger and bufferhubd.
  Add libvrflinger for use in SurfaceFlinger
  Export surface flinger includes
parents 61a21618 3079cb7c
Loading
Loading
Loading
Loading
+0 −17
Original line number Diff line number Diff line
@@ -58,23 +58,6 @@ enum VrManagerTransaction {
    GET_VR_MODE_STATE,
};

enum class VrDisplayStateTransaction {
  ON_DISPLAY_STATE_CHANGED = IBinder::FIRST_CALL_TRANSACTION,
};

class IVrDisplayStateService : public IInterface {
public:
    DECLARE_META_INTERFACE(VrDisplayStateService)

    virtual void displayAvailable(bool available) = 0;
};

class BnVrDisplayStateService : public BnInterface<IVrDisplayStateService> {
public:
    status_t onTransact(uint32_t code, const Parcel &data, Parcel *reply,
                        uint32_t flags = 0) override;
};

};  // namespace android

#endif // ANDROID_VR_MANAGER_H
+12 −2
Original line number Diff line number Diff line
@@ -71,6 +71,15 @@ class BufferHubBuffer : public pdx::Client {
  }

  using Client::event_fd;

  Status<int> GetEventMask(int events) {
    if (auto* client_channel = GetChannel()) {
      return client_channel->GetEventMask(events);
    } else {
      return pdx::ErrorStatus(EINVAL);
    }
  }

  native_handle_t* native_handle() const {
    return const_cast<native_handle_t*>(slices_[0].handle());
  }
@@ -158,8 +167,9 @@ class BufferProducer : public pdx::ClientBase<BufferProducer, BufferHubBuffer> {
  int Post(const LocalHandle& ready_fence) {
    return Post(ready_fence, nullptr, 0);
  }
  template <typename Meta, typename = typename std::enable_if<
                               !std::is_void<Meta>::value>::type>
  template <
      typename Meta,
      typename = typename std::enable_if<!std::is_void<Meta>::value>::type>
  int Post(const LocalHandle& ready_fence, const Meta& meta) {
    return Post(ready_fence, &meta, sizeof(meta));
  }
+87 −0
Original line number Diff line number Diff line
# Copyright (C) 2008 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.

LOCAL_PATH := $(call my-dir)

sourceFiles := \
	acquired_buffer.cpp \
	compositor.cpp \
	debug_hud_data.cpp \
	debug_hud_view.cpp \
	display_manager_service.cpp \
	display_service.cpp \
	display_surface.cpp \
	epoll_event_dispatcher.cpp \
	hardware_composer.cpp \
	screenshot_service.cpp \
	surface_channel.cpp \
	video_compositor.cpp \
	video_mesh_surface.cpp \
	vr_flinger.cpp \
	vsync_service.cpp

includeFiles := $(LOCAL_PATH)/include

staticLibraries := \
	libsurfaceflingerincludes \
	libhwcomposer-command-buffer \
	libbufferhub \
	libbufferhubqueue \
	libeds \
	libdisplay \
	libdvrcommon \
	libdvrgraphics \
	libperformance \
	libsensor \
	libpdx_default_transport \

sharedLibraries := \
	android.dvr.composer@1.0 \
	android.hardware.graphics.allocator@2.0 \
	android.hardware.graphics.composer@2.1 \
	libbinder \
	libbase \
	libcutils \
	liblog \
	libhardware \
	libutils \
	libEGL \
	libGLESv1_CM \
	libGLESv2 \
	libvulkan \
	libui \
	libgui \
	libsync \
	libhidlbase \
	libhidltransport \
	libfmq \

include $(CLEAR_VARS)
LOCAL_SRC_FILES := $(sourceFiles)
LOCAL_C_INCLUDES := $(includeFiles)
LOCAL_EXPORT_C_INCLUDE_DIRS := $(includeFiles)

LOCAL_CFLAGS += -DLOG_TAG=\"vr_flinger\"
LOCAL_CFLAGS += -DTRACE=0
LOCAL_CFLAGS += -DATRACE_TAG=ATRACE_TAG_GRAPHICS
LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
ifeq ($(TARGET_USES_QCOM_BSP), true)
    LOCAL_C_INCLUDES += hardware/qcom/display/libgralloc
    LOCAL_C_INCLUDES += hardware/qcom/display/libqdutils
    LOCAL_SHARED_LIBRARIES += libqdutils
endif
LOCAL_SHARED_LIBRARIES := $(sharedLibraries)
LOCAL_WHOLE_STATIC_LIBRARIES := $(staticLibraries)
LOCAL_MODULE := libvrflinger
include $(BUILD_STATIC_LIBRARY)
+100 −0
Original line number Diff line number Diff line
#include "acquired_buffer.h"

#include <log/log.h>
#include <sync/sync.h>

using android::pdx::LocalHandle;

namespace android {
namespace dvr {

AcquiredBuffer::AcquiredBuffer(const std::shared_ptr<BufferConsumer>& buffer,
                               LocalHandle acquire_fence, uint64_t /*sequence*/)
    : buffer_(buffer), acquire_fence_(std::move(acquire_fence)) {}

AcquiredBuffer::AcquiredBuffer(const std::shared_ptr<BufferConsumer>& buffer,
                               int* error) {
  LocalHandle fence;
  const int ret = buffer->Acquire(&fence);

  if (error)
    *error = ret;

  if (ret < 0) {
    ALOGW("AcquiredBuffer::AcquiredBuffer: Failed to acquire buffer: %s",
          strerror(-ret));
    buffer_ = nullptr;
    // Default construct sets acquire_fence_ to empty.
  } else {
    buffer_ = buffer;
    acquire_fence_ = std::move(fence);
  }
}

AcquiredBuffer::AcquiredBuffer(AcquiredBuffer&& other)
    : buffer_(std::move(other.buffer_)),
      acquire_fence_(std::move(other.acquire_fence_)) {}

AcquiredBuffer::~AcquiredBuffer() { Release(LocalHandle(kEmptyFence)); }

AcquiredBuffer& AcquiredBuffer::operator=(AcquiredBuffer&& other) {
  if (this != &other) {
    Release(LocalHandle(kEmptyFence));

    buffer_ = std::move(other.buffer_);
    acquire_fence_ = std::move(other.acquire_fence_);
  }
  return *this;
}

bool AcquiredBuffer::IsAvailable() const {
  if (IsEmpty())
    return false;

  // Only check the fence if the acquire fence is not empty.
  if (acquire_fence_) {
    const int ret = sync_wait(acquire_fence_.Get(), 0);
    ALOGD_IF(TRACE || (ret < 0 && errno != ETIME),
             "AcquiredBuffer::IsAvailable: acquire_fence_=%d sync_wait()=%d "
             "errno=%d.",
             acquire_fence_.Get(), ret, ret < 0 ? errno : 0);
    if (ret == 0) {
      // The fence is completed, so to avoid further calls to sync_wait we close
      // it here.
      acquire_fence_.Close();
    }
    return ret == 0;
  } else {
    return true;
  }
}

LocalHandle AcquiredBuffer::ClaimAcquireFence() {
  return std::move(acquire_fence_);
}

std::shared_ptr<BufferConsumer> AcquiredBuffer::ClaimBuffer() {
  return std::move(buffer_);
}

int AcquiredBuffer::Release(LocalHandle release_fence) {
  if (buffer_) {
    // Close the release fence since we can't transfer it with an async release.
    release_fence.Close();
    const int ret = buffer_->ReleaseAsync();
    if (ret < 0) {
      ALOGE("AcquiredBuffer::Release: Failed to release buffer %d: %s",
            buffer_->id(), strerror(-ret));
      if (ret != -ESHUTDOWN)
        return ret;
    }

    buffer_ = nullptr;
    acquire_fence_.Close();
  }

  return 0;
}

}  // namespace dvr
}  // namespace android
+82 −0
Original line number Diff line number Diff line
#ifndef ANDROID_DVR_SERVICES_DISPLAYD_ACQUIRED_BUFFER_H_
#define ANDROID_DVR_SERVICES_DISPLAYD_ACQUIRED_BUFFER_H_

#include <pdx/file_handle.h>
#include <private/dvr/buffer_hub_client.h>

#include <memory>

namespace android {
namespace dvr {

// Manages the ACQUIRE/RELEASE ownership cycle of a BufferConsumer.
class AcquiredBuffer {
 public:
  static constexpr int kEmptyFence = pdx::LocalHandle::kEmptyFileHandle;

  AcquiredBuffer() : buffer_(nullptr), acquire_fence_(kEmptyFence) {}

  // Constructs an AcquiredBuffer from a BufferConsumer pointer and an acquire
  // fence. The BufferConsumer MUST be in the ACQUIRED state prior to calling
  // this constructor; the constructor does not attempt to ACQUIRE the buffer
  // itself.
  AcquiredBuffer(const std::shared_ptr<BufferConsumer>& buffer,
                 pdx::LocalHandle acquire_fence, uint64_t sequence);

  // Constructs an AcquiredBuffer from a BufferConsumer. The BufferConsumer MUST
  // be in the POSTED state prior to calling this constructor, as this
  // constructor attempts to ACQUIRE the buffer. If ACQUIRING the buffer fails
  // this instance is left in the empty state. An optional error code is
  // returned in |error|, which may be nullptr if not needed.
  AcquiredBuffer(const std::shared_ptr<BufferConsumer>& buffer, int* error);

  // Move constructor. Behaves similarly to the move assignment operator below.
  AcquiredBuffer(AcquiredBuffer&& other);

  ~AcquiredBuffer();

  // Move assignment operator. Moves the BufferConsumer and acquire fence from
  // |other| into this instance after RELEASING the current BufferConsumer and
  // closing the acquire fence. After the move |other| is left in the empty
  // state.
  AcquiredBuffer& operator=(AcquiredBuffer&& other);

  // Accessors for the underlying BufferConsumer, the acquire fence, and the
  // use-case specific sequence value from the acquisition (see
  // dreamos/buffer_hub_client.h).
  std::shared_ptr<BufferConsumer> buffer() const { return buffer_; }
  int acquire_fence() const { return acquire_fence_.Get(); }

  // When non-empty, returns true if the acquired fence was signaled (or if the
  // fence is empty). Returns false when empty or if the fence is not signaled.
  bool IsAvailable() const;

  bool IsEmpty() const { return buffer_ == nullptr; }

  // Returns the acquire fence, passing ownership to the caller.
  pdx::LocalHandle ClaimAcquireFence();

  // Returns the buffer, passing ownership to the caller. Caller is responsible
  // for calling Release on the returned buffer.
  std::shared_ptr<BufferConsumer> ClaimBuffer();

  // Releases the BufferConsumer, passing the release fence in |release_fence|
  // to the producer. On success, the BufferConsumer and acquire fence are set
  // to empty state; if release fails, the BufferConsumer and acquire fence are
  // left in place and a negative error code is returned.
  int Release(pdx::LocalHandle release_fence);

 private:
  AcquiredBuffer(const AcquiredBuffer&) = delete;
  void operator=(const AcquiredBuffer&) = delete;

  std::shared_ptr<BufferConsumer> buffer_;
  // Mutable so that the fence can be closed when it is determined to be
  // signaled during IsAvailable().
  mutable pdx::LocalHandle acquire_fence_;
};

}  // namespace dvr
}  // namespace android

#endif  // ANDROID_DVR_SERVICES_DISPLAYD_ACQUIRED_BUFFER_H_
Loading