Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-webassembly-examples
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Morten Sorvig
qt-webassembly-examples
Commits
27cc01c0
Commit
27cc01c0
authored
5 years ago
by
Morten Sorvig
Browse files
Options
Downloads
Patches
Plain Diff
Apply some fixes:
- tile size calculation - work around QTBUG-75793
parent
8befa85d
Branches
5.13
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mandelbrot/main.cpp
+1
-1
1 addition, 1 deletion
mandelbrot/main.cpp
mandelbrot/renderthread.cpp
+29
-21
29 additions, 21 deletions
mandelbrot/renderthread.cpp
mandelbrot/renderthread.h
+1
-3
1 addition, 3 deletions
mandelbrot/renderthread.h
with
31 additions
and
25 deletions
mandelbrot/main.cpp
+
1
−
1
View file @
27cc01c0
...
...
@@ -57,7 +57,7 @@ int main(int argc, char *argv[])
{
QApplication
app
(
argc
,
argv
);
//
w
e're managing the number of threads elsewhere; set the global
//
W
e're managing the number of threads elsewhere; set the global
// thread limit to a large value so it won't interfere.
QThreadPool
::
globalInstance
()
->
setMaxThreadCount
(
1024
);
...
...
This diff is collapsed.
Click to expand it.
mandelbrot/renderthread.cpp
+
29
−
21
View file @
27cc01c0
...
...
@@ -55,6 +55,10 @@
#include
<QThreadPool>
#include
<cmath>
#ifdef Q_OS_WASM
#include
<emscripten.h>
#endif
// runs function on a thread from the global QThreadPool, returns a
// function that can be called to vait for the function to finish.
std
::
function
<
void
()
>
runOnThread
(
std
::
function
<
void
()
>
fn
)
...
...
@@ -157,14 +161,21 @@ MandelbrotRenderer::RenderPassResult MandelbrotRenderer::renderTile(int tile, in
QSize
imageSize
=
image
->
size
();
int
halfWidth
=
imageSize
.
width
()
/
2
;
int
halfHeight
=
imageSize
.
height
()
/
2
;
this
->
tileSize
=
(
imageSize
.
height
()
+
this
->
tileCount
-
1
)
/
this
->
tileCount
;
const
int
MaxIterations
=
(
1
<<
(
2
*
pass
+
6
))
+
32
;
const
int
Limit
=
4
;
bool
allBlack
=
true
;
int
beginY
=
tileBegin
(
tile
,
imageSize
.
height
())
-
halfHeight
;
int
endY
=
tileEnd
(
tile
,
imageSize
.
height
())
-
halfHeight
;
// qDebug() << "redner tile" << tile << tileBegin(tile, imageSize.height()) << beginY << endY << imageSize.height() << (beginY + halfHeight) << (endY -1 + halfHeight) << QThread::currentThread();
#if 0
qDebug() << "render tile" << tile
<< "tileBegin" << tileBegin(tile, imageSize.height()) << "tileEnd" << tileEnd(tile, imageSize.height())
<< "beginY" << beginY << "endY" << endY
<< "lines" << beginY + halfHeight << endY + halfHeight
<< "image height" << imageSize.height();
#endif
for
(
int
y
=
beginY
;
y
<
endY
;
++
y
)
{
if
(
shouldAbort
())
...
...
@@ -300,14 +311,13 @@ uint MandelbrotRenderer::rgbFromWaveLength(double wave)
int
MandelbrotRenderer
::
tileBegin
(
int
tileIndex
,
int
totalSize
)
{
int
tileSize
=
(
totalSize
/
(
tileCount
-
1
)
);
return
tileIndex
*
tileSize
;
Q_UNUSED
(
totalSize
);
return
tileIndex
*
this
->
tileSize
;
}
int
MandelbrotRenderer
::
tileEnd
(
int
tileIndex
,
int
totalSize
)
{
int
tileSize
=
(
totalSize
/
(
tileCount
-
1
));
return
(
tileIndex
*
tileSize
+
tileSize
)
%
(
totalSize
);
return
qMin
(
tileIndex
*
this
->
tileSize
+
this
->
tileSize
,
totalSize
);
}
RenderThread
::
RenderThread
(
int
threadCount
,
QObject
*
parent
)
...
...
@@ -315,21 +325,19 @@ RenderThread::RenderThread(int threadCount, QObject *parent)
{
restart
=
false
;
abort
=
false
;
int
threadAndTileCount
=
threadCount
;
renderer
=
new
MandelbrotRenderer
(
threadAndTileCount
*
2
,
threadAndTileCount
,
[
this
]()
->
bool
{
QMutexLocker
locker
(
&
mutex
);
return
abort
||
restart
;
},
[
this
](
const
QImage
&
image
,
double
scaleFactor
)
{
qDebug
()
<<
"emit renderedImage"
;
emit
renderedImage
(
image
.
copy
(),
scaleFactor
);
}
);
int
tileCount
=
threadCount
*
2
;
auto
shouldAbort
=
[
this
]()
->
bool
{
QMutexLocker
locker
(
&
mutex
);
return
abort
||
restart
;
};
auto
imageReady
=
[
this
](
const
QImage
&
image
,
double
scaleFactor
)
{
emit
renderedImage
(
image
.
copy
(),
scaleFactor
);
#ifdef Q_OS_WASM
MAIN_THREAD_ASYNC_EM_ASM
(
"Browser.mainLoop.resume();"
);
#endif
};
renderer
=
new
MandelbrotRenderer
(
tileCount
,
threadCount
,
shouldAbort
,
imageReady
);
}
RenderThread
::~
RenderThread
()
...
...
This diff is collapsed.
Click to expand it.
mandelbrot/renderthread.h
+
1
−
3
View file @
27cc01c0
...
...
@@ -80,6 +80,7 @@ public:
private
:
int
tileCount
;
int
tileSize
;
int
threadCount
;
std
::
function
<
bool
()
>
shouldAbort
;
std
::
function
<
void
(
const
QImage
&
,
double
scaleFactor
)
>
imageReady
;
...
...
@@ -92,11 +93,8 @@ class ThreadPack
{
public:
ThreadPack
(
int
threadCount
);
template
<
typename
T
>
T
pforeach
(
int
begin
,
int
end
,
std
::
function
<
T
(
int
)
>
);
private:
void
threadFunction
();
int
threadCount
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment