offscrn.cpp

Go to the documentation of this file.
00001 // $Id: offscrn.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 #include "camtypes.h"
00100 // camconfig.h must be included immediately after camtypes.h
00101 #include "camconfig.h"
00102 
00103 #include "GDrawIntf.h"
00104 #include "offscrn.h"
00105 #include "grnddib.h"        // GRenderDIB
00106 //#include "mario.h"            // _R(IDE_NOMORE_MEMORY)
00107 #include "XaDrwOld.h"       // GDraw device context funcitons
00108 //#include "ndcchbmp.h"     // NodeCacheBitmap
00109 #include "oilbitmap.h"      // WinBitmap class
00110 //#include "capturemanager.h"   // CaptureManager - in camtypes.h [AUTOMATICALLY REMOVED]
00111 
00112 #include "prntview.h"       // for PrintView. I'm only temporary - delete me when done with.
00113 
00114 CC_IMPLEMENT_MEMDUMP(GRenderRegionWrapper, CC_CLASS_MEMDUMP)
00115 
00116 #define new CAM_DEBUG_NEW
00117 
00119 //
00120 //                              GRenderRegionWrapper
00121 //
00123 
00124 /********************************************************************************************
00125 >   static GRenderRegionWrapper* GRenderRegionWrapper::GetAppropriateRenderWrapper (
00126                     GRenderRegion* pActiveRR,
00127                     double ResFactor,
00128                     DocRect AreaOfDocumentToRender,
00129                     UINT32 bpp,
00130                     BOOL NeedsTransp
00131             )
00132     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00133     Created:    5/06/2000
00134     Purpose:    If there is no active render region then create and initialise a new 
00135                 GRenderDIB (via the QuickRenderer wrapper)
00136                 Otherwise we will need a GDrawBorrower which will allow us to restore
00137                 GDraw to the state which the active render region has it in
00138                 If we have to change dpi, then we use a new ConcurrentRenderer
00139     SeeAlso:    
00140  ********************************************************************************************/
00141 GRenderRegionWrapper* GRenderRegionWrapper::GetAppropriateRenderWrapper (
00142                     GRenderRegion* pActiveRR,
00143                     double ResFactor,
00144                     DocRect AreaOfDocumentToRender,
00145                     UINT32 bpp,
00146                     BOOL NeedsTransp)
00147 {
00148     if(NeedsTransp)
00149     {
00150         ENSURE(bpp==32,"Can only handle transp when rendering to 32bpp bmp");
00151         if(bpp!=32)
00152             return NULL;
00153     }
00154 
00155     GRenderRegionWrapper* pNewWrap = NULL;
00156 
00157     if(pActiveRR == NULL)
00158     {
00159         pNewWrap = (GRenderRegionWrapper*) new QuickRenderer();
00160     }
00161     else
00162     {
00163         if(ResFactor!=1.0 || bpp!=32)
00164         {
00165             pNewWrap = (GRenderRegionWrapper*) new ConcurrentRenderer();
00166         }
00167         else
00168         {
00169             // can only use offscreen rendering system in 32bpp mode and
00170             // using same resolution as screen (ie same kernel matrix)
00171             pNewWrap = (GRenderRegionWrapper*) new GDrawBorrower();
00172         }
00173     }
00174 
00175     if(!pNewWrap->Initialise(pActiveRR, ResFactor, AreaOfDocumentToRender, bpp, NeedsTransp))
00176     {
00177         // failed to init. free mem.
00178         delete pNewWrap;
00179         return NULL;
00180     }
00181 
00182     // initialised and ready to render
00183     return pNewWrap;
00184 }
00185 
00186 
00187 
00188 /********************************************************************************************
00189 
00190 >   ConcurrentRenderer* GRenderRegionWrapper::GetConcurrentRenderer(
00191                                                             GRenderRegion* pSourceRR,
00192                                                             double ResFactor,
00193                                                             DocRect AreaOfDocumentToRender,
00194                                                             UINT32 bpp,
00195                                                             BOOL NeedsTransp
00196                                                             )
00197     Author:     Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com>
00198     Created:    13/07/2000
00199 
00200     Inputs:     pSourceRR               The render-region to base ourself upon.
00201                                         If NULL, then we will use the current view settings.
00202                 ResFactor               Scale at which to render things, RELATIVE to the
00203                                         source RR's scale factor, as we're assuming you'll
00204                                         want to be at the same scale for most uses.
00205                 AreaOfDocumentToRender  The area to render, in millipoints.
00206                 bpp                     bits per pixel. must be 32 if you want transparency.
00207                 NeedsTransp             Whether you want transparency on or not.
00208 
00209     Returns:    The RenderWrapper created, or
00210                 NULL if unsuccessful.
00211 
00212     Purpose:    Create and use a concurrent renderer.
00213                 This flavour of render wrapper derives from QuickRenderer, and creates
00214                 a fresh GRenderRegion, whose rendering matrix is based on the source RR.
00215 
00216                 Here's an example without any error-checking:
00217 
00218                     ConcurrentRenderer* pRendWrap    = GRenderRegionWrapper::GetConcurrentRenderer(...)
00219                     GRenderRegion*      pOffscreenRR = pRendWrap->GetRenderRegion();
00220                     pOffscreenRR->SetFillColour(COLOUR_BLACK);
00221                     pOffscreenRR->SetLineColour(COLOUR_TRANS);
00222                     pOffscreenRR->DrawPath(pPathToDraw);
00223                     pRendWrap->GetBitmapPointers(&pBmpInfo, &pBmpBits);
00224                     pRendWrap->RestorePreviousRendererState();
00225 
00226     Errors:     ERROR2 if pSourceRR is NULL or you ask for a transparent, non-32bpp RR.
00227 
00228     See also:   BitmapShadower::RenderShadowedNodeOffscreen() for a real-use example.
00229 
00230 ********************************************************************************************/
00231 ConcurrentRenderer* GRenderRegionWrapper::GetConcurrentRenderer(
00232                         GRenderRegion* pSourceRR,
00233                         double ResFactor,
00234                         DocRect AreaOfDocumentToRender,
00235                         UINT32 bpp,
00236                         BOOL NeedsTransp    )
00237 {
00238     ERROR2IF(NeedsTransp && (bpp != 32), NULL, "Can only do transp with 32 bpp bitmaps");
00239 
00240     ConcurrentRenderer* pNewWrap = new ConcurrentRenderer;
00241     if (!pNewWrap->Initialise(pSourceRR, ResFactor, AreaOfDocumentToRender, bpp, NeedsTransp))
00242     {
00243         delete pNewWrap;
00244         pNewWrap = NULL;
00245     }
00246 
00247     return pNewWrap;
00248 }
00249 
00250 
00251 
00252 /********************************************************************************************
00253 >   void GRenderRegionWrapper::NewWrappedRRCreated(GRenderRegion* pGrr)
00254     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00255     Created:    5/06/2000
00256     Purpose:    Allow parent to set flags on any newly created GRenderRegions
00257     SeeAlso:    
00258  ********************************************************************************************/
00259 void GRenderRegionWrapper::NewWrappedRRCreated(GRenderRegion* pGrr)
00260 {
00261     pGrr->SetIsWrapped(TRUE);
00262 }
00263 
00264 /********************************************************************************************
00265 >   void GRenderRegionWrapper::GetBitmapPointers(LPBITMAPINFO* bi, LPBYTE *by)
00266     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00267     Created:    5/06/2000
00268     Purpose:    Passes back the DIB pointers which WinBitmaps are comprised of
00269     SeeAlso:    
00270  ********************************************************************************************/
00271 void GRenderRegionWrapper::GetBitmapPointers(LPBITMAPINFO* bi, LPBYTE *by)
00272 {
00273     GRenderRegion *pGrr = GetRenderRegion();
00274     *bi = pGrr->pBitmapInfo;
00275     *by = pGrr->pBits;
00276 }
00277 
00278 // Karim 06/07/2000
00279 // I'm commenting these pre-processor directives out, to fix a bug with the new shadowing
00280 // code, where shadows at anything other than 100% zoom are incorrectly scaled. This is a
00281 // BODGE, and this code should be revisited at a later date.
00282 
00283 //#ifdef _DEBUG
00284 // allows QuickRenderer::CreateGRenderDIB to access the bmp pointers of render region it creates
00285 // NB exploits GRenderRegionWrapper's 'friend'ship with GRenderRegion, just used in DEBUG builds
00286 void GRenderRegionWrapper::GetBitmapPointers(GRenderRegion* pGrr, LPBITMAPINFO* bi, LPBYTE *by)
00287 {
00288     *bi = pGrr->pBitmapInfo;
00289     *by = pGrr->pBits;
00290 }
00291 //#endif
00292 
00293 /********************************************************************************************
00294 >   void GRenderRegionWrapper::SetBitmapPointers(LPBITMAPINFO* bi, LPBYTE *by)
00295     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00296     Created:    8/06/2000
00297     Purpose:    Set DIB pointers within the RenderRegion.
00298                 Primarily used to prevent Quick&Concurrent Renderers from deleting
00299                 the bitmap contained within their underlying GRenderDIBs
00300     SeeAlso:    QuickRenderer::RestorePreviousRendererState
00301  ********************************************************************************************/
00302 void GRenderRegionWrapper::SetBitmapPointers(LPBITMAPINFO bi, LPBYTE by)
00303 {
00304     GRenderRegion *pGrr = GetRenderRegion();
00305     pGrr->SetBitmapPointers(bi, by);
00306 }
00307 
00308 /********************************************************************************************
00309 >   KernelBitmap* GRenderRegionWrapper::GetKernelBitmap()
00310     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00311     Created:    5/06/2000
00312     Purpose:    Encapsulates bitmap pointers of underlying render region in a KernelBitmap
00313     SeeAlso:    
00314  ********************************************************************************************/
00315 KernelBitmap* GRenderRegionWrapper::GetKernelBitmap()
00316 {
00317     LPBITMAPINFO bi;
00318     LPBYTE by;
00319     GetBitmapPointers(&bi,&by);
00320 
00321     LPBITMAPINFOHEADER  bh = &bi->bmiHeader;
00322     if(bh->biCompression==0x80000001)
00323     {
00324         GetRenderRegion()->GetDrawContext()->ConvertBitmap(
00325                                     bh, by,
00326                                     bh, by,
00327                                     0
00328                                 );
00329     }
00330 
00331     CWxBitmap* pTempBmp= new CWxBitmap(bi, by);
00332     KernelBitmap* kBmp = new KernelBitmap(pTempBmp,TRUE);
00333     return kBmp;
00334 }
00335 
00337 //
00338 //                              GDrawBorrower
00339 //
00341 
00342 /********************************************************************************************
00343 >   GDrawBorrower::GDrawBorrower()
00344     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00345     Created:    5/06/2000
00346     Purpose:    Constructor
00347     SeeAlso:    
00348  ********************************************************************************************/
00349 GDrawBorrower::GDrawBorrower()
00350 {
00351     m_pBorrowedRR = NULL;
00352 }
00353 
00354 /********************************************************************************************
00355 >   GDrawBorrower::~GDrawBorrower()
00356     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00357     Created:    5/06/2000
00358     Purpose:    DeConstructor
00359     SeeAlso:    
00360  ********************************************************************************************/
00361 GDrawBorrower::~GDrawBorrower()
00362 {
00363     ENSURE(m_pBorrowedRR==NULL,"Deconstructor not meant to be called like this. Use RestorePreviousRendererState()");
00364 }
00365 
00366 /********************************************************************************************
00367 >   virtual BOOL GDrawBorrower::Initialise(
00368                     GRenderRegion* pActiveRR,
00369                     double ResFactor,
00370                     DocRect AreaOfDocumentToRender,
00371                     UINT32 bpp,
00372                     BOOL NeedsTransp )
00373     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00374     Created:    5/06/2000
00375     Purpose:    Puts pActiveRR into offscreen rendering state
00376     SeeAlso:    
00377  ********************************************************************************************/
00378 BOOL GDrawBorrower::Initialise(
00379                     GRenderRegion* pActiveRR,
00380                     double ResFactor,
00381                     DocRect AreaOfDocumentToRender,
00382                     UINT32 bpp,
00383                     BOOL NeedsTransp )
00384 {
00385     ERROR2IF(!(bpp==32),FALSE,"Can only do 32bpp offscreen bmps at present.");
00386 
00387     Capture* pCapture = m_pBorrowedRR->StartCapture(this, AreaOfDocumentToRender, CAPTUREINFO(ctNESTABLE, cfNONE), NeedsTransp, FALSE);
00388     return (pCapture!=NULL);
00389 }
00390 
00391 /********************************************************************************************
00392 >   virtual BOOL GDrawBorrower::RestorePreviousRendererState()
00393     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00394     Created:    5/06/2000
00395     Purpose:    Pops top offscreen state and restores GDraw state via offscreen rendering
00396                 system call
00397                 NB Bitmaps not freed - only offscreen state structure memory
00398     SeeAlso:    
00399  ********************************************************************************************/
00400 BOOL GDrawBorrower::RestorePreviousRendererState()
00401 {
00402     // restore GDRAW state and free offscreen state mem
00403     BOOL bOK = m_pBorrowedRR->StopCapture(this, FALSE, FALSE);
00404     m_pBorrowedRR = NULL;
00405     delete this;
00406     return bOK;
00407 }
00408 
00409 /********************************************************************************************
00410 >   GDrawBorrower::
00411     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00412     Created:    5/06/2000
00413     Purpose:    
00414     SeeAlso:    
00415  ********************************************************************************************/
00417 //
00418 //                              QuickRenderer
00419 //
00421 
00422 /********************************************************************************************
00423 >   QuickRenderer::QuickRenderer()
00424     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00425     Created:    5/06/2000
00426     Purpose:    Constructor
00427     SeeAlso:    
00428  ********************************************************************************************/
00429 QuickRenderer::QuickRenderer()
00430 {
00431     m_pNewRR = NULL;
00432 }
00433 
00434 /********************************************************************************************
00435 >   QuickRenderer::~QuickRenderer()
00436     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00437     Created:    5/06/2000
00438     Purpose:    DeConstructor
00439     SeeAlso:    
00440  ********************************************************************************************/
00441 QuickRenderer::~QuickRenderer()
00442 {
00443     ENSURE(m_pNewRR==NULL,"Deconstructor not meant to be called like this. Use RestorePreviousRendererState()");
00444 }
00445 
00446 /********************************************************************************************
00447 >   virtual BOOL QuickRenderer::Initialise(
00448                     GRenderRegion* pActiveRR,
00449                     double ResFactor,
00450                     DocRect AreaOfDocumentToRender,
00451                     UINT32 bpp,
00452                     BOOL NeedsTransp )
00453     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00454     Created:    5/06/2000
00455     Purpose:    
00456     SeeAlso:    
00457  ********************************************************************************************/
00458 BOOL QuickRenderer::Initialise(
00459                     GRenderRegion* pActiveRR,
00460                     double ResFactor,
00461                     DocRect AreaOfDocumentToRender,
00462                     UINT32 bpp,
00463                     BOOL NeedsTransp )
00464 {
00465     ENSURE(pActiveRR==NULL,"GDraw state about to be change unrevocably, and it appears there is a render region active");
00466 
00467     // Setup a new GRenderDIB (NB also initialises memory)
00468     m_pNewRR = CreateGRenderDIB(ResFactor, AreaOfDocumentToRender, bpp, NeedsTransp);
00469 
00470     if(m_pNewRR)
00471         return TRUE;
00472     else
00473         return FALSE;
00474 }
00475 
00476 /********************************************************************************************
00477 >   virtual void QuickRenderer::RestoreSimple()
00478     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00479     Created:    27/07/2004
00480     Purpose:    Free up the RenderRegion we created. Nothing to restore
00481                 NB deliberately prevents ~GRenderDIB from freeing the bitmap
00482                 that it has just rendered by setting it's internal bmp pointers
00483                 to NULL
00484     SeeAlso:
00485     NB:         It is up to you to free the bitmap otherwise a mem leak will occur!
00486  ********************************************************************************************/
00487 void QuickRenderer::RestoreSimple()
00488 {
00489     // assumes you have already got pointers to the rendered bitmap, and don't want it to be deleted
00490     SetBitmapPointers(NULL,NULL);       // NB now that we are using GRenderDIB need to be careful not to DisplayBits() in StopRender()
00491     if (m_pNewRR)
00492     {
00493         m_pNewRR->StopRender();
00494         delete m_pNewRR;
00495         m_pNewRR = NULL;
00496     }
00497 }
00498 
00499 /********************************************************************************************
00500 >   virtual BOOL QuickRenderer::RestorePreviousRendererState()
00501     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00502     Created:    5/06/2000
00503     Purpose:    Free up the RenderRegion we created. Nothing to restore
00504                 NB deliberately prevents ~GRenderDIB from freeing the bitmap
00505                 that it has just rendered by setting it's internal bmp pointers
00506                 to NULL
00507     SeeAlso:
00508     NB:         It is up to you to free the bitmap otherwise a mem leak will occur!
00509  ********************************************************************************************/
00510 BOOL QuickRenderer::RestorePreviousRendererState()
00511 {
00512     RestoreSimple();
00513 
00514     delete this;
00515     return TRUE;
00516 }
00517 
00518 /********************************************************************************************
00519 >   static GRenderDIB* QuickRenderer::CreateGRenderDIB(
00520                     double ResFactor,
00521                     DocRect AreaOfDocumentToRender,
00522                     UINT32 bpp,
00523                     BOOL NeedsTransp,
00524                     Matrix* pSourceMat)
00525     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00526     Created:    5/06/2000
00527     Purpose:    Create and start a GRenderDIB ready for rendering
00528     SeeAlso:    
00529     Errors:     Returns NULL if unable to alloc mem for bitmaps in StartRender()
00530  ********************************************************************************************/
00531 GRenderDIB* QuickRenderer::CreateGRenderDIB(
00532                     double ResFactor,
00533                     DocRect AreaOfDocumentToRender,
00534                     UINT32 bpp,
00535                     BOOL NeedsTransp,
00536                     Matrix* pSourceMat)
00537 {
00539     //                              Setup a new GRenderDIB
00541     GRenderDIB* pNewGRR=NULL;
00542     BOOL DoWantBMPSmoothing = FALSE;
00543     BOOL ok;
00544 
00545     // Setup new GRenderDIB based on current Screen resolution and ResFactor multiplier
00546     View* pView = View::GetCurrent();
00547 
00548     // get the top spread
00549     Spread* pSpread = Document::GetSelectedSpread();
00550 
00551     // if we've been passed a source matrix, then we'll scale it up by ResFactor and use that.
00552 // DEBUG:
00553     // Note that we currently check whether the view is for printing, solely so that this code
00554     // can live on the net without breaking printing of shadows more than it already is.
00555     Matrix Mat;
00556     if (pSourceMat != NULL)
00557     {
00558         FIXED16 Scale;
00559         DocCoord dcTrans;
00560 
00561         pSourceMat->Decompose(&Scale, NULL, NULL, NULL, &dcTrans);
00562 
00563         // Karim 04/09/2000
00564         // BODGE, to cope with printing reflected images.
00565         // If the given matrix contains a reflection, then its determinant < 0.
00566         // If this is so, then we'll scale the matrix by -1, which corrects the output.
00567         if (pSourceMat->Det() < 0.0)
00568             Scale *= FIXED16(-1);
00569 
00570         Mat = Matrix(Scale * FIXED16(ResFactor), Scale * FIXED16(ResFactor));
00571         Mat.SetTranslation(dcTrans);
00572 
00573 //      Mat *= *pSourceMat;
00574     }
00575 
00576     // otherwise, we'll use the view's settings, scaled up by ResFactor.
00577     else
00578     {
00579         Mat = pView->ConstructScaledRenderingMatrix(pSpread, ResFactor);
00580     }
00581 
00582     // get the scale factor out of the matrix.
00583     FIXED16 Scale;
00584     Mat.Decompose(&Scale);
00585 
00586     //  double dpi = Scale.MakeDouble() * PIXELS_PER_INCH;
00587     double dpi = 0.0;   // use screen dpi (ie PIXELS_PER_INCH)
00588 
00589     // Create a new GRenderDIB region
00590     pNewGRR = new GRenderDIB(AreaOfDocumentToRender, Mat, Scale, bpp, dpi);
00591     ERROR2IF(pNewGRR == NULL,FALSE,"Failed to create a GRenderDIB!");
00592 
00593     // Ensure bmp mem is not allocated from limited memory
00594     NewWrappedRRCreated((GRenderRegion*) pNewGRR);
00595 
00596     // State flags + pixel width calculations
00597     if(!pNewGRR->AttachDevice(pView, NULL, pSpread))        // view and spread from previous RR rather than Current - nb in create bitmap copy case
00598     {
00599         ERROR3("Cannot attach devices");
00600         
00601         delete pNewGRR;
00602         pNewGRR = NULL;
00603         return NULL;
00604     }
00605 
00606     pNewGRR->m_DoCompression = NeedsTransp;
00607     
00608     ok = pNewGRR->InitDevice();
00609     if (!ok)
00610     {
00611         delete pNewGRR;
00612         pNewGRR = NULL;
00613         return NULL;
00614     }
00615     pNewGRR->InitAttributes();
00616     pNewGRR->RRQuality.SetQuality(QUALITY_MAX);
00617     pNewGRR->SetQualityLevel();
00618     pNewGRR->SetLineAttributes();
00619     pNewGRR->SetFillAttributes();
00620 
00621     // NB following call gets GRendRegion to create the bitmap into which GDraw will render
00622     BOOL Started = pNewGRR->StartRender();
00623 
00624 // Karim 06/07/2000
00625 // I'm commenting these pre-processor directives out, to fix a bug with the new shadowing
00626 // code, where shadows at anything other than 100% zoom are incorrectly scaled. This is a
00627 // BODGE, and this code should be revisited at a later date.
00628 
00629 //#ifdef _DEBUG
00630     // Set DIB dpi indicators correctly - so they are correct if adding to bitmap gallery (not required)
00631     double  PixPerMetre =   PIXELS_PER_INCH * INCHES_PER_METRE;
00632             PixPerMetre *=  Scale.MakeDouble();
00633 
00634     LPBITMAPINFO bi;
00635     LPBYTE by;
00636     GetBitmapPointers(pNewGRR,&bi,&by);
00637     if(bi)
00638     {
00639         bi->bmiHeader.biXPelsPerMeter = (INT32) (PixPerMetre + 0.5);
00640         bi->bmiHeader.biYPelsPerMeter = (INT32) (PixPerMetre + 0.5);
00641     }
00642 //#endif
00643 
00644     if(Started)
00645     {
00646         pNewGRR->SaveContext();
00647 
00648         if(DoWantBMPSmoothing)
00649         {
00650             (pNewGRR->GetDrawContext())->SetTileSmoothingFlag(TRUE);
00651         }
00652 
00653         return pNewGRR;
00654     }
00655     else
00656     {
00657 //      ENSURE(FALSE,"StartRender failed to alloc bmp for GDraw to render into.");
00658         delete pNewGRR;
00659         return NULL;
00660     }
00661 
00662 }
00663 
00664 /********************************************************************************************
00665 >   QuickRenderer::
00666     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00667     Created:    5/06/2000
00668     Purpose:    
00669     SeeAlso:    
00670  ********************************************************************************************/
00672 //
00673 //                              ConcurrentRenderer
00674 //
00676 
00677 ConcurrentRenderer::ConcurrentRenderer()
00678 {
00679     m_pOldGD = NULL;
00680     m_pNewGD = NULL;
00681     m_pView = NULL;
00682 }
00683 
00684 ConcurrentRenderer::~ConcurrentRenderer()
00685 {
00686     if (m_pOldGD != NULL || m_pNewGD != NULL)
00687     {
00688         TRACEUSER( "Gerry", _T("GDraw context not restored in ConcurrentRenderer::~ConcurrentRenderer\n"));
00689     }
00690 }
00691 
00692 /********************************************************************************************
00693 >   virtual BOOL ConcurrentRenderer::Initialise(
00694                     GRenderRegion* pActiveRR,
00695                     double ResFactor,
00696                     DocRect AreaOfDocumentToRender,
00697                     UINT32 bpp,
00698                     BOOL NeedsTransp
00699             )
00700     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00701     Created:    5/06/2000
00702     Purpose:    
00703     SeeAlso:    
00704  ********************************************************************************************/
00705 BOOL ConcurrentRenderer::Initialise(
00706                     GRenderRegion* pActiveRR,
00707                     double ResFactor,
00708                     DocRect AreaOfDocumentToRender,
00709                     UINT32 bpp,
00710                     BOOL NeedsTransp
00711             )
00712 {
00713     // if we have no source render-region, then we need to manufacture a rendering matrix
00714     // for ourself.
00715     // to generate our render-matrix, we use the current view and spread, together with
00716     // a user-specified dpi value.
00717     Matrix  SourceMat;
00718     if (pActiveRR == NULL)
00719     {
00720         View* pView = View::GetCurrent();
00721         if (pView == NULL)
00722             return FALSE;
00723 
00724         double PixelsPerInch = pView->GetConvertToEditableShapesDPI();
00725 
00726         Spread* pSpread = Document::GetSelectedSpread();
00727         if (pSpread == NULL)
00728             return FALSE;
00729 
00730         FIXED16         ViewPixelWidth  = pView->GetScaledPixelWidth();
00731         const double    AppPixelWidth   = MILLIPOINTS_PER_INCH / (double)PixelsPerInch;
00732         double ViewScaleFactor = ViewPixelWidth.MakeDouble() / AppPixelWidth;
00733 
00734         SourceMat = pView->ConstructScaledRenderingMatrix(pSpread, ViewScaleFactor);
00735     }
00736 
00737     // we have a source render-region, so get its matrix and scale up ResFactor
00738     // so that our offscreen RR would effectively have the same scaled pixel width
00739     // as its source render-region (not taking into account the original value of ResFactor).
00740     else
00741     {
00742         SourceMat = pActiveRR->GetMatrix();
00743         const double ActualPixelWidth = (double)pActiveRR->GetPixelWidth();
00744         const double DefPixelWidth = MILLIPOINTS_PER_INCH / (double)GRenderRegion::GetDefaultDPI();
00745         ResFactor *= DefPixelWidth / ActualPixelWidth;
00746     }
00747 
00748 //  m_pView = pActiveRR->GetRenderView();
00749 //  m_pView = View::GetCurrent();
00750 //  if (m_pView)
00751 //  {
00752 //      TRACEUSER( "Gerry", _T("Forcing default context\n"));
00753 //      m_bOldForce = m_pView->SetForceDefaultColourContexts();
00754 //  }
00755 
00756     m_pNewGD = new GDrawAsm;
00757     if (m_pNewGD && m_pNewGD->Init())
00758     {
00759         // Save current device context
00760         m_pOldGD = GRenderRegion::SetTempDrawContext(m_pNewGD);
00761 //      m_pOldGD = GRenderRegion::GetStaticDrawContext();
00762 //      GRenderRegion::GD = pGDAsm;
00763     }
00764 
00765     // Setup a new GRenderDIB (NB also initialises memory).
00766     m_pNewRR = CreateGRenderDIB(ResFactor, AreaOfDocumentToRender, bpp, NeedsTransp, &SourceMat);
00767     if (m_pNewRR != NULL)
00768     {
00769         return TRUE;
00770     }
00771 
00772     // If we get here then we have failed so clean up and return false
00773     delete m_pNewGD;
00774     m_pNewGD = NULL;
00775     GRenderRegion::SetTempDrawContext(m_pOldGD);
00776     m_pOldGD = NULL;
00777     return FALSE;
00778 }
00779 
00780 /********************************************************************************************
00781 >   ConcurrentRenderer::
00782     Author:     Ilan_Copelyn (Xara Group Ltd) <camelotdev@xara.com>
00783     Created:    4/02/2000
00784     Purpose:    
00785     SeeAlso:    QuickRenderer::RestorePreviousRendererState()
00786  ********************************************************************************************/
00787 BOOL ConcurrentRenderer::RestorePreviousRendererState()
00788 {
00789     // Dismantle the GRenderDIB render region we created
00790     // WHILE it's still in the temp GDraw Context that we created before we created 
00791     // the GRenderDIB
00792     QuickRenderer::RestoreSimple();
00793 
00794     // Now restore the device context's state, and free the memory used
00795     if(!m_pOldGD)
00796     {
00797         ERROR2(FALSE,"State of previous device context was not saved.");
00798     }
00799     else
00800     {
00801         if (GRenderRegion::SetTempDrawContext(m_pOldGD) != m_pNewGD)
00802         {
00803             TRACEUSER( "Gerry", _T("Not m_pNewGD when restoring\n"));
00804         }
00805         m_pOldGD = NULL;
00806         delete m_pNewGD;
00807         m_pNewGD = NULL;
00808     }
00809 
00810     // Behave like other versions of this function and delete ourselves (urgh)
00811     delete this;
00812 
00813     return TRUE;
00814 }
00815 

Generated on Sat Nov 10 03:48:40 2007 for Camelot by  doxygen 1.4.4