1 | |
2 | // |
3 | // This source file is part of appleseed. |
4 | // Visit http://appleseedhq.net/ for additional information and resources. |
5 | // |
6 | // This software is released under the MIT license. |
7 | // |
8 | // Copyright (c) 2012-2013 Esteban Tovagliari, Jupiter Jazz Limited |
9 | // Copyright (c) 2014-2017 Esteban Tovagliari, The appleseedhq Organization |
10 | // |
11 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
12 | // of this software and associated documentation files (the "Software"), to deal |
13 | // in the Software without restriction, including without limitation the rights |
14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
15 | // copies of the Software, and to permit persons to whom the Software is |
16 | // furnished to do so, subject to the following conditions: |
17 | // |
18 | // The above copyright notice and this permission notice shall be included in |
19 | // all copies or substantial portions of the Software. |
20 | // |
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
27 | // THE SOFTWARE. |
28 | // |
29 | |
30 | // appleseed.python headers. |
31 | #include "pyseed.h" // has to be first, to avoid redefinition warnings |
32 | #include "gillocks.h" |
33 | |
34 | // appleseed.renderer headers. |
35 | #include "renderer/api/frame.h" |
36 | #include "renderer/kernel/rendering/itilecallback.h" |
37 | |
38 | // appleseed.foundation headers. |
39 | #include "foundation/platform/compiler.h" |
40 | |
41 | namespace bpy = boost::python; |
42 | using namespace foundation; |
43 | using namespace renderer; |
44 | |
45 | namespace |
46 | { |
47 | class ITileCallbackWrapper |
48 | : public ITileCallback |
49 | , public bpy::wrapper<ITileCallback> |
50 | { |
51 | public: |
52 | virtual void release() APPLESEED_OVERRIDE |
53 | { |
54 | delete this; |
55 | } |
56 | |
57 | virtual void pre_render(const size_t x, const size_t y, const size_t width, const size_t height) APPLESEED_OVERRIDE |
58 | { |
59 | // Lock Python's global interpreter lock (GIL), |
60 | // it was released in MasterRenderer.render. |
61 | ScopedGILLock lock; |
62 | |
63 | if (bpy::override f = this->get_override("pre_render" )) |
64 | f(x, y, width, height); |
65 | } |
66 | |
67 | void default_pre_render(const size_t x, const size_t y, const size_t width, const size_t height) |
68 | { |
69 | } |
70 | |
71 | virtual void post_render_tile(const Frame* frame, const size_t tile_x, const size_t tile_y) APPLESEED_OVERRIDE |
72 | { |
73 | // Lock Python's global interpreter lock (GIL), |
74 | // it was released in MasterRenderer.render. |
75 | ScopedGILLock lock; |
76 | |
77 | if (bpy::override f = this->get_override("post_render_tile" )) |
78 | f(bpy::ptr(frame), tile_x, tile_y); |
79 | } |
80 | |
81 | void default_post_render_tile(const Frame* frame, const size_t tile_x, const size_t tile_y) |
82 | { |
83 | } |
84 | |
85 | virtual void post_render(const Frame* frame) APPLESEED_OVERRIDE |
86 | { |
87 | // Lock Python's global interpreter lock (GIL), |
88 | // it was released in MasterRenderer.render. |
89 | ScopedGILLock lock; |
90 | |
91 | if (bpy::override f = this->get_override("post_render" )) |
92 | f(bpy::ptr(frame)); |
93 | } |
94 | |
95 | void default_post_render(const Frame* frame) |
96 | { |
97 | } |
98 | }; |
99 | } |
100 | |
101 | void bind_tile_callback() |
102 | { |
103 | bpy::class_<ITileCallbackWrapper, boost::noncopyable>("ITileCallback" ) |
104 | .def("pre_render" , &ITileCallback::pre_render, &ITileCallbackWrapper::default_pre_render) |
105 | .def("post_render_tile" , &ITileCallback::post_render_tile, &ITileCallbackWrapper::default_post_render_tile) |
106 | .def("post_render" , &ITileCallback::post_render, &ITileCallbackWrapper::default_post_render) |
107 | ; |
108 | } |
109 | |