locked
IDXGISwapChain1::Present1 and screen color

    Question

  • I'm new to Direct2D and XAML app development and can't figure this one out, so any help will be highly appreciated. I created a new "Direct2D App (XAML)" project in Visual Studio Express 2012. This project has SimpleTextRenderer class (derived from DirectXBase) that displays text on screen using Direct2D. The XAML page calls the following functions:

    ...

    m_renderer->Render();

    m_renderer->Present();

    ...

    The Present() function has the following line of code in it:

    HRESULT hr = m_swapChain->Present1(1, 0, &parameters);

    where m_swapChain is an instance of IDXGISwapChain1.

    If I omit the call to m_renderer->Render() function and just invoke m_renderer->Present() in some timer callback, the screen color changes. Now I know that the project also demonstrates how the background color can be changed when "Next" and "Previous" buttons are pressed in the bottom app bar, but I commented that code out and the screen color keeps changing (in the callback for timer that I set up) by itself, even when I don't press any buttons. Is this behavior expected? What is the behavior of Present1() function if it's called again and again and there's nothing to draw? Does it show empty frames in different colors or is that a bug somewhere?

    To duplicate this problem, please create this project in VS 2012 and add the following code in DirectXPage::DirectXPage():

    Windows::Foundation::TimeSpan timeSpan;

    timeSpan.Duration  = 10000000;

    ThreadPoolTimer^ timer = ThreadPoolTimer::CreatePeriodicTimer(
            ref new TimerElapsedHandler([this](ThreadPoolTimer^ source)
            {
                Dispatcher->RunAsync(CoreDispatcherPriority::High,
                                     ref new DispatchedHandler([this]()
                {
                      //m_renderer->Render(); 
                        m_renderer->Present();
                }));

           }),  timeSpan);

    The problem obviously goes away if I un-comment the call to Render() 'cause that functions clears the screen and draws some text again. I just want to know why the screen color is changing in the scenario I described above. Please let me know if more information is needed.

    Tuesday, January 01, 2013 3:39 AM

All replies

  • Hello,

    Would you please provide us the whole codes to reproduce this issue,

    You can upload your project to SkyDrive
    http://skydrive.live.com/

    It is not necessary that you send out the whole of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business details from it.

    If you don't want to upload the sample code, you can try to get the paid support from https://getsupport.microsoft.com/

    Best regards,
    Jesse


    Jesse Jiang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, January 02, 2013 6:18 AM
  • Hi Jesse,

    Thanks for the reply. The problem is fairly easy to reproduce with the project that "VS Express 2012 for Windows" creates. Here are the steps:

    1. Launch Visual Studio Express 2012 for Windows 8.

    2. Select File -> New Project

    3. Select "Direct2D App (XAML)" under Visual C++. This will create a whole bunch of files including SimpleTextRenderer.cpp, and DirectXPage.xaml.cpp.

    4. In DirectXPage.xaml.cpp, add this line at the top: "using namespace Windows::System::Threading;"

    5. In DirectXPage::DirectXPage() function, copy the following code after the call to m_renderer->Initialize:

        Windows::Foundation::TimeSpan timeSpan;
        timeSpan.Duration  = 10000000;

        ThreadPoolTimer^ timer = ThreadPoolTimer::CreatePeriodicTimer(
            ref new TimerElapsedHandler([this](ThreadPoolTimer^ source)
            {
                Dispatcher->RunAsync(CoreDispatcherPriority::High,
                                     ref new DispatchedHandler([this]()
                {
                    //m_renderer->Render();
                    m_renderer->Present();
                }));
            }),
        timeSpan);

    6. Now run the program. You'll see that the screen color keeps changing after every call to m_renderer->Present().

    I commented out all references to BackgroundColors in SimpleTextRenderer.cpp to make sure that that's not causing it (even though that should only come into action when next and previous buttons are pressed), but the color still changes. 

    Please let me know if you are able to reproduce the problem or not. A quick reply will be appreciated.

    Thanks.


    Tuesday, January 08, 2013 6:35 AM