Porting applications from windows

Porting from Windows to Linux, part 1

Hi and welcome to a blog series about how to port graphics applications from Windows to Linux. The series will have three parts: Today, in the first part, we’ll be looking at prerequisites for porting. These are things you can do any time to facilitate porting later on, while still working on Windows exclusively. In the second part, the actual porting work will be done, and in the last part, I’ll talk a bit about the finishing touches, rough edges, and how to keep everything working. All of this is based on my experience with porting my research framework; which is a medium-sized project (

180 kLoC) that supports Linux, Windows and Mac OS X.

However, before we start, let’s assess the state of the project before the porting begins. For this series, I assume you have a Visual Studio based solution written in C++, with Direct3D being used for graphics. Your primary development environment is Visual Studio, and you haven’t developed for Linux before. You’re now at the point where you want to add Linux support to your application while keeping Windows intact – so we’re not talking about a rushed conversion from Windows to Linux, but of a new port of your application which will be maintained and supported alongside the Windows version.

Prerequisites

Let’s start by sorting out the obvious stuff: Your need a source control solution which will work on Linux. If your project is stored in TFS, now is the time to export everything to your favourite portable source control. If you are not sure what to choose, take Mercurial, which comes with a nice UI for all platforms.

Next, check all your dependencies. If you rely on WIC for image loading, you’ll have to find a portable solution first. In my experience, it’s usually easier to have the same code running on Windows and Linux later on than having a dedicated path for each OS. In my project, I wrapped the low-level libraries like libpng or libjpg directly instead of using a larger image library.

Now is also the time to write tests. You’ll need to be able to quickly verify that everything is working again. If you haven’t written any automated tests yet, this is the moment to start. You’ll mostly need functional tests, for instance, for disk I/O, so focus on those first. I say mostly functional tests, as unit tests tend to be OS agnostic. In my framework, unit tests cover low-level OS facilities like threads and memory allocators, while everything else, including graphics, is covered by functional tests.

For testing, I can highly recommend Google Test. It’s not designed for functional tests right away, but it’s very easy to write a wrapper around a Google Test enabled project for functional testing. My wrapper is written in Python and sets up a new folder for each functional test, executes each test in a new process and gathers all results.

Finally, if you have any build tools, make sure that those are portable now. I used to write them in C# when it was really new, but since a few years, I use only Python for build tools. Python code tends to be easy to maintain and it requires no build process whatsoever, making it ideally suited for build system infrastructure. Which brings us to the most important issue, the build system.

Build system

If you are using Visual Studio (or MSBuild from the command line), stop right now and start porting it to a portable build system. While in theory, MSBuild is portable to Linux using xbuild, in practice, you’ll still want to have a build system which is developed on all three platforms and used for large code bases. I have tried a bunch of them and finally settled with CMake. It uses an arcane scripting language, but it works, and it works reliably on Windows, Linux, and Mac OS X.

Porting from Visual Studio to CMake might seem like a huge effort at first, but it’ll make the transition to Linux much easier later on. The good thing about CMake is that it works perfectly on Windows and it produces Visual Studio project files, so your existing Windows developer experience remains the same. The only difference is that adding new source files now requires you to edit a text file instead of using the IDE directly, but that’s about it.

While writing your CMake files, here’s a few things you should double-check:

  • Are your path names case-sensitive? Windows doesn’t care, but on Linux, your include directory won’t be found if you mess up paths.
  • Are you setting compiler flags directly? Check if CMake already sets them for you before adding a huge list of compiler flags manually.
  • Are your dependencies correctly set up? With Visual Studio, it’s possible to not define all dependencies correctly and still get a correct build; while other build tools will choke on it. Use the graph output of CMake to visualize the dependencies and double check both the build order, and the individual project dependencies.

With CMake, you should also take advantage of the “Find” mechanism for dependencies. On Linux, nearly all dependencies are available as system libraries, serviced by the package manager, so it definitely makes sense to link against the system version of a dependency if it is recent enough.

Читайте также:  Windows 10 служба точек восстановления

The end result of this step should be exactly the same binaries as before, but using CMake as the build system instead of storing the solutions directly in source control. Once this is done, we can start looking at the code.

Clean code

Did you ever #include system headers like in your code? Use system types like DWORD ? Now is the time to clean up and to isolate these things. You want to achieve two goals here:

  • Remove system includes from headers as much as possible.
  • Remove any Visual C++ specific code.

