os/graphics/graphicsdeviceinterface/screendriver/swins/AccelBitmap.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "GraphicsAccelerator.h"
sl@0
    17
sl@0
    18
// Windows headers...
sl@0
    19
#define UNICODE
sl@0
    20
#pragma warning( disable : 4201 )
sl@0
    21
#define WIN32_LEAN_AND_MEAN
sl@0
    22
#define NOSERVICE
sl@0
    23
#include <windows.h>
sl@0
    24
#include <windowsx.h>
sl@0
    25
#pragma warning( default : 4201 )
sl@0
    26
sl@0
    27
#include <bitdraw.h>
sl@0
    28
#include "_WININC.H"
sl@0
    29
sl@0
    30
/** Fills a structure with data which describes the basic details of this bitmap.
sl@0
    31
sl@0
    32
@param aInfo Bitmap information structure to fill with the details of this bitmap.
sl@0
    33
@return KErrNone if successful, KErrBadHandle if a value has not been assigned to iHandle. */
sl@0
    34
EXPORT_C TInt RHardwareBitmap::GetInfo(TAcceleratedBitmapInfo& aInfo) const
sl@0
    35
	{
sl@0
    36
	if(!iHandle)
sl@0
    37
		return(KErrBadHandle);
sl@0
    38
sl@0
    39
	// -1 or less refers to the screen. It is the (screen number + 1) actually with "-" sign.
sl@0
    40
	if(iHandle <= -1)
sl@0
    41
		{
sl@0
    42
        RWindows* window = ::WindowHandler(-iHandle - 1);
sl@0
    43
		aInfo.iDisplayMode = window->iDisplayMode;
sl@0
    44
		aInfo.iAddress = (TUint8*)(window->EpocBitmapBits());
sl@0
    45
		aInfo.iSize = window->iEpocBitmapSize;
sl@0
    46
		aInfo.iLinePitch = window->iEpocBitmapLinePitch;
sl@0
    47
		aInfo.iPhysicalAddress = 0;
sl@0
    48
		switch(aInfo.iDisplayMode)
sl@0
    49
			{
sl@0
    50
			case ENone:
sl@0
    51
				aInfo.iPixelShift = -1;
sl@0
    52
				break;
sl@0
    53
			case EGray2:
sl@0
    54
				aInfo.iPixelShift = 0;
sl@0
    55
				break;
sl@0
    56
			case EGray4:
sl@0
    57
				aInfo.iPixelShift = 1;
sl@0
    58
				break;
sl@0
    59
			case EGray16:
sl@0
    60
			case EColor16:
sl@0
    61
				aInfo.iPixelShift = 2;
sl@0
    62
				break;
sl@0
    63
			case EGray256:
sl@0
    64
			case EColor256:
sl@0
    65
				aInfo.iPixelShift = 3;
sl@0
    66
				break;
sl@0
    67
			case EColor4K:
sl@0
    68
			case EColor64K:
sl@0
    69
				aInfo.iPixelShift = 4;
sl@0
    70
				break;
sl@0
    71
			case EColor16M:
sl@0
    72
			case ERgb:
sl@0
    73
			case EColor16MU:
sl@0
    74
				aInfo.iPixelShift = 5;
sl@0
    75
				break;
sl@0
    76
			}
sl@0
    77
		}
sl@0
    78
	else
sl@0
    79
		aInfo = *(TAcceleratedBitmapInfo*)iHandle;	// iHandle is really a pointer to a TAcceleratedBitmapInfo
sl@0
    80
sl@0
    81
	return(KErrNone);
sl@0
    82
	}
sl@0
    83
sl@0
    84
/**
sl@0
    85
This method sets the value of iHandle data member.
sl@0
    86
When the iHandle's value is positive - the it is the bitmap address in the memory.
sl@0
    87
When the iHandle's value is negative - it is a screen number reference:
sl@0
    88
 "-1" - screen 0, "-2" - screen 1, "-3" - screen 2, ...
sl@0
    89
All that means: negative iHandle values describe the RHardwareBitmap object as a screen
sl@0
    90
bitmap, the screen number can be calculated from iHandle's value. 
sl@0
    91
Positive iHandle values describe RHardwareBitmap object as an in-memory bitmap.
sl@0
    92
By default iHandle is initialized with 0, which means - invalid handle and uninitialized
sl@0
    93
RHardwareBitmap object.
sl@0
    94
@param aScreenNo Screen number.
sl@0
    95
@return KErrNone
sl@0
    96
*/
sl@0
    97
