1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "BakedOpRenderer.h" 18 #include "BakedOpDispatcher.h" 19 #include "FrameBuilder.h" 20 #include "LayerUpdateQueue.h" 21 #include "RecordingCanvas.h" 22 #include "tests/common/TestUtils.h" 23 24 #include <gtest/gtest.h> 25 26 using namespace android; 27 using namespace android::uirenderer; 28 29 const FrameBuilder::LightGeometry sLightGeometery = { {100, 100, 100}, 50}; 30 const BakedOpRenderer::LightInfo sLightInfo = { 128, 128 }; 31 32 RENDERTHREAD_TEST(LeakCheck, saveLayer_overdrawRejection) { 33 auto node = TestUtils::createNode(0, 0, 100, 100, 34 [](RenderProperties& props, RecordingCanvas& canvas) { 35 canvas.saveLayerAlpha(0, 0, 100, 100, 128, SaveFlags::ClipToLayer); 36 canvas.drawRect(0, 0, 100, 100, SkPaint()); 37 canvas.restore(); 38 39 // opaque draw, rejects saveLayer beneath 40 canvas.drawRect(0, 0, 100, 100, SkPaint()); 41 }); 42 RenderState& renderState = renderThread.renderState(); 43 Caches& caches = Caches::getInstance(); 44 45 FrameBuilder frameBuilder(SkRect::MakeWH(100, 100), 100, 100, 46 sLightGeometery, Caches::getInstance()); 47 frameBuilder.deferRenderNode(*TestUtils::getSyncedNode(node)); 48 BakedOpRenderer renderer(caches, renderState, true, sLightInfo); 49 frameBuilder.replayBakedOps<BakedOpDispatcher>(renderer); 50 } 51 52 RENDERTHREAD_TEST(LeakCheck, saveLayerUnclipped_simple) { 53 auto node = TestUtils::createNode(0, 0, 200, 200, 54 [](RenderProperties& props, RecordingCanvas& canvas) { 55 canvas.saveLayerAlpha(10, 10, 190, 190, 128, (SaveFlags::Flags)(0)); 56 canvas.drawRect(0, 0, 200, 200, SkPaint()); 57 canvas.restore(); 58 }); 59 RenderState& renderState = renderThread.renderState(); 60 Caches& caches = Caches::getInstance(); 61 62 FrameBuilder frameBuilder(SkRect::MakeWH(200, 200), 200, 200, 63 sLightGeometery, Caches::getInstance()); 64 frameBuilder.deferRenderNode(*TestUtils::getSyncedNode(node)); 65 BakedOpRenderer renderer(caches, renderState, true, sLightInfo); 66 frameBuilder.replayBakedOps<BakedOpDispatcher>(renderer); 67 } 68