diff options
Diffstat (limited to 'libs/hwui/tests')
-rw-r--r-- | libs/hwui/tests/Android.mk | 36 | ||||
-rw-r--r-- | libs/hwui/tests/TestContext.cpp | 65 | ||||
-rw-r--r-- | libs/hwui/tests/TestContext.h | 38 | ||||
-rw-r--r-- | libs/hwui/tests/main.cpp | 23 |
4 files changed, 96 insertions, 66 deletions
diff --git a/libs/hwui/tests/Android.mk b/libs/hwui/tests/Android.mk index 7bdce7f..2fff07d 100644 --- a/libs/hwui/tests/Android.mk +++ b/libs/hwui/tests/Android.mk @@ -15,34 +15,9 @@ # local_target_dir := $(TARGET_OUT_DATA)/local/tmp -LOCAL_PATH:= $(call my-dir) +LOCAL_PATH:= $(call my-dir)/.. include $(CLEAR_VARS) -LOCAL_CFLAGS += -DUSE_OPENGL_RENDERER -DEGL_EGLEXT_PROTOTYPES -DGL_GLEXT_PROTOTYPES -LOCAL_CFLAGS += -Wno-unused-parameter -LOCAL_CFLAGS += -DATRACE_TAG=ATRACE_TAG_VIEW -DLOG_TAG=\"OpenGLRenderer\" - -LOCAL_SRC_FILES:= \ - TestContext.cpp \ - main.cpp - -LOCAL_C_INCLUDES += \ - $(LOCAL_PATH)/.. \ - external/skia/src/core - -LOCAL_SHARED_LIBRARIES := \ - liblog \ - libcutils \ - libutils \ - libskia \ - libgui \ - libui \ - libhwui - -ifeq ($(WITH_MALLOC_LEAK_CHECK),true) - LOCAL_CFLAGS += -DMALLOC_LEAK_CHECK -endif - LOCAL_MODULE_PATH := $(local_target_dir) LOCAL_MODULE:= hwuitest LOCAL_MODULE_TAGS := tests @@ -50,7 +25,10 @@ LOCAL_MULTILIB := both LOCAL_MODULE_STEM_32 := hwuitest LOCAL_MODULE_STEM_64 := hwuitest64 -include external/stlport/libstlport.mk -include $(BUILD_EXECUTABLE) +include $(LOCAL_PATH)/Android.common.mk -include $(call all-makefiles-under,$(LOCAL_PATH)) +LOCAL_SRC_FILES += \ + tests/TestContext.cpp \ + tests/main.cpp + +include $(BUILD_EXECUTABLE) diff --git a/libs/hwui/tests/TestContext.cpp b/libs/hwui/tests/TestContext.cpp index 35e402d..542bbae 100644 --- a/libs/hwui/tests/TestContext.cpp +++ b/libs/hwui/tests/TestContext.cpp @@ -16,30 +16,59 @@ #include "TestContext.h" -#include <gui/ISurfaceComposer.h> -#include <gui/SurfaceComposerClient.h> +namespace android { +namespace uirenderer { +namespace test { -using namespace android; +static const int IDENT_DISPLAYEVENT = 1; -DisplayInfo gDisplay; -sp<SurfaceComposerClient> gSession; - -void createTestEnvironment() { - gSession = new SurfaceComposerClient(); +static DisplayInfo getBuiltInDisplay() { + DisplayInfo display; sp<IBinder> dtoken(SurfaceComposerClient::getBuiltInDisplay( - ISurfaceComposer::eDisplayIdMain)); - status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &gDisplay); + ISurfaceComposer::eDisplayIdMain)); + status_t status = SurfaceComposerClient::getDisplayInfo(dtoken, &display); LOG_ALWAYS_FATAL_IF(status, "Failed to get display info\n"); + return display; +} + +android::DisplayInfo gDisplay = getBuiltInDisplay(); + +TestContext::TestContext() { + mLooper = new Looper(true); + mSurfaceComposerClient = new SurfaceComposerClient(); + mLooper->addFd(mDisplayEventReceiver.getFd(), IDENT_DISPLAYEVENT, + Looper::EVENT_INPUT, nullptr, nullptr); } -sp<SurfaceControl> createWindow(int width, int height) { - sp<SurfaceControl> control = gSession->createSurface(String8("HwuiTest"), - width, height, PIXEL_FORMAT_RGBX_8888); +TestContext::~TestContext() {} + +sp<Surface> TestContext::surface() { + if (!mSurfaceControl.get()) { + mSurfaceControl = mSurfaceComposerClient->createSurface(String8("HwuiTest"), + gDisplay.w, gDisplay.h, PIXEL_FORMAT_RGBX_8888); - SurfaceComposerClient::openGlobalTransaction(); - control->setLayer(0x7FFFFFF); - control->show(); - SurfaceComposerClient::closeGlobalTransaction(); + SurfaceComposerClient::openGlobalTransaction(); + mSurfaceControl->setLayer(0x7FFFFFF); + mSurfaceControl->show(); + SurfaceComposerClient::closeGlobalTransaction(); + } - return control; + return mSurfaceControl->getSurface(); } + +void TestContext::waitForVsync() { + // Request vsync + mDisplayEventReceiver.requestNextVsync(); + + // Wait + mLooper->pollOnce(-1); + + // Drain it + DisplayEventReceiver::Event buf[100]; + while (mDisplayEventReceiver.getEvents(buf, 100) > 0) { } +} + +} // namespace test +} // namespace uirenderer +} // namespace android + diff --git a/libs/hwui/tests/TestContext.h b/libs/hwui/tests/TestContext.h index 8a5d530..7b30fc1 100644 --- a/libs/hwui/tests/TestContext.h +++ b/libs/hwui/tests/TestContext.h @@ -17,17 +17,39 @@ #ifndef TESTCONTEXT_H #define TESTCONTEXT_H -#include <ui/DisplayInfo.h> +#include <gui/DisplayEventReceiver.h> +#include <gui/ISurfaceComposer.h> +#include <gui/SurfaceComposerClient.h> #include <gui/SurfaceControl.h> +#include <gui/Surface.h> +#include <ui/DisplayInfo.h> +#include <utils/Looper.h> + +namespace android { +namespace uirenderer { +namespace test { + +extern DisplayInfo gDisplay; +#define dp(x) ((x) * android::uirenderer::test::gDisplay.density) + +class TestContext { +public: + TestContext(); + ~TestContext(); + + sp<Surface> surface(); -extern android::DisplayInfo gDisplay; -#define dp(x) ((x) * gDisplay.density) + void waitForVsync(); -// Initializes all the static globals that are shared across all contexts -// such as display info -void createTestEnvironment(); +private: + sp<SurfaceComposerClient> mSurfaceComposerClient; + sp<SurfaceControl> mSurfaceControl; + DisplayEventReceiver mDisplayEventReceiver; + sp<Looper> mLooper; +}; -// Defaults to fullscreen -android::sp<android::SurfaceControl> createWindow(int width = -1, int height = -1); +} // namespace test +} // namespace uirenderer +} // namespace android #endif diff --git a/libs/hwui/tests/main.cpp b/libs/hwui/tests/main.cpp index d847d13..a12dac7 100644 --- a/libs/hwui/tests/main.cpp +++ b/libs/hwui/tests/main.cpp @@ -24,16 +24,18 @@ #include <DisplayListRenderer.h> #include <RenderNode.h> #include <renderthread/RenderProxy.h> +#include <renderthread/RenderTask.h> #include "TestContext.h" using namespace android; using namespace android::uirenderer; using namespace android::uirenderer::renderthread; +using namespace android::uirenderer::test; class ContextFactory : public IContextFactory { public: - virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) { + virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) override { return new AnimationContext(clock); } }; @@ -41,7 +43,7 @@ public: static DisplayListRenderer* startRecording(RenderNode* node) { DisplayListRenderer* renderer = new DisplayListRenderer(); renderer->setViewport(node->getWidth(), node->getHeight()); - renderer->prepare(false); + renderer->prepare(); return renderer; } @@ -66,24 +68,23 @@ sp<RenderNode> createCard(int x, int y, int width, int height) { return node; } -int main() { - createTestEnvironment(); +int main(int argc, char* argv[]) { + TestContext testContext; // create the native surface const int width = gDisplay.w; const int height = gDisplay.h; - sp<SurfaceControl> control = createWindow(width, height); - sp<Surface> surface = control->getSurface(); + sp<Surface> surface = testContext.surface(); RenderNode* rootNode = new RenderNode(); - rootNode->incStrong(0); + rootNode->incStrong(nullptr); rootNode->mutateStagingProperties().setLeftTopRightBottom(0, 0, width, height); rootNode->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); rootNode->mutateStagingProperties().setClipToBounds(false); rootNode->setPropertyFieldsDirty(RenderNode::GENERIC); ContextFactory factory; - RenderProxy* proxy = new RenderProxy(false, rootNode, &factory); + std::unique_ptr<RenderProxy> proxy(new RenderProxy(false, rootNode, &factory)); proxy->loadSystemProperties(); proxy->initialize(surface); float lightX = width / 2.0; @@ -110,6 +111,8 @@ int main() { endRecording(renderer, rootNode); for (int i = 0; i < 150; i++) { + testContext.waitForVsync(); + ATRACE_NAME("UI-Draw Frame"); for (size_t ci = 0; ci < cards.size(); ci++) { cards[ci]->mutateStagingProperties().setTranslationX(i); @@ -118,13 +121,11 @@ int main() { } nsecs_t frameTimeNs = systemTime(CLOCK_MONOTONIC); proxy->syncAndDrawFrame(frameTimeNs, 0, gDisplay.density); - usleep(12000); } sleep(5); - delete proxy; - rootNode->decStrong(0); + rootNode->decStrong(nullptr); printf("Success!\n"); return 0; |