Browse Source

Fix warnings on linux

Linux now compiles (clang++-3.5) without warnings when the following is enabled (these flags are identical to equator mac warnings):
-Wreorder -Wconstant-conversion -Wint-conversion -Woverloaded-virtual -Wuninitialized -Wunused-parameter -Wshorten-64-to-32 -Wstrict-aliasing -Wshadow -Wconversion -Wsign-compare -Werror -Wsign-conversion
tags/2021-05-28
hogliux 10 years ago
parent
commit
8c242b7547
13 changed files with 340 additions and 335 deletions
  1. +2
    -2
      modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp
  2. +21
    -21
      modules/juce_audio_devices/native/juce_linux_ALSA.cpp
  3. +7
    -7
      modules/juce_audio_devices/native/juce_linux_Midi.cpp
  4. +2
    -2
      modules/juce_core/native/juce_linux_CommonFile.cpp
  5. +5
    -5
      modules/juce_core/native/juce_linux_Network.cpp
  6. +3
    -3
      modules/juce_core/native/juce_linux_SystemStats.cpp
  7. +1
    -1
      modules/juce_core/native/juce_posix_SharedCode.h
  8. +2
    -2
      modules/juce_events/native/juce_linux_Messaging.cpp
  9. +5
    -5
      modules/juce_graphics/native/juce_freetype_Fonts.cpp
  10. +2
    -2
      modules/juce_gui_basics/native/juce_linux_Clipboard.cpp
  11. +93
    -89
      modules/juce_gui_basics/native/juce_linux_Windowing.cpp
  12. +1
    -1
      modules/juce_gui_extra/native/juce_linux_SystemTrayIcon.cpp
  13. +196
    -195
      modules/juce_opengl/native/juce_OpenGL_linux.h

+ 2
- 2
modules/juce_audio_basics/buffers/juce_FloatVectorOperations.cpp View File

@@ -507,7 +507,7 @@ void JUCE_CALLTYPE FloatVectorOperations::clear (float* dest, int num) noexcept
#if JUCE_USE_VDSP_FRAMEWORK
vDSP_vclr (dest, 1, (size_t) num);
#else
zeromem (dest, num * sizeof (float));
zeromem (dest, (size_t) num * sizeof (float));
#endif
}
@@ -516,7 +516,7 @@ void JUCE_CALLTYPE FloatVectorOperations::clear (double* dest, int num) noexcept
#if JUCE_USE_VDSP_FRAMEWORK
vDSP_vclrD (dest, 1, (size_t) num);
#else
zeromem (dest, num * sizeof (double));
zeromem (dest, (size_t) num * sizeof (double));
#endif
}


+ 21
- 21
modules/juce_audio_devices/native/juce_linux_ALSA.cpp View File

