summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKrzysztof Kowalczyk <kkowalczyk@tlapx60ubu.(none)>2007-09-21 05:20:16 -0700
committerKrzysztof Kowalczyk <kkowalczyk@tlapx60ubu.(none)>2007-09-21 05:20:16 -0700
commit617550199762fab42ca2e202e641e047b3efbac0 (patch)
tree9a9701ec5468c158af03ef05a96a256a1f3adfac /test
parentfb5bf808b88992c1772a10e4ed9fe788fb618417 (diff)
simplify perf-test code
Diffstat (limited to 'test')
-rwxr-xr-x[-rw-r--r--]test/perf-test-pdf-engine.h67
-rwxr-xr-x[-rw-r--r--]test/perf-test-preview-dummy.cc3
-rwxr-xr-x[-rw-r--r--]test/perf-test-preview-win.cc80
-rwxr-xr-x[-rw-r--r--]test/perf-test.cc114
4 files changed, 86 insertions, 178 deletions
diff --git a/test/perf-test-pdf-engine.h b/test/perf-test-pdf-engine.h
index d000226c..7c454aa6 100644..100755
--- a/test/perf-test-pdf-engine.h
+++ b/test/perf-test-pdf-engine.h
@@ -37,55 +37,16 @@ private:
double m_dy;
};
-/* Abstract class representing cached bitmap. Allows different implementations
- on different platforms. */
-class RenderedBitmap {
+class PdfEnginePoppler {
public:
- virtual ~RenderedBitmap() {};
- virtual int dx() = 0;
- virtual int dy() = 0;
- virtual int rowSize() = 0;
- virtual unsigned char *data() = 0;
-
-#ifdef WIN32
- // TODO: this is for WINDOWS only
- virtual HBITMAP createDIBitmap(HDC) = 0;
- virtual void stretchDIBits(HDC, int, int, int, int) = 0;
-#endif
-};
-
-class RenderedBitmapSplash : public RenderedBitmap {
-public:
- RenderedBitmapSplash(SplashBitmap *);
- virtual ~RenderedBitmapSplash();
-
- virtual int dx();
- virtual int dy();
- virtual int rowSize();
- virtual unsigned char *data();
-
-#ifdef WIN32
- virtual HBITMAP createDIBitmap(HDC);
- virtual void stretchDIBits(HDC, int, int, int, int);
-#endif
-protected:
- SplashBitmap *_bitmap;
-};
-
-class PdfEngine {
-public:
- PdfEngine() :
- _fileName(0)
- , _pageCount(INVALID_PAGE_NO)
- { }
-
- virtual ~PdfEngine() { free((void*)_fileName); }
+ PdfEnginePoppler();
+ ~PdfEnginePoppler();
const char *fileName(void) const { return _fileName; };
void setFileName(const char *fileName) {
assert(!_fileName);
- _fileName = (const char*)strdup(fileName);
+ _fileName = (char*)strdup(fileName);
}
bool validPageNo(int pageNo) const {
@@ -96,32 +57,18 @@ public:
int pageCount(void) const { return _pageCount; }
- virtual bool load(const char *fileName) = 0;
- virtual int pageRotation(int pageNo) = 0;
- virtual SizeD pageSize(int pageNo) = 0;
- virtual RenderedBitmap *renderBitmap(int pageNo, double zoomReal, int rotation,
- BOOL (*abortCheckCbkA)(void *data),
- void *abortCheckCbkDataA) = 0;
-
-protected:
- const char *_fileName;
- int _pageCount;
-};
-
-class PdfEnginePoppler : public PdfEngine {
-public:
- PdfEnginePoppler();
- virtual ~PdfEnginePoppler();
virtual bool load(const char *fileName);
virtual int pageRotation(int pageNo);
virtual SizeD pageSize(int pageNo);
- virtual RenderedBitmap *renderBitmap(int pageNo, double zoomReal, int rotation,
+ virtual SplashBitmap *renderBitmap(int pageNo, double zoomReal, int rotation,
BOOL (*abortCheckCbkA)(void *data),
void *abortCheckCbkDataA);
PDFDoc* pdfDoc() { return _pdfDoc; }
SplashOutputDev * outputDevice();
private:
+ char *_fileName;
+ int _pageCount;
PDFDoc * _pdfDoc;
SplashOutputDev * _outputDev;
diff --git a/test/perf-test-preview-dummy.cc b/test/perf-test-preview-dummy.cc
index 63604867..10c55181 100644..100755
--- a/test/perf-test-preview-dummy.cc
+++ b/test/perf-test-preview-dummy.cc
@@ -6,9 +6,8 @@ Using this perf-test still works for performance testing, you just don't
get any visual feedback during testing.
*/
-#include "perf-test-pdf-engine.h"
-void PreviewBitmapSplash(RenderedBitmap *bmpSplash)
+void PreviewBitmapSplash(SplashBitmap *bmpSplash)
{
}
diff --git a/test/perf-test-preview-win.cc b/test/perf-test-preview-win.cc
index fdb11bd6..5f3f09b0 100644..100755
--- a/test/perf-test-preview-win.cc
+++ b/test/perf-test-preview-win.cc
@@ -3,6 +3,8 @@
/* This is a preview support for perf-test for Windows */
+#include <windows.h>
+
#include "perf-test-pdf-engine.h"
#include <assert.h>
@@ -13,7 +15,7 @@
static HWND gHwndSplash;
static HBRUSH gBrushBg;
-static RenderedBitmap *gBmpSplash;
+static SplashBitmap *gBmpSplash;
int rect_dx(RECT *r)
{
@@ -29,6 +31,60 @@ int rect_dy(RECT *r)
return dy;
}
+static HBITMAP createDIBitmapCommon(SplashBitmap *bmp, HDC hdc)
+{
+ int bmpDx = bmp->getWidth();
+ int bmpDy = bmp->getHeight();
+ int bmpRowSize = bmp->getRowSize();
+
+ BITMAPINFOHEADER bmih;
+ bmih.biSize = sizeof(bmih);
+ bmih.biHeight = -bmpDy;
+ bmih.biWidth = bmpDx;
+ bmih.biPlanes = 1;
+ bmih.biBitCount = 24;
+ bmih.biCompression = BI_RGB;
+ bmih.biSizeImage = bmpDy * bmpRowSize;;
+ bmih.biXPelsPerMeter = bmih.biYPelsPerMeter = 0;
+ bmih.biClrUsed = bmih.biClrImportant = 0;
+
+ unsigned char* bmpData = bmp->getDataPtr();
+ HBITMAP hbmp = ::CreateDIBitmap(hdc, &bmih, CBM_INIT, bmpData, (BITMAPINFO *)&bmih , DIB_RGB_COLORS);
+ return hbmp;
+}
+
+static void stretchDIBitsCommon(SplashBitmap *bmp, HDC hdc, int leftMargin, int topMargin, int pageDx, int pageDy)
+{
+ int bmpDx = bmp->getWidth();
+ int bmpDy = bmp->getHeight();
+ int bmpRowSize = bmp->getRowSize();
+
+ BITMAPINFOHEADER bmih;
+ bmih.biSize = sizeof(bmih);
+ bmih.biHeight = -bmpDy;
+ bmih.biWidth = bmpDx;
+ bmih.biPlanes = 1;
+ // we could create this dibsection in monochrome
+ // if the printer is monochrome, to reduce memory consumption
+ // but splash is currently setup to return a full colour bitmap
+ bmih.biBitCount = 24;
+ bmih.biCompression = BI_RGB;
+ bmih.biSizeImage = bmpDy * bmpRowSize;;
+ bmih.biXPelsPerMeter = bmih.biYPelsPerMeter = 0;
+ bmih.biClrUsed = bmih.biClrImportant = 0;
+ SplashColorPtr bmpData = bmp->getDataPtr();
+
+ ::StretchDIBits(hdc,
+ // destination rectangle
+ -leftMargin, -topMargin, pageDx, pageDy,
+ // source rectangle
+ 0, 0, bmpDx, bmpDy,
+ bmpData,
+ (BITMAPINFO *)&bmih ,
+ DIB_RGB_COLORS,
+ SRCCOPY);
+}
+
/* Set the client area size of the window 'hwnd' to 'dx'/'dy'. */
static void resizeClientArea(HWND hwnd, int x, int dx, int dy, int *dx_out)
{
@@ -46,14 +102,14 @@ static void resizeClientArea(HWND hwnd, int x, int dx, int dy, int *dx_out)
*dx_out = win_dx;
}
-static void resizeClientAreaToRenderedBitmap(HWND hwnd, RenderedBitmap *bmp, int x, int *dxOut)
+static void resizeClientAreaToRenderedBitmap(HWND hwnd, SplashBitmap *bmp, int x, int *dxOut)
{
- int dx = bmp->dx();
- int dy = bmp->dy();
+ int dx = bmp->getWidth();
+ int dy = bmp->getHeight();
resizeClientArea(hwnd, x, dx, dy, dxOut);
}
-static void drawBitmap(HWND hwnd, RenderedBitmap *bmp)
+static void drawBitmap(HWND hwnd, SplashBitmap *bmp)
{
PAINTSTRUCT ps;
@@ -61,15 +117,15 @@ static void drawBitmap(HWND hwnd, RenderedBitmap *bmp)
SetBkMode(hdc, TRANSPARENT);
FillRect(hdc, &ps.rcPaint, gBrushBg);
- HBITMAP hbmp = bmp->createDIBitmap(hdc);
+ HBITMAP hbmp = createDIBitmapCommon(bmp, hdc);
if (hbmp) {
HDC bmpDC = CreateCompatibleDC(hdc);
if (bmpDC) {
SelectObject(bmpDC, hbmp);
int xSrc = 0, ySrc = 0;
int xDest = 0, yDest = 0;
- int bmpDx = bmp->dx();
- int bmpDy = bmp->dy();
+ int bmpDx = bmp->getWidth();
+ int bmpDy = bmp->getHeight();
BitBlt(hdc, xDest, yDest, bmpDx, bmpDy, bmpDC, xSrc, ySrc, SRCCOPY);
DeleteDC(bmpDC);
bmpDC = NULL;
@@ -82,9 +138,11 @@ static void drawBitmap(HWND hwnd, RenderedBitmap *bmp)
static void onPaint(HWND hwnd)
{
- if (hwnd == gHwndSplash)
- if (gBmpSplash)
+ if (hwnd == gHwndSplash) {
+ if (gBmpSplash) {
drawBitmap(hwnd, gBmpSplash);
+ }
+ }
}
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
@@ -209,7 +267,7 @@ static void UpdateWindows(void)
pumpMessages();
}
-void PreviewBitmapSplash(RenderedBitmap *bmpSplash)
+void PreviewBitmapSplash(SplashBitmap *bmpSplash)
{
if (!initWinIfNecessary())
return;
diff --git a/test/perf-test.cc b/test/perf-test.cc
index 1f0991a9..46a6d6b9 100644..100755
--- a/test/perf-test.cc
+++ b/test/perf-test.cc
@@ -48,7 +48,7 @@ typedef BOOL int;
*/
extern void PreviewBitmapInit(void);
extern void PreviewBitmapDestroy(void);
-extern void PreviewBitmapSplash(RenderedBitmap *bmpSplash);
+extern void PreviewBitmapSplash(SplashBitmap *bmpSplash);
typedef struct StrList {
struct StrList *next;
@@ -401,103 +401,9 @@ void SplashColorsInit(void)
splashColorSet(SPLASH_COL_WHITE_PTR, 0xff, 0xff, 0xff, 0);
}
-RenderedBitmapSplash::RenderedBitmapSplash(SplashBitmap *bitmap)
-{
- _bitmap = bitmap;
-}
-
-RenderedBitmapSplash::~RenderedBitmapSplash() {
- delete _bitmap;
-}
-
-int RenderedBitmapSplash::dx()
-{
- return _bitmap->getWidth();
-}
-
-int RenderedBitmapSplash::dy()
-{
- return _bitmap->getHeight();
-}
-
-int RenderedBitmapSplash::rowSize()
-{
- return _bitmap->getRowSize();
-}
-
-unsigned char *RenderedBitmapSplash::data()
-{
- return _bitmap->getDataPtr();
-}
-
-#ifdef WIN32
-static HBITMAP createDIBitmapCommon(RenderedBitmap *bmp, HDC hdc)
-{
- int bmpDx = bmp->dx();
- int bmpDy = bmp->dy();
- int bmpRowSize = bmp->rowSize();
-
- BITMAPINFOHEADER bmih;
- bmih.biSize = sizeof(bmih);
- bmih.biHeight = -bmpDy;
- bmih.biWidth = bmpDx;
- bmih.biPlanes = 1;
- bmih.biBitCount = 24;
- bmih.biCompression = BI_RGB;
- bmih.biSizeImage = bmpDy * bmpRowSize;;
- bmih.biXPelsPerMeter = bmih.biYPelsPerMeter = 0;
- bmih.biClrUsed = bmih.biClrImportant = 0;
-
- unsigned char* bmpData = bmp->data();
- HBITMAP hbmp = ::CreateDIBitmap(hdc, &bmih, CBM_INIT, bmpData, (BITMAPINFO *)&bmih , DIB_RGB_COLORS);
- return hbmp;
-}
-
-static void stretchDIBitsCommon(RenderedBitmap *bmp, HDC hdc, int leftMargin, int topMargin, int pageDx, int pageDy)
-{
- int bmpDx = bmp->dx();
- int bmpDy = bmp->dy();
- int bmpRowSize = bmp->rowSize();
-
- BITMAPINFOHEADER bmih;
- bmih.biSize = sizeof(bmih);
- bmih.biHeight = -bmpDy;
- bmih.biWidth = bmpDx;
- bmih.biPlanes = 1;
- // we could create this dibsection in monochrome
- // if the printer is monochrome, to reduce memory consumption
- // but splash is currently setup to return a full colour bitmap
- bmih.biBitCount = 24;
- bmih.biCompression = BI_RGB;
- bmih.biSizeImage = bmpDy * bmpRowSize;;
- bmih.biXPelsPerMeter = bmih.biYPelsPerMeter = 0;
- bmih.biClrUsed = bmih.biClrImportant = 0;
- SplashColorPtr bmpData = bmp->data();
-
- ::StretchDIBits(hdc,
- // destination rectangle
- -leftMargin, -topMargin, pageDx, pageDy,
- // source rectangle
- 0, 0, bmpDx, bmpDy,
- bmpData,
- (BITMAPINFO *)&bmih ,
- DIB_RGB_COLORS,
- SRCCOPY);
-}
-
-HBITMAP RenderedBitmapSplash::createDIBitmap(HDC hdc)
-{
- return createDIBitmapCommon(this, hdc);
-}
-
-void RenderedBitmapSplash::stretchDIBits(HDC hdc, int leftMargin, int topMargin, int pageDx, int pageDy)
-{
- stretchDIBitsCommon(this, hdc, leftMargin, topMargin, pageDx, pageDy);
-}
-#endif
-
PdfEnginePoppler::PdfEnginePoppler() :
- PdfEngine()
+ _fileName(0)
+ , _pageCount(INVALID_PAGE_NO)
, _pdfDoc(NULL)
, _outputDev(NULL)
{
@@ -505,6 +411,7 @@ PdfEnginePoppler::PdfEnginePoppler() :
PdfEnginePoppler::~PdfEnginePoppler()
{
+ free(_fileName);
delete _outputDev;
delete _pdfDoc;
}
@@ -547,7 +454,7 @@ SplashOutputDev * PdfEnginePoppler::outputDevice() {
return _outputDev;
}
-RenderedBitmap *PdfEnginePoppler::renderBitmap(
+SplashBitmap *PdfEnginePoppler::renderBitmap(
int pageNo, double zoomReal, int rotation,
BOOL (*abortCheckCbkA)(void *data),
void *abortCheckCbkDataA)
@@ -564,10 +471,7 @@ RenderedBitmap *PdfEnginePoppler::renderBitmap(
abortCheckCbkA, abortCheckCbkDataA);
SplashBitmap* bmp = _outputDev->takeBitmap();
- if (bmp)
- return new RenderedBitmapSplash(bmp);
-
- return NULL;
+ return bmp;
}
struct FindFileState {
@@ -1015,7 +919,7 @@ Exit:
static void RenderPdf(const char *fileName)
{
const char *fileNameSplash = NULL;
- PdfEngine * engineSplash = NULL;
+ PdfEnginePoppler * engineSplash = NULL;
// TODO: fails if file already exists and has read-only attribute
CopyFile(fileName, POPPLER_TMP_NAME, FALSE);
@@ -1041,7 +945,7 @@ static void RenderPdf(const char *fileName)
if ((gPageNo != PAGE_NO_NOT_GIVEN) && (gPageNo != curPage))
continue;
- RenderedBitmap *bmpSplash = NULL;
+ SplashBitmap *bmpSplash = NULL;
MsTimer msTimer;
bmpSplash = engineSplash->renderBitmap(curPage, 100.0, 0, NULL, NULL);
@@ -1051,7 +955,7 @@ static void RenderPdf(const char *fileName)
if (!bmpSplash)
LogInfo("page splash %d: failed to render\n", curPage);
else
- LogInfo("page splash %d (%dx%d): %.2f ms\n", curPage, bmpSplash->dx(), bmpSplash->dy(), timeInMs);
+ LogInfo("page splash %d (%dx%d): %.2f ms\n", curPage, bmpSplash->getWidth(), bmpSplash->getHeight(), timeInMs);
if (ShowPreview()) {
PreviewBitmapSplash(bmpSplash);