Browse Source

Graphics code refactoring

tags/2021-05-28
tpoole 8 years ago
parent
commit
0874e47a35
6 changed files with 744 additions and 648 deletions
  1. +1
    -1
      modules/juce_graphics/juce_graphics.cpp
  2. +4
    -0
      modules/juce_graphics/juce_graphics.h
  3. +609
    -624
      modules/juce_graphics/native/juce_win32_Direct2DGraphicsContext.cpp
  4. +103
    -0
      modules/juce_graphics/native/juce_win32_Direct2DGraphicsContext.h
  5. +2
    -0
      modules/juce_graphics/native/juce_win32_DirectWriteTypeface.cpp
  6. +25
    -23
      modules/juce_gui_basics/native/juce_win32_Windowing.cpp

+ 1
- 1
modules/juce_graphics/juce_graphics.cpp View File

@@ -57,7 +57,7 @@
#undef JUCE_USE_DIRECTWRITE
#endif
#if JUCE_USE_DIRECTWRITE
#if JUCE_USE_DIRECTWRITE || JUCE_DIRECT2D
/* If you hit a compile error trying to include these files, you may need to update
your version of the Windows SDK to the latest one. The DirectWrite and Direct2D
headers are in the version 7 SDKs.


+ 4
- 0
modules/juce_graphics/juce_graphics.h View File

@@ -142,4 +142,8 @@ class LowLevelGraphicsContext;
#include "native/juce_mac_CoreGraphicsContext.h"
#endif
#if JUCE_DIRECT2D && JUCE_WINDOWS
#include "native/juce_win32_Direct2DGraphicsContext.h"
#endif
}

+ 609
- 624
modules/juce_graphics/native/juce_win32_Direct2DGraphicsContext.cpp
File diff suppressed because it is too large
View File


+ 103
- 0
modules/juce_graphics/native/juce_win32_Direct2DGraphicsContext.h View File

@@ -0,0 +1,103 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2017 - ROLI Ltd.
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 5 End-User License
Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
27th April 2017).
End User License Agreement: www.juce.com/juce-5-licence
Privacy Policy: www.juce.com/juce-5-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
#pragma once
#ifndef _WINDEF_
class HWND__; // Forward or never
typedef HWND__* HWND;
#endif
class Direct2DLowLevelGraphicsContext : public LowLevelGraphicsContext
{
public:
Direct2DLowLevelGraphicsContext (HWND);
~Direct2DLowLevelGraphicsContext();
//==============================================================================
bool isVectorDevice() const override { return false; }
void setOrigin (Point<int>) override;
void addTransform (const AffineTransform&) override;
float getPhysicalPixelScaleFactor() override;
bool clipToRectangle (const Rectangle<int>&) override;
bool clipToRectangleList (const RectangleList<int>&) override;
void excludeClipRectangle (const Rectangle<int>&) override;
void clipToPath (const Path&, const AffineTransform&) override;
void clipToImageAlpha (const Image&, const AffineTransform&) override;
bool clipRegionIntersects (const Rectangle<int>&) override;
Rectangle<int> getClipBounds() const override;
bool isClipEmpty() const override;
//==============================================================================
void saveState() override;
void restoreState() override;
void beginTransparencyLayer (float opacity) override;
void endTransparencyLayer() override;
//==============================================================================
void setFill (const FillType&) override;
void setOpacity (float) override;
void setInterpolationQuality (Graphics::ResamplingQuality) override;
//==============================================================================
void fillRect (const Rectangle<int>&, bool replaceExistingContents) override;
void fillRect (const Rectangle<float>&) override;
void fillRectList (const RectangleList<float>&) override;
void fillPath (const Path&, const AffineTransform&) override;
void drawImage (const Image& sourceImage, const AffineTransform&) override;
//==============================================================================
void drawLine (const Line<float>&) override;
void setFont (const Font&) override;
const Font& getFont() override;
void drawGlyph (int glyphNumber, const AffineTransform&) override;
bool drawTextLayout (const AttributedString&, const Rectangle<float>&) override;
void resized();
void clear();
void start();
void end();
//==============================================================================
private:
struct SavedState;
HWND hwnd;
SavedState* currentState;
OwnedArray<SavedState> states;
Rectangle<int> bounds;
struct Pimpl;
friend struct Pimpl;
friend struct ContainerDeletePolicy<Pimpl>;
ScopedPointer<Pimpl> pimpl;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Direct2DLowLevelGraphicsContext)
};

+ 2
- 0
modules/juce_graphics/native/juce_win32_DirectWriteTypeface.cpp View File

@@ -265,6 +265,8 @@ public:
IDWriteFontFace* getIDWriteFontFace() const noexcept { return dwFontFace; }
float getUnitsToHeightScaleFactor() const noexcept { return unitsToHeightScaleFactor; }
private:
SharedResourcePointer<Direct2DFactories> factories;
ComSmartPtr<IDWriteFontFace> dwFontFace;


+ 25
- 23
modules/juce_gui_basics/native/juce_win32_Windowing.cpp View File

@@ -1837,33 +1837,35 @@ private:
}
else
#endif
{
HRGN rgn = CreateRectRgn (0, 0, 0, 0);
const int regionType = GetUpdateRgn (hwnd, rgn, false);
HRGN rgn = CreateRectRgn (0, 0, 0, 0);
const int regionType = GetUpdateRgn (hwnd, rgn, false);
PAINTSTRUCT paintStruct;
HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
// message and become re-entrant, but that's OK
PAINTSTRUCT paintStruct;
HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
// message and become re-entrant, but that's OK
// if something in a paint handler calls, e.g. a message box, this can become reentrant and
// corrupt the image it's using to paint into, so do a check here.
static bool reentrant = false;
if (! reentrant)
{
const ScopedValueSetter<bool> setter (reentrant, true, false);
// if something in a paint handler calls, e.g. a message box, this can become reentrant and
// corrupt the image it's using to paint into, so do a check here.
static bool reentrant = false;
if (! reentrant)
{
const ScopedValueSetter<bool> setter (reentrant, true, false);
if (dontRepaint)
component.handleCommandMessage (0); // (this triggers a repaint in the openGL context)
else
performPaint (dc, rgn, regionType, paintStruct);
}
if (dontRepaint)
component.handleCommandMessage (0); // (this triggers a repaint in the openGL context)
else
performPaint (dc, rgn, regionType, paintStruct);
}
DeleteObject (rgn);
EndPaint (hwnd, &paintStruct);
DeleteObject (rgn);
EndPaint (hwnd, &paintStruct);
#if JUCE_MSVC
_fpreset(); // because some graphics cards can unmask FP exceptions
#endif
#if JUCE_MSVC
_fpreset(); // because some graphics cards can unmask FP exceptions
#endif
}
lastPaintTime = Time::getMillisecondCounter();
}
@@ -1993,8 +1995,8 @@ private:
void updateDirect2DContext()
{
if (currentRenderingEngine != direct2DRenderingEngine)
direct2DContext = 0;
else if (direct2DContext == 0)
direct2DContext = nullptr;
else if (direct2DContext == nullptr)
direct2DContext = new Direct2DLowLevelGraphicsContext (hwnd);
}
#endif


Loading…
Cancel
Save