コード例 #1
0
    bool capturePixels(SkBitmap* bmp) {
        sk_sp<SkColorSpace> colorSpace = SkColorSpace::MakeSRGB();
        SkImageInfo destinationConfig =
                SkImageInfo::Make(mSize.width(), mSize.height(), kRGBA_8888_SkColorType,
                                  kPremul_SkAlphaType, colorSpace);
        bmp->allocPixels(destinationConfig);
        android_memset32((uint32_t*)bmp->getPixels(), SK_ColorRED,
                         mSize.width() * mSize.height() * 4);

        android::CpuConsumer::LockedBuffer nativeBuffer;
        android::status_t retval = mCpuConsumer->lockNextBuffer(&nativeBuffer);
        if (retval == android::BAD_VALUE) {
            SkDebugf("write_canvas_png() got no buffer; returning transparent");
            // No buffer ready to read - commonly triggered by dm sending us
            // a no-op source, or calling code that doesn't do anything on this
            // backend.
            bmp->eraseColor(SK_ColorTRANSPARENT);
            return false;
        } else if (retval) {
            SkDebugf("Failed to lock buffer to read pixels: %d.", retval);
            return false;
        }

        // Move the pixels into the destination SkBitmap

        LOG_ALWAYS_FATAL_IF(nativeBuffer.format != android::PIXEL_FORMAT_RGBA_8888,
                            "Native buffer not RGBA!");
        SkImageInfo nativeConfig = SkImageInfo::Make(nativeBuffer.width, nativeBuffer.height,
                                                     kRGBA_8888_SkColorType, kPremul_SkAlphaType);

        // Android stride is in pixels, Skia stride is in bytes
        SkBitmap nativeWrapper;
        bool success = nativeWrapper.installPixels(nativeConfig, nativeBuffer.data,
                                                   nativeBuffer.stride * 4);
        if (!success) {
            SkDebugf("Failed to wrap HWUI buffer in a SkBitmap");
            return false;
        }

        LOG_ALWAYS_FATAL_IF(bmp->colorType() != kRGBA_8888_SkColorType,
                            "Destination buffer not RGBA!");
        success = nativeWrapper.readPixels(destinationConfig, bmp->getPixels(), bmp->rowBytes(), 0,
                                           0);
        if (!success) {
            SkDebugf("Failed to extract pixels from HWUI buffer");
            return false;
        }

        mCpuConsumer->unlockBuffer(nativeBuffer);

        return true;
    }
コード例 #2
0
ファイル: cb_utils.cpp プロジェクト: Ll0ir/display
int CBUtils::qcomuiClearRegion(Region region, EGLDisplay dpy){

    int ret = 0;
    int compositionType = QCCompositionType::getInstance().getCompositionType();
    if ((compositionType == COMPOSITION_TYPE_GPU) || sGPUlayerpresent) {
        //return ERROR when GPU composition is used or any layer is flagged
        //for GPU composition.
        return -1;
    }



    android_native_buffer_t *renderBuffer =
          qdutils::eglHandles::getInstance().getAndroidNativeRenderBuffer(dpy);

    if (!renderBuffer) {
        ALOGE("%s: eglGetRenderBufferANDROID returned NULL buffer",
             __FUNCTION__);
        return -1;
    }
   private_handle_t *fbHandle = (private_handle_t *)renderBuffer->handle;
    if(!fbHandle) {
        ALOGE("%s: Framebuffer handle is NULL", __FUNCTION__);
        return -1;
    }

    int bytesPerPixel = 4;
    if (HAL_PIXEL_FORMAT_RGB_565 == fbHandle->format) {
        bytesPerPixel = 2;
    }

    Region::const_iterator it = region.begin();
    Region::const_iterator const end = region.end();
    const int32_t stride = renderBuffer->stride*bytesPerPixel;
    while (it != end) {
        const Rect& r = *it++;
        uint8_t* dst = (uint8_t*) fbHandle->base +
            (r.left + r.top*renderBuffer->stride)*bytesPerPixel;
        int w = r.width()*bytesPerPixel;
        int h = r.height();

        do {
            if(4 == bytesPerPixel){
                android_memset32((uint32_t*)dst, 0, w);
            } else {
                android_memset16((uint16_t*)dst, 0, w);
            }
            dst += stride;
        } while(--h);
    }
    return 0;
}
コード例 #3
0
ファイル: egl.cpp プロジェクト: e0234/android_frameworks_base
static void early_egl_init(void) 
{
#if !USE_FAST_TLS_KEY
    pthread_key_create(&gGLWrapperKey, NULL);
#endif
#if EGL_TRACE
    pthread_key_create(&gGLTraceKey, NULL);
    initEglTraceLevel();
#endif
    uint32_t addr = (uint32_t)((void*)gl_no_context);
    android_memset32(
            (uint32_t*)(void*)&gHooksNoContext, 
            addr, 
            sizeof(gHooksNoContext));

    setGLHooksThreadSpecific(&gHooksNoContext);
}
コード例 #4
0
void gr_flip_32(unsigned *bits, unsigned short *ptr, unsigned count)
{
   unsigned i=0;
   while (i<count) {
        uint32_t rgb32, red, green, blue, alpha;

        /* convert 16 bits to 32 bits */
        
        rgb32 = ptr[i];
        red = (rgb32 & 0x1f) << 3; // shift left 3 for full precision
        green = (rgb32 & 0x7E0) << 5; // shift right 5 to align, shift left 2 for full precision, shift left 8 for rgb
        blue = (rgb32 & 0xF800) << 8; // shift right 11 to aligh, shift left 3 for full precision, left 16 for rgb 
        
        rgb32 = 0xFF000000 | red | green | blue;
        
        android_memset32((uint32_t *)bits, rgb32, 4);
        i++;
        bits++;
    }
}