2b41631d068cb94016046d3367547316819714cf
[profile/ivi/qtbase.git] / src / plugins / platforms / qnx / qqnxwindow.cpp
1 /***************************************************************************
2 **
3 ** Copyright (C) 2011 - 2012 Research In Motion
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qqnxwindow.h"
43 #include "qqnxglcontext.h"
44 #include "qqnxintegration.h"
45 #include "qqnxscreen.h"
46
47 #include <QtGui/QWindow>
48 #include <QtGui/QWindowSystemInterface>
49
50 #include <QtCore/QDebug>
51
52 #include <errno.h>
53
54 QT_BEGIN_NAMESPACE
55
56 QQnxWindow::QQnxWindow(QWindow *window, screen_context_t context)
57     : QPlatformWindow(window),
58       m_screenContext(context),
59       m_window(0),
60       m_currentBufferIndex(-1),
61       m_previousBufferIndex(-1),
62       m_platformOpenGLContext(0),
63       m_screen(0),
64       m_parentWindow(0),
65       m_visible(true)
66 {
67 #if defined(QQNXWINDOW_DEBUG)
68     qDebug() << Q_FUNC_INFO << "window =" << window << ", size =" << window->size();
69 #endif
70     int result;
71
72     // Create child QNX window
73     errno = 0;
74     result = screen_create_window_type(&m_window, m_screenContext, SCREEN_CHILD_WINDOW);
75     if (result != 0) {
76         qFatal("QQnxWindow: failed to create window, errno=%d", errno);
77     }
78
79     // Set window buffer usage based on rendering API
80     int val;
81     QSurface::SurfaceType surfaceType = window->surfaceType();
82     switch (surfaceType) {
83     case QSurface::RasterSurface:
84         val = SCREEN_USAGE_NATIVE | SCREEN_USAGE_READ | SCREEN_USAGE_WRITE;
85         break;
86     case QSurface::OpenGLSurface:
87         val = SCREEN_USAGE_OPENGL_ES2;
88         break;
89     default:
90         qFatal("QQnxWindow: unsupported window API");
91         break;
92     }
93
94     errno = 0;
95     result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_USAGE, &val);
96     if (result != 0) {
97         qFatal("QQnxWindow: failed to set window buffer usage, errno=%d", errno);
98     }
99
100     // Alpha channel is always pre-multiplied if present
101     errno = 0;
102     val = SCREEN_PRE_MULTIPLIED_ALPHA;
103     result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ALPHA_MODE, &val);
104     if (result != 0) {
105         qFatal("QQnxWindow: failed to set window alpha mode, errno=%d", errno);
106     }
107
108     // Make the window opaque
109     errno = 0;
110     val = SCREEN_TRANSPARENCY_NONE;
111     result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_TRANSPARENCY, &val);
112     if (result != 0) {
113         qFatal("QQnxWindow: failed to set window transparency, errno=%d", errno);
114     }
115
116     // Set the window swap interval
117     errno = 0;
118     val = 1;
119     result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SWAP_INTERVAL, &val);
120     if (result != 0) {
121         qFatal("QQnxWindow: failed to set window swap interval, errno=%d", errno);
122     }
123
124     setScreen(static_cast<QQnxScreen *>(window->screen()->handle()));
125
126     // Add window to plugin's window mapper
127     QQnxIntegration::addWindow(m_window, window);
128 }
129
130 QQnxWindow::~QQnxWindow()
131 {
132 #if defined(QQNXWINDOW_DEBUG)
133     qDebug() << Q_FUNC_INFO << "window =" << window();
134 #endif
135     // Remove from plugin's window mapper
136     QQnxIntegration::removeWindow(m_window);
137
138     // Remove from parent's Hierarchy.
139     removeFromParent();
140     m_screen->updateHierarchy();
141
142     // We shouldn't allow this case unless QT allows it. Does it? Or should we send the
143     // handleCloseEvent on all children when this window is deleted?
144     if (m_childWindows.size() > 0)
145         qFatal("QQnxWindow: window destroyed before children!");
146
147     // Cleanup QNX window and its buffers
148     screen_destroy_window(m_window);
149 }
150
151 void QQnxWindow::setGeometry(const QRect &rect)
152 {
153 #if defined(QQNXWINDOW_DEBUG)
154     qDebug() << Q_FUNC_INFO << "window =" << window() << ", (" << rect.x() << "," << rect.y() << "," << rect.width() << "," << rect.height() << ")";
155 #endif
156
157     QRect oldGeometry = geometry();
158
159     // Call base class method
160     QPlatformWindow::setGeometry(rect);
161
162     // Set window geometry equal to widget geometry
163     errno = 0;
164     int val[2];
165     val[0] = rect.x();
166     val[1] = rect.y();
167     int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, val);
168     if (result != 0) {
169         qFatal("QQnxWindow: failed to set window position, errno=%d", errno);
170     }
171
172     errno = 0;
173     val[0] = rect.width();
174     val[1] = rect.height();
175     result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SIZE, val);
176     if (result != 0) {
177         qFatal("QQnxWindow: failed to set window size, errno=%d", errno);
178     }
179
180     // Set viewport size equal to window size
181     errno = 0;
182     result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_SOURCE_SIZE, val);
183     if (result != 0) {
184         qFatal("QQnxWindow: failed to set window source size, errno=%d", errno);
185     }
186
187     // Now move all children.
188     QPoint offset;
189     if (!oldGeometry.isEmpty()) {
190         offset = rect.topLeft();
191         offset -= oldGeometry.topLeft();
192
193         QList<QQnxWindow*>::iterator it;
194         for (it = m_childWindows.begin(); it != m_childWindows.end(); it++) {
195             (*it)->setOffset(offset);
196         }
197     }
198 }
199
200 void QQnxWindow::setOffset(const QPoint &offset)
201 {
202 #if defined(QQNXWINDOW_DEBUG)
203     qDebug() << Q_FUNC_INFO << "window =" << window();
204 #endif
205     // Move self and then children.
206     QRect newGeometry = geometry();
207     newGeometry.translate(offset);
208
209     // Call the base class
210     QPlatformWindow::setGeometry(newGeometry);
211
212     int val[2];
213
214     errno = 0;
215     val[0] = newGeometry.x();
216     val[1] = newGeometry.y();
217     int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_POSITION, val);
218     if (result != 0) {
219         qFatal("QQnxWindow: failed to set window position, errno=%d", errno);
220     }
221
222     QList<QQnxWindow*>::iterator it;
223     for (it = m_childWindows.begin(); it != m_childWindows.end(); it++) {
224         (*it)->setOffset(offset);
225     }
226 }
227
228 void QQnxWindow::setVisible(bool visible)
229 {
230 #if defined(QQNXWINDOW_DEBUG)
231     qDebug() << Q_FUNC_INFO << "window =" << window() << "visible =" << visible;
232 #endif
233
234     m_visible = visible;
235
236     QQnxWindow *root = this;
237     while (root->m_parentWindow)
238         root = root->m_parentWindow;
239
240     root->updateVisibility(root->m_visible);
241
242     window()->requestActivateWindow();
243 }
244
245 void QQnxWindow::updateVisibility(bool parentVisible)
246 {
247 #if defined(QQNXWINDOW_DEBUG)
248     qDebug() << Q_FUNC_INFO << "parentVisible =" << parentVisible << "window =" << window();
249 #endif
250     // Set window visibility
251     errno = 0;
252     int val = (m_visible && parentVisible) ? 1 : 0;
253     int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &val);
254     if (result != 0) {
255         qFatal("QQnxWindow: failed to set window visibility, errno=%d", errno);
256     }
257
258     QList<QQnxWindow *>::iterator it;
259     for (it = m_childWindows.begin(); it != m_childWindows.end(); it++) {
260         (*it)->updateVisibility(m_visible && parentVisible);
261     }
262 }
263
264 void QQnxWindow::setOpacity(qreal level)
265 {
266 #if defined(QQNXWINDOW_DEBUG)
267     qDebug() << Q_FUNC_INFO << "window =" << window() << "opacity =" << level;
268 #endif
269     // Set window global alpha
270     errno = 0;
271     int val = (int)(level * 255);
272     int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_GLOBAL_ALPHA, &val);
273     if (result != 0) {
274         qFatal("QQnxWindow: failed to set window global alpha, errno=%d", errno);
275     }
276
277     // TODO: How to handle children of this window? If we change all the visibilities, then
278     //       the transparency will look wrong...
279 }
280
281 void QQnxWindow::setBufferSize(const QSize &size)
282 {
283 #if defined(QQNXWINDOW_DEBUG)
284     qDebug() << Q_FUNC_INFO << "window =" << window() << "size =" << size;
285 #endif
286     // Set window buffer size
287     errno = 0;
288     int val[2] = { size.width(), size.height() };
289     int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_BUFFER_SIZE, val);
290     if (result != 0) {
291         qFatal("QQnxWindow: failed to set window buffer size, errno=%d", errno);
292     }
293
294     // Create window buffers if they do not exist
295     if (!hasBuffers()) {
296         // Get pixel format from EGL config if using OpenGL;
297         // otherwise inherit pixel format of window's screen
298         if (m_platformOpenGLContext != 0) {
299             val[0] = platformWindowFormatToNativeFormat(m_platformOpenGLContext->format());
300         } else {
301             val[0] = m_screen->nativeFormat();
302         }
303
304         errno = 0;
305         result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_FORMAT, val);
306         if (result != 0) {
307             qFatal("QQnxWindow: failed to set window pixel format, errno=%d", errno);
308         }
309
310         errno = 0;
311         result = screen_create_window_buffers(m_window, MAX_BUFFER_COUNT);
312         if (result != 0) {
313             qFatal("QQnxWindow: failed to create window buffers, errno=%d", errno);
314         }
315     }
316
317     // Cache new buffer size
318     m_bufferSize = size;
319
320     // Buffers were destroyed; reacquire them
321     m_currentBufferIndex = -1;
322     m_previousDirty = QRegion();
323     m_scrolled = QRegion();
324 }
325
326 QQnxBuffer &QQnxWindow::renderBuffer()
327 {
328 #if defined(QQNXWINDOW_DEBUG)
329     qDebug() << Q_FUNC_INFO << "window =" << window();
330 #endif
331     // Check if render buffer is invalid
332     if (m_currentBufferIndex == -1) {
333         // Get all buffers available for rendering
334         errno = 0;
335         screen_buffer_t buffers[MAX_BUFFER_COUNT];
336         int result = screen_get_window_property_pv(m_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)buffers);
337         if (result != 0) {
338             qFatal("QQnxWindow: failed to query window buffers, errno=%d", errno);
339         }
340
341         // Wrap each buffer
342         for (int i = 0; i < MAX_BUFFER_COUNT; ++i) {
343             m_buffers[i] = QQnxBuffer(buffers[i]);
344         }
345
346         // Use the first available render buffer
347         m_currentBufferIndex = 0;
348         m_previousBufferIndex = -1;
349     }
350
351     return m_buffers[m_currentBufferIndex];
352 }
353
354 void QQnxWindow::scroll(const QRegion &region, int dx, int dy, bool flush)
355 {
356 #if defined(QQNXWINDOW_DEBUG)
357     qDebug() << Q_FUNC_INFO << "window =" << window();
358 #endif
359     copyBack(region, dx, dy, flush);
360     m_scrolled += region;
361 }
362
363 void QQnxWindow::post(const QRegion &dirty)
364 {
365     // Check if render buffer exists and something was rendered
366     if (m_currentBufferIndex != -1 && !dirty.isEmpty()) {
367 #if defined(QQNXWINDOW_DEBUG)
368         qDebug() << "QQnxWindow::post - window =" << window();
369 #endif
370         QQnxBuffer &currentBuffer = m_buffers[m_currentBufferIndex];
371
372         // Copy unmodified region from old render buffer to new render buffer;
373         // required to allow partial updates
374         QRegion preserve = m_previousDirty - dirty - m_scrolled;
375         copyBack(preserve, 0, 0);
376
377         // Calculate region that changed
378         QRegion modified = preserve + dirty + m_scrolled;
379         QRect rect = modified.boundingRect();
380         int dirtyRect[4] = { rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height() };
381
382         // Update the display with contents of render buffer
383         errno = 0;
384         int result = screen_post_window(m_window, currentBuffer.nativeBuffer(), 1, dirtyRect, 0);
385         if (result != 0) {
386             qFatal("QQnxWindow: failed to post window buffer, errno=%d", errno);
387         }
388
389         // Advance to next nender buffer
390         m_previousBufferIndex = m_currentBufferIndex++;
391         if (m_currentBufferIndex >= MAX_BUFFER_COUNT) {
392             m_currentBufferIndex = 0;
393         }
394
395         // Save modified region and clear scrolled region
396         m_previousDirty = dirty;
397         m_scrolled = QRegion();
398
399         // Notify screen that window posted
400         if (m_screen != 0) {
401             m_screen->onWindowPost(this);
402         }
403     }
404 }
405
406 void QQnxWindow::setScreen(QQnxScreen *platformScreen)
407 {
408 #if defined(QQNXWINDOW_DEBUG)
409     qDebug() << Q_FUNC_INFO << "window =" << window() << "platformScreen =" << platformScreen;
410 #endif
411
412     if (m_screen == platformScreen)
413         return;
414
415     if (m_screen)
416         m_screen->removeWindow(this);
417     platformScreen->addWindow(this);
418     m_screen = platformScreen;
419
420     // Move window to proper screen/display
421     errno = 0;
422     screen_display_t display = platformScreen->nativeDisplay();
423     int result = screen_set_window_property_pv(m_window, SCREEN_PROPERTY_DISPLAY, (void **)&display);
424     if (result != 0) {
425         qFatal("QQnxWindow: failed to set window display, errno=%d", errno);
426     }
427
428     // Add window to display's window group
429     errno = 0;
430     result = screen_join_window_group(m_window, platformScreen->windowGroupName());
431     if (result != 0) {
432         qFatal("QQnxWindow: failed to join window group, errno=%d", errno);
433     }
434
435     QList<QQnxWindow*>::iterator it;
436     for (it = m_childWindows.begin(); it != m_childWindows.end(); it++) {
437         // Only subwindows and tooltips need necessarily be moved to another display with the window.
438         if ((window()->windowType() & Qt::WindowType_Mask) == Qt::SubWindow ||
439             (window()->windowType() & Qt::WindowType_Mask) == Qt::ToolTip)
440             (*it)->setScreen(platformScreen);
441     }
442
443     m_screen->updateHierarchy();
444 }
445
446 void QQnxWindow::removeFromParent()
447 {
448 #if defined(QQNXWINDOW_DEBUG)
449     qDebug() << Q_FUNC_INFO << "window =" << window();
450 #endif
451     // Remove from old Hierarchy position
452     if (m_parentWindow) {
453         if (m_parentWindow->m_childWindows.removeAll(this))
454             m_parentWindow = 0;
455         else
456             qFatal("QQnxWindow: Window Hierarchy broken; window has parent, but parent hasn't got child.");
457     } else {
458         m_screen->removeWindow(this);
459     }
460 }
461
462 void QQnxWindow::setParent(const QPlatformWindow *window)
463 {
464 #if defined(QQNXWINDOW_DEBUG)
465     qDebug() << Q_FUNC_INFO << "window =" << this->window() << "platformWindow =" << window;
466 #endif
467     // Cast away the const, we need to modify the hierarchy.
468     QQnxWindow *newParent = 0;
469
470     if (window)
471         newParent = static_cast<QQnxWindow*>((QPlatformWindow *)window);
472
473     if (newParent == m_parentWindow)
474         return;
475
476     removeFromParent();
477     m_parentWindow = newParent;
478
479     // Add to new hierarchy position.
480     if (m_parentWindow) {
481         if (m_parentWindow->m_screen != m_screen)
482             setScreen(m_parentWindow->m_screen);
483
484         m_parentWindow->m_childWindows.push_back(this);
485     } else {
486         m_screen->addWindow(this);
487     }
488
489     m_screen->updateHierarchy();
490 }
491
492 void QQnxWindow::raise()
493 {
494 #if defined(QQNXWINDOW_DEBUG)
495     qDebug() << Q_FUNC_INFO << "window =" << window();
496 #endif
497
498     QQnxWindow *oldParent = m_parentWindow;
499     if (oldParent) {
500         removeFromParent();
501         oldParent->m_childWindows.push_back(this);
502     } else {
503         m_screen->raiseWindow(this);
504     }
505
506     m_screen->updateHierarchy();
507 }
508
509 void QQnxWindow::lower()
510 {
511 #if defined(QQNXWINDOW_DEBUG)
512     qDebug() << Q_FUNC_INFO << "window =" << window();
513 #endif
514
515     QQnxWindow *oldParent = m_parentWindow;
516     if (oldParent) {
517         removeFromParent();
518         oldParent->m_childWindows.push_front(this);
519     } else {
520         m_screen->lowerWindow(this);
521     }
522
523     m_screen->updateHierarchy();
524 }
525
526 void QQnxWindow::requestActivateWindow()
527 {
528 #if defined(QQNXWINDOW_DEBUG)
529     qDebug() << Q_FUNC_INFO << "window =" << window();
530 #endif
531
532     // TODO: Tell screen to set keyboard focus to this window.
533
534     // Notify that we gained focus.
535     gainedFocus();
536 }
537
538 void QQnxWindow::gainedFocus()
539 {
540 #if defined(QQNXWINDOW_DEBUG)
541     qDebug() << Q_FUNC_INFO << "window =" << window();
542 #endif
543
544     // Got focus
545     QWindowSystemInterface::handleWindowActivated(window());
546 }
547
548 void QQnxWindow::setPlatformOpenGLContext(QQnxGLContext *platformOpenGLContext)
549 {
550     // This function does not take ownership of the platform gl context.
551     // It is owned by the frontend QOpenGLContext
552     m_platformOpenGLContext = platformOpenGLContext;
553 }
554
555 QQnxWindow *QQnxWindow::findWindow(screen_window_t windowHandle)
556 {
557     if (m_window == windowHandle)
558         return this;
559
560     Q_FOREACH (QQnxWindow *window, m_childWindows) {
561         QQnxWindow * const result = window->findWindow(windowHandle);
562         if (result)
563             return result;
564     }
565
566     return 0;
567 }
568
569 void QQnxWindow::updateZorder(int &topZorder)
570 {
571     errno = 0;
572     int result = screen_set_window_property_iv(m_window, SCREEN_PROPERTY_ZORDER, &topZorder);
573     topZorder++;
574
575     if (result != 0)
576         qFatal("QQnxWindow: failed to set window z-order=%d, errno=%d, mWindow=%p", topZorder, errno, m_window);
577
578     QList<QQnxWindow*>::const_iterator it;
579
580     for (it = m_childWindows.begin(); it != m_childWindows.end(); it++)
581         (*it)->updateZorder(topZorder);
582 }
583
584 void QQnxWindow::copyBack(const QRegion &region, int dx, int dy, bool flush)
585 {
586 #if defined(QQNXWINDOW_DEBUG)
587     qDebug() << Q_FUNC_INFO << "window =" << window();
588 #endif
589     int result;
590
591     // Abort if previous buffer is invalid
592     if (m_previousBufferIndex == -1) {
593         return;
594     }
595
596     // Abort if nothing to copy
597     if (region.isEmpty()) {
598         return;
599     }
600
601     QQnxBuffer &currentBuffer = m_buffers[m_currentBufferIndex];
602     QQnxBuffer &previousBuffer = m_buffers[m_previousBufferIndex];
603
604     // Break down region into non-overlapping rectangles
605     QVector<QRect> rects = region.rects();
606     for (int i = rects.size() - 1; i >= 0; i--) {
607         // Clip rectangle to bounds of target
608         QRect rect = rects[i].intersected( currentBuffer.rect() );
609
610         if (rect.isEmpty())
611             continue;
612
613         // Setup blit operation
614         int attribs[] = { SCREEN_BLIT_SOURCE_X, rect.x(),
615                           SCREEN_BLIT_SOURCE_Y, rect.y(),
616                           SCREEN_BLIT_SOURCE_WIDTH, rect.width(),
617                           SCREEN_BLIT_SOURCE_HEIGHT, rect.height(),
618                           SCREEN_BLIT_DESTINATION_X, rect.x() + dx,
619                           SCREEN_BLIT_DESTINATION_Y, rect.y() + dy,
620                           SCREEN_BLIT_DESTINATION_WIDTH, rect.width(),
621                           SCREEN_BLIT_DESTINATION_HEIGHT, rect.height(),
622                           SCREEN_BLIT_END };
623
624         // Queue blit operation
625         errno = 0;
626         result = screen_blit(m_screenContext, currentBuffer.nativeBuffer(), previousBuffer.nativeBuffer(), attribs);
627         if (result != 0) {
628             qFatal("QQnxWindow: failed to blit buffers, errno=%d", errno);
629         }
630     }
631
632     // Check if flush requested
633     if (flush) {
634         // Wait for all blits to complete
635         errno = 0;
636         result = screen_flush_blits(m_screenContext, SCREEN_WAIT_IDLE);
637         if (result != 0) {
638             qFatal("QQnxWindow: failed to flush blits, errno=%d", errno);
639         }
640
641         // Buffer was modified outside the CPU
642         currentBuffer.invalidateInCache();
643     }
644 }
645
646 int QQnxWindow::platformWindowFormatToNativeFormat(const QSurfaceFormat &format)
647 {
648 #if defined(QQNXWINDOW_DEBUG)
649     qDebug() << Q_FUNC_INFO;
650 #endif
651     // Extract size of colour channels from window format
652     int redSize = format.redBufferSize();
653     if (redSize == -1) {
654         qFatal("QQnxWindow: red size not defined");
655     }
656
657     int greenSize = format.greenBufferSize();
658     if (greenSize == -1) {
659         qFatal("QQnxWindow: green size not defined");
660     }
661
662     int blueSize = format.blueBufferSize();
663     if (blueSize == -1) {
664         qFatal("QQnxWindow: blue size not defined");
665     }
666
667     // select matching native format
668     if (redSize == 5 && greenSize == 6 && blueSize == 5) {
669         return SCREEN_FORMAT_RGB565;
670     } else if (redSize == 8 && greenSize == 8 && blueSize == 8) {
671         return SCREEN_FORMAT_RGBA8888;
672     } else {
673         qFatal("QQnxWindow: unsupported pixel format");
674         return 0;
675     }
676 }
677
678 QT_END_NAMESPACE