From: Pierre Ossman Date: Thu, 27 Apr 2017 11:28:49 +0000 (+0200) Subject: Use sub-image instead of clipping X-Git-Tag: v1.8.0~20 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=819f297de50d6d713d5b1a5f1031b97f09a4f7a1;p=tigervnc.git Use sub-image instead of clipping It seems to be more efficient. (cherry picked from commit 2d0dc3abee27c9383ad3ab23e02ecf94fcdd7596) --- diff --git a/vncviewer/Surface_OSX.cxx b/vncviewer/Surface_OSX.cxx index 2dfaa477..668187bc 100644 --- a/vncviewer/Surface_OSX.cxx +++ b/vncviewer/Surface_OSX.cxx @@ -30,32 +30,36 @@ static void render(CGContextRef gc, CGImageRef image, 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) { 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); CGContextSetBlendMode(gc, mode); CGContextSetAlpha(gc, alpha); - // We have to use clipping to partially display an image rect.origin.x = x; rect.origin.y = y; rect.size.width = w; 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); + + CGImageRelease(subimage); } static CGContextRef make_bitmap(int width, int height, unsigned char* data) @@ -108,11 +112,10 @@ void Surface::draw(int src_x, int src_y, int x, int y, int w, int h) CGContextConcatCTM(fl_gc, CGAffineTransformInvert(CGContextGetCTM(fl_gc))); // macOS Coordinates are from bottom left, not top left - src_y = height() - (src_y + h); y = Fl_Window::current()->h() - (y + h); 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); } @@ -124,11 +127,10 @@ void Surface::draw(Surface* dst, int src_x, int src_y, int x, int y, int w, int bitmap = make_bitmap(dst->width(), dst->height(), dst->data); // macOS Coordinates are from bottom left, not top left - src_y = height() - (src_y + h); y = dst->height() - (y + h); 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); } @@ -142,11 +144,10 @@ void Surface::blend(int src_x, int src_y, int x, int y, int w, int h, int a) CGContextConcatCTM(fl_gc, CGAffineTransformInvert(CGContextGetCTM(fl_gc))); // macOS Coordinates are from bottom left, not top left - src_y = height() - (src_y + h); y = Fl_Window::current()->h() - (y + h); 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); } @@ -158,11 +159,10 @@ void Surface::blend(Surface* dst, int src_x, int src_y, int x, int y, int w, int bitmap = make_bitmap(dst->width(), dst->height(), dst->data); // macOS Coordinates are from bottom left, not top left - src_y = height() - (src_y + h); y = dst->height() - (y + h); 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); }