Browse Source

Use sub-image instead of clipping

It seems to be more efficient.
tags/v1.8.90
Pierre Ossman 7 years ago
parent
commit
2d0dc3abee
1 changed files with 18 additions and 18 deletions
  1. 18
    18
      vncviewer/Surface_OSX.cxx

+ 18
- 18
vncviewer/Surface_OSX.cxx View File



static void render(CGContextRef gc, CGImageRef image, static void render(CGContextRef gc, CGImageRef image,
CGBlendMode mode, CGFloat alpha, CGBlendMode mode, CGFloat alpha,
int src_x, int src_y, int src_w, int src_h,
int src_x, int src_y,
int x, int y, int w, int h) int x, int y, int w, int h)
{ {
CGRect rect; CGRect rect;
CGImageRef subimage;

rect.origin.x = src_x;
rect.origin.y = src_y;
rect.size.width = w;
rect.size.height = h;

subimage = CGImageCreateWithImageInRect(image, rect);
if (!subimage)
throw rdr::Exception("CGImageCreateImageWithImageInRect");


CGContextSaveGState(gc); CGContextSaveGState(gc);


CGContextSetBlendMode(gc, mode); CGContextSetBlendMode(gc, mode);
CGContextSetAlpha(gc, alpha); CGContextSetAlpha(gc, alpha);


// We have to use clipping to partially display an image
rect.origin.x = x; rect.origin.x = x;
rect.origin.y = y; rect.origin.y = y;
rect.size.width = w; rect.size.width = w;
rect.size.height = h; rect.size.height = h;


CGContextClipToRect(gc, rect);

rect.origin.x = x - src_x;
rect.origin.y = y - src_y;
rect.size.width = src_w;
rect.size.height = src_h;

CGContextDrawImage(gc, rect, image);
CGContextDrawImage(gc, rect, subimage);


CGContextRestoreGState(gc); CGContextRestoreGState(gc);

CGImageRelease(subimage);
} }


static CGContextRef make_bitmap(int width, int height, unsigned char* data) static CGContextRef make_bitmap(int width, int height, unsigned char* data)
CGContextConcatCTM(fl_gc, CGAffineTransformInvert(CGContextGetCTM(fl_gc))); CGContextConcatCTM(fl_gc, CGAffineTransformInvert(CGContextGetCTM(fl_gc)));


// macOS Coordinates are from bottom left, not top left // macOS Coordinates are from bottom left, not top left
src_y = height() - (src_y + h);
y = Fl_Window::current()->h() - (y + h); y = Fl_Window::current()->h() - (y + h);


render(fl_gc, image, kCGBlendModeCopy, 1.0, render(fl_gc, image, kCGBlendModeCopy, 1.0,
src_x, src_y, width(), height(), x, y, w, h);
src_x, src_y, x, y, w, h);


CGContextRestoreGState(fl_gc); CGContextRestoreGState(fl_gc);
} }
bitmap = make_bitmap(dst->width(), dst->height(), dst->data); bitmap = make_bitmap(dst->width(), dst->height(), dst->data);


// macOS Coordinates are from bottom left, not top left // macOS Coordinates are from bottom left, not top left
src_y = height() - (src_y + h);
y = dst->height() - (y + h); y = dst->height() - (y + h);


render(bitmap, image, kCGBlendModeCopy, 1.0, render(bitmap, image, kCGBlendModeCopy, 1.0,
src_x, src_y, width(), height(), x, y, w, h);
src_x, src_y, x, y, w, h);


CGContextRelease(bitmap); CGContextRelease(bitmap);
} }
CGContextConcatCTM(fl_gc, CGAffineTransformInvert(CGContextGetCTM(fl_gc))); CGContextConcatCTM(fl_gc, CGAffineTransformInvert(CGContextGetCTM(fl_gc)));


// macOS Coordinates are from bottom left, not top left // macOS Coordinates are from bottom left, not top left
src_y = height() - (src_y + h);
y = Fl_Window::current()->h() - (y + h); y = Fl_Window::current()->h() - (y + h);


render(fl_gc, image, kCGBlendModeNormal, (CGFloat)a/255.0, render(fl_gc, image, kCGBlendModeNormal, (CGFloat)a/255.0,
src_x, src_y, width(), height(), x, y, w, h);
src_x, src_y, x, y, w, h);


CGContextRestoreGState(fl_gc); CGContextRestoreGState(fl_gc);
} }
bitmap = make_bitmap(dst->width(), dst->height(), dst->data); bitmap = make_bitmap(dst->width(), dst->height(), dst->data);


// macOS Coordinates are from bottom left, not top left // macOS Coordinates are from bottom left, not top left
src_y = height() - (src_y + h);
y = dst->height() - (y + h); y = dst->height() - (y + h);


render(bitmap, image, kCGBlendModeNormal, (CGFloat)a/255.0, render(bitmap, image, kCGBlendModeNormal, (CGFloat)a/255.0,
src_x, src_y, width(), height(), x, y, w, h);
src_x, src_y, x, y, w, h);


CGContextRelease(bitmap); CGContextRelease(bitmap);
} }

Loading…
Cancel
Save