Skip to content

Commit d3ce576

Browse files
committed
revert video transfer double buffering
1 parent 33fef04 commit d3ce576

File tree

3 files changed

+96
-21
lines changed

3 files changed

+96
-21
lines changed

LICENSE.3DSGBA

Lines changed: 0 additions & 8 deletions
This file was deleted.

LICENSE.thirdparty

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
3DSGBA:
3+
Copyright (C) 2014 Steveice10
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10+
11+
ini:
12+
Copyright (c) 2016 rxi
13+
14+
15+
Permission is hereby granted, free of charge, to any person obtaining a copy of
16+
this software and associated documentation files (the "Software"), to deal in
17+
the Software without restriction, including without limitation the rights to
18+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
19+
of the Software, and to permit persons to whom the Software is furnished to do
20+
so, subject to the following conditions:
21+
22+
The above copyright notice and this permission notice shall be included in all
23+
copies or substantial portions of the Software.
24+
25+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31+
SOFTWARE.
32+
33+
SDL_gfx:
34+
Copyright (C) 2001-2012 Andreas Schiffler
35+
36+
This software is provided 'as-is', without any express or implied
37+
warranty. In no event will the authors be held liable for any damages
38+
arising from the use of this software.
39+
40+
Permission is granted to anyone to use this software for any purpose,
41+
including commercial applications, and to alter it and redistribute it
42+
freely, subject to the following restrictions:
43+
44+
1. The origin of this software must not be misrepresented; you must not
45+
claim that you wrote the original software. If you use this software
46+
in a product, an acknowledgment in the product documentation would be
47+
appreciated but is not required.
48+
49+
2. Altered source versions must be plainly marked as such, and must not be
50+
misrepresented as being the original software.
51+
52+
3. This notice may not be removed or altered from any source
53+
distribution.
54+
55+
Andreas Schiffler -- aschiffler at ferzkopp dot net
56+
57+
Ne10:
58+
/*
59+
* Copyright 2012-16 ARM Limited and Contributors.
60+
* All rights reserved.
61+
*
62+
* Redistribution and use in source and binary forms, with or without
63+
* modification, are permitted provided that the following conditions are met:
64+
* * Redistributions of source code must retain the above copyright
65+
* notice, this list of conditions and the following disclaimer.
66+
* * Redistributions in binary form must reproduce the above copyright
67+
* notice, this list of conditions and the following disclaimer in the
68+
* documentation and/or other materials provided with the distribution.
69+
* * Neither the name of ARM Limited nor the
70+
* names of its contributors may be used to endorse or promote products
71+
* derived from this software without specific prior written permission.
72+
*
73+
* THIS SOFTWARE IS PROVIDED BY ARM LIMITED AND CONTRIBUTORS "AS IS" AND
74+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
75+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
76+
* DISCLAIMED. IN NO EVENT SHALL ARM LIMITED AND CONTRIBUTORS BE LIABLE FOR ANY
77+
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
78+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
79+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
80+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
82+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83+
*/
84+
85+
/*
86+
* See: http://opensource.org/licenses/BSD-3-Clause for template
87+
*/

source/switch/main.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static const char *stringsNoYes[] = {"No", "Yes"};
5151
static char currentRomPath[PATH_LENGTH] = {'\0'};
5252

5353
static Mutex videoLock;
54-
static u16 *videoTransferBuffer[2];
54+
static u16 *videoTransferBuffer;
5555
static int videoTransferBackbuffer = 0;
5656
static u32 *conversionBuffer;
5757

@@ -517,8 +517,7 @@ static inline u32 bbgr_555_to_rgb_888(u16 in) {
517517

518518
void systemDrawScreen() {
519519
mutexLock(&videoLock);
520-
u16 *dstBuffer = videoTransferBuffer[videoTransferBackbuffer];
521-
memcpy(dstBuffer, pix, sizeof(u16) * 256 * 160);
520+
memcpy(videoTransferBuffer, pix, sizeof(u16) * 256 * 160);
522521
mutexUnlock(&videoLock);
523522

524523
g_video_frames++;
@@ -615,7 +614,7 @@ int main(int argc, char *argv[]) {
615614
threadCreate(&audio_thread, audio_thread_main, NULL, 0x10000, 0x2B, 2);
616615
threadStart(&audio_thread);
617616

618-
for (int i = 0; i < 2; i++) videoTransferBuffer[i] = (u16 *)malloc(256 * 160 * sizeof(u16));
617+
videoTransferBuffer = (u16 *)malloc(256 * 160 * sizeof(u16));
619618
conversionBuffer = (u32 *)malloc(256 * 160 * sizeof(u32));
620619
mutexInit(&videoLock);
621620

@@ -659,15 +658,10 @@ int main(int argc, char *argv[]) {
659658
inputTransferKeysHeld = keysHeld;
660659
mutexUnlock(&inputLock);
661660

662-
mutexLock(&videoLock);
663-
// mutexLock(&videoLock);
664-
int frontBuffer = videoTransferBackbuffer;
665-
videoTransferBackbuffer ^= 1;
666-
mutexUnlock(&videoLock);
667-
668661
if (emulationRunning && !emulationPaused) {
669-
u16 *srcImage16 = videoTransferBuffer[frontBuffer];
670-
for (int i = 0; i < 256 * 160; i++) conversionBuffer[i] = bbgr_555_to_rgb_888(srcImage16[i]);
662+
mutexLock(&videoLock);
663+
664+
for (int i = 0; i < 256 * 160; i++) conversionBuffer[i] = bbgr_555_to_rgb_888(videoTransferBuffer[i]);
671665

672666
u32 *srcImage = conversionBuffer;
673667

@@ -722,6 +716,8 @@ int main(int argc, char *argv[]) {
722716
}
723717
}
724718
}
719+
720+
mutexUnlock(&videoLock);
725721
}
726722

727723
bool actionStopEmulation = false;
@@ -848,7 +844,7 @@ int main(int argc, char *argv[]) {
848844
uiDeinit();
849845

850846
free(conversionBuffer);
851-
for (int i = 0; i < 2; i++) free(videoTransferBuffer[i]);
847+
free(videoTransferBuffer);
852848

853849
threadWaitForExit(&audio_thread);
854850
threadClose(&audio_thread);

0 commit comments

Comments
 (0)