bool PipePictureRenderer::render(SkBitmap** out) {
    SkASSERT(fCanvas.get() != NULL);
    SkASSERT(fPicture != NULL);
    if (NULL == fCanvas.get() || NULL == fPicture) {
        return false;
    }

    PipeController pipeController(fCanvas.get());
    SkGPipeWriter writer;
    SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
    pipeCanvas->drawPicture(fPicture);
    writer.endRecording();
    fCanvas->flush();
    if (out) {
        *out = SkNEW(SkBitmap);
        setup_bitmap(*out, SkScalarCeilToInt(fPicture->cullRect().width()),
                           SkScalarCeilToInt(fPicture->cullRect().height()));
        fCanvas->readPixels(*out, 0, 0);
    }
    if (fEnableWrites) {
        return write(fCanvas, fWritePath, fMismatchPath, fInputFilename, fJsonSummaryPtr,
                     fUseChecksumBasedFilenames);
    } else {
        return true;
    }
}
DEF_TEST(Pipe, reporter) {
    SkBitmap bitmap;
    bitmap.setConfig(SkBitmap::kARGB_8888_Config, 64, 64);
    SkCanvas canvas(bitmap);

    PipeController pipeController(&canvas);
    SkGPipeWriter writer;
    SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
    testDrawingBadBitmap(pipeCanvas);
    writer.endRecording();

    testDrawingAfterEndRecording(&canvas);
}
Exemple #3
0
static void test_pipeTests(skiatest::Reporter*) {
    SkBitmap bitmap;
    bitmap.setConfig(SkBitmap::kARGB_8888_Config, 64, 64);
    SkCanvas canvas(bitmap);

    PipeController pipeController(&canvas);
    SkGPipeWriter writer;
    SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
    testDrawingBadBitmap(pipeCanvas);
    writer.endRecording();

    testDrawingAfterEndRecording(&canvas);
}
// Ensure that pipe gracefully handles attempting to draw after endRecording is called on the
// SkGPipeWriter.
static void testDrawingAfterEndRecording(SkCanvas* canvas) {
    PipeController pc(canvas);
    SkGPipeWriter writer;
    SkCanvas* pipeCanvas = writer.startRecording(&pc, SkGPipeWriter::kCrossProcess_Flag);
    writer.endRecording();

    SkBitmap bm;
    bm.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
    bm.allocPixels();
    bm.eraseColor(SK_ColorTRANSPARENT);

    SkShader* shader = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode,
                                                    SkShader::kClamp_TileMode);
    SkPaint paint;
    paint.setShader(shader)->unref();
    pipeCanvas->drawPaint(paint);

    pipeCanvas->drawBitmap(bm, 0, 0);
}
void PipeTask::draw() {
    SkBitmap bitmap;
    SetupBitmap(fReference.config(), fGM.get(), &bitmap);

    SkCanvas canvas(bitmap);
    PipeController pipeController(&canvas, &SkImageDecoder::DecodeMemory);
    SkGPipeWriter writer;

    SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
                                                 fFlags,
                                                 bitmap.width(),
                                                 bitmap.height());
    pipeCanvas->concat(fGM->getInitialTransform());
    fGM->draw(pipeCanvas);
    writer.endRecording();

    if (!BitmapsEqual(bitmap, fReference)) {
        this->fail();
        this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
    }
}
Exemple #6
0
bool PipePictureRenderer::render(const SkString* path, SkBitmap** out) {
    SkASSERT(fCanvas.get() != NULL);
    SkASSERT(fPicture != NULL);
    if (NULL == fCanvas.get() || NULL == fPicture) {
        return false;
    }

    PipeController pipeController(fCanvas.get());
    SkGPipeWriter writer;
    SkCanvas* pipeCanvas = writer.startRecording(&pipeController);
    pipeCanvas->drawPicture(*fPicture);
    writer.endRecording();
    fCanvas->flush();
    if (NULL != path) {
        return write(fCanvas, path, fJsonSummaryPtr);
    }
    if (NULL != out) {
        *out = SkNEW(SkBitmap);
        setup_bitmap(*out, fPicture->width(), fPicture->height());
        fCanvas->readPixels(*out, 0, 0);
    }
    return true;
}
    virtual void onDrawContent(SkCanvas* canvas) {
        if (fSocket) {
            if (fSocket->isConnected()) {
                if (fSync) {
                    int count = 0;
                    while (fSocket->readPacket(readData, this) > 0 &&
                           count < MAX_READ_PER_FRAME)
                        ++count;
                }
                else
                    fSocket->readPacket(readData, this);
            }
            else
                fSocket->connectToServer();
        }
        size_t bytesRead = 0;
        SkGPipeReader::Status status;
        SkCanvas bufferCanvas(fBase);
        SkCanvas* tempCanvas;
        while (fTotalBytesRead < fData.count()) {
            if (fVector)
                tempCanvas = canvas;
            else
                tempCanvas = &bufferCanvas;
            SkGPipeReader reader(tempCanvas);
            status = reader.playback(fData.begin() + fTotalBytesRead,
                                     fData.count() - fTotalBytesRead,
                                     &bytesRead);
            SkASSERT(SkGPipeReader::kError_Status != status);
            fTotalBytesRead += bytesRead;
        }
        if (fVector)
            fTotalBytesRead = 0;
        else
            canvas->drawBitmap(fBase, 0, 0, NULL);

        size_t totalBytesRead = 0;
        while (totalBytesRead < fBuffer.count()) {
            SkGPipeReader reader(canvas);
            status = reader.playback(fBuffer.begin() + totalBytesRead,
                                     fBuffer.count() - totalBytesRead,
                                     &bytesRead);
            SkASSERT(SkGPipeReader::kError_Status != status);
            totalBytesRead += bytesRead;
        }

        SkNetPipeController controller(canvas);
        SkGPipeWriter writer;
        SkCanvas* writerCanvas = writer.startRecording(&controller,
                                                       SkGPipeWriter::kCrossProcess_Flag);

        //controller.disablePlayback();
        SkPaint p;
        p.setColor(fPalette->getColor());
        p.setStyle(SkPaint::kStroke_Style);
        p.setStrokeWidth(fBrushSize);
        p.setStrokeCap(SkPaint::kRound_Cap);
        p.setStrokeJoin(SkPaint::kRound_Join);
        p.setAntiAlias(fAA);
        p.setPathEffect(new SkCornerPathEffect(55))->unref();
        writerCanvas->drawPath(fCurrLine, p);
        writer.endRecording();

        controller.writeToSocket(fSocket, fType);
        if (fType == SkSocket::kPipeAppend_type && fSocket) {
            fSocket->suspendWrite();
            fCurrLine.reset();
        }

        this->inval(NULL);
    }