-
-
Notifications
You must be signed in to change notification settings - Fork 67
Creating child window for rendering #285
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
Merged
highperformancecoder
merged 9 commits into
highperformancecoder:RESTService-branch
from
digiperfect:RESTService-branch
Feb 24, 2021
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3d7408b
Initial rendering code commit
digiperfect-tech 1733fe1
Struct for WindowInformation and reusing the child window across repa…
digiperfect-tech c119dd7
offset reversal fixed
digiperfect-tech d14090c
Added processing of offset arguments, though they don't work
digiperfect-tech 01eeda1
winInfo made public
digiperfect-tech 9131626
function placeholder
digiperfect-tech 446d6e3
WindowInformation in separate file
digiperfect-tech 2be7a38
Pass parentWindowId and offsets etc with each call to renderFrame
digiperfect-tech ac55587
Moved surface and all window bookkeeping logic to WindowInformation
digiperfect-tech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,13 +23,19 @@ | |
| #include <cairoSurfaceImage.h> | ||
|
|
||
| namespace minsky | ||
| { | ||
| class RenderNativeWindow: public ecolab::CairoSurface | ||
| { | ||
| class WindowInformation; | ||
| class RenderNativeWindow : public ecolab::CairoSurface | ||
| { | ||
| public: | ||
| void renderToNativeWindow(unsigned long window); | ||
| private: | ||
| CLASSDESC_ACCESS(RenderNativeWindow); | ||
| std::shared_ptr<WindowInformation> winInfoPtr; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you will probably have to classdesc::Exclude this member. |
||
|
|
||
| public: | ||
| void resizeWindow(int offsetLeft, int offsetTop, int childWidth, int childHeight); | ||
| void renderFrame(unsigned long parentWindowId, int offsetLeft, int offsetTop, int childWidth, int childHeight); | ||
| }; | ||
| } | ||
| } // namespace minsky | ||
|
|
||
| #include "renderNativeWindow.cd" | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| /* | ||
| @copyright Steve Keen 2021 | ||
| @author Janak Porwal | ||
| This file is part of Minsky. | ||
|
|
||
| Minsky is free software: you can redistribute it and/or modify it | ||
| under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| Minsky is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with Minsky. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #include "windowInformation.h" | ||
| #include "minsky_epilogue.h" | ||
|
|
||
| #include <stdexcept> | ||
| #include <string> | ||
|
|
||
| #if defined(CAIRO_HAS_XLIB_SURFACE) && !defined(MAC_OSX_TK) | ||
| #include <cairo/cairo-xlib.h> | ||
| #include <X11/Xlib.h> | ||
| #endif | ||
|
|
||
| #if defined(CAIRO_HAS_WIN32_SURFACE) && !defined(__CYGWIN__) | ||
| #define USE_WIN32_SURFACE | ||
| #endif | ||
|
|
||
| #ifdef _WIN32 | ||
| #undef Realloc | ||
| #include <windows.h> | ||
| #include <wingdi.h> | ||
| #ifdef USE_WIN32_SURFACE | ||
| #include <cairo/cairo-win32.h> | ||
| #endif | ||
| #endif | ||
|
|
||
| #if defined(MAC_OSX_TK) | ||
| #include <Carbon/Carbon.h> | ||
| #include <cairo/cairo-quartz.h> | ||
| #include "getContext.h" | ||
| #endif | ||
|
|
||
| using namespace std; | ||
| using namespace ecolab; | ||
|
|
||
| namespace minsky | ||
| { | ||
|
|
||
| #ifdef USE_WIN32_SURFACE | ||
| #elif defined(MAC_OSX_TK) | ||
| #else | ||
| int throwOnXError(Display *, XErrorEvent *ev) | ||
| { | ||
| char errorMessage[256]; | ||
| XGetErrorText(ev->display, ev->error_code, errorMessage, sizeof(errorMessage)); | ||
| throw runtime_error(errorMessage); | ||
| } | ||
| #endif | ||
|
|
||
| unsigned long WindowInformation::getChildWindowId() { | ||
| return childWindowId; | ||
| } | ||
|
|
||
| Display *WindowInformation::getDisplay() { | ||
| return display; | ||
| } | ||
|
|
||
| WindowInformation::~WindowInformation() { | ||
| childSurface.reset(); | ||
| XDestroyWindow(display, childWindowId); | ||
| } | ||
|
|
||
| ecolab::cairo::SurfacePtr WindowInformation::getSurface() { | ||
| return childSurface; | ||
| } | ||
|
|
||
| void WindowInformation::createSurface(){ | ||
| #ifdef USE_WIN32_SURFACE | ||
| { | ||
| /* TODO */ | ||
| } | ||
| #elif defined(MAC_OSX_TK) | ||
|
|
||
| { | ||
| /* TODO */ | ||
| } | ||
| #else | ||
| {childSurface.reset(new cairo::Surface(cairo_xlib_surface_create(getDisplay(), getChildWindowId(), wAttr.visual, childWidth, childHeight), childWidth, childHeight)); | ||
| cairo_surface_set_device_offset(childSurface->surface(), -wAttr.x, -wAttr.y); | ||
| } | ||
| #endif | ||
| } | ||
|
|
||
| WindowInformation::WindowInformation(unsigned long parentWin, int left, int top, int cWidth, int cHeight) | ||
| { | ||
| parentWindowId = parentWin; | ||
| offsetLeft = left; | ||
| offsetTop = top; | ||
|
|
||
| static bool errorHandlingSet = (XSetErrorHandler(throwOnXError), true); | ||
| display = XOpenDisplay(nullptr); | ||
| int err = XGetWindowAttributes(display, parentWin, &wAttr); | ||
| if (err > 1) | ||
| throw runtime_error("Invalid window: " + to_string(parentWin)); | ||
|
|
||
| childWidth = wAttr.width - offsetLeft; | ||
| childHeight = wAttr.height - offsetTop; | ||
|
|
||
| // TODO:: Take care of scrollbars | ||
|
|
||
| if (cWidth > 0) { | ||
| childWidth = min(childWidth, cWidth); | ||
| } | ||
|
|
||
| if (cHeight > 0) { | ||
| childHeight = min(childHeight, cHeight); | ||
| } | ||
|
|
||
| childWindowId = XCreateSimpleWindow(display, parentWin, offsetLeft, offsetTop, childWidth, childHeight, 0, 0, 0); //TODO:: Should we pass visual and attributes at the end? | ||
highperformancecoder marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| XMapWindow(display, childWindowId); | ||
| createSurface(); | ||
| } | ||
| } // namespace minsky | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| @copyright Steve Keen 2021 | ||
| @author Janak Porwal | ||
| This file is part of Minsky. | ||
|
|
||
| Minsky is free software: you can redistribute it and/or modify it | ||
| under the terms of the GNU General Public License as published by | ||
| the Free Software Foundation, either version 3 of the License, or | ||
| (at your option) any later version. | ||
|
|
||
| Minsky is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with Minsky. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| #ifndef WINDOW_INFORMATION_H | ||
| #define WINDOW_INFORMATION_H | ||
|
|
||
| #include <cairoSurfaceImage.h> | ||
| #include <X11/Xlib.h> | ||
|
|
||
| namespace minsky | ||
| { | ||
| class WindowInformation | ||
| { | ||
| unsigned long parentWindowId; | ||
| unsigned long childWindowId; | ||
|
|
||
| Display* display; // Weak reference, returned by system | ||
| ecolab::cairo::SurfacePtr childSurface; | ||
|
|
||
| private: | ||
| void createSurface(); | ||
| public: | ||
| int childWidth; | ||
| int childHeight; | ||
| int offsetLeft; | ||
| int offsetTop; | ||
|
|
||
| XWindowAttributes wAttr; | ||
| unsigned long getChildWindowId(); | ||
| Display* getDisplay(); | ||
|
|
||
| public: | ||
| ~WindowInformation(); | ||
| WindowInformation(unsigned long parentWin, int left, int top, int cWidth, int cHeight); | ||
|
|
||
| ecolab::cairo::SurfacePtr getSurface(); | ||
|
|
||
| WindowInformation(const WindowInformation&)=delete; | ||
| void operator=(const WindowInformation&)=delete; | ||
| }; | ||
| } // namespace minsky | ||
|
|
||
| #endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My intuition is that painting the background canvas is not necessary for X11, but might be for Windows. I guess we should suck it and see.