Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(741)

Side by Side Diff: ports/sdl/nacl.patch

Issue 337323007: Add quakespasm, and OpenGL+SDL-based port of quake1. (Closed) Base URL: https://naclports.googlecode.com/svn/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 diff --git a/Makefile.in b/Makefile.in 1 diff --git a/Makefile.in b/Makefile.in
2 index e29dc6d..bb485dd 100644 2 index e29dc6d..bb485dd 100644
3 --- a/Makefile.in 3 --- a/Makefile.in
4 +++ b/Makefile.in 4 +++ b/Makefile.in
5 @@ -36,13 +36,13 @@ TARGET = libSDL.la 5 @@ -36,13 +36,13 @@ TARGET = libSDL.la
6 SOURCES = @SOURCES@ 6 SOURCES = @SOURCES@
7 OBJECTS = @OBJECTS@ 7 OBJECTS = @OBJECTS@
8 8
9 -SDLMAIN_TARGET = libSDLmain.a 9 -SDLMAIN_TARGET = libSDLmain.a
10 +SDLMAIN_TARGET = libSDLmain.la 10 +SDLMAIN_TARGET = libSDLmain.la
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 extern AudioBootStrap MINTAUDIO_DMA8_bootstrap; 326 extern AudioBootStrap MINTAUDIO_DMA8_bootstrap;
327 #endif 327 #endif
328 +#if SDL_AUDIO_DRIVER_NACL 328 +#if SDL_AUDIO_DRIVER_NACL
329 +extern AudioBootStrap NACLAUD_bootstrap; 329 +extern AudioBootStrap NACLAUD_bootstrap;
330 +#endif 330 +#endif
331 #if SDL_AUDIO_DRIVER_DISK 331 #if SDL_AUDIO_DRIVER_DISK
332 extern AudioBootStrap DISKAUD_bootstrap; 332 extern AudioBootStrap DISKAUD_bootstrap;
333 #endif 333 #endif
334 diff --git a/src/audio/nacl/SDL_naclaudio.cc b/src/audio/nacl/SDL_naclaudio.cc 334 diff --git a/src/audio/nacl/SDL_naclaudio.cc b/src/audio/nacl/SDL_naclaudio.cc
335 new file mode 100644 335 new file mode 100644
336 index 0000000..908a498 336 index 0000000..7a02156
337 --- /dev/null 337 --- /dev/null
338 +++ b/src/audio/nacl/SDL_naclaudio.cc 338 +++ b/src/audio/nacl/SDL_naclaudio.cc
339 @@ -0,0 +1,150 @@ 339 @@ -0,0 +1,140 @@
340 +#include "SDL_config.h" 340 +#include "SDL_config.h"
341 +#include "SDL_naclaudio.h" 341 +#include "SDL_naclaudio.h"
342 + 342 +
343 +#include <assert.h> 343 +#include <assert.h>
344 + 344 +
345 +#include <ppapi/c/pp_instance.h> 345 +#include <ppapi/c/pp_instance.h>
346 +#include <ppapi/c/ppb.h> 346 +#include <ppapi/c/ppb.h>
347 +#include <ppapi/c/ppb_audio.h> 347 +#include <ppapi/c/ppb_audio.h>
348 +#include <ppapi/c/ppb_audio_config.h> 348 +#include <ppapi/c/ppb_audio_config.h>
349 +#include <ppapi/c/ppb_core.h> 349 +#include <ppapi/c/ppb_core.h>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 + SDL_OutOfMemory(); 404 + SDL_OutOfMemory();
405 + if (_this) { 405 + if (_this) {
406 + SDL_free(_this); 406 + SDL_free(_this);
407 + } 407 + }
408 + return (0); 408 + return (0);
409 + } 409 + }
410 + SDL_memset(_this->hidden, 0, (sizeof *_this->hidden)); 410 + SDL_memset(_this->hidden, 0, (sizeof *_this->hidden));
411 + 411 +
412 + _this->hidden->mutex = SDL_CreateMutex(); 412 + _this->hidden->mutex = SDL_CreateMutex();
413 + 413 +
414 + _this->hidden->opened = false;
415 +
416 + // TODO: Move audio device creation to NACLAUD_OpenAudio. 414 + // TODO: Move audio device creation to NACLAUD_OpenAudio.
417 + const PPB_Audio_1_1* g_nacl_audio_interface = 415 + g_nacl_audio_interface =
418 + (const PPB_Audio_1_1*)g_nacl_get_interface(PPB_AUDIO_INTERFACE_1_1); 416 + (const PPB_Audio_1_1*)g_nacl_get_interface(PPB_AUDIO_INTERFACE_1_1);
419 + const PPB_AudioConfig_1_1* g_nacl_audio_config_interface = 417 + g_nacl_audio_config_interface =
420 + (const PPB_AudioConfig_1_1*)g_nacl_get_interface( 418 + (const PPB_AudioConfig_1_1*)g_nacl_get_interface(
421 + PPB_AUDIO_CONFIG_INTERFACE_1_1); 419 + PPB_AUDIO_CONFIG_INTERFACE_1_1);
422 + 420 +
423 + _this->hidden->sample_frame_count = 421 + _this->hidden->sample_frame_count =
424 + g_nacl_audio_config_interface->RecommendSampleFrameCount( 422 + g_nacl_audio_config_interface->RecommendSampleFrameCount(
425 + g_nacl_pp_instance, PP_AUDIOSAMPLERATE_44100, kSampleFrameCount); 423 + g_nacl_pp_instance, PP_AUDIOSAMPLERATE_44100, kSampleFrameCount);
426 + 424 +
427 + PP_Resource audio_config = g_nacl_audio_config_interface->CreateStereo16Bit( 425 + PP_Resource audio_config = g_nacl_audio_config_interface->CreateStereo16Bit(
428 + g_nacl_pp_instance, PP_AUDIOSAMPLERATE_44100, 426 + g_nacl_pp_instance, PP_AUDIOSAMPLERATE_44100,
429 + _this->hidden->sample_frame_count); 427 + _this->hidden->sample_frame_count);
(...skipping 11 matching lines...) Expand all
441 + 439 +
442 + return _this; 440 + return _this;
443 +} 441 +}
444 + 442 +
445 +AudioBootStrap NACLAUD_bootstrap = { 443 +AudioBootStrap NACLAUD_bootstrap = {
446 + NACLAUD_DRIVER_NAME, "SDL nacl audio driver", 444 + NACLAUD_DRIVER_NAME, "SDL nacl audio driver",
447 + NACLAUD_Available, NACLAUD_CreateDevice 445 + NACLAUD_Available, NACLAUD_CreateDevice
448 +}; 446 +};
449 + 447 +
450 +static void NACLAUD_CloseAudio(_THIS) { 448 +static void NACLAUD_CloseAudio(_THIS) {
451 + SDL_LockMutex(_this->hidden->mutex);
452 + _this->hidden->opened = 0;
453 + SDL_UnlockMutex(_this->hidden->mutex);
454 +} 449 +}
455 + 450 +
456 +static void AudioCallback(void* samples, uint32_t buffer_size, PP_TimeDelta, 451 +static void AudioCallback(void* samples, uint32_t buffer_size, PP_TimeDelta,
457 + void* data) { 452 + void* data) {
458 + SDL_AudioDevice* _this = reinterpret_cast<SDL_AudioDevice*>(data); 453 + SDL_AudioDevice* _this = reinterpret_cast<SDL_AudioDevice*>(data);
459 + 454 +
460 + SDL_LockMutex(_this->hidden->mutex); 455 + SDL_LockMutex(_this->hidden->mutex);
461 + if (_this->hidden->opened) { 456 + /* Only do anything if audio is enabled and not paused */
457 + if (_this->enabled && !_this->paused) {
462 + SDL_memset(samples, _this->spec.silence, buffer_size); 458 + SDL_memset(samples, _this->spec.silence, buffer_size);
463 + SDL_LockMutex(_this->mixer_lock); 459 + SDL_LockMutex(_this->mixer_lock);
464 + (*_this->spec.callback)(_this->spec.userdata, (Uint8*)samples, buffer_size) ; 460 + (*_this->spec.callback)(_this->spec.userdata, (Uint8*)samples, buffer_size) ;
465 + SDL_UnlockMutex(_this->mixer_lock); 461 + SDL_UnlockMutex(_this->mixer_lock);
466 + } else { 462 + } else {
467 + SDL_memset(samples, 0, buffer_size); 463 + SDL_memset(samples, 0, buffer_size);
468 + } 464 + }
469 + SDL_UnlockMutex(_this->hidden->mutex); 465 + SDL_UnlockMutex(_this->hidden->mutex);
470 + 466 +
471 + return; 467 + return;
472 +} 468 +}
473 + 469 +
474 +static int NACLAUD_OpenAudio(_THIS, SDL_AudioSpec* spec) { 470 +static int NACLAUD_OpenAudio(_THIS, SDL_AudioSpec* spec) {
475 + // We don't care what the user wants. 471 + // We don't care what the user wants.
476 + spec->freq = 44100; 472 + spec->freq = 44100;
477 + spec->format = AUDIO_S16LSB; 473 + spec->format = AUDIO_S16LSB;
478 + spec->channels = 2; 474 + spec->channels = 2;
479 + spec->samples = _this->hidden->sample_frame_count; 475 + spec->samples = _this->hidden->sample_frame_count;
480 +
481 + SDL_LockMutex(_this->hidden->mutex);
482 + _this->hidden->opened = 1;
483 + SDL_UnlockMutex(_this->hidden->mutex);
484 +
485 + // Do not create an audio thread.
486 + return 1; 476 + return 1;
487 +} 477 +}
488 + 478 +
489 +} // extern "C" 479 +} // extern "C"
490 diff --git a/src/audio/nacl/SDL_naclaudio.h b/src/audio/nacl/SDL_naclaudio.h 480 diff --git a/src/audio/nacl/SDL_naclaudio.h b/src/audio/nacl/SDL_naclaudio.h
491 new file mode 100644 481 new file mode 100644
492 index 0000000..b166ab0 482 index 0000000..ab52848
493 --- /dev/null 483 --- /dev/null
494 +++ b/src/audio/nacl/SDL_naclaudio.h 484 +++ b/src/audio/nacl/SDL_naclaudio.h
495 @@ -0,0 +1,30 @@ 485 @@ -0,0 +1,23 @@
496 +#include "SDL_config.h" 486 +#include "SDL_config.h"
497 + 487 +
498 +#ifndef _SDL_naclaudio_h 488 +#ifndef _SDL_naclaudio_h
499 +#define _SDL_naclaudio_h 489 +#define _SDL_naclaudio_h
500 + 490 +
501 +extern "C" { 491 +extern "C" {
502 +#include "SDL_audio.h" 492 +#include "SDL_audio.h"
503 +#include "../SDL_sysaudio.h" 493 +#include "../SDL_sysaudio.h"
504 +#include "SDL_mutex.h" 494 +#include "SDL_mutex.h"
505 +} 495 +}
506 + 496 +
507 +#include <ppapi/c/ppb_audio.h> 497 +#include <ppapi/c/ppb_audio.h>
508 + 498 +
509 +/* Hidden "this" pointer for the video functions */ 499 +/* Hidden "this" pointer for the video functions */
510 +#define _THIS SDL_AudioDevice *_this 500 +#define _THIS SDL_AudioDevice *_this
511 + 501 +
512 +struct SDL_PrivateAudioData { 502 +struct SDL_PrivateAudioData {
513 +
514 + SDL_mutex* mutex; 503 + SDL_mutex* mutex;
515 + // This flag is use to determine when the audio is opened and we can start
516 + // serving audio data instead of silence. This is needed because current
517 + // Pepper2 can only be used from the main thread; Therefore, we start the
518 + // audio thread very early.
519 + bool opened;
520 +
521 + int sample_frame_count; 504 + int sample_frame_count;
522 + PP_Resource audio; 505 + PP_Resource audio;
523 +}; 506 +};
524 + 507 +
525 +#endif /* _SDL_naclaudio_h */ 508 +#endif /* _SDL_naclaudio_h */
526 diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c 509 diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c
527 index 5c2d81f..7a757a3 100644 510 index 5c2d81f..7a757a3 100644
528 --- a/src/cpuinfo/SDL_cpuinfo.c 511 --- a/src/cpuinfo/SDL_cpuinfo.c
529 +++ b/src/cpuinfo/SDL_cpuinfo.c 512 +++ b/src/cpuinfo/SDL_cpuinfo.c
530 @@ -53,6 +53,8 @@ static void illegal_instruction(int sig) 513 @@ -53,6 +53,8 @@ static void illegal_instruction(int sig)
(...skipping 16 matching lines...) Expand all
547 +static __inline__ int CPU_getCPUIDFeatures(void) { return 0; } 530 +static __inline__ int CPU_getCPUIDFeatures(void) { return 0; }
548 + 531 +
549 +#endif // SDL_ASSEMBLY_ROUTINES 532 +#endif // SDL_ASSEMBLY_ROUTINES
550 + 533 +
551 + 534 +
552 static __inline__ int CPU_haveRDTSC(void) 535 static __inline__ int CPU_haveRDTSC(void)
553 { 536 {
554 if ( CPU_haveCPUID() ) { 537 if ( CPU_haveCPUID() ) {
555 diff --git a/src/main/nacl/pepper_instance.c b/src/main/nacl/pepper_instance.c 538 diff --git a/src/main/nacl/pepper_instance.c b/src/main/nacl/pepper_instance.c
556 new file mode 100644 539 new file mode 100644
557 index 0000000..997e13a 540 index 0000000..6e1f036
558 --- /dev/null 541 --- /dev/null
559 +++ b/src/main/nacl/pepper_instance.c 542 +++ b/src/main/nacl/pepper_instance.c
560 @@ -0,0 +1,310 @@ 543 @@ -0,0 +1,338 @@
561 +/* 544 +/*
562 + * Copyright (c) 2011 The Native Client Authors. All rights reserved. 545 + * Copyright (c) 2011 The Native Client Authors. All rights reserved.
563 + * Use of this source code is governed by a BSD-style license that can be 546 + * Use of this source code is governed by a BSD-style license that can be
564 + * found in the LICENSE file. 547 + * found in the LICENSE file.
565 + */ 548 + */
566 +#include <assert.h> 549 +#include <assert.h>
567 +#include <errno.h> 550 +#include <errno.h>
568 +#include <fcntl.h> 551 +#include <fcntl.h>
569 +#include <libtar.h> 552 +#include <libtar.h>
570 +#include <pthread.h> 553 +#include <pthread.h>
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 + free(message); 674 + free(message);
692 + return count; 675 + return count;
693 +} 676 +}
694 + 677 +
695 +static void ProcessArgs() { 678 +static void ProcessArgs() {
696 + int i; 679 + int i;
697 + int rtn; 680 + int rtn;
698 + int mount_default = 1; 681 + int mount_default = 1;
699 + nacl_io_log("SDL: ProcessArgs %d\n", g_argc); 682 + nacl_io_log("SDL: ProcessArgs %d\n", g_argc);
700 + 683 +
701 + umount("/"); 684 + // This could fail if the sdl_mount_http attributes
binji 2014/07/18 23:48:04 Hm, this seems like a significant change. Mention
Sam Clegg 2014/07/19 00:59:50 Split into separate CL
685 + // above created a mount on "/".
686 + fprintf(stderr, "SDL: creating memfs on root\n");
687 +
688 + rtn = umount("/");
689 + if (rtn != 0)
690 + fprintf(stderr, "SDL: umount failed: %s\n", strerror(errno));
691 +
692 + rtn = mount("", "/", "memfs", 0, "");
693 + if (rtn != 0)
694 + fprintf(stderr, "SDL: mount failed: %s\n", strerror(errno));
695 +
696 + rtn = mkdir("/tmp", S_IRWXU | S_IRWXG);
697 + if (rtn != 0)
698 + fprintf(stderr, "SDL: mkdir /tmp failed: %s\n", strerror(errno));
699 +
700 + rtn = mkdir("/home", S_IRWXU | S_IRWXG);
701 + if (rtn != 0)
702 + fprintf(stderr, "SDL: mkdir /home failed: %s\n", strerror(errno));
703 +
704 + rtn = mount("", "/tmp", "html5fs", 0, "type=TEMPORARY");
705 + if (rtn != 0)
706 + fprintf(stderr, "SDL: mount /tmp failed: %s\n", strerror(errno));
702 + 707 +
703 + for (i = 0; i < g_argc; i++) { 708 + for (i = 0; i < g_argc; i++) {
704 + if (!strcmp(g_argn[i], "ps_stdout")) { 709 + if (!strcmp(g_argn[i], "ps_stdout")) {
705 + int fd1 = open(g_argv[i], O_WRONLY); 710 + int fd1 = open(g_argv[i], O_WRONLY);
706 + dup2(fd1, 1); 711 + dup2(fd1, 1);
707 + } else if (!strcmp(g_argn[i], "ps_stderr")) { 712 + } else if (!strcmp(g_argn[i], "ps_stderr")) {
708 + int fd2 = open(g_argv[i], O_WRONLY); 713 + int fd2 = open(g_argv[i], O_WRONLY);
709 + dup2(fd2, 2); 714 + dup2(fd2, 2);
710 + } else if (!strcmp(g_argn[i], "ps_tty_prefix")) { 715 + } else if (!strcmp(g_argn[i], "ps_tty_prefix")) {
711 + g_tty_prefix = g_argv[i]; 716 + g_tty_prefix = g_argv[i];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 + rtn = mount(source, target, "httpfs", 0, ""); 754 + rtn = mount(source, target, "httpfs", 0, "");
750 + if (rtn != 0) 755 + if (rtn != 0)
751 + fprintf(stderr, "SDL: mount failed: %s\n", strerror(errno)); 756 + fprintf(stderr, "SDL: mount failed: %s\n", strerror(errno));
752 + } 757 + }
753 + } 758 + }
754 + } 759 + }
755 + 760 +
756 + if (mount_default) { 761 + if (mount_default) {
757 + // Create an http mount by default 762 + // Create an http mount by default
758 + fprintf(stderr, "SDL: creating default http mount\n"); 763 + fprintf(stderr, "SDL: creating default http mount\n");
759 + rtn = mount("", "/", "httpfs", 0, ""); 764 + rtn = chdir("/home");
760 + if (rtn != 0) fprintf(stderr, "SDL: mount failed: %s\n", strerror(errno)); 765 + if (rtn != 0)
761 + } else { 766 + fprintf(stderr, "SDL: chdir failed: %s\n", strerror(errno));
762 + // This could fail if the sdl_mount_http attributes 767 + rtn = mount(".", "/home", "httpfs", 0, "");
763 + // about created a mount on "/". 768 + if (rtn != 0)
764 + fprintf(stderr, "SDL: creating memfs on root\n"); 769 + fprintf(stderr, "SDL: mount failed: %s\n", strerror(errno));
765 + mount("", "/", "memfs", 0, "");
766 + } 770 + }
767 + 771 +
768 + for (i = 0; i < g_argc; i++) { 772 + for (i = 0; i < g_argc; i++) {
769 + if (!strcmp(g_argn[i], "sdl_tar_extract")) { 773 + nacl_io_log("SDL: arg=%s\n", g_argn[i]);
774 + if (!stricmp(g_argn[i], "PWD")) {
775 + int rtn = chdir(g_argv[i]);
776 + if (rtn != 0)
777 + nacl_io_log("SDL: chdir(%s) failed\n", g_argv[i]);
778 + else
779 + nacl_io_log("SDL: chdir(%s)\n", g_argv[i]);
780 + } else if (!strcmp(g_argn[i], "sdl_tar_extract")) {
770 + const char* source; 781 + const char* source;
771 + const char* target = "/"; 782 + const char* target = "/";
772 + char* sep; 783 + char* sep;
773 + char buf[64]; 784 + char buf[64];
774 + int n; 785 + int n;
775 + 786 +
776 + const char* q, *p = g_argv[i]; 787 + const char* q, *p = g_argv[i];
777 + while (*p) { 788 + while (*p) {
778 + while (*p && isspace(*p)) ++p; 789 + while (*p && isspace(*p)) ++p;
779 + if (!*p) break; 790 + if (!*p) break;
(...skipping 17 matching lines...) Expand all
797 + 808 +
798 + TAR* tar; 809 + TAR* tar;
799 + rtn = tar_open(&tar, (char*)source, NULL, O_RDONLY, 0, 0); 810 + rtn = tar_open(&tar, (char*)source, NULL, O_RDONLY, 0, 0);
800 + if (rtn != 0) { 811 + if (rtn != 0) {
801 + fprintf(stderr, "SDL: tar_open failed\n"); 812 + fprintf(stderr, "SDL: tar_open failed\n");
802 + assert(0); 813 + assert(0);
803 + continue; 814 + continue;
804 + } 815 + }
805 + 816 +
806 + rtn = mkdir(target, S_IRWXU | S_IRWXG); 817 + rtn = mkdir(target, S_IRWXU | S_IRWXG);
807 + if (rtn != 0) { 818 + if (rtn != 0)
808 + fprintf(stderr, "SDL: mkdir failed: %s\n", strerror(errno)); 819 + fprintf(stderr, "SDL: mkdir failed: %s\n", strerror(errno));
809 + } 820 +
810 + rtn = tar_extract_all(tar, (char*)target); 821 + rtn = tar_extract_all(tar, (char*)target);
811 + if (rtn != 0) { 822 + if (rtn != 0) {
812 + fprintf(stderr, "SDL: tar_extract_all failed\n"); 823 + fprintf(stderr, "SDL: tar_extract_all failed\n");
813 + assert(0); 824 + assert(0);
814 + } 825 + }
815 + 826 +
816 + rtn = tar_close(tar); 827 + rtn = tar_close(tar);
817 + if (rtn != 0) { 828 + if (rtn != 0) {
818 + fprintf(stderr, "SDL: tar_clone failed\n"); 829 + fprintf(stderr, "SDL: tar_clone failed\n");
819 + assert(0); 830 + assert(0);
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after
1816 + queue_.push(event); 1827 + queue_.push(event);
1817 + SDL_UnlockMutex(mu_); 1828 + SDL_UnlockMutex(mu_);
1818 + } 1829 + }
1819 + 1830 +
1820 +private: 1831 +private:
1821 + std::queue<SDL_Event*> queue_; 1832 + std::queue<SDL_Event*> queue_;
1822 + SDL_mutex* mu_; 1833 + SDL_mutex* mu_;
1823 +}; 1834 +};
1824 + 1835 +
1825 +#endif // _SDL_nacl_eventqueue_h 1836 +#endif // _SDL_nacl_eventqueue_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698