Multitasking Scamper (the web browser in Squeak)

Lex Spoon lex at cc.gatech.edu
Wed Jan 20 00:11:40 UTC 1999


This is cool.  I've actually played with this route, too.  IMHO, however, it should be left as a preference.  Here's why.

To usefully "background" a computation in Squeak, you must run it at a lower priority than the Morphic UI.  Otherwise, the "background" computation will grab the CPU and not release it until it finishes--thus lockingthe UI.  However, if you run it at a lower priority than the UI, you run the risk that it will get no CPU usage at all.  In a lot of cases this is a low risk; however, causing it to happen is as simple as putting a BouncingAtomsMorph on your desktop.

The ideal case would be to preempt the background comptuation periodically, and run it at the same priority as the UI.  The UI is alrady polite about yielding control periodically, so only the computation needs to be preempted.  This way, neither process will hog the CPU to itself, so both Squeak stays responsive, and the image eventually gets decoded.

However, I never figured out how to preempt a process in Squeak....  If someone *does* figure it out, it would make Scamper a whole lot nicer to use.

Lex


PS - instead of adding inst vars to DownloadImageMorph, it would actually work to just have downloadStateIn: do the decode right after it does the download, and put the decoded image on downloadQueue.

PPS - I noticed you slipped a change in there to remove the hourglass cursor from image decodes.  I share your sentiment--it doesn't make sense for a background decode to do this.  On the other hand, it's kind of nice for *foreground* decodes.  This is a common situation in Squeak: most things assume there is a user around to talk to.



Carl Watts <Carl at AppliedThought.com> wrote:
> --============_-1295344331==_============
> Content-Type: text/plain; charset="us-ascii"
> Content-Transfer-Encoding: quoted-printable
> 
> Congratulations to the Squeak Team for 2.3, I continue to be SO impressed by=
>  many of the ideas going to the Morph classes and into Squeak in general. =
>  Attached is my own small contribution I wrote this morning.  I wish I had=
>  more time to contribute to Squeak but somehow I got diverted from Smalltalk=
>  to writing a Palm Pilot app!
> 
> Multitasking Scamper.st:
> 
> This small change to DownloadingImageMorph makes it use background processes=
>  to download images in Scamper (the web browser built into Squeak). Just=
>  like Navigator and Internet Explorer do.
> 
> So you can scroll through a web page, reading the text or do whatever else=
>  you want while the images are downloading in background.  The images will=
>  appear on the page 1-by-1 as they finish downloading.
> 
> 
> Carl Watts
> http://AppliedThought.com/carl/carlgwatts.html
> 
> --============_-1295344331==_============
> Content-Type: multipart/appledouble; boundary="============_-1295344331==_D============"
> 
> --============_-1295344331==_D============
> Content-Transfer-Encoding: base64
> Content-Type: application/applefile; name="%Multitasking_Scamper.st"
> Content-Disposition: attachment; filename="%Multitasking_Scamper.st"
> 
> AAUWBwACAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAADAAAAPgAAABcAAAAJAAAAVQAAACAA
> AAAIAAAAdQAAABBNdWx0aXRhc2tpbmcgU2NhbXBlci5zdFRFWFRSKmNoAQAA5AAoAAAA
> AAAAAAAAAAAAAAAAAAAA/jcruv43K7pLbQwA/jc4tQ==
> --============_-1295344331==_D============
> Content-Type: text/plain; name="Multitasking_Scamper.st"; charset="us-ascii"
> Content-Transfer-Encoding: quoted-printable
> Content-Disposition: attachment; filename="Multitasking_Scamper.st"
> 
> 'From Squeak 2.3 of January 14, 1999 on 19 January 1999 at 11:40:42 am'!
> Morph subclass: #DownloadingImageMorph
> 	instanceVariableNames: 'url altText defaultExtent image downloadQueue=
>  nextImage gettingNextImage '
> 	classVariableNames: ''
> 	poolDictionaries: ''
> 	category: 'HTML-Formatter'!
> 
> !DownloadingImageMorph commentStamp: 'cgw 1/19/1999 11:26' prior: 0!
> a placeholder for an image that is downloading
> 
> Modification History:
> CGW 1/19/99: made the downloading occur in a background process so this=
>  morph would not hold up the whole WorldMorph during it's step.  Since Damag=
> eRecorder>recordInvalidRect: isn't safely re-entrant, I isolated re-entrancy=
>  concerns here (by using 2 new instVars nextImage and gettingNextImage) (htt=
> p://AppliedThought.com/carl/carlgwatts.html)
> 
> Instance Variables:
> url
> altText
> defaultExtent
> image
> downloadQueue
> nextImage - the next image to show after the current one (or nil if none).
> gettingNextImage - whether a background process that is busy downloading the=
>  next image!
> 
> !DownloadingImageMorph methodsFor: 'as yet unclassified' stamp: 'cgw=
>  1/19/1999 11:30'!
> initialize
> 	"Initialize the receiver."
> 
> 	super initialize.
> 	altText _ '[image]'.
> 	self color: Color transparent.
> 	downloadQueue _ SharedQueue new.
> 	gettingNextImage _ false.! !
> 
> !DownloadingImageMorph methodsFor: 'as yet unclassified' stamp: 'cgw=
>  1/19/1999 11:29'!
> step
> 	"Take the next step in my morphing (must return quickly or the whole World=
>  will slow down)."
> 	"In order to return quickly, do the downloading in a background process."
> 
> 	| doc |
> 	super step.
> 	gettingNextImage ifTrue: [
> 		"There is already a background process busy getting the next image."
> 		^self].
> 	nextImage notNil ifTrue: [
> 		"The next image has been downloaded, now set self to show it."
> 		image _ nextImage.
> 		nextImage _ nil.
> 		self setContents.
> 		^self].
> 	downloadQueue isEmpty ifFalse: [
> 		doc _ downloadQueue next.
> 		doc mainType =3D 'image' ifTrue: [
> 			"Fork a backgroundProcess to download the next image."
> 			gettingNextImage _ true.
> 			[	nextImage _ ImageReadWriter formFromStream: doc contentStream binary.
> 				gettingNextImage _ false] forkAt: Processor userBackgroundPriority]].! !
> 
> 
> !ImageReadWriter class methodsFor: 'image reading/writing' stamp: 'cgw=
>  1/19/1999 11:35'!
> formFromStream: aBinaryStream
> 	"Answer a ColorForm stored on the given stream.  closes the stream"
> 	"Don't change the cursor because this method can be called from a=
>  background process."
> 
> 	| reader readerClass form  |
> 	readerClass _ self withAllSubclasses
> 		detect: [:subclass | aBinaryStream reset. (subclass new on: aBinaryStream)=
>  understandsImageFormat]
> 		ifNone: [
> 			(aBinaryStream respondsTo: #close) ifTrue: [ aBinaryStream close ].
> 			^self error: 'image format not recognized'].
> 	reader _ readerClass new on: aBinaryStream reset.
> 	form _ reader nextImage.
> 	reader close.
> 	^form
> ! !
> 
> 
> 
> --============_-1295344331==_D============--
> --============_-1295344331==_============--





More information about the Squeak-dev mailing list