[education/rkward] rkward/rbackend/rkwarddevice: Implement releasing masks (and unify the handling across the different resource types)

Thomas Friedrichsmeier null at kde.org
Sat Mar 26 08:53:32 GMT 2022


Git commit 5b66169a6dbb01deea0e57da10a83e42988dbe2e by Thomas Friedrichsmeier.
Committed on 26/03/2022 at 08:52.
Pushed by tfry into branch 'master'.

Implement releasing masks (and unify the handling across the different resource types)

M  +1    -1    rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
M  +7    -17   rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
M  +10   -5    rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
M  +20   -23   rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp

https://invent.kde.org/education/rkward/commit/5b66169a6dbb01deea0e57da10a83e42988dbe2e

diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
index c442c235..c1553f40 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice.cpp
@@ -266,7 +266,7 @@ int RKGraphicsDevice::registerPattern(const QBrush& brush) {
 
 void RKGraphicsDevice::destroyPattern(int id) {
 	RK_TRACE(GRAPHICS_DEVICE);
-	if (id == 0) patterns.clear();
+	if (id < 0) patterns.clear();
 	else patterns.remove(id);
 }
 
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
index b659db46..d21ebb1b 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_frontendtransmitter.cpp
@@ -361,10 +361,6 @@ void RKGraphicsDeviceFrontendTransmitter::newData () {
 		} else if (opcode == RKDSetPattern) {
 			streamer.outstream << (qint32) readNewPattern(streamer.instream, device);
 			streamer.writeOutBuffer();
-		} else if (opcode == RKDReleasePattern) {
-			qint32 index;
-			streamer.instream >> index;
-			device->destroyPattern(index);
 		} else if (opcode == RKDStartRecordTilingPattern) {
 			double width, height, x, y;
 			streamer.instream >> width >> height;
@@ -381,14 +377,17 @@ void RKGraphicsDeviceFrontendTransmitter::newData () {
 			qint8 ok = device->setClipToCachedPath(index) ? 1 : 0;
 			streamer.outstream << ok;
 			streamer.writeOutBuffer();
-		} else if (opcode == RKDReleaseClipPath) {
+		} else if (opcode == RKDReleaseCachedResource) {
+			quint8 type;
 			qint32 len;
-			streamer.instream >> len;
-			if (len < 0) device->destroyCachedPath(-1);
+			streamer.instream >> type >> len;
 			for (int i = 0; i < len; ++i) {
 				qint32 index;
 				streamer.instream >> index;
-				device->destroyCachedPath(index);
+				if (type == RKDPattern) device->destroyPattern(index);
+				else if (type == RKDClipPath) device->destroyCachedPath(index);
+				else if (type == RKDMask) device->destroyMask(index);
+				else RK_ASSERT(false);
 			}
 		} else if (opcode == RKDStartRecordClipPath) {
 			device->startRecordPath();
@@ -406,15 +405,6 @@ void RKGraphicsDeviceFrontendTransmitter::newData () {
 			qint8 ok = device->setMask(index) ? 1 : 0;
 			streamer.outstream << ok;
 			streamer.writeOutBuffer();
-		} else if (opcode == RKDReleaseMask) {
-			qint32 len;
-			streamer.instream >> len;
-			if (len < 0) device->destroyMask(-1);
-			for (int i = 0; i < len; ++i) {
-				qint32 index;
-				streamer.instream >> index;
-				device->destroyMask(index);
-			}
 		} else if (opcode == RKDStartRecordMask) {
 			device->startRecordMask();
 		} else if (opcode == RKDEndRecordMask) {
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
index 645a804c..75574020 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_protocol_shared.h
@@ -44,6 +44,13 @@
  * 
  */
 
+enum RKDCachedResourceType {
+	RKDPattern,
+	RKDClipPath,
+	RKDMask,
+	RKDGroup
+};
+
 enum RKDFillType {
 	ColorFill,
 	PatternFill
@@ -88,12 +95,10 @@ enum RKDOpcodes {
 	RKDRaster,
 	RKDSetSize,            // 15
 	RKDStopGettingEvents,
-	RKDReleasePattern,
+	RKDReleaseCachedResource,
 	RKDStartRecordTilingPattern,      // part of setPattern in R
-	RKDReleaseClipPath,
-	RKDStartRecordClipPath,//20
-	RKDReleaseMask,
-	RKDStartRecordMask,
+	RKDStartRecordClipPath,
+	RKDStartRecordMask,    // 20
 
 	// Synchronous operations
 	RKDFetchNextEvent      = 100,
diff --git a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
index 90ed87b4..3409867a 100644
--- a/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
+++ b/rkward/rbackend/rkwarddevice/rkgraphicsdevice_stubs.cpp
@@ -728,18 +728,29 @@ SEXP RKD_SetPattern (SEXP pattern, pDevDesc dev) {
 	return makeInt(index);
 }
 
-void RKD_ReleasePattern (SEXP ref, pDevDesc dev) {
+void releaseCachedResource(RKDCachedResourceType type, SEXP ref, pDevDesc dev) {
 	RK_TRACE(GRAPHICS_DEVICE);
-	qint32 index;
-	if (Rf_isNull(ref)) index = 0;  // means: destroy all patterns
-	else index = INTEGER(ref)[0];
 	{
 		RKGraphicsDataStreamWriteGuard wguard;
-		WRITE_HEADER(RKDReleasePattern, dev);
-		RKD_OUT_STREAM << index;
+		WRITE_HEADER(RKDReleaseCachedResource, dev);
+		RKD_OUT_STREAM << (quint8) type;
+		if (Rf_isNull(ref)) {
+			RKD_OUT_STREAM << (qint32) 1 << (qint32) -1; // means: destroy all objects of that type
+		} else {
+			qint32 len = LENGTH(ref);
+			RKD_OUT_STREAM << len;
+			for (int i = 0; i < len; ++i) {
+				RKD_OUT_STREAM << (qint32) INTEGER(ref)[i];
+			}
+		}
 	}
 }
 
+void RKD_ReleasePattern (SEXP ref, pDevDesc dev) {
+	RK_TRACE(GRAPHICS_DEVICE);
+	releaseCachedResource(RKDPattern, ref, dev);
+}
+
 SEXP RKD_SetClipPath (SEXP path, SEXP ref, pDevDesc dev) {
 	RK_TRACE(GRAPHICS_DEVICE);
 	qint32 index = -1;
@@ -792,19 +803,7 @@ SEXP RKD_SetClipPath (SEXP path, SEXP ref, pDevDesc dev) {
 
 void RKD_ReleaseClipPath (SEXP ref, pDevDesc dev) {
 	RK_TRACE(GRAPHICS_DEVICE);
-	{
-		RKGraphicsDataStreamWriteGuard wguard;
-		WRITE_HEADER(RKDReleaseClipPath, dev);
-		if (Rf_isNull(ref)) {
-			RKD_OUT_STREAM << (qint32) -1; // means: destroy all clippaths
-		} else {
-			qint32 len = LENGTH(ref);
-			RKD_OUT_STREAM << len;
-			for (int i = 0; i < len; ++i) {
-				RKD_OUT_STREAM << (qint32) INTEGER(ref)[i];
-			}
-		}
-	}
+	releaseCachedResource(RKDClipPath, ref, dev);
 }
 
 SEXP RKD_SetMask (SEXP mask, SEXP ref, pDevDesc dev) {
@@ -855,11 +854,9 @@ SEXP RKD_SetMask (SEXP mask, SEXP ref, pDevDesc dev) {
 	return R_NilValue;
 }
 
-void RKD_ReleaseMask (SEXP ref, pDevDesc dd) {
+void RKD_ReleaseMask (SEXP ref, pDevDesc dev) {
 	RK_TRACE(GRAPHICS_DEVICE);
-#ifdef __GNUC__
-#warning implement me
-#endif
+	releaseCachedResource(RKDMask, ref, dev);
 }
 
 #endif


More information about the rkward-tracker mailing list