From 492d1e617cc8ac392784c3b4daa2bcfc79e4415f Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 1 Sep 2016 11:16:18 +0200 Subject: Don't use stride and use static buffer in example plugin. --- plugin.h | 2 ++ pluginlv2.cc | 2 +- plugintest.cc | 22 ++++++++++++---------- plugintest.h | 2 ++ 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/plugin.h b/plugin.h index b8a3f64..b7f683f 100644 --- a/plugin.h +++ b/plugin.h @@ -155,6 +155,8 @@ public: std::uint8_t* data{nullptr}; //< Allocated (or reused) RGBA buffer, filled by the plugin. }; +#define pgzRGBA(r, g, b, a) ((b) | (g) << 8 | (r) << 16 | (a) << 24) + //! Render call back. //! \param width The client area width as specified by the host. //! \param max_height The maximum allowed clieant area height as specified diff --git a/pluginlv2.cc b/pluginlv2.cc index c264223..2fe98ad 100644 --- a/pluginlv2.cc +++ b/pluginlv2.cc @@ -464,7 +464,7 @@ LV2_Inline_Display_Image_Surface* PluginLV2::inlineRender(LV2_Handle instance, plugin_lv2->surf.width = plugin_lv2->drawContext.width; plugin_lv2->surf.height = plugin_lv2->drawContext.height; - plugin_lv2->surf.stride = plugin_lv2->surf.width; // no padding + plugin_lv2->surf.stride = 0; plugin_lv2->surf.data = plugin_lv2->drawContext.data; diff --git a/plugintest.cc b/plugintest.cc index a23c44b..cbe34fe 100644 --- a/plugintest.cc +++ b/plugintest.cc @@ -182,25 +182,27 @@ void PluginTest::onInlineRedraw(std::size_t width, std::size_t max_height, InlineDrawContext& context) { - std::size_t height = std::min(width / 2, max_height); + std::size_t height = std::min(width, max_height); + if (!context.data || (context.width != width)) { - delete[] context.data; - context.data = new std::uint8_t[width * height * 4]; + context.width = width; + context.height = height; + context.data = (unsigned char*)inlineDisplayBuffer; } - context.width = width; - context.height = height; + + std::cout << "width: " << width << " height: " << height << std::endl; for(std::size_t x = 0; x < context.width; ++x) { for(std::size_t y = 0; y < context.height; ++y) { - unsigned char* p = context.data + ((x + y * context.width) * 4); - p[0] = 0; // B; - p[1] = 0; // G - p[2] = 255; // R - p[3] = 0; // A + inlineDisplayBuffer[x + y * context.width] = + pgzRGBA(lround(255 * (float(x) / float(context.width))), + lround(255 * (1 + -1 * (float(x) / float(context.width)))), + lround(255 * (float(y) / float(context.height))), + 0); // Apparently not used } } } diff --git a/plugintest.h b/plugintest.h index f750121..6d33767 100644 --- a/plugintest.h +++ b/plugintest.h @@ -121,6 +121,8 @@ private: WPARAM wParam, LPARAM lParam); #endif // defined(WIN32) + unsigned int inlineDisplayBuffer[1024 * 1024]; + int mouseX{0}; int mouseY{0}; }; -- cgit v1.2.3