Settled NSBitmapImageRep TODOs on the Mac OS X backend.

This commit is contained in:
Pietro Gagliardi 2014-08-10 13:19:42 -04:00
parent 09a1239d94
commit 0b3f6570ac
3 changed files with 12 additions and 6 deletions

View File

@ -51,9 +51,12 @@ func areaView_drawRect(self C.id, rect C.struct_xrect, data unsafe.Pointer) {
return return
} }
i := a.handler.Paint(cliprect) i := a.handler.Paint(cliprect)
C.drawImage( success := C.drawImage(
unsafe.Pointer(pixelData(i)), C.intptr_t(i.Rect.Dx()), C.intptr_t(i.Rect.Dy()), C.intptr_t(i.Stride), unsafe.Pointer(pixelData(i)), C.intptr_t(i.Rect.Dx()), C.intptr_t(i.Rect.Dy()), C.intptr_t(i.Stride),
C.intptr_t(cliprect.Min.X), C.intptr_t(cliprect.Min.Y)) C.intptr_t(cliprect.Min.X), C.intptr_t(cliprect.Min.Y))
if success == C.NO {
panic("error drawing into Area (exactly what is unknown)")
}
} }
func parseModifiers(e C.id) (m Modifiers) { func parseModifiers(e C.id) (m Modifiers) {

View File

@ -112,10 +112,11 @@ id newArea(void *goarea)
return (id) a; return (id) a;
} }
void drawImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride, intptr_t xdest, intptr_t ydest) BOOL drawImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride, intptr_t xdest, intptr_t ydest)
{ {
unsigned char *planes[1]; // NSBitmapImageRep wants an array of planes; we have one plane unsigned char *planes[1]; // NSBitmapImageRep wants an array of planes; we have one plane
NSBitmapImageRep *bitmap; NSBitmapImageRep *bitmap;
BOOL success;
planes[0] = (unsigned char *) pixels; planes[0] = (unsigned char *) pixels;
bitmap = [[NSBitmapImageRep alloc] bitmap = [[NSBitmapImageRep alloc]
@ -126,18 +127,20 @@ void drawImage(void *pixels, intptr_t width, intptr_t height, intptr_t stride, i
samplesPerPixel:4 samplesPerPixel:4
hasAlpha:YES hasAlpha:YES
isPlanar:NO isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace // TODO NSDeviceRGBColorSpace? // NSCalibratedRGBColorSpace changes the colors; let's not
// thanks to JtRip in irc.freenode.net/#macdev
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:0 // this is where the flag for placing alpha first would go if alpha came first; the default is alpha last, which is how we're doing things (otherwise the docs say "Color planes are arranged in the standard order—for example, red before green before blue for RGB color."); this is also where the flag for non-premultiplied colors would go if we used it (the default is alpha-premultiplied) bitmapFormat:0 // this is where the flag for placing alpha first would go if alpha came first; the default is alpha last, which is how we're doing things (otherwise the docs say "Color planes are arranged in the standard order—for example, red before green before blue for RGB color."); this is also where the flag for non-premultiplied colors would go if we used it (the default is alpha-premultiplied)
bytesPerRow:toNSInteger(stride) bytesPerRow:toNSInteger(stride)
bitsPerPixel:32]; bitsPerPixel:32];
// TODO this CAN fali; check error success = [bitmap drawInRect:NSMakeRect((CGFloat) xdest, (CGFloat) ydest, (CGFloat) width, (CGFloat) height)
[bitmap drawInRect:NSMakeRect((CGFloat) xdest, (CGFloat) ydest, (CGFloat) width, (CGFloat) height)
fromRect:NSZeroRect // draw whole image fromRect:NSZeroRect // draw whole image
operation:NSCompositeSourceOver operation:NSCompositeSourceOver
fraction:1.0 fraction:1.0
respectFlipped:YES respectFlipped:YES
hints:nil]; hints:nil];
[bitmap release]; [bitmap release];
return success;
} }
uintptr_t modifierFlags(id e) uintptr_t modifierFlags(id e)

View File

@ -100,7 +100,7 @@ extern struct xrect frame(id);
/* area_darwin.h */ /* area_darwin.h */
extern Class getAreaClass(void); extern Class getAreaClass(void);
extern id newArea(void *); extern id newArea(void *);
extern void drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t); extern BOOL drawImage(void *, intptr_t, intptr_t, intptr_t, intptr_t, intptr_t);
extern uintptr_t modifierFlags(id); extern uintptr_t modifierFlags(id);
extern struct xpoint getTranslatedEventPoint(id, id); extern struct xpoint getTranslatedEventPoint(id, id);
extern intptr_t buttonNumber(id); extern intptr_t buttonNumber(id);