llimagedecodethread.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * @file llimagedecodethread.h
  3. * @brief Image decode thread class declaration.
  4. *
  5. * $LicenseInfo:firstyear=2000&license=viewergpl$
  6. *
  7. * Copyright (c) 2000-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLIMAGEDECODETHREAD_H
  33. #define LL_LLIMAGEDECODETHREAD_H
  34. #include <memory>
  35. #include "llimage.h"
  36. #include "llpointer.h"
  37. #include "llrefcount.h"
  38. #include "llthreadpool.h"
  39. class LLImageDecodeThread
  40. {
  41. protected:
  42. LOG_CLASS(LLImageDecodeThread);
  43. public:
  44. class Responder : public LLThreadSafeRefCount
  45. {
  46. protected:
  47. LOG_CLASS(LLImageDecodeThread::Responder);
  48. ~Responder() override = default;
  49. public:
  50. virtual void completed(bool success, LLImageRaw* raw,
  51. LLImageRaw* aux) = 0;
  52. };
  53. // 'pool_size' is the number of LLThreads that will be launched. When
  54. // omitted or equal to 0, this number is determined automatically
  55. // depending on the available threading concurrency.
  56. LLImageDecodeThread(U32 pool_size = 0);
  57. void shutdown();
  58. size_t getPending();
  59. bool decodeImage(const LLPointer<LLImageFormatted>& image, S32 discard,
  60. bool needs_aux, const LLPointer<Responder>& responder);
  61. private:
  62. class ImageRequest
  63. {
  64. protected:
  65. LOG_CLASS(LLImageDecodeThread::ImageRequest);
  66. public:
  67. ImageRequest(const LLPointer<LLImageFormatted>& image,
  68. S32 discard, bool needs_aux,
  69. const LLPointer<Responder>& responder);
  70. ~ImageRequest();
  71. bool processRequest();
  72. void finishRequest(bool completed);
  73. private:
  74. // Input
  75. LLPointer<LLImageFormatted> mFormattedImage;
  76. LLPointer<LLImageRaw> mDecodedImageRaw;
  77. LLPointer<LLImageRaw> mDecodedImageAux;
  78. LLPointer<LLImageDecodeThread::Responder> mResponder;
  79. S32 mDiscardLevel;
  80. bool mNeedsAux;
  81. // Output
  82. bool mDecodedRaw;
  83. bool mDecodedAux;
  84. };
  85. private:
  86. std::unique_ptr<LLThreadPool> mThreadPoolp;
  87. };
  88. // Global, initialized in llappviewer.cpp and used in newview/. Moved here so
  89. // that LLImageDecodeThread consumers do not need to include llappviewer.h to
  90. // use it. HB
  91. extern LLImageDecodeThread* gImageDecodeThreadp;
  92. #endif