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

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

Issue 322963002: hide SkBitmap::setConfig (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 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/gpu/GrSurface.cpp ('k') | src/images/SkImageDecoder.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 2011 Google Inc. 2 * Copyright 2011 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 "SkGpuDevice.h" 8 #include "SkGpuDevice.h"
9 9
10 #include "effects/GrBicubicEffect.h" 10 #include "effects/GrBicubicEffect.h"
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 118
119 struct GrSkDrawProcs : public SkDrawProcs { 119 struct GrSkDrawProcs : public SkDrawProcs {
120 public: 120 public:
121 GrContext* fContext; 121 GrContext* fContext;
122 GrTextContext* fTextContext; 122 GrTextContext* fTextContext;
123 GrFontScaler* fFontScaler; // cached in the skia glyphcache 123 GrFontScaler* fFontScaler; // cached in the skia glyphcache
124 }; 124 };
125 125
126 /////////////////////////////////////////////////////////////////////////////// 126 ///////////////////////////////////////////////////////////////////////////////
127 127
128 static SkBitmap::Config grConfig2skConfig(GrPixelConfig config, bool* isOpaque) {
129 switch (config) {
130 case kAlpha_8_GrPixelConfig:
131 *isOpaque = false;
132 return SkBitmap::kA8_Config;
133 case kRGB_565_GrPixelConfig:
134 *isOpaque = true;
135 return SkBitmap::kRGB_565_Config;
136 case kRGBA_4444_GrPixelConfig:
137 *isOpaque = false;
138 return SkBitmap::kARGB_4444_Config;
139 case kSkia8888_GrPixelConfig:
140 // we don't currently have a way of knowing whether
141 // a 8888 is opaque based on the config.
142 *isOpaque = false;
143 return SkBitmap::kARGB_8888_Config;
144 default:
145 *isOpaque = false;
146 return SkBitmap::kNo_Config;
147 }
148 }
149
150 /* 128 /*
151 * GrRenderTarget does not know its opaqueness, only its config, so we have 129 * GrRenderTarget does not know its opaqueness, only its config, so we have
152 * to make conservative guesses when we return an "equivalent" bitmap. 130 * to make conservative guesses when we return an "equivalent" bitmap.
153 */ 131 */
154 static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) { 132 static SkBitmap make_bitmap(GrContext* context, GrRenderTarget* renderTarget) {
155 bool isOpaque;
156 SkBitmap::Config config = grConfig2skConfig(renderTarget->config(), &isOpaqu e);
157
158 SkBitmap bitmap; 133 SkBitmap bitmap;
159 bitmap.setConfig(config, renderTarget->width(), renderTarget->height(), 0, 134 bitmap.setInfo(renderTarget->info());
160 isOpaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType);
161 return bitmap; 135 return bitmap;
162 } 136 }
163 137
164 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) { 138 SkGpuDevice* SkGpuDevice::Create(GrSurface* surface, unsigned flags) {
165 SkASSERT(NULL != surface); 139 SkASSERT(NULL != surface);
166 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) { 140 if (NULL == surface->asRenderTarget() || NULL == surface->getContext()) {
167 return NULL; 141 return NULL;
168 } 142 }
169 if (surface->asTexture()) { 143 if (surface->asTexture()) {
170 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur e(), flags)); 144 return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTextur e(), flags));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 179
206 // Hold onto to the texture in the pixel ref (if there is one) because the t exture holds a ref 180 // Hold onto to the texture in the pixel ref (if there is one) because the t exture holds a ref
207 // on the RT but not vice-versa. 181 // on the RT but not vice-versa.
208 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do this without 182 // TODO: Remove this trickery once we figure out how to make SkGrPixelRef do this without
209 // busting chrome (for a currently unknown reason). 183 // busting chrome (for a currently unknown reason).
210 GrSurface* surface = fRenderTarget->asTexture(); 184 GrSurface* surface = fRenderTarget->asTexture();
211 if (NULL == surface) { 185 if (NULL == surface) {
212 surface = fRenderTarget; 186 surface = fRenderTarget;
213 } 187 }
214 188
215 SkImageInfo info; 189 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef,
216 surface->asImageInfo(&info); 190 (surface->info(), surface, SkToBool(flags & kCac hed_Flag)));
217 SkPixelRef* pr = SkNEW_ARGS(SkGrPixelRef, (info, surface, SkToBool(flags & k Cached_Flag)));
218 191
219 this->setPixelRef(pr)->unref(); 192 this->setPixelRef(pr)->unref();
220 } 193 }
221 194
222 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo , 195 SkGpuDevice* SkGpuDevice::Create(GrContext* context, const SkImageInfo& origInfo ,
223 int sampleCount) { 196 int sampleCount) {
224 if (kUnknown_SkColorType == origInfo.colorType() || 197 if (kUnknown_SkColorType == origInfo.colorType() ||
225 origInfo.width() < 0 || origInfo.height() < 0) { 198 origInfo.width() < 0 || origInfo.height() < 0) {
226 return NULL; 199 return NULL;
227 } 200 }
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 694
722 // Draw the mask into maskTexture with the path's top-left at the origin usi ng tempPaint. 695 // Draw the mask into maskTexture with the path's top-left at the origin usi ng tempPaint.
723 SkMatrix translate; 696 SkMatrix translate;
724 translate.setTranslate(-maskRect.fLeft, -maskRect.fTop); 697 translate.setTranslate(-maskRect.fLeft, -maskRect.fTop);
725 am.set(context, translate); 698 am.set(context, translate);
726 context->drawPath(tempPaint, devPath, stroke); 699 context->drawPath(tempPaint, devPath, stroke);
727 return true; 700 return true;
728 } 701 }
729 702
730 SkBitmap wrap_texture(GrTexture* texture) { 703 SkBitmap wrap_texture(GrTexture* texture) {
731 SkImageInfo info;
732 texture->asImageInfo(&info);
733
734 SkBitmap result; 704 SkBitmap result;
735 result.setInfo(info); 705 result.setInfo(texture->info());
736 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); 706 result.setPixelRef(SkNEW_ARGS(SkGrPixelRef, (result.info(), texture)))->unre f();
737 return result; 707 return result;
738 } 708 }
739 709
740 }; 710 };
741 711
742 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath, 712 void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
743 const SkPaint& paint, const SkMatrix* prePathMatrix, 713 const SkPaint& paint, const SkMatrix* prePathMatrix,
744 bool pathIsMutable) { 714 bool pathIsMutable) {
745 CHECK_FOR_ANNOTATION(paint); 715 CHECK_FOR_ANNOTATION(paint);
746 CHECK_SHOULD_DRAW(draw, false); 716 CHECK_SHOULD_DRAW(draw, false);
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
2006 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(pict ure, i); 1976 GrCachedLayer* layer = fContext->getLayerCache()->findLayerOrCreate(pict ure, i);
2007 1977
2008 if (NULL != layer->getTexture()) { 1978 if (NULL != layer->getTexture()) {
2009 fContext->unlockScratchTexture(layer->getTexture()); 1979 fContext->unlockScratchTexture(layer->getTexture());
2010 layer->setTexture(NULL); 1980 layer->setTexture(NULL);
2011 } 1981 }
2012 } 1982 }
2013 1983
2014 return true; 1984 return true;
2015 } 1985 }
OLDNEW
« no previous file with comments | « src/gpu/GrSurface.cpp ('k') | src/images/SkImageDecoder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698