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

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

Issue 1342113002: add ImageShader, sharing code with its Bitmap cousin (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 5 years, 3 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
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('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_Base.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 SkData* onRefEncoded() const override; 73 SkData* onRefEncoded() const override;
74 bool getROPixels(SkBitmap*) const override; 74 bool getROPixels(SkBitmap*) const override;
75 GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override; 75 GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override;
76 76
77 // exposed for SkSurface_Raster via SkNewImageFromPixelRef 77 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
78 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig in, size_t rowBytes, 78 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig in, size_t rowBytes,
79 const SkSurfaceProps*); 79 const SkSurfaceProps*);
80 80
81 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 81 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
82 82
83 SkShader* onNewShader(SkShader::TileMode,
84 SkShader::TileMode,
85 const SkMatrix* localMatrix) const override;
86
87 bool isOpaque() const override; 83 bool isOpaque() const override;
88 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; 84 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
89 85
90 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props) 86 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props)
91 : INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props) 87 : INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props)
92 , fBitmap(bm) 88 , fBitmap(bm)
93 { 89 {
94 if (bm.pixelRef()->isPreLocked()) { 90 if (bm.pixelRef()->isPreLocked()) {
95 // we only preemptively lock if there is no chance of triggering som ething expensive 91 // we only preemptively lock if there is no chance of triggering som ething expensive
96 // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already. 92 // 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
137 : INHERITED(info.width(), info.height(), pr->getGenerationID(), props) 133 : INHERITED(info.width(), info.height(), pr->getGenerationID(), props)
138 { 134 {
139 fBitmap.setInfo(info, rowBytes); 135 fBitmap.setInfo(info, rowBytes);
140 fBitmap.setPixelRef(pr, pixelRefOrigin); 136 fBitmap.setPixelRef(pr, pixelRefOrigin);
141 fBitmap.lockPixels(); 137 fBitmap.lockPixels();
142 SkASSERT(fBitmap.isImmutable()); 138 SkASSERT(fBitmap.isImmutable());
143 } 139 }
144 140
145 SkImage_Raster::~SkImage_Raster() {} 141 SkImage_Raster::~SkImage_Raster() {}
146 142
147 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo de tileY,
148 const SkMatrix* localMatrix) const {
149 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix);
150 }
151
152 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface Props& props) const { 143 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface Props& props) const {
153 return SkSurface::NewRaster(info, &props); 144 return SkSurface::NewRaster(info, &props);
154 } 145 }
155 146
156 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes, 147 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes,
157 int srcX, int srcY) const { 148 int srcX, int srcY) const {
158 SkBitmap shallowCopy(fBitmap); 149 SkBitmap shallowCopy(fBitmap);
159 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY); 150 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
160 } 151 }
161 152
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 // pixelref since the caller might call setImmutable() themselves 296 // pixelref since the caller might call setImmutable() themselves
306 // (thus changing our state). 297 // (thus changing our state).
307 if (fBitmap.isImmutable()) { 298 if (fBitmap.isImmutable()) {
308 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); 299 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
309 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); 300 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin());
310 return true; 301 return true;
311 } 302 }
312 } 303 }
313 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); 304 return this->INHERITED::onAsLegacyBitmap(bitmap, mode);
314 } 305 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698