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 "Properties.h"
19
20 #include "tests/common/TestUtils.h"
21
22 #include <SkBitmap.h>
23 #include <SkImage.h>
24 #include <gtest/gtest.h>
25
26 using namespace android;
27 using namespace android::uirenderer;
28
RENDERTHREAD_TEST(DeferredLayerUpdater,updateLayer)29 RENDERTHREAD_TEST(DeferredLayerUpdater, updateLayer) {
30 sp<DeferredLayerUpdater> layerUpdater = TestUtils::createTextureLayerUpdater(renderThread);
31 layerUpdater->setSize(100, 100);
32 layerUpdater->setBlend(true);
33
34 // updates are deferred so the backing layer should still be in its default state
35 EXPECT_EQ(0u, layerUpdater->backingLayer()->getWidth());
36 EXPECT_EQ(0u, layerUpdater->backingLayer()->getHeight());
37 EXPECT_FALSE(layerUpdater->backingLayer()->getForceFilter());
38 EXPECT_FALSE(layerUpdater->backingLayer()->isBlend());
39 EXPECT_EQ(Matrix4::identity(), layerUpdater->backingLayer()->getTexTransform());
40
41 // push the deferred updates to the layer
42 SkMatrix scaledMatrix = SkMatrix::MakeScale(0.5, 0.5);
43 SkBitmap bitmap;
44 bitmap.allocN32Pixels(16, 16);
45 sk_sp<SkImage> layerImage = SkImage::MakeFromBitmap(bitmap);
46 layerUpdater->updateLayer(true, scaledMatrix, layerImage);
47
48 // the backing layer should now have all the properties applied.
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