egl/eglinterface/src/eglwindowinterface.cpp
author hgs
Thu, 09 Sep 2010 10:13:45 +0300
changeset 171 414d4b727fd9
permissions -rw-r--r--
201034
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
171
hgs
parents:
diff changeset
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     2
// All rights reserved.
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
hgs
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     7
//
hgs
parents:
diff changeset
     8
// Initial Contributors:
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    10
//
hgs
parents:
diff changeset
    11
// Contributors:
hgs
parents:
diff changeset
    12
//
hgs
parents:
diff changeset
    13
// Description:
hgs
parents:
diff changeset
    14
//
hgs
parents:
diff changeset
    15
hgs
parents:
diff changeset
    16
hgs
parents:
diff changeset
    17
/**
hgs
parents:
diff changeset
    18
 @file
hgs
parents:
diff changeset
    19
 @publishedPartner
hgs
parents:
diff changeset
    20
 @prototype
hgs
parents:
diff changeset
    21
*/
hgs
parents:
diff changeset
    22
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
#include "eglwindowinterface.h"
hgs
parents:
diff changeset
    25
#include "eglwindow.h"
hgs
parents:
diff changeset
    26
#include <e32base.h>
hgs
parents:
diff changeset
    27
#include <w32std.h>
hgs
parents:
diff changeset
    28
#include <hal.h>
hgs
parents:
diff changeset
    29
hgs
parents:
diff changeset
    30
hgs
parents:
diff changeset
    31
EXPORT_C TEglWindowInterface::TEglWindowInterface(EGLNativeWindowType aNativeWindow) :
hgs
parents:
diff changeset
    32
    iEglWindow(reinterpret_cast<REglWindowBase*>(aNativeWindow))
hgs
parents:
diff changeset
    33
    {
hgs
parents:
diff changeset
    34
    }
hgs
parents:
diff changeset
    35
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
EXPORT_C TBool TEglWindowInterface::IsValid() const
hgs
parents:
diff changeset
    38
    {
hgs
parents:
diff changeset
    39
    if(iEglWindow->IsRWindow())
hgs
parents:
diff changeset
    40
        {
hgs
parents:
diff changeset
    41
        TInt wsHandle = reinterpret_cast<const RWindow*>(iEglWindow)->WsHandle();
hgs
parents:
diff changeset
    42
        return (wsHandle != 0);
hgs
parents:
diff changeset
    43
        }
hgs
parents:
diff changeset
    44
    else
hgs
parents:
diff changeset
    45
        {
hgs
parents:
diff changeset
    46
        return iEglWindow->IsValid();
hgs
parents:
diff changeset
    47
        }
hgs
parents:
diff changeset
    48
    }
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
hgs
parents:
diff changeset
    51
EXPORT_C TSize TEglWindowInterface::SizeInPixels() const
hgs
parents:
diff changeset
    52
    {
hgs
parents:
diff changeset
    53
    if(iEglWindow->IsRWindow())
hgs
parents:
diff changeset
    54
        {
hgs
parents:
diff changeset
    55
        return reinterpret_cast<const RWindow*>(iEglWindow)->Size();
hgs
parents:
diff changeset
    56
        }
hgs
parents:
diff changeset
    57
    else
hgs
parents:
diff changeset
    58
        {
hgs
parents:
diff changeset
    59
        return iEglWindow->SizeInPixels();
hgs
parents:
diff changeset
    60
        }
hgs
parents:
diff changeset
    61
    }
hgs
parents:
diff changeset
    62
hgs
parents:
diff changeset
    63
hgs
parents:
diff changeset
    64
