1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2021 Google LLC 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#include "src/gpu/GrWritePixelsRenderTask.h" 9cb93a386Sopenharmony_ci 10cb93a386Sopenharmony_ci#include "src/gpu/GrGpu.h" 11cb93a386Sopenharmony_ci#include "src/gpu/GrOpFlushState.h" 12cb93a386Sopenharmony_ci#include "src/gpu/GrResourceAllocator.h" 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_cisk_sp<GrRenderTask> GrWritePixelsTask::Make(GrDrawingManager* dm, 15cb93a386Sopenharmony_ci sk_sp<GrSurfaceProxy> dst, 16cb93a386Sopenharmony_ci SkIRect rect, 17cb93a386Sopenharmony_ci GrColorType srcColorType, 18cb93a386Sopenharmony_ci GrColorType dstColorType, 19cb93a386Sopenharmony_ci const GrMipLevel texels[], 20cb93a386Sopenharmony_ci int levelCount) { 21cb93a386Sopenharmony_ci return sk_sp<GrRenderTask>(new GrWritePixelsTask(dm, 22cb93a386Sopenharmony_ci std::move(dst), 23cb93a386Sopenharmony_ci rect, 24cb93a386Sopenharmony_ci srcColorType, 25cb93a386Sopenharmony_ci dstColorType, 26cb93a386Sopenharmony_ci texels, 27cb93a386Sopenharmony_ci levelCount)); 28cb93a386Sopenharmony_ci} 29cb93a386Sopenharmony_ci 30cb93a386Sopenharmony_ciGrWritePixelsTask::GrWritePixelsTask(GrDrawingManager* dm, 31cb93a386Sopenharmony_ci sk_sp<GrSurfaceProxy> dst, 32cb93a386Sopenharmony_ci SkIRect rect, 33cb93a386Sopenharmony_ci GrColorType srcColorType, 34cb93a386Sopenharmony_ci GrColorType dstColorType, 35cb93a386Sopenharmony_ci const GrMipLevel texels[], 36cb93a386Sopenharmony_ci int levelCount) 37cb93a386Sopenharmony_ci : fRect(rect) 38cb93a386Sopenharmony_ci , fSrcColorType(srcColorType) 39cb93a386Sopenharmony_ci , fDstColorType(dstColorType) { 40cb93a386Sopenharmony_ci this->addTarget(dm, std::move(dst)); 41cb93a386Sopenharmony_ci fLevels.reset(levelCount); 42cb93a386Sopenharmony_ci std::copy_n(texels, levelCount, fLevels.get()); 43cb93a386Sopenharmony_ci} 44cb93a386Sopenharmony_ci 45cb93a386Sopenharmony_civoid GrWritePixelsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { 46cb93a386Sopenharmony_ci alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(), 47cb93a386Sopenharmony_ci GrResourceAllocator::ActualUse::kYes); 48cb93a386Sopenharmony_ci alloc->incOps(); 49cb93a386Sopenharmony_ci} 50cb93a386Sopenharmony_ci 51cb93a386Sopenharmony_ciGrRenderTask::ExpectedOutcome GrWritePixelsTask::onMakeClosed(GrRecordingContext*, 52cb93a386Sopenharmony_ci SkIRect* targetUpdateBounds) { 53cb93a386Sopenharmony_ci *targetUpdateBounds = fRect; 54cb93a386Sopenharmony_ci return ExpectedOutcome::kTargetDirty; 55cb93a386Sopenharmony_ci} 56cb93a386Sopenharmony_ci 57cb93a386Sopenharmony_cibool GrWritePixelsTask::onExecute(GrOpFlushState* flushState) { 58cb93a386Sopenharmony_ci GrSurfaceProxy* dstProxy = this->target(0); 59cb93a386Sopenharmony_ci if (!dstProxy->isInstantiated()) { 60cb93a386Sopenharmony_ci return false; 61cb93a386Sopenharmony_ci } 62cb93a386Sopenharmony_ci GrSurface* dstSurface = dstProxy->peekSurface(); 63cb93a386Sopenharmony_ci return flushState->gpu()->writePixels(dstSurface, 64cb93a386Sopenharmony_ci fRect, 65cb93a386Sopenharmony_ci fDstColorType, 66cb93a386Sopenharmony_ci fSrcColorType, 67cb93a386Sopenharmony_ci fLevels.get(), 68cb93a386Sopenharmony_ci fLevels.count()); 69cb93a386Sopenharmony_ci} 70