virtualized some Region calls.

There is a deeper issue here: regions should be handled by the graphics driver that is associated with the Fl_Window of this widget... .

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11643 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher 2016-04-17 15:36:23 +00:00
parent c9d3eabf4e
commit cdf85352c4
17 changed files with 76 additions and 35 deletions

View File

@ -114,6 +114,7 @@ protected:
public:
Fl_Graphics_Driver();
virtual ~Fl_Graphics_Driver() {}
static Fl_Graphics_Driver &default_driver();
virtual char can_do_alpha_blending() { return 0; }
// --- implementation is in src/fl_rect.cxx which includes src/drivers/xxx/Fl_xxx_Graphics_Driver_rect.cxx
virtual void point(int x, int y) = 0;
@ -245,9 +246,9 @@ public:
virtual void set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win);
virtual void reset_spot();
// each platform implements these 3 functions its own way
static void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h);
static Fl_Region XRectangleRegion(int x, int y, int w, int h);
static void XDestroyRegion(Fl_Region r);
virtual void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h);
virtual Fl_Region XRectangleRegion(int x, int y, int w, int h);
virtual void XDestroyRegion(Fl_Region r);
protected:
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx

View File

@ -686,7 +686,10 @@ void Fl::flush() {
if (!wi->visible_r()) continue;
if (wi->damage()) {i->flush(); wi->clear_damage();}
// destroy damage regions for windows that don't use them:
if (i->region) {Fl_Graphics_Driver::XDestroyRegion(i->region); i->region = 0;}
if (i->region) {
fl_graphics_driver->XDestroyRegion(i->region);
i->region = 0;
}
}
}
screen_driver()->flush();
@ -1491,7 +1494,10 @@ void Fl_Widget::damage(uchar fl) {
// damage entire window by deleting the region:
Fl_X* i = Fl_X::i((Fl_Window*)this);
if (!i) return; // window not mapped, so ignore it
if (i->region) {Fl_Graphics_Driver::XDestroyRegion(i->region); i->region = 0;}
if (i->region) {
fl_graphics_driver->XDestroyRegion(i->region);
i->region = 0;
}
damage_ |= fl;
Fl::damage(FL_DAMAGE_CHILD);
}
@ -1525,13 +1531,13 @@ void Fl_Widget::damage(uchar fl, int X, int Y, int W, int H) {
if (wi->damage()) {
// if we already have damage we must merge with existing region:
if (i->region) {
Fl_Graphics_Driver::add_rectangle_to_region(i->region, X, Y, W, H);
fl_graphics_driver->add_rectangle_to_region(i->region, X, Y, W, H);
}
wi->damage_ |= fl;
} else {
// create a new region:
if (i->region) Fl_Graphics_Driver::XDestroyRegion(i->region);
i->region = Fl_Graphics_Driver::XRectangleRegion(X,Y,W,H);
if (i->region) fl_graphics_driver->XDestroyRegion(i->region);
i->region = fl_graphics_driver->XRectangleRegion(X,Y,W,H);
wi->damage_ = fl;
}
Fl::damage(FL_DAMAGE_CHILD);

View File

@ -37,6 +37,18 @@ Fl_Graphics_Driver::Fl_Graphics_Driver() {
font_descriptor_ = NULL;
};
Fl_Graphics_Driver &Fl_Graphics_Driver::default_driver()
{
static Fl_Graphics_Driver *pMainDriver = 0L;
if (!pMainDriver) {
pMainDriver = Fl_Display_Device::display_device()->driver();
}
return *pMainDriver;
}
void Fl_Graphics_Driver::text_extents(const char*t, int n, int& dx, int& dy, int& w, int& h)
{
w = (int)width(t, n);
@ -100,6 +112,25 @@ void Fl_Graphics_Driver::free_color(Fl_Color i, int overlay)
}
void Fl_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h)
{
// nothing to do, reimplement in driver if needed
}
Fl_Region Fl_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h)
{
// nothing to do, reimplement in driver if needed
return 0;
}
void Fl_Graphics_Driver::XDestroyRegion(Fl_Region r)
{
// nothing to do, reimplement in driver if needed
}
//
// End of "$Id$".
//

View File

@ -1936,7 +1936,7 @@ static void handleUpdateEvent( Fl_Window *window )
i->wait_for_expose = 0;
if ( i->region ) {
Fl_Graphics_Driver::XDestroyRegion(i->region);
Fl_Graphics_Driver::default_driver().XDestroyRegion(i->region);
i->region = 0;
}
window->clear_damage(FL_DAMAGE_ALL);

View File

