116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck/*
216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck * Copyright (C) 2015 The Android Open Source Project
316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck *
416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck * Licensed under the Apache License, Version 2.0 (the "License");
516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck * you may not use this file except in compliance with the License.
616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck * You may obtain a copy of the License at
716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck *
816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck *      http://www.apache.org/licenses/LICENSE-2.0
916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck *
1016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck * Unless required by applicable law or agreed to in writing, software
1116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck * distributed under the License is distributed on an "AS IS" BASIS,
1216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck * See the License for the specific language governing permissions and
1416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck * limitations under the License.
1516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck */
1616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck
1716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck#include "TestSceneBase.h"
1816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck
1916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reckclass HwLayerAnimation;
2016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck
2127e58b4f54d693ff1db7ab2edb5d47ca296c1278Chris Craikstatic TestScene::Registrar _HwLayer(TestScene::Info{
2216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck    "hwlayer",
2316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck    "A nested pair of nodes with LAYER_TYPE_HARDWARE set on each. "
2416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck    "Tests the hardware layer codepath.",
2527e58b4f54d693ff1db7ab2edb5d47ca296c1278Chris Craik    TestScene::simpleCreateScene<HwLayerAnimation>
2616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck});
2716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck
2816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reckclass HwLayerAnimation : public TestScene {
2916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reckpublic:
3016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck    sp<RenderNode> card;
3116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck    void createContent(int width, int height, TestCanvas& canvas) override {
3216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck        card = TestUtils::createNode(0, 0, 200, 200,
3316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck                [](RenderProperties& props, TestCanvas& canvas) {
3416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck            props.mutateLayerProperties().setType(LayerType::RenderLayer);
3516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck            canvas.drawColor(0xFF0000FF, SkXfermode::kSrcOver_Mode);
3616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck        });
3716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck        canvas.drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); // background
3816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck        canvas.drawRenderNode(card.get());
3916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck    }
4016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck    void doFrame(int frameNr) override {
4116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck        int curFrame = frameNr % 150;
4216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck        card->mutateStagingProperties().setTranslationX(curFrame);
4316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck        card->mutateStagingProperties().setTranslationY(curFrame);
4416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck        card->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y);
4516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck    }
4616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck};
47