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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "SkImage_Base.h"
9 #include "SkPixelRef.h"
10
11 // fixes https://bug.skia.org/5096
12 static bool is_not_subset(const SkBitmap& bm) {
13 SkASSERT(bm.pixelRef());
14 SkISize dim = bm.pixelRef()->info().dimensions();
15 SkASSERT(dim != bm.dimensions() || bm.pixelRefOrigin().isZero());
16 return dim == bm.dimensions();
17 }
18
19 class SkImage_Raster : public SkImage_Base {
20 public:
21 static bool ValidArgs(const Info& info, size_t rowBytes, bool hasColorTable,
22 size_t* minSize) {
23 const int maxDimension = SK_MaxS32 >> 2;
24
25 if (info.width() <= 0 || info.height() <= 0) {
26 return false;
27 }
28 if (info.width() > maxDimension || info.height() > maxDimension) {
29 return false;
30 }
31 if ((unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType) {
32 return false;
33 }
34 if ((unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType) {
35 return false;
36 }
37
38 if (kUnknown_SkColorType == info.colorType()) {
39 return false;
40 }
41
42 const bool needsCT = kIndex_8_SkColorType == info.colorType();
43 if (needsCT != hasColorTable) {
44 return false;
45 }
46
47 if (rowBytes < info.minRowBytes()) {
48 return false;
49 }
50
51 size_t size = info.getSafeSize(rowBytes);
52 if (0 == size) {
53 return false;
54 }
55
56 if (minSize) {
57 *minSize = size;
58 }
59 return true;
60 }
61
62 SkImage_Raster(const SkImageInfo&, sk_sp<SkData>, size_t rb, SkColorTable*);
63 virtual ~SkImage_Raster();
64
65 SkImageInfo onImageInfo() const override {
66 return fBitmap.info();
67 }
68
69 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, Cac hingHint) const override;
70 bool onPeekPixels(SkPixmap*) const override;
71 const SkBitmap* onPeekBitmap() const override { return &fBitmap; }
72
73 SkData* onRefEncoded(GrContext*) const override;
74 bool getROPixels(SkBitmap*, CachingHint) const override;
75 GrTexture* asTextureRef(GrContext*, const GrTextureParams&,
76 SkSourceGammaTreatment) const override;
77 sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
78
79 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
80 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size _t rowBytes);
81
82 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
83
84 bool isOpaque() const override;
85 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
86
87 SkImage_Raster(const SkBitmap& bm, bool bitmapMayBeMutable = false)
88 : INHERITED(bm.width(), bm.height(),
89 is_not_subset(bm) ? bm.getGenerationID()
90 : (uint32_t)kNeedNewImageUniqueID)
91 , fBitmap(bm)
92 {
93 if (bm.pixelRef()->isPreLocked()) {
94 // we only preemptively lock if there is no chance of triggering som ething expensive
95 // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already.
96 fBitmap.lockPixels();
97 }
98 SkASSERT(bitmapMayBeMutable || fBitmap.isImmutable());
99 }
100
101 bool onIsLazyGenerated() const override {
102 return fBitmap.pixelRef() && fBitmap.pixelRef()->isLazyGenerated();
103 }
104
105 private:
106 SkBitmap fBitmap;
107
108 typedef SkImage_Base INHERITED;
109 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698