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" 1854fa17f667c285a5c9225e238c8132dfe830ef36Chris Craik#include "utils/Color.h" 1916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 2016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reckclass RecentsAnimation; 2116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 2227e58b4f54d693ff1db7ab2edb5d47ca296c1278Chris Craikstatic TestScene::Registrar _Recents(TestScene::Info{ 2316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck "recents", 2416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck "A recents-like scrolling list of textures. " 2516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck "Consists of updating a texture every frame", 2627e58b4f54d693ff1db7ab2edb5d47ca296c1278Chris Craik TestScene::simpleCreateScene<RecentsAnimation> 2716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck}); 2816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 2916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reckclass RecentsAnimation : public TestScene { 3016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reckpublic: 3116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck void createContent(int width, int height, TestCanvas& renderer) override { 3216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck static SkColor COLORS[] = { 3354fa17f667c285a5c9225e238c8132dfe830ef36Chris Craik Color::Red_500, 3454fa17f667c285a5c9225e238c8132dfe830ef36Chris Craik Color::Purple_500, 3554fa17f667c285a5c9225e238c8132dfe830ef36Chris Craik Color::Blue_500, 3654fa17f667c285a5c9225e238c8132dfe830ef36Chris Craik Color::Green_500, 3716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck }; 3816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 3916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck thumbnailSize = std::min(std::min(width, height) / 2, 720); 4016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck int cardsize = std::min(width, height) - dp(64); 4116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 4254fa17f667c285a5c9225e238c8132dfe830ef36Chris Craik renderer.drawColor(Color::White, SkXfermode::kSrcOver_Mode); 4316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck renderer.insertReorderBarrier(true); 4416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 4516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck int x = dp(32); 4616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck for (int i = 0; i < 4; i++) { 4716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck int y = (height / 4) * i; 4816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck SkBitmap thumb = TestUtils::createSkBitmap(thumbnailSize, thumbnailSize); 4916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck thumb.eraseColor(COLORS[i]); 5016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck sp<RenderNode> card = createCard(x, y, cardsize, cardsize, thumb); 5116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck card->mutateStagingProperties().setElevation(i * dp(8)); 5216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck renderer.drawRenderNode(card.get()); 5316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck mThumbnail = thumb; 5416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck mCards.push_back(card); 5516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck } 5616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 5716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck renderer.insertReorderBarrier(false); 5816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck } 5916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 6016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck void doFrame(int frameNr) override { 6116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck int curFrame = frameNr % 150; 6216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck for (size_t ci = 0; ci < mCards.size(); ci++) { 6316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck mCards[ci]->mutateStagingProperties().setTranslationY(curFrame); 6416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck mCards[ci]->setPropertyFieldsDirty(RenderNode::Y); 6516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck } 6616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck mThumbnail.eraseColor(TestUtils::interpolateColor( 6754fa17f667c285a5c9225e238c8132dfe830ef36Chris Craik curFrame / 150.0f, Color::Green_500, Color::DeepOrange_500)); 6816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck } 6916c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 7016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reckprivate: 7116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck sp<RenderNode> createCard(int x, int y, int width, int height, 7216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck const SkBitmap& thumb) { 7316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck return TestUtils::createNode(x, y, x + width, y + height, 7416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck [&thumb, width, height](RenderProperties& props, TestCanvas& canvas) { 7516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck props.setElevation(dp(16)); 7616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck props.mutableOutline().setRoundRect(0, 0, width, height, dp(10), 1); 7716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck props.mutableOutline().setShouldClip(true); 7816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 7954fa17f667c285a5c9225e238c8132dfe830ef36Chris Craik canvas.drawColor(Color::Grey_200, SkXfermode::kSrcOver_Mode); 8016c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck canvas.drawBitmap(thumb, 0, 0, thumb.width(), thumb.height(), 8116c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 0, 0, width, height, nullptr); 8216c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck }); 8316c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck } 8416c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck 8516c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck SkBitmap mThumbnail; 8616c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck std::vector< sp<RenderNode> > mCards; 8716c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck int thumbnailSize; 8816c9d6a92e1b86d448c00c52a1630f3e71e6df76John Reck}; 89