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