Exemple #1
0
bool GraphicsContext3DInternal::paintCompositedResultsToCanvas(CanvasRenderingContext* context)
{
    LOGWEBGL("paintCompositedResultsToCanvas()");
    ImageBuffer* imageBuffer = context->canvas()->buffer();
    const SkBitmap& canvasBitmap =
        imageBuffer->context()->platformContext()->recordingCanvas()->getDevice()->accessBitmap(false);
    SkCanvas canvas(canvasBitmap);

    MutexLocker lock(m_fboMutex);

    FBO* fbo = m_frontFBO;
    if (!fbo)
        return false;

    SkBitmap bitmap;
    bitmap.setConfig(SkBitmap::kARGB_8888_Config, m_width, m_height, fbo->bytesPerRow());

    unsigned char* bits = NULL;
    if (fbo->lockGraphicBuffer((void**)&bits)) {
        bitmap.setPixels(bits);

        SkRect  dstRect;
        dstRect.iset(0, 0, imageBuffer->size().width(), imageBuffer->size().height());
        canvas.save();
        canvas.translate(0, SkIntToScalar(imageBuffer->size().height()));
        canvas.scale(SK_Scalar1, -SK_Scalar1);
        canvas.drawBitmapRect(bitmap, 0, dstRect);
        canvas.restore();
        bitmap.setPixels(0);
        fbo->unlockGraphicBuffer();
    }

    return true;
}
Exemple #2
0
PassRefPtr<ImageData> GraphicsContext3DInternal::paintRenderingResultsToImageData()
{
    LOGWEBGL("paintRenderingResultsToImageData()");

    // Reading premultiplied alpha would involve unpremultiplying, which is lossy.
    if (m_attrs.premultipliedAlpha)
        return 0;

    RefPtr<ImageData> imageData = ImageData::create(IntSize(m_width, m_height));
    unsigned char* pixels = imageData->data()->data()->data();
    //[CAPPFIX_WEB_WEBGL] - better performance
    if (m_canvasDirty) {
        glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
    } else {
        LOGWEBGL("paintRenderingResultsToImageData() >>> from clean canvas, so read the back buffer >>> m_canvasDirty:%d", m_canvasDirty);
        unsigned char* bits;
        MutexLocker lock(m_fboMutex);

        FBO* fbo = m_frontFBO;
        if (!fbo)
            return NULL;

        if (fbo->lockGraphicBuffer((void**)&bits)) {
            memcpy(pixels, bits, (m_width * m_height * 4));
            fbo->unlockGraphicBuffer();
        }
    }
    LOGWEBGL("-paintRenderingResultsToImageData()");
    // [CAPPFIX_WEB_WEBGL_END]
    return imageData;
}