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

Commit 8f78faa1 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

add support for out-of-range copybit scaling. camera capture is in color again

parent dafb08dc
Loading
Loading
Loading
Loading
+55 −52
Original line number Diff line number Diff line
@@ -245,6 +245,8 @@ LayerBuffer::Buffer::Buffer(const ISurface::BufferHeap& buffers, ssize_t offset)
    src.img.format  = buffers.format;
    src.img.base    = (void*)(intptr_t(buffers.heap->base()) + offset);

    // FIXME: gross hack, we should never access private_handle_t from here,
    // but this is needed by msm drivers
    private_handle_t* hnd = new private_handle_t(
            buffers.heap->heapID(), buffers.heap->getSize(), 0);
    hnd->offset = offset;
@@ -421,7 +423,21 @@ void LayerBuffer::BufferSource::onDraw(const Region& clip) const
            int t(W); W=H; H=t;
        }

#if 0
#ifdef EGL_ANDROID_get_render_buffer
        EGLDisplay dpy = eglGetCurrentDisplay();
        EGLSurface draw = eglGetCurrentSurface(EGL_DRAW); 
        EGLClientBuffer clientBuf = eglGetRenderBufferANDROID(dpy, draw);
        android_native_buffer_t* nb = (android_native_buffer_t*)clientBuf;
        if (nb == 0) {
            err = BAD_VALUE;
        } else {
            copybit_image_t dst;
            dst.w       = nb->width;
            dst.h       = nb->height;
            dst.format  = nb->format;
            dst.base    = NULL; // unused by copybit on msm7k
            dst.handle  = (native_handle_t *)nb->handle;

            /* With LayerBuffer, it is likely that we'll have to rescale the
             * surface, because this is often used for video playback or
             * camera-preview. Since we want these operation as fast as possible
@@ -441,20 +457,23 @@ void LayerBuffer::BufferSource::onDraw(const Region& clip) const
            else if (src_height*mag < H)    yscale = mag;

            if (UNLIKELY(xscale!=1.0f || yscale!=1.0f)) {
            if (UNLIKELY(mTemporaryDealer == 0)) {
                // allocate a memory-dealer for this the first time
                mTemporaryDealer = mLayer.mFlinger->getSurfaceHeapManager()
                    ->createHeap(ISurfaceComposer::eHardware);
                mTempBitmap.init(mTemporaryDealer);
            }

                const int tmp_w = floorf(src_width  * xscale);
                const int tmp_h = floorf(src_height * yscale);
            err = mTempBitmap.setBits(tmp_w, tmp_h, 1, src.img.format);
                
                if (mTempBitmap==0 || 
                        mTempBitmap->getWidth() < tmp_w || 
                        mTempBitmap->getHeight() < tmp_h) {
                    mTempBitmap.clear();
                    mTempBitmap = new android::Buffer(tmp_w, tmp_h, src.img.format);
                    err = mTempBitmap->initCheck();
                }

                if (LIKELY(err == NO_ERROR)) {
                    NativeBuffer tmp;
                mTempBitmap.getBitmapSurface(&tmp.img);
                    tmp.img.w = tmp_w;
                    tmp.img.h = tmp_h;
                    tmp.img.format = src.img.format;
                    tmp.img.handle = (native_handle_t*)mTempBitmap->getNativeBuffer()->handle;
                    tmp.crop.l = 0;
                    tmp.crop.t = 0;
                    tmp.crop.r = tmp.img.w;
@@ -469,26 +488,10 @@ void LayerBuffer::BufferSource::onDraw(const Region& clip) const
                    src = tmp;
                }
            }
#endif

#ifdef EGL_ANDROID_get_render_buffer
        EGLDisplay dpy = eglGetCurrentDisplay();
        EGLSurface draw = eglGetCurrentSurface(EGL_DRAW); 
        EGLClientBuffer clientBuf = eglGetRenderBufferANDROID(dpy, draw);
        android_native_buffer_t* nb = (android_native_buffer_t*)clientBuf;
        if (nb == 0) {
            err = BAD_VALUE;
        } else {
            copybit_image_t dst;
            dst.w       = nb->width;
            dst.h       = nb->height;
            dst.format  = nb->format;
            dst.base    = NULL; // unused by copybit on msm7k
            dst.handle  = (native_handle_t *)nb->handle;

            const Rect& transformedBounds = mLayer.getTransformedBounds();
            const copybit_rect_t& drect
                    = reinterpret_cast<const copybit_rect_t&>(transformedBounds);
            const copybit_rect_t& drect =
                reinterpret_cast<const copybit_rect_t&>(transformedBounds);
            const State& s(mLayer.drawingState());
            region_iterator it(clip);