void gfxContext::PushGroupAndCopyBackground(gfxASurface::gfxContentType content) { if (content == gfxASurface::CONTENT_COLOR_ALPHA && !(GetFlags() & FLAG_DISABLE_COPY_BACKGROUND)) { nsRefPtr<gfxASurface> s = CurrentSurface(); if ((s->GetAllowUseAsSource() || s->GetType() == gfxASurface::SurfaceTypeTee) && (s->GetContentType() == gfxASurface::CONTENT_COLOR || s->GetOpaqueRect().Contains(GetRoundOutDeviceClipExtents(this)))) { cairo_push_group_with_content(mCairo, CAIRO_CONTENT_COLOR); nsRefPtr<gfxASurface> d = CurrentSurface(); if (d->GetType() == gfxASurface::SurfaceTypeTee) { NS_ASSERTION(s->GetType() == gfxASurface::SurfaceTypeTee, "Mismatched types"); nsAutoTArray<nsRefPtr<gfxASurface>,2> ss; nsAutoTArray<nsRefPtr<gfxASurface>,2> ds; static_cast<gfxTeeSurface*>(s.get())->GetSurfaces(&ss); static_cast<gfxTeeSurface*>(d.get())->GetSurfaces(&ds); NS_ASSERTION(ss.Length() == ds.Length(), "Mismatched lengths"); gfxPoint translation = d->GetDeviceOffset() - s->GetDeviceOffset(); for (PRUint32 i = 0; i < ss.Length(); ++i) { CopySurface(ss[i], ds[i], translation); } } else { CopySurface(s, d, gfxPoint(0, 0)); } d->SetOpaqueRect(s->GetOpaqueRect()); return; } } cairo_push_group_with_content(mCairo, (cairo_content_t) content); }
bool Physics::MoveXFromTo(Location * pFromLocation,Location * pToLocation,vector<Surface*> surfaces) { vector<Surface*>::iterator iterator; iterator = surfaces.begin(); if(pFromLocation->X < pToLocation->X) { while(iterator != surfaces.end()) { Surface * pSurface = *iterator; if(LocationInSurfaceY(pToLocation, pSurface)) { if((pSurface->isSlope == 2) && SlopeInSurfaceX(pToLocation, pSurface) && LocationInSurfaceX(pToLocation, pSurface)) { pSurfaceFinal = CopySurface(pSurface); pSurfaceFinal->xTo = pFromLocation->X; return true; } if(!pSurface->isCloud && ((pFromLocation->X + pFromLocation->width) <= pSurface->xFrom && (pToLocation->X + pToLocation->width) >= pSurface->xFrom)) { pSurfaceFinal = pSurface; return true; } } iterator++; } } else { while(iterator != surfaces.end()) { Surface * pSurface = *iterator; if(LocationInSurfaceY(pToLocation, pSurface)) { if((pSurface->isSlope == 1) && SlopeInSurfaceX(pToLocation, pSurface) && LocationInSurfaceX(pToLocation, pSurface)) { pSurfaceFinal = CopySurface(pSurface); pSurfaceFinal->xTo = pFromLocation->X; return true; } if(!pSurface->isCloud && (pFromLocation->X >= pSurface->xTo && pToLocation->X <= pSurface->xTo)) { pSurfaceFinal=pSurface; return true; } } iterator++; } } return false; }
Surface::Surface(const Surface& other) : _surface(nullptr) { if (other._surface) { _surface = CopySurface(other._surface); } }
Surface& Surface::operator=(const Surface& other) { if (this != &other) { SDL_FreeSurface(_surface); _surface = CopySurface(other._surface); } return *this; }
Surface::Surface(const char* filename) : _surface(nullptr) { if (filename && *filename) { SDL_Surface* raw = IMG_Load(filename); if (raw) { // Convert the image from its native format to our desired // format. _surface = CopySurface(raw); SDL_FreeSurface(raw); } } }
SmartPointer<SDL_Surface> load_bitmap__allegroformat(const std::string& filename) { std::string fullfilename = GetFullFileName(filename); SDL_Surface* img = IMG_Load(Utf8ToSystemNative(fullfilename).c_str()); if(!img) return NULL; if( img->format->BitsPerPixel == 8 ) return img; SmartPointer<SDL_Surface> converted = create_32bpp_sdlsurface__allegroformat(img->w, img->h); CopySurface(converted.get(), img, 0, 0, 0, 0, img->w, img->h); //SDL_Surface* converted = SDL_DisplayFormat(img); SDL_FreeSurface(img); if(!converted.get()) { errors << "Failed: Converting of bitmap " << filename << /*" to " << bpp <<*/ " bit" << endl; return NULL; } return converted; }
bool Physics::FallYFromTo(Location * pFromLocation,Location * pToLocation,vector<Surface*> surfaces) { bool isFalling; vector<Surface*>::iterator iterator; Surface * pOnSurface; float toLocationYdiff; float fromLocationY; float toLocationY; fromLocationY = pFromLocation->Y + pFromLocation->height; toLocationY = pToLocation->Y + pToLocation->height; isFalling = true; iterator = surfaces.begin(); while(iterator != surfaces.end()) { Surface * pSurface = *iterator; toLocationYdiff = fabs(toLocationY - pSurface->yFrom); if(LocationInSurfaceX(pToLocation, pSurface)) { if(pSurface->isSlope!=0 && SlopeInSurfaceX(pToLocation, pSurface)) { if(pSurface->isSlope==1) { if(toLocationY >= pSurface->SlopeCoefficientB + (pSurface->SlopeCoefficientA * pToLocation->X )) { isFalling = false; pOnSurface = CopySurface(pSurface); pOnSurface->yFrom = toLocationY; } } else { if(toLocationY >= pSurface->SlopeCoefficientB + (pSurface->SlopeCoefficientA * (pToLocation->width + pToLocation->X))) { isFalling = false; pOnSurface = CopySurface(pSurface); pOnSurface->yFrom = toLocationY; } } } else if((pSurface->yFrom <= toLocationY && pSurface->yFrom >= fromLocationY) || toLocationYdiff < 5) { if(!pSurface->isCloud || CWin::keystateDown == 0) { isFalling = false; pOnSurface = pSurface; } } } iterator++; } if(isFalling) { return false; } else { pOnSurfaceFinalFall = pOnSurface; return true; } }
virtual nsresult PostOutput(BufferInfo::Param aInfo, MediaFormat::Param aFormat, const media::TimeUnit& aDuration) override { if (!EnsureGLContext()) { return NS_ERROR_FAILURE; } nsRefPtr<layers::Image> img = mImageContainer->CreateImage(ImageFormat::SURFACE_TEXTURE); layers::SurfaceTextureImage::Data data; data.mSurfTex = mSurfaceTexture.get(); data.mSize = mConfig.mDisplay; data.mOriginPos = gl::OriginPos::BottomLeft; layers::SurfaceTextureImage* stImg = static_cast<layers::SurfaceTextureImage*>(img.get()); stImg->SetData(data); if (WantCopy()) { EGLImage eglImage = CopySurface(img); if (!eglImage) { return NS_ERROR_FAILURE; } EGLSync eglSync = nullptr; if (sEGLLibrary.IsExtensionSupported(GLLibraryEGL::KHR_fence_sync) && mGLContext->IsExtensionSupported(GLContext::OES_EGL_sync)) { MOZ_ASSERT(mGLContext->IsCurrent()); eglSync = sEGLLibrary.fCreateSync(EGL_DISPLAY(), LOCAL_EGL_SYNC_FENCE, nullptr); MOZ_ASSERT(eglSync); mGLContext->fFlush(); } else { NS_WARNING("No EGL fence support detected, rendering artifacts may occur!"); } img = mImageContainer->CreateImage(ImageFormat::EGLIMAGE); layers::EGLImageImage::Data data; data.mImage = eglImage; data.mSync = eglSync; data.mOwns = true; data.mSize = mConfig.mDisplay; data.mOriginPos = gl::OriginPos::TopLeft; layers::EGLImageImage* typedImg = static_cast<layers::EGLImageImage*>(img.get()); typedImg->SetData(data); } nsresult rv; int32_t flags; NS_ENSURE_SUCCESS(rv = aInfo->Flags(&flags), rv); bool isSync = !!(flags & MediaCodec::BUFFER_FLAG_SYNC_FRAME); int32_t offset; NS_ENSURE_SUCCESS(rv = aInfo->Offset(&offset), rv); int64_t presentationTimeUs; NS_ENSURE_SUCCESS(rv = aInfo->PresentationTimeUs(&presentationTimeUs), rv); nsRefPtr<VideoData> v = VideoData::CreateFromImage(mConfig, mImageContainer, offset, presentationTimeUs, aDuration.ToMicroseconds(), img, isSync, presentationTimeUs, gfx::IntRect(0, 0, mConfig.mDisplay.width, mConfig.mDisplay.height)); ENVOKE_CALLBACK(Output, v); return NS_OK; }
void CApplicationRenderer::Process() { #ifndef HAS_SDL int iWidth = 0; int iHeight = 0; int iLeft = 0; int iTop = 0; LPDIRECT3DSURFACE8 lpSurfaceBack = NULL; LPDIRECT3DSURFACE8 lpSurfaceFront = NULL; while (!m_bStop) { if (!m_enabled || g_graphicsContext.IsFullScreenVideo()) { Sleep(50); continue; } if (!m_pWindow || iWidth == 0 || iHeight == 0 || m_Resolution != g_graphicsContext.GetVideoResolution()) { m_pWindow = (CGUIDialogBusy*)m_gWindowManager.GetWindow(WINDOW_DIALOG_BUSY); if (m_pWindow) { m_pWindow->Initialize();//need to load the window to determine size. if (m_pWindow->GetID() == WINDOW_INVALID) { //busywindow couldn't be loaded so stop this thread. m_pWindow = NULL; m_bStop = true; break; } SAFE_RELEASE(m_lpSurface); FRECT rect = m_pWindow->GetScaledBounds(); m_pWindow->ClearAll(); //unload iLeft = (int)floor(rect.left); iTop = (int)floor(rect.top); iWidth = (int)ceil(rect.right - rect.left); iHeight = (int)ceil(rect.bottom - rect.top); m_Resolution = g_graphicsContext.GetVideoResolution(); } } float t0 = (1000.0f/g_graphicsContext.GetFPS()); float t1 = m_time + t0; //time when we expect a new render float t2 = (float)timeGetTime(); if (t1 < t2) //we're late rendering { try { if (timeGetTime() >= (m_time + g_advancedSettings.m_busyDialogDelay)) { CSingleLock lockg (g_graphicsContext); if (m_prevbusycount != m_busycount) { Sleep(1); continue; } if (!m_pWindow || iWidth == 0 || iHeight == 0) { Sleep(1000); continue; } if (m_Resolution != g_graphicsContext.GetVideoResolution()) { continue; } if (m_busycount > 0) m_busycount--; //no busy indicator if a progress dialog is showing if ((m_gWindowManager.HasModalDialog() && (m_gWindowManager.GetTopMostModalDialogID() != WINDOW_VIDEO_INFO) && (m_gWindowManager.GetTopMostModalDialogID() != WINDOW_MUSIC_INFO)) || (m_gWindowManager.GetTopMostModalDialogID() == WINDOW_DIALOG_PROGRESS)) { //TODO: render progress dialog here instead of in dialog::Progress m_time = timeGetTime(); lockg.Leave(); Sleep(1); continue; } if (m_lpSurface == NULL) { D3DSURFACE_DESC desc; g_application.RenderNoPresent(); HRESULT result = g_graphicsContext.Get3DDevice()->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &lpSurfaceFront); if (SUCCEEDED(result)) { lpSurfaceFront->GetDesc( &desc ); iLeft = 0; iTop = 0; iWidth = desc.Width; iHeight = desc.Height; } else { lockg.Leave(); Sleep(1000); continue; } if (!SUCCEEDED(g_graphicsContext.Get3DDevice()->CreateImageSurface(iWidth, iHeight, desc.Format, &m_lpSurface))) { SAFE_RELEASE(lpSurfaceFront); lockg.Leave(); Sleep(1000); continue; } //copy part underneeth busy dialog const RECT rc = { iLeft, iTop, iLeft + iWidth, iTop + iHeight }; const RECT rcDest = { 0, 0, iWidth, iHeight }; if (!CopySurface(lpSurfaceFront, &rc, m_lpSurface, &rcDest)) { SAFE_RELEASE(lpSurfaceFront); SAFE_RELEASE(m_lpSurface); lockg.Leave(); Sleep(1000); continue; } //copy front buffer to backbuffer(s) to avoid jumping bool bBufferCopied = true; for (int i = 0; i < g_graphicsContext.GetBackbufferCount(); i++) { if (!SUCCEEDED(g_graphicsContext.Get3DDevice()->GetBackBuffer( i, D3DBACKBUFFER_TYPE_MONO, &lpSurfaceBack))) { bBufferCopied = false; break; } if (!CopySurface(lpSurfaceFront, NULL, lpSurfaceBack, NULL)) { bBufferCopied = false; break; } SAFE_RELEASE(lpSurfaceBack); } if (!bBufferCopied) { SAFE_RELEASE(lpSurfaceFront); SAFE_RELEASE(lpSurfaceBack); SAFE_RELEASE(m_lpSurface); lockg.Leave(); Sleep(1000); continue; } SAFE_RELEASE(lpSurfaceFront); } if (!SUCCEEDED(g_graphicsContext.Get3DDevice()->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &lpSurfaceBack))) { lockg.Leave(); Sleep(1000); continue; } g_graphicsContext.Get3DDevice()->BeginScene(); //copy dialog background to backbuffer const RECT rc = { 0, 0, iWidth, iHeight }; const RECT rcDest = { iLeft, iTop, iLeft + iWidth, iTop + iHeight }; const D3DRECT rc2 = { iLeft, iTop, iLeft + iWidth, iTop + iHeight }; g_graphicsContext.Get3DDevice()->Clear(1, &rc2, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00010001, 1.0f, 0L); if (!CopySurface(m_lpSurface, &rc, lpSurfaceBack, &rcDest)) { SAFE_RELEASE(lpSurfaceBack); g_graphicsContext.Get3DDevice()->EndScene(); lockg.Leave(); Sleep(1000); continue; } SAFE_RELEASE(lpSurfaceBack); if (!m_busyShown) { m_pWindow->Show(); m_busyShown = true; } m_pWindow->Render(); g_graphicsContext.Get3DDevice()->EndScene(); //D3DSWAPEFFECT_DISCARD is used so we can't just present the busy rect but can only present the entire screen. g_graphicsContext.Get3DDevice()->Present( NULL, NULL, NULL, NULL ); } m_busycount++; m_prevbusycount = m_busycount; } catch (...) { CLog::Log(LOGERROR, __FUNCTION__" - Exception caught when busy rendering"); SAFE_RELEASE(lpSurfaceFront); SAFE_RELEASE(lpSurfaceBack); SAFE_RELEASE(m_lpSurface); } } Sleep(1); } #endif }