50class VDevBuffer :
public Timer
65 std::vector<Entry> maFreeBuffers;
68 std::vector<Entry> maUsedBuffers;
79 virtual ~VDevBuffer()
override;
85 virtual void Invoke()
override;
88VDevBuffer::VDevBuffer()
89 :
Timer(
"drawinglayer::VDevBuffer via Invoke()")
91 SetTimeout(10L * 1000L);
94VDevBuffer::~VDevBuffer()
99 while (!maFreeBuffers.empty())
101 maFreeBuffers.back().buf.disposeAndClear();
102 maFreeBuffers.pop_back();
105 while (!maUsedBuffers.empty())
107 maUsedBuffers.back().buf.disposeAndClear();
108 maUsedBuffers.pop_back();
114 if (device->GetOutputWidthPixel() >= rSizePixel.
getWidth()
115 && device->GetOutputHeightPixel() >= rSizePixel.
getHeight())
117 bool requireSmall =
false;
121 if (device->GetRenderBackendName() ==
"svp")
130 && (device->GetOutputWidthPixel() > 32 || device->GetOutputHeightPixel() > 32))
148 if (!maFreeBuffers.empty())
150 auto aFound(maFreeBuffers.end());
152 for (
auto a = maFreeBuffers.begin(); a != maFreeBuffers.end(); ++a)
154 assert(
a->buf &&
"Empty pointer in VDevBuffer (!)");
156 if (nBits ==
a->buf->GetBitCount())
159 if (aFound != maFreeBuffers.end())
165 const bool bCandidateOkay = isSizeSuitable(
a->buf, rSizePixel);
170 const sal_uLong aSquare(aFound->buf->GetOutputWidthPixel()
171 * aFound->buf->GetOutputHeightPixel());
172 const sal_uLong aCandidateSquare(
a->buf->GetOutputWidthPixel()
173 *
a->buf->GetOutputHeightPixel());
175 if (aCandidateSquare < aSquare)
190 bOkay = isSizeSuitable(aFound->buf, rSizePixel);
197 bOkay = isSizeSuitable(aFound->buf, rSizePixel);
202 if (aFound != maFreeBuffers.end())
204 pRetval = aFound->buf;
205 maFreeBuffers.erase(aFound);
215 if (maDeviceTemplates[pRetval]->isDisposed())
217 maDeviceTemplates.erase(pRetval);
224 pRetval->Erase(pRetval->PixelToLogic(
229 pRetval->SetOutputSizePixel(rSizePixel,
true);
238 maDeviceTemplates[pRetval] = &rOutDev;
239 pRetval->SetOutputSizePixel(rSizePixel,
true);
244 pRetval->SetMapMode();
245 pRetval->SetRasterOp(RasterOp::OverPaint);
249 maUsedBuffers.emplace_back(pRetval);
257 const auto aUsedFound
258 = std::find_if(maUsedBuffers.begin(), maUsedBuffers.end(),
259 [&rDevice](
const Entry& el) { return el.buf == &rDevice; });
260 SAL_WARN_IF(aUsedFound == maUsedBuffers.end(),
"drawinglayer",
261 "OOps, non-registered buffer freed (!)");
262 if (aUsedFound != maUsedBuffers.end())
264 maFreeBuffers.emplace_back(*aUsedFound);
265 maUsedBuffers.erase(aUsedFound);
266 SAL_WARN_IF(maFreeBuffers.size() > 1000,
"drawinglayer",
267 "excessive cached buffers, " << maFreeBuffers.size() <<
" entries!");
272void VDevBuffer::Invoke()
276 while (!maFreeBuffers.empty())
278 auto aLastOne = maFreeBuffers.back();
279 maDeviceTemplates.erase(aLastOne.buf);
280 aLastOne.buf.disposeAndClear();
281 maFreeBuffers.pop_back();
289 const int nAvInd(500);
290 static double fFactors[nAvInd];
291 static int nIndex(nAvInd + 1);
292 static int nRepeat(5);
293 static int nWorseTotal(0);
294 static int nBetterTotal(0);
302 for (a = 0;
a < nAvInd;
a++)
312 for (a = 0;
a < nRepeat;
a++)
316 const AlphaMask aAlphaMask(aSizePixel, &nMaskValue);
324 for (a = 0;
a < nRepeat;
a++)
328 aSizePixel.Width(), aSizePixel.Height(),
337 const sal_uInt64 nTimeFormer(nTimeB - nTimeA);
338 const sal_uInt64 nTimeNew(nTimeC - nTimeB);
341 if (nTimeFormer != nTimeNew && 0 != nTimeFormer && 0 != nTimeNew)
343 if ((nTimeFormer < 10 || nTimeNew < 10) && nRepeat < 500)
346 SAL_INFO(
"drawinglayer.processor2d",
"Increment nRepeat to " << nRepeat);
350 const double fNewFactor((
double)nTimeFormer / nTimeNew);
351 fFactors[
nIndex % nAvInd] = fNewFactor;
353 double fAverage(0.0);
355 for (a = 0;
a < nAvInd;
a++)
356 fAverage += fFactors[a];
359 if (fNewFactor < 1.0)
366 "Former: %ld New: %ld It got %s (factor %f) (av. last %d Former/New is %f, "
367 "WorseTotal: %d, BetterTotal: %d)",
368 nTimeFormer, nTimeNew, fNewFactor < 1.0 ?
"WORSE" :
"BETTER",
369 fNewFactor < 1.0 ? 1.0 / fNewFactor : fNewFactor, nAvInd, fAverage, nWorseTotal,
371 SAL_INFO(
"drawinglayer.processor2d", buf);
387 return *aVDevBuffer.
get();
409 "impBufferDevice render helper: Copying from Window to VDev, this should be avoided (!)");
451 const Point aEmptyPoint;
460 static bool bDoSaveForVisualControl(
false);
461 static const OUString sDumpPath(OUString::createFromAscii(std::getenv(
"VCL_DUMP_BMP_PATH")));
463 if (!sDumpPath.isEmpty() && bDoSaveForVisualControl)
465 SvFileStream aNew(sDumpPath +
"content.bmp", StreamMode::WRITE | StreamMode::TRUNC);
467 WriteDIB(aContent, aNew,
false,
true);
482 if (!sDumpPath.isEmpty() && bDoSaveForVisualControl)
485 StreamMode::WRITE | StreamMode::TRUNC);
493 else if (0.0 != fTrans)
498 static bool bCompareFormerAndNewTimings(
true);
500 if (bCompareFormerAndNewTimings)
540 static bool bUseNew(
false);
555 const AlphaMask aAlphaMask(aSizePixel, &nMaskValue);
572 "impBufferDevice: No content, check isVisible() before accessing (!)");
579 "impBufferDevice: No content, check isVisible() before accessing (!)");
Bitmap const & GetBitmap() const
void SetOrigin(const Point &rOrigin)
void EnableMapMode(bool bEnable=true)
basegfx::B2DHomMatrix GetViewTransformation() const
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
void DrawTransformedBitmapEx(const basegfx::B2DHomMatrix &rTransformation, const BitmapEx &rBitmapEx, double fAlpha=1.0)
RasterOp GetRasterOp() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
Size GetOutputSizePixel() const
virtual sal_uInt16 GetBitCount() const
void SetRasterOp(RasterOp eRasterOp)
SAL_DLLPRIVATE void DrawOutDev(const Point &, const Size &, const Point &, const Size &, const Printer &)=delete
const MapMode & GetMapMode() const
AntialiasingFlags GetAntialiasing() const
OutDevType GetOutDevType() const
bool IsMapModeEnabled() const
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long getHeight() const
constexpr tools::Long Height() const
constexpr tools::Long getWidth() const
constexpr tools::Long Width() const
virtual void Invoke() override
static VclPtr< reference_type > Create(Arg &&... arg)
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
void paint(double fTrans=0.0)
VirtualDevice & getTransparence()
tools::Rectangle maDestPixel
VirtualDevice & getContent()
VclPtr< VirtualDevice > mpAlpha
impBufferDevice(OutputDevice &rOutDev, const basegfx::B2DRange &rRange)
VclPtr< VirtualDevice > mpContent
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
VCL_DLLPUBLIC bool isVCLSkiaEnabled()
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
B2IRange fround(const B2DRange &rRange)
VDevBuffer & getVDevBuffer()
int sprintf(char(&s)[N], char const *format, T &&... arguments)