6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
46 #include <directories.h>
48 #include "EntryIterator.h"
49 #include "IconCache.h"
51 #include "NodeWalker.h"
52 #include "StopWatch.h"
56 const char* pathsToSearch
[] = {
57 // "/boot/home/config/settings/NetPositive/Bookmarks/",
65 namespace BTrackerPrivate
{
67 class IconSpewer
: public SimpleThread
{
69 IconSpewer(bool newCache
= true);
71 void SetTarget(BWindow
* target
)
72 { this->target
= target
; }
80 const entry_ref
* NextRef();
86 CachedEntryIterator
* cachingIterator
;
87 int32 searchPathIndex
;
89 bigtime_t lastCycleLap
;
99 class IconTestWindow
: public BWindow
{
102 bool QuitRequested();
104 IconSpewer iconSpewer
;
107 } // namespace BTrackerPrivate
110 // #pragma mark - IconSpewer
113 IconSpewer::IconSpewer(bool newCache
)
124 walker
= new TNodeWalker(pathsToSearch
[searchPathIndex
++]);
126 cachingIterator
= new CachedEntryIterator(walker
, 40);
130 IconSpewer::~IconSpewer()
133 delete cachingIterator
;
140 BStopWatch
watch("", true);
142 AutoLock
<BLocker
> lock(locker
);
144 if (!lock
|| quitting
)
159 kill_thread(fScanThread
);
164 const icon_size kIconSize
= B_LARGE_ICON
;
165 const int32 kRowCount
= 10;
166 const int32 kColumnCount
= 10;
170 IconSpewer::DrawSomeNew()
173 BView
* view
= target
->FindView("iconView");
176 BRect
bounds(target
->Bounds());
177 view
->SetHighColor(Color(255, 255, 255));
178 view
->FillRect(bounds
);
180 view
->SetHighColor(Color(0, 0, 0));
183 sprintf(buffer
, "last cycle time %" B_PRId64
" ms", cycleTime
/1000);
184 view
->DrawString(buffer
, BPoint(20, bounds
.bottom
- 20));
188 sprintf(buffer
, "average draw time %" B_PRId64
" us per icon",
189 watch
.ElapsedTime() / numDrawn
);
190 view
->DrawString(buffer
, BPoint(20, bounds
.bottom
- 30));
193 sprintf(buffer
, "directory: %s", currentPath
.Path());
194 view
->DrawString(buffer
, BPoint(20, bounds
.bottom
- 40));
198 for (int32 row
= 0; row
< kRowCount
; row
++) {
199 for (int32 column
= 0; column
< kColumnCount
; column
++) {
200 BEntry
entry(NextRef());
201 Model
model(&entry
, true);
206 if (model
.IsDirectory())
207 entry
.GetPath(¤tPath
);
209 IconCache::sIconCache
->Draw(&model
, view
,
210 BPoint(column
* (kIconSize
+ 2), row
* (kIconSize
+ 2)),
211 kNormalIcon
, kIconSize
, true);
219 bool oldIconCacheInited
= false;
223 IconSpewer::DrawSomeOld()
226 if (!oldIconCacheInited
)
227 BIconCache::InitIconCaches();
230 target
->SetTitle("old cache");
231 BView
* view
= target
->FindView("iconView");
234 BRect
bounds(target
->Bounds());
235 view
->SetHighColor(Color(255, 255, 255));
236 view
->FillRect(bounds
);
238 view
->SetHighColor(Color(0, 0, 0));
241 sprintf(buffer
, "last cycle time %Ld ms", cycleTime
/1000);
242 view
->DrawString(buffer
, BPoint(20, bounds
.bottom
- 20));
245 sprintf(buffer
, "average draw time %Ld us per icon",
246 watch
.ElapsedTime() / numDrawn
);
247 view
->DrawString(buffer
, BPoint(20, bounds
.bottom
- 30));
249 sprintf(buffer
, "directory: %s", currentPath
.Path());
250 view
->DrawString(buffer
, BPoint(20, bounds
.bottom
- 40));
254 for (int32 row
= 0; row
< kRowCount
; row
++) {
255 for (int32 column
= 0; column
< kColumnCount
; column
++) {
256 BEntry
entry(NextRef());
257 BModel
model(&entry
, true);
262 if (model
.IsDirectory())
263 entry
.GetPath(¤tPath
);
265 BIconCache::LockIconCache();
266 BIconCache
* iconCache
267 = BIconCache::GetIconCache(&model
, kIconSize
);
268 iconCache
->Draw(view
, BPoint(column
* (kIconSize
+ 2),
269 row
* (kIconSize
+ 2)), B_NORMAL_ICON
, kIconSize
, true);
270 BIconCache::UnlockIconCache();
281 IconSpewer::NextRef()
285 result
= cachingIterator
->GetNextRef(&ref
);
287 result
= walker
->GetNextRef(&ref
);
293 if (!pathsToSearch
[searchPathIndex
]) {
294 bigtime_t now
= watch
.ElapsedTime();
295 cycleTime
= now
- lastCycleLap
;
297 PRINT(("**************************hit end of disk, starting over\n"));
301 walker
= new TNodeWalker(pathsToSearch
[searchPathIndex
++]);
303 cachingIterator
->SetTo(walker
);
304 result
= cachingIterator
->GetNextRef(&ref
);
306 result
= walker
->GetNextRef(&ref
);
308 ASSERT(result
== B_OK
);
309 // we don't expect and cannot deal with any problems here
314 // #pragma mark - IconTestWindow
317 IconTestWindow::IconTestWindow()
319 BWindow(BRect(100, 100, 500, 600), "icon cache test",
320 B_TITLED_WINDOW_LOOK
, B_NORMAL_WINDOW_FEEL
, 0),
321 iconSpewer(modifiers() == 0)
323 iconSpewer
.SetTarget(this);
324 BView
* view
= new BView(Bounds(), "iconView", B_FOLLOW_ALL
, B_WILL_DRAW
);
331 IconTestWindow::QuitRequested()
341 (new IconTestWindow())->Show();