(reland) Retire framebuffer_device_t from gralloc
gralloc is deprecated. The only place we refer
to framebuffer_device_t is HWC2. This change
moves functionality of framebuffer_device_t to
HWC2.
Bug: 145244672
Test: boot, host side tests
Change-Id: I8da21373fe435517e281835acf856b13172f5d4d
Signed-off-by: Roman Kiryanov <rkir@google.com>
diff --git a/system/gralloc/gralloc_30.cpp b/system/gralloc/gralloc_30.cpp
index 7491fb4..6597405 100644
--- a/system/gralloc/gralloc_30.cpp
+++ b/system/gralloc/gralloc_30.cpp
@@ -709,116 +709,6 @@
template <class T> T& unconst(const T& x) { return const_cast<T&>(x); }
-class goldfish_fb30_device_t {
-private:
- framebuffer_device_t device;
- goldfish_gralloc30_module_t* gralloc_module;
-
-public:
- goldfish_fb30_device_t(private_module_t* module)
- : device({}), gralloc_module(module->impl()) {
- device.common = make_hw_device(module->to_hw_module(),
- &s_goldfish_fb30_device_close);
- device.setSwapInterval = &s_setSwapInterval;
- device.post = &s_post;
-
- {
- const HostConnectionSession conn = gralloc_module->getHostConnectionSession();
- ExtendedRCEncoderContext *const rcEnc = conn.getRcEncoder();
-
- unconst(device.flags) = 0;
- unconst(device.width) = rcEnc->rcGetFBParam(rcEnc, FB_WIDTH);
- unconst(device.height) = rcEnc->rcGetFBParam(rcEnc, FB_HEIGHT);;
- unconst(device.stride) = device.width;
- unconst(device.format) = HAL_PIXEL_FORMAT_RGBA_8888;
- unconst(device.xdpi) = rcEnc->rcGetFBParam(rcEnc, FB_XDPI);
- unconst(device.ydpi) = rcEnc->rcGetFBParam(rcEnc, FB_YDPI);
- unconst(device.fps) = rcEnc->rcGetFBParam(rcEnc, FB_FPS);
- unconst(device.minSwapInterval) = rcEnc->rcGetFBParam(rcEnc, FB_MIN_SWAP_INTERVAL);
- unconst(device.maxSwapInterval) = rcEnc->rcGetFBParam(rcEnc, FB_MAX_SWAP_INTERVAL);
- }
- }
-
- hw_device_t* get_hw_device_ptr() { return &device.common; }
-
-private:
- int setSwapInterval(const int interval) {
- const HostConnectionSession conn = gralloc_module->getHostConnectionSession();
- ExtendedRCEncoderContext *const rcEnc = conn.getRcEncoder();
-
- rcEnc->rcFBSetSwapInterval(rcEnc, interval);
- return 0;
- }
-
- int post(cb_handle_t& handle) {
- if (!(handle.usage & GRALLOC_USAGE_HW_FB)) {
- RETURN_ERROR_CODE(-EINVAL);
- }
-
- if (handle.hostHandle) {
- const HostConnectionSession conn = gralloc_module->getHostConnectionSession();
- ExtendedRCEncoderContext *const rcEnc = conn.getRcEncoder();
-
- rcEnc->rcFBPost(rcEnc, handle.hostHandle);
- }
-
- return 0;
- }
-
- static int s_goldfish_fb30_device_close(struct hw_device_t *d) {
- goldfish_fb30_device_t* fbd = from_hw_device(d);
- if (!fbd) {
- RETURN_ERROR_CODE(-EINVAL);
- }
-
- std::unique_ptr<goldfish_fb30_device_t> deleter(fbd);
- return 0;
- }
-
- static int s_setSwapInterval(struct framebuffer_device_t* d, int interval) {
- goldfish_fb30_device_t* fbd = from_framebuffer_device(d);
- if (!fbd) {
- RETURN_ERROR_CODE(-EINVAL);
- }
-
- return fbd->setSwapInterval(interval);
- }
-
- static int s_post(struct framebuffer_device_t* d, buffer_handle_t h) {
- goldfish_fb30_device_t* fbd = from_framebuffer_device(d);
- if (!fbd) {
- RETURN_ERROR_CODE(-EINVAL);
- }
-
- cb_handle_t* handle = cb_handle_t::from_unconst(h);
- if (!handle) {
- RETURN_ERROR_CODE(-EINVAL);
- }
-
- return fbd->post(*handle);
- }
-
- static goldfish_fb30_device_t* from_hw_device(hw_device_t* d) {
- if (!d) {
- RETURN_ERROR(nullptr);
- }
-
- if (d->close == &s_goldfish_fb30_device_close) {
- return reinterpret_cast<goldfish_fb30_device_t*>(d);
- } else {
- RETURN_ERROR(nullptr);
- }
- }
-
- static goldfish_fb30_device_t* from_framebuffer_device(framebuffer_device_t* d) {
- if (!d) {
- RETURN_ERROR(nullptr);
- }
-
- return from_hw_device(&d->common);
- }
-};
-
const uint32_t CB_HANDLE_MAGIC_30 = CB_HANDLE_MAGIC_BASE | 0x2;
struct cb_handle_30_t : public cb_handle_t {
@@ -1137,18 +1027,6 @@
return 0;
}
-int gralloc_device_open_fb0(private_module_t* module, hw_device_t** device) {
- std::unique_ptr<goldfish_fb30_device_t> fb_device =
- std::make_unique<goldfish_fb30_device_t>(module);
- if (!fb_device) {
- RETURN_ERROR_CODE(-ENOMEM);
- }
-
- *device = fb_device->get_hw_device_ptr();
- fb_device.release();
- return 0;
-}
-
int gralloc_device_open(const hw_module_t* hw_module,
const char* name,
hw_device_t** device) {
@@ -1167,10 +1045,6 @@
return gralloc_device_open_gpu0(module, device);
}
- if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
- return gralloc_device_open_fb0(module, device);
- }
-
RETURN_ERROR_CODE(-EINVAL);
}
diff --git a/system/gralloc/gralloc_old.cpp b/system/gralloc/gralloc_old.cpp
index ace8c9f..683c288 100644
--- a/system/gralloc/gralloc_old.cpp
+++ b/system/gralloc/gralloc_old.cpp
@@ -419,13 +419,6 @@
return should_unmap;
}
-//
-// Our framebuffer device structure
-//
-struct fb_device_t {
- framebuffer_device_t device;
-};
-
static int map_buffer(cb_handle_old_t *cb, void **vaddr)
{
if (cb->bufferFd < 0) {
@@ -1001,107 +994,6 @@
return 0;
}
-static int fb_compositionComplete(struct framebuffer_device_t* dev)
-{
- (void)dev;
-
- return 0;
-}
-
-//
-// Framebuffer device functions
-//
-static int fb_post(struct framebuffer_device_t* dev, buffer_handle_t buffer)
-{
- fb_device_t *fbdev = (fb_device_t *)dev;
- if (!fbdev) {
- return -EINVAL;
- }
- const cb_handle_old_t *cb = cb_handle_old_t::from(buffer);
- if (!cb) {
- return -EINVAL;
- }
- if (!cb->canBePosted()) {
- return -EINVAL;
- }
-
- // Make sure we have host connection
- DEFINE_AND_VALIDATE_HOST_CONNECTION;
-
- // increment the post count of the buffer
- int32_t *postCountPtr = (int32_t *)cb->getBufferPtr();
- if (!postCountPtr) {
- // This should not happen
- return -EINVAL;
- }
- (*postCountPtr)++;
-
- // send post request to host
- hostCon->lock();
- rcEnc->rcFBPost(rcEnc, cb->hostHandle);
- hostCon->flush();
- hostCon->unlock();
-
- return 0;
-}
-
-/* unused (for now)
-static int fb_setUpdateRect(struct framebuffer_device_t* dev,
- int l, int t, int w, int h)
-{
- fb_device_t *fbdev = (fb_device_t *)dev;
-
- (void)l;
- (void)t;
- (void)w;
- (void)h;
-
- if (!fbdev) {
- return -EINVAL;
- }
-
- // Make sure we have host connection
- DEFINE_AND_VALIDATE_HOST_CONNECTION;
-
- // send request to host
- // TODO: XXX - should be implemented
- //rcEnc->rc_XXX
-
- return 0;
-}
-*/
-
-static int fb_setSwapInterval(struct framebuffer_device_t* dev,
- int interval)
-{
- fb_device_t *fbdev = (fb_device_t *)dev;
-
- if (!fbdev) {
- return -EINVAL;
- }
-
- // Make sure we have host connection
- DEFINE_AND_VALIDATE_HOST_CONNECTION;
-
- // send request to host
- hostCon->lock();
- rcEnc->rcFBSetSwapInterval(rcEnc, interval);
- hostCon->flush();
- hostCon->unlock();
-
- return 0;
-}
-
-static int fb_close(struct hw_device_t *dev)
-{
- fb_device_t *fbdev = (fb_device_t *)dev;
-
- free(fbdev);
-
- return 0;
-}
-
-
//
// gralloc module functions - refcount + locking interface
//
@@ -1598,67 +1490,6 @@
*device = &dev->device.common;
status = 0;
}
- else if (!strcmp(name, GRALLOC_HARDWARE_FB0)) {
-
- // return error if connection with host can not be established
- DEFINE_AND_VALIDATE_HOST_CONNECTION;
- hostCon->lock();
-
- //
- // Query the host for Framebuffer attributes
- //
- D("gralloc: query Frabuffer attribs\n");
- EGLint width = rcEnc->rcGetFBParam(rcEnc, FB_WIDTH);
- D("gralloc: width=%d\n", width);
- EGLint height = rcEnc->rcGetFBParam(rcEnc, FB_HEIGHT);
- D("gralloc: height=%d\n", height);
- EGLint xdpi = rcEnc->rcGetFBParam(rcEnc, FB_XDPI);
- D("gralloc: xdpi=%d\n", xdpi);
- EGLint ydpi = rcEnc->rcGetFBParam(rcEnc, FB_YDPI);
- D("gralloc: ydpi=%d\n", ydpi);
- EGLint fps = rcEnc->rcGetFBParam(rcEnc, FB_FPS);
- D("gralloc: fps=%d\n", fps);
- EGLint min_si = rcEnc->rcGetFBParam(rcEnc, FB_MIN_SWAP_INTERVAL);
- D("gralloc: min_swap=%d\n", min_si);
- EGLint max_si = rcEnc->rcGetFBParam(rcEnc, FB_MAX_SWAP_INTERVAL);
- D("gralloc: max_swap=%d\n", max_si);
- hostCon->unlock();
-
- //
- // Allocate memory for the framebuffer device
- //
- fb_device_t *dev;
- dev = (fb_device_t*)malloc(sizeof(fb_device_t));
- if (NULL == dev) {
- return -ENOMEM;
- }
- memset(dev, 0, sizeof(fb_device_t));
-
- // Initialize our device structure
- //
- dev->device.common.tag = HARDWARE_DEVICE_TAG;
- dev->device.common.version = 0;
- dev->device.common.module = const_cast<hw_module_t*>(module);
- dev->device.common.close = fb_close;
- dev->device.setSwapInterval = fb_setSwapInterval;
- dev->device.post = fb_post;
- dev->device.setUpdateRect = 0; //fb_setUpdateRect;
- dev->device.compositionComplete = fb_compositionComplete; //XXX: this is a dummy
-
- const_cast<uint32_t&>(dev->device.flags) = 0;
- const_cast<uint32_t&>(dev->device.width) = width;
- const_cast<uint32_t&>(dev->device.height) = height;
- const_cast<int&>(dev->device.stride) = width;
- const_cast<int&>(dev->device.format) = HAL_PIXEL_FORMAT_RGBA_8888;
- const_cast<float&>(dev->device.xdpi) = xdpi;
- const_cast<float&>(dev->device.ydpi) = ydpi;
- const_cast<float&>(dev->device.fps) = fps;
- const_cast<int&>(dev->device.minSwapInterval) = min_si;
- const_cast<int&>(dev->device.maxSwapInterval) = max_si;
- *device = &dev->device.common;
-
- status = 0;
- }
return status;
}
diff --git a/system/hwc2/EmuHWC2.cpp b/system/hwc2/EmuHWC2.cpp
index b44c3a7..a2f7b0c 100644
--- a/system/hwc2/EmuHWC2.cpp
+++ b/system/hwc2/EmuHWC2.cpp
@@ -31,7 +31,6 @@
#include "../egl/goldfish_sync.h"
#include "ThreadInfo.h"
-#include "gralloc_cb.h"
#if defined(LOG_NNDEBUG) && LOG_NNDEBUG == 0
#define ALOGVV ALOGV
@@ -81,6 +80,21 @@
getCapabilities = getCapabilitiesHook;
getFunction = getFunctionHook;
populateCapabilities();
+ initDisplayParameters();
+}
+
+Error EmuHWC2::initDisplayParameters() {
+ DEFINE_AND_VALIDATE_HOST_CONNECTION
+ hostCon->lock();
+
+ mDisplayWidth = rcEnc->rcGetFBParam(rcEnc, FB_WIDTH);
+ mDisplayHeight = rcEnc->rcGetFBParam(rcEnc, FB_HEIGHT);
+ mDisplayDpiX = rcEnc->rcGetFBParam(rcEnc, FB_XDPI);
+ mDisplayDpiY = rcEnc->rcGetFBParam(rcEnc, FB_YDPI);
+
+ hostCon->unlock();
+
+ return HWC2::Error::None;
}
void EmuHWC2::doGetCapabilities(uint32_t* outCount, int32_t* outCapabilities) {
@@ -376,6 +390,18 @@
return Error::None;
}
+const cb_handle_t* EmuHWC2::allocateDisplayColorBuffer() {
+ // HAL_PIXEL_FORMAT_RGBA_8888 was hardcoded in framebuffer_device_t in
+ // gralloc
+
+ return mGrallocModule.allocateBuffer(mDisplayWidth, mDisplayHeight,
+ HAL_PIXEL_FORMAT_RGBA_8888);
+}
+
+void EmuHWC2::freeDisplayColorBuffer(const cb_handle_t* h) {
+ mGrallocModule.freeBuffer(h);
+}
+
//Gralloc Functions
EmuHWC2::GrallocModule::GrallocModule() {
int ret;
@@ -383,32 +409,32 @@
ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &mHw);
assert(ret == 0 && "Gralloc moudle not found");
mGralloc = reinterpret_cast<const gralloc_module_t*>(mHw);
-
- ret = framebuffer_open(mHw, &mFbDev);
- assert(ret == 0 && "Fail to open FrameBuffer device");
+ ret = gralloc_open(mHw, &mAllocDev);
+ assert(ret == 0 && "Fail to open GPU device");
}
EmuHWC2::GrallocModule::~GrallocModule() {
- if (mHandle != nullptr) {
- mAllocDev->free(mAllocDev, mHandle);
- ALOGI("free targetCb %u", cb_handle_t::from(mHandle)->hostHandle);
- gralloc_close(mAllocDev);
- }
+ gralloc_close(mAllocDev);
}
-uint32_t EmuHWC2::GrallocModule::getTargetCb() {
- if (mHandle == nullptr) {
- int ret, stride;
- ret = gralloc_open(mHw, &mAllocDev);
- assert(ret == 0 && "Fail to open GPU device");
- ret = mAllocDev->alloc(mAllocDev,
- mFbDev->width, mFbDev->height, mFbDev->format,
- GRALLOC_USAGE_HW_COMPOSER|GRALLOC_USAGE_HW_RENDER,
- &mHandle, &stride);
- assert(ret == 0 && "Fail to allocate target ColorBuffer");
- ALOGI("targetCb %u", cb_handle_t::from(mHandle)->hostHandle);
- }
- return cb_handle_t::from(mHandle)->hostHandle;
+const cb_handle_t* EmuHWC2::GrallocModule::allocateBuffer(int width, int height, int format) {
+ int ret;
+ int stride;
+ buffer_handle_t handle;
+
+ ret = mAllocDev->alloc(mAllocDev, width, height, format,
+ GRALLOC_USAGE_HW_COMPOSER|GRALLOC_USAGE_HW_RENDER,
+ &handle, &stride);
+ assert(ret == 0 && "Fail to allocate target ColorBuffer");
+
+ return cb_handle_t::from(handle);
+}
+
+void EmuHWC2::GrallocModule::freeBuffer(const cb_handle_t* h) {
+ int ret;
+
+ ret = mAllocDev->free(mAllocDev, h);
+ assert(ret == 0 && "Fail to free target ColorBuffer");
}
// Display functions
@@ -452,10 +478,14 @@
mActiveConfig(nullptr),
mColorModes(),
mSetColorTransform(false),
- mStateMutex()
- {
+ mStateMutex() {
mVsyncThread.run("", -19 /* ANDROID_PRIORITY_URGENT_AUDIO */);
- }
+ mTargetCb = device.allocateDisplayColorBuffer();
+}
+
+EmuHWC2::Display::~Display() {
+ mDevice.freeDisplayColorBuffer(mTargetCb);
+}
Error EmuHWC2::Display::acceptChanges() {
ALOGVV("%s: displayId %u", __FUNCTION__, (uint32_t)mId);
@@ -759,7 +789,7 @@
if (numLayer == 0) {
ALOGVV("No layers, exit");
- mGralloc->getFb()->post(mGralloc->getFb(), mClientTarget.getBuffer());
+ post(hostCon, rcEnc, mClientTarget.getBuffer());
*outRetireFence = mClientTarget.getFence();
return Error::None;
}
@@ -842,12 +872,12 @@
}
if (hostCompositionV1) {
p->version = 1;
- p->targetHandle = mGralloc->getTargetCb();
+ p->targetHandle = mTargetCb->hostHandle;
p->numLayers = numLayer;
} else {
p2->version = 2;
p2->displayId = mHostDisplayId;
- p2->targetHandle = mGralloc->getTargetCb();
+ p2->targetHandle = mTargetCb->hostHandle;
p2->numLayers = numLayer;
}
@@ -891,7 +921,7 @@
hostCon->unlock();
} else {
// we set all layers Composition::Client, so do nothing.
- mGralloc->getFb()->post(mGralloc->getFb(), mClientTarget.getBuffer());
+ post(hostCon, rcEnc, mClientTarget.getBuffer());
*outRetireFence = mClientTarget.getFence();
ALOGV("%s fallback to post, returns outRetireFence %d",
__FUNCTION__, *outRetireFence);
@@ -1279,18 +1309,17 @@
return Error::None;
}
-int EmuHWC2::Display::populatePrimaryConfigs() {
+int EmuHWC2::Display::populatePrimaryConfigs(int width, int height, int dpiX, int dpiY) {
ALOGVV("%s DisplayId %u", __FUNCTION__, (uint32_t)mId);
std::unique_lock<std::mutex> lock(mStateMutex);
- mGralloc.reset(new GrallocModule());
auto newConfig = std::make_shared<Config>(*this);
// vsync is 60 hz;
newConfig->setAttribute(Attribute::VsyncPeriod, mVsyncPeriod);
- newConfig->setAttribute(Attribute::Width, mGralloc->getFb()->width);
- newConfig->setAttribute(Attribute::Height, mGralloc->getFb()->height);
- newConfig->setAttribute(Attribute::DpiX, mGralloc->getFb()->xdpi*1000);
- newConfig->setAttribute(Attribute::DpiY, mGralloc->getFb()->ydpi*1000);
+ newConfig->setAttribute(Attribute::Width, width);
+ newConfig->setAttribute(Attribute::Height, height);
+ newConfig->setAttribute(Attribute::DpiX, dpiX * 1000);
+ newConfig->setAttribute(Attribute::DpiY, dpiY * 1000);
newConfig->setId(static_cast<hwc2_config_t>(mConfigs.size()));
ALOGV("Found new config %d: %s", (uint32_t)newConfig->getId(),
@@ -1307,13 +1336,23 @@
return 0;
}
+void EmuHWC2::Display::post(HostConnection *hostCon,
+ ExtendedRCEncoderContext *rcEnc,
+ buffer_handle_t h) {
+ const cb_handle_t* cb = cb_handle_t::from(h);
+ assert(cb && "cb_handle_t::from(h) failed");
+
+ hostCon->lock();
+ rcEnc->rcFBPost(rcEnc, cb->hostHandle);
+ hostCon->unlock();
+}
+
HWC2::Error EmuHWC2::Display::populateSecondaryConfigs(uint32_t width, uint32_t height,
uint32_t dpi) {
ALOGVV("%s DisplayId %u, width %u, height %u, dpi %u",
__FUNCTION__, (uint32_t)mId, width, height, dpi);
std::unique_lock<std::mutex> lock(mStateMutex);
- mGralloc.reset(new GrallocModule());
auto newConfig = std::make_shared<Config>(*this);
// vsync is 60 hz;
newConfig->setAttribute(Attribute::VsyncPeriod, mVsyncPeriod);
@@ -1597,7 +1636,8 @@
int EmuHWC2::populatePrimary() {
int ret = 0;
auto display = std::make_shared<Display>(*this, HWC2::DisplayType::Physical);
- ret = display->populatePrimaryConfigs();
+ ret = display->populatePrimaryConfigs(mDisplayWidth, mDisplayHeight,
+ mDisplayDpiX, mDisplayDpiY);
if (ret != 0) {
return ret;
}
diff --git a/system/hwc2/EmuHWC2.h b/system/hwc2/EmuHWC2.h
index ff056ca..dfc51e4 100644
--- a/system/hwc2/EmuHWC2.h
+++ b/system/hwc2/EmuHWC2.h
@@ -35,6 +35,7 @@
#include <set>
#include <cutils/native_handle.h>
+#include "gralloc_cb.h"
#include "MiniFence.h"
#include "HostConnection.h"
@@ -141,14 +142,14 @@
public:
GrallocModule();
~GrallocModule();
- framebuffer_device_t* getFb() { return mFbDev; }
- uint32_t getTargetCb();
+
+ const cb_handle_t* allocateBuffer(int width, int height, int format);
+ void freeBuffer(const cb_handle_t*);
+
private:
const hw_module_t* mHw = nullptr;
const gralloc_module_t* mGralloc = nullptr;
alloc_device_t* mAllocDev = nullptr;
- framebuffer_device_t* mFbDev = nullptr;
- buffer_handle_t mHandle = nullptr;
};
typedef struct compose_layer {
@@ -216,6 +217,7 @@
class Display {
public:
Display(EmuHWC2& device, HWC2::DisplayType type);
+ ~Display();
hwc2_display_t getId() const {return mId;}
// HWC2 Display functions
@@ -267,11 +269,14 @@
HWC2::Error setDisplayBrightness(float brightness);
// Read configs from PRIMARY Display
- int populatePrimaryConfigs();
+ int populatePrimaryConfigs(int width, int height, int dpiX, int dpiY);
HWC2::Error populateSecondaryConfigs(uint32_t width, uint32_t height,
uint32_t dpi);
private:
+ void post(HostConnection *hostCon, ExtendedRCEncoderContext *rcEnc,
+ buffer_handle_t h);
+
class Config {
public:
Config(Display& display)
@@ -379,12 +384,11 @@
// called. To prevent a bad state from crashing us during a dump
// call, all public calls into Display must acquire this mutex.
mutable std::mutex mStateMutex;
- std::unique_ptr<GrallocModule> mGralloc;
std::unique_ptr<ComposeMsg> mComposeMsg;
std::unique_ptr<ComposeMsg_v2> mComposeMsg_v2;
int mSyncDeviceFd;
-
- };
+ const cb_handle_t* mTargetCb;
+ };
template<typename MF, MF memFunc, typename ...Args>
static int32_t displayHook(hwc2_device_t* device, hwc2_display_t displayId,
@@ -472,6 +476,11 @@
std::tuple<Layer*, HWC2::Error> getLayer(hwc2_display_t displayId,
hwc2_layer_t layerId);
+ HWC2::Error initDisplayParameters();
+ const cb_handle_t* allocateDisplayColorBuffer();
+ void freeDisplayColorBuffer(const cb_handle_t* h);
+
+ GrallocModule mGrallocModule;
std::unordered_set<HWC2::Capability> mCapabilities;
// These are potentially accessed from multiple threads, and are protected
@@ -488,6 +497,10 @@
std::map<hwc2_display_t, std::shared_ptr<Display>> mDisplays;
std::unordered_map<hwc2_layer_t, std::shared_ptr<Layer>> mLayers;
+ int mDisplayWidth;
+ int mDisplayHeight;
+ int mDisplayDpiX;
+ int mDisplayDpiY;
};
}