OLD | NEW |
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_Base.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 bool getROPixels(SkBitmap*) const override; | 72 bool getROPixels(SkBitmap*) const override; |
73 GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override; | 73 GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override; |
74 SkImage* onNewSubset(const SkIRect&) const override; | 74 SkImage* onNewSubset(const SkIRect&) const override; |
75 | 75 |
76 // exposed for SkSurface_Raster via SkNewImageFromPixelRef | 76 // exposed for SkSurface_Raster via SkNewImageFromPixelRef |
77 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig
in, size_t rowBytes, | 77 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig
in, size_t rowBytes, |
78 const SkSurfaceProps*); | 78 const SkSurfaceProps*); |
79 | 79 |
80 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } | 80 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } |
81 | 81 |
82 SkShader* onNewShader(SkShader::TileMode, | |
83 SkShader::TileMode, | |
84 const SkMatrix* localMatrix) const override; | |
85 | |
86 bool isOpaque() const override; | 82 bool isOpaque() const override; |
87 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; | 83 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; |
88 | 84 |
89 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props) | 85 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props) |
90 : INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props) | 86 : INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props) |
91 , fBitmap(bm) | 87 , fBitmap(bm) |
92 { | 88 { |
93 if (bm.pixelRef()->isPreLocked()) { | 89 if (bm.pixelRef()->isPreLocked()) { |
94 // we only preemptively lock if there is no chance of triggering som
ething expensive | 90 // 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. | 91 // like a lazy decode or imagegenerator. PreLocked means it is flat
pixels already. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 : INHERITED(info.width(), info.height(), pr->getGenerationID(), props) | 132 : INHERITED(info.width(), info.height(), pr->getGenerationID(), props) |
137 { | 133 { |
138 fBitmap.setInfo(info, rowBytes); | 134 fBitmap.setInfo(info, rowBytes); |
139 fBitmap.setPixelRef(pr, pixelRefOrigin); | 135 fBitmap.setPixelRef(pr, pixelRefOrigin); |
140 fBitmap.lockPixels(); | 136 fBitmap.lockPixels(); |
141 SkASSERT(fBitmap.isImmutable()); | 137 SkASSERT(fBitmap.isImmutable()); |
142 } | 138 } |
143 | 139 |
144 SkImage_Raster::~SkImage_Raster() {} | 140 SkImage_Raster::~SkImage_Raster() {} |
145 | 141 |
146 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo
de tileY, | |
147 const SkMatrix* localMatrix) const { | |
148 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix); | |
149 } | |
150 | |
151 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
ize_t dstRowBytes, | 142 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s
ize_t dstRowBytes, |
152 int srcX, int srcY) const { | 143 int srcX, int srcY) const { |
153 SkBitmap shallowCopy(fBitmap); | 144 SkBitmap shallowCopy(fBitmap); |
154 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY); | 145 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY); |
155 } | 146 } |
156 | 147 |
157 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP
tr) const { | 148 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP
tr) const { |
158 const SkImageInfo info = fBitmap.info(); | 149 const SkImageInfo info = fBitmap.info(); |
159 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { | 150 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { |
160 return nullptr; | 151 return nullptr; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 // pixelref since the caller might call setImmutable() themselves | 311 // pixelref since the caller might call setImmutable() themselves |
321 // (thus changing our state). | 312 // (thus changing our state). |
322 if (fBitmap.isImmutable()) { | 313 if (fBitmap.isImmutable()) { |
323 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); | 314 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); |
324 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); | 315 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); |
325 return true; | 316 return true; |
326 } | 317 } |
327 } | 318 } |
328 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); | 319 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); |
329 } | 320 } |
OLD | NEW |