Exemplo n.º 1
0
/********************************************************************************************
>	virtual BOOL ConcurrentRenderer::Initialise(
					GRenderRegion* pActiveRR,
					double ResFactor,
					DocRect AreaOfDocumentToRender,
					UINT32 bpp,
					BOOL NeedsTransp
			)
	Author:		Ilan_Copelyn (Xara Group Ltd) <*****@*****.**>
	Created:	5/06/2000
	Purpose:	
	SeeAlso:	
 ********************************************************************************************/
BOOL ConcurrentRenderer::Initialise(
					GRenderRegion* pActiveRR,
					double ResFactor,
					DocRect AreaOfDocumentToRender,
					UINT32 bpp,
					BOOL NeedsTransp
			)
{
	// if we have no source render-region, then we need to manufacture a rendering matrix
	// for ourself.
	// to generate our render-matrix, we use the current view and spread, together with
	// a user-specified dpi value.
	Matrix	SourceMat;
	if (pActiveRR == NULL)
	{
		View* pView = View::GetCurrent();
		if (pView == NULL)
			return FALSE;

		double PixelsPerInch = pView->GetConvertToEditableShapesDPI();

		Spread* pSpread = Document::GetSelectedSpread();
		if (pSpread == NULL)
			return FALSE;

		FIXED16			ViewPixelWidth	= pView->GetScaledPixelWidth();
		const double	AppPixelWidth	= MILLIPOINTS_PER_INCH / (double)PixelsPerInch;
		double ViewScaleFactor = ViewPixelWidth.MakeDouble() / AppPixelWidth;

		SourceMat = pView->ConstructScaledRenderingMatrix(pSpread, ViewScaleFactor);
	}

	// we have a source render-region, so get its matrix and scale up ResFactor
	// so that our offscreen RR would effectively have the same scaled pixel width
	// as its source render-region (not taking into account the original value of ResFactor).
	else
	{
		SourceMat = pActiveRR->GetMatrix();
		const double ActualPixelWidth = (double)pActiveRR->GetPixelWidth();
		const double DefPixelWidth = MILLIPOINTS_PER_INCH / (double)GRenderRegion::GetDefaultDPI();
		ResFactor *= DefPixelWidth / ActualPixelWidth;
	}

//	m_pView = pActiveRR->GetRenderView();
//	m_pView = View::GetCurrent();
//	if (m_pView)
//	{
//		TRACEUSER( "Gerry", _T("Forcing default context\n"));
//		m_bOldForce = m_pView->SetForceDefaultColourContexts();
//	}

	m_pNewGD = new GDrawAsm;
	if (m_pNewGD && m_pNewGD->Init())
	{
		// Save current device context
		m_pOldGD = GRenderRegion::SetTempDrawContext(m_pNewGD);
//		m_pOldGD = GRenderRegion::GetStaticDrawContext();
//		GRenderRegion::GD = pGDAsm;
	}

	// Setup a new GRenderDIB (NB also initialises memory).
	m_pNewRR = CreateGRenderDIB(ResFactor, AreaOfDocumentToRender, bpp, NeedsTransp, &SourceMat);
	if (m_pNewRR != NULL)
	{
		return TRUE;
	}

	// If we get here then we have failed so clean up and return false
	delete m_pNewGD;
	m_pNewGD = NULL;
	GRenderRegion::SetTempDrawContext(m_pOldGD);
	m_pOldGD = NULL;
	return FALSE;
}
Exemplo n.º 2
0
/********************************************************************************************
>	static GRenderDIB* QuickRenderer::CreateGRenderDIB(
					double ResFactor,
					DocRect AreaOfDocumentToRender,
					UINT32 bpp,
					BOOL NeedsTransp,
					Matrix* pSourceMat)
	Author:		Ilan_Copelyn (Xara Group Ltd) <*****@*****.**>
	Created:	5/06/2000
	Purpose:	Create and start a GRenderDIB ready for rendering
	SeeAlso:	
	Errors:		Returns NULL if unable to alloc mem for bitmaps in StartRender()
 ********************************************************************************************/