@@ -57,7 +57,7 @@ static void getDeviceSampleRates (snd_pcm_t* handle, Array<double>& rates)
for (int i = 0; ratesToTry[i] != 0; ++i)
{
if (snd_pcm_hw_params_any (handle, hwParams) >= 0
&& snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
&& snd_pcm_hw_params_test_rate (handle, hwParams, (unsigned int) ratesToTry[i], 0) == 0)
{
rates.addIfNotAlreadyThere ((double) ratesToTry[i]);
}
@@ -257,10 +257,10 @@ public:
int dir = 0;
unsigned int periods = 4;
snd_pcm_uframes_t samplesPerPeriod = bufferSize;
snd_pcm_uframes_t samplesPerPeriod = (snd_pcm_uframes_t) bufferSize;
if (JUCE_ALSA_FAILED (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
|| JUCE_ALSA_FAILED (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
|| JUCE_ALSA_FAILED (snd_pcm_hw_params_set_channels (handle, hwParams, (unsigned int ) numChannels))
|| JUCE_ALSA_FAILED (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
|| JUCE_ALSA_FAILED (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
|| JUCE_ALSA_FAILED (snd_pcm_hw_params (handle, hwParams)))
@@ -274,7 +274,7 @@ public:
|| JUCE_ALSA_FAILED (snd_pcm_hw_params_get_periods (hwParams, &periods, &dir)))
latency = 0;
else
latency = frames * (periods - 1); // (this is the method JACK uses to guess the latency..)
latency = (int) frames * ((int) periods - 1); // (this is the method JACK uses to guess the latency..)
JUCE_ALSA_LOG ("frames: " << (int) frames << ", periods: " << (int) periods
<< ", samplesPerPeriod: " << (int) samplesPerPeriod);
@@ -316,22 +316,22 @@ public:
if (isInterleaved)
{
scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
scratch.ensureSize ((size_t) ((int) sizeof (float) * numSamples * numChannelsRunning), false);
for (int i = 0; i < numChannelsRunning; ++i)
converter->convertSamples (scratch.getData(), i, data[i], 0, numSamples);
numDone = snd_pcm_writei (handle, scratch.getData(), numSamples);
numDone = snd_pcm_writei (handle, scratch.getData(), (snd_pcm_uframes_t) numSamples);
}
else
{
for (int i = 0; i < numChannelsRunning; ++i)
converter->convertSamples (data[i], data[i], numSamples);
numDone = snd_pcm_writen (handle, (void**) data, numSamples);
numDone = snd_pcm_writen (handle, (void**) data, (snd_pcm_uframes_t) numSamples);
}
if (numDone < 0 && JUCE_ALSA_FAILED (snd_pcm_recover (handle, numDone, 1 /* silent */)))
if (numDone < 0 && JUCE_ALSA_FAILED (snd_pcm_recover (handle, (int) numDone, 1 /* silent */)))
return false;
if (numDone < numSamples)
@@ -347,12 +347,12 @@ public:
if (isInterleaved)
{
scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
scratch.ensureSize ((size_t) ((int) sizeof (float) * numSamples * numChannelsRunning), false);
scratch.fillWith (0); // (not clearing this data causes warnings in valgrind)
snd_pcm_sframes_t num = snd_pcm_readi (handle, scratch.getData(), numSamples);
snd_pcm_sframes_t num = snd_pcm_readi (handle, scratch.getData(), (snd_pcm_uframes_t) numSamples);
if (num < 0 && JUCE_ALSA_FAILED (snd_pcm_recover (handle, num, 1 /* silent */)))
if (num < 0 && JUCE_ALSA_FAILED (snd_pcm_recover (handle, (int) num, 1 /* silent */)))
return false;
if (num < numSamples)
@@ -363,9 +363,9 @@ public:
}
else
{
snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, (snd_pcm_uframes_t) numSamples);
if (num < 0 && JUCE_ALSA_FAILED (snd_pcm_recover (handle, num, 1 /* silent */)))
if (num < 0 && JUCE_ALSA_FAILED (snd_pcm_recover (handle, (int) num, 1 /* silent */)))
return false;
if (num < numSamples)
@@ -503,7 +503,7 @@ public:
}
}
ensureMinimumNumBitsSet (outputChannels, minChansOut);
ensureMinimumNumBitsSet (outputChannels, (int) minChansOut);
outputChannelBuffer.setSize (jmax ((int) minChansOut, outputChannels.getHighestBit()) + 1, bufferSize);
outputChannelBuffer.clear();
@@ -557,7 +557,7 @@ public:
return;
}
ensureMinimumNumBitsSet (currentInputChans, minChansIn);
ensureMinimumNumBitsSet (currentInputChans, (int) minChansIn);
if (! inputDevice->setParameters ((unsigned int) sampleRate,
jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
@@ -656,7 +656,7 @@ public:
snd_pcm_sframes_t avail = snd_pcm_avail_update (inputDevice->handle);
if (avail < 0)
JUCE_ALSA_FAILED (snd_pcm_recover (inputDevice->handle, avail, 0));
JUCE_ALSA_FAILED (snd_pcm_recover (inputDevice->handle, (int) avail, 0));
}
audioIoInProgress = true;
@@ -688,7 +688,7 @@ public:
else
{
for (int i = 0; i < outputChannelDataForCallback.size(); ++i)
zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
zeromem (outputChannelDataForCallback[i], sizeof (float) * (size_t) bufferSize);
}
}
@@ -702,7 +702,7 @@ public:
snd_pcm_sframes_t avail = snd_pcm_avail_update (outputDevice->handle);
if (avail < 0)
JUCE_ALSA_FAILED (snd_pcm_recover (outputDevice->handle, avail, 0));
JUCE_ALSA_FAILED (snd_pcm_recover (outputDevice->handle, (int) avail, 0));
audioIoInProgress = true;
@@ -1092,9 +1092,9 @@ private:
if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
break;
snd_pcm_info_set_device (pcmInfo, device);
snd_pcm_info_set_device (pcmInfo, (unsigned int) device);
for (int subDevice = 0, nbSubDevice = 1; subDevice < nbSubDevice; ++subDevice)
for (unsigned int subDevice = 0, nbSubDevice = 1; subDevice < nbSubDevice; ++subDevice)
{
snd_pcm_info_set_subdevice (pcmInfo, subDevice);
snd_pcm_info_set_stream (pcmInfo, SND_PCM_STREAM_CAPTURE);
@@ -1118,7 +1118,7 @@ private:
}
else
{
id << "hw:" << cardId << "," << device << "," << subDevice;
id << "hw:" << cardId << "," << device << "," << (int) subDevice;
name << cardName << ", " << snd_pcm_info_get_name (pcmInfo)
<< " {" << snd_pcm_info_get_subdevice_name (pcmInfo) << "}";
}


+ 7
- 7
modules/juce_audio_devices/native/juce_linux_Midi.cpp View File

@@ -133,14 +133,14 @@ private:
if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
{
const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
HeapBlock<pollfd> pfd (numPfds);
snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
HeapBlock<pollfd> pfd ((size_t) numPfds);
snd_seq_poll_descriptors (seqHandle, pfd, (unsigned int) numPfds, POLLIN);
HeapBlock <uint8> buffer (maxEventSize);
while (! threadShouldExit())
{
if (poll (pfd, numPfds, 100) > 0) // there was a "500" here which is a bit long when we exit the program and have to wait for a timeout on this poll call
if (poll (pfd, (nfds_t) numPfds, 100) > 0) // there was a "500" here which is a bit long when we exit the program and have to wait for a timeout on this poll call
{
if (threadShouldExit())
break;
@@ -154,14 +154,14 @@ private:
if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
{
// xxx what about SYSEXes that are too big for the buffer?
const int numBytes = snd_midi_event_decode (midiParser, buffer,
const long numBytes = snd_midi_event_decode (midiParser, buffer,
maxEventSize, inputEvent);
snd_midi_event_reset_decode (midiParser);
if (numBytes > 0)
{
const MidiMessage message ((const uint8*) buffer, numBytes,
const MidiMessage message ((const uint8*) buffer, (int) numBytes,
Time::getMillisecondCounter() * 0.001);
client.handleIncomingMidiMessage (message, inputEvent->dest.port);
@@ -410,7 +410,7 @@ public:
maxEventSize (16 * 1024)
{
jassert (port.isValid() && midiOutput != nullptr);
snd_midi_event_new (maxEventSize, &midiParser);
snd_midi_event_new ((size_t) maxEventSize, &midiParser);
}
~MidiOutputDevice()
@@ -425,7 +425,7 @@ public:
{
maxEventSize = message.getRawDataSize();
snd_midi_event_free (midiParser);
snd_midi_event_new (maxEventSize, &midiParser);
snd_midi_event_new ((size_t) maxEventSize, &midiParser);
}
snd_seq_event_t event;


+ 2
- 2
modules/juce_core/native/juce_linux_CommonFile.cpp View File

@@ -138,8 +138,8 @@ private:
JUCE_DECLARE_NON_COPYABLE (Pimpl)
};
DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCard)
: pimpl (new DirectoryIterator::NativeIterator::Pimpl (directory, wildCard))
DirectoryIterator::NativeIterator::NativeIterator (const File& directory, const String& wildCardStr)
: pimpl (new DirectoryIterator::NativeIterator::Pimpl (directory, wildCardStr))
{
}


+ 5
- 5
modules/juce_core/native/juce_linux_Network.cpp View File

@@ -127,7 +127,7 @@ public:
if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
return 0; // (timeout)
const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, (size_t) bytesToRead, MSG_WAITALL));
if (bytesRead == 0)
finished = true;
@@ -193,7 +193,7 @@ private:
else if (timeOutMs < 0)
timeOutTime = 0xffffffff;
else
timeOutTime += timeOutMs;
timeOutTime += (uint32) timeOutMs;
String hostName, hostPath;
int hostPort;
@@ -391,12 +391,12 @@ private:
const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
if (send (socketHandle, static_cast <const char*> (requestHeader.getData()) + totalHeaderSent, numToSend, 0) != numToSend)
if (send (socketHandle, static_cast <const char*> (requestHeader.getData()) + totalHeaderSent, (size_t) numToSend, 0) != numToSend)
return false;
totalHeaderSent += numToSend;
totalHeaderSent += (size_t) numToSend;
if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, totalHeaderSent, requestHeader.getSize()))
if (progressCallback != nullptr && ! progressCallback (progressCallbackContext, (int) totalHeaderSent, (int) requestHeader.getSize()))
return false;
}


+ 3
- 3
modules/juce_core/native/juce_linux_SystemStats.cpp View File

@@ -98,14 +98,14 @@ int SystemStats::getMemorySizeInMegabytes()
struct sysinfo sysi;
if (sysinfo (&sysi) == 0)
return sysi.totalram * sysi.mem_unit / (1024 * 1024);
return (int) (sysi.totalram * sysi.mem_unit / (1024 * 1024));
return 0;
}
int SystemStats::getPageSize()
{
return sysconf (_SC_PAGESIZE);
return (int) sysconf (_SC_PAGESIZE);
}
//==============================================================================
@@ -167,7 +167,7 @@ uint32 juce_millisecondsSinceStartup() noexcept
timespec t;
clock_gettime (CLOCK_MONOTONIC, &t);
return t.tv_sec * 1000 + t.tv_nsec / 1000000;
return (uint32) (t.tv_sec * 1000 + t.tv_nsec / 1000000);
}
int64 Time::getHighResolutionTicks() noexcept


