[squeak-dev] The Trunk: EToys-eem.399.mcz

commits at source.squeak.org commits at source.squeak.org
Fri Jul 17 23:51:12 UTC 2020


Eliot Miranda uploaded a new version of EToys to project The Trunk:
http://source.squeak.org/trunk/EToys-eem.399.mcz

==================== Summary ====================

Name: EToys-eem.399
Author: eem
Time: 17 July 2020, 4:51:05.430052 pm
UUID: dfb4916e-d9f3-40e7-8da2-2badb5372778
Ancestors: EToys-mt.398

Fix the WebCamMorph so that more than one camera can be used at the same time.

e,g, if you have a laptop with a secondary display attached with a camera (such as the Apple Cinema Display) you can do this:

WebCamMorph new cameraNumber: 2; openInWorld.
WebCamMorph new cameraNumber: 1; openInWorld.
WebCamMorph new cameraNumber: 2; openInWorld.
WebCamMorph new cameraNumber: 1; openInWorld.

position them around the display, change their size, and even give them rotation.  But interestingly adding rotation invokes the garbage collector since the warp form is not cached.

e.g.
GCs			5,066 (582.7 ms between GCs 314.9 ms runtime between GCs)
	full		245 totalling 221,724 ms (13.9% runtime), avg 905 ms
				marking		128,554 ms (58%) avg 524.7 ms,
				compacting	93,170 ms (42%) avg 380.3 ms
	scavenges	4,821 totalling 24,912 ms (1.56% runtime), avg 5.2 ms
	tenures		232,261 (avg 48 tenures per scavenge)

=============== Diff against EToys-mt.398 ===============

Item was added:
+ ----- Method: WebCamMorph>>cameraIsOn (in category 'accessing') -----
+ cameraIsOn
+ 	^camIsOn!

Item was added:
+ ----- Method: WebCamMorph>>cameraNumber (in category 'accessing') -----
+ cameraNumber
+ 	^camNum!

Item was added:
+ ----- Method: WebCamMorph>>cameraNumber: (in category 'accessing') -----
+ cameraNumber: anInteger
+ 	camNum ~= anInteger ifTrue:
+ 		[camNum := anInteger.
+ 		 self initializeDisplayForm]!

Item was changed:
  ----- Method: WebCamMorph>>delete (in category 'submorphs-add/remove') -----
  delete
+ 	self off.
+ 	super delete!
- 	self class instanceCount > 1
- 		ifFalse: [self off]
- 		ifTrue: [
- 			self stopStepping.
- 			camIsOn := false].
- 	super delete.!

Item was changed:
  ----- Method: WebCamMorph>>drawOn: (in category 'drawing') -----
  drawOn: aCanvas 
+ 	camIsOn ifFalse:
+ 		[self initializeDisplayForm.
+ 		 self on].
+ 	camIsOn ifTrue:
+ 		[(CameraInterface frameExtent: camNum) ~= displayForm extent ifTrue:
+ 			[self initializeDisplayForm]].
+ 	displayForm ifNil:
+ 		[self initializeDisplayForm].
- 
  	useFrameSize ifTrue: [self extent: frameExtent].
  	self drawCameraImageOn: aCanvas.
  	self drawFPSOn: aCanvas.
+ 	self drawOverlayTextOn: aCanvas!
- 	self drawOverlayTextOn: aCanvas.
- !

Item was changed:
  ----- Method: WebCamMorph>>initialize (in category 'initialization') -----
  initialize
  	super initialize.
  	camNum := 1.
  	camIsOn := false.
  	showFPS := false.
  	captureDelayMs := 16. "stepTime"	
  	fps := 60. "guess."
  	lastDisplayTime := 0.
  	framesSinceLastDisplay := 0.
  	useFrameSize := false.
  	resolution := #medium.
  	orientation := #natural.
+ 	frameExtent := self class resolutionFor: resolution!
- 	frameExtent := self class resolutionFor: resolution.
- 	self initializeDisplayForm.
- 	self extent: frameExtent.
- 	self on.
- 
- 	!

Item was changed:
  ----- Method: WebCamMorph>>off (in category 'accessing') -----
  off
  	self stopStepping.
  	camIsOn := false.
+ 	"Be careful not to close the camera if any other morphs are using the same camera."
+ 	(self class allInstances anySatisfy: [:wcm| wcm cameraNumber = camNum and: [wcm cameraIsOn]]) ifFalse:
+ 		[CameraInterface  closeCamera: camNum].
+ 	self changed
- 	self updateDisplay.
- 	CameraInterface  closeCamera: camNum.
  	
+ 	"self allInstances select: [:wcm| wcm cameraNumber = 1 and: [wcm cameraIsOn]]"!
- 
- 	
- !

Item was changed:
  ----- Method: WebCamMorph>>on (in category 'accessing') -----
  on
+ 	camIsOn ifTrue: [^true].
+ 	(CameraInterface cameraIsOpen: camNum) ifFalse:
+ 		[(CameraInterface openCamera: camNum width: frameExtent x height: frameExtent y) ifNil:
+ 			[^false]].
+ 	"The plugin/camera subsystem may end up choosing a different width and height.
+ 	 So use the width and height it has selected; it may not be what was asked for."
- 	
- 	(CameraInterface cameraIsOpen: camNum)
- 		ifTrue: [ ^camIsOn := true.].
- 	(CameraInterface openCamera: camNum width: frameExtent x height: frameExtent y)
- 		ifNil: [^false].
- 	CameraInterface waitForCameraStart: camNum.
  	self initializeDisplayForm.
+ 	CameraInterface waitForCameraStart: camNum.
- 	self extent: frameExtent.
  	camIsOn := true.
+ 	self startStepping!
- 	self startStepping.
- 	!



More information about the Squeak-dev mailing list