TEST (OpenGLFullscreenRegion, OneFullscreen)
{
    FullscreenRegion monitor (CompRect (0, 0, 1024, 768));
    EXPECT_TRUE  (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768),
                                       FullscreenRegion::Desktop));
}
TEST (OpenGLFullscreenRegion, NormalWindows)
{
    FullscreenRegion monitor (CompRect (0, 0, 1024, 768));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (10, 10, 40, 30)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (20, 20, 50, 20)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768),
                                       FullscreenRegion::Desktop));
}
TEST (OpenGLFullscreenRegion, AlphaOverFullscreen)
{
    FullscreenRegion monitor (CompRect (0, 0, 1024, 768));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (50, 60, 70, 80),
                                       FullscreenRegion::Alpha));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768),
                                       FullscreenRegion::Desktop));
}
TEST (OpenGLFullscreenRegion, MaximizedWithDocks)  // LP: #1053902
{
    FullscreenRegion monitor (CompRect (0, 0, 1024, 768));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 24)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 24, 64, 744)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (64, 24, 960, 744)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768),
                                       FullscreenRegion::Desktop));
}
TEST (OpenGLFullscreenRegion, Overflow)
{
    FullscreenRegion monitor (CompRect (0, 0, 1024, 768));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (10, 10, 40, 30)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (-10, -10, 1044, 788)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768),
                                       FullscreenRegion::Desktop));
}
TEST (OpenGLFullscreenRegion, CancelFullscreen2)
{
    FullscreenRegion monitor (CompRect (0, 0, 1024, 768));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (-100, -100, 1, 1)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (2000, 2000, 123, 456)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (500, 500, 345, 234)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (10, 10, 40, 30)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (20, 20, 50, 20)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768)));
    EXPECT_FALSE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768),
                                       FullscreenRegion::Desktop));
}
TEST (OpenGLFullscreenRegion, KeepUnredirectedStateIfNotOnMonitor)
{
    CompRect left (0, 0, 1024, 768);
    CompRect right (1025, 0, 1024, 768);
    CompRegion all (0, 0, 2048, 768);
    CompRect offscreen1 (2048, 0, 1024, 768);
    CompRect offscreen2 (-1024, 0, 1024, 768);
    CompRegion window (right);
    FullscreenRegion monitor (left, all);

    /* Eg, not covering the monitor, should be redirected */
    EXPECT_FALSE (monitor.isCoveredBy (window));

    /* Don't allow the redirection however, because we weren't
     * covering the monitor at all. */
    EXPECT_FALSE (monitor.allowRedirection (window));

    /* Verify off-screen windows are always redirected (eg. other viewports) */
    EXPECT_TRUE (monitor.allowRedirection (offscreen1));
    EXPECT_TRUE (monitor.allowRedirection (offscreen2));
}
TEST (OpenGLFullscreenRegion, FullscreenNoDesktop)
{
    FullscreenRegion monitor (CompRect (0, 0, 1024, 768));
    EXPECT_TRUE (monitor.isCoveredBy (CompRegion (0, 0, 1024, 768)));
}
Beispiel #9
0
/* This function currently always performs occlusion detection to
   minimize paint regions. OpenGL precision requirements are no good
   enough to guarantee that the results from using occlusion detection
   is the same as without. It's likely not possible to see any
   difference with most hardware but occlusion detection in the
   transformed screen case should be made optional for those who do
   see a difference. */
