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

Unified Diff: cc/resources/gpu_rasterizer.cc

Issue 69343005: Added preliminary support for tile rasterization with Ganesh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase (ScopedResource). Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/resource_provider.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/resources/gpu_rasterizer.cc
diff --git a/cc/resources/gpu_rasterizer.cc b/cc/resources/gpu_rasterizer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4cae56b3179f609da8d47c605ac02cb9f329fb93
--- /dev/null
+++ b/cc/resources/gpu_rasterizer.cc
@@ -0,0 +1,128 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/resources/gpu_rasterizer.h"
+
+#include "base/logging.h"
+#include "cc/output/context_provider.h"
+#include "cc/resources/resource_format.h"
+#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "third_party/skia/include/gpu/GrContext.h"
+#include "third_party/skia/include/gpu/SkGpuDevice.h"
+#include "ui/gfx/size_conversions.h"
+
+namespace cc {
+
+namespace {
+
+GrPixelConfig toGrFormat(ResourceFormat format) {
+ switch (format) {
+ case RGBA_8888:
+ return kRGBA_8888_GrPixelConfig;
+ case BGRA_8888:
+ return kBGRA_8888_GrPixelConfig;
+ case RGBA_4444:
+ return kRGBA_4444_GrPixelConfig;
+ default:
+ break; // If you break here, you're gonna have a bad time.
+ }
+ DCHECK(false) << "Unsupported resource format.";
+ return kSkia8888_GrPixelConfig;
+}
+
+} // namespace
+
+GpuRasterizer::RasterTask::RasterTask(
+ Tile* tile, scoped_ptr<ScopedResource> resource)
+ : tile_(tile), resource_(resource.Pass()) {
+}
+
+GpuRasterizer::RasterTask::~RasterTask() { }
+
+GpuRasterizer::Queue::Queue() { }
+
+GpuRasterizer::Queue::~Queue() { }
+
+void GpuRasterizer::Queue::Append(
+ Tile* tile, scoped_ptr<ScopedResource> resource) {
+ raster_tasks_.push_back(new RasterTask(tile, resource.Pass()));
+}
+
+scoped_ptr<GpuRasterizer> GpuRasterizer::Create(
+ ContextProvider* context_provider,
+ ResourceProvider* resource_provider) {
+ return make_scoped_ptr(
+ new GpuRasterizer(context_provider, resource_provider));
+}
+
+GpuRasterizer::GpuRasterizer(
+ ContextProvider* context_provider,
+ ResourceProvider* resource_provider)
+ : context_provider_(context_provider),
+ resource_provider_(resource_provider) {
+}
+
+GpuRasterizer::~GpuRasterizer() {
+}
+
+void GpuRasterizer::SetClient(GpuRasterizerClient* client) {
+ client_ = client;
+}
+
+void GpuRasterizer::Rasterize(
+ const Queue& queue,
+ RenderingStatsInstrumentation* rendering_stats_instrumentation) {
+ TRACE_EVENT0("cc", "GpuRasterizer::Rasterize");
+
+ if (queue.raster_tasks_.empty())
+ return;
+
+ blink::WebGraphicsContext3D* context = context_provider_->Context3d();
+ GrContext* gr_context = context_provider_->GrContext();
+ CHECK(client_);
+ CHECK(context);
+ CHECK(gr_context);
+
+ context->makeContextCurrent();
+ gr_context->resetContext();
+ for (RasterTaskVector::const_iterator it = queue.raster_tasks_.begin();
+ it != queue.raster_tasks_.end(); ++it) {
+ RasterTask* task = *it;
+ Tile* tile = task->tile_;
+ DCHECK_NE(task->resource_->id(), 0u);
+ {
+ ResourceProvider::ScopedWriteLockGL lock(
+ resource_provider_, task->resource_->id());
+
+ DCHECK_NE(lock.texture_id(), 0u);
+ GrBackendTextureDesc desc;
+ desc.fFlags = kRenderTarget_GrBackendTextureFlag;
+ desc.fWidth = tile->size().width();
+ desc.fHeight = tile->size().height();
+ desc.fConfig = toGrFormat(lock.format());
+ desc.fOrigin = kTopLeft_GrSurfaceOrigin;
+ desc.fTextureHandle = lock.texture_id();
+ skia::RefPtr<GrTexture> texture =
+ skia::AdoptRef(gr_context->wrapBackendTexture(desc));
+ skia::RefPtr<SkGpuDevice> device =
+ skia::AdoptRef(SkGpuDevice::Create(texture.get()));
+ CHECK(device);
+ skia::RefPtr<SkCanvas> canvas =
+ skia::AdoptRef(new SkCanvas(device.get()));
+
+ if (tile->opaque_rect().IsEmpty())
+ canvas->clear(SK_ColorTRANSPARENT);
+
+ tile->picture_pile()->RasterDirect(
+ canvas.get(), tile->content_rect(), tile->contents_scale(),
+ rendering_stats_instrumentation);
+ }
+
+ client_->OnGpuRasterTaskCompleted(tile, task->resource_.Pass());
+ }
+ gr_context->flush();
+}
+
+} // namespace cc
« no previous file with comments | « cc/resources/gpu_rasterizer.h ('k') | cc/resources/resource_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698