| Index: third_party/WebKit/Source/platform/graphics/gpu/TextureImageBufferSurface.cpp
|
| diff --git a/third_party/WebKit/Source/platform/graphics/gpu/TextureImageBufferSurface.cpp b/third_party/WebKit/Source/platform/graphics/gpu/TextureImageBufferSurface.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4b90543683050cd78e1a8022169590eea848efdc
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/platform/graphics/gpu/TextureImageBufferSurface.cpp
|
| @@ -0,0 +1,139 @@
|
| +/*
|
| + * Copyright (c) 2013, Google Inc. All rights reserved.
|
| + *
|
| + * Redistribution and use in source and binary forms, with or without
|
| + * modification, are permitted provided that the following conditions are
|
| + * met:
|
| + *
|
| + * * Redistributions of source code must retain the above copyright
|
| + * notice, this list of conditions and the following disclaimer.
|
| + * * Redistributions in binary form must reproduce the above
|
| + * copyright notice, this list of conditions and the following disclaimer
|
| + * in the documentation and/or other materials provided with the
|
| + * distribution.
|
| + * * Neither the name of Google Inc. nor the names of its
|
| + * contributors may be used to endorse or promote products derived from
|
| + * this software without specific prior written permission.
|
| + *
|
| + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| + */
|
| +
|
| +#include "platform/graphics/gpu/TextureImageBufferSurface.h"
|
| +
|
| +#include "gpu/command_buffer/client/gles2_interface.h"
|
| +#include "gpu/command_buffer/common/mailbox.h"
|
| +#include "gpu/command_buffer/common/sync_token.h"
|
| +#include "platform/graphics/gpu/SharedGpuContext.h"
|
| +#include "platform/graphics/skia/SkiaUtils.h"
|
| +#include "platform/wtf/PtrUtil.h"
|
| +#include "platform/wtf/RefPtr.h"
|
| +#include "skia/ext/texture_handle.h"
|
| +#include "third_party/skia/include/gpu/GrBackendSurface.h"
|
| +#include "third_party/skia/include/gpu/GrContext.h"
|
| +
|
| +namespace blink {
|
| +
|
| +TextureImageBufferSurface::TextureImageBufferSurface(
|
| + gpu::gles2::GLES2Interface* webgl_gl,
|
| + GLenum texture_target,
|
| + GLuint webgl_texture_id,
|
| + const IntSize& size,
|
| + OpacityMode opacity_mode,
|
| + const CanvasColorParams& color_params)
|
| + : ImageBufferSurface(size, opacity_mode, color_params) {
|
| + if (!SharedGpuContext::IsValid())
|
| + return;
|
| + gpu::gles2::GLES2Interface* gl = SharedGpuContext::Gl();
|
| + GrContext* gr_context = SharedGpuContext::Gr();
|
| + context_id_ = SharedGpuContext::ContextId();
|
| + CHECK(gr_context);
|
| +
|
| + gpu::Mailbox mailbox;
|
| + webgl_gl->GenMailboxCHROMIUM(mailbox.name);
|
| + DVLOG(1) << webgl_texture_id << " / " << texture_target;
|
| + webgl_gl->ProduceTextureDirectCHROMIUM(webgl_texture_id, texture_target,
|
| + mailbox.name);
|
| +
|
| + gpu::SyncToken sync_token;
|
| + const GLuint64 fence_sync = webgl_gl->InsertFenceSyncCHROMIUM();
|
| + webgl_gl->Flush();
|
| + webgl_gl->GenSyncTokenCHROMIUM(fence_sync, sync_token.GetData());
|
| + gl->WaitSyncTokenCHROMIUM(sync_token.GetData());
|
| +
|
| + GLuint texture =
|
| + gl->CreateAndConsumeTextureCHROMIUM(texture_target, mailbox.name);
|
| +
|
| + SkAlphaType alpha_type =
|
| + (kOpaque == opacity_mode) ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
|
| + SkImageInfo info = SkImageInfo::Make(
|
| + size.Width(), size.Height(), color_params.GetSkColorType(), alpha_type,
|
| + color_params.GetSkColorSpaceForSkSurfaces());
|
| + SkSurfaceProps disable_lcd_props(0, kUnknown_SkPixelGeometry);
|
| +
|
| + GrGLTextureInfo tinfo;
|
| + tinfo.fTarget = texture_target;
|
| + tinfo.fID = texture;
|
| + GrBackendTextureDesc desc;
|
| + desc.fFlags = kRenderTarget_GrBackendTextureFlag;
|
| + desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
|
| + desc.fWidth = size.Width();
|
| + desc.fHeight = size.Height();
|
| + desc.fSampleCnt = 0;
|
| + desc.fConfig = kSkia8888_GrPixelConfig;
|
| + desc.fTextureHandle = skia::GrGLTextureInfoToGrBackendObject(tinfo);
|
| + surface_ = SkSurface::MakeFromBackendTexture(
|
| + gr_context, desc, color_params.GetSkColorSpaceForSkSurfaces(),
|
| + kOpaque == opacity_mode ? nullptr : &disable_lcd_props);
|
| +
|
| + if (!surface_)
|
| + return;
|
| +
|
| + DVLOG(1) << "texture: " << texture;
|
| + DVLOG(1) << "Skia texture: " << GetBackingTextureHandleForOverwrite();
|
| +
|
| + canvas_ = WTF::WrapUnique(new SkiaPaintCanvas(surface_->getCanvas()));
|
| + Clear();
|
| +
|
| + // Always save an initial frame, to support resetting the top level matrix
|
| + // and clip.
|
| + canvas_->save();
|
| +}
|
| +
|
| +bool TextureImageBufferSurface::IsValid() const {
|
| + return surface_ && SharedGpuContext::IsValid() &&
|
| + context_id_ == SharedGpuContext::ContextId();
|
| +}
|
| +
|
| +sk_sp<SkImage> TextureImageBufferSurface::NewImageSnapshot(AccelerationHint,
|
| + SnapshotReason) {
|
| + return surface_->makeImageSnapshot();
|
| +}
|
| +
|
| +GLuint TextureImageBufferSurface::GetBackingTextureHandleForOverwrite() {
|
| + if (!surface_)
|
| + return 0;
|
| + return skia::GrBackendObjectToGrGLTextureInfo(
|
| + surface_->getTextureHandle(
|
| + SkSurface::kDiscardWrite_TextureHandleAccess))
|
| + ->fID;
|
| +}
|
| +
|
| +bool TextureImageBufferSurface::WritePixels(const SkImageInfo& orig_info,
|
| + const void* pixels,
|
| + size_t row_bytes,
|
| + int x,
|
| + int y) {
|
| + return surface_->getCanvas()->writePixels(orig_info, pixels, row_bytes, x, y);
|
| +}
|
| +
|
| +} // namespace blink
|
|
|