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

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: now with actual added files 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
« include/core/SkShader.h ('K') | « 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; 67 const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override;
68 SkData* onRefEncoded() const override; 68 SkData* onRefEncoded() const override;
69 bool getROPixels(SkBitmap*) const override; 69 bool getROPixels(SkBitmap*) const override;
70 70
71 // exposed for SkSurface_Raster via SkNewImageFromPixelRef 71 // exposed for SkSurface_Raster via SkNewImageFromPixelRef
72 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig in, size_t rowBytes, 72 SkImage_Raster(const SkImageInfo&, SkPixelRef*, const SkIPoint& pixelRefOrig in, size_t rowBytes,
73 const SkSurfaceProps*); 73 const SkSurfaceProps*);
74 74
75 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); } 75 SkPixelRef* getPixelRef() const { return fBitmap.pixelRef(); }
76 76
77 SkShader* onNewShader(SkShader::TileMode,
78 SkShader::TileMode,
79 const SkMatrix* localMatrix) const override;
80
81 bool isOpaque() const override; 77 bool isOpaque() const override;
82 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override; 78 bool onAsLegacyBitmap(SkBitmap*, LegacyBitmapMode) const override;
83 79
84 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props) 80 SkImage_Raster(const SkBitmap& bm, const SkSurfaceProps* props)
85 : INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props) 81 : INHERITED(bm.width(), bm.height(), bm.getGenerationID(), props)
86 , fBitmap(bm) 82 , fBitmap(bm)
87 { 83 {
88 if (bm.pixelRef()->isPreLocked()) { 84 if (bm.pixelRef()->isPreLocked()) {
89 // we only preemptively lock if there is no chance of triggering som ething expensive 85 // we only preemptively lock if there is no chance of triggering som ething expensive
90 // like a lazy decode or imagegenerator. PreLocked means it is flat pixels already. 86 // 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
131 : INHERITED(info.width(), info.height(), pr->getGenerationID(), props) 127 : INHERITED(info.width(), info.height(), pr->getGenerationID(), props)
132 { 128 {
133 fBitmap.setInfo(info, rowBytes); 129 fBitmap.setInfo(info, rowBytes);
134 fBitmap.setPixelRef(pr, pixelRefOrigin); 130 fBitmap.setPixelRef(pr, pixelRefOrigin);
135 fBitmap.lockPixels(); 131 fBitmap.lockPixels();
136 SkASSERT(fBitmap.isImmutable()); 132 SkASSERT(fBitmap.isImmutable());
137 } 133 }
138 134
139 SkImage_Raster::~SkImage_Raster() {} 135 SkImage_Raster::~SkImage_Raster() {}
140 136
141 SkShader* SkImage_Raster::onNewShader(SkShader::TileMode tileX, SkShader::TileMo de tileY,
142 const SkMatrix* localMatrix) const {
143 return SkShader::CreateBitmapShader(fBitmap, tileX, tileY, localMatrix);
144 }
145
146 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface Props& props) const { 137 SkSurface* SkImage_Raster::onNewSurface(const SkImageInfo& info, const SkSurface Props& props) const {
147 return SkSurface::NewRaster(info, &props); 138 return SkSurface::NewRaster(info, &props);
148 } 139 }
149 140
150 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes, 141 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes,
151 int srcX, int srcY) const { 142 int srcX, int srcY) const {
152 SkBitmap shallowCopy(fBitmap); 143 SkBitmap shallowCopy(fBitmap);
153 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY); 144 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
154 } 145 }
155 146
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 // pixelref since the caller might call setImmutable() themselves 264 // pixelref since the caller might call setImmutable() themselves
274 // (thus changing our state). 265 // (thus changing our state).
275 if (fBitmap.isImmutable()) { 266 if (fBitmap.isImmutable()) {
276 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); 267 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
277 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); 268 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin());
278 return true; 269 return true;
279 } 270 }
280 } 271 }
281 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); 272 return this->INHERITED::onAsLegacyBitmap(bitmap, mode);
282 } 273 }
OLDNEW
« include/core/SkShader.h ('K') | « src/image/SkImage_Gpu.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698