@ -239,7 +239,7 @@ void Fl_Cocoa_Window_Driver::hide() {
q_release_context(this);
if ( ip->xid == fl_window )
fl_window = 0;
if (ip->region) Fl_Graphics_Driver::XDestroyRegion(ip->region);
if (ip->region) Fl_Graphics_Driver::default_driver().XDestroyRegion(ip->region);
ip->destroy();
delete ip;
}

View File

@ -78,6 +78,9 @@ public:
void copy_offscreen_with_alpha(int x,int y,int w,int h,HBITMAP bitmap,int srcx,int srcy);
#endif
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h);
Fl_Region XRectangleRegion(int x, int y, int w, int h);
void XDestroyRegion(Fl_Region r);
protected:
void transformed_vertex0(int x, int y);
void fixloop();

View File

@ -144,7 +144,7 @@ void Fl_Translated_GDI_Graphics_Driver::untranslate_all() {
SetWindowOrgEx((HDC)gc(), origins[depth].x, origins[depth].y, NULL);
}
void Fl_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H) {
void Fl_GDI_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H) {
Fl_Region R = XRectangleRegion(X, Y, W, H);
CombineRgn(r, r, R, RGN_OR);
XDestroyRegion(R);
@ -166,7 +166,7 @@ void Fl_GDI_Graphics_Driver::fixloop() { // remove equal points from closed pat
while (n>2 && p[n-1].x == p[0].x && p[n-1].y == p[0].y) n--;
}
Fl_Region Fl_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
Fl_Region Fl_GDI_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
if (Fl_Surface_Device::surface() == Fl_Display_Device::display_device()) return CreateRectRgn(x,y,x+w,y+h);
// because rotation may apply, the rectangle becomes a polygon in device coords
POINT pt[4] = { {x, y}, {x + w, y}, {x + w, y + h}, {x, y + h} };
@ -174,16 +174,16 @@ Fl_Region Fl_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
return CreatePolygonRgn(pt, 4, ALTERNATE);
}
void Fl_Graphics_Driver::XDestroyRegion(Fl_Region r) {
void Fl_GDI_Graphics_Driver::XDestroyRegion(Fl_Region r) {
DeleteObject(r);
}
void Fl_Graphics_Driver::reset_spot()
void Fl_GDI_Graphics_Driver::reset_spot()
{
}
void Fl_Graphics_Driver::set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win)
void Fl_GDI_Graphics_Driver::set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win)
{
if (!win) return;
Fl_Window* tw = win;

View File

@ -32,12 +32,6 @@
extern Window fl_window;
void Fl_Graphics_Driver::XDestroyRegion(void*) { }
//void Fl_Graphics_Driver::clip_region(void*) { }
Fl_Region Fl_Graphics_Driver::XRectangleRegion(int, int, int, int) { }
void Fl_Graphics_Driver::add_rectangle_to_region(void*, int, int, int, int) { }
/*
* By linking this module, the following static method will instantiate the
* PicoSDL Graphics driver as the main display driver.

View File

@ -64,6 +64,9 @@ public:
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
void draw_CGImage(CGImageRef cgimg, int x, int y, int w, int h, int srcx, int srcy, int sw, int sh);
static CGRect fl_cgrectmake_cocoa(int x, int y, int w, int h);
void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h);
Fl_Region XRectangleRegion(int x, int y, int w, int h);
void XDestroyRegion(Fl_Region r);
protected:
void transformed_vertex0(float x, float y);
void fixloop();

View File

@ -76,7 +76,7 @@ CGRect Fl_Quartz_Graphics_Driver::fl_cgrectmake_cocoa(int x, int y, int w, int h
return CGRectMake(x - 0.5, y - 0.5, w, h);
}
void Fl_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H) {
void Fl_Quartz_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H) {
CGRect arg = Fl_Quartz_Graphics_Driver::fl_cgrectmake_cocoa(X, Y, W, H);
int j; // don't add a rectangle totally inside the Fl_Region
for(j = 0; j < r->count; j++) {
@ -88,7 +88,7 @@ void Fl_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int
}
}
Fl_Region Fl_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
Fl_Region Fl_Quartz_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
Fl_Region R = (Fl_Region)malloc(sizeof(*R));
R->count = 1;
R->rects = (CGRect *)malloc(sizeof(CGRect));
@ -96,7 +96,7 @@ Fl_Region Fl_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
return R;
}
void Fl_Graphics_Driver::XDestroyRegion(Fl_Region r) {
void Fl_Quartz_Graphics_Driver::XDestroyRegion(Fl_Region r) {
if(r) {
free(r->rects);
free(r);

View File

@ -202,7 +202,7 @@ void Fl_Quartz_Graphics_Driver::polygon(int x, int y, int x1, int y1, int x2, in
// intersects current and x,y,w,h rectangle and returns result as a new Fl_Region
static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h)
{
if (current == NULL) return Fl_Graphics_Driver::XRectangleRegion(x,y,w,h);
if (current == NULL) return Fl_Graphics_Driver::default_driver().XRectangleRegion(x,y,w,h);
CGRect r = Fl_Quartz_Graphics_Driver::fl_cgrectmake_cocoa(x, y, w, h);
Fl_Region outr = (Fl_Region)malloc(sizeof(*outr));
outr->count = current->count;
@ -217,8 +217,8 @@ static Fl_Region intersect_region_and_rect(Fl_Region current, int x,int y,int w,
outr->rects = (CGRect*)realloc(outr->rects, outr->count * sizeof(CGRect));
}
else {
Fl_Graphics_Driver::XDestroyRegion(outr);
outr = Fl_Graphics_Driver::XRectangleRegion(0,0,0,0);
Fl_Graphics_Driver::default_driver().XDestroyRegion(outr);
outr = Fl_Graphics_Driver::default_driver().XRectangleRegion(0,0,0,0);
}
return outr;
}

View File

@ -79,6 +79,9 @@ public:
#if ! defined(FL_DOXYGEN)
void copy_offscreen_with_alpha(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
#endif
void add_rectangle_to_region(Fl_Region r, int x, int y, int w, int h);
Fl_Region XRectangleRegion(int x, int y, int w, int h);
void XDestroyRegion(Fl_Region r);
protected:
void transformed_vertex0(short x, short y);
void fixloop();

View File

@ -96,7 +96,7 @@ void Fl_Xlib_Graphics_Driver::copy_offscreen_with_alpha(int x, int y, int w, int
#endif
void Fl_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H) {
void Fl_Xlib_Graphics_Driver::add_rectangle_to_region(Fl_Region r, int X, int Y, int W, int H) {
XRectangle R;
R.x = X; R.y = Y; R.width = W; R.height = H;
XUnionRectWithRegion(&R, r, r);

View File

@ -150,7 +150,7 @@ static int clip_x (int x) {
// Missing X call: (is this the fastest way to init a 1-rectangle region?)
// MSWindows equivalent exists, implemented inline in win32.H
Fl_Region Fl_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
Fl_Region Fl_Xlib_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
XRectangle R;
clip_to_short(x, y, w, h);
R.x = x; R.y = y; R.width = w; R.height = h;
@ -159,7 +159,7 @@ Fl_Region Fl_Graphics_Driver::XRectangleRegion(int x, int y, int w, int h) {
return r;
}
void Fl_Graphics_Driver::XDestroyRegion(Fl_Region r) {
void Fl_Xlib_Graphics_Driver::XDestroyRegion(Fl_Region r) {
::XDestroyRegion(r);
}

View File

@ -69,13 +69,13 @@ void Fl::set_color(Fl_Color i, uchar red, uchar green, uchar blue) {
void Fl::set_color(Fl_Color i, unsigned int c)
{
fl_graphics_driver->set_color(i, c);
Fl_Graphics_Driver::default_driver().set_color(i, c);
}
void Fl::free_color(Fl_Color i, int overlay)
{
fl_graphics_driver->free_color(i, overlay);
Fl_Graphics_Driver::default_driver().free_color(i, overlay);
}

View File

@ -53,12 +53,12 @@ void fl_draw(const char* str, int l, float x, float y) {
void fl_set_spot(int font, int size, int X, int Y, int W, int H, Fl_Window *win)
{
fl_graphics_driver->set_spot(font, size, X, Y, W, H, win);
Fl_Graphics_Driver::default_driver().set_spot(font, size, X, Y, W, H, win);
}
void fl_reset_spot()
{
fl_graphics_driver->reset_spot();
Fl_Graphics_Driver::default_driver().reset_spot();
}
//

View File

@ -89,7 +89,7 @@ void gl_start() {
int x, y, w, h;
if (fl_clip_box(0, 0, Fl_Window::current()->w(), Fl_Window::current()->h(),
x, y, w, h)) {
fl_clip_region(Fl_Graphics_Driver::XRectangleRegion(x,y,w,h));
fl_clip_region(Fl_Graphics_Driver::default_driver().XRectangleRegion(x,y,w,h));
glScissor(x, Fl_Window::current()->h()-(y+h), w, h);
glEnable(GL_SCISSOR_TEST);
} else {