Skip to content

Commit

Permalink
improvement(sdlafvideorender): support sdl window and native window
Browse files Browse the repository at this point in the history
Signed-off-by: pingkai <pingkai010@gmail.com>
  • Loading branch information
pingkai committed Jun 5, 2020
1 parent a61e6b2 commit 9a0c1f5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
23 changes: 15 additions & 8 deletions framework/render/video/SdlAFVideoRender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,12 @@ SDL_Rect SdlAFVideoRender::getSnapRect()

int SdlAFVideoRender::setDisPlay(void *view)
{
if (mCurrentView == view) {
auto *display = static_cast<CicadaSDLView *>(view);
if (mCurrentView == display->view) {
return 0;
}
mCurrentView = display->view;
if (mCurrentView == nullptr) {
return 0;
}
if (mVideoWindow != nullptr) {
Expand All @@ -416,19 +421,21 @@ int SdlAFVideoRender::setDisPlay(void *view)
SDL_DestroyRenderer(mVideoRender);
mVideoRender = nullptr;
}
mCurrentView = view;
if (mCurrentView == nullptr) {
return 0;
}
if (SDL_WasInit(SDL_INIT_VIDEO) != SDL_INIT_VIDEO) {
SDL_Init(SDL_INIT_VIDEO);
mInitByMe = true;
}
mVideoWindow = SDL_CreateWindowFrom(view);
SDL_ShowWindow(mVideoWindow);
if (display->type == CicadaSDLViewType_NATIVE_WINDOW) {
mVideoWindow = SDL_CreateWindowFrom(display->view);
SDL_ShowWindow(mVideoWindow);
} else
mVideoWindow = static_cast<SDL_Window *>(display->view);

if (mVideoWindow) {
mVideoRender = SDL_CreateRenderer(mVideoWindow, -1, 0);
mVideoRender = SDL_GetRenderer(mVideoWindow);
if (mVideoRender == nullptr) {
mVideoRender = SDL_CreateRenderer(mVideoWindow, -1, 0);
}
}

return 0;
Expand Down
7 changes: 7 additions & 0 deletions framework/render/video/SdlAFVideoRender.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
#include <mutex>
#include <render/video/AFActiveVideoRender.h>

enum CicadaSDLViewType { CicadaSDLViewType_SDL_WINDOW, CicadaSDLViewType_NATIVE_WINDOW };

typedef struct CicadaSDLView_t {
void *view;
CicadaSDLViewType type;
} CicadaSDLView;

class SdlAFVideoRender : public IVideoRender, private IVSync::Listener {
public:
SdlAFVideoRender();
Expand Down

0 comments on commit 9a0c1f5

Please sign in to comment.