diff options
| author | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-10-31 17:33:00 +0100 |
|---|---|---|
| committer | Nick Dedekind <nicholas.dedekind@gmail.com> | 2012-10-31 17:33:00 +0100 |
| commit | 829f338433192fb45d4d5091486bb94c1f0eb380 (patch) | |
| tree | 14422040f591aea4f27ae250ec2ef3e24dfd5efd | |
| parent | 871b4f1dbd9a2e88b596a3c60da480a9cd1bd069 (diff) | |
Added icon shadow on launcher drag.
Fixes LP: #765715 (bzr r2873.3.1)
| -rw-r--r-- | launcher/Launcher.cpp | 56 | ||||
| -rw-r--r-- | launcher/Launcher.h | 3 | ||||
| -rw-r--r-- | launcher/SoftwareCenterLauncherIcon.cpp | 4 | ||||
| -rw-r--r-- | unity-shared/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | unity-shared/GraphicsUtils.cpp | 71 | ||||
| -rw-r--r-- | unity-shared/GraphicsUtils.h | 36 | ||||
| -rw-r--r-- | unity-shared/IconRenderer.cpp | 28 | ||||
| -rw-r--r-- | unity-shared/IconRenderer.h | 4 |
8 files changed, 125 insertions, 78 deletions
diff --git a/launcher/Launcher.cpp b/launcher/Launcher.cpp index 3d089b81e..5a7348db7 100644 --- a/launcher/Launcher.cpp +++ b/launcher/Launcher.cpp @@ -49,6 +49,8 @@ #include "unity-shared/UScreen.h" #include "unity-shared/UBusMessages.h" #include "unity-shared/UnitySettings.h" +#include "unity-shared/GraphicsUtils.h" + #include <UnityCore/GLibWrapper.h> #include <UnityCore/Variant.h> @@ -114,7 +116,6 @@ Launcher::Launcher(nux::BaseWindow* parent, , _active_quicklist(nullptr) , _hovered(false) , _hidden(false) - , _render_drag_window(false) , _shortcuts_shown(false) , _data_checked(false) , _steal_drag(false) @@ -152,8 +153,6 @@ Launcher::Launcher(nux::BaseWindow* parent, _collection_window->collected.connect(sigc::mem_fun(this, &Launcher::OnDNDDataCollected)); - _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(2, 2, 1, nux::BITFMT_R8G8B8A8); - bg_effect_helper_.owner = this; bg_effect_helper_.enabled = false; @@ -1757,13 +1756,6 @@ void Launcher::DrawContent(nux::GraphicsEngine& GfxContext, bool force_draw) nux::Geometry const& geo_absolute = GetAbsoluteGeometry(); RenderArgs(args, bkg_box, &launcher_alpha, geo_absolute); bkg_box.width -= RIGHT_LINE_WIDTH; - - if (_drag_icon && _render_drag_window) - { - RenderIconToTexture(GfxContext, _drag_icon, _offscreen_drag_texture); - _render_drag_window = false; - ShowDragWindow(); - } nux::Color clear_colour = nux::Color(0x00000000); @@ -2030,10 +2022,10 @@ void Launcher::StartIconDrag(AbstractLauncherIcon::Ptr const& icon) _drag_icon_position = _model->IconIndex(icon); HideDragWindow(); - _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(_icon_size, _icon_size, 1, nux::BITFMT_R8G8B8A8); + _offscreen_drag_texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(GetWidth(), GetWidth(), 1, nux::BITFMT_R8G8B8A8); _drag_window = new LauncherDragWindow(_offscreen_drag_texture); - - _render_drag_window = true; + RenderIconToTexture(nux::GetWindowThread()->GetGraphicsEngine(), _drag_icon, _offscreen_drag_texture); + ShowDragWindow(); ubus_.SendMessage(UBUS_LAUNCHER_ICON_START_DND); } @@ -2077,8 +2069,6 @@ void Launcher::EndIconDrag() if (MouseBeyondDragThreshold()) TimeUtil::SetTimeStruct(&_times[TIME_DRAG_THRESHOLD], &_times[TIME_DRAG_THRESHOLD], ANIM_DURATION_SHORT); - _render_drag_window = false; - _hide_machine.SetQuirk(LauncherHideMachine::INTERNAL_DND_ACTIVE, false); ubus_.SendMessage(UBUS_LAUNCHER_ICON_END_DND); } @@ -2503,7 +2493,7 @@ void Launcher::RenderIconToTexture(nux::GraphicsEngine& GfxContext, AbstractLaun clock_gettime(CLOCK_MONOTONIC, ¤t); SetupRenderArg(icon, current, arg); - arg.render_center = nux::Point3(roundf(_icon_size / 2.0f), roundf(_icon_size / 2.0f), 0.0f); + arg.render_center = nux::Point3(roundf(texture->GetWidth() / 2.0f), roundf(texture->GetHeight() / 2.0f), 0.0f); arg.logical_center = arg.render_center; arg.x_rotation = 0.0f; arg.running_arrow = false; @@ -2515,7 +2505,7 @@ void Launcher::RenderIconToTexture(nux::GraphicsEngine& GfxContext, AbstractLaun std::list<RenderArg> drag_args; drag_args.push_front(arg); - SetOffscreenRenderTarget(texture); + graphics::PushOffscreenRenderTarget(texture); unsigned int alpha = 0, src = 0, dest = 0; GfxContext.GetRenderStates().GetBlend(alpha, src, dest); @@ -2529,9 +2519,11 @@ void Launcher::RenderIconToTexture(nux::GraphicsEngine& GfxContext, AbstractLaun GfxContext.GetRenderStates().SetBlend(alpha, src, dest); - icon_renderer->PreprocessIcons(drag_args, nux::Geometry(0, 0, _icon_size, _icon_size)); - icon_renderer->RenderIcon(nux::GetWindowThread()->GetGraphicsEngine(), arg, nux::Geometry(0, 0, _icon_size, _icon_size), nux::Geometry(0, 0, _icon_size, _icon_size)); - RestoreSystemRenderTarget(); + nux::Geometry geo(0, 0, texture->GetWidth(), texture->GetWidth()); + + icon_renderer->PreprocessIcons(drag_args, geo); + icon_renderer->RenderIcon(GfxContext, arg, geo, geo); + unity::graphics::PopOffscreenRenderTarget(); } nux::GestureDeliveryRequest Launcher::GestureEvent(const nux::GestureEvent &event) @@ -2552,30 +2544,6 @@ nux::GestureDeliveryRequest Launcher::GestureEvent(const nux::GestureEvent &even return nux::GestureDeliveryRequest::NONE; } -void -Launcher::SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture) -{ - int width = texture->GetWidth(); - int height = texture->GetHeight(); - - auto graphics_display = nux::GetGraphicsDisplay(); - auto gpu_device = graphics_display->GetGpuDevice(); - gpu_device->FormatFrameBufferObject(width, height, nux::BITFMT_R8G8B8A8); - gpu_device->SetColorRenderTargetSurface(0, texture->GetSurfaceLevel(0)); - gpu_device->ActivateFrameBuffer(); - - auto graphics_engine = graphics_display->GetGraphicsEngine(); - graphics_engine->SetContext(0, 0, width, height); - graphics_engine->SetViewport(0, 0, width, height); - graphics_engine->Push2DWindow(width, height); - graphics_engine->EmptyClippingRegion(); -} - -void Launcher::RestoreSystemRenderTarget() -{ - nux::GetWindowCompositor().RestoreRenderingSurface(); -} - bool Launcher::DndIsSpecialRequest(std::string const& uri) const { return (boost::algorithm::ends_with(uri, ".desktop") || uri.find("device://") == 0); diff --git a/launcher/Launcher.h b/launcher/Launcher.h index 726f8170a..a66c0c7ce 100644 --- a/launcher/Launcher.h +++ b/launcher/Launcher.h @@ -317,9 +317,6 @@ private: virtual long PostLayoutManagement(long LayoutResult); - void SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture); - void RestoreSystemRenderTarget(); - void OnDisplayChanged(Display* display); void OnDNDDataCollected(const std::list<char*>& mimes); diff --git a/launcher/SoftwareCenterLauncherIcon.cpp b/launcher/SoftwareCenterLauncherIcon.cpp index c79c2e706..876ad0233 100644 --- a/launcher/SoftwareCenterLauncherIcon.cpp +++ b/launcher/SoftwareCenterLauncherIcon.cpp @@ -68,8 +68,8 @@ void SoftwareCenterLauncherIcon::Animate(nux::ObjectPtr<Launcher> const& launche launcher_ = launcher; icon_texture_ = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture( - launcher->GetIconSize(), - launcher->GetIconSize(), + launcher->GetWidth(), + launcher->GetWidth(), 1, nux::BITFMT_R8G8B8A8); diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index 28dcc84e8..0c39967d1 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -34,6 +34,7 @@ set (UNITY_SHARED_SOURCES DashStyle.cpp DefaultThumbnailProvider.cpp FontSettings.cpp + GraphicsUtils.cpp IMTextEntry.cpp IconLoader.cpp IconRenderer.cpp diff --git a/unity-shared/GraphicsUtils.cpp b/unity-shared/GraphicsUtils.cpp new file mode 100644 index 000000000..dfd8dbeae --- /dev/null +++ b/unity-shared/GraphicsUtils.cpp @@ -0,0 +1,71 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2010 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> + */ + +#include "GraphicsUtils.h" +#include <NuxGraphics/GLTextureResourceManager.h> + +namespace unity +{ +namespace graphics +{ + +std::stack<nux::ObjectPtr<nux::IOpenGLBaseTexture>> rendering_stack; + +void PushOffscreenRenderTarget_(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture) +{ + int width = texture->GetWidth(); + int height = texture->GetHeight(); + + auto graphics_display = nux::GetGraphicsDisplay(); + auto gpu_device = graphics_display->GetGpuDevice(); + gpu_device->FormatFrameBufferObject(width, height, nux::BITFMT_R8G8B8A8); + gpu_device->SetColorRenderTargetSurface(0, texture->GetSurfaceLevel(0)); + gpu_device->ActivateFrameBuffer(); + + auto graphics_engine = graphics_display->GetGraphicsEngine(); + graphics_engine->SetContext(0, 0, width, height); + graphics_engine->SetViewport(0, 0, width, height); + graphics_engine->Push2DWindow(width, height); + graphics_engine->EmptyClippingRegion(); +} + +void PushOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture) +{ + PushOffscreenRenderTarget_(texture); + rendering_stack.push(texture); +} + +void PopOffscreenRenderTarget() +{ + g_assert(rendering_stack.size() > 0); + + rendering_stack.pop(); + if (rendering_stack.size() > 0) + { + nux::ObjectPtr<nux::IOpenGLBaseTexture>& texture = rendering_stack.top(); + PushOffscreenRenderTarget_(texture); + } + else + { + nux::GetWindowCompositor().RestoreRenderingSurface(); + } +} + +} +} \ No newline at end of file diff --git a/unity-shared/GraphicsUtils.h b/unity-shared/GraphicsUtils.h new file mode 100644 index 000000000..dd65d3b00 --- /dev/null +++ b/unity-shared/GraphicsUtils.h @@ -0,0 +1,36 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2010 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Nick Dedekind <nick.dedekind@canonical.com> + */ + +#ifndef UNITY_GRAPHICS_ADAPTER +#define UNITY_GRAPHICS_ADAPTER + +#include <Nux/Nux.h> + +namespace unity +{ +namespace graphics +{ + +void PushOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture); +void PopOffscreenRenderTarget(); + +} +} + +#endif // UNITY_GRAPHICS_ADAPTER \ No newline at end of file diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index ca6b0db5f..980cb6e0c 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -26,6 +26,7 @@ #include <NuxGraphics/GLTextureResourceManager.h> #include <NuxGraphics/CairoGraphics.h> +#include "GraphicsUtils.h" #include <gtk/gtk.h> @@ -1010,7 +1011,7 @@ void IconRenderer::RenderProgressToTexture(nux::GraphicsEngine& GfxContext, int progress_y = fill_y + (fill_height - progress_height) / 2; int half_size = (right_edge - left_edge) / 2; - SetOffscreenRenderTarget(texture); + unity::graphics::PushOffscreenRenderTarget(texture); // FIXME glClear(GL_COLOR_BUFFER_BIT); @@ -1041,7 +1042,7 @@ void IconRenderer::RenderProgressToTexture(nux::GraphicsEngine& GfxContext, GfxContext.PopClippingRectangle(); - RestoreSystemRenderTarget(); + unity::graphics::PopOffscreenRenderTarget(); } void IconRenderer::DestroyTextures() @@ -1134,29 +1135,6 @@ void IconRenderer::GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, n PerspectiveMatrix.Perspective(Fovy, AspectRatio, NearClipPlane, FarClipPlane); } -void -IconRenderer::SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture) -{ - int width = texture->GetWidth(); - int height = texture->GetHeight(); - - nux::GetGraphicsDisplay()->GetGpuDevice()->FormatFrameBufferObject(width, height, nux::BITFMT_R8G8B8A8); - nux::GetGraphicsDisplay()->GetGpuDevice()->SetColorRenderTargetSurface(0, texture->GetSurfaceLevel(0)); - nux::GetGraphicsDisplay()->GetGpuDevice()->ActivateFrameBuffer(); - - nux::GetGraphicsDisplay()->GetGraphicsEngine()->SetContext(0, 0, width, height); - nux::GetGraphicsDisplay()->GetGraphicsEngine()->SetViewport(0, 0, width, height); - nux::GetGraphicsDisplay()->GetGraphicsEngine()->Push2DWindow(width, height); - nux::GetGraphicsDisplay()->GetGraphicsEngine()->EmptyClippingRegion(); -} - -void -IconRenderer::RestoreSystemRenderTarget() -{ - nux::GetWindowCompositor().RestoreRenderingSurface(); -} - - // The local namespace is purely for namespacing the file local variables below. namespace local { diff --git a/unity-shared/IconRenderer.h b/unity-shared/IconRenderer.h index d45fcd715..9b84e3e3e 100644 --- a/unity-shared/IconRenderer.h +++ b/unity-shared/IconRenderer.h @@ -84,10 +84,6 @@ protected: float FarClipPlane, float Fovy); - void SetOffscreenRenderTarget(nux::ObjectPtr<nux::IOpenGLBaseTexture> texture); - - void RestoreSystemRenderTarget(); - private: int icon_size; int image_size; |
