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

Side by Side Diff: src/lazy/SkDiscardablePixelRef.cpp

Issue 830033003: change API contract: disallow zero-sized images or surfaces (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 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/SkSurface_Raster.cpp ('k') | tests/SurfaceTest.cpp » ('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 2013 Google Inc. 2 * Copyright 2013 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 "SkDiscardablePixelRef.h" 8 #include "SkDiscardablePixelRef.h"
9 #include "SkDiscardableMemory.h" 9 #include "SkDiscardableMemory.h"
10 #include "SkImageGenerator.h" 10 #include "SkImageGenerator.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void SkDiscardablePixelRef::onUnlockPixels() { 91 void SkDiscardablePixelRef::onUnlockPixels() {
92 fDiscardableMemory->unlock(); 92 fDiscardableMemory->unlock();
93 } 93 }
94 94
95 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst, 95 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst,
96 SkDiscardableMemory::Factory* factory) { 96 SkDiscardableMemory::Factory* factory) {
97 SkImageInfo info; 97 SkImageInfo info;
98 SkAutoTDelete<SkImageGenerator> autoGenerator(generator); 98 SkAutoTDelete<SkImageGenerator> autoGenerator(generator);
99 if ((NULL == autoGenerator.get()) 99 if ((NULL == autoGenerator.get())
100 || (!autoGenerator->getInfo(&info)) 100 || (!autoGenerator->getInfo(&info))
101 || info.isEmpty()
101 || (!dst->setInfo(info))) { 102 || (!dst->setInfo(info))) {
102 return false; 103 return false;
103 } 104 }
104 // Since dst->setInfo() may have changed/fixed-up info, we copy it back from that bitmap 105 // Since dst->setInfo() may have changed/fixed-up info, we copy it back from that bitmap
105 info = dst->info(); 106 info = dst->info();
106 107
107 SkASSERT(info.colorType() != kUnknown_SkColorType); 108 SkASSERT(info.colorType() != kUnknown_SkColorType);
108 if (dst->empty()) { // Use a normal pixelref. 109 if (dst->empty()) { // Use a normal pixelref.
109 return dst->tryAllocPixels(); 110 return dst->tryAllocPixels();
110 } 111 }
111 SkAutoTUnref<SkDiscardablePixelRef> ref( 112 SkAutoTUnref<SkDiscardablePixelRef> ref(
112 SkNEW_ARGS(SkDiscardablePixelRef, 113 SkNEW_ARGS(SkDiscardablePixelRef,
113 (info, autoGenerator.detach(), dst->rowBytes(), factory))); 114 (info, autoGenerator.detach(), dst->rowBytes(), factory)));
114 dst->setPixelRef(ref); 115 dst->setPixelRef(ref);
115 return true; 116 return true;
116 } 117 }
117 118
118 // This is the public API 119 // This is the public API
119 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) { 120 bool SkInstallDiscardablePixelRef(SkImageGenerator* generator, SkBitmap* dst) {
120 return SkInstallDiscardablePixelRef(generator, dst, NULL); 121 return SkInstallDiscardablePixelRef(generator, dst, NULL);
121 } 122 }
OLDNEW
« no previous file with comments | « src/image/SkSurface_Raster.cpp ('k') | tests/SurfaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698