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
This commit is contained in:
parent
e2348ccb47
commit
589a39eb81
@ -58,8 +58,6 @@ public:
|
||||
|
||||
static SkBitmapDevice* Create(const SkImageInfo&, const SkSurfaceProps&);
|
||||
|
||||
SkImageInfo imageInfo() const override;
|
||||
|
||||
protected:
|
||||
bool onShouldDisableLCD(const SkPaint&) const override;
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
/**
|
||||
* Construct a new device.
|
||||
*/
|
||||
explicit SkBaseDevice(const SkSurfaceProps&);
|
||||
explicit SkBaseDevice(const SkImageInfo&, const SkSurfaceProps&);
|
||||
virtual ~SkBaseDevice();
|
||||
|
||||
SkMetaData& getMetaData();
|
||||
@ -39,7 +39,7 @@ public:
|
||||
* Return ImageInfo for this device. If the canvas is not backed by pixels
|
||||
* (cpu or gpu), then the info's ColorType will be kUnknown_SkColorType.
|
||||
*/
|
||||
virtual SkImageInfo imageInfo() const;
|
||||
const SkImageInfo& imageInfo() const { return fInfo; }
|
||||
|
||||
/**
|
||||
* Return SurfaceProps for this device.
|
||||
@ -371,9 +371,15 @@ private:
|
||||
|
||||
virtual SkImageFilterCache* getImageFilterCache() { return NULL; }
|
||||
|
||||
friend class SkBitmapDevice;
|
||||
void privateResize(int w, int h) {
|
||||
*const_cast<SkImageInfo*>(&fInfo) = fInfo.makeWH(w, h);
|
||||
}
|
||||
|
||||
SkIPoint fOrigin;
|
||||
SkMetaData* fMetaData;
|
||||
SkSurfaceProps fSurfaceProps;
|
||||
const SkImageInfo fInfo;
|
||||
const SkSurfaceProps fSurfaceProps;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_ACCESSBITMAP
|
||||
SkBitmap fLegacyBitmap;
|
||||
|
@ -69,7 +69,7 @@ static bool valid_for_bitmap_device(const SkImageInfo& info,
|
||||
}
|
||||
|
||||
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::Create(const SkImageInfo& info) {
|
||||
}
|
||||
|
||||
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 @@ SkBitmapDevice* SkBitmapDevice::Create(const SkImageInfo& origInfo,
|
||||
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 @@ void SkBitmapDevice::replaceBitmapBackendForRasterSurface(const SkBitmap& bm) {
|
||||
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*) {
|
||||
|
@ -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 @@ SkMetaData& SkBaseDevice::getMetaData() {
|
||||
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();
|
||||
|
@ -122,10 +122,22 @@ sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted,
|
||||
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);
|
||||
|
||||
|
@ -66,16 +66,6 @@ public:
|
||||
|
||||
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;
|
||||
|
@ -559,7 +559,8 @@ private:
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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 @@ void SkPDFDevice::drawDevice(const SkDraw& d, SkBaseDevice* device,
|
||||
&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);
|
||||
}
|
||||
|
@ -119,8 +119,6 @@ public:
|
||||
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. */
|
||||
|
@ -570,10 +570,11 @@ SkBaseDevice* SkSVGDevice::Create(const SkISize& size, SkXMLWriter* writer) {
|
||||
}
|
||||
|
||||
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(const SkISize& size, SkXMLWriter* writer)
|
||||
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()),
|
||||
|
@ -17,8 +17,6 @@ class SkSVGDevice : public SkBaseDevice {
|
||||
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 @@ private:
|
||||
SkXMLWriter* fWriter;
|
||||
SkAutoTDelete<AutoElement> fRootElement;
|
||||
SkAutoTDelete<ResourceBucket> fResourceBucket;
|
||||
SkISize fSize;
|
||||
|
||||
typedef SkBaseDevice INHERITED;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user