System headers should be only included in source files, if possible. If not, you should isolate the classes/functions and provide generic wrappers around them. For instance, if you have a class for handling files, you can either use the PIMPL idiom or just derive a Windows-specific class from it. The second solution is usually simpler if your file class is already derived from somewhere (a generic stream interface, for instance.) Even if not, we’re wrapping an extremely slow operating system function here (file reads will typically hit the disk), so the cost of a virtual function call won’t matter in practice.

To get rid of Visual C++ specific code, turn on all warnings and treat them as errors. There are a bunch of bogus warnings you can disable (I’ve blogged about them previously), but everything else should get fixed now. In particular, you don’t want any Visual C++ specific extensions enabled in headers. The reason why you want all warnings to be fixed is that on Linux, you’ll be getting hundreds of compile errors and warnings at first, and the less these are swamped by issues that are also present on Windows, the better.

While cleaning up, you should pay special attention to integer sizes. Windows uses 32-bit long s in 64-bit mode, Linux defaults to 64-bit long s. To avoid any confusion, I simply use 64-bit integers when it comes to memory sizes.

The better you clean up your code, the less work you’ll have to spend later during porting. The goal here should be to get everything to build on Windows, with platform specific files identified and isolated.

So much for today! Next week, we’ll look at how to get rid of Direct3D and how to start bringing up the code base on Linux. Stay tuned!

Перенос приложений в Windows 10 Porting apps to Windows 10

В этом разделе описано, как перенести имеющееся приложение на платформу UWP, где можно будет создать один пакет приложения для Windows 10, который пользователи смогут установить на все типы устройств. This section describes how to port your existing app to the Universal Windows Platform (UWP) where you can create a single Windows 10 app package that your customers can install onto all types of devices. В вашем распоряжении будут превосходное аппаратное обеспечение, замечательные возможности получения дохода, современный API, адаптивные элементы управления пользовательским интерфейсом и широкий спектр способов ввода информации, включая мышь, клавиатуру, сенсорные экраны и голосовые команды. Your app will benefit from exciting new hardware, great monetization opportunities, a modern API set, adaptive UI controls, and a range of input modalities including mouse/keyboard, touch, and speech.

Среда выполнения Windows (WinRT) — это технология, которая позволяет создавать приложения универсальной платформы Windows (UWP). The Windows Runtime (WinRT) is the technology that lets you build Universal Windows Platform (UWP) apps. Базовую информацию о приложениях WinRT и UWP см. в разделе Что такое приложение универсальной платформы Windows (UWP)? You can refer to What’s a Universal Windows Platform (UWP) app? for more background on WinRT and UWP apps.

Это руководство по переносу описывает различия между используемой технологией вашего приложения и UWP. This porting guide explains the differences between your current app’s technology and the Universal Windows Platform (UWP). После того, как вы поймете путь между технологиями, вы можете ознакомиться с остальными материалами в Центре разработки, который является универсальным ресурсом для разработки приложений UWP. Once the path between technologies is understood, you’ll be able to dive into the rest of the Developer Center, which is a comprehensive resource for developing UWP apps. Когда вы будете готовы, отличным способом начать знакомство будет раздел Разработка приложений Store. A good way to do that, when you’re ready, is to start with How to develop a Store app.

Porting Windows 7* Applications to Windows 8* Store Apps

Published: 10/10/2012 Last Updated: 10/10/2012

Overview

This article will guide developers in the process of porting a Windows 7 application to a Windows 8 Store app. We will discuss the design considerations, language options, and more.

Why Convert?

One compelling reason to create and port applications to Windows 8 is that users will like them more when designed with a touch-first experience in mind. Touch is arguably more natural for certain types of applications, and these applications make good candidates for being ported to Windows Store apps. Some of the types of applications that are well-suited for conversion include:

  • Casual painting and drawing applications
  • Games – casual games and hardcore games can both benefit from touch
  • Content viewing applications – touch-based interaction with the content for zooming, scrolling, etc.

Why would you want to convert a Windows 7 desktop application to a Windows Store app?There are many potential reasons for doing this:

  • Your application will likely provide a more immersive user experience after enabling it for the Windows 8 touch-based UI
  • Windows Store is a new source of monetization for your app
  • Windows UI look and feel is clean, intuitive touch-based UI
  • Access to Window 8 Runtime APIs, which are new unified APIs for touch, sensors, etc.
  • Support of the latest HTML5/CSS3 features for building HTML/JavaScript*-based store apps
Читайте также:  What is linux freeware

