void newton_sqrt() { typedef exprtk::symbol_table<T> symbol_table_t; typedef exprtk::expression<T> expression_t; typedef exprtk::parser<T> parser_t; typedef exprtk::function_compositor<T> compositor_t; T x = T(0); exprtk::symbol_table<T> symbol_table; symbol_table.add_constants(); symbol_table.add_variable("x",x); compositor_t compositor(symbol_table); compositor .add("newton_sqrt_impl", "switch " "{ " " case x < 0 : -inf; " " case x == 0 : 0; " " case x == 1 : 1; " " default: " " ~{ " " z := 100; " " y := x / 2; " " while ((z := (z - 1)) > 0) " " { " " if (equal(y * y,x), z := 0, 0);" " y := (1 / 2) * (y + (x / y)) " " } " " }; " "} ", "x","y","z"); compositor .add("newton_sqrt", "newton_sqrt_impl(x,0,0)","x"); std::string expression_str = "newton_sqrt(x)"; expression_t expression; expression.register_symbol_table(symbol_table); exprtk::parser<T> parser; parser.compile(expression_str,expression); for (std::size_t i = 0; i < 100; ++i) { x = i; T result = expression.value(); printf("sqrt(%03d) - Result: %12.10f\tReal: %12.10f\n", static_cast<unsigned int>(i), result, std::sqrt(x)); } }
// NoOverflowInIncrementVisuallyNonEmptyPixelCount tests fail if the number of // pixels is calculated in 32-bit integer, because 65536 * 65536 would become 0 // if it was calculated in 32-bit and thus it would be considered as empty. TEST_F(WebMeaningfulLayoutsTest, NoOverflowInIncrementVisuallyNonEmptyPixelCount) { SimRequest mainResource("https://example.com/test.html", "text/html"); SimRequest svgResource("https://example.com/test.svg", "image/svg+xml"); loadURL("https://example.com/test.html"); mainResource.start(); mainResource.write("<DOCTYPE html><body><img src=\"test.svg\">"); // Run pending tasks to initiate the request to test.svg. testing::runPendingTasks(); EXPECT_EQ(0, webViewClient().visuallyNonEmptyLayoutCount()); // We serve the SVG file and check visuallyNonEmptyLayoutCount() before // mainResource.finish() because finishing the main resource causes // |FrameView::m_isVisuallyNonEmpty| to be true and // visuallyNonEmptyLayoutCount() to be 1 irrespective of the SVG sizes. svgResource.start(); svgResource.write( "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"65536\" " "width=\"65536\"></svg>"); svgResource.finish(); compositor().beginFrame(); EXPECT_EQ(1, webViewClient().visuallyNonEmptyLayoutCount()); mainResource.finish(); }
int main(int argc, char *argv[]) { // Enable the following to have touch events generated from mouse events. // Very handy for testing touch event delivery without a real touch device. // QGuiApplication::setAttribute(Qt::AA_SynthesizeTouchForUnhandledMouseEvents, true); QGuiApplication app(argc, argv); QScreen *screen = QGuiApplication::primaryScreen(); QRect screenGeometry = screen->availableGeometry(); QSurfaceFormat format; format.setDepthBufferSize(16); QRect geom = screenGeometry; if (QCoreApplication::arguments().contains(QLatin1String("-nofullscreen"))) geom = QRect(screenGeometry.width() / 4, screenGeometry.height() / 4, screenGeometry.width() / 2, screenGeometry.height() / 2); QOpenGLWindow window(format, geom); QWindowCompositor compositor(&window); window.show(); return app.exec(); }
//surface implementation SurfaceRes::SurfaceRes(wl_client& client, unsigned int id) : Resource(client, id, &wl_surface_interface, &surfaceImplementation, 3), surfaceContext_(nullptr) { if(!compositor().backend()) { ny::sendWarning("SurfaceRes::SurfaceRes: no valid backend, cant create context."); return; } surfaceContext_ = compositor().backend()->createSurfaceContext(); if(!surfaceContext_) { ny::sendWarning("SurfaceRes::SurfaceRes: failed to create context."); } }
void QWaylandKeyboardPrivate::updateModifierState(uint code, uint32_t state) { #ifndef QT_NO_WAYLAND_XKB if (!xkb_context) return; xkb_state_update_key(xkb_state, code, state == WL_KEYBOARD_KEY_STATE_PRESSED ? XKB_KEY_DOWN : XKB_KEY_UP); uint32_t modsDepressed = xkb_state_serialize_mods(xkb_state, (xkb_state_component)XKB_STATE_DEPRESSED); uint32_t modsLatched = xkb_state_serialize_mods(xkb_state, (xkb_state_component)XKB_STATE_LATCHED); uint32_t modsLocked = xkb_state_serialize_mods(xkb_state, (xkb_state_component)XKB_STATE_LOCKED); uint32_t group = xkb_state_serialize_group(xkb_state, (xkb_state_component)XKB_STATE_EFFECTIVE); if (this->modsDepressed == modsDepressed && this->modsLatched == modsLatched && this->modsLocked == modsLocked && this->group == group) return; this->modsDepressed = modsDepressed; this->modsLatched = modsLatched; this->modsLocked = modsLocked; this->group = group; modifiers(compositor()->nextSerial(), modsDepressed, modsLatched, modsLocked, group); #else Q_UNUSED(code); Q_UNUSED(state); #endif }
void ScreenManager::run() { Uint32 last_ticks = 0; Uint32 elapsed_ticks = 0; handle_screen_switch(); while (!m_screen_stack.empty()) { Uint32 ticks = SDL_GetTicks(); elapsed_ticks += ticks - last_ticks; last_ticks = ticks; /** ticks (as returned from SDL_GetTicks) per frame */ const Uint32 ticks_per_frame = static_cast<Uint32>(1000.0 / m_target_framerate * g_debug.get_game_speed_multiplier()); if (elapsed_ticks > ticks_per_frame*4) { // when the game loads up or levels are switched the // elapsed_ticks grows extremely large, so we just ignore those // large time jumps elapsed_ticks = 0; } if (elapsed_ticks < ticks_per_frame) { Uint32 delay_ticks = ticks_per_frame - elapsed_ticks; SDL_Delay(delay_ticks); last_ticks += delay_ticks; elapsed_ticks += delay_ticks; } int frames = 0; while (elapsed_ticks >= ticks_per_frame && frames < MAX_FRAME_SKIP) { elapsed_ticks -= ticks_per_frame; float timestep = 1.0f / m_target_framerate; g_real_time += timestep; timestep *= m_speed; g_game_time += timestep; process_events(); update_gamelogic(timestep); frames += 1; } if (!m_screen_stack.empty()) { Compositor compositor(m_video_system); draw(compositor); } SoundManager::current()->update(); handle_screen_switch(); } }
void newton_sqrt() { typedef exprtk::symbol_table<T> symbol_table_t; typedef exprtk::expression<T> expression_t; typedef exprtk::parser<T> parser_t; typedef exprtk::function_compositor<T> compositor_t; typedef typename compositor_t::function function_t; T x = T(0); symbol_table_t symbol_table; symbol_table.add_constants(); symbol_table.add_variable("x",x); compositor_t compositor(symbol_table); compositor .add( function_t( // define function: newton_sqrt(x) "newton_sqrt", " switch " " { " " case x < 0 : -inf; " " case x == 0 : 0; " " case x == 1 : 1; " " default: " " ~{ " " var z := 100; " " var sqrt_x := x / 2; " " repeat " " sqrt_x := (1 / 2) * (sqrt_x + (x / sqrt_x)); " " if (equal(sqrt_x^2, x)) " " break[sqrt_x]; " " until ((z -= 1) <= 0); " " }; " " } ", "x")); std::string expression_str = "newton_sqrt(x)"; expression_t expression; expression.register_symbol_table(symbol_table); parser_t parser; parser.compile(expression_str,expression); for (std::size_t i = 0; i < 100; ++i) { x = i; T result = expression.value(); printf("sqrt(%03d) - Result: %12.10f\tReal: %12.10f\n", static_cast<unsigned int>(i), result, std::sqrt(x)); } }
void RenderView::repaintRectangleInViewAndCompositedLayers(const IntRect& ur, bool immediate) { if (!shouldRepaint(ur)) return; repaintViewRectangle(ur, immediate); #if USE(ACCELERATED_COMPOSITING) // If we're a frame, repaintViewRectangle will have repainted via a RenderObject in the // parent document. if (document()->ownerElement()) return; if (compositor()->inCompositingMode()) compositor()->repaintCompositedLayersAbsoluteRect(ur); #endif }
std::vector<std::string> hmd_type::get_vulkan_device_extensions_required( VkPhysicalDevice physical_device) const { vr::IVRCompositor *compositor(vr::VRCompositor()); std::string extensions(compositor->GetVulkanDeviceExtensionsRequired(physical_device, nullptr, 0), '\0'); compositor->GetVulkanDeviceExtensionsRequired(physical_device, &extensions[0], uint32_t(extensions.size())); return string_split(trim_null_characters(std::move(extensions)), " "); }
//ON PAINT EVENTS void DissolvedWidget::paintEvent(QPaintEvent *){ QPainter scope(&m_scope); scope.drawPixmap(-1,0,m_scope.width(),m_scope.height(), m_scope); scope.setPen(QPen(QColor(0,0,0,0))); scope.setBrush(QColor(0,0,0,255)); scope.drawRect(m_scope.width()-1,0,1,m_scope.height()); scope.setBrush(QColor(0,255,0,255)); int scope_dif = rand()%(m_scope.height()/2); scope.drawRect(m_scope.width()-1,scope_dif,1,2*scope_dif); QPainter compositor(&m_composit); switch (m_location){ case Map: { QPixmap background = QPixmap("://floorplan"); compositor.drawPixmap(0,0,background.width(),background.height(),background); } break; case Patient: { QPixmap background = QPixmap("://patient"); compositor.drawPixmap(0,0,background.width(),background.height(),background); } break; case Lab1: { QPixmap background = QPixmap("://lab1"); compositor.drawPixmap(0,0,background.width(),background.height(),background); } break; case Lab2: { QPixmap background = QPixmap("://lab2"); compositor.drawPixmap(0,0,background.width(),background.height(),background); } break; case Lab3: { QPixmap background = QPixmap("://lab3"); compositor.drawPixmap(0,0,background.width(),background.height(),background); } break; default: break; } QPixmap hud = QPixmap("://hud"); compositor.drawPixmap(0,800,hud.width(),hud.height(),hud); QPixmap item = QPixmap("://dna_green"); compositor.drawPixmap( 7,810,100,100,item); item = QPixmap("://proteine"); compositor.drawPixmap(117,806,100,100,item); item = QPixmap("://gel"); compositor.drawPixmap(224,806,100,100,item); item = QPixmap("://vector"); compositor.drawPixmap(331,806,100,100,item); item = QPixmap("://primer"); compositor.drawPixmap( 10,913,100,100,item); item = QPixmap("://urin"); compositor.drawPixmap(117,913,100,100,item); item = QPixmap("://dna_red"); compositor.drawPixmap(224,913,100,100,item); compositor.drawPixmap(834,919,m_scope.width(),m_scope.height(),m_scope); QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); painter.drawPixmap(0,0,this->width(), this->height(), m_composit); }
void RenderLayerStackingNode::dirtyNormalFlowList() { ASSERT(m_layerListMutationAllowed); #if !ASSERT_DISABLED updateStackingParentForNormalFlowList(0); #endif if (m_normalFlowList) m_normalFlowList->clear(); m_normalFlowListDirty = true; if (!renderer()->documentBeingDestroyed()) { compositor()->setCompositingLayersNeedRebuild(); if (layer()->acceleratedCompositingForOverflowScrollEnabled()) compositor()->setNeedsToRecomputeCompositingRequirements(); } }
// Compositing layer dimensions take outline size into account, so we have to recompute layer // bounds when it changes. // FIXME: This is ugly; it would be nice to have a better way to do this. void RenderView::setMaximalOutlineSize(int o) { if (o != m_maximalOutlineSize) { m_maximalOutlineSize = o; // maximalOutlineSize affects compositing layer dimensions. compositor()->setCompositingLayersNeedRebuild(); // FIXME: this really just needs to be a geometry update. } }
void QWaylandTouchPrivate::sendUp(uint32_t time, int touch_id) { if (!focusResource) return; uint32_t serial = compositor()->nextSerial(); wl_touch_send_up(focusResource->handle, serial, time, touch_id); }
TEST_F(WebMeaningfulLayoutsTest, FinishedParsing) { SimRequest mainResource("https://example.com/index.html", "text/html"); loadURL("https://example.com/index.html"); mainResource.complete("content"); compositor().beginFrame(); EXPECT_EQ(1, webViewClient().finishedParsingLayoutCount()); }
/** * Get the weston_seat associated with the Weston compositor. * Currently, only one (1) seat is supported by this plugin. **/ struct weston_seat * Globals::seat() { struct wl_list *seat_list; struct weston_seat *seat; seat_list = &compositor()->seat_list; assert(wl_list_length(seat_list) == 1); seat = container_of(seat_list->next, struct weston_seat, link); return seat; }
/** * Get the weston_output associated with the Weston compositor. * Currently, only one (1) output is supported by this plugin. **/ struct weston_output * Globals::output() { struct wl_list *output_list; output_list = &compositor()->output_list; if (wl_list_length(output_list) != 1) { weston_log("weston-wfits: ERROR: single output support only!\n"); assert(wl_list_length(output_list) == 1); } return container_of(output_list->next, struct weston_output, link); }
void SurfaceRes::sendFrameDone() { for(auto& cb : commited_.frameCallbacks) { if(cb) { wl_callback_send_done(&cb->wlResource(), compositor().time()); cb->destroy(); } } commited_.frameCallbacks.clear(); }
TEST_F(WebMeaningfulLayoutsTest, FinishedParsingThenLoading) { SimRequest mainResource("https://example.com/index.html", "text/html"); SimRequest imageResource("https://example.com/cat.png", "image/png"); loadURL("https://example.com/index.html"); mainResource.complete("<img src=cat.png>"); compositor().beginFrame(); EXPECT_EQ(1, webViewClient().finishedParsingLayoutCount()); EXPECT_EQ(0, webViewClient().finishedLoadingLayoutCount()); imageResource.complete("image data"); // Pump the message loop to process the image loading task. testing::runPendingTasks(); compositor().beginFrame(); EXPECT_EQ(1, webViewClient().finishedParsingLayoutCount()); EXPECT_EQ(1, webViewClient().finishedLoadingLayoutCount()); }
void ClientWindowQuickItem::mousePressEvent(QMouseEvent *event) { Q_D(ClientWindowQuickItem); // Let mouse press go through anyway, if focus on click is enabled this // will give focus to the window before the use can drag it QWaylandQuickShellSurfaceItem::mousePressEvent(event); // If the modifier is pressed we initiate a move operation if (d->isModifierHeld && event->buttons().testFlag(Qt::LeftButton)) { QWaylandWlShellSurface *wlShellSurface = qobject_cast<QWaylandWlShellSurface *>(shellSurface()); if (wlShellSurface) { Q_EMIT wlShellSurface->startMove(compositor()->defaultSeat()); return; } QWaylandXdgSurface *xdgSurface = qobject_cast<QWaylandXdgSurface *>(shellSurface()); if (xdgSurface) { Q_EMIT xdgSurface->startMove(compositor()->defaultSeat()); return; } } }
TEST_F(IntersectionObserverTest, ObserveSchedulesFrame) { SimRequest mainResource("https://example.com/", "text/html"); loadURL("https://example.com/"); mainResource.complete("<div id='target'></div>"); IntersectionObserverInit observerInit; TrackExceptionState exceptionState; TestIntersectionObserverCallback* observerCallback = new TestIntersectionObserverCallback(document()); IntersectionObserver* observer = IntersectionObserver::create( observerInit, *observerCallback, exceptionState); ASSERT_FALSE(exceptionState.hadException()); compositor().beginFrame(); ASSERT_FALSE(compositor().needsBeginFrame()); EXPECT_TRUE(observer->takeRecords(exceptionState).isEmpty()); EXPECT_EQ(observerCallback->callCount(), 0); Element* target = document().getElementById("target"); ASSERT_TRUE(target); observer->observe(target, exceptionState); EXPECT_TRUE(compositor().needsBeginFrame()); }
void RenderLayerStackingNode::dirtyNormalFlowList() { ASSERT(m_layerListMutationAllowed); #if ASSERT_ENABLED updateStackingParentForNormalFlowList(0); #endif if (m_normalFlowList) m_normalFlowList->clear(); m_normalFlowListDirty = true; if (!renderer()->documentBeingDestroyed()) compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); }
void RenderLayerStackingNode::dirtyZOrderLists() { ASSERT(m_layerListMutationAllowed); ASSERT(isStackingContainer()); #if !ASSERT_DISABLED updateStackingParentForZOrderLists(0); #endif if (m_posZOrderList) m_posZOrderList->clear(); if (m_negZOrderList) m_negZOrderList->clear(); m_zOrderListsDirty = true; m_descendantsAreContiguousInStackingOrderDirty = true; if (!renderer()->documentBeingDestroyed()) { compositor()->setNeedsUpdateCompositingRequirementsState(); compositor()->setCompositingLayersNeedRebuild(); if (layer()->acceleratedCompositingForOverflowScrollEnabled()) compositor()->setNeedsToRecomputeCompositingRequirements(); } }
TEST_F(WebMeaningfulLayoutsTest, FinishedLoading) { SimRequest mainResource("https://example.com/index.html", "text/html"); loadURL("https://example.com/index.html"); mainResource.start(); mainResource.write("content"); mainResource.finish(); compositor().beginFrame(); EXPECT_TRUE(webViewClient().hadFinishedLoadingLayout()); }
int main( int argc, char** argv ) { kvs::glut::Application app( argc, argv ); kvs::glut::Screen screen( &app ); screen.background()->setColor( kvs::RGBColor( 255, 255, 255 ) ); screen.show(); kvs::Vector3ui resolution( 32, 32, 32 ); kvs::StructuredVolumeObject* object1 = new kvs::HydrogenVolumeData( resolution ); kvs::glew::StochasticUniformGridEngine* engine1 = new kvs::glew::StochasticUniformGridEngine(); engine1->setShader( kvs::Shader::BlinnPhong( 0.3, 0.5, 0.8, 100 ) ); kvs::ColorMap cmap1( kvs::RGBFormulae::Hot( 256 ) ); kvs::OpacityMap omap1( 256 ); omap1.setRange( object1->minValue(), object1->maxValue() ); omap1.addPoint( object1->minValue(), 0 ); omap1.addPoint( object1->maxValue(), 0.8 ); omap1.create(); kvs::TransferFunction tfunc1( cmap1, omap1 ); engine1->setTransferFunction( tfunc1 ); kvs::StructuredVolumeObject* volume = new kvs::TornadoVolumeData( resolution ); kvs::StructuredVolumeObject* object2 = new kvs::StructuredVectorToScalar( volume ); kvs::glew::StochasticUniformGridEngine* engine2 = new kvs::glew::StochasticUniformGridEngine(); engine2->setShader( kvs::Shader::BlinnPhong( 0.8, 0.2, 0.8, 50 ) ); kvs::ColorMap cmap2( kvs::RGBFormulae::PM3D( 256 ) ); kvs::OpacityMap omap2( 256 ); omap2.setRange( object2->minValue(), object2->maxValue() ); omap2.addPoint( object2->minValue(), 0 ); omap2.addPoint( object2->maxValue(), 0.3 ); omap2.create(); kvs::TransferFunction tfunc2( cmap2, omap2 ); engine2->setTransferFunction( tfunc2 ); delete volume; kvs::ObjectManager* object_manager = screen.objectManager(); kvs::RendererManager* renderer_manager = screen.rendererManager(); kvs::IDManager* id_manager = screen.IDManager(); kvs::glew::StochasticRenderingCompositor compositor( object_manager, renderer_manager, id_manager ); compositor.setRepetitionLevel( 50 ); compositor.enableLODControl( 1 ); compositor.registerObject( object1, engine1 ); compositor.registerObject( object2, engine2 ); return app.run(); }
void gcd() { typedef exprtk::symbol_table<T> symbol_table_t; typedef exprtk::expression<T> expression_t; typedef exprtk::parser<T> parser_t; typedef exprtk::function_compositor<T> compositor_t; typedef typename compositor_t::function function_t; symbol_table_t symbol_table; symbol_table.add_function("println",gcd_println); compositor_t compositor(symbol_table); compositor .add( function_t( // define function: gcd(x,y) "gcd", " switch " " { " " case 0 = x : 0; " " case 0 = y : x; " " case x = y : x; " " case x > y : gcd(x - y, y); " " default : gcd(x, y - x); " " } ", "x","y")); const std::string gcd_program = " i := 0; " " while ((i += 1) < 100) " " { " " j := 0; " " repeat " " println(i, j, gcd(i,j)); " " until ((j += 1) >= 100); " " }; "; expression_t expression; expression.register_symbol_table(symbol_table); parser_t parser; parser.enable_unknown_symbol_resolver(); parser.compile(gcd_program,expression); expression.value(); }
void RenderLayerStackingNode::dirtyZOrderLists() { ASSERT(m_layerListMutationAllowed); ASSERT(isStackingContext()); #if ASSERT_ENABLED updateStackingParentForZOrderLists(0); #endif if (m_posZOrderList) m_posZOrderList->clear(); if (m_negZOrderList) m_negZOrderList->clear(); m_zOrderListsDirty = true; if (!renderer()->documentBeingDestroyed()) compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); }
void RunPriorityBp( PriorityBpRunner& priorityBpRunner, SettingsScalable& settingsScalable, ImageScalable& imageScalable, MaskScalable& maskScalable, const std::string& highResOutputFilePath, int depth) { Compositor::Input compositorInput(settingsScalable, imageScalable, maskScalable); priorityBpRunner.RunAndGetPatches(compositorInput.patches); std::auto_ptr<Compositor> compositor(CompositorFactory::Create(settingsScalable.compositorPatchType, settingsScalable.compositorPatchBlender)); if (compositor.get()) { OutputWxImage outputWxImage(highResOutputFilePath, depth); compositor->Compose(compositorInput, outputWxImage); } }
void SurfaceRes::remap() { if(!mapped()) return; auto* bckn = compositor().backend(); if(!bckn) { ny::sendWarning("SurfaceRes::commit: compositor has no valid backend"); return; } mappedOutputs_ = bckn->outputsAt(extents()); ny::sendLog("found mapOutputs: ", mappedOutputs_.size()); for(auto* o : mappedOutputs_) { o->mapSurface(*this); } }
TEST_F(WebMeaningfulLayoutsTest, VisuallyNonEmptyTextCharacters) { SimRequest mainResource("https://example.com/index.html", "text/html"); loadURL("https://example.com/index.html"); mainResource.start(); // Write 201 characters. const char* tenCharacters = "0123456789"; for (int i = 0; i < 20; ++i) mainResource.write(tenCharacters); mainResource.write("!"); mainResource.finish(); compositor().beginFrame(); EXPECT_EQ(1, webViewClient().visuallyNonEmptyLayoutCount()); }
void PaintLayerStackingNode::dirtyZOrderLists() { #if DCHECK_IS_ON() DCHECK(m_layerListMutationAllowed); #endif DCHECK(isStackingContext()); #if ENABLE(ASSERT) updateStackingParentForZOrderLists(0); #endif if (m_posZOrderList) m_posZOrderList->clear(); if (m_negZOrderList) m_negZOrderList->clear(); m_zOrderListsDirty = true; if (!layoutObject()->documentBeingDestroyed()) compositor()->setNeedsCompositingUpdate(CompositingUpdateRebuildTree); }