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

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

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