+ 1
- 1
modules/juce_core/native/juce_posix_SharedCode.h View File

@@ -1274,7 +1274,7 @@ private:
{
struct timespec t;
clock_gettime (CLOCK_MONOTONIC, &t);
time = 1000000000 * (int64) t.tv_sec + t.tv_nsec;
time = (uint64) (1000000000 * (int64) t.tv_sec + (int64) t.tv_nsec);
}
void wait() noexcept


+ 2
- 2
modules/juce_events/native/juce_linux_Messaging.cpp View File

@@ -74,7 +74,7 @@ public:
ScopedUnlock ul (lock);
const unsigned char x = 0xff;
size_t bytesWritten = write (fd[0], &x, 1);
ssize_t bytesWritten = write (fd[0], &x, 1);
(void) bytesWritten;
}
}
@@ -186,7 +186,7 @@ private:
const ScopedUnlock ul (lock);
unsigned char x;
size_t numBytes = read (fd[1], &x, 1);
ssize_t numBytes = read (fd[1], &x, 1);
(void) numBytes;
}


+ 5
- 5
modules/juce_graphics/native/juce_freetype_Fonts.cpp View File

@@ -244,7 +244,7 @@ private:
if (face.face != 0)
{
if (faceIndex == 0)
numFaces = face.face->num_faces;
numFaces = (int) face.face->num_faces;
if ((face.face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
faces.add (new KnownTypeface (file, faceIndex, face));
@@ -319,7 +319,7 @@ public:
if (faceWrapper != nullptr)
{
FT_Face face = faceWrapper->face;
const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
const unsigned int glyphIndex = FT_Get_Char_Index (face, (FT_ULong) character);
if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM | FT_LOAD_NO_HINTING) == 0
&& face->glyph->format == ft_glyph_format_outline)
@@ -332,7 +332,7 @@ public:
addGlyph (character, destShape, face->glyph->metrics.horiAdvance * scale);
if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
addKerning (face, character, glyphIndex);
addKerning (face, (uint32) character, glyphIndex);
return true;
}
@@ -437,7 +437,7 @@ private:
const float height = (float) (face->ascender - face->descender);
uint32 rightGlyphIndex;
uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
FT_ULong rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
while (rightGlyphIndex != 0)
{
@@ -445,7 +445,7 @@ private:
if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0
&& kerning.x != 0)
addKerningPair (character, rightCharCode, kerning.x / height);
addKerningPair ((juce_wchar) character, (juce_wchar) rightCharCode, kerning.x / height);
rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
}


+ 2
- 2
modules/juce_gui_basics/native/juce_linux_Clipboard.cpp View File

@@ -68,7 +68,7 @@ namespace ClipboardHelpers
(unsigned char**) &clipData) == Success)
{
if (actualType == atom_UTF8_STRING && actualFormat == 8)
returnData = String::fromUTF8 (clipData, numItems);
returnData = String::fromUTF8 (clipData, (int) numItems);
else if (actualType == XA_STRING && actualFormat == 8)
returnData = String (clipData, numItems);
@@ -184,7 +184,7 @@ namespace ClipboardHelpers
XChangeProperty (evt.display, evt.requestor,
evt.property, evt.target,
propertyFormat /* 8 or 32 */, PropModeReplace,
reinterpret_cast<const unsigned char*> (data.getData()), numDataItems);
reinterpret_cast<const unsigned char*> (data.getData()), (int) numDataItems);
reply.property = evt.property; // " == success"
}
}


+ 93
- 89
modules/juce_gui_basics/native/juce_linux_Windowing.cpp View File

