1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef GrGLGpuCommandBuffer_DEFINED 9 #define GrGLGpuCommandBuffer_DEFINED 10 11 #include "src/gpu/GrGpuCommandBuffer.h" 12 13 #include "src/gpu/GrOpFlushState.h" 14 #include "src/gpu/gl/GrGLGpu.h" 15 #include "src/gpu/gl/GrGLRenderTarget.h" 16 17 class GrGLGpu; 18 class GrGLRenderTarget; 19 20 class GrGLGpuTextureCommandBuffer : public GrGpuTextureCommandBuffer { 21 public: GrGLGpuTextureCommandBuffer(GrGLGpu * gpu)22 GrGLGpuTextureCommandBuffer(GrGLGpu* gpu) : fGpu(gpu) {} 23 copy(GrSurface * src,const SkIRect & srcRect,const SkIPoint & dstPoint)24 void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override { 25 fGpu->copySurface(fTexture, src, srcRect, dstPoint); 26 } 27 transferFrom(const SkIRect & srcRect,GrColorType surfaceColorType,GrColorType bufferColorType,GrGpuBuffer * transferBuffer,size_t offset)28 void transferFrom(const SkIRect& srcRect, GrColorType surfaceColorType, 29 GrColorType bufferColorType, GrGpuBuffer* transferBuffer, 30 size_t offset) override { 31 fGpu->transferPixelsFrom(fTexture, srcRect.fLeft, srcRect.fTop, srcRect.width(), 32 srcRect.height(), surfaceColorType, bufferColorType, 33 transferBuffer, offset); 34 } 35 insertEventMarker(const char * msg)36 void insertEventMarker(const char* msg) override { 37 fGpu->insertEventMarker(msg); 38 } 39 reset()40 void reset() { 41 fTexture = nullptr; 42 } 43 44 private: 45 GrGLGpu* fGpu; 46 47 typedef GrGpuTextureCommandBuffer INHERITED; 48 }; 49 50 class GrGLGpuRTCommandBuffer : public GrGpuRTCommandBuffer { 51 /** 52 * We do not actually buffer up draws or do any work in the this class for GL. Instead commands 53 * are immediately sent to the gpu to execute. Thus all the commands in this class are simply 54 * pass through functions to corresponding calls in the GrGLGpu class. 55 */ 56 public: GrGLGpuRTCommandBuffer(GrGLGpu * gpu)57 GrGLGpuRTCommandBuffer(GrGLGpu* gpu) : fGpu(gpu) {} 58 59 void begin() override; end()60 void end() override {} 61 insertEventMarker(const char * msg)62 void insertEventMarker(const char* msg) override { 63 fGpu->insertEventMarker(msg); 64 } 65 inlineUpload(GrOpFlushState * state,GrDeferredTextureUploadFn & upload)66 void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override { 67 state->doUpload(upload); 68 } 69 copy(GrSurface * src,const SkIRect & srcRect,const SkIPoint & dstPoint)70 void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override { 71 fGpu->copySurface(fRenderTarget, src,srcRect, dstPoint); 72 } 73 transferFrom(const SkIRect & srcRect,GrColorType surfaceColorType,GrColorType bufferColorType,GrGpuBuffer * transferBuffer,size_t offset)74 void transferFrom(const SkIRect& srcRect, GrColorType surfaceColorType, 75 GrColorType bufferColorType, GrGpuBuffer* transferBuffer, 76 size_t offset) override { 77 fGpu->transferPixelsFrom(fRenderTarget, srcRect.fLeft, srcRect.fTop, srcRect.width(), 78 srcRect.height(), surfaceColorType, bufferColorType, 79 transferBuffer, offset); 80 } 81 82 void set(GrRenderTarget*, GrSurfaceOrigin, 83 const GrGpuRTCommandBuffer::LoadAndStoreInfo&, 84 const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo&); 85 reset()86 void reset() { 87 fRenderTarget = nullptr; 88 } 89 90 private: gpu()91 GrGpu* gpu() override { return fGpu; } 92 onDraw(const GrPrimitiveProcessor & primProc,const GrPipeline & pipeline,const GrPipeline::FixedDynamicState * fixedDynamicState,const GrPipeline::DynamicStateArrays * dynamicStateArrays,const GrMesh mesh[],int meshCount,const SkRect & bounds)93 void onDraw(const GrPrimitiveProcessor& primProc, 94 const GrPipeline& pipeline, 95 const GrPipeline::FixedDynamicState* fixedDynamicState, 96 const GrPipeline::DynamicStateArrays* dynamicStateArrays, 97 const GrMesh mesh[], 98 int meshCount, 99 const SkRect& bounds) override { 100 fGpu->draw(fRenderTarget, fOrigin, primProc, pipeline, fixedDynamicState, 101 dynamicStateArrays, mesh, meshCount); 102 } 103 onClear(const GrFixedClip & clip,const SkPMColor4f & color)104 void onClear(const GrFixedClip& clip, const SkPMColor4f& color) override { 105 fGpu->clear(clip, color, fRenderTarget, fOrigin); 106 } 107 onClearStencilClip(const GrFixedClip & clip,bool insideStencilMask)108 void onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) override { 109 fGpu->clearStencilClip(clip, insideStencilMask, fRenderTarget, fOrigin); 110 } 111 112 GrGLGpu* fGpu; 113 GrGpuRTCommandBuffer::LoadAndStoreInfo fColorLoadAndStoreInfo; 114 GrGpuRTCommandBuffer::StencilLoadAndStoreInfo fStencilLoadAndStoreInfo; 115 116 typedef GrGpuRTCommandBuffer INHERITED; 117 }; 118 119 #endif 120 121