Skip to content

Commit

Permalink
Fix canvas replace buffer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
onecoolx committed Dec 31, 2016
1 parent b8d2ab9 commit 804b276
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
Justin Oh [email protected] ----- Bug fix
Rain [email protected] ----- Win32 Platform bug fix
Mic_Zhang [email protected] ----- Bug fix
Zeronavi [email protected] ----- Test and bug report
1 change: 1 addition & 0 deletions src/gfx/gfx_painter.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ inline void gfx_painter<Pixfmt>::attach(abstract_rendering_buffer* buffer)
if (buffer) {
m_fmt.attach(*static_cast<gfx_rendering_buffer*>(buffer));
m_rb.attach(m_fmt);
static_cast<gfx_rendering_buffer*>(buffer)->set_buffer_observer(&m_rb);
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/gfx/gfx_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace gfx {

// graphics renderer with clip.
template <typename PixelFormat>
class gfx_renderer
class gfx_renderer : public gfx_rendering_buffer::gfx_buffer_observer
{
public:
typedef PixelFormat pixfmt_type;
Expand All @@ -34,11 +34,17 @@ class gfx_renderer
{
}

~gfx_renderer()
virtual ~gfx_renderer()
{
m_clip_path.reset();
}

virtual void buffer_notify(void)
{
// reset clip_rect
m_clip_rect = rect(0, 0, m_pixfmt->width() - 1, m_pixfmt->height() - 1);
}

void attach(pixfmt_type& fmt)
{
m_pixfmt = &fmt;
Expand Down
7 changes: 7 additions & 0 deletions src/gfx/gfx_rendering_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ gfx_rendering_buffer::gfx_rendering_buffer()

gfx_rendering_buffer::gfx_rendering_buffer(byte* ptr, unsigned int width, unsigned int height, int stride)
: m_buffer(0)
, m_observer(0)
, m_width(0)
, m_height(0)
, m_stride(0)
Expand All @@ -32,6 +33,12 @@ gfx_rendering_buffer::gfx_rendering_buffer(byte* ptr, unsigned int width, unsign
init(ptr, width, height, stride);
}

void gfx_rendering_buffer::replace(byte* ptr, unsigned int width, unsigned int height, int stride)
{
init(ptr, width, height, stride);
notify_buffer_changed();
}

void gfx_rendering_buffer::init(byte* ptr, unsigned int width, unsigned int height, int stride)
{
m_buffer = ptr;
Expand Down
11 changes: 11 additions & 0 deletions src/gfx/gfx_rendering_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ class gfx_rendering_buffer : public abstract_rendering_buffer
}
} row_data;

class gfx_buffer_observer
{
public:
virtual ~gfx_buffer_observer() {}
virtual void buffer_notify(void) = 0;
};

gfx_rendering_buffer();
gfx_rendering_buffer(byte* ptr, unsigned int width, unsigned int height, int stride);

virtual void init(byte* ptr, unsigned int width, unsigned int height, int stride);
virtual void replace(byte* ptr, unsigned int width, unsigned int height, int stride);

virtual unsigned int width(void) const { return m_width; }
virtual unsigned int height(void) const { return m_height; }
Expand Down Expand Up @@ -66,11 +74,14 @@ class gfx_rendering_buffer : public abstract_rendering_buffer
unsigned int internal_height(void) const { return m_height; }
int internal_stride(void) const { return m_stride; }

void set_buffer_observer(gfx_buffer_observer* o) { m_observer = o; }
void notify_buffer_changed(void) { if (m_observer) m_observer->buffer_notify(); }
private:
gfx_rendering_buffer(const gfx_rendering_buffer&);
gfx_rendering_buffer& operator=(const gfx_rendering_buffer&);

byte* m_buffer;
gfx_buffer_observer* m_observer;
pod_array<byte*> m_rows;
unsigned int m_width; // width in pixels
unsigned int m_height; // height in pixels
Expand Down
1 change: 1 addition & 0 deletions src/include/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class abstract_rendering_buffer
virtual ~abstract_rendering_buffer() {}

virtual void init(byte* ptr, unsigned int width, unsigned int height, int stride) = 0;
virtual void replace(byte* ptr, unsigned int width, unsigned int height, int stride) = 0;

virtual unsigned int width(void) const = 0;
virtual unsigned int height(void) const = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/picasso_rendering_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void rendering_buffer::attach(byte* buf, unsigned int width, unsigned int height

void rendering_buffer::replace(byte* buf, unsigned int width, unsigned int height, int stride)
{
m_impl->init(buf, width, height, stride);
m_impl->replace(buf, width, height, stride);
}

bool rendering_buffer::is_empty(void)
Expand Down

0 comments on commit 804b276

Please sign in to comment.