1
// Copyright (c) 2012- PPSSPP Project.
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
18
#include "GPUDebugInterface.h"
20
void GPUDebugBuffer::Allocate(u32 stride, u32 height, GEBufferFormat fmt, bool flipped, bool reversed) {
21
GPUDebugBufferFormat actualFmt = GPUDebugBufferFormat(fmt);
22
if (reversed && actualFmt < GPU_DBG_FORMAT_8888) {
23
actualFmt |= GPU_DBG_FORMAT_REVERSE_FLAG;
25
Allocate(stride, height, actualFmt, flipped);
28
void GPUDebugBuffer::Allocate(u32 stride, u32 height, GPUDebugBufferFormat fmt, bool flipped) {
29
if (alloc_ && stride_ == stride && height_ == height && fmt_ == fmt) {
30
// Already allocated the right size.
42
u32 pixelSize = PixelSize(fmt);
43
data_ = new u8[pixelSize * stride * height];
46
void GPUDebugBuffer::Free() {
47
if (alloc_ && data_ != NULL) {
53
u32 GPUDebugBuffer::PixelSize(GPUDebugBufferFormat fmt) const {
55
case GPU_DBG_FORMAT_8888:
56
case GPU_DBG_FORMAT_8888_BGRA:
57
case GPU_DBG_FORMAT_FLOAT:
58
case GPU_DBG_FORMAT_24BIT_8X:
59
case GPU_DBG_FORMAT_24X_8BIT:
60
case GPU_DBG_FORMAT_FLOAT_DIV_256:
61
case GPU_DBG_FORMAT_24BIT_8X_DIV_256:
64
case GPU_DBG_FORMAT_888_RGB:
67
case GPU_DBG_FORMAT_8BIT:
75
u32 GPUDebugBuffer::GetRawPixel(int x, int y) const {
76
if (data_ == nullptr) {
84
u32 pixelSize = PixelSize(fmt_);
85
u32 byteOffset = pixelSize * (stride_ * y + x);
86
const u8 *ptr = &data_[byteOffset];
90
return *(const u32 *)ptr;
92
return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
94
return *(const u16 *)ptr;
96
return *(const u8 *)ptr;