Let’s take a closer look at some of these compelling reasons.

Windows Store

The store is integrated into the Windows 8 experience. Launched directly from the Start Menu, a familiar tile-based look and feel for browsing and downloading applications quickly.

Here is some more information about using the Windows Store to sell your apps:

Windows 8 UI Experience

Touch first, less chrome, fast, fluid; these are just some of the descriptive words used to describe the Windows 8 look and feel. The interface is optimized for mobile form factors and designed to work with finger, mouse, or keyboard input giving users even more ways to interact with their PCs.

The start screen provides a new feature called Live Tiles that gives developers an interesting opportunity to get their app noticed. Live content can be displayed on the tile icon and keep the user updated as to what is new in your application at a glance.

There are even more exciting Window 8 UI features that offer developers opportunities to create compelling Windows 8 apps. Refer to these articles for more on Windows 8 UI features:

Windows 8 Runtime APIs

New for Windows 8 is a set of APIs called the Windows Runtime. The Windows Runtime is a unified set of APIs that can be used in .Net languages, C++, and HTML/JavaScript equally. The Windows Runtime is similar to using the .NET APIs you may be familiar with , but they have been implemented with COM inC++ to allows use from languages other than .Net.. The major differences from traditional .NET APIs include the removal of many of the redundant, obsolete, and legacy APIs.

Porting

Now that you have decided to move your application to Windows 8, what is it going to take? The following sections describe some of the options and challenges in moving to Windows 8.

Touch

Adding touch support to your Windows 8 application is an important aspect of the porting process.

Let’s look at an example of what type of UI in your existing app would probably be ready for a touch-based interface and what would need some work. Here is a screen shot of a popular painting program:


Figure 1 — Main drawing page screen shot using Paint from Microsoft Windows 7*.

Highlighted in red are some of the immediately visible problem areas when thinking about how this application will work with touch.

  • The title and status bars at the top and bottom –Screen real-estate is at a premium on smaller form factors, the space taken up by these status bars is being wasted since the primary purpose of this application is to paint on the canvas.
  • The controls on the menu bar – These small icon controls will be hard to select if only using touch.
  • Color selection – The small icons are a problem along with more screen taken up for colors than anything else besides the canvas. A possible design consideration would be to think about how often a user switches colors, is this something that needs to always be available on the screen?

Let’s now take a look at what a similar application looks like using the Windows 8 Store UI. This is a similar painting program in two modes. The first figure shows the main canvas drawing part of the application. The second image shows what you see when the settings menu is brought up.


Figure 2 — Main canvas screen shot using Microsoft Fresh Paint from Windows 8*

Immediately visible is how the canvas is center stage. The only visible UI besides the canvas are the undo and redo arrows. The settings UI is not immediately visible, but using touch or even a mouse will bring up the menu. A right-click or using your finger to swipe up from the bottom brings up this menu and is shown below:


Figure 3 — Settings screen shot using Microsoft Fresh Paint from Windows 8*

All the same controls are there, you can change your brush, update the color, etc., but now the interface to do this is quite a bit easier if you are using touch. Comparing just the color selection UI, you can tell the buttons are laid out farther apart making it easier to select with just a fingertip. The indicator of what color is selected is also an interesting detail and calls out the color subtly. The status bars that are persistent in the Windows 7 version are there once the settings menu is brought up so nothing is lost.

Here are a couple of great articles for learning more specifics about what makes a good touch-enabled UI:

Development

Now that we have looked at some ideas regarding the UI and touch considerations, we can look at how to create this new great looking application.

One nice feature of developing a Windows Store app is the amount of choices available for creating this new application. Possible choices include:

  • XAML and C++, C# or Visual Basic*
  • HTML5, CSS, and Javascript
  • C++, DirectX*
  • DirectX, XAML, C++
  • A combination of C#, Javascript, and C++

Ideally, your Windows 7 application will already be written in one of these languages or at minimum one of these languages will be familiar to you.

MFC /Win32* C++ to Windows Runtime C++

Some of the available APIs that you might have previously used are gone, one example is GDI. There are two main ways to draw things on the screen. One option is to use DirectX and Direct2D* to do your drawing. The second option is to use XAML, which is new for C++ developers. The third option is to use both DirectX and XAML together; this is really a great option to quickly build things like settings and title menus with XAML but keep the main application drawing components as DirectX. A great example of this model is the Fresh Paint application shown in Figures 2 and 3. The menu for selecting paint brushes and colors is designed with XAML and the main canvas of the application is a Direct2D surface.

