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

Commit 2bd7d98f authored by Mathias Agopian's avatar Mathias Agopian
Browse files

fallout from getting rid of IGraphicBufferAlloc

Test: compiled & run
Bug: cleanup
Change-Id: I1590105d3abef985c2ae7c1a03cdf5fd2ec4bef9
parent 62dd27ab
Loading
Loading
Loading
Loading
+7 −16
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@
#include <ui/GraphicBuffer.h>
#include <ui/PixelFormat.h>

#include <gui/IGraphicBufferAlloc.h>
#include <gui/ISurfaceComposer.h>
#include <hwui/Bitmap.h>

#include <SkCanvas.h>
@@ -111,21 +109,14 @@ static jlong android_graphics_GraphicBuffer_wrap(JNIEnv* env, jobject clazz,
static jlong android_graphics_GraphicBuffer_create(JNIEnv* env, jobject clazz,
        jint width, jint height, jint format, jint usage) {

    sp<ISurfaceComposer> composer(ComposerService::getComposerService());
    sp<IGraphicBufferAlloc> alloc(composer->createGraphicBufferAlloc());
    if (alloc == NULL) {
        if (kDebugGraphicBuffer) {
            ALOGW("createGraphicBufferAlloc() failed in GraphicBuffer.create()");
        }
        return NULL;
    }
    sp<GraphicBuffer> buffer = new GraphicBuffer(
            uint32_t(width), uint32_t(height), PixelFormat(format), uint32_t(usage),
            std::string("android_graphics_GraphicBuffer_create pid [") +
                    std::to_string(getpid()) +"]");

    status_t error;
    sp<GraphicBuffer> buffer(alloc->createGraphicBuffer(width, height, format, 1, usage, &error));
    if (buffer == NULL) {
        if (kDebugGraphicBuffer) {
            ALOGW("createGraphicBuffer() failed in GraphicBuffer.create()");
        }
    status_t error = buffer->initCheck();
    if (error < 0) {
        ALOGW_IF(kDebugGraphicBuffer, "createGraphicBuffer() failed in GraphicBuffer.create()");
        return NULL;
    }

+8 −19
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@
#include <binder/Parcel.h>

#include <ui/GraphicBuffer.h>
#include <gui/IGraphicBufferAlloc.h>
#include <gui/ISurfaceComposer.h>
#include <private/gui/ComposerService.h>

#include <hardware/gralloc1.h>
@@ -73,15 +71,6 @@ public:
static jlong android_hardware_HardwareBuffer_create(JNIEnv* env, jobject clazz,
        jint width, jint height, jint format, jint layers, jlong usage) {

    sp<ISurfaceComposer> composer(ComposerService::getComposerService());
    sp<IGraphicBufferAlloc> alloc(composer->createGraphicBufferAlloc());
    if (alloc == NULL) {
        if (kDebugGraphicBuffer) {
            ALOGW("createGraphicBufferAlloc() failed in HardwareBuffer.create()");
        }
        return NULL;
    }

    // TODO: update createGraphicBuffer to take two 64-bit values.
    int pixelFormat = android_hardware_HardwareBuffer_convertToPixelFormat(format);
    if (pixelFormat == 0) {
@@ -92,14 +81,14 @@ static jlong android_hardware_HardwareBuffer_create(JNIEnv* env, jobject clazz,
    }
    uint64_t producerUsage = 0;
    uint64_t consumerUsage = 0;
    android_hardware_HardwareBuffer_convertToGrallocUsageBits(&producerUsage, &consumerUsage, usage,
            0);
    status_t error;
    sp<GraphicBuffer> buffer(alloc->createGraphicBuffer(width, height, pixelFormat,
            layers, producerUsage, consumerUsage,
            std::string("HardwareBuffer pid [") + std::to_string(getpid()) +"]",
            &error));
    if (buffer == NULL) {
    android_hardware_HardwareBuffer_convertToGrallocUsageBits(
            &producerUsage, &consumerUsage, usage, 0);

    sp<GraphicBuffer> buffer = new GraphicBuffer(width, height, pixelFormat, layers,
            producerUsage, consumerUsage,
            std::string("HardwareBuffer pid [") + std::to_string(getpid()) +"]");
    status_t error = buffer->initCheck();
    if (error < 0) {
        if (kDebugGraphicBuffer) {
            ALOGW("createGraphicBuffer() failed in HardwareBuffer.create()");
        }
+8 −15
Original line number Diff line number Diff line
@@ -30,8 +30,6 @@
#include <EGL/egl.h>
#include <EGL/eglext.h>

#include <gui/IGraphicBufferAlloc.h>
#include <gui/ISurfaceComposer.h>
#include <private/gui/ComposerService.h>
#include <binder/IServiceManager.h>
#include <ui/PixelFormat.h>
@@ -219,13 +217,6 @@ sk_sp<Bitmap> Bitmap::allocateHardwareBitmap(uirenderer::renderthread::RenderThr
    renderThread.eglManager().initialize();
    uirenderer::Caches& caches = uirenderer::Caches::getInstance();

    sp<ISurfaceComposer> composer(ComposerService::getComposerService());
    sp<IGraphicBufferAlloc> alloc(composer->createGraphicBufferAlloc());
    if (alloc == NULL) {
        ALOGW("createGraphicBufferAlloc() failed in GraphicBuffer.create()");
        return nullptr;
    }

    const SkImageInfo& info = skBitmap.info();
    if (info.colorType() == kUnknown_SkColorType || info.colorType() == kAlpha_8_SkColorType) {
        ALOGW("unable to create hardware bitmap of colortype: %d", info.colorType());
@@ -240,12 +231,14 @@ sk_sp<Bitmap> Bitmap::allocateHardwareBitmap(uirenderer::renderthread::RenderThr
            needSRGB, &internalFormat, &format, &type);

    PixelFormat pixelFormat = internalFormatToPixelFormat(internalFormat);
    status_t error;
    sp<GraphicBuffer> buffer = alloc->createGraphicBuffer(info.width(), info.height(), pixelFormat,
            1, GraphicBuffer::USAGE_HW_TEXTURE | GraphicBuffer::USAGE_SW_WRITE_NEVER
            | GraphicBuffer::USAGE_SW_READ_NEVER , &error);

    if (!buffer.get()) {
    sp<GraphicBuffer> buffer = new GraphicBuffer(info.width(), info.height(), pixelFormat,
            GraphicBuffer::USAGE_HW_TEXTURE |
            GraphicBuffer::USAGE_SW_WRITE_NEVER |
            GraphicBuffer::USAGE_SW_READ_NEVER,
            std::string("Bitmap::allocateHardwareBitmap pid [") + std::to_string(getpid()) + "]");

    status_t error = buffer->initCheck();
    if (error < 0) {
        ALOGW("createGraphicBuffer() failed in GraphicBuffer.create()");
        return nullptr;
    }
+3 −10
Original line number Diff line number Diff line
@@ -17,10 +17,6 @@
#include "TestSceneBase.h"
#include "utils/Color.h"

#include <gui/IGraphicBufferAlloc.h>
#include <gui/ISurfaceComposer.h>
#include <private/gui/ComposerService.h>
#include <binder/IServiceManager.h>
#include <ui/PixelFormat.h>
#include <SkGradientShader.h>
#include <SkImagePriv.h>
@@ -39,14 +35,11 @@ public:
    void createContent(int width, int height, Canvas& canvas) override {
        canvas.drawColor(Color::Red_500, SkBlendMode::kSrcOver);

        status_t error;
        sp<ISurfaceComposer> composer(ComposerService::getComposerService());
        sp<IGraphicBufferAlloc> alloc(composer->createGraphicBufferAlloc());
        uint32_t usage = GraphicBuffer::USAGE_HW_TEXTURE
                | GraphicBuffer::USAGE_SW_READ_NEVER
                | GRALLOC_USAGE_SW_WRITE_RARELY;
        sp<GraphicBuffer> buffer = alloc->createGraphicBuffer(400, 200, PIXEL_FORMAT_RGBA_8888, 1,
                usage, &error);

        sp<GraphicBuffer> buffer = new GraphicBuffer(400, 200, PIXEL_FORMAT_RGBA_8888, usage);

        unsigned char* pixels = nullptr;
        buffer->lock(GraphicBuffer::USAGE_SW_WRITE_RARELY, ((void**)&pixels));