LCOV - code coverage report
Current view: top level - vcl/workben - icontest.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 78 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 17 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : /*
      11             :  * =======================================================================
      12             :  *
      13             :  * This is a quick hack to test some stuff. Work in progress. Don't touch
      14             :  * and don't bother inspecting too closely.
      15             :  *
      16             :  * =======================================================================
      17             :  */
      18             : 
      19             : #include <iostream>
      20             : 
      21             : #include <math.h>
      22             : 
      23             : #include <GL/glew.h>
      24             : 
      25             : #include <glm/gtx/bit.hpp>
      26             : 
      27             : #include <com/sun/star/lang/XComponent.hpp>
      28             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/ucb/UniversalContentBroker.hpp>
      31             : #include <comphelper/processfactory.hxx>
      32             : #include <cppuhelper/bootstrap.hxx>
      33             : #include <osl/file.hxx>
      34             : #include <vcl/builder.hxx>
      35             : #include <vcl/button.hxx>
      36             : #include <vcl/dialog.hxx>
      37             : #include <vcl/fixed.hxx>
      38             : #include <vcl/graph.hxx>
      39             : #include <vcl/graphicfilter.hxx>
      40             : #include <vcl/image.hxx>
      41             : #include <vcl/openglwin.hxx>
      42             : #include <vcl/opengl/OpenGLContext.hxx>
      43             : #include <vcl/opengl/OpenGLHelper.hxx>
      44             : #include <vcl/svapp.hxx>
      45             : #include <vcl/vclmain.hxx>
      46             : #include <vcl/wrkwin.hxx>
      47             : 
      48             : using namespace com::sun::star;
      49             : 
      50             : namespace {
      51             :     const int WIDTH = 1000, HEIGHT = 800;
      52             : 
      53           0 :     double getTimeNow()
      54             :     {
      55             :         TimeValue aValue;
      56           0 :         osl_getSystemTime(&aValue);
      57           0 :         return (double)aValue.Seconds +
      58           0 :             (double)aValue.Nanosec / (1000*1000*1000);
      59             :     }
      60             : 
      61             : }
      62             : 
      63             : class MyWorkWindow : public WorkWindow
      64             : {
      65             : private:
      66             : 
      67             : protected:
      68             :     double mnStartTime;
      69             :     int mnPaintCount;
      70             : 
      71             : public:
      72             :     Graphic maGraphic;
      73             :     Bitmap *mpBitmap;
      74             :     VclPtr<FixedBitmap> mpFixedBitmap;
      75             : 
      76             :     MyWorkWindow( vcl::Window* pParent, WinBits nWinStyle );
      77           0 :     virtual ~MyWorkWindow() { disposeOnce(); }
      78           0 :     virtual void dispose() SAL_OVERRIDE { mpFixedBitmap.clear(); WorkWindow::dispose(); }
      79             :     void LoadGraphic( const OUString& sImageFile );
      80             : 
      81             :     virtual void Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect ) SAL_OVERRIDE;
      82             :     virtual void Resize() SAL_OVERRIDE;
      83             : };
      84             : 
      85           0 : MyWorkWindow::MyWorkWindow( vcl::Window* pParent, WinBits nWinStyle )
      86             :     : WorkWindow(pParent, nWinStyle)
      87             :     , mpBitmap(NULL)
      88           0 :     , mpFixedBitmap(NULL)
      89             : {
      90           0 :     mnPaintCount = 0;
      91           0 :     mnStartTime = getTimeNow();
      92           0 :     EnableInput();
      93           0 : }
      94             : 
      95           0 : void MyWorkWindow::LoadGraphic( const OUString& sImageFile )
      96             : {
      97           0 :     SvFileStream aFileStream( sImageFile, StreamMode::READ );
      98           0 :     GraphicFilter aGraphicFilter(false);
      99           0 :     if (aGraphicFilter.ImportGraphic(maGraphic, sImageFile, aFileStream) != 0)
     100             :     {
     101             :         SAL_WARN("vcl.icontest", "Could not import image '" << sImageFile << "'");
     102           0 :         return;
     103           0 :     }
     104             : }
     105             : 
     106           0 : void MyWorkWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect)
     107             : {
     108           0 :     std::cout << "==> Paint! " << mnPaintCount++ << " (vcl) " << GetSizePixel() << " " << getTimeNow() - mnStartTime << std::endl;
     109             : 
     110           0 :     Size aGraphicSize( maGraphic.GetSizePixel() );
     111           0 :     float aspect = ((float) aGraphicSize.Width()) / aGraphicSize.Height();
     112           0 :     Size aSize;
     113           0 :     if( aspect >= ((float) WIDTH) / HEIGHT )
     114           0 :         aSize = Size( WIDTH, HEIGHT/aspect );
     115             :     else
     116           0 :         aSize = Size( WIDTH * aspect, HEIGHT );
     117           0 :     aSize.setWidth( aSize.Width() * (1 + (0.1*sin(mnPaintCount/60.))) );
     118           0 :     aSize.setHeight( aSize.Height() * (1 + (0.1*sin(mnPaintCount/50.))) );
     119             : 
     120           0 :     Bitmap aEmpty;
     121           0 :     mpFixedBitmap->SetBitmap( aEmpty );
     122           0 :     GraphicConversionParameters aConv( aSize );
     123           0 :     mpBitmap = new Bitmap( maGraphic.GetBitmap( aConv ) );
     124           0 :     mpFixedBitmap->SetBitmap( *mpBitmap );
     125           0 :     mpFixedBitmap->SetSizePixel( aSize );
     126             : 
     127           0 :     WorkWindow::Paint(rRenderContext, rRect);
     128             : 
     129           0 :     if (mnPaintCount == 100)
     130           0 :         Application::Quit();
     131             : 
     132           0 :     Invalidate( InvalidateFlags::Children );
     133           0 : }
     134             : 
     135           0 : void MyWorkWindow::Resize()
     136             : {
     137             :     SAL_INFO("vcl.icontest", "Resize " << GetSizePixel());
     138           0 : }
     139             : 
     140           0 : class IconTestApp : public Application
     141             : {
     142             : public:
     143             :     virtual void Init() SAL_OVERRIDE;
     144             :     virtual int Main() SAL_OVERRIDE;
     145             : 
     146           0 :     IconTestApp() : nRet(EXIT_SUCCESS) {};
     147             : 
     148             : private:
     149             :     int nRet;
     150             : 
     151             :     void DoItWithVcl(const OUString& sImageFile);
     152             : };
     153             : 
     154           0 : void IconTestApp::Init()
     155             : {
     156           0 :     nRet = EXIT_SUCCESS;
     157             : 
     158             :     uno::Reference<uno::XComponentContext> xContext =
     159           0 :         cppu::defaultBootstrap_InitialComponentContext();
     160             :     uno::Reference<lang::XMultiComponentFactory> xFactory =
     161           0 :         xContext->getServiceManager();
     162             :     uno::Reference<lang::XMultiServiceFactory> xSFactory =
     163           0 :         uno::Reference<lang::XMultiServiceFactory> (xFactory, uno::UNO_QUERY_THROW);
     164           0 :     comphelper::setProcessServiceFactory(xSFactory);
     165             : 
     166             :     // Create UCB (for backwards compatibility, in case some code still uses
     167             :     // plain createInstance w/o args directly to obtain an instance):
     168             :     ::ucb::UniversalContentBroker::create(
     169           0 :         comphelper::getProcessComponentContext() );
     170           0 : }
     171             : 
     172           0 : int IconTestApp::Main()
     173             : {
     174           0 :     if (GetCommandLineParamCount() != 1)
     175             :     {
     176           0 :         fprintf(stderr, "Usage: imagetest <image>\n");
     177           0 :         return EXIT_FAILURE;
     178             :     }
     179           0 :     OUString sImageFile( GetCommandLineParam( 0 ) );
     180           0 :     DoItWithVcl( sImageFile );
     181             : 
     182           0 :     return nRet;
     183             : }
     184             : 
     185           0 : void IconTestApp::DoItWithVcl( const OUString& sImageFile)
     186             : {
     187             :     try
     188             :     {
     189           0 :         VclPtrInstance<MyWorkWindow> pWindow( nullptr, WB_APP | WB_STDWORK | WB_SIZEABLE | WB_CLOSEABLE | WB_CLIPCHILDREN );
     190             : 
     191           0 :         pWindow->SetText(OUString("VCL Image Test"));
     192             : 
     193           0 :         pWindow->LoadGraphic( sImageFile );
     194           0 :         pWindow->mpFixedBitmap = VclPtr<FixedBitmap>::Create( pWindow );
     195           0 :         pWindow->mpFixedBitmap->SetPosPixel( Point( 0, 0 ) );
     196           0 :         pWindow->mpFixedBitmap->Show();
     197             : 
     198           0 :         pWindow->Hide();
     199           0 :         pWindow->Show();
     200             : 
     201           0 :         Execute();
     202             :     }
     203           0 :     catch (const uno::Exception &e)
     204             :     {
     205           0 :         fprintf(stderr, "fatal error: %s\n", OUStringToOString(e.Message, osl_getThreadTextEncoding()).getStr());
     206           0 :         nRet = EXIT_FAILURE;
     207             :     }
     208           0 :     catch (const std::exception &e)
     209             :     {
     210           0 :         fprintf(stderr, "fatal error: %s\n", e.what());
     211           0 :         nRet = EXIT_FAILURE;
     212             :     }
     213           0 : }
     214             : 
     215           0 : void vclmain::createApplication()
     216             : {
     217           0 :     static IconTestApp aApp;
     218           0 : }
     219             : 
     220             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11