Skip to content

Commit

Permalink
Switched ImageContainer to shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
d87 committed Nov 14, 2020
1 parent be19c66 commit bc751c1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/D4See.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ VOID OnPaint() //HDC hdc)
{
using namespace std::chrono_literals;

ImageContainer* frame = gWinMgr.frame;
std::shared_ptr<ImageContainer>& frame = gWinMgr.frame;

if (frame) {

Expand Down Expand Up @@ -357,7 +357,7 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR lpCmdLine, INT iCmdSho
);
hr = pD2DFactory->CreateHwndRenderTarget(props, D2D1::HwndRenderTargetProperties(hWnd, size), &pRenderTarget);

gWinMgr.SelectImage(new ImageContainer(hWnd, playlist->Current()->path, playlist->Current()->format));
gWinMgr.SelectImage(std::make_shared<ImageContainer>(hWnd, playlist->Current()->path, playlist->Current()->format));
gWinMgr.frame->threadInitFinished.wait();
gWinMgr.ResizeForImage();

Expand Down Expand Up @@ -400,7 +400,7 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR lpCmdLine, INT iCmdSho
case WM_FRAMEERROR:
case WM_FRAMEREADY: {
ImageContainer* f = (ImageContainer*)msg.wParam;
if (f == gWinMgr.frame) {
if (f == gWinMgr.frame.get()) {
//gWinMgr.newImagePending = true;
//RedrawWindow(hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE);
LOG("Accepted WM_FRAMEREADY for {0}", wide_to_utf8(f->filename));
Expand All @@ -427,7 +427,7 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR lpCmdLine, INT iCmdSho
gWinMgr.SelectPlaylist(playlist);

auto cur = playlist->Current();
gWinMgr.SelectImage(new ImageContainer(hWnd, cur->path, cur->format));
gWinMgr.SelectImage(std::make_shared<ImageContainer>(hWnd, cur->path, cur->format));

break;
}
Expand All @@ -444,7 +444,7 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR lpCmdLine, INT iCmdSho
auto delta = now - prevTime;

if (gWinMgr.frame) {
ImageContainer* frame = gWinMgr.frame;
std::shared_ptr<ImageContainer>& frame = gWinMgr.frame;
if (!frame->isAnimated) {
if (frame->decoderBatchId != frame->drawId) {
LOG("Batch Ids: {0} - {1}", frame->drawId, frame->decoderBatchId);
Expand Down
22 changes: 9 additions & 13 deletions src/WindowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ void WindowManager::StopTimer(UINT_PTR id) {

WindowManager::~WindowManager() {
if (playlist) delete playlist;
if (frame) delete frame;
if (frame_prefetch) delete frame_prefetch;
//if (frame) delete frame;
//if (frame_prefetch) delete frame_prefetch;
}

//void ClearWindowForFrame(HWND hWnd, ImageContainer* f) {
Expand Down Expand Up @@ -53,12 +53,12 @@ void WindowManager::ShowPrefetch() {
}

void WindowManager::DiscardPrefetch() {
if (frame_prefetch)
delete frame_prefetch;
//if (frame_prefetch)
//delete frame_prefetch;
frame_prefetch = nullptr;
}

void WindowManager::StartPrefetch(ImageContainer* f) {
void WindowManager::StartPrefetch(std::shared_ptr<ImageContainer> f) {
frame_prefetch = f;
// Start 2 minute timer
SetTimer(hWnd, D4S_PREFETCH_TIMEOUT, 120000, NULL);
Expand Down Expand Up @@ -94,11 +94,11 @@ void WindowManager::LoadImageFromPlaylist(int prefetchDir) {
}
else { // Changed direction or jumped more than 1
DiscardPrefetch();
SelectImage(new ImageContainer(hWnd, cur->path, cur->format));
SelectImage(std::make_shared<ImageContainer>(hWnd, cur->path, cur->format));
}
}
if (following) {
StartPrefetch(new ImageContainer(hWnd, following->path, following->format));
StartPrefetch(std::make_shared<ImageContainer>(hWnd, following->path, following->format));
}
else {
frame_prefetch = nullptr;
Expand Down Expand Up @@ -245,11 +245,7 @@ void WindowManager::ToggleBorderless(int doRedraw) {
}
}

void WindowManager::SelectImage(ImageContainer* f) {
if (frame != nullptr) {
delete frame;
}

void WindowManager::SelectImage(std::shared_ptr<ImageContainer> f) {
LOG_DEBUG("<<<<<<< FRAME SWITCH >>>>>>>");
//LOG_DEBUG(" -- {0} --", f->filename);
frame = f;
Expand Down Expand Up @@ -662,7 +658,7 @@ void WindowManager::HandleMenuCommand(unsigned int uIDItem) {
if (filepath != L"") {
auto pl = new Playlist(filepath);
SelectPlaylist(pl);
SelectImage(new ImageContainer(hWnd, pl->Current()->path, pl->Current()->format));
SelectImage(std::make_shared<ImageContainer>(hWnd, pl->Current()->path, pl->Current()->format));
//std::cout << filepath.c_str() << std::endl;
}
break;
Expand Down
8 changes: 4 additions & 4 deletions src/WindowManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ struct WINDOW_SAVED_DATA {
class WindowManager {
public:
HWND hWnd;
ImageContainer* frame = nullptr;
ImageContainer* frame_prefetch = nullptr; // prefecth container
std::shared_ptr<ImageContainer> frame = nullptr;
std::shared_ptr<ImageContainer> frame_prefetch = nullptr; // prefecth container
Playlist* playlist = nullptr;
PlaylistSortMethod sortMethod = PlaylistSortMethod::ByName;
D4See::InputHandler input;
Expand Down Expand Up @@ -81,11 +81,11 @@ class WindowManager {
void NextImage();
void PreviousImage();
void LoadImageFromPlaylist(int prefetchDir);
void StartPrefetch(ImageContainer* f);
void StartPrefetch(std::shared_ptr<ImageContainer> f);
void ShowPrefetch();
void LimitPanOffset();
void DiscardPrefetch();
void SelectImage(ImageContainer* f);
void SelectImage(std::shared_ptr<ImageContainer> f);
void SelectPlaylist(Playlist* playlist);
void GetWindowSizeForImage(RECT& rrc);
void ResizeForImage();
Expand Down

0 comments on commit bc751c1

Please sign in to comment.