aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/fonts/SkRandomScalerContext.cpp
diff options
context:
space:
mode:
authorGravatar bungeman <bungeman@google.com>2016-10-20 16:06:52 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-10-20 22:00:28 +0000
commit7cfd46aebda7b7d2b88e73621ed0d1be7244c2ca (patch)
treeace6ecfe18447644e928f6ef204ab39f2767f24f /src/fonts/SkRandomScalerContext.cpp
parent050ffa9ad5d2bafc935c0a48ce3caed47446be12 (diff)
SkScalerContext to use smart pointers.
CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-ASAN-Trybot;master.client.skia:Test-Ubuntu-Clang-GCE-CPU-AVX2-x86_64-Debug-MSAN-Trybot Change-Id: I27a714388b8ded7dfc968e322b0a587205f575f1 Reviewed-on: https://skia-review.googlesource.com/3731 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/fonts/SkRandomScalerContext.cpp')
-rw-r--r--src/fonts/SkRandomScalerContext.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/fonts/SkRandomScalerContext.cpp b/src/fonts/SkRandomScalerContext.cpp
index c9cb87c03c..96a2619876 100644
--- a/src/fonts/SkRandomScalerContext.cpp
+++ b/src/fonts/SkRandomScalerContext.cpp
@@ -5,17 +5,19 @@
* found in the LICENSE file.
*/
-#include "SkRandomScalerContext.h"
+#include "SkCanvas.h"
#include "SkGlyph.h"
+#include "SkMakeUnique.h"
#include "SkPath.h"
-#include "SkCanvas.h"
+#include "SkRandomScalerContext.h"
#include "SkRasterizer.h"
+class SkDescriptor;
+
class SkRandomScalerContext : public SkScalerContext {
public:
- SkRandomScalerContext(SkRandomTypeface*, const SkScalerContextEffects&,
+ SkRandomScalerContext(sk_sp<SkRandomTypeface>, const SkScalerContextEffects&,
const SkDescriptor*, bool fFakeIt);
- virtual ~SkRandomScalerContext();
protected:
unsigned generateGlyphCount() override;
@@ -27,27 +29,22 @@ protected:
void generateFontMetrics(SkPaint::FontMetrics*) override;
private:
- SkRandomTypeface* fFace;
- SkScalerContext* fProxy;
+ SkRandomTypeface* getRandomTypeface() const {
+ return static_cast<SkRandomTypeface*>(this->getTypeface());
+ }
+ std::unique_ptr<SkScalerContext> fProxy;
bool fFakeIt;
};
-#define STD_SIZE 1
-
-#include "SkDescriptor.h"
-
-SkRandomScalerContext::SkRandomScalerContext(SkRandomTypeface* face,
+SkRandomScalerContext::SkRandomScalerContext(sk_sp<SkRandomTypeface> face,
const SkScalerContextEffects& effects,
const SkDescriptor* desc,
bool fakeIt)
- : SkScalerContext(face, effects, desc)
- , fFace(face)
+ : SkScalerContext(std::move(face), effects, desc)
, fFakeIt(fakeIt) {
- fProxy = face->proxy()->createScalerContext(effects, desc);
+ fProxy = this->getRandomTypeface()->proxy()->createScalerContext(effects, desc);
}
-SkRandomScalerContext::~SkRandomScalerContext() { delete fProxy; }
-
unsigned SkRandomScalerContext::generateGlyphCount() {
return fProxy->getGlyphCount();
}
@@ -90,7 +87,7 @@ void SkRandomScalerContext::generateMetrics(SkGlyph* glyph) {
fProxy->getPath(*glyph, &path);
SkRect storage;
- const SkPaint& paint = fFace->paint();
+ const SkPaint& paint = this->getRandomTypeface()->paint();
const SkRect& newBounds = paint.doComputeFastBounds(path.getBounds(),
&storage,
SkPaint::kFill_Style);
@@ -167,7 +164,7 @@ void SkRandomScalerContext::generateImage(const SkGlyph& glyph) {
SkCanvas canvas(bm);
canvas.translate(-SkIntToScalar(glyph.fLeft),
-SkIntToScalar(glyph.fTop));
- canvas.drawPath(path, fFace->paint());
+ canvas.drawPath(path, this->getRandomTypeface()->paint());
} else {
fProxy->forceGenerateImageFromPath();
fProxy->getImage(glyph);
@@ -198,7 +195,8 @@ SkRandomTypeface::SkRandomTypeface(sk_sp<SkTypeface> proxy, const SkPaint& paint
SkScalerContext* SkRandomTypeface::onCreateScalerContext(const SkScalerContextEffects& effects,
const SkDescriptor* desc) const {
- return new SkRandomScalerContext(const_cast<SkRandomTypeface*>(this), effects, desc, fFakeIt);
+ return new SkRandomScalerContext(sk_ref_sp(const_cast<SkRandomTypeface*>(this)),
+ effects, desc, fFakeIt);
}
void SkRandomTypeface::onFilterRec(SkScalerContextRec* rec) const {