JUCE v8.0.9
JUCE API
 
Loading...
Searching...
No Matches
juce::Direct2DPixelData Class Reference

#include <juce_Direct2DImage_windows.h>

Inheritance diagram for juce::Direct2DPixelData:
Collaboration diagram for juce::Direct2DPixelData:

Public Types

using BackupExtensions = ImagePixelDataBackupExtensions
 
using NativeExtensions = ImagePixelDataNativeExtensions
 
using Page = Direct2DPixelDataPage
 
using Pages = Direct2DPixelDataPages
 
using Ptr = ReferenceCountedObjectPtr< Direct2DPixelData >
 

Public Member Functions

 Direct2DPixelData (ComSmartPtr< ID2D1Device1 >, ComSmartPtr< ID2D1Bitmap1 >)
 
 Direct2DPixelData (Image::PixelFormat, int, int, bool)
 
 ~Direct2DPixelData () override
 
void applyGaussianBlurEffect (float radius)
 
void applyGaussianBlurEffectInArea (Rectangle< int >, float) override
 Applies a native blur effect to this image, if available.
 
void applySingleChannelBoxBlurEffect (int radius)
 
void applySingleChannelBoxBlurEffectInArea (Rectangle< int >, int) override
 Applies a native blur effect to this image, if available.
 
ImagePixelData::Ptr clone () override
 Creates a copy of this image.
 
std::unique_ptr< LowLevelGraphicsContextcreateLowLevelContext () override
 Creates a context that will draw into this image.
 
std::unique_ptr< ImageTypecreateType () const override
 Creates an instance of the type of this image.
 
void decReferenceCount () noexcept
 Decreases the object's reference count.
 
bool decReferenceCountWithoutDeleting () noexcept
 Decreases the object's reference count.
 
void desaturate ()
 
void desaturateInArea (Rectangle< int >) override
 Changes all the colours to be shades of grey, based on their current luminosity.
 
const BackupExtensionsgetBackupExtensions () const override
 
BackupExtensionsgetBackupExtensions () override
 Returns a raw pointer to an instance of ImagePixelDataBackupExtensions if this ImagePixelData provides this extension, or nullptr otherwise.
 
ComSmartPtr< ID2D1Bitmap1 > getFirstPageForDevice (ComSmartPtr< ID2D1Device1 > device)
 
ImagePixelDataNativeExtensions getNativeExtensions () override
 
Span< const PagegetPagesForDevice (ComSmartPtr< ID2D1Device1 >)
 
int getReferenceCount () const noexcept
 Returns the object's current reference count.
 
virtual int getSharedCount () const noexcept
 Returns the number of Image objects which are currently referring to the same internal shared image data.
 
void incReferenceCount () noexcept
 Increments the object's reference count.
 
void initialiseBitmapData (Image::BitmapData &, int, int, Image::BitmapData::ReadWriteMode) override
 Initialises a BitmapData object.
 
void moveImageSection (Point< int > destTopLeft, Rectangle< int > sourceRect)
 Copies a section of the image to somewhere else within itself.
 
void multiplyAllAlphas (float amount)
 
void multiplyAllAlphasInArea (Rectangle< int >, float) override
 Multiples all alpha-channel values in the image by the specified amount.
 
void sendDataChangeMessage ()
 

Public Attributes

const int height
 
ListenerList< Listenerlisteners
 
const Image::PixelFormat pixelFormat
 The pixel format of the image data.
 
NamedValueSet userData
 User-defined settings that are attached to this image.
 
const int width
 

Protected Member Functions

void resetReferenceCount () noexcept
 Resets the reference count to zero without deleting the object.
 

Private Types

enum class  State {
  initiallyUndefined ,
  initiallyCleared ,
  drawing ,
  drawn ,
  outdated
}
 

Private Member Functions

 Direct2DPixelData (ImagePixelData::Ptr, State)
 
void adapterCreated (DxgiAdapter::Ptr) override
 
void adapterRemoved (DxgiAdapter::Ptr adapter) override
 
template<typename Fn >
bool applyEffectInArea (Rectangle< int >, Fn &&)
 
bool backupNow () override
 This function will attempt to make the image resilient to graphics device disconnection by copying from graphics memory to main memory.
 
bool canBackup () const override
 Returns if there is an up-to-date copy of this image in graphics memory, or false otherwise.
 
std::unique_ptr< Context > createNativeContext ()
 
bool createPersistentBackup (ComSmartPtr< ID2D1Device1 > deviceHint)
 
auto getIteratorForDevice (ComSmartPtr< ID2D1Device1 >)
 
ComSmartPtr< ID2D1Device1 > getMostRelevantDevice ()
 
