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

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

Issue 25275004: store SkAlphaType inside SkBitmap, on road to support unpremul (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
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 "SkSurface_Base.h" 8 #include "SkSurface_Base.h"
9 #include "SkImagePriv.h" 9 #include "SkImagePriv.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 return true; 81 return true;
82 } 82 }
83 83
84 SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, void* pixels, size _t rb) 84 SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, void* pixels, size _t rb)
85 : INHERITED(info.fWidth, info.fHeight) { 85 : INHERITED(info.fWidth, info.fHeight) {
86 bool isOpaque; 86 bool isOpaque;
87 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); 87 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
88 88
89 fBitmap.setConfig(config, info.fWidth, info.fHeight, rb); 89 fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, isOpaque ?
scroggo 2013/10/18 19:32:40 Again, these should use the alpha type from the in
90 kOpaque_SkAlphaType : kPremul_SkAlphaType);
90 fBitmap.setPixels(pixels); 91 fBitmap.setPixels(pixels);
91 fBitmap.setIsOpaque(isOpaque);
92 fWeOwnThePixels = false; // We are "Direct" 92 fWeOwnThePixels = false; // We are "Direct"
93 } 93 }
94 94
95 SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, SkPixelRef* pr, si ze_t rb) 95 SkSurface_Raster::SkSurface_Raster(const SkImage::Info& info, SkPixelRef* pr, si ze_t rb)
96 : INHERITED(info.fWidth, info.fHeight) { 96 : INHERITED(info.fWidth, info.fHeight) {
97 bool isOpaque; 97 bool isOpaque;
98 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque); 98 SkBitmap::Config config = SkImageInfoToBitmapConfig(info, &isOpaque);
99 99
100 fBitmap.setConfig(config, info.fWidth, info.fHeight, rb); 100 fBitmap.setConfig(config, info.fWidth, info.fHeight, rb, isOpaque ?
101 kOpaque_SkAlphaType : kPremul_SkAlphaType);
101 fBitmap.setPixelRef(pr); 102 fBitmap.setPixelRef(pr);
102 fBitmap.setIsOpaque(isOpaque);
103 fWeOwnThePixels = true; 103 fWeOwnThePixels = true;
104 104
105 if (!isOpaque) { 105 if (!isOpaque) {
106 fBitmap.eraseColor(SK_ColorTRANSPARENT); 106 fBitmap.eraseColor(SK_ColorTRANSPARENT);
107 } 107 }
108 } 108 }
109 109
110 SkCanvas* SkSurface_Raster::onNewCanvas() { 110 SkCanvas* SkSurface_Raster::onNewCanvas() {
111 return SkNEW_ARGS(SkCanvas, (fBitmap)); 111 return SkNEW_ARGS(SkCanvas, (fBitmap));
112 } 112 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 size_t size = (size_t)size64; 172 size_t size = (size_t)size64;
173 void* pixels = sk_malloc_throw(size); 173 void* pixels = sk_malloc_throw(size);
174 if (NULL == pixels) { 174 if (NULL == pixels) {
175 return NULL; 175 return NULL;
176 } 176 }
177 177
178 SkAutoTUnref<SkPixelRef> pr(SkNEW_ARGS(SkMallocPixelRef, (pixels, size, NULL , true))); 178 SkAutoTUnref<SkPixelRef> pr(SkNEW_ARGS(SkMallocPixelRef, (pixels, size, NULL , true)));
179 return SkNEW_ARGS(SkSurface_Raster, (info, pr, rowBytes)); 179 return SkNEW_ARGS(SkSurface_Raster, (info, pr, rowBytes));
180 } 180 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698