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

Unified Diff: src/image/SkImage_Raster.h

Issue 2205273003: Add onDrawBitmapLattice(), avoid unnecessary bitmap->image copy (Closed) Base URL: https://skia.googlesource.com/skia.git@copypaste
Patch Set: 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: src/image/SkImage_Raster.h
diff --git a/src/image/SkImage_Raster.h b/src/image/SkImage_Raster.h
new file mode 100644
index 0000000000000000000000000000000000000000..74981d31914838a6e2bbe1aa564668fe133cd258
--- /dev/null
+++ b/src/image/SkImage_Raster.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkImage_Base.h"
+#include "SkPixelRef.h"
+
+// fixes https://bug.skia.org/5096
+static bool is_not_subset(const SkBitmap& bm) {
+ SkASSERT(bm.pixelRef());
+ SkISize dim = bm.pixelRef()->info().dimensions();
+ SkASSERT(dim != bm.dimensions() || bm.pixelRefOrigin().isZero());
+ return dim == bm.dimensions();
+}
+
+class SkImage_Raster : public SkImage_Base {
+public:
+ static bool ValidArgs(const Info& info, size_t rowBytes, bool hasColorTable,
+ size_t* minSize) {
+ const int maxDimension = SK_MaxS32 >> 2;
+
+ if (info.width() <= 0 || info.height() <= 0) {
+ return false;
+ }
+ if (info.width() > maxDimension || info.height() > maxDimension) {
+ return false;
+ }
+ if ((unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType) {
+ return false;
+ }
+ if ((unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType) {
+ return false;
+ }
+
+ if (kUnknown_SkColorType == info.colorType()) {
+ return false;
+ }
+
+ const bool needsCT = kIndex_8_SkColorType == info.colorType();
+ if (needsCT != hasColorTable) {
+ return false;
+ }
+
+ if (rowBytes < info.minRowBytes()) {
+ return false;
+ }
+
+ size_t size = info.getSafeSize(rowBytes);
+ if (0 == size) {
+ return false;
+ }
+
+ if (minSize) {
+ *minSize = size;
+ }
+ return true;
+ }
+
+ SkImage_Raster(const SkImageInfo&, sk_sp<SkData>, size_t rb, SkColorTable*);
+ virtual ~SkImage_Raster();
+
+ SkImageInfo onImageInfo() const override {
+ return fBitmap.info();
+ }
+
+ bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override;
+ bool onPeekPixels(SkPixmap*) const override;
+ const SkBitmap* onPeekBitmap() const override { return &fBitmap; }
+
+ SkData* onRefEncoded(GrContext*) const override;
+ bool getROPixels(SkBitmap*, CachingHint) const override;
+ GrTexture* asTextureRef(GrContext*, const GrTextureParams&,
+ SkSourceGammaTreatment) const override;
+ sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
+
+ // exposed for SkSurface_Raster via SkNewImageFromPixelRef
+ SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size_t rowBytes);
+
+ SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
+
+ bool isOpaque() const override;
+ bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
+
+ SkImage_Raster(const SkBitmap& bm, bool bitmapMayBeMutable = false)
+ : INHERITED(bm.width(), bm.height(),
+ is_not_subset(bm) ? bm.getGenerationID()
+ : (uint32_t)kNeedNewImageUniqueID)
+ , fBitmap(bm)
+ {
+ if (bm.pixelRef()->isPreLocked()) {
+ // we only preemptively lock if there is no chance of triggering something expensive
+ // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already.
+ fBitmap.lockPixels();
+ }
+ SkASSERT(bitmapMayBeMutable || fBitmap.isImmutable());
+ }
+
+ bool onIsLazyGenerated() const override {
+ return fBitmap.pixelRef() && fBitmap.pixelRef()->isLazyGenerated();
+ }
+
+private:
+ SkBitmap fBitmap;
+
+ typedef SkImage_Base INHERITED;
+};

Powered by Google App Engine
This is Rietveld 408576698