ref: 322f72313d66550698e918707ea5d32e44da9dca
parent: 92fa7cbcd1e519e3fff221cb010caa4ba8669c54
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Mon Nov 14 07:59:48 EST 2011
mothra: limit amount of image data kept in devdraw to 8MB
--- a/sys/src/cmd/mothra/getpix.c
+++ b/sys/src/cmd/mothra/getpix.c
@@ -21,12 +21,6 @@
[BMP] "bmp -9t",
};
-void storebitmap(Rtext *t, Image *b){
- t->b=b;
- free(t->text);
- t->text=0;
-}
-
void getimage(Rtext *t, Www *w){
int pfd[2];
Action *ap;
@@ -40,7 +34,7 @@
seturl(&url, ap->image, w->url->fullname);
for(p=w->pix;p!=nil; p=p->next)
if(strcmp(ap->image, p->name)==0 && ap->width==p->width && ap->height==p->height){
- storebitmap(t, p->b);
+ t->b = p->b;
w->changed=1;
return;
}
@@ -87,7 +81,7 @@
p->height=ap->height;
p->next=w->pix;
w->pix=p;
- storebitmap(t, b);
+ t->b=b;
w->changed=1;
}
@@ -144,8 +138,15 @@
}
}
-void freepix(void *p)
-{
+ulong countpix(void *p){
+ ulong n=0;
+ Pix *x;
+ for(x = p; x; x = x->next)
+ n += Dy(x->b->r)*bytesperline(x->b->r, x->b->depth);
+ return n;
+}
+
+void freepix(void *p){
Pix *x, *xx;
xx = p;
while(x = xx){
--- a/sys/src/cmd/mothra/mothra.c
+++ b/sys/src/cmd/mothra/mothra.c
@@ -961,9 +961,10 @@
* get the file at the given url
*/
void geturl(char *urlname, int method, char *body, int plumb, int map){
- int i, fd, typ;
+ int i, fd, typ, pfd[2];
char cmd[NNAME];
- int pfd[2];
+ Rtext *t;
+ ulong n;
Www *w;
if(*urlname == '#'){
@@ -1013,11 +1014,22 @@
case HTML:
fd = pipeline("/bin/uhtml", fd);
case PLAIN:
+ n=0;
+ for(i=wwwtop-1; i>=0 && i!=(wwwtop-NWWW-1); i--){
+ w = www(i);
+ n += countpix(w->pix);
+ if(n < NPIXMB*1024*1024)
+ continue;
+ if(!w->finished && !w->alldone)
+ continue;
+ for(t=w->text; t; t=t->next)
+ if(t->b && t->user)
+ t->b=0;
+ freepix(w->pix);
+ w->pix=0;
+ }
w = www(i = wwwtop++);
if(i >= NWWW){
- extern void freeform(void *p);
- extern void freepix(void *p);
-
/* wait for the reader to finish the document */
while(!w->finished && !w->alldone){
unlockdisplay(display);
@@ -1024,7 +1036,6 @@
sleep(10);
lockdisplay(display);
}
-
freetext(w->text);
freeform(w->form);
freepix(w->pix);
--- a/sys/src/cmd/mothra/mothra.h
+++ b/sys/src/cmd/mothra/mothra.h
@@ -1,6 +1,7 @@
enum{
NWWW=64, /* # of pages we hold in the log */
NXPROC=5, /* # of parallel procs loading the pix */
+ NPIXMB=8, /* megabytes of image data to keep arround */
NNAME=512,
NLINE=256,
NAUTH=128,
@@ -82,12 +83,14 @@
void htmlerror(char *, int, char *, ...); /* user-supplied routine */
void seturl(Url *, char *, char *);
void getpix(Rtext *, Www *);
+ulong countpix(void *p);
+void freepix(void *p);
int pipeline(char *, int);
int urlopen(Url *, int, char *);
void getfonts(void);
void *emalloc(int);
void *emallocz(int, int);
-void setbitmap(Rtext *);
+void freeform(void *p);
void message(char *, ...);
int snooptype(int fd);
void mkfieldpanel(Rtext *);