DeferredLayerUpdaterTests.cpp revision 56ad6ec42f814e9e61030ff819cac4e5d31def8b
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"
18
19#include "renderthread/OpenGLPipeline.h"
20#include "tests/common/TestUtils.h"
21
22#include <gtest/gtest.h>
23
24using namespace android;
25using namespace android::uirenderer;
26
27RENDERTHREAD_TEST(DeferredLayerUpdater, updateLayer) {
28    renderthread::OpenGLPipeline pipeline(renderThread);
29    sp<DeferredLayerUpdater> layerUpdater = pipeline.createTextureLayer();
30    layerUpdater->setSize(100, 100);
31    layerUpdater->setBlend(true);
32
33
34    // updates are deferred so the backing layer should still be in its default state
35    EXPECT_EQ((uint32_t)GL_NONE, layerUpdater->backingLayer()->getRenderTarget());
36    EXPECT_EQ(0u, layerUpdater->backingLayer()->getWidth());
37    EXPECT_EQ(0u, layerUpdater->backingLayer()->getHeight());
38    EXPECT_FALSE(layerUpdater->backingLayer()->getForceFilter());
39    EXPECT_FALSE(layerUpdater->backingLayer()->isBlend());
40    EXPECT_EQ(Matrix4::identity(), layerUpdater->backingLayer()->getTexTransform());
41
42    // push the deferred updates to the layer
43    Matrix4 scaledMatrix;
44    scaledMatrix.loadScale(0.5, 0.5, 0.0);
45    layerUpdater->updateLayer(true, GL_TEXTURE_EXTERNAL_OES, scaledMatrix.data);
46
47    // the backing layer should now have all the properties applied.
48    EXPECT_EQ((uint32_t)GL_TEXTURE_EXTERNAL_OES, layerUpdater->backingLayer()->getRenderTarget());
49    EXPECT_EQ(100u, layerUpdater->backingLayer()->getWidth());
50    EXPECT_EQ(100u, layerUpdater->backingLayer()->getHeight());
51    EXPECT_TRUE(layerUpdater->backingLayer()->getForceFilter());
52    EXPECT_TRUE(layerUpdater->backingLayer()->isBlend());
53    EXPECT_EQ(scaledMatrix, layerUpdater->backingLayer()->getTexTransform());
54}
55