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

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

Issue 1789443002: Revert "Revert of add Make variations to return SkImage by sk_sp (patchset #5 id:80001 of https://c… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: use get, not release, when calling legacy function that wants ptr Created 4 years, 9 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/core/SkShader.cpp ('k') | src/image/SkImagePriv.h » ('j') | 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBitmapCache.h" 9 #include "SkBitmapCache.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkData.h" 11 #include "SkData.h"
12 #include "SkImageEncoder.h" 12 #include "SkImageEncoder.h"
13 #include "SkImageGenerator.h" 13 #include "SkImageGenerator.h"
14 #include "SkImagePriv.h" 14 #include "SkImagePriv.h"
15 #include "SkImageShader.h" 15 #include "SkImageShader.h"
16 #include "SkImage_Base.h" 16 #include "SkImage_Base.h"
17 #include "SkNextID.h" 17 #include "SkNextID.h"
18 #include "SkPicture.h"
18 #include "SkPixelRef.h" 19 #include "SkPixelRef.h"
19 #include "SkPixelSerializer.h" 20 #include "SkPixelSerializer.h"
20 #include "SkReadPixelsRec.h" 21 #include "SkReadPixelsRec.h"
21 #include "SkString.h" 22 #include "SkString.h"
22 #include "SkSurface.h" 23 #include "SkSurface.h"
23 24
24 #if SK_SUPPORT_GPU 25 #if SK_SUPPORT_GPU
25 #include "GrTexture.h" 26 #include "GrTexture.h"
26 #include "GrContext.h" 27 #include "GrContext.h"
27 #include "SkImage_Gpu.h" 28 #include "SkImage_Gpu.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 } 144 }
144 145
145 return nullptr; 146 return nullptr;
146 } 147 }
147 148
148 SkData* SkImage::refEncoded() const { 149 SkData* SkImage::refEncoded() const {
149 GrContext* ctx = nullptr; // should we allow the caller to pass in a ctx? 150 GrContext* ctx = nullptr; // should we allow the caller to pass in a ctx?
150 return as_IB(this)->onRefEncoded(ctx); 151 return as_IB(this)->onRefEncoded(ctx);
151 } 152 }
152 153
153 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { 154 sk_sp<SkImage> SkImage::MakeFromEncoded(sk_sp<SkData> encoded, const SkIRect* su bset) {
154 if (nullptr == encoded || 0 == encoded->size()) { 155 if (nullptr == encoded || 0 == encoded->size()) {
155 return nullptr; 156 return nullptr;
156 } 157 }
157 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded); 158 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded.get() );
158 return generator ? SkImage::NewFromGenerator(generator, subset) : nullptr; 159 return SkImage::MakeFromGenerator(generator, subset);
159 } 160 }
160 161
161 const char* SkImage::toString(SkString* str) const { 162 const char* SkImage::toString(SkString* str) const {
162 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(), 163 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
163 this->isOpaque() ? "opaque" : ""); 164 this->isOpaque() ? "opaque" : "");
164 return str->c_str(); 165 return str->c_str();
165 } 166 }
166 167
167 SkImage* SkImage::newSubset(const SkIRect& subset) const { 168 sk_sp<SkImage> SkImage::makeSubset(const SkIRect& subset) const {
168 if (subset.isEmpty()) { 169 if (subset.isEmpty()) {
169 return nullptr; 170 return nullptr;
170 } 171 }
171 172
172 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height()); 173 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
173 if (!bounds.contains(subset)) { 174 if (!bounds.contains(subset)) {
174 return nullptr; 175 return nullptr;
175 } 176 }
176 177
177 // optimization : return self if the subset == our bounds 178 // optimization : return self if the subset == our bounds
178 if (bounds == subset) { 179 if (bounds == subset) {
179 return SkRef(const_cast<SkImage*>(this)); 180 return sk_ref_sp(const_cast<SkImage*>(this));
180 } 181 }
181 return as_IB(this)->onNewSubset(subset); 182 return as_IB(this)->onMakeSubset(subset);
182 } 183 }
183 184
184 #if SK_SUPPORT_GPU 185 #if SK_SUPPORT_GPU
185 186
186 GrTexture* SkImage::getTexture() const { 187 GrTexture* SkImage::getTexture() const {
187 return as_IB(this)->peekTexture(); 188 return as_IB(this)->peekTexture();
188 } 189 }
189 190
190 bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekTexture ()); } 191 bool SkImage::isTextureBacked() const { return SkToBool(as_IB(this)->peekTexture ()); }
191 192
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 if (GrTextureToYUVPlanes(texture, sizes, planes, rowBytes, colorSpace)) { 277 if (GrTextureToYUVPlanes(texture, sizes, planes, rowBytes, colorSpace)) {
277 return true; 278 return true;
278 } 279 }
279 } 280 }
280 #endif 281 #endif
281 return SkRGBAToYUV(this, sizes, planes, rowBytes, colorSpace); 282 return SkRGBAToYUV(this, sizes, planes, rowBytes, colorSpace);
282 } 283 }
283 284
284 //////////////////////////////////////////////////////////////////////////////// /////////////////// 285 //////////////////////////////////////////////////////////////////////////////// ///////////////////
285 286
286 SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) { 287 sk_sp<SkImage> SkImage::MakeFromBitmap(const SkBitmap& bm) {
287 SkPixelRef* pr = bm.pixelRef(); 288 SkPixelRef* pr = bm.pixelRef();
288 if (nullptr == pr) { 289 if (nullptr == pr) {
289 return nullptr; 290 return nullptr;
290 } 291 }
291 292
292 #if SK_SUPPORT_GPU 293 #if SK_SUPPORT_GPU
293 if (GrTexture* tex = pr->getTexture()) { 294 if (GrTexture* tex = pr->getTexture()) {
294 SkAutoTUnref<GrTexture> unrefCopy; 295 SkAutoTUnref<GrTexture> unrefCopy;
295 if (!bm.isImmutable()) { 296 if (!bm.isImmutable()) {
296 tex = GrDeepCopyTexture(tex, SkBudgeted::kNo); 297 tex = GrDeepCopyTexture(tex, SkBudgeted::kNo);
297 if (nullptr == tex) { 298 if (nullptr == tex) {
298 return nullptr; 299 return nullptr;
299 } 300 }
300 unrefCopy.reset(tex); 301 unrefCopy.reset(tex);
301 } 302 }
302 const SkImageInfo info = bm.info(); 303 const SkImageInfo info = bm.info();
303 return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID() , info.alphaType(), 304 return sk_make_sp<SkImage_Gpu>(info.width(), info.height(), bm.getGenera tionID(),
304 tex, SkBudgeted::kNo); 305 info.alphaType(), tex, SkBudgeted::kNo);
305 } 306 }
306 #endif 307 #endif
307 308
308 // This will check for immutable (share or copy) 309 // This will check for immutable (share or copy)
309 return SkNewImageFromRasterBitmap(bm); 310 return SkMakeImageFromRasterBitmap(bm);
310 } 311 }
311 312
312 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const { 313 bool SkImage::asLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) const {
313 return as_IB(this)->onAsLegacyBitmap(bitmap, mode); 314 return as_IB(this)->onAsLegacyBitmap(bitmap, mode);
314 } 315 }
315 316
316 bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con st { 317 bool SkImage_Base::onAsLegacyBitmap(SkBitmap* bitmap, LegacyBitmapMode mode) con st {
317 // As the base-class, all we can do is make a copy (regardless of mode). 318 // As the base-class, all we can do is make a copy (regardless of mode).
318 // Subclasses that want to be more optimal should override. 319 // Subclasses that want to be more optimal should override.
319 SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(), 320 SkImageInfo info = SkImageInfo::MakeN32(this->width(), this->height(),
320 this->isOpaque() ? kOpaque_SkAlphaType : kPr emul_SkAlphaType); 321 this->isOpaque() ? kOpaque_SkAlphaType : kPr emul_SkAlphaType);
321 if (!bitmap->tryAllocPixels(info)) { 322 if (!bitmap->tryAllocPixels(info)) {
322 return false; 323 return false;
323 } 324 }
324 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes( ), 0, 0)) { 325 if (!this->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes( ), 0, 0)) {
325 bitmap->reset(); 326 bitmap->reset();
326 return false; 327 return false;
327 } 328 }
328 329
329 if (kRO_LegacyBitmapMode == mode) { 330 if (kRO_LegacyBitmapMode == mode) {
330 bitmap->setImmutable(); 331 bitmap->setImmutable();
331 } 332 }
332 return true; 333 return true;
333 } 334 }
334 335
335 SkImage* SkImage::NewFromPicture(const SkPicture* picture, const SkISize& dimens ions, 336 sk_sp<SkImage> SkImage::MakeFromPicture(sk_sp<SkPicture> picture, const SkISize& dimensions,
336 const SkMatrix* matrix, const SkPaint* paint) { 337 const SkMatrix* matrix, const SkPaint* p aint) {
337 if (!picture) { 338 if (!picture) {
338 return nullptr; 339 return nullptr;
339 } 340 }
340 return NewFromGenerator(SkImageGenerator::NewFromPicture(dimensions, picture , matrix, paint)); 341 return MakeFromGenerator(SkImageGenerator::NewFromPicture(dimensions, pictur e.get(),
342 matrix, paint));
341 } 343 }
342 344
343 bool SkImage::isLazyGenerated() const { 345 bool SkImage::isLazyGenerated() const {
344 return as_IB(this)->onIsLazyGenerated(); 346 return as_IB(this)->onIsLazyGenerated();
345 } 347 }
346 348
347 //////////////////////////////////////////////////////////////////////////////// ////// 349 //////////////////////////////////////////////////////////////////////////////// //////
348 350
349 #if !SK_SUPPORT_GPU 351 #if !SK_SUPPORT_GPU
350 352
351 SkImage* SkImage::NewTextureFromPixmap(GrContext*, const SkPixmap&, SkBudgeted b udgeted) { 353 sk_sp<SkImage> SkImage::MakeTextureFromPixmap(GrContext*, const SkPixmap&, SkBud geted budgeted) {
352 return nullptr; 354 return nullptr;
353 } 355 }
354 356
355 SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlph aType, 357 sk_sp<SkImage> SkImage::MakeFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType,
356 TextureReleaseProc, ReleaseContext) { 358 TextureReleaseProc, ReleaseContext) {
357 return nullptr; 359 return nullptr;
358 } 360 }
359 361
360 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 362 sk_sp<SkImage> SkImage::MakeFromAdoptedTexture(GrContext*, const GrBackendTextur eDesc&,
363 SkAlphaType) {
361 return nullptr; 364 return nullptr;
362 } 365 }
363 366
364 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 367 sk_sp<SkImage> SkImage::MakeFromTextureCopy(GrContext*, const GrBackendTextureDe sc&, SkAlphaType) {
365 return nullptr; 368 return nullptr;
366 } 369 }
367 370
368 SkImage* SkImage::newTextureImage(GrContext*) const { 371 sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
372 const GrBackendObject yuvTexture Handles[3],
373 const SkISize yuvSizes[3],
374 GrSurfaceOrigin origin) {
375 return nullptr;
376 }
377
378 sk_sp<SkImage> SkImage::makeTextureImage(GrContext*) const {
369 return nullptr; 379 return nullptr;
370 } 380 }
371 381
372 #endif 382 #endif
383
384 //////////////////////////////////////////////////////////////////////////////// ///////////////////
385
386 #ifdef SK_SUPPORT_LEGACY_IMAGEFACTORY
387 SkImage* SkImage::NewRasterCopy(const Info& info, const void* pixels, size_t row Bytes,
388 SkColorTable* ctable) {
389 return MakeRasterCopy(SkPixmap(info, pixels, rowBytes, ctable)).release();
390 }
391
392 SkImage* SkImage::NewRasterData(const Info& info, SkData* pixels, size_t rowByte s) {
393 return MakeRasterData(info, sk_ref_sp(pixels), rowBytes).release();
394 }
395
396 SkImage* SkImage::NewFromRaster(const Info& info, const void* pixels, size_t row Bytes,
397 RasterReleaseProc proc, ReleaseContext releasect x) {
398 return MakeFromRaster(SkPixmap(info, pixels, rowBytes), proc, releasectx).re lease();
399 }
400
401 SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
402 return MakeFromBitmap(bm).release();
403 }
404
405 SkImage* SkImage::NewFromGenerator(SkImageGenerator* gen, const SkIRect* subset) {
406 return MakeFromGenerator(gen, subset).release();
407 }
408
409 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
410 return MakeFromEncoded(sk_ref_sp(encoded), subset).release();
411 }
412
413 SkImage* SkImage::NewFromTexture(GrContext* ctx, const GrBackendTextureDesc& des c, SkAlphaType at,
414 TextureReleaseProc proc, ReleaseContext release ctx) {
415 return MakeFromTexture(ctx, desc, at, proc, releasectx).release();
416 }
417
418 SkImage* SkImage::NewFromAdoptedTexture(GrContext* ctx, const GrBackendTextureDe sc& desc,
419 SkAlphaType at) {
420 return MakeFromAdoptedTexture(ctx, desc, at).release();
421 }
422
423 SkImage* SkImage::NewFromTextureCopy(GrContext* ctx, const GrBackendTextureDesc& desc,
424 SkAlphaType at) {
425 return MakeFromTextureCopy(ctx, desc, at).release();
426 }
427
428 SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx, SkYUVColorSpace space,
429 const GrBackendObject yuvTextureHandles [3],
430 const SkISize yuvSizes[3],
431 GrSurfaceOrigin origin) {
432 return MakeFromYUVTexturesCopy(ctx, space, yuvTextureHandles, yuvSizes, orig in).release();
433 }
434
435 SkImage* SkImage::NewFromPicture(const SkPicture* picture, const SkISize& dimens ions,
436 const SkMatrix* matrix, const SkPaint* paint) {
437 return MakeFromPicture(sk_ref_sp(const_cast<SkPicture*>(picture)), dimension s,
438 matrix, paint).release();
439 }
440
441 SkImage* SkImage::NewTextureFromPixmap(GrContext* ctx, const SkPixmap& pmap, SkB udgeted budgeted) {
442 return MakeTextureFromPixmap(ctx, pmap, budgeted).release();
443 }
444 #endif
OLDNEW
« no previous file with comments | « src/core/SkShader.cpp ('k') | src/image/SkImagePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698