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

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

Issue 1149773005: Add direct getter for GrCaps to GrContext. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: init caps in the right place Created 5 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/SkGpuDevice.cpp ('k') | tests/GrDrawTargetTest.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 2010 Google Inc. 2 * Copyright 2010 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 "SkGr.h" 8 #include "SkGr.h"
9 9
10 #include "GrCaps.h"
10 #include "GrDrawContext.h" 11 #include "GrDrawContext.h"
11 #include "GrXferProcessor.h" 12 #include "GrXferProcessor.h"
12 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
13 #include "SkConfig8888.h" 14 #include "SkConfig8888.h"
14 #include "SkData.h" 15 #include "SkData.h"
15 #include "SkErrorInternals.h" 16 #include "SkErrorInternals.h"
16 #include "SkGrPixelRef.h" 17 #include "SkGrPixelRef.h"
17 #include "SkMessageBus.h" 18 #include "SkMessageBus.h"
18 #include "SkPixelRef.h" 19 #include "SkPixelRef.h"
19 #include "SkResourceCache.h" 20 #include "SkResourceCache.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 90
90 enum Stretch { 91 enum Stretch {
91 kNo_Stretch, 92 kNo_Stretch,
92 kBilerp_Stretch, 93 kBilerp_Stretch,
93 kNearest_Stretch 94 kNearest_Stretch
94 }; 95 };
95 96
96 static Stretch get_stretch_type(const GrContext* ctx, int width, int height, 97 static Stretch get_stretch_type(const GrContext* ctx, int width, int height,
97 const GrTextureParams* params) { 98 const GrTextureParams* params) {
98 if (params && params->isTiled()) { 99 if (params && params->isTiled()) {
99 if (!ctx->npotTextureTileSupport() && (!SkIsPow2(width) || !SkIsPow2(hei ght))) { 100 if (!ctx->caps()->npotTextureTileSupport() && (!SkIsPow2(width) || !SkIs Pow2(height))) {
100 switch(params->filterMode()) { 101 switch(params->filterMode()) {
101 case GrTextureParams::kNone_FilterMode: 102 case GrTextureParams::kNone_FilterMode:
102 return kNearest_Stretch; 103 return kNearest_Stretch;
103 case GrTextureParams::kBilerp_FilterMode: 104 case GrTextureParams::kBilerp_FilterMode:
104 case GrTextureParams::kMipMap_FilterMode: 105 case GrTextureParams::kMipMap_FilterMode:
105 return kBilerp_Stretch; 106 return kBilerp_Stretch;
106 } 107 }
107 } 108 }
108 } 109 }
109 return kNo_Stretch; 110 return kNo_Stretch;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // creates a new texture that is the input texture scaled up to the next power o f two in 192 // creates a new texture that is the input texture scaled up to the next power o f two in
192 // width or height. If optionalKey is valid it will be set on the new texture. s tretch 193 // width or height. If optionalKey is valid it will be set on the new texture. s tretch
193 // controls whether the scaling is done using nearest or bilerp filtering. 194 // controls whether the scaling is done using nearest or bilerp filtering.
194 GrTexture* stretch_texture_to_next_pot(GrTexture* inputTexture, Stretch stretch, 195 GrTexture* stretch_texture_to_next_pot(GrTexture* inputTexture, Stretch stretch,
195 SkPixelRef* pixelRef, 196 SkPixelRef* pixelRef,
196 const GrUniqueKey& optionalKey) { 197 const GrUniqueKey& optionalKey) {
197 SkASSERT(kNo_Stretch != stretch); 198 SkASSERT(kNo_Stretch != stretch);
198 199
199 GrContext* context = inputTexture->getContext(); 200 GrContext* context = inputTexture->getContext();
200 SkASSERT(context); 201 SkASSERT(context);
202 const GrCaps* caps = context->caps();
201 203
202 // Either it's a cache miss or the original wasn't cached to begin with. 204 // Either it's a cache miss or the original wasn't cached to begin with.
203 GrSurfaceDesc rtDesc = inputTexture->desc(); 205 GrSurfaceDesc rtDesc = inputTexture->desc();
204 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag; 206 rtDesc.fFlags = rtDesc.fFlags | kRenderTarget_GrSurfaceFlag;
205 rtDesc.fWidth = GrNextPow2(rtDesc.fWidth); 207 rtDesc.fWidth = GrNextPow2(rtDesc.fWidth);
206 rtDesc.fHeight = GrNextPow2(rtDesc.fHeight); 208 rtDesc.fHeight = GrNextPow2(rtDesc.fHeight);
207 rtDesc.fConfig = GrMakePixelConfigUncompressed(rtDesc.fConfig); 209 rtDesc.fConfig = GrMakePixelConfigUncompressed(rtDesc.fConfig);
208 210
209 // If the config isn't renderable try converting to either A8 or an 32 bit c onfig. Otherwise, 211 // If the config isn't renderable try converting to either A8 or an 32 bit c onfig. Otherwise,
210 // fail. 212 // fail.
211 if (!context->isConfigRenderable(rtDesc.fConfig, false)) { 213 if (!caps->isConfigRenderable(rtDesc.fConfig, false)) {
212 if (GrPixelConfigIsAlphaOnly(rtDesc.fConfig)) { 214 if (GrPixelConfigIsAlphaOnly(rtDesc.fConfig)) {
213 if (context->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) { 215 if (caps->isConfigRenderable(kAlpha_8_GrPixelConfig, false)) {
214 rtDesc.fConfig = kAlpha_8_GrPixelConfig; 216 rtDesc.fConfig = kAlpha_8_GrPixelConfig;
215 } else if (context->isConfigRenderable(kSkia8888_GrPixelConfig, fals e)) { 217 } else if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) {
216 rtDesc.fConfig = kSkia8888_GrPixelConfig; 218 rtDesc.fConfig = kSkia8888_GrPixelConfig;
217 } else { 219 } else {
218 return NULL; 220 return NULL;
219 } 221 }
220 } else if (kRGB_GrColorComponentFlags == 222 } else if (kRGB_GrColorComponentFlags ==
221 (kRGB_GrColorComponentFlags & GrPixelConfigComponentMask(rtDe sc.fConfig))) { 223 (kRGB_GrColorComponentFlags & GrPixelConfigComponentMask(rtDe sc.fConfig))) {
222 if (context->isConfigRenderable(kSkia8888_GrPixelConfig, false)) { 224 if (caps->isConfigRenderable(kSkia8888_GrPixelConfig, false)) {
223 rtDesc.fConfig = kSkia8888_GrPixelConfig; 225 rtDesc.fConfig = kSkia8888_GrPixelConfig;
224 } else { 226 } else {
225 return NULL; 227 return NULL;
226 } 228 }
227 } else { 229 } else {
228 return NULL; 230 return NULL;
229 } 231 }
230 } 232 }
231 233
232 GrTexture* stretched = create_texture_for_bmp(context, optionalKey, rtDesc, pixelRef, NULL, 0); 234 GrTexture* stretched = create_texture_for_bmp(context, optionalKey, rtDesc, pixelRef, NULL, 0);
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 418
417 static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, 419 static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx,
418 const SkBitmap& origBitmap, 420 const SkBitmap& origBitmap,
419 const GrUniqueKey& optionalK ey) { 421 const GrUniqueKey& optionalK ey) {
420 SkBitmap tmpBitmap; 422 SkBitmap tmpBitmap;
421 423
422 const SkBitmap* bitmap = &origBitmap; 424 const SkBitmap* bitmap = &origBitmap;
423 425
424 GrSurfaceDesc desc; 426 GrSurfaceDesc desc;
425 generate_bitmap_texture_desc(*bitmap, &desc); 427 generate_bitmap_texture_desc(*bitmap, &desc);
428 const GrCaps* caps = ctx->caps();
426 429
427 if (kIndex_8_SkColorType == bitmap->colorType()) { 430 if (kIndex_8_SkColorType == bitmap->colorType()) {
428 if (ctx->isConfigTexturable(kIndex_8_GrPixelConfig)) { 431 if (caps->isConfigTexturable(kIndex_8_GrPixelConfig)) {
429 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig , 432 size_t imageSize = GrCompressedFormatDataSize(kIndex_8_GrPixelConfig ,
430 bitmap->width(), bitma p->height()); 433 bitmap->width(), bitma p->height());
431 SkAutoMalloc storage(imageSize); 434 SkAutoMalloc storage(imageSize);
432 build_index8_data(storage.get(), origBitmap); 435 build_index8_data(storage.get(), origBitmap);
433 436
434 // our compressed data will be trimmed, so pass width() for its 437 // our compressed data will be trimmed, so pass width() for its
435 // "rowBytes", since they are the same now. 438 // "rowBytes", since they are the same now.
436 return create_texture_for_bmp(ctx, optionalKey, desc, origBitmap.pix elRef(), 439 return create_texture_for_bmp(ctx, optionalKey, desc, origBitmap.pix elRef(),
437 storage.get(), bitmap->width()); 440 storage.get(), bitmap->width());
438 } else { 441 } else {
439 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType); 442 origBitmap.copyTo(&tmpBitmap, kN32_SkColorType);
440 // now bitmap points to our temp, which has been promoted to 32bits 443 // now bitmap points to our temp, which has been promoted to 32bits
441 bitmap = &tmpBitmap; 444 bitmap = &tmpBitmap;
442 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info()); 445 desc.fConfig = SkImageInfo2GrPixelConfig(bitmap->info());
443 } 446 }
444 } 447 }
445 448
446 // Is this an ETC1 encoded texture? 449 // Is this an ETC1 encoded texture?
447 #ifndef SK_IGNORE_ETC1_SUPPORT 450 #ifndef SK_IGNORE_ETC1_SUPPORT
448 // Make sure that the underlying device supports ETC1 textures before we go ahead 451 // Make sure that the underlying device supports ETC1 textures before we go ahead
449 // and check the data. 452 // and check the data.
450 else if (ctx->isConfigTexturable(kETC1_GrPixelConfig) 453 else if (caps->isConfigTexturable(kETC1_GrPixelConfig)
451 // If the bitmap had compressed data and was then uncompressed, it'l l still return 454 // If the bitmap had compressed data and was then uncompressed, it'l l still return
452 // compressed data on 'refEncodedData' and upload it. Probably not g ood, since if 455 // compressed data on 'refEncodedData' and upload it. Probably not g ood, since if
453 // the bitmap has available pixels, then they might not be what the decompressed 456 // the bitmap has available pixels, then they might not be what the decompressed
454 // data is. 457 // data is.
455 && !(bitmap->readyToDraw())) { 458 && !(bitmap->readyToDraw())) {
456 GrTexture *texture = load_etc1_texture(ctx, optionalKey, *bitmap, desc); 459 GrTexture *texture = load_etc1_texture(ctx, optionalKey, *bitmap, desc);
457 if (texture) { 460 if (texture) {
458 return texture; 461 return texture;
459 } 462 }
460 } 463 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 } 767 }
765 return SkImageInfo::Make(w, h, ct, at); 768 return SkImageInfo::Make(w, h, ct, at);
766 } 769 }
767 770
768 771
769 void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap * dst) { 772 void GrWrapTextureInBitmap(GrTexture* src, int w, int h, bool isOpaque, SkBitmap * dst) {
770 const SkImageInfo info = GrMakeInfoFromTexture(src, w, h, isOpaque); 773 const SkImageInfo info = GrMakeInfoFromTexture(src, w, h, isOpaque);
771 dst->setInfo(info); 774 dst->setInfo(info);
772 dst->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, src)))->unref(); 775 dst->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, src)))->unref();
773 } 776 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | tests/GrDrawTargetTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698