Direct2DPixelDataPagesgetPagesStructForDevice (ComSmartPtr< ID2D1Device1 >)
 
bool isBackupEnabled () const override
 
void moveValidatedImageSection (Point< int > destTopLeft, Rectangle< int > sourceRect) override
 
bool needsBackup () const override
 Returns true if the main-memory copy of the image is out-of-date, false if it's up-to-date.
 
void setBackupEnabled (bool) override
 The automatic image backup mechanism can be disabled by passing false to this function, or enabled by passing true.
 

Static Private Member Functions

static void copyPages (ComSmartPtr< ID2D1Device1 >, Direct2DPixelData &, Direct2DPixelData &, Point< int >, Rectangle< int >)
 

Private Attributes

ImagePixelData::Ptr backingData
 
SharedResourcePointer< DirectXdirectX
 
ComSmartPtr< ID2D1Device1 > mostRecentDevice
 
std::map< ComSmartPtr< ID2D1Device1 >, PagespagesForDevice
 
Atomic< int > refCount { 0 }
 
State state
 
bool sync = true
 

Member Typedef Documentation

◆ BackupExtensions

◆ NativeExtensions

◆ Page

◆ Pages

◆ Ptr

Member Enumeration Documentation

◆ State

enum class juce::Direct2DPixelData::State
strongprivate
Enumerator
initiallyUndefined 
initiallyCleared 
drawing 
drawn 
outdated 

Constructor & Destructor Documentation

◆ Direct2DPixelData() [1/3]

juce::Direct2DPixelData::Direct2DPixelData ( ComSmartPtr< ID2D1Device1 >  ,
ComSmartPtr< ID2D1Bitmap1 >   
)

◆ Direct2DPixelData() [2/3]

juce::Direct2DPixelData::Direct2DPixelData ( Image::PixelFormat  ,
int  ,
int  ,
bool   
)

◆ ~Direct2DPixelData()

juce::Direct2DPixelData::~Direct2DPixelData ( )
override

◆ Direct2DPixelData() [3/3]

juce::Direct2DPixelData::Direct2DPixelData ( ImagePixelData::Ptr  ,
State   
)
private

Member Function Documentation

◆ adapterCreated()

void juce::Direct2DPixelData::adapterCreated ( DxgiAdapter::Ptr  )
inlineoverrideprivatevirtual

◆ adapterRemoved()

void juce::Direct2DPixelData::adapterRemoved ( DxgiAdapter::Ptr  adapter)
inlineoverrideprivatevirtual

◆ applyEffectInArea()

template<typename Fn >
bool juce::Direct2DPixelData::applyEffectInArea ( Rectangle< int >  ,
Fn &&   
)
private

◆ applyGaussianBlurEffect()

void juce::ImagePixelData::applyGaussianBlurEffect ( float  radius)
inlineinherited

◆ applyGaussianBlurEffectInArea()

void juce::Direct2DPixelData::applyGaussianBlurEffectInArea ( Rectangle< int >  bounds,
float  radius 
)
overridevirtual

Applies a native blur effect to this image, if available.

This blur applies to all channels of the input image. It may be more expensive to calculate than a box blur, but should produce higher-quality results.

The default implementation will modify the image pixel-by-pixel on the CPU, which will be slow. Native image types may provide optimised implementations.

Reimplemented from juce::ImagePixelData.

◆ applySingleChannelBoxBlurEffect()

void juce::ImagePixelData::applySingleChannelBoxBlurEffect ( int  radius)
inlineinherited

◆ applySingleChannelBoxBlurEffectInArea()

void juce::Direct2DPixelData::applySingleChannelBoxBlurEffectInArea ( Rectangle< int >  bounds,
int  radius 
)
overridevirtual

Applies a native blur effect to this image, if available.

This is intended for blurring single-channel images, which is useful when rendering drop shadows. This is implemented as several box-blurs in series. The results should be visually similar to a Gaussian blur, but less accurate.

The default implementation will modify the image pixel-by-pixel on the CPU, which will be slow. Native image types may provide optimised implementations.

Reimplemented from juce::ImagePixelData.

◆ backupNow()

bool juce::Direct2DPixelData::backupNow ( )
overrideprivatevirtual

This function will attempt to make the image resilient to graphics device disconnection by copying from graphics memory to main memory.

By default, backups happen automatically, so there's no need to call this function unless auto-backup has been disabled on this image.

Flushing may fail if the graphics device goes away before its memory can be read. If needsBackup() returns false, then backupNow() will always return true without doing any work.

Returns
true if the main-memory copy of the image is up-to-date, or false otherwise.
See also
setBackupEnabled(), isBackupEnabled()

Implements juce::ImagePixelDataBackupExtensions.

