store info in basedevice, change getter to non-virtual const&

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2261003003

Review-Url: https://codereview.chromium.org/2261003003
diff --git a/src/core/SkBitmapDevice.cpp b/src/core/SkBitmapDevice.cpp
index 41416e7..75eaa96 100644
--- a/src/core/SkBitmapDevice.cpp
+++ b/src/core/SkBitmapDevice.cpp
@@ -69,7 +69,7 @@
 }
 
 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap)
-    : INHERITED(SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType))
+    : INHERITED(bitmap.info(), SkSurfaceProps(SkSurfaceProps::kLegacyFontHost_InitType))
     , fBitmap(bitmap)
 {
     SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr));
@@ -81,7 +81,7 @@
 }
 
 SkBitmapDevice::SkBitmapDevice(const SkBitmap& bitmap, const SkSurfaceProps& surfaceProps)
-    : INHERITED(surfaceProps)
+    : INHERITED(bitmap.info(), surfaceProps)
     , fBitmap(bitmap)
 {
     SkASSERT(valid_for_bitmap_device(bitmap.info(), nullptr));
@@ -120,13 +120,10 @@
     return new SkBitmapDevice(bitmap, surfaceProps);
 }
 
-SkImageInfo SkBitmapDevice::imageInfo() const {
-    return fBitmap.info();
-}
-
 void SkBitmapDevice::setNewSize(const SkISize& size) {
     SkASSERT(!fBitmap.pixelRef());
     fBitmap.setInfo(fBitmap.info().makeWH(size.fWidth, size.fHeight));
+    this->privateResize(fBitmap.info().width(), fBitmap.info().height());
 }
 
 void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) {
@@ -134,6 +131,7 @@
     SkASSERT(bm.height() == fBitmap.height());
     fBitmap = bm;   // intent is to use bm's pixelRef (and rowbytes/config)
     fBitmap.lockPixels();
+    this->privateResize(fBitmap.info().width(), fBitmap.info().height());
 }
 
 SkBaseDevice* SkBitmapDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) {
diff --git a/src/core/SkDevice.cpp b/src/core/SkDevice.cpp
index 5eaf44d..4534c2f 100644
--- a/src/core/SkDevice.cpp
+++ b/src/core/SkDevice.cpp
@@ -24,7 +24,10 @@
 #include "SkTextBlobRunIterator.h"
 #include "SkTextToPathIter.h"
 
-SkBaseDevice::SkBaseDevice(const SkSurfaceProps& surfaceProps) : fSurfaceProps(surfaceProps) {
+SkBaseDevice::SkBaseDevice(const SkImageInfo& info, const SkSurfaceProps& surfaceProps)
+    : fInfo(info)
+    , fSurfaceProps(surfaceProps)
+{
     fOrigin.setZero();
     fMetaData = nullptr;
 }
@@ -40,10 +43,6 @@
     return *fMetaData;
 }
 
-SkImageInfo SkBaseDevice::imageInfo() const {
-    return SkImageInfo::MakeUnknown();
-}
-
 #ifdef SK_SUPPORT_LEGACY_ACCESSBITMAP
 const SkBitmap& SkBaseDevice::accessBitmap(bool changePixels) {
     const SkBitmap& bitmap = this->onAccessBitmap();
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 040833b..258355e 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -122,10 +122,22 @@
                                               info.width(), info.height(), flags));
 }
 
-SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height, unsigned flags) 
-    : INHERITED(drawContext->surfaceProps())
+static SkImageInfo make_info(GrDrawContext* context, int w, int h, bool opaque) {
+    SkColorType colorType;
+    if (!GrPixelConfigToColorType(context->config(), &colorType)) {
+        colorType = kUnknown_SkColorType;
+    }
+    return SkImageInfo::Make(w, h, colorType,
+                             opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType,
+                             sk_ref_sp(context->getColorSpace()));
+}
+
+SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height, unsigned flags)
+    : INHERITED(make_info(drawContext.get(), width, height, SkToBool(flags & kIsOpaque_Flag)),
+                drawContext->surfaceProps())
     , fContext(SkRef(drawContext->accessRenderTarget()->getContext()))
