Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[windows] [gui] Support ti.GUI(fast_gui=True) on Win32 #1953

Merged
merged 7 commits into from
Oct 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ __pycache__
*.jpg
*.egg-info
.tlang_cache
.tidle_*
/taichi/common/version.h
/taichi/common/commit_hash.h
/python/test_env
Expand Down
12 changes: 6 additions & 6 deletions python/taichi/lang/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def subscript(value, *indices):
if isinstance(value, np.ndarray):
return value.__getitem__(*indices)

if isinstance(value, tuple) or isinstance(value, list):
if isinstance(value, (tuple, list, dict)):
assert len(indices) == 1
return value[indices[0]]

Expand Down Expand Up @@ -243,6 +243,7 @@ def layout():

for func in self.materialize_callbacks:
func()
self.materialize_callbacks = []

def clear(self):
if self.prog:
Expand Down Expand Up @@ -534,12 +535,11 @@ def static(x, *xs):
return [static(x)] + [static(x) for x in xs]
import types
import taichi as ti
if isinstance(x, (bool, int, float, range, list, tuple, enumerate,
ti.ndrange, ti.GroupedNDRange)) or x is None:
return x
elif isinstance(x, ti.lang.expr.Expr) and x.ptr.is_global_var():
if isinstance(x,
(bool, int, float, range, list, tuple, enumerate, ti.ndrange,
ti.GroupedNDRange, zip, filter, map)) or x is None:
return x
elif isinstance(x, ti.Matrix) and x.is_global():
elif isinstance(x, (ti.Expr, ti.Matrix)) and x.is_global():
return x
elif isinstance(x, (types.FunctionType, types.MethodType)):
return x
Expand Down
10 changes: 2 additions & 8 deletions python/taichi/lang/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ def tensor_to_ext_arr(tensor: ti.template(), arr: ti.ext_arr()):
arr[I] = tensor[I]


@ti.func
def cook_image_type(x):
x = ti.cast(x, ti.f32)
return x


@ti.kernel
def vector_to_fast_image(img: ti.template(), out: ti.ext_arr()):
# FIXME: Why is ``for i, j in img:`` slower than:
Expand All @@ -34,7 +28,7 @@ def vector_to_fast_image(img: ti.template(), out: ti.ext_arr()):
@ti.kernel
def tensor_to_image(tensor: ti.template(), arr: ti.ext_arr()):
for I in ti.grouped(tensor):
t = cook_image_type(tensor[I])
t = ti.cast(tensor[I], ti.f32)
arr[I, 0] = t
arr[I, 1] = t
arr[I, 2] = t
Expand All @@ -44,7 +38,7 @@ def tensor_to_image(tensor: ti.template(), arr: ti.ext_arr()):
def vector_to_image(mat: ti.template(), arr: ti.ext_arr()):
for I in ti.grouped(mat):
for p in ti.static(range(mat.n)):
arr[I, p] = cook_image_type(mat[I][p])
arr[I, p] = ti.cast(mat[I][p], ti.f32)
if ti.static(mat.n <= 2):
arr[I, 2] = 0

Expand Down
2 changes: 1 addition & 1 deletion python/taichi/lang/ndrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def __init__(self, *args):
args = list(args)
for i in range(len(args)):
if isinstance(args[i], list):
args[i] = list(args[i])
args[i] = tuple(args[i])
if not isinstance(args[i], tuple):
args[i] = (0, args[i])
assert len(args[i]) == 2
Expand Down
23 changes: 13 additions & 10 deletions taichi/gui/win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,21 @@ void GUI::create_window() {

void GUI::redraw() {
UpdateWindow(hwnd);
// http:// www.cplusplus.com/reference/cstdlib/calloc/
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
auto c = reinterpret_cast<unsigned char *>(data + (j * width) + i);
auto d = canvas->img[i][height - j - 1];
c[0] = uint8(clamp(int(d[2] * 255.0_f), 0, 255));
c[1] = uint8(clamp(int(d[1] * 255.0_f), 0, 255));
c[2] = uint8(clamp(int(d[0] * 255.0_f), 0, 255));
c[3] = 0;
if (!fast_gui) {
// http://www.cplusplus.com/reference/cstdlib/calloc/
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
auto c = reinterpret_cast<unsigned char *>(data + (j * width) + i);
auto d = canvas->img[i][height - j - 1];
c[0] = uint8(clamp(int(d[2] * 255.0_f), 0, 255));
c[1] = uint8(clamp(int(d[1] * 255.0_f), 0, 255));
c[2] = uint8(clamp(int(d[0] * 255.0_f), 0, 255));
c[3] = 0;
}
}
}
bitmap = CreateBitmap(width, height, 1, 32, (void *)data);
bitmap = CreateBitmap(width, height, 1, 32,
fast_gui ? (void *)fast_buf : (void *)data);
SelectObject(src, bitmap);
BitBlt(hdc, 0, 0, width, height, src, 0, 0, SRCCOPY);
DeleteObject(bitmap);
Expand Down