@@ -189,7 +189,7 @@ bool KeyPress::isKeyCurrentlyDown (const int keyCode)
ScopedXLock xlock;
const int keycode = XKeysymToKeycode (display, keysym);
const int keycode = XKeysymToKeycode (display, (KeySym) keysym);
const int keybyte = keycode >> 3;
const int keybit = (1 << (keycode & 7));
@@ -235,7 +235,7 @@ namespace XSHMHelpers
24, ZPixmap, 0, &segmentInfo, 50, 50);
if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
xImage->bytes_per_line * xImage->height,
(size_t) (xImage->bytes_per_line * xImage->height),
IPC_CREAT | 0777)) >= 0)
{
segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
@@ -505,7 +505,7 @@ class XBitmapImage : public ImagePixelData
{
public:
XBitmapImage (const Image::PixelFormat format, const int w, const int h,
const bool clearImage, const int imageDepth_, Visual* visual)
const bool clearImage, const unsigned int imageDepth_, Visual* visual)
: ImagePixelData (format, w, h),
imageDepth (imageDepth_),
gc (None)
@@ -528,12 +528,13 @@ public:
segmentInfo.shmaddr = (char *) -1;
segmentInfo.readOnly = False;
xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0, &segmentInfo, w, h);
xImage = XShmCreateImage (display, visual, imageDepth, ZPixmap, 0,
&segmentInfo, (unsigned int) w, (unsigned int) h);
if (xImage != nullptr)
{
if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
xImage->bytes_per_line * xImage->height,
(size_t) (xImage->bytes_per_line * xImage->height),
IPC_CREAT | 0777)) >= 0)
{
if (segmentInfo.shmid != -1)
@@ -564,7 +565,7 @@ public:
if (! isUsingXShm())
#endif
{
imageDataAllocated.allocate (lineStride * h, format == Image::ARGB && clearImage);
imageDataAllocated.allocate ((size_t) (lineStride * h), format == Image::ARGB && clearImage);
imageData = imageDataAllocated;
xImage = (XImage*) ::calloc (1, sizeof (XImage));
@@ -590,7 +591,7 @@ public:
const int pixStride = 2;
const int stride = ((w * pixStride + 3) & ~3);
imageData16Bit.malloc (stride * h);
imageData16Bit.malloc ((size_t) (stride * h));
xImage->data = imageData16Bit;
xImage->bitmap_pad = 16;
xImage->depth = pixStride * 8;
@@ -657,7 +658,7 @@ public:
ImageType* createType() const override { return new NativeImageType(); }
void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
void blitToWindow (Window window, int dx, int dy, unsigned int dw, unsigned int dh, int sx, int sy)
{
ScopedXLock xlock;
@@ -678,23 +679,23 @@ public:
if (imageDepth == 16)
{
const uint32 rMask = xImage->red_mask;
const uint32 gMask = xImage->green_mask;
const uint32 bMask = xImage->blue_mask;
const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
const uint32 rMask = (uint32) xImage->red_mask;
const uint32 gMask = (uint32) xImage->green_mask;
const uint32 bMask = (uint32) xImage->blue_mask;
const uint32 rShiftL = (uint32) jmax (0, getShiftNeeded (rMask));
const uint32 rShiftR = (uint32) jmax (0, -getShiftNeeded (rMask));
const uint32 gShiftL = (uint32) jmax (0, getShiftNeeded (gMask));
const uint32 gShiftR = (uint32) jmax (0, -getShiftNeeded (gMask));
const uint32 bShiftL = (uint32) jmax (0, getShiftNeeded (bMask));
const uint32 bShiftR = (uint32) jmax (0, -getShiftNeeded (bMask));
const Image::BitmapData srcData (Image (this), Image::BitmapData::readOnly);
for (int y = sy; y < sy + dh; ++y)
for (int y = sy; y < sy + (int)dh; ++y)
{
const uint8* p = srcData.getPixelPointer (sx, y);
for (int x = sx; x < sx + dw; ++x)
for (int x = sx; x < sx + (int)dw; ++x)
{
const PixelRGB* const pixel = (const PixelRGB*) p;
p += srcData.pixelStride;
@@ -723,7 +724,7 @@ public:
private:
//==============================================================================
XImage* xImage;
const int imageDepth;
const unsigned int imageDepth;
HeapBlock<uint8> imageDataAllocated;
HeapBlock<char> imageData16Bit;
int pixelStride, lineStride;
@@ -755,13 +756,13 @@ namespace PixmapHelpers
{
ScopedXLock xlock;
const int width = image.getWidth();
const int height = image.getHeight();
const unsigned int width = (unsigned int) image.getWidth();
const unsigned int height = (unsigned int) image.getHeight();
HeapBlock<uint32> colour (width * height);
int index = 0;
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
for (int y = 0; y < (int) height; ++y)
for (int x = 0; x < (int) width; ++x)
colour[index++] = image.getPixelAt (x, y).getARGB();
XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
@@ -782,21 +783,21 @@ namespace PixmapHelpers
{
ScopedXLock xlock;
const int width = image.getWidth();
const int height = image.getHeight();
const int stride = (width + 7) >> 3;
const unsigned int width = (unsigned int) image.getWidth();
const unsigned int height = (unsigned int) image.getHeight();
const unsigned int stride = (width + 7) >> 3;
HeapBlock<char> mask;
mask.calloc (stride * height);
const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
for (int y = 0; y < height; ++y)
for (unsigned int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
for (unsigned int x = 0; x < width; ++x)
{
const char bit = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
const int offset = y * stride + (x >> 3);
const unsigned int offset = y * stride + (x >> 3);
if (image.getPixelAt (x, y).getAlpha() >= 128)
if (image.getPixelAt ((int) x, (int) y).getAlpha() >= 128)
mask[offset] |= bit;
}
}
@@ -943,7 +944,7 @@ public:
clientMsg.format = 32;
clientMsg.message_type = Atoms::get().windowState;
clientMsg.data.l[0] = 0; // Remove
clientMsg.data.l[1] = fs;
clientMsg.data.l[1] = (long) fs;
clientMsg.data.l[2] = 0;
clientMsg.data.l[3] = 1; // Normal Source
@@ -984,8 +985,8 @@ public:
XMoveResizeWindow (display, windowH,
bounds.getX() - windowBorder.getLeft(),
bounds.getY() - windowBorder.getTop(),
bounds.getWidth(),
bounds.getHeight());
(unsigned int) bounds.getWidth(),
(unsigned int) bounds.getHeight());
if (deletionChecker != nullptr)
{
@@ -1105,7 +1106,7 @@ public:
if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
{
for (int i = windowListSize; --i >= 0;)
for (int i = (int) windowListSize; --i >= 0;)
{
if (LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]))
{
@@ -1235,7 +1236,7 @@ public:
&& atts.map_state == IsViewable
&& ! isFocused())
{
XSetInputFocus (display, windowH, RevertToParent, getUserTime());
XSetInputFocus (display, windowH, RevertToParent, (::Time) getUserTime());
isActiveApplication = true;
}
}
@@ -1255,7 +1256,7 @@ public:
void setIcon (const Image& newIcon) override
{
const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
HeapBlock<unsigned long> data (dataSize);
HeapBlock<unsigned long> data ((size_t) dataSize);
int index = 0;
data[index++] = (unsigned long) newIcon.getWidth();
@@ -1371,7 +1372,7 @@ public:
{
ScopedXLock xlock;
updateKeyStates (keyEvent.keycode, true);
updateKeyStates ((int) keyEvent.keycode, true);
String oldLocale (::setlocale (LC_ALL, 0));
::setlocale (LC_ALL, "");
@@ -1384,7 +1385,7 @@ public:
keyCode = (int) unicodeChar;
if (keyCode < 0x20)
keyCode = XkbKeycodeToKeysym (display, keyEvent.keycode, 0, currentModifiers.isShiftDown() ? 1 : 0);
keyCode = (int) XkbKeycodeToKeysym (display, (::KeyCode) keyEvent.keycode, 0, currentModifiers.isShiftDown() ? 1 : 0);
keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
}
@@ -1499,12 +1500,12 @@ public:
{
if (! isKeyReleasePartOfAutoRepeat (keyEvent))
{
updateKeyStates (keyEvent.keycode, false);
updateKeyStates ((int) keyEvent.keycode, false);
KeySym sym;
{
ScopedXLock xlock;
sym = XkbKeycodeToKeysym (display, keyEvent.keycode, 0, 0);
sym = XkbKeycodeToKeysym (display, (::KeyCode) keyEvent.keycode, 0, 0);
}
const ModifierKeys oldMods (currentModifiers);
@@ -1544,7 +1545,7 @@ public:
void handleButtonPressEvent (const XButtonPressedEvent& buttonPressEvent)
{
updateKeyModifiers (buttonPressEvent.state);
updateKeyModifiers ((int) buttonPressEvent.state);
switch (pointerMap [buttonPressEvent.button - Button1])
{
@@ -1561,7 +1562,7 @@ public:
void handleButtonReleaseEvent (const XButtonReleasedEvent& buttonRelEvent)
{
updateKeyModifiers (buttonRelEvent.state);
updateKeyModifiers ((int) buttonRelEvent.state);
if (parentWindow != 0)
updateWindowBounds();
@@ -1584,7 +1585,7 @@ public:
void handleMotionNotifyEvent (const XPointerMovedEvent& movedEvent)
{
updateKeyModifiers (movedEvent.state);
updateKeyModifiers ((int) movedEvent.state);
lastMousePos = Point<int> (movedEvent.x_root, movedEvent.y_root);
@@ -1603,7 +1604,7 @@ public:
if (! currentModifiers.isAnyMouseButtonDown())
{
updateKeyModifiers (enterEvent.state);
updateKeyModifiers ((int) enterEvent.state);
handleMouseEvent (0, getMousePos (enterEvent), currentModifiers, getEventTime (enterEvent));
}
}
@@ -1616,7 +1617,7 @@ public:
if (((! currentModifiers.isAnyMouseButtonDown()) && leaveEvent.mode == NotifyNormal)
|| leaveEvent.mode == NotifyUngrab)
{
updateKeyModifiers (leaveEvent.state);
updateKeyModifiers ((int) leaveEvent.state);
handleMouseEvent (0, getMousePos (leaveEvent), currentModifiers, getEventTime (leaveEvent));
}
}
@@ -1751,7 +1752,7 @@ public:
&& XGetWindowAttributes (display, clientMsg.window, &atts))
{
if (atts.map_state == IsViewable)
XSetInputFocus (display, clientMsg.window, RevertToParent, clientMsg.data.l[1]);
XSetInputFocus (display, clientMsg.window, RevertToParent, (::Time) clientMsg.data.l[1]);
}
}
}
@@ -1910,7 +1911,7 @@ private:
#endif
(totalArea.getWidth() + 31) & ~31,
(totalArea.getHeight() + 31) & ~31,
false, peer.depth, peer.visual));
false, (unsigned int) peer.depth, peer.visual));
}
startTimer (repaintTimerPeriod);
@@ -1938,7 +1939,9 @@ private:
xbitmap->blitToWindow (peer.windowH,
i->getX(), i->getY(), i->getWidth(), i->getHeight(),
i->getX(), i->getY(),
(unsigned int) i->getWidth(),
(unsigned int) i->getHeight(),
i->getX() - totalArea.getX(), i->getY() - totalArea.getY());
}
}
@@ -2286,7 +2289,7 @@ private:
const Atoms& atoms = Atoms::get();
// Associate the PID, allowing to be shut down when something goes wrong
unsigned long pid = getpid();
unsigned long pid = (unsigned long) getpid();
xchangeProperty (windowH, atoms.pid, XA_CARDINAL, 32, &pid, 1);
// Set window manager protocols
@@ -2337,7 +2340,7 @@ private:
static int64 getEventTime (::Time t)
{
static int64 eventTimeOffset = 0x12345678;
const int64 thisMessageTime = t;
const int64 thisMessageTime = (int64) t;
if (eventTimeOffset == 0x12345678)
eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
@@ -2392,7 +2395,7 @@ private:
if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
wx = wy = 0;
bounds.setBounds (wx, wy, ww, wh);
bounds.setBounds (wx, wy, (int) ww, (int) wh);
}
}
@@ -2452,7 +2455,7 @@ private:
msg.display = display;
msg.window = dragAndDropSourceWindow;
msg.format = 32;
msg.data.l[0] = windowH;
msg.data.l[0] = (long) windowH;
ScopedXLock xlock;
XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
@@ -2464,7 +2467,7 @@ private:
msg.display = display;
msg.window = targetWindow;
msg.format = 32;
msg.data.l[0] = windowH;
msg.data.l[0] = (long) windowH;
ScopedXLock xlock;
return XSendEvent (display, targetWindow, False, 0, (XEvent*) &msg) != 0;
@@ -2492,9 +2495,9 @@ private:
const int numMimeTypes = dragState.getNumMimeTypes();
msg.data.l[1] = (dragState.xdndVersion << 24) | (numMimeTypes > 3);
msg.data.l[2] = numMimeTypes > 0 ? mimeTypes[0] : 0;
msg.data.l[3] = numMimeTypes > 1 ? mimeTypes[1] : 0;
msg.data.l[4] = numMimeTypes > 2 ? mimeTypes[2] : 0;
msg.data.l[2] = numMimeTypes > 0 ? (long) mimeTypes[0] : 0;
msg.data.l[3] = numMimeTypes > 1 ? (long) mimeTypes[1] : 0;
msg.data.l[4] = numMimeTypes > 2 ? (long) mimeTypes[2] : 0;
sendExternalDragAndDropMessage (msg, targetWindow);
}
@@ -2514,7 +2517,7 @@ private:
msg.data.l[1] = 0;
msg.data.l[2] = (mousePos.x << 16) | mousePos.y;
msg.data.l[3] = CurrentTime;
msg.data.l[4] = Atoms::get().XdndActionCopy; // this is all JUCE currently supports
msg.data.l[4] = (long) Atoms::get().XdndActionCopy; // this is all JUCE currently supports
dragState.expectingStatus = sendExternalDragAndDropMessage (msg, targetWindow);
}
@@ -2526,7 +2529,7 @@ private:
msg.message_type = Atoms::get().XdndStatus;
msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
msg.data.l[4] = dropAction;
msg.data.l[4] = (long) dropAction;
sendDragAndDropMessage (msg);
}
@@ -2575,7 +2578,7 @@ private:
evt.xselectionrequest.property,
targetType, 8,
dragState.textOrFiles.toRawUTF8(),
dragState.textOrFiles.getNumBytesAsUTF8());
(int) dragState.textOrFiles.getNumBytesAsUTF8());
}
XSendEvent (display, evt.xselectionrequest.requestor, True, 0, &s);
@@ -2594,10 +2597,10 @@ private:
|| (Atom) clientMsg.data.l[4] == Atoms::get().XdndActionPrivate))
{
if ((clientMsg.data.l[1] & 2) == 0) // target requests silent rectangle
dragState.silentRect.setBounds (clientMsg.data.l[2] >> 16,
clientMsg.data.l[2] & 0xffff,
clientMsg.data.l[3] >> 16,
clientMsg.data.l[3] & 0xffff);
dragState.silentRect.setBounds ((int) clientMsg.data.l[2] >> 16,
(int) clientMsg.data.l[2] & 0xffff,
(int) clientMsg.data.l[3] >> 16,
(int) clientMsg.data.l[3] & 0xffff);
dragState.canDrop = true;
}
@@ -2664,7 +2667,7 @@ private:
if (dragAndDropSourceWindow == 0)
return;
dragAndDropSourceWindow = clientMsg.data.l[0];
dragAndDropSourceWindow = (::Window) clientMsg.data.l[0];
Point<int> dropPos ((int) clientMsg.data.l[2] >> 16,
(int) clientMsg.data.l[2] & 0xffff);
@@ -2735,7 +2738,7 @@ private:
return;
}
dragAndDropSourceWindow = clientMsg.data.l[0];
dragAndDropSourceWindow = (::Window) clientMsg.data.l[0];
if ((clientMsg.data.l[1] & 1) != 0)
{
@@ -2759,7 +2762,7 @@ private:
{
for (int i = 2; i < 5; ++i)
if (clientMsg.data.l[i] != None)
srcMimeTypeAtomList.add (clientMsg.data.l[i]);
srcMimeTypeAtomList.add ((unsigned long) clientMsg.data.l[i]);
if (srcMimeTypeAtomList.size() == 0)
{
@@ -2796,7 +2799,7 @@ private:
if (! prop.success)
break;
dropData.append (prop.data, prop.numItems * prop.actualFormat / 8);
dropData.append (prop.data, prop.numItems * (size_t) prop.actualFormat / 8);
if (prop.bytesLeft <= 0)
break;
@@ -2836,7 +2839,7 @@ private:
dragAndDropCurrentMimeType,
Atoms::getCreating ("JXSelectionWindowProperty"),
windowH,
clientMsg.data.l[2]);
(::Time) clientMsg.data.l[2]);
}
}
@@ -3112,8 +3115,8 @@ void Desktop::Displays::findDisplays (float masterScale)
const long* const position = (const long*) prop.data;
Display d;
d.userArea = d.totalArea = Rectangle<int> (position[0], position[1],
position[2], position[3]) / masterScale;
d.userArea = d.totalArea = Rectangle<int> ((int) position[0], (int) position[1],
(int) position[2], (int) position[3]) / masterScale;
d.isMain = (displays.size() == 0);
d.scale = masterScale;
d.dpi = getDisplayDPI (i);
@@ -3272,8 +3275,8 @@ void* CustomMouseCursorInfo::create() const
return nullptr;
ScopedXLock xlock;
const unsigned int imageW = image.getWidth();
const unsigned int imageH = image.getHeight();
const unsigned int imageW = (unsigned int) image.getWidth();
const unsigned int imageH = (unsigned int) image.getHeight();
int hotspotX = hotspot.x;
int hotspotY = hotspot.y;
@@ -3310,10 +3313,10 @@ void* CustomMouseCursorInfo::create() const
if (xcursorSupportsARGB != nullptr)
{
if (XcursorImage* xcImage = xcursorImageCreate (imageW, imageH))
if (XcursorImage* xcImage = xcursorImageCreate ((int) imageW, (int) imageH))
{
xcImage->xhot = hotspotX;
xcImage->yhot = hotspotY;
xcImage->xhot = (XcursorDim) hotspotX;
xcImage->yhot = (XcursorDim) hotspotY;
XcursorPixel* dest = xcImage->pixels;
for (int y = 0; y < (int) imageH; ++y)
@@ -3335,17 +3338,17 @@ void* CustomMouseCursorInfo::create() const
if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
return nullptr;
Image im (Image::ARGB, cursorW, cursorH, true);
Image im (Image::ARGB, (int) cursorW, (int) cursorH, true);
{
Graphics g (im);
if (imageW > cursorW || imageH > cursorH)
{
hotspotX = (hotspotX * cursorW) / imageW;
hotspotY = (hotspotY * cursorH) / imageH;
hotspotX = (hotspotX * (int) cursorW) / (int) imageW;
hotspotY = (hotspotY * (int) cursorH) / (int) imageH;
g.drawImageWithin (image, 0, 0, imageW, imageH,
g.drawImageWithin (image, 0, 0, (int) imageW, (int) imageH,
RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
false);
}
@@ -3355,19 +3358,19 @@ void* CustomMouseCursorInfo::create() const
}
}
const int stride = (cursorW + 7) >> 3;
const unsigned int stride = (cursorW + 7) >> 3;
HeapBlock<char> maskPlane, sourcePlane;
maskPlane.calloc (stride * cursorH);
sourcePlane.calloc (stride * cursorH);
const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
for (int y = cursorH; --y >= 0;)
for (int y = (int) cursorH; --y >= 0;)
{
for (int x = cursorW; --x >= 0;)
for (int x = (int) cursorW; --x >= 0;)
{
const char mask = (char) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
const int offset = y * stride + (x >> 3);
const unsigned int offset = (unsigned int) y * stride + ((unsigned int) x >> 3);
const Colour c (im.getPixelAt (x, y));
@@ -3383,7 +3386,8 @@ void* CustomMouseCursorInfo::create() const
black.red = black.green = black.blue = 0;
white.red = white.green = white.blue = 0xffff;
void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black,
(unsigned int) hotspotX, (unsigned int) hotspotY);
XFreePixmap (display, sourcePixmap);
XFreePixmap (display, maskPixmap);
@@ -3594,7 +3598,7 @@ const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| Keys::ex
const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| Keys::extendedKeyModifier;
const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| Keys::extendedKeyModifier;
const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| Keys::extendedKeyModifier;
const int KeyPress::playKey = (0xffeeff00) | Keys::extendedKeyModifier;
const int KeyPress::stopKey = (0xffeeff01) | Keys::extendedKeyModifier;
const int KeyPress::fastForwardKey = (0xffeeff02) | Keys::extendedKeyModifier;
const int KeyPress::rewindKey = (0xffeeff03) | Keys::extendedKeyModifier;
const int KeyPress::playKey = ((int) 0xffeeff00) | Keys::extendedKeyModifier;
const int KeyPress::stopKey = ((int) 0xffeeff01) | Keys::extendedKeyModifier;
const int KeyPress::fastForwardKey = ((int) 0xffeeff02) | Keys::extendedKeyModifier;
const int KeyPress::rewindKey = ((int) 0xffeeff03) | Keys::extendedKeyModifier;

+ 1
- 1
modules/juce_gui_extra/native/juce_linux_SystemTrayIcon.cpp View File

@@ -57,7 +57,7 @@ public:
ev.xclient.format = 32;
ev.xclient.data.l[0] = CurrentTime;
ev.xclient.data.l[1] = 0 /*SYSTEM_TRAY_REQUEST_DOCK*/;
ev.xclient.data.l[2] = windowH;
ev.xclient.data.l[2] = (long) windowH;
ev.xclient.data.l[3] = 0;
ev.xclient.data.l[4] = 0;


+ 196
- 195
modules/juce_opengl/native/juce_OpenGL_linux.h View File

@@ -1,195 +1,196 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2013 - Raw Material Software Ltd.
Permission is granted to use this software under the terms of either:
a) the GPL v2 (or any later version)
b) the Affero GPL v3
Details of these licenses can be found at: www.gnu.org/licenses
JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
------------------------------------------------------------------------------
To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.juce.com for more information.
==============================================================================
*/
extern Display* display;
extern XContext windowHandleXContext;
//==============================================================================
class OpenGLContext::NativeContext
{
public:
NativeContext (Component& component,
const OpenGLPixelFormat& pixelFormat,
void* shareContext,
bool /*useMultisampling*/,
OpenGLVersion)
: renderContext (0), embeddedWindow (0), swapFrames (0), bestVisual (0),
contextToShareWith (shareContext)
{
ScopedXLock xlock;
XSync (display, False);
GLint attribs[] =
{
GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_RED_SIZE, pixelFormat.redBits,
GLX_GREEN_SIZE, pixelFormat.greenBits,
GLX_BLUE_SIZE, pixelFormat.blueBits,
GLX_ALPHA_SIZE, pixelFormat.alphaBits,
GLX_DEPTH_SIZE, pixelFormat.depthBufferBits,
GLX_STENCIL_SIZE, pixelFormat.stencilBufferBits,
GLX_ACCUM_RED_SIZE, pixelFormat.accumulationBufferRedBits,
GLX_ACCUM_GREEN_SIZE, pixelFormat.accumulationBufferGreenBits,
GLX_ACCUM_BLUE_SIZE, pixelFormat.accumulationBufferBlueBits,
GLX_ACCUM_ALPHA_SIZE, pixelFormat.accumulationBufferAlphaBits,
None
};
bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
if (bestVisual == nullptr)
return;
ComponentPeer* const peer = component.getPeer();
Window windowH = (Window) peer->getNativeHandle();
Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
XSetWindowAttributes swa;
swa.colormap = colourMap;
swa.border_pixel = 0;
swa.event_mask = ExposureMask | StructureNotifyMask;
const Rectangle<int> bounds (component.getTopLevelComponent()
->getLocalArea (&component, component.getLocalBounds()));
embeddedWindow = XCreateWindow (display, windowH,
bounds.getX(), bounds.getY(),
jmax (1, bounds.getWidth()),
jmax (1, bounds.getHeight()),
0, bestVisual->depth,
InputOutput,
bestVisual->visual,
CWBorderPixel | CWColormap | CWEventMask,
&swa);
XSaveContext (display, (XID) embeddedWindow, windowHandleXContext, (XPointer) peer);
XMapWindow (display, embeddedWindow);
XFreeColormap (display, colourMap);
XSync (display, False);
}
~NativeContext()
{
if (embeddedWindow != 0)
{
ScopedXLock xlock;
XUnmapWindow (display, embeddedWindow);
XDestroyWindow (display, embeddedWindow);
}
if (bestVisual != nullptr)
XFree (bestVisual);
}
void initialiseOnRenderThread (OpenGLContext& context)
{
ScopedXLock xlock;
renderContext = glXCreateContext (display, bestVisual, (GLXContext) contextToShareWith, GL_TRUE);
context.makeActive();
}
void shutdownOnRenderThread()
{
deactivateCurrentContext();
glXDestroyContext (display, renderContext);
renderContext = nullptr;
}
bool makeActive() const noexcept
{
return renderContext != 0
&& glXMakeCurrent (display, embeddedWindow, renderContext);
}
bool isActive() const noexcept
{
return glXGetCurrentContext() == renderContext && renderContext != 0;
}
static void deactivateCurrentContext()
{
glXMakeCurrent (display, None, 0);
}
void swapBuffers()
{
glXSwapBuffers (display, embeddedWindow);
}
void updateWindowPosition (const Rectangle<int>& newBounds)
{
bounds = newBounds;
ScopedXLock xlock;
XMoveResizeWindow (display, embeddedWindow,
bounds.getX(), bounds.getY(),
jmax (1, bounds.getWidth()),
jmax (1, bounds.getHeight()));
}
bool setSwapInterval (int numFramesPerSwap)
{
if (numFramesPerSwap == swapFrames)
return true;
PFNGLXSWAPINTERVALSGIPROC GLXSwapIntervalSGI
= (PFNGLXSWAPINTERVALSGIPROC) OpenGLHelpers::getExtensionFunction ("glXSwapIntervalSGI");
if (GLXSwapIntervalSGI != nullptr)
{
swapFrames = numFramesPerSwap;
GLXSwapIntervalSGI (numFramesPerSwap);
return true;
}
return false;
}
int getSwapInterval() const { return swapFrames; }
bool createdOk() const noexcept { return true; }
void* getRawContext() const noexcept { return renderContext; }
GLuint getFrameBufferID() const noexcept { return 0; }
struct Locker { Locker (NativeContext&) {} };
private:
GLXContext renderContext;
Window embeddedWindow;
int swapFrames;
Rectangle<int> bounds;
XVisualInfo* bestVisual;
void* contextToShareWith;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext)
};
//==============================================================================
bool OpenGLHelpers::isContextActive()
{
ScopedXLock xlock;
return glXGetCurrentContext() != 0;
}
/*

==============================================================================

This file is part of the JUCE library.
Copyright (c) 2013 - Raw Material Software Ltd.

Permission is granted to use this software under the terms of either:
a) the GPL v2 (or any later version)
b) the Affero GPL v3

Details of these licenses can be found at: www.gnu.org/licenses

JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.

------------------------------------------------------------------------------

To release a closed-source product which uses JUCE, commercial licenses are
available: visit www.juce.com for more information.

==============================================================================
*/

