Ejemplo n.º 1
0
bool D3dApp::IsDeviceLost()
{
	HRESULT hr = m_pMyD3dDevice->TestCooperativeLevel();

	if(hr==D3DERR_DEVICELOST)
	{
		Sleep(20);
		return true;
	}
	else if(hr==D3DERR_DRIVERINTERNALERROR)
	{
		MessageBox(0,_T("Internal Driver Error... Exiting"),0,0);
		PostQuitMessage(0);
		return true;
	}
	else if(hr==D3DERR_DEVICENOTRESET)
	{
		OnLostDevice();
		m_pMyD3dDevice->Reset(&m_D3dParams);
		OnResetDevice();
		return false;
	}
	else
	{
		return false;
	}
}
Ejemplo n.º 2
0
void Graphics::Resize( int width,int height )
{
	if( m_windowed )
	{
		m_d3dpp.BackBufferWidth = width;
		m_d3dpp.BackBufferHeight = height;

		Locker lock( &m_cs );

		OnLostDevice();

		m_pDirect3DDevice->Reset( &m_d3dpp );

		OnResetDevice();

		D3DVIEWPORT9 vp;
		vp.X  = 0;
		vp.Y  = 0;
		vp.Width = m_d3dpp.BackBufferWidth;
		vp.Height = m_d3dpp.BackBufferHeight;
		vp.MinZ  = 0.0f;
		vp.MaxZ  = 1.0f;
		m_pDirect3DDevice->SetViewport(&vp);
	}
}
Ejemplo n.º 3
0
void CP3DRenderer::Present(HWND hWnd)
{
	Prof(RENDERER_CP3DRenderer__Present);

	// Present the backbuffer contents to the display
	if (g_pD3DDevice->Present( NULL, NULL, hWnd, NULL ) == D3DERR_DEVICELOST)
		OnLostDevice();
}
Ejemplo n.º 4
0
//--------------------------------------------------------------------------------------
// Handles the GUI events
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
{

    switch( nControlID )
    {
        case IDC_TOGGLEFULLSCREEN:
            DXUTToggleFullScreen(); break;
        case IDC_TOGGLEREF:
            DXUTToggleREF(); break;
        case IDC_CHANGEDEVICE:
            g_SettingsDlg.SetActive( !g_SettingsDlg.IsActive() ); break;

        case IDC_ENABLE_PRESHADER:
        {
            g_bEnablePreshader = g_SampleUI.GetCheckBox( IDC_ENABLE_PRESHADER )->GetChecked();

            if( DXUTGetD3D9Device() != NULL )
            {
                OnLostDevice( NULL );
                OnDestroyDevice( NULL );
                OnCreateDevice( DXUTGetD3D9Device(), DXUTGetD3D9BackBufferSurfaceDesc(), NULL );
                OnResetDevice( DXUTGetD3D9Device(), DXUTGetD3D9BackBufferSurfaceDesc(), NULL );
            }
            break;
        }

        case IDC_ACTIVE_LIGHT:
            if( !g_LightControl[g_nActiveLight].IsBeingDragged() )
            {
                g_nActiveLight++;
                g_nActiveLight %= g_nNumActiveLights;
            }
            break;

        case IDC_NUM_LIGHTS:
            if( !g_LightControl[g_nActiveLight].IsBeingDragged() )
            {
                WCHAR sz[100];
                swprintf_s( sz, 100, L"# Lights: %d", g_SampleUI.GetSlider( IDC_NUM_LIGHTS )->GetValue() );
                g_SampleUI.GetStatic( IDC_NUM_LIGHTS_STATIC )->SetText( sz );

                g_nNumActiveLights = g_SampleUI.GetSlider( IDC_NUM_LIGHTS )->GetValue();
                g_nActiveLight %= g_nNumActiveLights;
            }
            break;

        case IDC_LIGHT_SCALE:
            g_fLightScale = ( float )( g_SampleUI.GetSlider( IDC_LIGHT_SCALE )->GetValue() * 0.10f );

            WCHAR sz[100];
            swprintf_s( sz, 100, L"Light scale: %0.2f", g_fLightScale );
            g_SampleUI.GetStatic( IDC_LIGHT_SCALE_STATIC )->SetText( sz );
            break;
    }

}
Ejemplo n.º 5
0
drawableTexAtlas2D::~drawableTexAtlas2D()
{
	if(mTex || mTopSurf)
		OnLostDevice();
	if(mTextureOffsets != NULL) 
	{ 
		if(mNumTextures > 1) 
		{ delete [] mTextureOffsets; mTextureOffsets = NULL; }
		else
		{ delete mTextureOffsets; mTextureOffsets = NULL; }
	}
}
Ejemplo n.º 6
0
STDMETHODIMP VMRSurfaceAllocator::PresentImage( DWORD_PTR dwUserID, VMR9PresentationInfo *lpPresInfo )
{
	HRESULT hr = 0;
	//IDirect3DTexture9 *lpTexture;
	CheckPointer( lpPresInfo, E_POINTER );
	CheckPointer( lpPresInfo->lpSurf, E_POINTER );

	//while( lock )
	//{
	//  Sleep( 1 );
	//}

	mdraw->WaitDrawEnd( 1, 16 );

	hr = PresentToTexture( lpPresInfo );

	//if(hr == D3D_OK)
	//{
	//  if ( texnum < 0 )
	//  {
	//    hr = lpPresInfo->lpSurf->GetContainer(IID_IDirect3DTexture9,(void **)&lpTexture);
	//  } else
	//  {
	//    lpTexture = m_alpDirect3DTexture[ texnum ];
	//    lpTexture->AddRef();
	//    hr = D3D_OK;
	//  }

	//  if ( hr == D3D_OK )
	//  {
	//    //...ここで必要であればテクスチャを使っての描画処理を行う
	//    lpTexture->Release();
	//  }
	//}

	if ( hr == D3DERR_DEVICELOST )
	{
		OnLostDevice();
		hr = D3DDev->TestCooperativeLevel();
		if ( hr == D3DERR_DEVICENOTRESET )
		{
			OnResetDevice();
		}
	}

	//mdraw->UnlockDarawEnd();

	return hr;
}
Ejemplo n.º 7
0
void Graphics::LostDevice()
{
	if( !m_init )
	{
		return;
	}

	m_deviceLost = true;
	if( !m_windowActive )
	{
		return;
	}

	OnLostDevice();	

	ResetDevice();
}
Ejemplo n.º 8
0
void TreeGeneratorCanvas::RenderWindow()
{
	Driver* driver = gEngine->GetDriver();
	IDirect3DDevice9* d3dDevice = driver->GetD3DDevice();
	Camera* extraCamera = gEngine->GetSceneManager()->GetExtraCamera();

	switch(d3dDevice->TestCooperativeLevel())
	{
	case D3D_OK:
		{
			extraCamera->FrameUpdate();

			if(wxWindow::FindFocus() == this)
				extraCamera->ApplyCameraController();

			driver->RenderToSwapChain(swapChainIndex);
			driver->Clear(D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x7f36404a, 1.0f);
			driver->BeginScene();

			std::vector<Vector3> points;
			points.push_back(Vector3::Zero);
			points.push_back(Vector3(2, 0, 0));
			DebugDrawer::DrawLine(points, 0xffff0000, extraCamera);

			if(mTree)
				mTree->Draw(extraCamera);

			driver->EndScene();
			driver->Present((HWND)GetHWND());

			break;
		}

	case D3DERR_DEVICELOST:
		break;

	case D3DERR_DEVICENOTRESET:
		{
			OnLostDevice();
			OnResetDevice();
			break;
		}
	}
}
Ejemplo n.º 9
0
void D3dApp::EnableFullScreen(bool enable)
{
	if(enable)
	{
		if(!m_D3dParams.Windowed)return;

		int Width = GetSystemMetrics(SM_CXSCREEN);
		int Height = GetSystemMetrics(SM_CYSCREEN);

		m_D3dParams.BackBufferFormat = D3DFMT_X8R8G8B8;
		m_D3dParams.BackBufferWidth = Width;
		m_D3dParams.BackBufferHeight = Height;

		m_D3dParams.Windowed = false;

		SetWindowLongPtr(m_hMainWnd, GWL_STYLE, WS_POPUP);

		SetWindowPos(m_hMainWnd,HWND_TOP,0,0,Width,Height,SWP_NOZORDER | SWP_SHOWWINDOW);
	}
	else
	{
		if(m_D3dParams.Windowed)return;

		RECT windowrect = {0,0, 800,600};

		AdjustWindowRect(&windowrect,WS_CAPTION,false);

		m_D3dParams.BackBufferFormat = D3DFMT_UNKNOWN;
		m_D3dParams.BackBufferWidth = windowrect.right;
		m_D3dParams.BackBufferHeight = windowrect.bottom;
		m_D3dParams.Windowed = true;

		SetWindowLongPtr(m_hMainWnd, GWL_STYLE, WS_CAPTION);

		SetWindowPos(m_hMainWnd,HWND_TOP,(GetSystemMetrics(SM_CXSCREEN)/2)-(windowrect.right/2),
		(GetSystemMetrics(SM_CYSCREEN)/2)-(windowrect.bottom/2),
			windowrect.right,windowrect.bottom,SWP_NOZORDER | SWP_SHOWWINDOW);
	}

	OnLostDevice();
	m_pMyD3dDevice->Reset(&m_D3dParams);
	OnResetDevice();
}
Ejemplo n.º 10
0
void drawableTexAtlas2D::Release()
{
	if(mTex || mTopSurf)
		OnLostDevice();
}
Ejemplo n.º 11
0
bool CWinSystemX11::SetWindow(int width, int height, bool fullscreen, const std::string &output, int *winstate)
{
  bool changeWindow = false;
  bool changeSize = false;
  float mouseX = 0.5;
  float mouseY = 0.5;

  if (!m_mainWindow)
  {
    CInputManager::GetInstance().SetMouseActive(false);
  }

  if (m_mainWindow && ((m_bFullScreen != fullscreen) || m_currentOutput.compare(output) != 0 || m_windowDirty))
  {
    // set mouse to last known position
    // we can't trust values after an xrr event
    if (m_bIsInternalXrr && m_MouseX >= 0 && m_MouseY >= 0)
    {
      mouseX = (float)m_MouseX/m_nWidth;
      mouseY = (float)m_MouseY/m_nHeight;
    }
    else if (!m_windowDirty)
    {
      Window root_return, child_return;
      int root_x_return, root_y_return;
      int win_x_return, win_y_return;
      unsigned int mask_return;
      bool isInWin = XQueryPointer(m_dpy, m_mainWindow, &root_return, &child_return,
                                   &root_x_return, &root_y_return,
                                   &win_x_return, &win_y_return,
                                   &mask_return);

      if (isInWin)
      {
        mouseX = (float)win_x_return/m_nWidth;
        mouseY = (float)win_y_return/m_nHeight;
      }
    }

    CInputManager::GetInstance().SetMouseActive(false);
    OnLostDevice();
    DestroyWindow();
    m_windowDirty = true;
  }

  // create main window
  if (!m_mainWindow)
  {
    EnableSystemScreenSaver(false);

    Colormap cmap;
    XSetWindowAttributes swa;
    XVisualInfo *vi;
    int x0 = 0;
    int y0 = 0;

    XOutput *out = g_xrandr.GetOutput(output);
    if (!out)
      out = g_xrandr.GetOutput(m_currentOutput);
    if (out)
    {
      m_nScreen = out->screen;
      x0 = out->x;
      y0 = out->y;
    }

    vi = GetVisual();
    if (!vi)
    {
      CLog::Log(LOGERROR, "Failed to find matching visual");
      return false;
    }

    cmap = XCreateColormap(m_dpy, RootWindow(m_dpy, vi->screen), vi->visual, AllocNone);

    bool hasWM = HasWindowManager();

    int def_vis = (vi->visual == DefaultVisual(m_dpy, vi->screen));
    swa.override_redirect = hasWM ? False : True;
    swa.border_pixel = fullscreen ? 0 : 5;
    swa.background_pixel = def_vis ? BlackPixel(m_dpy, vi->screen) : 0;
    swa.colormap = cmap;
    swa.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask |
                     ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
                     PropertyChangeMask | StructureNotifyMask | KeymapStateMask |
                     EnterWindowMask | LeaveWindowMask | ExposureMask;
    unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect | CWEventMask;

    m_mainWindow = XCreateWindow(m_dpy, RootWindow(m_dpy, vi->screen),
                    x0, y0, width, height, 0, vi->depth,
                    InputOutput, vi->visual,
                    mask, &swa);

    swa.override_redirect = False;
    swa.border_pixel = 0;
    swa.event_mask = ExposureMask;
    mask = CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect | CWColormap | CWEventMask;

    m_glWindow = XCreateWindow(m_dpy, m_mainWindow,
                    0, 0, width, height, 0, vi->depth,
                    InputOutput, vi->visual,
                    mask, &swa);

    if (fullscreen && hasWM)
    {
      Atom fs = XInternAtom(m_dpy, "_NET_WM_STATE_FULLSCREEN", True);
      XChangeProperty(m_dpy, m_mainWindow, XInternAtom(m_dpy, "_NET_WM_STATE", True), XA_ATOM, 32, PropModeReplace, (unsigned char *) &fs, 1);
      // disable desktop compositing for KDE, when Kodi is in full-screen mode
      int one = 1;
      XChangeProperty(m_dpy, m_mainWindow, XInternAtom(m_dpy, "_KDE_NET_WM_BLOCK_COMPOSITING", True), XA_CARDINAL, 32,
                      PropModeReplace, (unsigned char*) &one,  1);
    }

    // define invisible cursor
    Pixmap bitmapNoData;
    XColor black;
    static char noData[] = { 0,0,0,0,0,0,0,0 };
    black.red = black.green = black.blue = 0;

    bitmapNoData = XCreateBitmapFromData(m_dpy, m_mainWindow, noData, 8, 8);
    m_invisibleCursor = XCreatePixmapCursor(m_dpy, bitmapNoData, bitmapNoData,
                                            &black, &black, 0, 0);
    XFreePixmap(m_dpy, bitmapNoData);
    XDefineCursor(m_dpy,m_mainWindow, m_invisibleCursor);
    XFree(vi);

    //init X11 events
    CWinEventsX11Imp::Init(m_dpy, m_mainWindow);

    changeWindow = true;
    changeSize = true;
  }

  if (!CWinEventsX11Imp::HasStructureChanged() && ((width != m_nWidth) || (height != m_nHeight)))
  {
    changeSize = true;
  }

  if (changeSize || changeWindow)
  {
    XResizeWindow(m_dpy, m_mainWindow, width, height);
  }

  if ((width != m_nWidth) || (height != m_nHeight) || changeWindow)
  {
    XResizeWindow(m_dpy, m_glWindow, width, height);
  }

  if (changeWindow)
  {
    m_icon = None;
    {
      CreateIconPixmap();
      XWMHints *wm_hints;
      XClassHint *class_hints;
      XTextProperty windowName, iconName;

      std::string titleString = CCompileInfo::GetAppName();
      std::string classString = titleString;
      char *title = (char*)titleString.c_str();

      XStringListToTextProperty(&title, 1, &windowName);
      XStringListToTextProperty(&title, 1, &iconName);

      wm_hints = XAllocWMHints();
      wm_hints->initial_state = NormalState;
      wm_hints->icon_pixmap = m_icon;
      wm_hints->flags = StateHint | IconPixmapHint;

      class_hints = XAllocClassHint();
      class_hints->res_class = (char*)classString.c_str();
      class_hints->res_name = (char*)classString.c_str();

      XSetWMProperties(m_dpy, m_mainWindow, &windowName, &iconName,
                            NULL, 0, NULL, wm_hints,
                            class_hints);
      XFree(class_hints);
      XFree(wm_hints);

      // register interest in the delete window message
      Atom wmDeleteMessage = XInternAtom(m_dpy, "WM_DELETE_WINDOW", False);
      XSetWMProtocols(m_dpy, m_mainWindow, &wmDeleteMessage, 1);
    }

    // placement of window may follow mouse
    XWarpPointer(m_dpy, None, m_mainWindow, 0, 0, 0, 0, mouseX*width, mouseY*height);

    XMapRaised(m_dpy, m_glWindow);
    XMapRaised(m_dpy, m_mainWindow);

    // discard events generated by creating the window, i.e. xrr events
    XSync(m_dpy, TRUE);

    if (winstate)
      *winstate = 1;
  }

  UpdateCrtc();

  return true;
}
Ejemplo n.º 12
0
bool CWinSystemX11::SetFullScreen(bool fullScreen, RESOLUTION_INFO& res, bool blankOtherDisplays)
{
  XOutput out;
  XMode mode;

  if (fullScreen)
  {
    out.name = res.strOutput;
    mode.w   = res.iWidth;
    mode.h   = res.iHeight;
    mode.hz  = res.fRefreshRate;
    mode.id  = res.strId;
  }
  else
  {
    out.name = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP).strOutput;
    mode.w   = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP).iWidth;
    mode.h   = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP).iHeight;
    mode.hz  = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP).fRefreshRate;
    mode.id  = CDisplaySettings::GetInstance().GetResolutionInfo(RES_DESKTOP).strId;
  }
 
  XMode   currmode = g_xrandr.GetCurrentMode(out.name);
  if (!currmode.name.empty())
  {
    // flip h/w when rotated
    if (m_bIsRotated)
    {
      int w = mode.w;
      mode.w = mode.h;
      mode.h = w;
    }

    // only call xrandr if mode changes
    if (m_mainWindow)
    {
      if (currmode.w != mode.w || currmode.h != mode.h ||
          currmode.hz != mode.hz || currmode.id != mode.id)
      {
        CLog::Log(LOGNOTICE, "CWinSystemX11::SetFullScreen - calling xrandr");

        // remember last position of mouse
        Window root_return, child_return;
        int root_x_return, root_y_return;
        int win_x_return, win_y_return;
        unsigned int mask_return;
        bool isInWin = XQueryPointer(m_dpy, m_mainWindow, &root_return, &child_return,
                                     &root_x_return, &root_y_return,
                                     &win_x_return, &win_y_return,
                                     &mask_return);

        if (isInWin)
        {
          m_MouseX = win_x_return;
          m_MouseY = win_y_return;
        }
        else
        {
          m_MouseX = -1;
          m_MouseY = -1;
        }

        OnLostDevice();
        m_bIsInternalXrr = true;
        g_xrandr.SetMode(out, mode);
        return true;
      }
    }
  }

  if (!SetWindow(res.iWidth, res.iHeight, fullScreen, m_userOutput))
    return false;

  m_nWidth      = res.iWidth;
  m_nHeight     = res.iHeight;
  m_bFullScreen = fullScreen;
  m_currentOutput = m_userOutput;

  return true;
}
Ejemplo n.º 13
0
void DX11::TextureSurface::OnResetDevice(Gpu::Api * gpu)
{
	OnLostDevice(gpu);

	unsigned width = unsigned(viewport.Width);
	unsigned height = unsigned(viewport.Height);
	bool typeless = (format == Gpu::DrawSurface::Format_Typeless);

	if(relativeWindow)
	{
		gpu->GetBackbufferSize(width, height, relativeWindow);
		width = unsigned(widthFactor * float(width));
		height = unsigned(heightFactor * float(height));
	}

	viewport = CD3D11_VIEWPORT(0.0f, 0.0f, float(width), float(height));

	static const DXGI_FORMAT SURFACE_FORMAT_TO_DXGI_FORMAT[Format_Total] =
	{
		DXGI_FORMAT_R8G8B8A8_UNORM,
		DXGI_FORMAT_B8G8R8A8_UNORM,
		DXGI_FORMAT_R16G16B16A16_FLOAT,
		DXGI_FORMAT_R11G11B10_FLOAT,
		DXGI_FORMAT_R16_FLOAT,
		DXGI_FORMAT_R24G8_TYPELESS
	};

	DXGI_FORMAT dxgiFormat = SURFACE_FORMAT_TO_DXGI_FORMAT[format];

	unsigned mipLevels = generateMips ? min(width, height) / 4 : 1;

	D3D11_BIND_FLAG bindFlag = typeless ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_RENDER_TARGET;

	ID3D11Texture2D * texture2D = 0;
	CD3D11_TEXTURE2D_DESC textureDesc(
		dxgiFormat,
		width,
		height,
		1,
		mipLevels, // MIP LEVELS - *MUST NEVER* BE GREATER THAN log2(width) OR log2(height)
		bindFlag | D3D11_BIND_SHADER_RESOURCE);

	device->CreateTexture2D(&textureDesc, 0, &texture2D);

	if(typeless) dxgiFormat = DXGI_FORMAT_R24_UNORM_X8_TYPELESS;

	ID3D11ShaderResourceView * shaderView;
	CD3D11_SHADER_RESOURCE_VIEW_DESC shaderViewDesc(
		texture2D,
		D3D11_SRV_DIMENSION_TEXTURE2D,
		dxgiFormat,
		0,
		mipLevels);
	device->CreateShaderResourceView(texture2D, &shaderViewDesc, &shaderView);
	
	if(!typeless)
	{
		CD3D11_RENDER_TARGET_VIEW_DESC renderViewDesc(
			texture2D,
			D3D11_RTV_DIMENSION_TEXTURE2D,
			dxgiFormat);
		device->CreateRenderTargetView(texture2D, &renderViewDesc, &renderTargetView);

		CD3D11_TEXTURE2D_DESC depthStencilTextureDesc(
			DXGI_FORMAT_D24_UNORM_S8_UINT,
			width,
			height,
			1,
			1,
			D3D11_BIND_DEPTH_STENCIL);
		device->CreateTexture2D(&depthStencilTextureDesc, 0, &depthStencilTexture);

		device->CreateDepthStencilView(
			depthStencilTexture,
			&CD3D11_DEPTH_STENCIL_VIEW_DESC(D3D11_DSV_DIMENSION_TEXTURE2D),
			&depthStencilView);
	}
	else
	{
		device->CreateDepthStencilView(
			texture2D,
			&CD3D11_DEPTH_STENCIL_VIEW_DESC(D3D11_DSV_DIMENSION_TEXTURE2D, DXGI_FORMAT_D24_UNORM_S8_UINT),
			&depthStencilView);
	}

	texture = new DX11::Texture(texture2D, shaderView, textureDesc);

	Clear();
}
Ejemplo n.º 14
0
DX11::TextureSurface::~TextureSurface()
{
	OnLostDevice(gpu);
}
Ejemplo n.º 15
0
bool CWinSystemX11::SetWindow(int width, int height, bool fullscreen, const std::string &output)
{
  bool changeWindow = false;
  bool changeSize = false;
  float mouseX = 0.5;
  float mouseY = 0.5;

  if (!m_mainWindow)
  {
    CInputManager::GetInstance().SetMouseActive(false);
  }

  if (m_mainWindow && ((m_bFullScreen != fullscreen) || m_currentOutput.compare(output) != 0 || m_windowDirty))
  {
    // set mouse to last known position
    // we can't trust values after an xrr event
    if (m_bIsInternalXrr && m_MouseX >= 0 && m_MouseY >= 0)
    {
      mouseX = (float)m_MouseX/m_nWidth;
      mouseY = (float)m_MouseY/m_nHeight;
    }
    else if (!m_windowDirty)
    {
      Window root_return, child_return;
      int root_x_return, root_y_return;
      int win_x_return, win_y_return;
      unsigned int mask_return;
      bool isInWin = XQueryPointer(m_dpy, m_mainWindow, &root_return, &child_return,
                                   &root_x_return, &root_y_return,
                                   &win_x_return, &win_y_return,
                                   &mask_return);

      if (isInWin)
      {
        mouseX = (float)win_x_return/m_nWidth;
        mouseY = (float)win_y_return/m_nHeight;
      }
    }

    CInputManager::GetInstance().SetMouseActive(false);
    OnLostDevice();
    DestroyWindow();
    m_windowDirty = true;
  }

  // create main window
  if (!m_mainWindow)
  {
    EnableSystemScreenSaver(false);

#if defined(HAS_GLX)
    GLint att[] =
    {
      GLX_RGBA,
      GLX_RED_SIZE, 8,
      GLX_GREEN_SIZE, 8,
      GLX_BLUE_SIZE, 8,
      GLX_ALPHA_SIZE, 8,
      GLX_DEPTH_SIZE, 24,
      GLX_DOUBLEBUFFER,
      None
    };
#endif
#if defined(HAS_EGL)
    EGLint att[] =
    {
      EGL_RED_SIZE, 8,
      EGL_GREEN_SIZE, 8,
      EGL_BLUE_SIZE, 8,
      EGL_ALPHA_SIZE, 8,
      EGL_BUFFER_SIZE, 32,
      EGL_DEPTH_SIZE, 24,
      EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
      EGL_NONE
    };
#endif

    Colormap cmap;
    XSetWindowAttributes swa;
    XVisualInfo *vi;
    int x0 = 0;
    int y0 = 0;

    XOutput *out = g_xrandr.GetOutput(output);
    if (!out)
      out = g_xrandr.GetOutput(m_currentOutput);
    if (out)
    {
      m_nScreen = out->screen;
      x0 = out->x;
      y0 = out->y;
    }

#if defined(HAS_GLX)
    vi = glXChooseVisual(m_dpy, m_nScreen, att);
#endif
#if defined(HAS_EGL)
    if (m_eglDisplay == EGL_NO_DISPLAY)
    {
      m_eglDisplay = eglGetDisplay((EGLNativeDisplayType)m_dpy);
      if (m_eglDisplay == EGL_NO_DISPLAY)
      {
        CLog::Log(LOGERROR, "failed to get egl display\n");
	return false;
      }
      if (!eglInitialize(m_eglDisplay, NULL, NULL))
      {
	CLog::Log(LOGERROR, "failed to initialize egl display\n");
	return false;
      }
    }

    EGLint numConfigs;
    EGLConfig eglConfig = 0;
    if (!eglChooseConfig(m_eglDisplay, att, &eglConfig, 1, &numConfigs) || numConfigs == 0) {
      CLog::Log(LOGERROR, "Failed to choose a config %d\n", eglGetError());
    }
    m_eglConfig=eglConfig;

    EGLint eglVisualid;
    if (!eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_NATIVE_VISUAL_ID, &eglVisualid))
    {
      CLog::Log(LOGERROR, "Failed to query native visual id\n");
    }
    XVisualInfo x11_visual_info_template;
    x11_visual_info_template.visualid = eglVisualid;
    int num_visuals;
    vi = XGetVisualInfo(m_dpy,
                        VisualIDMask,
                        &x11_visual_info_template,
                        &num_visuals);

#endif

    if(!vi)
    {
      CLog::Log(LOGERROR, "Failed to find matching visual");
      return false;
    }

    cmap = XCreateColormap(m_dpy, RootWindow(m_dpy, vi->screen), vi->visual, AllocNone);

    bool hasWM = HasWindowManager();

    int def_vis = (vi->visual == DefaultVisual(m_dpy, vi->screen));
    swa.override_redirect = hasWM ? False : True;
    swa.border_pixel = fullscreen ? 0 : 5;
    swa.background_pixel = def_vis ? BlackPixel(m_dpy, vi->screen) : 0;
    swa.colormap = cmap;
    swa.event_mask = FocusChangeMask | KeyPressMask | KeyReleaseMask |
                     ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
                     PropertyChangeMask | StructureNotifyMask | KeymapStateMask |
                     EnterWindowMask | LeaveWindowMask | ExposureMask;
    unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect | CWEventMask;

    m_mainWindow = XCreateWindow(m_dpy, RootWindow(m_dpy, vi->screen),
                    x0, y0, width, height, 0, vi->depth,
                    InputOutput, vi->visual,
                    mask, &swa);

    swa.override_redirect = False;
    swa.border_pixel = 0;
    swa.event_mask = ExposureMask;
    mask = CWBackPixel | CWBorderPixel | CWColormap | CWOverrideRedirect | CWColormap | CWEventMask;

    m_glWindow = XCreateWindow(m_dpy, m_mainWindow,
                    0, 0, width, height, 0, vi->depth,
                    InputOutput, vi->visual,
                    mask, &swa);

    if (fullscreen && hasWM)
    {
      Atom fs = XInternAtom(m_dpy, "_NET_WM_STATE_FULLSCREEN", True);
      XChangeProperty(m_dpy, m_mainWindow, XInternAtom(m_dpy, "_NET_WM_STATE", True), XA_ATOM, 32, PropModeReplace, (unsigned char *) &fs, 1);
      // disable desktop compositing for KDE, when Kodi is in full-screen mode
      int one = 1;
      XChangeProperty(m_dpy, m_mainWindow, XInternAtom(m_dpy, "_KDE_NET_WM_BLOCK_COMPOSITING", True), XA_CARDINAL, 32,
                      PropModeReplace, (unsigned char*) &one,  1);
    }

    // define invisible cursor
    Pixmap bitmapNoData;
    XColor black;
    static char noData[] = { 0,0,0,0,0,0,0,0 };
    black.red = black.green = black.blue = 0;

    bitmapNoData = XCreateBitmapFromData(m_dpy, m_mainWindow, noData, 8, 8);
    m_invisibleCursor = XCreatePixmapCursor(m_dpy, bitmapNoData, bitmapNoData,
                                            &black, &black, 0, 0);
    XFreePixmap(m_dpy, bitmapNoData);
    XDefineCursor(m_dpy,m_mainWindow, m_invisibleCursor);

    //init X11 events
    CWinEventsX11Imp::Init(m_dpy, m_mainWindow);

    changeWindow = true;
    changeSize = true;

#if defined(HAS_EGL)
    m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, m_glWindow, NULL);
    if (m_eglSurface == EGL_NO_SURFACE)
    {
      CLog::Log(LOGERROR, "failed to create egl window surface\n");
      return false;
    }