EXPORT_C TInt RHardwareBitmap::SetAsScreenReference(TInt aScreenNo)
sl@0
    98
	{
sl@0
    99
	iHandle = aScreenNo;
sl@0
   100
	return KErrNone;
sl@0
   101
	}
sl@0
   102
sl@0
   103
EXPORT_C TInt RHardwareBitmap::Create(TDisplayMode aDisplayMode, TSize aSize, TUid /*aCreatorUid*/)
sl@0
   104
	{
sl@0
   105
	// Make line pitch different from normal bitmaps, useful for testing purposes.
sl@0
   106
	TInt hwWidth = ((aSize.iWidth + 15) / 16) * 16;
sl@0
   107
sl@0
   108
	TInt linePitch;
sl@0
   109
sl@0
   110
	switch(aDisplayMode)
sl@0
   111
		{
sl@0
   112
		case EColor256:
sl@0
   113
		case EGray256:
sl@0
   114
			linePitch = hwWidth;
sl@0
   115
			break;
sl@0
   116
		case EColor64K:
sl@0
   117
		case EColor4K:
sl@0
   118
			linePitch = hwWidth * 2;
sl@0
   119
			break;
sl@0
   120
		case EColor16M:
sl@0
   121
			linePitch = (((hwWidth * 3) + 11) / 12) * 12; // Multiples of 12 bytes!
sl@0
   122
			break;
sl@0
   123
		case ERgb:
sl@0
   124
		case EColor16MU:
sl@0
   125
			linePitch = hwWidth * 4;
sl@0
   126
			break;
sl@0
   127
		default:
sl@0
   128
			return(KErrNotSupported);
sl@0
   129
		}
sl@0
   130
sl@0
   131
	TInt memSize = sizeof(TAcceleratedBitmapInfo)+linePitch*aSize.iHeight;
sl@0
   132
sl@0
   133
	TAcceleratedBitmapInfo* bitmap = (TAcceleratedBitmapInfo*)GlobalAllocPtr(GMEM_FIXED,memSize);
sl@0
   134
sl@0
   135
	if(!bitmap)
sl@0
   136
		return(KErrNoMemory);
sl@0
   137
sl@0
   138
	bitmap->iDisplayMode = aDisplayMode;
sl@0
   139
	bitmap->iAddress = (TUint8*)(bitmap+1);
sl@0
   140
	bitmap->iSize = aSize;
sl@0
   141
	bitmap->iLinePitch = linePitch;
sl@0
   142
	switch(aDisplayMode)
sl@0
   143
		{
sl@0
   144
		case ENone:
sl@0
   145
			bitmap->iPixelShift = -1;
sl@0
   146
			break;
sl@0
   147
		case EGray2:
sl@0
   148
			bitmap->iPixelShift = 0;
sl@0
   149
			break;
sl@0
   150
		case EGray4:
sl@0
   151
			bitmap->iPixelShift = 1;
sl@0
   152
			break;
sl@0
   153
		case EGray16:
sl@0
   154
		case EColor16:
sl@0
   155
			bitmap->iPixelShift = 2;
sl@0
   156
			break;
sl@0
   157
		case EGray256:
sl@0
   158
		case EColor256:
sl@0
   159
			bitmap->iPixelShift = 3;
sl@0
   160
			break;
sl@0
   161
		case EColor4K:
sl@0
   162
		case EColor64K:
sl@0
   163
			bitmap->iPixelShift = 4;
sl@0
   164
			break;
sl@0
   165
		case EColor16M:
sl@0
   166
		case ERgb:
sl@0
   167
		case EColor16MU:
sl@0
   168
			bitmap->iPixelShift = 5;
sl@0
   169
			break;
sl@0
   170
		}
sl@0
   171
	bitmap->iPhysicalAddress = 0;
sl@0
   172
sl@0
   173
	iHandle = (TInt)bitmap;
sl@0
   174
sl@0
   175
	return(KErrNone);
sl@0
   176
	}
sl@0
   177
sl@0
   178
EXPORT_C void RHardwareBitmap::Destroy()
sl@0
   179
	{
sl@0
   180
	GlobalFreePtr((void*)iHandle);
sl@0
   181
	}
sl@0
   182