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

Side by Side Diff: src/image/SkImage_Raster.cpp

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
« src/core/SkCanvas.cpp ('K') | « src/image/SkImage_Raster.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkImage_Base.h" 8 #include "SkImage_Raster.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkColorTable.h" 11 #include "SkColorTable.h"
12 #include "SkData.h" 12 #include "SkData.h"
13 #include "SkImagePriv.h" 13 #include "SkImagePriv.h"
14 #include "SkPixelRef.h" 14 #include "SkPixelRef.h"
15 #include "SkSurface.h" 15 #include "SkSurface.h"
16 16
17 #if SK_SUPPORT_GPU 17 #if SK_SUPPORT_GPU
18 #include "GrContext.h" 18 #include "GrContext.h"
19 #include "SkGr.h" 19 #include "SkGr.h"
20 #include "SkGrPriv.h" 20 #include "SkGrPriv.h"
21 #endif 21 #endif
22 22
23 // fixes https://bug.skia.org/5096
24 static bool is_not_subset(const SkBitmap& bm) {
25 SkASSERT(bm.pixelRef());
26 SkISize dim = bm.pixelRef()->info().dimensions();
27 SkASSERT(dim != bm.dimensions() || bm.pixelRefOrigin().isZero());
28 return dim == bm.dimensions();
29 }
30
31 class SkImage_Raster : public SkImage_Base {
32 public:
33 static bool ValidArgs(const Info& info, size_t rowBytes, bool hasColorTable,
34 size_t* minSize) {
35 const int maxDimension = SK_MaxS32 >> 2;
36
37 if (info.width() <= 0 || info.height() <= 0) {
38 return false;
39 }
40 if (info.width() > maxDimension || info.height() > maxDimension) {
41 return false;
42 }
43 if ((unsigned)info.colorType() > (unsigned)kLastEnum_SkColorType) {
44 return false;
45 }
46 if ((unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType) {
47 return false;
48 }
49
50 if (kUnknown_SkColorType == info.colorType()) {
51 return false;
52 }
53
54 const bool needsCT = kIndex_8_SkColorType == info.colorType();
55 if (needsCT != hasColorTable) {
56 return false;
57 }
58
59 if (rowBytes < info.minRowBytes()) {
60 return false;
61 }
62
63 size_t size = info.getSafeSize(rowBytes);
64 if (0 == size) {
65 return false;
66 }
67
68 if (minSize) {
69 *minSize = size;
70 }
71 return true;
72 }
73
74 SkImage_Raster(const SkImageInfo&, sk_sp<SkData>, size_t rb, SkColorTable*);
75 virtual ~SkImage_Raster();
76
77 SkImageInfo onImageInfo() const override {
78 return fBitmap.info();
79 }
80
81 bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, Cac hingHint) const override;
82 bool onPeekPixels(SkPixmap*) const override;
83 const SkBitmap* onPeekBitmap() const override { return &fBitmap; }
84
85 SkData* onRefEncoded(GrContext*) const override;
86 bool getROPixels(SkBitmap*, CachingHint) const override;
87 GrTexture* asTextureRef(GrContext*, const GrTextureParams&,
88 SkSourceGammaTreatment) const override;
89 sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
90
91 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
92 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& origin, size _t rowBytes);
93
94 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
95
96 bool isOpaque() const override;
97 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
98
99 SkImage_Raster(const SkBitmap& bm, bool bitmapMayBeMutable = false)
100 : INHERITED(bm.width(), bm.height(),
101 is_not_subset(bm) ? bm.getGenerationID()
102 : (uint32_t)kNeedNewImageUniqueID)
103 , fBitmap(bm)
104 {
105 if (bm.pixelRef()->isPreLocked()) {
106 // we only preemptively lock if there is no chance of triggering som ething expensive
107 // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already.
108 fBitmap.lockPixels();
109 }
110 SkASSERT(bitmapMayBeMutable || fBitmap.isImmutable());
111 }
112
113 bool onIsLazyGenerated() const override {
114 return fBitmap.pixelRef() && fBitmap.pixelRef()->isLazyGenerated();
115 }
116
117 private:
118 SkBitmap fBitmap;
119
120 typedef SkImage_Base INHERITED;
121 };
122
123 ///////////////////////////////////////////////////////////////////////////////
124
125 static void release_data(void* addr, void* context) { 23 static void release_data(void* addr, void* context) {
126 SkData* data = static_cast<SkData*>(context); 24 SkData* data = static_cast<SkData*>(context);
127 data->unref(); 25 data->unref();
128 } 26 }
129 27
130 SkImage_Raster::SkImage_Raster(const Info& info, sk_sp<SkData> data, size_t rowB ytes, 28 SkImage_Raster::SkImage_Raster(const Info& info, sk_sp<SkData> data, size_t rowB ytes,
131 SkColorTable* ctable) 29 SkColorTable* ctable)
132 : INHERITED(info.width(), info.height(), kNeedNewImageUniqueID) 30 : INHERITED(info.width(), info.height(), kNeedNewImageUniqueID)
133 { 31 {
134 void* addr = const_cast<void*>(data->data()); 32 void* addr = const_cast<void*>(data->data());
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // pixelref since the caller might call setImmutable() themselves 194 // pixelref since the caller might call setImmutable() themselves
297 // (thus changing our state). 195 // (thus changing our state).
298 if (fBitmap.isImmutable()) { 196 if (fBitmap.isImmutable()) {
299 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); 197 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
300 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); 198 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin());
301 return true; 199 return true;
302 } 200 }
303 } 201 }
304 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); 202 return this->INHERITED::onAsLegacyBitmap(bitmap, mode);
305 } 203 }
OLDNEW
« src/core/SkCanvas.cpp ('K') | « src/image/SkImage_Raster.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698