◆ canBackup()

bool juce::Direct2DPixelData::canBackup ( ) const
overrideprivatevirtual

Returns if there is an up-to-date copy of this image in graphics memory, or false otherwise.

See also
needsBackup()

Implements juce::ImagePixelDataBackupExtensions.

◆ clone()

ImagePixelData::Ptr juce::Direct2DPixelData::clone ( )
overridevirtual

Creates a copy of this image.

Implements juce::ImagePixelData.

◆ copyPages()

static void juce::Direct2DPixelData::copyPages ( ComSmartPtr< ID2D1Device1 >  ,
Direct2DPixelData ,
Direct2DPixelData ,
Point< int >  ,
Rectangle< int >   
)
staticprivate

◆ createLowLevelContext()

std::unique_ptr< LowLevelGraphicsContext > juce::Direct2DPixelData::createLowLevelContext ( )
overridevirtual

Creates a context that will draw into this image.

Implements juce::ImagePixelData.

◆ createNativeContext()

std::unique_ptr< Context > juce::Direct2DPixelData::createNativeContext ( )
private

◆ createPersistentBackup()

bool juce::Direct2DPixelData::createPersistentBackup ( ComSmartPtr< ID2D1Device1 >  deviceHint)
private

◆ createType()

std::unique_ptr< ImageType > juce::Direct2DPixelData::createType ( ) const
inlineoverridevirtual

Creates an instance of the type of this image.

Implements juce::ImagePixelData.

◆ decReferenceCount()

void juce::ReferenceCountedObject::decReferenceCount ( )
inlinenoexceptinherited

Decreases the object's reference count.

If the count gets to zero, the object will be deleted.

References jassert.

◆ decReferenceCountWithoutDeleting()

bool juce::ReferenceCountedObject::decReferenceCountWithoutDeleting ( )
inlinenoexceptinherited

Decreases the object's reference count.

If the count gets to zero, the object will not be deleted, but this method will return true, allowing the caller to take care of deletion.

References jassert.

◆ desaturate()

void juce::ImagePixelData::desaturate ( )
inlineinherited

◆ desaturateInArea()

void juce::Direct2DPixelData::desaturateInArea ( Rectangle< int >  bounds)
overridevirtual

Changes all the colours to be shades of grey, based on their current luminosity.

The default implementation will modify the image pixel-by-pixel on the CPU, which will be slow. Native image types may provide optimised implementations.

Reimplemented from juce::ImagePixelData.

◆ getBackupExtensions() [1/2]

const BackupExtensions * juce::Direct2DPixelData::getBackupExtensions ( ) const
inlineoverridevirtual

Reimplemented from juce::ImagePixelData.

◆ getBackupExtensions() [2/2]

BackupExtensions * juce::Direct2DPixelData::getBackupExtensions ( )
inlineoverridevirtual

Returns a raw pointer to an instance of ImagePixelDataBackupExtensions if this ImagePixelData provides this extension, or nullptr otherwise.

Reimplemented from juce::ImagePixelData.

◆ getFirstPageForDevice()

ComSmartPtr< ID2D1Bitmap1 > juce::Direct2DPixelData::getFirstPageForDevice ( ComSmartPtr< ID2D1Device1 >  device)
inline

References getPagesForDevice().

◆ getIteratorForDevice()

auto juce::Direct2DPixelData::getIteratorForDevice ( ComSmartPtr< ID2D1Device1 >  )
private

◆ getMostRelevantDevice()

ComSmartPtr< ID2D1Device1 > juce::Direct2DPixelData::getMostRelevantDevice ( )
private

◆ getNativeExtensions()

ImagePixelDataNativeExtensions juce::Direct2DPixelData::getNativeExtensions ( )
overridevirtual

intentionally not callable from user code

Reimplemented from juce::ImagePixelData.

◆ getPagesForDevice()

Span< const Page > juce::Direct2DPixelData::getPagesForDevice ( ComSmartPtr< ID2D1Device1 >  )

Referenced by getFirstPageForDevice().

◆ getPagesStructForDevice()

Direct2DPixelDataPages & juce::Direct2DPixelData::getPagesStructForDevice ( ComSmartPtr< ID2D1Device1 >  )
private

◆ getReferenceCount()

int juce::ReferenceCountedObject::getReferenceCount ( ) const
inlinenoexceptinherited

Returns the object's current reference count.

◆ getSharedCount()

virtual int juce::ImagePixelData::getSharedCount ( ) const
virtualnoexceptinherited

Returns the number of Image objects which are currently referring to the same internal shared image data.

This is different to the reference count as an instance of ImagePixelData can internally depend on another ImagePixelData via it's member variables.

