summaryrefslogtreecommitdiff
path: root/libs/hwui/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/tests/unit')
-rw-r--r--libs/hwui/tests/unit/ABitmapTests.cpp46
-rw-r--r--libs/hwui/tests/unit/CacheManagerTests.cpp8
-rw-r--r--libs/hwui/tests/unit/FatVectorTests.cpp2
-rw-r--r--libs/hwui/tests/unit/GpuMemoryTrackerTests.cpp65
-rw-r--r--libs/hwui/tests/unit/RenderNodeDrawableTests.cpp43
-rw-r--r--libs/hwui/tests/unit/SkiaBehaviorTests.cpp4
-rw-r--r--libs/hwui/tests/unit/SkiaCanvasTests.cpp5
-rw-r--r--libs/hwui/tests/unit/SkiaDisplayListTests.cpp7
-rw-r--r--libs/hwui/tests/unit/SkiaPipelineTests.cpp90
-rw-r--r--libs/hwui/tests/unit/SkiaRenderPropertiesTests.cpp3
-rw-r--r--libs/hwui/tests/unit/VectorDrawableAtlasTests.cpp163
-rw-r--r--libs/hwui/tests/unit/VectorDrawableTests.cpp8
-rw-r--r--libs/hwui/tests/unit/main.cpp3
13 files changed, 130 insertions, 317 deletions
diff --git a/libs/hwui/tests/unit/ABitmapTests.cpp b/libs/hwui/tests/unit/ABitmapTests.cpp
new file mode 100644
index 000000000000..8e2f7e09d406
--- /dev/null
+++ b/libs/hwui/tests/unit/ABitmapTests.cpp
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+
+#include "android/graphics/bitmap.h"
+#include "apex/TypeCast.h"
+#include "hwui/Bitmap.h"
+#include "tests/common/TestUtils.h"
+
+using namespace android;
+using namespace android::uirenderer;
+
+TEST(ABitmap, notifyPixelsChanged) {
+ // generate a bitmap and its public API handle
+ sk_sp<Bitmap> bitmap(TestUtils::createBitmap(1, 1));
+ ABitmap* abmp = android::TypeCast::toABitmap(bitmap.get());
+
+ // verify that notification changes the genID
+ uint32_t genID = bitmap->getGenerationID();
+ ABitmap_notifyPixelsChanged(abmp);
+ ASSERT_TRUE(bitmap->getGenerationID() != genID);
+
+ // mark the bitmap as immutable
+ ASSERT_FALSE(bitmap->isImmutable());
+ bitmap->setImmutable();
+ ASSERT_TRUE(bitmap->isImmutable());
+
+ // attempt to notify that the pixels have changed
+ genID = bitmap->getGenerationID();
+ ABitmap_notifyPixelsChanged(abmp);
+ ASSERT_TRUE(bitmap->getGenerationID() == genID);
+}
diff --git a/libs/hwui/tests/unit/CacheManagerTests.cpp b/libs/hwui/tests/unit/CacheManagerTests.cpp
index 3f1ef93c878c..c83a3c88cbdd 100644
--- a/libs/hwui/tests/unit/CacheManagerTests.cpp
+++ b/libs/hwui/tests/unit/CacheManagerTests.cpp
@@ -33,7 +33,8 @@ static size_t getCacheUsage(GrContext* grContext) {
}
RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) {
- DisplayInfo displayInfo = DeviceInfo::get()->displayInfo();
+ int32_t width = DeviceInfo::get()->getWidth();
+ int32_t height = DeviceInfo::get()->getHeight();
GrContext* grContext = renderThread.getGrContext();
ASSERT_TRUE(grContext != nullptr);
@@ -42,7 +43,7 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) {
std::vector<sk_sp<SkSurface>> surfaces;
while (getCacheUsage(grContext) <= renderThread.cacheManager().getBackgroundCacheSize()) {
- SkImageInfo info = SkImageInfo::MakeA8(displayInfo.w, displayInfo.h);
+ SkImageInfo info = SkImageInfo::MakeA8(width, height);
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(grContext, SkBudgeted::kYes, info);
surface->getCanvas()->drawColor(SK_AlphaTRANSPARENT);
@@ -52,8 +53,7 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(CacheManager, trimMemory) {
}
// create an image and pin it so that we have something with a unique key in the cache
- sk_sp<Bitmap> bitmap =
- Bitmap::allocateHeapBitmap(SkImageInfo::MakeA8(displayInfo.w, displayInfo.h));
+ sk_sp<Bitmap> bitmap = Bitmap::allocateHeapBitmap(SkImageInfo::MakeA8(width, height));
sk_sp<SkImage> image = bitmap->makeImage();
ASSERT_TRUE(SkImage_pinAsTexture(image.get(), grContext));
diff --git a/libs/hwui/tests/unit/FatVectorTests.cpp b/libs/hwui/tests/unit/FatVectorTests.cpp
index 8523e6c9e973..6585a6249b44 100644
--- a/libs/hwui/tests/unit/FatVectorTests.cpp
+++ b/libs/hwui/tests/unit/FatVectorTests.cpp
@@ -15,7 +15,7 @@
*/
#include <gtest/gtest.h>
-#include <utils/FatVector.h>
+#include <ui/FatVector.h>
#include <tests/common/TestUtils.h>
diff --git a/libs/hwui/tests/unit/GpuMemoryTrackerTests.cpp b/libs/hwui/tests/unit/GpuMemoryTrackerTests.cpp
deleted file mode 100644
index dac888cd79ca..000000000000
--- a/libs/hwui/tests/unit/GpuMemoryTrackerTests.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <GpuMemoryTracker.h>
-#include <gtest/gtest.h>
-
-#include "renderthread/EglManager.h"
-#include "renderthread/RenderThread.h"
-#include "tests/common/TestUtils.h"
-
-#include <utils/StrongPointer.h>
-
-using namespace android;
-using namespace android::uirenderer;
-using namespace android::uirenderer::renderthread;
-
-class TestGPUObject : public GpuMemoryTracker {
-public:
- TestGPUObject() : GpuMemoryTracker(GpuObjectType::Texture) {}
-
- void changeSize(int newSize) { notifySizeChanged(newSize); }
-};
-
-// Other tests may have created a renderthread and EGL context.
-// This will destroy the EGLContext on RenderThread if it exists so that the
-// current thread can spoof being a GPU thread
-static void destroyEglContext() {
- if (TestUtils::isRenderThreadRunning()) {
- TestUtils::runOnRenderThread([](RenderThread& thread) { thread.destroyRenderingContext(); });
- }
-}
-
-TEST(GpuMemoryTracker, sizeCheck) {
- destroyEglContext();
-
- GpuMemoryTracker::onGpuContextCreated();
- ASSERT_EQ(0, GpuMemoryTracker::getTotalSize(GpuObjectType::Texture));
- ASSERT_EQ(0, GpuMemoryTracker::getInstanceCount(GpuObjectType::Texture));
- {
- TestGPUObject myObj;
- ASSERT_EQ(1, GpuMemoryTracker::getInstanceCount(GpuObjectType::Texture));
- myObj.changeSize(500);
- ASSERT_EQ(500, GpuMemoryTracker::getTotalSize(GpuObjectType::Texture));
- myObj.changeSize(1000);
- ASSERT_EQ(1000, GpuMemoryTracker::getTotalSize(GpuObjectType::Texture));
- myObj.changeSize(300);
- ASSERT_EQ(300, GpuMemoryTracker::getTotalSize(GpuObjectType::Texture));
- }
- ASSERT_EQ(0, GpuMemoryTracker::getTotalSize(GpuObjectType::Texture));
- ASSERT_EQ(0, GpuMemoryTracker::getInstanceCount(GpuObjectType::Texture));
- GpuMemoryTracker::onGpuContextDestroyed();
-}
diff --git a/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp b/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp
index c813cd945905..3632be06c45f 100644
--- a/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp
+++ b/libs/hwui/tests/unit/RenderNodeDrawableTests.cpp
@@ -24,6 +24,7 @@
#include "DamageAccumulator.h"
#include "FatalTestCanvas.h"
#include "IContextFactory.h"
+#include "hwui/Paint.h"
#include "RecordingCanvas.h"
#include "SkiaCanvas.h"
#include "pipeline/skia/SkiaDisplayList.h"
@@ -59,7 +60,7 @@ TEST(RenderNodeDrawable, create) {
namespace {
static void drawOrderedRect(Canvas* canvas, uint8_t expectedDrawOrder) {
- SkPaint paint;
+ Paint paint;
// order put in blue channel, transparent so overlapped content doesn't get rejected
paint.setColor(SkColorSetARGB(1, 0, 0, expectedDrawOrder));
canvas->drawRect(0, 0, 100, 100, paint);
@@ -211,7 +212,7 @@ TEST(RenderNodeDrawable, saveLayerClipAndMatrixRestore) {
ASSERT_EQ(SkRect::MakeLTRB(0, 0, 400, 800), getRecorderClipBounds(recorder));
EXPECT_TRUE(getRecorderMatrix(recorder).isIdentity());
- SkPaint paint;
+ Paint paint;
paint.setAntiAlias(true);
paint.setColor(SK_ColorGREEN);
recorder.drawRect(0.0f, 400.0f, 400.0f, 800.0f, paint);
@@ -291,7 +292,7 @@ RENDERTHREAD_TEST(RenderNodeDrawable, projectionReorder) {
properties.setTranslationX(SCROLL_X);
properties.setTranslationY(SCROLL_Y);
- SkPaint paint;
+ Paint paint;
paint.setColor(SK_ColorWHITE);
canvas.drawRect(0, 0, 100, 100, paint);
},
@@ -302,7 +303,7 @@ RENDERTHREAD_TEST(RenderNodeDrawable, projectionReorder) {
[](RenderProperties& properties, SkiaRecordingCanvas& canvas) {
properties.setProjectBackwards(true);
properties.setClipToBounds(false);
- SkPaint paint;
+ Paint paint;
paint.setColor(SK_ColorDKGRAY);
canvas.drawRect(-10, -10, 60, 60, paint);
},
@@ -310,7 +311,7 @@ RENDERTHREAD_TEST(RenderNodeDrawable, projectionReorder) {
auto child = TestUtils::createSkiaNode(
0, 50, 100, 100,
[&projectingRipple](RenderProperties& properties, SkiaRecordingCanvas& canvas) {
- SkPaint paint;
+ Paint paint;
paint.setColor(SK_ColorBLUE);
canvas.drawRect(0, 0, 100, 50, paint);
canvas.drawRenderNode(projectingRipple.get());
@@ -375,14 +376,14 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(RenderNodeDrawable, emptyReceiver) {
[](RenderProperties& properties, SkiaRecordingCanvas& canvas) {
properties.setProjectBackwards(true);
properties.setClipToBounds(false);
- SkPaint paint;
+ Paint paint;
canvas.drawRect(0, 0, 100, 100, paint);
},
"P");
auto child = TestUtils::createSkiaNode(
0, 0, 100, 100,
[&projectingRipple](RenderProperties& properties, SkiaRecordingCanvas& canvas) {
- SkPaint paint;
+ Paint paint;
canvas.drawRect(0, 0, 100, 100, paint);
canvas.drawRenderNode(projectingRipple.get());
},
@@ -483,7 +484,7 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(RenderNodeDrawable, projectionHwLayer) {
properties.setTranslationX(SCROLL_X);
properties.setTranslationY(SCROLL_Y);
- canvas.drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, SkPaint());
+ canvas.drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, Paint());
},
"B"); // B
auto projectingRipple = TestUtils::createSkiaNode(
@@ -491,14 +492,14 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(RenderNodeDrawable, projectionHwLayer) {
[](RenderProperties& properties, SkiaRecordingCanvas& canvas) {
properties.setProjectBackwards(true);
properties.setClipToBounds(false);
- canvas.drawOval(100, 100, 300, 300, SkPaint()); // drawn mostly out of layer bounds
+ canvas.drawOval(100, 100, 300, 300, Paint()); // drawn mostly out of layer bounds
},
"R"); // R
auto child = TestUtils::createSkiaNode(
100, 100, 300, 300,
[&projectingRipple](RenderProperties& properties, SkiaRecordingCanvas& canvas) {
canvas.drawRenderNode(projectingRipple.get());
- canvas.drawArc(0, 0, LAYER_WIDTH, LAYER_HEIGHT, 0.0f, 280.0f, true, SkPaint());
+ canvas.drawArc(0, 0, LAYER_WIDTH, LAYER_HEIGHT, 0.0f, 280.0f, true, Paint());
},
"C"); // C
auto parent = TestUtils::createSkiaNode(
@@ -578,7 +579,7 @@ RENDERTHREAD_TEST(RenderNodeDrawable, projectionChildScroll) {
0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
[](RenderProperties& properties, SkiaRecordingCanvas& canvas) {
properties.setProjectionReceiver(true);
- canvas.drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, SkPaint());
+ canvas.drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, Paint());
},
"B"); // B
auto projectingRipple = TestUtils::createSkiaNode(
@@ -591,7 +592,7 @@ RENDERTHREAD_TEST(RenderNodeDrawable, projectionChildScroll) {
properties.setTranslationY(SCROLL_Y);
properties.setProjectBackwards(true);
properties.setClipToBounds(false);
- canvas.drawOval(0, 0, 200, 200, SkPaint());
+ canvas.drawOval(0, 0, 200, 200, Paint());
},
"R"); // R
auto child = TestUtils::createSkiaNode(
@@ -946,7 +947,7 @@ RENDERTHREAD_TEST(RenderNodeDrawable, simple) {
[](RenderProperties& props, SkiaRecordingCanvas& canvas) {
sk_sp<Bitmap> bitmap(TestUtils::createBitmap(25, 25));
canvas.drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
- SkPaint());
+ Paint());
canvas.drawBitmap(*bitmap, 10, 10, nullptr);
});
@@ -1022,7 +1023,7 @@ TEST(RenderNodeDrawable, renderNode) {
auto child = TestUtils::createSkiaNode(
10, 10, 110, 110, [](RenderProperties& props, SkiaRecordingCanvas& canvas) {
- SkPaint paint;
+ Paint paint;
paint.setColor(SK_ColorWHITE);
canvas.drawRect(0, 0, 100, 100, paint);
});
@@ -1030,7 +1031,7 @@ TEST(RenderNodeDrawable, renderNode) {
auto parent = TestUtils::createSkiaNode(
0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
[&child](RenderProperties& props, SkiaRecordingCanvas& canvas) {
- SkPaint paint;
+ Paint paint;
paint.setColor(SK_ColorDKGRAY);
canvas.drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, paint);
@@ -1065,7 +1066,7 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(RenderNodeDrawable, layerComposeQuality) {
auto layerNode = TestUtils::createSkiaNode(
0, 0, LAYER_WIDTH, LAYER_HEIGHT,
[](RenderProperties& properties, SkiaRecordingCanvas& canvas) {
- canvas.drawPaint(SkPaint());
+ canvas.drawPaint(Paint());
});
layerNode->animatorProperties().mutateLayerProperties().setType(LayerType::RenderLayer);
@@ -1096,10 +1097,8 @@ TEST(ReorderBarrierDrawable, testShadowMatrix) {
int getDrawCounter() { return mDrawCounter; }
virtual void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override {
- // expect to draw 2 RenderNodeDrawable, 1 StartReorderBarrierDrawable,
- // 1 EndReorderBarrierDrawable
- mDrawCounter++;
- SkCanvas::onDrawDrawable(drawable, matrix);
+ // Do not expect this to be called. See RecordingCanvas.cpp DrawDrawable for context.
+ EXPECT_TRUE(false);
}
virtual void didTranslate(SkScalar dx, SkScalar dy) override {
@@ -1159,8 +1158,8 @@ TEST(ReorderBarrierDrawable, testShadowMatrix) {
// create a canvas not backed by any device/pixels, but with dimensions to avoid quick rejection
ShadowTestCanvas canvas(CANVAS_WIDTH, CANVAS_HEIGHT);
RenderNodeDrawable drawable(parent.get(), &canvas, false);
- canvas.drawDrawable(&drawable);
- EXPECT_EQ(9, canvas.getDrawCounter());
+ drawable.draw(&canvas);
+ EXPECT_EQ(5, canvas.getDrawCounter());
}
// Draw a vector drawable twice but with different bounds and verify correct bounds are used.
diff --git a/libs/hwui/tests/unit/SkiaBehaviorTests.cpp b/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
index df5f45618070..7951537e1525 100644
--- a/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
+++ b/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
@@ -48,14 +48,14 @@ TEST(SkiaBehavior, lightingColorFilter_simplify) {
SkColor observedColor;
SkBlendMode observedMode;
- ASSERT_TRUE(filter->asColorMode(&observedColor, &observedMode));
+ ASSERT_TRUE(filter->asAColorMode(&observedColor, &observedMode));
EXPECT_EQ(0xFF223344, observedColor);
EXPECT_EQ(SkBlendMode::kModulate, observedMode);
}
{
sk_sp<SkColorFilter> failFilter(SkColorMatrixFilter::MakeLightingFilter(0x11223344, 0x1));
- EXPECT_FALSE(failFilter->asColorMode(nullptr, nullptr));
+ EXPECT_FALSE(failFilter->asAColorMode(nullptr, nullptr));
}
}
diff --git a/libs/hwui/tests/unit/SkiaCanvasTests.cpp b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
index f6178aff0c2e..fcc64fdd0be6 100644
--- a/libs/hwui/tests/unit/SkiaCanvasTests.cpp
+++ b/libs/hwui/tests/unit/SkiaCanvasTests.cpp
@@ -16,6 +16,7 @@
#include "tests/common/TestUtils.h"
+#include <hwui/Paint.h>
#include <SkBlurDrawLooper.h>
#include <SkCanvasStateUtils.h>
#include <SkPicture.h>
@@ -32,7 +33,7 @@ TEST(SkiaCanvas, drawShadowLayer) {
// clear to white
canvas.drawColor(SK_ColorWHITE, SkBlendMode::kSrc);
- SkPaint paint;
+ Paint paint;
// it is transparent to ensure that we still draw the rect since it has a looper
paint.setColor(SK_ColorTRANSPARENT);
// this is how view's shadow layers are implemented
@@ -78,7 +79,7 @@ TEST(SkiaCanvas, colorSpaceXform) {
sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
// Playback to a software sRGB canvas. The result should be fully red.
- canvas.asSkCanvas()->drawPicture(picture);
+ canvas.drawPicture(*picture);
ASSERT_EQ(0xFF0000FF, *skBitmap.getAddr32(0, 0));
}
diff --git a/libs/hwui/tests/unit/SkiaDisplayListTests.cpp b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
index 6fb164a99ae4..d08aea668b2a 100644
--- a/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
+++ b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
@@ -208,10 +208,9 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaDisplayList, prepareListAndChildren_vdOffscr
test::TestContext testContext;
testContext.setRenderOffscreen(true);
auto surface = testContext.surface();
- int width, height;
- surface->query(NATIVE_WINDOW_WIDTH, &width);
- surface->query(NATIVE_WINDOW_HEIGHT, &height);
- canvasContext->setSurface(std::move(surface));
+ int width = ANativeWindow_getWidth(surface.get());
+ int height = ANativeWindow_getHeight(surface.get());
+ canvasContext->setSurface(surface.get());
TreeInfo info(TreeInfo::MODE_FULL, *canvasContext.get());
DamageAccumulator damageAccumulator;
diff --git a/libs/hwui/tests/unit/SkiaPipelineTests.cpp b/libs/hwui/tests/unit/SkiaPipelineTests.cpp
index a671bdada09a..e7a889d08cfd 100644
--- a/libs/hwui/tests/unit/SkiaPipelineTests.cpp
+++ b/libs/hwui/tests/unit/SkiaPipelineTests.cpp
@@ -23,12 +23,14 @@
#include "AnimationContext.h"
#include "DamageAccumulator.h"
#include "IContextFactory.h"
+#include "hwui/Paint.h"
#include "SkiaCanvas.h"
#include "pipeline/skia/SkiaDisplayList.h"
#include "pipeline/skia/SkiaOpenGLPipeline.h"
#include "pipeline/skia/SkiaRecordingCanvas.h"
#include "pipeline/skia/SkiaUtils.h"
#include "renderthread/CanvasContext.h"
+#include "tests/common/TestContext.h"
#include "tests/common/TestUtils.h"
#include <gui/BufferItemConsumer.h>
@@ -59,43 +61,10 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaPipeline, renderFrame) {
ASSERT_EQ(TestUtils::getColor(surface, 0, 0), SK_ColorRED);
}
-RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaPipeline, testOnPrepareTree) {
- auto redNode = TestUtils::createSkiaNode(
- 0, 0, 1, 1, [](RenderProperties& props, SkiaRecordingCanvas& redCanvas) {
- redCanvas.drawColor(SK_ColorRED, SkBlendMode::kSrcOver);
- });
-
- LayerUpdateQueue layerUpdateQueue;
- SkRect dirty = SkRectMakeLargest();
- std::vector<sp<RenderNode>> renderNodes;
- renderNodes.push_back(redNode);
- bool opaque = true;
- android::uirenderer::Rect contentDrawBounds(0, 0, 1, 1);
- auto pipeline = std::make_unique<SkiaOpenGLPipeline>(renderThread);
- {
- // add a pointer to a deleted vector drawable object in the pipeline
- sp<VectorDrawableRoot> dirtyVD(new VectorDrawableRoot(new VectorDrawable::Group()));
- dirtyVD->mutateProperties()->setScaledSize(5, 5);
- pipeline->getVectorDrawables()->push_back(dirtyVD.get());
- }
-
- // pipeline should clean list of dirty vector drawables before prepare tree
- pipeline->onPrepareTree();
-
- auto surface = SkSurface::MakeRasterN32Premul(1, 1);
- surface->getCanvas()->drawColor(SK_ColorBLUE, SkBlendMode::kSrcOver);
- ASSERT_EQ(TestUtils::getColor(surface, 0, 0), SK_ColorBLUE);
-
- // drawFrame will crash if "SkiaPipeline::onPrepareTree" did not clean invalid VD pointer
- pipeline->renderFrame(layerUpdateQueue, dirty, renderNodes, opaque, contentDrawBounds, surface,
- SkMatrix::I());
- ASSERT_EQ(TestUtils::getColor(surface, 0, 0), SK_ColorRED);
-}
-
RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaPipeline, renderFrameCheckOpaque) {
auto halfGreenNode = TestUtils::createSkiaNode(
0, 0, 2, 2, [](RenderProperties& props, SkiaRecordingCanvas& bottomHalfGreenCanvas) {
- SkPaint greenPaint;
+ Paint greenPaint;
greenPaint.setColor(SK_ColorGREEN);
greenPaint.setStyle(SkPaint::kFill_Style);
bottomHalfGreenCanvas.drawRect(0, 1, 2, 2, greenPaint);
@@ -293,7 +262,7 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaPipeline, deferRenderNodeScene) {
};
std::vector<sp<RenderNode>> nodes;
- SkPaint transparentPaint;
+ Paint transparentPaint;
transparentPaint.setAlpha(128);
// backdrop
@@ -424,21 +393,50 @@ RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaPipeline, clip_replace) {
EXPECT_EQ(1, surface->canvas()->mDrawCounter);
}
-static sp<Surface> createDummySurface() {
- sp<IGraphicBufferProducer> producer;
- sp<IGraphicBufferConsumer> consumer;
- BufferQueue::createBufferQueue(&producer, &consumer);
- producer->setMaxDequeuedBufferCount(1);
- producer->setAsyncMode(true);
- return new Surface(producer);
-}
-
RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaPipeline, context_lost) {
- auto surface = createDummySurface();
+ test::TestContext context;
+ auto surface = context.surface();
auto pipeline = std::make_unique<SkiaOpenGLPipeline>(renderThread);
EXPECT_FALSE(pipeline->isSurfaceReady());
- EXPECT_TRUE(pipeline->setSurface(surface.get(), SwapBehavior::kSwap_default, ColorMode::SRGB, 0));
+ EXPECT_TRUE(pipeline->setSurface(surface.get(), SwapBehavior::kSwap_default));
EXPECT_TRUE(pipeline->isSurfaceReady());
renderThread.destroyRenderingContext();
EXPECT_FALSE(pipeline->isSurfaceReady());
}
+
+RENDERTHREAD_SKIA_PIPELINE_TEST(SkiaPipeline, pictureCallback) {
+ // create a pipeline and add a picture callback
+ auto pipeline = std::make_unique<SkiaOpenGLPipeline>(renderThread);
+ int callbackCount = 0;
+ pipeline->setPictureCapturedCallback(
+ [&callbackCount](sk_sp<SkPicture>&& picture) { callbackCount += 1; });
+
+ // create basic red frame and render it
+ auto redNode = TestUtils::createSkiaNode(
+ 0, 0, 1, 1, [](RenderProperties& props, SkiaRecordingCanvas& redCanvas) {
+ redCanvas.drawColor(SK_ColorRED, SkBlendMode::kSrcOver);
+ });
+ LayerUpdateQueue layerUpdateQueue;
+ SkRect dirty = SkRectMakeLargest();
+ std::vector<sp<RenderNode>> renderNodes;
+ renderNodes.push_back(redNode);
+ bool opaque = true;
+ android::uirenderer::Rect contentDrawBounds(0, 0, 1, 1);
+ auto surface = SkSurface::MakeRasterN32Premul(1, 1);
+ pipeline->renderFrame(layerUpdateQueue, dirty, renderNodes, opaque, contentDrawBounds, surface,
+ SkMatrix::I());
+
+ // verify the callback was called
+ EXPECT_EQ(1, callbackCount);
+
+ // render a second frame and check the callback count
+ pipeline->renderFrame(layerUpdateQueue, dirty, renderNodes, opaque, contentDrawBounds, surface,
+ SkMatrix::I());
+ EXPECT_EQ(2, callbackCount);
+
+ // unset the callback, render another frame, check callback was not invoked
+ pipeline->setPictureCapturedCallback(nullptr);
+ pipeline->renderFrame(layerUpdateQueue, dirty, renderNodes, opaque, contentDrawBounds, surface,
+ SkMatrix::I());
+ EXPECT_EQ(2, callbackCount);
+}
diff --git a/libs/hwui/tests/unit/SkiaRenderPropertiesTests.cpp b/libs/hwui/tests/unit/SkiaRenderPropertiesTests.cpp
index 635429dea359..eec25c6bd40d 100644
--- a/libs/hwui/tests/unit/SkiaRenderPropertiesTests.cpp
+++ b/libs/hwui/tests/unit/SkiaRenderPropertiesTests.cpp
@@ -24,6 +24,7 @@
#include "DamageAccumulator.h"
#include "FatalTestCanvas.h"
#include "IContextFactory.h"
+#include "hwui/Paint.h"
#include "SkiaCanvas.h"
#include "pipeline/skia/SkiaDisplayList.h"
#include "pipeline/skia/SkiaPipeline.h"
@@ -60,7 +61,7 @@ static void testProperty(std::function<void(RenderProperties&)> propSetupCallbac
0, 0, CANVAS_WIDTH, CANVAS_HEIGHT,
[propSetupCallback](RenderProperties& props, SkiaRecordingCanvas& canvas) {
propSetupCallback(props);
- SkPaint paint;
+ Paint paint;
paint.setColor(SK_ColorWHITE);
canvas.drawRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT, paint);
});
diff --git a/libs/hwui/tests/unit/VectorDrawableAtlasTests.cpp b/libs/hwui/tests/unit/VectorDrawableAtlasTests.cpp
deleted file mode 100644
index 0c95fdd42851..000000000000
--- a/libs/hwui/tests/unit/VectorDrawableAtlasTests.cpp
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <gtest/gtest.h>
-
-#include <GrRectanizer.h>
-#include "pipeline/skia/VectorDrawableAtlas.h"
-#include "tests/common/TestUtils.h"
-
-using namespace android;
-using namespace android::uirenderer;
-using namespace android::uirenderer::renderthread;
-using namespace android::uirenderer::skiapipeline;
-
-RENDERTHREAD_SKIA_PIPELINE_TEST(VectorDrawableAtlas, addGetRemove) {
- VectorDrawableAtlas atlas(100 * 100);
- atlas.prepareForDraw(renderThread.getGrContext());
- // create 150 rects 10x10, which won't fit in the atlas (atlas can fit no more than 100 rects)
- const int MAX_RECTS = 150;
- AtlasEntry VDRects[MAX_RECTS];
-
- sk_sp<SkSurface> atlasSurface;
-
- // check we are able to allocate new rects
- // check that rects in the atlas do not intersect
- for (uint32_t i = 0; i < MAX_RECTS; i++) {
- VDRects[i] = atlas.requestNewEntry(10, 10, renderThread.getGrContext());
- if (0 == i) {
- atlasSurface = VDRects[0].surface;
- }
- ASSERT_TRUE(VDRects[i].key != INVALID_ATLAS_KEY);
- ASSERT_TRUE(VDRects[i].surface.get() != nullptr);
- ASSERT_TRUE(VDRects[i].rect.width() == 10 && VDRects[i].rect.height() == 10);
-
- // nothing in the atlas should intersect
- if (atlasSurface.get() == VDRects[i].surface.get()) {
- for (uint32_t j = 0; j < i; j++) {
- if (atlasSurface.get() == VDRects[j].surface.get()) {
- ASSERT_FALSE(VDRects[i].rect.intersect(VDRects[j].rect));
- }
- }
- }
- }
-
- // first 1/3 rects should all be in the same surface
- for (uint32_t i = 1; i < MAX_RECTS / 3; i++) {
- ASSERT_NE(VDRects[i].key, VDRects[0].key);
- ASSERT_EQ(VDRects[i].surface.get(), atlasSurface.get());
- }
-
- // first rect is using atlas and last is a standalone surface
- ASSERT_NE(VDRects[0].surface.get(), VDRects[MAX_RECTS - 1].surface.get());
-
- // check getEntry returns the same surfaces that we had created
- for (uint32_t i = 0; i < MAX_RECTS; i++) {
- auto VDRect = atlas.getEntry(VDRects[i].key);
- ASSERT_TRUE(VDRect.key != INVALID_ATLAS_KEY);
- ASSERT_EQ(VDRects[i].key, VDRect.key);
- ASSERT_EQ(VDRects[i].surface.get(), VDRect.surface.get());
- ASSERT_EQ(VDRects[i].rect, VDRect.rect);
- atlas.releaseEntry(VDRect.key);
- }
-
- // check that any new rects will be allocated in the atlas, even that rectanizer is full.
- // rects in the atlas should not intersect.
- for (uint32_t i = 0; i < MAX_RECTS / 3; i++) {
- VDRects[i] = atlas.requestNewEntry(10, 10, renderThread.getGrContext());
- ASSERT_TRUE(VDRects[i].key != INVALID_ATLAS_KEY);
- ASSERT_EQ(VDRects[i].surface.get(), atlasSurface.get());
- ASSERT_TRUE(VDRects[i].rect.width() == 10 && VDRects[i].rect.height() == 10);
- for (uint32_t j = 0; j < i; j++) {
- ASSERT_FALSE(VDRects[i].rect.intersect(VDRects[j].rect));
- }
- }
-}
-
-RENDERTHREAD_SKIA_PIPELINE_TEST(VectorDrawableAtlas, disallowSharedSurface) {
- VectorDrawableAtlas atlas(100 * 100);
- // don't allow to use a shared surface
- atlas.setStorageMode(VectorDrawableAtlas::StorageMode::disallowSharedSurface);
- atlas.prepareForDraw(renderThread.getGrContext());
- // create 150 rects 10x10, which won't fit in the atlas (atlas can fit no more than 100 rects)
- const int MAX_RECTS = 150;
- AtlasEntry VDRects[MAX_RECTS];
-
- // check we are able to allocate new rects
- // check that rects in the atlas use unique surfaces
- for (uint32_t i = 0; i < MAX_RECTS; i++) {
- VDRects[i] = atlas.requestNewEntry(10, 10, renderThread.getGrContext());
- ASSERT_TRUE(VDRects[i].key != INVALID_ATLAS_KEY);
- ASSERT_TRUE(VDRects[i].surface.get() != nullptr);
- ASSERT_TRUE(VDRects[i].rect.width() == 10 && VDRects[i].rect.height() == 10);
-
- // nothing in the atlas should use the same surface
- for (uint32_t j = 0; j < i; j++) {
- ASSERT_NE(VDRects[i].surface.get(), VDRects[j].surface.get());
- }
- }
-}
-
-RENDERTHREAD_SKIA_PIPELINE_TEST(VectorDrawableAtlas, repack) {
- VectorDrawableAtlas atlas(100 * 100);
- ASSERT_FALSE(atlas.isFragmented());
- atlas.prepareForDraw(renderThread.getGrContext());
- ASSERT_FALSE(atlas.isFragmented());
- // create 150 rects 10x10, which won't fit in the atlas (atlas can fit no more than 100 rects)
- const int MAX_RECTS = 150;
- AtlasEntry VDRects[MAX_RECTS];
-
- sk_sp<SkSurface> atlasSurface;
-
- // fill the atlas with check we are able to allocate new rects
- for (uint32_t i = 0; i < MAX_RECTS; i++) {
- VDRects[i] = atlas.requestNewEntry(10, 10, renderThread.getGrContext());
- if (0 == i) {
- atlasSurface = VDRects[0].surface;
- }
- ASSERT_TRUE(VDRects[i].key != INVALID_ATLAS_KEY);
- }
-
- ASSERT_FALSE(atlas.isFragmented());
-
- // first 1/3 rects should all be in the same surface
- for (uint32_t i = 1; i < MAX_RECTS / 3; i++) {
- ASSERT_NE(VDRects[i].key, VDRects[0].key);
- ASSERT_EQ(VDRects[i].surface.get(), atlasSurface.get());
- }
-
- // release all entries
- for (uint32_t i = 0; i < MAX_RECTS; i++) {
- auto VDRect = atlas.getEntry(VDRects[i].key);
- ASSERT_TRUE(VDRect.key != INVALID_ATLAS_KEY);
- atlas.releaseEntry(VDRect.key);
- }
-
- ASSERT_FALSE(atlas.isFragmented());
-
- // allocate 4x4 rects, which will fragment the atlas badly, because each entry occupies a 10x10
- // area
- for (uint32_t i = 0; i < 4 * MAX_RECTS; i++) {
- AtlasEntry entry = atlas.requestNewEntry(4, 4, renderThread.getGrContext());
- ASSERT_TRUE(entry.key != INVALID_ATLAS_KEY);
- }
-
- ASSERT_TRUE(atlas.isFragmented());
-
- atlas.repackIfNeeded(renderThread.getGrContext());
-
- ASSERT_FALSE(atlas.isFragmented());
-} \ No newline at end of file
diff --git a/libs/hwui/tests/unit/VectorDrawableTests.cpp b/libs/hwui/tests/unit/VectorDrawableTests.cpp
index 5db002862fcd..6d4c57413f00 100644
--- a/libs/hwui/tests/unit/VectorDrawableTests.cpp
+++ b/libs/hwui/tests/unit/VectorDrawableTests.cpp
@@ -85,9 +85,9 @@ const static TestData sTestDataSet[] = {
outPath->rCubicTo(8.0, 8.0, 8.0, 8.0, 8.0, 8.0);
outPath->cubicTo(16.0, 16.0, 9.0, 9.0, 9.0, 9.0);
outPath->rCubicTo(0.0, 0.0, 9.0, 9.0, 9.0, 9.0);
- outPath->arcTo(10.0, 10.0, 0.0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 10.0,
+ outPath->arcTo(10.0, 10.0, 0.0, SkPath::kLarge_ArcSize, SkPathDirection::kCW, 10.0,
10.0);
- outPath->arcTo(10.0, 10.0, 0.0, SkPath::kLarge_ArcSize, SkPath::kCW_Direction, 20.0,
+ outPath->arcTo(10.0, 10.0, 0.0, SkPath::kLarge_ArcSize, SkPathDirection::kCW, 20.0,
20.0);
}},
@@ -159,7 +159,7 @@ const static TestData sTestDataSet[] = {
},
[](SkPath* outPath) {
outPath->moveTo(300.0, 70.0);
- outPath->arcTo(230.0, 230.0, 0.0, SkPath::kLarge_ArcSize, SkPath::kCCW_Direction,
+ outPath->arcTo(230.0, 230.0, 0.0, SkPath::kLarge_ArcSize, SkPathDirection::kCCW,
301.0, 70.0);
outPath->close();
outPath->moveTo(300.0, 70.0);
@@ -395,7 +395,7 @@ TEST(VectorDrawable, drawPathWithoutIncrementingShaderRefCount) {
bitmap.allocN32Pixels(5, 5, false);
SkCanvas canvas(bitmap);
- sk_sp<SkShader> shader = SkShader::MakeColorShader(SK_ColorBLACK);
+ sk_sp<SkShader> shader = SkShaders::Color(SK_ColorBLACK);
// Initial ref count is 1
EXPECT_TRUE(shader->unique());
diff --git a/libs/hwui/tests/unit/main.cpp b/libs/hwui/tests/unit/main.cpp
index 83d888c310f0..402cb5814366 100644
--- a/libs/hwui/tests/unit/main.cpp
+++ b/libs/hwui/tests/unit/main.cpp
@@ -18,8 +18,6 @@
#include "gtest/gtest.h"
#include "Properties.h"
-#include "debug/GlesDriver.h"
-#include "debug/NullGlesDriver.h"
#include "hwui/Typeface.h"
#include "tests/common/LeakChecker.h"
@@ -65,7 +63,6 @@ int main(int argc, char* argv[]) {
}
// Replace the default GLES driver
- debug::GlesDriver::replace(std::make_unique<debug::NullGlesDriver>());
Properties::isolatedProcess = true;
// Run the tests