recording canvas background color completely affect the target canvas irrespective of the canvas bounds.

18 views
Skip to first unread message

SONAIPANDI SONAIPANDI

unread,
Jul 30, 2024, 6:52:11 AMJul 30
to skia-discuss
Hi all. I am recording the drawing commands and store in the skpicture in background thread like below.

SkPictureRecorder recorder;

SkCanvas* canvas = recorder.beginRecording(SkRect::MakeWH(256 * scaleFactor, 256 * scaleFactor));

canvas->scale(scaleFactor, scaleFactor);

if(key == "R0C0"){

canvas->drawColor(SK_ColorRED);

}

std::pair<bool, bool> result = drawInCanvas(canvas, surfaceinfopointer->getxOffset(), surfaceinfopointer->getyOffset(),width, height, validityBool, isCaching, zoomValue, surfaceinfopointer->getIsFaulty(),key);    //drawing code

sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();

surfaceinfopointer->setPicture(picture);

And then I playback the drawing commands in main thread like below.

 for(int i=startX; i<=endX; i++) {

                for(int j=startY; j<=endY; j++) {

                    std::string key = "R"+std::to_string(i)+"C"+std::to_string(j);

                    auto dictValue = surfaceListDict.get(key);

                    bool isvalid = false;

                    if(dictValue.has_value()){

                        auto dictValuePointer = dictValue->get();

 canvas->drawPicture(dictValuePointer->getPicture());

}

}

In main thread If R0C0 's picture replay the drawing commands the red color should affect the recording portion which is given in
beginRecording(SkRect::MakeWH(256 * scaleFactor, 256 * scaleFactor));
but the canvas bg color(red) is rendered for the whole canvas in main thread

If I clip the canvas rect like this 

canvas->clipRect(SkRect::MakeWH(256 * scaleFactor, 256 * scaleFactor));

I am getting red background color for the clipped region correctly in the main canvas.

But why we need to clip the rect then what about this parameter does SkRect::MakeWH(256 * scaleFactor, 256 * scaleFactor);

Could you please help me to understand Skpicture in detail?


Reply all
Reply to author
Forward
0 new messages