void
PrivateGLScreen::paintOutputRegion (const GLMatrix   &transform,
				    const CompRegion &region,
				    CompOutput       *output,
				    unsigned int     mask)
{
    CompRegion    tmpRegion (region);
    CompWindow    *w;
    GLWindow      *gw;
    int           windowMask, odMask;
    bool          status, unredirectFS;
    bool          withOffset = false;
    GLMatrix      vTransform;
    CompPoint     offXY;
    std::set<CompWindow*> unredirected;

    CompWindowList                   pl;
    CompWindowList::reverse_iterator rit;

    unredirectFS = CompositeScreen::get (screen)->
	getOption ("unredirect_fullscreen_windows")->value ().b ();

    const CompMatch &unredirectable = CompositeScreen::get (screen)->
	getOption ("unredirect_match")->value ().match ();

    const CompString &blacklist =
	getOption ("unredirect_driver_blacklist")->value ().s ();

    bool blacklisted = driverIsBlacklisted (blacklist.c_str ());

    if (mask & PAINT_SCREEN_TRANSFORMED_MASK)
    {
	windowMask     = PAINT_WINDOW_ON_TRANSFORMED_SCREEN_MASK;
    }
    else
    {
	windowMask     = 0;
    }

    /*
     * We need to COPY the PaintList for now because there seem to be some
     * odd cases where the master list might change during the below loops.
     * (LP: #958540)
     */
    pl = cScreen->getWindowPaintList ();

    if (!(mask & PAINT_SCREEN_NO_OCCLUSION_DETECTION_MASK))
    {
	FullscreenRegion fs (*output, screen->region ());

	/* detect occlusions */
	for (rit = pl.rbegin (); rit != pl.rend (); ++rit)
	{
	    w = (*rit);
	    gw = GLWindow::get (w);

	    if (w->destroyed ())
		continue;

	    if (!w->shaded ())
	    {
		/* Non-damaged windows don't have valid pixmap
		 * contents and we aren't displaying them yet
		 * so don't factor them into occlusion detection */
		if (!gw->priv->cWindow->damaged ())
		{
		    gw->priv->clip = region;
		    continue;
		}
		if (!w->isViewable ())
		    continue;
	    }

	    /* copy region */
	    gw->priv->clip = tmpRegion;

	    odMask = PAINT_WINDOW_OCCLUSION_DETECTION_MASK;

	    if ((cScreen->windowPaintOffset ().x () != 0 ||
		 cScreen->windowPaintOffset ().y () != 0) &&
		!w->onAllViewports ())
	    {
		withOffset = true;

		offXY = w->getMovementForOffset (cScreen->windowPaintOffset ());

		vTransform = transform;
		vTransform.translate (offXY.x (), offXY.y (), 0);

		gw->priv->clip.translate (-offXY.x (), -offXY. y ());

		odMask |= PAINT_WINDOW_WITH_OFFSET_MASK;
		status = gw->glPaint (gw->paintAttrib (), vTransform,
				      tmpRegion, odMask);
	    }
	    else
	    {
		withOffset = false;
		status = gw->glPaint (gw->paintAttrib (), transform, tmpRegion,
				      odMask);
	    }

	    if (status)
	    {
		if (withOffset)
		{
		    tmpRegion -= w->region ().translated (offXY);
		}
		else
		    tmpRegion -= w->region ();
	    }

	    FullscreenRegion::WinFlags flags = 0;
	    if (w->type () & CompWindowTypeDesktopMask)
	        flags |= FullscreenRegion::Desktop;
	    if (w->alpha ())
		flags |= FullscreenRegion::Alpha;
	    
	    /* Anything which was not occlusion detected is not a suitable
	     * candidate for unredirection either */
	    if (!status)
		flags |= FullscreenRegion::NoOcclusionDetection;

	    CompositeWindow *cw = CompositeWindow::get (w);

	    /*
	     * Windows with alpha channels can partially occlude windows
	     * beneath them and so neither should be unredirected in that case.
	     *
	     * Performance note:  unredirectable.evaluate is SLOW because it
	     * involves regex matching. Too slow to do on every window for
	     * every frame. So we only call it if a window is redirected AND
	     * potentially needs unredirecting. This means changes to
	     * unredirect_match while a window is unredirected already may not
	     * take effect until it is un-fullscreened again. But that's better
	     * than the high price of regex matching on every frame.
	     */
	    if (unredirectFS &&
		!blacklisted &&
		!(mask & PAINT_SCREEN_TRANSFORMED_MASK) &&
		!(mask & PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS_MASK) &&
		fs.isCoveredBy (w->region (), flags) &&
		(!cw->redirected () || unredirectable.evaluate (w)))
	    {
		unredirected.insert (w);
	    }
	    else
	    {
		if (!cw->redirected ())
		{
		    if (fs.allowRedirection (w->region ()))
		    {
			// 1. GLWindow::release to force gw->priv->needsRebind
			gw->release ();

			// 2. GLWindow::bind, which redirects the window,
			//    rebinds the pixmap, and then rebinds the pixmap
			//    to a texture.
			gw->bind ();

			// 3. Your window is now redirected again with the
			//    latest pixmap contents.
		    }
		    else
		    {
			unredirected.insert (w);
		    }
		}
	    }
	}
    }

    /* Unredirect any redirected fullscreen windows */
    foreach (CompWindow *fullscreenWindow, unredirected)
	CompositeWindow::get (fullscreenWindow)->unredirect ();

    if (!(mask & PAINT_SCREEN_NO_BACKGROUND_MASK))
	paintBackground (transform,
	                 tmpRegion,
	                 (mask & PAINT_SCREEN_TRANSFORMED_MASK));

    /* paint all windows from bottom to top */
    foreach (w, pl)
    {
	if (w->destroyed ())
	    continue;

        gw = GLWindow::get (w);

        /* Release any queued ConfigureWindow requests now */
	gw->priv->configureLock->release ();

	if (unredirected.find (w) != unredirected.end ())
	    continue;

	if (!w->shaded ())
	{
	    if (!w->isViewable ())
		continue;
	}

	const CompRegion &clip =
	    (!(mask & PAINT_SCREEN_NO_OCCLUSION_DETECTION_MASK)) ?
	    gw->clip () : region;

	if ((cScreen->windowPaintOffset ().x () != 0 ||
	     cScreen->windowPaintOffset ().y () != 0) &&
	    !w->onAllViewports ())
	{
	    offXY = w->getMovementForOffset (cScreen->windowPaintOffset ());

	    vTransform = transform;
	    vTransform.translate (offXY.x (), offXY.y (), 0);
	    gw->glPaint (gw->paintAttrib (), vTransform, clip,
		         windowMask | PAINT_WINDOW_WITH_OFFSET_MASK);
	}
	else
	{
	    gw->glPaint (gw->paintAttrib (), transform, clip, windowMask);
	}
    }
}