extern Display* display;
extern XContext windowHandleXContext;

//==============================================================================
class OpenGLContext::NativeContext
{
public:
NativeContext (Component& component,
const OpenGLPixelFormat& cPixelFormat,
void* shareContext,
bool /*useMultisampling*/,
OpenGLVersion)
: renderContext (0), embeddedWindow (0), swapFrames (0), bestVisual (0),
contextToShareWith (shareContext)
{
ScopedXLock xlock;
XSync (display, False);

GLint attribs[] =
{
GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_RED_SIZE, cPixelFormat.redBits,
GLX_GREEN_SIZE, cPixelFormat.greenBits,
GLX_BLUE_SIZE, cPixelFormat.blueBits,
GLX_ALPHA_SIZE, cPixelFormat.alphaBits,
GLX_DEPTH_SIZE, cPixelFormat.depthBufferBits,
GLX_STENCIL_SIZE, cPixelFormat.stencilBufferBits,
GLX_ACCUM_RED_SIZE, cPixelFormat.accumulationBufferRedBits,
GLX_ACCUM_GREEN_SIZE, cPixelFormat.accumulationBufferGreenBits,
GLX_ACCUM_BLUE_SIZE, cPixelFormat.accumulationBufferBlueBits,
GLX_ACCUM_ALPHA_SIZE, cPixelFormat.accumulationBufferAlphaBits,
None
};

bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
if (bestVisual == nullptr)
return;

ComponentPeer* const peer = component.getPeer();
Window windowH = (Window) peer->getNativeHandle();

Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
XSetWindowAttributes swa;
swa.colormap = colourMap;
swa.border_pixel = 0;
swa.event_mask = ExposureMask | StructureNotifyMask;

Rectangle<int> glBounds (component.getTopLevelComponent()
->getLocalArea (&component, component.getLocalBounds()));

embeddedWindow = XCreateWindow (display, windowH,
glBounds.getX(), glBounds.getY(),
(unsigned int) jmax (1, glBounds.getWidth()),
(unsigned int) jmax (1, glBounds.getHeight()),
0, bestVisual->depth,
InputOutput,
bestVisual->visual,
CWBorderPixel | CWColormap | CWEventMask,
&swa);

XSaveContext (display, (XID) embeddedWindow, windowHandleXContext, (XPointer) peer);

XMapWindow (display, embeddedWindow);
XFreeColormap (display, colourMap);

XSync (display, False);
}

~NativeContext()
{
if (embeddedWindow != 0)
{
ScopedXLock xlock;
XUnmapWindow (display, embeddedWindow);
XDestroyWindow (display, embeddedWindow);
}

if (bestVisual != nullptr)
XFree (bestVisual);
}

void initialiseOnRenderThread (OpenGLContext& context)
{
ScopedXLock xlock;
renderContext = glXCreateContext (display, bestVisual, (GLXContext) contextToShareWith, GL_TRUE);
context.makeActive();
}

void shutdownOnRenderThread()
{
deactivateCurrentContext();
glXDestroyContext (display, renderContext);
renderContext = nullptr;
}

bool makeActive() const noexcept
{
return renderContext != 0
&& glXMakeCurrent (display, embeddedWindow, renderContext);
}

bool isActive() const noexcept
{
return glXGetCurrentContext() == renderContext && renderContext != 0;
}

static void deactivateCurrentContext()
{
glXMakeCurrent (display, None, 0);
}

void swapBuffers()
{
glXSwapBuffers (display, embeddedWindow);
}

void updateWindowPosition (const Rectangle<int>& newBounds)
{
bounds = newBounds;

ScopedXLock xlock;
XMoveResizeWindow (display, embeddedWindow,
bounds.getX(), bounds.getY(),
(unsigned int) jmax (1, bounds.getWidth()),
(unsigned int) jmax (1, bounds.getHeight()));
}

bool setSwapInterval (int numFramesPerSwap)
{
if (numFramesPerSwap == swapFrames)
return true;

PFNGLXSWAPINTERVALSGIPROC GLXSwapIntervalSGI
= (PFNGLXSWAPINTERVALSGIPROC) OpenGLHelpers::getExtensionFunction ("glXSwapIntervalSGI");

if (GLXSwapIntervalSGI != nullptr)
{
swapFrames = numFramesPerSwap;
GLXSwapIntervalSGI (numFramesPerSwap);
return true;
}

return false;
}

int getSwapInterval() const { return swapFrames; }
bool createdOk() const noexcept { return true; }
void* getRawContext() const noexcept { return renderContext; }
GLuint getFrameBufferID() const noexcept { return 0; }

struct Locker { Locker (NativeContext&) {} };

private:
GLXContext renderContext;
Window embeddedWindow;

int swapFrames;
Rectangle<int> bounds;
XVisualInfo* bestVisual;
void* contextToShareWith;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeContext)
};

//==============================================================================
bool OpenGLHelpers::isContextActive()
{
ScopedXLock xlock;
return glXGetCurrentContext() != 0;
}

Loading…
Cancel
Save