DisplayPlane* TngPlaneManager::getPlaneHelper(int dsp, int type) { RETURN_NULL_IF_NOT_INIT(); if (dsp < 0 || dsp > IDisplayDevice::DEVICE_EXTERNAL) { ETRACE("Invalid display device %d", dsp); return 0; } int index = dsp == IDisplayDevice::DEVICE_PRIMARY ? 0 : 1; if (type == DisplayPlane::PLANE_PRIMARY || type == DisplayPlane::PLANE_CURSOR) { return getPlane(type, index); } else if (type == DisplayPlane::PLANE_SPRITE) { return getAnyPlane(type); } else if (type == DisplayPlane::PLANE_OVERLAY) { // use overlay A for pipe A and overlay C for pipe B if possible DisplayPlane *plane = getPlane(type, index); if (plane == NULL) { plane = getPlane(type, !index); } return plane; } else { ETRACE("invalid plane type %d", type); return 0; } }
// HWC 1.4 requires that we return all of the compatible configs in getDisplayConfigs // this is needed so getActiveConfig/setActiveConfig work correctly. It is up to the // user space to decide what speed to send. drmModeModeInfoPtr Drm::detectAllConfigs(int device, int *modeCount) { RETURN_NULL_IF_NOT_INIT(); Mutex::Autolock _l(mLock); if (modeCount != NULL) *modeCount = 0; else return NULL; int outputIndex = getOutputIndex(device); if (outputIndex < 0) { ELOGTRACE("invalid device"); return NULL; } DrmOutput *output= &mOutputs[outputIndex]; if (!output->connected) { ELOGTRACE("device is not connected"); return NULL; } if (output->connector->count_modes <= 0) { ELOGTRACE("invalid count of modes"); return NULL; } *modeCount = output->connector->count_modes; return output->connector->modes; }
uint32_t BufferManager::allocGrallocBuffer(uint32_t width, uint32_t height, uint32_t format, uint32_t usage) { RETURN_NULL_IF_NOT_INIT(); if (!mGralloc) { WLOGTRACE("Alloc device is not available"); return 0; } if (!width || !height) { ELOGTRACE("invalid input parameter"); return 0; } ILOGTRACE("size of graphic buffer to create: %dx%d", width, height); uint32_t handle = 0; int stride; status_t err = gralloc_device_alloc_img( mGralloc, width, height, format, usage, (buffer_handle_t *)&handle, &stride); if (err != 0) { ELOGTRACE("failed to allocate gralloc buffer, error = %d", err); return 0; } return handle; }
int DisplayPlaneManager::getFreePlanes(int dsp, int type) { RETURN_NULL_IF_NOT_INIT(); if (dsp < 0 || dsp > IDisplayDevice::DEVICE_EXTERNAL) { ETRACE("Invalid display device %d", dsp); return 0; } if (type < 0 || type >= DisplayPlane::PLANE_MAX) { ETRACE("Invalid plane type %d", type); return 0; } uint32_t freePlanes = mFreePlanes[type] | mReclaimedPlanes[type]; if (type == DisplayPlane::PLANE_PRIMARY || type == DisplayPlane::PLANE_CURSOR) { return ((freePlanes & (1 << dsp)) == 0) ? 0 : 1; } else { int count = 0; for (int i = 0; i < 32; i++) { if ((1 << i) & freePlanes) { count++; } } return count; } return 0; }
int Hwcomposer::getActiveConfig(int disp) { RETURN_NULL_IF_NOT_INIT(); if (disp != 0) { ELOGTRACE("invalid disp %d", disp); return -1; } // return device->getActiveConfig(); return 0; }
int Hwcomposer::getActiveConfig(int disp) { RETURN_NULL_IF_NOT_INIT(); if (disp < 0 || disp >= IDisplayDevice::DEVICE_COUNT) { ELOGTRACE("invalid disp %d", disp); return -1; } IDisplayDevice *device = mDisplayDevices.itemAt(disp); if (!device) { ELOGTRACE("no device found"); return -1; } return device->getActiveConfig(); }
DisplayPlane* DisplayPlaneManager::getAnyPlane(int type) { RETURN_NULL_IF_NOT_INIT(); if (type < 0 || type >= DisplayPlane::PLANE_MAX) { ETRACE("Invalid plane type %d", type); return 0; } int freePlaneIndex = getPlane(mReclaimedPlanes[type]); if (freePlaneIndex >= 0) return mPlanes[type].itemAt(freePlaneIndex); freePlaneIndex = getPlane(mFreePlanes[type]); if (freePlaneIndex >= 0) return mPlanes[type].itemAt(freePlaneIndex); return 0; }
uint32_t BufferManager::allocFrameBuffer(int width, int height, int *stride) { RETURN_NULL_IF_NOT_INIT(); if (!mGralloc) { WLOGTRACE("Alloc device is not available"); return 0; } if (!width || !height || !stride) { ELOGTRACE("invalid input parameter"); return 0; } ILOGTRACE("size of frame buffer to create: %dx%d", width, height); uint32_t handle = 0; status_t err = gralloc_device_alloc_img( mGralloc, width, height, DrmConfig::getFrameBufferFormat(), 0, // GRALLOC_USAGE_HW_FB (buffer_handle_t *)&handle, stride); if (err != 0) { ELOGTRACE("failed to allocate frame buffer, error = %d", err); return 0; } DataBuffer *buffer = NULL; BufferMapper *mapper = NULL; do { buffer = lockDataBuffer(handle); if (!buffer) { ELOGTRACE("failed to get data buffer, handle = %#x", handle); break; } mapper = createBufferMapper(*buffer); if (!mapper) { ELOGTRACE("failed to create buffer mapper"); break; } uint32_t fbHandle; if (!(fbHandle = mapper->getFbHandle(0))) { ELOGTRACE("failed to get Fb handle"); break; } mFrameBuffers.add(fbHandle, mapper); unlockDataBuffer(buffer); return fbHandle; } while (0); // error handling, release all allocated resources if (buffer) { unlockDataBuffer(buffer); } if (mapper) { delete mapper; } gralloc_device_free_img(mGralloc, (buffer_handle_t)handle); return 0; }