mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Gfx: Implement GDI+ fallback
This commit is contained in:
parent
44300e2f41
commit
20cac72e9b
@ -17,6 +17,9 @@
|
||||
*/
|
||||
|
||||
#include "Canvas.h"
|
||||
#include "CanvasD2D.h"
|
||||
#include "CanvasGDIP.h"
|
||||
#include "../Platform.h"
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
@ -31,6 +34,34 @@ Canvas::~Canvas()
|
||||
{
|
||||
}
|
||||
|
||||
Canvas* Canvas::Create(Renderer renderer)
|
||||
{
|
||||
if (renderer == Renderer::GDIP)
|
||||
{
|
||||
return new CanvasGDIP();
|
||||
}
|
||||
else if (renderer == Renderer::D2D && Platform::IsAtLeastWin7())
|
||||
{
|
||||
if (CanvasD2D::Initialize())
|
||||
{
|
||||
return new CanvasD2D();
|
||||
}
|
||||
|
||||
CanvasD2D::Finalize();
|
||||
}
|
||||
else if (renderer == Renderer::PreferD2D)
|
||||
{
|
||||
if (Canvas* canvas = Create(Renderer::D2D))
|
||||
{
|
||||
return canvas;
|
||||
}
|
||||
|
||||
return Create(Renderer::GDIP);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
void Canvas::Resize(int w, int h)
|
||||
{
|
||||
m_W = w;
|
||||
|
@ -26,12 +26,24 @@
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
enum class Renderer
|
||||
{
|
||||
GDIP,
|
||||
D2D,
|
||||
|
||||
// Attempts to use D2D. If D2D is not available, fallbacks to use GDI+.
|
||||
PreferD2D
|
||||
};
|
||||
|
||||
// Provides methods for drawing text, bitmaps, etc.
|
||||
class __declspec(novtable) Canvas
|
||||
{
|
||||
public:
|
||||
virtual ~Canvas();
|
||||
|
||||
// Creates the canvas using the specified rendering engine. May return nullptr.
|
||||
static Canvas* Create(Renderer renderer);
|
||||
|
||||
int GetW() const { return m_W; }
|
||||
int GetH() const { return m_H; }
|
||||
|
||||
|
@ -53,7 +53,6 @@ CanvasD2D::CanvasD2D() : Canvas(),
|
||||
m_Bitmap(),
|
||||
m_TextAntiAliasing(false)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
CanvasD2D::~CanvasD2D()
|
||||
|
@ -38,9 +38,6 @@ namespace Gfx {
|
||||
class CanvasD2D : public Canvas
|
||||
{
|
||||
public:
|
||||
CanvasD2D();
|
||||
~CanvasD2D();
|
||||
|
||||
virtual void Resize(int w, int h);
|
||||
|
||||
virtual bool BeginDraw();
|
||||
@ -75,9 +72,12 @@ public:
|
||||
virtual void FillRectangle(Gdiplus::Rect& rect, const Gdiplus::SolidBrush& brush) override;
|
||||
|
||||
private:
|
||||
friend class Canvas;
|
||||
friend class FontCollectionD2D;
|
||||
friend class TextFormatD2D;
|
||||
|
||||
CanvasD2D();
|
||||
~CanvasD2D();
|
||||
CanvasD2D(const CanvasD2D& other) {}
|
||||
|
||||
static bool Initialize();
|
||||
|
@ -32,9 +32,6 @@ namespace Gfx {
|
||||
class CanvasGDIP : public Canvas
|
||||
{
|
||||
public:
|
||||
CanvasGDIP();
|
||||
~CanvasGDIP();
|
||||
|
||||
virtual void Resize(int w, int h);
|
||||
|
||||
virtual bool BeginDraw();
|
||||
@ -69,6 +66,10 @@ public:
|
||||
virtual void FillRectangle(Gdiplus::Rect& rect, const Gdiplus::SolidBrush& brush) override;
|
||||
|
||||
private:
|
||||
friend class Canvas;
|
||||
|
||||
CanvasGDIP();
|
||||
~CanvasGDIP();
|
||||
CanvasGDIP(const CanvasGDIP& other) {}
|
||||
|
||||
void Dispose();
|
||||
|
@ -37,8 +37,7 @@
|
||||
#include "MeasureScript.h"
|
||||
#include "../Version.h"
|
||||
#include "../Common/PathUtil.h"
|
||||
#include "../Common/Gfx/CanvasD2D.h"
|
||||
#include "../Common/Gfx/CanvasGDIP.h"
|
||||
#include "../Common/Gfx/Canvas.h"
|
||||
|
||||
using namespace Gdiplus;
|
||||
|
||||
@ -2078,8 +2077,7 @@ bool MeterWindow::ReadSkin()
|
||||
useD2D = 0!=m_Parser.ReadInt(L"Rainmeter", L"__UseD2D", useD2D ? 1 : 0);
|
||||
}
|
||||
|
||||
m_Canvas = (Platform::IsAtLeastWinVista() && useD2D) ?
|
||||
(Gfx::Canvas*)new Gfx::CanvasD2D() : (Gfx::Canvas*)new Gfx::CanvasGDIP();
|
||||
m_Canvas = Gfx::Canvas::Create(useD2D ? Gfx::Renderer::PreferD2D : Gfx::Renderer::GDIP);
|
||||
|
||||
// Gotta have some kind of buffer during initialization
|
||||
CreateDoubleBuffer(1, 1);
|
||||
|
Loading…
Reference in New Issue
Block a user