📄 sdl_epocvideo.cpp
字号:
#endif // Draw black background Mem::FillZ(screenBuffer, Private->EPOC_BytesPerScreen);#if 0 for (int y = 0; y < Private->EPOC_ScreenSize.iHeight; y++) { for (int x = 0; x < Private->EPOC_ScreenSize.iWidth; x++) {#ifdef SYMBIAN_CRYSTAL const TUint16 color = 0; // ((x+y)>>1) & 0xf; /* Draw blue stripes pattern, because in e.g. 320x200 mode there is a big background area*/#else // SYMBIAN_SERIES60 const TUint16 color = 0; /* Draw black background */#endif *screenBuffer++ = color; } }#endif}/* We don't actually allow hardware surfaces other than the main one */static int EPOC_AllocHWSurface(_THIS, SDL_Surface* /*surface*/){ return(-1);}static void EPOC_FreeHWSurface(_THIS, SDL_Surface* /*surface*/){ return;}static int EPOC_LockHWSurface(_THIS, SDL_Surface* /*surface*/){ return(0);}static void EPOC_UnlockHWSurface(_THIS, SDL_Surface* /*surface*/){ return;}static int EPOC_FlipHWSurface(_THIS, SDL_Surface* /*surface*/){ return(0);}static void EPOC_DirectUpdate(_THIS, int numrects, SDL_Rect *rects){ //TInt focusWindowGroupId = Private->EPOC_WsSession.GetFocusWindowGroup();//these are async services // if (focusWindowGroupId != Private->EPOC_WsWindowGroupID) { //for that cannot be called from //SDL threads ??? if (!Private->EPOC_IsWindowFocused) { /* Force focus window to redraw again for cleaning away SDL screen graphics *//* TInt pos = Private->EPOC_WsWindowGroup.OrdinalPosition(); Private->EPOC_WsWindowGroup.SetOrdinalPosition(0, KMaxTInt); TRect rect = TRect(Private->EPOC_WsWindow.Size()); Private->EPOC_WsWindow.Invalidate(rect); Private->EPOC_WsWindowGroup.SetOrdinalPosition(pos, ECoeWinPriorityNormal); */ /* If this is not the topmost window, wait here! Sleep for 1 second to give cpu time to multitasking and poll for being the topmost window. */ // if (Private->EPOC_WsSession.GetFocusWindowGroup() != Private->EPOC_WsWindowGroupID) { /* !!TODO: Could call GetRedraw() etc. for WsSession and redraw the screen if needed. That might be needed if a small dialog comes in front of Game screen. */ // while (Private->EPOC_WsSession.GetFocusWindowGroup() != Private->EPOC_WsWindowGroupID) SDL_PauseAudio(1); SDL_Delay(1000); return; // } // RedrawWindowL(_this); } SDL_PauseAudio(0); // if we are not focused, do not draw// if (!Private->EPOC_IsWindowFocused)// return;#if defined(__WINS__) || defined(TEST_BM_DRAW) TBitmapUtil lock(Private->EPOC_Bitmap); lock.Begin(TPoint(0,0)); // Lock bitmap heap Private->EPOC_WindowGc->Activate(Private->EPOC_WsWindow); TUint16* screenBuffer = (TUint16*)Private->EPOC_Bitmap->DataAddress();#else TUint16* screenBuffer = (TUint16*)Private->EPOC_FrameBuffer;#endif if (Private->EPOC_ScreenOrientation == CFbsBitGc::EGraphicsOrientationRotated270) DirectDrawRotated(_this, numrects, rects, screenBuffer); else DirectDraw(_this, numrects, rects, screenBuffer); #if defined(__WINS__) || defined(TEST_BM_DRAW) TRect rect = TRect(Private->EPOC_WsWindow.Size()); Private->EPOC_WsWindow.Invalidate(rect); Private->EPOC_WsWindow.BeginRedraw(rect); Private->EPOC_WindowGc->BitBlt(TPoint(), Private->EPOC_Bitmap); Private->EPOC_WsWindow.EndRedraw(); Private->EPOC_WindowGc->Deactivate(); lock.End(); // Unlock bitmap heap Private->EPOC_WsSession.Flush();#else#ifndef SYMBIAN_CRYSTAL // This is not needed in Crystal. What is the performance penalty in SERIES60? TRect rect2 = TRect(Private->EPOC_WsWindow.Size()); Private->EPOC_DrawDevice->UpdateRegion(rect2); // Should we update rects parameter area only?? Private->EPOC_DrawDevice->Update();#endif#endif /* Update virtual cursor. !!Do not yet work properly Private->EPOC_WsSession.SetPointerCursorPosition(Private->EPOC_WsSession.PointerCursorPosition()); */ /*static int foo = 1; for ( int i=0; i < numrects; ++i ) { const SDL_Rect& currentRect = rects[i]; SDL_Rect rect2; rect2.x = currentRect.x; rect2.y = currentRect.y; rect2.w = currentRect.w; rect2.h = currentRect.h; if (rect2.w <= 0 || rect2.h <= 0) continue; foo++; if((foo % 200) == 0) { SDL_TRACE1("foo %d", foo); CFbsBitmap* b = new (ELeave) CFbsBitmap; SDL_TRACE1("bee %d", (int)b); int e = b->Create(TSize(currentRect.w, currentRect.h), Private->EPOC_DisplayMode); SDL_TRACE1("err %d", e); if(e != KErrNone) User::Panic(_L("damn"), e); TBitmapUtil u(b); u.Begin(TPoint(0, 0)); TUint32* d = b->DataAddress(); SDL_TRACE1("addr %d", (int)d); for(TInt o = 0; o < currentRect.h; o++) for(TInt p = 0; p < currentRect.w; p++) { u.SetPos(TPoint(p, o)); u.SetPixel(0xFFFF); } SDL_TRACE1("w %d", (int)currentRect.w); SDL_TRACE1("h %d", (int)currentRect.h); SDL_TRACE1("addr %d", (int)Private->EPOC_DisplayMode); const TUint f = (TUint)Private->EPOC_FrameBuffer; const TUint y = (TUint)Private->EPOC_BytesPerScreen; SDL_TRACE1("frame %u", f); SDL_TRACE1("bytes %u", y); Mem::Copy(d, Private->EPOC_FrameBuffer, Private->EPOC_BytesPerScreen); SDL_TRACE("kopied"); u.End(); TBuf<32> name; name.Format(_L("C:\\nokia\\images\\doom%d.mbm"), (foo / 200)); e= b->Save(name); if(e != KErrNone) User::Panic(_L("damned"), e); delete b; }}*/}void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer){ TInt i; const TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1; const TPoint fixedOffset = Private->EPOC_ScreenOffset; const TInt screenW = _this->screen->w; const TInt screenH = _this->screen->h; const TInt sourceScanlineLength = screenW; const TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth; /* Render the rectangles in the list */ for ( i=0; i < numrects; ++i ) { const SDL_Rect& currentRect = rects[i]; SDL_Rect rect2; rect2.x = currentRect.x; rect2.y = currentRect.y; rect2.w = currentRect.w; rect2.h = currentRect.h; if (rect2.w <= 0 || rect2.h <= 0) /* sanity check */ continue; /* All variables are measured in pixels */ /* Check rects validity, i.e. upper and lower bounds */ TInt maxX = Min(screenW - 1, rect2.x + rect2.w - 1); TInt maxY = Min(screenH - 1, rect2.y + rect2.h - 1); if (maxX < 0 || maxY < 0) /* sanity check */ continue; /* Clip from bottom */ maxY = Min(maxY, Private->EPOC_ScreenSize.iHeight-1); /* TODO: Clip from the right side */ const TInt sourceRectWidth = maxX - rect2.x + 1; const TInt sourceRectWidthInBytes = sourceRectWidth * sourceNumBytesPerPixel; const TInt sourceRectHeight = maxY - rect2.y + 1; const TInt sourceStartOffset = rect2.x + rect2.y * sourceScanlineLength; const TUint skipValue = 1; // no skip TInt targetStartOffset = fixedOffset.iX + rect2.x + (fixedOffset.iY +rect2.y) * targetScanlineLength; // Nokia7650 native mode: 12 bpp --> 12 bpp // switch (_this->screen->format->BitsPerPixel) { case 12: { TUint16* bitmapLine = (TUint16*)_this->screen->pixels + sourceStartOffset; TUint16* screenMemory = screenBuffer + targetStartOffset; if (skipValue == 1) { for(TInt y = 0 ; y < sourceRectHeight ; y++) { Mem::Copy(screenMemory, bitmapLine, sourceRectWidthInBytes); } bitmapLine += sourceScanlineLength; screenMemory += targetScanlineLength; } else { for(TInt y = 0 ; y < sourceRectHeight ; y++) { //TODO: optimize: separate loops for 1, 2 and n skip. Mem::Copy() can be used in unscaled case. TUint16* bitmapPos = bitmapLine; /* 2 bytes per pixel */ TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */ for(TInt x = 0 ; x < sourceRectWidth ; x++) { __ASSERT_DEBUG(screenMemory < (screenBuffer + Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(screenMemory >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(bitmapLine < ((TUint16*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(bitmapLine >= (TUint16*)_this->screen->pixels, User::Panic(_L("SDL"), KErrCorrupt)); *screenMemoryLinePos++ = *bitmapPos; bitmapPos+=skipValue; } bitmapLine += sourceScanlineLength; screenMemory += targetScanlineLength; } } } break; // 256 color paletted mode: 8 bpp --> 12 bpp // default: { if(Private->EPOC_BytesPerPixel <= 2) { TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset; TUint16* screenMemory = screenBuffer + targetStartOffset; for(TInt y = 0 ; y < sourceRectHeight ; y++) { TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */ TUint16* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */ /* Convert each pixel from 256 palette to 4k color values */ for(TInt x = 0 ; x < sourceRectWidth ; x++) { __ASSERT_DEBUG(screenMemoryLinePos < (screenBuffer + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(screenMemoryLinePos >= screenBuffer, User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(_L("SDL"), KErrCorrupt)); *screenMemoryLinePos++ = EPOC_HWPalette_256_to_Screen[*bitmapPos++]; // bitmapPos+=skipValue; //TODO: optimize: separate loops for 1, 2 and n skip } bitmapLine += sourceScanlineLength; screenMemory += targetScanlineLength; } } else { TUint8* bitmapLine = (TUint8*)_this->screen->pixels + sourceStartOffset; TUint32* screenMemory = reinterpret_cast<TUint32*>(screenBuffer + targetStartOffset); for(TInt y = 0 ; y < sourceRectHeight ; y++) { TUint8* bitmapPos = bitmapLine; /* 1 byte per pixel */ TUint32* screenMemoryLinePos = screenMemory; /* 2 bytes per pixel */ /* Convert each pixel from 256 palette to 4k color values */ for(TInt x = 0 ; x < sourceRectWidth ; x++) { __ASSERT_DEBUG(screenMemoryLinePos < (reinterpret_cast<TUint32*>(screenBuffer) + (Private->EPOC_ScreenSize.iWidth * Private->EPOC_ScreenSize.iHeight)), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(screenMemoryLinePos >= reinterpret_cast<TUint32*>(screenBuffer), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(bitmapPos < ((TUint8*)_this->screen->pixels + (_this->screen->w * _this->screen->h)), User::Panic(_L("SDL"), KErrCorrupt)); __ASSERT_DEBUG(bitmapPos >= (TUint8*)_this->screen->pixels, User::Panic(_L("SDL"), KErrCorrupt)); *screenMemoryLinePos++ = EPOC_HWPalette_256_to_Screen[*bitmapPos++]; // bitmapPos+=skipValue; //TODO: optimize: separate loops for 1, 2 and n skip } bitmapLine += sourceScanlineLength; screenMemory += targetScanlineLength; } } } } // switch } // for}/*void DirectDraw(_THIS, int numrects, SDL_Rect *rects, TUint16* screenBuffer){ TInt i; const TInt sourceNumBytesPerPixel = ((_this->screen->format->BitsPerPixel-1)>>3) + 1; const TPoint fixedOffset = Private->EPOC_ScreenOffset; const TInt screenW = _this->screen->w; const TInt screenH = _this->screen->h; const TInt sourceScanlineLength = screenW; const TInt targetScanlineLength = Private->EPOC_ScreenSize.iWidth; /* Render the rectangles in the list *//* for ( i=0; i < numrects; ++i ) { const SDL_Rect& currentRect = rects[i]; SDL_Rect rect2; rect2.x = currentRect.x;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -