 +}
 +
 +SDL_Rect **NACL_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) {
++  // TODO: list modes
 +  return (SDL_Rect **) -1;
 +}
 +
 +
 +SDL_Surface *NACL_SetVideoMode(_THIS, SDL_Surface *current,
 +    int width, int height, int bpp, Uint32 flags) {
-+  if ( _this->hidden->buffer ) {
-+    SDL_free( _this->hidden->buffer );
-+  }
-+
-+  bpp = 32; // Let SDL handle pixel format conversion.
-+  width = _this->hidden->ow;
-+  height = _this->hidden->oh;
-+
-+  _this->hidden->buffer = SDL_malloc(width * height * (bpp / 8));
-+  if ( ! _this->hidden->buffer ) {
-+    SDL_SetError("Couldn't allocate buffer for requested mode");
-+    return(NULL);
-+  }
-+
-+  SDL_memset(_this->hidden->buffer, 0, width * height * (bpp / 8));
++
++  fprintf(stderr, "setvideomode %d %d %d %u\n", width, height, bpp, flags);
++  fflush(stderr);
++
++  if (width > _this->hidden->ow || height > _this->hidden->oh)
++    return NULL;
++  _this->hidden->bpp = bpp = 32; // Let SDL handle pixel format conversion.
++  _this->hidden->w = width;
++  _this->hidden->h = height;
++
++  SDLNaclJob* job = new SDLNaclJob(CREATE_GRAPHICS_CONTEXT, _this);
++  int32_t rv = gNaclMainThreadRunner->RunJob(job);
++  if (rv != PP_OK)
++    return NULL;
 +
 +  /* Allocate the new pixel format for the screen */
 +  if ( ! SDL_ReallocFormat(current, bpp, 0xFF0000, 0xFF00, 0xFF, 0) ) {
-+    SDL_free(_this->hidden->buffer);
-+    _this->hidden->buffer = NULL;
 +    SDL_SetError("Couldn't allocate new pixel format for requested mode");
 +    return(NULL);
 +  }

+
+  device->free = NACL_DeleteDevice;
+
+  flush(device, 0);
+
+  return device;
+}
+

+#include "close_code.h"
+
+#endif /* _SDL_nacl_h */
diff -urN SDL-1.2.14/include/SDL_platform.h SDL-1.2.14-nacl//include/SDL_platform.h
--- SDL-1.2.14/include/SDL_platform.h	2009-10-13 03:07:19.000000000 +0400
+++ SDL-1.2.14-nacl//include/SDL_platform.h	2011-11-28 23:43:22.679635058 +0400
@@ -63,10 +63,14 @@
 #undef __IRIX__
 #define __IRIX__	1