GRenderDIB* QuickRenderer::CreateGRenderDIB(
					double ResFactor,
					DocRect AreaOfDocumentToRender,
					UINT32 bpp,
					BOOL NeedsTransp,
					Matrix* pSourceMat)
{
	/////////////////////////////////////////////////////////////////////////////////////////////
	//								Setup a new GRenderDIB
	/////////////////////////////////////////////////////////////////////////////////////////////
	GRenderDIB* pNewGRR=NULL;
	BOOL DoWantBMPSmoothing = FALSE;
	BOOL ok;

	// Setup new GRenderDIB based on current Screen resolution and ResFactor multiplier
	View* pView = View::GetCurrent();

	// get the top spread
	Spread* pSpread = Document::GetSelectedSpread();

	// if we've been passed a source matrix, then we'll scale it up by ResFactor and use that.
// DEBUG:
	// Note that we currently check whether the view is for printing, solely so that this code
	// can live on the net without breaking printing of shadows more than it already is.
	Matrix Mat;
	if (pSourceMat != NULL)
	{
		FIXED16 Scale;
		DocCoord dcTrans;

		pSourceMat->Decompose(&Scale, NULL, NULL, NULL, &dcTrans);

		// Karim 04/09/2000
		// BODGE, to cope with printing reflected images.
		// If the given matrix contains a reflection, then its determinant < 0.
		// If this is so, then we'll scale the matrix by -1, which corrects the output.
		if (pSourceMat->Det() < 0.0)
			Scale *= FIXED16(-1);

		Mat = Matrix(Scale * FIXED16(ResFactor), Scale * FIXED16(ResFactor));
		Mat.SetTranslation(dcTrans);

//		Mat *= *pSourceMat;
	}

	// otherwise, we'll use the view's settings, scaled up by ResFactor.
	else
	{
		Mat = pView->ConstructScaledRenderingMatrix(pSpread, ResFactor);
	}

	// get the scale factor out of the matrix.
	FIXED16 Scale;
	Mat.Decompose(&Scale);

	//	double dpi = Scale.MakeDouble() * PIXELS_PER_INCH;
	double dpi = 0.0;	// use screen dpi (ie PIXELS_PER_INCH)

	// Create a new GRenderDIB region
	pNewGRR = new GRenderDIB(AreaOfDocumentToRender, Mat, Scale, bpp, dpi);
	ERROR2IF(pNewGRR == NULL,FALSE,"Failed to create a GRenderDIB!");

	// Ensure bmp mem is not allocated from limited memory
	NewWrappedRRCreated((GRenderRegion*) pNewGRR);

	// State flags + pixel width calculations
	if(!pNewGRR->AttachDevice(pView, NULL, pSpread))		// view and spread from previous RR rather than Current - nb in create bitmap copy case
	{
		ERROR3("Cannot attach devices");
		
		delete pNewGRR;
		pNewGRR = NULL;
		return NULL;
	}

	pNewGRR->m_DoCompression = NeedsTransp;
	
	ok = pNewGRR->InitDevice();
	if (!ok)
	{
		delete pNewGRR;
		pNewGRR = NULL;
		return NULL;
	}
	pNewGRR->InitAttributes();
	pNewGRR->RRQuality.SetQuality(QUALITY_MAX);
	pNewGRR->SetQualityLevel();
	pNewGRR->SetLineAttributes();
	pNewGRR->SetFillAttributes();

	// NB following call gets GRendRegion to create the bitmap into which GDraw will render
	BOOL Started = pNewGRR->StartRender();

// Karim 06/07/2000
// I'm commenting these pre-processor directives out, to fix a bug with the new shadowing
// code, where shadows at anything other than 100% zoom are incorrectly scaled. This is a
// BODGE, and this code should be revisited at a later date.

//#ifdef _DEBUG
	// Set DIB dpi indicators correctly - so they are correct if adding to bitmap gallery (not required)
	double	PixPerMetre =	PIXELS_PER_INCH * INCHES_PER_METRE;
			PixPerMetre *=	Scale.MakeDouble();

	LPBITMAPINFO bi;
	LPBYTE by;
	GetBitmapPointers(pNewGRR,&bi,&by);
	if(bi)
	{
		bi->bmiHeader.biXPelsPerMeter = (INT32) (PixPerMetre + 0.5);
		bi->bmiHeader.biYPelsPerMeter = (INT32) (PixPerMetre + 0.5);
	}
//#endif

	if(Started)
	{
		pNewGRR->SaveContext();

		if(DoWantBMPSmoothing)
		{
			(pNewGRR->GetDrawContext())->SetTileSmoothingFlag(TRUE);
		}

		return pNewGRR;
	}
	else
	{
//		ENSURE(FALSE,"StartRender failed to alloc bmp for GDraw to render into.");
		delete pNewGRR;
		return NULL;
	}

}