~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to GPU/Common/GPUDebugInterface.cpp

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2012- PPSSPP Project.
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
12
// A copy of the GPL 2.0 should have been included with the program.
 
13
// If not, see http://www.gnu.org/licenses/
 
14
 
 
15
// Official git repository and contact information can be found at
 
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
 
17
 
 
18
#include "GPUDebugInterface.h"
 
19
 
 
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;
 
24
        }
 
25
        Allocate(stride, height, actualFmt, flipped);
 
26
}
 
27
 
 
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.
 
31
                flipped_ = flipped;
 
32
                return;
 
33
        }
 
34
 
 
35
        Free();
 
36
        alloc_ = true;
 
37
        height_ = height;
 
38
        stride_ = stride;
 
39
        fmt_ = fmt;
 
40
        flipped_ = flipped;
 
41
 
 
42
        u32 pixelSize = PixelSize(fmt);
 
43
        data_ = new u8[pixelSize * stride * height];
 
44
}
 
45
 
 
46
void GPUDebugBuffer::Free() {
 
47
        if (alloc_ && data_ != NULL) {
 
48
                delete [] data_;
 
49
        }
 
50
        data_ = NULL;
 
51
}
 
52
 
 
53
u32 GPUDebugBuffer::PixelSize(GPUDebugBufferFormat fmt) const { 
 
54
        switch (fmt) {
 
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:
 
62
                return 4;
 
63
 
 
64
        case GPU_DBG_FORMAT_888_RGB:
 
65
                return 3;
 
66
 
 
67
        case GPU_DBG_FORMAT_8BIT:
 
68
                return 1;
 
69
 
 
70
        default:
 
71
                return 2;
 
72
        }
 
73
}
 
74
 
 
75
u32 GPUDebugBuffer::GetRawPixel(int x, int y) const {
 
76
        if (data_ == nullptr) {
 
77
                return 0;
 
78
        }
 
79
 
 
80
        if (flipped_) {
 
81
                y = height_ - y - 1;
 
82
        }
 
83
 
 
84
        u32 pixelSize = PixelSize(fmt_);
 
85
        u32 byteOffset = pixelSize * (stride_ * y + x);
 
86
        const u8 *ptr = &data_[byteOffset];
 
87
 
 
88
        switch (pixelSize) {
 
89
        case 4:
 
90
                return *(const u32 *)ptr;
 
91
        case 3:
 
92
                return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16);
 
93
        case 2:
 
94
                return *(const u16 *)ptr;
 
95
        case 1:
 
96
                return *(const u8 *)ptr;
 
97
        default:
 
98
                return 0;
 
99
        }
 
100
}