d0df0bb045f3d0830b139d65e7d46b19500ed679
[profile/ivi/opencv.git] / modules / gpu / src / cuda / internal_shared.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
4 //\r
5 //  By downloading, copying, installing or using the software you agree to this license.\r
6 //  If you do not agree to this license, do not download, install,\r
7 //  copy or use the software.\r
8 //\r
9 //\r
10 //                           License Agreement\r
11 //                For Open Source Computer Vision Library\r
12 //\r
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.\r
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.\r
15 // Third party copyrights are property of their respective owners.\r
16 //\r
17 // Redistribution and use in source and binary forms, with or without modification,\r
18 // are permitted provided that the following conditions are met:\r
19 //\r
20 //   * Redistribution's of source code must retain the above copyright notice,\r
21 //     this list of conditions and the following disclaimer.\r
22 //\r
23 //   * Redistribution's in binary form must reproduce the above copyright notice,\r
24 //     this list of conditions and the following disclaimer in the documentation\r
25 //     and/or other materials provided with the distribution.\r
26 //\r
27 //   * The name of the copyright holders may not be used to endorse or promote products\r
28 //     derived from this software without specific prior written permission.\r
29 //\r
30 // This software is provided by the copyright holders and contributors "as is" and\r
31 // any express or implied warranties, including, but not limited to, the implied\r
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.\r
33 // In no event shall the Intel Corporation or contributors be liable for any direct,\r
34 // indirect, incidental, special, exemplary, or consequential damages\r
35 // (including, but not limited to, procurement of substitute goods or services;\r
36 // loss of use, data, or profits; or business interruption) however caused\r
37 // and on any theory of liability, whether in contract, strict liability,\r
38 // or tort (including negligence or otherwise) arising in any way out of\r
39 // the use of this software, even if advised of the possibility of such damage.\r
40 //\r
41 //M*/\r
42 \r
43 #ifndef __OPENCV_internal_shared_HPP__\r
44 #define __OPENCV_internal_shared_HPP__\r
45 \r
46 #include <cuda_runtime.h>\r
47 #include <npp.h>\r
48 #include "NPP_staging.hpp"\r
49 #include "opencv2/gpu/devmem2d.hpp"\r
50 #include "safe_call.hpp"\r
51 #include "opencv2/gpu/device/common.hpp"\r
52 \r
53 namespace cv { namespace gpu \r
54 {\r
55     enum \r
56     {\r
57         BORDER_REFLECT101_GPU = 0,\r
58         BORDER_REPLICATE_GPU,\r
59         BORDER_CONSTANT_GPU,\r
60         BORDER_REFLECT_GPU,\r
61         BORDER_WRAP_GPU\r
62     };\r
63             \r
64     // Converts CPU border extrapolation mode into GPU internal analogue.\r
65     // Returns true if the GPU analogue exists, false otherwise.\r
66     bool tryConvertToGpuBorderType(int cpuBorderType, int& gpuBorderType);\r
67 \r
68     class NppStreamHandler\r
69     {\r
70     public:\r
71         inline explicit NppStreamHandler(cudaStream_t newStream = 0)\r
72         {\r
73             oldStream = nppGetStream();\r
74             nppSetStream(newStream);\r
75         }\r
76 \r
77         inline ~NppStreamHandler()\r
78         {\r
79             nppSetStream(oldStream);\r
80         }\r
81 \r
82     private:\r
83         cudaStream_t oldStream;\r
84     };\r
85 \r
86     class NppStStreamHandler\r
87     {\r
88     public:\r
89         inline explicit NppStStreamHandler(cudaStream_t newStream = 0)\r
90         {\r
91             oldStream = nppStSetActiveCUDAstream(newStream);\r
92         }\r
93 \r
94         inline ~NppStStreamHandler()\r
95         {\r
96             nppStSetActiveCUDAstream(oldStream);\r
97         }\r
98 \r
99     private:\r
100         cudaStream_t oldStream;\r
101     };\r
102 }}\r
103 \r
104 #endif /* __OPENCV_internal_shared_HPP__ */\r