-    , fDrawContext(std::move(drawContext)) {
+    , fDrawContext(std::move(drawContext))
+{
     fSize.set(width, height);
     fOpaque = SkToBool(flags & kIsOpaque_Flag);
 
diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h
index d5fe04f..4de0a50 100644
--- a/src/gpu/SkGpuDevice.h
+++ b/src/gpu/SkGpuDevice.h
@@ -66,16 +66,6 @@
 
     GrDrawContext* accessDrawContext() override;
 
-    SkImageInfo imageInfo() const override {
-        SkColorType colorType;
-        if (!GrPixelConfigToColorType(fDrawContext->config(), &colorType)) {
-            colorType = kUnknown_SkColorType;
-        }
-        return SkImageInfo::Make(fSize.fWidth, fSize.fHeight, colorType,
-                                 fOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType,
-                                 sk_ref_sp(fDrawContext->getColorSpace()));
-    }
-
     void drawPaint(const SkDraw&, const SkPaint& paint) override;
     virtual void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
                             const SkPoint[], const SkPaint& paint) override;
diff --git a/src/pdf/SkPDFDevice.cpp b/src/pdf/SkPDFDevice.cpp
index edf1728..73d41b1 100644
--- a/src/pdf/SkPDFDevice.cpp
+++ b/src/pdf/SkPDFDevice.cpp
@@ -559,7 +559,8 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 SkPDFDevice::SkPDFDevice(SkISize pageSize, SkScalar rasterDpi, SkPDFDocument* doc, bool flip)
-    : INHERITED(SkSurfaceProps(0, kUnknown_SkPixelGeometry))
+    : INHERITED(SkImageInfo::MakeUnknown(pageSize.width(), pageSize.height()),
+                SkSurfaceProps(0, kUnknown_SkPixelGeometry))
     , fPageSize(pageSize)
     , fContentSize(pageSize)
     , fExistingClipRegion(SkIRect::MakeSize(pageSize))
@@ -1294,11 +1295,6 @@
                                 &content.entry()->fContent);
 }
 
-SkImageInfo SkPDFDevice::imageInfo() const {
-    SkImageInfo info = SkImageInfo::MakeUnknown(fPageSize.width(), fPageSize.height());
-    return info;
-}
-
 sk_sp<SkSurface> SkPDFDevice::makeSurface(const SkImageInfo& info, const SkSurfaceProps& props) {
     return SkSurface::MakeRaster(info, &props);
 }
diff --git a/src/pdf/SkPDFDevice.h b/src/pdf/SkPDFDevice.h
index 4a86028..6588efb 100644
--- a/src/pdf/SkPDFDevice.h
+++ b/src/pdf/SkPDFDevice.h
@@ -119,8 +119,6 @@
     void drawDevice(const SkDraw&, SkBaseDevice*, int x, int y,
                     const SkPaint&) override;
 
-    SkImageInfo imageInfo() const override;
-
     // PDF specific methods.
 
     /** Create the resource dictionary for this device. */
diff --git a/src/svg/SkSVGDevice.cpp b/src/svg/SkSVGDevice.cpp
index 4330901..3ba721e 100644
--- a/src/svg/SkSVGDevice.cpp
+++ b/src/svg/SkSVGDevice.cpp
@@ -570,10 +570,11 @@
 }
 
 SkSVGDevice::SkSVGDevice(const SkISize& size, SkXMLWriter* writer)
-    : INHERITED(SkSurfaceProps(0, kUnknown_SkPixelGeometry))
+    : INHERITED(SkImageInfo::MakeUnknown(size.fWidth, size.fHeight),
+                SkSurfaceProps(0, kUnknown_SkPixelGeometry))
     , fWriter(writer)
     , fResourceBucket(new ResourceBucket)
-    , fSize(size) {
+{
     SkASSERT(writer);
 
     fWriter->writeHeader();
@@ -590,11 +591,6 @@
 SkSVGDevice::~SkSVGDevice() {
 }
 
-SkImageInfo SkSVGDevice::imageInfo() const {
-    SkImageInfo info = SkImageInfo::MakeUnknown(fSize.fWidth, fSize.fHeight);
-    return info;
-}
-
 void SkSVGDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
     AutoElement rect("rect", fWriter, fResourceBucket, draw, paint);
     rect.addRectAttributes(SkRect::MakeWH(SkIntToScalar(this->width()),
diff --git a/src/svg/SkSVGDevice.h b/src/svg/SkSVGDevice.h
index bf86e15..cb13ffd 100644
--- a/src/svg/SkSVGDevice.h
+++ b/src/svg/SkSVGDevice.h
@@ -17,8 +17,6 @@
 public:
     static SkBaseDevice* Create(const SkISize& size, SkXMLWriter* writer);
 
-    SkImageInfo imageInfo() const override;
-
 protected:
     void drawPaint(const SkDraw&, const SkPaint& paint) override;
     void drawPoints(const SkDraw&, SkCanvas::PointMode mode, size_t count,
@@ -68,7 +66,6 @@
     SkXMLWriter*                  fWriter;
     SkAutoTDelete<AutoElement>    fRootElement;
     SkAutoTDelete<ResourceBucket> fResourceBucket;
-    SkISize                       fSize;
 
     typedef SkBaseDevice INHERITED;
 };