EXPORT_C TSize TEglWindowInterface::SizeInTwips() const
hgs
parents:
diff changeset
    65
    {
hgs
parents:
diff changeset
    66
    if(iEglWindow->IsRWindow())
hgs
parents:
diff changeset
    67
        {
hgs
parents:
diff changeset
    68
        //This is a simple solution to get the twip size of an RWindow.
hgs
parents:
diff changeset
    69
        //A temporary CWsScreenDevice is constructed for the screen that
hgs
parents:
diff changeset
    70
        //the RWindow exists on and is used to convert the size in pixels
hgs
parents:
diff changeset
    71
        //to a size in twips. The temporary CWsScreenDevice is then destructed.
hgs
parents:
diff changeset
    72
        //If this is found to be non-performant, we could use a TLS thread 
hgs
parents:
diff changeset
    73
        //singleton that lazily creates screen devices and maintains a list
hgs
parents:
diff changeset
    74
        //thoughout its lifetime. The singleton could be destroyed though a
hgs
parents:
diff changeset
    75
        //static function on TEglWindowInterface as part of eglReleaseThread().
hgs
parents:
diff changeset
    76
        //This represents more complexity and should only be considered as an
hgs
parents:
diff changeset
    77
        //optimisation if it is found to be neccessary. Note that use of the HAL
hgs
parents:
diff changeset
    78
        //interface is not really an option, since we need to find the pixel 
hgs
parents:
diff changeset
    79
        //size of the screen and this could be virtualised by the screen.
hgs
parents:
diff changeset
    80
    
hgs
parents:
diff changeset
    81
        const RWindow* window = reinterpret_cast<const RWindow*>(iEglWindow);
hgs
parents:
diff changeset
    82
        RWsSession* winSession = window->Session();
hgs
parents:
diff changeset
    83
        EGL_WINDOW_ASSERT_DEBUG(winSession, EEglWindowPanicRWindowHasNoSession);
hgs
parents:
diff changeset
    84
        
hgs
parents:
diff changeset
    85
        //Do a placement new to avoid the possible KErrNoMemory error.
hgs
parents:
diff changeset
    86
        TUint8 screenDevMem[sizeof(CWsScreenDevice)];
hgs
parents:
diff changeset
    87
        CWsScreenDevice* screenDev = new (screenDevMem) CWsScreenDevice(*winSession);
hgs
parents:
diff changeset
    88
hgs
parents:
diff changeset
    89
        //Nothing we can do about this error.
hgs
parents:
diff changeset
    90
        TInt err = screenDev->Construct(window->ScreenNumber());
hgs
parents:
diff changeset
    91
        if(err != KErrNone)
hgs
parents:
diff changeset
    92
            {
hgs
parents:
diff changeset
    93
            screenDev->~CWsScreenDevice();
hgs
parents:
diff changeset
    94
            return TSize(0,0);
hgs
parents:
diff changeset
    95
            }
hgs
parents:
diff changeset
    96
        
hgs
parents:
diff changeset
    97
        TSize pixelSize = window->Size();
hgs
parents:
diff changeset
    98
        TInt twipWidth = screenDev->HorizontalPixelsToTwips(pixelSize.iWidth);
hgs
parents:
diff changeset
    99
        TInt twipHeight = screenDev->VerticalPixelsToTwips(pixelSize.iHeight);
hgs
parents:
diff changeset
   100
        TSize twipSize(twipWidth, twipHeight);
hgs
parents:
diff changeset
   101
        
hgs
parents:
diff changeset
   102
        screenDev->~CWsScreenDevice();
hgs
parents:
diff changeset
   103
        return twipSize;
hgs
parents:
diff changeset
   104
        }
hgs
parents:
diff changeset
   105
    else
hgs
parents:
diff changeset
   106
        {
hgs
parents:
diff changeset
   107
        return iEglWindow->SizeInTwips();
hgs
parents:
diff changeset
   108
        }
hgs
parents:
diff changeset
   109
    }
hgs
parents:
diff changeset
   110
hgs
parents:
diff changeset
   111
hgs
parents:
diff changeset
   112
EXPORT_C TInt TEglWindowInterface::ScreenNumber() const
hgs
parents:
diff changeset
   113
    {
hgs
parents:
diff changeset
   114
    if(iEglWindow->IsRWindow())
hgs
parents:
diff changeset
   115
        {
hgs
parents:
diff changeset
   116
        return reinterpret_cast<const RWindow*>(iEglWindow)->ScreenNumber();
hgs
parents:
diff changeset
   117
        }
hgs
parents:
diff changeset
   118
    else
hgs
parents:
diff changeset
   119
        {
hgs
parents:
diff changeset
   120
        return iEglWindow->ScreenNumber();
hgs
parents:
diff changeset
   121
        }
hgs
parents:
diff changeset
   122
    }
