Trace dump tool, for dumping pngs (and in the future more stuff).

This commit is contained in:
Ben Vanik
2015-12-13 11:59:14 -08:00
parent aec43ffb2e
commit 7419e7eb4a
12 changed files with 510 additions and 7 deletions

View File

@@ -466,6 +466,32 @@ void GLContext::EndSwap() {
SwapBuffers(dc_);
}
std::unique_ptr<RawImage> GLContext::Capture() {
GraphicsContextLock lock(this);
std::unique_ptr<RawImage> raw_image(new RawImage());
raw_image->width = target_window_->width();
raw_image->stride = raw_image->width * 4;
raw_image->height = target_window_->height();
raw_image->data.resize(raw_image->stride * raw_image->height);
glReadPixels(0, 0, target_window_->width(), target_window_->height(), GL_RGBA,
GL_UNSIGNED_BYTE, raw_image->data.data());
// Flip vertically in-place.
size_t yt = 0;
size_t yb = (raw_image->height - 1) * raw_image->stride;
while (yt < yb) {
for (size_t i = 0; i < raw_image->stride; ++i) {
std::swap(raw_image->data[yt + i], raw_image->data[yb + i]);
}
yt += raw_image->stride;
yb -= raw_image->stride;
}
return raw_image;
}
} // namespace gl
} // namespace ui
} // namespace xe

View File

@@ -44,6 +44,8 @@ class GLContext : public GraphicsContext {
void BeginSwap() override;
void EndSwap() override;
std::unique_ptr<RawImage> Capture() override;
Blitter* blitter() { return &blitter_; }
private:

View File

@@ -11,6 +11,7 @@
#define XENIA_UI_GRAPHICS_CONTEXT_H_
#include <memory>
#include <vector>
namespace xe {
namespace ui {
@@ -19,6 +20,17 @@ class GraphicsProvider;
class ImmediateDrawer;
class Window;
class RawImage {
public:
RawImage() = default;
~RawImage() = default;
size_t width = 0;
size_t height = 0;
size_t stride = 0;
std::vector<uint8_t> data;
};
class GraphicsContext {
public:
virtual ~GraphicsContext();
@@ -36,6 +48,8 @@ class GraphicsContext {
virtual void BeginSwap() = 0;
virtual void EndSwap() = 0;
virtual std::unique_ptr<RawImage> Capture() = 0;
protected:
explicit GraphicsContext(GraphicsProvider* provider, Window* target_window);