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

Side by Side Diff: src/gpu/SkGrPixelRef.cpp

Issue 1576983002: Make SkBitmap::CopyTo respect requested dst color type when bitmap is texture backed. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix size_t warnings Created 4 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/core/SkPixelRef.cpp ('k') | tests/BitmapCopyTest.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 /* 2 /*
3 * Copyright 2010 Google Inc. 3 * Copyright 2010 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 10
11 #include "SkGrPixelRef.h" 11 #include "SkGrPixelRef.h"
12 12
13 #include "GrContext.h" 13 #include "GrContext.h"
14 #include "GrTexture.h" 14 #include "GrTexture.h"
15 #include "GrTexturePriv.h" 15 #include "GrTexturePriv.h"
16 #include "SkBitmapCache.h" 16 #include "SkBitmapCache.h"
17 #include "SkGr.h" 17 #include "SkGr.h"
18 #include "SkRect.h" 18 #include "SkRect.h"
19 19
20 SkROLockPixelsPixelRef::SkROLockPixelsPixelRef(const SkImageInfo& info) 20 SkROLockPixelsPixelRef::SkROLockPixelsPixelRef(const SkImageInfo& info)
21 : INHERITED(info) {} 21 : INHERITED(info) {}
22 22
23 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {} 23 SkROLockPixelsPixelRef::~SkROLockPixelsPixelRef() {}
24 24
25 bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) { 25 bool SkROLockPixelsPixelRef::onNewLockPixels(LockRec* rec) {
26 fBitmap.reset(); 26 fBitmap.reset();
27 // SkDebugf("---------- calling readpixels in support of lockpixels\n"); 27 // SkDebugf("---------- calling readpixels in support of lockpixels\n");
28 if (!this->onReadPixels(&fBitmap, nullptr)) { 28 if (!this->onReadPixels(&fBitmap, this->info().colorType(), nullptr)) {
29 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n"); 29 SkDebugf("SkROLockPixelsPixelRef::onLockPixels failed!\n");
30 return false; 30 return false;
31 } 31 }
32 fBitmap.lockPixels(); 32 fBitmap.lockPixels();
33 if (nullptr == fBitmap.getPixels()) { 33 if (nullptr == fBitmap.getPixels()) {
34 return false; 34 return false;
35 } 35 }
36 36
37 rec->fPixels = fBitmap.getPixels(); 37 rec->fPixels = fBitmap.getPixels();
38 rec->fColorTable = nullptr; 38 rec->fColorTable = nullptr;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 static bool tryAllocBitmapPixels(SkBitmap* bitmap) { 148 static bool tryAllocBitmapPixels(SkBitmap* bitmap) {
149 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator(); 149 SkBitmap::Allocator* allocator = SkBitmapCache::GetAllocator();
150 if (nullptr != allocator) { 150 if (nullptr != allocator) {
151 return allocator->allocPixelRef(bitmap, 0); 151 return allocator->allocPixelRef(bitmap, 0);
152 } else { 152 } else {
153 // DiscardableMemory is not available, fallback to default allocator 153 // DiscardableMemory is not available, fallback to default allocator
154 return bitmap->tryAllocPixels(); 154 return bitmap->tryAllocPixels();
155 } 155 }
156 } 156 }
157 157
158 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { 158 bool SkGrPixelRef::onReadPixels(SkBitmap* dst, SkColorType colorType, const SkIR ect* subset) {
159 if (nullptr == fSurface || fSurface->wasDestroyed()) { 159 if (nullptr == fSurface || fSurface->wasDestroyed()) {
160 return false; 160 return false;
161 } 161 }
162 162
163 GrPixelConfig config;
164 if (kRGBA_8888_SkColorType == colorType) {
165 config = kRGBA_8888_GrPixelConfig;
166 } else if (kBGRA_8888_SkColorType == colorType) {
167 config = kBGRA_8888_GrPixelConfig;
168 } else {
169 return false;
170 }
171
163 SkIRect bounds; 172 SkIRect bounds;
164 if (subset) { 173 if (subset) {
165 bounds = *subset; 174 bounds = *subset;
166 } else { 175 } else {
167 bounds = SkIRect::MakeWH(this->info().width(), this->info().height()); 176 bounds = SkIRect::MakeWH(this->info().width(), this->info().height());
168 } 177 }
169 178
170 //Check the cache 179 //Check the cache
171 if(!SkBitmapCache::Find(this->getGenerationID(), bounds, dst)) { 180 if(!SkBitmapCache::Find(this->getGenerationID(), bounds, dst)) {
172 //Cache miss 181 //Cache miss
173 182
174 SkBitmap cachedBitmap; 183 SkBitmap cachedBitmap;
175 cachedBitmap.setInfo(this->info().makeWH(bounds.width(), bounds.height() )); 184 cachedBitmap.setInfo(SkImageInfo::Make(bounds.width(), bounds.height(), colorType,
185 this->info().alphaType(),
186 this->info().profileType()));
176 187
177 // If we can't alloc the pixels, then fail 188 // If we can't alloc the pixels, then fail
178 if (!tryAllocBitmapPixels(&cachedBitmap)) { 189 if (!tryAllocBitmapPixels(&cachedBitmap)) {
179 return false; 190 return false;
180 } 191 }
181 192
182 // Try to read the pixels from the surface 193 // Try to read the pixels from the surface
183 void* buffer = cachedBitmap.getPixels(); 194 void* buffer = cachedBitmap.getPixels();
184 bool readPixelsOk = fSurface->readPixels(bounds.fLeft, bounds.fTop, 195 bool readPixelsOk = fSurface->readPixels(bounds.fLeft, bounds.fTop,
185 bounds.width(), bounds.height(), 196 bounds.width(), bounds.height(),
186 kSkia8888_GrPixelConfig, 197 config, buffer, cachedBitmap.rowBytes());
187 buffer, cachedBitmap.rowBytes());
188 198
189 if (!readPixelsOk) { 199 if (!readPixelsOk) {
190 return false; 200 return false;
191 } 201 }
192 202
193 // If we are here, pixels were read correctly from the surface. 203 // If we are here, pixels were read correctly from the surface.
194 cachedBitmap.setImmutable(); 204 cachedBitmap.setImmutable();
195 //Add to the cache 205 //Add to the cache
196 SkBitmapCache::Add(this, bounds, cachedBitmap); 206 SkBitmapCache::Add(this, bounds, cachedBitmap);
197 207
198 dst->swap(cachedBitmap); 208 dst->swap(cachedBitmap);
199 } 209 }
200 210
201 return true; 211 return true;
202 212
203 } 213 }
OLDNEW
« no previous file with comments | « src/core/SkPixelRef.cpp ('k') | tests/BitmapCopyTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698