gfx/skia/trunk/src/views/sdl/SkOSWindow_SDL.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1
michael@0 2 /*
michael@0 3 * Copyright 2011 Google Inc.
michael@0 4 *
michael@0 5 * Use of this source code is governed by a BSD-style license that can be
michael@0 6 * found in the LICENSE file.
michael@0 7 */
michael@0 8 #include "SkOSWindow_SDL.h"
michael@0 9 #include "SkCanvas.h"
michael@0 10 #include "SkColorPriv.h"
michael@0 11 #include "SkGLCanvas.h"
michael@0 12 #include "SkOSMenu.h"
michael@0 13 #include "SkTime.h"
michael@0 14
michael@0 15 static void post_SkEvent_event() {
michael@0 16 SDL_Event evt;
michael@0 17 evt.type = SDL_USEREVENT;
michael@0 18 evt.user.type = SDL_USEREVENT;
michael@0 19 evt.user.code = 0;
michael@0 20 evt.user.data1 = NULL;
michael@0 21 evt.user.data2 = NULL;
michael@0 22 SDL_PushEvent(&evt);
michael@0 23 }
michael@0 24
michael@0 25 static bool skia_setBitmapFromSurface(SkBitmap* dst, SDL_Surface* src) {
michael@0 26 SkBitmap::Config config;
michael@0 27
michael@0 28 switch (src->format->BytesPerPixel) {
michael@0 29 case 2:
michael@0 30 config = SkBitmap::kRGB_565_Config;
michael@0 31 break;
michael@0 32 case 4:
michael@0 33 config = SkBitmap::kARGB_8888_Config;
michael@0 34 break;
michael@0 35 default:
michael@0 36 return false;
michael@0 37 }
michael@0 38
michael@0 39 dst->setConfig(config, src->w, src->h, src->pitch);
michael@0 40 dst->setPixels(src->pixels);
michael@0 41 return true;
michael@0 42 }
michael@0 43
michael@0 44 SkOSWindow::SkOSWindow(void* screen) {
michael@0 45 fScreen = reinterpret_cast<SDL_Surface*>(screen);
michael@0 46 this->resize(fScreen->w, fScreen->h);
michael@0 47
michael@0 48 uint32_t rmask = SK_R32_MASK << SK_R32_SHIFT;
michael@0 49 uint32_t gmask = SK_G32_MASK << SK_G32_SHIFT;
michael@0 50 uint32_t bmask = SK_B32_MASK << SK_B32_SHIFT;
michael@0 51 uint32_t amask = SK_A32_MASK << SK_A32_SHIFT;
michael@0 52
michael@0 53 if (fScreen->flags & SDL_OPENGL) {
michael@0 54 fSurface = NULL;
michael@0 55 fGLCanvas = new SkGLCanvas;
michael@0 56 fGLCanvas->setViewport(fScreen->w, fScreen->h);
michael@0 57 } else {
michael@0 58 fGLCanvas = NULL;
michael@0 59 fSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, fScreen->w, fScreen->h,
michael@0 60 32, rmask, gmask, bmask, amask);
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64 SkOSWindow::~SkOSWindow() {
michael@0 65 delete fGLCanvas;
michael@0 66 if (fSurface) {
michael@0 67 SDL_FreeSurface(fSurface);
michael@0 68 }
michael@0 69 }
michael@0 70
michael@0 71 #include <OpenGL/gl.h>
michael@0 72
michael@0 73 void SkOSWindow::doDraw() {
michael@0 74 if (fGLCanvas) {
michael@0 75 glEnable(GL_BLEND);
michael@0 76 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
michael@0 77 glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
michael@0 78 glEnable(GL_TEXTURE_2D);
michael@0 79 glClearColor(0, 0, 0, 0);
michael@0 80 glClear(GL_COLOR_BUFFER_BIT);
michael@0 81
michael@0 82 int count = fGLCanvas->save();
michael@0 83 this->draw(fGLCanvas);
michael@0 84 fGLCanvas->restoreToCount(count);
michael@0 85 SDL_GL_SwapBuffers( );
michael@0 86 } else {
michael@0 87 if ( SDL_MUSTLOCK(fSurface) ) {
michael@0 88 if ( SDL_LockSurface(fSurface) < 0 ) {
michael@0 89 return;
michael@0 90 }
michael@0 91 }
michael@0 92
michael@0 93 SkBitmap bitmap;
michael@0 94
michael@0 95 if (skia_setBitmapFromSurface(&bitmap, fSurface)) {
michael@0 96 SkCanvas canvas(bitmap);
michael@0 97 this->draw(&canvas);
michael@0 98 }
michael@0 99
michael@0 100 if ( SDL_MUSTLOCK(fSurface) ) {
michael@0 101 SDL_UnlockSurface(fSurface);
michael@0 102 }
michael@0 103
michael@0 104 int result = SDL_BlitSurface(fSurface, NULL, fScreen, NULL);
michael@0 105 if (result) {
michael@0 106 SkDebugf("------- SDL_BlitSurface returned %d\n", result);
michael@0 107 }
michael@0 108 SDL_UpdateRect(fScreen, 0, 0, fScreen->w, fScreen->h);
michael@0 109 }
michael@0 110 }
michael@0 111
michael@0 112 static SkKey find_skkey(SDLKey src) {
michael@0 113 // this array must match the enum order in SkKey.h
michael@0 114 static const SDLKey gKeys[] = {
michael@0 115 SDLK_UNKNOWN,
michael@0 116 SDLK_UNKNOWN, // left softkey
michael@0 117 SDLK_UNKNOWN, // right softkey
michael@0 118 SDLK_UNKNOWN, // home
michael@0 119 SDLK_UNKNOWN, // back
michael@0 120 SDLK_UNKNOWN, // send
michael@0 121 SDLK_UNKNOWN, // end
michael@0 122 SDLK_0,
michael@0 123 SDLK_1,
michael@0 124 SDLK_2,
michael@0 125 SDLK_3,
michael@0 126 SDLK_4,
michael@0 127 SDLK_5,
michael@0 128 SDLK_6,
michael@0 129 SDLK_7,
michael@0 130 SDLK_8,
michael@0 131 SDLK_9,
michael@0 132 SDLK_ASTERISK,
michael@0 133 SDLK_HASH,
michael@0 134 SDLK_UP,
michael@0 135 SDLK_DOWN,
michael@0 136 SDLK_LEFT,
michael@0 137 SDLK_RIGHT,
michael@0 138 SDLK_RETURN, // OK
michael@0 139 SDLK_UNKNOWN, // volume up
michael@0 140 SDLK_UNKNOWN, // volume down
michael@0 141 SDLK_UNKNOWN, // power
michael@0 142 SDLK_UNKNOWN, // camera
michael@0 143 };
michael@0 144
michael@0 145 const SDLKey* array = gKeys;
michael@0 146 for (size_t i = 0; i < SK_ARRAY_COUNT(gKeys); i++) {
michael@0 147 if (array[i] == src) {
michael@0 148 return static_cast<SkKey>(i);
michael@0 149 }
michael@0 150 }
michael@0 151 return kNONE_SkKey;
michael@0 152 }
michael@0 153
michael@0 154 void SkOSWindow::handleSDLEvent(const SDL_Event& event) {
michael@0 155 switch (event.type) {
michael@0 156 case SDL_VIDEORESIZE:
michael@0 157 this->resize(event.resize.w, event.resize.h);
michael@0 158 break;
michael@0 159 case SDL_VIDEOEXPOSE:
michael@0 160 this->doDraw();
michael@0 161 break;
michael@0 162 case SDL_MOUSEMOTION:
michael@0 163 if (event.motion.state == SDL_PRESSED) {
michael@0 164 this->handleClick(event.motion.x, event.motion.y,
michael@0 165 SkView::Click::kMoved_State);
michael@0 166 }
michael@0 167 break;
michael@0 168 case SDL_MOUSEBUTTONDOWN:
michael@0 169 case SDL_MOUSEBUTTONUP:
michael@0 170 this->handleClick(event.button.x, event.button.y,
michael@0 171 event.button.state == SDL_PRESSED ?
michael@0 172 SkView::Click::kDown_State :
michael@0 173 SkView::Click::kUp_State);
michael@0 174 break;
michael@0 175 case SDL_KEYDOWN: {
michael@0 176 SkKey sk = find_skkey(event.key.keysym.sym);
michael@0 177 if (kNONE_SkKey != sk) {
michael@0 178 if (event.key.state == SDL_PRESSED) {
michael@0 179 this->handleKey(sk);
michael@0 180 } else {
michael@0 181 this->handleKeyUp(sk);
michael@0 182 }
michael@0 183 }
michael@0 184 break;
michael@0 185 }
michael@0 186 case SDL_USEREVENT:
michael@0 187 if (SkEvent::ProcessEvent()) {
michael@0 188 post_SkEvent_event();
michael@0 189 }
michael@0 190 break;
michael@0 191 }
michael@0 192 }
michael@0 193
michael@0 194 void SkOSWindow::onHandleInval(const SkIRect& r) {
michael@0 195 SDL_Event evt;
michael@0 196 evt.type = SDL_VIDEOEXPOSE;
michael@0 197 evt.expose.type = SDL_VIDEOEXPOSE;
michael@0 198 SDL_PushEvent(&evt);
michael@0 199 }
michael@0 200
michael@0 201 void SkOSWindow::onSetTitle(const char title[]) {
michael@0 202 SDL_WM_SetCaption(title, NULL);
michael@0 203 }
michael@0 204
michael@0 205 void SkOSWindow::onAddMenu(const SkOSMenu* sk_menu) {}
michael@0 206
michael@0 207 ///////////////////////////////////////////////////////////////////////////////////////
michael@0 208
michael@0 209 void SkEvent::SignalNonEmptyQueue() {
michael@0 210 SkDebugf("-------- signal nonempty\n");
michael@0 211 post_SkEvent_event();
michael@0 212 }
michael@0 213
michael@0 214 static Uint32 timer_callback(Uint32 interval) {
michael@0 215 // SkDebugf("-------- timercallback %d\n", interval);
michael@0 216 SkEvent::ServiceQueueTimer();
michael@0 217 return 0;
michael@0 218 }
michael@0 219
michael@0 220 void SkEvent::SignalQueueTimer(SkMSec delay)
michael@0 221 {
michael@0 222 SDL_SetTimer(0, NULL);
michael@0 223 if (delay) {
michael@0 224 SDL_SetTimer(delay, timer_callback);
michael@0 225 }
michael@0 226 }

mercurial