Merge pull request #10816 from hrydgard/fix-restore-pause-screen

Android: Properly restore savestate screenshots on the Pause screen on task switching away and back.
This commit is contained in:
Unknown W. Brackets authored and GitHub committed 2018-03-27 22:51:20 -04:00
commit b2941014f2
13 files changed
+120 -21

No files matched your search

+3
View File
@@ -681,6 +681,7 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) {
screenManager->setUIContext(uiContext);
screenManager->setDrawContext(g_draw);
screenManager->setPostRenderCallback(&RenderOverlays, nullptr);
screenManager->deviceRestored();
#ifdef _WIN32
winAudioBackend = CreateAudioBackend((AudioBackendType)g_Config.iAudioBackend);
@@ -702,6 +703,8 @@ bool NativeInitGraphics(GraphicsContext *graphicsContext) {
}
void NativeShutdownGraphics() {
screenManager->deviceLost();
if (gpu)
gpu->DeviceLost();
+12 -2
View File
@@ -49,7 +49,7 @@ AsyncImageFileView::AsyncImageFileView(const std::string &filename, UI::ImageSiz
AsyncImageFileView::~AsyncImageFileView() {}
void AsyncImageFileView::GetContentDimensions(const UIContext &dc, float &w, float &h) const {
if (texture_) {
if (texture_ && texture_->GetTexture()) {
float texw = (float)texture_->Width();
float texh = (float)texture_->Height();
switch (sizeMode_) {
@@ -77,6 +77,16 @@ void AsyncImageFileView::SetFilename(std::string filename) {
}
}
void AsyncImageFileView::DeviceLost() {
if (texture_.get())
texture_->DeviceLost();
}
void AsyncImageFileView::DeviceRestored(Draw::DrawContext *draw) {
if (texture_.get())
texture_->DeviceRestored(draw);
}
void AsyncImageFileView::Draw(UIContext &dc) {
using namespace Draw;
if (!texture_ && !textureFailed_ && !filename_.empty()) {
@@ -90,7 +100,7 @@ void AsyncImageFileView::Draw(UIContext &dc) {
}
// TODO: involve sizemode
if (texture_) {
if (texture_ && texture_->GetTexture()) {
dc.Flush();
dc.GetDrawContext()->BindTexture(0, texture_->GetTexture());
dc.Draw()->Rect(bounds_.x, bounds_.y, bounds_.w, bounds_.h, color_);
+5 -2
View File
@@ -60,8 +60,8 @@ private:
class PrioritizedWorkQueue;
// TextureView takes a texture that is assumed to be alive during the lifetime
// of the view. TODO: Actually make async using the task.
// AsyncImageFileView loads a texture from a file, and reloads it as necessary.
// TODO: Actually make async, doh.
class AsyncImageFileView : public UI::Clickable {
public:
AsyncImageFileView(const std::string &filename, UI::ImageSizeMode sizeMode, PrioritizedWorkQueue *wq, UI::LayoutParams *layoutParams = 0);
@@ -70,6 +70,9 @@ public:
void GetContentDimensions(const UIContext &dc, float &w, float &h) const override;
void Draw(UIContext &dc) override;
void DeviceLost() override;
void DeviceRestored(Draw::DrawContext *draw) override;
void SetFilename(std::string filename);
void SetColor(uint32_t color) { color_ = color; }
void SetOverlayText(std::string text) { text_ = text; }
+35 -5
View File
@@ -7,6 +7,7 @@
#include "file/vfs.h"
#include "ext/jpge/jpgd.h"
#include "UI/TextureUtil.h"
#include "Common/Log.h"
static Draw::DataFormat ZimToT3DFormat(int zim) {
switch (zim) {
@@ -37,7 +38,7 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType ty
type = DetectImageFileType(data, size);
}
if (type == TYPE_UNKNOWN) {
ELOG("File has unknown format");
ELOG("File (size: %d) has unknown format", (int)size);
return false;
}
@@ -79,7 +80,7 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType ty
break;
default:
ELOG("Unknown image format");
ELOG("Unsupported image format %d", (int)type);
return false;
}
@@ -87,6 +88,7 @@ static bool LoadTextureLevels(const uint8_t *data, size_t size, ImageFileType ty
}
bool ManagedTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type, bool generateMips) {
generateMips_ = generateMips;
using namespace Draw;
int width[16]{}, height[16]{};
@@ -135,18 +137,20 @@ bool ManagedTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, Imag
}
bool ManagedTexture::LoadFromFile(const std::string &filename, ImageFileType type, bool generateMips) {
filename_ = "";
generateMips_ = generateMips;
size_t fileSize;
uint8_t *buffer = VFSReadFile(filename.c_str(), &fileSize);
if (!buffer) {
ELOG("Failed to read file %s", filename.c_str());
filename_ = "";
ELOG("Failed to read file '%s'", filename.c_str());
return false;
}
bool retval = LoadFromFileData(buffer, fileSize, type, generateMips);
if (retval) {
filename_ = filename;
} else {
ELOG("Failed to load texture %s", filename.c_str());
filename_ = "";
ELOG("Failed to load texture '%s'", filename.c_str());
}
delete[] buffer;
return retval;
@@ -164,6 +168,32 @@ std::unique_ptr<ManagedTexture> CreateTextureFromFile(Draw::DrawContext *draw, c
return std::unique_ptr<ManagedTexture>(mtex);
}
void ManagedTexture::DeviceLost() {
ILOG("ManagedTexture::DeviceLost(%s)", filename_.c_str());
if (texture_)
texture_->Release();
texture_ = nullptr;
}
void ManagedTexture::DeviceRestored(Draw::DrawContext *draw) {
ILOG("ManagedTexture::DeviceRestored(%s)", filename_.c_str());
_assert_(!texture_);
draw_ = draw;
// Vulkan: Can't load textures before the first frame has started.
// Should probably try to lift that restriction again someday..
loadPending_ = true;
}
Draw::Texture *ManagedTexture::GetTexture() {
if (loadPending_) {
if (!LoadFromFile(filename_, ImageFileType::DETECT, generateMips_)) {
ELOG("ManagedTexture failed: '%s'", filename_.c_str());
}
loadPending_ = false;
}
return texture_;
}
// TODO: Remove the code duplication between this and LoadFromFileData
std::unique_ptr<ManagedTexture> CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, int size, ImageFileType type, bool generateMips) {
if (!draw)
+7 -2
View File
@@ -23,15 +23,20 @@ public:
bool LoadFromFile(const std::string &filename, ImageFileType type = ImageFileType::DETECT, bool generateMips = false);
bool LoadFromFileData(const uint8_t *data, size_t dataSize, ImageFileType type = ImageFileType::DETECT, bool generateMips = false);
Draw::Texture *GetTexture() { return texture_; } // For immediate use, don't store.
Draw::Texture *GetTexture(); // For immediate use, don't store.
int Width() const { return texture_->Width(); }
int Height() const { return texture_->Height(); }
void DeviceLost();
void DeviceRestored(Draw::DrawContext *draw);
private:
Draw::Texture *texture_ = nullptr;
Draw::DrawContext *draw_;
std::string filename_; // Textures that are loaded from files can reload themselves automatically.
bool generateMips_ = false;
bool loadPending_ = false;
};
std::unique_ptr<ManagedTexture> CreateTextureFromFile(Draw::DrawContext *draw, const char *filename, ImageFileType fileType, bool generateMips = false);
std::unique_ptr<ManagedTexture> CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, int size, ImageFileType fileType, bool generateMips = false);
std::unique_ptr<ManagedTexture> CreateTextureFromFileData(Draw::DrawContext *draw, const uint8_t *data, int size, ImageFileType fileType, bool generateMips = false);
+1 -1
View File
@@ -366,7 +366,7 @@ uint8_t *VFSReadFile(const char *filename, size_t *size) {
}
}
if (!fileSystemFound) {
ELOG("Missing filesystem for %s", filename);
ELOG("Missing filesystem for '%s'", filename);
} // Otherwise, the file was just missing. No need to log.
return 0;
}
+10
View File
@@ -97,6 +97,16 @@ bool ScreenManager::axis(const AxisInput &axis) {
}
}
void ScreenManager::deviceLost() {
for (auto &iter : stack_)
iter.screen->deviceLost();
}
void ScreenManager::deviceRestored() {
for (auto &iter : stack_)
iter.screen->deviceRestored();
}
void ScreenManager::resized() {
std::lock_guard<std::recursive_mutex> guard(inputLock_);
// Have to notify the whole stack, otherwise there will be problems when going back
+5
View File
@@ -58,6 +58,8 @@ public:
virtual bool key(const KeyInput &key) { return false; }
virtual bool axis(const AxisInput &touch) { return false; }
virtual void sendMessage(const char *msg, const char *value) {}
virtual void deviceLost() {}
virtual void deviceRestored() {}
virtual void RecreateViews() {}
@@ -115,6 +117,9 @@ public:
void resized();
void shutdown();
void deviceLost();
void deviceRestored();
// Push a dialog box in front. Currently 1-level only.
void push(Screen *screen, int layerFlags = 0);
+10
View File
@@ -61,6 +61,16 @@ void UIScreen::update() {
}
}
void UIScreen::deviceLost() {
if (root_)
root_->DeviceLost();
}
void UIScreen::deviceRestored() {
if (root_)
root_->DeviceRestored(screenManager()->getDrawContext());
}
void UIScreen::preRender() {
using namespace Draw;
Draw::DrawContext *draw = screenManager()->getDrawContext();
+10 -8
View File
@@ -15,16 +15,18 @@ public:
UIScreen();
~UIScreen();
virtual void update() override;
virtual void preRender() override;
virtual void render() override;
virtual void postRender() override;
void update() override;
void preRender() override;
void render() override;
void postRender() override;
void deviceLost() override;
void deviceRestored() override;
virtual bool touch(const TouchInput &touch) override;
virtual bool key(const KeyInput &touch) override;
virtual bool axis(const AxisInput &touch) override;
bool touch(const TouchInput &touch) override;
bool key(const KeyInput &touch) override;
bool axis(const AxisInput &touch) override;
virtual TouchInput transformTouch(const TouchInput &touch) override;
TouchInput transformTouch(const TouchInput &touch) override;
virtual void TriggerFinish(DialogResult result);
+4
View File
@@ -33,6 +33,7 @@ class Texture;
class UIContext;
namespace Draw {
class DrawContext;
class Texture;
}
@@ -365,6 +366,9 @@ public:
virtual void Axis(const AxisInput &input) {}
virtual void Update();
virtual void DeviceLost() {}
virtual void DeviceRestored(Draw::DrawContext *draw) {}
// If this view covers these coordinates, it should add itself and its children to the list.
virtual void Query(float x, float y, std::vector<View *> &list);
virtual std::string Describe() const;
+15 -1
View File
@@ -117,6 +117,20 @@ void ViewGroup::Axis(const AxisInput &input) {
}
}
void ViewGroup::DeviceLost() {
std::lock_guard<std::mutex> guard(modifyLock_);
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
(*iter)->DeviceLost();
}
}
void ViewGroup::DeviceRestored(Draw::DrawContext *draw) {
std::lock_guard<std::mutex> guard(modifyLock_);
for (auto iter = views_.begin(); iter != views_.end(); ++iter) {
(*iter)->DeviceRestored(draw);
}
}
void ViewGroup::Draw(UIContext &dc) {
if (hasDropShadow_) {
// Darken things behind.
@@ -124,7 +138,7 @@ void ViewGroup::Draw(UIContext &dc) {
float dropsize = 30.0f;
dc.Draw()->DrawImage4Grid(dc.theme->dropShadow4Grid,
bounds_.x - dropsize, bounds_.y,
bounds_.x2() + dropsize, bounds_.y2()+dropsize*1.5, 0xDF000000, 3.0f);
bounds_.x2() + dropsize, bounds_.y2()+dropsize*1.5f, 0xDF000000, 3.0f);
}
if (clip_) {
+3
View File
@@ -38,6 +38,9 @@ public:
virtual void Update() override;
virtual void Query(float x, float y, std::vector<View *> &list) override;
virtual void DeviceLost() override;
virtual void DeviceRestored(Draw::DrawContext *draw) override;
virtual void Draw(UIContext &dc) override;
// These should be unused.