2015-05-26 19:32:23 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTextBlob.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTypeface.h"
|
2020-07-01 16:55:01 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-05-26 19:32:23 +00:00
|
|
|
// This tests that we correctly regenerate textblobs after freeing all gpu resources crbug/491350
|
|
|
|
namespace skiagm {
|
2021-06-03 14:14:16 +00:00
|
|
|
class TextBlobUseAfterGpuFree : public GM {
|
2015-05-26 19:32:23 +00:00
|
|
|
public:
|
|
|
|
TextBlobUseAfterGpuFree() { }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString onShortName() override {
|
|
|
|
return SkString("textblobuseaftergpufree");
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(kWidth, kHeight);
|
|
|
|
}
|
|
|
|
|
2021-06-03 14:14:16 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
|
|
|
auto dContext = GrAsDirectContext(canvas->recordingContext());
|
|
|
|
|
2015-05-26 19:32:23 +00:00
|
|
|
const char text[] = "Hamburgefons";
|
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 20);
|
2018-12-23 03:29:45 +00:00
|
|
|
auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
|
2015-05-26 19:32:23 +00:00
|
|
|
|
|
|
|
// draw textblob
|
|
|
|
SkRect rect = SkRect::MakeLTRB(0.f, 0.f, SkIntToScalar(kWidth), kHeight / 2.f);
|
|
|
|
SkPaint rectPaint;
|
|
|
|
rectPaint.setColor(0xffffffff);
|
|
|
|
canvas->drawRect(rect, rectPaint);
|
2018-12-23 03:29:45 +00:00
|
|
|
canvas->drawTextBlob(blob, 20, 60, SkPaint());
|
2015-05-26 19:32:23 +00:00
|
|
|
|
|
|
|
// This text should look fine
|
2021-06-03 14:14:16 +00:00
|
|
|
if (dContext) {
|
|
|
|
dContext->freeGpuResources();
|
2020-06-29 19:36:12 +00:00
|
|
|
}
|
2018-12-23 03:29:45 +00:00
|
|
|
canvas->drawTextBlob(blob, 20, 160, SkPaint());
|
2015-05-26 19:32:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-10-08 22:48:26 +00:00
|
|
|
inline static constexpr int kWidth = 200;
|
|
|
|
inline static constexpr int kHeight = 200;
|
2015-05-26 19:32:23 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2015-05-26 19:32:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new TextBlobUseAfterGpuFree;)
|
2020-08-06 18:11:56 +00:00
|
|
|
} // namespace skiagm
|