1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2019 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "include/core/SkPaint.h" 9cb93a386Sopenharmony_ci#include "include/core/SkPicture.h" 10cb93a386Sopenharmony_ci#include "include/core/SkPictureRecorder.h" 11cb93a386Sopenharmony_ci#include "include/core/SkRect.h" 12cb93a386Sopenharmony_ci#include "tests/Test.h" 13cb93a386Sopenharmony_ci#include "tools/debugger/DebugLayerManager.h" 14cb93a386Sopenharmony_ci 15cb93a386Sopenharmony_ci// Adds one full update, one partial update, and requests one image a few frames later. 16cb93a386Sopenharmony_cistatic void test_basic(skiatest::Reporter* reporter) { 17cb93a386Sopenharmony_ci // prepare supporting objects 18cb93a386Sopenharmony_ci int layerWidth = 100; 19cb93a386Sopenharmony_ci int layerHeight = 100; 20cb93a386Sopenharmony_ci 21cb93a386Sopenharmony_ci // make a picture that fully updates the layer 22cb93a386Sopenharmony_ci SkPictureRecorder rec; 23cb93a386Sopenharmony_ci SkCanvas* canvas = rec.beginRecording(layerWidth, layerHeight); 24cb93a386Sopenharmony_ci canvas->clear(0x00000000); 25cb93a386Sopenharmony_ci SkPaint paint; 26cb93a386Sopenharmony_ci paint.setColor(SK_ColorBLUE); 27cb93a386Sopenharmony_ci canvas->drawOval(SkRect::MakeLTRB(1,1,99,99), paint); 28cb93a386Sopenharmony_ci auto picture1 = rec.finishRecordingAsPicture(); 29cb93a386Sopenharmony_ci SkIRect dirtyRectFull = SkIRect::MakeLTRB(0, 0, layerWidth, layerHeight); 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ci // make a second picture that acts as a partial update. 32cb93a386Sopenharmony_ci SkPictureRecorder rec2; 33cb93a386Sopenharmony_ci canvas = rec2.beginRecording(layerWidth, layerHeight); 34cb93a386Sopenharmony_ci paint.setColor(SK_ColorGREEN); 35cb93a386Sopenharmony_ci canvas->drawOval(SkRect::MakeLTRB(40,40,60,60), paint); 36cb93a386Sopenharmony_ci auto picture2 = rec2.finishRecordingAsPicture(); 37cb93a386Sopenharmony_ci SkIRect dirtyRectPartial = SkIRect::MakeLTRB(40,40,60,60); 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_ci int node = 2; 40cb93a386Sopenharmony_ci 41cb93a386Sopenharmony_ci // create and exercise DebugLayerManager 42cb93a386Sopenharmony_ci DebugLayerManager dlm; 43cb93a386Sopenharmony_ci dlm.storeSkPicture(node, 0, picture1, dirtyRectFull); 44cb93a386Sopenharmony_ci dlm.storeSkPicture(node, 10, picture2, dirtyRectPartial); 45cb93a386Sopenharmony_ci auto frames = dlm.listFramesForNode(node); 46cb93a386Sopenharmony_ci 47cb93a386Sopenharmony_ci // Confirm the layer manager stored these at the right places. 48cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, frames.size() == 2); 49cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, frames[0] == 0); 50cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, frames[1] == 10); 51cb93a386Sopenharmony_ci 52cb93a386Sopenharmony_ci SkPixmap pixmap; 53cb93a386Sopenharmony_ci // request an image of the layer between the two updates. 54cb93a386Sopenharmony_ci for (int i=0; i<10; i++) { 55cb93a386Sopenharmony_ci auto image = dlm.getLayerAsImage(node, i); 56cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, image->width() == layerWidth); 57cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, image->height() == layerHeight); 58cb93a386Sopenharmony_ci // confirm center is blue, proving only first pic was drawn. 59cb93a386Sopenharmony_ci image->peekPixels(&pixmap); 60cb93a386Sopenharmony_ci SkColor paintColor = pixmap.getColor(50, 50); 61cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, paintColor == SK_ColorBLUE); 62cb93a386Sopenharmony_ci } 63cb93a386Sopenharmony_ci 64cb93a386Sopenharmony_ci // For any images after the second draw, confirm the center is green, but the area just outside 65cb93a386Sopenharmony_ci // that smaller circle is still blue, proving dlm drew both pictures. 66cb93a386Sopenharmony_ci for (int i=10; i<12; i++) { 67cb93a386Sopenharmony_ci auto image = dlm.getLayerAsImage(node, i); 68cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, image->width() == layerWidth); 69cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, image->height() == layerHeight); 70cb93a386Sopenharmony_ci image->peekPixels(&pixmap); 71cb93a386Sopenharmony_ci auto innerColor = pixmap.getColor(50, 50); 72cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, innerColor == SK_ColorGREEN); 73cb93a386Sopenharmony_ci auto outerColor = pixmap.getColor(10, 50); 74cb93a386Sopenharmony_ci REPORTER_ASSERT(reporter, outerColor == SK_ColorBLUE); 75cb93a386Sopenharmony_ci } 76cb93a386Sopenharmony_ci 77cb93a386Sopenharmony_ci 78cb93a386Sopenharmony_ci} 79cb93a386Sopenharmony_ci 80cb93a386Sopenharmony_ciDEF_TEST(DebugLayerManagerTest, reporter) { 81cb93a386Sopenharmony_ci test_basic(reporter); 82cb93a386Sopenharmony_ci} 83