[release] version bump to 13.0 beta1
[vuplus_xbmc] / xbmc / cores / VideoRenderers / BaseRenderer.h
1 #pragma once
2
3 /*
4  *      Copyright (C) 2005-2013 Team XBMC
5  *      http://xbmc.org
6  *
7  *  This Program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2, or (at your option)
10  *  any later version.
11  *
12  *  This Program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with XBMC; see the file COPYING.  If not, see
19  *  <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 #include <vector>
24
25 #include "guilib/Resolution.h"
26 #include "guilib/Geometry.h"
27 #include "RenderFormats.h"
28 #include "RenderFeatures.h"
29
30 #define MAX_PLANES 3
31 #define MAX_FIELDS 3
32 #define NUM_BUFFERS 3
33
34 class CSetting;
35
36 typedef struct YV12Image
37 {
38   uint8_t* plane[MAX_PLANES];
39   int      planesize[MAX_PLANES];
40   unsigned stride[MAX_PLANES];
41   unsigned width;
42   unsigned height;
43   unsigned flags;
44
45   unsigned cshift_x; /* this is the chroma shift used */
46   unsigned cshift_y;
47   unsigned bpp; /* bytes per pixel */
48 } YV12Image;
49
50 enum EFIELDSYNC
51 {
52   FS_NONE,
53   FS_TOP,
54   FS_BOT
55 };
56
57 // Render Methods
58 enum RenderMethods
59 {
60   RENDER_METHOD_AUTO     = 0,
61   RENDER_METHOD_ARB,
62   RENDER_METHOD_GLSL,
63   RENDER_METHOD_SOFTWARE,
64   RENDER_METHOD_D3D_PS,
65   RENDER_METHOD_DXVA,
66   RENDER_METHOD_DXVAHD,
67   RENDER_OVERLAYS        = 99   // to retain compatibility
68 };
69
70 typedef void (*RenderUpdateCallBackFn)(const void *ctx, const CRect &SrcRect, const CRect &DestRect);
71 typedef void (*RenderFeaturesCallBackFn)(const void *ctx, Features &renderFeatures);
72
73 struct DVDVideoPicture;
74
75 class CBaseRenderer
76 {
77 public:
78   CBaseRenderer();
79   virtual ~CBaseRenderer();
80
81   void SetViewMode(int viewMode);
82   RESOLUTION GetResolution() const;
83   void GetVideoRect(CRect &source, CRect &dest);
84   float GetAspectRatio() const;
85
86   virtual bool AddVideoPicture(DVDVideoPicture* picture, int index) { return false; }
87   virtual void Flush() {};
88
89   /**
90    * Returns number of references a single buffer can retain when rendering a single frame
91    */
92   virtual unsigned int GetProcessorSize() { return 0; }
93   virtual unsigned int GetMaxBufferSize() { return 0; }
94   virtual void         SetBufferSize(int numBuffers) { }
95   virtual void         ReleaseBuffer(int idx) { }
96
97   virtual bool Supports(ERENDERFEATURE feature) { return false; }
98
99   // Supported pixel formats, can be called before configure
100   std::vector<ERenderFormat> SupportedFormats()  { return std::vector<ERenderFormat>(); }
101
102   virtual void RegisterRenderUpdateCallBack(const void *ctx, RenderUpdateCallBackFn fn);
103   virtual void RegisterRenderFeaturesCallBack(const void *ctx, RenderFeaturesCallBackFn fn);
104
105   static void SettingOptionsRenderMethodsFiller(const CSetting *setting, std::vector< std::pair<std::string, int> > &list, int &current);
106
107 protected:
108   void       ChooseBestResolution(float fps);
109   bool       FindResolutionFromOverride(float fps, float& weight, bool fallback);
110   void       FindResolutionFromFpsMatch(float fps, float& weight);
111   RESOLUTION FindClosestResolution(float fps, float multiplier, RESOLUTION current, float& weight);
112   static float      RefreshWeight(float refresh, float fps);
113   void       CalcNormalDisplayRect(float offsetX, float offsetY, float screenWidth, float screenHeight, float inputFrameRatio, float zoomAmount, float verticalShift);
114   void       CalculateFrameAspectRatio(unsigned int desired_width, unsigned int desired_height);
115   void       ManageDisplay();
116
117   virtual void       ReorderDrawPoints();//might be overwritten (by egl e.x.)
118   void       saveRotatedCoords();//saves the current state of m_rotatedDestCoords
119   void       syncDestRectToRotatedPoints();//sync any changes of m_destRect to m_rotatedDestCoords
120   void       restoreRotatedCoords();//restore the current state of m_rotatedDestCoords from saveRotatedCoords 
121   void       MarkDirty();
122
123   RESOLUTION m_resolution;    // the resolution we're running in
124   unsigned int m_sourceWidth;
125   unsigned int m_sourceHeight;
126   float m_sourceFrameRatio;
127   float m_fps;
128
129   unsigned int m_renderOrientation; // orientation of the video in degress counter clockwise
130   unsigned int m_oldRenderOrientation; // orientation of the previous frame
131   // for drawing the texture with glVertex4f (holds all 4 corner points of the destination rect
132   // with correct orientation based on m_renderOrientation
133   // 0 - top left, 1 - top right, 2 - bottom right, 3 - bottom left
134   CPoint m_rotatedDestCoords[4];
135   CPoint m_savedRotatedDestCoords[4];//saved points from saveRotatedCoords call
136
137   CRect m_destRect;
138   CRect m_oldDestRect; // destrect of the previous frame
139   CRect m_sourceRect;
140
141   // rendering flags
142   unsigned m_iFlags;
143
144   const void* m_RenderUpdateCallBackCtx;
145   RenderUpdateCallBackFn m_RenderUpdateCallBackFn;
146
147   const void* m_RenderFeaturesCallBackCtx;
148   RenderFeaturesCallBackFn m_RenderFeaturesCallBackFn;
149 };