hgs
parents:
diff changeset
   123
hgs
parents:
diff changeset
   124
hgs
parents:
diff changeset
   125
EXPORT_C void TEglWindowInterface::SetBackgroundColor(TRgb aColor, TBool aTriggerRedraw)
hgs
parents:
diff changeset
   126
    {
hgs
parents:
diff changeset
   127
    if(iEglWindow->IsRWindow())
hgs
parents:
diff changeset
   128
        {
hgs
parents:
diff changeset
   129
        RWindow* window = reinterpret_cast<RWindow*>(iEglWindow);
hgs
parents:
diff changeset
   130
        window->SetBackgroundColor(aColor);
hgs
parents:
diff changeset
   131
        if(aTriggerRedraw)
hgs
parents:
diff changeset
   132
            {
hgs
parents:
diff changeset
   133
            window->Invalidate();
hgs
parents:
diff changeset
   134
            }
hgs
parents:
diff changeset
   135
        }
hgs
parents:
diff changeset
   136
    else
hgs
parents:
diff changeset
   137
        {
hgs
parents:
diff changeset
   138
        iEglWindow->SetBackgroundColor(aColor, aTriggerRedraw);
hgs
parents:
diff changeset
   139
        }
hgs
parents:
diff changeset
   140
    }
hgs
parents:
diff changeset
   141
hgs
parents:
diff changeset
   142
hgs
parents:
diff changeset
   143
EXPORT_C TInt TEglWindowInterface::SetBackgroundSurface(const TSurfaceConfiguration &aConfiguration, TBool aTriggerRedraw)
hgs
parents:
diff changeset
   144
    {
hgs
parents:
diff changeset
   145
    if(iEglWindow->IsRWindow())
hgs
parents:
diff changeset
   146
        {
hgs
parents:
diff changeset
   147
#ifdef _DEBUG
hgs
parents:
diff changeset
   148
        TSurfaceId surface;
hgs
parents:
diff changeset
   149
        aConfiguration.GetSurfaceId(surface);
hgs
parents:
diff changeset
   150
        EGL_WINDOW_ASSERT_DEBUG(!surface.IsNull(), EEglWindowPanicInvalidSurface);
hgs
parents:
diff changeset
   151
#endif
hgs
parents:
diff changeset
   152
        return reinterpret_cast<RWindow*>(iEglWindow)->SetBackgroundSurface(aConfiguration, aTriggerRedraw);
hgs
parents:
diff changeset
   153
        }
hgs
parents:
diff changeset
   154
    else
hgs
parents:
diff changeset
   155
        {
hgs
parents:
diff changeset
   156
        return iEglWindow->SetBackgroundSurface(aConfiguration, aTriggerRedraw);
hgs
parents:
diff changeset
   157
        }
hgs
parents:
diff changeset
   158
    }
hgs
parents:
diff changeset
   159
hgs
parents:
diff changeset
   160
hgs
parents:
diff changeset
   161
EXPORT_C void TEglWindowInterface::RemoveBackgroundSurface(TBool aTriggerRedraw)
hgs
parents:
diff changeset
   162
    {
hgs
parents:
diff changeset
   163
    if(iEglWindow->IsRWindow())
hgs
parents:
diff changeset
   164
        {
hgs
parents:
diff changeset
   165
        RWindow* window = reinterpret_cast<RWindow*>(iEglWindow);
hgs
parents:
diff changeset
   166
        RWsSession* winSession = window->Session();
hgs
parents:
diff changeset
   167
        EGL_WINDOW_ASSERT_DEBUG(winSession, EEglWindowPanicRWindowHasNoSession);    
hgs
parents:
diff changeset
   168
        window->RemoveBackgroundSurface(aTriggerRedraw);
hgs
parents:
diff changeset
   169
        }
hgs
parents:
diff changeset
   170
    else
hgs
parents:
diff changeset
   171
        {
hgs
parents:
diff changeset
   172
        iEglWindow->RemoveBackgroundSurface(aTriggerRedraw);
hgs
parents:
diff changeset
   173
        }
hgs
parents:
diff changeset
   174
    }