From 2e5a10608394186fd1324c97b17d7f08e0c0aaf6 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Thu, 30 Jan 2014 17:57:27 +0100 Subject: [PATCH] Get rid of getStride() It was confusing and not properly used everywhere. Callers should use the stride they get when they get the buffer pointer. --- common/rfb/PixelBuffer.cxx | 17 ++++++++--------- common/rfb/PixelBuffer.h | 8 +++----- unix/x0vncserver/XPixelBuffer.cxx | 5 ++--- unix/x0vncserver/XPixelBuffer.h | 6 ------ unix/xserver/hw/vnc/XserverDesktop.cc | 11 +++-------- unix/xserver/hw/vnc/XserverDesktop.h | 2 -- vncviewer/FLTKPixelBuffer.cxx | 4 ++-- vncviewer/OSXPixelBuffer.cxx | 2 +- vncviewer/PlatformPixelBuffer.cxx | 4 ++-- vncviewer/PlatformPixelBuffer.h | 4 +--- vncviewer/Win32PixelBuffer.cxx | 2 +- vncviewer/X11PixelBuffer.cxx | 8 ++------ vncviewer/X11PixelBuffer.h | 2 -- win/rfb_win32/DIBSectionBuffer.h | 3 --- 14 files changed, 25 insertions(+), 53 deletions(-) diff --git a/common/rfb/PixelBuffer.cxx b/common/rfb/PixelBuffer.cxx index ace0934d..ea19d183 100644 --- a/common/rfb/PixelBuffer.cxx +++ b/common/rfb/PixelBuffer.cxx @@ -1,4 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * Copyright 2014 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -61,8 +62,8 @@ PixelBuffer::getImage(void* imageBuf, const Rect& r, int outStride) { FullFramePixelBuffer::FullFramePixelBuffer(const PixelFormat& pf, int w, int h, - rdr::U8* data_) - : PixelBuffer(pf, w, h), data(data_) + rdr::U8* data_, int stride_) + : PixelBuffer(pf, w, h), data(data_), stride(stride_) { } @@ -71,12 +72,10 @@ FullFramePixelBuffer::FullFramePixelBuffer() : data(0) {} FullFramePixelBuffer::~FullFramePixelBuffer() {} -int FullFramePixelBuffer::getStride() const { return width(); } - -rdr::U8* FullFramePixelBuffer::getBufferRW(const Rect& r, int* stride) +rdr::U8* FullFramePixelBuffer::getBufferRW(const Rect& r, int* stride_) { - *stride = getStride(); - return &data[(r.tl.x + (r.tl.y * *stride)) * format.bpp/8]; + *stride_ = stride; + return &data[(r.tl.x + (r.tl.y * stride)) * format.bpp/8]; } @@ -255,7 +254,7 @@ ManagedPixelBuffer::ManagedPixelBuffer() }; ManagedPixelBuffer::ManagedPixelBuffer(const PixelFormat& pf, int w, int h) - : FullFramePixelBuffer(pf, w, h, 0), datasize(0) + : FullFramePixelBuffer(pf, w, h, NULL, w), datasize(0) { checkDataSize(); }; @@ -271,7 +270,7 @@ ManagedPixelBuffer::setPF(const PixelFormat &pf) { }; void ManagedPixelBuffer::setSize(int w, int h) { - width_ = w; height_ = h; checkDataSize(); + width_ = w; height_ = h; stride = w; checkDataSize(); }; diff --git a/common/rfb/PixelBuffer.h b/common/rfb/PixelBuffer.h index 94230247..59d71c79 100644 --- a/common/rfb/PixelBuffer.h +++ b/common/rfb/PixelBuffer.h @@ -1,4 +1,5 @@ /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. + * Copyright 2014 Pierre Ossman for Cendio AB * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -93,14 +94,10 @@ namespace rfb { class FullFramePixelBuffer : public PixelBuffer { public: FullFramePixelBuffer(const PixelFormat& pf, int width, int height, - rdr::U8* data_); + rdr::U8* data, int stride); virtual ~FullFramePixelBuffer(); public: - // - Get the number of pixels per row in the actual pixel buffer data area - // This may in some cases NOT be the same as width(). - virtual int getStride() const; - // Get a pointer to specified pixel data virtual const rdr::U8* getBuffer(const Rect& r, int* stride) { return getBufferRW(r, stride); @@ -134,6 +131,7 @@ namespace rfb { FullFramePixelBuffer(); rdr::U8* data; + int stride; }; // -=- Managed pixel buffer class diff --git a/unix/x0vncserver/XPixelBuffer.cxx b/unix/x0vncserver/XPixelBuffer.cxx index f88eda49..f4641825 100644 --- a/unix/x0vncserver/XPixelBuffer.cxx +++ b/unix/x0vncserver/XPixelBuffer.cxx @@ -35,8 +35,7 @@ XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory, m_dpy(dpy), m_image(factory.newImage(dpy, rect.width(), rect.height())), m_offsetLeft(rect.tl.x), - m_offsetTop(rect.tl.y), - m_stride(0) + m_offsetTop(rect.tl.y) { // Fill in the PixelFormat structure of the parent class. format = PixelFormat(m_image->xim->bits_per_pixel, @@ -57,7 +56,7 @@ XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory, // Calculate the distance in pixels between two subsequent scan // lines of the framebuffer. This may differ from image width. - m_stride = m_image->xim->bytes_per_line * 8 / m_image->xim->bits_per_pixel; + stride = m_image->xim->bytes_per_line * 8 / m_image->xim->bits_per_pixel; // Get initial screen image from the X display. m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop); diff --git a/unix/x0vncserver/XPixelBuffer.h b/unix/x0vncserver/XPixelBuffer.h index ab4f88e5..da031615 100644 --- a/unix/x0vncserver/XPixelBuffer.h +++ b/unix/x0vncserver/XPixelBuffer.h @@ -46,9 +46,6 @@ public: // Detect changed pixels, notify the server. inline void poll(VNCServer *server) { m_poller->poll(server); } - // Override PixelBuffer::getStride(). - virtual int getStride() const { return m_stride; } - // Override PixelBuffer::grabRegion(). virtual void grabRegion(const rfb::Region& region); @@ -60,9 +57,6 @@ protected: int m_offsetLeft; int m_offsetTop; - // The number of pixels in a row, with padding included. - int m_stride; - // Copy pixels from the screen to the pixel buffer, // for the specified rectangular area of the buffer. inline void grabRect(const Rect &r) { diff --git a/unix/xserver/hw/vnc/XserverDesktop.cc b/unix/xserver/hw/vnc/XserverDesktop.cc index e53dccde..f93cf658 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.cc +++ b/unix/xserver/hw/vnc/XserverDesktop.cc @@ -177,7 +177,7 @@ void XserverDesktop::unblockUpdates() server->unblockUpdates(); } -void XserverDesktop::setFramebuffer(int w, int h, void* fbptr, int stride) +void XserverDesktop::setFramebuffer(int w, int h, void* fbptr, int stride_) { ScreenSet layout; @@ -191,12 +191,12 @@ void XserverDesktop::setFramebuffer(int w, int h, void* fbptr, int stride) if (!fbptr) { fbptr = new rdr::U8[w * h * (format.bpp/8)]; - stride = w; + stride_ = w; directFbptr = false; } data = (rdr::U8*)fbptr; - stride_ = stride; + stride = stride_; layout = computeScreenLayout(); @@ -1044,11 +1044,6 @@ void XserverDesktop::grabRegion(const rfb::Region& region) grabbing = false; } -int XserverDesktop::getStride() const -{ - return stride_; -} - void XserverDesktop::keyEvent(rdr::U32 keysym, bool down) { if (down) diff --git a/unix/xserver/hw/vnc/XserverDesktop.h b/unix/xserver/hw/vnc/XserverDesktop.h index fa03d8ab..046f31f1 100644 --- a/unix/xserver/hw/vnc/XserverDesktop.h +++ b/unix/xserver/hw/vnc/XserverDesktop.h @@ -109,7 +109,6 @@ public: // rfb::PixelBuffer callbacks virtual void grabRegion(const rfb::Region& r); - virtual int getStride() const; // rdr::Substitutor callback virtual char* substitute(const char* varName); @@ -131,7 +130,6 @@ private: rfb::HTTPServer* httpServer; network::TcpListener* listener; network::TcpListener* httpListener; - int stride_; bool deferredUpdateTimerSet; bool grabbing; bool ignoreHooks_; diff --git a/vncviewer/FLTKPixelBuffer.cxx b/vncviewer/FLTKPixelBuffer.cxx index 91ff787e..588e2f83 100644 --- a/vncviewer/FLTKPixelBuffer.cxx +++ b/vncviewer/FLTKPixelBuffer.cxx @@ -25,7 +25,7 @@ FLTKPixelBuffer::FLTKPixelBuffer(int width, int height) : PlatformPixelBuffer(rfb::PixelFormat(32, 24, false, true, 255, 255, 255, 0, 8, 16), - width, height, NULL) + width, height, NULL, width) { data = new rdr::U8[width * height * format.bpp/8]; if (data == NULL) @@ -43,7 +43,7 @@ void FLTKPixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h) const uchar *buf_start; pixel_bytes = format.bpp/8; - stride_bytes = pixel_bytes * getStride(); + stride_bytes = pixel_bytes * stride; buf_start = data + pixel_bytes * src_x + stride_bytes * src_y; diff --git a/vncviewer/OSXPixelBuffer.cxx b/vncviewer/OSXPixelBuffer.cxx index fc216a12..d196497f 100644 --- a/vncviewer/OSXPixelBuffer.cxx +++ b/vncviewer/OSXPixelBuffer.cxx @@ -39,7 +39,7 @@ static rfb::LogWriter vlog("OSXPixelBuffer"); OSXPixelBuffer::OSXPixelBuffer(int width, int height) : PlatformPixelBuffer(rfb::PixelFormat(32, 24, false, true, 255, 255, 255, 16, 8, 0), - width, height, NULL), + width, height, NULL, width), bitmap(NULL) { CGColorSpaceRef lut; diff --git a/vncviewer/PlatformPixelBuffer.cxx b/vncviewer/PlatformPixelBuffer.cxx index 8a24690c..ced04467 100644 --- a/vncviewer/PlatformPixelBuffer.cxx +++ b/vncviewer/PlatformPixelBuffer.cxx @@ -20,7 +20,7 @@ PlatformPixelBuffer::PlatformPixelBuffer(const rfb::PixelFormat& pf, int width, int height, - rdr::U8* data) : - FullFramePixelBuffer(pf, width, height, data) + rdr::U8* data, int stride) : + FullFramePixelBuffer(pf, width, height, data, stride) { } diff --git a/vncviewer/PlatformPixelBuffer.h b/vncviewer/PlatformPixelBuffer.h index 28d085aa..03842ac8 100644 --- a/vncviewer/PlatformPixelBuffer.h +++ b/vncviewer/PlatformPixelBuffer.h @@ -24,12 +24,10 @@ class PlatformPixelBuffer: public rfb::FullFramePixelBuffer { public: PlatformPixelBuffer(const rfb::PixelFormat& pf, int width, int height, - rdr::U8* data); + rdr::U8* data, int stride); virtual void draw(int src_x, int src_y, int x, int y, int w, int h) = 0; -protected: - int stride; }; #endif diff --git a/vncviewer/Win32PixelBuffer.cxx b/vncviewer/Win32PixelBuffer.cxx index 429f63f1..9fb04145 100644 --- a/vncviewer/Win32PixelBuffer.cxx +++ b/vncviewer/Win32PixelBuffer.cxx @@ -40,7 +40,7 @@ static rfb::LogWriter vlog("Win32PixelBuffer"); Win32PixelBuffer::Win32PixelBuffer(int width, int height) : PlatformPixelBuffer(rfb::PixelFormat(32, 24, false, true, 255, 255, 255, 16, 8, 0), - width, height, NULL), + width, height, NULL, width), bitmap(NULL) { BITMAPINFOHEADER bih; diff --git a/vncviewer/X11PixelBuffer.cxx b/vncviewer/X11PixelBuffer.cxx index 3675eb57..c709984b 100644 --- a/vncviewer/X11PixelBuffer.cxx +++ b/vncviewer/X11PixelBuffer.cxx @@ -94,7 +94,7 @@ static PixelFormat display_pf() } X11PixelBuffer::X11PixelBuffer(int width, int height) : - PlatformPixelBuffer(display_pf(), width, height, NULL), + PlatformPixelBuffer(display_pf(), width, height, NULL, 0), shminfo(NULL), xim(NULL) { // Might not be open at this point @@ -110,6 +110,7 @@ X11PixelBuffer::X11PixelBuffer(int width, int height) : } data = (rdr::U8*)xim->data; + stride = xim->bytes_per_line / (getPF().bpp/8); } @@ -139,11 +140,6 @@ void X11PixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h) } -int X11PixelBuffer::getStride() const -{ - return xim->bytes_per_line / (getPF().bpp/8); -} - static bool caughtError; static int XShmAttachErrorHandler(Display *dpy, XErrorEvent *error) diff --git a/vncviewer/X11PixelBuffer.h b/vncviewer/X11PixelBuffer.h index 6d54165f..c2ffdc28 100644 --- a/vncviewer/X11PixelBuffer.h +++ b/vncviewer/X11PixelBuffer.h @@ -33,8 +33,6 @@ public: virtual void draw(int src_x, int src_y, int x, int y, int w, int h); - int getStride() const; - protected: int setupShm(); diff --git a/win/rfb_win32/DIBSectionBuffer.h b/win/rfb_win32/DIBSectionBuffer.h index 1a9ef134..cf9e7bc1 100644 --- a/win/rfb_win32/DIBSectionBuffer.h +++ b/win/rfb_win32/DIBSectionBuffer.h @@ -47,14 +47,11 @@ namespace rfb { virtual void setPF(const PixelFormat &pf); virtual void setSize(int w, int h); - virtual int getStride() const {return stride;} - // *** virtual void copyRect(const Rect &dest, const Point &move_by_delta); public: HBITMAP bitmap; protected: void recreateBuffer(); - int stride; HWND window; HDC device; }; -- 2.39.5