#endif
  }

  if (!CWinEventsX11Imp::HasStructureChanged() && ((width != m_nWidth) || (height != m_nHeight)))
  {
    changeSize = true;
  }

  if (changeSize || changeWindow)
  {
    XResizeWindow(m_dpy, m_mainWindow, width, height);
  }

  if ((width != m_nWidth) || (height != m_nHeight) || changeWindow)
  {
    XResizeWindow(m_dpy, m_glWindow, width, height);
  }

  if (changeWindow)
  {
    m_icon = None;
    {
      CreateIconPixmap();
      XWMHints *wm_hints;
      XClassHint *class_hints;
      XTextProperty windowName, iconName;

      std::string titleString = CCompileInfo::GetAppName();
      std::string classString = titleString;
      char *title = (char*)titleString.c_str();

      XStringListToTextProperty(&title, 1, &windowName);
      XStringListToTextProperty(&title, 1, &iconName);

      wm_hints = XAllocWMHints();
      wm_hints->initial_state = NormalState;
      wm_hints->icon_pixmap = m_icon;
      wm_hints->flags = StateHint | IconPixmapHint;

      class_hints = XAllocClassHint();
      class_hints->res_class = (char*)classString.c_str();
      class_hints->res_name = (char*)classString.c_str();

      XSetWMProperties(m_dpy, m_mainWindow, &windowName, &iconName,
                            NULL, 0, NULL, wm_hints,
                            class_hints);
      XFree(class_hints);
      XFree(wm_hints);

      // register interest in the delete window message
      Atom wmDeleteMessage = XInternAtom(m_dpy, "WM_DELETE_WINDOW", False);
      XSetWMProtocols(m_dpy, m_mainWindow, &wmDeleteMessage, 1);
    }

    // placement of window may follow mouse
    XWarpPointer(m_dpy, None, m_mainWindow, 0, 0, 0, 0, mouseX*width, mouseY*height);

    XMapRaised(m_dpy, m_glWindow);
    XMapRaised(m_dpy, m_mainWindow);

    // discard events generated by creating the window, i.e. xrr events
    XSync(m_dpy, TRUE);

    CDirtyRegionList dr;
    RefreshGlxContext(m_currentOutput.compare(output) != 0);
    XSync(m_dpy, FALSE);
    g_graphicsContext.Clear(0);
    g_graphicsContext.Flip(dr);
#if defined(HAS_GLX)
    g_Windowing.ResetVSync();
#endif
    m_windowDirty = false;
    m_bIsInternalXrr = false;

// what's this???
#if defined(HAS_GLX)
    CSingleLock lock(m_resourceSection);
    // tell any shared resources
    for (std::vector<IDispResource *>::iterator i = m_resources.begin(); i != m_resources.end(); ++i)
      (*i)->OnResetDevice();
#endif
  }

  UpdateCrtc();

  return true;
}
Ejemplo n.º 16
0
bool Display(float timeDelta)
{
	if( Device )
	{
		//
		// spin the cube:旋转立方体
		//
		D3DXMATRIX Rx, Ry;

		// rotate 45 degrees on x-axis,顺时针旋转
		D3DXMatrixRotationX(&Rx, 3.14f / 4.0f);

		// incremement y-rotation angle each frame
		static float y = 0.0f;
		D3DXMatrixRotationY(&Ry, y);
		y += timeDelta;

		// reset angle to zero when angle reaches 2*PI
		if( y >= 6.28f )
			y = 0.0f;

		// combine x- and y-axis rotation transformations.
		D3DXMATRIX p = Rx * Ry;

        // 本地坐标变换到世界坐标
		Device->SetTransform(D3DTS_WORLD, &p);

		//
		// draw the scene:
		//
		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
		Device->BeginScene();

        // 设置数据流来源
		Device->SetStreamSource(0,              // 使用0号数据流
                                VB,             // 要加载到流中的顶点内存
                                0,              // 渲染偏移量
                                sizeof(Vertex));// 每个元素的字节数
        // 设置索引缓冲区
		Device->SetIndices(IB);
        // 设置顶点格式
		Device->SetFVF(Vertex::FVF);

		// Draw cube.将几何信息送到渲染管线
		Device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,  // 图元类型,这里是三角形
                                      0,                   // 索引基数,用于指定某个顶点缓冲区(回合并到一个全局的缓冲区,所以要指定)
                                      0,                   // 引用的最小索引值
                                      8,                   // 要渲染的顶点数量,这里是8个顶点
                                      0,                   // 从缓冲区读取的第几个元素
                                      12);                 // 要渲染的图元数量,这里是12个三角形

		Device->EndScene();
		HRESULT hr = Device->Present(0, 0, 0, 0);
		if(hr == D3DERR_DEVICELOST)
		{
			if(Device->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
			{
				OnLostDevice();
				OnResetDevice();
			}
		}
	}
	return true;
}
Ejemplo n.º 17
0
void Graphics::ChangeScreenMode( bool windowed )
{
	if( windowed==m_windowed )
	{
		return;
	}
	m_windowed = windowed;

	if( m_windowed )
	{
		ZeroMemory( &m_d3dpp, sizeof( m_d3dpp ) );
		m_d3dpp.Windowed = TRUE;
		m_d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
		m_d3dpp.BackBufferWidth = m_rectClient.right-m_rectClient.left;
		m_d3dpp.BackBufferHeight = m_rectClient.bottom-m_rectClient.top;
		m_d3dpp.BackBufferCount = 1;
		m_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		m_d3dpp.EnableAutoDepthStencil = TRUE;
		m_d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8;
		m_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
	}
	else
	{
		D3DDISPLAYMODE d3ddisp;
		m_pDirect3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT,&d3ddisp );

		ZeroMemory( &m_d3dpp, sizeof( m_d3dpp ) );
		m_d3dpp.Windowed = FALSE;
		m_d3dpp.BackBufferFormat = d3ddisp.Format;
		m_d3dpp.BackBufferWidth = m_screenWidth;
		m_d3dpp.BackBufferHeight = m_screenHeight;
		m_d3dpp.BackBufferCount = 1;
		m_d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		m_d3dpp.EnableAutoDepthStencil = TRUE;
		m_d3dpp.AutoDepthStencilFormat = D3DFMT_D24X8;
		m_d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
		m_d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;

		::GetWindowRect(m_window, &m_rectWindow);
		::GetClientRect(m_window, &m_rectClient);
	}

	Locker lock( &m_cs );

	OnLostDevice();

	m_pDirect3DDevice->Reset( &m_d3dpp );

	OnResetDevice();

	D3DVIEWPORT9 vp;
	vp.X  = 0;
	vp.Y  = 0;
	vp.Width = m_d3dpp.BackBufferWidth;
	vp.Height = m_d3dpp.BackBufferHeight;
	vp.MinZ  = 0.0f;
	vp.MaxZ  = 1.0f;
	m_pDirect3DDevice->SetViewport(&vp);

	if( m_windowed )
	{
		// フルスクリーンだった場合、ウィンドウスタイルや位置が自動的に変わるため、
		// 元に戻す必要がある。
		// フルスクリーン用のウィンドウを作っている場合は、この問題が発生しない(ウィンドウの表示、非表示は切り替える必要がある)
		::SetWindowLong(m_window, GWL_STYLE, WS_OVERLAPPEDWINDOW | WS_VISIBLE );
		::SetWindowPos(m_window, HWND_NOTOPMOST,
			m_rectWindow.left, m_rectWindow.top,
			m_rectWindow.right - m_rectWindow.left,
			m_rectWindow.bottom - m_rectWindow.top,
			SWP_SHOWWINDOW );
	}
	else
	{
		// フルスクリーンにした段階で、自動的に変更される。
		// だが、わかりにくいため念のため明記しておく。
		::SetWindowLong(m_window, GWL_STYLE, WS_POPUP | WS_VISIBLE);
	}
}