{"id":254,"date":"2022-03-01T13:54:33","date_gmt":"2022-03-01T12:54:33","guid":{"rendered":"http:\/\/graphics32\/?page_id=254"},"modified":"2022-03-01T14:35:13","modified_gmt":"2022-03-01T13:35:13","slug":"back-ends","status":"publish","type":"page","link":"https:\/\/melander.dk\/graphics32\/back-ends\/","title":{"rendered":"Back-Ends"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Traditionally bitmaps in Graphics32 have been using resources managed by the Windows GDI. While this is feasible for most usage scenarios in Windows there are some that require certain less resource-restricted approaches like handle-less bitmaps or bitmaps that rely on memory-mapped files. Prior to Graphics32 1.9 several community-driven patches existed that added these features.<br>With the arrival of broader platform support in Graphics32 we have separated the memory management as well as OS or graphics subsystem specific methods from the generic methods in <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TBitmap32\/_Body.htm\">TBitmap32<\/a> and have moved these portions into so called back-end classes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Approach and compatibility<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In order to keep backwards compatibility the <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TBitmap32\/_Body.htm\">TBitmap32<\/a> class still exposes the same external interface. In order to get a clean cut from the platform specific methods and properties we implemented a new in-between class <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TCustomBitmap32\/_Body.htm\">TCustomBitmap32<\/a> which is truly platform agnostic and relies solely on the associated back-end class to handle its needs. As a matter of fact <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TCustomBitmap32\/_Body.htm\">TCustomBitmap32<\/a> is missing all Text, Canvas and Handle methods. Back-ends may implement predefined interfaces to implement the functionality.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The back-end instance is switchable during the life-cycle of a <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TCustomBitmap32\/_Body.htm\">TCustomBitmap32<\/a> instance. Conversion to the new back-end instance is handled transparently, i.e. without loosing the bitmap&#8217;s surface contents. For instance this allows for temporarily switching a handle-less memory-only bitmap to a GDI bitmap with handle and vice versa. <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TCustomBitmap32\/_Body.htm\">TCustomBitmap32<\/a> exposes the current back-end via its <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TCustomBitmap32\/Properties\/Backend.htm\">Backend<\/a> property.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: delphi; title: ; quick-code: false; notranslate\" title=\"\">\nbegin\n  MyBitmap := TBitmap32.Create;\n  TMMFBackend.Create(MyBitmap); \/\/ Switch to a handle-less memory mapped file back-end...\n  MyBitmap.SetSize(5000, 5000);\n \n  \/\/ Draw onto your new big bitmap...\n  \/\/ Note: No text or canvas drawing is allowed because TMMFBackend does not implement those operations.\n  \/\/ Use TGDIMMFBackend instead...\n \n  TGDIBackend.Create(MyBitmap); \/\/ Switch to a GDI back-end and convert the current buffer...\n  MyBitmap.SaveToFile(&#039;test.bmp&#039;);\nend;\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\">Class and interface overview<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Currently Graphics32 ships with the following back-end classes which are subclasses of <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TBackend\/_Body.htm\">TBackend<\/a> and implement several interfaces (see below):<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Generic back-ends<\/strong><ul><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends_Generic\/Classes\/TMemoryBackend\/_Body.htm\">TMemoryBackend<\/a> (default for <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TCustomBitmap32\/_Body.htm\">TCustomBitmap32<\/a>)<\/li><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends_Generic\/Classes\/TMMFBackend\/_Body.htm\">TMMFBackend<\/a><\/li><\/ul><\/li><li><strong>Windows GDI\/VCL back-ends<\/strong><ul><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends_VCL\/Classes\/TGDIBackend\/_Body.htm\">TGDIBackend<\/a> (default for <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TBitmap32\/_Body.htm\">TBitmap32<\/a>)<\/li><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends_VCL\/Classes\/TGDIMMFBackend\/_Body.htm\">TGDIMMFBackend<\/a><\/li><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends_VCL\/Classes\/TGDIMemoryBackend\/_Body.htm\">TGDIMemoryBackend<\/a><\/li><\/ul><\/li><li><strong>Lazarus back-ends (currently Windows, OS X Carbon, GTK)<\/strong><ul><li>TLCLBackend (default for <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TBitmap32\/_Body.htm\">TBitmap32<\/a>)<\/li><li>TLCLMMFBackend (Windows only)<\/li><\/ul><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">By default <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TBitmap32\/_Body.htm\">TBitmap32<\/a> now uses the back-end class TGDIBackend on Delphi\/VCL\/Windows and TLCLBackend on FreePascal\/LCL\/[supported OS (see above)].<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each of these back-ends may or may not implement certain pre-defined interfaces which can be queried for at runtime, either directly via the back-end or indirectly via the bitmap instance:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends\/Interfaces\/IPaintSupport\/_Body.htm\">IPaintSupport<\/a><\/li><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends\/Interfaces\/ICopyFromBitmapSupport\/_Body.htm\">ICopyFromBitmapSupport<\/a><\/li><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends\/Interfaces\/IBitmapContextSupport\/_Body.htm\">IBitmapContextSupport<\/a><\/li><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends\/Interfaces\/IDeviceContextSupport\/_Body.htm\">IDeviceContextSupport<\/a><\/li><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends\/Interfaces\/ITextSupport\/_Body.htm\">ITextSupport<\/a><\/li><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends\/Interfaces\/IFontSupport\/_Body.htm\">IFontSupport<\/a><\/li><li><a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32_Backends\/Interfaces\/ICanvasSupport\/_Body.htm\">ICanvasSupport<\/a><\/li><\/ul>\n\n\n\n<div class=\"wp-block-uagb-inline-notice uagb-inline_notice__outer-wrap uagb-inline_notice__align-left uagb-block-0c28345b\"><h5 class=\"uagb-notice-title\">Note<\/h5><div class=\"uagb-notice-text\"><p>Most of the methods and properties left in <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TBitmap32\/_Body.htm\">TBitmap32<\/a> query the back-end for these specific interfaces. Failing to implement the required interfaces in the back-end class will cause the method call or property read to fail with an exception. We recommend to change your custom routines or methods to use <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TCustomBitmap32\/_Body.htm\">TCustomBitmap32<\/a> instead of <a href=\"https:\/\/graphics32.github.io\/Docs\/Units\/GR32\/Classes\/TBitmap32\/_Body.htm\">TBitmap32<\/a> wherever possible.<\/p><\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Traditionally bitmaps in Graphics32 have been using resources managed by the Windows GDI. While this is feasible for most usage scenarios in Windows there are some that require certain less resource-restricted approaches like handle-less bitmaps or bitmaps that rely<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-254","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/pages\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/comments?post=254"}],"version-history":[{"count":2,"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/pages\/254\/revisions"}],"predecessor-version":[{"id":266,"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/pages\/254\/revisions\/266"}],"wp:attachment":[{"href":"https:\/\/melander.dk\/graphics32\/wp-json\/wp\/v2\/media?parent=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}