static jlong create(JNIEnv* env, jclass clazz, jlong rootNodePtr, jlong surfacePtr) { RenderNode* rootNode = reinterpret_cast<RenderNode*>(rootNodePtr); sp<Surface> surface(reinterpret_cast<Surface*>(surfacePtr)); ContextFactory factory; RenderProxy* proxy = new RenderProxy(false, rootNode, &factory); proxy->loadSystemProperties(); proxy->setSwapBehavior(kSwap_discardBuffer); proxy->initialize(surface); // Shadows can't be used via this interface, so just set the light source // to all 0s. (and width & height are unused, TODO remove them) proxy->setup(0, 0, (Vector3){0, 0, 0}, 0, 0, 0); return (jlong) proxy; }
static jboolean android_view_ThreadedRenderer_loadSystemProperties(JNIEnv* env, jobject clazz, jlong proxyPtr) { RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); return proxy->loadSystemProperties(); }
int main() { createTestEnvironment(); // 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(); RenderNode* rootNode = new RenderNode(); rootNode->incStrong(0); 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); proxy->loadSystemProperties(); proxy->initialize(surface); float lightX = width / 2.0; proxy->setup(width, height, (Vector3){lightX, dp(-200.0f), dp(800.0f)}, dp(800.0f), 255 * 0.075, 255 * 0.15); android::uirenderer::Rect DUMMY; std::vector< sp<RenderNode> > cards; DisplayListRenderer* renderer = startRecording(rootNode); renderer->drawColor(0xFFFFFFFF, SkXfermode::kSrcOver_Mode); renderer->insertReorderBarrier(true); for (int x = dp(16); x < (width - dp(116)); x += dp(116)) { for (int y = dp(16); y < (height - dp(116)); y += dp(116)) { sp<RenderNode> card = createCard(x, y, dp(100), dp(100)); renderer->drawRenderNode(card.get(), DUMMY, 0); cards.push_back(card); } } renderer->insertReorderBarrier(false); endRecording(renderer, rootNode); for (int i = 0; i < 150; i++) { ATRACE_NAME("UI-Draw Frame"); for (size_t ci = 0; ci < cards.size(); ci++) { cards[ci]->mutateStagingProperties().setTranslationX(i); cards[ci]->mutateStagingProperties().setTranslationY(i); cards[ci]->setPropertyFieldsDirty(RenderNode::X | RenderNode::Y); } nsecs_t frameTimeNs = systemTime(CLOCK_MONOTONIC); proxy->syncAndDrawFrame(frameTimeNs, 0, gDisplay.density); usleep(12000); } sleep(5); delete proxy; rootNode->decStrong(0); printf("Success!\n"); return 0; }