Derek Sollenberger | 56ad6ec | 2016-07-22 12:13:32 -0400 | [diff] [blame] | 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 "DeferredLayerUpdater.h" |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 18 | #include "GlLayer.h" |
Derek Sollenberger | 56ad6ec | 2016-07-22 12:13:32 -0400 | [diff] [blame] | 19 | |
| 20 | #include "renderthread/OpenGLPipeline.h" |
| 21 | #include "tests/common/TestUtils.h" |
| 22 | |
| 23 | #include <gtest/gtest.h> |
| 24 | |
| 25 | using namespace android; |
| 26 | using namespace android::uirenderer; |
| 27 | |
| 28 | RENDERTHREAD_TEST(DeferredLayerUpdater, updateLayer) { |
| 29 | renderthread::OpenGLPipeline pipeline(renderThread); |
| 30 | sp<DeferredLayerUpdater> layerUpdater = pipeline.createTextureLayer(); |
| 31 | layerUpdater->setSize(100, 100); |
| 32 | layerUpdater->setBlend(true); |
| 33 | |
| 34 | |
| 35 | // updates are deferred so the backing layer should still be in its default state |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 36 | if (layerUpdater->backingLayer()->getApi() == Layer::Api::OpenGL) { |
| 37 | GlLayer* glLayer = static_cast<GlLayer*>(layerUpdater->backingLayer()); |
| 38 | EXPECT_EQ((uint32_t)GL_NONE, glLayer->getRenderTarget()); |
| 39 | } |
Derek Sollenberger | 56ad6ec | 2016-07-22 12:13:32 -0400 | [diff] [blame] | 40 | EXPECT_EQ(0u, layerUpdater->backingLayer()->getWidth()); |
| 41 | EXPECT_EQ(0u, layerUpdater->backingLayer()->getHeight()); |
| 42 | EXPECT_FALSE(layerUpdater->backingLayer()->getForceFilter()); |
| 43 | EXPECT_FALSE(layerUpdater->backingLayer()->isBlend()); |
| 44 | EXPECT_EQ(Matrix4::identity(), layerUpdater->backingLayer()->getTexTransform()); |
| 45 | |
| 46 | // push the deferred updates to the layer |
| 47 | Matrix4 scaledMatrix; |
| 48 | scaledMatrix.loadScale(0.5, 0.5, 0.0); |
| 49 | layerUpdater->updateLayer(true, GL_TEXTURE_EXTERNAL_OES, scaledMatrix.data); |
| 50 | |
| 51 | // the backing layer should now have all the properties applied. |
Greg Daniel | 8cd3edf | 2017-01-09 14:15:41 -0500 | [diff] [blame] | 52 | if (layerUpdater->backingLayer()->getApi() == Layer::Api::OpenGL) { |
| 53 | GlLayer* glLayer = static_cast<GlLayer*>(layerUpdater->backingLayer()); |
| 54 | EXPECT_EQ((uint32_t)GL_TEXTURE_EXTERNAL_OES, glLayer->getRenderTarget()); |
| 55 | } |
Derek Sollenberger | 56ad6ec | 2016-07-22 12:13:32 -0400 | [diff] [blame] | 56 | EXPECT_EQ(100u, layerUpdater->backingLayer()->getWidth()); |
| 57 | EXPECT_EQ(100u, layerUpdater->backingLayer()->getHeight()); |
| 58 | EXPECT_TRUE(layerUpdater->backingLayer()->getForceFilter()); |
| 59 | EXPECT_TRUE(layerUpdater->backingLayer()->isBlend()); |
| 60 | EXPECT_EQ(scaledMatrix, layerUpdater->backingLayer()->getTexTransform()); |
| 61 | } |