◆ incReferenceCount()

void juce::ReferenceCountedObject::incReferenceCount ( )
inlinenoexceptinherited

Increments the object's reference count.

This is done automatically by the smart pointer, but is public just in case it's needed for nefarious purposes.

◆ initialiseBitmapData()

void juce::Direct2DPixelData::initialiseBitmapData ( Image::BitmapData ,
int  x,
int  y,
Image::BitmapData::ReadWriteMode   
)
overridevirtual

Initialises a BitmapData object.

Implements juce::ImagePixelData.

◆ isBackupEnabled()

bool juce::Direct2DPixelData::isBackupEnabled ( ) const
overrideprivatevirtual

◆ moveImageSection()

void juce::ImagePixelData::moveImageSection ( Point< int >  destTopLeft,
Rectangle< int >  sourceRect 
)
inherited

Copies a section of the image to somewhere else within itself.

◆ moveValidatedImageSection()

void juce::Direct2DPixelData::moveValidatedImageSection ( Point< int >  destTopLeft,
Rectangle< int >  sourceRect 
)
overrideprivatevirtual

Reimplemented from juce::ImagePixelData.

◆ multiplyAllAlphas()

void juce::ImagePixelData::multiplyAllAlphas ( float  amount)
inlineinherited

◆ multiplyAllAlphasInArea()

void juce::Direct2DPixelData::multiplyAllAlphasInArea ( Rectangle< int >  bounds,
float  amount 
)
overridevirtual

Multiples all alpha-channel values in the image by the specified amount.

The default implementation will modify the image pixel-by-pixel on the CPU, which will be slow. Native image types may provide optimised implementations.

Reimplemented from juce::ImagePixelData.

◆ needsBackup()

bool juce::Direct2DPixelData::needsBackup ( ) const
overrideprivatevirtual

Returns true if the main-memory copy of the image is out-of-date, false if it's up-to-date.

See also
canBackup()

Implements juce::ImagePixelDataBackupExtensions.

◆ resetReferenceCount()

void juce::ReferenceCountedObject::resetReferenceCount ( )
inlineprotectednoexceptinherited

Resets the reference count to zero without deleting the object.

You should probably never need to use this!

◆ sendDataChangeMessage()

void juce::ImagePixelData::sendDataChangeMessage ( )
inherited

◆ setBackupEnabled()

void juce::Direct2DPixelData::setBackupEnabled ( bool  )
overrideprivatevirtual

The automatic image backup mechanism can be disabled by passing false to this function, or enabled by passing true.

If you disable automatic backup for a particular image, make sure you test that your software behaves as expected when graphics devices are disconnected. One easy way to test this on Windows is to use your program over a remote desktop session, and to end and re-start the session while the image is being displayed.

The most common scenario where this flag is useful is when drawing single-use images. e.g. for a drop shadow or other effect, the following series of steps might be carried out on each paint call:

  • Create a path that matches the shadowed component's outline
  • Draw the path into a temporary image
  • Blur the temporary image
  • Draw the temporary image into some other context
  • (destroy the temporary image)

In this case, where the image is created, modified, used, and destroyed in quick succession, there's no need to keep a resilient backup of the image around, so it's reasonable to call setBackupEnabled(false) after constructing the image.

See also
isBackupEnabled(), backupNow()

Implements juce::ImagePixelDataBackupExtensions.

Member Data Documentation

◆ backingData

ImagePixelData::Ptr juce::Direct2DPixelData::backingData
private

◆ directX

SharedResourcePointer<DirectX> juce::Direct2DPixelData::directX
private

◆ height

const int juce::ImagePixelData::height
inherited

◆ listeners

ListenerList<Listener> juce::ImagePixelData::listeners
inherited

◆ mostRecentDevice

ComSmartPtr<ID2D1Device1> juce::Direct2DPixelData::mostRecentDevice
private

Referenced by adapterRemoved().

◆ pagesForDevice

std::map<ComSmartPtr<ID2D1Device1>, Pages> juce::Direct2DPixelData::pagesForDevice
private

Referenced by adapterRemoved().

◆ pixelFormat

const Image::PixelFormat juce::ImagePixelData::pixelFormat
inherited

The pixel format of the image data.

◆ refCount

Atomic<int> juce::ReferenceCountedObject::refCount { 0 }
privateinherited

◆ state

State juce::Direct2DPixelData::state
private

◆ sync

bool juce::Direct2DPixelData::sync = true
private

◆ userData

NamedValueSet juce::ImagePixelData::userData
inherited

User-defined settings that are attached to this image.

See also
Image::getProperties().

◆ width

const int juce::ImagePixelData::width
inherited

The documentation for this class was generated from the following file: