|
@@ -10,79 +10,121 @@
|
10
|
10
|
|
11
|
11
|
class TestApp1 : public DKApplication
|
12
|
12
|
{
|
13
|
|
- DKObject<DKWindow> window;
|
14
|
|
- DKObject<DKThread> renderThread;
|
15
|
|
-
|
16
|
|
- DKAtomicNumber32 runningRenderThread;
|
17
|
13
|
public:
|
18
|
|
- void RenderThread(void)
|
|
14
|
+
|
|
15
|
+ void OnInitialize(void) override
|
19
|
16
|
{
|
20
|
|
- DKObject<DKGraphicsDevice> device = DKGraphicsDevice::SharedInstance();
|
21
|
|
- DKObject<DKCommandQueue> queue = device->CreateCommandQueue();
|
22
|
|
- DKObject<DKSwapChain> swapChain = queue->CreateSwapChain(window);
|
|
17
|
+ DKLogD("%s", DKGL_FUNCTION_NAME);
|
23
|
18
|
|
24
|
19
|
DKTimer timer;
|
25
|
|
- timer.Reset();
|
26
|
|
-
|
27
|
|
- DKLog("Render thread begin");
|
28
|
|
- while (!runningRenderThread.CompareAndSet(0, 0))
|
|
20
|
+ for (auto format : { DKCompressor::Deflate, DKCompressor::LZ4, DKCompressor::LZ4HC })
|
29
|
21
|
{
|
30
|
|
- DKRenderPassDescriptor rpd = swapChain->CurrentRenderPassDescriptor();
|
31
|
|
- double t = timer.Elapsed();
|
32
|
|
- t = (cos(t) + 1.0) * 0.5;
|
33
|
|
- rpd.colorAttachments.Value(0).clearColor = DKColor(t, 0.0, 0.0, 0.0);
|
34
|
|
-
|
35
|
|
- DKObject<DKCommandBuffer> buffer = queue->CreateCommandBuffer();
|
36
|
|
- DKObject<DKRenderCommandEncoder> encoder = buffer->CreateRenderCommandEncoder(rpd);
|
37
|
|
- if (encoder)
|
|
22
|
+ const char* fmt = [](DKCompressor::Method m) {
|
|
23
|
+ switch (m)
|
|
24
|
+ {
|
|
25
|
+ case DKCompressor::Deflate: return "DEFLATE";
|
|
26
|
+ case DKCompressor::LZ4: return "LZ4";
|
|
27
|
+ case DKCompressor::LZ4HC: return "LZ4HC";
|
|
28
|
+ }
|
|
29
|
+ return "Unknown";
|
|
30
|
+ }(format);
|
|
31
|
+
|
|
32
|
+ auto GetFileSizeStr = [](const DKFile* file)
|
38
|
33
|
{
|
39
|
|
- // draw scene!
|
40
|
|
-
|
41
|
|
- encoder->EndEncoding();
|
42
|
|
- buffer->Commit();
|
43
|
|
- //buffer->WaitUntilCompleted();
|
44
|
|
- swapChain->Present();
|
|
34
|
+ size_t s = file->TotalLength();
|
|
35
|
+ if (s > size_t(1) << 40)
|
|
36
|
+ {
|
|
37
|
+ size_t d = size_t(1) << 40;
|
|
38
|
+ double n = static_cast<double>(s / d);
|
|
39
|
+ double f = static_cast<double>(s % d) / static_cast<double>(d);
|
|
40
|
+ return DKString::Format("%.3fTB", n + f);
|
|
41
|
+ }
|
|
42
|
+ if (s > size_t(1) << 30)
|
|
43
|
+ {
|
|
44
|
+ size_t d = size_t(1) << 30;
|
|
45
|
+ double n = static_cast<double>(s / d);
|
|
46
|
+ double f = static_cast<double>(s % d) / static_cast<double>(d);
|
|
47
|
+ return DKString::Format("%.3fGB", n + f);
|
|
48
|
+ }
|
|
49
|
+ if (s > size_t(1) << 20)
|
|
50
|
+ {
|
|
51
|
+ size_t d = size_t(1) << 20;
|
|
52
|
+ double n = static_cast<double>(s / d);
|
|
53
|
+ double f = static_cast<double>(s % d) / static_cast<double>(d);
|
|
54
|
+ return DKString::Format("%.3fMB", n + f);
|
|
55
|
+ }
|
|
56
|
+ if (s > size_t(1) << 10)
|
|
57
|
+ {
|
|
58
|
+ size_t d = size_t(1) << 10;
|
|
59
|
+ double n = static_cast<double>(s / d);
|
|
60
|
+ double f = static_cast<double>(s % d) / static_cast<double>(d);
|
|
61
|
+ return DKString::Format("%.3fKB", n + f);
|
|
62
|
+ }
|
|
63
|
+ return DKString::Format("%dB", s);
|
|
64
|
+ };
|
|
65
|
+
|
|
66
|
+ DKString filename1 = "C:\\Users\\hong\\desktop\\test\\1";
|
|
67
|
+ DKString filename2 = filename1 + "." + fmt;
|
|
68
|
+ DKString filename3 = filename2 + ".dec";
|
|
69
|
+ DKObject<DKFile> f1 = DKFile::Create(filename1, DKFile::ModeOpenExisting, DKFile::ModeShareRead);
|
|
70
|
+ DKObject<DKFile> f2 = DKFile::Create(filename2, DKFile::ModeOpenNew, DKFile::ModeShareExclusive);
|
|
71
|
+ DKObject<DKFile> f3 = DKFile::Create(filename3, DKFile::ModeOpenNew, DKFile::ModeShareExclusive);
|
|
72
|
+
|
|
73
|
+ DKLog("--> Compressing %s", fmt);
|
|
74
|
+ DKCompressor comp(format);
|
|
75
|
+
|
|
76
|
+ bool result;
|
|
77
|
+ timer.Reset();
|
|
78
|
+ // compress
|
|
79
|
+ result = comp.Compress(f1, f2);
|
|
80
|
+ double elapsed = timer.Elapsed();
|
|
81
|
+
|
|
82
|
+ if (result)
|
|
83
|
+ DKLog("File Compressed (%s): %ls -> %ls (%fsec)", fmt,
|
|
84
|
+ (const wchar_t*)GetFileSizeStr(f1), (const wchar_t*)GetFileSizeStr(f2), elapsed);
|
|
85
|
+ else
|
|
86
|
+ {
|
|
87
|
+ DKLog("File Compression failed");
|
|
88
|
+ continue;
|
45
|
89
|
}
|
|
90
|
+
|
|
91
|
+ f2->SetCurrentPosition(0);
|
|
92
|
+ timer.Reset();
|
|
93
|
+ // decompress
|
|
94
|
+ result = DKCompressor::Decompress(f2, f3);
|
|
95
|
+ elapsed = timer.Elapsed();
|
|
96
|
+
|
|
97
|
+ if (result)
|
|
98
|
+ DKLog("File Decompressed (%s): %ls -> %ls (%fsec)", fmt,
|
|
99
|
+ (const wchar_t*)GetFileSizeStr(f2), (const wchar_t*)GetFileSizeStr(f3), elapsed);
|
46
|
100
|
else
|
47
|
101
|
{
|
|
102
|
+ DKLog("File Decompression failed");
|
|
103
|
+ continue;
|
48
|
104
|
}
|
49
|
105
|
|
50
|
|
- DKThread::Sleep(0.01);
|
51
|
|
- }
|
52
|
|
- DKLog("RenderThread terminating...");
|
53
|
|
- }
|
|
106
|
+ // generate hash
|
|
107
|
+ for (DKFile* f : { f1.Ptr(), f2.Ptr(), f3.Ptr() })
|
|
108
|
+ {
|
|
109
|
+ DKString path = f->Path();
|
|
110
|
+ f->SetCurrentPosition(0);
|
|
111
|
+ DKHashResultSHA1 sha1;
|
|
112
|
+ if (DKHashSHA1(f, sha1))
|
|
113
|
+ {
|
|
114
|
+ DKLog("SHA1(%ls): %ls", (const wchar_t*)path, (const wchar_t*)sha1.String());
|
|
115
|
+ }
|
|
116
|
+ else
|
|
117
|
+ DKLog("SHA1(%ls) failed!", (const wchar_t*)path);
|
|
118
|
+ }
|
54
|
119
|
|
55
|
|
- void OnInitialize(void) override
|
56
|
|
- {
|
57
|
|
- DKLogD("%s", DKGL_FUNCTION_NAME);
|
58
|
|
- try {
|
59
|
|
- window = DKWindow::Create("DefaultWindow");
|
60
|
|
- }
|
61
|
|
- catch (DKError& e)
|
62
|
|
- {
|
63
|
|
- DKLogE("error? :%ls", (const wchar_t*)e.Description());
|
64
|
120
|
}
|
65
|
|
- window->Activate();
|
66
|
121
|
|
67
|
|
- window->AddEventHandler(this,
|
68
|
|
- DKFunction([this](const DKWindow::WindowEvent& e) {
|
69
|
|
- if (e.type == DKWindow::WindowEvent::WindowClosed)
|
70
|
|
- DKApplication::Instance()->Terminate(0);
|
71
|
|
- }),
|
72
|
|
- NULL, NULL);
|
73
|
|
-
|
74
|
|
- runningRenderThread = 1;
|
75
|
|
- renderThread = DKThread::Create(DKFunction(this, &TestApp1::RenderThread)->Invocation());
|
|
122
|
+ Terminate(0);
|
76
|
123
|
}
|
77
|
124
|
void OnTerminate(void) override
|
78
|
125
|
{
|
79
|
126
|
DKLogD("%s", DKGL_FUNCTION_NAME);
|
80
|
127
|
|
81
|
|
- runningRenderThread = 0;
|
82
|
|
- renderThread->WaitTerminate();
|
83
|
|
- renderThread = NULL;
|
84
|
|
- window = NULL;
|
85
|
|
-
|
86
|
128
|
DKLogI("Memory Pool Statistics");
|
87
|
129
|
size_t numBuckets = DKMemoryPoolNumberOfBuckets();
|
88
|
130
|
DKMemoryPoolBucketStatus* buckets = new DKMemoryPoolBucketStatus[numBuckets];
|