[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] gsoc-2024-ahmet 369d6be7: makefile and inital obj-c
From: |
Werner Lemberg |
Subject: |
[freetype2-demos] gsoc-2024-ahmet 369d6be7: makefile and inital obj-c |
Date: |
Sun, 4 Aug 2024 18:54:41 -0400 (EDT) |
branch: gsoc-2024-ahmet
commit 369d6be79ee9adb1706b248bfae3bedcb3c6a0df
Author: Ahmet Goksu <ahmet@goksu.in>
Commit: Ahmet Goksu <ahmet@goksu.in>
makefile and inital obj-c
---
graph/cocoa/grcocoa.h | 9 +++++
graph/cocoa/grcocoa.mm | 100 +++++++++++++++++++++++++++++++++++++++++++++++++
graph/cocoa/rules.mk | 22 +++++++++++
graph/grinit.c | 4 ++
graph/rules.mk | 1 -
5 files changed, 135 insertions(+), 1 deletion(-)
diff --git a/graph/cocoa/grcocoa.h b/graph/cocoa/grcocoa.h
new file mode 100644
index 00000000..cb5d6287
--- /dev/null
+++ b/graph/cocoa/grcocoa.h
@@ -0,0 +1,9 @@
+#ifndef GRCOCOA_H_
+#define GRCOCOA_H_
+
+#include "grobjs.h"
+#include "grdevice.h"
+
+extern grDevice gr_cocoa_device;
+
+#endif /* GRCOCOA_H_ */
diff --git a/graph/cocoa/grcocoa.mm b/graph/cocoa/grcocoa.mm
new file mode 100644
index 00000000..02c30377
--- /dev/null
+++ b/graph/cocoa/grcocoa.mm
@@ -0,0 +1,100 @@
+#include "grcocoa.h"
+#include "graph.h"
+#include <Cocoa/Cocoa.h>
+#include <objc/runtime.h>
+
+typedef struct {
+ grSurface root;
+ NSWindow *window;
+ NSBitmapImageRep *bitmapRep;
+ NSImageView *imageView;
+} grCocoaSurface;
+
+static int gr_cocoa_device_init(void) {
+ // initialization for Cocoa
+ return 0;
+}
+
+static void gr_cocoa_device_done(void) {
+ // cleanup
+}
+
+static int gr_cocoa_surface_init(grSurface *surface, grBitmap *bitmap) {
+ grCocoaSurface *cocoa_surface = (grCocoaSurface *)surface;
+ int width = bitmap->width;
+ int height = bitmap->rows;
+
+ cocoa_surface->bitmapRep = [[NSBitmapImageRep alloc]
+ initWithBitmapDataPlanes:NULL
+ pixelsWide:width
+ pixelsHigh:height
+ bitsPerSample:8
+ samplesPerPixel:4
+ hasAlpha:YES
+ isPlanar:NO
+ colorSpaceName:NSDeviceRGBColorSpace
+ bitmapFormat:0
+ bytesPerRow:width * 4
+ bitsPerPixel:32];
+
+ cocoa_surface->window = [[NSWindow alloc]
initWithContentRect:NSMakeRect(0, 0, width, height)
+ styleMask:(NSWindowStyleMaskTitled | NSWindowStyleMaskClosable |
NSWindowStyleMaskResizable)
+ backing:NSBackingStoreBuffered
+ defer:NO];
+ [cocoa_surface->window setTitle:@"FreeType Cocoa Demo"];
+ cocoa_surface->imageView = [[NSImageView alloc]
initWithFrame:NSMakeRect(0, 0, width, height)];
+ [cocoa_surface->imageView setImage:[[NSImage alloc]
initWithSize:NSMakeSize(width, height)]];
+ [[cocoa_surface->window contentView] addSubview:cocoa_surface->imageView];
+ [cocoa_surface->window makeKeyAndOrderFront:nil];
+
+ surface->bitmap = *bitmap;
+ return 1;
+}
+
+static void gr_cocoa_surface_done(grSurface *surface) {
+ grCocoaSurface *cocoa_surface = (grCocoaSurface *)surface;
+ [cocoa_surface->window close];
+ [cocoa_surface->bitmapRep release];
+}
+
+static void gr_cocoa_surface_refresh_rectangle(grSurface *surface, int x, int
y, int w, int h) {
+ grCocoaSurface *cocoa_surface = (grCocoaSurface *)surface;
+ // update the bitmap data here
+ unsigned char* bitmap_data = [cocoa_surface->bitmapRep bitmapData];
+ for (int row = y; row < y + h; row++) {
+ for (int col = x; col < x + w; col++) {
+ int pixel_index = (row * cocoa_surface->bitmapRep.bytesPerRow) +
(col * 4);
+ //update the pixel data
+ bitmap_data[pixel_index] = 255; // Red
+ bitmap_data[pixel_index + 1] = 255; // Green
+ bitmap_data[pixel_index + 2] = 255; // Blue
+ bitmap_data[pixel_index + 3] = 255; // Alpha
+ }
+ }
+
+ [[cocoa_surface->imageView image]
addRepresentation:cocoa_surface->bitmapRep];
+ [cocoa_surface->imageView setNeedsDisplay:YES];
+}
+
+static int gr_cocoa_surface_listen_event(grSurface *surface, int event_mask,
grEvent *event) {
+ // event handling here
+ // return 0 for now
+ return 0;
+}
+
+static grPixelMode gr_cocoa_pixel_modes[] = {
+ gr_pixel_mode_rgb24
+};
+
+grDevice gr_cocoa_device = {
+ sizeof(grCocoaSurface),
+ "cocoa",
+ gr_cocoa_device_init,
+ gr_cocoa_device_done,
+ gr_cocoa_surface_init,
+ gr_cocoa_surface_done,
+ gr_cocoa_surface_refresh_rectangle,
+ gr_cocoa_surface_listen_event,
+ -1,
+ NULL
+};
diff --git a/graph/cocoa/rules.mk b/graph/cocoa/rules.mk
new file mode 100644
index 00000000..1130fe97
--- /dev/null
+++ b/graph/cocoa/rules.mk
@@ -0,0 +1,22 @@
+#**************************************************************************
+#*
+#* Cocoa specific rules file, used to compile the Cocoa graphics driver
+#* to the graphics subsystem
+#*
+#**************************************************************************
+ifeq ($(shell uname),Darwin)
+
+ GR_COCOA := $(GRAPH)/cocoa
+
+ GRAPH_OBJS += $(OBJ_DIR_2)/grcocoa.$O
+
+ DEVICES += COCOA
+
+ $(OBJ_DIR_2)/grcocoa.$O: $(GR_COCOA)/grcocoa.mm $(GR_COCOA)/grcocoa.h
$(GRAPH_H)
+ $(CC) $(CFLAGS) $(GRAPH_INCLUDES:%=$I%) \
+ $I$(subst /,$(COMPILER_SEP),$(GR_COCOA)) \
+ $T$(subst /,$(COMPILER_SEP),$@ $<)
+
+endif
+
+# EOF
diff --git a/graph/grinit.c b/graph/grinit.c
index 0d665d55..0bfc5987 100644
--- a/graph/grinit.c
+++ b/graph/grinit.c
@@ -29,6 +29,10 @@
#include "mac/grmac.h"
#endif
+#ifdef DEVICE_COCOA
+#include "cocoa/grcocoa.h"
+#endif
+
#ifdef DEVICE_ALLEGRO
#include "allegro/gralleg.h"
#endif
diff --git a/graph/rules.mk b/graph/rules.mk
index a11797fd..f0a02f2a 100644
--- a/graph/rules.mk
+++ b/graph/rules.mk
@@ -38,7 +38,6 @@ GRAPH_OBJS := $(OBJ_DIR_2)/gblblit.$(O) \
$(OBJ_DIR_2)/grswizzle.$(O)
-
# Default value for COMPILE_GRAPH_LIB;
# this value can be modified by the system-specific graphics drivers.
#
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] gsoc-2024-ahmet 369d6be7: makefile and inital obj-c,
Werner Lemberg <=