Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: experimental/svg/model/SkSVGRenderContext.h

Issue 2222793002: [SVGDom] Add <svg> viewBox support (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: SkSVGRenderContext initialization cleanup Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: experimental/svg/model/SkSVGRenderContext.h
diff --git a/experimental/svg/model/SkSVGRenderContext.h b/experimental/svg/model/SkSVGRenderContext.h
index 50a6d59e5e84ee109cbadc1e42d7fe294582f86f..61c43a644106d6a7bdb7d37e5a47c9e0e1c6279c 100644
--- a/experimental/svg/model/SkSVGRenderContext.h
+++ b/experimental/svg/model/SkSVGRenderContext.h
@@ -8,11 +8,13 @@
#ifndef SkSVGRenderContext_DEFINED
#define SkSVGRenderContext_DEFINED
-#include "SkSize.h"
#include "SkPaint.h"
+#include "SkRect.h"
+#include "SkSize.h"
#include "SkTLazy.h"
+#include "SkTypes.h"
-class SkPaint;
+class SkCanvas;
class SkSVGLength;
class SkSVGLengthContext {
@@ -25,21 +27,22 @@ public:
kOther,
};
+ const SkSize& viewPort() const { return fViewport; }
void setViewPort(const SkSize& viewport) { fViewport = viewport; }
SkScalar resolve(const SkSVGLength&, LengthType) const;
+ SkRect resolveRect(const SkSVGLength& x, const SkSVGLength& y,
+ const SkSVGLength& w, const SkSVGLength& h) const;
private:
SkSize fViewport;
};
-class SkSVGRenderContext {
+class SkSVGPresentationContext {
public:
- explicit SkSVGRenderContext(const SkSize& initialViewport);
- SkSVGRenderContext(const SkSVGRenderContext&) = default;
- SkSVGRenderContext& operator=(const SkSVGRenderContext&);
-
- const SkSVGLengthContext& lengthContext() const { return fLengthContext; }
+ SkSVGPresentationContext();
+ SkSVGPresentationContext(const SkSVGPresentationContext&);
+ SkSVGPresentationContext& operator=(const SkSVGPresentationContext&);
const SkPaint* fillPaint() const { return fFill.getMaybeNull(); }
const SkPaint* strokePaint() const { return fStroke.getMaybeNull(); }
@@ -48,12 +51,42 @@ public:
void setStrokeColor(SkColor);
private:
+ void initFrom(const SkSVGPresentationContext&);
+
SkPaint& ensureFill();
SkPaint& ensureStroke();
- SkSVGLengthContext fLengthContext;
- SkTLazy<SkPaint> fFill;
- SkTLazy<SkPaint> fStroke;
+ // TODO: convert to regular SkPaints and track explicit attribute values instead.
+ SkTLazy<SkPaint> fFill;
+ SkTLazy<SkPaint> fStroke;
+};
+
+class SkSVGRenderContext {
+public:
+ SkSVGRenderContext(SkCanvas*, const SkSVGLengthContext&, const SkSVGPresentationContext&);
+ SkSVGRenderContext(const SkSVGRenderContext&);
+ ~SkSVGRenderContext();
+
+ const SkSVGLengthContext& lengthContext() const { return *fLengthContext; }
+ SkSVGLengthContext* writableLengthContext() { return fLengthContext.writable(); }
+
+ const SkSVGPresentationContext& presentationContext() const { return *fPresentationContext; }
+ SkSVGPresentationContext* writablePresentationContext() {
+ return fPresentationContext.writable();
+ }
+
+ SkCanvas* canvas() const { return fCanvas; }
+
+private:
+ // Stack-only
+ void* operator new(size_t) = delete;
+ void* operator new(size_t, void*) = delete;
+ SkSVGRenderContext& operator=(const SkSVGRenderContext&) = delete;
+
+ SkTCopyOnFirstWrite<SkSVGLengthContext> fLengthContext;
+ SkTCopyOnFirstWrite<SkSVGPresentationContext> fPresentationContext;
+ SkCanvas* fCanvas;
robertphillips 2016/08/08 13:55:28 // This is the save count on 'fCanvas' at construc
f(malita) 2016/08/08 17:13:29 Done.
+ int fCanvasSaveCount;
};
#endif // SkSVGRenderContext_DEFINED

Powered by Google App Engine
This is Rietveld 408576698