root/trunk/BAL/Widgets/WebKit/SDL/WebWindowSDL.cpp

Revision 1368, 5.4 kB (checked in by mbensi, 7 months ago)

BAL:

2010-02-15 Mario Bensi <mbensi@pleyo.com>

add Threads on drt.

  • Scripts/Drt/runThreadTests.py: Added.
  • Scripts/Drt/runtests.py:
  • Widgets/WebKit/SDL/WebWindowSDL.cpp: remove space
    (WebWindow::updateRect):

WebKit?:

2010-02-15 Mario Bensi <mbensi@pleyo.com>

Add test in createPlugin.

Line 
1 /*
2  * Copyright (C) 2010 Pleyo.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  * 3.  Neither the name of Pleyo nor the names of
14  *     its contributors may be used to endorse or promote products derived
15  *     from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY PLEYO AND ITS CONTRIBUTORS "AS IS" AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL PLEYO OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #include "config.h"
29
30 #include "GraphicsContext.h"
31 #include "WebWindow.h"
32 #include "WebView.h"
33 #include "SDL/SDL.h"
34 #include <signal.h>
35 #include <unistd.h>
36
37 using namespace WebCore;
38 static bool quit = false;
39  
40 void WebWindow::createPlatformWindow()
41 {
42 #if PLATFORM(SDLCAIRO)
43     m_surface = cairo_image_surface_create_for_data (
44                                     (unsigned char*)m_mainSurface->pixels,
45                                     CAIRO_FORMAT_ARGB32,
46                                     m_mainSurface->w,
47                                     m_mainSurface->h,
48                                     m_mainSurface->pitch);
49 #else
50     Uint32 rmask, gmask, bmask, amask;
51     rmask = 0x00ff0000;
52     gmask = 0x0000ff00;
53     bmask = 0x000000ff;
54     amask = 0xff000000;
55     m_surface = SDL_CreateRGBSurface(SDL_HWSURFACE | SDL_SRCALPHA, m_mainSurface->w, m_mainSurface->h, 32,
56                                   rmask, gmask, bmask, amask);
57 #endif
58 }
59
60 GraphicsContext* WebWindow::createContext()
61 {
62 #if PLATFORM(SDLCAIRO)
63     cairo_t* cr = cairo_create(m_surface);
64     GraphicsContext *ctx = new GraphicsContext(cr);
65 #else
66     GraphicsContext *ctx = new GraphicsContext(m_surface);
67 #endif
68     return ctx;
69 }
70
71 void WebWindow::releaseContext(GraphicsContext* ctx)
72 {
73 #if PLATFORM(SDLCAIRO)
74     cairo_t* cr = ctx->platformContext();
75     cairo_destroy(cr);
76 #endif
77     delete ctx;
78 }
79
80 void WebWindow::updateRect(BalRectangle src, BalRectangle dest)
81 {
82 #if !PLATFORM(SDLCAIRO)
83     SDL_BlitSurface(m_surface, &src, m_mainSurface, &src);
84     SDL_BlitSurface(m_mainSurface, &src, SDL_GetVideoSurface(), &dest);
85 #else
86     if (SDL_GetVideoSurface()->flags & SDL_DOUBLEBUF)
87         SDL_Flip(SDL_GetVideoSurface());
88     else
89         SDL_UpdateRect(SDL_GetVideoSurface(), dest.x, dest.y, dest.w, dest.h);
90 #endif
91 }
92
93 static void quitCatcher(int)
94 {
95     SDL_Quit();
96     exit(1);
97 }
98
99 void WebWindow::runMainLoop()
100 {
101     quit = false;
102
103     signal(SIGKILL, &quitCatcher);
104     signal(SIGINT, &quitCatcher);
105     signal(SIGTERM, &quitCatcher);
106
107     SDL_Event event;
108     while (!quit) {
109         if (SDL_PollEvent(&event) != 0)
110         {
111             switch (event.type) {
112                 case SDL_ACTIVEEVENT:
113                 {
114                     SDL_ExposeEvent ev;
115                     memset(&ev, 0, sizeof(SDL_ExposeEvent));
116                     BalRectangle rect = m_webView->frameRect();
117                     onExpose(ev, rect);
118                     break;
119                 }
120                 case SDL_KEYDOWN:
121                     onKeyDown(event.key);
122                     break;
123                 case SDL_KEYUP:
124                     onKeyUp(event.key);
125                     break;
126                 case SDL_MOUSEMOTION:
127                     onMouseMotion(event.motion);
128                     break;
129                 case SDL_MOUSEBUTTONDOWN:
130                     if(event.button.button == SDL_BUTTON_WHEELUP || event.button.button == SDL_BUTTON_WHEELDOWN)
131                         onScroll(event.button);
132                     else
133                         onMouseButtonDown(event.button);
134                     break;
135                 case SDL_MOUSEBUTTONUP:
136                     if(event.button.button == SDL_BUTTON_WHEELUP || event.button.button == SDL_BUTTON_WHEELDOWN) {
137                         onScroll(event.button);
138                     }
139                     else
140                         onMouseButtonUp(event.button);
141                 case SDL_VIDEORESIZE:
142                     break;
143                 case SDL_VIDEOEXPOSE:
144                 {
145                     BalRectangle rect = m_webView->frameRect();
146                     onExpose(event.expose, rect);
147                     break;
148                 }
149                 case SDL_USEREVENT:
150                     onUserEvent(event.user);
151                     break;
152                 case SDL_SYSWMEVENT:
153                     break;
154                 default:
155                     ;//printf("other event\n");
156             }
157         } else
158             onIdle();
159     }
160 }
161
162 void WebWindow::stopMainLoop()
163 {
164     quit = true;
165 }
Note: See TracBrowser for help on using the browser.