Читайте также:  Как произойдет обновление windows 10

In addition to using Windows Runtime APIs from C++, some MFC APIs are still allowed but many APIs are not allowed if the app is to be a certified Windows Store app. Some obvious examples of disallowed APIs include things like message boxes, serial port APIs, DirectShow*, etc.

For more specifics on which Win32 APIs can be used in addition to alternative APIs available to Windows apps, see the following articles:

Here are some other resources to help you get started and learn the ins and outs of Windows Runtime C++ development:

Desktop .Net to Windows Runtime .Net

The set of .Net APIs available in Windows Store app development is not the same set available when creating Windows 7 apps. Check out the following Microsoft article .NET for Windows Store apps overview for the specific details on what has changed. Obvious changes include using a folder picker class that integrates into the Windows 8 UI instead of the FolderBrowserDialog used for desktop folder browsing. The article Windows* Style app development: Using Window Runtime from C# provides some further details on the nuances of using C# from Windows 8 Runtime.

HTML to Windows Runtime HTML/JavaScript App

With the addition ofHTML5/JavaScript language being an option as a first-class development environment, the opportunity to move existing HTML-based web sites and apps to Windows Store apps is possible.

Much of your HTML code will be reusable when moving to a Windows Store app, but be aware of these considerations:

  • Enabling support for touch and gestures.
  • Enabling support for multiple screen sizes, although this problem already exists when designing for different computer monitors. The Windows 8 snap view is another screen size to consider when figuring out how your application will scale down.
  • Plugging into the Windows 8 App framework. This includes framework features such as the application lifecycle, contracts, live tiles, sensors, etc.
  • Conforming to the Windows 8 UI style. There are libraries available to make this as simple as possible.

Here is some further reading on HTML5 and porting to an HTML Windows Store app:

Conclusion

Microsoft has done a great job leveraging the languages used most for Windows 7 desktop development to make the transition to Windows Store apps as easy as possible. With some thought around how to make use of Touch and Windows 8-specific features, your Windows 7 application will greatly benefit from being ported to a Window Store app.

Acknowledgements

Thanks to Ashok Emani for contributions to this article.

About the Author

Nathan Totura is an application engineer in Intel’s Software and Services Group. Currently working on the Intel® Atom™ processor-enabling team, he helps connect software developers with Intel technology and resources. Primarily these technologies include tablets and handsets on the Android*, Windows 8, and Tizen* platforms.

Notices

INFORMATION IN THIS DOCUMENT IS PROVIDED IN CONNECTION WITH INTEL PRODUCTS. NO LICENSE, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, TO ANY INTELLECTUAL PROPERTY RIGHTS IS GRANTED BY THIS DOCUMENT. EXCEPT AS PROVIDED IN INTEL’S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT.

UNLESS OTHERWISE AGREED IN WRITING BY INTEL, THE INTEL PRODUCTS ARE NOT DESIGNED NOR INTENDED FOR ANY APPLICATION IN WHICH THE FAILURE OF THE INTEL PRODUCT COULD CREATE A SITUATION WHERE PERSONAL INJURY OR DEATH MAY OCCUR.

Intel may make changes to specifications and product descriptions at any time, without notice. Designers must not rely on the absence or characteristics of any features or instructions marked «reserved» or «undefined.» Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them. The information here is subject to change without notice. Do not finalize a design with this information.

The products described in this document may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are available on request.

Contact your local Intel sales office or your distributor to obtain the latest specifications and before placing your product order.

Copies of documents which have an order number and are referenced in this document, or other Intel literature, may be obtained by calling 1-800-548-4725, or go to: http://www.intel.com/design/literature.htm

Software and workloads used in performance tests may have been optimized for performance only on Intel microprocessors. Performance tests, such as SYSmark and MobileMark, are measured using specific computer systems, components, software, operations, and functions. Any change to any of those factors may cause the results to vary. You should consult other information and performance tests to assist you in fully evaluating your contemplated purchases, including the performance of that product when combined with other products.

Any software source code reprinted in this document is furnished under a software license and may only be used or copied in accordance with the terms of that license.

Intel, the Intel logo, and Atom are trademarks of Intel Corporation in the US and/or other countries.

Copyright © 2012 Intel Corporation. All rights reserved.

*Other names and brands may be claimed as the property of others.

This sample source code is released under the Intel Sample Source Code License Agreement

Оцените статью