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

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

Issue 939623005: Pass Rendertarget into context (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: sampleapp Created 5 years, 10 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') | src/gpu/effects/GrConfigConversionEffect.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 "GrXferProcessor.h" 10 #include "GrXferProcessor.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // If filtering is not desired then we want to ensure all texels in the resa mpled image are 238 // If filtering is not desired then we want to ensure all texels in the resa mpled image are
239 // copies of texels from the original. 239 // copies of texels from the original.
240 GrTextureParams params(SkShader::kClamp_TileMode, 240 GrTextureParams params(SkShader::kClamp_TileMode,
241 kBilerp_Stretch == stretch ? GrTextureParams::kBilerp _FilterMode : 241 kBilerp_Stretch == stretch ? GrTextureParams::kBilerp _FilterMode :
242 GrTextureParams::kNone_F ilterMode); 242 GrTextureParams::kNone_F ilterMode);
243 paint.addColorTextureProcessor(inputTexture, SkMatrix::I(), params); 243 paint.addColorTextureProcessor(inputTexture, SkMatrix::I(), params);
244 244
245 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtD esc.fHeight)); 245 SkRect rect = SkRect::MakeWH(SkIntToScalar(rtDesc.fWidth), SkIntToScalar(rtD esc.fHeight));
246 SkRect localRect = SkRect::MakeWH(1.f, 1.f); 246 SkRect localRect = SkRect::MakeWH(1.f, 1.f);
247 247
248 GrContext::AutoRenderTarget autoRT(context, stretched->asRenderTarget());
249 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip); 248 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialClip);
250 context->drawNonAARectToRect(paint, SkMatrix::I(), rect, localRect); 249 context->drawNonAARectToRect(stretched->asRenderTarget(), paint, SkMatrix::I (), rect,
250 localRect);
251 251
252 return stretched; 252 return stretched;
253 } 253 }
254 254
255 #ifndef SK_IGNORE_ETC1_SUPPORT 255 #ifndef SK_IGNORE_ETC1_SUPPORT
256 static GrTexture *load_etc1_texture(GrContext* ctx, const GrContentKey& optional Key, 256 static GrTexture *load_etc1_texture(GrContext* ctx, const GrContentKey& optional Key,
257 const SkBitmap &bm, GrSurfaceDesc desc) { 257 const SkBitmap &bm, GrSurfaceDesc desc) {
258 SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData()); 258 SkAutoTUnref<SkData> data(bm.pixelRef()->refEncodedData());
259 259
260 // Is this even encoded data? 260 // Is this even encoded data?
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 GrRenderTarget* renderTarget = result->asRenderTarget(); 389 GrRenderTarget* renderTarget = result->asRenderTarget();
390 SkASSERT(renderTarget); 390 SkASSERT(renderTarget);
391 391
392 SkAutoTUnref<GrFragmentProcessor> 392 SkAutoTUnref<GrFragmentProcessor>
393 yuvToRgbProcessor(GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1 ], yuvTextures[2], 393 yuvToRgbProcessor(GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1 ], yuvTextures[2],
394 yuvInfo.fSize, yuvInfo.fColor Space)); 394 yuvInfo.fSize, yuvInfo.fColor Space));
395 GrPaint paint; 395 GrPaint paint;
396 paint.addColorProcessor(yuvToRgbProcessor); 396 paint.addColorProcessor(yuvToRgbProcessor);
397 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvInfo.fSize[0].fWidth), 397 SkRect r = SkRect::MakeWH(SkIntToScalar(yuvInfo.fSize[0].fWidth),
398 SkIntToScalar(yuvInfo.fSize[0].fHeight)); 398 SkIntToScalar(yuvInfo.fSize[0].fHeight));
399 GrContext::AutoRenderTarget autoRT(ctx, renderTarget);
400 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip); 399 GrContext::AutoClip ac(ctx, GrContext::AutoClip::kWideOpen_InitialClip);
401 ctx->drawRect(paint, SkMatrix::I(), r); 400 ctx->drawRect(renderTarget, paint, SkMatrix::I(), r);
402 401
403 return result; 402 return result;
404 } 403 }
405 404
406 static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx, 405 static GrTexture* create_unstretched_bitmap_texture(GrContext* ctx,
407 const SkBitmap& origBitmap, 406 const SkBitmap& origBitmap,
408 const GrContentKey& optional Key) { 407 const GrContentKey& optional Key) {
409 SkBitmap tmpBitmap; 408 SkBitmap tmpBitmap;
410 409
411 const SkBitmap* bitmap = &origBitmap; 410 const SkBitmap* bitmap = &origBitmap;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 *ctOut = ct; 632 *ctOut = ct;
634 } 633 }
635 if (ptOut) { 634 if (ptOut) {
636 *ptOut = pt; 635 *ptOut = pt;
637 } 636 }
638 return true; 637 return true;
639 } 638 }
640 639
641 /////////////////////////////////////////////////////////////////////////////// 640 ///////////////////////////////////////////////////////////////////////////////
642 641
643 void SkPaint2GrPaintNoShader(GrContext* context, const SkPaint& skPaint, GrColor paintColor, 642 void SkPaint2GrPaintNoShader(GrContext* context, GrRenderTarget* rt, const SkPai nt& skPaint,
644 bool constantColor, GrPaint* grPaint) { 643 GrColor paintColor, bool constantColor, GrPaint* gr Paint) {
645 644
646 grPaint->setDither(skPaint.isDither()); 645 grPaint->setDither(skPaint.isDither());
647 grPaint->setAntiAlias(skPaint.isAntiAlias()); 646 grPaint->setAntiAlias(skPaint.isAntiAlias());
648 647
649 SkXfermode* mode = skPaint.getXfermode(); 648 SkXfermode* mode = skPaint.getXfermode();
650 GrXPFactory* xpFactory = NULL; 649 GrXPFactory* xpFactory = NULL;
651 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) { 650 if (!SkXfermode::AsXPFactory(mode, &xpFactory)) {
652 // Fall back to src-over 651 // Fall back to src-over
653 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode); 652 xpFactory = GrPorterDuffXPFactory::Create(SkXfermode::kSrcOver_Mode);
654 } 653 }
(...skipping 16 matching lines...) Expand all
671 grPaint->addColorProcessor(fp); 670 grPaint->addColorProcessor(fp);
672 } 671 }
673 } 672 }
674 } 673 }
675 674
676 #ifndef SK_IGNORE_GPU_DITHER 675 #ifndef SK_IGNORE_GPU_DITHER
677 // If the dither flag is set, then we need to see if the underlying context 676 // If the dither flag is set, then we need to see if the underlying context
678 // supports it. If not, then install a dither effect. 677 // supports it. If not, then install a dither effect.
679 if (skPaint.isDither() && grPaint->numColorStages() > 0) { 678 if (skPaint.isDither() && grPaint->numColorStages() > 0) {
680 // What are we rendering into? 679 // What are we rendering into?
681 const GrRenderTarget *target = context->getRenderTarget(); 680 SkASSERT(rt);
682 SkASSERT(target);
683 681
684 // Suspect the dithering flag has no effect on these configs, otherwise 682 // Suspect the dithering flag has no effect on these configs, otherwise
685 // fall back on setting the appropriate state. 683 // fall back on setting the appropriate state.
686 if (target->config() == kRGBA_8888_GrPixelConfig || 684 if (GrPixelConfigIs8888(rt->config()) ||
687 target->config() == kBGRA_8888_GrPixelConfig) { 685 GrPixelConfigIs8888(rt->config())) {
688 // The dither flag is set and the target is likely 686 // The dither flag is set and the target is likely
689 // not going to be dithered by the GPU. 687 // not going to be dithered by the GPU.
690 SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create()); 688 SkAutoTUnref<GrFragmentProcessor> fp(GrDitherEffect::Create());
691 if (fp.get()) { 689 if (fp.get()) {
692 grPaint->addColorProcessor(fp); 690 grPaint->addColorProcessor(fp);
693 grPaint->setDither(false); 691 grPaint->setDither(false);
694 } 692 }
695 } 693 }
696 } 694 }
697 #endif 695 #endif
698 } 696 }
699 697
700 void SkPaint2GrPaintShader(GrContext* context, const SkPaint& skPaint, const SkM atrix& viewM, 698 void SkPaint2GrPaintShader(GrContext* context, GrRenderTarget* rt, const SkPaint & skPaint,
701 bool constantColor, GrPaint* grPaint) { 699 const SkMatrix& viewM, bool constantColor, GrPaint* g rPaint) {
702 SkShader* shader = skPaint.getShader(); 700 SkShader* shader = skPaint.getShader();
703 if (NULL == shader) { 701 if (NULL == shader) {
704 SkPaint2GrPaintNoShader(context, skPaint, SkColor2GrColor(skPaint.getCol or()), 702 SkPaint2GrPaintNoShader(context, rt, skPaint, SkColor2GrColor(skPaint.ge tColor()),
705 constantColor, grPaint); 703 constantColor, grPaint);
706 return; 704 return;
707 } 705 }
708 706
709 GrColor paintColor = SkColor2GrColor(skPaint.getColor()); 707 GrColor paintColor = SkColor2GrColor(skPaint.getColor());
710 708
711 // Start a new block here in order to preserve our context state after calli ng 709 // Start a new block here in order to preserve our context state after calli ng
712 // asFragmentProcessor(). Since these calls get passed back to the client, w e don't really 710 // asFragmentProcessor(). Since these calls get passed back to the client, w e don't really
713 // want them messing around with the context. 711 // want them messing around with the context.
714 { 712 {
715 // SkShader::asFragmentProcessor() may do offscreen rendering. Save off the current RT,
716 // and clip
717 GrContext::AutoRenderTarget art(context, NULL);
718 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl ip); 713 GrContext::AutoClip ac(context, GrContext::AutoClip::kWideOpen_InitialCl ip);
719 714
720 // Allow the shader to modify paintColor and also create an effect to be installed as 715 // Allow the shader to modify paintColor and also create an effect to be installed as
721 // the first color effect on the GrPaint. 716 // the first color effect on the GrPaint.
722 GrFragmentProcessor* fp = NULL; 717 GrFragmentProcessor* fp = NULL;
723 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) { 718 if (shader->asFragmentProcessor(context, skPaint, viewM, NULL, &paintCol or, &fp) && fp) {
724 grPaint->addColorProcessor(fp)->unref(); 719 grPaint->addColorProcessor(fp)->unref();
725 constantColor = false; 720 constantColor = false;
726 } 721 }
727 } 722 }
728 723
729 // The grcolor is automatically set when calling asFragmentProcessor. 724 // The grcolor is automatically set when calling asFragmentProcessor.
730 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint. 725 // If the shader can be seen as an effect it returns true and adds its effec t to the grpaint.
731 SkPaint2GrPaintNoShader(context, skPaint, paintColor, constantColor, grPaint ); 726 SkPaint2GrPaintNoShader(context, rt, skPaint, paintColor, constantColor, grP aint);
732 } 727 }
OLDNEW
« no previous file with comments | « src/gpu/SkGpuDevice.cpp ('k') | src/gpu/effects/GrConfigConversionEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698