YUV to RGB Texture threading GrProcessorDataManager
authorjoshualitt <joshualitt@chromium.org>
Thu, 9 Jul 2015 14:31:31 +0000 (07:31 -0700)
committerCommit bot <commit-bot@chromium.org>
Thu, 9 Jul 2015 14:31:32 +0000 (07:31 -0700)
BUG=skia:

Review URL: https://codereview.chromium.org/1230803002

gm/yuvtorgbeffect.cpp
src/gpu/GrPipelineBuilder.h
src/gpu/SkGr.cpp
src/gpu/effects/GrYUVtoRGBEffect.cpp
src/gpu/effects/GrYUVtoRGBEffect.h
src/image/SkImage_Gpu.cpp

index 62855cf..0da1b24 100644 (file)
@@ -111,8 +111,10 @@ protected:
                                        {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
 
             for (int i = 0; i < 6; ++i) {
+                GrPipelineBuilder pipelineBuilder;
                 SkAutoTUnref<GrFragmentProcessor> fp(
-                            GrYUVtoRGBEffect::Create(texture[indices[i][0]],
+                            GrYUVtoRGBEffect::Create(pipelineBuilder.getProcessorDataManager(),
+                                                     texture[indices[i][0]],
                                                      texture[indices[i][1]],
                                                      texture[indices[i][2]],
                                                      sizes,
@@ -120,7 +122,6 @@ protected:
                 if (fp) {
                     SkMatrix viewMatrix;
                     viewMatrix.setTranslate(x, y);
-                    GrPipelineBuilder pipelineBuilder;
                     pipelineBuilder.setRenderTarget(rt);
                     pipelineBuilder.addColorProcessor(fp);
                     tt.target()->drawSimpleRect(&pipelineBuilder,
index 87c2bc0..df384b3 100644 (file)
@@ -14,6 +14,7 @@
 #include "GrGpuResourceRef.h"
 #include "GrFragmentStage.h"
 #include "GrProcOptInfo.h"
+#include "GrProcessorDataManager.h"
 #include "GrRenderTarget.h"
 #include "GrStencil.h"
 #include "GrXferProcessor.h"
@@ -391,6 +392,8 @@ public:
     void setClip(const GrClip& clip) { fClip = clip; }
     const GrClip& clip() const { return fClip; }
 
+    GrProcessorDataManager* getProcessorDataManager() { return &fProcDataManager; }
+
 private:
     // Calculating invariant color / coverage information is expensive, so we partially cache the
     // results.
@@ -431,6 +434,7 @@ private:
 
     typedef SkSTArray<4, GrFragmentStage> FragmentStageArray;
 
+    GrProcessorDataManager                  fProcDataManager;
     SkAutoTUnref<GrRenderTarget>            fRenderTarget;
     uint32_t                                fFlags;
     GrStencilSettings                       fStencilSettings;
index a703146..5608030 100644 (file)
@@ -428,10 +428,11 @@ static GrTexture* load_yuv_texture(GrContext* ctx, const GrUniqueKey& optionalKe
     GrRenderTarget* renderTarget = result->asRenderTarget();
     SkASSERT(renderTarget);
 
+    GrPaint paint;
     SkAutoTUnref<GrFragmentProcessor>
-        yuvToRgbProcessor(GrYUVtoRGBEffect::Create(yuvTextures[0], yuvTextures[1], yuvTextures[2],
+        yuvToRgbProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorDataManager(), yuvTextures[0],
+                                                   yuvTextures[1], yuvTextures[2],
                                                    yuvInfo.fSize, yuvInfo.fColorSpace));
-    GrPaint paint;
     paint.addColorProcessor(yuvToRgbProcessor);
     SkRect r = SkRect::MakeWH(SkIntToScalar(yuvInfo.fSize[0].fWidth),
                               SkIntToScalar(yuvInfo.fSize[0].fHeight));
index 92acab3..a46cb92 100644 (file)
@@ -17,9 +17,9 @@ namespace {
 
 class YUVtoRGBEffect : public GrFragmentProcessor {
 public:
-    static GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture,
-                                       GrTexture* vTexture, const SkISize sizes[3],
-                                       SkYUVColorSpace colorSpace) {
+    static GrFragmentProcessor* Create(GrProcessorDataManager* procDataManager, GrTexture* yTexture,
+                                       GrTexture* uTexture, GrTexture* vTexture,
+                                       const SkISize sizes[3], SkYUVColorSpace colorSpace) {
         SkScalar w[3], h[3];
         w[0] = SkIntToScalar(sizes[0].fWidth)  / SkIntToScalar(yTexture->width());
         h[0] = SkIntToScalar(sizes[0].fHeight) / SkIntToScalar(yTexture->height());
@@ -40,7 +40,7 @@ public:
              (sizes[2].fHeight != sizes[0].fHeight)) ?
             GrTextureParams::kBilerp_FilterMode :
             GrTextureParams::kNone_FilterMode;
-        return SkNEW_ARGS(YUVtoRGBEffect, (yTexture, uTexture, vTexture, yuvMatrix,
+        return SkNEW_ARGS(YUVtoRGBEffect, (procDataManager, yTexture, uTexture, vTexture, yuvMatrix,
                                            uvFilterMode, colorSpace));
     }
 
@@ -110,9 +110,9 @@ public:
     }
 
 private:
-    YUVtoRGBEffect(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture,
-                   const SkMatrix yuvMatrix[3], GrTextureParams::FilterMode uvFilterMode,
-                   SkYUVColorSpace colorSpace)
+    YUVtoRGBEffect(GrProcessorDataManager*, GrTexture* yTexture, GrTexture* uTexture,
+                   GrTexture* vTexture, const SkMatrix yuvMatrix[3],
+                   GrTextureParams::FilterMode uvFilterMode, SkYUVColorSpace colorSpace)
     : fYTransform(kLocal_GrCoordSet, yuvMatrix[0], yTexture, GrTextureParams::kNone_FilterMode)
     , fYAccess(yTexture)
     , fUTransform(kLocal_GrCoordSet, yuvMatrix[1], uTexture, uvFilterMode)
@@ -166,8 +166,9 @@ const GrGLfloat YUVtoRGBEffect::GLProcessor::kRec601ConversionMatrix[16] = {
 //////////////////////////////////////////////////////////////////////////////
 
 GrFragmentProcessor*
-GrYUVtoRGBEffect::Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture,
-                         const SkISize sizes[3], SkYUVColorSpace colorSpace) {
-    SkASSERT(yTexture && uTexture && vTexture && sizes);
-    return YUVtoRGBEffect::Create(yTexture, uTexture, vTexture, sizes, colorSpace);
+GrYUVtoRGBEffect::Create(GrProcessorDataManager* procDataManager, GrTexture* yTexture,
+                         GrTexture* uTexture, GrTexture* vTexture, const SkISize sizes[3],
+                         SkYUVColorSpace colorSpace) {
+    SkASSERT(procDataManager && yTexture && uTexture && vTexture && sizes);
+    return YUVtoRGBEffect::Create(procDataManager, yTexture, uTexture, vTexture, sizes, colorSpace);
 }
index 0367978..a7379a4 100644 (file)
 #include "SkImageInfo.h"
 
 class GrFragmentProcessor;
+class GrProcessorDataManager;
 class GrTexture;
 
 namespace GrYUVtoRGBEffect {
     /**
      * Creates an effect that performs color conversion from YUV to RGB
      */
-    GrFragmentProcessor* Create(GrTexture* yTexture, GrTexture* uTexture, GrTexture* vTexture,
-                                const SkISize sizes[3], SkYUVColorSpace colorSpace);
+    GrFragmentProcessor* Create(GrProcessorDataManager*, GrTexture* yTexture, GrTexture* uTexture,
+                                GrTexture* vTexture, const SkISize sizes[3],
+                                SkYUVColorSpace colorSpace);
 };
 
 #endif
index d9ae619..a3fe022 100644 (file)
@@ -230,8 +230,8 @@ SkImage* SkImage::NewFromYUVTexturesCopy(GrContext* ctx , SkYUVColorSpace colorS
 
     GrPaint paint;
     paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
-    paint.addColorProcessor(GrYUVtoRGBEffect::Create(yTex, uTex, vTex, yuvSizes,
-                                                     colorSpace))->unref();
+    paint.addColorProcessor(GrYUVtoRGBEffect::Create(paint.getProcessorDataManager(), yTex, uTex,
+                                                     vTex, yuvSizes, colorSpace))->unref();
 
     const SkRect rect = SkRect::MakeWH(SkIntToScalar(dstDesc.fWidth),
                                        SkIntToScalar(dstDesc.fHeight));